home *** CD-ROM | disk | FTP | other *** search
/ Beijing Paradise BBS Backup / PARADISE.ISO / software / BBSDOORW / FAL702.ZIP / BULLETIN.C < prev    next >
Encoding:
C/C++ Source or Header  |  1994-08-27  |  7.3 KB  |  260 lines

  1. /*
  2. ** This program is distributed with the FALKEN BBS and with the FALKEN
  3. ** Doors Development Kit.  This program is copyright 1989 by Herb Rose
  4. */
  5.  
  6. /*
  7. ** First, the general include files and some data declarations
  8. */
  9.  
  10. #include "stdio.h"
  11. #include "stdlib.h"
  12. #include "string.h"
  13. #include <time.h>
  14. #include "doorutil.h"
  15. #include <sys\types.h>
  16. #include <sys\stat.h>
  17.  
  18. char menu2[] = "Press [ENTER] to continue";
  19.  
  20. char active[] = "FALKEN Bulletins Section.\r";
  21.  
  22. char prompt[] =
  23. "\rFlags : M=Must Read   U=Updated\r\r"
  24. "Enter Bulletin Number or 'q' to quit > ";
  25.  
  26. char menutext[] =
  27. "\r\r\rFalken Bulletins Section\r\r"
  28. "Number  Flags  Date      Subject\r"
  29. "------  -----  --------  ----------------------------------------\r";
  30.  
  31. char menuformat[] = "  %2d    %-5s  %8s  %s\r";
  32.  
  33. char cb[100];
  34.  
  35. int bulnum;
  36.  
  37. int nostop = 0;
  38.  
  39. int must_read[16];
  40. unsigned long bull_date[16];
  41. unsigned updated[16];
  42.  
  43. char datestr[16][10];
  44. char subject[16][40];
  45.  
  46. int dc_monthsiz[] = {31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31};
  47.  
  48. unsigned dc_yearstart[] = {
  49.     0, 366, 731, 1096, 1461, 1827, 2192, 2557,
  50.     2922, 3288, 3653, 4018, 4383, 4749, 5114, 5479,
  51.     5844, 6210, 6575, 6940, 7305, 7671, 8036, 8401,
  52.     8766, 9132, 9497, 9862, 10227, 10593, 10958, 11323,
  53.     11688, 12054, 12419, 12784, 13149, 13515, 13880, 14245,
  54.     14610, 14976, 15341, 15706, 16071, 16437, 16802, 17167,
  55.     17532, 17898, 18263, 18628, 18993, 19359, 19724, 20089,
  56.     20454, 20820, 21185, 21550, 21915, 22281, 22646, 23011,
  57.     23376, 23742, 24107, 24472, 24837, 25203, 25568, 25933,
  58.     26298, 26664, 27029, 27394, 27759, 28125, 28490, 28855,
  59.     29220, 29586, 29951, 30316, 30681, 31047, 31412, 31777,
  60.     32142, 32508, 32873, 33238, 33603, 33969, 34334, 34699,
  61.     35064, 35430, 35795, 36160, 36525, 36891, 37256, 37621,
  62.     37986, 38352, 38717, 39082, 39447, 39813, 40178, 40543,
  63. 40908, 41274, 41639, 42004, 42369, 42735, 43100, 43465};
  64.  
  65.  
  66. int numtodate();
  67.  
  68. /*
  69. ** DATETONUM converts 3 integers (mm dd yy) into an unsigned
  70. ** integer compatible with FALKEN date representation
  71. */
  72.  
  73. unsigned datetonum(kmon, kday, kyear)
  74. unsigned kmon, kday, kyear;
  75. {
  76.     unsigned k, l;
  77.     if (kyear >= 1900)
  78.         kyear -= 1900;
  79.     if (kyear > 118)
  80.         return 0;
  81.     if ((kyear & 3) == 0)
  82.         dc_monthsiz[1] = 29;
  83.     else
  84.         dc_monthsiz[1] = 28;
  85.     k = dc_yearstart[kyear];
  86.     for (l = 1; l < kmon; l++)
  87.         k += dc_monthsiz[l - 1];
  88.     k += kday;
  89.     return k;
  90. }
  91.  
  92. FILE *fp;
  93.  
  94. main()
  95. {
  96.     int j, k, n, len;
  97.     unsigned long lj;
  98.     struct stat statrec;
  99.     struct tm *loctptr;
  100.     char tstr[4];
  101.  
  102.     fp=NULL;
  103.  
  104.     for (j = 0; j < 16; j++)
  105.     {
  106.         must_read[j] = 0;
  107.         bull_date[j] = 0L;
  108.         sprintf(cb, "bulletin.%d", j + 1);
  109.         if (stat(cb, &statrec) == 0)    /* this file exists ? */
  110.         {
  111.             loctptr = localtime(&statrec.st_atime);
  112.             sprintf(datestr[j], "%02d/%02d/%02d",
  113.                     loctptr->tm_mon + 1, loctptr->tm_mday,
  114.                     loctptr->tm_year);
  115.             bull_date[j] = statrec.st_atime;
  116.             fp = fopen(cb, "r");
  117.             fgets(cb, 80, fp);
  118.             cb[strlen(cb) - 1] = '\0';
  119.             cb[39] = '\0';
  120.             strcpy(subject[j], cb);
  121.             fclose(fp);
  122.             fp=NULL;
  123.         }
  124.     }
  125.  
  126.     init();
  127.  
  128.     for (j = 0, lj = 1L; j < 16; j++, lj <<= 1)
  129.     {
  130.         if (bull_date[j] > myacct->bulreadtime)
  131.         {
  132.             updated[j] = 1;
  133.             if (cfg->bul_must_read_flags & lj)
  134.             {
  135.                 must_read[j] = 1;
  136.             }
  137.         }
  138.     }
  139.  
  140.     send(active);               /* send a 'we are alive' to the user */
  141.  
  142. /*
  143. **  Now the main loop -
  144. **   basically, we wait for the user to type something.
  145. **   anything except 'exit' is considered to be a file name.
  146. **   if 'exit' is entered, we will terminate normally.
  147. **   else, attempt to open the file, and send it to the user.
  148. **   we will pause between pages.
  149. */
  150.  
  151.     for (;;)
  152.     {
  153.         send(menutext);
  154.         for (j = 0; j < 16; j++)
  155.         {
  156.             if (bull_date[j])
  157.             {
  158.                 tstr[0] = must_read[j] ? 'M' : ' ';
  159.                 tstr[1] = updated[j] ? 'U' : ' ';
  160.                 tstr[2] = '\0';
  161.                 qprintf(menuformat, j + 1, tstr, datestr[j], subject[j]);
  162.             }
  163.         }
  164.  
  165.         send(prompt);
  166.  
  167.         qgets(cb, 80);
  168.  
  169.         strlwr(cb);
  170.         if ((cb[0] == 'q') || (cb[0] == 'x'))
  171.         {
  172.             for (j = 0, k = 0; j < 16; j++)
  173.             {
  174.                 if (must_read[j])
  175.                 {
  176.                     k++;
  177.                     qprintf(cb, "You must first read bulletin #%d.\r", j + 1);
  178.                 }
  179.             }
  180.  
  181.             if (!k)
  182.             {
  183.                 myacct->bulreadtime = time(NULL);
  184.                 exit(0);
  185.             }
  186.             send("Press [ENTER] to continue..");
  187.             continue;
  188.         }
  189.  
  190.         j = atoi(cb);
  191.         if (j < 1 || j > 16)
  192.         {
  193.             send("Invalid Bulletin Number.  Press [ENTER] to continue.\r");
  194.             qgets(cb, 80);
  195.             continue;
  196.         }
  197.         sprintf(cb, "bulletin.%d", j);
  198.         bulnum = j - 1;
  199.         fp = fopen(cb, "ra");
  200.         if (fp == NULL)
  201.         {                       /* cannot open file! */
  202.             send("Error opening file.\r");
  203.         }
  204.         else
  205.         {                       /* file is open, so we can start sending it
  206.                                  * to user */
  207.             n = 0;
  208. /*
  209. ** This while loop causes us to loop until end of file.
  210. ** At that point we go back to the
  211. ** outer loop, that continues until the user enters 'exit' to
  212. ** terminate the program
  213. */
  214.             while (!n)
  215.             {
  216.                 for (k = 0; k < 23;)
  217.                 {
  218.                     if (fgets(cb, 79, fp) == NULL)
  219.                     {
  220.                 read_err:
  221.                         n = 1;
  222.                         must_read[bulnum] = 0;
  223.                         updated[bulnum] = 0;
  224.                         send("End of bulletin.  Press [ENTER] to continue\r");
  225.                         qgets(cb, 80);
  226.                         break;
  227.                     }
  228.                     else
  229.                     {
  230.                         cb[79] = '\0';
  231.                         len = strlen(cb);
  232.                         if (len == 0)
  233.                             goto read_err;
  234.                         cb[len - 1] = '\r';
  235. /*
  236. ** the screen width of the user's terminal is in the account structure
  237. ** as member 'linlen'.  We can determine how many screen lines this
  238. ** string will create on the user's screen by dividing the length by
  239. ** his screen width.  Add one for the \r at the end
  240. ** we will continue sending output until we have sent 23 screen lines.
  241. */
  242.                         if (len > myacct->linlen)
  243.                             k++;
  244.                         k++;
  245.                         send(cb);
  246.                     }
  247.                 }               /* end for */
  248.                 if (!n)
  249.                 {
  250.                     send(menu2);
  251.                     qgets(cb,80);
  252.                 }               /* end if !n */
  253.             }                   /* end while */
  254.             fclose(fp);
  255.             fp=NULL;
  256.         }                       /* end else */
  257.     }                           /* end for (;;) */
  258. }
  259.  
  260.