pci: don't do sanity check for missing pci bus, the check can misfire.
[minix.git] / commands / simple / shar.c
blobc5096bc3d9405c905d7545573ae8d35b0cdc05ad
1 /* shar - make a shell archive Author: Michiel Husijes */
3 #include <stdlib.h> /* for the nonstd :-( _PROTOTYPE */
4 #include <stdio.h>
6 static _PROTOTYPE( void error, (char *progname, char *operation,
7 char *filename) );
8 _PROTOTYPE( int main, (int argc, char **argv) );
10 int main(argc, argv)
11 int argc;
12 char *argv[];
14 int argn;
15 register int ch;
16 register FILE *fp;
17 int exitstatus;
18 char *filename;
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);
40 if (ch == EOF) break;
42 fputs("/\n", stdout);
43 if (ferror(fp)) {
44 error(argv[0], "reading ", filename);
45 exitstatus = 1;
47 if (fclose(fp) != 0) {
48 error(argv[0], "closing ", filename);
49 exitstatus = 1;
51 if (ferror(stdout)) break; /* lost already */
54 fflush(stdout);
55 if (ferror(stdout)) {
56 error(argv[0], "writing ", "stdout");
57 exitstatus = 1;
59 return(exitstatus);
62 static void error(progname, operation, filename)
63 char *progname;
64 char *operation;
65 char *filename;
67 fputs(progname, stderr);
68 fputs(": error ", stderr);
69 fputs(operation, stderr);
70 perror(filename);