From:	MERC::"uunet!CRVAX.SRI.COM!RELAY-INFO-VAX" 15-MAR-1993 16:23:28.71
To:	Info-VAX@KL.SRI.COM
CC:	
Subj:	Re: Help needed working with MAILBOXES in C (Source included)


In article <C3w1qo.A8L@acsu.buffalo.edu>,
v064qpfu@ubvmsb.cc.buffalo.edu (Christopher S. D'Arrigo) writes:
|>
|>$ run post 
|>$
|>New mail on node UBVMS from UBVMS::V064QPFU 
|>$ mail
|>You have 1 new message. 
|>   1 UBVMS::V064QPFU    14-MAR-1993  TEST 
|>
|>MAIL> ex
|>
|>$ show log/table=lnm$job *mail
|>
|>(LNM$JOB_822C27C0)                                                          
|>
|>  "INMAIL" = "MBA9533:"                                                     
|>
|>My questions are as follows : 
|>
|>1.) What is happening to OUTMAIL and how can I correct the code to 
|>    assign it correctly ? 

I think your code does assign it correctly, but once all channels to the mailbox
are deassigned, both it and its logical name go away.  What I can't see from
glancing at your code is why the logical name INMAIL hangs around.

|>2.) How can I modify the code to mail me a subject of : 
|>
|>    INMAIL = MBAXXXX: , OUTMAIL MBAXXXX   
|>
|>    rather than TEST (which I now have in there temporarily) so that I can 
|>    see that the logicals were assigned properly ?  

Since you have here a string with imbedded blanks in it, you must put quotes
around it.  That is, you want a /SUBJECT line that looks like this:

	/SUBJECT="INMAIL= MBAXXXX: , OUTMAIL = MBAXXXX"

The code you posted didn't enclose the subject string in quotes, so you're
limited to a single word (which DCL will convert to upper case).

SYS$CREMBX returns I/O channels as words (unsigned int), not longwords
(unsigned int).  You therefore end up with garbage in the high-order 2 bytes
of each variable.  Since you never actually use the values after the $CREMBX
call, this is a harmless error.

Similarly, the "length" output parameter from LIB$SYS_TRNLOG is a word, not
a longword.

Your LIB$SYS_TRNLOG calls are wrong--the third parameter is a descriptor for
a buffer to hold the output of the logical name translation.  You are
passing an integer.  If you were to check the return status from your
LIB$SYS_TRNLOG calls, I think you'd find that they are failing with
LIB$_INVSTRDES (invalid string descriptor) status.  You need to create
buffers to hold the logical name translations (64 characters is the max
length), set up descriptors for them, and then, when you get the results back,
you must NUL-terminate the strings so that the standard C string functions
can cope with them.

The other thing that you should do is adjust the length field (dsc$w_length)
of the "command" descriptor to match the actual length of the command.
Right now, you're always passing LIB$SPAWN an 80-character command string with
a NUL and a bunch of garbage bytes at the back of it.  It looks like you're
lucking out and DCL is ignoring everything past the NUL, but you're playing
with fire here--I wouldn't depend on that happening in all cases.

Here's an (untested) version of your code that should do the right thing.

Note that I took out the sleep() before the LIB$SPAWN call.  It accomplishes
nothing.

------------------------------- Cut Here --------------------------------------

#include <stdio.h> 
#include <descrip.h> 
#include <string.h> 

#define WHAT "TEST "   /* Temporarily placed in as a subject */ 

main()

{ /* Beginning of main function */ 

unsigned short length ; 

unsigned short inchannel, outchannel;  /* mailbox I/O channel numbers */

char indev[65], outdev[65]; /* logical name translation buffers (with room for
			       max. log. name size plus a NUL byte) */
$DESCRIPTOR(d_indev, indev); /* descriptor for indev */
$DESCRIPTOR(d_outdev, outdev); /* descriptor for outdev */

char user[10] = "V064QPFU" ; 

char command_text[80]; 

$DESCRIPTOR(command,command_text) ; 

$DESCRIPTOR(INBOX,"INMAIL") ; 
$DESCRIPTOR(OUTBOX,"OUTMAIL");

SYS$CREMBX(NULL,&inchannel, &132,&1000,&0,NULL,&INBOX) ; 
SYS$CREMBX(NULL,&outchannel,&132,&1000,&0,NULL,&OUTBOX) ; 

LIB$SYS_TRNLOG(&INBOX,&length,&d_indev) ;
indev[length] = 0;  /* NUL-terminate the string */
LIB$SYS_TRNLOG(&OUTBOX,&length,&d_outdev) ;
outdev[length] = 0; /* NUL-terminate the string */

/* NUL-terminate

sprintf(command_text,
    "MAIL/NOSELF NL: /SUBJECT= \"INMAIL = %s , OUTMAIL = %s\" %s",
    indev,
    outdev,
    user);

command.dsc$w_length = strlen(command_text); /* set correct length in
					        descriptor */

LIB$SPAWN(&command,&INBOX,&OUTBOX,&1,NULL) ; 

} /* Ending of main function */ 


