From:	MERC::"uunet!CRVAX.SRI.COM!RELAY-INFO-VAX"  8-JUL-1992 02:03:11.33
To:	info-vax@kl.sri.com
CC:	
Subj:	CTRAP Release Version 2.0 (part 1 of 2)

Well, I've finally gotten around to writing a new version of CTRAP.
Included in this message is part 1 of 2 in VMSSHARE format.  

From the documentation:

   This program is used to trap incoming broadcast messages.
   Normally, when a broadcast message is received (such as mail,
   bitnet messages, PHONE, TALK, etc....) it is blasted all over the
   screen.  This is rather annoying.  If you are in an editor, it often
   either screws up your program nicely, or it just disappears 
   altogether.  Ctrap provides a good way to trap these incoming broadcast 
   messages and store them until you are ready for them.

   Format: CTRAP [ON [file] | DUMP [file] | OFF]


The following is a summary of new features included with version 2.0:

        (1) Quiet mode.  By specifying a file when ctrap is first turned on,
        CTRAP will store incoming messages into the file without any 
        notification.
        (2) File output.  By specifying a file when a ctrap dump command is
        given, the user can store the messages into the file instead of 
        having it displayed on screen.
        (3) Mail option.  By defining the logical CTRAP$MAIL to be a filename,
        the user has the ability to communicate with a bitnet SENDer.  
        See CTRAP.HLP for more info on the mail option.
        (4) Number of pending messages added to "Msg(s) pending" signal.
        (5) Bug fixed in message lengths.  Messages should now be in their
        correct lengths instead of taking up 200+ extra spaces every now 
        and then.
        (6) An additional side effect is included in the documentation.
        (7) Added documentation included throughout the source code for 
            clarity, although the code still has spaghetti-like qualities.

That's it.  Suggestions, comments, snickers bars, etc. can be sent to 
castillo@nauvax.ucc.nau.edu; flames go directly go NLA0:, do not pass
nau.edu, do not collect my snickers bar.

Belgarion. (aka ulysses castillo)
_____
Ulysses Castillo (aka Belgarion)
Castillo@nauvax.ucc.nau.edu
"Be assured, I am with you always, to the end of Time.", Matt. 28:20

