From 50f30f5f00ca1885fdb88c6f21b5414468e3b764 Mon Sep 17 00:00:00 2001 From: kibook Date: Tue, 26 Nov 2024 15:08:26 -0500 Subject: [PATCH] s1kd-flatten: Remove "merging" behaviour of -a/-R Removed the "merging" behaviour of the -R and recently added -a options, where the contents of the referenced PM would be copied into the main PM in an S1000D-compliant way. Instead, the tool will always use the non-S1000D-compliant format of including the whole element in place of the . There are too many different ways that merging can be done, so it's better to let projects decide how using a separate tool, such as an XSL transformation on the output of s1kd-flatten. For example, they can decide to make the output S1000D-compliant by turning the element into a , or copying the contents directly into the main PM. The -a option has been removed since it no longer has any meaning with the new behaviour of -R. --- tools/s1kd-flatten/README.md | 12 +- ...-S1KDTOOLS-A-23-00-00-00A-040A-D_EN-CA.XML | 10 +- tools/s1kd-flatten/doc/s1kd-flatten.1 | 15 +- tools/s1kd-flatten/s1kd-flatten.c | 130 ++++++------------ 4 files changed, 46 insertions(+), 121 deletions(-) diff --git a/tools/s1kd-flatten/README.md b/tools/s1kd-flatten/README.md index 7c3bb74b..30e8f7d5 100644 --- a/tools/s1kd-flatten/README.md +++ b/tools/s1kd-flatten/README.md @@ -18,13 +18,6 @@ reference. # OPTIONS - - \-a, --recursively-add-entries - Recursively flatten referenced publication modules, copying their - content in to a new PM entry in the "master" publication module. The - PM entry is given the title of the referenced publication module. - The -R (--recursively) option works similarly, but does not create a - new PM entry. - - \-c, --containers Flatten referenced container data modules by copying the references inside the container directly in to the publication module. The @@ -77,10 +70,7 @@ reference. Quiet mode. Errors are not printed. - \-R, --recursively - Recursively flatten referenced publication modules, copying their - content in to the "master" publication module. This is similar to - the -a (--recursively-add-entries) option, but the contents are - copied directly rather than being added to a new PM entry. + Recursively flatten referenced publication modules. - \-r, --recursive Search directories recursively. diff --git a/tools/s1kd-flatten/doc/DMC-S1KDTOOLS-A-23-00-00-00A-040A-D_EN-CA.XML b/tools/s1kd-flatten/doc/DMC-S1KDTOOLS-A-23-00-00-00A-040A-D_EN-CA.XML index db377f42..f7a34c74 100644 --- a/tools/s1kd-flatten/doc/DMC-S1KDTOOLS-A-23-00-00-00A-040A-D_EN-CA.XML +++ b/tools/s1kd-flatten/doc/DMC-S1KDTOOLS-A-23-00-00-00A-040A-D_EN-CA.XML @@ -42,7 +42,7 @@ Add -l (--list) option. - Add -a (--recursively-add-entries) option. + Change behaviour of -R option. @@ -67,12 +67,6 @@ OPTIONS - - -a, --recursively-add-entries - - Recursively flatten referenced publication modules, copying their content in to a new PM entry in the "master" publication module. The PM entry is given the title of the referenced publication module. The -R (--recursively) option works similarly, but does not create a new PM entry. - - -c, --containers @@ -154,7 +148,7 @@ -R, --recursively - Recursively flatten referenced publication modules, copying their content in to the "master" publication module. This is similar to the -a (--recursively-add-entries) option, but the contents are copied directly rather than being added to a new PM entry. + Recursively flatten referenced publication modules. diff --git a/tools/s1kd-flatten/doc/s1kd-flatten.1 b/tools/s1kd-flatten/doc/s1kd-flatten.1 index e2f0558d..be845ceb 100644 --- a/tools/s1kd-flatten/doc/s1kd-flatten.1 +++ b/tools/s1kd-flatten/doc/s1kd-flatten.1 @@ -23,15 +23,6 @@ the data module code, language and/or issue info provided in each reference. .SH OPTIONS .TP -.B \-a, \-\-recursively\-add\-entries -Recursively flatten referenced publication modules, copying their -content in to a new PM entry in the "master" publication module. -The PM entry is given the title of the referenced publication module. -The \-R (\-\-recursively) option works similarly, but does not create a -new PM entry. -.RS -.RE -.TP .B \-c, \-\-containers Flatten referenced container data modules by copying the references inside the container directly in to the publication module. @@ -110,11 +101,7 @@ Errors are not printed. .RE .TP .B \-R, \-\-recursively -Recursively flatten referenced publication modules, copying their -content in to the "master" publication module. -This is similar to the \-a (\-\-recursively\-add\-entries) option, but -the contents are copied directly rather than being added to a new PM -entry. +Recursively flatten referenced publication modules. .RS .RE .TP diff --git a/tools/s1kd-flatten/s1kd-flatten.c b/tools/s1kd-flatten/s1kd-flatten.c index ad6de446..38a63c2a 100644 --- a/tools/s1kd-flatten/s1kd-flatten.c +++ b/tools/s1kd-flatten/s1kd-flatten.c @@ -15,7 +15,7 @@ #include "xsl.h" #define PROG_NAME "s1kd-flatten" -#define VERSION "3.5.0" +#define VERSION "4.0.0" #define ERR_PREFIX PROG_NAME ": ERROR: " #define WRN_PREFIX PROG_NAME ": WARNING: " @@ -53,7 +53,6 @@ static int flatten_container = 0; static int recursive = 0; static int recursive_search = 0; static int remove_unresolved = 0; -static int add_pmentry = 0; static int only_pm_refs = 0; @@ -61,29 +60,28 @@ static enum verbosity { QUIET, NORMAL, VERBOSE, DEBUG } verbosity = NORMAL; static void show_help(void) { - puts("Usage: " PROG_NAME " [-d ] [-I ] [-acDfilmNPpqRruvxh?] [...]"); + puts("Usage: " PROG_NAME " [-d ] [-I ] [-cDfilmNPpqRruvxh?] [...]"); puts(""); puts("Options:"); - puts(" -a, --recursively-add-entries Recursively flatten referenced PMs, adding a new PM entry for each."); - puts(" -c, --containers Flatten referenced container data modules."); - puts(" -D, --remove Remove unresolved references."); - puts(" -d, --dir Directory to start search in."); - puts(" -f, --overwrite Overwrite publication module."); - puts(" -h, -?, --help Show help/usage message."); - puts(" -I, --include Search for referenced objects."); - puts(" -i, --ignore-issue Always match the latest issue of an object found."); - puts(" -l, --list Treat input as a list of objects."); - puts(" -m, --modify Modiy references without flattening them."); - puts(" -N, --omit-issue Assume issue/inwork numbers are omitted."); - puts(" -P, --only-pm-refs Only flatten PM refs."); - puts(" -p, --simple Output a simple, flat XML file."); - puts(" -q, --quiet Quiet mode."); - puts(" -R, --recursively Recursively flatten referenced PMs."); - puts(" -r, --recursive Search directories recursively."); - puts(" -u, --unique Remove duplicate references."); - puts(" -v, --verbose Verbose output."); - puts(" -x, --use-xinclude Use XInclude references."); - puts(" --version Show version information."); + puts(" -c, --containers Flatten referenced container data modules."); + puts(" -D, --remove Remove unresolved references."); + puts(" -d, --dir Directory to start search in."); + puts(" -f, --overwrite Overwrite publication module."); + puts(" -h, -?, --help Show help/usage message."); + puts(" -I, --include Search for referenced objects."); + puts(" -i, --ignore-issue Always match the latest issue of an object found."); + puts(" -l, --list Treat input as a list of objects."); + puts(" -m, --modify Modiy references without flattening them."); + puts(" -N, --omit-issue Assume issue/inwork numbers are omitted."); + puts(" -P, --only-pm-refs Only flatten PM refs."); + puts(" -p, --simple Output a simple, flat XML file."); + puts(" -q, --quiet Quiet mode."); + puts(" -R, --recursively Recursively flatten referenced PMs."); + puts(" -r, --recursive Search directories recursively."); + puts(" -u, --unique Remove duplicate references."); + puts(" -v, --verbose Verbose output."); + puts(" -x, --use-xinclude Use XInclude references."); + puts(" --version Show version information."); LIBXML2_PARSE_LONGOPT_HELP } @@ -152,10 +150,6 @@ static void flatten_pm_ref(xmlNodePtr pm_ref, xmlNsPtr xiNs) char pm_fname_temp[PATH_MAX]; char fs_pm_fname[PATH_MAX] = ""; - xmlNodePtr xi; - xmlDocPtr doc; - xmlNodePtr pm; - bool found = false; xmlNodePtr cur; @@ -238,65 +232,14 @@ static void flatten_pm_ref(xmlNodePtr pm_ref, xmlNsPtr xiNs) found = true; - if (recursive) { - xmlDocPtr subpm; - xmlNodePtr pmentry = NULL; - xmlNodePtr content; - + if (flatten_ref) { if (verbosity >= VERBOSE) { fprintf(stderr, I_INCLUDE, fs_pm_fname); } - subpm = read_xml_doc(fs_pm_fname); - - /* Create a new PM entry to contain the contents of the referenced PM. */ - if (add_pmentry) { - xmlChar *title; - - pmentry = xmlNewNode(NULL, BAD_CAST "pmEntry"); - - title = xpath_first_value(subpm, NULL, BAD_CAST "//pmTitle"); - xmlNewChild(pmentry, NULL, BAD_CAST "pmEntryTitle", title); - xmlFree(title); - - pmentry = xmlAddNextSibling(pm_ref, pmentry); - } - - content = first_xpath_node(subpm, NULL, "//content"); - - if (content) { - xmlNodePtr c; - - flatten_pm_entry(content, xiNs); - - /* Add the contents to the new PM entry. */ - if (add_pmentry) { - for (c = content->children; c; c = c->next) { - if (xmlStrcmp(c->name, BAD_CAST "pmEntry") != 0) { - continue; - } - - xmlAddChild(pmentry, xmlCopyNode(c, 1)); - } - /* Or, add the contents directly to the main PM. */ - } else { - for (c = content->last; c; c = c->prev) { - if (xmlStrcmp(c->name, BAD_CAST "pmEntry") != 0) { - continue; - } + if (xinclude && !recursive) { + xmlNodePtr xi; - xmlAddNextSibling(pm_ref, xmlCopyNode(c, 1)); - } - } - } - - xmlFreeDoc(subpm); - } else if (flatten_ref) { - if (verbosity >= VERBOSE) { - fprintf(stderr, I_INCLUDE, fs_pm_fname); - } - - if (xinclude) { xi = xmlNewNode(xiNs, BAD_CAST "include"); xmlSetProp(xi, BAD_CAST "href", BAD_CAST fs_pm_fname); @@ -306,10 +249,23 @@ static void flatten_pm_ref(xmlNodePtr pm_ref, xmlNsPtr xiNs) xi = xmlAddPrevSibling(pm_ref, xi); } } else { - doc = read_xml_doc(fs_pm_fname); - pm = xmlDocGetRootElement(doc); - xmlAddPrevSibling(pm_ref, xmlCopyNode(pm, 1)); - xmlFreeDoc(doc); + xmlDocPtr subpm; + + subpm = read_xml_doc(fs_pm_fname); + + if (recursive) { + xmlNodePtr content; + + content = first_xpath_node(subpm, NULL, "//content"); + + if (content) { + flatten_pm_entry(content, xiNs); + } + } + + xmlAddPrevSibling(pm_ref, xmlCopyNode(xmlDocGetRootElement(subpm), 1)); + + xmlFreeDoc(subpm); } } } else if (remove_unresolved) { @@ -665,10 +621,9 @@ int main(int argc, char **argv) xmlNodePtr cur; - const char *sopts = "acDd:fxmNPpqRruvI:ilh?"; + const char *sopts = "cDd:fxmNPpqRruvI:ilh?"; struct option lopts[] = { {"version" , no_argument , 0, 0}, - {"recursively-add-entries", no_argument , 0, 'a'}, {"help" , no_argument , 0, 'h'}, {"containers" , no_argument , 0, 'c'}, {"remove" , no_argument , 0, 'D'}, @@ -709,7 +664,6 @@ int main(int argc, char **argv) } LIBXML2_PARSE_LONGOPT_HANDLE(lopts, loptind, optarg) break; - case 'a': recursive = 1; add_pmentry = 1; break; case 'c': flatten_container = 1; break; case 'D': remove_unresolved = 1; break; case 'd': free(search_dir); search_dir = strdup(optarg); break;