Blame SOURCES/popt-1.13-alias-equal-arg.patch

30b197
diff -up popt-1.13/popt.c.alias-equal-arg popt-1.13/popt.c
30b197
--- popt-1.13/popt.c.alias-equal-arg	2007-12-11 20:04:06.000000000 +0200
30b197
+++ popt-1.13/popt.c	2011-06-14 11:57:21.000000000 +0300
30b197
@@ -308,8 +308,9 @@ static int handleExec(/*@special@*/ popt
30b197
 
30b197
 /* Only one of longName, shortName may be set at a time */
30b197
 static int handleAlias(/*@special@*/ poptContext con,
30b197
-		/*@null@*/ const char * longName, char shortName,
30b197
-		/*@exposed@*/ /*@null@*/ const char * nextCharArg)
30b197
+		/*@null@*/ const char * longName, size_t longNameLen,
30b197
+		char shortName,
30b197
+		/*@exposed@*/ /*@null@*/ const char * nextArg)
30b197
 	/*@uses con->aliases, con->numAliases, con->optionStack, con->os,
30b197
 		con->os->currAlias, con->os->currAlias->option.longName @*/
30b197
 	/*@modifies con @*/
30b197
@@ -319,9 +320,11 @@ static int handleAlias(/*@special@*/ pop
30b197
     int i;
30b197
 
30b197
     if (item) {
30b197
-	if (longName && (item->option.longName &&
30b197
-		!strcmp(longName, item->option.longName)))
30b197
+	if (longName && item->option.longName
30b197
+	 && longNameLen == strlen(item->option.longName)
30b197
+	 && !strncmp(longName, item->option.longName, longNameLen))
30b197
 	    return 0;
30b197
+	else
30b197
 	if (shortName && shortName == item->option.shortName)
30b197
 	    return 0;
30b197
     }
30b197
@@ -331,10 +334,14 @@ static int handleAlias(/*@special@*/ pop
30b197
 
30b197
     for (i = con->numAliases - 1; i >= 0; i--) {
30b197
 	item = con->aliases + i;
30b197
-	if (longName && !(item->option.longName &&
30b197
-			!strcmp(longName, item->option.longName)))
30b197
-	    continue;
30b197
-	else if (shortName != item->option.shortName)
30b197
+	if (longName) {
30b197
+	    if (item->option.longName == NULL)
30b197
+		continue;
30b197
+	    if (longNameLen != strlen(item->option.longName))
30b197
+		continue;
30b197
+	    if (strncmp(longName, item->option.longName, longNameLen))
30b197
+		continue;
30b197
+	} else if (shortName != item->option.shortName)
30b197
 	    continue;
30b197
 	break;
30b197
     }
30b197
@@ -343,8 +350,8 @@ static int handleAlias(/*@special@*/ pop
30b197
     if ((con->os - con->optionStack + 1) == POPT_OPTION_DEPTH)
30b197
 	return POPT_ERROR_OPTSTOODEEP;
30b197
 
30b197
-    if (nextCharArg && *nextCharArg)
30b197
-	con->os->nextCharArg = nextCharArg;
30b197
+    if (longName == NULL && nextArg && *nextArg)
30b197
+	con->os->nextCharArg = nextArg;
30b197
 
30b197
     con->os++;
30b197
     con->os->next = 0;
30b197
@@ -352,8 +359,20 @@ static int handleAlias(/*@special@*/ pop
30b197
     con->os->nextArg = NULL;
30b197
     con->os->nextCharArg = NULL;
30b197
     con->os->currAlias = con->aliases + i;
30b197
-    rc = poptDupArgv(con->os->currAlias->argc, con->os->currAlias->argv,
30b197
-		&con->os->argc, &con->os->argv);
30b197
+    {	const char ** av;
30b197
+	int ac = con->os->currAlias->argc;
30b197
+	/* Append --foo=bar arg to alias argv array (if present). */ 
30b197
+	if (longName && nextArg && *nextArg) {
30b197
+	    int i;
30b197
+	    av = alloca((ac + 1 + 1) * sizeof(*av));
30b197
+	    for (i = 0; i < ac; i++)
30b197
+		av[i] = con->os->currAlias->argv[i];
30b197
+	    av[ac++] = nextArg;
30b197
+	    av[ac] = NULL;
30b197
+	} else
30b197
+	    av = con->os->currAlias->argv;
30b197
+	rc = poptDupArgv(ac, av, &con->os->argc, &con->os->argv);
30b197
+    }
30b197
     con->os->argb = NULL;
30b197
 
30b197
     return (rc ? rc : 1);
30b197
@@ -795,13 +814,6 @@ int poptGetNextOpt(poptContext con)
30b197
 		else
30b197
 		    singleDash = 1;
30b197
 
30b197
-		/* XXX aliases with arg substitution need "--alias=arg" */
30b197
-		if (handleAlias(con, optString, '\0', NULL))
30b197
-		    continue;
30b197
-
30b197
-		if (handleExec(con, optString, '\0'))
30b197
-		    continue;
30b197
-
30b197
 		/* Check for "--long=arg" option. */
30b197
 		for (oe = optString; *oe && *oe != '='; oe++)
30b197
 		    {};
30b197
@@ -809,6 +821,15 @@ int poptGetNextOpt(poptContext con)
30b197
 		if (*oe == '=')
30b197
 		    longArg = oe + 1;
30b197
 
30b197
+		/* XXX aliases with arg substitution need "--alias=arg" */
30b197
+		if (handleAlias(con, optString, optStringLen, '\0', longArg)) {
30b197
+		    longArg = NULL;
30b197
+		    continue;
30b197
+		}
30b197
+
30b197
+		if (handleExec(con, optString, '\0'))
30b197
+		    continue;
30b197
+
30b197
 		opt = findOption(con->options, optString, optStringLen, '\0', &cb, &cbData,
30b197
 				 singleDash);
30b197
 		if (!opt && !singleDash)
30b197
@@ -834,7 +855,7 @@ int poptGetNextOpt(poptContext con)
30b197
 
30b197
 	    con->os->nextCharArg = NULL;
30b197
 
30b197
-	    if (handleAlias(con, NULL, *origOptString, origOptString + 1))
30b197
+	    if (handleAlias(con, NULL, 0, *origOptString, origOptString + 1))
30b197
 		continue;
30b197
 
30b197
 	    if (handleExec(con, NULL, *origOptString)) {