#define PROGNAME "crossparse"
#include "test.h"
+#include "getline.h"
static const char sopts[] = "f:ECVH";
static const struct option lopts[] = {
int i;
const char *filename = NULL;
- FILE *infile = NULL;
if (argc > 0)
progname = argv[0];
mode = MODE_ENGLISH;
break;
case 'f':
- infile = stdin;
filename = optarg;
break;
case 'V':
}
}
- 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))