1 /* shar - make a shell archive Author: Michiel Husijes */
3 #include <stdlib.h> /* for the nonstd :-( _PROTOTYPE */
6 static _PROTOTYPE( void error
, (char *progname
, char *operation
,
8 _PROTOTYPE( int main
, (int argc
, char **argv
) );
21 for (argn
= 1; argn
< argc
; argn
++) {
22 filename
= argv
[argn
];
23 if ((fp
= fopen(filename
, "r")) == NULL
) {
24 error(argv
[0], "opening ", filename
);
27 fputs("echo x - ", stdout
);
28 fputs(filename
, stdout
);
29 fputs("\nsed '/^X/s///' > ", stdout
);
30 fputs(filename
, stdout
);
31 fputs(" << '/'\n", stdout
);
32 while ((ch
= getc(fp
)) != EOF
) {
44 error(argv
[0], "reading ", filename
);
47 if (fclose(fp
) != 0) {
48 error(argv
[0], "closing ", filename
);
51 if (ferror(stdout
)) break; /* lost already */
56 error(argv
[0], "writing ", "stdout");
62 static void error(progname
, operation
, filename
)
67 fputs(progname
, stderr
);
68 fputs(": error ", stderr
);
69 fputs(operation
, stderr
);