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