=================================================================== RCS file: /cvsrepo/anoncvs/cvs/src/usr.bin/split/split.c,v retrieving revision 1.13 retrieving revision 1.14 diff -c -r1.13 -r1.14 *** src/usr.bin/split/split.c 2006/08/10 22:44:17 1.13 --- src/usr.bin/split/split.c 2007/09/05 21:07:53 1.14 *************** *** 1,4 **** ! /* $OpenBSD: split.c,v 1.13 2006/08/10 22:44:17 millert Exp $ */ /* $NetBSD: split.c,v 1.5 1995/08/31 22:22:05 jtc Exp $ */ /* --- 1,4 ---- ! /* $OpenBSD: split.c,v 1.14 2007/09/05 21:07:53 millert Exp $ */ /* $NetBSD: split.c,v 1.5 1995/08/31 22:22:05 jtc Exp $ */ /* *************** *** 40,46 **** #if 0 static char sccsid[] = "@(#)split.c 8.3 (Berkeley) 4/25/94"; #else ! static char rcsid[] = "$OpenBSD: split.c,v 1.13 2006/08/10 22:44:17 millert Exp $"; #endif #endif /* not lint */ --- 40,46 ---- #if 0 static char sccsid[] = "@(#)split.c 8.3 (Berkeley) 4/25/94"; #else ! static char rcsid[] = "$OpenBSD: split.c,v 1.14 2007/09/05 21:07:53 millert Exp $"; #endif #endif /* not lint */ *************** *** 286,329 **** newfile(void) { static char *suffix, *sufftail; ! static int defname; if (ofd == -1) { ! if (fname[0] == '\0') { ! fname[0] = 'x'; ! suffix = fname + 1; ! defname = 1; } else { suffix = fname + strlen(fname); ! defname = 0; } - memset(suffix, 'a', sufflen); suffix[sufflen] = '\0'; sufftail = suffix + sufflen - 1; ! --sufftail[0]; /* incremented later */ ! ofd = fileno(stdout); ! } ! ! if (sufftail[0] == 'z') { ! int i; ! ! /* Increment the non-tail portion of the suffix. */ ! for (i = sufflen - 2; i >= 0; i--) { ! if (suffix[i] != 'z') { ! suffix[i]++; break; ! } } ! if (i < 0) { ! /* Hack to support y and z prefix if no name spec'd. */ ! if (!defname || fname[0] == 'z') ! errx(EX_DATAERR, "too many files"); ! ++fname[0]; ! memset(suffix, 'a', sufflen); ! } else ! sufftail[0] = 'a'; /* reset tail */ ! } else ! ++sufftail[0]; if (!freopen(fname, "w", stdout)) err(EX_IOERR, "%s", fname); --- 286,317 ---- newfile(void) { static char *suffix, *sufftail; ! char *sptr; if (ofd == -1) { ! ofd = fileno(stdout); ! if (*fname == '\0') { ! *fname = 'x'; /* no name specified, use 'x' */ ! memset(fname + 1, 'a', sufflen); ! suffix = fname; ! sufflen++; /* treat 'x' as part of suffix */ } else { suffix = fname + strlen(fname); ! memset(suffix, 'a', sufflen); } suffix[sufflen] = '\0'; sufftail = suffix + sufflen - 1; ! } else { ! for (sptr = sufftail; sptr >= suffix; sptr--) { ! if (*sptr != 'z') { ! (*sptr)++; break; ! } else ! *sptr = 'a'; } ! if (sptr < suffix) ! errx(EX_DATAERR, "too many files"); ! } if (!freopen(fname, "w", stdout)) err(EX_IOERR, "%s", fname);