home *** CD-ROM | disk | FTP | other *** search
/ Power Programmierung 2 / Power-Programmierung CD 2 (Tewi)(1994).iso / c / library / dos / packer / lzw14 / ex_arc.c < prev    next >
Encoding:
C/C++ Source or Header  |  1994-05-29  |  2.9 KB  |  121 lines

  1. /*
  2. **   EX_ARC.C       Copyright (C) 1994 by MarshallSoft Computing, Inc.
  3. **
  4. **   This program is used to extract a file from archive created with
  5. **   MK_ARC. For example, to extract the file TEST.C from the archive
  6. **   MY_PGMS.ARC, type:
  7. **
  8. **      EX_ARC TEST.C MY_PGMS.ARC
  9. */
  10.  
  11. #include <stdio.h>
  12. #include <stdlib.h>
  13. #include <dos.h>
  14. #include <fcntl.h>
  15. #include <sys\types.h>
  16. #include <sys\stat.h>
  17. #include <io.h>
  18. #include <string.h>
  19. #include <conio.h>
  20. #include <ctype.h>
  21.  
  22. #include "LZW4C.H"
  23. #include "RW_IO.H"
  24. #include "DIR_IO.H"
  25. #include "SAYERROR.H"
  26.  
  27. int DummyWrite(char);
  28.  
  29. void main(int argc, char *argv[])
  30. {int i, k, c;
  31.  int RetCode;
  32.  int Len;
  33.  char *Ptr;
  34.  char Filename[15];
  35.  char Requested[15];
  36.  /* begin */
  37.  if(argc!=3)
  38.    {printf("Usage: EX_ARC <filename> <archive>\n");
  39.     exit(1);
  40.    }
  41.  RetCode = InitLZW(malloc,14);
  42.  if(RetCode<0)
  43.    {SayError(RetCode);
  44.     exit(2);
  45.    }
  46.  puts("\nEX_ARC 1.0: Type any key to abort...");
  47.  /* make requested file all upper case */
  48.  Ptr = argv[1];
  49.  Len = strlen(Ptr);
  50.  for(i=0;i<Len;i++) Requested[i] = toupper(*Ptr++);
  51.  Requested[Len] = '\0';
  52.  printf("Searching for '%s' in archive '%s'\n",Requested,argv[2]);
  53.  /* open input file for expansion */
  54.  if(!ReaderOpen(argv[2])) exit(4);
  55.  for(i=0;;i++)
  56.    {if(kbhit())
  57.       {puts("\n...Aborted by user !");
  58.        break;
  59.       }
  60.     /* find start of next filename */
  61.     for(k=0;k<5;k++)
  62.        {c = Reader();
  63.         if(c==-1)
  64.            {ReaderClose();
  65.             TermLZW(free);
  66.             exit(0);
  67.            }
  68.         /* skip past any 0's */
  69.         if(c!='\0') break;
  70.        }
  71.     Filename[0] = (char)c;
  72.     /* get complete filename */
  73.     for(k=1;k<13;k++)
  74.        {c = Reader();
  75.         Filename[k] = (char)c;
  76.         if(c=='\0') break;
  77.        }
  78.     if(c!='\0')
  79.        {printf("ERROR: Cannot find filename in %s\n",argv[1]);
  80.         TermLZW(free);
  81.         exit(0);
  82.        }
  83.     if(strcmp(Filename,argv[2])==0)
  84.       {printf("ERROR: Archive contains file '%s' named same as archive\n",argv[2]);
  85.        exit(1);
  86.       }
  87.     else
  88.       {/* right file to extract ? */
  89.        if(strcmp(Filename,Requested)==0)
  90.          {/* open output file */
  91.           printf("Expanding %12s ",Filename);
  92.           if(!WriterOpen(Filename)) exit(3);
  93.           /* do the expansion */
  94.           if((RetCode=Expand(Reader,Writer))<0)
  95.             {SayError(RetCode);
  96.              exit(5);
  97.             }
  98.           puts("OK");
  99.           WriterClose();
  100.           ReaderClose();
  101.           exit(0);
  102.          }
  103.        else
  104.          {/* skip file */
  105.           printf("Skipping %12s \n",Filename);
  106.           if((RetCode=Expand(Reader,DummyWrite))<0)
  107.             {SayError(RetCode);
  108.              exit(5);
  109.             }
  110.          }
  111.       }
  112.    }
  113. }
  114.  
  115. int DummyWrite(char Byte)
  116. {int Code = 0;
  117.  /* Byte dumped ! */
  118.  Byte = Byte + 0;
  119.  return(Code);
  120. }
  121.