From:	CRDGW2::CRDGW2::MRGATE::"SMTP::CRVAX.SRI.COM::RELAY-INFO-VAX"  8-JUN-1991 14:14:26.89
To:	ARISIA::EVERHART
CC:	
Subj:	Re: Mailboxes.

From:	RELAY-INFO-VAX@CRVAX.SRI.COM@SMTP@CRDGW2
To:	Everhart@Arisia@MRGATE

Received:  by crdgw1.ge.com (5.57/GE 1.99)
	 id AA13564; Sat, 8 Jun 91 14:01:50 EDT
Received: From ucbvax.Berkeley.EDU ([128.32.133.1]) by CRVAX.SRI.COM with TCP; Fri,  7 JUN 91 13:29:50 PDT
Received: by ucbvax.Berkeley.EDU (5.63/1.42)
	id AA01944; Fri, 7 Jun 91 13:13:17 -0700
Received: from USENET by ucbvax.Berkeley.EDU with netnews
	for info-vax@kl.sri.com (info-vax@kl.sri.com)
	(contact usenet@ucbvax.Berkeley.EDU if you have questions)
Date: 7 Jun 91 20:05:40 GMT
From: cis.ohio-state.edu!zaphod.mps.ohio-state.edu!mips!spool.mu.edu!news.cs.indiana.edu!arizona.edu!leonard@ucbvax.Berkeley.EDU
Organization: University of Arizona
Subject: Re: Mailboxes.
Message-Id: <1991Jun7.130541.762@arizona.edu>
References: <17574.284bd324@ul.ie>, <1636@seq.uncwil.edu>
Sender: info-vax-request@kl.sri.com
To: info-vax@kl.sri.com

In article <1636@seq.uncwil.edu>, session@seq.uncwil.edu 
(Zack C. Sessions) writes:
> 9025189@ul.ie writes:
> 
>>				Does anybody know how to handle mailboxes in DCL
>>(is it possible to create them in dcl?) or a high level language equivilant.
>>						Baader.
> 
> There is no DCL facility which can create a mailbox, it must be done
> in a compiled language program which calls the $CREMBX system service.
> You COULD create your own DCL command which creates a mailbox using
> that technique, ie, write a program and install it as a DCL command).
> Once the mailbox has been created DCL can OPEN it and READ and WRITE
> from/to it.
> 
> Zack Sessions
> session@seq.uncwil.edu

Here's a couple of programs, PRMMBX.C and DELMBX.C, which create
and delete a permanent mailbox, suitable for manipulation via DCL.

Aaron

Aaron Leonard (AL104), <Leonard@Arizona.EDU>
University of Arizona Telecommunications, Tucson AZ 85721

