home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 10 Tools / 10-Tools.zip / ICONPL8.ZIP / UNPACK.C < prev    next >
Text File  |  1990-03-23  |  2KB  |  60 lines

  1. #include <stdio.h>
  2. /*
  3.  *  This program is designed to unpack the individual files that have
  4.  *  been combined in .pak files to facilitate file transfer. In a .pak
  5.  *  file, there are heading lines consisting of
  6.  *
  7.  *    ##########
  8.  *
  9.  *  followed by a file name, followed by the lines of the file up to
  10.  *  the next heading line.
  11.  *
  12.  *  This program expects the .pak file as standard input and creates
  13.  *  the unpacked file at the local it is run.
  14.  *
  15.  *  This program is not particularly sophisticated and it may need modification
  16.  *  for the local environment.  In particular, it uses gets(s) to get the
  17.  *  next line into s without a line terminator.  The alternative is to use
  18.  *  fgets(s,n,stdin) and replace the line terminator by a null.
  19.  */
  20.  
  21. /*
  22.  *  Maximum line length; some test output has very long lines.
  23.  */
  24. #define maxlen 1000
  25.  
  26. main()
  27.    {
  28.    char line[maxlen+2];
  29.    char name[30];
  30.    int first;
  31.    FILE *outfile;
  32.  
  33.    while (fgets(line, maxlen+2, stdin)) {    /* get the next line */
  34.       if (!strcmp("##########\n", line)) {    /* look for heading line */
  35.          if (first == 1)
  36.             fclose(outfile);            /* close currently open file */
  37.          first = 1;
  38.          if (gets(name) == NULL) {        /* get file name */
  39.             fprintf(stderr,"premature eof on input\n");
  40.             fflush(stderr);
  41.             exit();
  42.             }
  43.          outfile = fopen(name, "w");        /* open file for writing */
  44.          if (outfile == NULL) {
  45.             fprintf(stderr,"cannot open file \"%s\"\n", name);
  46.             abort();
  47.             }
  48.          }
  49.       else {
  50.          fputs(line,outfile);            /* else write line to file */
  51.          if (ferror(outfile)) {
  52.             fprintf(stderr,"error writing \"%s\"\n");
  53.             fflush(stderr);
  54.             abort();
  55.             }
  56.          }
  57.       }
  58.    exit();
  59.    }
  60.