home *** CD-ROM | disk | FTP | other *** search
/ Usenet 1994 January / usenetsourcesnewsgroupsinfomagicjanuary1994.iso / sources / misc / volume32 / xbbs / part08 / bbsczip.c < prev    next >
C/C++ Source or Header  |  1992-09-08  |  5KB  |  225 lines

  1. #include <stdio.h>
  2. #include <string.h>
  3. #include <ctype.h>
  4. #include "bbscdef.h"
  5.  
  6.  
  7. char            save_old_m[99];
  8. extern int      user_priv, last_msg_read, read_flag, read_number, reply_sw;
  9. extern int      first_msg_in, blocked_m;
  10. int             cont_read;
  11. int             contin;
  12. int             zip;
  13.  
  14.  
  15. parse_zip(string)
  16.     char           *string;
  17. {
  18.  
  19.     register char  *file_ptr, *xptr;
  20.     register int    i;
  21.  
  22.     strcpy(m_pathname, ORGPATH);
  23.     file_ptr = (m_pathname + strlen(m_pathname));
  24.     xptr = who_am_I;
  25.  
  26.     i = 0;
  27.     while (string[i] != ' ') {
  28.         *file_ptr = string[i];
  29.         *xptr = string[i];
  30.         ++xptr;
  31.         ++file_ptr;
  32.         ++i;
  33.     }
  34.     *file_ptr = '/';
  35.     ++file_ptr;
  36.     *file_ptr = '\0';
  37.     *xptr = '\0';
  38.  
  39. }
  40. cmd_z()
  41. {
  42.     FILE           *fpt, *fopen();
  43.     char           *fgets(), *getenv();
  44.     char            choice[4];
  45. #ifndef SYSV
  46.     char            dir_priv_ascii[7];
  47. #endif
  48. #ifdef SYSV
  49.     char            dir_priv_ascii[20];
  50. #endif
  51.     char           *buf_ptr, *file_ptr, *char_ptr;
  52.     int             line_cnt, ret, i;
  53.     int             index_value, ptr;
  54.     int             length, strl, ii;
  55.     int             read_type;
  56.     int             ret_type;
  57.  
  58.     strcpy(buf128, MSGS);
  59.     strcpy(save_old_m, m_pathname);
  60.     first_msg_in = TRUE;
  61.     read_type = 0;
  62.     stop_that = FALSE;
  63.     zip = TRUE;
  64.     portsout("\n\r\n\rY(our messages) or N(ew messages) Y/n? ");
  65.     portsin(choice, 1);
  66.     portsout(CRLF);
  67.     if (choice[0] == 'n' || choice[0] == 'N') {
  68.         read_type = 1;
  69.         cont_read = 0;
  70.         portsout("C(ontinous read) or S(ingle at a time) c/S? ");
  71.         portsin(choice, 1);
  72.         portsout(CRLF);
  73.         if (choice[0] == 'c' || choice[0] == 'C') {
  74.             cont_read = 1;
  75.             contin = TRUE;
  76.         }
  77.     }
  78.     if ((fpt = fopen(buf128, "r")) == NULL) {
  79.         portsout("\n\rError Opening File Area List: Notify Sysop!\n\r");
  80.         zip = FALSE;
  81.         return (-1);
  82.     }
  83.     line_cnt = 0;
  84.     while (fpt) {
  85.         zfl(f_lines[line_cnt], 81);
  86.         if ((fgets(f_lines[line_cnt], 80, fpt)) == NULL) {
  87.             if (line_cnt == 0) {
  88.                 portsout("\n\rEOF Unexpected in Message Area List: Notify Sysop!\n\r");
  89.                 zip = FALSE;
  90.                 return (-1);
  91.             }
  92.             break;    /* if not 1st line */
  93.         }        /* end of if ((fgets)) */
  94.         if (line_cnt > 0) {
  95.             length = strlen(f_lines[line_cnt]);
  96.             length -= 57;
  97.             if (length > 6)
  98.                 length = 6;
  99.             substr(f_lines[line_cnt], dir_priv_ascii, 57, length);
  100.             strl = strlen(dir_priv_ascii);
  101.             if (strl == 0) {
  102.                 portsout("\n\rError reading privilege level\n\r");
  103.                 exit(1);
  104.             }
  105.             dir_priv[line_cnt] = atoi(dir_priv_ascii);
  106.             if (dir_priv[line_cnt] > user_priv)
  107.                 goto next_read;
  108.             strcpy(who_am_i, f_lines[line_cnt]);
  109.             buf_ptr = who_am_i;
  110.             buf_ptr += 56;
  111.             for (ptr = 0; ptr < 5; ptr++)
  112.                 *buf_ptr++ = ' ';
  113.             *buf_ptr = '\0';
  114.             sprintf(buf128, "%2d) %s", line_cnt, who_am_i);
  115.         }
  116. next_read:
  117.         ++line_cnt;
  118.     }            /* end of while (fpt) */
  119.     fclose(fpt);
  120.  
  121.     if (line_cnt <= 1) {
  122.         zip = FALSE;
  123.         return;
  124.     }
  125.     for (index_value = 1; index_value < line_cnt; index_value++) {
  126.         if (dir_priv[index_value] <= user_priv) {
  127.             if (stop_that)
  128.                 goto dats_all;
  129.             parse_zip(f_lines[index_value]);
  130.             hdrread();
  131.             portsout("\n\rSwitching to area '");
  132.             portsout(who_am_I);
  133.             portsout("'\n\r");
  134.             ret_type = 1;
  135.             if (!read_type)
  136.                 cmd_y();
  137.             else
  138.                 ret_type = new_msgs();
  139.             if (ret_type == 0 || ret_type == ERROR)
  140.                 goto dats_all;
  141.             portsout("\n\r*************************************************\n\r");
  142.         }
  143.     }
  144. dats_all:
  145.     strcpy(m_pathname, save_old_m);
  146.     i = strlen(m_pathname);
  147.     if (i > 0) {
  148.         hdrread();
  149.         set_first_read();
  150.     }
  151.     if (contin == TRUE && cont_read == 1)
  152.         contin = FALSE;
  153.     stop_that = FALSE;
  154.     zip = FALSE;
  155. }
  156. int
  157. new_msgs()
  158. {
  159.     int             rc, fd, q_msg;
  160.     int             t1;
  161.     char            chr[2];
  162.     int             new_msg;
  163.     int             how;
  164.     set_first_read();
  165.     new_msg = last_msg_read + 1;
  166.     q_msg = new_msg;
  167.     read_flag = TRUE;
  168.     if ((fd = msgopen(0)) == ERROR) {
  169.         zip = FALSE;
  170.         return (ERROR);
  171.     }
  172.     how = 1;
  173.     while ((rc = msgreadx(fd, q_msg++)) != ERROR) {
  174.         if (rc == 0 || rc == -10) {
  175.             continue;
  176.         }
  177.         read_number = atoi(msg_no);
  178.         cmd_r();
  179.         last_msg_read = read_number;
  180.         set_write();
  181.         if (cont_read == 1)
  182.             goto cont_rd;
  183.         if (user_priv >= mpE) {
  184.             portsout("\n\rDo you wish to reply to this message? (y/N): ");
  185.             portsin(chr, 1);
  186.             portsout(CRLF);
  187.             if (chr[0] == 'Y' || chr[0] == 'y') {
  188.                 portsout("\n\rDo you wish to use blocked (right justified) format?  (y/N: ");
  189.                 portsin(chr, 1);
  190.                 portsout(CRLF);
  191.                 if (chr[0] == 'y' || chr[0] == 'Y') 
  192.                     blocked_m = 1;
  193.                 else
  194.                     blocked_m = 0;
  195.                 reply_sw = TRUE;
  196.                 strcpy(msg_to, msg_from);
  197.                 strcpy(x_pathandfile, "(R) ");
  198.                 strcat(x_pathandfile, msg_subject);
  199.                 substr(x_pathandfile, msg_subject, 1, 20);
  200.                 cmd_e();
  201.                 reply_sw = FALSE;
  202.             }
  203.         }
  204.         portsout("\n\r\n\rContinue reading messages within this message base? (Y/n): ");
  205.         portsin(chr, 1);
  206.         portsout(CRLF);
  207.         if (chr[0] == 'n' || chr[0] == 'N')
  208.             break;
  209. cont_rd:    if (stop_that) {
  210.             stop_that = FALSE;
  211.             read_flag = FALSE;
  212.             how = 0;
  213.             break;
  214.         }
  215.         if (cont_read == 1) {
  216.             portsout(CRLF);
  217.             portsout("----------------------------------------");
  218.         }
  219.         portsout(CRLF);
  220.     }
  221.     read_flag = FALSE;
  222.     msgclose(fd);
  223.     return (how);
  224. }
  225.