Panu Matilainen e3441c
commit 35052b96232810cbf0d91a4f1d1d3ff25a142fd0
Panu Matilainen e3441c
Author: Panu Matilainen <pmatilai@redhat.com>
Panu Matilainen e3441c
Date:   Mon Mar 15 11:54:55 2010 +0200
Panu Matilainen e3441c
Panu Matilainen e3441c
    Add an enhanced argvSplitString() function for splitting strings to argv's
Panu Matilainen e3441c
    - Returns the newly created argv instead of useless "this always returns 0"
Panu Matilainen e3441c
    - By default make a "real" split, including empty strings
Panu Matilainen e3441c
    - Flags argument allows controlling behavior, for now only flag is to
Panu Matilainen e3441c
      preserve argvSplit() behavior but leaves room for future enhancements
Panu Matilainen e3441c
      such as quoted splitting etc
Panu Matilainen e3441c
Panu Matilainen e3441c
commit 12802c36c9a3b7260d9f788afc826b1cc5ee05e2
Panu Matilainen e3441c
Author: Panu Matilainen <pmatilai@redhat.com>
Panu Matilainen e3441c
Date:   Mon Mar 15 12:00:55 2010 +0200
Panu Matilainen e3441c
Panu Matilainen e3441c
    Avoid eating empty lines in spec %prep section (RhBug:573339)
Panu Matilainen e3441c
    - In spec %prep context empty lines don't usually matter but they can
Panu Matilainen e3441c
      be significant in eg here-documents.
Panu Matilainen e3441c
    - Fixes regression from commit 94ff22b129aeb31c38848231e40f87aa4a5613a1
Panu Matilainen e3441c
Panu Matilainen e3441c
diff --git a/rpmio/argv.c b/rpmio/argv.c
Panu Matilainen e3441c
index d633462..f21da1c 100644
Panu Matilainen e3441c
--- a/rpmio/argv.c
Panu Matilainen e3441c
+++ b/rpmio/argv.c
Panu Matilainen e3441c
@@ -168,7 +168,7 @@ int argvAppend(ARGV_t * argvp, ARGV_const_t av)
Panu Matilainen e3441c
     return 0;
Panu Matilainen e3441c
 }
Panu Matilainen e3441c
 
Panu Matilainen e3441c
-int argvSplit(ARGV_t * argvp, const char * str, const char * seps)
Panu Matilainen e3441c
+ARGV_t argvSplitString(const char * str, const char * seps, argvFlags flags)
Panu Matilainen e3441c
 {
Panu Matilainen e3441c
     char *dest = xmalloc(strlen(str) + 1);
Panu Matilainen e3441c
     ARGV_t argv;
Panu Matilainen e3441c
@@ -189,14 +189,22 @@ int argvSplit(ARGV_t * argvp, const char * str, const char * seps)
Panu Matilainen e3441c
     argv = xmalloc( (argc + 1) * sizeof(*argv));
Panu Matilainen e3441c
 
Panu Matilainen e3441c
     for (c = 0, s = dest; s < t; s+= strlen(s) + 1) {
Panu Matilainen e3441c
-	if (*s == '\0')
Panu Matilainen e3441c
+	if (*s == '\0' && (flags & ARGV_SKIPEMPTY))
Panu Matilainen e3441c
 	    continue;
Panu Matilainen e3441c
 	argv[c] = xstrdup(s);
Panu Matilainen e3441c
 	c++;
Panu Matilainen e3441c
     }
Panu Matilainen e3441c
     argv[c] = NULL;
Panu Matilainen e3441c
-    *argvp = argv;
Panu Matilainen e3441c
     free(dest);
Panu Matilainen e3441c
+    return argv;
Panu Matilainen e3441c
+}
Panu Matilainen e3441c
+
Panu Matilainen e3441c
+/* Backwards compatibility */
Panu Matilainen e3441c
+int argvSplit(ARGV_t * argvp, const char * str, const char * seps)
Panu Matilainen e3441c
+{
Panu Matilainen e3441c
+    if (argvp) {
Panu Matilainen e3441c
+	*argvp = argvSplitString(str, seps, ARGV_SKIPEMPTY);
Panu Matilainen e3441c
+    }
Panu Matilainen e3441c
     return 0;
Panu Matilainen e3441c
 }
Panu Matilainen e3441c
 
Panu Matilainen e3441c
diff --git a/rpmio/argv.h b/rpmio/argv.h
Panu Matilainen e3441c
index 6a6fc7f..86ec137 100644
Panu Matilainen e3441c
--- a/rpmio/argv.h
Panu Matilainen e3441c
+++ b/rpmio/argv.h
Panu Matilainen e3441c
@@ -138,6 +138,20 @@ int argvAddNum(ARGV_t * argvp, int val);
Panu Matilainen e3441c
  */
Panu Matilainen e3441c
 int argvAppend(ARGV_t * argvp, ARGV_const_t av);
Panu Matilainen e3441c
 
Panu Matilainen e3441c
+typedef enum argvFlags_e {
Panu Matilainen e3441c
+    ARGV_NONE		= 0,
Panu Matilainen e3441c
+    ARGV_SKIPEMPTY	= (1 << 0),	/* omit empty strings from result */
Panu Matilainen e3441c
+} argvFlags;
Panu Matilainen e3441c
+
Panu Matilainen e3441c
+/** \ingroup rpmargv
Panu Matilainen e3441c
+ * Split a string into an argv array.
Panu Matilainen e3441c
+ * @param str		string arg to split
Panu Matilainen e3441c
+ * @param seps		seperator characters
Panu Matilainen e3441c
+ * @param flags		flags to control behavior
Panu Matilainen e3441c
+ * @return		argv array
Panu Matilainen e3441c
+ */
Panu Matilainen e3441c
+ARGV_t argvSplitString(const char * str, const char * seps, argvFlags flags);
Panu Matilainen e3441c
+
Panu Matilainen e3441c
 /** \ingroup rpmargv
Panu Matilainen e3441c
  * Split a string into an argv array.
Panu Matilainen e3441c
  * @retval *argvp	argv array
Panu Matilainen e3441c
diff --git a/build/parsePrep.c b/build/parsePrep.c
Panu Matilainen e3441c
index 8e10c00..394c162 100644
Panu Matilainen e3441c
--- a/build/parsePrep.c
Panu Matilainen e3441c
+++ b/build/parsePrep.c
Panu Matilainen e3441c
@@ -522,7 +522,7 @@ int parsePrep(rpmSpec spec)
Panu Matilainen e3441c
 	}
Panu Matilainen e3441c
     }
Panu Matilainen e3441c
 
Panu Matilainen e3441c
-    argvSplit(&saveLines, getStringBuf(sb), "\n");
Panu Matilainen e3441c
+    saveLines = argvSplitString(getStringBuf(sb), "\n", ARGV_NONE);
Panu Matilainen e3441c
     for (lines = saveLines; *lines; lines++) {
Panu Matilainen e3441c
 	res = 0;
Panu Matilainen e3441c
 	if (rstreqn(*lines, "%setup", sizeof("%setup")-1)) {