source: trunk/third/enscript/src/gsint.h @ 17620

Revision 17620, 14.3 KB checked in by ghudson, 22 years ago (diff)
This commit was generated by cvs2svn to compensate for changes in r17619, which included commits to RCS files with non-trunk default branches.
Line 
1/*
2 * Internal header file.
3 * Copyright (c) 1995-1998 Markku Rossi.
4 *
5 * Author: Markku Rossi <mtr@iki.fi>
6 */
7
8/*
9 * This file is part of GNU enscript.
10 *
11 * This program is free software; you can redistribute it and/or modify
12 * it under the terms of the GNU General Public License as published by
13 * the Free Software Foundation; either version 2, or (at your option)
14 * any later version.
15 *
16 * This program is distributed in the hope that it will be useful,
17 * but WITHOUT ANY WARRANTY; without even the implied warranty of
18 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
19 * GNU General Public License for more details.
20 *
21 * You should have received a copy of the GNU General Public License
22 * along with this program; see the file COPYING.  If not, write to
23 * the Free Software Foundation, 59 Temple Place - Suite 330,
24 * Boston, MA 02111-1307, USA.
25 */
26
27#ifndef GSINT_H
28#define GSINT_H
29
30/*
31 * Config stuffs.
32 */
33
34#ifdef HAVE_CONFIG_H
35#include <config.h>
36#endif
37
38#include <stdio.h>
39
40#include <sys/types.h>
41#include <sys/stat.h>
42
43#ifndef ___P
44#if PROTOTYPES
45#define ___P(protos) protos
46#else /* no PROTOTYPES */
47#define ___P(protos) ()
48#endif /* no PROTOTYPES */
49#endif
50
51#if STDC_HEADERS
52
53#include <stdlib.h>
54#include <string.h>
55
56#else /* no STDC_HEADERS */
57
58#if HAVE_STDLIB_H
59#include <stdlib.h>
60#endif
61
62#if HAVE_STRING_H
63#include <string.h>
64#endif
65
66#ifndef HAVE_STRCHR
67#define strchr index
68#define strrchr rindex
69#endif
70char *strchr ();
71char *strrchr ();
72
73#ifndef HAVE_STRERROR
74extern char *strerror ___P ((int));
75#endif
76
77#ifndef HAVE_MEMMOVE
78extern void *memmove ___P ((void *, void *, size_t));
79#endif
80
81#ifndef HAVE_MEMCPY
82extern void *memcpy ___P ((void *, void *, size_t));
83#endif
84
85#endif /* no STDC_HEADERS */
86
87#if HAVE_UNISTD_H
88#include <unistd.h>
89#endif
90
91#if HAVE_MATH_H
92#include <math.h>
93#else
94extern double atan2 ___P ((double, double));
95#endif
96
97#include <errno.h>
98#include <time.h>
99#include <assert.h>
100#include <ctype.h>
101
102#if HAVE_PWD_H
103#include <pwd.h>
104#else
105#include "dummypwd.h"
106#endif
107
108#if ENABLE_NLS
109#include <libintl.h>
110#define _(String) gettext (String)
111#else
112#define _(String) String
113#endif
114
115#if HAVE_LC_MESSAGES
116#include <locale.h>
117#endif
118
119#ifndef HAVE_GETCWD
120#if HAVE_GETWD
121#define getcwd(buf, len) getwd(buf)
122#endif /* HAVE_GETWD */
123#endif /* not HAVE_GETCWD */
124
125#include "afm.h"
126#include "strhash.h"
127#include "xalloc.h"
128
129/*
130 * Types and definitions.
131 */
132
133#define MATCH(a, b) (strcmp (a, b) == 0)
134
135#define ISNUMBERDIGIT(ch) \
136  (('0' <= (ch) && (ch) <= '9') || (ch) == '.' || (ch) == '-' || (ch) == '+')
137
138/* Return the width of the character <ch> */
139#define CHAR_WIDTH(ch) (font_widths[(unsigned char) (ch)])
140
141/* Current point y movement from line to line. */
142#define LINESKIP (Fpt.h + baselineskip)
143
144
145/* Constants for output files. */
146#define OUTPUT_FILE_NONE   NULL
147#define OUTPUT_FILE_STDOUT ((char *) 1)
148
149/* Underlay styles. */
150#define UL_STYLE_OUTLINE        0
151#define UL_STYLE_FILLED         1
152
153struct media_entry_st
154{
155  struct media_entry_st *next;
156  char *name;
157  int w;
158  int h;
159  int llx;
160  int lly;
161  int urx;
162  int ury;
163};
164
165typedef struct media_entry_st MediaEntry;
166
167typedef enum
168{
169  HDR_NONE,
170  HDR_SIMPLE,
171  HDR_FANCY
172} HeaderType;
173
174
175typedef enum
176{
177  ENC_ISO_8859_1,
178  ENC_ISO_8859_2,
179  ENC_ISO_8859_3,
180  ENC_ISO_8859_4,
181  ENC_ISO_8859_5,
182  ENC_ISO_8859_7,
183  ENC_ASCII,
184  ENC_ASCII_FISE,
185  ENC_ASCII_DKNO,
186  ENC_IBMPC,
187  ENC_MAC,
188  ENC_VMS,
189  ENC_HP8,
190  ENC_KOI8,
191  ENC_PS
192} InputEncoding;
193
194typedef enum
195{
196  LABEL_SHORT,
197  LABEL_LONG
198} PageLabelFormat;
199
200typedef enum
201{
202  MWLS_NONE     = 0,
203  MWLS_PLUS     = 1,
204  MWLS_BOX      = 2,
205  MWLS_ARROW    = 3
206} MarkWrappedLinesStyle;
207
208typedef enum
209{
210  NPF_SPACE,
211  NPF_QUESTIONMARK,
212  NPF_CARET,
213  NPF_OCTAL
214} NonPrintableFormat;
215
216typedef enum
217{
218  FORMFEED_COLUMN,
219  FORMFEED_PAGE,
220  FORMFEED_HCOLUMN
221} FormFeedType;
222
223typedef enum
224{
225  LE_TRUNCATE,
226  LE_CHAR_WRAP,
227  LE_WORD_WRAP
228} LineEndType;
229
230struct file_lookup_ctx_st
231{
232  char name[256];
233  char suffix[256];
234  char fullname[512];
235};
236
237typedef struct file_lookup_ctx_st FileLookupCtx;
238
239typedef int (*PathWalkProc) ___P ((char *path, void *context));
240
241struct input_stream_st
242{
243  int is_pipe;                  /* Is <fp> opened to pipe? */
244  FILE *fp;
245  unsigned char buf[4096];
246  unsigned int data_in_buf;
247  unsigned int bufpos;
248  unsigned int nreads;
249  unsigned char *unget_ch;
250  unsigned int unget_pos;
251  unsigned int unget_alloc;
252};
253
254typedef struct input_stream_st InputStream;
255
256struct page_range_st
257{
258  struct page_range_st *next;
259  int odd;
260  int even;
261  unsigned int start;
262  unsigned int end;
263};
264
265typedef struct page_range_st PageRange;
266
267struct font_point_st
268{
269  double w;                     /* width */
270  double h;                     /* height */
271};
272
273typedef struct font_point_st FontPoint;
274
275struct color_st
276{
277  float r;
278  float g;
279  float b;
280};
281
282typedef struct color_st Color;
283
284struct cached_font_info_st
285{
286  double font_widths[256];
287  char font_ctype[256];
288  AFMBoolean font_is_fixed;
289  AFMNumber font_bbox_lly;
290};
291
292typedef struct cached_font_info_st CachedFontInfo;
293
294
295/*
296 * Global variables.
297 */
298
299extern char *program;
300extern FILE *ofp;
301extern char version_string[];
302extern char ps_version_string[];
303extern char date_string[];
304extern struct tm run_tm;
305extern struct tm mod_tm;
306extern struct passwd *passwd;
307extern char libpath[];
308extern char *afm_path;
309extern char afm_path_buffer[];
310extern MediaEntry *media_names;
311extern MediaEntry *media;
312extern char no_job_header_switch[];
313extern char output_first_line[];
314extern char queue_param[];
315extern char spooler_command[];
316extern int nl;
317extern int bs;
318extern unsigned int current_pagenum;
319extern unsigned int input_filenum;
320extern unsigned int current_file_linenum;
321extern char fname[];
322
323/* Statistics. */
324extern int total_pages;
325extern int num_truncated_lines;
326extern int num_missing_chars;
327extern int missing_chars[];
328extern int num_non_printable_chars;
329extern int non_printable_chars[];
330
331/* Dimensions that are used during PostScript generation. */
332extern int d_page_w;
333extern int d_page_h;
334extern int d_header_w;
335extern int d_header_h;
336extern int d_footer_h;
337extern int d_output_w;
338extern int d_output_h;
339extern int d_output_x_margin;
340extern int d_output_y_margin;
341extern unsigned int nup_xpad;
342extern unsigned int nup_ypad;
343
344/* Document needed resources. */
345extern StringHashPtr res_fonts;
346
347/* Fonts to download. */
348extern StringHashPtr download_fonts;
349
350/* Additional key-value pairs, passed to the generated PostScript code. */
351extern StringHashPtr pagedevice;
352extern StringHashPtr statusdict;
353
354/* User defined strings. */
355extern StringHashPtr user_strings;
356
357/* Cache for AFM files. */
358extern StringHashPtr afm_cache;
359extern StringHashPtr afm_info_cache;
360
361/* AFM library handle. */
362extern AFMHandle afm;
363
364/* Fonts. */
365extern char *HFname;
366extern FontPoint HFpt;
367extern char *Fname;
368extern FontPoint Fpt;
369extern FontPoint default_Fpt;
370extern char *default_Fname;
371
372extern double font_widths[];
373extern char font_ctype[];
374extern int font_is_fixed;
375extern double font_bbox_lly;
376
377/* Options. */
378
379extern char *printer;
380extern char printer_buf[];
381extern int verbose;
382extern int num_copies;
383extern char *title;
384extern int num_columns;
385extern LineEndType line_end;
386extern int quiet;
387extern int landscape;
388extern HeaderType header;
389extern char *fancy_header_name;
390extern char fancy_header_default[];
391extern double line_indent;
392extern char *page_header;
393extern char *output_file;
394extern unsigned int lines_per_page;
395extern InputEncoding encoding;
396extern char *media_name;
397extern char media_name_buffer[];
398extern char *encoding_name;
399extern char encoding_name_buffer[];
400extern int special_escapes;
401extern int escape_char;
402extern int default_escape_char;
403extern int tabsize;
404extern double baselineskip;
405extern FontPoint ul_ptsize;
406extern double ul_gray;
407extern char *ul_font;
408extern char *underlay;
409extern char ul_position_buf[];
410extern char *ul_position;
411extern double ul_x;
412extern double ul_y;
413extern double ul_angle;
414extern unsigned int ul_style;
415extern char *ul_style_str;
416extern char ul_style_str_buf[];
417extern int ul_position_p;
418extern int ul_angle_p;
419extern PageLabelFormat page_label;
420extern char *page_label_format;
421extern char page_label_format_buf[];
422extern int pass_through;
423extern int line_numbers;
424extern unsigned int start_line_number;
425extern int interpret_formfeed;
426extern NonPrintableFormat non_printable_format;
427extern MarkWrappedLinesStyle mark_wrapped_lines_style;
428extern char mark_wrapped_lines_style_name[];
429extern char *npf_name;
430extern char npf_name_buf[];
431extern int clean_7bit;
432extern int append_ctrl_D;
433extern unsigned int highlight_bars;
434extern double highlight_bar_gray;
435extern int page_prefeed;
436extern PageRange *page_ranges;
437extern int borders;
438extern double line_highlight_gray;
439extern double bggray;
440extern int accept_composites;
441extern FormFeedType formfeed_type;
442extern char *input_filter_stdin;
443extern int toc;
444extern FILE *toc_fp;
445extern char *toc_fmt_string;
446extern unsigned int file_align;
447extern int slicing;
448extern unsigned int slice;
449extern char states_path[];
450extern char states_color_model[];
451extern char states_config_file[];
452extern char states_highlight_level[];
453extern unsigned int nup;
454extern unsigned int nup_rows;
455extern unsigned int nup_columns;
456extern int nup_landscape;
457extern unsigned int nup_width;
458extern unsigned int nup_height;
459extern double nup_scale;
460extern char *output_language;
461extern int output_language_pass_through;
462extern int generate_PageSize;
463extern double horizontal_column_height;
464extern unsigned int pslevel;
465extern int rotate_even_pages;
466
467
468/*
469 * Prototypes for global functions.
470 */
471
472/* Print message if <verbose> is >= <verbose_level>. */
473#define MESSAGE(verbose_level, body)            \
474  do {                                          \
475    if (!quiet && verbose >= (verbose_level))   \
476      fprintf body;                             \
477  } while (0)
478
479/* Report continuable error. */
480#define ERROR(body)                     \
481  do {                                  \
482    fprintf (stderr, "%s: ", program);  \
483    fprintf body;                       \
484    fprintf (stderr, "\n");             \
485    fflush (stderr);                    \
486  } while (0)
487
488/* Report fatal error and exit with status 1.  Function never returns. */
489#define FATAL(body)                     \
490  do {                                  \
491    fprintf (stderr, "%s: ", program);  \
492    fprintf body;                       \
493    fprintf (stderr, "\n");             \
494    fflush (stderr);                    \
495    exit (1);                           \
496  } while (0)
497
498/*
499 * Read config file <path, name>.  Returns bool.  If function fails, error
500 * is found from errno.
501 */
502int read_config ___P ((char *path, char *name));
503
504/* Print PostScript header to our output stream. */
505void dump_ps_header ___P ((void));
506
507/* Print PostScript trailer to our output stream. */
508void dump_ps_trailer ___P ((void));
509
510/*
511 * Open InputStream to <fp> or <fname>.  If <input_filter> is given
512 * it is used to pre-filter the incoming data stream.  Function returns
513 * 1 if stream could be opened or 0 otherwise.
514 */
515int is_open ___P ((InputStream *is, FILE *fp, char *fname,
516                   char *input_filter));
517
518/* Close InputStream <is>. */
519void is_close ___P ((InputStream *is));
520
521/*
522 * Read next character from the InputStream <is>.  Returns EOF if
523 * EOF was reached.
524 */
525int is_getc ___P ((InputStream *is));
526
527/*
528 * Put character <ch> back to the InputStream <is>.  Function returns EOF
529 * if character couldn't be unget.
530 */
531int is_ungetc ___P ((int ch, InputStream *is));
532
533/*
534 * Process single input file <fp>.  File's name is given in <fname> and
535 * it is used to print headers.
536 */
537void process_file ___P ((char *fname, InputStream *fp));
538
539/* Add a new media to the list of known media. */
540void add_media ___P ((char *name, int w, int h, int llx, int lly, int urx,
541                      int ury));
542
543/* Print a listing of missing characters. */
544void do_list_missing_characters ___P ((int *array));
545
546/*
547 * Check if file <name, suffix> exists.  Returns bool.  If function fails
548 * error can be found from errno.
549 */
550int file_existsp ___P ((char *name, char *suffix));
551
552/*
553 * Paste file <name, suffix> to output stream.  Returns bool. If
554 * function fails, error can be found from errno.
555 */
556int paste_file ___P ((char *name, char *suffix));
557
558/*
559 * Do tilde substitution for filename <from> and insert result to <to>.
560 * Buffer <to> must be long enought to hold expanded name.
561 */
562void tilde_subst ___P ((char *from, char *to));
563
564/*
565 * Parse one float dimension from string <string>.  If <units> is true,
566 * then number can be followed by an optional unit specifier.  If
567 * <horizontal> is true, then dimension is horizontal, otherwise it
568 * is vertical.
569 */
570double parse_float ___P ((char *string, int units, int horizontal));
571
572/*
573 * Parse font spec <spec> and return font's name and size in variables
574 * <name_return> and <size_return>.  Returns 1 if <spec> was a valid
575 * font spec or 0 otherwise.  Returned name <name_return> is allocated
576 * with xcalloc() and must be freed by caller.
577 */
578int parse_font_spec ___P ((char *spec, char **name_return,
579                           FontPoint *size_return));
580
581/*
582 * Read body font's character widths and character codes from AFM files.
583 */
584void read_font_info ___P ((void));
585
586/*
587 * Try to download font <name>.
588 */
589void download_font ___P ((char *name));
590
591/*
592 * Escape all PostScript string's special characters from string <string>.
593 * Returns a xmalloc()ated result.
594 */
595char *escape_string ___P ((char *string));
596
597/*
598 * Expand user escapes from string <string>.  Returns a xmalloc()ated
599 * result.
600 */
601char *format_user_string ___P ((char *context_name, char *string));
602
603/*
604 * Parses key-value pair <kv> and inserts/deletes key from <set>.
605 */
606void parse_key_value_pair ___P ((StringHashPtr set, char *kv));
607
608/*
609 * Count how many non-empty items there are in the key-value set <set>.
610 */
611int count_key_value_set ___P ((StringHashPtr set));
612
613/*
614 * Walk through path <path> and call <proc> once for each of its
615 * components.  Function returns 0 if all components were accessed.
616 * Callback <proc> can interrupt walking by returning a non zero
617 * return value.  In that case value is returned as the return value
618 * of the pathwalk().
619 */
620int pathwalk ___P ((char *path, PathWalkProc proc, void *context));
621
622/* Lookup file from path.  <context> must point to FileLookupCtx. */
623int file_lookup ___P ((char *path, void *context));
624
625
626/*
627 * Portable printer interface.
628 */
629
630/*
631 * Open and initialize printer <cmd>, <options>, <queue_param> and
632 * <printer_name>.  Function returns a FILE pointer to which enscript
633 * can generate its PostScript output or NULL if printer
634 * initialization failed.  Command can store its context information
635 * to variable <context_return> wich is passed as an argument to the
636 * printer_close() function.
637 */
638FILE *printer_open ___P ((char *cmd, char *options, char *queue_param,
639                          char *printer_name, void **context_return));
640
641/*
642 * Flush all pending output to printer <context> and close it.
643 */
644void printer_close ___P ((void *context));
645
646#endif /* not GSINT_H */
Note: See TracBrowser for help on using the repository browser.