Skip to content

Commit

Permalink
*** empty log message ***
Browse files Browse the repository at this point in the history
  • Loading branch information
brouhaha committed Dec 30, 2001
1 parent dbc4896 commit 83f20f0
Show file tree
Hide file tree
Showing 6 changed files with 117 additions and 16 deletions.
4 changes: 2 additions & 2 deletions parser.y
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@
int integer;
double fp;
char *string;
struct { double width; double height; } size;
struct { int first; int last; } range;
page_size_t size;
range_t range;
}

%token <integer> INTEGER
Expand Down
4 changes: 2 additions & 2 deletions scanner.l
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
$Id: scanner.l,v 1.9 2001/12/30 08:29:50 eric Exp $
$Id: scanner.l,v 1.10 2001/12/30 09:09:08 eric Exp $
*/

%option case-insensitive
Expand All @@ -8,9 +8,9 @@ $Id: scanner.l,v 1.9 2001/12/30 08:29:50 eric Exp $
%{
#include <stdio.h>
#include <string.h>
#include "parser.tab.h"
#include "type.h"
#include "semantics.h"
#include "parser.tab.h"

#ifdef SCANNER_DEBUG
#define LDBG(x) printf x
Expand Down
60 changes: 54 additions & 6 deletions semantics.c
Original file line number Diff line number Diff line change
@@ -1,24 +1,55 @@
#include <stdlib.h>
#include <string.h>
#include <stdio.h>

#include "type.h"
#include "parser.tab.h"
#include "semantics.h"
#include "parser.tab.h"


FILE *yyin;
int line; /* line number in spec file */


int input_count; /* total input pages in spec */
int output_count; /* total output pages in spec */
int input_page_count; /* total input pages in spec */
int output_page_count; /* total output pages in spec */


input_context_t *current_input_context;


void input_push_context (input_context_type_t type)
{
input_context_t *new_input_context;

new_input_context = malloc (sizeof (input_context_t));
if (! new_input_context)
{
fprintf (stderr, "failed to calloc an input context\n");
return;
}

if (current_input_context)
{
memcpy (new_input_context, current_input_context, sizeof (input_context_t));
new_input_context->page_count = 0;
}
else
memset (new_input_context, 0, sizeof (input_context_t));

new_input_context->parent_input_context = current_input_context;
current_input_context = new_input_context;
};

void input_pop_context (void)
{
if (! current_input_context)
{
fprintf (stderr, "failed to pop an input context\n");
return;
}

current_input_context = current_input_context->parent_input_context;
};

void input_set_file (char *name)
Expand All @@ -27,20 +58,25 @@ void input_set_file (char *name)

void input_images (int first, int last)
{
input_count += ((last - first) + 1);
input_page_count += ((last - first) + 1);
if (first == last)
printf ("image %d\n", first);
else
printf ("iamges %d..%d\n", first, last);
printf ("images %d..%d\n", first, last);
}


void output_push_context (void)
{
};

void output_set_file (char *name)
{
};

void output_pages (int first, int last)
{
output_count += ((last - first) + 1);
output_page_count += ((last - first) + 1);
if (first == last)
printf ("page %d\n", first);
else
Expand All @@ -67,8 +103,20 @@ boolean parse_spec_file (char *fn)

line = 1;

input_push_context (INPUT_CONTEXT_ALL); /* create initial input context */
output_push_context (); /* create initial output context */

yyparse ();

if (input_page_count != output_page_count)
{
fprintf (stderr, "input page count %d != output page count %d\n",
input_page_count, output_page_count);
goto fail;
}

fprintf (stderr, "%d pages specified\n", input_page_count);

result = 1;

fail:
Expand Down
57 changes: 55 additions & 2 deletions semantics.h
Original file line number Diff line number Diff line change
@@ -1,3 +1,23 @@
typedef struct
{
double width;
double height;
} page_size_t;

typedef struct
{
int first;
int last;
} range_t;

typedef struct
{
double left;
double right;
double top;
double bottom;
} crop_t;

typedef enum
{
INPUT_CONTEXT_ALL,
Expand All @@ -6,11 +26,44 @@ typedef enum
} input_context_type_t;


typedef struct
{
boolean has_size;
page_size_t size;

boolean has_rotation;
int rotation;

boolean has_crop;
crop_t crop;
} input_modifiers_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 input_context_t
{
struct input_context_t *parent_input_context;

int page_count; /* how many pages reference this context,
including those from subcontexts */

input_modifiers_t modifiers [INPUT_MODIFIER_TYPE_COUNT];
} input_context_t;


extern int line; /* line number in spec file */


extern int input_count; /* total input pages in spec */
extern int output_count; /* total output pages in spec */
extern int input_page_count; /* total input pages in spec */
extern int output_page_count; /* total output pages in spec */


boolean parse_spec_file (char *fn);
Expand Down
4 changes: 2 additions & 2 deletions t2p.c
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
/*
* tiffg4: reencode a bilevel TIFF file as a single-strip TIFF Class F Group 4
* Main program
* $Id: t2p.c,v 1.4 2001/12/30 08:29:50 eric Exp $
* $Id: t2p.c,v 1.5 2001/12/30 09:09:08 eric Exp $
* Copyright 2001 Eric Smith <[email protected]>
*
* This program is free software; you can redistribute it and/or modify
Expand All @@ -28,8 +28,8 @@

#include "type.h"
#include "bitblt.h"
#include "parser.tab.h"
#include "semantics.h"
#include "parser.tab.h"
#include "tiff2pdf.h"


Expand Down
4 changes: 2 additions & 2 deletions tumble.c
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
/*
* tiffg4: reencode a bilevel TIFF file as a single-strip TIFF Class F Group 4
* Main program
* $Id: tumble.c,v 1.4 2001/12/30 08:29:50 eric Exp $
* $Id: tumble.c,v 1.5 2001/12/30 09:09:08 eric Exp $
* Copyright 2001 Eric Smith <[email protected]>
*
* This program is free software; you can redistribute it and/or modify
Expand All @@ -28,8 +28,8 @@

#include "type.h"
#include "bitblt.h"
#include "parser.tab.h"
#include "semantics.h"
#include "parser.tab.h"
#include "tiff2pdf.h"


Expand Down

0 comments on commit 83f20f0

Please sign in to comment.