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"
107 #define _(String) gettext (String)
115 #define getcwd(buf, len) getwd(buf)
116 #endif /* HAVE_GETWD */
117 #endif /* not HAVE_GETCWD */
124 * Types and definitions.
127 #define MATCH(a, b) (strcmp (a, b) == 0)
129 #define ISNUMBERDIGIT(ch) \
130 (('0' <= (ch) && (ch) <= '9') || (ch) == '.' || (ch) == '-' || (ch) == '+')
132 /* Return the width of the character <ch> */
133 #define FNT_CHAR_WIDTH(ch) (font_widths[(unsigned char) (ch)])
135 /* Current point y movement from line to line. */
136 #define LINESKIP (Fpt.h + baselineskip)
139 /* Constants for output files. */
140 #define OUTPUT_FILE_NONE NULL
141 #define OUTPUT_FILE_STDOUT ((char *) 1)
143 /* Underlay styles. */
144 #define UL_STYLE_OUTLINE 0
145 #define UL_STYLE_FILLED 1
147 struct media_entry_st
149 struct media_entry_st *next;
159 typedef struct media_entry_st MediaEntry;
191 struct encoding_registry_st
194 InputEncoding encoding;
199 typedef struct encoding_registry_st EncodingRegistry;
213 } MarkWrappedLinesStyle;
221 } NonPrintableFormat;
244 typedef struct buffer_st Buffer;
246 struct file_lookup_ctx_st
248 /* The name of the file to lookup. */
251 /* The suffix of the file. This string is appended to <name>. */
254 /* Buffer to which the name of the file is constructed. If the
255 file_lookup() returns 1, the name of the file is here. The
256 caller of the file_lookup() must allocate this buffer. */
260 typedef struct file_lookup_ctx_st FileLookupCtx;
262 typedef int (*PathWalkProc) ___P ((char *path, void *context));
265 struct input_stream_st
267 int is_pipe; /* Is <fp> opened to pipe? */
269 unsigned char buf[4096];
270 unsigned int data_in_buf;
273 unsigned char *unget_ch;
274 unsigned int unget_pos;
275 unsigned int unget_alloc;
278 typedef struct input_stream_st InputStream;
283 struct page_range_st *next;
290 typedef struct page_range_st PageRange;
294 double w; /* width */
295 double h; /* height */
298 typedef struct font_point_st FontPoint;
307 typedef struct color_st Color;
309 struct cached_font_info_st
311 double font_widths[256];
312 char font_ctype[256];
313 AFMBoolean font_is_fixed;
314 AFMNumber font_bbox_lly;
317 typedef struct cached_font_info_st CachedFontInfo;
324 extern char *program;
326 extern char *date_string;
327 extern struct tm run_tm;
328 extern struct tm mod_tm;
329 extern struct passwd *passwd;
330 extern char *libpath;
331 extern char *afm_path;
332 extern MediaEntry *media_names;
333 extern MediaEntry *media;
334 extern char *no_job_header_switch;
335 extern char *output_first_line;
336 extern char *queue_param;
337 extern char *spooler_command;
340 extern unsigned int current_pagenum;
341 extern unsigned int input_filenum;
342 extern unsigned int current_file_linenum;
346 extern int total_pages;
347 extern int num_truncated_lines;
348 extern int num_missing_chars;
349 extern int missing_chars[];
350 extern int num_non_printable_chars;
351 extern int non_printable_chars[];
353 /* Dimensions that are used during PostScript generation. */
356 extern int d_header_w;
357 extern int d_header_h;
358 extern int d_footer_h;
359 extern int d_output_w;
360 extern int d_output_h;
361 extern int d_output_x_margin;
362 extern int d_output_y_margin;
363 extern unsigned int nup_xpad;
364 extern unsigned int nup_ypad;
366 /* Document needed resources. */
367 extern StringHashPtr res_fonts;
369 /* Fonts to download. */
370 extern StringHashPtr download_fonts;
372 /* Additional key-value pairs, passed to the generated PostScript code. */
373 extern StringHashPtr pagedevice;
374 extern StringHashPtr statusdict;
376 /* User defined strings. */
377 extern StringHashPtr user_strings;
379 /* Cache for AFM files. */
380 extern StringHashPtr afm_cache;
381 extern StringHashPtr afm_info_cache;
383 /* AFM library handle. */
384 extern AFMHandle afm;
388 extern FontPoint HFpt;
390 extern FontPoint Fpt;
391 extern FontPoint default_Fpt;
392 extern char *default_Fname;
393 extern InputEncoding default_Fencoding;
395 extern double font_widths[];
396 extern char font_ctype[];
397 extern int font_is_fixed;
398 extern double font_bbox_lly;
400 /* Known input encodings. */
401 extern EncodingRegistry encodings[];
405 extern char *printer;
407 extern int num_copies;
409 extern int num_columns;
410 extern LineEndType line_end;
412 extern int landscape;
413 extern HeaderType header;
414 extern char *fancy_header_name;
415 extern char *fancy_header_default;
416 extern double line_indent;
417 extern char *page_header;
418 extern char *page_footer;
419 extern char *output_file;
420 extern unsigned int lines_per_page;
421 extern InputEncoding encoding;
422 extern char *media_name;
423 extern char *encoding_name;
424 extern int special_escapes;
425 extern int escape_char;
426 extern int default_escape_char;
428 extern double baselineskip;
429 extern FontPoint ul_ptsize;
430 extern double ul_gray;
431 extern char *ul_font;
432 extern char *underlay;
433 extern char *ul_position;
436 extern double ul_angle;
437 extern unsigned int ul_style;
438 extern char *ul_style_str;
439 extern int ul_position_p;
440 extern int ul_angle_p;
441 extern PageLabelFormat page_label;
442 extern char *page_label_format;
443 extern int pass_through;
444 extern int line_numbers;
445 extern unsigned int start_line_number;
446 extern int interpret_formfeed;
447 extern NonPrintableFormat non_printable_format;
448 extern MarkWrappedLinesStyle mark_wrapped_lines_style;
449 extern char *mark_wrapped_lines_style_name;
450 extern char *npf_name;
451 extern int clean_7bit;
452 extern int append_ctrl_D;
453 extern unsigned int highlight_bars;
454 extern double highlight_bar_gray;
455 extern int page_prefeed;
456 extern PageRange *page_ranges;
458 extern double line_highlight_gray;
459 extern double bggray;
460 extern int accept_composites;
461 extern FormFeedType formfeed_type;
462 extern char *input_filter_stdin;
465 extern char *toc_fmt_string;
466 extern unsigned int file_align;
468 extern unsigned int slice;
470 extern char *states_binary;
471 extern int states_color;
472 extern char *states_config_file;
473 extern char *states_highlight_style;
474 extern char *states_path;
476 extern unsigned int nup;
477 extern unsigned int nup_rows;
478 extern unsigned int nup_columns;
479 extern int nup_landscape;
480 extern unsigned int nup_width;
481 extern unsigned int nup_height;
482 extern double nup_scale;
483 extern int nup_columnwise;
484 extern char *output_language;
485 extern int output_language_pass_through;
486 extern int generate_PageSize;
487 extern double horizontal_column_height;
488 extern unsigned int pslevel;
489 extern int rotate_even_pages;
490 extern int swap_even_page_margins;
491 extern int continuous_page_numbers;
495 * Prototypes for global functions.
498 /* Print message if <verbose> is >= <verbose_level>. */
499 #define MESSAGE(verbose_level, body) \
501 if (!quiet && verbose >= (verbose_level)) \
505 /* Report continuable error. */
506 #define ERROR(body) \
508 fprintf (stderr, "%s: ", program); \
510 fprintf (stderr, "\n"); \
514 /* Report fatal error and exit with status 1. Function never returns. */
515 #define FATAL(body) \
517 fprintf (stderr, "%s: ", program); \
519 fprintf (stderr, "\n"); \
525 * Read config file <path, name>. Returns bool. If function fails, error
526 * is found from errno.
528 int read_config ___P ((char *path, char *name));
530 /* Print PostScript header to our output stream. */
531 void dump_ps_header ___P ((void));
533 /* Print PostScript trailer to our output stream. */
534 void dump_ps_trailer ___P ((void));
537 * Open InputStream to <fp> or <fname>. If <input_filter> is given
538 * it is used to pre-filter the incoming data stream. Function returns
539 * 1 if stream could be opened or 0 otherwise.
541 int is_open ___P ((InputStream *is, FILE *fp, char *fname,
542 char *input_filter));
544 /* Close InputStream <is>. */
545 void is_close ___P ((InputStream *is));
548 * Read next character from the InputStream <is>. Returns EOF if
551 int is_getc ___P ((InputStream *is));
554 * Put character <ch> back to the InputStream <is>. Function returns EOF
555 * if character couldn't be unget.
557 int is_ungetc ___P ((int ch, InputStream *is));
560 void buffer_init ___P ((Buffer *buffer));
562 void buffer_uninit ___P ((Buffer *buffer));
564 Buffer *buffer_alloc ();
566 void buffer_free ___P ((Buffer *buffer));
568 void buffer_append ___P ((Buffer *buffer, const char *data));
570 void buffer_append_len ___P ((Buffer *buffer, const char *data, size_t len));
572 char *buffer_copy ___P ((Buffer *buffer));
574 void buffer_clear ___P ((Buffer *buffer));
576 char *buffer_ptr ___P ((Buffer *buffer));
578 size_t buffer_len ___P ((Buffer *buffer));
582 * Process single input file <fp>. File's name is given in <fname> and
583 * it is used to print headers. The argument <is_toc> specifies whether
584 * the file is a table of contents file or not.
586 void process_file ___P ((char *fname, InputStream *fp, int is_toc));
588 /* Add a new media to the list of known media. */
589 void add_media ___P ((char *name, int w, int h, int llx, int lly, int urx,
592 /* Print a listing of missing characters. */
593 void do_list_missing_characters ___P ((int *array));
596 * Check if file <name, suffix> exists. Returns bool. If function fails
597 * error can be found from errno.
599 int file_existsp ___P ((char *name, char *suffix));
602 * Paste file <name, suffix> to output stream. Returns bool. If
603 * function fails, error can be found from errno.
605 int paste_file ___P ((char *name, char *suffix));
608 * Do tilde substitution for filename <fname>. The function returns a
609 * xmalloc()ated result that must be freed by the caller.
611 char *tilde_subst ___P ((char *fname));
614 * Parse one float dimension from string <string>. If <units> is true,
615 * then number can be followed by an optional unit specifier. If
616 * <horizontal> is true, then dimension is horizontal, otherwise it
619 double parse_float ___P ((char *string, int units, int horizontal));
622 * Parse font spec <spec> and return font's name, size, and encoding
623 * in variables <name_return>, <size_return>, and <encoding_return>.
624 * Returns 1 if <spec> was a valid font spec or 0 otherwise. Returned
625 * name <name_return> is allocated with xcalloc() and must be freed by
628 int parse_font_spec ___P ((char *spec, char **name_return,
629 FontPoint *size_return,
630 InputEncoding *encoding_return));
633 * Read body font's character widths and character codes from AFM files.
635 void read_font_info ___P ((void));
638 * Try to download font <name>.
640 void download_font ___P ((char *name));
643 * Escape all PostScript string's special characters from string <string>.
644 * Returns a xmalloc()ated result.
646 char *escape_string ___P ((char *string));
649 * Expand user escapes from string <string>. Returns a xmalloc()ated
652 char *format_user_string ___P ((char *context_name, char *string));
655 * Parses key-value pair <kv> and inserts/deletes key from <set>.
657 void parse_key_value_pair ___P ((StringHashPtr set, char *kv));
660 * Count how many non-empty items there are in the key-value set <set>.
662 int count_key_value_set ___P ((StringHashPtr set));
665 * Walk through path <path> and call <proc> once for each of its
666 * components. Function returns 0 if all components were accessed.
667 * Callback <proc> can interrupt walking by returning a non zero
668 * return value. In that case value is returned as the return value
671 int pathwalk ___P ((char *path, PathWalkProc proc, void *context));
673 /* Lookup file from path. <context> must point to FileLookupCtx. */
674 int file_lookup ___P ((char *path, void *context));
678 * Portable printer interface.
682 * Open and initialize printer <cmd>, <options>, <queue_param> and
683 * <printer_name>. Function returns a FILE pointer to which enscript
684 * can generate its PostScript output or NULL if printer
685 * initialization failed. Command can store its context information
686 * to variable <context_return> wich is passed as an argument to the
687 * printer_close() function.
689 FILE *printer_open ___P ((char *cmd, char *options, char *queue_param,
690 char *printer_name, void **context_return));
693 * Flush all pending output to printer <context> and close it.
695 void printer_close ___P ((void *context));
698 * Escape filenames for shell usage
700 char *shell_escape ___P ((const char *fn));
702 #endif /* not GSINT_H */