pretty-printing
git-svn-id: https://asn1c.svn.sourceforge.net/svnroot/asn1c/trunk@371 59561ff5-6e30-0410-9f3c-9617f08c8826
diff --git a/skeletons/BIT_STRING.c b/skeletons/BIT_STRING.c
index b6da3ae..c3788d8 100644
--- a/skeletons/BIT_STRING.c
+++ b/skeletons/BIT_STRING.c
@@ -78,6 +78,7 @@
char *p = scratch;
char *scend = scratch + (sizeof(scratch) - 10);
const BIT_STRING_t *st = (const BIT_STRING_t *)sptr;
+ int xcan = (flags & XER_F_CANONICAL);
uint8_t *buf;
uint8_t *end;
@@ -94,8 +95,7 @@
*/
for(buf++; buf < end; buf++) {
int v = *buf;
- int nline = (flags & XER_F_CANONICAL)
- ?0:((((buf - st->buf) - 1) % 16) == 0);
+ int nline = xcan?0:((((buf - st->buf) - 1) % 8) == 0);
if(p >= scend || nline) {
er.encoded += p - scratch;
_ASN_CALLBACK(scratch, p - scratch);
@@ -108,7 +108,8 @@
}
er.encoded += p - scratch;
- _ASN_CALLBACK(scratch, p - scratch);
+ if(!xcan && (((buf - st->buf) - 1) % 8) == 0)
+ _i_ASN_TEXT_INDENT(1, ilevel);
if(buf < end + 1) {
int v = *buf;
@@ -120,6 +121,9 @@
_ASN_CALLBACK(scratch, p - scratch);
}
+ if(!xcan && ((st->size - 1) % 8) == 0)
+ _i_ASN_TEXT_INDENT(1, ilevel - 1);
+
return er;
}
@@ -149,7 +153,8 @@
* Hexadecimal dump.
*/
for(buf++; buf < end; buf++) {
- if(((buf - st->buf) - 1) % 16 == 0 && (st->size > 16)) {
+ if(((buf - st->buf) - 1) % 16 == 0 && (st->size > 17)
+ && buf != st->buf+1) {
int i;
/* Indentation */
if(cb("\n", 1, app_key)) return -1;
@@ -162,9 +167,21 @@
*p++ = h2c[*buf & 0x0F];
*p++ = 0x20;
}
- if(p > scratch) p--; /* Eat the tailing space */
- /* Dump the incomplete 16-bytes row */
- return cb(scratch, p - scratch, app_key);
+ if(p > scratch) {
+ p--; /* Eat the tailing space */
+
+ if((st->size > 17)) {
+ int i;
+ if(cb("\n", 1, app_key)) return -1;
+ for(i = 0; i < ilevel; i++) cb(" ", 1, app_key);
+ }
+
+ /* Dump the incomplete 16-bytes row */
+ if(cb(scratch, p - scratch, app_key))
+ return -1;
+ }
+
+ return 0;
}