Skip to content

Commit

Permalink
Remove the odd/even page stuff, which was of almost no utlity.
Browse files Browse the repository at this point in the history
  • Loading branch information
brouhaha committed Jun 7, 2022
1 parent 0fa4379 commit d4a9738
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 88 deletions.
16 changes: 0 additions & 16 deletions parser.y
Original file line number Diff line number Diff line change
Expand Up @@ -59,10 +59,6 @@
%token CM
%token INCH

%token EVEN
%token ODD
%token ALL

%token PORTRAIT
%token LANDSCAPE

Expand Down Expand Up @@ -203,25 +199,13 @@ modifier_clauses:
modifier_clause
| modifier_clauses modifier_clause ;

modifier_clause_list:
'{' modifier_clauses '}' ;

part_clause:
ODD { input_set_modifier_context (INPUT_MODIFIER_ODD); }
modifier_clause_list
{ input_set_modifier_context (INPUT_MODIFIER_ALL); }
| EVEN { input_set_modifier_context (INPUT_MODIFIER_EVEN); }
modifier_clause_list
{ input_set_modifier_context (INPUT_MODIFIER_ALL); } ;

blank_page_clause:
BLANK { input_set_file (NULL); } size_clause;

input_clause:
input_file_clause ';'
| image_clause ';'
| images_clause ';'
| part_clause ';'
| modifier_clauses ';'
| blank_page_clause ';'
| input_clause_list ;
Expand Down
3 changes: 0 additions & 3 deletions scanner.l
Original file line number Diff line number Diff line change
Expand Up @@ -78,15 +78,13 @@ e { yylval.size.width = 34.0;
yylval.size.height = 44.0;
return PAGE_SIZE; }

all { return ALL; }
author { return AUTHOR; }
blank { return BLANK; }
bookmark { return BOOKMARK; }
cm { return CM; }
colormap { return COLORMAP; }
creator { return CREATOR; }
crop { return CROP; }
even { return EVEN; }
file { return FILE_KEYWORD; }
imagemask { return IMAGEMASK; }
image { return IMAGE; }
Expand All @@ -96,7 +94,6 @@ input { return INPUT; }
keywords { return KEYWORDS; }
label { return LABEL; }
landscape { return LANDSCAPE; }
odd { return ODD; }
output { return OUTPUT; }
overlay { return OVERLAY; }
page { return PAGE; }
Expand Down
75 changes: 16 additions & 59 deletions semantics.c
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ typedef struct input_context_t
char *input_file;
bool is_blank;

input_modifiers_t modifiers [INPUT_MODIFIER_TYPE_COUNT];
input_modifiers_t modifiers;
} input_context_t;


Expand Down Expand Up @@ -127,8 +127,6 @@ int bookmark_level;
input_context_t *first_input_context;
input_context_t *last_input_context;

input_modifier_type_t current_modifier_context = INPUT_MODIFIER_ALL;

input_image_t *first_input_image;
input_image_t *last_input_image;

Expand Down Expand Up @@ -176,22 +174,6 @@ void input_pop_context (void)
last_input_context = last_input_context->parent;
};

void input_set_modifier_context (input_modifier_type_t type)
{
current_modifier_context = type;
#ifdef SEMANTIC_DEBUG
SDBG(("modifier type "));
switch (type)
{
case INPUT_MODIFIER_ALL: SDBG(("all")); break;
case INPUT_MODIFIER_ODD: SDBG(("odd")); break;
case INPUT_MODIFIER_EVEN: SDBG(("even")); break;
default: SDBG(("unknown %d", type));
}
SDBG(("\n"));
#endif /* SEMANTIC_DEBUG */
}

static void input_clone (void)
{
input_context_t *new_input_context;
Expand Down Expand Up @@ -221,22 +203,22 @@ void input_set_file (char *name)

void input_set_rotation (int rotation)
{
last_input_context->modifiers [current_modifier_context].has_rotation = 1;
last_input_context->modifiers [current_modifier_context].rotation = rotation;
last_input_context->modifiers.has_rotation = 1;
last_input_context->modifiers.rotation = rotation;
SDBG(("rotation %d\n", rotation));
}

void input_set_page_size (page_size_t size)
{
last_input_context->modifiers [current_modifier_context].has_page_size = 1;
last_input_context->modifiers [current_modifier_context].page_size = size;
last_input_context->modifiers.has_page_size = 1;
last_input_context->modifiers.page_size = size;
SDBG(("page size %f, %f\n", size.width, size.height));
}

void input_set_transparency (rgb_range_t rgb_range)
{
last_input_context->modifiers [current_modifier_context].has_transparency = 1;
last_input_context->modifiers [current_modifier_context].transparency = rgb_range;
last_input_context->modifiers.has_transparency = 1;
last_input_context->modifiers.transparency = rgb_range;
}

static void increment_input_image_count (int count)
Expand Down Expand Up @@ -502,56 +484,39 @@ static char *get_input_filename (input_context_t *context)
}

