From:	CRDGW2::CRDGW2::MRGATE::"SMTP::CRVAX.SRI.COM::RELAY-INFO-VAX" 14-APR-1991 20:26:11.64
To:	ARISIA::EVERHART
CC:	
Subj:	BITNET Mail

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

Received:  by crdgw1.ge.com (5.57/GE 1.97)
	 id AA25244; Sun, 14 Apr 91 19:52:09 EDT
Received: From UCBVAX.BERKELEY.EDU by CRVAX.SRI.COM with TCP; Sun, 14 APR 91 13:39:11 PST
Received: by ucbvax.Berkeley.EDU (5.63/1.42)
	id AA27580; Sun, 14 Apr 91 13:35:46 -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: 12 Apr 91 03:01:24 GMT
From: ucrmath!watnxt1!duchow@ucsd.edu  (John Duchowski)
Organization: University of California, Riverside
Subject: BITNET Mail
Message-Id: <13542@ucrmath.ucr.edu>
Sender: info-vax-request@kl.sri.com
To: info-vax@kl.sri.com

Hello Everyone !

     First of all, many, many thanks to all of you who responded to my
BITNET Mail message.  I have received many valuable suggestions and have
learned a great deal.  Most of the suggestions concerned setting broadcast
in such a way to to prevent messages coming fro this or that process.  In
general, to stop the "progress massages" from Mail, Send, etc., one needs
to:
     SET BROADCAST=NOUSER1
     SET BROADCAST=NOUSER2
     SET BROADCAST=NOUSER3

However, that essentially leaves you "deaf" even to the messages you might
want to hear.  An original and very useful solution was provided by:
"Belgarion (Ulysses): Show Me the Way." <CASTILLO@nauvax.ucc.nau.edu>.
I thought that this was probably the best way to do it, especially that
it provides you with the opportinity to eat the pie and keep it too :-).

> [parts of the original message deleted]
>
> I am sending you CTRAP.  It traps broadcast messages so you can 
> look at them later....  Extract this message, cut where it says
> CUT HERE, and then @filename.  this will explode the ctrap files.
> then @makectrap to make it.  There is a .hlp file.

> you will also need this logical in your login.com ::

> $ DEFINE CTRAP_EXE_FILE DISK:[DIR.PATH]CTRAP.EXE

> (where disk,dir, and path are your disk dir and path of course)

 +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+   
||   -  Belgarion -                       The Dawn Knows No Reprieve        ||
||(aka Ulysses Kevin Castillo)           ----------------------------       || 
||  castillo@nauvax.ucc.nau.edu          belgarion@hacks.arizona.edu        ||
||  ukc@mvaxcs1.cse.nau.edu              ukc@gnu.ai.mit.edu                 ||  
||                ----------------------------------                        ||
||     --&&--        In endless search for quota       --&&--               ||
 =--=--=--=--=--=--=--=--=--=--=--=--=--=--=--=--=--=--=--=--=--=--=--=--=--

