[comp.os.vms] Translating logical names from C

RSD1901@TAMSIGMA.BITNET.UUCP (01/21/88)

I'm posting this to the entire list as there have been a couple of questions
about $TRNLNM as of late...

>Dear InfoVaxers,
>    This is my third try at this so my apologys is it comes thru
>more then once.  My mailer is somewhat braindead and keeps coming
>back and telling me it doesn't know where to send messages if it can't
>find send my message.  Ow well, here goes nothing.
>
>
>    Its friday and maybe thats why I can't figure this out but maybe
>someone else can help.  I am trying to use the system service sys$trnlnm
>to translate a logical name.  However, how to define the struct for the
>itemlst eludes me.  All I want to do is have in my hot little hands a
>pointer to a string containing the translated logical.  Can anyone
>help?
>
>        Thanks
>
>       Al Saganich, Systems Analyst, Mass General Hosp.
>        Saganich%frodo.decnet@mghccc.harvard.edu
>
>
>heres what I'm trying to do.
>
>#include <STDIO.h>
>#include <SSdef.h>   /* the system reurn codes */
>#include <Descrip.h> /* the descriptor definitions */
>#include <Llndef.h>  /* the attributes to $trnlnm */
>
>/* translate the give logical name and print the translation */
>main()
>{
>int sys$trnlnm();
>
>$DESCRIPTOR(Log_nam,"EDTINI");
>$DESCRIPTOR(Tab_nam,"PROCESS");
>
>sys$trnlnm(NULL,&Tab_nam,$Log_nam,NULL,&itemlst)
>
>printf("%s\n",somestringpointer}
>------

Al,

Here's a way to do it with an RTL routine instead of SYS$TRNLNM. It calls
SYS$TRNLNM for you and you don't have to fool with item lists.

  {
    static struct dsc$descriptor_s
      translation_dsc={(maximum length of trans.),DSC$K_DTYPE_T,DSC$K_CLASS_S};
    $DESCRIPTOR(lognam_dsc,"LOGNAME");
    char *translation[(max. len. trans.)];
    static int translen,ssrc;
    translation_dsc.dsc$a_pointer=translation;
    ssrc=lib$sys_trnlog(&lognam_dsc,&translen,&translation_dsc,0,0,0);
    printf("%s\n",translation);
  }

translation_dsc -- descriptor for translation
lognam_dsc      -- descriptor for logical name to be translated
translation     -- character string to contain translation
translen        -- length of translation
ssrc            -- return code from system service
lib$sys_trnlog  -- RTL routine which calls $TRNLNM for you

If you need to specify the table name (if you're translating something which
is only listed in one table you won't need to), the table name can be specified
following the "translation_dsc" actual parameter in this particular call. The
last two arguments are for the access mode for the logical you're seeking and
the mask of tables in which to search for it if they are not the same as
LNM$PROCESS_DIRECTORY or you wish to disable searching in one particular table.
I've never used these arguments so you'll have to look in your Run-Time Library
manual if you need them.

You may have a problem with extraneous characters at the end of your
translation. In that case, you'd have to do a strncpy(translation,newtrans,
translen) to keep only the number of characters returned from the system service
by the parameter "translen". The "#include" directives you have in there will
be sufficient.

Good luck...

--Shane Davis
  Texas A&M Univ. Software Systems Group

********************************************************************************
        BITnet             THEnet                       Internet

  XPMAINT@TAMVENUS      THOR::XPMAINT           xpmaint@venus.tamu.edu
  RSD1901@TAMSIGMA       ZAC::RSD1901                   --------
  X222SD@TAMVM1            ------               x222sd@tamvm1.tamu.edu
        ------          CONS::RSD1901           rsd1901@cons.tamu.edu

        SPAN: UTSPAN::UTADNX::(THEnet addr)
********************************************************************************

sarge@con.Berkeley.EDU (Steven Sargent) (01/29/88)

We do something like this as well.  The one thing that I have to add is
that "process-permanent" logical names (e.g, SYS$INPUT) have a 4-byte
booger prepended to their translations.  In our "getenv" replacement
routine, we snarf up the logical name translation and then say words like:

	return (*p == '\33')? p+4: p;

to get around it.  (Anybody know what that 4 bytes of stuff is?)

S.

hydrovax@nmtsun.nmt.edu (M. Warner Losh) (01/31/88)

In article <429@pasteur.Berkeley.Edu>, sarge@con.Berkeley.EDU
(Steven Sargent) writes:
> "process-permanent" logical names (e.g, SYS$INPUT) have a 4-byte
> booger prepended to their translations.
> [...]
> (Anybody know what that 4 bytes of stuff is?)

According to one of the manuals that I was looking through recently
(yes, it is for VMS :-), the first byte is an escape character
(\033) while the other three point to something called an RMS internal
file number.  The manual claims that this speeds things up quite a bit.

-- 
bitnet:	losh@nmt.csnet			M. Warner Losh
	warner@hydrovax.nmt.csnet    ! Don't know if this works, let me know.
csnet:	warner@hydrovax.nmt.edu
uucp:	...{cmcl2, ihnp4}!lanl!unmvax!nmtsun!warner%hydrovax

jumper@trwrb.UUCP (Gregory S. Jumper) (02/01/88)

The four-byte header in the equivalence string of a logical name which refers
to a process-permanent file contains the "escape" and "null" characters,
followed by two bytes representing the RMS Internal File Identifier for that
process-permanent file.  This header allows for faster access to these files.


Greg Jumper

ARPA Internet:  trwrb!jumper@trwind.TRW.COM
         UUCP:  ...{decvax,ihnp4,ucbvax}!trwrb!jumper

dave@terminus.UUCP (VAX Headroom @ The End of the Galaxy) (02/03/88)

I believe the first 4 bytes at the beginning of things like
SYS$INPUT and SYS$OUTPUT are an ISI, and RMS internal stream identifier.
These files are always open and rms uses this to identify the "channel"
being used to communicate with the entity pointed to by the logical name.
-- 
...ihnp4!utah-cs!utah-gr!uplherc!sp7040!obie!terminus!trntor.dnet!dave
				"...between the streets of dallas and the
				 beaches of miami...this was max headroom's
				 finest hour."