From 06ceedbf2fe163aa510a6aee0bcf92968a3133cf Mon Sep 17 00:00:00 2001 From: "Sven M. Hallberg" <pesco@khjk.org> Date: Mon, 19 Dec 2022 23:10:10 +0000 Subject: [PATCH] define LZW_clear and LZW_eod in terms of 'codeword' The only difference between the codeword and the litspec rules was that the latter validated that code < 258. This has become redundant because they were only still used for eod and clear both of which have their own specific validation for the code value. Thus the litspec rules and their validations can go. --- lzw.c | 49 ++----------------------------------------------- 1 file changed, 2 insertions(+), 47 deletions(-) diff --git a/lzw.c b/lzw.c index 34c4280..1bab004 100644 --- a/lzw.c +++ b/lzw.c @@ -112,46 +112,6 @@ validate_LZW_12bitcodeword(HParseResult *p, void *u) return (ctx->next >= BITLIMIT_11 && ctx->next < BITLIMIT_12); } -bool -validate_LZW_9bitlitspec(HParseResult *p, void *u) -{ - LZW_context_T * ctx = (LZW_context_T *) u; - //fprintf(debug, "9 bit lit: %lu, next: %u\n", p->ast->uint, ctx->next); // DEBUG - //fflush(debug); // DEBUG - uint64_t code = H_CAST_UINT(p->ast); - return (ctx->next < BITLIMIT_9 && code < 258); -} - -bool -validate_LZW_10bitlitspec(HParseResult *p, void *u) -{ - LZW_context_T * ctx = (LZW_context_T *) u; - //fprintf(debug, "10 bit lit: %lu, next: %u\n", p->ast->uint, ctx->next); // DEBUG - //fflush(debug); // DEBUG - uint64_t code = H_CAST_UINT(p->ast); - return (ctx->next >= BITLIMIT_9 && ctx->next < BITLIMIT_10 && code < 258); -} - -bool -validate_LZW_11bitlitspec(HParseResult *p, void *u) -{ - LZW_context_T * ctx = (LZW_context_T *) u; - //fprintf(debug, "11 bit lit: %lu, next: %u\n", p->ast->uint, ctx->next); // DEBUG - //fflush(debug); // DEBUG - uint64_t code = H_CAST_UINT(p->ast); - return (ctx->next >= BITLIMIT_10 && ctx->next < BITLIMIT_11 && code < 258); -} - -bool -validate_LZW_12bitlitspec(HParseResult *p, void *u) -{ - LZW_context_T * ctx = (LZW_context_T *) u; - //fprintf(debug, "12 bit lit: %lu, next: %u\n", p->ast->uint, ctx->next); // DEBUG - //fflush(debug); // DEBUG - uint64_t code = H_CAST_UINT(p->ast); - return (ctx->next >= BITLIMIT_11 && ctx->next < BITLIMIT_12 && code < 258); -} - bool validate_LZW_clear(HParseResult *p, void *u) { @@ -320,13 +280,8 @@ void init_LZW_parser() H_RULE (codeword, h_choice(LZW_9bitcodeword, LZW_10bitcodeword, LZW_11bitcodeword, LZW_12bitcodeword, NULL)); - H_VDRULE(LZW_9bitlitspec, h_bits(9, false), context); - H_VDRULE(LZW_10bitlitspec, h_bits(10, false), context); - H_VDRULE(LZW_11bitlitspec, h_bits(11, false), context); - H_VDRULE(LZW_12bitlitspec, h_bits(12, false), context); - - H_AVDRULE(LZW_clear, h_choice(LZW_9bitlitspec, LZW_10bitlitspec, LZW_11bitlitspec, LZW_12bitlitspec, NULL), context); - H_VDRULE(LZW_eod, h_choice(LZW_9bitlitspec, LZW_10bitlitspec, LZW_11bitlitspec, LZW_12bitlitspec, NULL), context); + H_AVDRULE(LZW_clear, codeword, context); + H_VDRULE (LZW_eod, codeword, context); H_AVDRULE(LZW_output, codeword, context); H_ADRULE(LZW_body, h_many(h_choice(LZW_clear, LZW_output, NULL)), context); -- GitLab