ERIC@UOFT02.BITNET (07/07/88)
/***********************************************************************/ /* This program will log any messages sent to you in a disk file so as */ /* to provide you with a disk copy of any messages sent your way. It */ /* can be handy if you miss messages due to the screen clearing, or if */ /* you receive death threats and need a copy of them, or whatever... */ /* It puts a date and time stamp on each message so you will know when */ /* it was sent... */ /* */ /* Program by Eric Rostetter, University of Toledo, Toledo, Ohio 43606 */ /* */ /* To use: SPAWN/NOWAIT RUN MESSAGE */ /* */ /* I would suggest that you set up a logical symbol for it, as in: */ /* $ message :== "spawn/nowait run message" */ /* */ /* To stop this program, use the STOP command, or, simply logout... */ /* */ /* Please send any comments, suggestions, changes, etc. to ERIC@UOFT02 */ /* */ /* This file contains the source of the program MESSAGE.C, version 4.0 */ /***********************************************************************/ /***********************************************************************/ /* Modification History: */ /* 21-MAR-1986 Started coding of program, used part of reply. */ /* 21-MAR-1986 Finished initial coding of program version 1.0 */ /* 2-APR-1987 Started coding version 3.0 using REPLY updates */ /* 7-APR-1987 Put some code deleted above back so it works!! */ /* 20-APR-1987 Set MBXDSABL terminal characteristic on entry. */ /* */ /***********************************************************************/ /***********************************************************************/ /* Before we start anything, lets have a word from our sponsors... */ /***********************************************************************/ #include <stdio> #include <descrip> #include <ctype> #include <iodef> #include <ttdef> #include <tt2def> #define then #define false 0 #define true 1 /***********************************************************************/ /* First define all the needed global data structures for the programs */ /***********************************************************************/ FILE *fp; /* output file id for messages. */ int status; /* return status from functions */ int tt_chan,msg_chan; /* kb & mailbox channel numbers */ struct { /* the date and time of message */ char weekday[10]; /* --> the day of the week here */ char filler[1]; /* --> always contains a space! */ char date[12]; /* --> the date in ascii please */ char time[08]; /* --> the time in ascii please */ } header; struct { char buffer[20]; /* the mailbox message info blk */ char length; /* the current message's length */ char filler; /* for some reason this is null */ char message[100]; /* the messages sent to mailbox */ } mbx; struct {unsigned class :8; /* --> terminal class goes here */ unsigned type :8; /* --> the terminal type please */ unsigned page_width :16; /* --> terminal width goes here */ unsigned term_char :24; /* --> terminal characteristics */ unsigned page_length :8; /* --> page length goes in here */ unsigned extended :32; /* --> extended characteristics */ } charbuf; /* terminal characteristics buf */ $DESCRIPTOR(term, "SYS$OUTPUT"); struct dsc$descriptor_s header_dsc = { 20, DSC$K_DTYPE_T, DSC$K_CLASS_S, header.date }; /***********************************************************************/ /* Set up an AST handler for any trapped messages that come our way... */ /***********************************************************************/ get_msg() { mbx.message[mbx.length] = 0; /* null terminates msgs */ fp=fopen("sys$login:msg.log","a+"); /* open up the out file */ if (fp == NULL) then { /* check for open error */ printf("?MESSAGE: Open failed on sys$login:msg.log"); exit(); } get_time(); /* gets a time and date */ fprintf(fp,"%s\n", header.weekday); /* print time log notes */ fprintf(fp,"%s\n", mbx.message); /* puts message to file */ fclose(fp); /* closes the out file */ status=sys$qio(3,msg_chan,IO$_READVBLK /* - do read on mailbox */ ,0,get_msg,0,&mbx,120,0,0,0,0); /* - with an AST finish */ } /***********************************************************************/ /* Now the real work starts... This loop is the main control loop... */ /***********************************************************************/ main() { initialize(); /* inits a few things */ pause(); /* and hibernate here */ } /***********************************************************************/ /* Let's initialialize some things before we start about our business! */ /***********************************************************************/ initialize() { strcpy(header.filler," "); /* make display neat... */ lib$disable_ctrl( &34603008 ); /* disable CTRL Y and T */ /* Creates mailbox to receive all the messages that are sent our way... */ status = lib$asn_wth_mbx(&term,&0,&0,&tt_chan,&msg_chan); if (status != true) then lib$signal(status); /* Now tell VMS to send the messages to the mailbox so we can log them! */ status=sys$qiow(0,tt_chan,IO$_SENSEMODE,/* get terminal setting */ 0,0,0,&charbuf,12,0,0,0,0); /* so as to change them */ if (status != true) lib$signal(status); /* exits this if errors */ charbuf.term_char = charbuf.term_char /* do SET TERM/MBXDSABL */ |TT$M_MBXDSABL; /* to set up mailbox... */ charbuf.extended = charbuf.extended /* SET TERM/BRDCSTMBX */ |TT2$M_BRDCSTMBX; /* so we receive in mbx */ status=sys$qiow(0,tt_chan,IO$_SETMODE /* really set them here */ ,0,0,0,&charbuf,12,0,0,0,0); if (status != true) lib$signal(status); /* exits this if errors */ /* Queue an ast routine to read from the terminal's message mailbox... */ status=sys$qio(3,msg_chan,IO$_READVBLK,0,get_msg,0,&mbx,120,0,0,0,0); } /***********************************************************************/ /* Get the time and date that a message was sent so that we can log it */ /***********************************************************************/ get_time() { int i; /* counter variables... */ unsigned int j[4]; /* holds internal times */ static char day_list[] = "MONDAY, TUESDAY, WEDNESDAY,THURSDAY, FRIDAY, SATURDAY, SUNDAY, "; lib$date_time(&header_dsc); /* get the current time */ sys$gettim(&j[0]); /* and an internal time */ lib$day_of_week(&j[0], &i); /* gets day of the week */ i = (i - 1) * 10; /* calculate offset now */ strncpy(header.weekday,&day_list[i],10);/* put in output buffer */ }