Deleted Added
full compact
split.c (24360) split.c (28071)
1/*
2 * Copyright (c) 1987, 1993, 1994
3 * The Regents of the University of California. All rights reserved.
4 *
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
7 * are met:
8 * 1. Redistributions of source code must retain the above copyright

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

27 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
28 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
29 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
30 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
31 * SUCH DAMAGE.
32 */
33
34#ifndef lint
1/*
2 * Copyright (c) 1987, 1993, 1994
3 * The Regents of the University of California. All rights reserved.
4 *
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
7 * are met:
8 * 1. Redistributions of source code must retain the above copyright

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

27 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
28 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
29 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
30 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
31 * SUCH DAMAGE.
32 */
33
34#ifndef lint
35static char copyright[] =
35static const char copyright[] =
36"@(#) Copyright (c) 1987, 1993, 1994\n\
37 The Regents of the University of California. All rights reserved.\n";
38#endif /* not lint */
39
40#ifndef lint
36"@(#) Copyright (c) 1987, 1993, 1994\n\
37 The Regents of the University of California. All rights reserved.\n";
38#endif /* not lint */
39
40#ifndef lint
41#if 0
41static char sccsid[] = "@(#)split.c 8.2 (Berkeley) 4/16/94";
42static char sccsid[] = "@(#)split.c 8.2 (Berkeley) 4/16/94";
43#endif
42#endif /* not lint */
43
44#include <sys/param.h>
45
46#include <ctype.h>
47#include <err.h>
48#include <fcntl.h>
49#include <stdio.h>

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

58int file_open; /* If a file open. */
59int ifd = -1, ofd = -1; /* Input/output file descriptors. */
60char bfr[MAXBSIZE]; /* I/O buffer. */
61char fname[MAXPATHLEN]; /* File name prefix. */
62
63void newfile __P((void));
64void split1 __P((void));
65void split2 __P((void));
44#endif /* not lint */
45
46#include <sys/param.h>
47
48#include <ctype.h>
49#include <err.h>
50#include <fcntl.h>
51#include <stdio.h>

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

60int file_open; /* If a file open. */
61int ifd = -1, ofd = -1; /* Input/output file descriptors. */
62char bfr[MAXBSIZE]; /* I/O buffer. */
63char fname[MAXPATHLEN]; /* File name prefix. */
64
65void newfile __P((void));
66void split1 __P((void));
67void split2 __P((void));
66void usage __P((void));
68static void usage __P((void));
67
68int
69main(argc, argv)
70 int argc;
71 char *argv[];
72{
73 int ch;
74 char *ep, *p;

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

84 if (numlines == 0) {
85 p = argv[optind - 1];
86 if (p[0] == '-' && p[1] == ch && !p[2])
87 numlines = strtol(++p, &ep, 10);
88 else
89 numlines =
90 strtol(argv[optind] + 1, &ep, 10);
91 if (numlines <= 0 || *ep)
69
70int
71main(argc, argv)
72 int argc;
73 char *argv[];
74{
75 int ch;
76 char *ep, *p;

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

86 if (numlines == 0) {
87 p = argv[optind - 1];
88 if (p[0] == '-' && p[1] == ch && !p[2])
89 numlines = strtol(++p, &ep, 10);
90 else
91 numlines =
92 strtol(argv[optind] + 1, &ep, 10);
93 if (numlines <= 0 || *ep)
92 errx(1,
93 "%s: illegal line count.", optarg);
94 errx(1, "%s: illegal line count", optarg);
94 }
95 break;
96 case '-': /* Undocumented: historic stdin flag. */
97 if (ifd != -1)
98 usage();
99 ifd = 0;
100 break;
101 case 'b': /* Byte count. */
102 if ((bytecnt = strtol(optarg, &ep, 10)) <= 0 ||
95 }
96 break;
97 case '-': /* Undocumented: historic stdin flag. */
98 if (ifd != -1)
99 usage();
100 ifd = 0;
101 break;
102 case 'b': /* Byte count. */
103 if ((bytecnt = strtol(optarg, &ep, 10)) <= 0 ||
103 *ep != '\0' && *ep != 'k' && *ep != 'm')
104 errx(1, "%s: illegal byte count.", optarg);
104 (*ep != '\0' && *ep != 'k' && *ep != 'm'))
105 errx(1, "%s: illegal byte count", optarg);
105 if (*ep == 'k')
106 bytecnt *= 1024;
107 else if (*ep == 'm')
108 bytecnt *= 1048576;
109 break;
110 case 'l': /* Line count. */
111 if (numlines != 0)
112 usage();
113 if ((numlines = strtol(optarg, &ep, 10)) <= 0 || *ep)
106 if (*ep == 'k')
107 bytecnt *= 1024;
108 else if (*ep == 'm')
109 bytecnt *= 1048576;
110 break;
111 case 'l': /* Line count. */
112 if (numlines != 0)
113 usage();
114 if ((numlines = strtol(optarg, &ep, 10)) <= 0 || *ep)
114 errx(1, "%s: illegal line count.", optarg);
115 errx(1, "%s: illegal line count", optarg);
115 break;
116 default:
117 usage();
118 }
119 argv += optind;
120 argc -= optind;
121
122 if (*argv != NULL)

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

263 }
264 /*
265 * Hack to increase max files; original code wandered through
266 * magic characters. Maximum files is 3 * 26 * 26 == 2028
267 */
268#define MAXFILES 676
269 if (fnum == MAXFILES) {
270 if (!defname || fname[0] == 'z')
116 break;
117 default:
118 usage();
119 }
120 argv += optind;
121 argc -= optind;
122
123 if (*argv != NULL)

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

264 }
265 /*
266 * Hack to increase max files; original code wandered through
267 * magic characters. Maximum files is 3 * 26 * 26 == 2028
268 */
269#define MAXFILES 676
270 if (fnum == MAXFILES) {
271 if (!defname || fname[0] == 'z')
271 errx(1, "too many files.");
272 errx(1, "too many files");
272 ++fname[0];
273 fnum = 0;
274 }
275 fpnt[0] = fnum / 26 + 'a';
276 fpnt[1] = fnum % 26 + 'a';
277 ++fnum;
278 if (!freopen(fname, "w", stdout))
279 err(1, "%s", fname);
280}
281
273 ++fname[0];
274 fnum = 0;
275 }
276 fpnt[0] = fnum / 26 + 'a';
277 fpnt[1] = fnum % 26 + 'a';
278 ++fnum;
279 if (!freopen(fname, "w", stdout))
280 err(1, "%s", fname);
281}
282
282void
283static void
283usage()
284{
285 (void)fprintf(stderr,
286"usage: split [-b byte_count] [-l line_count] [file [prefix]]\n");
287 exit(1);
288}
284usage()
285{
286 (void)fprintf(stderr,
287"usage: split [-b byte_count] [-l line_count] [file [prefix]]\n");
288 exit(1);
289}