]> git.draconx.ca Git - cdecl99.git/blobdiff - t/crossparse.c
Avoid gnulib getline module.
[cdecl99.git] / t / crossparse.c
index e77a1cc9f21b846d6f46866affd5181d82e717b8..5f7eddc1324d732cda1634039b20465b24b1f725 100644 (file)
@@ -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))