reorganizing output method
git-svn-id: https://asn1c.svn.sourceforge.net/svnroot/asn1c/trunk@878 59561ff5-6e30-0410-9f3c-9617f08c8826
diff --git a/skeletons/asn-decoder-template.c b/skeletons/asn-decoder-template.c
index 76559d1..4a53bc9 100644
--- a/skeletons/asn-decoder-template.c
+++ b/skeletons/asn-decoder-template.c
@@ -30,7 +30,11 @@
static int opt_check; /* -c */
static int opt_print; /* -p */
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 { \
if(!opt_debug) break; \
@@ -76,8 +80,7 @@
}
break;
case 'p':
- opt_toxml = 0; /* Override '-x' */
- opt_print++;
+ opt_ometh = OUT_PRINT;
break;
case 's':
opt_stack = atoi(optarg);
@@ -89,8 +92,7 @@
}
break;
case 'x':
- opt_print = 0; /* Override '-p' */
- opt_toxml++;
+ opt_ometh = OUT_XML;
break;
case 'h':
default:
@@ -121,7 +123,7 @@
}
#ifdef ASN_DECODER_DEFAULT_OUTPUT_XML
- if(!opt_print) opt_toxml++;
+ if(opt_ometh == OUT_NONE) opt_ometh = OUT_XML;
#endif
setvbuf(stdout, 0, _IOLBF, 0);
@@ -145,14 +147,20 @@
exit(EX_DATAERR);
}
- fprintf(stderr, "%s: decoded successfully\n", fname);
-
- if(opt_print) asn_fprint(stdout, pduType, structure);
-
- if(opt_toxml
- && xer_fprint(stdout, pduType, structure)) {
- fprintf(stderr, "%s: Cannot convert into XML\n", fname);
- exit(EX_UNAVAILABLE);
+ switch(opt_ometh) {
+ case OUT_NONE:
+ fprintf(stderr, "%s: decoded successfully\n", fname);
+ break;
+ case OUT_PRINT: /* -p */
+ asn_fprint(stdout, pduType, structure);
+ break;
+ 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 */