Skip to content
Snippets Groups Projects
Commit 06ceedbf authored by Sven M. Hallberg's avatar Sven M. Hallberg
Browse files

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.
parent 9a9b18b4
No related branches found
No related tags found
1 merge request!36LZW rework
...@@ -112,46 +112,6 @@ validate_LZW_12bitcodeword(HParseResult *p, void *u) ...@@ -112,46 +112,6 @@ validate_LZW_12bitcodeword(HParseResult *p, void *u)
return (ctx->next >= BITLIMIT_11 && ctx->next < BITLIMIT_12); 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 bool
validate_LZW_clear(HParseResult *p, void *u) validate_LZW_clear(HParseResult *p, void *u)
{ {
...@@ -320,13 +280,8 @@ void init_LZW_parser() ...@@ -320,13 +280,8 @@ void init_LZW_parser()
H_RULE (codeword, h_choice(LZW_9bitcodeword, LZW_10bitcodeword, H_RULE (codeword, h_choice(LZW_9bitcodeword, LZW_10bitcodeword,
LZW_11bitcodeword, LZW_12bitcodeword, NULL)); LZW_11bitcodeword, LZW_12bitcodeword, NULL));
H_VDRULE(LZW_9bitlitspec, h_bits(9, false), context); H_AVDRULE(LZW_clear, codeword, context);
H_VDRULE(LZW_10bitlitspec, h_bits(10, false), context); H_VDRULE (LZW_eod, codeword, 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_output, codeword, context); H_AVDRULE(LZW_output, codeword, context);
H_ADRULE(LZW_body, h_many(h_choice(LZW_clear, LZW_output, NULL)), context); H_ADRULE(LZW_body, h_many(h_choice(LZW_clear, LZW_output, NULL)), context);
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment