home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 2 BBS / 02-BBS.zip / VP2_409E.SZH / SEEN.C < prev    next >
Text File  |  1991-06-27  |  10KB  |  412 lines

  1. /*
  2.   $Header: seen.c 3.3 87/12/12 00:45:16 Bob Exp $
  3.  
  4.                           The Conference Mail System
  5.  
  6.               This module was originally written by Bob Hartman
  7.                        Sysop of FidoNet node 1:132/101
  8.  
  9.    Spark Software, 427-3 Amherst St, CS 2032, Suite 232, Nashua, NH 03061
  10.  
  11.  The Conference Mail System  is a  complete Echomail processing package.  It
  12.  is a superset of the original  Echomail utilities created by Jeff Rush, and
  13.  also contains ideas gleaned from the  ARCmail,  Renum,  oMMM, MGM, and Opus
  14.  programs that were created by various software authors.
  15.  
  16.  This program source code is being released with the following provisions:
  17.  
  18.  1.  You are  free to make  changes to this source  code for use on your own
  19.  machine,  however,  altered source files may not be distributed without the
  20.  consent of Spark Software.
  21.  
  22.  2.  You may distribute "patches"  or  "diff" files for any changes that you
  23.  have made, provided that the "patch" or "diff" files are also sent to Spark
  24.  Software for inclusion in future releases of the entire package.   A "diff"
  25.  file for the source archives may also contain a compiled version,  provided
  26.  it is  clearly marked as not  being created  from the original source code.
  27.  No other  executable  versions may be  distributed without  the  consent of
  28.  Spark Software.
  29.  
  30.  3.  You are free to include portions of this source code in any program you
  31.  develop, providing:  a) Credit is given to Spark Software for any code that
  32.  may is used, and  b) The resulting program is free to anyone wanting to use
  33.  it, including commercial and government users.
  34.  
  35.  4.  There is  NO  technical support  available for dealing with this source
  36.  code, or the accompanying executable files.  This source  code  is provided
  37.  as is, with no warranty expressed or implied (I hate legalease).   In other
  38.  words, if you don't know what to do with it,  don't use it,  and if you are
  39.  brave enough to use it, you're on your own.
  40.  
  41.  Spark Software may be contacted by modem at (603) 888-8179 (node 1:132/101)
  42.  on the public FidoNet network, or at the address given above.
  43.  
  44.  To use this code you will need Microsoft C version 4.0, and also Microsoft
  45.  Macro Assembler version 4.0.
  46.  
  47. */
  48.  
  49. /*
  50.    $Log:    seen.c $
  51.  * Revision 3.3  87/12/12  00:45:16  Bob
  52.  * Source code release
  53.  *
  54. */
  55.  
  56. #include <stdio.h>
  57. #include <ctype.h>
  58. #include <fcntl.h>
  59. #include <io.h>
  60. #include <time.h>
  61. #include <string.h>
  62. #include <stdlib.h>
  63. #include <math.h>
  64. #include "fastecho.h"
  65.  
  66. #define DEBUG 0
  67.  
  68. extern SEACONFIG config;
  69. extern AREAS_PTR areas[];
  70. extern char board_name[], sysop_name[];
  71. extern int tot_areas;
  72. extern char bbsfile[];
  73. extern char *arc_cmd[];
  74. extern int nread;
  75. extern int arc_args;
  76. extern int last_msg;
  77. extern int high_one;
  78. extern int convert;
  79. extern char seen_byline[];
  80. extern char originline[];
  81. extern char tearline[];
  82. extern int max_msgs;
  83. extern int ctrla;
  84. extern int *msg_nums;
  85. extern char *holder1;
  86. extern int mail_low;
  87. extern int mail_high;
  88. extern char *seen_by;
  89. extern char *origin;
  90. extern char *tear;
  91. extern char *holder;
  92. extern int tearl;
  93. extern int originl;
  94. extern int seen_byl;
  95. extern int msgl;
  96. extern int seen_nets[];
  97. extern int seen_nodes[];
  98. extern int not_seen[];
  99. extern int tot_seen;
  100. extern char arealine[];
  101. extern int areal;
  102. extern MSG_PTR h;
  103. extern int msgs_done;
  104. extern int priv_net;
  105.  
  106. void next_str (char * *p,char *sb_string,int l,int l1)
  107. {
  108.    char *p1;
  109.  
  110. #if DEBUG
  111.    printf ("Attempting to find '%s' in:\n%s\n", sb_string, *p);
  112. #endif
  113.  
  114.    p1 = *p;
  115.  
  116. /* while (1) { */
  117.    while (*(*p)) {
  118.  
  119. #if DEBUG
  120.       printf ("calling with '%s', '%c', '%d'\n", *p, *sb_string, l1);
  121. #endif
  122.  
  123.       *p = match_byte (*p, *sb_string, l1);
  124.  
  125.       /* If we are past the end of the message, then get out */
  126.       if (*p == NULL)
  127.       {
  128.  
  129. #if DEBUG
  130.          printf ("no dice\n");
  131. #endif
  132.  
  133.          *p = (char *) (p1 + l1);
  134.          return;
  135.       }
  136.  
  137. #if DEBUG
  138.       printf ("Matched here '%s'\n", *p);
  139. #endif
  140.  
  141.       if (strncmp (*p, sb_string, l) != 0)
  142.       {
  143.          ++(*p);
  144.          continue;
  145.       }
  146.       else
  147.       {
  148.  
  149. #if DEBUG
  150.          printf("It matched good\n");
  151. #endif
  152.          break;
  153.       }
  154.    }
  155. }
  156.  
  157. void get_seen_bys (
  158.    char *st_string,
  159.    int st_stringl,
  160.    char *sb_string,
  161.    int snets[],
  162.    int snodes[],
  163.    int *tseen)
  164. {
  165.    int j, last_net, l;
  166.    char *p;
  167.  
  168.    p = st_string;
  169.    last_net = -1;
  170.    *tseen = 0;
  171.    l = strlen (sb_string);
  172.  
  173.    next_str (&p, sb_string, l, st_stringl);
  174.  
  175.    while (*p)
  176.    {
  177.       /* Make sure that we can still store them */
  178.       if (*tseen >= 450)
  179.          break;
  180.  
  181.       /* Get to a digit */
  182.       while (*p)
  183.       {
  184.          /* If it is a digit, we are all set */
  185.          if (isdigit(*p))
  186.             break;
  187.  
  188.          /* If it is a hard return, then we have to get to the next SB */
  189.          else if (*p == '\r')
  190.          {
  191.             next_str (&p, sb_string, l, st_stringl - (int) (p - st_string));
  192.          }
  193.          else
  194.             ++p;
  195.       }
  196.  
  197.       if (*p == '\0')
  198.          break;
  199.  
  200.       /* Now get the net out of net/node, or just the node */
  201.       j = atoi (p);
  202.  
  203.       /* Now get rid of that number */
  204.       while (isdigit (*p))
  205.          ++p;
  206.  
  207.       /* Is it a net/node pair? */
  208.       if (*p == '/')
  209.       {
  210.          ++p;
  211.          last_net = snets[*tseen] = j;
  212.          snodes[*tseen] = atoi (p);
  213.          while (isdigit (*p))
  214.             ++p;
  215.       }
  216.       else
  217.       {
  218.          snets[*tseen] = last_net;
  219.          snodes[*tseen] = j;
  220.       }
  221.  
  222. #if DEBUG
  223.       printf ("Got seen-by %d/%d\n", snets[*tseen], snodes[*tseen]);
  224. #endif
  225.  
  226.       /* This logic assumes that seen-bys are ordered (as they should be) */
  227.       if ((snets[*tseen-1] != snets[*tseen]) ||
  228.           (snodes[*tseen-1] != snodes[*tseen]))
  229.       {
  230.          ++*tseen;
  231.       }
  232.  
  233. /*
  234.       for (k = 0; k < *tseen; k++)
  235.       {
  236.          if ((snets[k] == snets[*tseen]) &&
  237.              (snodes[k] == snodes[*tseen]))
  238.          {
  239.             break;
  240.          }
  241.       }
  242.       if (k >= *tseen)
  243.          ++*tseen;
  244.  */
  245.  
  246.    }
  247. }
  248.  
  249. void create_seen (
  250.    char *ptr,
  251.    int nets[],
  252.    int nodes[],
  253.    int num_nodes,
  254.    int normal,
  255.    char *sb_string)
  256. {
  257.    register int cnt1;
  258.    int i, lastnet, cnt;
  259.    char *curloc;
  260.    char *p21;
  261.    char next[50];
  262.  
  263.    p21 = ptr;
  264.    /* Make the last net be nothing legal */
  265.    lastnet = -100;
  266.  
  267.    /* If we are doing the ^A kludge, do it */
  268.    if (ctrla)
  269.    {
  270.       *p21++ = 1;
  271.    }
  272.    else
  273.    {
  274.       *p21++ = '\n';
  275.    }
  276.    strcpy (p21, sb_string);
  277.  
  278.    /* So far the length is zero */
  279.    seen_byl = 0;
  280.  
  281.    /* Our count is as many chars as we put in so far */
  282.    cnt = strlen (p21) + 1;
  283.  
  284.    /* Current pointer for next one */
  285.    curloc = p21+strlen(p21);
  286.  
  287.    /* Now for each node put in the seen-by */
  288.    for (i = 0; i < num_nodes; i++)
  289.    {
  290.  
  291. #if DEBUG
  292.       printf ("Current is %d/%d\n", nets[i], nodes[i]);
  293. #endif
  294.  
  295.       /* If we are dealing with a private net, be careful */
  296.       if (!normal)
  297.       {
  298.          if (nets[i] == priv_net)
  299.             continue;
  300.       }
  301.  
  302.       /* If the net or node number is negative, bag it */
  303.       if ((nets[i] <= 0) || (nodes[i] < 0))
  304.          continue;
  305.  
  306.       /* If it was the same as the last net, don't put in the net number */
  307.       if (nets[i] == lastnet)
  308.       {
  309. /*       itoa (nodes[i], next, 10);
  310.          p1 = &next[strlen(next)];
  311.          *p1++ = ' ';
  312.          *p1 = '\0';
  313.  */
  314.          sprintf (next, "%d ", nodes[i]);
  315.  
  316. #if DEBUG
  317.          printf ("next1 = '%s'\n", next);
  318. #endif
  319.  
  320.       }
  321.       else
  322.       {
  323. /*       itoa (nets[i], next, 10);
  324.          p1 = &next[strlen(next)];
  325.          *p1++ = '/';
  326.          itoa (nodes[i], p1, 10);
  327.          p1 = &p1[strlen(p1)];
  328.          *p1++ = ' ';
  329.          *p1 = '\0';
  330.  */
  331.          sprintf (next, "%d/%d ", nets[i], nodes[i]);
  332.  
  333. #if DEBUG
  334.          printf ("next = '%s'\n", next);
  335. #endif
  336.  
  337.          /* Set the new lastnet variable */
  338.          lastnet = nets[i];
  339.       }
  340.  
  341. #if DEBUG
  342.       printf ("currently it is '%s'\n", ptr);
  343. #endif
  344.  
  345.       /* If our current line would be more than 70 chars start a new line */
  346.       if (cnt + strlen (next) >= 70)
  347.       {
  348.          /* Do the ^A kludge properly */
  349.          *curloc++ = '\r';
  350.          *curloc++ = '\n';
  351.          if (ctrla)
  352.          {
  353.             *curloc++ = 1;
  354.             cnt1 = 1;
  355.          }
  356.          else
  357.          {
  358.             cnt1 = 0;
  359.          }
  360.          strcpy (curloc, sb_string);
  361.  
  362.          /* Add in the total count so far */
  363.          seen_byl += cnt;
  364.  
  365.          /* The count for this line so far */
  366.          cnt = strlen (curloc) + cnt1 + 2;
  367.          cnt1 = cnt - cnt1 - 2;
  368.  
  369.          /* Increment the pointer by the right amount */
  370.          curloc += cnt1;
  371.  
  372. /*       itoa (nets[i], next, 10);
  373.          p1 = &next[strlen(next)];
  374.          *p1++ = '/';
  375.          itoa (nodes[i], p1, 10);
  376.          p1 = &p1[strlen(p1)];
  377.          *p1++ = ' ';
  378.          *p1 = '\0';
  379.  */
  380.  
  381.          sprintf (next, "%d/%d ", nets[i], nodes[i]);
  382.  
  383. #if DEBUG
  384.          printf ("next2 = '%s'\n", next);
  385. #endif
  386.  
  387.       }
  388.  
  389.       /* Add in the new number */
  390.       strcpy (curloc, next);
  391.  
  392.       /* The length of this string so we don't count it again */
  393.       cnt1 = strlen (next);
  394.  
  395.       /* Increment the current location pointer */
  396.       curloc += cnt1;
  397.  
  398.       /* Increment our line count */
  399.       cnt += cnt1;
  400.  
  401. #if DEBUG
  402.       printf ("its '%s'\n", ptr);
  403. #endif
  404.  
  405.    }
  406.  
  407.    strcpy (curloc, "\r\n\r\n");
  408.    seen_byl += cnt + 4;
  409.  
  410. }
  411.  
  412.