home *** CD-ROM | disk | FTP | other *** search
/ Usenet 1994 January / usenetsourcesnewsgroupsinfomagicjanuary1994.iso / sources / misc / volume32 / xbbs / part01 / bbsc1.c.B next >
Text File  |  1992-09-08  |  44KB  |  1,802 lines

  1. file_loc( strg )
  2. char *strg;
  3. {
  4.     int             result;
  5.     int             i;
  6.     int             zz;
  7.     int             outok;
  8.     int             len_in, len_file, times;
  9.     long            foo;
  10.     char            timeptr[30];
  11.     char           *fileptr;
  12.     char            temp[15];
  13.     char            string_loc[20];
  14.     int             lnctx, xp;
  15.     
  16.     if (xpert)
  17.         xp = 10;
  18.     else
  19.         xp = 5;
  20.  
  21.  
  22.     lnctx = 1;
  23.     substr(z_date, z_mm, 1, 2);
  24.     substr(z_date, z_dd, 4, 2);
  25.     substr(z_date, z_yy, 7, 2);
  26.     xmm = atol(z_mm);
  27.     xdd = atol(z_dd);
  28.     xyy = atol(z_yy);
  29.     foo = atol(yy);
  30.     outok = FALSE;
  31.     old_long_date = (xyy * 10000L) + (xmm * 100L) + xdd;
  32.     if( strg == NULL) {
  33.         portsout("\n\r\n\rInput file name substring (max 14 characters): ");
  34.         portsin(string_loc, 14);
  35.         portsout(CRLF);
  36.         fileptr = strchr(string_loc, '*');
  37.         if( fileptr != NULL ) {
  38.             portsout("\n\rDo not use an asterisk as part of the string.\n\r\n\r");
  39.             return;
  40.         }
  41.     } else {
  42.         strcpy(string_loc, strg );
  43.     }
  44.     len_in = strlen(string_loc);
  45.     if (!len_in)
  46.         return;
  47.     strcpy(buf128, f_pathname);
  48.     strcat(buf128, FILES);
  49.     if ((rdstatbuf = fopen(buf128, "r")) == NULL) {
  50.         portsout("\n\rThe are NO files available!\n\r");
  51.         return;
  52.     }
  53.     msgck();
  54.     portsout("\n\rSearching for a comparison\n\r\n\r");
  55.     while (fscanf(rdstatbuf, "%14s", x_filename) != EOF) {
  56.         zz = 0;
  57.         if (x_filename[0] == '~') {
  58.             goto finisx;    /* Special case so that that
  59.                      * following files are not displayed
  60.                      * - can be used to disallow uploads
  61.                      * from being shown until they are
  62.                      * validated. */
  63.         }
  64.         if (x_filename[0] == '+') {
  65.             fileptr = x_filename + 1;
  66.             strcpy(work_msg, fileptr);
  67.             (void) fgets(buf128, 80, rdstatbuf);
  68.             goto xend;
  69.         }
  70.         if (x_filename[0] == '.') {
  71.             strcpy(x_filename, "   ");
  72.             strcpy(who_am_i, "   ");
  73.             strcpy(who_am_I, "   ");
  74.             zz++;
  75.         }
  76.         if (result = fgets(buf128, 55, rdstatbuf) == NULL) {
  77.             if (!zz)
  78.                 strcpy(buf128, " ***** No description on file *****");
  79.         }
  80.         strip(buf128);
  81.         if (!zz)
  82.             term_space(buf128);
  83.         result = strlen(buf128);
  84.         if (result == 0) {
  85.             if (!zz)
  86.                 strcpy(buf128, " ***** No description on file *****");
  87.         }
  88.         if (!zz) {
  89.             len_file = strlen(x_filename);
  90.             if (len_file < len_in) {
  91.                 outok = FALSE;
  92.                 goto xend;
  93.             }
  94.             strcpy(x_pathandfile, f_pathname);
  95.             strcat(x_pathandfile, x_filename);
  96.             result = stat(x_pathandfile, &statbuf);
  97.             if (result != 0) {
  98.                 strcpy(who_am_i, "OFFLINE");
  99.                 strcpy(who_am_I, "    ");
  100.                 outok = FALSE;
  101.                 goto xend;
  102.             }
  103.             xmm = statbuf.st_size;
  104.             sprintf(who_am_i, "%6ld", xmm);
  105.             xmm = statbuf.st_mtime;
  106.             strcpy(timeptr, ctime(&xmm));
  107.             substr(timeptr, bufx, 5, 6);
  108.             strcpy(who_am_I, bufx);
  109.             substr(timeptr, bufx, 5, 3);
  110.             substr(timeptr, z_dd, 9, 2);
  111.             substr(timeptr, z_yy, 23, 2);
  112.             xdd = atol(z_dd);
  113.             xyy = atol(z_yy);
  114.             if (foo > xyy) {
  115.                 strcpy(who_am_I, bufx);
  116.                 strcat(who_am_I, "-");
  117.                 strcat(who_am_I, z_yy);
  118.             }
  119.             times = len_file - len_in + 1;
  120.             outok = FALSE;
  121.             for (result = 1; result <= times; result++) {
  122.                 substr(x_filename, temp, result, len_in);
  123.                 if (strcmp(temp, string_loc) == 0) {
  124.                     outok = TRUE;
  125.                     break;
  126.                 }
  127.             }
  128.         }
  129.         if (!outok)
  130.             goto xend;
  131.         sprintf(work_msg, "%-15s%-7s%-6s%-50s", x_filename, who_am_i, who_am_I, buf128);
  132.         strip(work_msg);
  133.         term_space(work_msg);
  134.  
  135.         sprintf(buf128, "%s\n\r", work_msg);
  136.         portsout(buf128);
  137.         if (stop_that) {
  138.             fclose(rdstatbuf);
  139.             stop_that = FALSE;
  140.             return;
  141.         }
  142.         if (toggle) {
  143.             lnctx++;
  144.             if (lnctx == 23) {
  145.                 portsout(CRLF);
  146.                 portsout("*** Depress a key to continue ( control-k to quit ) ........ ");
  147.                 jnk[0] = portin();
  148.                 if (jnk[0] == CTL_K || stop_that) {
  149.                     stop_that = FALSE;
  150.                     fclose(rdstatbuf);
  151.                     return;
  152.                 }
  153.                 portsout(CRLF);
  154.                 lnctx = 1;
  155.             }
  156.         }
  157. xend:
  158.         ;
  159.     }
  160. finisx:
  161.     fclose(rdstatbuf);
  162.     if (toggle && lnctx > xp) {
  163.         portsout(CRLF);
  164.         portsout("*** Depress a key to continue ........ ");
  165.         jnk[0] = portin();
  166.         portsout(CRLF);
  167.     }
  168.     portsout(CRLF);
  169.     portsout(CRLF);
  170. }
  171. file_n()
  172. {
  173.     int             result;
  174.     int             i;
  175.     int             zz;
  176.     int             outok;
  177.     long            foo;
  178.     char            timeptr[30];
  179.     char           *fileptr;
  180.     int             lnctx, xp;
  181.     static char    *dates[] = {"Jan", "Feb", "Mar", "Apr", "May", "Jun",
  182.                  "Jul", "Aug", "Sep", "Oct", "Nov", "Dec",};
  183.     substr(z_date, z_mm, 1, 2);
  184.     substr(z_date, z_dd, 4, 2);
  185.     substr(z_date, z_yy, 7, 2);
  186.     lnctx = 1;
  187.     if (xpert)
  188.         xp = 10;
  189.     else
  190.         xp = 5;
  191.     xmm = atol(z_mm);
  192.     xdd = atol(z_dd);
  193.     xyy = atol(z_yy);
  194.     foo = atol(yy);
  195.     outok = FALSE;
  196.     old_long_date = (xyy * 10000L) + (xmm * 100L) + xdd;
  197.     strcpy(buf128, f_pathname);
  198.     strcat(buf128, FILES);
  199.     if ((rdstatbuf = fopen(buf128, "r")) == NULL) {
  200.         portsout("\n\rThe are NO files available!\n\r");
  201.         return;
  202.     }
  203.     strcpy(buf128, TMPFILE);
  204.     strcat(buf128, port_id);
  205.     msgck();
  206.     portsout("\n\rStarting the new file search.\n\r\n\r");
  207.     while (fscanf(rdstatbuf, "%14s", x_filename) != EOF) {
  208.         zz = 0;
  209.         if (x_filename[0] == '~') {
  210.             goto finisn;    /* Special case so that that
  211.                      * following files are not displayed
  212.                      * - can be used to disallow uploads
  213.                      * from being shown until they are
  214.                      * validated. */
  215.         }
  216.         if (x_filename[0] == '+') {
  217.             fileptr = x_filename + 1;
  218.             strcpy(work_msg, fileptr);
  219.             (void) fgets(buf128, 80, rdstatbuf);
  220.             goto nend;
  221.         }
  222.         if (x_filename[0] == '.') {
  223.             strcpy(x_filename, "   ");
  224.             strcpy(who_am_i, "   ");
  225.             strcpy(who_am_I, "   ");
  226.             zz++;
  227.         }
  228.         if (result = fgets(buf128, 55, rdstatbuf) == NULL) {
  229.             if (!zz)
  230.                 strcpy(buf128, " ***** No description on file *****");
  231.         }
  232.         strip(buf128);
  233.         if (!zz)
  234.             term_space(buf128);
  235.         result = strlen(buf128);
  236.         if (result == 0) {
  237.             if (!zz)
  238.                 strcpy(buf128, " ***** No description on file *****");
  239.         }
  240.         if (!zz) {
  241.             strcpy(x_pathandfile, f_pathname);
  242.             strcat(x_pathandfile, x_filename);
  243.             result = stat(x_pathandfile, &statbuf);
  244.             if (result != 0) {
  245.                 strcpy(who_am_i, "OFFLINE");
  246.                 strcpy(who_am_I, "    ");
  247.                 outok = FALSE;
  248.                 goto nend;
  249.             }
  250.             xmm = statbuf.st_size;
  251.             sprintf(who_am_i, "%6ld", xmm);
  252.             xmm = statbuf.st_mtime;
  253.             strcpy(timeptr, ctime(&xmm));
  254.             substr(timeptr, bufx, 5, 6);
  255.             strcpy(who_am_I, bufx);
  256.             substr(timeptr, bufx, 5, 3);
  257.             substr(timeptr, z_dd, 9, 2);
  258.             substr(timeptr, z_yy, 23, 2);
  259.             xdd = atol(z_dd);
  260.             xyy = atol(z_yy);
  261.             if (foo > xyy) {
  262.                 strcpy(who_am_I, bufx);
  263.                 strcat(who_am_I, "-");
  264.                 strcat(who_am_I, z_yy);
  265.             }
  266.             for (result = 0; result < 12; result++) {
  267.                 i = strcmp(bufx, dates[result]);
  268.                 if (!i) {
  269.                     xmm = (long) result + 1;
  270.                     new_long_date = (xyy * 10000L) + (xmm * 100L) + xdd;
  271.                     if (new_long_date < old_long_date) {
  272.                         outok = FALSE;
  273.                         goto nend;
  274.                     }
  275.                     outok = TRUE;
  276.                     break;
  277.                 }
  278.             }
  279.  
  280.         }
  281.         if (!outok)
  282.             goto nend;
  283. aroundn:
  284.         sprintf(work_msg, "%-15s%-7s%-6s%-50s", x_filename, who_am_i, who_am_I, buf128);
  285. arondn:
  286.         strip(work_msg);
  287.         term_space(work_msg);
  288.  
  289.         sprintf(buf128, "%s\n\r", work_msg);
  290.         portsout(buf128);
  291.         if (stop_that) {
  292.             fclose(rdstatbuf);
  293.             stop_that = FALSE;
  294.             return;
  295.         }
  296.         if (toggle) {
  297.             lnctx++;
  298.             if (lnctx == 23) {
  299.                 portsout(CRLF);
  300.                 portsout("*** Depress a key to continue ( control-k to quit ) ........ ");
  301.                 jnk[0] = portin();
  302.                 if (jnk[0] == CTL_K || stop_that) {
  303.                     stop_that = FALSE;
  304.                     fclose(rdstatbuf);
  305.                     return;
  306.                 }
  307.                 portsout(CRLF);
  308.                 lnctx = 1;
  309.             }
  310.         }
  311. nend:
  312.         ;
  313.     }
  314. finisn:
  315.     fclose(rdstatbuf);
  316. finisln:
  317.     if (toggle && lnctx > xp) {
  318.         portsout(CRLF);
  319.         portsout("*** Depress a key to continue ........ ");
  320.         jnk[0] = portin();
  321.         portsout(CRLF);
  322.     }
  323.     portsout(CRLF);
  324.     portsout(CRLF);
  325. }
  326. file_u()
  327. {
  328.     char            choic1[2], *str_result;
  329.     FILE           *storbuff;
  330.     int             result, tryit, tryit1, code;
  331. fileu:
  332.     tryit = FALSE;
  333.     tryit1 = FALSE;
  334.     if_kermit = 0;
  335.     portsout("\n\rYour usage time will be STOPPED during uploads and \n\r");
  336.     portsout("the size of the file(s) will be added to your limit.\n\r");
  337.     portsout(CRLF);
  338.     portsout("Input filename for upload:  ");
  339.     portsin(x_filename, 15);
  340.     if (strlen(x_filename) < 1)
  341.         return;
  342.     if (x_filename[0] == '.' || x_filename[0] == '/' || x_filename[0] == ' ') {
  343.         portsout("\n\r\n\rIllegal Filename!\n\r");
  344.         return;
  345.     }
  346.     code = strlen(x_filename);
  347.     code--;
  348.     if (x_filename[code] == '.' || x_filename[code] == '/' || x_filename[code] == ' ') {
  349.         portsout("\n\r\n\rIllegal Filename! \n\r");
  350.         return;
  351.     }
  352.     code = strcmp(x_filename, "files.bbs");
  353.     if (code == 0) {
  354.         portsout("\n\r\n\rIllegal Filename! \n\r");
  355.         return;
  356.     }
  357.     code = legalname("|`><!;:", x_filename);
  358.     if (code == 0) {
  359.         portsout("\n\r\n\rIllegal Filename! \n\r");
  360.         return;
  361.     }
  362.     portsout(CRLF);
  363.     str_result = strchr(x_filename, '*');
  364.     if (str_result != NULL)
  365.         tryit = TRUE;
  366.     strcpy(x_pathandfile, u_pathname);
  367.     strcat(x_pathandfile, x_filename);
  368.     if (!tryit) {
  369.         result = stat(x_pathandfile, &statbuf);
  370.         if (result == 0) {
  371.             portsout("That file already exists!\n\r");
  372.             return;
  373.         }
  374.     }
  375.     portsout(CRLF);
  376.     if ( tryit ) {
  377.         portsout("Options: K(ermit),  B(atch ymodem),  Z(modem),\n\r\n\r");
  378.         portsout("Commands: K,B,Z  ===> ");
  379.     }
  380.     else {
  381.         portsout("Options: X(modem), C(rc xmodem), B(atch ymodem), Y(modem), Z(modem),\n\r");
  382.         portsout("         K(ermit), S(EAlink),    A(scii)\n\r\n\r");
  383.         portsout("Commands: X,C,B,Y,Z,K,S,A  ===> ");
  384.     }
  385.     portsin(choic1, 1);
  386.     portsout(CRLF);
  387.     *choic1 = toupper(*choic1);
  388.     if ((inbuf = fopen(callers, "a")) == NULL) {    /* create or open for
  389.                              * append */
  390.         portsout(CRLF);
  391.         portsout("Can't open/create callers file!");
  392.         portsout(CRLF);
  393.         return;
  394.     }
  395.     code = fprintf(inbuf, "%s %s  ", "   UPLOAD  ", x_filename);
  396.     if (code < 0) {
  397.         portsout(CRLF);
  398.         portsout("Caller file has problem writing");
  399.         portsout(CRLF);
  400.     } 
  401.     fclose(inbuf);
  402.     if (choic1[0] == 'K' || choic1[0] == 'B' || choic1[0] == 'Z')
  403.         tryit1 = TRUE;
  404.     if (tryit && !tryit1) {
  405.         portsout("\n\rIllegal use of wildcards - Must be KERMIT, YMODEM BATCH, or ZMODEM\n\r");
  406.         typexfr(11);
  407.         return;
  408.     }
  409.     switch (choic1[0]) {
  410.     case ('X'):
  411.         strcpy(x_pathandfile, RB);
  412.         strcat(x_pathandfile, u_pathname);
  413.         strcat(x_pathandfile, x_filename);
  414.         typexfr(5);
  415.         uploadtime();
  416.         result = system(x_pathandfile);
  417.         restoresig();
  418.         updatef();
  419.         enabletime();
  420.         break;
  421.     case ('Y'):
  422.         strcpy(x_pathandfile, YMDR);
  423.         strcat(x_pathandfile, u_pathname);
  424.         strcat(x_pathandfile, x_filename);
  425.         typexfr(3);
  426.         uploadtime();
  427.         result = system(x_pathandfile);
  428.         restoresig();
  429.         updatef();
  430.         enabletime();
  431.         break;
  432.     case ('C'):
  433.         strcpy(x_pathandfile, CRCR);
  434.         strcat(x_pathandfile, u_pathname);
  435.         strcat(x_pathandfile, x_filename);
  436.         typexfr(4);
  437.         uploadtime();
  438.         result = system(x_pathandfile);
  439.         restoresig();
  440.         updatef();
  441.         enabletime();
  442.         break;
  443.     case ('S'):
  444.         strcpy(x_pathandfile, SEAR);
  445.         strcat(x_pathandfile, u_pathname);
  446.         strcat(x_pathandfile, x_filename);
  447.         typexfr(7);
  448.         uploadtime();
  449.         result = system(x_pathandfile);
  450.         restoresig();
  451.         updatef();
  452.         enabletime();
  453.         break;
  454.     case ('A'):
  455.         strcpy(x_pathandfile, u_pathname);
  456.         strcat(x_pathandfile, x_filename);
  457.         typexfr(8);
  458.         if ((storbuff = fopen(x_pathandfile, "w")) == NULL) {
  459.             portsout("\n\rError opening upload file!\n\r");
  460.             break;
  461.         }
  462.         fds = fileno(storbuff);
  463.         rewind(storbuff);
  464.         locking(fds, LK_LOCK, 0L);
  465.         portsout("\n\rTerminate the ASCII upload with a control d ( ^d )");
  466.         portsout("\n\rReady to receive ASCII upload....\n\r");
  467.         uploadtime();
  468.  
  469.         restoremodes();
  470.         portrst();
  471.  
  472.         while ((fgets(buf128, 132, stdin)) != NULL) {
  473.             result = fputs(buf128, storbuff);
  474.         }
  475.         rewind(storbuff);
  476.         locking(fds, LK_UNLCK, 0L);
  477.         fclose(storbuff);
  478.  
  479.         portinit();
  480.         setmodes();
  481.  
  482.         updatef();
  483.         enabletime();
  484.         break;
  485.     case ('B'):
  486.         strcpy(x_pathandfile, YMR);
  487.         portsout("Please start your YMODEM transfer");
  488.         portsout(CRLF);
  489.         if_kermit = 1;
  490.         typexfr(2);
  491.         uploadtime();
  492.         result = system(x_pathandfile);
  493.         restoresig();
  494.         strcpy(x_pathandfile, KRE);
  495.         result = system(x_pathandfile);
  496.         if ((rdstatbuf = fopen(FLIST, "r")) == NULL) {
  497.             portsout("\n\rERROR: Unable to update!\n\r");
  498.             exit(1);
  499.         }
  500.         while (fscanf(rdstatbuf, "%14s", x_filename) != EOF) {
  501.             strcpy(x_pathandfile, u_pathname);
  502.             strcat(x_pathandfile, x_filename);
  503.             result = stat(x_pathandfile, &statbuf);
  504.             if (result != 0) {
  505.                 updatef();
  506.             } else {
  507.                 portsout(CRLF);
  508.                 portsout(x_filename);
  509.                 portsout(":  Duplicate file deleted!\n\r");
  510.                 strcpy(x_pathandfile, USRBBS);
  511.                 strcat(x_pathandfile, x_filename);
  512.                 result = unlink(x_pathandfile);
  513.             }
  514.         }
  515.         enabletime();
  516.         fclose(rdstatbuf);
  517.         break;
  518.     case ('K'):
  519.         strcpy(x_pathandfile, KRA);
  520.         portsout("Please start your KERMIT transfer");
  521.         portsout(CRLF);
  522.         if_kermit = 1;
  523.         typexfr(6);
  524.         uploadtime();
  525.         result = system(x_pathandfile);
  526.         restoresig();
  527.         strcpy(x_pathandfile, KRE);
  528.         result = system(x_pathandfile);
  529.         if ((rdstatbuf = fopen(FLIST, "r")) == NULL) {
  530.             portsout("\n\rERROR: Unable to update!\n\r");
  531.             exit(1);
  532.         }
  533.         while (fscanf(rdstatbuf, "%14s", x_filename) != EOF) {
  534.             strcpy(x_pathandfile, u_pathname);
  535.             strcat(x_pathandfile, x_filename);
  536.             result = stat(x_pathandfile, &statbuf);
  537.             if (result != 0) {
  538.                 updatef();
  539.             } else {
  540.                 portsout(CRLF);
  541.                 portsout(x_filename);
  542.                 portsout(":  Duplicate file deleted!\n\r");
  543.                 strcpy(x_pathandfile, USRBBS);
  544.                 strcat(x_pathandfile, x_filename);
  545.                 result = unlink(x_pathandfile);
  546.             }
  547.         }
  548.         enabletime();
  549.         fclose(rdstatbuf);
  550.         break;
  551.     case ('Z'):
  552.         strcpy(x_pathandfile, RZ);
  553.         portsout("Please start your ZMODEM transfer");
  554.         portsout(CRLF);
  555.         if_kermit = 1;
  556.         typexfr(1);
  557.         uploadtime();
  558.         result = system(x_pathandfile);
  559.         restoresig();
  560.         strcpy(x_pathandfile, KRE);
  561.         result = system(x_pathandfile);
  562.         if ((rdstatbuf = fopen(FLIST, "r")) == NULL) {
  563.             portsout("\n\rERROR: Unable to update!\n\r");
  564.             exit(1);
  565.         }
  566.         while (fscanf(rdstatbuf, "%14s", x_filename) != EOF) {
  567.             strcpy(x_pathandfile, u_pathname);
  568.             strcat(x_pathandfile, x_filename);
  569.             result = stat(x_pathandfile, &statbuf);
  570.             if (result != 0) {
  571.                 updatef();
  572.             } else {
  573.                 portsout(CRLF);
  574.                 portsout(x_filename);
  575.                 portsout(":  Duplicate file deleted!\n\r");
  576.                 strcpy(x_pathandfile, USRBBS);
  577.                 strcat(x_pathandfile, x_filename);
  578.                 result = unlink(x_pathandfile);
  579.             }
  580.         }
  581.         enabletime();
  582.         fclose(rdstatbuf);
  583.         break;
  584.     default:
  585.         portsout("Illegal option");
  586.         portsout(CRLF);
  587.         typexfr(11);
  588.         break;
  589.     }
  590.     portsout(CRLF);
  591. }
  592. uploadtime()
  593. {
  594.     xsec = alarm(0);
  595.     Ztime = xsec;
  596.     alarm(32767);
  597. }
  598. enabletime()
  599. {
  600.     sec = xsec;
  601.     alarm(sec);
  602. }
  603. digit(datr) char *
  604.                     datr;
  605. {
  606.     int             res;
  607.     char           *datr1;
  608.     datr1 = datr;
  609.     while (*datr1) {
  610.         res = *datr1;
  611.         if (!isdigit(res))
  612.             *datr1 = ' ';
  613.         datr1++;
  614.     }
  615. }
  616.  
  617.  
  618. updatef()
  619. {
  620.     /*
  621.      * The following modifications to "updatef()" allow you to have
  622.      * MAX_DEC_LINES lines of description for uploaded files instead of
  623.      * just one. 
  624.      */
  625. #define MAX_DESC_LINES  5
  626.     int             code;
  627.     int             index, index2;
  628.     char            buf50[MAX_DESC_LINES][51], tmp[51];
  629.  
  630.     if (if_kermit == 0) {
  631.         strcpy(buf128, u_pathname);
  632.     } else {
  633.         strcpy(buf128, USRBBS);
  634.     }
  635.     strcat(buf128, x_filename);
  636.     (void) stat(buf128, &statbuf);
  637.     if (statbuf.st_size == ((off_t) 0)) {
  638.         unlink(buf128);
  639.         return;
  640.     }
  641.     max_dload += statbuf.st_size;
  642.     set_upd(-statbuf.st_size);
  643.     portsout(CRLF);
  644.     portsout("Please describe ");
  645.     portsout(x_filename);
  646.     sprintf(tmp, "    ( max of 50 characters on %d lines ) ", MAX_DESC_LINES);
  647.     portsout(tmp);
  648.     portsout(CRLF);
  649.     portsout("NOTE: NO WORD WRAP.  Please watch how long your lines are!!");
  650.     portsout(CRLF);
  651.     portsout("Start with a / on line 1 for SYSOP ONLY!");
  652.     portsout(CRLF);
  653.     portsout("  ---------1---------2---------3---------4---------5");
  654.     portsout(CRLF);
  655.     index = 1;
  656.     sprintf(tmp, "%1d:", index);
  657.     portsout(tmp);
  658.     portsin(buf50[0], 50);
  659.     portsout(CRLF);
  660.     while ((buf50[(index - 1)][0] != '\0') && (index < MAX_DESC_LINES)) {
  661.         index++;
  662.         sprintf(tmp, "%1d:", index);
  663.         portsout(tmp);
  664.         portsin(buf50[(index - 1)], 50);
  665.         portsout(CRLF);
  666.     }
  667.     if (buf50[0][0] == '/') {
  668.         portsout(CRLF);
  669.         portsout(x_filename);
  670.         portsout(" will NOT be logged\n\r");
  671.         if ((inbuf = fopen(callers, "a")) == NULL) {
  672.             portsout(CRLF);
  673.             portsout("Can't open/create callers.bbs!");
  674.             portsout(CRLF);
  675.             return;
  676.         }
  677.         code = fprintf(inbuf, "%s %s", x_filename, buf50[0]);
  678.         if (code < 0) {
  679.             portsout(CRLF);
  680.             portsout("Callers file has problem writing");
  681.             portsout(CRLF);
  682.         } else {
  683.             fputs("\n", inbuf);
  684.         }
  685.         index2 = 1;
  686.         while (index2 < index) {
  687.             fprintf(inbuf, ". %s\n", buf50[index2]);
  688.             index2++;
  689.         }
  690.         if( index == MAX_DESC_LINES )
  691.             fprintf(inbuf, ".\n");
  692.         fclose(inbuf);
  693.         if (if_kermit == 0) {
  694.             strcpy(x_pathandfile, u_pathname);
  695.         } else {
  696.             strcpy(x_pathandfile, USRBBS);
  697.         }
  698.         strcat(x_pathandfile, x_filename);
  699.         strcpy(buf128, ORGPATH);
  700.         strcat(buf128, x_filename);
  701.         code = link(x_pathandfile, buf128);
  702.         if( code == -1) {
  703.             strcpy(buf128, "mv ");
  704.             strcat(buf128, x_pathandfile);
  705.             strcat(buf128, " ");
  706.             strcat(buf128, ORGPATH);
  707.             strcat(buf128, x_filename);
  708.             (void)system(buf128);
  709.             portsout("\n\r\n\rPlease leave a message to the sysop advising him that the\n");
  710.             portsout("bbs users' home directory is NOT in the same filesystem as the upload path.\n\r\n\r");
  711.         }
  712.             
  713.         (void)unlink(x_pathandfile);
  714.         return;
  715.     }
  716.     strcpy(who_am_i, u_pathname);
  717.     strcat(who_am_i, FILES);
  718.     if ((inbuf = fopen(who_am_i, "a")) == NULL) {    /* create or open for
  719.                              * append */
  720.         portsout(CRLF);
  721.         portsout("Can't open/create files.bbs!");
  722.         portsout(CRLF);
  723.         return;
  724.     }
  725.     fds = fileno(inbuf);
  726.     rewind(inbuf);
  727.     locking(fds, LK_LOCK, 0L);
  728.     code = fprintf(inbuf, "%s %s", x_filename, buf50[0]);
  729.     if (code < 0) {
  730.         portsout(CRLF);
  731.         portsout("List file has problem writing");
  732.         portsout(CRLF);
  733.     } else {
  734.         fputs("\n", inbuf);    /* put lf on end of each record */
  735.     }
  736.     index2 = 1;
  737.     while (index2 < index) {
  738.         fprintf(inbuf, ". %s\n", buf50[index2]);
  739.         index2++;
  740.     }
  741.     if( index == MAX_DESC_LINES )
  742.         fprintf(inbuf, ".\n");
  743.     rewind(inbuf);
  744.     locking(fds, LK_UNLCK, 0L);
  745.     fclose(inbuf);
  746.     if (if_kermit != 0) {
  747.         strcpy(x_pathandfile, USRBBS);
  748.         strcat(x_pathandfile, x_filename);
  749.         strcpy(buf128, u_pathname);
  750.         strcat(buf128, x_filename);
  751.         code = link(x_pathandfile, buf128);
  752.         if( code == -1) {
  753.             strcpy(buf128, "mv ");
  754.             strcat(buf128, x_pathandfile);
  755.             strcat(buf128, " ");
  756.             strcat(buf128, u_pathname);
  757.             strcat(buf128, x_filename);
  758.             (void)system(buf128);
  759.             portsout("\n\r\n\rPlease leave a message to the sysop advising him that the\n");
  760.             portsout("bbs users' home directory is NOT in the same filesystem as the upload path.\n\r\n\r");
  761.         }
  762.             
  763.         code = unlink(x_pathandfile);
  764.     }
  765. }
  766. enough_time()
  767. {
  768.     long            lsec, lspeed;
  769.     int             size, speed, code, result, astptr;
  770.     static int      baud[15] = {0, 50, 75, 110, 134, 150, 200, 300, 600, 1200, 1800, 2400, 4800, 9600, 19200};
  771.     char            data_buffer[600];
  772.     char         *ppr, *locptr;
  773.     locptr = strchr(x_pathandfile, '*');
  774.     if( locptr == NULL )
  775.         astptr = 0;
  776.     else
  777.         astptr = 1;
  778.     strcpy(data_buffer, "ls ");
  779.     strcat(data_buffer, x_pathandfile);
  780.     strcat(data_buffer, " > /tmp/wild");
  781.     strcat(data_buffer, port_id);
  782.     code = system(data_buffer);
  783.     if( !astptr )
  784.         x_pathandfile[0] = '\0';
  785.     code = 0;
  786.     sum_size = 0L;
  787.     sum_lsec = 0L;
  788.     strcpy(data_buffer, "/tmp/wild");
  789.     strcat(data_buffer, port_id);
  790.     portsout("\n\rThe following files will be sent:\n\r");
  791.     if ((inbuf = fopen(data_buffer, "r")) == NULL)
  792.         return (FALSE);
  793.     while (fscanf(inbuf, "%s", data_buffer) != EOF) {
  794.         result = stat(data_buffer, &statbuf);
  795.         if( !astptr ) {
  796.             strcat(x_pathandfile, data_buffer);
  797.             strcat(x_pathandfile, " ");
  798.         }
  799.         ppr = strrchr(data_buffer, '/');
  800.         if (ppr == NULL)
  801.             ppr = data_buffer;
  802.         else
  803.             ppr++;
  804.         if (result != 0) {
  805.             fclose(inbuf);
  806.             strcpy(data_buffer, "/tmp/wild");
  807.             strcat(data_buffer, port_id);
  808.             result = unlink(data_buffer);
  809.             return (FALSE);
  810.         }
  811.         result = strcmp(ppr, "files.bbs");
  812.         if( result == 0 ) {
  813.             portsout("\n\rIllegal file request\n\r");
  814.             return(FALSE);
  815.         }
  816.         portsout(ppr);
  817.         portsout(CRLF);
  818.         size = (statbuf.st_size / 128) + 1;
  819.         ioctl(0, TCGETA, &ttyhold);
  820.         speed = baud[ttyhold.c_cflag & 017];
  821.         lspeed = speed;
  822.         lsec = size;
  823.         sum_lsec = sum_lsec + (lsec * 128L * 11L / lspeed);
  824.         sum_size = sum_size + statbuf.st_size;
  825.         code++;
  826.     }
  827.     if( ! astptr ) {
  828.         ppr = strrchr( x_pathandfile, ' ');
  829.         if( ppr != NULL )
  830.             *ppr = '\0';
  831.     }
  832.     fclose(inbuf);
  833.     strcpy(data_buffer, "/tmp/wild");
  834.     strcat(data_buffer, port_id);
  835.     result = unlink(data_buffer);
  836.     strcpy(buf128, "\n\rTotal number of files = ");
  837.     itoa(data_buffer, code);
  838.     strcat(buf128, data_buffer);
  839.     strcat(buf128, "\n\r");
  840.     portsout(buf128);
  841.     strcpy(buf128, "Total number of bytes = ");
  842.     sprintf(data_buffer, "%ld", sum_size);
  843.     strcat(buf128, data_buffer);
  844.     portsout(buf128);
  845.     strcpy(buf128, "\n\rTotal download time = ");
  846.     sprintf(data_buffer, "%ld", sum_lsec);
  847.     strcat(buf128, data_buffer);
  848.     strcat(buf128, " seconds\n\r");
  849.     portsout(buf128);
  850.     xsec = alarm(0);
  851.     Ztime = xsec;
  852.     sec = xsec;
  853.     alarm(sec);
  854.     if (sum_lsec > xsec)
  855.         return (FALSE);
  856.     if ((sum_size + dload_total) > max_dload)
  857.         return (FALSE);
  858.     if( sum_size == 0L )
  859.         return (FALSE);
  860.     return (TRUE);
  861. }
  862. file_d()
  863. {
  864.     FILE        *zipp;
  865.     char            choic2[2], *str_result, *ptr, *ptr1;
  866.     long            lsec, hold_sec, jsec, ksec;
  867.     unsigned        start_sec, stop_sec;
  868.     long            var_sec;
  869.     int             result, tryit, tryit1, size, speed, default_flag, code;
  870.     int        mult;
  871.     static int      baud[15] = {0, 50, 75, 110, 134, 150, 200, 300, 600, 1200, 1800, 2400, 4800, 9600, 19200};
  872. filed:
  873.     result = stat(DLMSG, &statbuf);
  874.     if (!result) {
  875.         portsout(CRLF);
  876.         no_cntrl_k = TRUE;
  877.         cmd_p(DLMSG);
  878.         no_cntrl_k = FALSE;
  879.         portsout(CRLF);
  880.     }
  881.     tryit = FALSE;
  882.     tryit1 = FALSE;
  883.     mult = FALSE;
  884.     portsout(CRLF);
  885.     portsout("Input file name(s) to download:  ");
  886.     portsin(x_filename, 98);
  887.     if (strlen(x_filename) < 1)
  888.         return;
  889.     if (x_filename[0] == '.' || x_filename[0] == '/' || x_filename[0] == ' ') {
  890.         portsout("\n\r\n\rIllegal Filename! \n\r");
  891.         return;
  892.     }
  893.     code = strlen(x_filename);
  894.     code--;
  895.     if (x_filename[code] == '.' || x_filename[code] == '/' || x_filename[code] == ' ') {
  896.         portsout("\n\r\n\rIllegal Filename! \n\r");
  897.         return;
  898.     }
  899.     code = strcmp(x_filename, "files.bbs");
  900.     if (code == 0) {
  901.         portsout("\n\r\n\rIllegal Filename! \n\r");
  902.         return;
  903.     }
  904.     str_result = strchr(x_filename, '*');
  905.     if (str_result != NULL)
  906.         tryit = TRUE;
  907.  
  908.     str_result = strchr(x_filename, ' ');
  909.     if (str_result != NULL) {
  910.         tryit = TRUE;
  911.         mult = TRUE;
  912.     }
  913.  
  914.     portsout(CRLF);
  915.     code = legalname("|`><!;:", x_filename);
  916.     if (code == 0) {
  917.         portsout("\n\r\n\rIllegal Filename! \n\r");
  918.         return;
  919.     }
  920.     if( mult ) {
  921.         ptr = x_filename;
  922.         x_pathandfile[0] = '\0';
  923.         while(1) {
  924.             ptr1 = strchr(ptr, ' ');
  925.             if(ptr1 == NULL)
  926.                 break;    
  927.             *ptr1 = '\0';
  928.             strcat(x_pathandfile, f_pathname);
  929.             strcat(x_pathandfile, ptr);
  930.             strcat(x_pathandfile, " ");
  931.             *ptr1 = (char)' ';
  932.             ptr = ptr1 + 1;
  933.         }
  934.         strcat(x_pathandfile, f_pathname);
  935.         strcat(x_pathandfile, ptr);
  936.     } else {
  937.         strcpy(x_pathandfile, f_pathname);
  938.         strcat(x_pathandfile, x_filename);
  939.     }
  940.     if (!tryit) {
  941.         result = stat(x_pathandfile, &statbuf);
  942.         if (result != 0) {
  943.             portsout("\n\rThat file does not exist!\n\r");
  944.             portsout("Remember that file names are CASE sensitive.\n\r");
  945.             return;
  946.         }
  947.         size = (statbuf.st_size / 128) + 1;
  948.         ioctl(0, TCGETA, &ttyhold);
  949.         speed = baud[ttyhold.c_cflag & 017];
  950.         lsec = size;
  951.         lsec = lsec * 128L * 11L / speed;
  952.         sum_size = statbuf.st_size;
  953.         xsec = alarm(0);
  954.         Ztime = xsec;
  955.         sec = xsec;
  956.         alarm(sec);
  957.         hold_sec = lsec;
  958.         if (lsec > xsec) {
  959.             portsout("\n\rYou don't have enough time left to download that file.\n\r");
  960.             return;
  961.         }
  962.         if ((statbuf.st_size + dload_total) > max_dload) {
  963.             portsout("\n\rThis download will overrun your download limit.");
  964.             portsout("\n\rUploads will increase your limit.\n\r");
  965.             return;
  966.         }
  967.     } else {
  968.         if (!enough_time()) {
  969.             portsout("\n\rYou don't have enough time/bytes or an error was detected.\n\r");
  970.             return;
  971.         }
  972.         hold_sec = sum_lsec;
  973.     }
  974.     hold_sec /= 2L;
  975.     portsout(CRLF);
  976.     if ( tryit ) 
  977.         portsout("Multi-file options: Z(modem),  B(atch ymodem), K(ermit)");
  978.     else {
  979.         portsout("Options: Z(modem),  C(rc xmodem), X(modem), B(atch ymodem), Y(modem),\n\r");
  980.         portsout("         K(ermit),  S(EAlink),    A(scii),  T(ype)");
  981.     }
  982.     portsout(CRLF);
  983.     portsout(CRLF);
  984.     if ( tryit )
  985.         portsout("Commands: Z,B,K  ===> ");
  986.     else
  987.         portsout("Commands: Z,C,X,B,Y,K,S,A,T  ===> ");
  988.     portsin(choic2, 1);
  989.     portsout(CRLF);
  990.     default_flag = 1;
  991.     *choic2 = toupper(*choic2);
  992.     if ((inbuf = fopen(callers, "a")) == NULL) {    /* create or open for
  993.                              * append */
  994.         portsout(CRLF);
  995.         portsout("Can't open/create callers file!");
  996.         portsout(CRLF);
  997.         return;
  998.     }
  999.     code = fprintf(inbuf, "%s %s  ", "   DNLOAD  ", x_filename);
  1000.     if (code < 0) {
  1001.         portsout(CRLF);
  1002.         portsout("Caller file has problem writing");
  1003.         portsout(CRLF);
  1004.     } 
  1005.     fclose(inbuf);
  1006.     if (choic2[0] == 'K' || choic2[0] == 'B' || choic2[0] == 'Z')
  1007.         tryit1 = TRUE;
  1008.     if (tryit && !tryit1) {
  1009.         portsout("\n\rIllegal use of wildcards - Must be KERMIT, YMODEM BATCH, or ZMODEM\n\r");
  1010.         typexfr(11);
  1011.         return;
  1012.     }
  1013.     start_sec = stop_sec = 0;
  1014.     xsec = alarm(0);
  1015.     alarm(32767);
  1016.     switch (choic2[0]) {
  1017.     case ('T'):
  1018.         portsout("\n\r\n\rOne moment please while an ascii check is done on the file ......  ");
  1019.         if(!asciicheck(x_pathandfile)) {
  1020.             portsout("Sorry.\n\rEither the file does not exist or it is not printable ascii.\n\r\n\r");
  1021.             typexfr(10);
  1022.             return;
  1023.         }
  1024.         portsout("ok.\n\r\n\r");
  1025.         cmd_p(x_pathandfile);
  1026.         typexfr(9);
  1027.         break;
  1028.     case ('A'):
  1029.         strcpy(x_pathandfile, f_pathname);
  1030.         strcat(x_pathandfile, x_filename);
  1031.         portsout("\n\r\n\rOne moment please while an ascii check is done on the file ......  ");
  1032.         if(!asciicheck(x_pathandfile)) {
  1033.             portsout("Sorry.\n\rEither the file does not exist or it is not printable ascii.\n\r\n\r");
  1034.             typexfr(10);
  1035.             return;
  1036.         }
  1037.         portsout("ok.\n\r\n\r");
  1038.         typexfr(8);
  1039.         portsout("\n\rOnce the transfer starts, you may terminate it by typing a Control-K");
  1040.         portsout("\n\rType a character to start the transfer when you are ready ===>  ");
  1041.         portsin(choic2, 1);
  1042.         portsout(CRLF);
  1043.         no_cntrl_k = TRUE;
  1044.         if (!toggle) {
  1045.             cmd_p(x_pathandfile);
  1046.         } else {
  1047.             toggle = FALSE;
  1048.             cmd_p(x_pathandfile);
  1049.             toggle = TRUE;
  1050.         }
  1051.         no_cntrl_k = FALSE;
  1052.         sleep(3);
  1053.         break;
  1054.     case ('X'):
  1055.         strcpy(x_pathandfile, SB);
  1056.         strcat(x_pathandfile, f_pathname);
  1057.         strcat(x_pathandfile, x_filename);
  1058.         typexfr(5);
  1059.         result = system(x_pathandfile);
  1060.         restoresig();
  1061.         start_sec = result;
  1062.         sleep(1);
  1063.         break;
  1064.     case ('Y'):
  1065.         strcpy(x_pathandfile, YMDS);
  1066.         strcat(x_pathandfile, f_pathname);
  1067.         strcat(x_pathandfile, x_filename);
  1068.         typexfr(3);
  1069.         result = system(x_pathandfile);
  1070.         restoresig();
  1071.         start_sec = result;
  1072.         sleep(1);
  1073.         break;
  1074.     case ('C'):
  1075.         strcpy(x_pathandfile, CRCS);
  1076.         strcat(x_pathandfile, f_pathname);
  1077.         strcat(x_pathandfile, x_filename);
  1078.         typexfr(4);
  1079.         result = system(x_pathandfile);
  1080.         restoresig();
  1081.         start_sec = result;
  1082.         sleep(1);
  1083.         break;
  1084.     case ('S'):
  1085.         strcpy(x_pathandfile, SEAS);
  1086.         strcat(x_pathandfile, f_pathname);
  1087.         strcat(x_pathandfile, x_filename);
  1088.         typexfr(7);
  1089.         result = system(x_pathandfile);
  1090.         restoresig();
  1091.         start_sec = result;
  1092.         sleep(1);
  1093.         break;
  1094.     case ('Z'):
  1095.         strcpy(msg_text, SZ);
  1096.         strcat(msg_text, x_pathandfile);
  1097.         typexfr(1);
  1098.         result = system(msg_text);
  1099.         restoresig();
  1100.         start_sec = result;
  1101.         sleep(1);
  1102.         break;
  1103.     case ('B'):
  1104.         strcpy(msg_text, YMS);
  1105.         strcat(msg_text, x_pathandfile);
  1106.         typexfr(2);
  1107.         result = system(msg_text);
  1108.         restoresig();
  1109.         start_sec = result;
  1110.         sleep(1);
  1111.         break;
  1112.     case ('K'):
  1113.         strcpy(msg_text, KS);
  1114.         strcat(msg_text, x_pathandfile);
  1115.         typexfr(6);
  1116.         portsout("Ready to start KERMIT transfer");
  1117.         portsout(CRLF);
  1118.         result = system(msg_text);
  1119.         restoresig();
  1120.         start_sec = result;
  1121.         break;
  1122.     default:
  1123.         portsout("Illegal option");
  1124.         typexfr(11);
  1125.         default_flag = 0;
  1126.         portsout(CRLF);
  1127.         break;
  1128.     }
  1129.     sec = alarm(0);
  1130.     jsec = 32767L - (long) sec;
  1131.     ksec = (long) xsec;
  1132.     ksec -= jsec;
  1133.     if (ksec <= 2L)
  1134.         ksec = 2L;
  1135.     xsec = (unsigned int) ksec;
  1136.     code = 0;
  1137.     if (default_flag) {
  1138.         if ((zipp = fopen(callers, "a")) == NULL) {    /* create or open for
  1139.                                  * append */
  1140.             portsout(CRLF);
  1141.             portsout("Can't open/create callers file!");
  1142.             portsout(CRLF);
  1143.             return;
  1144.         }
  1145.         if (start_sec == 0) {
  1146.             dload_total += sum_size;
  1147.             set_upd(sum_size);
  1148.             code = fprintf(zipp, "      Transfer seems to be OK.\n");
  1149.         } else 
  1150.             code = fprintf(zipp, "      Transfer seems to have failed.\n");
  1151.         if (code < 0) {
  1152.             portsout(CRLF);
  1153.             portsout("Caller file has problem writing");
  1154.             portsout(CRLF);
  1155.         } 
  1156.         fclose(zipp);
  1157.  
  1158.     }
  1159.     alarm(xsec);
  1160.     portsout(CRLF);
  1161. }
  1162. typexfr(typex)  int typex;
  1163. {
  1164.     int code;
  1165.     if ((inbuf = fopen(callers, "a")) == NULL) {    /* create or open for
  1166.                              * append */
  1167.         portsout(CRLF);
  1168.         portsout("Can't open/create callers file!");
  1169.         portsout(CRLF);
  1170.         return;
  1171.     }
  1172.     switch (typex) {
  1173.         case (1): code = fprintf(inbuf, " using ZMODEM\n");
  1174.             break;
  1175.         case (2): code = fprintf(inbuf, " using BATCH YMODEM\n");
  1176.             break;
  1177.         case (3): code = fprintf(inbuf, " using YMODEM\n");
  1178.             break;
  1179.         case (4): code = fprintf(inbuf, " using XMODEM-CRC\n");
  1180.             break;
  1181.         case (5): code = fprintf(inbuf, " using XMODEM-CHECKSUM\n");
  1182.             break;
  1183.         case (6): code = fprintf(inbuf, " using KERMIT\n");
  1184.             break;
  1185.         case (7): code = fprintf(inbuf, " using SEALINK\n");
  1186.             break;
  1187.         case (8): code = fprintf(inbuf, " using ASCII\n");
  1188.             break;
  1189.         case (9): code = fprintf(inbuf, " using TYPE\n");
  1190.             break;
  1191.         case (10): code = fprintf(inbuf, " NOT printable ASCII\n");
  1192.             break;
  1193.         default:  code = fprintf(inbuf, " ......... illegal option!\n");
  1194.             break;
  1195.     }
  1196.     if (code < 0) {
  1197.         portsout(CRLF);
  1198.         portsout("Caller file has problem writing");
  1199.         portsout(CRLF);
  1200.     }
  1201.     fclose(inbuf);
  1202. }
  1203.  
  1204. cmd_e()
  1205. {                /* enter a message */
  1206.     int             entering, editing, char_cnt, temp_int, temp_int1;
  1207.     char            l_cnt[3], type[2], ans[2];
  1208.     char           *char_ptr;
  1209.     char            tmp[80];
  1210.  
  1211.     entering = editing = TRUE;
  1212.     cnt1 = 0;
  1213.     strcpy(l_cnt, "00");
  1214.     msg_text[0] = '\0';    /* init message text area */
  1215.     portsout(CRLF);
  1216.     portsout("This will be message # ");
  1217.     portsout(h_act_msg);
  1218.     portsout(CRLF);
  1219.     if (!reply_sw) {
  1220.         entr_name();
  1221.         entr_subj();
  1222.     }
  1223.     if (!end_msg)
  1224.         entr_priv();
  1225.     if (end_msg)
  1226.         strcpy(pubpriv, "5");
  1227.  
  1228.     portsout(CRLF);
  1229.     sprintf(tmp, "A line can contain 72 characters, up to %d lines.", MAX_MSG_LINES);
  1230.     portsout(tmp);
  1231.     portsout(CRLF);
  1232.     portsout("To end, enter a carriage return on an empty line.");
  1233.     portsout(CRLF);
  1234.     if(blocked_m)
  1235.         portsout("The lines will automatically word wrap and block.");
  1236.     else
  1237.         portsout("The lines will automatically word wrap.");
  1238.     portsout(CRLF);
  1239. Enter:
  1240.     portsout(CRLF);
  1241.     portsout("    .___.____1____.____2____.____3____.____4____.____5____.____6____.____7__");
  1242.     portsout(CRLF);
  1243.  
  1244.     char_cnt = 72;
  1245.     work_msg[0] = '\0';
  1246.     while (entering) {    /* get the text of the message */
  1247.         linecnt(l_cnt);    /* calc line count */
  1248.  
  1249.         portsout(l_cnt);/* show line count */
  1250.         portsout("> ");    /* and prompt */
  1251.         portsout(work_msg);
  1252.         strcpy(buf128, work_msg);
  1253.         in_the_buffer = strlen(buf128);
  1254.         work_msg[0] = '\0';
  1255.         portsinm(x_pathandfile, char_cnt, buf128);
  1256.         char_ptr = strrchr(x_pathandfile, ' ');
  1257.         temp_int = strlen(x_pathandfile);
  1258.         if (temp_int >= char_cnt) {
  1259.             if (x_pathandfile[temp_int - 1] == '\n' || x_pathandfile[temp_int - 1] == '\r' || x_pathandfile[temp_int - 1] == ' ') {
  1260.                 char_cnt = 72;
  1261.                 goto enter1;
  1262.             }
  1263.             if (char_ptr != NULL) {
  1264.                 *char_ptr = '\0';
  1265.                 char_ptr++;
  1266.                 strcpy(work_msg, char_ptr);
  1267.                 temp_int = strlen(work_msg);
  1268.                 for (temp_int1 = 1; temp_int1 <= temp_int; temp_int1++)
  1269.                     portsout("\b");
  1270.                 for (temp_int1 = 1; temp_int1 <= temp_int; temp_int1++)
  1271.                     portsout(" ");
  1272.                 char_cnt = 72 - temp_int;
  1273.  
  1274.             } else {
  1275.                 char_cnt = 72;
  1276.             }
  1277.         } else {
  1278.             char_cnt = 72;
  1279.             work_msg[0] = '\0';
  1280.  
  1281.         }
  1282. enter1:
  1283.         strcat(buf128, x_pathandfile);
  1284.         portsout(CRLF);
  1285.  
  1286.         strcat(buf128, "\n");    /* put a <lf> on each line */
  1287.         if(blocked_m) {
  1288.             strcpy(x_pathandfile, buf128);
  1289.             block_text();
  1290.         }
  1291.  
  1292.         if (strlen(buf128) < 2) {    /* count cr too */
  1293.             entering = FALSE;    /* all done */
  1294.         } else {
  1295.             strcat(msg_text, buf128);    /* append each line to
  1296.                              * text */
  1297.         }
  1298.         if ((++cnt1) > MAX_MSG_LINES) {    /* only allow 20 lines */
  1299.             entering = FALSE;    /* all done */
  1300.         }
  1301.     }
  1302.  
  1303.     while (editing) {    /* save it, fix it, list it, or get out */
  1304.         portsout(CRLF);
  1305.         portsout("(S)ave,    (L)ist,     (C)ontinue, or (Q)uit");
  1306.         portsout(CRLF);
  1307.         portsout("ce(N)ter,  (B)lock,    (D)elete,      (I)nsert,    (R)eplace,  or (E)dit line");
  1308.         portsout(CRLF);
  1309.         portsout("Change     sub(J)ect,  recei(V)er, or (P)rivilege ==> ");
  1310.         portsin(ans, 1);/* get a byte */
  1311.         portsout(CRLF);
  1312.  
  1313.         *ans = toupper(*ans);
  1314.  
  1315.         switch (ans[0]) {    /* get 1 byte */
  1316.         case ('S'):    /* save message */
  1317.             new_msg = atoi(h_act_msg);
  1318.             savemsg();
  1319.             editing = FALSE;    /* get out of while */
  1320.             break;
  1321.         case ('E'):    /* edit message */
  1322.         case ('I'):    /* edit message */
  1323.         case ('D'):    /* edit message */
  1324.         case ('R'):
  1325.         case ('N'):
  1326.         case ('B'):
  1327.             editmsg(*ans);
  1328.             break;
  1329.         case ('P'):
  1330.             if (end_msg) {
  1331.                 portsout("\n\rCannot change the privilege on a log off message\n\r");
  1332.                 break;
  1333.             }
  1334.             entr_priv();
  1335.             portsout(CRLF);
  1336.             break;
  1337.         case ('J'):
  1338.             if (end_msg) {
  1339.                 portsout("\n\rCannot change the subject on a log off message\n\r");
  1340.                 break;
  1341.             }
  1342.             if (reply_sw) {
  1343.                 portsout("\n\rCannot change the subject on a reply to a message\n\r");
  1344.                 break;
  1345.             }
  1346.             portsout(CRLF);
  1347.             entr_subj();
  1348.             portsout(CRLF);
  1349.             break;
  1350.         case ('V'):
  1351.             if (end_msg) {
  1352.                 portsout("\n\rCannot change the name of the receiver on a log off message\n\r");
  1353.                 break;
  1354.             }
  1355.             if (reply_sw) {
  1356.                 portsout("\n\rCannot change the receiver's name on a message reply\n\r");
  1357.                 break;
  1358.             }
  1359.             entr_name();
  1360.             break;
  1361.         case ('L'):    /* list message */
  1362.             listmsg();
  1363.             break;
  1364.         case ('Q'):    /* get out w/out saving */
  1365.             portsout("\n\r\n\rAre you sure you want to quit? (Y/n): ");
  1366.             portsin(ans, 1);
  1367.             portsout(CRLF);
  1368.             if (ans[0] == 'N' || ans[0] == 'n')
  1369.                 break;
  1370.             editing = FALSE;    /* get out of while */
  1371.             break;
  1372.         case ('C'):
  1373.             if (cnt1 == MAX_MSG_LINES) {
  1374.                 sprintf(tmp, "\n\rMessage is already %d lines!\n\r", MAX_MSG_LINES);
  1375.                 portsout(tmp);
  1376.                 break;
  1377.             }
  1378.             entering = TRUE;
  1379.             cnt1--;
  1380.             itoa(l_cnt, cnt1);
  1381.             goto Enter;
  1382.             break;
  1383.         default:
  1384.             portsout(CRLF);
  1385.             portsout("Shall we try that one again?\r\n");
  1386.             break;
  1387.         }
  1388.     }
  1389.  
  1390. }
  1391. /* end of function               */
  1392. entr_name()
  1393. {
  1394.     char            z_fname[11], z_lname[16], z_full[22];
  1395.     int             length, length1;
  1396.     char            firstz[20], lastz[20];
  1397.     char            priv[6];
  1398.     char            etime[9];
  1399.     char            esize[9];
  1400. enter_it_again:
  1401.     length1 = 0;
  1402.     portsout(CRLF);
  1403.     portsout("                                           ____.____1\r\n");
  1404.     portsout("Enter the FIRST NAME of the receiver ===>  ");
  1405.     portsin(z_fname, 10);
  1406.     length = strlen(z_fname);
  1407.     if (!length) {
  1408.         strcpy(z_fname, "All");
  1409.         z_lname[0] = '\0';
  1410.         goto bobble;
  1411.     }
  1412.     portsout(CRLF);
  1413.     portsout("                                           ____.____1____.\r\n");
  1414.     portsout("Enter the LAST NAME of the receiver ====>  ");
  1415.     portsin(z_lname, 15);
  1416.     length1 = strlen(z_lname);
  1417. bobble:
  1418.     portsout(CRLF);
  1419.     fix_name(z_fname);
  1420.     fix_name(z_lname);
  1421.     length += length1;
  1422.     if (length > 20) {
  1423.         portsout("\n\rI'm sorry; however, the name is TOO long to be posted!\n\r");
  1424.         goto enter_it_again;
  1425.     }
  1426.     strcpy(z_full, z_fname);
  1427.     strcat(z_full, " ");
  1428.     strcat(z_full, z_lname);
  1429.     strcpy(msg_to, z_full);
  1430.     portsout(CRLF);
  1431.     if ((inbuf = fopen(USERPRIV, "r")) == NULL) {
  1432.         portsout(CRLF);
  1433.         portsout("Can't open user priv file!");
  1434.         portsout(CRLF);
  1435.         exit(1);
  1436.     }
  1437.     while (fscanf(inbuf, "%s%s%s%s%s", firstz, lastz, priv, etime, esize) != EOF) {
  1438.         if ((strcmp(firstz, z_fname) == 0) &&
  1439.             (strcmp(lastz, z_lname) == 0)) {
  1440.             return;
  1441.         }
  1442.     }
  1443.     fclose(inbuf);
  1444.     if( strcmp(z_fname, "Sysop") == 0 ) {
  1445.         strcpy(msg_to, SYSOP);
  1446.         return;
  1447.     }
  1448.     if( strcmp(z_fname, "All") == 0 ) {
  1449.         strcpy(msg_to, "All Users");
  1450.         return;
  1451.     }
  1452.     portsout("\n\rWarning: there is no user on this system by that name.\n\r");
  1453.     portsout("Do you still wish to use it? (Y/n): ");
  1454.     portsin(etime, 1);
  1455.     portsout(CRLF);
  1456.     if( etime[0] == 'N' || etime[0] == 'n' )
  1457.         goto enter_it_again;
  1458. }
  1459.  
  1460. entr_subj()
  1461. {
  1462.     int             length;
  1463.     portsout("                             ____.____1____.____2\n\r");
  1464.     portsout("What is the subject     ===> ");
  1465.     portsin(msg_subject, 20);
  1466.     length = strlen(msg_subject);
  1467.     if (!length) {
  1468.         strcpy(msg_subject, "*** NO SUBJECT ***");
  1469.     }
  1470. }
  1471. entr_priv()
  1472. {
  1473.     char            type[2];
  1474.     portsout(CRLF);
  1475.     portsout("Do you wish the message to be P(ublic) or pri(V)ate) (P/V) ?  ");
  1476.     portsin(type, 1);
  1477.     *type = toupper(*type);
  1478.     switch (type[0]) {
  1479.     case ('P'):
  1480.         strcpy(pubpriv, "0");
  1481.         break;
  1482.     case ('V'):
  1483.         strcpy(pubpriv, "5");
  1484.         break;
  1485.     default:
  1486.         portsout("\n\rDefaulting to public!\n\r");
  1487.         strcpy(pubpriv, "0");
  1488.         break;
  1489.     }
  1490. }
  1491. linecnt(lcnt)            /* 2 byte string of line numbers */
  1492.     char           *lcnt;
  1493. {
  1494.     int             icnt;
  1495.     char            xcnt[4];
  1496.  
  1497.     icnt = atoi(lcnt);
  1498.     if (++icnt < 10) {
  1499.         strcpy(lcnt, "0");
  1500.         itoa(xcnt, icnt);
  1501.         strcat(lcnt, xcnt);
  1502.     } else {
  1503.         itoa(xcnt, icnt);
  1504.         strcpy(lcnt, xcnt);
  1505.     }
  1506.     return;
  1507. }
  1508. /* end of function               */
  1509.  
  1510. savemsg()
  1511. {                /* save a message */
  1512.     int             fd;
  1513.  
  1514.     portsout("Saving...\r\n");
  1515.  
  1516.     strcpy(msg_delete, pubpriv);    /* delete byte */
  1517.     strcpy(msg_date, mm);
  1518.     strcat(msg_date, "/");
  1519.     strcat(msg_date, dd);
  1520.     strcat(msg_date, "/");
  1521.     strcat(msg_date, yy);
  1522.  
  1523.     strcpy(msg_time, ttime);/* and the time */
  1524.  
  1525.     strcpy(msg_from, w_fname);    /* and the from name */
  1526.     strcat(msg_from, " ");
  1527.     strcat(msg_from, w_lname);
  1528.     if ((inbuf = fopen(callers, "a")) == NULL) {    /* create or open for
  1529.                              * append */
  1530.         portsout(CRLF);
  1531.         portsout("Can't open/create callers file!");
  1532.         portsout(CRLF);
  1533.         return;
  1534.     }
  1535.     fd = fprintf(inbuf, "%s%s", "   Message being sent to ", msg_to);
  1536.     if (fd < 0) {
  1537.         portsout(CRLF);
  1538.         portsout("Caller file has problem writing");
  1539.         portsout(CRLF);
  1540.     } else {
  1541.         fputs("\n", inbuf);    /* put lf on end of each record */
  1542.     }
  1543.     fclose(inbuf);
  1544.     hdrread();        /* Guarantee proper header and table */
  1545.     if ((fd = msgopen(2)) == ERROR) {    /* open i/o */
  1546.         return (ERROR);
  1547.     }
  1548.     msgwrt(fd);        /* write the message */
  1549.     msgclose(fd);
  1550.  
  1551.     strcpy(h_date, msg_date);
  1552.     hdrwrt();        /* update the header file */
  1553. }
  1554. /* end of function               */
  1555.  
  1556.  
  1557. listmsg()
  1558. {
  1559.     char           *ptr, byte, lcnt[3];
  1560.     int             i;
  1561.  
  1562.     ptr = msg_text;        /* ptr points to start of text */
  1563.     strcpy(lcnt, "00");
  1564.  
  1565.     portsout(CRLF);
  1566.     while (*ptr != 0) {
  1567.         linecnt(lcnt);
  1568.         portsout(lcnt);    /* put out line number */
  1569.         portsout(">");
  1570.         while (byte = *ptr++) {
  1571.             if (byte == '\n') {    /* we dont save <cr>, so add *//* i
  1572.                          * t here when find a <cr> */
  1573.                 portsout(CRLF);
  1574.                 break;
  1575.             } else
  1576.                 portout(byte);
  1577.         }
  1578.     }
  1579. }
  1580. /* end of function               */
  1581.  
  1582. editmsg(tflag) char
  1583.     tflag;
  1584. {
  1585.     char            ans[3];
  1586.     int             lnum;    /* line number to edit */
  1587.     char            tmp[80];
  1588.  
  1589.     while (1) {
  1590.         portsout(CRLF);
  1591.         portsout("Enter line number to ");
  1592.         if (tflag == 'E')
  1593.             portsout("edit,");
  1594.         else if (tflag == 'D')
  1595.             portsout("delete,");
  1596.         else if (tflag == 'I')
  1597.             portsout("insert after,");
  1598.         else if (tflag == 'R')
  1599.             portsout("replace,");
  1600.         else if (tflag == 'N')
  1601.             portsout("center,");
  1602.         else if (tflag == 'B')
  1603.             portsout("block,");
  1604.         else
  1605.             return;
  1606.         portsout(CRLF);
  1607.         portsout("   or RETURN to exit ==> ");
  1608.         portsin(ans, 2);/* only MAX_MSG_LINES lines possible */
  1609.         portsout(CRLF);
  1610.         if (tflag == 'I' && cnt1 == MAX_MSG_LINES) {
  1611.             sprintf(tmp, "\n\rMessage is already %d lines!\n\r", MAX_MSG_LINES);
  1612.             portsout(tmp);
  1613.             return;
  1614.         }
  1615.         lnum = atoi(ans);
  1616.         if (lnum <= 0) {
  1617.             break;    /* out of while and return */
  1618.         }
  1619.         if ((lnum < MAX_MSG_LINES) || ((lnum == MAX_MSG_LINES) && (tflag != 'I'))) {
  1620.             editline(lnum, tflag);
  1621.             break;
  1622.         } else {    /* else slap on hand and loop around */
  1623.             sprintf(tmp, "Aw come on, there can only be %d lines!", MAX_MSG_LINES);
  1624.             portsout(tmp);
  1625.             portsout(CRLF);
  1626.             portsout("Shall we try that again?");
  1627.             portsout(CRLF);
  1628.         }
  1629.     }
  1630. }
  1631. /* end of function               */
  1632.  
  1633. usenet()
  1634. {                /* added for 7.2.1 USENET access */
  1635.  
  1636.  
  1637. #ifdef  SYSV
  1638. #define logname getlogin
  1639. #endif
  1640.  
  1641.     char           *logname();
  1642.  
  1643.     static char     shell[] = "SHELL=/bin/sh";
  1644.     static char     home[150];
  1645.     static char     logn[50];
  1646.     char            cmd[512];
  1647.     char            news[520];
  1648.     char            tmp[512];
  1649.     FILE           *newsf;
  1650.     int             mask;
  1651.     char            term;
  1652.  
  1653.     strcpy(home, "HOME=");
  1654.     strcpy(logn,"LOGNAME=");
  1655.     strcat(home, ORGPATH);
  1656.     strcat(home, "usenet/");
  1657.     strcat(home, u_fname);
  1658.     strcat(home, "/");
  1659.     strcat(home, u_lname);
  1660.     strcat(logn, logname());
  1661.  
  1662.     sprintf(news, "%susenet/%s/%s/.newsrc", ORGPATH, u_fname, u_lname);
  1663.     if (access(news, 00) == -1) {
  1664.         mask = umask(0000);
  1665.         portsout("creating necessary news files\n\r");
  1666.         portsout("\n\r");
  1667.         sprintf(tmp, "/bin/mkdir %susenet/%s", ORGPATH, u_fname);
  1668.         system(tmp);
  1669.         strcat(tmp, "/");
  1670.         strcat(tmp, u_lname);
  1671.         system(tmp);
  1672.         if ((newsf = fopen(news, "w")) == NULL) {
  1673.             portsout("open of .newsrc failed\n\r");
  1674.             exit(-1);
  1675.         }
  1676.         fprintf(newsf, "");
  1677.         fclose(newsf);
  1678.         umask(mask);
  1679.     }
  1680. menu:
  1681.     portsout("\n\rWhich type of terminal do you have:\n\r");
  1682.     portsout("1) Ansi Standard Monitor\n\r");
  1683.     portsout("2) ANSI.SYS for MS-DOS\n\r");
  1684.     portsout("3) VT100\n\r");
  1685.     portsout("4) Macintosh MacTerm in VT-100 mode\n\r");
  1686.     portsout("5) VT52 Terminal\n\r");
  1687.     portsout("6) Televideo 925\n\r");
  1688.     portsout("7) Televideo 910\n\r");
  1689.     portsout("8) Tandy DT-100\n\r");
  1690.     portsout("9) Dumb  - Use this when nothing else works correctly.\n\r");
  1691.     portsout("           Instead of the normal \"- MORE -\" inbetween pages\n\r");
  1692.     portsout("           You will see nothing, BUT you will hear a beep.\n\r");
  1693.     portsout("           This is the same thing. \"?\" is for help\n\r");
  1694.     portsout("\n\rQ) Return to main menu\n\r");
  1695.     portsout("===> ");
  1696.     term = portin();
  1697.     portsout("\n\r");
  1698.     switch (term) {
  1699.     case ('1'):
  1700.         putenv("TERM=ansi");
  1701.         break;
  1702.     case ('2'):
  1703.         putenv("TERM=dosansi");
  1704.         break;
  1705.     case ('3'):
  1706.         putenv("TERM=vt100");
  1707.         break;
  1708.     case ('4'):
  1709.         putenv("TERM=macterm");
  1710.         break;
  1711.     case ('5'):
  1712.         putenv("TERM=vt52so");
  1713.         break;
  1714.     case ('6'):
  1715.         putenv("TERM=tvi925co");
  1716.         break;
  1717.     case ('7'):
  1718.         putenv("TERM=tvi910");
  1719.         break;
  1720.     case ('8'):
  1721.         putenv("TERM=dt100");
  1722.         break;
  1723.     case ('9'):
  1724.         putenv("TERM=dumb");
  1725.         break;
  1726.     case ('Q'):
  1727.     case ('q'):
  1728.         portsout("\n\r");
  1729.         return (0);
  1730.         break;
  1731.     default:
  1732.         portsout("\n\rYou have selected an unsupported type. Please try again\n\r");
  1733.         goto menu;
  1734.         break;
  1735.     }
  1736.  
  1737.     putenv(shell);
  1738.     putenv(home);
  1739.     putenv(logn);
  1740. choose:
  1741.     portsout("\n\rDo you wish to:\n\r");
  1742.     portsout("1) Readnews\n\r");
  1743.     portsout("2) Postnews\n\r");
  1744.     portsout("\n\rQ) Return to main menu\n\r");
  1745.     portsout("===>");
  1746.     term = portin();
  1747.     portsout("\n\r");
  1748.     switch (term) {
  1749.     case ('1'):
  1750.         restoremodes();
  1751.         portrst();
  1752.         STDerr = freopen("/dev/tty", "w+", stderr);
  1753.         sprintf(cmd, "%s -n all",READN);
  1754.         system(cmd);
  1755.         break;
  1756.     case ('2'):
  1757.         restoremodes();
  1758.         portrst();
  1759.         STDerr = freopen("/dev/tty", "w+", stderr);
  1760.         sprintf(cmd, "%s",POSTN);
  1761.         system(cmd);
  1762.         break;
  1763.     case ('Q'):
  1764.     case ('q'):
  1765.         portsout("\n\r");
  1766.         strcpy(home, "HOME=");
  1767.         strcpy(logn, "LOGNAME=");
  1768.         cmd[0] = '\0';
  1769.         news[0] = '\0';
  1770.         tmp[0] = '\0';
  1771.         return (0);
  1772.         break;
  1773.     default:
  1774.         portsout("Please try again\n\r");
  1775.         goto choose;
  1776.         break;
  1777.     }
  1778.  
  1779.     strcpy(home, "HOME=");
  1780.     strcpy(logn, "LOGNAME=");
  1781.     cmd[0] = '\0';
  1782.     news[0] = '\0';
  1783.     tmp[0] = '\0';
  1784.  
  1785.     strcpy(buf128, STDERR);
  1786.     strcat(buf128, port_id);
  1787.     STDerr = freopen(buf128, "w+", stderr);
  1788.     portinit();
  1789.     setmodes();
  1790.     restoresig();
  1791.  
  1792. }
  1793. restoresig()
  1794. {
  1795.     signal(SIGALRM, timer);
  1796.     signal(SIGHUP, hanged);
  1797.     signal(SIGUSR1, mon_toggle);
  1798.     signal(SIGUSR2, sys_toggle);
  1799.     signal(SIGPIPE, chat);
  1800.  
  1801. }
  1802.