home *** CD-ROM | disk | FTP | other *** search
/ World of Ham Radio 1994 January / AMSOFT_1994.iso / packet / pbbs / cbbs / prog / states.c < prev    next >
Encoding:
C/C++ Source or Header  |  1993-12-31  |  2.1 KB  |  113 lines

  1.  
  2. /*
  3.  *  STATES.C  5/14/89
  4.  *  Makes a Hierarchical list from W9ZRX's bbs STATES file.
  5.  *  Syntax < STATES [STATE.FILE] [COUNTRY] [CONTINENT] >
  6.  *  Defaults are [LUSA0489.SRT] [USA] [NA].
  7.  *  (C) 1989 by the CBBS Group
  8.  */
  9.  
  10. #include <stdio.h>
  11. #include <ctype.h>
  12. #include <string.h>
  13.  
  14. #define ln_buf 256
  15. #define ln_call 6
  16. #define true 1
  17. #define false 0
  18.  
  19. char buf[ln_buf];
  20.  
  21. char *infile  = "LUSA0489.SRT";
  22. char *outfile = "STATES.MB";
  23. char *contry  = "USA";
  24. char *contint = "NA";
  25.  
  26. main(argc, argv)
  27. int argc;
  28. char *argv[];
  29. {
  30.   FILE *in, *out;
  31.   char call[11], call1[11], state[3];
  32.   int count, first;
  33.  
  34.   if (argc > 1) infile = argv[1];
  35.   if (argc > 2) contry = argv[2];
  36.   if (argc > 3) contint = argv[3];
  37.  
  38. /*
  39.  *  Open the input file.
  40.  */
  41.  
  42.   if ((in = fopen(infile, "r")) == NULL)
  43.   {
  44.     printf("Could not find input file - %s\n", infile);
  45.     exit(0);
  46.   }
  47.  
  48. /*
  49.  *  Open the output file.
  50.  */
  51.  
  52.   if ((out = fopen(outfile, "w")) == NULL)
  53.   {
  54.     printf("Could not open STATES.MB\n");
  55.     exit(0);
  56.   }
  57.   count = 1;
  58.   fill(call1, '\0', 11);
  59.   fill(state, '\0', 3);
  60.   first = true;
  61.  
  62.   while(fgets(buf, ln_buf, in) != NULL)
  63.   {
  64.      if (buf[0] != '\n')        /* Buffer is not a CR. */
  65.      if (isdigit(buf[2]) != 0)  /* Must be a callsign. */
  66.      if ((first) || (strncmp(call1, buf, ln_call) != 0)) /* No dups. */
  67.        {
  68.          strncpy(state, &buf[29], 2);
  69.          strncpy(call1, &buf[0], 10);
  70.          pcall(call, call1);
  71.          fprintf(out, "%s.%s.%s.%s\n", call, state, contry, contint);
  72.          printf("%u\n", count);
  73.          count++;
  74.          first = false;
  75.        }
  76.   }
  77.  
  78.   fclose(in);
  79.   fclose(out);
  80.  
  81. }
  82.  
  83. /*
  84.  *  Fill memory with a character.
  85.  */
  86.  
  87. fill(adr, ch, len)
  88. char *adr;
  89. char ch;
  90. int len;
  91. {
  92.   while (len--) *adr++ = ch;
  93. }
  94.  
  95. /*
  96.  *  Parse a call. Blank pad the output field. Remove leading and
  97.  *  trailing spaces and ssid.
  98.  */
  99.  
  100. pcall(c,p)
  101. char *c, *p;
  102. {
  103.   register short i;
  104.   fill (c, '\0',(ln_call+1));
  105.   while(*p && (*p == ' ')) p++;
  106.   for (i = ln_call; i && *p; i--)
  107.   {
  108.     if (*p == ' ') return;
  109.     if (*p == '-') return;
  110.     *c++ = *p++;
  111.   }
  112. }
  113.