home *** CD-ROM | disk | FTP | other *** search
/ High Voltage Shareware / high1.zip / high1 / DIR2 / BCUS.ZIP / US.C next >
Text File  |  1993-10-07  |  2KB  |  72 lines

  1. /*******************************
  2. * UnShar for MS-DOS
  3. *
  4. * Originally by Blake Coverett
  5. *
  6. * Released to the public domain.
  7. *
  8. */
  9.  
  10. #include <stdio.h>
  11. #include <string.h>
  12.  
  13. int main(int argc, char *argv[])
  14. {
  15.     FILE *fileIn;
  16.     FILE *fileOut = NULL;
  17.     int nState = 0;
  18.     static char szLine[1024];
  19.     char *pFName;
  20.     char *pTmp;
  21.  
  22.  
  23.     if (argc != 2) {
  24.         puts("Usage: us <shar-file-name>");
  25.         return 1;
  26.     }
  27.  
  28.     fileIn = fopen(argv[1], "r");
  29.     if (fileIn == NULL) {
  30.         printf("Unable to open %s\n", argv[1]);
  31.     }
  32.  
  33.     while (fgets(szLine, sizeof(szLine), fileIn))
  34.         switch (nState) {
  35.         case 0: /* between files */
  36.             if (strncmp(szLine, "sed", 3)) break;
  37.             pFName = strchr(szLine, '\'');
  38.             if (!pFName) break;
  39.             pFName++;
  40.             pTmp = strchr(pFName, '\'');
  41.             if (!pTmp) break;
  42.             *pTmp = '\0';
  43.             fileOut = fopen(pFName, "w");
  44.             printf("Extracting %s\n",pFName);
  45.             nState = 1;
  46.             break;
  47.         case 1: /* copying lines */
  48.             if (!strncmp(szLine, "END_OF_FILE", 11)) {
  49.                 fclose(fileOut);
  50.                 fileOut = NULL;
  51.                 nState = 0;
  52.                 break;
  53.             }
  54.             if (szLine[0] != 'X') {
  55.                 puts("Skipping line without 'X' prefix");
  56.                 break;
  57.             }
  58.             fputs(szLine+1, fileOut);
  59.             break;
  60.         }
  61.  
  62.     if (fileOut) {
  63.         puts("END_OF_FILE not found");
  64.         fclose(fileOut);
  65.     }
  66.  
  67.     fclose(fileIn);
  68.  
  69.     return 0;
  70. }
  71.  
  72.