FreeBSD/contrib/openpam/t/t_openpam_readword.c
/*
 * Read a word from the temp file and verify that the result matches our
 * expectations: whether a word was read at all, how many lines were read
 * (in case of quoted or escaped newlines), whether we reached the end of
 * the file and whether we reached the end of the line.
 */
Read a word from the temp file and verify that the result matches our
expectations: whether a word was read at all, how many lines were read
(in case of quoted or escaped newlines), whether we reached the end of
the file and whether we reached the end of the line.
Read a word from the temp file and verify that the result matches our expectations : whether a word was read at all how many lines were read ( in case of quoted or escaped newlines ) whether we reached the end of the file and whether we reached the end of the line .
static int
orw_expect(struct t_file *tf, const char *expected, int lines, int eof, int eol)
{
	int ch, lineno = 0;
	char *got;
	size_t len;
	got = openpam_readword(tf->file, &lineno, &len);
	if (t_ferror(tf))
		err(1, "%s(): %s", __func__, tf->name);
	if (expected != NULL && got == NULL) {
		t_verbose("expected <<%s>>, got nothing\n", expected);
		return (0);
	}
	if (expected == NULL && got != NULL) {
		t_verbose("expected nothing, got <<%s>>\n", got);
		return (0);
	}
	if (expected != NULL && got != NULL && strcmp(expected, got) != 0) {
		t_verbose("expected <<%s>>, got <<%s>>\n", expected, got);
		return (0);
	}
	if (lineno != lines) {
		t_verbose("expected to advance %d lines, advanced %d lines\n",
		    lines, lineno);
		return (0);
	}
	if (eof && !t_feof(tf)) {
		t_verbose("expected EOF, but didn't get it\n");
		return (0);
	}
	if (!eof && t_feof(tf)) {
		t_verbose("didn't expect EOF, but got it anyway\n");
		return (0);
	}
	ch = fgetc(tf->file);
	if (t_ferror(tf))
		err(1, "%s(): %s", __func__, tf->name);
	if (eol && ch != '\n') {
		t_verbose("expected EOL, but didn't get it\n");
		return (0);
	}
	if (!eol && ch == '\n') {
		t_verbose("didn't expect EOL, but got it anyway\n");
		return (0);
	}
	if (ch != EOF)
		ungetc(ch, tf->file);
	return (1);
}
static int orw_expect ( struct t_file * tf , const char * expected , int lines , int eof , int eol ) { int ch , lineno = 0 ; char * got ; size_t len ; got = openpam_readword ( tf -> file , & lineno , & len ) ; if ( t_ferror ( tf ) ) err ( 1 , " " , __func__ , tf -> name ) ; if ( expected != NULL && got == NULL ) { t_verbose ( " \n " , expected ) ; return ( 0 ) ; } if ( expected == NULL && got != NULL ) { t_verbose ( " \n " , got ) ; return ( 0 ) ; } if ( expected != NULL && got != NULL && strcmp ( expected , got ) != 0 ) { t_verbose ( " \n " , expected , got ) ; return ( 0 ) ; } if ( lineno != lines ) { t_verbose ( " \n " , lines , lineno ) ; return ( 0 ) ; } if ( eof && ! t_feof ( tf ) ) { t_verbose ( " \n " ) ; return ( 0 ) ; } if ( ! eof && t_feof ( tf ) ) { t_verbose ( " \n " ) ; return ( 0 ) ; } ch = fgetc ( tf -> file ) ; if ( t_ferror ( tf ) ) err ( 1 , " " , __func__ , tf -> name ) ; if ( eol && ch != ' \n ' ) { t_verbose ( " \n " ) ; return ( 0 ) ; } if ( ! eol && ch == ' \n ' ) { t_verbose ( " \n " ) ; return ( 0 ) ; } if ( ch != EOF ) ungetc ( ch , tf -> file ) ; return ( 1 ) ; }
Read a word from the temp file and verify that the result matches our
 expectations: whether a word was read at all, how many lines were read
 (in case of quoted or escaped newlines), whether we reached the end of
 the file and whether we reached the end of the line.
Read a word from the temp file and verify that the result matches our expectations : whether a word was read at all how many lines were read ( in case of quoted or escaped newlines ) whether we reached the end of the file and whether we reached the end of the line .