static bool get_input_rotation (input_context_t *context,
input_modifier_type_t type,
int *rotation)
{
for (; context; context = context->parent)
{
if (context->modifiers [type].has_rotation)
if (context->modifiers.has_rotation)
{
* rotation = context->modifiers [type].rotation;
return true;
}
if (context->modifiers [INPUT_MODIFIER_ALL].has_rotation)
{
* rotation = context->modifiers [INPUT_MODIFIER_ALL].rotation;
* rotation = context->modifiers.rotation;
return true;
}
}
return false; /* default */
}

static rgb_range_t *get_input_transparency (input_context_t *context,
input_modifier_type_t type)
static rgb_range_t *get_input_transparency (input_context_t *context)
{
for (; context; context = context->parent)
{
if (context->modifiers [type].has_transparency)
{
return & (context->modifiers [type].transparency);
}
if (context->modifiers [INPUT_MODIFIER_ALL].has_transparency)
if (context->modifiers.has_transparency)
{
return & (context->modifiers [INPUT_MODIFIER_ALL].transparency);
return & (context->modifiers.transparency);
}
}
return NULL; /* default */
}

static bool get_input_page_size (input_context_t *context,
input_modifier_type_t type,
page_size_t *page_size)
{
for (; context; context = context->parent)
{
if (context->modifiers [type].has_page_size)
if (context->modifiers.has_page_size)
{
* page_size = context->modifiers [type].page_size;
return true;
}
if (context->modifiers [INPUT_MODIFIER_ALL].has_page_size)
{
* page_size = context->modifiers [INPUT_MODIFIER_ALL].page_size;
* page_size = context->modifiers.page_size;
return true;
}
}
Expand Down Expand Up @@ -604,19 +569,16 @@ void dump_input_tree (void)
for (image = first_input_image; image; image = image->next)
for (i = image->range.first; i <= image->range.last; i++)
{
input_modifier_type_t parity = (i % 2) ? INPUT_MODIFIER_ODD : INPUT_MODIFIER_EVEN;
bool has_rotation, has_page_size;
int rotation;
page_size_t page_size;
rgb_range_t *transparency;

has_rotation = get_input_rotation (image->input_context,
parity,
& rotation);
has_page_size = get_input_page_size (image->input_context,
parity,
& page_size);
transparency = get_input_transparency (image->input_context, parity);
transparency = get_input_transparency (image->input_context);
fn = get_input_filename (image->input_context);
if (fn)
printf ("file '%s' image %d", fn, i);
Expand Down Expand Up @@ -752,7 +714,6 @@ bool process_controls (void)
int p = 0;
int page_index = 0;
input_attributes_t input_attributes;
input_modifier_type_t parity;
page_label_t *page_label;
output_attributes_t output_attributes;

Expand Down Expand Up @@ -802,20 +763,16 @@ bool process_controls (void)
}
}

parity = ((image->range.first + i) % 2) ? INPUT_MODIFIER_ODD : INPUT_MODIFIER_EVEN;

memset (& input_attributes, 0, sizeof (input_attributes));

input_attributes.rotation = 0;
input_attributes.has_rotation = get_input_rotation (image->input_context,
parity,
& input_attributes.rotation);

input_attributes.has_page_size = get_input_page_size (image->input_context,
parity,
& input_attributes.page_size);

input_attributes.transparency = get_input_transparency (image->input_context, parity);
input_attributes.transparency = get_input_transparency (image->input_context);

memset (& output_attributes, 0, sizeof (output_attributes));
output_attributes.colormap = get_output_colormap (page->output_context);
Expand Down
10 changes: 0 additions & 10 deletions semantics.h
Original file line number Diff line number Diff line change
Expand Up @@ -96,15 +96,6 @@ typedef struct
int count;
} page_label_t;

typedef enum
{
INPUT_MODIFIER_ALL,
INPUT_MODIFIER_ODD,
INPUT_MODIFIER_EVEN,
INPUT_MODIFIER_TYPE_COUNT /* must be last */
} input_modifier_type_t;


typedef struct bookmark_t
{
struct bookmark_t *next;
Expand All @@ -124,7 +115,6 @@ void yyerror (const char *s);
/* semantic routines for input statements */
void input_push_context (void);
void input_pop_context (void);
void input_set_modifier_context (input_modifier_type_t type);
void input_set_file (char *name);
void input_set_rotation (int rotation);
void input_set_transparency (rgb_range_t rgb_range);
Expand Down

0 comments on commit d4a9738

Please sign in to comment.