Line | |
---|
1 | /*
|
---|
2 | * Copy the files given as arguments to the standard output. The file
|
---|
3 | * name "-" refers to the standard input.
|
---|
4 | *
|
---|
5 | * Copyright (C) 1989 by Kenneth Almquist. All rights reserved.
|
---|
6 | * This file is part of ash, which is distributed under the terms specified
|
---|
7 | * by the Ash General Public License. See the file named LICENSE.
|
---|
8 | */
|
---|
9 |
|
---|
10 | #define main catfcmd
|
---|
11 |
|
---|
12 | #include "bltin.h"
|
---|
13 | #include "../error.h"
|
---|
14 | #include <sys/param.h>
|
---|
15 | #include <fcntl.h>
|
---|
16 |
|
---|
17 |
|
---|
18 | #ifdef SBUFSIZE
|
---|
19 | #define BUFSIZE() SBUFSIZE
|
---|
20 | #else
|
---|
21 | #ifdef MAXBSIZE
|
---|
22 | #define BUFSIZE() MAXBSIZE
|
---|
23 | #else
|
---|
24 | #define BUFSIZE() BSIZE
|
---|
25 | #endif
|
---|
26 | #endif
|
---|
27 |
|
---|
28 |
|
---|
29 | main(argc, argv) char **argv; {
|
---|
30 | char *filename;
|
---|
31 | char *buf = stalloc(BUFSIZE());
|
---|
32 | int fd;
|
---|
33 | int i;
|
---|
34 | #ifdef SHELL
|
---|
35 | volatile int input;
|
---|
36 | struct jmploc jmploc;
|
---|
37 | struct jmploc *volatile savehandler;
|
---|
38 | #endif
|
---|
39 |
|
---|
40 | INITARGS(argv);
|
---|
41 | #ifdef SHELL
|
---|
42 | input = -1;
|
---|
43 | if (setjmp(jmploc.loc)) {
|
---|
44 | close(input);
|
---|
45 | handler = savehandler;
|
---|
46 | longjmp(handler, 1);
|
---|
47 | }
|
---|
48 | savehandler = handler;
|
---|
49 | handler = &jmploc;
|
---|
50 | #endif
|
---|
51 | while ((filename = *++argv) != NULL) {
|
---|
52 | if (filename[0] == '-' && filename[1] == '\0') {
|
---|
53 | fd = 0;
|
---|
54 | } else {
|
---|
55 | #ifdef SHELL
|
---|
56 | INTOFF;
|
---|
57 | if ((fd = open(filename, O_RDONLY)) < 0)
|
---|
58 | error("Can't open %s", filename);
|
---|
59 | input = fd;
|
---|
60 | INTON;
|
---|
61 | #else
|
---|
62 | if ((fd = open(filename, O_RDONLY)) < 0) {
|
---|
63 | fprintf(stderr, "catf: Can't open %s\n", filename);
|
---|
64 | exit(2);
|
---|
65 | }
|
---|
66 | #endif
|
---|
67 | }
|
---|
68 | while ((i = read(fd, buf, BUFSIZE())) > 0) {
|
---|
69 | #ifdef SHELL
|
---|
70 | if (out1 == &memout) {
|
---|
71 | register char *p;
|
---|
72 | for (p = buf ; --i >= 0 ; p++) {
|
---|
73 | outc(*p, &memout);
|
---|
74 | }
|
---|
75 | } else {
|
---|
76 | write(1, buf, i);
|
---|
77 | }
|
---|
78 | #else
|
---|
79 | write(1, buf, i);
|
---|
80 | #endif
|
---|
81 | }
|
---|
82 | if (fd != 0)
|
---|
83 | close(fd);
|
---|
84 | }
|
---|
85 | #ifdef SHELL
|
---|
86 | handler = savehandler;
|
---|
87 | #endif
|
---|
88 | }
|
---|
Note:
See
TracBrowser
for help on using the repository browser.