home *** CD-ROM | disk | FTP | other *** search
/ Crawly Crypt Collection 2 / crawlyvol2.bin / program / c / plstsrc / misc.c < prev    next >
Encoding:
C/C++ Source or Header  |  1988-12-31  |  7.7 KB  |  255 lines

  1. /************************************************************************
  2. *************************************************************************
  3. ** NOTE:                                                               **
  4. **   This Module is part of the ATARI ST Implementation of Parselst    **
  5. **   It should NOT be used for general reference. Please read the com- **
  6. **   plete Disclaimer at the TOP of PARSELST.C.                        **
  7. **   Peter Glasmacher at 1:143/9  Ph (408)985-1538                     **
  8. *************************************************************************
  9. *************************************************************************/
  10.  
  11. /*----------------------------------------------------------------------*
  12. *                              Nodelist Parser                          *
  13. *                                                                       *
  14. *              This module was originally written by Bob Hartman        *
  15. *                       Sysop of FidoNet node 1:132/101                 *
  16. *                                                                       *
  17. * Spark Software, 427-3 Amherst St, CS 2032, Suite 232, Nashua, NH 03061*
  18. *                                                                       *
  19. * This program source code is being released with the following         *
  20. * provisions:                                                           *
  21. *                                                                       *
  22. * 1.  You are  free to make  changes to this source  code for use on    *
  23. *     your own machine,  however,  altered source files may not be      *
  24. *     distributed without the consent of Spark Software.                *
  25. *                                                                       *
  26. * 2.  You may distribute "patches"  or  "diff" files for any changes    *
  27. *     that you have made, provided that the "patch" or "diff" files are *
  28. *     also sent to Spark Software for inclusion in future releases of   *
  29. *     the entire package.   A "diff" file for the source archives may   *
  30. *     also contain a compiled version,  provided it is  clearly marked  *
  31. *     as not  being created  from the original source code.             *
  32. *     No other  executable  versions may be  distributed without  the   *
  33. *     consent of Spark Software.                                        *
  34. *                                                                       *
  35. * 3.  You are free to include portions of this source code in any       *
  36. *     program you develop, providing:  a) Credit is given to Spark      *
  37. *     Software for any code that may is used, and  b) The resulting     *
  38. *     program is free to anyone wanting to use it, including commercial *
  39. *     and government users.                                             *
  40. *                                                                       *
  41. * 4.  There is  NO  technical support  available for dealing with this  *
  42. *     source code, or the accompanying executable files.  This source   *
  43. *     code  is provided as is, with no warranty expressed or implied    *
  44. *     (I hate legalease).   In other words, if you don't know what to   *
  45. *     do with it,  don't use it,  and if you are brave enough to use it,*
  46. *      you're on your own.                                              *
  47. *                                                                       *
  48. * Spark Software may be contacted by modem at (603) 888-8179            *
  49. * (node 1:132/101)                                                      *
  50. * on the public FidoNet network, or at the address given above.         *
  51. *                                                                       *
  52. *-----------------------------------------------------------------------*/
  53.  
  54. #include <stdio.h>
  55. #include <stdlib.h>
  56. #include <string.h>
  57. #include <ctype.h>
  58. #include <time.h>
  59. #  include <ext.h>
  60. #  include <tos.h>
  61.  
  62. #include "types.h"
  63. #include "externs.h"
  64. #include "pl.h"
  65.  
  66.  
  67. cmp (a, b)
  68. struct nidxs *a, *b;
  69. {
  70.    if (a->idxnet < b->idxnet)    {
  71.       return (-1);
  72.    }   else if (a->idxnet > b->idxnet)    {
  73.       return (1);
  74.    }  else      {
  75.       return (a->idxnode - b->idxnode);
  76.    }
  77. }
  78.  
  79. /* Returns the next field that ends with a comma or newline */
  80.  
  81. char *nextfield (p, s)
  82. char *p, *s;
  83. {
  84.    while ((*p) && (*p != ',') && (*p != '\n'))    {
  85.       *s++ = *p++;
  86.    }
  87.    *s = '\0';
  88.    return (++p);
  89. }
  90.  
  91. /* Converts a "special" word to upper case and appends a space */
  92.  
  93. void spec_word (char *b1)
  94. {
  95. char *p1;
  96.  
  97.    strupr (b1);
  98.    p1 = b1 + strlen (b1);
  99.    *p1++ = ' ';
  100.    *p1 = '\0';
  101. }
  102.  
  103. /* Uses malloc() to get memory, but exits on allocation error */
  104.  
  105. char *mymalloc(unsigned int s)
  106. {
  107. char *p;
  108. extern void *malloc();
  109.  
  110.    p = malloc (s);
  111.    if (p == NULL)    {
  112.       printf ("\n\nNot Enough Memory - Exiting\n\n");
  113.       exit (1);
  114.    }
  115.    return (p);
  116. }
  117.  
  118. /* Gets the name of the nodelist that should be processed this run */
  119.  
  120. void nfile_name (char **fn)
  121. {
  122. int i;
  123. long t;
  124. struct tm *tm1, *localtime();
  125.  
  126.    /* Get todays info */
  127.    time (&t);
  128.    tm1 = localtime (&t);
  129.  
  130.    /* find all NODELIST.* files and if end in number, put in array */
  131.    get_nl_list ();
  132.  
  133.    for (i = tm1->tm_yday + 1; i >= 0; i--)    {
  134.       if (nl[i])   {
  135.          *fn = mymalloc (13);
  136.          sprintf (*fn, "NODELIST.%03d", i);
  137.          return;
  138.       }
  139.    }
  140.  
  141.    /* If no nodelist files, try last years */
  142.    for (i = 366; i >= tm1->tm_yday; i--)     {
  143.       if (nl[i])     {
  144.          *fn = mymalloc (13);
  145.          sprintf (*fn, "NODELIST.%03d", i);
  146.          return;
  147.       }
  148.    }
  149.  
  150.    /* If still nothing, try the big numbers */
  151.    for (i = 999; i >= 367; i--)    {
  152.       if (nl[i])   {
  153.          *fn = mymalloc (13);
  154.          sprintf (*fn, "NODELIST.%03d", i);
  155.          return;
  156.       }
  157.    }
  158.  
  159.    printf ("\n\nCannot find a valid NODELIST.xxx file - Exiting\n\n");
  160.    exit (1);
  161. }
  162.  
  163. /* Remove dashes from the string */
  164.  
  165. void undash (str)
  166. char *str;
  167. {
  168.    char *p, *p1;
  169.  
  170.    p = str;
  171.    p1 = str;
  172.    while (*p)   {
  173.       if (*p != '-')
  174.          *p1++ = *p;
  175.       ++p;
  176.    }
  177.    *p1 = '\0';
  178. }
  179.  
  180. void get_nl_list (void)
  181. {
  182.    char str[13];
  183.    char init_name[13];
  184.    int i, d;
  185.  
  186.    /* Start out by initializing what we are looking for */
  187.    strcpy (init_name, "NODELIST.*");
  188.    d = 0;
  189.  
  190.    /* Now loop through getting each file name that matches,
  191.       and copying the number into the array */
  192.    do      {
  193.       (void) filedir (init_name, d, str, 0);
  194.       i = 0;
  195.       d = 1;
  196.       sscanf (str, "NODELIST.%d", &i);
  197.  
  198.       if ((i > 0) &&
  199.           (isdigit (str[9])) &&
  200.           (isdigit (str[10])) &&
  201.           (isdigit (str[11])))     {
  202.          nl[i] = 1;
  203.       }
  204.    }
  205.    while (str[0] != '\0');
  206. }
  207.  
  208. struct ffblk sbuf;
  209.  
  210. filedir (name, times, ret_str, mode)
  211. char *name;
  212. int times;
  213. char *ret_str;
  214. int mode;
  215. {
  216.         if (times == 0)
  217.                 {
  218.                 if (findfirst (name,&sbuf,mode))
  219.                         sbuf.ff_name[0] = '\0';
  220.                 strcpy (ret_str, sbuf.ff_name);
  221.                 }
  222.         else
  223.                 {
  224.                 if (findnext (&sbuf))
  225.                         sbuf.ff_name[0] = '\0';
  226.                 strcpy (ret_str, sbuf.ff_name);
  227.                 }
  228.  
  229.    return (sbuf.ff_attrib);
  230.         }
  231.  
  232. void get_addr (char *s, int *z, int *net, int *node)
  233. {
  234.    if (sscanf (s, "%d:%d/%d", z, net, node) != 3)
  235.       {
  236.       *z = myzone;
  237.       if (sscanf (s, "%d/%d", net, node) != 2)
  238.          {
  239.          *node = *net;
  240.          *net = mynet;
  241.          }
  242.       }
  243. }
  244.  
  245. #undef exit
  246. void stexit(int code)
  247. {
  248.   if (wait)   {
  249.      puts("\n\rPress a key to exit.....\n\r");
  250.      Cnecin();
  251.   }
  252.      exit(code);
  253. }
  254.  
  255.