X-Git-Url: https://git.draconx.ca/gitweb/cdecl99.git/blobdiff_plain/aba6fe8bda05659f70ef0cca07aa02db72f23315..4ef59e97312cf3e8f537643c65bc2fef057b786b:/t/crossparse.c diff --git a/t/crossparse.c b/t/crossparse.c index e77a1cc..5f7eddc 100644 --- a/t/crossparse.c +++ b/t/crossparse.c @@ -28,6 +28,7 @@ #define PROGNAME "crossparse" #include "test.h" +#include "getline.h" static const char sopts[] = "f:ECVH"; static const struct option lopts[] = { @@ -139,7 +140,6 @@ int main(int argc, char **argv) int i; const char *filename = NULL; - FILE *infile = NULL; if (argc > 0) progname = argv[0]; @@ -153,7 +153,6 @@ int main(int argc, char **argv) mode = MODE_ENGLISH; break; case 'f': - infile = stdin; filename = optarg; break; case 'V': @@ -168,29 +167,19 @@ int main(int argc, char **argv) } } - if (infile) { + if (filename && !freopen(filename, "r", stdin)) { + print_error("%s: %s", filename, strerror(errno)); + return EXIT_FAILURE; + } else if (filename) { char *line = NULL; - size_t n; - - if (filename) { - infile = fopen(filename, "r"); - if (!infile) { - print_error("%s: %s", filename, - strerror(errno)); - return EXIT_FAILURE; - } - } + size_t n = 0; - while (getline(&line, &n, infile) >= 0) { - char *c = strchr(line, '\n'); - if (c) - *c = '\0'; + while (do_getline(&line, &n)) { if (!test_crossparse(line, mode)) ret = EXIT_FAILURE; } free(line); - fclose(infile); } else if (argv[optind]) { for (i = optind; i < argc; i++) { if (!test_crossparse(argv[i], mode))