$! ------------------ CUT HERE -----------------------
$ v='f$verify(f$trnlnm("SHARE_VERIFY"))'
$!
$! This archive created by VMS_SHARE Version 7.2-007  22-FEB-1990
$!   On  7-JUN-1991 13:00:30.38   By user LEONARD 
$!
$! This VMS_SHARE Written by:
$!    Andy Harper, Kings College London UK
$!
$! Acknowledgements to:
$!    James Gray       - Original VMS_SHARE
$!    Michael Bednarek - Original Concept and implementation
$!
$! TO UNPACK THIS SHARE FILE, CONCATENATE ALL PARTS IN ORDER
$! AND EXECUTE AS A COMMAND PROCEDURE  (  @name  )
$!
$! THE FOLLOWING FILE(S) WILL BE CREATED AFTER UNPACKING:
$!       1. 0README.;2
$!       2. DELMBX.C;1
$!       3. PRMMBX.C;2
$!       4. DELMBX.HLP;1
$!       5. PRMMBX.HLP;1
$!
$set="set"
$set symbol/scope=(nolocal,noglobal)
$f=f$parse("SHARE_TEMP","SYS$SCRATCH:.TMP_"+f$getjpi("","PID"))
$e="write sys$error  ""%UNPACK"", "
$w="write sys$output ""%UNPACK"", "
$ if f$trnlnm("SHARE_LOG") then $ w = "!"
$ ve=f$getsyi("version")
$ if ve-f$extract(0,1,ve) .ges. "4.4" then $ goto START
$ e "-E-OLDVER, Must run at least VMS 4.4"
$ v=f$verify(v)
$ exit 44
$UNPACK: SUBROUTINE ! P1=filename, P2=checksum
$ if f$search(P1) .eqs. "" then $ goto file_absent
$ e "-W-EXISTS, File ''P1' exists. Skipped."
$ delete 'f'*
$ exit
$file_absent:
$ if f$parse(P1) .nes. "" then $ goto dirok
$ dn=f$parse(P1,,,"DIRECTORY")
$ w "-I-CREDIR, Creating directory ''dn'."
$ create/dir 'dn'
$ if $status then $ goto dirok
$ e "-E-CREDIRFAIL, Unable to create ''dn'. File skipped."
$ delete 'f'*
$ exit
$dirok:
$ w "-I-PROCESS, Processing file ''P1'."
$ if .not. f$verify() then $ define/user sys$output nl:
$ EDIT/TPU/NOSEC/NODIS/COM=SYS$INPUT 'f'/OUT='P1'
PROCEDURE Unpacker ON_ERROR ENDON_ERROR;SET(FACILITY_NAME,"UNPACK");SET(
SUCCESS,OFF);SET(INFORMATIONAL,OFF);f:=GET_INFO(COMMAND_LINE,"file_name");b:=
CREATE_BUFFER(f,f);p:=SPAN(" ")@r&LINE_END;POSITION(BEGINNING_OF(b));
LOOP EXITIF SEARCH(p,FORWARD)=0;POSITION(r);ERASE(r);ENDLOOP;POSITION(
BEGINNING_OF(b));g:=0;LOOP EXITIF MARK(NONE)=END_OF(b);x:=ERASE_CHARACTER(1);
IF g=0 THEN IF x="X" THEN MOVE_VERTICAL(1);ENDIF;IF x="V" THEN APPEND_LINE;
MOVE_HORIZONTAL(-CURRENT_OFFSET);MOVE_VERTICAL(1);ENDIF;IF x="+" THEN g:=1;
ERASE_LINE;ENDIF;ELSE IF x="-" THEN IF INDEX(CURRENT_LINE,"+-+-+-+-+-+-+-+")=
1 THEN g:=0;ENDIF;ENDIF;ERASE_LINE;ENDIF;ENDLOOP;t:="0123456789ABCDEF";
POSITION(BEGINNING_OF(b));LOOP r:=SEARCH("`",FORWARD);EXITIF r=0;POSITION(r);
ERASE(r);x1:=INDEX(t,ERASE_CHARACTER(1))-1;x2:=INDEX(t,ERASE_CHARACTER(1))-1;
COPY_TEXT(ASCII(16*x1+x2));ENDLOOP;WRITE_FILE(b,GET_INFO(COMMAND_LINE,
"output_file"));ENDPROCEDURE;Unpacker;QUIT;
$ delete/nolog 'f'*
$ CHECKSUM 'P1'
$ IF CHECKSUM$CHECKSUM .eqs. P2 THEN $ EXIT
$ e "-E-CHKSMFAIL, Checksum of ''P1' failed."
$ ENDSUBROUTINE
$START:
$ create 'f'
X`5Bprmmbx`5D
X   prmmbx - a program that creates a permanent mailbox.
X       Args:    argv`5B1`5D - maxmsg - maximum size in bytes of a message
X                          that can be sent to this mailbox
X                argv`5B2`5D - bufquo - how big this mbx's buffer will be
X                argv`5B3`5D - prclognam - process logical name to point to m
Vbx.
X                          Defaults to `60UA_CREMBX'.
X   delmbx - a program that deletes a permanent mailbox.
X       Args:    argv`5B1`5D - name of mailbox to delete.
X           `20
$ CALL UNPACK 0README.;2 360402780
$ create 'f'
X/*
X * delmbx
X *   Delete a mailbox via the $DELMBX system service.
X *
X * Usage: delmbx mbxname
X *
X * Last modified:  2-Jan-1990/al
X *
X *  2-Jan-1990  al      First version
X *
X */
X
X#include <stdio.h>
X#include climsgdef
X#include descrip
X#include psldef
X#include stsdef
X
X#define VMSERR( s ) if (!($VMS_STATUS_SUCCESS(s))) exit(s)  `20
X
Xextern int main(int argc, char**argv)
X`7B
X    unsigned long int status, SYS$ASSIGN(), SYS$DELMBX();
X    size_t strlen();
X    void gripeaboutusage();
X
X    unsigned short int chan;
X    struct dsc$descriptor devnamD;
X
X    if (argc != 2)
X    `7B
X        gripeaboutusage();
X        exit(argc < 2 ? CLI$_INSFPRM : CLI$_MAXPARM);
X    `7D
X
X    /* set up the descriptor for the mailbox name */
X
X    devnamD.dsc$a_pointer = argv`5B1`5D;
X    devnamD.dsc$w_length = (unsigned short int) strlen(argv`5B1`5D);
X    devnamD.dsc$b_dtype = DSC$K_DTYPE_T;
X    devnamD.dsc$b_class = DSC$K_CLASS_S;
X   `20
X    status = SYS$ASSIGN(&devnamD, &chan, PSL$C_USER, 0);
X    VMSERR(status);
X
X    status = SYS$DELMBX(chan);
X    exit(status);
X
X`7D   /* main */
X`0C
Xvoid gripeaboutusage()
X`7B
X    fprintf(stderr, "usage: delmbx mailboxname\n");
X`7D
X
X/* delmbx.c */
$ CALL UNPACK DELMBX.C;1 270955496
$ create 'f'
X/* prmmbx
X *   Create a permanent mailbox via the $CREMBX system service.
X *   Requires PRMMBX privilege to work.
X *
X *     Args:    argv`5B1`5D - maxmsg - maximum size in bytes of a message
X *                        that can be sent to this mailbox
X *              argv`5B2`5D - bufquo - how big this mbx's buffer will be
X *              argv`5B3`5D - prclognam - Process logical name to point to m
Vbx.
X *                        Defaults to `60UA_PRMMBX'.
X *
X * Last modified:  2-Jan-1990/al
X *
X *  2-Jan-1990  al      Do LNM creation right
X * 29-Dec-1989  al      First version
X *
X */
X
X#include <stdio.h>
X#include <stdlib.h>
X#include <string.h>
X#include climsgdef
X#include descrip
X#include lnmdef
X#include psldef
X#include stsdef
X
X#define VMSERR( s ) if (!($VMS_STATUS_SUCCESS(s))) exit(s)  `20
X#define DEFPRCLOGNAM "UA_PRMMBX"                /* default LNM for new MBX *
V/
X#define PERMANENT 1
X#define TEMPORARY 0
X
Xtypedef struct _item `7B
X    unsigned short`09length;`09`09`09/* length of data buffer */
X    unsigned short`09code;`09`09`09/* item code */
X    unsigned char`09*buffer;`09`09/* data buffer */
X    unsigned long`09*retlen;`09`09/* returned item length */
X`7D ITEM;
X
Xextern int main(int argc, char **argv)
X`7B
X    unsigned long int status, LIB$SET_LOGICAL(), SYS$CREMBX(), SYS$CRELNM(),
X                      SYS$TRNLNM();
X    int atoi();
X    size_t strlen();
X    void gripeaboutusage();
X
X    unsigned short int chan;
X    unsigned long int maxmsg, bufquo;
X    char *defprclognam = DEFPRCLOGNAM;
X    $DESCRIPTOR(lnmtableD, "LNM$PROCESS_DIRECTORY");
X    $DESCRIPTOR(lnmD, "LNM$PERMANENT_MAILBOX");
X    $DESCRIPTOR(tmplnmD, "UA_TMP_PRMMBX");
X    $DESCRIPTOR(prctabD, "LNM$PROCESS_TABLE");
X    char *lnmval = "LNM$PROCESS_TABLE";
X    struct dsc$descriptor prclognamD;  `20
X    ITEM itmlst`5B2`5D;             /* itemlist for $CRELNM call */
X    char mbxname`5BLNM$C_NAMLENGTH+1`5D;
X    int mbxnamelength;
X    struct dsc$descriptor mbxnameD;
X
X    /* First, sanity-check the args.  argv`5B1`5D (maxmsg) defaults to 0;
X     * argv`5B2`5D (bufquo) defaults to 0; argv`5B3`5D (prclognam) defaults
V to
X     * "UA_PRMMBX".
X     */
X
X    if (argc > 4)
X    `7B
X        gripeaboutusage();
X        exit(CLI$_MAXPARM);
X    `7D
X
X    if (argc < 2)
X        maxmsg = 0;
X    else
X        sscanf(argv`5B1`5D, "%d", &maxmsg);
X
X    if (argc < 3)
X        bufquo = 0;
X    else
X        sscanf(argv`5B2`5D, "%d", &bufquo);
X
X    if (argc == 4)
X    `7B
X        prclognamD.dsc$a_pointer = argv`5B3`5D;
X        prclognamD.dsc$w_length = (unsigned short int) strlen(argv`5B3`5D);
X    `7D
X    else
X    `7B
X        prclognamD.dsc$a_pointer = defprclognam;`20
X        prclognamD.dsc$w_length = strlen(defprclognam);
X    `7D
X    prclognamD.dsc$b_dtype = DSC$K_DTYPE_T;
X    prclognamD.dsc$b_class = DSC$K_CLASS_S;
X
X    /* Define the LNM LNM$PERMANENT_MAILBOX in user mode to go into
X     * the LNM$PROCESS_TABLE LNM table.  This is to make the LNM pointing
X     * to the newly created MBX go into the job table rather than into
X     * the system table which is the default for permanent MBXes.  The
X     * LNM$PERMANENT_MAILBOX LNM is created in user mode so as to vanish
X     * when this image runs down.
X     */
X
X    itmlst`5B0`5D.length = (unsigned short int) strlen(lnmval);
X    itmlst`5B0`5D.code = LNM$_STRING;
X    itmlst`5B0`5D.buffer = lnmval;               `20
X    itmlst`5B1`5D.length = itmlst`5B1`5D.code = 0;
X
X    status = SYS$CRELNM(0, &lnmtableD, &lnmD, &PSL$C_USER, &itmlst);
X    VMSERR(status);
X
X    /* Now call $CREMBX, specifying the following args:
X     * prmflg <- 1 (permanent)
X     * chan
X     * maxmsg
X     * bufquo
X     * promsk <- 0 (all access allowed; user should SET DEV/PROT after calli
Vng)
X     * acmode <- PSL$C_USER
X     * lognam <- tmplnmD
X     */
X
X    status = SYS$CREMBX(PERMANENT, &chan, maxmsg, bufquo, 0, PSL$C_USER,`20
X                        &tmplnmD);
X    VMSERR(status);
X
X    /* The identity of the mailbox is now contained in the user mode process
X     * LNM pointed to by tmplnmD.  As this LNM will vanish when this image
X     * runs down, we must put its value into a super mode LNM.
X     */         `20
X
X    itmlst`5B0`5D.length = LNM$C_NAMLENGTH;
X    itmlst`5B0`5D.code = LNM$_STRING;
X    itmlst`5B0`5D.buffer = mbxname;
X    itmlst`5B0`5D.retlen = &mbxnamelength;
X    status = SYS$TRNLNM(0, &prctabD, &tmplnmD, &PSL$C_USER, &itmlst);  `20
X    VMSERR(status);
X
X    mbxnameD.dsc$w_length = (unsigned short int) mbxnamelength;
X    mbxnameD.dsc$a_pointer = mbxname;
X    mbxnameD.dsc$b_dtype = DSC$K_DTYPE_T;
X    mbxnameD.dsc$b_class = DSC$K_CLASS_S;
X    status = LIB$SET_LOGICAL(&prclognamD, &mbxnameD, 0, 0, 0);
X    exit(status);`20
X
X`7D   /* main */
X`0C
X/* gripeaboutusage
X *   complain to SYS$ERROR
X */
Xvoid gripeaboutusage()
X`7B
X    int fprintf();
X    fprintf(stderr, "Usage: prmmbx `5Bmaxmsg`5D `5Bbufquo`5D `5Bprclognam`5D
V\n");
X    fprintf(stderr,`20
X"where: maxmsg is the maximum size in bytes of a message that can be sent\n"
V);
X    fprintf(stderr, "       to the mailbox\n");
X    fprintf(stderr, "       bufquo is buffer size for mbx (max: 64k bytes)\n
V");
X    fprintf(stderr,`20
X"       prclognam is the process LNM that will point to the mbx.\n");
X`7D
$ CALL UNPACK PRMMBX.C;2 1230590569
$ create 'f'
X1 delmbx
X Delete a mailbox via the $DELBMX system service.
X
X Usage:
X
X $ DELMBX :== $STAFF_EXE:DELBMX
X
X $ DELMBX mailboxname
$ CALL UNPACK DELMBX.HLP;1 1998928657
$ create 'f'
X1 prmmbx
X Create a permanent mailbox via the $CREMBX system service.  Requires
X PRMMBX privilege.
X
X Usage:
X
X $ PRMMBX :== $STAFF_EXE:PRMMBX
X
X $ PRMMBX `5Bmaxmsg`5D `5Bbufquo`5D `5Bprclognam`5D
X
X where:`20
X
X maxmsg is the maximum size in bytes of a message that can be sent to
X        this mailbox
X bufquo is the number of bytes of nonpaged pool that can be used for
X        this mailbox's buffer
X prclognam is a process logical name that will be created to point to
X        the mailbox (default is UA_PRMMBX).
$ CALL UNPACK PRMMBX.HLP;1 487151116
$ v=f$verify(v)
$ EXIT

