Alternatively accept files from command line arguments in elfdeps
authorPanu Matilainen <pmatilai@redhat.com>
Tue, 8 Jan 2013 10:51:36 +0000 (12:51 +0200)
committerPanu Matilainen <pmatilai@redhat.com>
Tue, 29 Jan 2013 06:14:16 +0000 (08:14 +0200)
- Nothing actually needs this, but for testing & debugging command line
  args are often nicer than having to pass stuff via stdin.
(cherry picked from commit 6941d51e7e5139014418d1056acb6dafccefbab7)

tools/elfdeps.c

index fc9a905..a140014 100644 (file)
@@ -282,7 +282,6 @@ exit:
 
 int main(int argc, char *argv[])
 {
-    char fn[BUFSIZ];
     int provides = 0;
     int requires = 0;
     poptContext optCon;
@@ -303,9 +302,18 @@ int main(int argc, char *argv[])
        exit(EXIT_FAILURE);
     }
 
-    while (fgets(fn, sizeof(fn), stdin) != NULL) {
-       fn[strlen(fn)-1] = '\0';
-       (void) processFile(fn, requires);
+    /* Normally our data comes from stdin, but permit args too */
+    if (poptPeekArg(optCon)) {
+       const char *fn;
+       while ((fn = poptGetArg(optCon)) != NULL) {
+           (void) processFile(fn, requires);
+       }
+    } else {
+       char fn[BUFSIZ];
+       while (fgets(fn, sizeof(fn), stdin) != NULL) {
+           fn[strlen(fn)-1] = '\0';
+           (void) processFile(fn, requires);
+       }
     }
 
     poptFreeContext(optCon);