home *** CD-ROM | disk | FTP | other *** search
/ Simtel MSDOS 1992 December / simtel1292_SIMTEL_1292_Walnut_Creek.iso / _bbs / get_area.c < prev    next >
C/C++ Source or Header  |  1992-12-07  |  2KB  |  105 lines

  1. /*
  2.  * get_area.c
  3.  * get area description as line after path
  4.  */
  5.  
  6. #include <stdarg.h>
  7. #include <stdio.h>
  8. #include <stdlib.h>
  9. #include <string.h>
  10.  
  11. FILE *logfile = NULL;
  12.  
  13. #define SIMTEL    1
  14. #define OTHER    2
  15.  
  16. void
  17. myexit(int i) {
  18.     
  19.     fclose(logfile);
  20.     
  21.     exit(i);
  22. }
  23.  
  24. void
  25. print_err(const char *fmt, ...) {
  26.     va_list args;
  27.     char str[0x100];
  28.  
  29.     va_start(args, fmt);
  30.     vsprintf(str, fmt, args);
  31.     va_end(args);
  32.  
  33.     if (logfile)
  34.       fprintf(logfile, "%s", str);
  35.     fprintf(stderr, "%s", str);
  36. }
  37.  
  38. #ifdef __MSDOS__  
  39. void _Cdecl
  40. #else  
  41. void
  42. #endif  
  43. main(int argc, char *argv[]) {
  44.     char buf[200];
  45.     int i;
  46.     int input_t = 0;
  47.     char *p;
  48.     char search[30];
  49.     
  50.     if (argc != 4) {
  51.         fprintf(stderr, "usage: get_area [type] [# spaces] [path] < input_file > output_file\n");
  52.         fprintf(stderr, "type == simtel xxx\n");
  53.         myexit(1);
  54.     }
  55.     
  56.     i = atoi(argv[2]);
  57.     
  58.     if (NULL == (logfile = fopen("logfile", "at"))) {
  59.         print_err("erroring opening logfile\n");
  60.         myexit(1);
  61.     }
  62.     
  63.     if (0 == stricmp(argv[1], "simtel")) {
  64.         input_t = SIMTEL;
  65.         strcpy(search, strrchr(argv[3], '\\') + 1);
  66.     } else
  67.         input_t = OTHER;
  68.     
  69.     while (NULL != gets(buf)) {
  70.         switch(input_t) {
  71.         case SIMTEL:
  72.             p = strtok(buf, " \t");
  73.             if (0 == stricmp(search, p)) {
  74.                 p = strtok(NULL, " \t");
  75.                 p += 2;
  76.                 if (p) {
  77.                     if (i)
  78.                         printf("%*s%s\n", i, " ", p);
  79.                     else
  80.                         printf("%s\n", p);
  81.                 }
  82.                 myexit(0);
  83.             }
  84.             break;
  85.         case OTHER:
  86.             if (0 == stricmp(argv[3], buf)) {
  87.                 if (NULL != gets(buf)) {
  88.                     if (i)
  89.                         printf("%*s%s\n", i, " ", buf);
  90.                     else
  91.                         printf("%s\n", buf);
  92.                 }
  93.                 myexit(0);
  94.             }
  95.             break;
  96.         default:
  97.             print_err("bad input type \n");
  98.             myexit(1);
  99.         }
  100.     }
  101.     
  102.     print_err("no area found:\n%s\n", argv[3]);
  103.     myexit(1);
  104. }
  105.