$! ------------------ CUT HERE -----------------------
$ v='f$verify(f$trnlnm("SHARE_VERIFY"))'
$!
$! This archive created by VMS_SHARE Version 7.2-007  22-FEB-1990
$!   On  7-JUL-1992 09:34:10.55   By user CASTILLO 
$!
$! This VMS_SHARE Written by:
$!    Andy Harper, Kings College London UK
$!
$! Acknowledgements to:
$!    James Gray       - Original VMS_SHARE
$!    Michael Bednarek - Original Concept and implementation
$!
$!+ THIS PACKAGE DISTRIBUTED IN 2 PARTS, TO KEEP EACH PART
$!  BELOW 100 BLOCKS
$!
$! 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. BRDCST.C;1
$!       2. CTRAP.C;1
$!       3. CTRAP.COM;1
$!       4. CTRAP.H;1
$!       5. CTRAP.HLP;1
$!       6. MAKECTRAP.COM;1
$!       7. MBX.C;1
$!       8. QUEUE.C;1
$!       9. SEND_MAIL.C;1
$!      10. SEND_MAIL.H;1
$!      11. TOOLS.C;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/* `09CTRAP v2.0`09`09Summer 1992
X
X`09MODULE NAME: Brdcst.C
X`09AUTHOR:  Belgarion (castillo@nauvax.ucc.nau.edu)
X`09LAST REVISED: March 11, 1991  Release version 1.0.1
X                      ?????????????   Release version 1.2
X                      ?????????????   Release version 1.5
X`09              July 6, 1992    Release version 2.0
X
XThis file is for use with Ctrap.  It is the module containing all functions
Xrelating to broadcast trapping.
X
XThe buffer containing the broadcast messages is implemented as a circular qu
Veue
XADT.  The usable functions to manipulate brdcast_buf (the queue) are: push,
Xpop, setqueue.  When the number of broadcast messages received becomes large
Vr
Xthan the LIMIT, older messages are overwritten by the newer ones. floating o
Vff
Xinto limbo. */
X
X#include "ctrap.h"
X
X/*---------------------broadcast handling module----------------------------
V-*/
X
X/***************************************************************************
V***
X Function: setup_broad_hand()
X
X Description: enable the trapping of broadcast messages that would otherwise
X screw up the screen
X
X Arguments: int pbid, the pasteboard id.
X Return Value: none
X Side Effects: sets up an AST that calls brd_trap and passes pbid when a`20
X broadcast message appears.
X****************************************************************************
V**/
Xvoid setup_broad_hand(int pbid)
X`7B
X    smg$set_broadcast_trapping(&pbid,brd_trap,pbid);
X    fprintf(stdout,"Broadcast trapping enabled.\n");
X`7D`09`09`09`09/* setup_broad_hand */
X
X
X/***************************************************************************
V***
X Function: brd_trap()
X
X Description: This AST routine is called whenever a broadcast message comes
X to the terminal. EG: new mail, phone, talk, bitnet noise, and operators
X that want to get your attention.  The broadcast message(s) are retrieved
X and then displayed according to options you have chosen.
X
X Arguments: int pbid, the pasteboard id.
X Return Value: none
X Side Effects: removes the broadcast message from the system broadcast
X message mailbox; calls handle_msg.
X****************************************************************************
V**/
Xvoid brd_trap(int pbid)
X`7B
X    short int msgl;
X    int status;
X    msg_type msg;
X    msg.length = STRLIM;`09/* build a string descriptor for  */
X    msg.dtype = 14;`09`09/* the broadcast message          */
X    msg.class = 1;
X    msg.ptr = (char *) malloc(STRLIM);
X    status = 1;`09`09`09/* get and display the message(s) */
X
X    while (status == 1)
X    `7B
X`09int i;
X
X`09status = smg$get_broadcast_message(&pbid,&msg,&msgl);
X`09if (status == 1)
X`09`7B
X`09    for (i = msgl; i <= STRLIM; i++)
X`09`09msg.ptr`5Bi`5D = 0;
X`09    handle_msg(brdcst_buf,msg);
X`09`7D`09`09`09/* if */
X    `7D`09`09`09`09/* while */
X`7D`09`09`09`09/* brd_trap */
X
X
X/***************************************************************************
V***
X Function: handle_msg()
X
X Description: the main message handler.  If t_file is true, then the person
X is NOT notified, and the message is dumped into the file specified in t_nam
Ve.
X t_file is a global variable that is set to true if a filename is specified
X to CTRAP.COM when it is turned on.  t_name is the filename specified and is
X also global.  Finally, it calls a routine that can send mail under certain
X conditions.
X
X Arguments: queue *q, the brdcst_buffer (a queue); msg_type msg, a`20
X fixed length descriptor containing the broadcast message.
X Return Value: none
X Side Effects: you figure it out.
X****************************************************************************
V**/
Xvoid handle_msg(queue *q,msg_type msg)
X`7B
X    push(q,msg);
X    handle_mail(msg);
X    if (!t_file)
X`09notify_user();
X    else
X`09dump_msgs(t_name);
X`7D`09`09`09`09/* handle_msg */
X
X
X/***************************************************************************
V***
X Function: notify_user()
X
X Description: notifies the user by placing a message on the bottom of`20
X their screen.
X
X Arguments: none
X Return Value: none
X Side Effects: Affects the position of the cursor sometimes.
X****************************************************************************
V**/
Xvoid notify_user(void)
X`7B
X/*================
X   For the interested: <ESC> 7 = save cursor position; <ESC> 1m = bold;
X   <ESC>5m = blink; <ESC>`5B25;0H = put cursor on row 25, col 0; <ESC> 8 =`2
V0
X   return cursor to saved position.`20
X  ================
X*/
X    fprintf(stdout,"`1B7`1B`5B25;0H`1B`5B1m`1B`5B5mMsgs(s) pending: %d`1B`5B
V0m`1B8",
X`09    nummsgs(brdcst_buf));
X`7D`09`09`09`09/* notify_user */
X
X/***************************************************************************
V***
X Function: dump_msgs()
X
X Description: this dumps the messages contained in the queue to either`20
X the screen, or to a file as specified by the user.
X
X Arguments: char *fname, the filename to put the messages (possibly stdout)
X Return Value: none
X Side Effects: empties the queue.
X****************************************************************************
V**/
Xvoid dump_msgs(char *fname)
X`7B
X    msg_type msg;
X
X    /* btw, yes I know there's a better way, but I'm trying to make this
X       simple to read and understand, I'm not retarded or anything though. *
V/
X    if (strcmp(fname,"stdout") == 0)
X    `7B
X`09while (pop(brdcst_buf,&msg))
X`09    fprintf(stdout,"%s\n",msg.ptr);
X`09fprintf(stdout,"\nNo more messages.\n");
X    `7D
X    else
X    `7B
X`09FILE *fp;
X
X`09if ((fp = fopen(fname,"a")) != NULL)
X`09`7B
X`09    while (pop(brdcst_buf,&msg))
X`09    `7B
X`09`09if (!t_file)
X`09`09    fprintf(stdout,".");
X`09`09fprintf(fp,"%s\n",msg.ptr);
X`09    `7D
X`09    if (!t_file)
X`09`09fprintf(stdout,"Done.\n");
X`09    fclose(fp);
X`09`7D
X`09else
X`09    fprintf(stdout,"Error opening %s for append.\n",fname);
X    `7D
X    if (!t_file)
X`09fprintf(stdout,"`1B7`1B`5B25;0H                   `1B8");
X`7D`09`09`09`09/* dump_msgs */
X
X/* --------------- end of broadcast module ----------------------*/
$ CALL UNPACK BRDCST.C;1 725364240
$ create 'f'
X/* `09CTRAP v2.0`09`09Summer 1992
X
X`09MODULE NAME:  CTRAP.C`09the main module :)
X`09HEADER:       CTRAP.H
X                      SEND_MAIL.H
X`09SUBMODULES:   BRDCST.C
X`09`09      QUEUE.C
X`09`09      MBX.C
X                      SEND_MAIL.C
X                      TOOLS.C
X`09SHAREABLE IMAGE: SYS$LIBRARY:VAXCRTL/SHARE
X
X`09AUTHOR:  Belgarion (castillo@nauvax.ucc.nau.edu)
X`09LAST REVISED: March 12, 1991 release v 1.0.1
X                      ?????????????? release v 1.2
X`09`09      July 1, 1992  (Castillo)
X                 `09`09`09 fixed storage bug, miscell bugs
X                      July 6, 1992  release v 2.0
X
X`09Inspired by, and in consultation with
X`09`09Tony McCracken (ACM@nauvax.ucc.nau.edu)  &
X`09`09Sir Gareth /`7E  (mshimniok@xray1.chem.arizona.edu)
X`09
XNotice of Copyright: CTRAP is copyright (c) 1991 by Ulysses Castillo
X(castillo@nauvax.ucc.nau.edu) & Michael E. Shimniok
X(shimniok@hacks.arizona.edu).  All Rights Reserved. CTRAP may be distributed
Xfor free only.  CTRAP may only be distributed so long as no modifications ar
Ve
Xmade and this notice of copyright and disclaimer is included.   CTRAP may no
Vt
Xbe distributed as a part of any commercial package without the express writt
Ven
Xpermission of the authors.  The authors reserve the right to distribute cmai
Vl
Xfor commercial purposes at any time.
X
XDisclaimer: CTRAP IS DISTRIBUTED AS IS, WITH ALL FAULTS, AND CONTAINS NO
XEXPRESSED OR IMPLIED WARRANTIES INCLUDING ANY IMPLIED WARRANTY OF
XMERCHANTABILITY, USAGE OF TRADE, OR FITNESS FOR PARTICULAR PURPOSE AS ALLOWE
VD
XIN SECTION 2-316 OF THE UNIFORM COMMERCIAL CODE.  BY USING THIS PROGRAM, THE
XUSER AGREES TO HOLD HARMLESS THE AUTHORS FOR ANY DAMAGES WHATSOEVER INCURRED
V IN
XCONNECTION WITH THIS PROGRAM.
X
X`09Purpose:
X
XThis program is used to trap incoming broadcast messages. Normally, when a
Xbroadcast message is received (such as mail, bitnet messages, PHONE, TALK,
Xetc....) it is blasted all over the screen.  This is rather annoying.  If yo
Vu
Xare in an editor, it often either screws up your program nicely, or it just
Xdisappears altogether. Ctrap provides a good way to trap these incoming
Xbroadcast messages and store them until you are ready for them.
X
X`09Usage:
X
X`09To use this program, execute the ctrap.com file in the following
X`09manner:
X
X`09CTRAP ON `5Bfile`5D`09`09-- turn broadcast trapping on.
X`09CTRAP DUMP `5Bfile`5D`09-- Display the stored messages to the screen.
X`09CTRAP OFF`09`09-- turn broadcast trapping off.
X
X`09Methodology:
X`09
XThis program was meant to be executed through a comfile.  This comfile
Xspawn/nowaits this program.  The program goes through an early initializatio
Vn
Xand then is ready to trap the incoming messages. Once a broadcast message is
Xreceived, it is stored in a circular queue and the message "Msg(s) pending."
V is
Xprinted at row 25 of the terminal.  After a suitable amount of time, the
Xbroadcast messages can then be displayed on the screen by again calling the
Xcomfile (CTRAP DUMP).  The comfile communicates to this program through the
V use
Xof a temporary mailbox.  The mailbox is queued for read during initializatio
Vn.`20
XOnce a read is obtained, it processes the command.  If an invalid command is
Xread, it just goes on it's merry way doing absolutely nothing.  To stop the
Xprogram, a command is issued by the comfile (CTRAP QUIT).
X
XThe program spends most of its time in hibernation.  It only awakes during o
Vne
Xof the following: a) a broadcast message is received. b) a read to the termi
Vnal
Xmailbox is received.This reduces the CPU time used to very little since no C
VPU
Xis used when a process is hibernating.
X
X`09Compilation:
X`09`09Execute the make file that comes with this a la
X`09`09@MAKECTRAP.COM
X`09`09In the absence of this comfile the program may be compiled:
X`09`09cc CTRAP.C
X`09`09cc BRDCST.C
X`09`09cc MBX.C
X`09        cc QUEUE.C
X                cc SEND_MAIL.C
X`09`09link CTRAP,BRDCST,MBX,QUEUE, SEND_MAIL sys$input/opt
X`09`09sys$library:vaxcrtl/share
X                `5EZ
X`09Bugs:
X`09`09
XAs of this writing, there are no known bugs.  There are side effects. `20
X
X(1) While this program is running, a person may not spawn.  This is because
V a
Xspecial mailbox is used to trap the incoming messages.  This is VMS' fault.
V  It
Xis NOT mine, that's just the way it is.  (2) While this program is running,
XHELP does not work properly. Again, this is VMS' fault, not mine.  If you
Xfigure out a way  around it, let me know.
X
X        Bug reports may be sent to:
X`09 castillo@nauvax.ucc.nau.edu (internet) or
X`09 castillo@nauvax (bitnet)
X
X`09New_Features:
X
X        New features to version 2.0:
X
X(1) Quiet mode.  By specifying a file when ctrap is first turned on, CTRAP w
Vill
Xstore incoming messages into the file without any  notification.
X
X(2) File output.  By specifying a file when a ctrap dump command is given, t
Vhe
Xuser can store the messages into the file instead of  having it displayed on
Xscreen.
X
X(3) Mail option.  By defining the logical CTRAP$MAIL to be a filename, the u
Vser
Xhas the ability to communicate with a bitnet SENDer.   If a broadcast messag
Ve
Xis of the form: (node)user - message, and  CTRAP$MAIL is defined, ctrap will
Xsend the file pointed to by  CTRAP$MAIL to user@node using the
XDEFAULT_TRANSPORT_PROTOCOL specified in send_mail.h `5Bcurrently IN%`5D.  Th
Vis
Xenables you to tell the person sending to you that you are busy are not at y
Vour
Xterminal, or whatever.
X
X(4) Number of pending messages added to "Msg(s) pending" signal.
X
X(5) Bug fixed in message lengths.  Messages should now be in their correct
Xlengths instead of taking up 200+ extra spaces every now  and then.
X
X(6) An additional side effect is included in the documentation.
X
X(7) Added documentation included throughout the source code for  clarity. */
X
X#include "ctrap.h"
X
Xint main(int argc,char *argv`5B`5D)
X`7B
X    int pbid;`09`09`09/* pasteboard id */
X
X    if (argc == 2)
X    `7B
X`09t_file = 1;
X`09t_name = argv`5B1`5D;
X    `7D
X
X    initialize_mbx();`09`09/* initialize the terminal mailbox */
X    smg$create_pasteboard(&pbid);`09/* create a pasteboard */
X    brdcst_buf = (queue *) malloc(sizeof(queue));
X    setqueue(brdcst_buf);`09/* initialize the queue */
X    setup_broad_hand(pbid);`09/* setup the broadcast AST */
X    sys$hiber();`09`09/* hibernate until something happens */
X    fprintf(stdout,"Something is hosed up real good.\n"); /* never get here
V */
X    sys$exit(1);
X`7D`09`09`09`09/* main */
X
X/* -----------------end of CTRAP module ------------------------------*/
$ CALL UNPACK CTRAP.C;1 1010071780
$ create 'f'
X$! CTRAP.COM - v2.0`09Summer 1992`09The Camelot System
X$!
X$!   `09Last Updated: March 14, 1991
X$!                    July 6, 1992
X$! AUTHOR: Belgarion     (castillo@nauvax.ucc.nau.edu)
X$!         Sir Gareth /`7E (shimniok@tiamat.hacks.arizona.edu)
X$!
X$! This comfile executes the broadcast trapper CTRAP.EXE which is pointed
X$! to by the logical name CTRAP_EXE_FILE.
X$!
X$ CTrapOn = (f$trnlnm("CTRAP_MBX") .nes. "")  ! a boolean flag for later use
X$ if p1 .eqs. ""
X$ then gosub USAGE
X$ else if p1 .eqs. "ON"
X$      then gosub STARTUP
X$      else if p1 .eqs. "DUMP"
X$           then gosub DUMPIT
X$           else if p1 .eqs. "OFF"
X$`09         then gosub SHUTDOWN
X$`09`09 else gosub USAGE
X$`09`09 endif
X$`09    endif
X$      endif
X$ endif
X$ exit 1
X$!
X$ USAGE:
X$   type sys$input:
XCtrap v2.0
XUsage: ctrap `5BON `5Bfile`5D `7C DUMP `5Bfile`5D `7C OFF`5D
X$ return
X$!
X$ STARTUP:
X$   if CTrapOn
X$   then write sys$output "CTrap already enabled."
X$        return
X$   endif
X$   ctrap ="$''f$trnlnm("CTRAP_EXE_FILE")'"
X$   set term/nobroadcast/brdcstmbx
X$   write sys$output "Executing ctrap.  Hit return to get prompt."
X$   spawn/nowait/input=nla0:/proc="CTRAP-''f$getjpi("","proc_index")" -`20
X    ctrap 'p2'
X$ return
X$ DUMPIT:
X$   if .not. CTrapOn
X$   then write sys$output "CTrap not enabled."
X$        return
X$   endif
X$   open/write mmm CTRAP_MBX
X$   write mmm "DUMP ''p2'"
X$   close mmm
X$ return
X$ SHUTDOWN:
X$   if .not. CTrapOn
X$   then write sys$output "CTrap already disabled."
X$        return
X$   endif
X$   open/write mmm CTRAP_MBX
X$   write mmm "QUIT ''p2'"
X$   close mmm
X$   set term/broadcast/nobrdcstmbx
X$ return
$ CALL UNPACK CTRAP.COM;1 1159122774
$ create 'f'
X/* CTRAP v2.0  Summer 1992
X
X   CTRAP.H
X`09-- header file for ctrap.c
X`09AUTHOR: Belgarion (castillo@nauvax.ucc.nau.edu
X`09Last Updated: March 12, 1991
X`09`09      July 2, 1992
X                      July 6, 1992
X*/
X#include <string.h>
X#include <iodef.h>
X#include <ssdef.h>
X#include <stdio.h>
X#include "tools.c"
X
X
X#define LIMIT 1000`09`09/* max number of messages that can be trapped. */
X#define MBXBUFSIZ 512
X#define QUIT_CMD  "QUIT"
X#define START_CMD "START"
X#define DUMP_CMD  "DUMP"
X#define STRLIM `09512`09`09/* max characters per msg */
X
X/* Global structures: */
X
Xtypedef struct
X`7B
X    short int length;`09`09/* Length of string      */
X    char dtype;`09`09`09/* Type 14 is a string   */
X    char class;`09`09`09/* Class 1 is fixed length */
X    char *ptr;`09`09`09/* Pointer to the string */
X`7D msg_type;`09`09`09/* once initialized, this is a fixed */
X/* length string descriptor */
X
Xtypedef struct
X`7B
X    msg_type queuearray`5BLIMIT`5D;
X    int front;
X    int rear;
X    int numitems;
X`7D queue;
X
Xtypedef struct
X`7B
X    short length;`09`09/* descriptor length field */
X    char dtype;`09`09`09/* type field */
X    char class;`09`09`09/* class field */
X    char *ptr;`09`09`09/* pointer to the data */
X`7D mbx_descr;
X
X/* ------------function prototypes :: queue ----------------------------*/
Xvoid setqueue(queue *);
Xint isempty(queue *);
Xint isfull(queue *);
Xvoid push(queue *,msg_type);
Xint pop(queue *,msg_type *);
Xvoid checkqueue(queue *);
Xint nummsgs(queue *);
X/* -------------------function prototypes :: MBX --------------------*/
Xvoid initialize_mbx();
Xvoid mbxast();
Xextern void dump_msgs(char *fname);
Xchar *strextract(char *s, int j, int k);
X/* ----------------------- end prototypes :: BRDCST ------------------*/
Xvoid brd_trap(int);`09`09/* broadcast handler AST */
Xvoid setup_broad_hand(int);
Xvoid handle_msg(queue *,msg_type);`09/* Message handler */
Xvoid notify_user(void);
Xvoid dump_msgs();
Xchar *strtrim(char *);
Xvoid strclr(char *);
X/* prototypes for send_mail module are in send_mail.h!! */
X/* ---------------------global variables ----------------------------*/
Xshort int mbxchan;`09`09/* channel number */
Xchar *mbxbuff;`09`09`09/* mailbox buffer */
Xextern queue *brdcst_buf;
Xint t_file = 0;            /* flag that tells whether ctrap on file was used
V */
Xchar *t_name;              /* the filename to use. */
$ CALL UNPACK CTRAP.H;1 268458841
$ create 'f'
X1 CTRAP
X
X   v2.0
X
X   This program is used to trap incoming broadcast messages.
X   Normally, when a broadcast message is received (such as mail,
X   bitnet messages, PHONE, TALK, etc....) it is blasted all over the
X   screen.  This is rather annoying.  If you are in an editor, it often
X   either screws up your program nicely, or it just disappears`20
X   altogether.  Ctrap provides a good way to trap these incoming broadcast`2
V0
X   messages and store them until you are ready for them.
X
X   Format: CTRAP `5BON `5Bfile`5D `7C DUMP `5Bfile`5D `7C OFF`5D
X
X2 ON
X  `20
X   Turn CTRAP on.  If CTRAP is already on, you will get a message to that
X   effect.  CTRAP.COM will spawn/nowait CTRAP.EXE to perform its routines.
X  `20
X   If a file is specified, CTRAP is in quiet mode.  CTRAP appends all`20
X   broadcast messages to the file specified without notification to the`20
X   user.  If an error occurs, CTRAP will say so.
X
X   Format:
X
X   CTRAP ON `5BFILE`5D
X
X2 OFF
X  `20
X   Turns CTRAP off.  If CTRAP is already off, you will get a message to
X   that effect.  CTRAP.COM will communicate with CTRAP.EXE through a`20
X   mailbox to perform its shutdown routine.
X
X   Format:
X
X   CTRAP OFF
X
X2 DUMP
X
X    Display stored messages to the screen or to a file. `20
X    CTRAP.COM will communicate with CTRAP.EXE through a mailbox to display`2
V0
X    or append any stored broadcast messages to either the  screen or to a
X    file.  Note that CTRAP DUMP file does *not* put ctrap in a quiet mode.
X
X    Format:
X
X    CTRAP DUMP `5Bfile`5D
X
X2 The_C_in_Ctrap
X
X  Contrary to popular belief, the C in ctrap does not mean the C programming
X  language.  It stands for the Camelot System /`7E.  All Camelot System`20
X  utilities begin with C and all Excalibur System utilities (a spinoff of
X  the Camelot System) begin with E.  Just thought I'd clear that up.  Bel.
X
X2 Authors
X
X   Ulysses K. Castillo aka Belgarion */--
X   (castillo@nauvax.ucc.nau.edu)
X            &
X   Michael E. Shimniok aka Sir Gareth /`7E
X   (shimniok@tiamat.hacks.arizona.edu)
X
X   In consultation with:
X      Anthony C. McCracken
X      (acm@nauvax.ucc.nau.edu)
X
X   CTRAP is a Camelot System /`7E utility.
X   Last Update: July 6, 1992 release version 2.0
X
X   Please send any comments, flames, suggestions, snickers bars, or anything
X   about this program or any Camelot System utility to either`20
X   Castillo@nauvax.ucc.nau.edu or Shimniok@tiamat.hacks.arizona.edu. `20
X   For information about the Camelot System /`7E, send mail to either`20
X   Castillo@nauvax.ucc.nau.edu or Shimniok@hacks.arizona.edu.
X
X   Thanks to Kenn Crook (kcrook@ucs.indiana.edu) for the idea to add the
X   mail module.
X
X2  Copyright
X
X`09Notice of Copyright:`20
X    CTRAP is copyright (c) 1991 by Ulysses Castillo
X    (castillo@nauvax.ucc.nau.edu) & Michael E. Shimniok
X    (shimniok@hacks.arizona.edu).  All Rights Reserved.
X
X    CTRAP may be distributed for free only.  CTRAP may only be
X    distributed so long as no modifications are made and this notice of
X    copyright and disclaimer is included.   CTRAP may not be distributed as
V a
X    part of any commercial package without the express written permission of
X    the authors.  The authors reserve the right to distribute cmail for
X    commercial purposes at any time.
X
X2   Disclaimer
X`09
X    CTRAP IS DISTRIBUTED AS IS, WITH ALL FAULTS, AND CONTAINS
X    NO EXPRESSED OR IMPLIED WARRANTIES INCLUDING ANY IMPLIED WARRANTY OF
X    MERCHANTABILITY, USAGE OF TRADE, OR FITNESS FOR PARTICULAR PURPOSE AS
X    ALLOWED IN SECTION 2-316 OF THE UNIFORM COMMERCIAL CODE.  BY USING THIS
X    PROGRAM, THE USER AGREES TO HOLD HARMLESS THE AUTHORS FOR ANY DAMAGES
X    WHATSOEVER INCURRED IN CONNECTION WITH THIS PROGRAM.
X
X2  New_Features
X
X   New features to version 2.0 include:
X
X        (1) Quiet mode.  By specifying a file when ctrap is first turned on,
X        CTRAP will store incoming messages into the file without any`20
X        notification.
X
X        (2) File output.  By specifying a file when a ctrap dump command is
X        given, the user can store the messages into the file instead of`20
X        having it displayed on screen.
X
X        (3) Mail option.  By defining the logical CTRAP$MAIL to be a filenam
Ve,
X        the user has the ability to communicate with a bitnet SENDer. `20
X        If a broadcast message is of the form: (node)user - message, and`20
X        CTRAP$MAIL is defined, ctrap will send the file pointed to by`20
X        CTRAP$MAIL to user@node using the DEFAULT_TRANSPORT_PROTOCOL specifi
Ved
X        in send_mail.h `5Bcurrently IN%`5D.  This enables you to tell the pe
Vrson
X        sending to you that you are busy, are not at your terminal, or whate
Vver.
X
X        (4) Number of pending messages added to "Msg(s) pending" signal.
X
X        (5) Bug fixed in message lengths.  Messages should now be in their
X        correct lengths instead of taking up 200+ extra spaces every now`20
X        and then.
X
X        (6) An additional side effect is included in the documentation.
X
X        (7) Added documentation included throughout the source code for`20
X            clarity.
X
X        There are a couple of other features that are entirely undocumented,
X        and I leave it up to you to find them. *smile*  Belgarion.
X
X2  Bugs
X      `20
X   As of this writing, there are no known bugs.  There are a couple of`20
X   side effects. `20
X
X   (1) While this program is running, a person may not
X   spawn.  This is because a special mailbox is used to trap the
X   incoming messages.  This is VMS' fault.  It is NOT mine, that's
X   just the way it is.`20
X
X   (2) The HELP facility does not work very well.  This is probably
X   because of an error in the HELP and RMS facilities themselves.  I`20
X   haven't really been able to research it, but if you figure it out
X   for sure, let me know!
X
X   Bug reports may be sent to:
X   castillo@nauvax.ucc.nau.edu (internet) or
X   castillo@nauvax (bitnet).
$ CALL UNPACK CTRAP.HLP;1 172101324
$ create 'f'
X$!MAKECTRAP.COM`09`09Spring 1991
X$!Last Update: March 12, 1991
X$!             July 6, 1992 release v2.0
X$!AUTHOR: Belgarion.
X$!
X$!This file compiles & links the required files to make CTRAP.EXE
X$!Also sets the symbol CTRAP to the current path.  You will have to`20
X$!change that if you wish.
X$!All necessary files should be in the SAME directory!
X$!The files are:
X$!`09`09Ctrap.C`09`09-- main module
X$!              CTRAP.H`09`09-- The header file
X$!`09`09BRDCST.C`09-- Broadcast trap module
X$!`09`09QUEUE.C`09`09-- Broadcast trap submodule
X$!`09`09MBX.C`09`09-- Mailbox module
X$!              SEND_MAIL.C     -- module containing everything needed to`20
X$!                                 send mail
X$!              SEND_MAIL.H     -- send_mail header file
X$!              TOOLS.C         -- miscellaneous tools, NOT compiled!
X$!
X$ write sys$output "Here we go...."
X$ write sys$output " "
X$ write sys$output "Compiling Ctrap.C ..."
X$ cc ctrap.c/opt
X$ write sys$output "Compiling Brdcst.C ..."
X$ cc brdcst.c/opt
X$ write sys$output "Compiling MBX.C ..."
X$ cc mbx.c/opt
X$ write sys$output "Compiling Queue.C ..."
X$ cc queue.c/opt
X$ write sys$output "Compiling Send_Mail.C ..."
X$ cc Send_Mail.c/opt
X$ write sys$output "Linking..."
X$ Link Ctrap,brdcst,mbx,queue,send_mail,sys$input/opt
Xsys$library:vaxcrtl/share
X$ write sys$output "Done."
X$write sys$output " "
X$ inquire resp "Delete .obj files?"
X$ if resp .eqs. "Y"
X$ then
X$   delete/noconfirm ctrap.obj.*
X$   delete/noconfirm brdcst.obj.*
X$   delete/noconfirm mbx.obj.*
X$   delete/noconfirm queue.obj.*
X$   delete/noconfirm send_mail.obj.*
X$   write sys$output "Done."
X$ endif
X$type sys$input:
XYou must set the logical CTRAP_EXE_FILE as specified in the documentation.
XThe symbol ctrap is currently defined as:
X$
X$ curdir := 'f$environment("default")
X$ ctrap:=="@''curdir'ctrap.com"
X$ show symbol ctrap
X$write sys$output " "
X$exit
$ CALL UNPACK MAKECTRAP.COM;1 1816883830
$ create 'f'
X/* `09CTRAP v2.0`09`09Summer 1992
X
X`09MODULE NAME: MBX.C
X`09AUTHOR:  Belgarion (castillo@nauvax.ucc.nau.edu)
X`09LAST REVISED: March 12, 1991 release v1.0.1
X`09              July 6, 1992 release v2.0
X
X`09This file is for use with Ctrap.C  It is the module containing all
X`09functions relating to the terminal mailbox.
X
X`09All communication with ctrap is made by a comfile.  The comfile will
X`09write to a mailbox that is asynchronously read by this module.  The
X`09commands written into the mailbox affect ctrap.
X
X`09Current valid commands are:
X`09`09DUMP `5Bfile`5D --  Display the stored broadcast messages to the`20
Xscreen or to <file>.  The actual displaying is handled by the BRDCST module.
X`09        QUIT -- Quit CTRAP.  This disables broadcast trapping and does
Xa mass cleanup using sys$exit().
X
X*/
X
X#include "ctrap.h"
X
X/***************************************************************************
V***
X Function: initialize_mbx()
X
X Description: create mailbox, assign a channel, set up $qio.
X
X Arguments: none
X Return Value: none
X Side Effects: affects some global variables.
X****************************************************************************
V**/
Xvoid initialize_mbx()
X`7B
X    mbx_descr mbxnam;
X    int i = 0;
X
X    mbxnam.dtype = 14;`09`09/* type 14 means character string */
X    mbxnam.class = 2;`09`09/* class 2 means dynamic string   */
X    mbxnam.ptr = malloc(30);`09/* create a 30 byte buffer        */
X    strcpy(mbxnam.ptr,"CTRAP_MBX");`09/* logical name for the mailbox   */
X    mbxnam.length = strlen(mbxnam.ptr);
X    mbxbuff = (char *) malloc(MBXBUFSIZ);
X
X    sys$crembx(0,&mbxchan,256,4096,0,0,&mbxnam);`09/* create a mail box */
X    sys$qio(0,mbxchan,IO$_READVBLK,0,mbxast,0,mbxbuff,256,0,0,0,0);
X`7D`09`09`09`09/* initialize_mbx */
X
X/***************************************************************************
V***
X Function: mbxast()
X
X Description: called whenever a $qio read is completed.
X
X Arguments: none
X Return Value: none
X Side Effects: calls other functions as needed.
X****************************************************************************
V**/
Xvoid mbxast()
X`7B
X    int i;
X
X
X    if (strncmp(mbxbuff,DUMP_CMD,strlen(DUMP_CMD)) == 0)
X    `7B
X`09if (strlen(strtrim(mbxbuff)) > strlen(DUMP_CMD))`09/* got a file? */
X`09`7B
X`09    char *fname;
X
X`09    fname = (char *) malloc(sizeof(strtrim(mbxbuff)));
X`09    fname = strextract(mbxbuff,strlen(DUMP_CMD),strlen(mbxbuff));
X`09    fprintf(stdout,"\nDumping messages to: %s",fname);
X`09    dump_msgs(fname);
X`09`7D`09`09`09/* if -- got a file */
X`09else
X`09`7B
X`09    fprintf(stdout,"\n Dumping messages to screen:\n");
X`09    dump_msgs("stdout");
X`09`7D`09`09`09/* else -- don't have a file */
X    `7D`09`09`09`09/* if -- dump_cmd */
X
X
X    if (strncmp(mbxbuff,QUIT_CMD,strlen(QUIT_CMD)) == 0)
X    `7B
X`09if (strlen(strtrim(mbxbuff)) > strlen(QUIT_CMD))`09/* got a file? */
X`09`7B
X`09    char *fname;
X
X`09    fname = (char *) malloc(sizeof(strtrim(mbxbuff)));
X`09    fname = strextract(mbxbuff,strlen(QUIT_CMD),strlen(mbxbuff));
X`09    fprintf(stdout,"\nDumping messages to: %s",fname);
X`09    dump_msgs(fname);
X`09`7D`09`09`09/* if -- got a file */
X`09else
X`09`7B
X`09    fprintf(stdout,"\n Dumping messages to screen:\n");
X`09    dump_msgs("stdout");
X`09`7D`09`09`09/* else -- dont have a file */
X`09sys$dassgn(mbxchan);
X`09sys$exit(1);
X    `7D`09`09`09`09/* if -- quit_cmd */
X
X    for (i = 0; i < 256; i++)
X`09mbxbuff`5Bi`5D = 0;`09`09/* zero out the buffer */
X    sys$qio(0,mbxchan,IO$_READVBLK,0,mbxast,0,mbxbuff,256,0,0,0,0);
X    /* re-arm the AST */
X`7D`09`09`09`09/* mbxast */
X
X/* ---------------------------end module MBX -----------------------------*/
$ CALL UNPACK MBX.C;1 1046889769
$ create 'f'
X/* CTRAP v2.0`09`09`09Summer 1992
X
X`09MODULE NAME: Queue.C
X`09AUTHOR:  Belgarion  (castillo@nauvax.ucc.nau.edu)
X`09LAST REVISED: March 3, 1991
X                      July 6, 1992 release v2.0
X
XThis contains all the functions that implement the circular queue ADT.  The`
V20
Xbroadcast messages are contained in a fixed length (array) circular queue`20
Xknown as  brdcst_buf.  The individual messages are of msg_type, which is a`2
V0
Xfixed length string descriptor.
X
X*/
X
X#include "ctrap.h"
X
X/* ---------------queue manipulation functions------------------------- */
X
X/***************************************************************************
V***
X Function: setqueue()
X
X Description: setqueue sets front pointer to the top (0), the rear as the`20
Xbottom (LIMIT -1), and numitems as 0.  The queue is thus circular.
X
X Arguments: queue *q
X Return Value:`20
X Side Effects:`20
X****************************************************************************
V**/
Xvoid setqueue(queue *q)
X`7B
X    q->numitems = 0;
X    q->front = 1;
X    q->rear = LIMIT - 1;
X`7D`09`09`09`09/* setqueue */
X
X
X/***************************************************************************
V***
X Function: isempty()
X
X Description: tests to see if the queue is empty.  Empty is defined as`20
X numitems = 0.
X
X Arguments: queue *q
X Return Value: 1 if true, 0 otherwise.
X Side Effects: none
X****************************************************************************
V**/
Xint isempty(queue *q)
X`7B
X    return (q->numitems == 0);
X`7D`09`09`09`09/* isempty */
X
X
X/***************************************************************************
V***
X Function: isfull(queue *q)
X
X Description: test to see if the queue is full.  Full is defined as the`20
X start pointer == the rear pointer.
X
X Arguments: queue *q
X Return Value: 1 if true, 0 otherwise.
X Side Effects: none
X****************************************************************************
V**/
Xint isfull(queue *q)
X`7B
X    return (q->numitems == LIMIT - 1);
X`7D`09`09`09`09/* isfull */
X
X
X/***************************************************************************
V***
X Function: push ()
X
X Description: push attempts to push msg onto the queue.  When q->rear is`20
X < LIMIT - 1, q->rear is incremented by 1.  when q->rear is equal to LIMIT -
V1,
X q-rear is set to 1.  That is, it makes the queue circular.  Since the array
X rather large, this shouldnt happen too often.
X
X Arguments: queue *q, msg_type m (descriptor)
X Return Value:`20
X Side Effects:`20
X****************************************************************************
V**/
Xvoid push(queue *q,msg_type m)
X`7B
X    msg_type temp;
X
X    /* COPY temp to m, then set the pointer to temp.  Without copying
X       first, the pointer will always be at the last msg.
X    */
X    temp.length = m.length;
X    temp.dtype = m.dtype;
X    temp.class = m.class;
X    temp.ptr = (char *) malloc(81);
X    strcpy(temp.ptr,m.ptr);
X    q->rear = (q->rear % (LIMIT - 1)) + 1;`09/* increment rear */
X    q->queuearray`5Bq->rear`5D = temp;
X    q->numitems++;
X`7D`09`09`09`09/* push */
X
X
X/***************************************************************************
V***
X Function: pop ()
X
X Description: pop attempts to remove an item from the queue.  If the queue i
Vs
X   empty pop returns logical FALSE (0).  If it is not empty, pop
X   places the msg pointed to by front into *msg, and returns logical
X   TRUE (1).
X Arguments: queue *q, msg_type m
X Return Value: 0 if empty
X Side Effects: who cares
X****************************************************************************
V**/
Xint pop(queue *q,msg_type *m)
X`7B
X    if (isempty(q))
X`09return 0;
X
X    (*m) = q->queuearray`5Bq->front`5D;
X    q->front = (q->front % (LIMIT - 1)) + 1;
X    q->numitems--;
X    return 1;
X`7D`09`09`09`09/* pop */
X
Xvoid checkqueue(queue *q)
X`7B
X    int i;
X    for (i = 1; i <= q->numitems; i++)
X`09fprintf(stdout,"%d :> %s\n",i,q->queuearray`5Bi`5D.ptr);
X`7D
X
Xint nummsgs(queue *q)
X`7B
X    return q->numitems;
X`7D
X/*---------------end of queue manipulation functions-----------------------*
V/
$ CALL UNPACK QUEUE.C;1 1917826154
$ create 'f'
X/*      CTRAP v2.0              Summer 1992
X
X`09MODULE NAME: Send_mail.c -- Part of CTRAP, adapted from CMAIL.
X`09HEADER:      send_mail.h
X`09SUBMODULES:  tools.c -- included in send_mail.h
X`09SHAREABLE IMAGE: vaxcrtl/share
X`09AUTHOR:  Belgarion (castillo@nauvax.ucc.nau.edu)
X`09LAST REVISED: October 23, 1991
X`09`09      July 6, 1992, incorporated into CTRAP from CMAIL.
X
X`09Purpose: Send_Mail contains all the material necessary to send
X`09`09 mail to another user on a VAX/VMS system.
X
X`09Methodology: Uses MAIL$ routines to send mail.
X*/
X
X#include "send_mail.h"
X
X/***************************************************************************
V***
X Function: handle_mail()
X
X Description: Check to see if the incoming broadcast message is a SEND, if
X so, check to see if the logical CTRAP$MAIL exists, and if so, set things
X up to send off mail to the sender of the broadcast message.
X
X Arguments: msg_type msg -- contains the message in descriptor format
X Return Value: returns nothing.
X Side Effects: sends mail off under certain conditions, does not affect
X any other aspect of CTRAP.  Note that it only detects messages from users
X on another node, it CANNOT detect a send message from a user on the current
X node.  I don't feel like trying to figure out how to handle that.  Also not
Ve
X that it decides that a message is a SEND message if the format of the
X msg is of (blah)blah - blah.  So if a broadcast message comes in under
X that format and is not really a send message, then it's going to try to
X send mail off anyway. Oh well, live with it. /smile
X****************************************************************************
V**/
Xvoid handle_mail(msg_type msg)
X`7B
X    send_blk send_info;
X    char *tmp;
X    int t;
X
X    tmp = (char *) malloc(strlen(msg.ptr));
X    strclr(tmp);
X    tmp = strextract(msg.ptr,1,1);
X    send_info.file = (char *) malloc(255);
X    send_info.foreign = 0;
X
X    if ((strcmp("(",tmp) == 0) && (strclocate(msg.ptr,')') != strlen(msg.ptr
V))
X`09&& (strclocate(msg.ptr,'-') != strlen(msg.ptr)) &&
X`09(translate_lognam("CTRAP$MAIL","LNM$PROCESS",send_info.file) != -1))
X    `7B
X`09/* send message from another node */
X
X`09send_info.to = (char *) malloc(strlen(msg.ptr));
X`09send_info.subject = (char *) malloc(strlen(CTRAP_SUBJECT_LINE));
X`09strclr(send_info.to);
X`09strclr(send_info.subject);
X
X`09/* SEND messages are of the format: */
X`09/*        (NODE)USER - message      */
X`09/* Converting to:                   */
X`09/*      USER@NODE                   */
X`09/* -------------------------------- */
X`09strcat(send_info.to,strextract(msg.ptr,strclocate(msg.ptr,')') + 1,
X`09`09`09`09       strclocate(msg.ptr,' ')-1));
X`09strcat(send_info.to,"@");
X`09strcat(send_info.to,strextract(msg.ptr,strclocate(msg.ptr,'(')+1,
X`09`09`09`09       strclocate(msg.ptr,')')-1));
X`09strcat(send_info.subject,CTRAP_SUBJECT_LINE);
X`09if (send_mail(send_info) == -1)
X`09`09fprintf(stdout,"`1B7`1B`5B25;20HCtrap: Error sending mail.`1B8");
X    `7D`09`09`09`09/* if send message from another node */
X    else
X`09return;
X`7D`09`09`09`09/* handle_mail */
X
X
X/***************************************************************************
V***
X Function: send_mail()
X
X Description: Sends the file in info.file to the user in info.to
X`09`09`09  using the subject specified in info.subject.  Uses lots of
X`09`09`09  MAIL$ routines.
X Arguments: send_blk info
X Return Value: -1 if something goes wrong.
X Side Effects: who knows
X****************************************************************************
V**/
Xint send_mail(send_blk info)
X`7B
X    char username`5B255`5D,notify`5B10`5D;
X    mail_item_list in_list;
X    int status;
X    descr file_dsc;
X
X    /* initialize the send mail context */
X    user_context = 0;
X    /* initialize the null list */
X    set_null_list(&null_list);
X    status = mail$send_begin(&user_context,&null_list,&null_list);
X    if (status != SS$_NORMAL)
X`09return -1;`09
X
X    /* get username of sender */
X    get_from_username(username);
X
X
X    /*  determine if the TO is an internet address, if so, add the DEFAULT
X`09TRANSPORT to the attributes using the constant
X`09DEFAULT_INTERNET_TRANSPORT found in send_mail.h.
X     */
X    info.to = check_address(info.to);
X
X    /*  fill the TO line */
X    fill_list(MAIL$_SEND_TO_LINE,info.to,&in_list);
X    status = mail$send_add_attribute(&user_context,&in_list,&null_list);
X    if (status != SS$_NORMAL)
X`09return -1;
X
X    /*  fill the FROM line */
X    fill_list(MAIL$_SEND_FROM_LINE,username,&in_list);
X    status = mail$send_add_attribute(&user_context,&in_list,&null_list);
X    if (status != SS$_NORMAL)
X`09return -1;
X
X
X    /*  fill the SUBJECT line */
X    fill_list(MAIL$_SEND_SUBJECT,info.subject,&in_list);
X    status = mail$send_add_attribute(&user_context,&in_list,&null_list);
X    if (status != SS$_NORMAL)
X`09return -1;
X
X    /*  Define the sendee */
X    fill_list(MAIL$_SEND_USERNAME,info.to,&in_list);
X    status = mail$send_add_address(&user_context,&in_list,&null_list);
X    if (status != SS$_NORMAL)
X`09return -1;
X
X/*     ---- DO *NOT* uncomment this area unless you know precisely what
X            you are doing!!! `5B-- castillo@nauvax.ucc.nau.edu`5D
X
X    if (info.foreign)
X    `7B
X`09fill_list(MAIL$_SEND_FOREIGN,info.file,&in_list);
X`09status = mail$send_add_attribute(&user_context,&in_list,&null_list);
X    `7D
X
X      Send each record of the file info.file
X    if (!info.foreign)
X    `7B
X`09char sig_file`5B255`5D;
XYES, the comment ends below.
X
X*/
X`09if (send_add_file(info.file) == -1)
X`09`09return -1;
X/*
XYES, commenting starts again.
X
X`09if (translate_lognam("CMAIL$SIGNATURE","LNM$PROCESS",sig_file) != -1)
X`09`7B
X`09    int c;
X`09    fprintf(stdout,"Append %s to message? ",sig_file);
X`09    c = getc(stdin);
X`09    if (toupper(c) == 'Y')
X`09    `7B
X`09`09send_add_file(sig_file);
X`09    `7D`09`09
X
X`09`7D`09`09
X
X    `7D`09`09`09`09
X
XYes, commenting ends again.
X*/
X    /*  Send the mail message, end send context */
X    if (translate_lognam("CTRAP$NOTIFY","LNM$PROCESS",notify) != -1)
X`09fprintf(stdout,"`1B7`1B`5B25;20HSending %s to %s`1B8",info.file,info.to);
X    status = mail$send_message(&user_context,&null_list,&null_list);
X    if (status != SS$_NORMAL)
X`09return -1;
X    else if (strcmp(info.file,"SYS$LOGIN:CMAIL$TEMP.TMP") == 0)
X    `7B
X`09strcat(info.file,";*");
X`09build_descr(&file_dsc,info.file);
X`09lib$delete_file(&file_dsc);
X    `7D`09`09`09`09/* else if */
X    status = mail$send_end(&user_context,&null_list,&null_list);
X    if (status != SS$_NORMAL)
X`09return -1;
X`7D`09`09`09`09/* send_mail */
X
X
X
X/***************************************************************************
V***
X Function: get_from_username()
X Description:  Get's the username of the sender using $getjpi system service
V.
X
X Arguments: char *username
X Return Value: none
X Side Effects: none
X****************************************************************************
V**/
Xvoid get_from_username(char *username)
X`7B
X    item_list_3 list;
X    int status;
X
X    list.buffer_length = 10;
X    list.item_code = JPI$_USERNAME;
X    list.buffer_address = username;
X    list.return_length_address = 0;
X    list.end = 0;`09`09/* list will contain sender's username */
X    status = sys$getjpi(0,0,0,&list,0,0,0);
X`7D`09`09`09`09/* get_from_username */
X
X
X/***************************************************************************
V***
X Function: set_null_list()
X
X Description: Fill the null_list with all 0s.  Null_list is used to
X indicate an empty list to a mail$ function.
X Arguments: mail_item_list *list -- the list to be set to null.
X
X Return Value: none
X Side Effects: none
X****************************************************************************
V**/
Xvoid set_null_list(mail_item_list *list)
X`7B
X    (*list).buffer_length = 0;
X    (*list).item_code = 0;
X    (*list).buffer_address = 0;
X    (*list).return_length_address = 0;
X    (*list).terminate = 0;
X`7D`09`09`09`09/* set_null_list */
X
X
X/***************************************************************************
V***
X Function: fill_list()
X
X Description: fill the item list with a mail code, and the buffer.
X Arguments: int code, char *buffer, mail_item_list *list;
X
X Return Value: none
X Side Effects: none
X****************************************************************************
V**/
Xvoid fill_list(int code,char *buffer,mail_item_list *list)
X`7B
X    list->buffer_length = strlen(buffer);
X    list->item_code = code;
X    list->buffer_address = buffer;
X    list->return_length_address = 0;
X    list->terminate = 0;
X`7D`09`09`09`09/* fill_list */
X
X
X/***************************************************************************
V***
X Function: send_add_file()
X
X Description: Reads each record of the file *file, and sends it to
X mail$send_add_bodypart;
X Arguments: char *file -- the filename of the file to mail.
X
X Return Value: -1 if something goes wrong.
X Side Effects: none
X****************************************************************************
V**/
Xint send_add_file(char *file)
X`7B
X    FILE *fp;
X    const int MAX_LINE_LENGTH = 1024;
X    char *aline;
X    int status;
X    mail_item_list list;
X
X    aline = (char *) malloc(MAX_LINE_LENGTH);
X    if ((fp = fopen(file,"r")) == NULL)
X        return -1;
X
X    while ((!feof(fp)) && (fgets(aline,MAX_LINE_LENGTH - 1,fp)))
X    `7B
X`09aline`5Bstrlen(aline) - 1`5D = '\0';
X`09fill_list(MAIL$_SEND_RECORD,aline,&list);
X`09status = mail$send_add_bodypart(&user_context,&list,&null_list);
X    `7D`09`09`09`09/* while */
X`7D`09`09`09`09/* send_add_file */
X
X/***************************************************************************
V***
X Function: check_address()
X Description: checks to see if the address given is an internet address.
X If so, prepend the string with the constant DEFAULT_INTERNET_ADDRESS found
X in send_mail.h  (This may need to be modified for your system!)
X Arguments: char *to_string   (info.to)
X
X Return Value: char * -- if the to is an internet address, the internet
X address is returned with the DEFAULT_INTERNET_ADDRESS prepended.  If the
X to is not an internet address, return to_string.
X Side Effects: None.
X****************************************************************************
V**/
Xchar *check_address(char *to_string)
X`7B
X    mail_item_list list;
X    char *addr;
X    char *quote = "\"";`09`09/* must use escape sequence to use a quote with
Vin
X`09`09`09`09`09`09`09   a quoted string. */
X
X    if (strclocate(to_string,'@') != strlen(to_string))
X    `7B
X`09/* we have an inet addr */
X`09addr = (char *) malloc(355);
X`09strclr(addr);
X`09strcat(addr,DEFAULT_INTERNET_TRANSPORT);
X`09strcat(addr,quote);
X`09strcat(addr,to_string);
X`09strcat(addr,quote);
X`09return addr;
X    `7D`09`09`09`09/* if @ */
X    /* otherwise just return what we've been given. */
X    return to_string;
X`7D`09`09`09`09/* check_address */
$ CALL UNPACK SEND_MAIL.C;1 925342374
$ create 'f'
X#include <maildef.h>
X#include <jpidef.h>
X#include <stdio.h>
X#include <ssdef.h>
X#include <rmsdef.h>
X#include "ctrap.h"
X
X#define CTRAP_SUBJECT_LINE "CTRAP automatic response."
X
Xtypedef struct
X`7B
X    char *to;
X    char *subject;
X    char *file;
X    int foreign;
X`7D send_blk;
X
X
Xtypedef struct
X`7B
X    short int buffer_length;
X    short int item_code;
X    long int buffer_address;
X    long int return_length_address;
X    long int terminate;
X`7D mail_item_list;
X
Xtypedef struct
X`7B
X    short int buffer_length;
X    short int item_code;
X    long int buffer_address;
X    long int return_length_address;
X    short int buffer_length_null;
X    short int item_code_null;
X    long int buffer_address_null;
X    long int return_length_address_null;
X`7D mail_item_list_n_null;
X
X
Xtypedef struct
X`7B`09`09`09`09/* item_list_3 */
X    short int buffer_length;
X    short int item_code;
X    int buffer_address;
+-+-+-+-+-+-+-+-  END  OF PART 1 +-+-+-+-+-+-+-+-

