summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--CHANGES2
-rw-r--r--lib/header.c123
-rw-r--r--popt/popt.c3
-rw-r--r--rpmpopt45
4 files changed, 107 insertions, 66 deletions
diff --git a/CHANGES b/CHANGES
index 665ef5dcb..4c634da7f 100644
--- a/CHANGES
+++ b/CHANGES
@@ -2,6 +2,8 @@
- implemented install time prerequisites
- repaired %{#TAG} query format
- implemented ternary operator as query expression
+ - fixed --scripts to only print information on scripts which
+ are present
2.4.1 -> 2.4.2:
- completely rewrote queryformat code
diff --git a/lib/header.c b/lib/header.c
index 3d2ac12ee..a11767751 100644
--- a/lib/header.c
+++ b/lib/header.c
@@ -89,7 +89,7 @@ struct extensionCache {
};
struct sprintfToken {
- enum { PTOK_NONE = 0, PTOK_TAG, PTOK_ARRAY, PTOK_STRING, PTOK_NEST } type;
+ enum { PTOK_NONE = 0, PTOK_TAG, PTOK_ARRAY, PTOK_STRING, PTOK_COND } type;
union {
struct {
struct sprintfToken * format;
@@ -101,9 +101,12 @@ struct sprintfToken {
int len;
} string;
struct {
- struct sprintfToken * format;
- int numTokens;
- } nest;
+ struct sprintfToken * ifFormat;
+ int numIfTokens;
+ struct sprintfToken * elseFormat;
+ int numElseTokens;
+ struct sprintfTag tag;
+ } cond;
} u;
};
@@ -1111,8 +1114,12 @@ static void freeFormat(struct sprintfToken * format, int num) {
for (i = 0; i < num; i++) {
if (format[i].type == PTOK_ARRAY)
freeFormat(format[i].u.array.format, format[i].u.array.numTokens);
- if (format[i].type == PTOK_NEST)
- freeFormat(format[i].u.nest.format, format[i].u.nest.numTokens);
+ if (format[i].type == PTOK_COND) {
+ freeFormat(format[i].u.cond.ifFormat,
+ format[i].u.cond.numIfTokens);
+ freeFormat(format[i].u.cond.elseFormat,
+ format[i].u.cond.numElseTokens);
+ }
}
free(format);
}
@@ -1168,8 +1175,7 @@ static int parseExpression(struct sprintfToken * token, char * str,
const struct headerSprintfExtension * extensions,
char ** endPtr, char ** error) {
char * chptr, * end;
- struct sprintfToken ifpart, elsepart;
- const struct headerTagTableEntry * entry;
+ const struct headerTagTableEntry * tag;
const struct headerSprintfExtension * ext;
chptr = str;
@@ -1189,64 +1195,74 @@ static int parseExpression(struct sprintfToken * token, char * str,
chptr++;
- if (parseFormat(chptr, tags, extensions, &ifpart.u.nest.format,
- &ifpart.u.nest.numTokens, &end, PARSER_IN_EXPR, error))
+ if (parseFormat(chptr, tags, extensions, &token->u.cond.ifFormat,
+ &token->u.cond.numIfTokens, &end, PARSER_IN_EXPR, error))
return 1;
if (!*end) {
*error = "} expected in expression";
- freeFormat(ifpart.u.nest.format, ifpart.u.nest.numTokens);
+ freeFormat(token->u.cond.ifFormat, token->u.cond.numIfTokens);
return 1;
}
chptr = end;
- if (*chptr != ':') {
+ if (*chptr != ':' && *chptr != '|') {
*error = ": expected following ? subexpression";
- freeFormat(ifpart.u.nest.format, ifpart.u.nest.numTokens);
+ freeFormat(token->u.cond.ifFormat, token->u.cond.numIfTokens);
return 1;
}
- chptr++;
+ if (*chptr == '|') {
+ parseFormat(strdup(""), tags, extensions, &token->u.cond.elseFormat,
+ &token->u.cond.numElseTokens, &end, PARSER_IN_EXPR,
+ error);
+ } else {
+ chptr++;
- if (*chptr != '{') {
- *error = "{ exected after : in expression";
- return 1;
- }
+ if (*chptr != '{') {
+ *error = "{ exected after : in expression";
+ freeFormat(token->u.cond.ifFormat, token->u.cond.numIfTokens);
+ return 1;
+ }
- chptr++;
+ chptr++;
- if (parseFormat(chptr, tags, extensions, &elsepart.u.nest.format,
- &elsepart.u.nest.numTokens, &end, PARSER_IN_EXPR, error))
- return 1;
- if (!*end) {
- *error = "} expected in expression";
- freeFormat(ifpart.u.nest.format, ifpart.u.nest.numTokens);
- freeFormat(elsepart.u.nest.format, elsepart.u.nest.numTokens);
- return 1;
- }
+ if (parseFormat(chptr, tags, extensions, &token->u.cond.elseFormat,
+ &token->u.cond.numElseTokens, &end, PARSER_IN_EXPR,
+ error))
+ return 1;
+ if (!*end) {
+ *error = "} expected in expression";
+ freeFormat(token->u.cond.ifFormat, token->u.cond.numIfTokens);
+ return 1;
+ }
- chptr = end;
- if (*chptr != '|') {
- *error = "| expected at end of expression";
- freeFormat(ifpart.u.nest.format, ifpart.u.nest.numTokens);
- freeFormat(elsepart.u.nest.format, elsepart.u.nest.numTokens);
- return 1;
+ chptr = end;
+ if (*chptr != '|') {
+ *error = "| expected at end of expression";
+ freeFormat(token->u.cond.ifFormat, token->u.cond.numIfTokens);
+ freeFormat(token->u.cond.elseFormat, token->u.cond.numElseTokens);
+ return 1;
+ }
}
chptr++;
*endPtr = chptr;
-
- findTag(str, tags, extensions, &entry, &ext);
-
- if (entry || ext) {
- freeFormat(elsepart.u.nest.format, elsepart.u.nest.numTokens);
- *token = ifpart;
+
+ findTag(str, tags, extensions, &tag, &ext);
+
+ if (tag) {
+ token->u.cond.tag.ext = NULL;
+ token->u.cond.tag.tag = tag->val;
+ } else if (ext) {
+ token->u.cond.tag.ext = ext->u.tagFunction;
+ token->u.cond.tag.extNum = ext - extensions;
} else {
- freeFormat(ifpart.u.nest.format, ifpart.u.nest.numTokens);
- *token = elsepart;
+ token->u.cond.tag.ext = NULL;
+ token->u.cond.tag.tag = -1;
}
-
- token->type = PTOK_NEST;
+
+ token->type = PTOK_COND;
return 0;
}
@@ -1597,6 +1613,8 @@ static char * singleSprintf(Header h, struct sprintfToken * token,
int numElements;
int type;
void * data;
+ struct sprintfToken * condFormat;
+ int condNumFormats;
/* we assume the token and header have been validated already! */
@@ -1614,14 +1632,23 @@ static char * singleSprintf(Header h, struct sprintfToken * token,
token->u.tag.justOne ? 0 : element);
break;
- case PTOK_NEST:
- alloced = token->u.nest.numTokens * 20;
+ case PTOK_COND:
+ if (token->u.cond.tag.ext ||
+ headerIsEntry(h, token->u.cond.tag.tag)) {
+ condFormat = token->u.cond.ifFormat;
+ condNumFormats = token->u.cond.numIfTokens;
+ } else {
+ condFormat = token->u.cond.elseFormat;
+ condNumFormats = token->u.cond.numElseTokens;
+ }
+
+ alloced = condNumFormats * 20;
val = malloc(alloced);
*val = '\0';
len = 0;
- for (i = 0; i < token->u.nest.numTokens; i++) {
- thisItem = singleSprintf(h, token->u.nest.format + i,
+ for (i = 0; i < condNumFormats; i++) {
+ thisItem = singleSprintf(h, condFormat + i,
extensions, extCache, i);
thisItemLen = strlen(thisItem);
if ((thisItemLen + len) >= alloced) {
diff --git a/popt/popt.c b/popt/popt.c
index bc24b9b9a..d4dee0297 100644
--- a/popt/popt.c
+++ b/popt/popt.c
@@ -451,7 +451,8 @@ int poptReadConfigFile(poptContext con, char * fn) {
*dst++ = *chptr++;
if (chptr < end) {
if (*chptr == '\n')
- *(dst - 1) = *chptr++;
+ dst--, chptr++;
+ /* \ at the end of a line does not insert a \n */
else
*dst++ = *chptr++;
}
diff --git a/rpmpopt b/rpmpopt
index a4b7d92d5..e712b2e62 100644
--- a/rpmpopt
+++ b/rpmpopt
@@ -1,13 +1,24 @@
rpm alias --provides --qf '[%{PROVIDES}\n]'
-rpm alias --scripts --qf 'preinstall script:\n%{RPMTAG_PREIN}\
-postinstall script:\
-%{RPMTAG_POSTIN}\
-preuninstall script:\
-%{RPMTAG_PREUN}\
-postuninstall script: %{RPMTAG_POSTUN}\
-verify script:\
-%{VERIFYSCRIPT}\n'
+rpm alias --s2 --qf '\
+%|PREIN?{preinstall script\
+%|PREINPROG?{ (through %{PREINPROG})}|:\n%{PREIN}\n}:\
+{%|PREINPROG?{preinstall program: %{PREINPROG}\n}|}|\
+\
+%|POSTIN?{postinstall script\
+%|POSTINPROG?{ (through %{POSTINPROG})}|:\n%{POSTIN}\n}:\
+{%|POSTINPROG?{postinstall program: %{POSTINPROG}\n}|}|\
+\
+%|PREUN?{preuninstall script\
+%|PREUNPROG?{ (through %{PREUNPROG})}|:\n%{PREUN}\n}:\
+{%|PREUNPROG?{preuninstall program: %{PREUNPROG}\n}|}|\
+\
+%|POSTUN?{postuninstall script\
+%|POSTUNPROG?{ (through %{POSTUNPROG})}|:\n%{POSTUN}\n}:\
+{%|POSTUNPROG?{postuninstall program: %{POSTUNPROG}\n}|}|\
+\
+%|VERIFYSCRIPT?{verify script:\n%{VERIFYSCRIPT}\n}|\
+'
rpm alias --setperms -q --qf '[%{FILEMODES:octal} %{FILENAMES:shescape}\n]' \
--pipe "grep -v \(none\) | sed 's/^.../chmod /' | sh"
@@ -20,15 +31,15 @@ rpm alias --requires --qf \
"[%{REQUIRENAME} %{REQUIREFLAGS:depflags} %{REQUIREVERSION}\n]"
rpm alias -R --requires
-rpm alias --info --qf 'Name : %-27{NAME} Distribution: %{DISTRIBUTION}\
-Version : %-27{VERSION} Vendor: %{VENDOR}\
-Release : %-27{RELEASE} Build Date: %{BUILDTIME:date}\
-Install date: %-27{INSTALLTIME:date} Build Host: %{BUILDHOST}\
-Group : %-27{GROUP} Source RPM: %{SOURCERPM}\
-Size : %{SIZE}\
-Packager : %{PACKAGER}\
-URL : %{URL}\
-Summary : %{SUMMARY}\
+rpm alias --info --qf 'Name : %-27{NAME} Distribution: %{DISTRIBUTION}\n\
+Version : %-27{VERSION} Vendor: %{VENDOR}\n\
+Release : %-27{RELEASE} Build Date: %{BUILDTIME:date}\n\
+Install date: %-27{INSTALLTIME:date} Build Host: %{BUILDHOST}\n\
+Group : %-27{GROUP} Source RPM: %{SOURCERPM}\n\
+Size : %{SIZE}\n\
+Packager : %{PACKAGER}\n\
+URL : %{URL}\n\
+Summary : %{SUMMARY}\n\
Description :\n%{DESCRIPTION}\n'
rpm alias --changelog --qf '[* %{CHANGELOGTIME:day} %{CHANGELOGNAME}\n\n%{CHANGELOGTEXT}\n\n]'