home *** CD-ROM | disk | FTP | other *** search
-
- /*
- * STATES.C 5/14/89
- * Makes a Hierarchical list from W9ZRX's bbs STATES file.
- * Syntax < STATES [STATE.FILE] [COUNTRY] [CONTINENT] >
- * Defaults are [LUSA0489.SRT] [USA] [NA].
- * (C) 1989 by the CBBS Group
- */
-
- #include <stdio.h>
- #include <ctype.h>
- #include <string.h>
-
- #define ln_buf 256
- #define ln_call 6
- #define true 1
- #define false 0
-
- char buf[ln_buf];
-
- char *infile = "LUSA0489.SRT";
- char *outfile = "STATES.MB";
- char *contry = "USA";
- char *contint = "NA";
-
- main(argc, argv)
- int argc;
- char *argv[];
- {
- FILE *in, *out;
- char call[11], call1[11], state[3];
- int count, first;
-
- if (argc > 1) infile = argv[1];
- if (argc > 2) contry = argv[2];
- if (argc > 3) contint = argv[3];
-
- /*
- * Open the input file.
- */
-
- if ((in = fopen(infile, "r")) == NULL)
- {
- printf("Could not find input file - %s\n", infile);
- exit(0);
- }
-
- /*
- * Open the output file.
- */
-
- if ((out = fopen(outfile, "w")) == NULL)
- {
- printf("Could not open STATES.MB\n");
- exit(0);
- }
- count = 1;
- fill(call1, '\0', 11);
- fill(state, '\0', 3);
- first = true;
-
- while(fgets(buf, ln_buf, in) != NULL)
- {
- if (buf[0] != '\n') /* Buffer is not a CR. */
- if (isdigit(buf[2]) != 0) /* Must be a callsign. */
- if ((first) || (strncmp(call1, buf, ln_call) != 0)) /* No dups. */
- {
- strncpy(state, &buf[29], 2);
- strncpy(call1, &buf[0], 10);
- pcall(call, call1);
- fprintf(out, "%s.%s.%s.%s\n", call, state, contry, contint);
- printf("%u\n", count);
- count++;
- first = false;
- }
- }
-
- fclose(in);
- fclose(out);
-
- }
-
- /*
- * Fill memory with a character.
- */
-
- fill(adr, ch, len)
- char *adr;
- char ch;
- int len;
- {
- while (len--) *adr++ = ch;
- }
-
- /*
- * Parse a call. Blank pad the output field. Remove leading and
- * trailing spaces and ssid.
- */
-
- pcall(c,p)
- char *c, *p;
- {
- register short i;
- fill (c, '\0',(ln_call+1));
- while(*p && (*p == ' ')) p++;
- for (i = ln_call; i && *p; i--)
- {
- if (*p == ' ') return;
- if (*p == '-') return;
- *c++ = *p++;
- }
- }