# include "c.defs" /********************************************************************** INIT PROGRAM Reports time of last login. Reads, Saves, and Prints Mail. Reports on existence of old mail. Mail is saved in VANISH as it is being read. Command options: The following options control various actions. They may be written as +c (meaning always do it) or -c (never do it). The default is indicated: ASK means that the user is asked whether or not to perform the action. +l record login time (default: +) +s save mail (default: ask) +p print mail (default: ask) +r read mail (default: ask) +t check for TECO save files (default: -) +u print user name (default: +) The following options specify various names to be used in performing actions: s=foo specify fname1 for saved mail (default: OMAIL) "p=foo bar" specify file for printing (default: TPL:) "t=foo bar" specify TECO save file name (default: .SAVE. >) **********************************************************************/ # define process_options propt # define mail_exists mlexst # define get_user_name gtuser # define print_user_name pruser # define print_last_login prlog # define check_for_old_mail chkom # define check_for_teco_fies chktf # define type_files typfil # define copy_files cpfil # define print_files prtfil # define delete_files delfil # define close_files clofil # define file_type filty # define file_print filpr # define file_copy filcp # define save_name svnam # define print_name prnam # define teco_name tecnam extern int cout; /* standard output */ int fin0, fin1, fin2; /* mail files */ char fnam0[40], fnam1[40], fnam2[40]; /* mail file names */ char user[10]; /* user name */ int s_hit; /* interrupt flag */ /* options */ int lflag '+', sflag 'a', pflag 'a', rflag 'a', tflag '-', uflag '+'; char *save_name {"omail"}; char *print_name {"tpl:"}; char *teco_name {".save. >"}; main (argc, argv) int argc; char *argv[]; {int saved, backed_up, able_to_print, want_to_save; char *sconcat(); if (argc>1) process_options (argc-1,argv+1); get_user_name (); if (uflag=='+') print_user_name (); if (lflag=='+') print_last_login (); fin0 = copen (sconcat (fnam0, 2, user, " mail"), 'r'); fin1 = copen (sconcat (fnam1, 3, "common;", user, " mail"), 'r'); fin2 = copen (sconcat (fnam2, 3, "common;", user, " sends"), 'r'); saved = backed_up = want_to_save = FALSE; able_to_print = TRUE; if (mail_exists ()) {puts ("\nYou have mail."); if (ask ("Read Mail", rflag)) {backed_up = type_files (); if (!backed_up || ask ("Save Mail", sflag)) {want_to_save = TRUE; saved = copy_files (); if (saved && !backed_up && sflag!='+') puts ("\n(mail saved)"); } if (ask ("Print Mail", pflag)) able_to_print = print_files (); if ((want_to_save && !saved) || (!able_to_print && !saved)) puts ("\n(mail not deleted -- will be reread)\n"); else delete_files (); } close_files (); } if (!saved) check_for_old_mail (); if (tflag=='+') check_for_teco_files (); } /********************************************************************** AUXILIARY ROUTINES **********************************************************************/ process_options (argc, argv) int argc; char *argv[]; {char *s; int c; while (--argc>=0) {s = *argv++; c = s[0]; if (c=='-' || c=='+') switch (lower (s[1])) { case 'l': lflag = c; continue; case 's': sflag = c; continue; case 'p': pflag = c; continue; case 'r': rflag = c; continue; case 't': tflag = c; continue; case 'u': uflag = c; continue; } else if (s[1]=='=') switch (lower (s[0])) { case 's': save_name = s+2; continue; case 'p': print_name = s+2; continue; case 't': teco_name = s+2; continue; } cprint ("Unrecognized Option: %s\n", s); } } int mail_exists () {return (fin0>=0 || fin1>=0 || fin2>=0);} int type_files () {int out, temp, setsf(); char fname[40]; s_hit = FALSE; on (ctrls_interrupt, 1); on (ctrls_interrupt, setsf); out = copen (sconcat (fname, 3, "vanish;", user, " omail"), 'a'); file_type (fin0, out); file_type (fin1, out); file_type (fin2, out); if (out>=0) cclose (out); on (ctrls_interrupt, 0); temp = s_hit; s_hit = FALSE; return (!temp); } file_type (in, out) {int c; if (in<0 || s_hit) return; cputc ('\n', cout); if (out>=0) cputc ('\n', out); while ((c = cgetc (in)) > 0 || !ceof (in)) {cputc (c, cout); if (out>=0) cputc (c, out); if (s_hit) {if (out>=0) cputc ('\n', out); break; } } if (!s_hit) cputc ('\n', cout); rew (in); } copy_files () {int out; char buf[100]; out = copen (sconcat (buf, 2, save_name, " > dsk:"), 'w'); if (out<0) {puts ("unable to save mail"); return (FALSE); } if (fin0>=0) file_copy (fin0, out); if (fin1>=0) file_copy (fin1, out); if (fin2>=0) file_copy (fin2, out); cclose (out); return (TRUE); } int print_files () {int out; out = copen (print_name, 'w'); if (out < 0) {puts ("unable to print mail"); return (FALSE); } if (fin0>=0) file_copy (fin0, out); if (fin1>=0) file_copy (fin1, out); if (fin2>=0) file_copy (fin2, out); cclose (out); return (TRUE); } file_copy (in, out) {int c; cputc ('\n', out); while ((c = cgetc (in)) > 0 || !ceof (in)) cputc (c, out); rew (in); } get_user_name () {c6tos (rsname (), user); } print_user_name () {cprint ("\nUser: %s\n", user);} print_last_login () {int f, fdate; cal cdate; f = fopen ("_last_.login", 2); if (f >= 0) {if ((fdate = rfdate (f)) != -1) {f2cal (fdate, &cdate); cprint ("Last login: "); prcal (&cdate, cout); cputc ('\n', cout); } now (&cdate); sfdate (f, cal2f (&cdate)); close (f); } else close (fopen ("_last_.login", 3)); } delete_files () {if (fin0>=0) delete (fnam0); if (fin1>=0) delete (fnam1); if (fin2>=0) delete (fnam2); } close_files () {if (fin0>=0) cclose (fin0); if (fin1>=0) cclose (fin1); if (fin2>=0) cclose (fin2); } check_for_old_mail () {int f; char buf[100]; f = fopen (sconcat (buf, 2, save_name, " < dsk:"), 0); if (f>=0) {puts ("\nYou have old mail in your directory."); close (f); } } check_for_teco_files () {int f; f = fopen (teco_name, 0); if (f>=0) {puts ("\nYou have TECO save files in your directory."); close (f); } } int ask (s, flag) char *s; {int c; if (flag=='+') return (TRUE); if (flag=='-') return (FALSE); while (TRUE) {tyos (s); tyos (" (Y or N)? "); while (TRUE) {c = lower (utyi ()); if (c=='y') {tyos ("yes\r"); return (TRUE);} if (c=='n') {tyos ("no\r"); return (FALSE);} if (c=='\p') {spctty ('C'); break;} tyo (07); } } } char *sconcat(buf,n,s1,s2,s3) char *s1, *s2, *s3; {int c; char **s, *p, *q; p = buf; s = &s1; while (--n >= 0) {q = *s++; while (c = *q++) *p++ = c; } *p = 0; return (buf); } setsf () {s_hit = TRUE; tyo ('\r'); }