10 * See the License for the specific language governing permissions
11 * and limitations under the License.
12 *
13 * When distributing Covered Code, include this CDDL HEADER in each
14 * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
15 * If applicable, add the following below this CDDL HEADER, with the
16 * fields enclosed by brackets "[]" replaced with your own identifying
17 * information: Portions Copyright [yyyy] [name of copyright owner]
18 *
19 * CDDL HEADER END
20 */
21
22 /*
23 * Copyright (c) 1989, 2010, Oracle and/or its affiliates. All rights reserved.
24 */
25
26 /* Copyright (c) 1984, 1986, 1987, 1988, 1989 AT&T */
27 /* All Rights Reserved */
28
29 /*
30 * csplit - Context or line file splitter
31 * Compile: cc -O -s -o csplit csplit.c
32 */
33
34 #include <stdio.h>
35 #include <stdlib.h>
36 #include <unistd.h>
37 #include <string.h>
38 #include <ctype.h>
39 #include <errno.h>
40 #include <limits.h>
41 #include <regexpr.h>
42 #include <signal.h>
43 #include <locale.h>
44 #include <libintl.h>
45
46 #define LAST 0LL
47 #define ERR -1
48 #define FALSE 0
49 #define TRUE 1
374 if (delim == (char *)NULL) {
375 if (strlen(file) > pathconf(".", _PC_NAME_MAX)) {
376 fatal("Name too long: %s\n", file);
377 }
378 } else {
379 /* truncate file at pathname delim to do pathconf */
380 savedelim = *delim;
381 *delim = '\0';
382 /*
383 * file: pppppppp\0fffff\0
384 * ..... ^ file
385 * ............. ^ delim
386 */
387 if (strlen(delim + 1) > pathconf(file, _PC_NAME_MAX)) {
388 fatal("Name too long: %s\n", delim + 1);
389 }
390 *delim = savedelim;
391 }
392
393 if ((opfil = fopen(file, "w")) == NULL) {
394 (void) strcpy(tfile, file);
395 (void) sprintf(fptr, "%.*d", fiwidth, (ctr-2));
396 fatal("Cannot create %s\n", tfile);
397 }
398 return (opfil);
399 }
400 return (NULL);
401 }
402
403 /*
404 * Getline gets a line via fgets from the input stream "infile".
405 * The line is put into linbuf and may not be larger than LINSIZ.
406 * If getaline is called with a non-zero value, the current line
407 * is bumped, otherwise it is not(for R.E. searching).
408 */
409
410 static char *
411 getaline(int bumpcur)
412 {
413 char *ret;
414 if (bumpcur)
|
10 * See the License for the specific language governing permissions
11 * and limitations under the License.
12 *
13 * When distributing Covered Code, include this CDDL HEADER in each
14 * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
15 * If applicable, add the following below this CDDL HEADER, with the
16 * fields enclosed by brackets "[]" replaced with your own identifying
17 * information: Portions Copyright [yyyy] [name of copyright owner]
18 *
19 * CDDL HEADER END
20 */
21
22 /*
23 * Copyright (c) 1989, 2010, Oracle and/or its affiliates. All rights reserved.
24 */
25
26 /* Copyright (c) 1984, 1986, 1987, 1988, 1989 AT&T */
27 /* All Rights Reserved */
28
29 /*
30 * Copyright (c) 2018, Joyent, Inc.
31 */
32
33 /*
34 * csplit - Context or line file splitter
35 * Compile: cc -O -s -o csplit csplit.c
36 */
37
38 #include <stdio.h>
39 #include <stdlib.h>
40 #include <unistd.h>
41 #include <string.h>
42 #include <ctype.h>
43 #include <errno.h>
44 #include <limits.h>
45 #include <regexpr.h>
46 #include <signal.h>
47 #include <locale.h>
48 #include <libintl.h>
49
50 #define LAST 0LL
51 #define ERR -1
52 #define FALSE 0
53 #define TRUE 1
378 if (delim == (char *)NULL) {
379 if (strlen(file) > pathconf(".", _PC_NAME_MAX)) {
380 fatal("Name too long: %s\n", file);
381 }
382 } else {
383 /* truncate file at pathname delim to do pathconf */
384 savedelim = *delim;
385 *delim = '\0';
386 /*
387 * file: pppppppp\0fffff\0
388 * ..... ^ file
389 * ............. ^ delim
390 */
391 if (strlen(delim + 1) > pathconf(file, _PC_NAME_MAX)) {
392 fatal("Name too long: %s\n", delim + 1);
393 }
394 *delim = savedelim;
395 }
396
397 if ((opfil = fopen(file, "w")) == NULL) {
398 (void) strlcpy(tfile, file, sizeof (tfile));
399 (void) sprintf(fptr, "%.*d", fiwidth, (ctr-2));
400 fatal("Cannot create %s\n", tfile);
401 }
402 return (opfil);
403 }
404 return (NULL);
405 }
406
407 /*
408 * Getline gets a line via fgets from the input stream "infile".
409 * The line is put into linbuf and may not be larger than LINSIZ.
410 * If getaline is called with a non-zero value, the current line
411 * is bumped, otherwise it is not(for R.E. searching).
412 */
413
414 static char *
415 getaline(int bumpcur)
416 {
417 char *ret;
418 if (bumpcur)
|