]> git.draconx.ca Git - cdecl99.git/blobdiff - t/normalize.c
Port to use getline.h from dxcommon.
[cdecl99.git] / t / normalize.c
index 558f5562414c358d9079ba2906539c47a863bb4a..f55501b5cf27975f2c8a18bcfb7bb64ee089822d 100644 (file)
@@ -1,6 +1,6 @@
 /*
  * Helper application to test normalization of declaration specifiers.
- * Copyright © 2021-2023 Nick Bowler
+ * Copyright © 2021-2024 Nick Bowler
  *
  * This program is free software: you can redistribute it and/or modify
  * it under the terms of the GNU General Public License as published by
 #include <stdio.h>
 #include <stdlib.h>
 #include <string.h>
+#include <errno.h>
 #include <getopt.h>
 
 #include "cdecl.h"
 #include "cdecl-internal.h"
-#include "test.h"
 
 #define PROGNAME "normalize"
-static const char *progname = PROGNAME;
+#include "test.h"
+
 static const char sopts[] = "f:VH";
 static const struct option lopts[] = {
        { "file", 1, NULL, 'f' },
@@ -191,17 +192,12 @@ int main(int argc, char **argv)
                }
        }
 
-       if (filename) {
-               infile = fopen(filename, "r");
-               if (!infile) {
-                       perror(filename);
-                       return EXIT_FAILURE;
-               }
+       if (filename && !freopen(filename, "r", stdin)) {
+               print_error("%s: %s", filename, strerror(errno));
+               return EXIT_FAILURE;
        }
 
-       while ((rc = getline(&line, &n, infile)) >= 0) {
-               if (rc > 0 && line[rc-1] == '\n')
-                       line[rc-1] = 0;
+       while (test_getline(&line, &n)) {
                if (do_normalize(line, n) < 0)
                        ret = EXIT_FAILURE;
        }