2 * Internal header file.
3 * Copyright (c) 1995-2000 Markku Rossi.
5 * Author: Markku Rossi <mtr@iki.fi>
9 * This file is part of GNU enscript.
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)
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.
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, 51 Franklin Street, Fifth Floor,
24 * Boston, MA 02110-1301, USA.
40 #include <sys/types.h>
45 #define ___P(protos) protos
46 #else /* no PROTOTYPES */
47 #define ___P(protos) ()
48 #endif /* no PROTOTYPES */
56 #else /* no STDC_HEADERS */
68 #define strrchr rindex
74 extern char *strerror ___P ((int));
78 extern void *memmove ___P ((void *, void *, size_t));
82 extern void *memcpy ___P ((void *, void *, size_t));
85 #endif /* no STDC_HEADERS */
94 extern double atan2 ___P ((double, double));
105 #include "dummypwd.h"
110 #define _(String) gettext (String)
112 #define _(String) String
121 #define getcwd(buf, len) getwd(buf)
122 #endif /* HAVE_GETWD */
123 #endif /* not HAVE_GETCWD */
130 * Types and definitions.
133 #define MATCH(a, b) (strcmp (a, b) == 0)
135 #define ISNUMBERDIGIT(ch) \
136 (('0' <= (ch) && (ch) <= '9') || (ch) == '.' || (ch) == '-' || (ch) == '+')
138 /* Return the width of the character <ch> */
139 #define CHAR_WIDTH(ch) (font_widths[(unsigned char) (ch)])
141 /* Current point y movement from line to line. */
142 #define LINESKIP (Fpt.h + baselineskip)
145 /* Constants for output files. */
146 #define OUTPUT_FILE_NONE NULL
147 #define OUTPUT_FILE_STDOUT ((char *) 1)
149 /* Underlay styles. */
150 #define UL_STYLE_OUTLINE 0
151 #define UL_STYLE_FILLED 1
153 struct media_entry_st
155 struct media_entry_st *next;
165 typedef struct media_entry_st MediaEntry;
196 struct encoding_registry_st
199 InputEncoding encoding;
204 typedef struct encoding_registry_st EncodingRegistry;
218 } MarkWrappedLinesStyle;
226 } NonPrintableFormat;
249 typedef struct buffer_st Buffer;
251 struct file_lookup_ctx_st
253 /* The name of the file to lookup. */
256 /* The suffix of the file. This string is appended to <name>. */
259 /* Buffer to which the name of the file is constructed. If the
260 file_lookup() returns 1, the name of the file is here. The
261 caller of the file_lookup() must allocate this buffer. */
265 typedef struct file_lookup_ctx_st FileLookupCtx;
267 typedef int (*PathWalkProc) ___P ((char *path, void *context));
270 struct input_stream_st
272 int is_pipe; /* Is <fp> opened to pipe? */
274 unsigned char buf[4096];
275 unsigned int data_in_buf;
278 unsigned char *unget_ch;
279 unsigned int unget_pos;
280 unsigned int unget_alloc;
283 typedef struct input_stream_st InputStream;
288 struct page_range_st *next;
295 typedef struct page_range_st PageRange;
299 double w; /* width */
300 double h; /* height */
303 typedef struct font_point_st FontPoint;
312 typedef struct color_st Color;
314 struct cached_font_info_st
316 double font_widths[256];
317 char font_ctype[256];
318 AFMBoolean font_is_fixed;
319 AFMNumber font_bbox_lly;
322 typedef struct cached_font_info_st CachedFontInfo;
329 extern char *program;
331 extern char *version_string;
332 extern char *ps_version_string;
333 extern char *date_string;
334 extern struct tm run_tm;
335 extern struct tm mod_tm;
336 extern struct passwd *passwd;
337 extern char *libpath;
338 extern char *afm_path;
339 extern MediaEntry *media_names;
340 extern MediaEntry *media;
341 extern char *no_job_header_switch;
342 extern char *output_first_line;
343 extern char *queue_param;
344 extern char *spooler_command;
347 extern unsigned int current_pagenum;
348 extern unsigned int input_filenum;
349 extern unsigned int current_file_linenum;
353 extern int total_pages;
354 extern int num_truncated_lines;
355 extern int num_missing_chars;
356 extern int missing_chars[];
357 extern int num_non_printable_chars;
358 extern int non_printable_chars[];
360 /* Dimensions that are used during PostScript generation. */
363 extern int d_header_w;
364 extern int d_header_h;
365 extern int d_footer_h;
366 extern int d_output_w;
367 extern int d_output_h;
368 extern int d_output_x_margin;
369 extern int d_output_y_margin;
370 extern unsigned int nup_xpad;
371 extern unsigned int nup_ypad;
373 /* Document needed resources. */
374 extern StringHashPtr res_fonts;
376 /* Fonts to download. */
377 extern StringHashPtr download_fonts;
379 /* Additional key-value pairs, passed to the generated PostScript code. */
380 extern StringHashPtr pagedevice;
381 extern StringHashPtr statusdict;
383 /* User defined strings. */
384 extern StringHashPtr user_strings;
386 /* Cache for AFM files. */
387 extern StringHashPtr afm_cache;
388 extern StringHashPtr afm_info_cache;
390 /* AFM library handle. */
391 extern AFMHandle afm;
395 extern FontPoint HFpt;
397 extern FontPoint Fpt;
398 extern FontPoint default_Fpt;
399 extern char *default_Fname;
400 extern InputEncoding default_Fencoding;
402 extern double font_widths[];
403 extern char font_ctype[];
404 extern int font_is_fixed;
405 extern double font_bbox_lly;
407 /* Known input encodings. */
408 extern EncodingRegistry encodings[];
412 extern char *printer;
414 extern int num_copies;
416 extern int num_columns;
417 extern LineEndType line_end;
419 extern int landscape;
420 extern HeaderType header;
421 extern char *fancy_header_name;
422 extern char *fancy_header_default;
423 extern double line_indent;
424 extern char *page_header;
425 extern char *page_footer;
426 extern char *output_file;
427 extern unsigned int lines_per_page;
428 extern InputEncoding encoding;
429 extern char *media_name;
430 extern char *encoding_name;
431 extern int special_escapes;
432 extern int escape_char;
433 extern int default_escape_char;
435 extern double baselineskip;
436 extern FontPoint ul_ptsize;
437 extern double ul_gray;
438 extern char *ul_font;
439 extern char *underlay;
440 extern char *ul_position;
443 extern double ul_angle;
444 extern unsigned int ul_style;
445 extern char *ul_style_str;
446 extern int ul_position_p;
447 extern int ul_angle_p;
448 extern PageLabelFormat page_label;
449 extern char *page_label_format;
450 extern int pass_through;
451 extern int line_numbers;
452 extern unsigned int start_line_number;
453 extern int interpret_formfeed;
454 extern NonPrintableFormat non_printable_format;
455 extern MarkWrappedLinesStyle mark_wrapped_lines_style;
456 extern char *mark_wrapped_lines_style_name;
457 extern char *npf_name;
458 extern int clean_7bit;
459 extern int append_ctrl_D;
460 extern unsigned int highlight_bars;
461 extern double highlight_bar_gray;
462 extern int page_prefeed;
463 extern PageRange *page_ranges;
465 extern double line_highlight_gray;
466 extern double bggray;
467 extern int accept_composites;
468 extern FormFeedType formfeed_type;
469 extern char *input_filter_stdin;
472 extern char *toc_fmt_string;
473 extern unsigned int file_align;
475 extern unsigned int slice;
477 extern char *states_binary;
478 extern int states_color;
479 extern char *states_config_file;
480 extern char *states_highlight_style;
481 extern char *states_path;
483 extern unsigned int nup;
484 extern unsigned int nup_rows;
485 extern unsigned int nup_columns;
486 extern int nup_landscape;
487 extern unsigned int nup_width;
488 extern unsigned int nup_height;
489 extern double nup_scale;
490 extern int nup_columnwise;
491 extern char *output_language;
492 extern int output_language_pass_through;
493 extern int generate_PageSize;
494 extern double horizontal_column_height;
495 extern unsigned int pslevel;
496 extern int rotate_even_pages;
497 extern int swap_even_page_margins;
498 extern int continuous_page_numbers;
502 * Prototypes for global functions.
505 /* Print message if <verbose> is >= <verbose_level>. */
506 #define MESSAGE(verbose_level, body) \
508 if (!quiet && verbose >= (verbose_level)) \
512 /* Report continuable error. */
513 #define ERROR(body) \
515 fprintf (stderr, "%s: ", program); \
517 fprintf (stderr, "\n"); \
521 /* Report fatal error and exit with status 1. Function never returns. */
522 #define FATAL(body) \
524 fprintf (stderr, "%s: ", program); \
526 fprintf (stderr, "\n"); \
532 * Read config file <path, name>. Returns bool. If function fails, error
533 * is found from errno.
535 int read_config ___P ((char *path, char *name));
537 /* Print PostScript header to our output stream. */
538 void dump_ps_header ___P ((void));
540 /* Print PostScript trailer to our output stream. */
541 void dump_ps_trailer ___P ((void));
544 * Open InputStream to <fp> or <fname>. If <input_filter> is given
545 * it is used to pre-filter the incoming data stream. Function returns
546 * 1 if stream could be opened or 0 otherwise.
548 int is_open ___P ((InputStream *is, FILE *fp, char *fname,
549 char *input_filter));
551 /* Close InputStream <is>. */
552 void is_close ___P ((InputStream *is));
555 * Read next character from the InputStream <is>. Returns EOF if
558 int is_getc ___P ((InputStream *is));
561 * Put character <ch> back to the InputStream <is>. Function returns EOF
562 * if character couldn't be unget.
564 int is_ungetc ___P ((int ch, InputStream *is));
567 void buffer_init ___P ((Buffer *buffer));
569 void buffer_uninit ___P ((Buffer *buffer));
571 Buffer *buffer_alloc ();
573 void buffer_free ___P ((Buffer *buffer));
575 void buffer_append ___P ((Buffer *buffer, const char *data));
577 void buffer_append_len ___P ((Buffer *buffer, const char *data, size_t len));
579 char *buffer_copy ___P ((Buffer *buffer));
581 void buffer_clear ___P ((Buffer *buffer));
583 char *buffer_ptr ___P ((Buffer *buffer));
585 size_t buffer_len ___P ((Buffer *buffer));
589 * Process single input file <fp>. File's name is given in <fname> and
590 * it is used to print headers. The argument <is_toc> specifies whether
591 * the file is a table of contents file or not.
593 void process_file ___P ((char *fname, InputStream *fp, int is_toc));
595 /* Add a new media to the list of known media. */
596 void add_media ___P ((char *name, int w, int h, int llx, int lly, int urx,
599 /* Print a listing of missing characters. */
600 void do_list_missing_characters ___P ((int *array));
603 * Check if file <name, suffix> exists. Returns bool. If function fails
604 * error can be found from errno.
606 int file_existsp ___P ((char *name, char *suffix));
609 * Paste file <name, suffix> to output stream. Returns bool. If
610 * function fails, error can be found from errno.
612 int paste_file ___P ((char *name, char *suffix));
615 * Do tilde substitution for filename <fname>. The function returns a
616 * xmalloc()ated result that must be freed by the caller.
618 char *tilde_subst ___P ((char *fname));
621 * Parse one float dimension from string <string>. If <units> is true,
622 * then number can be followed by an optional unit specifier. If
623 * <horizontal> is true, then dimension is horizontal, otherwise it
626 double parse_float ___P ((char *string, int units, int horizontal));
629 * Parse font spec <spec> and return font's name, size, and encoding
630 * in variables <name_return>, <size_return>, and <encoding_return>.
631 * Returns 1 if <spec> was a valid font spec or 0 otherwise. Returned
632 * name <name_return> is allocated with xcalloc() and must be freed by
635 int parse_font_spec ___P ((char *spec, char **name_return,
636 FontPoint *size_return,
637 InputEncoding *encoding_return));
640 * Read body font's character widths and character codes from AFM files.
642 void read_font_info ___P ((void));
645 * Try to download font <name>.
647 void download_font ___P ((char *name));
650 * Escape all PostScript string's special characters from string <string>.
651 * Returns a xmalloc()ated result.
653 char *escape_string ___P ((char *string));
656 * Expand user escapes from string <string>. Returns a xmalloc()ated
659 char *format_user_string ___P ((char *context_name, char *string));
662 * Parses key-value pair <kv> and inserts/deletes key from <set>.
664 void parse_key_value_pair ___P ((StringHashPtr set, char *kv));
667 * Count how many non-empty items there are in the key-value set <set>.
669 int count_key_value_set ___P ((StringHashPtr set));
672 * Walk through path <path> and call <proc> once for each of its
673 * components. Function returns 0 if all components were accessed.
674 * Callback <proc> can interrupt walking by returning a non zero
675 * return value. In that case value is returned as the return value
678 int pathwalk ___P ((char *path, PathWalkProc proc, void *context));
680 /* Lookup file from path. <context> must point to FileLookupCtx. */
681 int file_lookup ___P ((char *path, void *context));
685 * Portable printer interface.
689 * Open and initialize printer <cmd>, <options>, <queue_param> and
690 * <printer_name>. Function returns a FILE pointer to which enscript
691 * can generate its PostScript output or NULL if printer
692 * initialization failed. Command can store its context information
693 * to variable <context_return> wich is passed as an argument to the
694 * printer_close() function.
696 FILE *printer_open ___P ((char *cmd, char *options, char *queue_param,
697 char *printer_name, void **context_return));
700 * Flush all pending output to printer <context> and close it.
702 void printer_close ___P ((void *context));
704 #endif /* not GSINT_H */