Deleted Added
full compact
cat.c (83962) cat.c (90106)
1/*
2 * Copyright (c) 1989, 1993
3 * The Regents of the University of California. All rights reserved.
4 *
5 * This code is derived from software contributed to Berkeley by
6 * Kevin Fall.
7 *
8 * Redistribution and use in source and binary forms, with or without

--- 31 unchanged lines hidden (view full) ---

40 The Regents of the University of California. All rights reserved.\n";
41#endif /* not lint */
42
43#ifndef lint
44#if 0
45static char sccsid[] = "@(#)cat.c 8.2 (Berkeley) 4/27/95";
46#endif
47static const char rcsid[] =
1/*
2 * Copyright (c) 1989, 1993
3 * The Regents of the University of California. All rights reserved.
4 *
5 * This code is derived from software contributed to Berkeley by
6 * Kevin Fall.
7 *
8 * Redistribution and use in source and binary forms, with or without

--- 31 unchanged lines hidden (view full) ---

40 The Regents of the University of California. All rights reserved.\n";
41#endif /* not lint */
42
43#ifndef lint
44#if 0
45static char sccsid[] = "@(#)cat.c 8.2 (Berkeley) 4/27/95";
46#endif
47static const char rcsid[] =
48 "$FreeBSD: head/bin/cat/cat.c 83962 2001-09-26 11:34:14Z ru $";
48 "$FreeBSD: head/bin/cat/cat.c 90106 2002-02-02 06:10:01Z imp $";
49#endif /* not lint */
50
51#include <sys/param.h>
52#include <sys/stat.h>
53#ifndef NO_UDOM_SUPPORT
54#include <sys/socket.h>
55#include <sys/un.h>
56#include <errno.h>

--- 8 unchanged lines hidden (view full) ---

65#include <string.h>
66#include <unistd.h>
67#include <stddef.h>
68
69int bflag, eflag, nflag, sflag, tflag, vflag;
70int rval;
71const char *filename;
72
49#endif /* not lint */
50
51#include <sys/param.h>
52#include <sys/stat.h>
53#ifndef NO_UDOM_SUPPORT
54#include <sys/socket.h>
55#include <sys/un.h>
56#include <errno.h>

--- 8 unchanged lines hidden (view full) ---

65#include <string.h>
66#include <unistd.h>
67#include <stddef.h>
68
69int bflag, eflag, nflag, sflag, tflag, vflag;
70int rval;
71const char *filename;
72
73int main __P((int argc, char *argv[]));
73static void scanfiles(char **argv, int cooked);
74static void cook_cat(FILE *);
75static void raw_cat(int);
74
76
75static void scanfiles __P((char **argv, int cooked));
76static void cook_cat __P((FILE *));
77static void raw_cat __P((int));
78
79#ifndef NO_UDOM_SUPPORT
77#ifndef NO_UDOM_SUPPORT
80static int udom_open __P((const char *path, int flags));
78static int udom_open(const char *path, int flags);
81#endif
82
83int
79#endif
80
81int
84main(argc, argv)
85 int argc;
86 char *argv[];
82main(int argc, char *argv[])
87{
88 int ch;
89
90 setlocale(LC_CTYPE, "");
91
92 while ((ch = getopt(argc, argv, "benstuv")) != -1)
93 switch (ch) {
94 case 'b':

--- 29 unchanged lines hidden (view full) ---

124 else
125 scanfiles(argv, 0);
126 if (fclose(stdout))
127 err(1, "stdout");
128 exit(rval);
129}
130
131void
83{
84 int ch;
85
86 setlocale(LC_CTYPE, "");
87
88 while ((ch = getopt(argc, argv, "benstuv")) != -1)
89 switch (ch) {
90 case 'b':

--- 29 unchanged lines hidden (view full) ---

120 else
121 scanfiles(argv, 0);
122 if (fclose(stdout))
123 err(1, "stdout");
124 exit(rval);
125}
126
127void
132scanfiles(argv, cooked)
133 char **argv;
134 int cooked;
128scanfiles(char **argv, int cooked)
135{
136 int i = 0;
137 char *path;
138 FILE *fp;
139
140 while ((path = argv[i]) != NULL || i == 0) {
141 int fd;
142

--- 26 unchanged lines hidden (view full) ---

169 }
170 if (path == NULL)
171 break;
172 ++i;
173 }
174}
175
176static void
129{
130 int i = 0;
131 char *path;
132 FILE *fp;
133
134 while ((path = argv[i]) != NULL || i == 0) {
135 int fd;
136

--- 26 unchanged lines hidden (view full) ---

163 }
164 if (path == NULL)
165 break;
166 ++i;
167 }
168}
169
170static void
177cook_cat(fp)
178 register FILE *fp;
171cook_cat(FILE *fp)
179{
172{
180 register int ch, gobble, line, prev;
173 int ch, gobble, line, prev;
181
182 /* Reset EOF condition on stdin. */
183 if (fp == stdin && feof(stdin))
184 clearerr(stdin);
185
186 line = gobble = 0;
187 for (prev = '\n'; (ch = getc(fp)) != EOF; prev = ch) {
188 if (prev == '\n') {

--- 48 unchanged lines hidden (view full) ---

237 rval = 1;
238 clearerr(fp);
239 }
240 if (ferror(stdout))
241 err(1, "stdout");
242}
243
244static void
174
175 /* Reset EOF condition on stdin. */
176 if (fp == stdin && feof(stdin))
177 clearerr(stdin);
178
179 line = gobble = 0;
180 for (prev = '\n'; (ch = getc(fp)) != EOF; prev = ch) {
181 if (prev == '\n') {

--- 48 unchanged lines hidden (view full) ---

230 rval = 1;
231 clearerr(fp);
232 }
233 if (ferror(stdout))
234 err(1, "stdout");
235}
236
237static void
245raw_cat(rfd)
246 register int rfd;
238raw_cat(int rfd)
247{
239{
248 register int off, wfd;
240 int off, wfd;
249 ssize_t nr, nw;
250 static size_t bsize;
251 static char *buf;
252 struct stat sbuf;
253
254 wfd = fileno(stdout);
255 if (buf == NULL) {
256 if (fstat(wfd, &sbuf))

--- 10 unchanged lines hidden (view full) ---

267 warn("%s", filename);
268 rval = 1;
269 }
270}
271
272#ifndef NO_UDOM_SUPPORT
273
274static int
241 ssize_t nr, nw;
242 static size_t bsize;
243 static char *buf;
244 struct stat sbuf;
245
246 wfd = fileno(stdout);
247 if (buf == NULL) {
248 if (fstat(wfd, &sbuf))

--- 10 unchanged lines hidden (view full) ---

259 warn("%s", filename);
260 rval = 1;
261 }
262}
263
264#ifndef NO_UDOM_SUPPORT
265
266static int
275udom_open(path, flags)
276 const char *path;
277 int flags;
267udom_open(const char *path, int flags)
278{
279 struct sockaddr_un sou;
280 int fd;
281 int len;
282
283 bzero(&sou, sizeof(sou));
284
285 /*

--- 34 unchanged lines hidden ---
268{
269 struct sockaddr_un sou;
270 int fd;
271 int len;
272
273 bzero(&sou, sizeof(sou));
274
275 /*

--- 34 unchanged lines hidden ---