diff options
| author | B. Watson <urchlay@slackware.uk> | 2025-12-14 17:09:19 -0500 |
|---|---|---|
| committer | B. Watson <urchlay@slackware.uk> | 2025-12-14 17:09:19 -0500 |
| commit | 9a4ed16f3584d84dc867bf8b8deda0d4d4d6ee63 (patch) | |
| tree | 306fc19d0023f924646f11b0864fbe3fa895e5e4 | |
| parent | 8f39b42f8feee7d009918bf3190be97fec4ca0cc (diff) | |
| download | alftools-9a4ed16f3584d84dc867bf8b8deda0d4d4d6ee63.tar.gz | |
alf -vv: Show new tokens as they are created.
| -rw-r--r-- | src/crunch.c | 45 |
1 files changed, 22 insertions, 23 deletions
diff --git a/src/crunch.c b/src/crunch.c index dcf3901..62e7110 100644 --- a/src/crunch.c +++ b/src/crunch.c @@ -45,8 +45,8 @@ int maxkidcount = 0, maxlevel = 0, totalkidcount = 0, nodeswithkids = 0; /* -vv */ char *fmt_chr(u8 c) { static char buf[10]; - if(c > 33 && c < 127) - sprintf(buf, "'%c'", c); + if(c > 32 && c < 127 && c != '$') + sprintf(buf, "%c", c); else sprintf(buf, "$%02x", c); return buf; @@ -62,7 +62,7 @@ void indent(int level) { /* -vv */ void print_tok(short tok, u8 chr) { - printf("#%d/%s\n", tok, fmt_chr(chr)); + printf("#%d: %s\n", tok, fmt_chr(chr)); } /* -vv */ @@ -143,6 +143,23 @@ void inc_output_len(void) { output_buf[output_len] = 0; } +void dump_stored_tok(int tok) { + printf("<%d >%d:%d #%d", in_pos, output_len, out_bitpos, tok); + if(tok == TOK_RESET) + fputs(" RESET", stdout); + else if(tok == TOK_END) + fputs(" END", stdout); + else if(tok < 256) + printf(" %s", fmt_chr(tok)); + + if(in_pos < input_len) { + if(tok != TOK_RESET && tok != TOK_END) + printf("\tnew: #%d", curr_token); + } + + putchar('\n'); +} + #if !defined(APPEND_BIT) && defined ALF_ENDIAN_OK /* This is 25% faster, but it requires knowing the endianness of @@ -150,16 +167,7 @@ void inc_output_len(void) { union { unsigned int ui; u8 bytes[4]; } ui2bytes; void store_token(int tok) { - if(opt_verbose > 1) { - printf("<%d >%d:%d #%d", in_pos, output_len, out_bitpos, tok); - if(tok == TOK_RESET) - fputs(" RESET", stdout); - else if(tok == TOK_END) - fputs(" END", stdout); - else if(tok < 256) - printf(" %s", fmt_chr(tok)); - putchar('\n'); - } + if(opt_verbose > 1) dump_stored_tok(tok); /* align token so, no matter what its size (9 thru 12), its top bit is at bit (23 - out_bitpos) of a 32-bit int. */ @@ -194,16 +202,7 @@ void append_bit(int bit) { void store_token(int tok) { int mask; - if(opt_verbose > 1) { - printf("<%d >%d:%d #%d", in_pos, output_len, out_bitpos, tok); - if(tok == TOK_RESET) - fputs(" RESET", stdout); - else if(tok == TOK_END) - fputs(" END", stdout); - else if(tok < 256) - printf(" %s", fmt_chr(tok)); - putchar('\n'); - } + if(opt_verbose > 1) dump_stored_tok(tok); for(mask = 1 << (token_bits - 1); mask; mask >>= 1) { append_bit(tok & mask ? 1 : 0); |
