Commit 7bee1282 authored by Lev Walkin's avatar Lev Walkin

reorganizing output method

parent 1e1cf7cb
...@@ -30,7 +30,11 @@ static void *data_decode_from_file(asn_TYPE_descriptor_t *asnTypeOfPDU, ...@@ -30,7 +30,11 @@ static void *data_decode_from_file(asn_TYPE_descriptor_t *asnTypeOfPDU,
static int opt_check; /* -c */ static int opt_check; /* -c */
static int opt_print; /* -p */ static int opt_print; /* -p */
static int opt_stack; /* -s */ static int opt_stack; /* -s */
static int opt_toxml; /* -x */ static enum output_method {
OUT_NONE, /* No pretty-printing */
OUT_PRINT, /* -p flag */
OUT_XML, /* -x flag */
} opt_ometh; /* -p or -x */
#define DEBUG(fmt, args...) do { \ #define DEBUG(fmt, args...) do { \
if(!opt_debug) break; \ if(!opt_debug) break; \
...@@ -76,8 +80,7 @@ main(int ac, char **av) { ...@@ -76,8 +80,7 @@ main(int ac, char **av) {
} }
break; break;
case 'p': case 'p':
opt_toxml = 0; /* Override '-x' */ opt_ometh = OUT_PRINT;
opt_print++;
break; break;
case 's': case 's':
opt_stack = atoi(optarg); opt_stack = atoi(optarg);
...@@ -89,8 +92,7 @@ main(int ac, char **av) { ...@@ -89,8 +92,7 @@ main(int ac, char **av) {
} }
break; break;
case 'x': case 'x':
opt_print = 0; /* Override '-p' */ opt_ometh = OUT_XML;
opt_toxml++;
break; break;
case 'h': case 'h':
default: default:
...@@ -121,7 +123,7 @@ main(int ac, char **av) { ...@@ -121,7 +123,7 @@ main(int ac, char **av) {
} }
#ifdef ASN_DECODER_DEFAULT_OUTPUT_XML #ifdef ASN_DECODER_DEFAULT_OUTPUT_XML
if(!opt_print) opt_toxml++; if(opt_ometh == OUT_NONE) opt_ometh = OUT_XML;
#endif #endif
setvbuf(stdout, 0, _IOLBF, 0); setvbuf(stdout, 0, _IOLBF, 0);
...@@ -145,14 +147,20 @@ main(int ac, char **av) { ...@@ -145,14 +147,20 @@ main(int ac, char **av) {
exit(EX_DATAERR); exit(EX_DATAERR);
} }
fprintf(stderr, "%s: decoded successfully\n", fname); switch(opt_ometh) {
case OUT_NONE:
if(opt_print) asn_fprint(stdout, pduType, structure); fprintf(stderr, "%s: decoded successfully\n", fname);
break;
if(opt_toxml case OUT_PRINT: /* -p */
&& xer_fprint(stdout, pduType, structure)) { asn_fprint(stdout, pduType, structure);
fprintf(stderr, "%s: Cannot convert into XML\n", fname); break;
exit(EX_UNAVAILABLE); case OUT_XML: /* -x */
if(xer_fprint(stdout, pduType, structure)) {
fprintf(stderr, "%s: Cannot convert into XML\n",
fname);
exit(EX_UNAVAILABLE);
}
break;
} }
/* Check ASN.1 constraints */ /* Check ASN.1 constraints */
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment