usr.bin/split/split.c
/*
 * split2 --
 *	Split the input by lines.
 */
split2
Split the input by lines.
split2 Split the input by lines .
void
split2()
{
	long lcnt;
	int len, bcnt;
	char *Ce, *Cs;
	for (lcnt = 0;;)
		switch (len = read(ifd, bfr, MAXBSIZE)) {
		case 0:
			exit(0);
		case -1:
			err(1, "read");
		default:
			if (!file_open) {
				newfile();
				file_open = 1;
			}
			for (Cs = Ce = bfr; len--; Ce++)
				if (*Ce == '\n' && ++lcnt == numlines) {
					bcnt = Ce - Cs + 1;
					if (write(ofd, Cs, bcnt) != bcnt)
						err(1, "write");
					lcnt = 0;
					Cs = Ce + 1;
					if (len)
						newfile();
					else
						file_open = 0;
				}
			if (Cs < Ce) {
				bcnt = Ce - Cs;
				if (write(ofd, Cs, bcnt) != bcnt)
					err(1, "write");
			}
		}
}
void split2 ( ) { long lcnt ; int len , bcnt ; char * Ce , * Cs ; for ( lcnt = 0 ; ; ) switch ( len = read ( ifd , bfr , MAXBSIZE ) ) { case 0 : exit ( 0 ) ; case -1 : err ( 1 , " " ) ; default : if ( ! file_open ) { newfile ( ) ; file_open = 1 ; } for ( Cs = Ce = bfr ; len -- ; Ce ++ ) if ( * Ce == ' \n ' && ++ lcnt == numlines ) { bcnt = Ce - Cs + 1 ; if ( write ( ofd , Cs , bcnt ) != bcnt ) err ( 1 , " " ) ; lcnt = 0 ; Cs = Ce + 1 ; if ( len ) newfile ( ) ; else file_open = 0 ; } if ( Cs < Ce ) { bcnt = Ce - Cs ; if ( write ( ofd , Cs , bcnt ) != bcnt ) err ( 1 , " " ) ; } } }
split2
      Split the input by lines.
split2 Split the input by lines .
/* NOTREACHED */