4 * This program "unbags" files "bagged" by bag. Can be used for non-UNIX
5 * folks that need to unbag stuff.
19 fprintf(stderr, "unbag: missing bagfile name\n");
22 f = fopen(argv[1], "r");
25 fprintf(stderr, "unbag: cannot open %s\n", argv[1]);
38 static char text[2048];
41 while ( fgets(text, 2048, f) != NULL )
44 if ( strncmp(text, "cat << \\EOF_", strlen("cat << \\EOF_"))!= 0 )
46 fprintf(stderr, "unbag: line %d: bad file format (missing BEGIN)\n", line);
47 fprintf(stderr, "unbag: text was '%s'\n", text);
50 nm = &text[strlen("cat << \\EOF_")];
51 for (p=nm; *p!=' '; p++) {;} /* find end of filename */
53 output = fopen(nm, "w");
56 fprintf(stderr, "unbag: cannot open ouput file %s\n", nm);
59 extract(f, output, nm);
64 /* Cat a f to f2 (lines <= 2047 characters) stopping after reading 'stop' */
69 static char text[2048];
72 while ( fgets(text, 2048, f)!=NULL )
75 text[strlen(text)-1] = '\0'; /* rm \n */
76 if ( strncmp(text, "EOF_", strlen("EOF_")) == 0 )
77 if ( strcmp(&text[strlen("EOF_")], stop) == 0 ) return;
80 fprintf(stderr,"unbag: line %d: bad file format: %s\n", line, stop);
83 fprintf(f2, "%s\n", &text[1]);
85 for (p=&text[1]; *p!='\0'; p++)