home *** CD-ROM | disk | FTP | other *** search
/ Columbia Kermit / kermit.zip / archives / uniflex.zip / ufuhlp.c < prev    next >
C/C++ Source or Header  |  1993-08-23  |  1KB  |  44 lines

  1. /* This program is used to unpack the UniFLEX kermit HELP file. */
  2.  
  3. #include <stdio.h>
  4.  
  5. main()
  6. {
  7.    char *fnm = "ufhelp.txt";            /* Default input file */
  8.    char *outdir = "/gen/kermit";        /* Files go there */
  9.    char *c = "~~~";                     /* File name lead-in */
  10.    FILE *ifp, *ofp;
  11.    char data[100];
  12.  
  13.    ofp = -1;
  14.    if ((ifp = fopen(fnm,"r")) == 0)
  15.    {
  16.       printf("Error opening input file %s\n",fnm);
  17.       exit(1);
  18.    }
  19.    if (chdir(outdir))
  20.    {
  21.       printf("Error going to '%s'\n",outdir);
  22.       exit(1);
  23.    }
  24.  
  25.    while (fgets(data,100,ifp))
  26.    {
  27.       if (strncmp(c,data,3) == 0)       /* lead-in string ? */
  28.       {
  29.          if (ofp != -1)                 /* Close old output file */
  30.             fclose(ofp);
  31.          data[strlen(data)-1] = '\0';   /* Zap trailing \n */
  32.          if ((ofp = fopen(&data[3],"w")) == 0)
  33.          {
  34.             printf("Error opening output file %s\n",&data[3]);
  35.             exit(1);
  36.          }
  37.       }
  38.       else
  39.          fputs(data,ofp);               /* Copy the data */
  40.    }
  41.    fclose(ifp);
  42.    fclose(ofp);
  43. }
  44.