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 * Enscript 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 3 of the License, or
14 * (at your option) any later version.
16 * Enscript 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 Enscript. If not, see <http://www.gnu.org/licenses/>.
38 #include <sys/types.h>
43 #define ___P(protos) protos
44 #else /* no PROTOTYPES */
45 #define ___P(protos) ()
46 #endif /* no PROTOTYPES */
54 #else /* no STDC_HEADERS */
66 #define strrchr rindex
72 extern char *strerror ___P ((int));
76 extern void *memmove ___P ((void *, void *, size_t));
80 extern void *memcpy ___P ((void *, void *, size_t));
83 #endif /* no STDC_HEADERS */
92 extern double atan2 ___P ((double, double));
103 #include "dummypwd.h"
108 #define _(String) gettext (String)
110 #define _(String) String
119 #define getcwd(buf, len) getwd(buf)
120 #endif /* HAVE_GETWD */
121 #endif /* not HAVE_GETCWD */
128 * Types and definitions.
131 #define MATCH(a, b) (strcmp (a, b) == 0)
133 #define ISNUMBERDIGIT(ch) \
134 (('0' <= (ch) && (ch) <= '9') || (ch) == '.' || (ch) == '-' || (ch) == '+')
136 /* Return the width of the character <ch> */
137 #define CHAR_WIDTH(ch) (font_widths[(unsigned char) (ch)])
139 /* Current point y movement from line to line. */
140 #define LINESKIP (Fpt.h + baselineskip)
143 /* Constants for output files. */
144 #define OUTPUT_FILE_NONE NULL
145 #define OUTPUT_FILE_STDOUT ((char *) 1)
147 /* Underlay styles. */
148 #define UL_STYLE_OUTLINE 0
149 #define UL_STYLE_FILLED 1
151 struct media_entry_st
153 struct media_entry_st *next;
163 typedef struct media_entry_st MediaEntry;
194 struct encoding_registry_st
197 InputEncoding encoding;
202 typedef struct encoding_registry_st EncodingRegistry;
216 } MarkWrappedLinesStyle;
224 } NonPrintableFormat;
247 typedef struct buffer_st Buffer;
249 struct file_lookup_ctx_st
251 /* The name of the file to lookup. */
254 /* The suffix of the file. This string is appended to <name>. */
257 /* Buffer to which the name of the file is constructed. If the
258 file_lookup() returns 1, the name of the file is here. The
259 caller of the file_lookup() must allocate this buffer. */
263 typedef struct file_lookup_ctx_st FileLookupCtx;
265 typedef int (*PathWalkProc) ___P ((char *path, void *context));
268 struct input_stream_st
270 int is_pipe; /* Is <fp> opened to pipe? */
272 unsigned char buf[4096];
273 unsigned int data_in_buf;
276 unsigned char *unget_ch;
277 unsigned int unget_pos;
278 unsigned int unget_alloc;
281 typedef struct input_stream_st InputStream;
286 struct page_range_st *next;
293 typedef struct page_range_st PageRange;
297 double w; /* width */
298 double h; /* height */
301 typedef struct font_point_st FontPoint;
310 typedef struct color_st Color;
312 struct cached_font_info_st
314 double font_widths[256];
315 char font_ctype[256];
316 AFMBoolean font_is_fixed;
317 AFMNumber font_bbox_lly;
320 typedef struct cached_font_info_st CachedFontInfo;
327 extern char *program;
329 extern char *version_string;
330 extern char *ps_version_string;
331 extern char *date_string;
332 extern struct tm run_tm;
333 extern struct tm mod_tm;
334 extern struct passwd *passwd;
335 extern char *libpath;
336 extern char *afm_path;
337 extern MediaEntry *media_names;
338 extern MediaEntry *media;
339 extern char *no_job_header_switch;
340 extern char *output_first_line;
341 extern char *queue_param;
342 extern char *spooler_command;
345 extern unsigned int current_pagenum;
346 extern unsigned int input_filenum;
347 extern unsigned int current_file_linenum;
351 extern int total_pages;
352 extern int num_truncated_lines;
353 extern int num_missing_chars;
354 extern int missing_chars[];
355 extern int num_non_printable_chars;
356 extern int non_printable_chars[];
358 /* Dimensions that are used during PostScript generation. */
361 extern int d_header_w;
362 extern int d_header_h;
363 extern int d_footer_h;
364 extern int d_output_w;
365 extern int d_output_h;
366 extern int d_output_x_margin;
367 extern int d_output_y_margin;
368 extern unsigned int nup_xpad;
369 extern unsigned int nup_ypad;
371 /* Document needed resources. */
372 extern StringHashPtr res_fonts;
374 /* Fonts to download. */
375 extern StringHashPtr download_fonts;
377 /* Additional key-value pairs, passed to the generated PostScript code. */
378 extern StringHashPtr pagedevice;
379 extern StringHashPtr statusdict;
381 /* User defined strings. */
382 extern StringHashPtr user_strings;
384 /* Cache for AFM files. */
385 extern StringHashPtr afm_cache;
386 extern StringHashPtr afm_info_cache;
388 /* AFM library handle. */
389 extern AFMHandle afm;
393 extern FontPoint HFpt;
395 extern FontPoint Fpt;
396 extern FontPoint default_Fpt;
397 extern char *default_Fname;
398 extern InputEncoding default_Fencoding;
400 extern double font_widths[];
401 extern char font_ctype[];
402 extern int font_is_fixed;
403 extern double font_bbox_lly;
405 /* Known input encodings. */
406 extern EncodingRegistry encodings[];
410 extern char *printer;
412 extern int num_copies;
414 extern int num_columns;
415 extern LineEndType line_end;
417 extern int landscape;
418 extern HeaderType header;
419 extern char *fancy_header_name;
420 extern char *fancy_header_default;
421 extern double line_indent;
422 extern char *page_header;
423 extern char *page_footer;
424 extern char *output_file;
425 extern unsigned int lines_per_page;
426 extern InputEncoding encoding;
427 extern char *media_name;
428 extern char *encoding_name;
429 extern int special_escapes;
430 extern int escape_char;
431 extern int default_escape_char;
433 extern double baselineskip;
434 extern FontPoint ul_ptsize;
435 extern double ul_gray;
436 extern char *ul_font;
437 extern char *underlay;
438 extern char *ul_position;
441 extern double ul_angle;
442 extern unsigned int ul_style;
443 extern char *ul_style_str;
444 extern int ul_position_p;
445 extern int ul_angle_p;
446 extern PageLabelFormat page_label;
447 extern char *page_label_format;
448 extern int pass_through;
449 extern int line_numbers;
450 extern unsigned int start_line_number;
451 extern int interpret_formfeed;
452 extern NonPrintableFormat non_printable_format;
453 extern MarkWrappedLinesStyle mark_wrapped_lines_style;
454 extern char *mark_wrapped_lines_style_name;
455 extern char *npf_name;
456 extern int clean_7bit;
457 extern int append_ctrl_D;
458 extern unsigned int highlight_bars;
459 extern double highlight_bar_gray;
460 extern int page_prefeed;
461 extern PageRange *page_ranges;
463 extern double line_highlight_gray;
464 extern double bggray;
465 extern int accept_composites;
466 extern FormFeedType formfeed_type;
467 extern char *input_filter_stdin;
470 extern char *toc_fmt_string;
471 extern unsigned int file_align;
473 extern unsigned int slice;
475 extern char *states_binary;
476 extern int states_color;
477 extern char *states_config_file;
478 extern char *states_highlight_style;
479 extern char *states_path;
481 extern unsigned int nup;
482 extern unsigned int nup_rows;
483 extern unsigned int nup_columns;
484 extern int nup_landscape;
485 extern unsigned int nup_width;
486 extern unsigned int nup_height;
487 extern double nup_scale;
488 extern int nup_columnwise;
489 extern char *output_language;
490 extern int output_language_pass_through;
491 extern int generate_PageSize;
492 extern double horizontal_column_height;
493 extern unsigned int pslevel;
494 extern int rotate_even_pages;
495 extern int swap_even_page_margins;
496 extern int continuous_page_numbers;
500 * Prototypes for global functions.
503 /* Print message if <verbose> is >= <verbose_level>. */
504 #define MESSAGE(verbose_level, body) \
506 if (!quiet && verbose >= (verbose_level)) \
510 /* Report continuable error. */
511 #define ERROR(body) \
513 fprintf (stderr, "%s: ", program); \
515 fprintf (stderr, "\n"); \
519 /* Report fatal error and exit with status 1. Function never returns. */
520 #define FATAL(body) \
522 fprintf (stderr, "%s: ", program); \
524 fprintf (stderr, "\n"); \
530 * Read config file <path, name>. Returns bool. If function fails, error
531 * is found from errno.
533 int read_config ___P ((char *path, char *name));
535 /* Print PostScript header to our output stream. */
536 void dump_ps_header ___P ((void));
538 /* Print PostScript trailer to our output stream. */
539 void dump_ps_trailer ___P ((void));
542 * Open InputStream to <fp> or <fname>. If <input_filter> is given
543 * it is used to pre-filter the incoming data stream. Function returns
544 * 1 if stream could be opened or 0 otherwise.
546 int is_open ___P ((InputStream *is, FILE *fp, char *fname,
547 char *input_filter));
549 /* Close InputStream <is>. */
550 void is_close ___P ((InputStream *is));
553 * Read next character from the InputStream <is>. Returns EOF if
556 int is_getc ___P ((InputStream *is));
559 * Put character <ch> back to the InputStream <is>. Function returns EOF
560 * if character couldn't be unget.
562 int is_ungetc ___P ((int ch, InputStream *is));
565 void buffer_init ___P ((Buffer *buffer));
567 void buffer_uninit ___P ((Buffer *buffer));
569 Buffer *buffer_alloc ();
571 void buffer_free ___P ((Buffer *buffer));
573 void buffer_append ___P ((Buffer *buffer, const char *data));
575 void buffer_append_len ___P ((Buffer *buffer, const char *data, size_t len));
577 char *buffer_copy ___P ((Buffer *buffer));
579 void buffer_clear ___P ((Buffer *buffer));
581 char *buffer_ptr ___P ((Buffer *buffer));
583 size_t buffer_len ___P ((Buffer *buffer));
587 * Process single input file <fp>. File's name is given in <fname> and
588 * it is used to print headers. The argument <is_toc> specifies whether
589 * the file is a table of contents file or not.
591 void process_file ___P ((char *fname, InputStream *fp, int is_toc));
593 /* Add a new media to the list of known media. */
594 void add_media ___P ((char *name, int w, int h, int llx, int lly, int urx,
597 /* Print a listing of missing characters. */
598 void do_list_missing_characters ___P ((int *array));
601 * Check if file <name, suffix> exists. Returns bool. If function fails
602 * error can be found from errno.
604 int file_existsp ___P ((char *name, char *suffix));
607 * Paste file <name, suffix> to output stream. Returns bool. If
608 * function fails, error can be found from errno.
610 int paste_file ___P ((char *name, char *suffix));
613 * Do tilde substitution for filename <fname>. The function returns a
614 * xmalloc()ated result that must be freed by the caller.
616 char *tilde_subst ___P ((char *fname));
619 * Parse one float dimension from string <string>. If <units> is true,
620 * then number can be followed by an optional unit specifier. If
621 * <horizontal> is true, then dimension is horizontal, otherwise it
624 double parse_float ___P ((char *string, int units, int horizontal));
627 * Parse font spec <spec> and return font's name, size, and encoding
628 * in variables <name_return>, <size_return>, and <encoding_return>.
629 * Returns 1 if <spec> was a valid font spec or 0 otherwise. Returned
630 * name <name_return> is allocated with xcalloc() and must be freed by
633 int parse_font_spec ___P ((char *spec, char **name_return,
634 FontPoint *size_return,
635 InputEncoding *encoding_return));
638 * Read body font's character widths and character codes from AFM files.
640 void read_font_info ___P ((void));
643 * Try to download font <name>.
645 void download_font ___P ((char *name));
648 * Escape all PostScript string's special characters from string <string>.
649 * Returns a xmalloc()ated result.
651 char *escape_string ___P ((char *string));
654 * Expand user escapes from string <string>. Returns a xmalloc()ated
657 char *format_user_string ___P ((char *context_name, char *string));
660 * Parses key-value pair <kv> and inserts/deletes key from <set>.
662 void parse_key_value_pair ___P ((StringHashPtr set, char *kv));
665 * Count how many non-empty items there are in the key-value set <set>.
667 int count_key_value_set ___P ((StringHashPtr set));
670 * Walk through path <path> and call <proc> once for each of its
671 * components. Function returns 0 if all components were accessed.
672 * Callback <proc> can interrupt walking by returning a non zero
673 * return value. In that case value is returned as the return value
676 int pathwalk ___P ((char *path, PathWalkProc proc, void *context));
678 /* Lookup file from path. <context> must point to FileLookupCtx. */
679 int file_lookup ___P ((char *path, void *context));
683 * Portable printer interface.
687 * Open and initialize printer <cmd>, <options>, <queue_param> and
688 * <printer_name>. Function returns a FILE pointer to which enscript
689 * can generate its PostScript output or NULL if printer
690 * initialization failed. Command can store its context information
691 * to variable <context_return> wich is passed as an argument to the
692 * printer_close() function.
694 FILE *printer_open ___P ((char *cmd, char *options, char *queue_param,
695 char *printer_name, void **context_return));
698 * Flush all pending output to printer <context> and close it.
700 void printer_close ___P ((void *context));
703 * Escape filenames for shell usage
705 char *shell_escape ___P ((const char *fn));
707 #endif /* not GSINT_H */