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 *date_string;
330 extern struct tm run_tm;
331 extern struct tm mod_tm;
332 extern struct passwd *passwd;
333 extern char *libpath;
334 extern char *afm_path;
335 extern MediaEntry *media_names;
336 extern MediaEntry *media;
337 extern char *no_job_header_switch;
338 extern char *output_first_line;
339 extern char *queue_param;
340 extern char *spooler_command;
343 extern unsigned int current_pagenum;
344 extern unsigned int input_filenum;
345 extern unsigned int current_file_linenum;
349 extern int total_pages;
350 extern int num_truncated_lines;
351 extern int num_missing_chars;
352 extern int missing_chars[];
353 extern int num_non_printable_chars;
354 extern int non_printable_chars[];
356 /* Dimensions that are used during PostScript generation. */
359 extern int d_header_w;
360 extern int d_header_h;
361 extern int d_footer_h;
362 extern int d_output_w;
363 extern int d_output_h;
364 extern int d_output_x_margin;
365 extern int d_output_y_margin;
366 extern unsigned int nup_xpad;
367 extern unsigned int nup_ypad;
369 /* Document needed resources. */
370 extern StringHashPtr res_fonts;
372 /* Fonts to download. */
373 extern StringHashPtr download_fonts;
375 /* Additional key-value pairs, passed to the generated PostScript code. */
376 extern StringHashPtr pagedevice;
377 extern StringHashPtr statusdict;
379 /* User defined strings. */
380 extern StringHashPtr user_strings;
382 /* Cache for AFM files. */
383 extern StringHashPtr afm_cache;
384 extern StringHashPtr afm_info_cache;
386 /* AFM library handle. */
387 extern AFMHandle afm;
391 extern FontPoint HFpt;
393 extern FontPoint Fpt;
394 extern FontPoint default_Fpt;
395 extern char *default_Fname;
396 extern InputEncoding default_Fencoding;
398 extern double font_widths[];
399 extern char font_ctype[];
400 extern int font_is_fixed;
401 extern double font_bbox_lly;
403 /* Known input encodings. */
404 extern EncodingRegistry encodings[];
408 extern char *printer;
410 extern int num_copies;
412 extern int num_columns;
413 extern LineEndType line_end;
415 extern int landscape;
416 extern HeaderType header;
417 extern char *fancy_header_name;
418 extern char *fancy_header_default;
419 extern double line_indent;
420 extern char *page_header;
421 extern char *page_footer;
422 extern char *output_file;
423 extern unsigned int lines_per_page;
424 extern InputEncoding encoding;
425 extern char *media_name;
426 extern char *encoding_name;
427 extern int special_escapes;
428 extern int escape_char;
429 extern int default_escape_char;
431 extern double baselineskip;
432 extern FontPoint ul_ptsize;
433 extern double ul_gray;
434 extern char *ul_font;
435 extern char *underlay;
436 extern char *ul_position;
439 extern double ul_angle;
440 extern unsigned int ul_style;
441 extern char *ul_style_str;
442 extern int ul_position_p;
443 extern int ul_angle_p;
444 extern PageLabelFormat page_label;
445 extern char *page_label_format;
446 extern int pass_through;
447 extern int line_numbers;
448 extern unsigned int start_line_number;
449 extern int interpret_formfeed;
450 extern NonPrintableFormat non_printable_format;
451 extern MarkWrappedLinesStyle mark_wrapped_lines_style;
452 extern char *mark_wrapped_lines_style_name;
453 extern char *npf_name;
454 extern int clean_7bit;
455 extern int append_ctrl_D;
456 extern unsigned int highlight_bars;
457 extern double highlight_bar_gray;
458 extern int page_prefeed;
459 extern PageRange *page_ranges;
461 extern double line_highlight_gray;
462 extern double bggray;
463 extern int accept_composites;
464 extern FormFeedType formfeed_type;
465 extern char *input_filter_stdin;
468 extern char *toc_fmt_string;
469 extern unsigned int file_align;
471 extern unsigned int slice;
473 extern char *states_binary;
474 extern int states_color;
475 extern char *states_config_file;
476 extern char *states_highlight_style;
477 extern char *states_path;
479 extern unsigned int nup;
480 extern unsigned int nup_rows;
481 extern unsigned int nup_columns;
482 extern int nup_landscape;
483 extern unsigned int nup_width;
484 extern unsigned int nup_height;
485 extern double nup_scale;
486 extern int nup_columnwise;
487 extern char *output_language;
488 extern int output_language_pass_through;
489 extern int generate_PageSize;
490 extern double horizontal_column_height;
491 extern unsigned int pslevel;
492 extern int rotate_even_pages;
493 extern int swap_even_page_margins;
494 extern int continuous_page_numbers;
498 * Prototypes for global functions.
501 /* Print message if <verbose> is >= <verbose_level>. */
502 #define MESSAGE(verbose_level, body) \
504 if (!quiet && verbose >= (verbose_level)) \
508 /* Report continuable error. */
509 #define ERROR(body) \
511 fprintf (stderr, "%s: ", program); \
513 fprintf (stderr, "\n"); \
517 /* Report fatal error and exit with status 1. Function never returns. */
518 #define FATAL(body) \
520 fprintf (stderr, "%s: ", program); \
522 fprintf (stderr, "\n"); \
528 * Read config file <path, name>. Returns bool. If function fails, error
529 * is found from errno.
531 int read_config ___P ((char *path, char *name));
533 /* Print PostScript header to our output stream. */
534 void dump_ps_header ___P ((void));
536 /* Print PostScript trailer to our output stream. */
537 void dump_ps_trailer ___P ((void));
540 * Open InputStream to <fp> or <fname>. If <input_filter> is given
541 * it is used to pre-filter the incoming data stream. Function returns
542 * 1 if stream could be opened or 0 otherwise.
544 int is_open ___P ((InputStream *is, FILE *fp, char *fname,
545 char *input_filter));
547 /* Close InputStream <is>. */
548 void is_close ___P ((InputStream *is));
551 * Read next character from the InputStream <is>. Returns EOF if
554 int is_getc ___P ((InputStream *is));
557 * Put character <ch> back to the InputStream <is>. Function returns EOF
558 * if character couldn't be unget.
560 int is_ungetc ___P ((int ch, InputStream *is));
563 void buffer_init ___P ((Buffer *buffer));
565 void buffer_uninit ___P ((Buffer *buffer));
567 Buffer *buffer_alloc ();
569 void buffer_free ___P ((Buffer *buffer));
571 void buffer_append ___P ((Buffer *buffer, const char *data));
573 void buffer_append_len ___P ((Buffer *buffer, const char *data, size_t len));
575 char *buffer_copy ___P ((Buffer *buffer));
577 void buffer_clear ___P ((Buffer *buffer));
579 char *buffer_ptr ___P ((Buffer *buffer));
581 size_t buffer_len ___P ((Buffer *buffer));
585 * Process single input file <fp>. File's name is given in <fname> and
586 * it is used to print headers. The argument <is_toc> specifies whether
587 * the file is a table of contents file or not.
589 void process_file ___P ((char *fname, InputStream *fp, int is_toc));
591 /* Add a new media to the list of known media. */
592 void add_media ___P ((char *name, int w, int h, int llx, int lly, int urx,
595 /* Print a listing of missing characters. */
596 void do_list_missing_characters ___P ((int *array));
599 * Check if file <name, suffix> exists. Returns bool. If function fails
600 * error can be found from errno.
602 int file_existsp ___P ((char *name, char *suffix));
605 * Paste file <name, suffix> to output stream. Returns bool. If
606 * function fails, error can be found from errno.
608 int paste_file ___P ((char *name, char *suffix));
611 * Do tilde substitution for filename <fname>. The function returns a
612 * xmalloc()ated result that must be freed by the caller.
614 char *tilde_subst ___P ((char *fname));
617 * Parse one float dimension from string <string>. If <units> is true,
618 * then number can be followed by an optional unit specifier. If
619 * <horizontal> is true, then dimension is horizontal, otherwise it
622 double parse_float ___P ((char *string, int units, int horizontal));
625 * Parse font spec <spec> and return font's name, size, and encoding
626 * in variables <name_return>, <size_return>, and <encoding_return>.
627 * Returns 1 if <spec> was a valid font spec or 0 otherwise. Returned
628 * name <name_return> is allocated with xcalloc() and must be freed by
631 int parse_font_spec ___P ((char *spec, char **name_return,
632 FontPoint *size_return,
633 InputEncoding *encoding_return));
636 * Read body font's character widths and character codes from AFM files.
638 void read_font_info ___P ((void));
641 * Try to download font <name>.
643 void download_font ___P ((char *name));
646 * Escape all PostScript string's special characters from string <string>.
647 * Returns a xmalloc()ated result.
649 char *escape_string ___P ((char *string));
652 * Expand user escapes from string <string>. Returns a xmalloc()ated
655 char *format_user_string ___P ((char *context_name, char *string));
658 * Parses key-value pair <kv> and inserts/deletes key from <set>.
660 void parse_key_value_pair ___P ((StringHashPtr set, char *kv));
663 * Count how many non-empty items there are in the key-value set <set>.
665 int count_key_value_set ___P ((StringHashPtr set));
668 * Walk through path <path> and call <proc> once for each of its
669 * components. Function returns 0 if all components were accessed.
670 * Callback <proc> can interrupt walking by returning a non zero
671 * return value. In that case value is returned as the return value
674 int pathwalk ___P ((char *path, PathWalkProc proc, void *context));
676 /* Lookup file from path. <context> must point to FileLookupCtx. */
677 int file_lookup ___P ((char *path, void *context));
681 * Portable printer interface.
685 * Open and initialize printer <cmd>, <options>, <queue_param> and
686 * <printer_name>. Function returns a FILE pointer to which enscript
687 * can generate its PostScript output or NULL if printer
688 * initialization failed. Command can store its context information
689 * to variable <context_return> wich is passed as an argument to the
690 * printer_close() function.
692 FILE *printer_open ___P ((char *cmd, char *options, char *queue_param,
693 char *printer_name, void **context_return));
696 * Flush all pending output to printer <context> and close it.
698 void printer_close ___P ((void *context));
701 * Escape filenames for shell usage
703 char *shell_escape ___P ((const char *fn));
705 #endif /* not GSINT_H */