home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Current Shareware 1994 January
/
SHAR194.ISO
/
compress
/
bcus.zip
/
US.C
next >
Wrap
Text File
|
1993-10-07
|
2KB
|
72 lines
/*******************************
* UnShar for MS-DOS
*
* Originally by Blake Coverett
*
* Released to the public domain.
*
*/
#include <stdio.h>
#include <string.h>
int main(int argc, char *argv[])
{
FILE *fileIn;
FILE *fileOut = NULL;
int nState = 0;
static char szLine[1024];
char *pFName;
char *pTmp;
if (argc != 2) {
puts("Usage: us <shar-file-name>");
return 1;
}
fileIn = fopen(argv[1], "r");
if (fileIn == NULL) {
printf("Unable to open %s\n", argv[1]);
}
while (fgets(szLine, sizeof(szLine), fileIn))
switch (nState) {
case 0: /* between files */
if (strncmp(szLine, "sed", 3)) break;
pFName = strchr(szLine, '\'');
if (!pFName) break;
pFName++;
pTmp = strchr(pFName, '\'');
if (!pTmp) break;
*pTmp = '\0';
fileOut = fopen(pFName, "w");
printf("Extracting %s\n",pFName);
nState = 1;
break;
case 1: /* copying lines */
if (!strncmp(szLine, "END_OF_FILE", 11)) {
fclose(fileOut);
fileOut = NULL;
nState = 0;
break;
}
if (szLine[0] != 'X') {
puts("Skipping line without 'X' prefix");
break;
}
fputs(szLine+1, fileOut);
break;
}
if (fileOut) {
puts("END_OF_FILE not found");
fclose(fileOut);
}
fclose(fileIn);
return 0;
}