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 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;
190 struct encoding_registry_st
193 InputEncoding encoding;
198 typedef struct encoding_registry_st EncodingRegistry;
212 } MarkWrappedLinesStyle;
220 } NonPrintableFormat;
243 typedef struct buffer_st Buffer;
245 struct file_lookup_ctx_st
247 /* The name of the file to lookup. */
250 /* The suffix of the file. This string is appended to <name>. */
253 /* Buffer to which the name of the file is constructed. If the
254 file_lookup() returns 1, the name of the file is here. The
255 caller of the file_lookup() must allocate this buffer. */
259 typedef struct file_lookup_ctx_st FileLookupCtx;
261 typedef int (*PathWalkProc) ___P ((char *path, void *context));
264 struct input_stream_st
266 int is_pipe; /* Is <fp> opened to pipe? */
268 unsigned char buf[4096];
269 unsigned int data_in_buf;
272 unsigned char *unget_ch;
273 unsigned int unget_pos;
274 unsigned int unget_alloc;
277 typedef struct input_stream_st InputStream;
282 struct page_range_st *next;
289 typedef struct page_range_st PageRange;
293 double w; /* width */
294 double h; /* height */
297 typedef struct font_point_st FontPoint;
306 typedef struct color_st Color;
308 struct cached_font_info_st
310 double font_widths[256];
311 char font_ctype[256];
312 AFMBoolean font_is_fixed;
313 AFMNumber font_bbox_lly;
316 typedef struct cached_font_info_st CachedFontInfo;
323 extern char *program;
325 extern char *date_string;
326 extern struct tm run_tm;
327 extern struct tm mod_tm;
328 extern struct passwd *passwd;
329 extern char *libpath;
330 extern char *afm_path;
331 extern MediaEntry *media_names;
332 extern MediaEntry *media;
333 extern char *no_job_header_switch;
334 extern char *output_first_line;
335 extern char *queue_param;
336 extern char *spooler_command;
339 extern unsigned int current_pagenum;
340 extern unsigned int input_filenum;
341 extern unsigned int current_file_linenum;
345 extern int total_pages;
346 extern int num_truncated_lines;
347 extern int num_missing_chars;
348 extern int missing_chars[];
349 extern int num_non_printable_chars;
350 extern int non_printable_chars[];
352 /* Dimensions that are used during PostScript generation. */
355 extern int d_header_w;
356 extern int d_header_h;
357 extern int d_footer_h;
358 extern int d_output_w;
359 extern int d_output_h;
360 extern int d_output_x_margin;
361 extern int d_output_y_margin;
362 extern unsigned int nup_xpad;
363 extern unsigned int nup_ypad;
365 /* Document needed resources. */
366 extern StringHashPtr res_fonts;
368 /* Fonts to download. */
369 extern StringHashPtr download_fonts;
371 /* Additional key-value pairs, passed to the generated PostScript code. */
372 extern StringHashPtr pagedevice;
373 extern StringHashPtr statusdict;
375 /* User defined strings. */
376 extern StringHashPtr user_strings;
378 /* Cache for AFM files. */
379 extern StringHashPtr afm_cache;
380 extern StringHashPtr afm_info_cache;
382 /* AFM library handle. */
383 extern AFMHandle afm;
387 extern FontPoint HFpt;
389 extern FontPoint Fpt;
390 extern FontPoint default_Fpt;
391 extern char *default_Fname;
392 extern InputEncoding default_Fencoding;
394 extern double font_widths[];
395 extern char font_ctype[];
396 extern int font_is_fixed;
397 extern double font_bbox_lly;
399 /* Known input encodings. */
400 extern EncodingRegistry encodings[];
404 extern char *printer;
406 extern int num_copies;
408 extern int num_columns;
409 extern LineEndType line_end;
411 extern int landscape;
412 extern HeaderType header;
413 extern char *fancy_header_name;
414 extern char *fancy_header_default;
415 extern double line_indent;
416 extern char *page_header;
417 extern char *page_footer;
418 extern char *output_file;
419 extern unsigned int lines_per_page;
420 extern InputEncoding encoding;
421 extern char *media_name;
422 extern char *encoding_name;
423 extern int special_escapes;
424 extern int escape_char;
425 extern int default_escape_char;
427 extern double baselineskip;
428 extern FontPoint ul_ptsize;
429 extern double ul_gray;
430 extern char *ul_font;
431 extern char *underlay;
432 extern char *ul_position;
435 extern double ul_angle;
436 extern unsigned int ul_style;
437 extern char *ul_style_str;
438 extern int ul_position_p;
439 extern int ul_angle_p;
440 extern PageLabelFormat page_label;
441 extern char *page_label_format;
442 extern int pass_through;
443 extern int line_numbers;
444 extern unsigned int start_line_number;
445 extern int interpret_formfeed;
446 extern NonPrintableFormat non_printable_format;
447 extern MarkWrappedLinesStyle mark_wrapped_lines_style;
448 extern char *mark_wrapped_lines_style_name;
449 extern char *npf_name;
450 extern int clean_7bit;
451 extern int append_ctrl_D;
452 extern unsigned int highlight_bars;
453 extern double highlight_bar_gray;
454 extern int page_prefeed;
455 extern PageRange *page_ranges;
457 extern double line_highlight_gray;
458 extern double bggray;
459 extern int accept_composites;
460 extern FormFeedType formfeed_type;
461 extern char *input_filter_stdin;
464 extern char *toc_fmt_string;
465 extern unsigned int file_align;
467 extern unsigned int slice;
469 extern char *states_binary;
470 extern int states_color;
471 extern char *states_config_file;
472 extern char *states_highlight_style;
473 extern char *states_path;
475 extern unsigned int nup;
476 extern unsigned int nup_rows;
477 extern unsigned int nup_columns;
478 extern int nup_landscape;
479 extern unsigned int nup_width;
480 extern unsigned int nup_height;
481 extern double nup_scale;
482 extern int nup_columnwise;
483 extern char *output_language;
484 extern int output_language_pass_through;
485 extern int generate_PageSize;
486 extern double horizontal_column_height;
487 extern unsigned int pslevel;
488 extern int rotate_even_pages;
489 extern int swap_even_page_margins;
490 extern int continuous_page_numbers;
494 * Prototypes for global functions.
497 /* Print message if <verbose> is >= <verbose_level>. */
498 #define MESSAGE(verbose_level, body) \
500 if (!quiet && verbose >= (verbose_level)) \
504 /* Report continuable error. */
505 #define ERROR(body) \
507 fprintf (stderr, "%s: ", program); \
509 fprintf (stderr, "\n"); \
513 /* Report fatal error and exit with status 1. Function never returns. */
514 #define FATAL(body) \
516 fprintf (stderr, "%s: ", program); \
518 fprintf (stderr, "\n"); \
524 * Read config file <path, name>. Returns bool. If function fails, error
525 * is found from errno.
527 int read_config ___P ((char *path, char *name));
529 /* Print PostScript header to our output stream. */
530 void dump_ps_header ___P ((void));
532 /* Print PostScript trailer to our output stream. */
533 void dump_ps_trailer ___P ((void));
536 * Open InputStream to <fp> or <fname>. If <input_filter> is given
537 * it is used to pre-filter the incoming data stream. Function returns
538 * 1 if stream could be opened or 0 otherwise.
540 int is_open ___P ((InputStream *is, FILE *fp, char *fname,
541 char *input_filter));
543 /* Close InputStream <is>. */
544 void is_close ___P ((InputStream *is));
547 * Read next character from the InputStream <is>. Returns EOF if
550 int is_getc ___P ((InputStream *is));
553 * Put character <ch> back to the InputStream <is>. Function returns EOF
554 * if character couldn't be unget.
556 int is_ungetc ___P ((int ch, InputStream *is));
559 void buffer_init ___P ((Buffer *buffer));
561 void buffer_uninit ___P ((Buffer *buffer));
563 Buffer *buffer_alloc ();
565 void buffer_free ___P ((Buffer *buffer));
567 void buffer_append ___P ((Buffer *buffer, const char *data));
569 void buffer_append_len ___P ((Buffer *buffer, const char *data, size_t len));
571 char *buffer_copy ___P ((Buffer *buffer));
573 void buffer_clear ___P ((Buffer *buffer));
575 char *buffer_ptr ___P ((Buffer *buffer));
577 size_t buffer_len ___P ((Buffer *buffer));
581 * Process single input file <fp>. File's name is given in <fname> and
582 * it is used to print headers. The argument <is_toc> specifies whether
583 * the file is a table of contents file or not.
585 void process_file ___P ((char *fname, InputStream *fp, int is_toc));
587 /* Add a new media to the list of known media. */
588 void add_media ___P ((char *name, int w, int h, int llx, int lly, int urx,
591 /* Print a listing of missing characters. */
592 void do_list_missing_characters ___P ((int *array));
595 * Check if file <name, suffix> exists. Returns bool. If function fails
596 * error can be found from errno.
598 int file_existsp ___P ((char *name, char *suffix));
601 * Paste file <name, suffix> to output stream. Returns bool. If
602 * function fails, error can be found from errno.
604 int paste_file ___P ((char *name, char *suffix));
607 * Do tilde substitution for filename <fname>. The function returns a
608 * xmalloc()ated result that must be freed by the caller.
610 char *tilde_subst ___P ((char *fname));
613 * Parse one float dimension from string <string>. If <units> is true,
614 * then number can be followed by an optional unit specifier. If
615 * <horizontal> is true, then dimension is horizontal, otherwise it
618 double parse_float ___P ((char *string, int units, int horizontal));
621 * Parse font spec <spec> and return font's name, size, and encoding
622 * in variables <name_return>, <size_return>, and <encoding_return>.
623 * Returns 1 if <spec> was a valid font spec or 0 otherwise. Returned
624 * name <name_return> is allocated with xcalloc() and must be freed by
627 int parse_font_spec ___P ((char *spec, char **name_return,
628 FontPoint *size_return,
629 InputEncoding *encoding_return));
632 * Read body font's character widths and character codes from AFM files.
634 void read_font_info ___P ((void));
637 * Try to download font <name>.
639 void download_font ___P ((char *name));
642 * Escape all PostScript string's special characters from string <string>.
643 * Returns a xmalloc()ated result.
645 char *escape_string ___P ((char *string));
648 * Expand user escapes from string <string>. Returns a xmalloc()ated
651 char *format_user_string ___P ((char *context_name, char *string));
654 * Parses key-value pair <kv> and inserts/deletes key from <set>.
656 void parse_key_value_pair ___P ((StringHashPtr set, char *kv));
659 * Count how many non-empty items there are in the key-value set <set>.
661 int count_key_value_set ___P ((StringHashPtr set));
664 * Walk through path <path> and call <proc> once for each of its
665 * components. Function returns 0 if all components were accessed.
666 * Callback <proc> can interrupt walking by returning a non zero
667 * return value. In that case value is returned as the return value
670 int pathwalk ___P ((char *path, PathWalkProc proc, void *context));
672 /* Lookup file from path. <context> must point to FileLookupCtx. */
673 int file_lookup ___P ((char *path, void *context));
677 * Portable printer interface.
681 * Open and initialize printer <cmd>, <options>, <queue_param> and
682 * <printer_name>. Function returns a FILE pointer to which enscript
683 * can generate its PostScript output or NULL if printer
684 * initialization failed. Command can store its context information
685 * to variable <context_return> wich is passed as an argument to the
686 * printer_close() function.
688 FILE *printer_open ___P ((char *cmd, char *options, char *queue_param,
689 char *printer_name, void **context_return));
692 * Flush all pending output to printer <context> and close it.
694 void printer_close ___P ((void *context));
697 * Escape filenames for shell usage
699 char *shell_escape ___P ((const char *fn));
701 #endif /* not GSINT_H */