Panu Matilainen 99eadd
commit 9a2547ff49ae2fa9a4c9118e5472bba045379f3d
Panu Matilainen 99eadd
Author: Panu Matilainen <pmatilai@redhat.com>
Panu Matilainen 99eadd
Date:   Thu Mar 29 11:26:57 2012 +0300
Panu Matilainen 99eadd
Panu Matilainen 99eadd
    Accept files as command line arguments again in rpmdeps (RhBug:807767)
Panu Matilainen 99eadd
    
Panu Matilainen 99eadd
    - Commit a25c3c7bac95ab7eb55f0ecf0b8793d8da341611 removed what was
Panu Matilainen 99eadd
      supposedly a non-supported method of passing files as arguments
Panu Matilainen 99eadd
      (instead of the normal stdin method) to rpmdeps. Turns out
Panu Matilainen 99eadd
      rpmdeps is even documented to take files as cli args, and that's
Panu Matilainen 99eadd
      how Fedora's %filter_setup macros are calling it...
Panu Matilainen 99eadd
    - Allow files as arguments again, but in a way that doesn't cause
Panu Matilainen 99eadd
      argvFoo() vs popt crash-n-burn.
Panu Matilainen 99eadd
    (cherry picked from commit fe252f21b370331016a952b085465cd97837aaef)
Panu Matilainen 99eadd
Panu Matilainen 99eadd
diff --git a/tools/rpmdeps.c b/tools/rpmdeps.c
Panu Matilainen 99eadd
index 6b0b527..c3112eb 100644
Panu Matilainen 99eadd
--- a/tools/rpmdeps.c
Panu Matilainen 99eadd
+++ b/tools/rpmdeps.c
Panu Matilainen 99eadd
@@ -60,11 +60,19 @@ main(int argc, char *argv[])
Panu Matilainen 99eadd
     if (optCon == NULL)
Panu Matilainen 99eadd
 	goto exit;
Panu Matilainen 99eadd
 
Panu Matilainen 99eadd
-    while (fgets(buf, sizeof(buf), stdin) != NULL) {
Panu Matilainen 99eadd
-	char *be = buf + strlen(buf) - 1;
Panu Matilainen 99eadd
-	while (strchr("\r\n", *be) != NULL)
Panu Matilainen 99eadd
-	    *be-- = '\0';
Panu Matilainen 99eadd
-	argvAdd(&av, buf);
Panu Matilainen 99eadd
+    /* normally files get passed through stdin but also accept files as args */
Panu Matilainen 99eadd
+    if (poptPeekArg(optCon)) {
Panu Matilainen 99eadd
+	const char *arg;
Panu Matilainen 99eadd
+	while ((arg = poptGetArg(optCon)) != NULL) {
Panu Matilainen 99eadd
+	    argvAdd(&av, arg);
Panu Matilainen 99eadd
+	}
Panu Matilainen 99eadd
+    } else {
Panu Matilainen 99eadd
+	while (fgets(buf, sizeof(buf), stdin) != NULL) {
Panu Matilainen 99eadd
+	    char *be = buf + strlen(buf) - 1;
Panu Matilainen 99eadd
+	    while (strchr("\r\n", *be) != NULL)
Panu Matilainen 99eadd
+		*be-- = '\0';
Panu Matilainen 99eadd
+	    argvAdd(&av, buf);
Panu Matilainen 99eadd
+	}
Panu Matilainen 99eadd
     }
Panu Matilainen 99eadd
     /* Make sure file names are sorted. */
Panu Matilainen 99eadd
     argvSort(av, NULL);