1 /* COPYRIGHT (C) 1990, 1992 Aladdin Enterprises.  All rights reserved.
2    Distributed by Free Software Foundation, Inc.
3 
4    This file is part of Ghostscript.
5 
6    Ghostscript is distributed in the hope that it will be useful, but
7    WITHOUT ANY WARRANTY.  No author or distributor accepts responsibility
8    to anyone for the consequences of using it or for whether it serves any
9    particular purpose or works at all, unless he says so in writing.  Refer
10    to the Ghostscript General Public License for full details.
11 
12    Everyone is granted permission to copy, modify and redistribute
13    Ghostscript, but only under the conditions described in the Ghostscript
14    General Public License.  A copy of this license is supposed to have been
15    given to you along with Ghostscript so you can know your rights and
16    responsibilities.  It should be in a file named COPYING.  Among other
17    things, the copyright notice and this notice must be preserved on all
18    copies.  */
19 
20 /* dviprlib.h */
21 
22 /* $Id: S_CFGBLD.H 1.1 1994/08/30 02:27:18 kaz Exp kaz $ */
23 
24 #ifndef s_cfgbld_h_INCLUDED
25 
26 
27 /* $Id: S_CFG.H 1.1 1994/08/30 02:27:18 kaz Exp kaz $ */
28 
29 #ifndef s_cfg_h_INCLUDED
30 #define CFG_MAGIC_NUMBER   ":K"
31 #define CFG_VERSION       2
32 
33 #define CFG_NAME          0
34 #define CFG_ENCODE_INFO   1
35 #define CFG_STRINGS_TYPE_COUNT 2
36 
37 #define CFG_STRINGS_NAME "name", "encode_info"
38 
39 #define CFG_PINS           0
40 #define CFG_MINIMAL_UNIT   1
41 #define CFG_MAXIMAL_UNIT   2
42 #define CFG_DPI            3
43 #define CFG_UPPER_POS      4
44 #define CFG_ENCODE         5
45 #define CFG_CONSTANT       6
46 #define CFG_Y_DPI          7
47 #define CFG_INTEGER_TYPE_COUNT 8
48 
49 #define CFG_INTEGER_NAME  "pins","minimal_unit","maximal_unit","dpi",\
50 "upper_position","encode","constant","y_dpi"
51 
52 #define CFG_BIT_IMAGE_MODE  0
53 #define CFG_SEND_BIT_IMAGE  1
54 #define CFG_BIT_ROW_HEADER  2
55 #define CFG_AFTER_BIT_IMAGE 3
56 #define CFG_LINE_FEED       4
57 #define CFG_FORM_FEED       5
58 #define CFG_NORMAL_MODE     6
59 #define CFG_SKIP_SPACES     7
60 #define CFG_PRTCODE_TYPE_COUNT 8
61 
62 #define CFG_PRTCODE_NAME "bit_image_mode", "send_bit_image", "bit_row_header",\
63   "after_bit_image", "line_feed", "form_feed",\
64   "normal_mode", "skip_spaces"
65 
66 #define CFG_FMT_BIT         0x80
67 #define CFG_FMT_FORMAT_BIT  0x70
68 #define CFG_FMT_COLUMN_BIT  0x07
69 #define CFG_FMT_ISO_BIT     0x08
70 
71 #define CFG_FMT_BIN_LTOH    0x00
72 #define CFG_FMT_BIN_HTOL    0x10
73 #define CFG_FMT_HEX_UPPER   0x20
74 #define CFG_FMT_HEX_LOWER   0x30
75 #define CFG_FMT_DECIMAL     0x40
76 #define CFG_FMT_OCTAL       0x50
77 #define CFG_FMT_ASSIGNMENT  0x60  /* assignment(user variables) */
78 #define CFG_FMT_STRINGS     0x70
79 
80 #define CFG_EXPR_TYPE_BIT   0xe0
81 #define CFG_EXPR_VAL_BIT    0x1f
82 #define CFG_VAL           0x80
83 #define CFG_VAL_DEFAULT   (0x00 | CFG_VAL)
84 #define CFG_VAL_CONSTANT  (0x01 | CFG_VAL)
85 #define CFG_VAL_WIDTH     (0x02 | CFG_VAL)
86 #define CFG_VAL_HEIGHT    (0x03 | CFG_VAL)
87 #define CFG_VAL_PAGE      (0x04 | CFG_VAL)
88 #define CFG_VAL_PAGECOUNT (0x05 | CFG_VAL)
89 #define CFG_VAL_DATASIZE  (0x06 | CFG_VAL)
90 #define CFG_VAL_X_DPI     (0x07 | CFG_VAL)
91 #define CFG_VAL_Y_DPI     (0x08 | CFG_VAL)
92 #define CFG_VAL_PINS_BYTE (0x09 | CFG_VAL)
93 #define CFG_VAL_X_POS     (0x0a | CFG_VAL)
94 #define CFG_VAL_Y_POS     (0x0b | CFG_VAL)
95 
96 /* user variable 'A' -- 'P' (0xa0 -- 0xaf) */
97 #define CFG_USERVAL       (0x20 | CFG_VAL)
98 #define CFG_USERVAL_COUNT 16
99 
100 #define CFG_OP  0xc0
101 /* logic 2 operand */
102 #define CFG_OP_ADD  (0x00 | CFG_OP)
103 #define CFG_OP_SUB  (0x01 | CFG_OP)
104 #define CFG_OP_MUL  (0x02 | CFG_OP)
105 #define CFG_OP_DIV  (0x03 | CFG_OP)
106 #define CFG_OP_MOD  (0x04 | CFG_OP)
107 
108 #define CFG_OP_SHL  (0x05 | CFG_OP)
109 #define CFG_OP_SHR  (0x06 | CFG_OP)
110 #define CFG_OP_AND  (0x07 | CFG_OP)
111 #define CFG_OP_OR   (0x08 | CFG_OP)
112 #define CFG_OP_XOR  (0x09 | CFG_OP)
113 /* extra operation (user cannot use) */
114 #define CFG_OP_POP  (0x2e | CFG_OP)
115 #define CFG_OP_NULL (0x2f | CFG_OP)
116 
117 #define CFG_OP_NAME	"+","-","*","/",\
118 "%","<",">","&",\
119   "|","^",\
120   /* 0x0a -- 0x0f */	NULL,NULL,\
121   /* Undefined */	NULL,NULL,NULL,NULL,\
122   \
123   /* 0x10 -- 0x1f*/	NULL,NULL,NULL,NULL,\
124   /* Undefined */	NULL,NULL,NULL,NULL,\
125   NULL,NULL,NULL,NULL,\
126   NULL,NULL,NULL,NULL,\
127   \
128   /* 0x20 -- 0x2d*/	NULL,NULL,NULL,NULL,\
129   /* Undefined */	NULL,NULL,NULL,NULL,\
130   NULL,NULL,NULL,NULL,\
131   NULL,NULL,\
132   \
133   "pop","null"
134 
135 #define CFG_TOP_IS_HIGH  0x00
136 #define CFG_TOP_IS_LOW   0x80
137 #define CFG_LEFT_IS_HIGH 0x40
138 #define CFG_LEFT_IS_LOW  0xc0
139 #define CFG_NON_MOVING   0x20
140 #define CFG_NON_TRANSPOSE_BIT 0x40
141 #define CFG_REVERSE_BIT       0x80
142 #define CFG_PIN_POSITION_BITS 0xc0
143 
144 #define CFG_ENCODE_NAME "NULL","HEX","FAX","PCL1","PCL2"
145 #define CFG_ENCODE_NULL  0x00
146 #define CFG_ENCODE_HEX   0x01
147 #define CFG_ENCODE_FAX   0x02
148 #define CFG_ENCODE_PCL1  0x03
149 #define CFG_ENCODE_PCL2  0x04
150 #define CFG_ENCODE_LIPS3 0x05    /* Not implemented yet. */
151 #define CFG_ENCODE_ESCPAGE 0x06  /* Not implemented yet. */
152 #define CFG_ENCODE_COUNT 0x05
153 
154 #define CFG_STACK_DEPTH  20
155 
156 #define CFG_ERROR_OTHER        -1
157 
158 #define CFG_ERROR_SYNTAX       -2
159 #define CFG_ERROR_RANGE        -3
160 #define CFG_ERROR_TYPE         -4
161 
162 #define CFG_ERROR_FILE_OPEN    -5
163 #define CFG_ERROR_OUTPUT       -6
164 #define CFG_ERROR_MEMORY       -7
165 #define CFG_ERROR_DIV0         -8
166 #define CFG_ERROR_NOT_SUPPORTED -9
167 
168 #if defined(MSDOS) || defined(_MSDOS)
169 #  ifndef __MSDOS__
170 #    define __MSDOS__
171 #  endif
172 #endif
173 #if defined(__MSDOS__) || defined(__STDC__)
174 #  ifndef __PROTOTYPES__
175 #    define __PROTOTYPES__
176 #  endif
177 #endif
178 #ifdef __NO_PROTOTYPES__
179 #  undef __PROTOTYPES__
180 #endif
181 
182 #if defined(__MSDOS__) && !defined(__GNUC__) && !defined(__WATCOMC__)
183 # ifndef __MSDOS_REAL__
184 #   define __MSDOS_REAL__
185 # endif
186 #else
187 # ifndef far
188 #   define far /* */
189 # endif
190 #endif
191 
192 typedef struct {
193   unsigned int version;
194 
195   long integer[CFG_INTEGER_TYPE_COUNT];
196   unsigned char *strings[CFG_STRINGS_TYPE_COUNT];
197   unsigned char *prtcode[CFG_PRTCODE_TYPE_COUNT];
198   unsigned int prtcode_size[CFG_PRTCODE_TYPE_COUNT];
199 } dviprt_cfg_t;
200 
201 typedef struct dviprt_print_s dviprt_print;
202 struct dviprt_print_s {
203   dviprt_cfg_t *printer;
204   unsigned int bitmap_width;
205   unsigned int bitmap_height;
206   unsigned int buffer_width;
207 
208   unsigned int device_x;
209   unsigned int device_y;
210   unsigned int bitmap_x;
211   unsigned int bitmap_y;
212   unsigned int last_x;
213 
214   int page_count;
215   unsigned char far *source_buffer;
216   unsigned char far *encode_buffer;
217   unsigned char far *psource;
218   unsigned char far *poutput;
219   int tempbuffer_f;
220 
221 #ifdef __PROTOTYPES__
222   int (*output_proc)(unsigned char far *,long ,void *);
223   int (*output_maximal_unit)(dviprt_print *,unsigned char far *,unsigned int );
224   long (*encode_getbuffersize_proc)(dviprt_print *,long);
225   long (*encode_encode_proc)(dviprt_print *,long ,int);
226 #else
227   int (*output_proc)();
228   int (*output_maximal_unit)();
229   long (*encode_getbuffersize_proc)();
230   long (*encode_encode_proc)();
231 #endif
232   void *pstream;
233 
234   unsigned long output_bytes;
235   unsigned int uservar[CFG_USERVAL_COUNT];
236 };
237 
238 #define dviprt_getscanlines(p) ((int)(p)->printer->integer[CFG_PINS]*8)
239 #define dviprt_getoutputbytes(p) ((unsigned long)(p)->output_bytes)
240 
241 #ifdef __PROTOTYPES__
242 extern int dviprt_readsrc(char *,dviprt_cfg_t *,
243 			  unsigned char *,int ,unsigned char *, int);
244 extern int dviprt_readcfg(char *,dviprt_cfg_t *,
245 			  unsigned char *,int , unsigned char *,int);
246 
247 extern int dviprt_beginpage(dviprt_print *);
248 extern long dviprt_initlibrary(dviprt_print *,dviprt_cfg_t *,
249 			       unsigned int ,unsigned int );
250 extern int dviprt_endbitmap(dviprt_print *);
251 extern int dviprt_setstream
252   (dviprt_print *p,int(*f)(unsigned char far*,long,void*),void *s);
253 extern int dviprt_setbuffer(dviprt_print *,unsigned char far *);
254 extern int dviprt_outputscanlines(dviprt_print *, unsigned char far *);
255 extern int dviprt_output(dviprt_print *,unsigned char far *,long );
256 extern int dviprt_unsetbuffer(dviprt_print *);
257 
258 extern int dviprt_setmessagestream(FILE *);
259 extern int dviprt_writesrc(char *,char *,dviprt_cfg_t *,unsigned char *,int );
260 extern int dviprt_writecfg(char *,char *,dviprt_cfg_t *,unsigned char *,int );
261 extern int dviprt_writec(char *,char *,dviprt_cfg_t *,unsigned char *,int );
262 #else /* !__PROTOTYPES__ */
263 extern int dviprt_readsrc();
264 extern int dviprt_readcfg();
265 extern long dviprt_initlibrary();
266 extern int dviprt_setstream();
267 extern int dviprt_setbuffer();
268 extern int dviprt_beginpage();
269 extern int dviprt_outputscanlines();
270 extern int dviprt_endbitmap();
271 extern int dviprt_output ();
272 extern int dviprt_unsetbuffer();
273 extern int dviprt_setmessagestream();
274 extern int dviprt_writesrc();
275 extern int dviprt_writecfg();
276 extern int dviprt_writec();
277 #endif /* __PROTOTYPES__ */
278 
279 extern char *dviprt_integername[];
280 extern char *dviprt_stringsname[];
281 extern char *dviprt_prtcodename[];
282 extern char *dviprt_encodename[];
283 
284 #define s_cfg_h_INCLUDED
285 #endif /* s_cfg_h_INCLUDED */
286 
287 
288 #define TEMP_CODEBUF_SIZE 2048
289 #define TEMP_READBUF_SIZE 1024
290 
291 /* MS-DOS (real-mode) */
292 #ifdef __MSDOS_REAL__
293 # define BufferCpy(a,b,c) _fmemcpy(a,b,c)
294 # define BufferCmp(a,b,c) _fmemcmp(a,b,c)
295 # define BufferAlloc(a)   _fmalloc(a)
296 # define BufferFree(a)    _ffree(a)
297 #else
298 # define BufferCpy(a,b,c) memcpy(a,b,c)
299 # define BufferCmp(a,b,c) memcmp(a,b,c)
300 # define BufferAlloc(a)   malloc(a)
301 # define BufferFree(a)    free(a)
302 #endif
303 
304 #ifndef MIN
305 #define MIN(a,b) ((a)<(b) ? (a) : (b))
306 #endif
307 #ifndef MAX
308 #define MAX(a,b) ((a)>(b) ? (a) : (b))
309 #endif
310 
311 #define CFG_LIBERROR_UNKNOWN_VALUE  -256
312 #define CFG_LIBERROR_UNKNOWN_FORMAT -257
313 #define CFG_LIBERROR_UNKNOWN_ESCSEQ -258
314 #define CFG_LIBERROR_OUTOFRANGE     -259
315 #define CFG_LIBERROR_INVALID_VALUE  -260
316 #define CFG_LIBERROR_COMPLICATED_EXPR  -261
317 #define CFG_LIBERROR_INCOMPLETE      -262
318 
319 typedef struct {
320   uchar *fname;
321   FILE *file;
322   int line_no;
323 
324   char temp_readbuf_f;
325   char temp_codebuf_f;
326   uchar *readbuf;
327   uchar *codebuf;
328   int readbuf_size;
329   int codebuf_size;
330 
331   uchar *pcodebuf;
332 
333   uchar *token;
334   uchar *endtoken;
335 } dviprt_cfg_i;
336 
337 #ifdef dviprlib_implementation
338 typedef struct {
339   int no;
340   long (*getworksize)(P2(dviprt_print *,long ));
341   long (*encode)(P3(dviprt_print *,long,int));
342 } dviprt_encoder;
343 
344 #define liblocal private
345 
346 liblocal dviprt_encoder *dviprt_getencoder_(P1(int ));
347 liblocal int dviprt_setcfgbuffer_(P3(dviprt_cfg_i *,int ,int ));
348 liblocal int dviprt_resetcfgbuffer_(P1(dviprt_cfg_i *));
349 liblocal int dviprt_initcfg_(P2(dviprt_cfg_t *,dviprt_cfg_i *));
350 liblocal int dviprt_printmessage(P2(char *,int ));
351 liblocal int dviprt_printerror(P2(char *,int ));
352 liblocal int dviprt_printwarning(P2(char *,int ));
353 liblocal int dviprt_printcfgerror(P3(dviprt_cfg_i *,char *,int ));
354 liblocal int dviprt_printcfgwarning(P3(dviprt_cfg_i *,char *,int ));
355 
356 extern int dviprt_print_headercomment_(P4(char *,char *,char *,FILE *));
357 extern char dviprt_message_buffer[];
358 #endif dviprlib_implementation
359 
360 #define s_cfgbld_h_INCLUDED
361 #endif /* s_cfgbld_h_INCLUDED */
362