              <<< VAXAXP::NOTES$:[NOTES$LIBRARY]VMSNOTES.NOTE;1 >>>
               -< VAX and Alpha VMS - Digital Internal Use Only >-
================================================================================
Note 922.2        Getting the file specification of SYS$OUTPUT            2 of 4
SWTHOM::LELEGARD "The Jazzing Troll"                 96 lines  23-MAY-1996 09:34
--------------------------------------------------------------------------------
Great !

I have written an equivalent C program for those who prefer HLL:

#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <descrip.h>
#include <ssdef.h>
#include <stsdef.h>
#include <lnmdef.h>
#include <starlet.h>
#include <rms.h>
#include <lib$routines.h>

#define ESC 0x1B
#define MAX_FILE_SPEC 256

#pragma member_alignment save
#pragma nomember_alignment

typedef struct {
    short length;
    short code;
    void  *buffer;
    short *retlen;
} ITEM;

typedef struct {
    union {
        char translation [MAX_FILE_SPEC];
        struct {
            unsigned char esc;
            unsigned char zero;
            unsigned short ifi;
            char device [MAX_FILE_SPEC - 4];
        } ppf;
    } u;
} PPF;

#pragma member_alignment restore


int main (int argc, char **argv)
{
    long status;
    short length;
    struct FAB fab;
    struct NAM nam;
    ITEM items [2];
    PPF translation;
    char resultant [MAX_FILE_SPEC];

    static const $DESCRIPTOR (sys_output, "SYS$OUTPUT");
    static const $DESCRIPTOR (lnm_file_dev, "LNM$FILE_DEV");

    items[0].code = LNM$_STRING;
    items[0].buffer = &translation;
    items[0].length = sizeof (translation) - 1;
    items[0].retlen = &length;
    items[1].code = items[1].length = 0;

    status = sys$trnlnm (0, &lnm_file_dev, &sys_output, 0, items);

    if (!$VMS_STATUS_SUCCESS (status))
        sys$exit (status);

    translation.u.translation [length] = '\0';

    if (length < 4 || translation.u.ppf.esc != ESC)
        printf ("Logical name = \"%s\"\n", translation);

    else {

        printf ("Logical name = <ESC> <%02X> <%04X> \"%s\"\n",
            translation.u.ppf.zero, translation.u.ppf.zero,
            translation.u.ppf.device);

        fab = cc$rms_fab;
        fab.fab$w_ifi = translation.u.ppf.ifi | FAB$M_PPF_IND;
        fab.fab$l_nam = &nam;

        nam = cc$rms_nam;
        nam.nam$l_rsa = resultant;
        nam.nam$b_rss = sizeof (resultant) - 1;

        status = sys$display (&fab);

        if (!$VMS_STATUS_SUCCESS (status))
            sys$exit (status);

        nam.nam$l_rsa [nam.nam$b_rsl] = '\0';

        printf ("NAM$L_RSA = \"%s\"\n", nam.nam$l_rsa);
    }
}
