home *** CD-ROM | disk | FTP | other *** search
/ CICA 1994 September / CICA_Shareware_for_Windows_Walnut_Creek_September_1994.iso / _bbs / file_id / find_diz.c < prev    next >
C/C++ Source or Header  |  1994-08-04  |  1KB  |  72 lines

  1. /*
  2.  * find_diz.c
  3.  * this finds the file description in the index file.
  4.  * 
  5.  */
  6.  
  7. #include <stdarg.h>
  8. #include <stdlib.h>
  9. #include <stdio.h>
  10. #include <string.h>
  11.  
  12. FILE *logfile;
  13.  
  14. static void _Cdecl    print_err(const char *fmt, ...);
  15.  
  16. static char copyright[] = "make_diz, Copyright (C) 1994 Walnut Creek CDROM\n";
  17.  
  18. void _Cdecl
  19. main(int argc, char *argv[]) {
  20.     FILE *fd;
  21.     FILE *out;
  22.     char buf1[100];
  23.     char buf[2000];
  24.     char *p;
  25.  
  26.     sprintf(buf1, "%s\\wildcat.txt", argv[2]);
  27.  
  28.     if (NULL == (fd = fopen(buf1, "r"))) {
  29.         fprintf(stderr, "Unable to open `%s' on CDROM.\n", buf1);
  30.         exit(1);
  31.     }
  32.  
  33.     p = strrchr(argv[1], '\\') + 1;
  34.  
  35.     while (NULL != fgets(buf, 1998, fd)) {
  36.         if (0 == strncmpi(buf, p, strlen(p))) {
  37.             if (NULL == (out = fopen("file_id.diz", "wt"))) {
  38.                 print_err("erroring opening file_id.diz\n");
  39.                 exit(1);
  40.             }
  41.  
  42.             fprintf(out, "%s", &buf[14]);
  43.             fclose(out);
  44.             
  45.             exit(0);
  46.         }
  47.     }
  48.  
  49.     print_err("unable to find `%s' in `%s'\n", p, buf1);
  50.     exit(1);
  51. }
  52.  
  53. void _Cdecl
  54. print_err(const char *fmt, ...) {
  55.     va_list args;
  56.     char str[500];
  57.  
  58.     va_start(args, fmt);
  59.     vsprintf(str, fmt, args);
  60.     va_end(args);
  61.  
  62.     if (NULL == (logfile = fopen("logfile", "at"))) {
  63.         fprintf(stderr, "erroring opening logfile\n");
  64.         exit(1);
  65.     }
  66.  
  67.     fprintf(logfile, "%s", str);
  68.     fclose(logfile);
  69.     
  70.     fprintf(stderr, "%s", str);
  71. }
  72.