source: trunk/minix/commands/simple/shar.c@ 20

Last change on this file since 20 was 9, checked in by Mattia Monga, 14 years ago

Minix 3.1.2a

File size: 1.5 KB
RevLine 
[9]1/* shar - make a shell archive Author: Michiel Husijes */
2
3#include <stdlib.h> /* for the nonstd :-( _PROTOTYPE */
4#include <stdio.h>
5
6static _PROTOTYPE( void error, (char *progname, char *operation,
7 char *filename) );
8_PROTOTYPE( int main, (int argc, char **argv) );
9
10int main(argc, argv)
11int argc;
12char *argv[];
13{
14 int argn;
15 register int ch;
16 register FILE *fp;
17 int exitstatus;
18 char *filename;
19
20 exitstatus = 0;
21 for (argn = 1; argn < argc; argn++) {
22 filename = argv[argn];
23 if ((fp = fopen(filename, "r")) == NULL) {
24 error(argv[0], "opening ", filename);
25 exitstatus = 1;
26 } else {
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) {
33 putchar('X');
34 putchar(ch);
35 while (ch != '\n') {
36 ch = getc(fp);
37 if (ch == EOF) break;
38 putchar(ch);
39 }
40 if (ch == EOF) break;
41 }
42 fputs("/\n", stdout);
43 if (ferror(fp)) {
44 error(argv[0], "reading ", filename);
45 exitstatus = 1;
46 }
47 if (fclose(fp) != 0) {
48 error(argv[0], "closing ", filename);
49 exitstatus = 1;
50 }
51 if (ferror(stdout)) break; /* lost already */
52 }
53 }
54 fflush(stdout);
55 if (ferror(stdout)) {
56 error(argv[0], "writing ", "stdout");
57 exitstatus = 1;
58 }
59 return(exitstatus);
60}
61
62static void error(progname, operation, filename)
63char *progname;
64char *operation;
65char *filename;
66{
67 fputs(progname, stderr);
68 fputs(": error ", stderr);
69 fputs(operation, stderr);
70 perror(filename);
71}
Note: See TracBrowser for help on using the repository browser.