From 3198051254614679f0bc78ca5f1bb406616f64ad Mon Sep 17 00:00:00 2001 From: H.G.Muller Date: Sun, 24 Apr 2016 14:00:50 +0200 Subject: [PATCH] Allow group specification in ArgInstall options The option that add a line to the existing multi-line options (e.g. -installTheme which adds to -themeNames) now can specify the line should be added within a group, by prefixing the line with "# GROUPNAME\n" (where \ and n separate characters). If a group of that name already exists, the line to add is insert immediately after the group header line. If not, the group is created, by adding both the group header line and the line to add, as well as an "# end" line to terminate the group. --- args.h | 29 ++++++++++++++++++++++++----- 1 files changed, 24 insertions(+), 5 deletions(-) diff --git a/args.h b/args.h index 85e8765..8b8fe8e 100644 --- a/args.h +++ b/args.h @@ -961,7 +961,7 @@ ParseArgs(GetFunc get, void *cl) char argValue[MAX_ARG_LEN]; ArgDescriptor *ad; char start; - char *q; + char *q, *r, *s; int i, octval; char ch; int posarg = 4; // default is game file @@ -1241,10 +1241,29 @@ ParseArgs(GetFunc get, void *cl) case ArgInstall: q = *(char **) ad->argLoc; - if((saveDate == 0 || saveDate - dateStamp < 0) && !strstr(q, argValue) ) { - int l = strlen(q) + strlen(argValue); - *(char **) ad->argLoc = malloc(l+2); - snprintf(*(char **) ad->argLoc, l+2, "%s%s\n", q, argValue); + r = NULL; s = argValue; + if(argValue[0] == '#') { // group specification + r = strstr(argValue, "\\n"); + if(r) *r++ = '\n', *r++ = NULLCHAR, s = r, r = argValue; // split s into line-to-add (s) and group (r) + } + if((saveDate == 0 || saveDate - dateStamp < 0) && !strstr(q, s) ) { // not seen before, and line does not occur yet + int l = strlen(q) + strlen(s); + if(r) { // must be put in group r + char *p = strstr(q, r); + if(p) { // group already exists + p += strlen(r); // determine insertion point (immediately after group header line) + *(char **) ad->argLoc = malloc(l+2); + *p++ = NULLCHAR; // spit old value (q) at insertion point into q and p + snprintf(*(char **) ad->argLoc, l+2, "%s%s\n%s", q, s, p); // insert (with newline) + } else { // group did not exist, create at end + l += strlen(r) + 8; + *(char **) ad->argLoc = malloc(l); + snprintf(*(char **) ad->argLoc, l, "%s%s%s\n# end\n", q, r, s); + } + } else { // no group, just add line at end + *(char **) ad->argLoc = malloc(l+2); + snprintf(*(char **) ad->argLoc, l+2, "%s%s\n", q, s); + } free(q); } break; -- 1.7.0.4