home *** CD-ROM | disk | FTP | other *** search
/ DP Tool Club 15 / CD_ASCQ_15_070894.iso / maj / 678 / un_arc.c < prev    next >
Text File  |  1994-02-12  |  2KB  |  89 lines

  1. /*
  2. **   UN_ARC.C       Copyright (C) 1992 by MarshallSoft Computing, Inc.
  3. **
  4. **   This program is used to expand archive created with MK_ARC. For
  5. **   example, to un-archive all the files in 'C.ARF', type:
  6. **
  7. **      UN_ARC C.ARF
  8. */
  9.  
  10. #include <stdio.h>
  11. #include <stdlib.h>
  12. #include <dos.h>
  13. #include <fcntl.h>
  14. #include <sys\types.h>
  15. #include <sys\stat.h>
  16. #include <io.h>
  17. #include <string.h>
  18. #include <conio.h>
  19.  
  20. #include "LZW4C.H"
  21. #include "RW_IO.H"
  22. #include "DIR_IO.H"
  23. #include "SAYERROR.H"
  24.  
  25. void main(int argc, char *argv[])
  26. {int i, k, c;
  27.  int RetCode;
  28.  char Filename[15];
  29.  int Files = 0;
  30.  /* begin */
  31.  if(argc!=2)
  32.    {printf("Usage: UN_ARC <archive_filespec>\n");
  33.     exit(1);
  34.    }
  35.  RetCode = InitLZW(malloc,14);
  36.  if(RetCode<0)
  37.    {SayError(RetCode);
  38.     exit(2);
  39.    }
  40.  puts("\nUN_ARC 1.0: Type any key to abort...");
  41.  /* open input file for expansion */
  42.  if(!ReaderOpen(argv[1])) exit(4);
  43.  for(i=0;;i++)
  44.    {if(kbhit())
  45.       {puts("\n...Aborted by user !");
  46.        break;
  47.       }
  48.     /* get filename */
  49.     for(k=0;k<5;k++)
  50.        {c = Reader();
  51.         if(c==-1)
  52.            {ReaderClose();
  53.             TermLZW(free);
  54.             printf("\n%d files expanded\n",Files);
  55.             exit(0);
  56.            }
  57.         /* skip past any 0's */
  58.         if(c!='\0') break;
  59.        }
  60.     Filename[0] = (char)c;
  61.     for(k=1;k<13;k++)
  62.        {c = Reader();
  63.         Filename[k] = (char)c;
  64.         if(c=='\0') break;
  65.        }
  66.     if(c!='\0')
  67.        {printf("ERROR: Cannot find filename in %s\n",argv[1]);
  68.         TermLZW(free);
  69.         exit(0);
  70.        }
  71.     if(strcmp(Filename,argv[1])==0)
  72.       {printf("ERROR: Archive contains file '%s' named same as archive\n",argv[1]);
  73.        exit(1);
  74.       }
  75.     else
  76.       {/* open output file */
  77.        printf("Expanding %12s ",Filename);
  78.        if(!WriterOpen(Filename)) exit(3);
  79.        /* do the expansion */
  80.        Files++;
  81.        if((RetCode=Expand(Reader,Writer))<0)
  82.          {SayError(RetCode);
  83.           exit(5);
  84.          }
  85.        puts("OK");
  86.        WriterClose();
  87.       }
  88.    }
  89. }