$! ------------------ CUT HERE -----------------------
$ v='f$verify(f$trnlnm("SHARE_VERIFY"))'
$!
$! This archive created by VMS_SHARE Version 7.2-007  22-FEB-1990
$!   On  5-APR-1991 14:23:33.92   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
$!
$! 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. OPTIONS.C;1
$!       9. QUEUE.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/* `09Brdcst.C v1.02`09`09Spring 1991
X
X`09MODULE NAME: Brdcst.C
X`09AUTHOR:  Belgarion (castillo@nauvax.ucc.nau.edu)
X`09LAST REVISED: March 11, 1991
X`09
X
X   `09This file is for use with Ctrap.C  It is the module containing all
X   `09functions relating to broadcast trapping.
X
X   `09The buffer containing the broadcast messages is implemented as a`20
X`09circular queue ADT.  The usable functions to manipulate
X `09brdcast_buf (the queue) are: push, pop, setqueue.  When the`09number`20
X`09of broadcast messages received becomes larger than the LIMIT, older`20
X`09messages are overwritten by the newer ones instead of just`20
X`09floating off into limbo.
X
X*/
X
X#include "ctrap.h"
X
X/*----------------broadcast handling module-----------------------------*/
X
Xvoid setup_broad_hand(int pbid)
X  `09/* Enable the trapping of broadcast messages that would otherwise   `20
X       screw up the screen.     `20
X       pbid is the pasteboard id, brdtrap is the AST function called`20
X       when a broadcast message is received.  The last pbid is the`20
X       argument passed to brdtrap.
X  `09*/
X`7B
X  `09smg$set_broadcast_trapping(&pbid,brd_trap, pbid);
X`09fprintf(stdout, "Broadcast trapping enabled.\n");
X`7D/* setup_broad_hand */
X
X
Xvoid brd_trap(int pbid)
X  `09/* This AST routine is called whenever a broadcast message comes to the
V`20
X       terminal. E.G. newmail, phone calls, bitnet noise and operators that`
V20
X       want to get your attention. The broadcast message(s) are retrieved  `
V20
X       and then displayed according to the flags that have been sent.
X  `09*/
X`7B
X   short int msgl;
X   int status;
X   msg_type msg;
X   msg.length = STRLIM;                   /* build a string descriptor for
V  */
X   msg.dtype = 14;                    /* the broadcast message          */
X   msg.class = 1;
X   msg.ptr = (char *) malloc(STRLIM);
X   status = 1;                        /* get and display the message(s) */
X   while (status == 1) `7B
X      status = smg$get_broadcast_message(&pbid,&msg,&msgl);
X      if (status == 1)`20
X`09`09handle_msg(brdcst_buf, msg);
X   `7D /* while */
X   free(msg.ptr);
X`7D /* brd_trap */
X
X
Xvoid handle_msg(queue *q, msg_type msg)
X`09/* handle_msg is the main message handler.  It uses the various
X`09   flags to decide what to do with the message.  In this early stage,
X`09   flags are not worried about at all.
X`09*/
X`7B`09  `20
X`09msg.ptr = strtrim(msg.ptr);
X`09push(q, msg);
X`09notify_user();
X`7D /* handle_msg */
X
X
Xvoid notify_user(void)
X`09/* notify_user places the message Msgs(s) pending on the bottom
X`09   of their screen.
X`09*/
X`7B
X`09fprintf(stdout,"`1B7`1B`5B25;0H`1B`5B1m`1B`5B5mMsgs(s) pending.`1B`5B0m`1
VB8");
X`7D /* notify_user */
X
Xvoid dump_msgs()
X`09/* this dumps the messages contained in the queue to the screen.
X`09*/
X`7B
X`09msg_type msg;
X
X`09while (pop(brdcst_buf, &msg)) `7B
X`09`09fprintf(stdout, "%s\n",msg.ptr);
X`09`7D /* while */
X`09fprintf(stdout,"\nNo more messages.\n");
X`09fprintf(stdout,"`1B7`1B`5B25;0H                `1B8");
X`7D /* dump_msgs */
X`09
Xchar *strtrim(char *s)
X`7B
X  int i=0;
X
X  while (s`5Bi`5D != 0) ++i;
X  if (i == 0)
X    return s;
X  --i;
X  while (s`5Bi`5D == '\n' `7C`7C s`5Bi`5D == ' ' `7C`7C s`5Bi`5D == '\t') --
Vi;
X  s`5B++i`5D = 0;
X
X  return s; `20
X`7D /* strtrim */
X
X   /* --------------- end of broadcast module ----------------------*/
$ CALL UNPACK BRDCST.C;1 1782911098
$ create 'f'
X/* `09CTrap.C v1.02`09`09Spring 1991
X
X`09MODULE NAME:  CTRAP.C`09the main module :)
X`09HEADER:       CTRAP.H
X`09SUBMODULES:   BRDCST.C
X                  QUEUE.C
X                  MBX.C
X`09SHAREABLE IMAGE: SYS$LIBRARY:VAXCRTL/SHARE
X
X`09AUTHOR:  Belgarion (castillo@nauvax.ucc.nau.edu)
X`09LAST REVISED: March 12, 1991
X
X`09Inspired by, and in consultation with`20
X`09`09Tony McCracken (ACM@nauvax.ucc.nau.edu)  &
X`09`09Sir Gareth /`7E  (mshimniok@xray1.chem.arizona.edu)
X`09
X`09Notice of Copyright:
X`09`09
X`09This program is Copyright(c) 1991 by Ulysses Castillo,`20
X`09Tony McCracken, and Michael E. Shimniok.  All rights reserved.
X`09This program may be copied as long as this notice of copyright and
X`09disclaimer is included.  If this program is posted in any form to`20
X`09any public forum, it must contain this notice of copyright,`20
X`09disclaimer, and all required files.
X
X`09Disclaimer:
X`09
X`09This program was tested on a VAX 3610 running VMS 5.3-1.  I
X`09do not make any claim that this program will work as stated.
X`09I don't guarantee that this program won't crash your VAX.
X`09All use is at the complete risk of the user.
X
X`09Purpose:
X
X`09This program is used to trap incoming broadcast messages.
X`09Normally, when a broadcast message is received (such as mail,
X`09bitnet messages, PHONE, TALK, etc....) it is blasted all over the
X`09screen.  This is rather annoying.  If you are in an editor, it often
X`09either screws up your program nicely, or it just disappears altogether.
X`09Ctrap provides a good way to trap these incoming broadcast messages and
X`09store them until you are ready for them.
X
X`09Usage:
X
X`09To use this program, execute the ctrap.com file in the following`20
X`09manner:
X
X`09CTRAP ON`09`09-- turn broadcast trapping on.
X`09CTRAP DUMP`09`09-- Display the stored messages to the screen.
X`09CTRAP OFF`09`09-- turn broadcast trapping off.
X
X`09Methodology:
X`09
X`09This program was meant to be executed through a comfile.  This comfile
X`09spawn/nowaits this program.  The program goes through an early`20
X`09initialization and then is ready to trap the incoming messages.
X`09Once a broadcast message is received, it is stored in a circular`20
X`09queue and the message "Msg(s) pending." is printed at row 25 of
X`09the terminal.  After a suitable amount of time, the broadcast`20
X`09messages can then be displayed on the screen by again calling the
X`09comfile (CTRAP DUMP).  The comfile communicates to this program`20
X`09through the use of a temporary mailbox.  The mailbox is queued
X`09for read during initialization.  Once a read is obtained, it`20
X`09processes the command.  If an invalid command is read, it just
X`09goes on it's merry way doing absolutely nothing.  To stop the program,
X`09a command is issued by the comfile (CTRAP QUIT).
X
X`09The program spends most of its time in hibernation.  It only`20
X`09awakes during one of the following:
X`09`09a) a broadcast message is received.
X`09`09b) a read to the terminal mailbox is received.
X
X`09This reduces the CPU time used to very little since no CPU is used
X`09when a process is hibernating.
X
X`09Compilation:
X`09`09Execute the make file that comes with this a la`20
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`09`09link CTRAP,BRDCST,MBX,QUEUE, sys$input/opt
X`09`09sys4library:vaxcrtl/share
X
X`09Future Expansions:
X
X`09Expansions immediately in the future will be:
X
X`09-r<input file> `09--- replace.`20
X`09`09an input file will be read on initialization.  The input file
X`09`09will be of the form:
X`09`09`09NAME = EQUIVALENT.
X
X`09`09The result: when a broadcast message is received, the input file
X`09`09will be searched.  If the text of the broadcast message matches
X`09`09any NAME entry, the text of the broadcast message will be altered
X`09`09to replace NAME with equivalent.  The result is something like:
X`09`09
X`09`09original:
X`09`09`09S1606266 is phoning you.
X
X`09`09with -r:
X`09`09`09Mike is phoning you.
X
X`09`09-x<input file name> --- exclusive.
X
X`09`09This switch will read an input file of the same format as above.
X`09`09When a broadcast message is received, the file is checked for`20
X`09`09matches.  If a match occurs, the broadcast message is displayed.
X`09`09Otherwise, the broadcast message is stored in the queue with the
X`09`09other broadcast messages.  This results in a selective display
X`09`09of messages (much like call screening on an answering machine).`20
X`09
X`09`09Bugs:
X`09`09
X`09`09As of this writing, there are no known bugs.  There is one`20
X`09`09side effect.  While this program is running, a person may not
X`09`09spawn.  This is because a special mailbox is used to trap the
X`09`09incoming messages.  This is VMS' fault.  It is NOT mine, that's
X`09`09just the way it is.  Bug reports may be sent to:
X`09`09castillo@nauvax.ucc.nau.edu (internet) or
X`09`09castillo@nauvax (bitnet)
X
X`09
X*/
X
X#include "ctrap.h"
X
Xint main(int argc, char *argv`5B`5D)
X`7B
X`09int pbid; `09`09`09`09/* pasteboard id */
X
X`09initialize_mbx(); `09`09      /* initialize the terminal mailbox */
X`09smg$create_pasteboard(&pbid); /* create a pasteboard */
X    brdcst_buf = (queue *)malloc(sizeof(queue));
X    setqueue(brdcst_buf);`09`09  /* initialize the queue */
X`09setup_broad_hand(pbid);`09`09  /* setup the broadcast AST */
X`09sys$hiber();`09`09`09`09  /* hibernate until something happens */
X`09fprintf(stdout, "Something is hosed up real good.\n");
X`09sys$exit(1);
X`7D /* main */
X
X/* -----------------end of CTRAP module ------------------------------*/
$ CALL UNPACK CTRAP.C;1 1411669189
$ create 'f'
X$! CTRAP.COM - V1.02`09Spring 1991`09The Camelot System
X$!
X$!   `09Last Updated: March 14, 1991
X$!
X$! AUTHOR: Belgarion     (castillo@nauvax.ucc.nau.edu)
X$!         Sir Gareth /`7E (mshimniok@xray.chem.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 v1.02
XUsage: ctrap `5BON`7COFF`7CDUMP`5D
X$ return
X$!
X$ STARTUP:
X$   if CTrapOn
X$   then write sys$output "CTrap already enabled."
X$        return
X$   endif
X$   set term/nobroadcast/brdcstmbx
X$   write sys$output "Executing ctrap.  Hit return to get prompt."
X$   spawn/nowait/input=nla0:/proc="Camelot-CTRAP" -`20
X    run CTRAP_EXE_FILE
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"
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"
X$   close mmm
X$   set term/broadcast/nobrdcstmbx
X$ return
$ CALL UNPACK CTRAP.COM;1 740890647
$ create 'f'
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*/
X#include <string.h>
X#include <iodef.h>
X#include <ssdef.h>
X#include <stdio.h>
X
X#define LIMIT 1000  /* 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 /* max characters per msg */
X
X/* Global structures: */
X
Xtypedef struct `7B
X           short int length;              /* Length of string      */
X           char      dtype;               /* Type 14 is a string   */
X           char      class;               /* Class 1 is fixed length */
X           char      *ptr;                /* Pointer to the string */
X        `7D msg_type;           /* once initialized, this is a fixed */
X                                 /* length string descriptor */
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 `7B
X   short length;                   /* descriptor length field */
X   char  dtype;                    /* type field */
X   char  class;                    /* class field */
X   char  *ptr;                     /* 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 *);
X/* -------------------function prototypes :: MBX --------------------*/
Xvoid initialize_mbx();
Xvoid mbxast();
Xextern void dump_msgs();
X/* ----------------------- end prototypes :: BRDCST ------------------*/
Xvoid brd_trap(int);                          /* broadcast handler AST */
Xvoid setup_broad_hand(int);`20
Xvoid handle_msg(queue *, msg_type);                /* Message handler */
Xvoid notify_user(void);
Xvoid dump_msgs();
Xchar *strtrim(char *);
X
X/* ---------------------global variables ----------------------------*/
X   short int mbxchan;  `09/* channel number */
X   char *mbxbuff;   /* mailbox buffer */`20
X   extern queue *brdcst_buf;
X
$ CALL UNPACK CTRAP.H;1 1685339840
$ create 'f'
X1 CTRAP
X
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`7COFF`7CDUMP`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
X   Format:
X
X   CTRAP ON
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.  CTRAP.COM will communicate
X    with CTRAP.EXE through a mailbox to display any stored broadcast
X    messages to the screen.
X
X   Format:
X
X   CTRAP DUMP
X
X2 Author
X
X   Ulysses K. Castillo aka Belgarion
X   (castillo@nauvax.ucc.nau.edu)
X
X   In consultation with:
X
X   Michael E. Shimniok aka Sir Gareth /`7E
X   (mshimniok@xray.chem.arizona.edu)
X              &
X   Anthony C. McCracken
X   (acm@nauvax.ucc.nau.edu)
X
X   for the Camelot System.
X
X   Last Update: March 12, 1991
X
X2  Copyright
X
X   Notice of Copyright:
X      `20
X   This program is Copyright(c) 1991 by Ulysses Castillo,`20
X   Tony McCracken, and Michael E. Shimniok.  All rights reserved.
X   This program may be copied as long as this notice of copyright and
X   disclaimer is included.  If this program is posted in any form to`20
X   any public forum, it must contain this notice of copyright,`20
X   disclaimer, and all required files.
X
X   Disclaimer:
X  `20
X   The author assumes no liability for any damage caused by`20
X   the use of this program.
X   Use of this program is at the sole risk of the user.
X
X2   Methodology
X
X   This program was meant to be executed through a comfile.  This`20
X   spawn/nowaits this program.  The program goes through an early`20
X   initialization and then is ready to trap the incoming messages.
X   Once a broadcast message is received, it is stored in a circular`20
X   queue and the message "Msg(s) pending." is printed at row 25 of
X   the terminal.  After a suitable amount of time, the broadcast`20
X   messages can then be displayed on the screen by again calling the
X   comfile (CTRAP DUMP).  The comfile communicates to this program`20
X   through the use of a temporary mailbox.  The mailbox is queued
X   for read during initialization.  Once a read is obtained, it`20
X   processes the command.  If an invalid command is read, it just
X   goes on it's merry way doing absolutely nothing.  To stop the`20
X   program a command is issued by the comfile (CTRAP OFF).
X
X   The program spends most of its time in hibernation.  It only`20
X   awakes during one of the following:
X       a) a broadcast message is received.
X       b) a read to the terminal mailbox is received.
X
X   This reduces the CPU time used to very little since no CPU is used
X   when a process is hibernating.
X
X
X2    Compilation
X
X   Execute the make file that comes with this a la`20
X   @MAKECTRAP.COM
X   In the absence of this comfile the program may be compiled:
X   cc CTRAP.C
X   cc BRDCST.C
X   cc MBX.C
X   cc QUEUE.C
X    link CTRAP,BRDCST,MBX,QUEUE, sys$input/opt
X   sys$library:vaxcrtl/share
X   `5EZ
X
X2    Expansions
X
X   Future expansions include:
X
X   Implementation of the following options:
X
X   REPLACE
X
X   an input file will be read on initialization.  The input file
X   will be of the form:
X   NAME=EQUIVALENT.
X
X   The result: when a broadcast message is received, the input file
X   will be searched.  If the text of the broadcast message matches
X   any NAME entry, the text of the broadcast message will be altered
X   to replace NAME with equivalent.  The result is something like:
X      `20
X   original:
X            S1606266 is phoning you.
X
X   with REPLACE option:
X            Mike is phoning you.
X
X   EXCLUSIVE
X
X   This switch will read an input file of the same format as above.
X   When a broadcast message is received, the file is checked for`20
X   matches.  If a match occurs, the broadcast message is displayed.
X   Otherwise, the broadcast message is stored in the queue with the
X   other broadcast messages.  This results in a selective display
X   of messages (much like call screening on an answering machine).`20
X   There will be an option to either store or display both
X   matched and unmatched broadcast messages.
X
X2  Bugs
X      `20
X   As of this writing, there are no known bugs.  There is one`20
X   side effect.  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.  Bug reports may be sent to:
X   castillo@nauvax.ucc.nau.edu (internet) or
X   castillo@nauvax (bitnet).
$ CALL UNPACK CTRAP.HLP;1 1126630112
$ create 'f'
X$!MAKECTRAP.COM`09`09Spring 1991
X$!Last Update: March 12, 1991
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$!
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 "Linking..."
X$ Link Ctrap,brdcst,mbx,queue,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$   write sys$output "Done."
X$ endif
X$ curdir := 'f$environment("default")
X$ ctrap:=="@''curdir'ctrap.com"
X$exit
$ CALL UNPACK MAKECTRAP.COM;1 1042243761
$ create 'f'
X/* `09MBX.C v1.02`09`09Spring 1991
X
X`09MODULE NAME: MBX.C
X`09AUTHOR:  Belgarion (castillo@nauvax.ucc.nau.edu)
X`09LAST REVISED: March 12, 1991
X`09
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. `20
X
X`09Current valid commands are:
X`09`09DUMP`09-- Display the stored broadcast messages to the screen.
X`09`09   `09       The actual displaying is handled by the BRDCST module.
X`09    QUIT`09-- Quit CTRAP.  This disables broadcast trapping and does
X`09`09`09`09   a mass cleanup using sys$exit().
X
X*/
X
X#include "ctrap.h"
X
Xvoid initialize_mbx()
X`7B
X   mbx_descr mbxnam;
X   int i=0;
X
X   mbxnam.dtype = 14;                 /* type 14 means character string */
X   mbxnam.class = 2;                  /* class 2 means dynamic string   */
X   mbxnam.ptr = malloc(30);           /* create a 30 byte buffer        */
X   strcpy(mbxnam.ptr,"CTRAP_MBX");    /* 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);  /* create a mail box */
X   sys$qio(0,mbxchan,IO$_READVBLK,0,mbxast,0,mbxbuff,256,0,0,0,0);
X`7D /* initialize_mbx */
X
Xvoid mbxast()
X`7B
X`09/* this AST is called whenever a read is completed.
X`09   The commands received are then acted upon`20
X`09*/
X `09int i;
X  `20
X`09/* GOD I wish there was a case statment for strings. */
X
X`09if (strcmp(mbxbuff,DUMP_CMD) == 0) `7B
X`09`09fprintf(stdout, "\nDumping messages ::\n");
X`09`09dump_msgs();
X`09`7D
X
X`09if (strcmp(mbxbuff,QUIT_CMD) == 0) `7B
X`09`09fprintf(stdout, "\nDumping messages ::\n");
X`09`09dump_msgs();
X`09`09sys$dassgn(mbxchan);
X`09`09sys$exit(1);
X`09`7D
X   `09for (i=0;i<256;i++)`20
X`09`09mbxbuff`5Bi`5D = 0; /* zero out the buffer */
X   `09sys$qio(0,mbxchan,IO$_READVBLK,0,mbxast,0,mbxbuff,256,0,0,0,0);
X`09/* re-arm the AST */
X`7D /* mbxast */
X
X
X/* ---------------------------end module MBX -----------------------------*/
$ CALL UNPACK MBX.C;1 474162383
$ create 'f'
X/* this file contains functions related to options for ctrap. */
X
X#include <string.h>
Xint replace = 0;
Xint exclusive = 0;
X
X
Xint parseoptions(argc, char *argv`5B`5D);
X`7B
X`09if (strncmp(argv`5B1`5D,"-r",2))
X`09`09replace = 1;
X`09if (strncmp(argv`5B1`5D,"-x",2))
X`09`09exclusive = 1;
X`7D
X
Xint scanreplace(char *arg, char *message)
X`7B
X`09char *filen;
X`09FILE *fp;
X`09char *aline;
X
X`09filen = strextract(arg, 3, strlen(arg));
X`09fp = fopen(filen,"r");
X `09while (fgets(fp,aline) != NULL)
X`09`09if (strstr(message,aline) != NULL)
X`09`09`09replace(aline, message);
X`7D
X
Xreplace(char *a, char *b)
X`7B
X`7D`09
X
Xchar *strstrlocate(char *s, char *l)
X`7B
X`09int pos, i, j, k;
X`09
X`09i = 0; j = 0; k = 0; pos = 0;
X`09j = 0;
X`09k = 0;
X`09pos=0;
X          s = arghit    l = oh
X`09for (i = 0,i <= (strlen(s) - strlen(l)), ++i) `7B
X`09`09while ((s`5Bj`5D != '\0') && (s`5Bj`5D != l`5Bk`5D))
X`09`09`09++j; /* find the first character of l in *s */
X`09`09pos = ++j;  6
X`09`09while(s`5Bj`5D == l`5Bk`5D)
X`09`09`09++j; ++k;
X`09`09if (k = stlren(l))
X`09`09`09return pos;  /* we found it */
X`09`09else
X`09`09`09k = 0; /* that wasn't it, try again */
X`09`7D
X`09return j;
X`7D
X
Xchar *strextract(char *s, int j, int k)
X`7B
X  char *t;
X  int i;
X
X  if (j > k)
X    return "\0";
X
X  t = (char *) malloc(k - j + 2);
X  for (i = j; i <= k; ++i)
X    t`5Bi - j`5D = s`5Bi`5D;
X  t`5B++i - j`5D = 0;
X
X  return t;
X`7D /* strextract */
X`09
X
X
$ CALL UNPACK OPTIONS.C;1 138886437
$ create 'f'
X/* Queue.C v1.02`09`09`09Spring 1991`09
X
X`09MODULE NAME: Queue.C
X`09AUTHOR:  Belgarion  (castillo@nauvax.ucc.nau.edu)
X`09LAST REVISED: March 3, 1991
X
X`09This contains all the functions that implement the circular queue`20
X    ADT.  The broadcast messages are contained in a fixed`20
X`09length (array) circular queue known as  brdcst_buf. `20
X    The individual messages are of msg_type, which is a fixed length`20
X`09string descriptor.
X
X*/
X
X#include "ctrap.h"
X
X/* ---------------queue manipulation functions------------------------- */
X
Xvoid setqueue(queue *q)
X/* setqueue sets front pointer to the top (0), the rear as the bottom
X   (LIMIT -1), and numitems as 0.  The queue is thus circular.
X*/
X`7B
X`09q->numitems = 0;
X`09q->front = 1;
X`09q->rear = LIMIT - 1;
X`7D /* setqueue */
X
X
Xint isempty(queue *q)
X/* isempty tests to see if the queue is empty.  If it is, it returns
X   logical TRUE (1) else logical FALSE (0).  Empty is defined as the
X   numitems = 0.
X*/
X`7B
X`09return (q->numitems == 0);
X`7D /* isempty */
X
X
Xint isfull(queue *q)
X/* isfull tests to see if the queue is full.  If it is, it returns
X   logical TRUE (1) else logical FALSE (0).  Full is defined as`20
X   the start pointer == the rear pointer.
X*/
X`7B
X`09return (q->numitems == LIMIT - 1);
X`7D /* isfull */
X
X
Xvoid push(queue *q, msg_type m)
X/* push attempts to push msg onto the queue.  When q->rear is < LIMIT - 1,
X   q->rear is incremented by 1.  when q->rear is equal to LIMIT -1, q-rear
X   is set to 1.  That is, it makes the queue circular.  Since the array`20
X   rather large, this shouldnt happen too often.
X*/
X`7B
X`09msg_type temp;
X
X`09/* COPY temp to m, then set the pointer to temp.  Without copying
X`09   first, the pointer will always be at the last msg.
X`09*/
X`09temp.length = m.length;
X`09temp.dtype = m.dtype;
X`09temp.class`09= m.class;
X`09temp.ptr = (char *) malloc(81);
X`09strcpy(temp.ptr,m.ptr);
X`09q->rear = (q->rear % (LIMIT -1)) + 1;  /* increment rear */
X`09q->queuearray`5Bq->rear`5D = temp;
X`09q->numitems++;
X`7D /* push */
X
X
Xint pop(queue *q, msg_type *m)
X/* pop attempts to remove an item from the queue.  If the queue is`20
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*/
X`7B
X`09if (isempty(q))
X`09`09return 0;
X
X`09(*m) = q->queuearray`5Bq->front`5D;
X`09q->front = (q->front % (LIMIT - 1)) + 1;
X`09q->numitems--;
X`09return 1;
X
X`7D /* pop */
X
X/*---------------end of queue manipulation functions-----------------------*
V/
X
X
Xvoid checkqueue(queue *q)
X`7B
X`09int i;
X`09for (i = 1;i <= q->numitems; i++)
X`09`09fprintf(stdout,"%d :> %s\n",i,q->queuearray`5Bi`5D.ptr);
X`7D
$ CALL UNPACK QUEUE.C;1 1191268798
$ v=f$verify(v)
$ EXIT

