home *** CD-ROM | disk | FTP | other *** search
/ Media Share 9 / MEDIASHARE_09.ISO / mail / qwkrep.zip / GENI.C < prev    next >
C/C++ Source or Header  |  1992-09-02  |  5KB  |  228 lines

  1. /*
  2.  * geni.c - parse a GEnie input data stream into messages
  3.  */
  4.  
  5. #include    <stdio.h>
  6. #include    <clib.h>
  7. #include    "callback.h"
  8.  
  9. char *mnam[] =
  10.  {
  11.     "jan",
  12.     "feb",
  13.     "mar",
  14.     "apr",
  15.     "may",
  16.     "jun",
  17.     "jul",
  18.     "aug",
  19.     "sep",
  20.     "oct",
  21.     "nov",
  22.     "dec"
  23.  };
  24.  
  25. static char hold[100];
  26.  
  27. static mcvt(mons)
  28. char *mons;
  29.  {
  30.     int i;
  31.  
  32. /* XXX */
  33.  
  34.     lower(mons);
  35.     mons[3] = 0;
  36.     for (i = 0; i < 12; i++)
  37.       if (strcmp(mons, mnam[i]) == 0)
  38.         break;
  39.     if (i < 12)
  40.       i++;
  41.     return(i);
  42.  }
  43.  
  44. static gettok(dest, src, len)
  45. char *dest, *src;
  46.  {
  47.     src = byp(src);
  48.     while (*src != ' ' && *src && len)
  49.      {
  50.         *dest++ = *src++;
  51.         len--;
  52.      }
  53.     *dest = 0;
  54.  }
  55.  
  56. static init_split()
  57.  {
  58.     FILE *fp;
  59.     char buff[30];
  60.  
  61.     strcpy(bbsname, "GENIE");
  62.     strcpy(bbstitle, "GEnie Information Services");
  63.     if ((fp = fopen("genie.cnf", "r")) != (FILE *) NULL &&
  64.                                     fgets(buff, 28, fp) != (char *) NULL)
  65.      {
  66.         strip(buff);
  67.         buff[25] = 0;
  68.         strcpy(bbsuser, buff);
  69.         fclose(fp);
  70.      }
  71.     else
  72.       strcpy(bbsuser, "WHO-AM-I");
  73.  }
  74.  
  75. int geni_split(line, whoami)
  76. char *line;
  77.  {
  78.     static int state = 0;
  79.     static int count;
  80.     int i, j;
  81.     int dt, mon, yr;
  82.     char *oline;
  83.     char junk[10];
  84.     char mons[10];
  85.     char work[80];
  86.  
  87.     static char area[6];
  88.     static char sub_hold[28];
  89.     static int confs = -1;
  90.     static int topics = -1;
  91.     static int nbl;
  92.  
  93.     strncpy(work, byp(oline = line), 78);
  94.     work[78] = 0;
  95.     strip(work);
  96.     if (state == 0 && strncmp(work, "--==>>", 6) == 0 &&
  97.                                 strncmp(&work[9], "<<==--", 6) == 0)
  98.      {
  99.         strncpy(area, &work[6], 3);
  100.         area[3] = 0;
  101.         mine(whoami);
  102.         init_split();
  103.         addconf("MAIL");
  104.         addconf(area);
  105.      }
  106.     if (area[0] == 0)
  107.       strcpy(area, "XXX");
  108.     if (state == 0)
  109.      {
  110.         if (strncmp(line, "From:   ", 8) == 0)
  111.          {
  112.             strcpy(confname, "MAIL");
  113.             gettok(from, &line[8], 25);
  114.             mine(whoami);
  115.             init_split();
  116.             addconf("MAIL");
  117.             strcpy(to, bbsuser);
  118.             state = 1;
  119.             count = 4;
  120.          }
  121.         if (strncmp(line, "Item    ", 8) == 0)
  122.          {
  123.             sscanf(byp(&line[20]), "%d/%d/%d", &yr, &mon, &dt);
  124.             sprintf(m_date, "%02d-%02d-%02d", mon, dt, yr);
  125.             gettok(m_time, byp(&line[43]), 5);
  126.          }
  127.         if (strncmp(line, "Category ", 9) == 0)
  128.          {
  129.             if (sscanf(line, "Category %d, Topic %d", &confs, &topics) == 2)
  130.              {
  131.                 strcpy(confname, area);
  132.                 state = 4;
  133.                 newmsg();
  134.              }
  135.          }
  136.         if (strncmp(line, "Sub:", 4) == 0)
  137.          {
  138.             memset(sub_hold, 0, 26);
  139.             strncpy(sub_hold, byp(&line[4]), 25);
  140.          }
  141.      }
  142.     else if (state == 1)
  143.      {
  144.         if (strncmp(line, "To:     ", 8) == 0)
  145.          {
  146.             gettok(to, &line[8], 25);
  147.             count = 4;
  148.          }
  149.         if (strncmp(line, "Sub:", 4) == 0)
  150.          {
  151.             memset(subject, 0, 26);
  152.             strncpy(subject, byp(&line[4]), 25);
  153.             state = 2;
  154.             newmsg();
  155.             nbl = 0;
  156.          }
  157.         else if (strncmp(line, "cc:", 3) == 0 || strncmp(line, "Cc:", 3) == 0)
  158.           count = 4;
  159.         else if (--count == 0)
  160.           state = 0;
  161.         return(0);
  162.      }
  163.     else if (state == 2)
  164.      {
  165.         if (strlen(byp(strip(line))) == 0)
  166.           state = 3;
  167.         return(0);
  168.      }
  169.     else if (state == 3)
  170.      {
  171.         if (strcmp(line, "=END=") == 0)
  172.          {
  173.             state = 0;
  174.             finish_msg();
  175.          }
  176.         else if (strlen(line) == 0)
  177.           nbl++;
  178.         else
  179.          {
  180.             while (nbl)
  181.              {
  182.                 nbl--;
  183.                 writemsg("");
  184.             }
  185.            writemsg(line);
  186.          }
  187.      }
  188.     else if (state == 4)
  189.      {
  190.         sscanf(line, "Message %d %s %s %d, %d", &msgnum, junk, mons, &dt, &yr);
  191.         msgnum--;
  192.         mon = mcvt(mons);
  193.         sprintf(m_date, "%02d-%02d-%02d", mon, dt, yr % 100);
  194.         state = 5;
  195.         if (topics != -1)
  196.          {
  197.             sprintf(hold, "%03d%03d / CONFERENCE %d, TOPIC: %d", confs, topics,
  198.                                                                 confs, topics);
  199.             writemsg(hold);
  200.             sprintf(to, "ALL %03d/%03d", confs, topics);
  201.             topics = -1;
  202.          }
  203.      }
  204.     else if (state == 5)
  205.      {
  206.         strncpy(from, line, 25);
  207.         strcpy(subject, sub_hold);
  208.         sscanf(byp(&line[25]), "at %s", m_time);
  209.         state = 6;
  210.      }
  211.     else if (state == 6)
  212.      {
  213.         if (strlen(byp(strip(line))) == 0)
  214.           state = 7;
  215.      }
  216.     else if (state == 7)
  217.      {
  218.         if (strcmp(line, " ************") == 0 ||
  219.                             strcmp(line, " ------------") == 0)
  220.          {
  221.             state = 0;
  222.             finish_msg();
  223.          }
  224.         else
  225.           writemsg(line);
  226.      }
  227.  }
  228.