Merge pull request #463 from libexpat/small-xmlwf-refactoring
Small xmlwf refactoring
This commit is contained in:
commit
10d3429621
@ -50,6 +50,14 @@
|
||||
# include <wchar.h>
|
||||
#endif
|
||||
|
||||
enum ExitCode {
|
||||
XMLWF_EXIT_SUCCESS = 0,
|
||||
XMLWF_EXIT_INTERNAL_ERROR = 1,
|
||||
XMLWF_EXIT_NOT_WELLFORMED = 2,
|
||||
XMLWF_EXIT_OUTPUT_ERROR = 3,
|
||||
XMLWF_EXIT_USAGE_ERROR = 4,
|
||||
};
|
||||
|
||||
/* Structures for handler user data */
|
||||
typedef struct NotationList {
|
||||
struct NotationList *next;
|
||||
@ -908,6 +916,19 @@ usage(const XML_Char *prog, int rc) {
|
||||
int wmain(int argc, XML_Char **argv);
|
||||
#endif
|
||||
|
||||
#define XMLWF_SHIFT_ARG_INTO(constCharStarTarget, argc, argv, i, j) \
|
||||
{ \
|
||||
if (argv[i][j + 1] == T('\0')) { \
|
||||
if (++i == argc) \
|
||||
usage(argv[0], XMLWF_EXIT_USAGE_ERROR); \
|
||||
constCharStarTarget = argv[i]; \
|
||||
} else { \
|
||||
constCharStarTarget = argv[i] + j + 1; \
|
||||
} \
|
||||
i++; \
|
||||
j = 0; \
|
||||
}
|
||||
|
||||
int
|
||||
tmain(int argc, XML_Char **argv) {
|
||||
int i, j;
|
||||
@ -920,7 +941,7 @@ tmain(int argc, XML_Char **argv) {
|
||||
int requireStandalone = 0;
|
||||
int requiresNotations = 0;
|
||||
int continueOnError = 0;
|
||||
int exitCode = 0;
|
||||
int exitCode = XMLWF_EXIT_SUCCESS;
|
||||
enum XML_ParamEntityParsing paramEntityParsing
|
||||
= XML_PARAM_ENTITY_PARSING_NEVER;
|
||||
int useStdin = 0;
|
||||
@ -984,27 +1005,13 @@ tmain(int argc, XML_Char **argv) {
|
||||
j++;
|
||||
break;
|
||||
case T('d'):
|
||||
if (argv[i][j + 1] == T('\0')) {
|
||||
if (++i == argc)
|
||||
usage(argv[0], 4);
|
||||
outputDir = argv[i];
|
||||
} else
|
||||
outputDir = argv[i] + j + 1;
|
||||
i++;
|
||||
j = 0;
|
||||
XMLWF_SHIFT_ARG_INTO(outputDir, argc, argv, i, j);
|
||||
break;
|
||||
case T('e'):
|
||||
if (argv[i][j + 1] == T('\0')) {
|
||||
if (++i == argc)
|
||||
usage(argv[0], 4);
|
||||
encoding = argv[i];
|
||||
} else
|
||||
encoding = argv[i] + j + 1;
|
||||
i++;
|
||||
j = 0;
|
||||
XMLWF_SHIFT_ARG_INTO(encoding, argc, argv, i, j);
|
||||
break;
|
||||
case T('h'):
|
||||
usage(argv[0], 0);
|
||||
usage(argv[0], XMLWF_EXIT_SUCCESS);
|
||||
return 0;
|
||||
case T('v'):
|
||||
showVersion(argv[0]);
|
||||
@ -1021,7 +1028,7 @@ tmain(int argc, XML_Char **argv) {
|
||||
}
|
||||
/* fall through */
|
||||
default:
|
||||
usage(argv[0], 4);
|
||||
usage(argv[0], XMLWF_EXIT_USAGE_ERROR);
|
||||
}
|
||||
}
|
||||
if (i == argc) {
|
||||
@ -1040,7 +1047,7 @@ tmain(int argc, XML_Char **argv) {
|
||||
|
||||
if (! parser) {
|
||||
tperror(T("Could not instantiate parser"));
|
||||
exit(1);
|
||||
exit(XMLWF_EXIT_INTERNAL_ERROR);
|
||||
}
|
||||
|
||||
if (requireStandalone)
|
||||
@ -1076,7 +1083,7 @@ tmain(int argc, XML_Char **argv) {
|
||||
* sizeof(XML_Char));
|
||||
if (! outName) {
|
||||
tperror(T("Could not allocate memory"));
|
||||
exit(1);
|
||||
exit(XMLWF_EXIT_INTERNAL_ERROR);
|
||||
}
|
||||
tcscpy(outName, outputDir);
|
||||
tcscat(outName, delim);
|
||||
@ -1084,7 +1091,7 @@ tmain(int argc, XML_Char **argv) {
|
||||
userData.fp = tfopen(outName, T("wb"));
|
||||
if (! userData.fp) {
|
||||
tperror(outName);
|
||||
exitCode = 3;
|
||||
exitCode = XMLWF_EXIT_OUTPUT_ERROR;
|
||||
if (continueOnError) {
|
||||
free(outName);
|
||||
cleanupUserData(&userData);
|
||||
@ -1153,7 +1160,7 @@ tmain(int argc, XML_Char **argv) {
|
||||
}
|
||||
XML_ParserFree(parser);
|
||||
if (! result) {
|
||||
exitCode = 2;
|
||||
exitCode = XMLWF_EXIT_NOT_WELLFORMED;
|
||||
cleanupUserData(&userData);
|
||||
if (! continueOnError) {
|
||||
break;
|
||||
|
Loading…
Reference in New Issue
Block a user