summaryrefslogtreecommitdiff
path: root/xmlwf/xmlwf.c
diff options
context:
space:
mode:
Diffstat (limited to 'xmlwf/xmlwf.c')
-rw-r--r--xmlwf/xmlwf.c48
1 files changed, 41 insertions, 7 deletions
diff --git a/xmlwf/xmlwf.c b/xmlwf/xmlwf.c
index 5121fa10..493b6973 100644
--- a/xmlwf/xmlwf.c
+++ b/xmlwf/xmlwf.c
@@ -322,6 +322,13 @@ freeNotations(XmlwfUserData *data) {
data->notationListHead = NULL;
}
+static void
+cleanupUserData(XmlwfUserData *userData) {
+ free((void *)userData->currentDoctypeName);
+ userData->currentDoctypeName = NULL;
+ freeNotations(userData);
+}
+
static int
xcscmp(const XML_Char *xs, const XML_Char *xt) {
while (*xs != 0 && *xt != 0) {
@@ -848,9 +855,11 @@ usage(const XML_Char *prog, int rc) {
stderr,
/* Generated with:
* $ xmlwf/xmlwf_helpgen.sh
+ * To update, change xmlwf/xmlwf_helpgen.py, then paste the output of
+ * xmlwf/xmlwf_helpgen.sh in here.
*/
/* clang-format off */
- T("usage: %s [-s] [-n] [-p] [-x] [-e ENCODING] [-w] [-r] [-d DIRECTORY]\n")
+ T("usage: %s [-s] [-n] [-p] [-x] [-e ENCODING] [-w] [-r] [-k] [-d DIRECTORY]\n")
T(" [-c | -m | -t] [-N]\n")
T(" [FILE [FILE ...]]\n")
T("\n")
@@ -867,6 +876,7 @@ usage(const XML_Char *prog, int rc) {
T(" -e ENCODING override any in-document [e]ncoding declaration\n")
T(" -w enable support for [W]indows code pages\n")
T(" -r disable memory-mapping and use normal file [r]ead IO calls instead\n")
+ T(" -k when processing multiple files, [k]eep processing after first file with error\n")
T("\n")
T("output control arguments:\n")
T(" -d DIRECTORY output [d]estination directory\n")
@@ -879,6 +889,13 @@ usage(const XML_Char *prog, int rc) {
T(" -h show this [h]elp message and exit\n")
T(" -v show program's [v]ersion number and exit\n")
T("\n")
+ T("exit status:\n")
+ T(" 0 the input files are well-formed and the output (if requested) was written successfully\n")
+ T(" 1 could not allocate data structures, signals a serious problem with execution environment\n")
+ T(" 2 one or more input files were not well-formed\n")
+ T(" 3 could not create an output file\n")
+ T(" 4 command-line argument error\n")
+ T("\n")
T("xmlwf of libexpat is software libre, licensed under the MIT license.\n")
T("Please report bugs at https://github.com/libexpat/libexpat/issues. Thank you!\n")
, /* clang-format on */
@@ -902,6 +919,8 @@ tmain(int argc, XML_Char **argv) {
int useNamespaces = 0;
int requireStandalone = 0;
int requiresNotations = 0;
+ int continueOnError = 0;
+ int exitCode = 0;
enum XML_ParamEntityParsing paramEntityParsing
= XML_PARAM_ENTITY_PARSING_NEVER;
int useStdin = 0;
@@ -967,7 +986,7 @@ tmain(int argc, XML_Char **argv) {
case T('d'):
if (argv[i][j + 1] == T('\0')) {
if (++i == argc)
- usage(argv[0], 2);
+ usage(argv[0], 4);
outputDir = argv[i];
} else
outputDir = argv[i] + j + 1;
@@ -977,7 +996,7 @@ tmain(int argc, XML_Char **argv) {
case T('e'):
if (argv[i][j + 1] == T('\0')) {
if (++i == argc)
- usage(argv[0], 2);
+ usage(argv[0], 4);
encoding = argv[i];
} else
encoding = argv[i] + j + 1;
@@ -990,6 +1009,10 @@ tmain(int argc, XML_Char **argv) {
case T('v'):
showVersion(argv[0]);
return 0;
+ case T('k'):
+ continueOnError = 1;
+ j++;
+ break;
case T('\0'):
if (j > 1) {
i++;
@@ -998,7 +1021,7 @@ tmain(int argc, XML_Char **argv) {
}
/* fall through */
default:
- usage(argv[0], 2);
+ usage(argv[0], 4);
}
}
if (i == argc) {
@@ -1061,7 +1084,14 @@ tmain(int argc, XML_Char **argv) {
userData.fp = tfopen(outName, T("wb"));
if (! userData.fp) {
tperror(outName);
- exit(3);
+ exitCode = 3;
+ if (continueOnError) {
+ free(outName);
+ cleanupUserData(&userData);
+ continue;
+ } else {
+ break;
+ }
}
setvbuf(userData.fp, NULL, _IOFBF, 16384);
#ifdef XML_UNICODE
@@ -1123,8 +1153,12 @@ tmain(int argc, XML_Char **argv) {
}
XML_ParserFree(parser);
if (! result) {
- exit(2);
+ exitCode = 2;
+ cleanupUserData(&userData);
+ if (! continueOnError) {
+ break;
+ }
}
}
- return 0;
+ return exitCode;
}