Article 160263 of comp.os.vms:
>         Most probably I'm missing something obvious. I want to define
>         a search path logical from a C program. I've read TFM, but
>         this did not enlighten me to much ;-(. My guess is that I setup
>         the item_list_3 structure wrong. Any help would be very much
>         appreciated. Below is the program I've came up with until now.

> #include <stdio.h>
> #include <string.h>
> #include <descrip.h>
> #include <lib$routines.h>

You will want lnmdef.h also to get LNM$_STRING (see later).

> int mode; /* Sorts of logicals: mode=0 plain
>                                 mode=LNM$M_CONCEALED concealed */

TFM explicit states that LNM$M_CONCEALED only works if no item-list
is specified !

> void define_rlogical_name(char *varname, char *string1, char *string2)
> {
>     struct dsc$descriptor_s renvdsc =
>       {0, DSC$K_DTYPE_T, DSC$K_CLASS_S, NULL};
>     struct dsc$descriptor_s rlnmdsc =
>       {17, DSC$K_DTYPE_T, DSC$K_CLASS_S, "LNM$PROCESS_TABLE"};
> 
>     struct
>     {  short length, code;
>        char *buff;
>     } *itmlist;

There are 2 short and 2 long in an item_list_3 structure (the missing is the
return length address).

You are declaring a pointer, where you want to declare an array.

>     itmlist[0].length = strlen(string1);
>     itmlist[0].buff = string1;
>     itmlist[0].code = 0;

This code should be LNM$_STRING.

>     itmlist[1].length = 0;
>     itmlist[1].buff = (char *)NULL;
>     itmlist[1].code = 0;
>     renvdsc.dsc$w_length  = strlen(varname);
>     renvdsc.dsc$a_pointer = varname;
> 
>     lib$set_logical (&renvdsc, 0, &rlnmdsc, &mode, &itmlist);
> }
> int main()
> {   mode = 0;
>    define_rlogical_name ("TEST", "foo", "bar");
> }

The following works:

#include <lnmdef.h>
#include <stdio.h>
#include <string.h>
#include <descrip.h>
#include <lib$routines.h>
int mode; /* Sorts of logicals: mode=0 plain
                                mode=LNM$M_CONCEALED concealed */

void define_rlogical_name(char *varname, char *string1, char *string2)
{
    struct dsc$descriptor_s renvdsc =
      {0, DSC$K_DTYPE_T, DSC$K_CLASS_S, NULL};
    struct dsc$descriptor_s rlnmdsc =
      {17, DSC$K_DTYPE_T, DSC$K_CLASS_S, "LNM$PROCESS_TABLE"};

    struct
    {  short length, code;
       char *buff;
       long retlen;
    } itmlist[2];

    itmlist[0].length = strlen(string1);
    itmlist[0].buff = string1;
    itmlist[0].code = LNM$_STRING;
    itmlist[0].retlen = 0;
    itmlist[1].length = 0;
    itmlist[1].buff = (char *)NULL;
    itmlist[1].code = 0;
    itmlist[1].retlen = 0;
    renvdsc.dsc$w_length  = strlen(varname);
    renvdsc.dsc$a_pointer = varname;

    printf("%d\n",lib$set_logical (&renvdsc, 0, &rlnmdsc, mode, &itmlist));
}

int main()
{   mode = 0;
   define_rlogical_name ("TEST", "foo", "bar");
}

                                                          Arne

Arne Vajhøj                             local DECNET:  KAL13::ARNE
Computer Department                     PSI:           PSI%23831001354030::ARNE
Southern Denmark Business School        Internet:      ARNE@KO.HHS.DK
                WWW URL: http://www.hhs.dk/~arne/arne.html



