home *** CD-ROM | disk | FTP | other *** search
/ Programmer 7500 / MAX_PROGRAMMERS.iso / INFO / FILUTL / CRCBBS.ZIP / CRCPC1E.C < prev   
Encoding:
C/C++ Source or Header  |  1985-10-22  |  11.0 KB  |  376 lines

  1. #include    "crcpchdr.h"
  2.  
  3. #define        DEBUG    TRUE    /* conditional debug code included when TRUE */
  4.  
  5. #define        DLMT        ","
  6. mail(z,args,opts)
  7. char z, *args, *opts;
  8. {
  9. FILE *fp, *tfp, *ofp;
  10. char *tok_ptr;
  11. char mailfile[15],workfile[15];
  12. char from[9],name[15],delete[10],type[5],comment[LINESIZE];
  13. char dir[DIRSIZE], root[ROOTSIZE];
  14. char dir_buff[STR_SIZE+2];
  15. char workstr1[STR_SIZE+2];
  16. char workstr2[STR_SIZE+2];
  17. char mailbox[15]; 
  18. char new_mbx[15];
  19. int del_flg ;
  20. int kilflg;
  21. int posflg, quiet;
  22. int writeout;
  23. int rc;
  24. int num_out;
  25. char ackstr[LINESIZE];
  26. char ackstr2[LINESIZE];
  27. char fdat[LINESIZE];
  28. char c;
  29.  
  30. stccpy(mailbox,home_dir,sizeof(mailbox));
  31. stccpy(new_mbx,home_dir,sizeof(new_mbx));
  32. strcat(mailbox,MAIL_EXT);
  33. strcat(new_mbx,WMAIL_EXT);
  34. num_out = 0;
  35. quiet = find_option(opts,'q');
  36. posflg = find_option(opts,'!');
  37. kilflg = find_option(opts,'k');        /* Auto-Mail Kill */
  38. if (sysdir("",MAILBOX)) {
  39.     printf("System directory '%s' not found.\r\n",MAILBOX);
  40.     mputs("Sorry, MAIL facility not active.");
  41.     return;
  42.     }
  43. else if ((fp=fopen(mailbox,"r"))==NULL) { /* Is stuff in his mailbox?  */
  44.     if (!quiet) printf("No mail.\r\n");
  45.     }
  46. else {    /* 1 */
  47.     if (posflg) c = 'Y';
  48.     else if (!*args) c = *disp_reply("You have mail. Read it now? (Y/N) ",workstr1,2);
  49.     else c = *args;
  50.     del_flg = FALSE;
  51.     if (toupper(c)!='Y') {
  52.         if (!quiet && beginner) {
  53.             mputs("Your mail will accumulate until it gets deleted, or you\r\n");
  54.             mputs("read it.  You may read it later with the <P> command.\r\n");    
  55.             }
  56.         else nothing_done();
  57.         fclose(fp);
  58.         }
  59.     else {  /* 2 */
  60.         if ((ofp=fopen(new_mbx,"w"))==NULL) { /* Can we create a new one? */
  61.             printf("Cannot create temporary mail box.  See %s\r\n",SYSOP);
  62.             fclose(fp);
  63.             goto getout;
  64.             }
  65.         while(fgets(dir_buff,STR_SIZE,fp)!=NULL) {
  66.             if (!notnull(dir_buff)) continue;    /* Skip */
  67.             *ackstr='\0';
  68.             *ackstr2='\0';
  69.             writeout = TRUE;    /* Saving by default */
  70.                    tok_ptr = incptr(stptok(stpblk(dir_buff),from,9,DLMT));
  71.             tok_ptr = incptr(stptok(stpblk(tok_ptr),name,13,DLMT));
  72.             tok_ptr = incptr(stptok(stpblk(tok_ptr),dir,DIRSIZE,DLMT));
  73.             tok_ptr = incptr(stptok(stpblk(tok_ptr),root,ROOTSIZE,DLMT));
  74.             tok_ptr = incptr(stptok(stpblk(tok_ptr),delete,10,DLMT));
  75.             tok_ptr = incptr(stptok(stpblk(tok_ptr),type,5,DLMT));
  76.             tok_ptr = incptr(stptok(stpblk(tok_ptr),fdat,LINESIZE,DLMT));
  77.             stccpy(comment,stpblk(tok_ptr),LINESIZE);
  78.             del_crlf(comment);
  79.             if (! (*from && *name && *type)) {
  80.                 printf("Missing info in MAILBOX queuefile - see %s\r\n",SYSOP);
  81. #if DEBUG==TRUE
  82.                 printf("from=%s,name=%s,type=%s\r\n",from,name,type);
  83. #endif
  84.                 }
  85.             else if (sysdir(dir,root)) {
  86.                 printf("Could not find directory: '%s',\r\n",prefix_dir(workstr1,dir,root));
  87.                 printf("mail file '%s' could not be retrieved.\r\n",name);
  88.                 sprintf(ackstr,"Could not find %s for %s (%s) on %s\r\n",
  89.                     prefix_dir(workstr1,name,dir),user_id,type,timedate());
  90.                 writeout = FALSE; /* We must forget about it */
  91.                 }
  92.             else {
  93.                 sysdir(home_dir,user_root);
  94.                 if (!strcmp(type,"MAIL")) {
  95.                     printf("MAIL from %s sent on %s:\r\n",from,fdat);
  96.                     sysdir(dir,root);
  97. #if    DEBUG==TRUE
  98.                     if (debug) {
  99.                         printf("just sysdir(%s,%s);\r\n",dir,root);
  100.                         printf("p_d()=%s\r\n",prefix_dir(workstr1,dir,root));
  101.                         }
  102. #endif
  103.                     if (typefile(name,opts)) goto nodelete;
  104.                     sprintf(ackstr,"User %s read mail (%s) on %s\r\n",
  105.                         user_id,prefix_dir(workstr1,name,dir),timedate());
  106.                     if (!kilflg) {
  107.                         c = *disp_reply("\r\nHold this message(default = N)? ",workstr1,2);
  108.                         writeout = (toupper(c)=='Y');
  109.                         if (writeout) {
  110.                             printf("Message held.\r\n");
  111.                             sprintf(ackstr2,"File %s placed on HOLD by user %s - do not delete\r\n",
  112.                                 prefix_dir(workstr1,name,dir),user_id);
  113.                             }
  114.                         }
  115.                     }
  116.                 else {
  117.                     printf("FILE from %s, Original name: %s, Sent on %s:\r\n",from,name,fdat);
  118.                     if (comment[0]!='\0') printf("REMARK: '%s'.\r\n",comment);
  119.                     if ((tfp=fopen(name,"r"))!=NULL) {
  120.                         fclose(tfp);
  121.                         printf("WARNING: file with same name on current directory\r\n");
  122.                         if (beginner) printf("         suggest giving new name.\r\n");
  123.                         }
  124.                     printf("Press <ENTER> to load file as '%s',\r\n",name);
  125.                     disp_reply("enter new filename, or type 'NUL' to throw away:\r\n>",workfile,13);
  126.                     if (workfile[0]=='\0') stccpy(workfile,name,sizeof(workfile));
  127.                     uppercase(workfile);
  128.                     if (!strcmp(workfile,"NUL")) {
  129.                         sprintf(ackstr,"User: %s ignored file %s on %s\r\n",
  130.                             user_id,prefix_dir(workstr1,name,dir),timedate());
  131.                         printf("File thrown away; ignored\r\n");
  132.                         }    
  133.                     else {
  134.                         prefix_dir(workstr1,home_dir,user_root);
  135.                         prefix_dir(workstr2,dir,root);
  136. #if DEBUG==TRUE
  137.                         if (debug) printf("about to copy %s%s to %s%s\r\n",
  138.                             workstr2,name,workstr1,workfile);
  139. #endif
  140.                         if (sysfcopy(workstr1,workfile,workstr2,name,FALSE,TRUE)) goto nodelete;
  141.                         sprintf(ackstr,"User %s loaded file %s as %s on %s\r\n",
  142.                             user_id,prefix_dir(workstr,name,dir),workfile,timedate());
  143.                         }
  144.                     writeout = FALSE;  /* Read or ignored */
  145.                     }
  146.                 cr();
  147.                 if (!writeout & !strcmp(delete,"DELETE")) {
  148.                     sysdir(dir,root);
  149.                     if (unlink(name)) {
  150.                         printf("Error while DELETE of '%s'.\r\n",name);
  151.                         sprintf(ackstr2,"File %s was NOT deleted, as was requested",prefix_dir(workstr,name,dir));
  152.                         }
  153.                     else {
  154.                         mputs("File deleted from source.\r\n");
  155.                         sprintf(ackstr2,"File was deleted as requested.");
  156.                         }
  157.                     }
  158.                 nodelete:        
  159.                 }
  160.             if (*ackstr | *ackstr2) {
  161.                 if (!sysdir(from,user_root)) {
  162.                     if ((tfp=fopen(SYSTEM_MSG,"a"))!=NULL) {
  163.                         if (*ackstr) fputs(ackstr,tfp);
  164.                         if (*ackstr2) fputs(ackstr2,tfp);
  165.                         printf("Receipt acknowledged to %s.\r\n",from);
  166.                         fclose(tfp);
  167.                         }
  168.                     }
  169.                 }
  170.             if (writeout) {
  171.                 fputs(dir_buff,ofp);
  172.                 num_out++;
  173.                 }
  174.             }     /* END WHILE */
  175. /* NOT SURE */    sysdir("",MAILBOX);    /* THIS IS NECESSARY */
  176.         fclose(fp);        /* Close input (old) mail log */
  177.         fclose(ofp);        /* Close output (new) mail log */
  178.         rc=unlink(mailbox);     /* He accepted: delete his old mailbox */
  179. #if DEBUG==TRUE
  180.         if (rc && debug) printf("%s not deleted, rc=%d\r\n",mailbox,rc);
  181. #endif
  182.         if (num_out>0) {
  183.             rc=rename(new_mbx,mailbox); /* Put new one in place */
  184. #if    DEBUG==TRUE
  185.             if (rc && debug) printf("%s not renamed, rc=%d\r\n",new_mbx,rc);
  186. #endif
  187.             }
  188.         else unlink(new_mbx);    /* Delete file if no MSGS held */
  189.         }  /* END ELSE 2 (WANTS TO READ MAIL) */
  190.     } /* END ELSE 1 */
  191. getout:
  192. sysdir(cur_dir,cur_root);
  193. }
  194.  
  195. user_set(c,args,opts)
  196. char c, *args, *opts;
  197. {
  198. char *prompt, *r;
  199. if (!*args && beginner && !find_option(opts,'q')) disp_msg(28);
  200. do {
  201.     if (!*args) {
  202.         show_tsets(opts);
  203.         if (beginner) prompt = "Enter number of item to change: ";
  204.         else prompt = "Item? ";
  205.         r = disp_reply(prompt,file_buff,LINESIZE);
  206.         }
  207.     else r = args;
  208.     if (*r) {
  209.         if (!stoi(r)) printf("Bad selection\r\n");
  210.         else change_tsets(stoi(r));
  211.         }
  212.     } while(*r && !*args);
  213. record_tdf();
  214. }
  215.  
  216. static show_tsets(opts)
  217. char *opts;
  218. {
  219. printf("Terminal settings:\r\n");
  220. printf("\r\n");
  221. printf("1.)  Width:  %s\r\n",utwidth?itos(utwidth):"NA");
  222. printf("2.)  Length: %s\r\n",utlength?itos(utlength):"NA");
  223. printf("3.)  Cls$:   %s\r\n",*utcls?dec_list(file_buff,utcls,LINESIZE):"NA");
  224. printf("4.)  Duplex: %s\r\n",duplex==FULL?"FULL":"HALF");
  225. printf("5.)  Tabs:   %s\r\n",tflag?"REAL":"EXPANDED");
  226. printf("\r\n");
  227. }
  228.  
  229. static change_tsets(num)
  230. int num;
  231. {
  232. char *prompt;
  233. switch(num) {
  234.     case 1: if (beginner) prompt = "Enter new terminal line width, chars ";
  235.         else prompt = "New width ";
  236.         utwidth = new_num(utwidth,prompt,10,255);
  237.         break;
  238.     case 2: if (beginner) prompt = "Enter new terminal page length, lines ";
  239.         else prompt = "New length ";
  240.         utlength = new_num(utlength,prompt,10,255);
  241.         break;
  242.     case 3: if (beginner) {
  243.             printf("Use '*' to delete cls sequence\r\n");
  244.             prompt = "Enter new clear screen sequence: ASCII codes separated by commas: ";
  245.             }
  246.         else prompt = "New cls sequence ? ";
  247.         disp_reply(prompt,file_buff,LINESIZE);
  248.         if (file_buff[0]) {
  249.             if (file_buff[0]=='*') file_buff[0] = '\0';
  250.             bin_list(utcls,file_buff,sizeof(utcls));
  251.             }
  252.         else nothing_done();
  253.         break;
  254.     
  255.     case 4: duplex = !duplex;
  256.         printf("Ok\r\n");
  257.         break;
  258.  
  259.     case 5: tflag = !tflag;
  260.         printf("Ok\r\n");
  261.         break;
  262.     }
  263. }
  264.  
  265. static record_tdf()
  266. {
  267. sprintf(termdef,"%s %s %d %d %s",
  268.     termtype,tflag?"DIRECT":"STANDARD",
  269.     utlength,utwidth,dec_list(file_buff,utcls,LINESIZE));
  270. }
  271.  
  272. static new_num(is,pr,b,t)
  273. int is;
  274. char *pr;
  275. int b, t;
  276. {
  277. int c;
  278. printf("%s (%d; %d-%d): ",pr,is,b,t);
  279. disp_reply("",file_buff,4);
  280. c = stoi(file_buff);
  281. if ((c!=0)&(b>c||t<c)) {    /* Allow 0 thru as CANCEL this function */
  282.     nothing_done();
  283.     return(is);
  284.     }
  285. else return c;
  286. }
  287.  
  288.  
  289. buzz_sysop(c,args,opts)
  290. char c, *args, *opts;
  291. {
  292. int quiet;
  293.  
  294. quiet = find_option(opts,'q');
  295. if (sysop_there) {
  296.     if (quiet) {
  297.         printf("%c.%c.%c.%c.%c.%c\r\n",BEEP,BEEP,BEEP,BEEP,BEEP,BEEP);
  298.         printf("Have buzzed console.  Please continue.\r\n");
  299.         }
  300.     else {
  301.         printf("If someone, such as the system operator, is nearby,\r\n");
  302.         printf("then s/he will intervene and converse with you.\r\n");
  303.         printf("Let me RING them now: %c.%c.%c.%c.%c.%c\r\n",BEEP,BEEP,BEEP,BEEP,BEEP,BEEP);
  304.         printf("Please continue using the system in the meantime.\r\n");
  305.         }
  306.     }
  307. else {
  308.     if (quiet) {
  309.         printf("Not present.\r\n");
  310.         }
  311.     else {
  312.         mputs("There is no system operator nearby.\r\n");
  313.         mputs("Please leave mail for system personnel\r\n");
  314.         mputs("regarding any system business.\r\n");
  315.         }
  316.     }
  317. }
  318.  
  319. ask_sysop(c,args,opts)
  320. char c, *args, *opts;
  321. {
  322. request_acct(opts);
  323. }
  324.  
  325. user_data(z,args,opts)
  326. char z, *args, *opts;
  327. {
  328. char c;
  329. char usern[11];
  330. int brief, quiet, conct, curdr;
  331.  
  332. quiet = find_option(opts,'q');
  333. brief = find_option(opts,'b');
  334. conct = find_option(opts,'c');  /* 'Show connect time' */
  335. curdr = find_option(opts,'d');    /* 'Show current Directory' */
  336.  
  337. if (!quiet) {
  338.     cr();
  339.     mputs("\r\nUser data sheet:\r\n");
  340.     cr();
  341.     }
  342. cr();
  343.  
  344. if (curdr) {
  345.     print_cd();
  346.     cr();
  347.     if (!conct) return;
  348.     }
  349.  
  350. if (!conct) {
  351.     if (no_account) {
  352.         printf("    Visiting user: ");
  353.         strcpy(usern,user_id);
  354.         if (strcmp(uppercase(usern),DEFLT_DIR)) printf(user_id);
  355.         if (userloc[0]) printf("    User location: %s\r\n",userloc);
  356.         printf("\r\n");
  357.         }
  358.     else {
  359.         printf("   System user id: %s\r\n",user_id);
  360.         if (username[0]) printf("             Name: %s\r\n",username);
  361.         if (laston[0]) printf(" Date last called: %s\r\n",laston);
  362.         if (!brief) {
  363.             if (usersys[0]) printf("     System type: %s\r\n",usersys);
  364.                 if (fxfer[0])   printf("   Files xferred: %s\r\n",fxfer);
  365.             if (termdef[0]) printf("      T-settings: %s\r\n",termdef);
  366.             }
  367.         printf("  Times on system: %d\r\n",timeson);
  368.         }  
  369.     if (quiet) return;
  370.     if (!brief) {
  371.         if (medit_opts[0]) printf("   Medit options: %s\r\n",medit_opts);
  372.         if (maxconnect!=defmaxconnect) {
  373.             printf("   Maximum visit: %d minutes\r\n",maxconnect);
  374.             }
  375.         if (!no_account) printf("   Average visit: %d minutes\r\n",(int)
  376.             (((long)totconnec