minimalistic mode


git-svn-id: https://asn1c.svn.sourceforge.net/svnroot/asn1c/trunk@967 59561ff5-6e30-0410-9f3c-9617f08c8826
diff --git a/asn1c/check-xxber.sh b/asn1c/check-xxber.sh
index 4432412..cb8cdee 100755
--- a/asn1c/check-xxber.sh
+++ b/asn1c/check-xxber.sh
@@ -15,7 +15,7 @@
 </C O="14" T="[UNIVERSAL 16]" A="SEQUENCE" L="8">
 EOM
 
-./enber < $ORIG - | ./unber -p -i 0 - > $TEST 2>&1
+./enber $ORIG | ./unber -p -i 0 - > $TEST 2>&1
 diff $diffArgs $ORIG $TEST >/dev/null 2>&1
 diffExitCode=$?
 
@@ -28,7 +28,7 @@
 echo '</I O="14" T="[UNIVERSAL 0]" TL="2" L="16">' >> $ORIG
 
 # Try trancoding again
-./enber < $ORIG - | ./unber -p -i 0 - > $TEST 2>&1
+./enber $ORIG | ./unber -p -i 0 - > $TEST 2>&1
 
 diff $diffArgs $ORIG $TEST
 diffExitCode=$?
diff --git a/asn1c/unber.1 b/asn1c/unber.1
index 7b718b9..e219df9 100644
--- a/asn1c/unber.1
+++ b/asn1c/unber.1
@@ -12,7 +12,7 @@
 .SH NAME
 unber \- ASN.1 BER Decoder
 .SH SYNOPSIS
-unber [\fB-1\fR] [\fB-i\fRindent] [\fB-p\fR] [\fB\-t\fR\fIdata-string\fR] [\fB-\fR] [\fIinfile\fR...]
+unber [\fB-1\fR] [\fB-i\fRindent] [\fB-m\fR] [\fB-p\fR] [\fB\-t\fR\fIdata-string\fR] [\fB-\fR] [\fIinfile\fR...]
 .SH DESCRIPTION
 unber takes the BER-encoded files and dumps their internal structure as human readable text.
 A single dash represents the standard input.
@@ -28,6 +28,9 @@
 \fB\-i\fR \fIindent\fR
 Use the specified number of spaces for output indentation. Default is 4 spaces.
 .TP
+\fB\-m\fR
+Generate minimum amount of output while still preserving BER encoding information.
+.TP
 \fB\-p\fR
 Do \fInot\fR attempt pretty-printing of known ASN.1 types (OBJECT IDENTIFIER, INTEGER, BOOLEAN, etc). By default, some ASN.1 types are converted into
 the text representation. This option is required for \&\fIenber\fR\|(1).
diff --git a/asn1c/unber.c b/asn1c/unber.c
index 03de104..8758ca5 100644
--- a/asn1c/unber.c
+++ b/asn1c/unber.c
@@ -45,6 +45,7 @@
 static int decode_tlv_from_string(const char *datastring);
 
 static int single_type_decoding = 0;	/* -1 enables that */
+static int minimalistic = 0;		/* -m enables that */
 static int pretty_printing = 1;		/* -p disables that */
 static char *indent_buffer = "    ";	/* -i controls that */
 
@@ -56,7 +57,7 @@
 	/*
 	 * Process command-line options.
 	 */
-	while((ch = getopt(ac, av, "1hi:pt:v")) != -1)
+	while((ch = getopt(ac, av, "1hi:mpt:v")) != -1)
 	switch(ch) {
 	case '1':
 		single_type_decoding = 1;
@@ -65,6 +66,9 @@
 		if(decode_tlv_from_string(optarg))
 			exit(EX_DATAERR);
 		exit(0);
+	case 'm':
+		minimalistic = 1;
+		break;
 	case 'p':
 		pretty_printing = 0;
 		break;
@@ -124,6 +128,7 @@
 "Options:\n"
 "  -1                 Decode only the first BER structure (otherwise, until EOF)\n"
 "  -i <indent>        Amount of spaces for output indentation (default is 4)\n"
+"  -m                 Minimalistic mode: print as little as possible\n"
 "  -p                 Do not attempt pretty-printing of known ASN.1 types\n"
 "  -t <data-string>   Decode the given tag[/length] sequence (e.g. -t \"bf20\")\n"
 "\n"
@@ -363,13 +368,14 @@
 	printf(constr ? ((tlv_len == -1) ? "I" : "C") : "P");
 
 	/* Print out the offset of this boundary, even if closing tag */
-	printf(" O=\"%" PRIdASN "\"", offset);
+	if(!minimalistic)
+		printf(" O=\"%" PRIdASN "\"", offset);
 
 	printf(" T=\"");
 	ber_tlv_tag_fwrite(tlv_tag, stdout);
 	printf("\"");
 
-	if(!fin || tlv_len == -1)
+	if(!fin || (tlv_len == -1 && !minimalistic))
 		printf(" TL=\"%ld\"", (long)tlen);
 	if(!fin) {
 		if(tlv_len == -1)
@@ -378,7 +384,8 @@
 			printf(" V=\"%ld\"", (long)tlv_len);
 	}
 
-	if(BER_TAG_CLASS(tlv_tag) == ASN_TAG_CLASS_UNIVERSAL) {
+	if(!minimalistic
+	&& BER_TAG_CLASS(tlv_tag) == ASN_TAG_CLASS_UNIVERSAL) {
 		const char *str;
 		ber_tlv_tag_t tvalue = BER_TAG_VALUE(tlv_tag);
 		str = ASN_UNIVERSAL_TAG2STR(tvalue);
@@ -386,7 +393,7 @@
 	}
 
 	if(fin) {
-		if(constr)
+		if(constr && !minimalistic)
 			printf(" L=\"%ld\"", (long)effective_size);
 		printf(">\n");
 	}