usr.bin/patch/inp.c
char *
ifetch(LINENUM line, int whichbuf)
{
	if (line < 1 || line > input_lines) {
		if (warn_on_invalid_line) {
			say("No such line %ld in input file, ignoring\n", line);
			warn_on_invalid_line = false;
		}
		return NULL;
	}
	if (using_plan_a)
		return i_ptr[line];
	else {
		LINENUM	offline = line % lines_per_buf;
		LINENUM	baseline = line - offline;

		if (tiline[0] == baseline)
			whichbuf = 0;
		else if (tiline[1] == baseline)
			whichbuf = 1;
		else {
			tiline[whichbuf] = baseline;

			if (lseek(tifd, (off_t) (baseline / lines_per_buf *
			    BUFFERSIZE), SEEK_SET) < 0)
				pfatal("cannot seek in the temporary input file");

			if (read(tifd, tibuf[whichbuf], BUFFERSIZE) < 0)
				pfatal("error reading tmp file %s", TMPINNAME);
		}
		return tibuf[whichbuf] + (tireclen * offline);
	}
}
/*
 * Fetch a line from the input file, \n terminated, not necessarily \0.
 */
Fetch a line from the input file, \n terminated, not necessarily \0.
Fetch a line from the input file \ n terminated not necessarily \ 0 .
char *
ifetch(LINENUM line, int whichbuf)
{
	if (line < 1 || line > input_lines) {
		if (warn_on_invalid_line) {
			say("No such line %ld in input file, ignoring\n", line);
			warn_on_invalid_line = false;
		}
		return NULL;
	}
	if (using_plan_a)
		return i_ptr[line];
	else {
		LINENUM	offline = line % lines_per_buf;
		LINENUM	baseline = line - offline;
		if (tiline[0] == baseline)
			whichbuf = 0;
		else if (tiline[1] == baseline)
			whichbuf = 1;
		else {
			tiline[whichbuf] = baseline;
			if (lseek(tifd, (off_t) (baseline / lines_per_buf *
			    BUFFERSIZE), SEEK_SET) < 0)
				pfatal("cannot seek in the temporary input file");
			if (read(tifd, tibuf[whichbuf], BUFFERSIZE) < 0)
				pfatal("error reading tmp file %s", TMPINNAME);
		}
		return tibuf[whichbuf] + (tireclen * offline);
	}
}
char * ifetch ( LINENUM line , int whichbuf ) { if ( line < 1 || line > input_lines ) { if ( warn_on_invalid_line ) { say ( " \n " , line ) ; warn_on_invalid_line = false ; } return NULL ; } if ( using_plan_a ) return i_ptr [ line ] ; else { LINENUM offline = line % lines_per_buf ; LINENUM baseline = line - offline ; if ( tiline [ 0 ] == baseline ) whichbuf = 0 ; else if ( tiline [ 1 ] == baseline ) whichbuf = 1 ; else { tiline [ whichbuf ] = baseline ; if ( lseek ( tifd , ( off_t ) ( baseline / lines_per_buf * BUFFERSIZE ) , SEEK_SET ) < 0 ) pfatal ( " " ) ; if ( read ( tifd , tibuf [ whichbuf ] , BUFFERSIZE ) < 0 ) pfatal ( " " , TMPINNAME ) ; } return tibuf [ whichbuf ] + ( tireclen * offline ) ; } }
Fetch a line from the input file, \n terminated, not necessarily \0.
Fetch a line from the input file \ n terminated not necessarily \ 0 .