Deleted Added
full compact
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
41#if 0
42static char sccsid[] = "@(#)split.c 8.2 (Berkeley) 4/16/94";
43#endif
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));
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);
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);
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);
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");
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
284usage()
285{
286 (void)fprintf(stderr,
287"usage: split [-b byte_count] [-l line_count] [file [prefix]]\n");
288 exit(1);
289}