1 /******************************************************************************
2   File:     $Id: pclscan.h,v 1.6 2000-10-22 11:05:34+02 Martin Rel $
3   Contents: Header for PCL scanner
4   Author:   Martin Lottermoser, Greifswaldstrasse 28, 38124 Braunschweig,
5             Germany, e-mail: Martin.Lottermoser@t-online.de
6 
7 *******************************************************************************
8 *									      *
9 *	Copyright (C) 1999, 2000 by Martin Lottermoser			      *
10 *	All rights reserved						      *
11 *									      *
12 ******************************************************************************/
13 
14 #ifndef _pclscan_h	/* Inclusion protection */
15 #define _pclscan_h
16 
17 /*****************************************************************************/
18 
19 /* Standard headers */
20 #include <stdio.h>
21 
22 /*****************************************************************************/
23 
24 /* Macro to convert a termination character into a parameter character.
25    It should only be applied to arguments in the range 64-94.
26  */
27 #define pcl_to_parameter_character(c)	((c) + ('a' - 'A'))
28 
29 /*****************************************************************************/
30 
31 #ifndef _pcl_Octet_defined
32 #define _pcl_Octet_defined
33 typedef unsigned char pcl_Octet;
34 #endif
35 
36 typedef struct {
37   unsigned short kind;
38    /* The value can be in the range 1-6:
39       1:  control code. chars[0] is this code and 'i' gives the number of its
40           occurrences (positive).
41       2:  two-character escape sequence. chars[0] is the second character, the
42           first was ESC.
43       3:  parameterized escape sequence. chars[0] is the parameterized
44           character, chars[1] is the group character, and chars[2] is the
45           termination character.
46       4:  same as 3, except that the sequence is not terminated. In this case
47           chars[2] is the octet which would be used as the termination
48           character, not the octet actually read from the input stream
49           (parameter character). pcl_to_parameter_character() can be used to
50           obtain the latter.
51       5:  same as 3, except that this is a part of a combined escape sequence
52           started earlier.
53       6:  same as 4, except that this is a part of a combined escape sequence
54           started earlier.
55     */
56   pcl_Octet chars[3];
57   pcl_Octet prefix;
58    /* This can be one of:
59       '\0': no value given
60       ' ':  value given without a sign
61       '+':  value given with prefix "+"
62       '-':  value given with prefix "-"
63     */
64   int i;	/* integer part of the value (including the sign) */
65   unsigned int scale;
66     /*  This can be zero or any power of ten. A value of zero means that the
67         value was given without a decimal point, a value of one that there were
68         no digits after the point. */
69   int fraction;
70    /* fractional part of the value (including the sign). The entire value is
71       i + ((float)fraction)/scale, provided 'scale' is non-zero. */
72 } pcl_Command;
73 
74 /*
75   A negative return code indicates an error which will terminate scanning.
76   A return code of zero indicates success.
77   A positive return code indicates that the interpreter or handler does not know
78   the command or the data and that the scanner should handle the case. */
79 typedef int (*pcl_CommandInterpreter)(FILE *in, const pcl_Command *cmd,
80   void *idata);
81 typedef int (*pcl_UnknownDataHandler)(FILE *in, void *hdata);
82 /*  A handler for unknown data should never read over an ESC character which
83     might start a printer command. */
84 
85 extern int pcl_is_control_code(int c);
86 extern int pcl_scan(FILE *in, pcl_CommandInterpreter interpreter, void *idata,
87   pcl_UnknownDataHandler handler, void *hdata);
88 
89 /*****************************************************************************/
90 
91 #endif	/* Inclusion protection */
92