summaryrefslogtreecommitdiff
path: root/pxl/pxparse.h
blob: b3ec1b8c15e21db97cb8029d6dfd2fc34808d07e (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
/* Portions Copyright (C) 2001 artofcode LLC.
   Portions Copyright (C) 1996, 2001 Artifex Software Inc.
   Portions Copyright (C) 1988, 2000 Aladdin Enterprises.
   This software is based in part on the work of the Independent JPEG Group.
   All Rights Reserved.

   This software is distributed under license and may not be copied, modified
   or distributed except as expressly authorized under the terms of that
   license.  Refer to licensing information at http://www.artifex.com/ or
   contact Artifex Software, Inc., 101 Lucas Valley Road #110,
   San Rafael, CA  94903, (415)492-9861, for further information. */
/*$Id$ */

/* pxparse.h */
/* Definitions and interface for PCL XL parser */
/* Requires gsmemory.h */

#ifndef pxparse_INCLUDED
#  define pxparse_INCLUDED

#include "pxoper.h"

/* ---------------- Definitions ---------------- */

/*
 * Define the minimum parser input buffer size.  The input buffer can
 * contain as much or as little data as the client wishes to supply;
 * the parser will always consume all of it.
 *
 * The minimum input buffer size is determined by the largest minimum size
 * required by the data decompression methods for bitmaps, which is currently
 * 1 byte for the RLE method.  Aside from that, the minimum size demanded
 * by the language itself is the size of the largest fixed-size language
 * token, which is 17 bytes (real32 or int32 box).  However, there is no
 * requirement that the client provide a buffer of this size: the parser
 * will buffer data internally if necessary.
 */
#define px_parser_max_token_size 1024
#define px_parser_min_input_size px_parser_max_token_size

/* Define the parser macro-states (used only for checking). */
#define ptsInSession		0x01
#define ptsInPage		0x02
#define ptsData			0x04	/* read data, want attribute */
#define ptsReadingStream	  0x08
#define ptsReadingRastPattern	  0x10
#define ptsReadingChar		  0x18
#define ptsReadingFont		  0x20
#define ptsReadingImage		  0x28
#define ptsReadingScan		  0x30
#define ptsReading		0x38		/* reading state */
#define ptsExecStream		0x40		/* executing a stream */
#define ptsInitial 0

/* Define the parser state. */
#ifndef px_parser_state_t_DEFINED
#  define px_parser_state_t_DEFINED
typedef struct px_parser_state_s px_parser_state_t;
#endif
#define max_stack max_px_args		/* must not exceed 256 */
struct px_parser_state_s {
	/* Set at initialization */
  gs_memory_t *memory;
  bool big_endian;
	/* Updated dynamically, for error reporting only */
  long operator_count;
  long parent_operator_count;
  int /*px_tag_t*/ last_operator;	/* pxtNull if none */
	/* Updated dynamically */
  int saved_count;		/* amount of leftover input in saved */
  uint data_left;		/* amount left to read of data or array */
  uint macro_state;		/* mask for macro-state */
  int stack_count;
  px_operator_proc((*data_proc));	/* operator awaiting data, if any */
  byte saved[px_parser_max_token_size];
  px_value_t stack[max_stack + 2];
  px_args_t args;
  byte attribute_indices[px_attribute_next];	/* indices of attrs on stack */
};

/* Define an abstract type for the state. */
#ifndef px_state_DEFINED
#  define px_state_DEFINED
typedef struct px_state_s px_state_t;
#endif

/* ---------------- Procedural interface ---------------- */

/* Allocate a parser state. */
px_parser_state_t *px_process_alloc(gs_memory_t *memory);

/* Release a parser state. */
void px_process_release(px_parser_state_t *st);

/* Initialize the parser state. */
void px_process_init(px_parser_state_t *st, bool big_endian);

/* Process a buffer of PCL XL commands. */
int px_process(px_parser_state_t *st, px_state_t *pxs,
		  stream_cursor_read *pr);

/* unfortunately we have to export this for pass through mode, other
   commands do not need to know how much data is left to parse. */
uint px_parser_data_left(px_parser_state_t *pxp);

#endif				/* pxparse_INCLUDED */