FreeBSD/contrib/ntp/ntpd/ntp_scanner.c
/* get next character from buffer or file. This will return any putback
 * character first; it will also make sure the last line is at least
 * virtually terminated with a '\n'.
 */
get next character from buffer or file. This will return any putback
character first; it will also make sure the last line is at least
virtually terminated with a '\n'.
get next character from buffer or file . This will return any putback character first ; it will also make sure the last line is at least virtually terminated with a ' \ n ' .
static int
lex_getch(
	struct FILE_INFO *stream
	)
{
	int ch;
	if (NULL == stream || stream->force_eof)
		return EOF;
	if (EOF != stream->backch) {
		ch = stream->backch;
		stream->backch = EOF;
		if (stream->fpi)
			conf_file_sum += ch;
	} else if (stream->fpi) {
		while ((ch = fgetc(stream->fpi)) != EOF && ch > SCHAR_MAX)
			stream->curpos.ncol++;
		if (EOF != ch) {
			conf_file_sum += ch;
			stream->curpos.ncol++;
		}
	} else {
		const char * scan;
		scan = &remote_config.buffer[remote_config.pos];
		while ((ch = (u_char)*scan) > SCHAR_MAX) {
			scan++;
			stream->curpos.ncol++;
		}
		if ('\0' != ch) {
			scan++;
			stream->curpos.ncol++;
		} else {
			ch = EOF;
		}
		remote_config.pos = (int)(scan - remote_config.buffer);
	}
	if (EOF == ch && stream->curpos.ncol != 0)
		ch = '\n';
	if (ch == '\n') {
		stream->bakpos = stream->curpos;
		stream->curpos.nline++;
		stream->curpos.ncol = 0;
	}
	return ch;
}
static int lex_getch ( struct FILE_INFO * stream ) { int ch ; if ( NULL == stream || stream -> force_eof ) return EOF ; if ( EOF != stream -> backch ) { ch = stream -> backch ; stream -> backch = EOF ; if ( stream -> fpi ) conf_file_sum += ch ; } else if ( stream -> fpi ) { while ( ( ch = fgetc ( stream -> fpi ) ) != EOF && ch > SCHAR_MAX ) stream -> curpos . ncol ++ ; if ( EOF != ch ) { conf_file_sum += ch ; stream -> curpos . ncol ++ ; } } else { const char * scan ; scan = & remote_config . buffer [ remote_config . pos ] ; while ( ( ch = ( u_char ) * scan ) > SCHAR_MAX ) { scan ++ ; stream -> curpos . ncol ++ ; } if ( ' \0 ' != ch ) { scan ++ ; stream -> curpos . ncol ++ ; } else { ch = EOF ; } remote_config . pos = ( int ) ( scan - remote_config . buffer ) ; } if ( EOF == ch && stream -> curpos . ncol != 0 ) ch = ' \n ' ; if ( ch == ' \n ' ) { stream -> bakpos = stream -> curpos ; stream -> curpos . nline ++ ; stream -> curpos . ncol = 0 ; } return ch ; }
get next character from buffer or file.
get next character from buffer or file .
/* fetch next 7-bit ASCII char (or EOF) from file */ /* fetch next 7-bit ASCII char from buffer */ /* If the last line ends without '\n', generate one. This
	 * happens most likely on Windows, where editors often have a
	 * sloppy concept of a line.
	 */ /* update scan position tallies */