示例#1
0
文件: cmpmain.c 项目: Wicker25/re2c
compare_result compare(FILE *fp1, FILE *fp2, int brief)
{
	// NOTE!!
	// This code is meant to be simple so I take shortcuts like
	// exiting without cleaning up.  Sorry.

	char buf1[39], buf2[8];		// these sizes are totally arbitrary
    scanstate ssrec, *ss=&ssrec;
	int n, cont;

	scanstate_init(ss, buf1, sizeof(buf1));
	readfp_attach(ss, fp1);
	compare_attach(ss);

    do {
		n = fread(buf2, 1, sizeof(buf2), fp2);
		if(n <= 0) {
			if(ferror(fp2)) {
				fprintf(stderr, "Error reading second file.\n");
				exit(17);
			}
			if(feof(fp2)) {
				break;
			}
		}

		cont = compare_continue(ss, buf2, n);
		if(cont < 0) {
			fprintf(stderr, "Error reading first file.\n");
			exit(17);
		}
    } while(cont == 0);

	return brief ? compare_check(ss) : compare_check_newlines(ss);
}
示例#2
0
文件: test.c 项目: bronson/tmtest
void compare_section_start(struct test *test,
    scanstate *cmpscan, int fd,
    const char *sectionname)
{
    // rewind the file
    if(lseek(fd, 0, SEEK_SET) < 0) {
        test_abort(test, "compare_section_start lseek compare: %s\n",
            strerror(errno));
    }

    scanstate_reset(cmpscan);
    readfd_attach(cmpscan, fd);
    compare_attach(cmpscan);

    // we may want to check the token to see if there are any
    // special requests (like detabbing).
}