home *** CD-ROM | disk | FTP | other *** search
/ Usenet 1994 January / usenetsourcesnewsgroupsinfomagicjanuary1994.iso / sources / misc / volume32 / xbbs / part03 / bbsc2.c next >
C/C++ Source or Header  |  1992-09-08  |  42KB  |  1,954 lines

  1. /* bbsc2.c    */
  2.  
  3. #include "bbsc12.h"
  4.  
  5. int             contin;
  6. extern int      zip;
  7.  
  8. editline(line_no, tflag)
  9.     int             line_no;
  10.     char            tflag;
  11. {
  12.     char           *work_ptr,    /* pointers */
  13.                    *msg_ptr, *new_ptr, tmp_tmp[3], byte;
  14.     int             i;    /* a counter */
  15.  
  16.     work_msg[0] = '\0';    /* init strings */
  17.     buf128[0] = '\0';
  18.     strcpy(tmp_tmp, " ");
  19.     i = 1;            /* assume at line one */
  20.  
  21.     work_ptr = work_msg;    /* put the addr of work_msg in the pointer */
  22.     msg_ptr = msg_text;    /* put the addr of the global message in ptr */
  23.     new_ptr = buf128;    /* the new line too */
  24.  
  25.     while (byte = *msg_ptr) {    /* if at the line then found it's
  26.                      * start */
  27.         if (line_no == i)
  28.             break;    /* found the line        */
  29.         while (byte = *msg_ptr++) {    /* move msg to work area *//* u
  30.                          * ntil end of msg */
  31.             *work_ptr++ = byte;
  32.             if (byte == '\n') {    /* end of line? */
  33.                 i++;
  34.                 break;    /* then stop moving */
  35.             }
  36.         }
  37.     }
  38.     if (byte == 0) {    /* if true then there ain't no such beast */
  39.         portsout("Hmmm, can't seem to find that line");
  40.         portsout(CRLF);
  41.         portsout("   give me another chance, ok?");
  42.         portsout(CRLF);
  43.         return;        /* here we go round the mulberry bush */
  44.     }
  45.  
  46.     portsout(CRLF);
  47.     portsout("Line to ");
  48.     if (tflag == 'E') {
  49.         portsout("edit");
  50.     } else if (tflag == 'I') {
  51.         portsout("insert after");
  52.     } else if (tflag == 'D') {
  53.         portsout("delete");
  54.     } else if (tflag == 'R') {
  55.         portsout("replace");
  56.     } else if (tflag == 'N') {
  57.         portsout("center");
  58.     } else if (tflag == 'B') {
  59.         portsout("block");
  60.     } else
  61.         return;
  62.  
  63.     portsout(" is:");
  64.     portsout(CRLF);
  65.     portsout(">");
  66.     x_pathandfile[0] = '\0';
  67.  
  68.     while (byte = *msg_ptr++) {    /* show the line to edit */
  69.         tmp_tmp[0] = byte;
  70.         strcat(x_pathandfile, tmp_tmp);
  71.         if (tflag == 'I') {
  72.             *work_ptr++ = byte;    /* if adding new line copy */
  73.         }
  74.         if (byte == '\n')
  75.             break;
  76.         portout(byte);
  77.     }
  78.     portsout(CRLF);
  79.  
  80.     if (tflag == 'D') {
  81.         portsout("Are you sure? (y/N) ==> ");
  82.         byte = portin();/* get answer */
  83.         portout(byte);    /* send it back */
  84.         if ((byte != 'Y') && (byte != 'y'))
  85.             return;
  86.         cnt1--;
  87.     } else {
  88.         if (tflag == 'E') {
  89.             if (substs() == 1)
  90.                 return;
  91.         }
  92.         if (tflag == 'N') {
  93.             center_text();
  94.         }
  95.         if (tflag == 'B') {
  96.             block_text();
  97.         }
  98.         if (tflag == 'R') {
  99.             portsout("   .___.____1____.____2____.____3____.____4____.____5____.____6____.____7__");
  100.             portsout(CRLF);
  101.             portsout("R: ");
  102.             portsin(buf128, 72);
  103.             strcat(buf128, "\n\0");
  104.             portsout(CRLF);
  105.         }
  106.         if (tflag == 'I') {
  107.             portsout("   .___.____1____.____2____.____3____.____4____.____5____.____6____.____7__");
  108.             portsout(CRLF);
  109.             portsout("I: ");
  110.             portsin(buf128, 72);
  111.             strcat(buf128, "\n\0");
  112.             portsout(CRLF);
  113.             cnt1++;
  114.         }
  115.         while (*work_ptr++ = *new_ptr++) { /* tag on new line to */ ;
  116.         }        /* work area */
  117.         *work_ptr--;    /* back up one */
  118.     }
  119.  
  120.     while (*work_ptr++ = *msg_ptr++) { /* now move in rest of */ ;
  121.     }            /* message to work area */
  122.     *work_ptr++ = '\0';    /* for luck */
  123.  
  124.     strcpy(msg_text, work_msg);    /* replace the message with the */
  125.     /* new line inserted */
  126. }
  127. block_text()
  128. {
  129.     char buffer[82], *ptr;
  130.     int len, i, j, k;
  131.     int stt, stp;
  132.     int spaces[80], words[80], spaces2add[80];
  133.     for (i=0; i<80; i++) {
  134.         spaces[i] = -1;
  135.         words[i] = -1;
  136.         spaces2add[i] = 0;
  137.     }
  138.     ptr = x_pathandfile;
  139.     len = strlen(x_pathandfile);
  140.     if( len < 55 )  {
  141.         strcpy(buf128, x_pathandfile);
  142.         return;
  143.     }
  144.     while ( *ptr == (char) ' ') {       /* get rid of initial spaces */
  145.         ptr++;
  146.         len--;
  147.     }
  148.     if( len < 55 ) {
  149.         strcpy(buf128, ptr);
  150.         return;
  151.     }
  152.     strcpy(buffer, ptr);
  153.     buffer[73]='\0';
  154.     i = 0;
  155.     ptr = strrchr( buffer, '\n');
  156.     if ( ptr != NULL ) {
  157.         *ptr = '\0';
  158.         i=1;
  159.         ptr--;
  160.     }
  161.     else {
  162.         ptr = buffer + strlen(buffer) - 1;
  163.     }
  164.     if( *ptr == (char) '\r' ) {
  165.         *ptr = '\0';
  166.         ptr--;
  167.     }
  168.     len = strlen(buffer);
  169.     while (*ptr) {
  170.         if( *ptr == (char)' ') {        /* get rid of terminal spaces */
  171.             *ptr = '\0';
  172.             if( ptr == buffer) {
  173.                 strcpy(buf128, x_pathandfile);
  174.                 return;
  175.             }
  176.             ptr--;
  177.             len--;
  178.         }
  179.         else
  180.             break;
  181.     }    
  182.     if(len >= 72) {
  183.         strcpy(buf128, x_pathandfile);
  184.         return;
  185.     }
  186.     ptr = buffer;
  187.     j = 0;
  188.     while (*ptr) {
  189.         if( *ptr == (char) ' ') {
  190.             spaces[j] = 0;
  191.             *ptr = '\0';
  192.         }
  193.         else
  194.             spaces[j] = 1;
  195.         ptr++; j++;
  196.     }
  197.     j=0;
  198.     stt=0;
  199.     while ( 1 ) {
  200.         for(stp = stt; stp < 80; stp++ ) {
  201.             if( spaces[stp] == -1 )
  202.                 goto Out_loop;
  203.             if( spaces[stp] == 0) {
  204.                 words[j] = stp - stt;
  205.                 stt = stp + 1;
  206.                 j++;
  207.                 break;
  208.             }
  209.         }
  210.     }
  211. Out_loop:
  212.  
  213.     stp = len;
  214.     k=1;
  215.     while(1) {
  216.         for ( j=0; j<80; j++ ) {
  217.             if(words[j] == -1 )
  218.                 break;
  219.             if( words[j] == k ) {
  220.                 spaces2add[j]++;    
  221.                 stp++;
  222.                 if(stp == 72)
  223.                     goto Out_loop2;
  224.             }
  225.         }
  226.         k++;
  227.         if( k > 72)
  228.             k = 1;
  229.     }
  230. Out_loop2:
  231.     j=0;
  232.     ptr = buffer;
  233.     strcpy(buf128, buffer);
  234.     while ( words[j] != -1 ) {
  235.         while(*ptr != (char) '\0')
  236.             ptr++;
  237.         ptr++;
  238.         strcat(buf128, " ");
  239.         for (k=0; k < spaces2add[j]; k++)
  240.             strcat(buf128, " ");
  241.         strcat(buf128, ptr);
  242.         j++;
  243.         if(( k=strlen(buf128)) >= 72)
  244.             break;
  245.     }
  246.     if(i)
  247.         strcat(buf128,"\n");        
  248.         
  249. }
  250.     
  251.         
  252.     
  253.  
  254. center_text()
  255. {
  256.     int len;
  257.     int newline;
  258.     char *ptr;
  259.     newline = 0;
  260.     ptr = x_pathandfile;
  261.     len = strlen(x_pathandfile);
  262.     if (len <= 0) {
  263.         strcpy(buf128, x_pathandfile);
  264.         return;
  265.     }
  266.     ptr = x_pathandfile + len -1;
  267.     if( *ptr = '\n') {
  268.         *ptr = '\0';
  269.         ptr --;
  270.         newline = 1;
  271.     }
  272.  
  273.     while ( *ptr == ' ') {
  274.         *ptr = '\0';
  275.         ptr--;
  276.         if( ptr < x_pathandfile) {
  277.             strcpy(buf128, x_pathandfile);
  278.             return;
  279.         }
  280.     }
  281.     len = strlen(x_pathandfile);
  282.     if( len <= 0) {
  283.         strcpy( buf128, x_pathandfile);
  284.         return;
  285.     }
  286.     ptr = x_pathandfile;
  287.     while (*ptr == ' ') {
  288.         if( *ptr == '\0') {
  289.             strcpy(buf128, x_pathandfile);
  290.             return;
  291.         }
  292.         ptr++;
  293.     }
  294.     strcpy(buf128, ptr);
  295.     len = (72 - (strlen(buf128)))/2;
  296.     x_pathandfile[0] = '\0';
  297.     ptr = x_pathandfile;
  298.     while ( len ) {
  299.         *ptr = ' ';
  300.         ptr++;
  301.         *ptr = '\0';
  302.         len--;
  303.     }
  304.     strcat(x_pathandfile, buf128);
  305.     strcpy(buf128, x_pathandfile);
  306.     if(newline)
  307.         strcat(buf128,"\n");
  308.  
  309. }
  310.     
  311.  
  312. int
  313. substs()
  314. {
  315.     int             len_old, len_new, len_tot;
  316.     int             result, dat;
  317.     char            temp[75];
  318.     len_tot = strlen(x_pathandfile);
  319.     portsout(CRLF);
  320.     for (dat = 0; dat <= 21; dat++) {
  321.         who_am_i[dat] = '\0';
  322.         who_am_I[dat] = '\0';
  323.     }
  324.     portsout("Enter the old string ( max 20 char ):  ");
  325.     portsin(who_am_i, 20);
  326.     portsout(CRLF);
  327.     portsout("Enter the new string ( max 20 char ):  ");
  328.     portsin(who_am_I, 20);
  329.     portsout(CRLF);
  330.     len_old = strlen(who_am_i);
  331.     len_new = strlen(who_am_I);
  332.     if ((len_tot - len_old + len_new) >= 74) {
  333.         portsout("\n\rLine length TOO long!\n\r");
  334.         return (1);
  335.     }
  336.     result = len_tot - len_old + 1;
  337.     for (dat = 1; dat <= result; dat++) {
  338.         substr(x_pathandfile, temp, dat, len_old);
  339.         if (strcmp(who_am_i, temp) == 0)
  340.             goto subz;
  341.     }
  342.     portsout("\n\rUnable to find the requested string!\n\r");
  343.     return (1);
  344. subz:
  345.     buf128[0] = '\0';
  346.     substr(x_pathandfile, buf128, 1, dat - 1);
  347.     strcat(buf128, who_am_I);
  348.     result = dat + len_old;
  349.     substr(x_pathandfile, temp, result, (len_tot - result + 1));
  350.     strcat(buf128, temp);
  351.     portsout("Edited Line \n\r");
  352.     portsout(buf128);
  353.     portsout(CRLF);
  354.     return (0);
  355. }
  356.  
  357. cmd_k()
  358. {
  359.     char            ans[11];
  360.     int             kill_msg, kill, fd, rc;
  361.  
  362.     if (!read_flag) {
  363.         portsout(CRLF);
  364.         portsout("Enter message number to delete ==> ");
  365.         portsin(ans, 10);
  366.         portsout(CRLF);
  367.         kill_msg = atoi(ans);
  368.         if (kill_msg == 0)
  369.             return;
  370.     }
  371.     if (read_flag) {
  372.         kill_msg = read_number;
  373.         itoa(ans, read_number);
  374.     }
  375.     fd = msgopen(2);    /* open i/o */
  376.     if ((rc = msgreadk(fd, kill_msg)) == ERROR || rc == 0 || rc == -10) {
  377.         portsout("\n\rNot your message to delete or not a valid message!");
  378.         portsout(CRLF);
  379.         return;
  380.     }
  381.     portsout("Deleting message...");
  382.     portsout(CRLF);
  383.     strcpy(msg_delete, "9");/* mark for deletion */
  384.     kill = xtable[kill_msg - 1];
  385.     if (msgrewrt(fd, kill) == ERROR) {    /* re-write the record just
  386.                          * read */
  387.         portsout("Sorry, can't delete that message");
  388.         portsout(CRLF);
  389.         return;
  390.     }
  391.     msgclose(fd);
  392.     portsout("Message ");
  393.     portsout(ans);
  394.     portsout(" has been deleted!");
  395.     portsout(CRLF);
  396.     return;
  397. }
  398. /* end of function         */
  399.  
  400. cmd_q()
  401. {
  402.     char            ans[6];
  403.     int             q_msg, fd, rc;
  404.  
  405.     if ((fd = msgopen(0)) == ERROR) {    /* open input */
  406.         return (ERROR);
  407.     }
  408.     portsout(CRLF);
  409.     portsout("Enter starting message number -- RETURN to exit  ==> ");
  410.     portsin(ans, 5);
  411.     lnctx = 5;
  412.     q_msg = atoi(ans);
  413.     if (q_msg == 0) {    /* = 0 all done */
  414.         msgclose(fd);
  415.         return;
  416.     }
  417.     portsout(CRLF);
  418.     portsout(CRLF);
  419.     portsout("No.      Date            Subject");
  420.     portsout(CRLF);
  421.     portsout("---------------------------------------");
  422.     portsout(CRLF);
  423.  
  424.     while ((rc = msgread(fd, q_msg++)) != ERROR) {    /* read until eof or
  425.                              * error */
  426.         if (rc == 0) {
  427.             continue;    /* not a valid msg */
  428.         }
  429.         portlsout(msg_no, 6);
  430.         portlsout(msg_date, 12);
  431.         portsout(msg_subject);
  432.         portsout(CRLF);
  433.         if (toggle) {
  434.             lnctx++;
  435.             if (lnctx == 23) {
  436.                 portsout(CRLF);
  437.                 portsout("*** Depress a key to continue ........ ");
  438.                 portsin(jnk, 1);
  439.                 portsout(CRLF);
  440.                 lnctx = 1;
  441.             }
  442.         }
  443.         if (stop_that) {/* ctl-K ? */
  444.             stop_that = FALSE;
  445.             break;
  446.         }
  447.     }
  448.     msgclose(fd);
  449. }
  450. /* end of function         */
  451.  
  452. cmd_r()
  453. {
  454.     char            msgno[6], *text, byte0, tmp[80];
  455.     char        well[3];
  456.     char           *file_ptr_x;
  457.     int             msg, msgtmp, read_switch, fd, loop_check, direction, xfr, kill_ok, rc;
  458.     int             counter;
  459.     kill_ok = FALSE;
  460.     strcpy(who_am_i, w_fname);
  461.     strcat(who_am_i, " ");
  462.     strcat(who_am_i, w_lname);
  463.     sprintf(who_am_I, "%-21s", who_am_i);
  464.     strcpy(buf128, m_pathname);
  465.     file_ptr_x = strrchr(buf128, '/');
  466.     *file_ptr_x = '\0';
  467.     file_ptr_x = strrchr(buf128, '/');
  468.     *file_ptr_x++;
  469.     strcpy(x_filename, file_ptr_x);
  470.     xfr = 0;
  471. read_again:
  472.     read_switch = FALSE;
  473.     if ((fd = msgopen(0)) == ERROR) {    /* open input */
  474.         return (ERROR);
  475.     }
  476.     if (!read_flag) {
  477.         portsout("\n\r");
  478.         portsout("Enter the message number to read, N for NEW, or");
  479.         portsout(" - Q to exit   ==> ");
  480.     }
  481.     direction = TRUE;
  482.     msg = 0;
  483.     while (!stop_that) {
  484.         if (!read_flag && !contin) {
  485.             portsin_cmp(msgno, 4, "QqRrNnKkXx*FfMmCc");
  486.             portsout(CRLF);
  487.         }
  488.         if (read_flag)
  489.             itoa(msgno, read_number);
  490.         if (msgno[0] == 'C' || msgno[0] == 'c') {
  491.             if (!read_switch)
  492.                 goto read_again;
  493.             contin = TRUE;
  494.             if (direction)
  495.                 goto forward;
  496.             else
  497.                 goto back;
  498.         }
  499.         if (msgno[0] == 'M' || msgno[0] == 'm') {
  500.             if (!read_switch)
  501.                 goto read_again;
  502.             reply_sw = TRUE;
  503.             portsout("\n\rDo you wish to use blocked (right justified) format?  (y/N: ");
  504.             portsin(well, 1);
  505.             portsout(CRLF);
  506.             if (well[0] == 'y' || well[0] == 'Y') 
  507.                 blocked_m = 1;
  508.             else
  509.                 blocked_m = 0;
  510.             strcpy(msg_to, msg_from);
  511.             strcpy(x_pathandfile, "(R) ");
  512.             strcat(x_pathandfile, msg_subject);
  513.             substr(x_pathandfile, msg_subject, 1, 20);
  514.             msgclose(fd);
  515.             cmd_e();
  516.             reply_sw = FALSE;
  517.             if ((fd = msgopen(0)) == ERROR) {    /* open input */
  518.                 return (ERROR);
  519.             }
  520.             portsout("\n\r\n\r(Continuing Reading of Messages)");
  521.             goto sorry;
  522.         }
  523.         if (msgno[0] == 'F' || msgno[0] == 'f') {
  524.     forward:
  525.             if (!read_switch)
  526.                 goto read_again;
  527.             msg++;
  528.             direction = TRUE;
  529.             goto next_msg;
  530.         }
  531.         if (msgno[0] == 'X' || msgno[0] == 'x') {
  532.             if (!read_switch)
  533.                 goto read_again;
  534.             if (!privmsg(mpX))
  535.                 goto sorry;
  536.             cmd_x();
  537.             rewritx();
  538.             goto sorry;
  539.         }
  540.         if (msgno[0] == 'K' || msgno[0] == 'k') {
  541.             if (!read_switch)
  542.                 goto read_again;
  543.             if (!kill_ok)
  544.                 goto sorry;
  545.             read_flag = TRUE;
  546.             read_number = atoi(msg_no);
  547.             cmd_k();
  548.             read_flag = FALSE;
  549.             kill_ok = FALSE;
  550.             goto sorry;
  551.         }
  552.         if (msgno[0] == 'n' || msgno[0] == 'N') {
  553.             msg = new_msg;
  554.             direction = TRUE;
  555.             if (msg == 0) {
  556.                 portsout(CRLF);
  557.                 portsout("There are no NEW messages to read");
  558.                 portsout(CRLF);
  559.             }
  560.             goto next_msg;
  561.         }
  562.         if (msgno[0] == 'R' || msgno[0] == 'r') {
  563.     back:
  564.             if (!read_switch)
  565.                 goto read_again;
  566.             msg--;
  567.             direction = FALSE;
  568.             if (msg <= 0) {
  569.                 msg = 1;
  570.                 if (contin)
  571.                     contin = FALSE;
  572.                 direction = TRUE;
  573.             }
  574.             goto next_msg;
  575.         }
  576.         if (msgno[0] == '^' || msgno[0] == '*') {
  577.             if (!read_switch)
  578.                 goto read_again;
  579.             direction = TRUE;
  580.             goto next_msg;
  581.         }
  582.         msgtmp = msgno[0];
  583.         msgtmp = isdigit(msgtmp);
  584.         if (!msgtmp) {
  585.             msgtmp = strlen(msgno);
  586.             if (!msgtmp) {
  587.                 if (direction)
  588.                     goto forward;
  589.                 else
  590.                     goto back;
  591.             }
  592.             msg = 0;
  593.             goto next_msg;
  594.         }
  595.         msg = atoi(msgno);
  596.         if (msg > 1000) {
  597.             portsout(CRLF);
  598.             portsout(msgno);
  599.             portsout(" is an illegal message number.\n\r");
  600.             portsout("It must be in the range from 1 - 1000.\n\r");
  601.             break;
  602.         }
  603.         direction = TRUE;
  604. next_msg:
  605.         if (msg <= 0) {
  606.             if (xfr > last_msg_read) {
  607.                 last_msg_read = xfr;
  608.                 new_msg = last_msg_read + 1;
  609.                 if (new_msg >= h_act)
  610.                     new_msg = 0;
  611.                 set_write();
  612.             }
  613.             break;
  614.         }
  615. msg_loop:
  616.         itoa(msgno, msg);
  617.         if ((rc = msgreadx(fd, msg)) == 0 || rc == ERROR) {
  618.             if (rc == 0) {
  619.                 if (direction) {
  620.                     msg++;
  621.                 }
  622.                 if (!direction) {
  623.                     msg--;
  624.                     if (msg <= 0) {
  625.                         msg = 1;
  626.                         if (contin)
  627.                             contin = FALSE;
  628.                         direction = TRUE;
  629.                     }
  630.                 }
  631.                 goto msg_loop;
  632.             }
  633.             if (rc == ERROR) {
  634.                 msg = h_act - 1;
  635.                 if (msg <= 1)
  636.                     if ((rc = msgreadx(fd, msg)) == 0 || rc == ERROR) {
  637.                         portsout("\n\r\n\rThis is an empty message base!\n\r\n\r");
  638.                         break;
  639.                     }
  640.                 for (loop_check = 1; loop_check <= msg; loop_check++) {
  641.                     if ((rc = msgreadx(fd, loop_check)) == 0 || rc == ERROR || rc == -10);
  642.                     else
  643.                         goto loop_next_ok;
  644.                 }
  645.                 if (rc == -10) {
  646.                     portsout("\n\rThere are no readable messages in this message base!\n\r\n\r");
  647.                     break;
  648.                 }
  649.                 portsout("\n\r\n\rThis is an empty message base!\n\r\n\r");
  650.                 break;
  651.         loop_next_ok:
  652.                 portsout("\n\rCan't go beyond last message\n\r");
  653.                 itoa(msgno, msg);
  654.                 portsout("Last active/inactive message in file = ");
  655.                 portsout(msgno);
  656.                 portsout(CRLF);
  657.                 if (contin)
  658.                     contin = FALSE;
  659.                 goto step2;
  660.             }
  661.         } else {
  662.             if (rc == -10) {
  663.                 if (direction) {
  664.                     msg++;
  665.                     goto msg_loop;
  666.                 }
  667.                 if (!direction) {
  668.                     msg--;
  669.                     if (msg <= 0) {
  670.                         direction = TRUE;
  671.                         if (contin)
  672.                             contin = FALSE;
  673.                         msg = 1;
  674.                     }
  675.                     goto msg_loop;
  676.                 }
  677.             }
  678.             if (xfr < msg)
  679.                 xfr = msg;
  680.             portsout(CRLF);
  681.             portsout("No. ");
  682.             portsout(msg_no);
  683.             portsout("  ");
  684.             portsout(msg_date);
  685.             portsout("  ");
  686.             portsout(msg_time);
  687.             portsout(CRLF);
  688.  
  689.             portsout("From: ");
  690.             portsout(msg_from);
  691.             portsout("       To: ");
  692.             portsout(msg_to);
  693.             portsout(CRLF);
  694.  
  695.             portsout("Subject: ");
  696.             portsout(msg_subject);
  697.             portsout(CRLF);
  698.             portsout("Message class: ");
  699.             if (msg_delete[0] == '0')
  700.                 portsout("Public");
  701.             else
  702.                 portsout("Private");
  703.             portsout("             Message base: ");
  704.             portsout(x_filename);
  705.             portsout(CRLF);
  706.             portsout(CRLF);
  707.  
  708.             kill_ok = check_from_to();
  709.  
  710.             text = msg_text;
  711.             counter = 7;
  712.             while (byte0 = (*text++)) {
  713.                 if (byte0 == '\n') {
  714.                     portout('\r');
  715.                 }
  716.                 portout(byte0);
  717.                 if (byte0 == '\n') {
  718.                     counter++;
  719.                     if (counter == 24 && !contin && toggle) {
  720.                         portsout("\n\r*** Depress a key to continue ........ ");
  721.                         portsin(jnk, 1);
  722.                         counter = 0;
  723.                         portsout(CRLF);
  724.                         portsout(CRLF);
  725.                     }
  726.                 }
  727.                 if (stop_that) {
  728.                     if (!zip)
  729.                         stop_that = FALSE;
  730.                     msgclose(fd);
  731.                     if (xfr > last_msg_read) {
  732.                         last_msg_read = xfr;
  733.                         new_msg = last_msg_read + 1;
  734.                         if (new_msg >= h_act)
  735.                             new_msg = 0;
  736.                         set_write();
  737.                     }
  738.                     return;
  739.                 }
  740.             }
  741.         }
  742. sorry:        if (read_flag) {
  743.             msgclose(fd);
  744.             return;
  745.         }
  746.         read_switch = TRUE;
  747.         if (counter >= 20 && !contin && toggle) {
  748.             portsout("\n\r*** Depress a key to continue ........ ");
  749.             portsin(jnk, 1);
  750.             counter = 0;
  751.             portsout(CRLF);
  752.         }
  753.         portsout("\n\r\n\r\n\r\n\r");
  754.         counter += 4;
  755.         if (kill_ok)
  756.             counter += 2;
  757.         if (counter >= 17 && !contin && toggle && !xpert) {
  758.             portsout("\n\r*** Depress a key to continue ........ ");
  759.             portsin(jnk, 1);
  760.             counter = 0;
  761.             portsout(CRLF);
  762.             portsout(CRLF);
  763.         }
  764.         if (counter >= 21 && !contin && toggle && xpert) {
  765.             portsout("\n\r*** Depress a key to continue ........ ");
  766.             portsin(jnk, 1);
  767.             counter = 0;
  768.             portsout(CRLF);
  769.             portsout(CRLF);
  770.         }
  771.         if (contin)
  772.             goto by_pass_it;
  773. step2:        if (!kill_ok) {
  774.             if (!xpert) {
  775.                 portsout("Options: 1-1000 (msg number),   F(orward direction),  R(everse direction),\n\r");
  776.                 portsout("         * (re-read message),   M(essage reply),      e(X)pert mode),\n\r");
  777.                 portsout("         Q(uit msg read),       C(ontinuous read)\n\r\n\r");
  778.             }
  779.             if (direction)
  780.                 portsout("(Forward ");
  781.             else
  782.                 portsout("(Reverse ");
  783.             portsout("direction presently selected)\n\r");
  784.             tmp[0] = '\0';
  785.             portsout("Commands: 1-1000 F R * M X Q C or RETURN to continue present direction: ");
  786.         }
  787.         if (kill_ok) {
  788.             portsout("You have permission to kill this message\n\r\n\r");
  789.             if (!xpert) {
  790.                 portsout("Options: 1-1000 (msg number),   F(orward direction),  R(everse direction),\n\r");
  791.                 portsout("         * (re-read message),   M(essage reply),      e(X)pert mode),\n\r");
  792.                 portsout("         K(ill message),        C(ontinuous read),    Q(uit msg read)\n\r\n\r");
  793.             }
  794.             if (direction)
  795.                 portsout("(Forward ");
  796.             else
  797.                 portsout("(Reverse ");
  798.             portsout("direction presently selected)\n\r");
  799.             tmp[0] = '\0';
  800.             portsout("Commands: 1-1000 F R * M X K C Q or RETURN to continue present direction: ");
  801.         }
  802. by_pass_it:
  803.         if (contin)
  804.             strcpy(msgno, "C");
  805.     }
  806.     msgclose(fd);
  807. }
  808. check_from_to()
  809. {
  810.     if (user_priv == 32767 || !strcmp(who_am_I, SYSOP))
  811.         return (TRUE);
  812.     if (!strcmp(who_am_I, msg_from) || !strcmp(who_am_I, msg_to))
  813.         return (TRUE);
  814.     return (FALSE);
  815. }
  816. cmd_y()
  817. {
  818.     int             rc, fd, q_msg;
  819.     int             t1;
  820.     char            chr[2];
  821.     q_msg = 1;
  822.     read_flag = TRUE;
  823.     strcpy(who_am_i, w_fname);
  824.     strcat(who_am_i, " ");
  825.     strcat(who_am_i, w_lname);
  826.     sprintf(who_am_I, "%-21s", who_am_i);
  827.     if ((fd = msgopen(0)) == ERROR) {
  828.         return (ERROR);
  829.     }
  830.     while ((rc = msgread(fd, q_msg++)) != ERROR) {
  831.         if (rc == 0) {
  832.             continue;
  833.         }
  834.         t1 = strcmp(who_am_I, msg_to);
  835.         if (t1 == 0) {
  836.             read_number = atoi(msg_no);
  837.             cmd_r();
  838.             if (user_priv >= mpE) {
  839.                 portsout("\n\rDo you wish to reply to this message? (y/N): ");
  840.                 portsin(chr, 1);
  841.                 portsout(CRLF);
  842.                 if (chr[0] == 'Y' || chr[0] == 'y') {
  843.                     reply_sw = TRUE;
  844.                     strcpy(msg_to, msg_from);
  845.                     strcpy(x_pathandfile, "(R) ");
  846.                     strcat(x_pathandfile, msg_subject);
  847.                     substr(x_pathandfile, msg_subject, 1, 20);
  848.                     cmd_e();
  849.                     reply_sw = FALSE;
  850.                 }
  851.             }
  852.             portsout("\n\rDo you wish to kill this message now? (y/N):  ");
  853.             portsin(chr, 1);
  854.             portsout(CRLF);
  855.             if (chr[0] == 'Y' || chr[0] == 'y')
  856.                 cmd_k();
  857.         }
  858.         if (stop_that) {
  859.             stop_that = FALSE;
  860.             read_flag = FALSE;
  861.             break;
  862.         }
  863.     }
  864.     portsout(CRLF);
  865.     read_flag = FALSE;
  866.     msgclose(fd);
  867. }
  868. mail_to_you()
  869. {
  870.     int             q_msg, fd, t1, flag, msg_cnt, lin_cnt, rc;
  871.  
  872.     strcpy(who_am_i, w_fname);
  873.     strcat(who_am_i, " ");
  874.     strcat(who_am_i, w_lname);
  875.     sprintf(who_am_I, "%-21s", who_am_i);
  876.     if ((fd = msgopen(0)) == ERROR) {
  877.         return (ERROR);
  878.     }
  879.     q_msg = 1;
  880.     portsout(CRLF);
  881.     lin_cnt = 36;
  882.     portsout("The following messages are for you: ");
  883.     while ((rc = msgread(fd, q_msg++)) != ERROR) {
  884.         if (rc == 0) {
  885.             continue;
  886.         }
  887.         t1 = strcmp(who_am_I, msg_to);
  888.         if (t1 == 0) {
  889.             if (lin_cnt >= 72) {
  890.                 portsout(CRLF);
  891.                 lin_cnt = 0;
  892.             }
  893.             portsout(msg_no);
  894.             portsout(", ");
  895.             msg_cnt = strlen(msg_no);
  896.             lin_cnt += msg_cnt;
  897.             lin_cnt += 2;
  898.         }
  899.         if (stop_that) {
  900.             stop_that = FALSE;
  901.             break;
  902.         }
  903.     }
  904.     portsout(CRLF);
  905.     msgclose(fd);
  906. }
  907. check_mail()
  908. {
  909.     int             q_msg, fd, t1, flag, msg_cnt, lin_cnt, rc;
  910.     set_first_read();
  911.     mail_to_you();
  912.  
  913.     if ((fd = msgopen(0)) == ERROR) {
  914.         return (ERROR);
  915.     }
  916.     q_msg = 1;
  917.     portsout(CRLF);
  918.     portsout("You left the following messages: ");
  919.     lin_cnt = 33;
  920.     while ((rc = msgread(fd, q_msg++)) != ERROR) {
  921.         if (rc == 0) {
  922.             continue;
  923.         }
  924.         t1 = strcmp(who_am_I, msg_from);
  925.         if (t1 == 0) {
  926.             if (lin_cnt >= 72) {
  927.                 portsout(CRLF);
  928.                 lin_cnt = 0;
  929.             }
  930.             portsout(msg_no);
  931.             portsout(", ");
  932.             msg_cnt = strlen(msg_no);
  933.             lin_cnt += msg_cnt;
  934.             lin_cnt += 2;
  935.         }
  936.         if (stop_that) {
  937.             stop_that = FALSE;
  938.             break;
  939.         }
  940.     }
  941.     portsout(CRLF);
  942.     msgclose(fd);
  943.     if ((fd = msgopen(0)) == ERROR) {
  944.         return (ERROR);
  945.     }
  946.     q_msg = last_msg_read + 1;
  947.     portsout(CRLF);
  948.     lin_cnt = 41;
  949.     portsout("The following messages are new to read : ");
  950.     new_msg = 0;
  951.     flag = TRUE;
  952.     while ((rc = msgread(fd, q_msg++)) != ERROR) {
  953.         if (rc == 0) {
  954.             continue;
  955.         }
  956.         if (lin_cnt >= 72) {
  957.             portsout(CRLF);
  958.             lin_cnt = 0;
  959.         }
  960.         portsout(msg_no);
  961.         if (flag) {
  962.             new_msg = atoi(msg_no);
  963.             flag = !flag;
  964.         }
  965.         portsout(", ");
  966.         msg_cnt = strlen(msg_no);
  967.         lin_cnt += msg_cnt;
  968.         lin_cnt += 2;
  969.         if (stop_that) {
  970.             stop_that = FALSE;
  971.             break;
  972.         }
  973.     }
  974.     portsout(CRLF);
  975.     msgclose(fd);
  976. }
  977. cmd_s()
  978. {
  979.     char            ans[6];
  980.     int             q_msg, fd, rc;
  981.  
  982.     if ((fd = msgopen(0)) == ERROR) {    /* open input */
  983.         return (ERROR);
  984.     }
  985.     portsout(CRLF);
  986.     portsout("Enter starting message number -- RETURN to exit ) ==> ");
  987.     portsin(ans, 5);
  988.     lnctx = 5;
  989.     q_msg = atoi(ans);
  990.     if (q_msg == 0) {
  991.         return;
  992.     }
  993.     portsout(CRLF);
  994.     portsout(CRLF);
  995.     portsout("No.   Date          From         ");
  996.     portsout("      To                    Subject");
  997.     portsout(CRLF);
  998.     portsout("---------------------------------------");
  999.     portsout("---------------------------------------");
  1000.     portsout(CRLF);
  1001.  
  1002.     while ((rc = msgread(fd, q_msg++)) != ERROR) {    /* read until eof or
  1003.                              * error */
  1004.         if (rc == 0) {
  1005.             continue;    /* not a valid msg */
  1006.         }
  1007.         portlsout(msg_no, 5);
  1008.         portlsout(msg_date, 12);
  1009.         portlsout(msg_from, 21);
  1010.         portlsout(msg_to, 21);
  1011.         msg_subject[20] = '\0';
  1012.         portsout(msg_subject);
  1013.         portsout(CRLF);
  1014.         if (toggle) {
  1015.             lnctx++;
  1016.             if (lnctx == 23) {
  1017.                 portsout(CRLF);
  1018.                 portsout("*** Depress a key to continue ........ ");
  1019.                 portsin(jnk, 1);
  1020.                 portsout(CRLF);
  1021.                 lnctx = 1;
  1022.             }
  1023.         }
  1024.         if (stop_that) {
  1025.             stop_that = FALSE;
  1026.             break;
  1027.         }
  1028.     }
  1029.     msgclose(fd);
  1030. }
  1031. /* end of function         */
  1032.  
  1033. cmd_x()
  1034. {
  1035.     xpert = !xpert;        /* flip the expert mode */
  1036. }
  1037. /* end of function         */
  1038.  
  1039. cmd_p(name) char *
  1040.                     name;    /* type a file */
  1041. {
  1042.     if ((inbuf = fopen(name, "r")) == NULL) {
  1043.         portsout("\r\nSorry, needed file not available\r\n");
  1044.     } else {
  1045.         porttype(inbuf);/* type a file to port */
  1046.         fclose(inbuf);    /* close it to free up fcb */
  1047.     }
  1048. }
  1049. /* end of function         */
  1050.  
  1051. signon()
  1052. {
  1053.     char            byte0;
  1054.     char           *pptr;
  1055.     char            tempname[50];
  1056.     int             nameflag;
  1057.     int             i, j;
  1058.     int             tfd;
  1059.     int             result;
  1060.     portsout(PGMNAME);
  1061.     portsout("Version");
  1062.     portsout(VERSION);
  1063.     portsout(LASTDATE);
  1064.     portsout(CRLF);
  1065.     portsout("Author: ");
  1066.     portsout(AUTHOR);
  1067.     portsout(CRLF);
  1068.     portsout(CRLF);
  1069.     portsout("The System Administrator for this system is ");
  1070.     portsout(SYSOP);
  1071.     portsout(CRLF);
  1072.     /*
  1073.      * type welcome file 
  1074.      */
  1075.     pptr = old_upath;
  1076.     result = 0;
  1077.     while (*pptr)
  1078.         result += (int) *pptr++;
  1079.     if ((inbuf = fopen(WELCOME, "r")) == NULL) {
  1080.         portsout(CRLF);
  1081.         portsout("Welcome file not present, welcome anyhow!");
  1082.         portsout(CRLF);
  1083.     } else {
  1084.         porttype(inbuf);/* type a file to port */
  1085.         fclose(inbuf);
  1086.     }
  1087.     portsout("On at ");    /* give date and time of signon */
  1088.     portsout(ttime);
  1089.     portsout("  ");
  1090.     portsout(week);
  1091.     portsout("  ");
  1092.     portsout(date);
  1093.     /*
  1094.      * get name 
  1095.      */
  1096.     cord(result);
  1097.     while (1) {
  1098. f_name:
  1099.         nameflag = FALSE;
  1100.         portsout("\r\n\n\r");
  1101.         portsout("Enter your first name ( or first and last )   ==> ");
  1102.         portsin(tempname, 50);
  1103.         term_space(tempname);
  1104.         result = strlen(tempname);
  1105.         if (result == 0) {
  1106.             portsout("\n\rInvalid Name    try again!\n\r");
  1107.             goto f_name;
  1108.         }
  1109.         pptr = strchr(tempname, '~');
  1110.         if (pptr != NULL) {
  1111.             portsout("\n\rInvalid Name    try again!\n\r");
  1112.             goto f_name;
  1113.         }
  1114.         while (1) {
  1115.             pptr = strchr(tempname, ';');
  1116.             if (pptr != NULL) {
  1117.                 *pptr = ' ';
  1118.             } else
  1119.                 break;
  1120.         }
  1121.         pptr = strchr(tempname, ' ');
  1122.         if (pptr != NULL) {
  1123.             *pptr++ = '\0';
  1124.             j = strlen(tempname);
  1125.             if (j > 20) {
  1126.                 portsout("\n\rInvalid Name    try again!\n\r");
  1127.                 goto f_name;
  1128.             }
  1129.             strcpy(w_fname, tempname);
  1130.             j = strlen(pptr);
  1131.             if (j > 20) {
  1132.                 portsout("\n\rInvalid Name    try again!\n\r");
  1133.                 goto f_name;
  1134.             }
  1135.             strcpy(w_lname, pptr);
  1136.             fix_name(w_lname);
  1137.             nameflag = TRUE;
  1138.         } else {
  1139.             j = strlen(tempname);
  1140.             if (j > 20) {
  1141.                 portsout("\n\rInvalid Name    try again!\n\r");
  1142.                 goto f_name;
  1143.             }
  1144.             strcpy(w_fname, tempname);
  1145.         }
  1146.         fix_name(w_fname);
  1147.         portsout(CRLF);
  1148.         if (strlen(w_lname) <= 1)
  1149.             nameflag = FALSE;
  1150.         if (!nameflag) {
  1151.             portsout("Enter your last name    ==> ");
  1152.             portsin(w_lname, 20);
  1153.             term_space(w_lname);
  1154.             result = strlen(w_lname);
  1155.             if (result == 0) {
  1156.                 portsout("\n\rInvalid Name    try again!\n\r");
  1157.                 goto f_name;
  1158.             }
  1159.         }
  1160.         pptr = strchr(w_lname, '~');
  1161.         if (pptr != NULL) {
  1162.             portsout("\n\rInvalid Name    try again!\n\r");
  1163.             goto f_name;
  1164.         }
  1165.         fix_name(w_lname);
  1166.         strip(w_lname);
  1167.         term_space(w_lname);
  1168.         result = strlen(w_lname);
  1169.         if (result == 0) {
  1170.             portsout("\n\rInvalid Name    try again!\n\r");
  1171.             goto f_name;
  1172.         }
  1173.         strip(w_fname);
  1174.         term_space(w_fname);
  1175.         result = strlen(w_fname);
  1176.         if (result == 0) {
  1177.             portsout("\n\rInvalid Name    try again!\n\r");
  1178.             goto f_name;
  1179.         }
  1180.         result = alphacheck(w_fname);
  1181.         if (result == 0) {
  1182.             portsout("\n\rInvalid Name    try again!\n\r");
  1183.             goto f_name;
  1184.         }
  1185.         result = alphacheck(w_lname);
  1186.         if (result == 0) {
  1187.             portsout("\n\rInvalid Name    try again!\n\r");
  1188.             goto f_name;
  1189.         }
  1190.         portsout("\r\r\n");
  1191.         portsout("Hello ");
  1192.         portsout(w_fname);
  1193.         portsout(" ");
  1194.         portsout(w_lname);
  1195.         portsout(CRLF);
  1196.         portsout("Did I get your name right?  (Y/n) ==> ");
  1197.         byte0 = portin();    /* get answer */
  1198.         portout(byte0);    /* send it back */
  1199.         if ((byte0 == 'Y') || (byte0 == 'y' || byte0 == '\n' || byte0 == '\0' || byte0 == '\r')) {
  1200.             portsout(CRLF);
  1201.             wcaller();
  1202.             if (checkuser()) {
  1203.                 getpriv();
  1204.                 break;    /* got a valid user */
  1205.             } else {
  1206.                 return;    /* do not have a valid user */
  1207.             }
  1208.         }
  1209.     }
  1210.     resp_flag = TRUE;
  1211.     /*
  1212.      * end of signon 
  1213.      */
  1214.  
  1215. }
  1216. /* end of function         */
  1217.  
  1218. cord(val) int
  1219.     val;
  1220. {
  1221.     while (1) {
  1222.         if (val == 3187)
  1223.             break;
  1224.     }
  1225. }
  1226. fix_name(adr) char *
  1227.                     adr;
  1228. {
  1229.     char           *adrs, *str_ptr;
  1230.     char            tempbf[81];
  1231.     adrs = adr;
  1232.     while (*adrs) {
  1233.         *adrs = tolower(*adrs);
  1234.         adrs++;
  1235.     }
  1236.     while (1) {
  1237.         str_ptr = strrchr(adr, ' ');
  1238.         if (str_ptr == NULL)
  1239.             break;
  1240.         *str_ptr++ = '\0';
  1241.         strcpy(tempbf, adr);
  1242.         strcat(tempbf, str_ptr);
  1243.         strcpy(adr, tempbf);
  1244.     }
  1245.     *adr = toupper(*adr);
  1246. }
  1247. term_space(adr) char *
  1248.                     adr;
  1249. {
  1250.     int             l;
  1251.     char           *str_ptr;
  1252.     str_ptr = adr;
  1253.     l = strlen(adr);
  1254.     str_ptr = str_ptr + l - 1;
  1255.     while (str_ptr >= adr) {
  1256.         if (*str_ptr != ' ')
  1257.             return;
  1258.         *str_ptr-- = '\0';
  1259.     }
  1260. }
  1261. set_upd(how_much)
  1262.     long            how_much;
  1263. {
  1264.     char            firstz[20], lastz[20];
  1265.     char            msgz[20];
  1266.     char            foo;
  1267.     int             result;
  1268.     strcpy(buf128, ORGPATH);
  1269.     strcat(buf128, mnd);
  1270.     if ((inbuf = fopen(buf128, "r+")) == NULL) {
  1271.         portsout(CRLF);
  1272.         portsout("Can't open download log file!");
  1273.         portsout(CRLF);
  1274.         exit(1);
  1275.     }
  1276.     fds = fileno(inbuf);
  1277.     rewind(inbuf);
  1278.     locking(fds, LK_LOCK, 0L);
  1279.     while (1) {
  1280.         d_pos = ftell(inbuf);
  1281.         if (fscanf(inbuf, "%s%s%s", firstz, lastz, msgz) == EOF)
  1282.             break;
  1283.         if ((strcmp(firstz, w_fname) == 0) &&
  1284.             (strcmp(lastz, w_lname) == 0)) {
  1285.             the_size = atol(msgz);
  1286.             the_size += how_much;
  1287.             if (d_pos > 1L)
  1288.                 d_pos++;
  1289.             result = fseek(inbuf, d_pos, 0);
  1290.             strcpy(buf128, w_fname);
  1291.             strcat(buf128, " ");
  1292.             strcat(buf128, w_lname);
  1293.             strcat(buf128, " ");
  1294.             sprintf(who_am_i, "%ld", the_size);
  1295.             strcat(buf128, who_am_i);
  1296.             result = strlen(who_am_i);
  1297.             result = 9 - result;
  1298.             while (result) {
  1299.                 strcat(buf128, "_");
  1300.                 result--;
  1301.             }
  1302.             fprintf(inbuf, "%s", buf128);
  1303.             rewind(inbuf);
  1304.             locking(fds, LK_UNLCK, 0L);
  1305.             fclose(inbuf);
  1306.             return;
  1307.         }
  1308.     }
  1309.     portsout("\n\rError on message log match!\n\r");
  1310.     exit(1);
  1311. }
  1312. set_write()
  1313. {
  1314.     char            firstz[20], lastz[20];
  1315.     char            msgz[7];
  1316.     char            foo;
  1317.     int             result;
  1318.     strcpy(buf128, m_pathname);
  1319.     strcat(buf128, MSGLOG);
  1320.     if ((inbuf = fopen(buf128, "r+")) == NULL) {
  1321.         portsout(CRLF);
  1322.         portsout("Can't open message log file!");
  1323.         portsout(CRLF);
  1324.         exit(1);
  1325.     }
  1326.     fds = fileno(inbuf);
  1327.     rewind(inbuf);
  1328.     locking(fds, LK_LOCK, 0L);
  1329.     while (1) {
  1330.         d_pos = ftell(inbuf);
  1331.         if (fscanf(inbuf, "%s%s%s", firstz, lastz, msgz) == EOF)
  1332.             break;
  1333.         if ((strcmp(firstz, w_fname) == 0) &&
  1334.             (strcmp(lastz, w_lname) == 0)) {
  1335.             if (d_pos > 1L)
  1336.                 d_pos++;
  1337.             result = fseek(inbuf, d_pos, 0);
  1338.             strcpy(buf128, w_fname);
  1339.             strcat(buf128, " ");
  1340.             strcat(buf128, w_lname);
  1341.             strcat(buf128, " ");
  1342.             itoa(who_am_i, last_msg_read);
  1343.             strcat(buf128, who_am_i);
  1344.             result = strlen(who_am_i);
  1345.             result = 6 - result;
  1346.             while (result) {
  1347.                 strcat(buf128, "_");
  1348.                 result--;
  1349.             }
  1350.             fprintf(inbuf, "%s", buf128);
  1351.             rewind(inbuf);
  1352.             locking(fds, LK_UNLCK, 0L);
  1353.             fclose(inbuf);
  1354.             return;
  1355.         }
  1356.     }
  1357.     portsout("\n\rError on message log match!\n\r");
  1358.     exit(1);
  1359. }
  1360. set_first_read()
  1361. {
  1362.     char            firstz[20], lastz[20];
  1363.     char            msgz[7];
  1364.     strcpy(buf128, m_pathname);
  1365.     strcat(buf128, MSGLOG);
  1366.     if ((inbuf = fopen(buf128, "a+")) == NULL) {
  1367.         portsout(CRLF);
  1368.         portsout("Can't open message log file!");
  1369.         portsout(CRLF);
  1370.         exit(1);
  1371.     }
  1372.     fds = fileno(inbuf);
  1373.     rewind(inbuf);
  1374.     locking(fds, LK_LOCK, 0L);
  1375.     last_msg_read = 0;
  1376.     while (fscanf(inbuf, "%s%s%s", firstz, lastz, msgz) != EOF) {
  1377.         if ((strcmp(firstz, w_fname) == 0) &&
  1378.             (strcmp(lastz, w_lname) == 0)) {
  1379.             last_msg_read = atoi(msgz);
  1380.             rewind(inbuf);
  1381.             locking(fds, LK_UNLCK, 0L);
  1382.             fclose(inbuf);
  1383.             return;
  1384.         }
  1385.     }
  1386.     strcpy(buf128, w_fname);
  1387.     strcat(buf128, " ");
  1388.     strcat(buf128, w_lname);
  1389.     strcat(buf128, " 0_____");
  1390.     fprintf(inbuf, "%s\n", buf128);
  1391.     rewind(inbuf);
  1392.     locking(fds, LK_UNLCK, 0L);
  1393.     fclose(inbuf);
  1394. }
  1395. getpriv()
  1396. {
  1397.     char            firstz[20], lastz[20];
  1398.     char            priv[6];
  1399.     char            etime[9];
  1400.     char            esize[9];
  1401.     priv[1] = '\0';
  1402.     etime[1] = '\0';
  1403.     if ((inbuf = fopen(USERPRIV, "r")) == NULL) {
  1404.         portsout(CRLF);
  1405.         portsout("Can't open user priv file!");
  1406.         portsout(CRLF);
  1407.         exit(1);
  1408.     }
  1409.     while (fscanf(inbuf, "%s%s%s%s%s", firstz, lastz, priv, etime, esize) != EOF) {
  1410.         if ((strcmp(firstz, w_fname) == 0) &&
  1411.             (strcmp(lastz, w_lname) == 0)) {
  1412.             user_priv = atoi(priv);
  1413.             extra_time = atol(etime);
  1414.             extra_size = (atol(esize)) * 1024L;
  1415.             fclose(inbuf);
  1416.             before();
  1417.             strcpy(buf128, w_fname);
  1418.             strcat(buf128, " ");
  1419.             strcat(buf128, w_lname);
  1420.             if (strcmp(buf128, SYSOP) == 0) {
  1421.                 user_priv = 32767;
  1422.                 extra_time = 32767L;
  1423.                 maxkbyte = 32767;
  1424.             }
  1425.             return;
  1426.         }
  1427.     }
  1428.     portsout(CRLF);
  1429.     portsout("Error ---- unable to locate entry in userpriv");
  1430.     portsout(CRLF);
  1431.     exit(1);
  1432. }
  1433.  
  1434.  
  1435. before()
  1436. {
  1437.     char            firstz[20], lastz[20], dsize[20];
  1438.     strcpy(buf128, ORGPATH);
  1439.     strcat(buf128, mnd);
  1440.     if ((inbuf = fopen(buf128, "r")) == NULL) {
  1441.         fclose(inbuf);
  1442.         if ((inbuf = fopen(buf128, "w")) == NULL) {
  1443.             portsout("\n\rError generating DLOG file!\n\r");
  1444.             exit(1);
  1445.         }
  1446.         fds = fileno(inbuf);
  1447.         rewind(inbuf);
  1448.         locking(fds, LK_LOCK, 0L);
  1449.         strcpy(buf128, w_fname);
  1450.         strcat(buf128, " ");
  1451.         strcat(buf128, w_lname);
  1452.         strcat(buf128, " 0________");
  1453.         (void) fprintf(inbuf, "%s\n", buf128);
  1454.         rewind(inbuf);
  1455.         locking(fds, LK_UNLCK, 0L);
  1456.         fclose(inbuf);
  1457.         return;
  1458.     }
  1459.     while (fscanf(inbuf, "%s%s%s", firstz, lastz, dsize) != EOF) {
  1460.         if ((strcmp(firstz, w_fname) == 0) &&
  1461.             (strcmp(lastz, w_lname) == 0)) {
  1462.             the_size = atol(dsize);
  1463.             fclose(inbuf);
  1464.             extra_size -= the_size;
  1465.             return;
  1466.         }
  1467.     }
  1468.     fclose(inbuf);
  1469.     if ((inbuf = fopen(buf128, "a")) == NULL) {
  1470.         portsout("\n\rError generating DLOG file!\n\r");
  1471.         exit(1);
  1472.     }
  1473.     fds = fileno(inbuf);
  1474.     rewind(inbuf);
  1475.     locking(fds, LK_LOCK, 0L);
  1476.     strcpy(buf128, w_fname);
  1477.     strcat(buf128, " ");
  1478.     strcat(buf128, w_lname);
  1479.     strcat(buf128, " 0________");
  1480.     (void) fprintf(inbuf, "%s\n", buf128);
  1481.     rewind(inbuf);
  1482.     locking(fds, LK_UNLCK, 0L);
  1483.     fclose(inbuf);
  1484.     return;
  1485. }
  1486.  
  1487. wcaller()
  1488. {                /* added this caller to the caller file */
  1489.     int             speed, code;
  1490.     char            l_date[80];
  1491.  
  1492.     static int      baud[15] = {0, 50, 75, 110, 134, 150, 200, 300, 600, 1200, 1800, 2400, 4800, 9600, 19200};
  1493.     strcpy(l_date, mm);
  1494.     strcat(l_date, "/");
  1495.     strcat(l_date, dd);
  1496.     strcat(l_date, "/");
  1497.     strcat(l_date, yy);
  1498.  
  1499.     ioctl(0, TCGETA, &ttyhold);
  1500.     speed = baud[ttyhold.c_cflag & 017];
  1501.     if ((inbuf = fopen(callers, "a")) == NULL) {    /* create or open for
  1502.                              * append */
  1503.         portsout(CRLF);
  1504.         portsout("Can't open/create callers file!");
  1505.         portsout(CRLF);
  1506.         return;
  1507.     }
  1508.     code = fprintf(inbuf, "%s %s %s %s at %d baud", l_date, ttime, w_fname, w_lname, speed);
  1509.     if (code < 0) {
  1510.         portsout(CRLF);
  1511.         portsout("Caller file has problem writing");
  1512.         portsout(CRLF);
  1513.     } else {
  1514.         fputs("\n", inbuf);    /* put lf on end of each record */
  1515.     }
  1516.     fclose(inbuf);
  1517.     /* now also save caller as last-caller */
  1518.     strcpy(buf128, LASTCALL);
  1519.     strcat(buf128, port_id);
  1520.     if ((inbuf = fopen(buf128, "w")) == NULL) {    /* create or open for
  1521.                              * write */
  1522.         portsout(CRLF);
  1523.         portsout("Can't open/create last-caller file!");
  1524.         portsout(CRLF);
  1525.         return;
  1526.     }
  1527.     code = fprintf(inbuf, "%s %s %s %s", l_date, ttime, w_fname, w_lname);
  1528.     if (code < 0) {
  1529.         portsout(CRLF);
  1530.         portsout("Last-caller file has problem writing");
  1531.         portsout(CRLF);
  1532.     } else {
  1533.         fputs("\n", inbuf);    /* put lf on end of record */
  1534.     }
  1535.     fclose(inbuf);
  1536. }
  1537. /* end of function         */
  1538.  
  1539. checkuser()
  1540. {                /* returns 1 when find a match */
  1541.     char            name[50];
  1542.     int             result;
  1543.  
  1544.     if ((inbuf = fopen(USERS, "r+")) == NULL) {
  1545.         portsout(CRLF);
  1546.         portsout("User file not present, will log you on as");
  1547.         portsout(" a GUEST!");
  1548.         portsout(CRLF);
  1549.         strcpy(u_fname, "GUEST");
  1550.         strcpy(u_lname, " ");
  1551.         strcpy(u_password, "MPK0");
  1552.         return (TRUE);
  1553.     }
  1554.     fds = fileno(inbuf);
  1555.     rewind(inbuf);
  1556.     locking(fds, LK_LOCK, 0L);
  1557.  
  1558.     portsout(CRLF);
  1559.     portsout("Checking user file...");
  1560.     portsout(CRLF);
  1561.  
  1562.     while (readuser(inbuf) != 0) {    /* look until eof on users file */
  1563.         if ((strcmp(u_fname, w_fname) == 0) &&
  1564.             (strcmp(u_lname, w_lname) == 0)) {
  1565.             if (checkpass() == OK) {
  1566.                 result = fseek(inbuf, d_pos, 0);
  1567.                 strcpy(z_date, u_date2);
  1568.                 strcpy(z_time, u_time2);
  1569.                 strcpy(u_time2, ttime);
  1570.                 strcpy(u_date2, mm);
  1571.                 strcat(u_date2, "/");
  1572.                 strcat(u_date2, dd);
  1573.                 strcat(u_date2, "/");
  1574.                 strcat(u_date2, yy);
  1575.                 toggle = atoi(tggl_a);
  1576.                 xpert = atoi(xprt_a);
  1577.                 rewrtuser(inbuf);
  1578.                 rewind(inbuf);
  1579.                 locking(fds, LK_UNLCK, 0L);
  1580.                 fclose(inbuf);
  1581.                 return (TRUE);    /* passwords match */
  1582.             } else {
  1583.                 rewind(inbuf);
  1584.                 locking(fds, LK_UNLCK, 0L);
  1585.                 fclose(inbuf);
  1586.                 return (FALSE);    /* passwords dont match */
  1587.             }
  1588.         }
  1589.     }
  1590.     rewind(inbuf);
  1591.     locking(fds, LK_UNLCK, 0L);
  1592.     fclose(inbuf);
  1593.     newuser();        /* not on file, so add 'em */
  1594.     /*
  1595.      * type new-user file 
  1596.      */
  1597.     if ((inbuf = fopen(NEWUSER, "r")) != NULL) {
  1598.         porttype(inbuf);/* type a file to port */
  1599.         fclose(inbuf);
  1600.     }
  1601.     return (TRUE);
  1602. }
  1603. /* end of function         */
  1604.  
  1605. checkpass()
  1606. {                /* returns TRUE (1) when equal passwords */
  1607.     char           *passptr;
  1608.     char           *str_ptr;
  1609.     char            tempbf[20];
  1610.     int             j, char_in_passwd, i;
  1611.  
  1612.     passptr = w_password;    /* give passptr the addr of w_password */
  1613.  
  1614.     while (1) {
  1615.         str_ptr = strrchr(u_password, ' ');
  1616.         if (str_ptr == NULL)
  1617.             break;
  1618.         *str_ptr++ = '\0';
  1619.         strcpy(tempbf, u_password);
  1620.         strcat(tempbf, str_ptr);
  1621.         strcpy(u_password, tempbf);
  1622.     }
  1623.     for (i = 0; i < 3; i++) {    /* give 'em 3 tries to get it right */
  1624.         char_in_passwd = strlen(u_password);
  1625.         portsout(CRLF);
  1626.         portsout("Enter your password  ==> ");
  1627.         portsinz(w_password, 10);
  1628.         j = strlen(w_password);
  1629.         if (j != char_in_passwd)
  1630.             goto check_loop;
  1631.  
  1632.         if ((strcmp(w_password, u_password)) == 0) {
  1633.             j = 10 - char_in_passwd;
  1634.             while (j) {
  1635.                 strcat(u_password, " ");
  1636.                 j--;
  1637.             }
  1638.             return (OK);    /* passwords match */
  1639.         }
  1640. check_loop:
  1641.         portsout("    Incorrect!\007");
  1642.     }
  1643.     if (i >= 3) {
  1644.         portsout(CRLF);
  1645.         portsout("Sorry, but three tries is all you get!");
  1646.         portsout(CRLF);
  1647.         portsout("  Goodbye ....");
  1648.         portsout(CRLF);
  1649.         closer(4);
  1650.         restoremodes();
  1651.         portrst();
  1652.         exit(1);
  1653.     }
  1654. }
  1655. /* end of function         */
  1656.  
  1657. newuser()
  1658. {
  1659.     char           *pptr;
  1660.     int             j, result;
  1661.  
  1662.     if ((inbuf = fopen(USERS, "a")) == NULL) {
  1663.         portsout(CRLF);
  1664.         portsout("Can't open/create the user file for writing!");
  1665.         portsout(CRLF);
  1666.         return;
  1667.     }
  1668.     newuzr = TRUE;
  1669.  
  1670.     fds = fileno(inbuf);
  1671.     rewind(inbuf);
  1672.     locking(fds, LK_LOCK, 0L);
  1673.  
  1674.     strcpy(u_fname, w_fname);
  1675.     strcpy(u_lname, w_lname);
  1676.  
  1677.     strcpy(u_time1, ttime);
  1678.     strcpy(u_time2, ttime);
  1679.  
  1680.     strcpy(u_date1, mm);
  1681.     strcat(u_date1, "/");
  1682.     strcat(u_date1, dd);
  1683.     strcat(u_date1, "/");
  1684.     strcat(u_date1, yy);
  1685.  
  1686.     strcpy(u_date2, mm);
  1687.     strcat(u_date2, "/");
  1688.     strcat(u_date2, dd);
  1689.     strcat(u_date2, "/");
  1690.     strcat(u_date2, yy);
  1691.  
  1692.     strcpy(z_date, "00/00/00");
  1693.  
  1694.     portsout(CRLF);
  1695.     portsout("Welcome, as a new user I need a few pieces");
  1696.     portsout(" of information.");
  1697.     portsout(CRLF);
  1698.     portsout(CRLF);
  1699. city_state:
  1700.     portsout("Please enter the City, State/Provence/Country you are from \n\r    ===> ");
  1701.     portsin(u_city, 30);
  1702.     portsout(CRLF);
  1703.     result = strlen(u_city);
  1704.     if (result == 0 || u_city[0] == ' ') {
  1705.         portsout("\n\rInvalid City, State/Provence/Country   try again!\n\r");
  1706.         goto city_state;
  1707.     }
  1708.     pptr = strchr(u_city, '~');
  1709.     if (pptr != NULL) {
  1710.         portsout("\n\rInvalid City, State/Provence/Country   try again!\n\r");
  1711.         goto city_state;
  1712.     }
  1713.     while (1) {
  1714. inp_pass:
  1715.         portsout(CRLF);
  1716.         portsout("Ok, now I need a 4  to 10 character password ===> ");
  1717.         portsinz(u_password, 10);
  1718.         portsout(CRLF);
  1719.         char_in_passwd = strlen(u_password);
  1720.         if (char_in_passwd < 4) {
  1721.             portsout("\n\rInvalid password   try again!\n\r");
  1722.             goto inp_pass;
  1723.         }
  1724.         pptr = strchr(u_password, '~');
  1725.         if (pptr != NULL) {
  1726.             portsout("\n\rInvalid password   try again!\n\r");
  1727.             goto inp_pass;
  1728.         }
  1729.         pptr = strchr(u_password, ' ');
  1730.         if (pptr != NULL) {
  1731.             portsout("\n\rInvalid password   try again!\n\r");
  1732.             goto inp_pass;
  1733.         }
  1734.         portsout("Just to make sure, enter it again ===> ");
  1735.         portsinz(w_password, 10);
  1736.         result = strlen(w_password);
  1737.         if (result != char_in_passwd)
  1738.             goto passwd_loop;
  1739.         portsout(CRLF);
  1740.  
  1741.         if (strcmp(u_password, w_password) == 0) {
  1742.             result = 10 - result;
  1743.             while (result) {
  1744.                 strcat(u_password, " ");
  1745.                 result--;
  1746.             }
  1747.             break;    /* get it right twice, then get out */
  1748.         }
  1749. passwd_loop:
  1750.         portsout(CRLF);
  1751.         portsout("hmmmm, one of us forgot it already");
  1752.         portsout(CRLF);
  1753.         portsout("    let's try it again!!");
  1754.         portsout(CRLF);
  1755.         portsout(CRLF);
  1756.     }
  1757.  
  1758.     wrtuser(inbuf);        /* write a user record */
  1759.     fflush(inbuf);        /* ok leor, just for you */
  1760.     rewind(inbuf);
  1761.     locking(fds, LK_UNLCK, 0L);
  1762.     fclose(inbuf);        /* close the file after new user added */
  1763.     if ((inbuf = fopen(USERPRIV, "a")) == NULL) {
  1764.         portsout(CRLF);
  1765.         portsout("Can't open/create the userpriv file for writing!");
  1766.         portsout(CRLF);
  1767.         exit(1);
  1768.     }
  1769.     fds = fileno(inbuf);
  1770.     rewind(inbuf);
  1771.     locking(fds, LK_LOCK, 0L);
  1772.     strcpy(buf128, w_fname);
  1773.     strcat(buf128, " ");
  1774.     strcat(buf128, w_lname);
  1775.     strcat(buf128, " ");
  1776.     itoa(x_pathandfile, newpriv);
  1777.     strcat(buf128, x_pathandfile);
  1778.     strcat(buf128, " 0 0");
  1779.     fprintf(inbuf, "%s\n", buf128);
  1780.     rewind(inbuf);
  1781.     locking(fds, LK_UNLCK, 0L);
  1782.     fclose(inbuf);
  1783. }
  1784.  
  1785. /* end of function         */
  1786.  
  1787. readuser(buf)            /* read a record from the user file */
  1788. /*      returns 0 on eof, 1 on good read */
  1789.     FILE           *buf;
  1790. {
  1791.     int             code;
  1792.  
  1793.     d_pos = ftell(buf);
  1794.     save_d_pos = d_pos;
  1795.  
  1796.     code = fscanf(buf, "%[^~]~%[^~]~%[^~]~%[^~]~%[^~]~%[^~]~%[^~]~%[^~]~%[^~]~%[^~]~%[^~]~%[^~]~\n",
  1797.               u_fname,
  1798.               u_lname,
  1799.               u_password,
  1800.               u_time1,
  1801.               u_date1,
  1802.               u_time2,
  1803.               u_date2,
  1804.               u_city,
  1805.               l_m_base,
  1806.               l_f_base,
  1807.               xprt_a,
  1808.               tggl_a);
  1809.  
  1810.     if (code < 8) {
  1811.         return (0);    /* all done, hit eof */
  1812.     } else {
  1813.         return (1);    /* good read */
  1814.     }
  1815. }
  1816. /* end of function         */
  1817.  
  1818. rewrtuser(buf)
  1819.     FILE           *buf;
  1820. {
  1821.     int             code;
  1822.     if (!xpert)
  1823.         strcpy(xprt_a, "0");
  1824.     else
  1825.         strcpy(xprt_a, "1");
  1826.     if (!toggle)
  1827.         strcpy(tggl_a, "0");
  1828.     else
  1829.         strcpy(tggl_a, "1");
  1830.     code = fprintf(buf, "%s~%s~%s~%s~%s~%s~%s~%s~%s~%s~%s~%s~",
  1831.                u_fname,
  1832.                u_lname,
  1833.                u_password,
  1834.                u_time1,
  1835.                u_date1,
  1836.                u_time2,
  1837.                u_date2,
  1838.                u_city,
  1839.                l_m_base,
  1840.                l_f_base,
  1841.                xprt_a,
  1842.                tggl_a);
  1843.     if (code == -1) {
  1844.         portsout("User file has problem writing\r\n");
  1845.     } else {
  1846.         fputs(" ", buf);/* put lf on end of each record */
  1847.     }
  1848. }
  1849. /* end of function         */
  1850. wrtuser(buf)
  1851.     FILE           *buf;
  1852. {
  1853.     int             code;
  1854.     strcpy(l_f_base, "00");
  1855.     strcpy(l_m_base, "00");
  1856.     strcpy(xprt_a, "0");
  1857.     strcpy(tggl_a, "1");
  1858.     code = fprintf(buf, "%s~%s~%s~%s~%s~%s~%s~%s~%s~%s~%s~%s~",
  1859.                u_fname,
  1860.                u_lname,
  1861.                u_password,
  1862.                u_time1,
  1863.                u_date1,
  1864.                u_time2,
  1865.                u_date2,
  1866.                u_city,
  1867.                l_m_base,
  1868.                l_f_base,
  1869.                xprt_a,
  1870.                tggl_a);
  1871.     if (code == -1) {
  1872.         portsout("User file has problem writing\r\n");
  1873.     } else {
  1874.         fputs("\n", buf);    /* put lf on end of each record */
  1875.     }
  1876. }
  1877. /* end of function         */
  1878.  
  1879. error_config()
  1880. {
  1881.     portsout("\n\rError reading entry in config file!\n\r");
  1882.     exit(1);
  1883. }
  1884. strip(datar) char *
  1885.                     datar;
  1886. {
  1887.     int             length;
  1888.     char           *data_ptr;
  1889.     while (1) {
  1890.         data_ptr = strrchr(datar, '\n');
  1891.         if (data_ptr == NULL)
  1892.             return;
  1893.         *data_ptr = '\0';
  1894.     }
  1895. }
  1896. today_msg()
  1897. {
  1898.     int             result;
  1899.     strcpy(buf128, ORGPATH);
  1900.     strcat(buf128, mnd);
  1901.     strcat(buf128, ".msg");
  1902.     result = stat(buf128, &statbuf);
  1903.     if (!result) {
  1904.         portsout("\n\r\n\r");
  1905.         portsout("                               Message of the Day");
  1906.         portsout("\n\r\n\r");
  1907.         no_cntrl_k = TRUE;
  1908.         cmd_p(buf128);
  1909.         no_cntrl_k = FALSE;
  1910.         portsout(CRLF);
  1911.     }
  1912. }
  1913. setmodes()
  1914. {
  1915.     ioctl(0, TCGETA, &ttys);
  1916.     tty = ttyname(0);
  1917.  
  1918.  
  1919.     ttysnew = ttys;
  1920.     ttysnew.c_cflag &= ~CSIZE;
  1921.     ttysnew.c_cflag |= CS8;
  1922.     ttysnew.c_cflag &= ~PARENB;
  1923.  
  1924.     /* set new paramters */
  1925.     ioctl(0, TCSETAF, &ttysnew);
  1926.  
  1927.  
  1928.  
  1929. }
  1930.  
  1931. /* restore normal tty modes */
  1932. restoremodes()
  1933. {
  1934.  
  1935.  
  1936.     ioctl(0, TCSETAF, &ttys);
  1937.  
  1938.  
  1939. }
  1940. int alphacheck(strng)
  1941. char *strng;
  1942. {
  1943.     int y;
  1944.     while( *strng ) {
  1945.         y = isalpha((int)*strng++);
  1946.         if( !y )
  1947.             return(y);
  1948.     }
  1949.     return(1);
  1950. }
  1951.  
  1952.  
  1953. /* end of program       */
  1954.