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

  1. /*------------------------------------------------------------------------
  2.        Name: bbscbult.c
  3.    Comments: Display file areas and select one
  4.   ------------------------------------------------------------------------*/
  5.  
  6. #include <stdio.h>
  7. #include <string.h>
  8. #include <ctype.h>
  9. #include <sys/types.h>
  10. #include <sys/stat.h>
  11. #include <time.h>
  12. #include "bbscdef.h"
  13.  
  14.  
  15. extern int      user_priv;
  16. long        atol();
  17. static int    indexb[99];
  18. static int    first_b_r = 1;
  19.  
  20. change_bult()
  21. {
  22.     FILE           *fpt, *fopen();
  23.     char           *fgets(), *getenv();
  24.     char            choice[4];
  25. #ifndef SYSV
  26.     char            dir_priv_ascii[7];
  27. #endif
  28. #ifdef SYSV
  29.     char            dir_priv_ascii[20];
  30. #endif
  31.     char           *buf_ptr;
  32.     int             line_cnt, ret, i;
  33.     int             index_value, ptr;
  34.     int        j, k;
  35.     int             length;
  36.  
  37.     if(first_b_r)
  38.         {
  39.         first_b_r = 0;
  40.         for(j=0; j<99; j++)
  41.             indexb[j]=0;
  42.         }
  43.  
  44.     substr(z_date, z_mm, 1, 2);
  45.     substr(z_date, z_dd, 4, 2);
  46.     substr(z_date, z_yy, 7, 2);
  47.     xmm = atol(z_mm);
  48.     xdd = atol(z_dd);
  49.     xyy = atol(z_yy);
  50.     old_long_date = (xyy*10000L) + (xmm*100L) + xdd;
  51.     while (1) {
  52.  
  53. do_again:
  54.     strcpy(buf128, BULLETINS);
  55.  
  56.     if ((fpt = fopen(buf128, "r")) == NULL) {
  57.         portsout("\n\r\n\rThere are no bulletins today!\n\r\n\r");
  58.         return ;
  59.     }
  60.     portsout("\n\r\n\r\n\r                  *******************************\n\r");
  61.     portsout("                  * Available Bulletins to Read *\n\r");
  62.     portsout("                  *******************************\n\r\n\r");
  63.     portsout("\n\r    Bulletin      Description                                      \n\r");
  64.     portsout("    ============= ========================================== \n\r");
  65.  
  66.     line_cnt = 0;
  67.     while (fpt) {
  68.         zfl(f_lines[line_cnt], 81);
  69.         if ((fgets(f_lines[line_cnt], 80, fpt)) == NULL) {
  70.             if (line_cnt == 0) {
  71.                 portsout("\n\rEOF Unexpected in Bulletin List: Notify Sysop!\n\r");
  72.                 return;
  73.             }
  74.             break;    /* if not 1st line */
  75.         }        /* end of if ((fgets)) */
  76.         if (line_cnt > 0) {
  77.             length = strlen(f_lines[line_cnt]);
  78.             length -= 57;
  79.             if(length > 6)
  80.                 length = 6;
  81.             substr(f_lines[line_cnt], dir_priv_ascii, 57, length);
  82.             dir_priv[line_cnt] = atoi(dir_priv_ascii);
  83.             if (dir_priv[line_cnt] > user_priv)
  84.                 goto next_read;
  85.             strcpy(who_am_i, f_lines[line_cnt]);
  86.             buf_ptr = who_am_i;
  87.             buf_ptr += 56;
  88.             for (ptr = 0; ptr < 5; ptr++)
  89.                 *buf_ptr++ = ' ';
  90.             *buf_ptr = '\0';
  91.             sprintf(buf128, "%2d) %s", line_cnt, who_am_i);
  92.             strip(buf128);
  93.             term_space(buf128);
  94.             portsout(buf128);
  95.             portsout("\n\r");
  96.         }
  97. next_read:
  98.         ++line_cnt;
  99.     }            /* end of while (fpt) */
  100.     if (line_cnt <= 1)
  101.         {
  102.         portsout("\n\r\n\rThere are no bulletins today!\n\r\n\r");
  103.         return;
  104.         }
  105.     portsout(CRLF);
  106.     portsout(" Q) Quit --- exit bulletin section");
  107.     portsout(CRLF);
  108.     fclose(fpt);
  109.     portsout(CRLF);
  110.     strcpy(buf128,"The following bulletins are new for you since the last day you called:  ");
  111.     j = strlen(buf128);
  112.     portsout(buf128);
  113.     for (index_value=1; index_value<line_cnt; index_value++)
  114.         {
  115.         if(dir_priv[index_value] <= user_priv)
  116.             {
  117.             check_new(f_lines[index_value], index_value);
  118.             k = strlen(buf128);
  119.             j+=k;
  120.             if( j >= 72)
  121.                 {
  122.                 j = 0;
  123.                 portsout(CRLF);
  124.                 }
  125.             }
  126.         }
  127.     portsout(CRLF);
  128.     portsout(CRLF);
  129.         portsout("Enter Selection ===> ");
  130.         portsin_cmp(choice, 2, "Qq");
  131.         portsout(CRLF);
  132.         *choice = toupper(*choice);
  133.  
  134.         if (*choice == 'Q')
  135.             return;
  136.  
  137.  
  138.         index_value = atoi(choice);
  139.         if (index_value > 0 && index_value < line_cnt) {
  140.             if (dir_priv[index_value] <= user_priv) {
  141.                 parse_bul(f_lines[index_value]);
  142.                 indexb[index_value -1] = 1;
  143.                 continue;
  144.             }
  145.         }
  146.     }
  147. }
  148.  
  149.  
  150.  
  151.  
  152.  
  153. parse_bul(string)
  154.     char           *string;
  155. {
  156.  
  157.     register char  *file_ptr, *xptr;
  158.     register int    i;
  159.  
  160.     strcpy(buf128, ORGPATH);
  161.     file_ptr = (buf128 + strlen(buf128));
  162.  
  163.     i = 0;
  164.     while (string[i] != ' ') {
  165.         *file_ptr = string[i];
  166.         ++file_ptr;
  167.         ++i;
  168.     }
  169.     *file_ptr = '\0';
  170.     cmd_p(buf128);
  171.  
  172. }
  173. check_new(string, indexer)
  174.     char           *string;
  175.     int        indexer;
  176. {
  177.     static char *dater[]={ "Jan", "Feb", "Mar", "Apr", "May", "Jun",
  178.         "Jul", "Aug", "Sep", "Oct", "Nov", "Dec", };
  179.     char        timeptr[30];
  180.     int        result, j, k;
  181.     struct    stat stater;
  182.  
  183.     register char  *file_ptr, *xptr;
  184.     register int    i;
  185.  
  186.     if(indexb[indexer-1])
  187.         {
  188.         file_ptr = buf128;
  189.         *file_ptr = '\0';
  190.         return;
  191.         }
  192.  
  193.     strcpy(buf128, ORGPATH);
  194.     file_ptr = (buf128 + strlen(buf128));
  195.  
  196.     i = 0;
  197.     while (string[i] != ' ') {
  198.         *file_ptr = string[i];
  199.         ++file_ptr;
  200.         ++i;
  201.     }
  202.     *file_ptr = '\0';
  203.     file_ptr = buf128;
  204.     result = stat(buf128, &stater);
  205.     if(result)
  206.         {
  207.         *file_ptr='\0';
  208.         return;
  209.         }
  210.     xmm = stater.st_mtime;
  211.     strcpy(timeptr, ctime(&xmm));
  212.     substr(timeptr, buf128, 5,3);
  213.     substr(timeptr, z_dd, 9, 2);
  214.     substr(timeptr, z_yy, 23,2);
  215.     xdd = atol(z_dd);
  216.     xyy = atol(z_yy);
  217.     for ( result =0; result < 12; result++)
  218.         {
  219.         i = strcmp(buf128, dater[result]);
  220.         if(!i)
  221.             {
  222.             xmm = (long) result +1;
  223.             new_long_date = (xyy*10000L) + (xmm*100L) + xdd;
  224.             if(new_long_date >= old_long_date)
  225.                 {
  226.                 itoa(buf128, indexer);
  227.                 strcat(buf128, ", ");
  228.                 portsout(buf128);
  229.                 }
  230.             else
  231.                  *file_ptr='\0';
  232.             return;
  233.             }
  234.         }
  235.         *file_ptr='\0';
  236. }
  237.