Example-C  How to get a logical name list of equivalences.

EXAMPLE TEMPLATE:
PRODUCT: DEC C Version 5.7
OP/SYS: OpenVMS Version
SOURCE: Philippe Vouters Fontainebleau/France
LOW-COST HIGH-TECH: http://techno-star.fr
OVERVIEW: This program shows a way to get the equivalences list of a logical name. The maximum number of equivalence is first obtained, then, looping for each index, each equivalence is printed out.
*** CAUTION *** This sample program has been tested using DEC V5.1 on OpenVMS Alpha V7.1. However, we cannot guarantee its effectiveness because of the possibility of error in transmitting or implementing it. It is meant to be used as a template for writing your own program, and may require modification for use on your system.
PROGRAM NOTES: $ CC thisprogram $ LINK thisprogram $ trnlnm :== $disk:[directory]thisprogram $ trnlnm string If not enclosed between quotes, the string is passed in lowercase often preventing a translation. If uppercasing should be preserved, enclose the uppercase string between quotes. For example: $ trnlnm "SYS$LOGIN"
PROGRAM: /* * COPYRIGHT (C) 1998 BY * DIGITAL EQUIPMENT CORPORATION, MAYNARD * MASSACHUSETTS. ALL RIGHTS RESERVED. * * THIS SOFTWARE IS FURNISHED UNDER A LICENSE AND MAY BE USED AND COPIED * ONLY IN ACCORDANCE WITH THE TERMS OF SUCH LICENSE AND WITH THE * INCLUSION OF THE ABOVE COPYRIGHT NOTICE. THIS SOFTWARE OR ANY OTHER * COPIES THEREOF MAY NOT BE PROVIDED OR OTHERWISE MADE AVAILABLE TO ANY * OTHER PERSON. NO TITLE TO AND OWNERSHIP OF THE SOFTWARE IS HEREBY * TRANSFERRED. * * THE INFORMATION IN THIS SOFTWARE IS SUBJECT TO CHANGE WITHOUT NOTICE * AND SHOULD NOT BE CONSTRUED AS A COMMITMENT BY DIGITAL EQUIPMENT * CORPORATION. * * DIGITAL ASSUMES NO RESPONSIBILITY FOR THE USE OR RELIABILITY OF ITS * SOFTWARE ON EQUIPMENT THAT IS NOT SUPPLIED BY DIGITAL. * * NO RESPONSIBILITY IS ASSUMED FOR THE USE OR RELIABILITY OF SOFTWARE ON * EQUIPMENT THAT IS NOT SUPPLIED BY DIGITAL EQUIPMENT CORPORATION. * * SUPPORT FOR THIS SOFTWARE IS NOT COVERED UNDER ANY DIGITAL SOFTWARE * PRODUCT SUPPORT CONTRACT, BUT MAY BE PROVIDED UNDER THE TERMS OF THE * CONSULTING AGREEMENT UNDER WHICH THIS SOFTWARE WAS DEVELOPED. */ #ifdef __DECC #pragma module trnlnm "V1.0-00" #else #module trnlnm "V1.0-00" #endif /* * Include C specific headers. */ #include <stdlib.h> #include <stdio.h> #include <string.h> /* * Include OpenVMS specific headers. */ #include <ssdef.h> #include <descrip.h> #include <lnmdef.h> #include <starlet.h> #include <lib$routines.h> #include <ssdef.h> #ifdef __ALPHA #pragma member_alignment save #pragma nomember_alignment word #endif typedef struct { /* Standard item for VMS system services */ unsigned short length; unsigned short code; void *buffer; unsigned short *retlen; } item_t; #ifdef __ALPHA #pragma member_alignment restore #endif int main (int argc, char **argv){ struct dsc$descriptor_s lognam_dsc = {0,DSC$K_DTYPE_T,DSC$K_CLASS_S,0}; $DESCRIPTOR (tabnam_dsc,"LNM$FILE_DEV"); char equivalence[255]; unsigned short equivlen; long max_index; item_t *itmlst; unsigned short ret; long i; int status; if (argc!=2){ printf ("Usage : trnlnm_lst <logical name>\n"); exit(0); } lognam_dsc.dsc$w_length = strlen(argv[1]); lognam_dsc.dsc$a_pointer = argv[1]; /* * Allocate TWO item list plus one (filled with zeroes). */ itmlst = calloc (3, sizeof (item_t)); /* * Get the maximum number logical name translations. */ itmlst[0].length = sizeof (max_index); itmlst[0].code = LNM$_MAX_INDEX; itmlst[0].buffer = &max_index; itmlst[0].retlen = &ret; status = sys$trnlnm(0,&tabnam_dsc,&lognam_dsc,0,itmlst); if ((!(status &1)) && (status != SS$_NOLOGNAM)) lib$signal(status); if (status == SS$_NOLOGNAM){ printf ("No translation for %s\n",argv[1]); exit(0); } printf ("\"%s\" = ",argv[1]); /* * Setup itmlst[1] with code LNM$_STRING and itmlst[0] with code * LNM$_INDEX which must be before LNM$_STRING, LNN$_LENGTH, or * LNM$_ATTRIBUTES. */ itmlst[1].length = sizeof (equivalence); itmlst[1].code = LNM$_STRING; itmlst[1].buffer = equivalence; itmlst[1].retlen = &equivlen; for (i=0;i<=max_index;i++){ itmlst[0].length = sizeof (i); itmlst[0].code = LNM$_INDEX; itmlst[0].buffer = &i; itmlst[0].retlen = NULL; status = sys$trnlnm(0,&tabnam_dsc,&lognam_dsc,0,itmlst); if (!(status &1)) lib$signal(status); equivalence[equivlen] = 0; if (i < max_index) printf ("\"%s\"\n\t =",equivalence); else printf ("\"%s\"\n",equivalence); } return (SS$_NORMAL); }
REFERENCE(S): OpenVMS System Services Manual
Did you find this helpful?