2 * Argument handling and main.
3 * Copyright (c) 1995-2003 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/>.
31 * Prototypes for static functions.
35 * Open output file according to user options. Void if output file
36 * has already been opened.
38 static void open_output_file ();
40 /* Close output file. */
41 static void close_output_file ();
43 /* Handle options from environment variable <var> */
44 static void handle_env_options ___P ((char *var));
46 /* Handle options from <argv> array. */
47 static void handle_options ___P ((int argc, char *argv[]));
49 /* Print usage info. */
52 /* Print version info. */
53 static void version ();
60 char *program; /* Program's name, used for messages. */
61 FILE *ofp = NULL; /* Output file. */
62 void *printer_context; /* Context for the printer. */
63 char *date_string = NULL; /* Preformatted time string. */
64 struct tm run_tm; /* Time when program is run. */
65 struct tm mod_tm; /* Last modification time for current file. */
66 struct passwd *passwd; /* Passwd entry for the user running this
69 /* Path to our library. */
70 char *enscript_library = LIBRARY;
72 /* Library lookup path. */
75 /* AFM library lookup path. */
76 char *afm_path = NULL;
78 MediaEntry *media_names = NULL; /* List of known media. */
79 MediaEntry *media = NULL; /* Entry for used media. */
80 int bs = 8; /* The backspace character. */
83 int total_pages = 0; /* Total number of pages printed. */
84 int num_truncated_lines = 0; /* Number of lines truncated. */
85 int num_missing_chars = 0; /* Number of unknown characters. */
86 int missing_chars[256] = {0}; /* Table of unknown characters. */
87 int num_non_printable_chars = 0; /* Number of non-printable characters. */
88 int non_printable_chars[256] = {0}; /* Table of non-printable characters. */
90 /* Output media dimensions that are used during PostScript emission. */
91 int d_page_w = 0; /* page's width */
92 int d_page_h = 0; /* page's height */
93 int d_header_w = 0; /* fancy header's width */
94 int d_header_h = 0; /* fancy header's height */
95 int d_footer_h = 0; /* fancy footer's height */
96 int d_output_w = 0; /* output area's width */
97 int d_output_h = 0; /* output area's height */
98 int d_output_x_margin = 5; /* output area's x marginal */
99 int d_output_y_margin = 2; /* output area's y marginal */
101 /* Document needed resources. */
102 StringHashPtr res_fonts; /* fonts */
104 /* Fonts to download. */
105 StringHashPtr download_fonts;
107 /* Additional key-value pairs, passed to the generated PostScript code. */
108 StringHashPtr pagedevice; /* for setpagedevice */
109 StringHashPtr statusdict; /* for statusdict */
111 /* User defined strings. */
112 StringHashPtr user_strings;
114 /* Cache for AFM files. */
115 StringHashPtr afm_cache = NULL;
116 StringHashPtr afm_info_cache = NULL;
118 /* AFM library handle. */
119 AFMHandle afm = NULL;
125 * Free single-letter options are: Q, x, y, Y
131 * An alias for -n, --copies.
135 * -1, -2, -3, -4, -5, -6, -7, -8, -9, --columns=NUM
137 * Number of columns per page. The default is 1 column.
142 * -a PAGES, --pages=PAGES
144 * Specify which pages are printed.
146 PageRange *page_ranges = NULL;
149 * -A ALIGN, --file-align=ALIGN
151 * Align input files to start from ALIGN page count. This is handy
152 * for two-side printings.
154 unsigned int file_align = 1;
157 * -b STRING, --header=STRING
159 * Set the string that is used as the page header. As a default, page
160 * header is constructed from filename, date and page number.
162 char *page_header = NULL;
167 * Do not print page headers.
171 * -c, --truncate-lines
173 * Truncate lines that are longer than the page width. Default is character
176 LineEndType line_end = LE_CHAR_WRAP;
179 * -C [START], --line-numbers[=START]
181 * Precede each line with its line number. As a default, do not mark
182 * line numbers. If the optional argument START is given, it
183 * specifies the number from which the line numbers are assumed to
184 * start in the file. This is useful if the file contains a region
187 int line_numbers = 0;
188 unsigned int start_line_number = 1;
193 * Name of the printer to which output is send. Defaults to system's
196 char *printer = NULL;
199 * -e [CHAR], --escapes[=CHAR]
201 * Enable special escape ('\000') interpretation. If option CHAR is given
202 * it is assumed to specify the escape character.
204 int special_escapes = 0;
205 int escape_char = '\0';
206 int default_escape_char;
209 * -E [LANG], --highlight=[LANG] (deprecated --pretty-print[=LANG])
211 * Highlight program source code. Highlighting is handled by creating
212 * an input filter with the states-program. States makes an educated
213 * guess about the start state but sometimes it fails, so the start
214 * state can also be specified to be LANG. This option overwrites
215 * input filter and enables special escapes.
219 char *hl_start_state = NULL;
226 char *Fname = "Courier";
227 FontPoint Fpt = {10.0, 10.0};
228 FontPoint default_Fpt; /* Point size of the original font. */
229 char *default_Fname; /* Name of the original font. */
230 InputEncoding default_Fencoding; /* The encoding of the original font. */
231 int user_body_font_defined = 0; /* Has user defined new body font? */
233 double font_widths[256]; /* Width array for body font. */
234 char font_ctype[256]; /* Font character types. */
235 int font_is_fixed; /* Is body font a fixed pitch font? */
236 double font_bbox_lly; /* Font's bounding box's lly-coordinate. */
241 * Select font to be used to print the standard simple header.
243 char *HFname = "Courier-Bold";
244 FontPoint HFpt = {10.0, 10.0};
249 * Print document even it contains binary data. This does nothing
250 * since enscript prints files anyway.
256 * Add a fancy header to top of every page. There are several header styles
257 * but the default is 'no fancy header'.
259 HeaderType header = HDR_SIMPLE;
260 char *fancy_header_name = NULL;
261 char *fancy_header_default = NULL;
264 * -h, --no-job-header
266 * Supress the job header page.
268 static int no_job_header = 0;
271 * -H num, --highlight-bars=num
273 * Print highlight bars under text. Bars will be <num> lines high.
274 * As a default, do not print bars.
276 unsigned int highlight_bars = 0;
281 * Indent every line this many characters.
283 double line_indent = 0.0;
284 char *line_indent_spec = "0";
287 * -I CMD, --filter=CMD
289 * Read input files through input filter CMD.
291 char *input_filter = NULL;
296 * Print borders around columns.
303 * An alias for -t, --title.
308 * -K, --no-page-prefeed
310 * Control page prefeed.
312 int page_prefeed = 0;
317 * Emulate lineprinter - make pages 66 lines long and omit headers.
321 * -L, --lines-per-page
323 * Specify how many lines should be printed on a single page. Normally
324 * enscript counts it from font point sizes.
326 unsigned int lines_per_page = (unsigned int) -1;
331 * Send mail notification to user after print job has been completed.
338 * Name of the output media. Default is A4.
340 char *media_name = NULL;
345 * Number of copies to print.
352 * Set the newline character: '\n' or '\r'. As a default, the newline
353 * character is specified by the input encoding.
360 * Leave output to the specified file. As a default result is spooled to
363 char *output_file = OUTPUT_FILE_NONE;
366 * -O, --missing-characters
368 * List all missing characters. Default is no listing.
370 int list_missing_characters = 0;
375 * Do not tell what we are doing. Default is to tell something but
384 * Print with page rotated 90 degrees (landscape mode). Default is
392 * Specify baselineskip value that is used when enscript moves to
393 * a new line. Current point movement is font_point_size + baselineskip.
395 double baselineskip = 1.0;
400 * Title which is printed to the banner page. If this option is given
401 * from the command line, this sets also the name of the stdin which
402 * is by the default "".
404 char *title = "Enscript Output";
410 * Specify tabulator size.
417 * Place text under every page. Default is no underlay.
420 FontPoint ul_ptsize = {200.0, 200.0};
421 char *ul_font = "Times-Roman";
422 char *underlay = NULL;
423 char *ul_position = NULL; /* Position info as a string. */
424 double ul_x; /* Position x-coordinate. */
425 double ul_y; /* Position y-coordinate. */
427 unsigned int ul_style = UL_STYLE_OUTLINE;
428 char *ul_style_str = NULL;
429 int ul_position_p = 0; /* Is ul-position given? */
430 int ul_angle_p = 0; /* Is ul-angle given? */
435 * Print NUM PostScript pages on each output page (n-up printing).
437 unsigned int nup = 1;
438 unsigned int nup_exp = 0;
439 unsigned int nup_rows = 1;
440 unsigned int nup_columns = 1;
441 int nup_landscape = 0;
442 unsigned int nup_width;
443 unsigned int nup_height;
449 * Tell what we are doing. Default is no verbose outputs.
456 * Print version information.
460 * -w LANGUAGE, --language=LANGUAGE
462 * Generate output for language LANGUAGE. The default is PostScript.
464 char *output_language = "PostScript";
465 int output_language_pass_through = 0;
468 * -W APP,option, --options=APP,OPTION
470 * Pass additional option to enscript's helper applications. The
471 * first part of the option's argument (APP) specifies the
472 * helper application to which the options are added. Currently the
473 * following helper application are defined:
477 Buffer *helper_options[256] = {0};
482 * Specifies input encoding. Default is ISO-8859.1.
484 InputEncoding encoding = ENC_ISO_8859_1;
485 char *encoding_name = NULL;
490 * Do not interpret form feed characters. As a default, form feed
491 * characters are interpreted.
493 int interpret_formfeed = 1;
498 * Pass through all PostScript and PCL files without any modifications.
499 * As a default, don't.
501 int pass_through = 0;
506 * Create color output with states?
510 * --continuous-page-numbers
512 * Count page numbers across input files. Don't restart numbering
513 * at beginning of each file.
515 int continuous_page_numbers = 0;
518 * --download-font=FONT
520 * Download font FONT to printer.
524 * --extended-return-values
526 * Enable extended return values.
528 int extended_return_values = 0;
533 * How stdin is shown to the filter command. The default is "" but
534 * some utilities might want it as "-".
536 char *input_filter_stdin = "";
541 * Set the string that is used as the page footer. As a default, the
542 * page has no footer. Setting this option does not necessary show
543 * any footer strings in the output. It depends on the selected
544 * header (`.hdr' file) whether it supports footer strings or not.
546 char *page_footer = NULL;
549 * --h-column-height=HEIGHT
551 * Set the horizontal column (channel) height to be HEIGHT. This option
552 * also sets the FormFeedType to `hcolumn'. The default value is set to be
553 * big enough to cause a jump to the next vertical column (100m).
555 double horizontal_column_height = 283465.0;
558 * --help-highlight (deprecated --help-pretty-print)
560 * Descript all supported -E, --highlight languages and file formats.
562 int help_highlight = 0;
565 * --highlight-bar-gray=val
567 * Specify the gray level for highlight bars.
569 double highlight_bar_gray = .97;
574 * List all known media. As a default do not list media names.
579 * --margins=LEFT:RIGHT:TOP:BOTTOM
581 * Adjust page marginals.
583 char *margins_spec = NULL;
586 * --mark-wrapped-lines[=STYLE]
588 * Mark wrapped lines so that they can be easily detected from the printout.
589 * Optional parameter STYLE specifies the marking style, the system default
592 char *mark_wrapped_lines_style_name = NULL;
593 MarkWrappedLinesStyle mark_wrapped_lines_style = MWLS_NONE;
596 * --non-printable-format=FORMAT
598 * Format in which non-printable characters are printed.
600 char *npf_name = NULL;
601 NonPrintableFormat non_printable_format = NPF_OCTAL;
606 * Layout N-up pages colunwise instead of row-wise.
608 int nup_columnwise = 0;
613 * The x-padding between N-up subpages.
615 unsigned int nup_xpad = 10;
620 * The y-padding between N-up subpages.
622 unsigned int nup_ypad = 10;
625 * --page-label-format=FORMAT
627 * Format in which page labels are printed; the default is "short".
629 char *page_label_format = NULL;
630 PageLabelFormat page_label;
635 * The PostScript language level that enscript should use; the default is 2.
637 unsigned int pslevel = 2;
640 * --printer-options=OPTIONS
642 * Pass extra options OPTIONS to the printer spooler.
644 char *printer_options = NULL;
647 * --rotate-even-pages
649 * Rotate each even-numbered page 180 degrees. This might be handy in
650 * two-side printing when the resulting pages are bind from some side.
651 * Greetings to Jussi-Pekka Sairanen.
653 int rotate_even_pages = 0;
658 * Horizontal input slicing. Print only NUMth wrapped input pages.
661 unsigned int slice = 1;
664 * --swap-even-page-margins
666 * Swap left and right side margins for each even numbered page. This
667 * might be handy in two-side printing.
669 int swap_even_page_margins = 0;
674 * Print Table of Contents page.
678 char *toc_fmt_string;
683 * Wrap long lines from word boundaries. The default is character wrap.
687 * AcceptCompositeCharacters: bool
689 * Specify whatever we accept composite characters or should them be
690 * considered as non-existent. As a default, do not accept them.
692 int accept_composites = 0;
697 * Append ^D character to the end of the output. Some printers require this
698 * but the default is false.
700 int append_ctrl_D = 0;
705 * Specify how characters greater than 127 are printed.
712 * Specify what to do when a formfeed character is encountered from the
713 * input stream. The default action is to jump to the beginning of the
716 FormFeedType formfeed_type = FORMFEED_COLUMN;
719 * GeneratePageSize: bool
721 * Specify whether the `PageSize' pagedevice definitions should be
722 * generated to the output.
724 int generate_PageSize = 1;
727 * NoJobHeaderSwitch: switch
729 * Spooler switch to suppress the job header (-h).
731 char *no_job_header_switch = NULL;
734 * OutputFirstLine: line
736 * Set the PostScript output's first line to something your system can handle.
737 * The default is "%!PS-Adobe-3.0"
739 char *output_first_line = NULL;
744 * The spooler command switch to select the printer queue (-P).
746 char *queue_param = NULL;
751 * The spooler command name (lpr).
753 char *spooler_command = NULL;
758 * An absolute path to the `states' binary.
761 char *states_binary = NULL;
766 * Should the States program generate color outputs.
768 int states_color = 0;
771 * StatesConfigFile: file
773 * The name of the states' configuration file.
775 char *states_config_file = NULL;
778 * StatesHighlightStyle: style
780 * The highlight style.
782 char *states_highlight_style = NULL;
787 * Define the path for the states program. The states program will
788 * lookup its state definition files from this path.
790 char *states_path = NULL;
792 /* ^@shade{GRAY}, set the line highlight gray. */
793 double line_highlight_gray = 1.0;
795 /* ^@bggray{GRAY}, set the text background gray. */
798 EncodingRegistry encodings[] =
800 {{"88591", "latin1", NULL}, ENC_ISO_8859_1, '\n', 8},
801 {{"88592", "latin2", NULL}, ENC_ISO_8859_2, '\n', 8},
802 {{"88593", "latin3", NULL}, ENC_ISO_8859_3, '\n', 8},
803 {{"88594", "latin4", NULL}, ENC_ISO_8859_4, '\n', 8},
804 {{"88595", "cyrillic", NULL}, ENC_ISO_8859_5, '\n', 8},
805 {{"88597", "greek", NULL}, ENC_ISO_8859_7, '\n', 8},
806 {{"88599", "latin5", NULL}, ENC_ISO_8859_9, '\n', 8},
807 {{"885910", "latin6", NULL}, ENC_ISO_8859_10, '\n', 8},
808 {{"ascii", NULL, NULL}, ENC_ASCII, '\n', 8},
809 {{"asciifise", "asciifi", "asciise"}, ENC_ASCII_FISE, '\n', 8},
810 {{"asciidkno", "asciidk", "asciino"}, ENC_ASCII_DKNO, '\n', 8},
811 {{"ibmpc", "pc", "dos"}, ENC_IBMPC, '\n', 8},
812 {{"mac", NULL, NULL}, ENC_MAC, '\r', 8},
813 {{"vms", NULL, NULL}, ENC_VMS, '\n', 8},
814 {{"hp8", NULL, NULL}, ENC_HP8, '\n', 8},
815 {{"koi8", NULL, NULL}, ENC_KOI8, '\n', 8},
816 {{"ps", "PS", NULL}, ENC_PS, '\n', 8},
817 {{"pslatin1", "ISOLatin1Encoding", NULL}, ENC_ISO_8859_1, '\n', 8},
819 {{NULL, NULL, NULL}, 0, 0, 0},
827 static struct option long_options[] =
829 {"columns", required_argument, 0, 0},
830 {"pages", required_argument, 0, 'a'},
831 {"file-align", required_argument, 0, 'A'},
832 {"header", required_argument, 0, 'b'},
833 {"no-header", no_argument, 0, 'B'},
834 {"truncate-lines", no_argument, 0, 'c'},
835 {"line-numbers", optional_argument, 0, 'C'},
836 {"printer", required_argument, 0, 'd'},
837 {"setpagedevice", required_argument, 0, 'D'},
838 {"escapes", optional_argument, 0, 'e'},
839 {"highlight", optional_argument, 0, 'E'},
840 {"font", required_argument, 0, 'f'},
841 {"header-font", required_argument, 0, 'F'},
842 {"print-anyway", no_argument, 0, 'g'},
843 {"fancy-header", optional_argument, 0, 'G'},
844 {"no-job-header", no_argument, 0, 'h'},
845 {"highlight-bars", optional_argument, 0, 'H'},
846 {"indent", required_argument, 0, 'i'},
847 {"filter", required_argument, 0, 'I'},
848 {"borders", no_argument, 0, 'j'},
849 {"page-prefeed", no_argument, 0, 'k'},
850 {"no-page-prefeed", no_argument, 0, 'K'},
851 {"lineprinter", no_argument, 0, 'l'},
852 {"lines-per-page", required_argument, 0, 'L'},
853 {"mail", no_argument, 0, 'm'},
854 {"media", required_argument, 0, 'M'},
855 {"copies", required_argument, 0, 'n'},
856 {"newline", required_argument, 0, 'N'},
857 {"output", required_argument, 0, 'p'},
858 {"missing-characters", no_argument, 0, 'O'},
859 {"quiet", no_argument, 0, 'q'},
860 {"silent", no_argument, 0, 'q'},
861 {"landscape", no_argument, 0, 'r'},
862 {"portrait", no_argument, 0, 'R'},
863 {"baselineskip", required_argument, 0, 's'},
864 {"statusdict", required_argument, 0, 'S'},
865 {"title", required_argument, 0, 't'},
866 {"tabsize", required_argument, 0, 'T'},
867 {"underlay", optional_argument, 0, 'u'},
868 {"nup", required_argument, 0, 'U'},
869 {"verbose", optional_argument, 0, 'v'},
870 {"version", no_argument, 0, 'V'},
871 {"language", required_argument, 0, 'w'},
872 {"option", required_argument, 0, 'W'},
873 {"encoding", required_argument, 0, 'X'},
874 {"no-formfeed", no_argument, 0, 'z'},
875 {"pass-through", no_argument, 0, 'Z'},
877 /* Long options without short counterparts. Next free is 157. */
878 {"color", optional_argument, 0, 142},
879 {"continuous-page-numbers", no_argument, 0, 156},
880 {"download-font", required_argument, 0, 131},
881 {"extended-return-values", no_argument, 0, 154},
882 {"filter-stdin", required_argument, 0, 138},
883 {"footer", required_argument, 0, 155},
884 {"h-column-height", required_argument, 0, 148},
885 {"help", no_argument, 0, 135},
886 {"help-highlight", no_argument, 0, 141},
887 {"highlight-bar-gray", required_argument, 0, 136},
888 {"list-media", no_argument, &list_media, 1},
889 {"margins", required_argument, 0, 144},
890 {"mark-wrapped-lines", optional_argument, 0, 143},
891 {"non-printable-format", required_argument, 0, 134},
892 {"nup-columnwise", no_argument, 0, 152},
893 {"nup-xpad", required_argument, 0, 145},
894 {"nup-ypad", required_argument, 0, 146},
895 {"page-label-format", required_argument, 0, 130},
896 {"ps-level", required_argument, 0, 149},
897 {"printer-options", required_argument, 0, 139},
898 {"rotate-even-pages", no_argument, 0, 150},
899 {"slice", required_argument, 0, 140},
900 {"style", required_argument, 0, 151},
901 {"swap-even-page-margins", no_argument, 0, 153},
902 {"toc", no_argument, &toc, 1},
903 {"word-wrap", no_argument, 0, 147},
904 {"ul-angle", required_argument, 0, 132},
905 {"ul-font", required_argument, 0, 128},
906 {"ul-gray", required_argument, 0, 129},
907 {"ul-position", required_argument, 0, 133},
908 {"ul-style", required_argument, 0, 137},
910 /* Backwards compatiblity options. */
911 {"pretty-print", optional_argument, 0, 'E'},
912 {"help-pretty-print", no_argument, 0, 141},
923 main (int argc, char *argv[])
936 /* Init our dynamic memory buffer. */
937 buffer_init (&buffer);
939 /* Get program's name. */
940 program = strrchr (argv[0], '/');
946 /* Make getopt_long() to use our modified programname. */
949 /* Create the default TOC format string. Wow, this is cool! */
950 /* xgettext:no-c-format */
951 toc_fmt_string = _("$3v $-40N $3% pages $4L lines $E $C");
953 /* Internationalization. */
956 * We want to change only messages (gs do not like decimals in 0,1
960 setlocale (LC_MESSAGES, "");
962 setlocale (LC_CTYPE, "");
964 setlocale (LC_PAPER, "");
968 bindtextdomain (PACKAGE, LOCALEDIR);
969 textdomain (PACKAGE);
972 /* Create date string. */
975 tm = localtime (&tim);
976 memcpy (&run_tm, tm, sizeof (*tm));
978 date_string = xstrdup (asctime (&run_tm));
979 i = strlen (date_string);
980 date_string[i - 1] = '\0';
982 /* Get user's passwd entry. */
983 passwd = getpwuid (getuid ());
985 FATAL ((stderr, _("couldn't get passwd entry for uid=%d: %s"), getuid (),
988 /* Defaults for some options. */
989 media_name = xstrdup ("A4");
990 encoding_name = xstrdup ("88591");
991 npf_name = xstrdup ("octal");
992 page_label_format = xstrdup ("short");
993 ul_style_str = xstrdup ("outline");
994 ul_position = xstrdup ("+0-0");
995 spooler_command = xstrdup ("lpr");
996 queue_param = xstrdup ("-P");
997 no_job_header_switch = xstrdup ("-h");
998 fancy_header_default = xstrdup ("enscript");
999 output_first_line = xstrdup ("%!PS-Adobe-3.0");
1001 /* Check ENSCRIPT_LIBRARY for custom library location. */
1002 cp = getenv ("ENSCRIPT_LIBRARY");
1004 enscript_library = cp;
1006 /* Fill up build-in libpath. */
1008 cp = getenv ("HOME");
1010 cp = passwd->pw_dir;
1012 buffer_clear (&buffer);
1013 buffer_append (&buffer, enscript_library);
1014 buffer_append (&buffer, PATH_SEPARATOR_STR);
1015 buffer_append (&buffer, cp);
1016 buffer_append (&buffer, "/.enscript");
1017 libpath = buffer_copy (&buffer);
1019 /* Defaults for the states filter. */
1021 states_binary = xstrdup ("states"); /* Take it from the user path. */
1023 buffer_clear (&buffer);
1024 buffer_append (&buffer, enscript_library);
1025 buffer_append (&buffer, "/hl/enscript.st");
1026 states_config_file = buffer_copy (&buffer);
1028 states_highlight_style = xstrdup ("emacs");
1030 /* The <cp> holds the user's home directory. */
1031 buffer_clear (&buffer);
1032 buffer_append (&buffer, cp);
1033 buffer_append (&buffer, "/.enscript");
1034 buffer_append (&buffer, PATH_SEPARATOR_STR);
1035 buffer_append (&buffer, enscript_library);
1036 buffer_append (&buffer, "/hl");
1037 states_path = buffer_copy (&buffer);
1039 /* Initialize resource sets. */
1040 res_fonts = strhash_init ();
1041 download_fonts = strhash_init ();
1042 pagedevice = strhash_init ();
1043 statusdict = strhash_init ();
1044 user_strings = strhash_init ();
1048 * Read configuration files.
1051 /* Global config. */
1052 #define CFG_FILE_NAME "enscript.cfg"
1053 if (!read_config (SYSCONFDIR, CFG_FILE_NAME))
1055 int saved_errno = errno;
1057 /* Try to read it from our library directory. This is mostly
1058 the case for the micro ports. */
1059 if (!read_config (enscript_library, CFG_FILE_NAME))
1061 /* Try `enscript_library/../../etc/'. This is the case for
1062 installations which set the prefix after the compilation
1063 and our SYSCONFDIR points to wrong directory. */
1065 buffer_clear (&buffer);
1066 buffer_append (&buffer, enscript_library);
1067 buffer_append (&buffer, "/../../etc");
1069 if (!read_config (buffer_ptr (&buffer), CFG_FILE_NAME))
1071 /* Maybe we are not installed yet, let's try `../lib'
1073 if (!read_config ("../lib", CFG_FILE_NAME)
1074 && !read_config ("../../lib", CFG_FILE_NAME))
1076 /* No luck, report error from the original config file. */
1077 ERROR ((stderr, _("couldn't read config file \"%s/%s\": %s"),
1078 enscript_library, CFG_FILE_NAME,
1079 strerror (saved_errno)));
1081 _("I did also try the following directories:")));
1082 ERROR ((stderr, _("\t%s"), SYSCONFDIR));
1083 ERROR ((stderr, _("\t%s"), enscript_library));
1084 ERROR ((stderr, _("\t%s"), buffer_ptr (&buffer)));
1085 ERROR ((stderr, _("\t../lib")));
1086 ERROR ((stderr, _("\t../../lib")));
1088 _("This is probably an installation error. Please, try to rebuild:")));
1089 ERROR ((stderr, _("\tmake distclean")));
1090 ERROR ((stderr, _("\t./configure --prefix=PREFIX")));
1091 ERROR ((stderr, _("\tmake")));
1092 ERROR ((stderr, _("\tmake check")));
1093 ERROR ((stderr, _("\tmake install")));
1094 ERROR ((stderr, _("or set the environment variable `ENSCRIPT_LIBRARY'"
1095 " to point to your library directory.")));
1099 /* Ok, we are not installed yet. Here is a small kludge
1100 to conform the GNU coding standards: we must be able
1101 to run without being installed, so we must append the
1102 `../lib' and `../../lib' directories to the libpath.
1103 The later allows us to be run form the `src/tests'
1105 buffer_clear (&buffer);
1106 buffer_append (&buffer, libpath);
1107 buffer_append (&buffer, PATH_SEPARATOR_STR);
1108 buffer_append (&buffer, "../lib");
1109 buffer_append (&buffer, PATH_SEPARATOR_STR);
1110 buffer_append (&buffer, "../../lib");
1113 libpath = buffer_copy (&buffer);
1119 read_config (SYSCONFDIR, "enscriptsite.cfg");
1121 /* Personal config. */
1122 read_config (cp, ".enscriptrc");
1128 /* Environment variables. */
1129 handle_env_options ("ENSCRIPT");
1130 handle_env_options ("GENSCRIPT");
1132 /* Command line arguments. */
1133 handle_options (argc, argv);
1136 * Check options which have some validity conditions.
1140 * Save the user-specified escape char so ^@escape{default} knows
1143 default_escape_char = escape_char;
1145 /* Input encoding. */
1148 for (i = 0; !found && encodings[i].names[0]; i++)
1149 for (j = 0; j < 3; j++)
1150 if (encodings[i].names[j] != NULL && MATCH (encodings[i].names[j],
1153 /* Found a match for this encoding. Use the first
1156 encoding = encodings[i].encoding;
1157 xfree (encoding_name);
1158 encoding_name = xstrdup (encodings[i].names[0]);
1161 nl = encodings[i].nl;
1162 bs = encodings[i].bs;
1167 FATAL ((stderr, _("unknown encoding: %s"), encoding_name));
1171 /* Default font for landscape, 2 column printing is Courier 7. */
1172 if (!user_body_font_defined && landscape && num_columns > 1)
1173 Fpt.w = Fpt.h = 7.0;
1175 /* Cache for font AFM information. */
1176 afm_cache = strhash_init ();
1177 afm_info_cache = strhash_init ();
1179 /* Open AFM library. */
1180 afm_error = afm_create (afm_path, verbose, &afm);
1181 if (afm_error != AFM_SUCCESS)
1185 afm_error_to_string (afm_error, buf);
1186 FATAL ((stderr, _("couldn't open AFM library: %s"), buf));
1190 * Save default Fpt and Fname since special escape 'font' can change
1191 * it and later we might want to switch back to the "default" font.
1193 default_Fpt.w = Fpt.w;
1194 default_Fpt.h = Fpt.h;
1195 default_Fname = Fname;
1196 default_Fencoding = encoding;
1198 /* Register that document uses at least these fonts. */
1199 strhash_put (res_fonts, Fname, strlen (Fname) + 1, NULL, NULL);
1200 strhash_put (res_fonts, HFname, strlen (HFname) + 1, NULL, NULL);
1202 /* As a default, download both named fonts. */
1203 strhash_put (download_fonts, Fname, strlen (Fname) + 1, NULL, NULL);
1204 strhash_put (download_fonts, HFname, strlen (HFname) + 1, NULL, NULL);
1206 /* Read font's character widths and character types. */
1209 /* Count the line indentation. */
1210 line_indent = parse_float (line_indent_spec, 1, 1);
1212 /* List media names. */
1215 printf (_("known media:\n\
1216 name width\theight\tllx\tlly\turx\tury\n\
1217 ------------------------------------------------------------\n"));
1218 for (mentry = media_names; mentry; mentry = mentry->next)
1219 printf ("%-16s %d\t%d\t%d\t%d\t%d\t%d\n",
1220 mentry->name, mentry->w, mentry->h,
1221 mentry->llx, mentry->lly, mentry->urx, mentry->ury);
1222 /* Exit after listing. */
1227 for (mentry = media_names; mentry; mentry = mentry->next)
1228 if (strcmp (media_name, mentry->name) == 0)
1234 FATAL ((stderr, _("do not know anything about media \"%s\""), media_name));
1238 /* Adjust marginals. */
1239 for (i = 0; i < 4; i++)
1241 if (*margins_spec == '\0')
1245 if (*margins_spec == ':')
1251 j = atoi (margins_spec);
1252 for (; *margins_spec != ':' && *margins_spec != '\0'; margins_spec++)
1254 if (*margins_spec == ':')
1264 media->urx = media->w - j;
1268 media->ury = media->h - j;
1271 case 3: /* bottom */
1278 _("set new marginals for media `%s' (%dx%d): llx=%d, lly=%d, urx=%d, ury=%d\n"),
1279 media->name, media->w, media->h, media->llx, media->lly,
1280 media->urx, media->ury));
1283 /* Page label format. */
1284 if (MATCH (page_label_format, "short"))
1285 page_label = LABEL_SHORT;
1286 else if (MATCH (page_label_format, "long"))
1287 page_label = LABEL_LONG;
1289 FATAL ((stderr, _("illegal page label format \"%s\""), page_label_format));
1291 /* Non-printable format. */
1292 if (MATCH (npf_name, "space"))
1293 non_printable_format = NPF_SPACE;
1294 else if (MATCH (npf_name, "questionmark"))
1295 non_printable_format = NPF_QUESTIONMARK;
1296 else if (MATCH (npf_name, "caret"))
1297 non_printable_format = NPF_CARET;
1298 else if (MATCH (npf_name, "octal"))
1299 non_printable_format = NPF_OCTAL;
1301 FATAL ((stderr, _("illegal non-printable format \"%s\""), npf_name));
1303 /* Mark wrapped lines style. */
1304 if (mark_wrapped_lines_style_name)
1306 if (MATCH (mark_wrapped_lines_style_name, "none"))
1307 mark_wrapped_lines_style = MWLS_NONE;
1308 else if (MATCH (mark_wrapped_lines_style_name, "plus"))
1309 mark_wrapped_lines_style = MWLS_PLUS;
1310 else if (MATCH (mark_wrapped_lines_style_name, "box"))
1311 mark_wrapped_lines_style = MWLS_BOX;
1312 else if (MATCH (mark_wrapped_lines_style_name, "arrow"))
1313 mark_wrapped_lines_style = MWLS_ARROW;
1315 FATAL ((stderr, _("illegal style for wrapped line marker: \"%s\""),
1316 mark_wrapped_lines_style_name));
1319 /* Count N-up stuffs. */
1325 FATAL ((stderr, _("illegal N-up argument: %d"), nup));
1330 FATAL ((stderr, _("N-up argument must be power of 2: %d"), nup));
1337 nup_rows = nup_exp / 2 * 2;
1340 nup_columns = (nup_exp + 1) / 2 * 2;
1341 if (nup_columns == 0)
1344 nup_landscape = nup_exp & 0x1;
1348 * Count output media dimensions.
1353 d_page_w = media->ury - media->lly;
1354 d_page_h = media->urx - media->llx;
1358 d_page_w = media->urx - media->llx;
1359 d_page_h = media->ury - media->lly;
1363 * Count N-up page width, height and scale.
1368 nup_width = media->ury - media->lly;
1369 nup_height = media->urx - media->llx;
1373 nup_width = media->urx - media->llx;
1374 nup_height = media->ury - media->lly;
1380 w = ((double) nup_width - (nup_columns - 1) * nup_xpad) / nup_columns;
1381 h = ((double) nup_height - (nup_rows - 1) * nup_ypad) / nup_rows;
1386 w = w / (media->urx - media->llx);
1387 h = h / (media->ury - media->lly);
1389 nup_scale = w < h ? w : h;
1393 * Underlay (this must come after output media dimensions, because
1394 * `underlay position' needs them).
1396 if (underlay != NULL)
1398 strhash_put (res_fonts, ul_font, strlen (ul_font) + 1, NULL, NULL);
1399 underlay = escape_string (underlay);
1402 /* Underlay X-coordinate. */
1403 ul_x = strtod (ul_position, &cp);
1404 if (cp == ul_position)
1407 FATAL ((stderr, _("malformed underlay position: %s"), ul_position));
1409 if (ul_position[0] == '-')
1412 /* Underlay Y-coordinate. */
1413 ul_y = strtod (cp, &cp2);
1415 goto malformed_position;
1419 /* Underlay Angle. */
1421 /* No angle given, count the default. */
1422 ul_angle = (atan2 (-d_page_h, d_page_w) / 3.14159265 * 180);
1424 /* Underlay style. */
1425 if (strcmp (ul_style_str, "outline") == 0)
1426 ul_style = UL_STYLE_OUTLINE;
1427 else if (strcmp (ul_style_str, "filled") == 0)
1428 ul_style = UL_STYLE_FILLED;
1430 FATAL ((stderr, _("illegal underlay style: %s"), ul_style_str));
1433 * Header. Note! The header attributes can be changed from
1434 * the `.hdr' files, these are only the defaults.
1437 d_header_w = d_page_w;
1445 d_header_h = HFpt.h * 1.5;
1453 /* Help highlight. */
1456 /* Create description with states. */
1457 printf (_("Highlighting is supported for the following languages and file formats:\n\n"));
1460 buffer_clear (&buffer);
1461 buffer_append (&buffer, states_binary);
1462 buffer_append (&buffer, " -f \"");
1463 buffer_append (&buffer, states_config_file);
1464 buffer_append (&buffer, "\" -p \"");
1465 buffer_append (&buffer, states_path);
1466 buffer_append (&buffer, "\" -s describe_languages ");
1467 buffer_append (&buffer, enscript_library);
1468 buffer_append (&buffer, "/hl/*.st");
1470 system (buffer_ptr (&buffer));
1475 * And now to the main business. The actual input file processing
1476 * is divided to two parts: PostScript generation and everything else.
1477 * The PostScript generation is handled in the conventional way, we
1478 * process the input and generate PostScript. However all other input
1479 * languages will be handled with States, we only pass enscript's
1480 * options to the states pre-filter and dump output.
1482 if (output_language_pass_through)
1488 /* The States output generation. */
1490 /* Resolve the start state. */
1492 start_state = hl_start_state;
1496 start_state = "passthrough";
1498 /* Create the states command. */
1502 buffer_append (&cmd, states_binary);
1503 buffer_append (&cmd, " -f \"");
1504 buffer_append (&cmd, states_config_file);
1505 buffer_append (&cmd, "\" -p \"");
1506 buffer_append (&cmd, states_path);
1507 buffer_append (&cmd, "\" ");
1510 buffer_append (&cmd, "-v ");
1514 buffer_append (&cmd, "-s");
1515 buffer_append (&cmd, start_state);
1516 buffer_append (&cmd, " ");
1519 buffer_append (&cmd, "-Dcolor=");
1520 buffer_append (&cmd, states_color ? "1" : "0");
1521 buffer_append (&cmd, " ");
1523 buffer_append (&cmd, "-Dstyle=");
1524 buffer_append (&cmd, states_highlight_style);
1525 buffer_append (&cmd, " ");
1527 buffer_append (&cmd, "-Dlanguage=");
1528 buffer_append (&cmd, output_language);
1529 buffer_append (&cmd, " ");
1531 buffer_append (&cmd, "-Dnum_input_files=");
1532 sprintf (intbuf, "%d", optind == argc ? 1 : argc - optind);
1533 buffer_append (&cmd, intbuf);
1534 buffer_append (&cmd, " ");
1536 buffer_append (&cmd, "-Ddocument_title=\'");
1537 if ((cp = shell_escape (title)) != NULL)
1539 buffer_append (&cmd, cp);
1542 buffer_append (&cmd, "\' ");
1544 buffer_append (&cmd, "-Dtoc=");
1545 buffer_append (&cmd, toc ? "1" : "0");
1547 /* Additional options for states? */
1548 if (helper_options['s'])
1550 Buffer *opts = helper_options['s'];
1552 buffer_append (&cmd, " ");
1553 buffer_append_len (&cmd, buffer_ptr (opts), buffer_len (opts));
1556 /* Append input files. */
1557 for (i = optind; i < argc; i++)
1560 if ((cp = shell_escape (argv[i])) != NULL)
1562 buffer_append (&cmd, " \'");
1563 buffer_append (&cmd, cp);
1564 buffer_append (&cmd, "\'");
1569 /* And do the job. */
1570 if (is_open (&is, stdin, NULL, buffer_ptr (&cmd)))
1572 open_output_file ();
1573 process_file ("unused", &is, 0);
1577 buffer_uninit (&cmd);
1581 /* The conventional way. */
1588 /* Create a highlight input filter. */
1589 buffer_clear (&buffer);
1590 buffer_append (&buffer, states_binary);
1591 buffer_append (&buffer, " -f \"");
1592 buffer_append (&buffer, states_config_file);
1593 buffer_append (&buffer, "\" -p \"");
1594 buffer_append (&buffer, states_path);
1595 buffer_append (&buffer, "\"");
1598 buffer_append (&buffer, " -v");
1602 buffer_append (&buffer, " -s ");
1603 buffer_append (&buffer, hl_start_state);
1606 buffer_append (&buffer, " -Dcolor=");
1607 buffer_append (&buffer, states_color ? "1" : "0");
1609 buffer_append (&buffer, " -Dstyle=");
1610 buffer_append (&buffer, states_highlight_style);
1612 buffer_append (&buffer, " -Dfont_spec=");
1613 buffer_append (&buffer, Fname);
1614 sprintf (fbuf, "@%g/%g", Fpt.w, Fpt.h);
1615 buffer_append (&buffer, fbuf);
1617 /* Additional options for states? */
1618 if (helper_options['s'])
1620 Buffer *opts = helper_options['s'];
1622 buffer_append (&buffer, " ");
1623 buffer_append_len (&buffer,
1624 buffer_ptr (opts), buffer_len (opts));
1627 buffer_append (&buffer, " \'%s\'");
1629 input_filter = buffer_copy (&buffer);
1630 input_filter_stdin = "-";
1633 /* Table of Contents. */
1636 toc_fp = tmpfile ();
1638 FATAL ((stderr, _("couldn't create temporary toc file: %s"),
1649 /* stdin's modification time is the current time. */
1650 memcpy (&mod_tm, &run_tm, sizeof (run_tm));
1652 if (is_open (&is, stdin, NULL, input_filter))
1654 /* Open output file. */
1655 open_output_file ();
1656 process_file (title_given ? title : "", &is, 0);
1662 for (; optind < argc; optind++)
1664 if (is_open (&is, NULL, argv[optind], input_filter))
1666 struct stat stat_st;
1668 /* Get modification time. */
1669 if (stat (argv[optind], &stat_st) == 0)
1671 tim = stat_st.st_mtime;
1672 tm = localtime (&tim);
1673 memcpy (&mod_tm, tm, sizeof (*tm));
1676 * Open output file. Output file opening is delayed to
1677 * this point so we can optimize the case when a
1678 * non-existing input file is printed => we do nothing.
1680 open_output_file ();
1682 process_file (argv[optind], &is, 0);
1685 ERROR ((stderr, _("couldn't stat input file \"%s\": %s"),
1694 /* Table of Contents. */
1697 /* This is really cool... */
1699 /* Set the printing options for toc. */
1701 special_escapes = 1;
1704 if (fseek (toc_fp, 0, SEEK_SET) != 0)
1705 FATAL ((stderr, _("couldn't rewind toc file: %s"),
1708 memcpy (&mod_tm, &run_tm, sizeof (run_tm));
1709 if (is_open (&is, toc_fp, NULL, NULL))
1711 process_file (_("Table of Contents"), &is, 1);
1716 /* Give trailer a chance to dump itself. */
1720 * Append ^D to the end of the output? Note! It must be ^D followed
1723 if (ofp != NULL && append_ctrl_D)
1724 fprintf (ofp, "\004\n");
1727 /* Close output file. */
1728 close_output_file ();
1730 /* Tell how things went. */
1734 * The value of <ofp> is not reset in close_output_file(),
1735 * this is ugly but it saves one flag.
1737 MESSAGE (0, (stderr, _("no output generated\n")));
1739 else if (output_language_pass_through)
1741 if (output_file == OUTPUT_FILE_NONE)
1742 MESSAGE (0, (stderr, _("output sent to %s\n"),
1743 printer ? printer : _("printer")));
1745 MESSAGE (0, (stderr, _("output left in %s\n"),
1746 output_file == OUTPUT_FILE_STDOUT ? "-" : output_file));
1750 unsigned int real_total_pages;
1754 if (total_pages > 0)
1755 real_total_pages = (total_pages - 1) / nup + 1;
1757 real_total_pages = 0;
1760 real_total_pages = total_pages;
1762 /* We did something, tell what. */
1764 snprintf(message, sizeof message, "%s%s%s%s%s",
1766 ngettext("%d page", "%d pages", real_total_pages),
1768 ngettext("%d copy", "%d copies", num_copies),
1770 MESSAGE (0, (stderr, message, real_total_pages, num_copies));
1772 if (output_file == OUTPUT_FILE_NONE)
1773 MESSAGE (0, (stderr, _(" sent to %s\n"),
1774 printer ? printer : _("printer")));
1776 MESSAGE (0, (stderr, _(" left in %s\n"),
1777 output_file == OUTPUT_FILE_STDOUT ? "-" : output_file));
1778 if (num_truncated_lines)
1781 MESSAGE (0, (stderr,
1782 ngettext("%d line was %s\n",
1783 "%d lines were %s\n",
1784 num_truncated_lines),
1785 num_truncated_lines,
1786 line_end == LE_TRUNCATE
1787 ? _("truncated") : _("wrapped")));
1790 if (num_missing_chars)
1793 MESSAGE (0, (stderr,
1794 ngettext("%d character was missing\n",
1795 "%d characters were missing\n",
1797 num_missing_chars));
1798 if (list_missing_characters)
1800 MESSAGE (0, (stderr, _("missing character codes (decimal):\n")));
1801 do_list_missing_characters (missing_chars);
1805 if (num_non_printable_chars)
1808 MESSAGE (0, (stderr,
1809 ngettext("%d non-printable character\n",
1810 "%d non-printable characters\n",
1811 num_non_printable_chars),
1812 num_non_printable_chars));
1813 if (list_missing_characters)
1815 MESSAGE (0, (stderr,
1816 _("non-printable character codes (decimal):\n")));
1817 do_list_missing_characters (non_printable_chars);
1822 /* Uninit our dynamic memory buffer. */
1823 buffer_uninit (&buffer);
1825 /* Return the extended return values only if requested. */
1826 if (!extended_return_values)
1829 /* This is the end. */
1842 /* Output file has already been opened, do nothing. */
1845 if (output_file == OUTPUT_FILE_NONE)
1847 char spooler_options[512];
1849 /* Format spooler options. */
1850 spooler_options[0] = '\0';
1852 strcat (spooler_options, "-m ");
1855 strcat (spooler_options, no_job_header_switch);
1856 strcat (spooler_options, " ");
1858 if (printer_options)
1859 strcat (spooler_options, printer_options);
1862 ofp = printer_open (spooler_command, spooler_options, queue_param,
1863 printer, &printer_context);
1865 FATAL ((stderr, _("couldn't open printer `%s': %s"), printer,
1868 else if (output_file == OUTPUT_FILE_STDOUT)
1872 ofp = fopen (output_file, "w");
1874 FATAL ((stderr, _("couldn't create output file \"%s\": %s"),
1875 output_file, strerror (errno)));
1881 close_output_file ()
1884 /* Output file hasn't been opened, we are done. */
1887 if (output_file == OUTPUT_FILE_NONE)
1888 printer_close (printer_context);
1889 else if (output_file != OUTPUT_FILE_STDOUT)
1891 FATAL ((stderr, _("couldn't close output file \"%s\": %s"),
1892 output_file, strerror (errno)));
1894 /* We do not reset <ofp> since its value is needed in diagnostigs. */
1899 handle_env_options (char *var)
1907 string = getenv (var);
1911 MESSAGE (2, (stderr, "handle_env_options(): %s=\"%s\"\n", var, string));
1913 /* Copy string so we can modify it in place. */
1914 str = xstrdup (string);
1917 * We can count this, each option takes at least 1 character and one
1918 * space. We also need one for program's name and one for the
1921 argc = (strlen (str) + 1) / 2 + 2;
1922 argv = xcalloc (argc, sizeof (char *));
1924 /* Set program name. */
1926 argv[argc++] = program;
1928 /* Split string and set arguments to argv array. */
1932 /* Skip leading whitespace. */
1933 for (; str[i] && isspace (str[i]); i++)
1938 /* Check for quoted arguments. */
1939 if (str[i] == '"' || str[i] == '\'')
1941 int endch = str[i++];
1943 argv[argc++] = str + i;
1945 /* Skip until we found the end of the quotation. */
1946 for (; str[i] && str[i] != endch; i++)
1949 FATAL ((stderr, _("syntax error in option string %s=\"%s\":\n\
1950 missing end of quotation: %c"), var, string, endch));
1956 argv[argc++] = str + i;
1958 /* Skip until whitespace if found. */
1959 for (; str[i] && !isspace (str[i]); i++)
1966 /* argv[argc] must be NULL. */
1969 MESSAGE (2, (stderr, "found following options (argc=%d):\n", argc));
1970 for (i = 0; i < argc; i++)
1971 MESSAGE (2, (stderr, "%3d = \"%s\"\n", i, argv[i]));
1973 /* Process options. */
1974 handle_options (argc, argv);
1976 /* Check that all got processed. */
1981 _("warning: didn't process following options from \
1982 environment variable %s:\n"),
1984 for (; optind < argc; optind++)
1985 MESSAGE (0, (stderr, _(" option %d = \"%s\"\n"), optind,
1993 * <str> must not be freed, since some global variables can point to
2000 handle_options (int argc, char *argv[])
2010 int option_index = 0;
2014 c = getopt_long (argc, argv,
2015 "#:123456789a:A:b:BcC::d:D:e::E::f:F:gGhH::i:I:jJ:kKlL:mM:n:N:o:Op:P:qrRs:S:t:T:u::U:vVw:W:X:zZ",
2016 long_options, &option_index);
2023 case 0: /* Long option found. */
2024 cp = long_options[option_index].name;
2026 if (strcmp (cp, "columns") == 0)
2028 num_columns = atoi (optarg);
2029 if (num_columns < 1)
2031 _("number of columns must be larger than zero")));
2035 /* Short options. */
2037 case '1': /* 1 column */
2038 case '2': /* 2 columns */
2039 case '3': /* 3 columns */
2040 case '4': /* 4 columns */
2041 case '5': /* 5 columns */
2042 case '6': /* 6 columns */
2043 case '7': /* 7 columns */
2044 case '8': /* 8 columns */
2045 case '9': /* 9 columns */
2046 num_columns = c - '0';
2049 case 'a': /* pages */
2050 prange = (PageRange *) xcalloc (1, sizeof (PageRange));
2052 if (strcmp (optarg, "odd") == 0)
2054 else if (strcmp (optarg, "even") == 0)
2058 cp = strchr (optarg, '-');
2061 if (optarg[0] == '-')
2063 prange->end = atoi (optarg + 1);
2064 else if (cp[1] == '\0')
2067 prange->start = atoi (optarg);
2068 prange->end = (unsigned int) -1;
2073 prange->start = atoi (optarg);
2074 prange->end = atoi (cp + 1);
2079 prange->start = prange->end = atoi (optarg);
2082 prange->next = page_ranges;
2083 page_ranges = prange;
2086 case 'A': /* file alignment */
2087 file_align = atoi (optarg);
2088 if (file_align == 0)
2089 FATAL ((stderr, _("file alignment must be larger than zero")));
2092 case 'b': /* page header */
2093 page_header = optarg;
2096 case 'B': /* no page headers */
2100 case 'c': /* truncate (cut) long lines */
2101 line_end = LE_TRUNCATE;
2104 case 'C': /* line numbers */
2107 start_line_number = atoi (optarg);
2110 case 'd': /* specify printer */
2113 printer = xstrdup (optarg);
2114 output_file = OUTPUT_FILE_NONE;
2117 case 'D': /* setpagedevice */
2118 parse_key_value_pair (pagedevice, optarg);
2121 case 'e': /* special escapes */
2122 special_escapes = 1;
2125 /* Specify the escape character. */
2126 if (isdigit (optarg[0]))
2127 /* As decimal, octal, or hexadicimal number. */
2128 escape_char = (int) strtoul (optarg, NULL, 0);
2130 /* As character directly. */
2131 escape_char = ((unsigned char *) optarg)[0];
2135 case 'E': /* highlight */
2137 special_escapes = 1;
2139 hl_start_state = optarg;
2142 case 'f': /* font */
2143 if (!parse_font_spec (optarg, &Fname, &Fpt, NULL))
2144 FATAL ((stderr, _("malformed font spec: %s"), optarg));
2145 user_body_font_defined = 1;
2148 case 'F': /* header font */
2149 if (!parse_font_spec (optarg, &HFname, &HFpt, NULL))
2150 FATAL ((stderr, _("malformed font spec: %s"), optarg));
2153 case 'g': /* print anyway */
2157 case 'G': /* fancy header */
2160 fancy_header_name = optarg;
2162 fancy_header_name = fancy_header_default;
2164 if (!file_existsp (fancy_header_name, ".hdr"))
2166 _("couldn't find header definition file \"%s.hdr\""),
2167 fancy_header_name));
2170 case 'h': /* no job header */
2174 case 'H': /* highlight bars */
2176 highlight_bars = atoi (optarg);
2181 case 'i': /* line indent */
2182 line_indent_spec = optarg;
2185 case 'I': /* input filter */
2186 input_filter = optarg;
2189 case 'j': /* borders */
2193 case 'k': /* enable page prefeed */
2197 case 'K': /* disable page prefeed */
2201 case 'l': /* emulate lineprinter */
2202 lines_per_page = 66;
2206 case 'L': /* lines per page */
2207 lines_per_page = atoi (optarg);
2208 if (lines_per_page <= 0)
2210 _("must print at least one line per each page: %s"),
2214 case 'm': /* send mail upon completion */
2218 case 'M': /* select output media */
2219 media_name = xstrdup (optarg);
2222 case 'n': /* num copies */
2224 num_copies = atoi (optarg);
2227 case 'N': /* newline character */
2228 if (!(optarg[0] == 'n' || optarg[0] == 'r') || optarg[1] != '\0')
2230 fprintf (stderr, _("%s: illegal newline character specifier: \
2231 '%s': expected 'n' or 'r'\n"),
2235 if (optarg[0] == 'n')
2242 case 'p': /* output file */
2243 /* Check output file "-". */
2244 if (strcmp (optarg, "-") == 0)
2245 output_file = OUTPUT_FILE_STDOUT;
2247 output_file = optarg;
2250 case 'O': /* list missing characters */
2251 list_missing_characters = 1;
2254 case 'q': /* quiet */
2259 case 'r': /* landscape */
2263 case 'R': /* portrait */
2267 case 's': /* baselineskip */
2268 baselineskip = atof (optarg);
2271 case 'S': /* statusdict */
2272 parse_key_value_pair (statusdict, optarg);
2275 case 't': /* title */
2281 case 'T': /* tabulator size */
2282 tabsize = atoi (optarg);
2287 case 'u': /* underlay */
2292 nup = atoi (optarg);
2295 case 'v': /* verbose */
2297 verbose = atoi (optarg);
2303 case 'V': /* version */
2308 case 'w': /* output language */
2309 output_language = optarg;
2310 if (strcmp (output_language, "PostScript") != 0)
2311 /* Other output languages are handled with states. */
2312 output_language_pass_through = 1;
2315 case 'W': /* a helper application option */
2316 cp = strchr (optarg, ',');
2319 _("malformed argument `%s' for option -W, --option: \
2323 if (cp - optarg != 1)
2324 FATAL ((stderr, _("helper application specification must be \
2325 single character: %s"),
2328 /* Take the index of the helper application and update `cp'
2329 to point to the beginning of the option. */
2333 if (helper_options[i] == NULL)
2334 helper_options[i] = buffer_alloc ();
2337 /* We already had some options for this helper
2338 application. Let's separate these arguments. */
2339 buffer_append (helper_options[i], " ");
2342 /* Add this new option. */
2343 buffer_append (helper_options[i], cp);
2346 case 'X': /* input encoding */
2347 xfree (encoding_name);
2348 encoding_name = xstrdup (optarg);
2351 case 'z': /* no form feeds */
2352 interpret_formfeed = 0;
2355 case 'Z': /* pass through */
2359 case 128: /* underlay font */
2360 if (!parse_font_spec (optarg, &ul_font, &ul_ptsize, NULL))
2361 FATAL ((stderr, _("malformed font spec: %s"), optarg));
2364 case 129: /* underlay gray */
2365 ul_gray = atof (optarg);
2368 case 130: /* page label format */
2369 xfree (page_label_format);
2370 page_label_format = xstrdup (optarg);
2373 case 131: /* download font */
2374 strhash_put (download_fonts, optarg, strlen (optarg) + 1, NULL,
2378 case 132: /* underlay angle */
2379 ul_angle = atof (optarg);
2383 case 133: /* underlay position */
2384 xfree (ul_position);
2385 ul_position = xstrdup (optarg);
2389 case 134: /* non-printable format */
2391 npf_name = xstrdup (optarg);
2394 case 135: /* help */
2399 case 136: /* highlight bar gray */
2400 highlight_bar_gray = atof (optarg);
2403 case 137: /* underlay style */
2404 xfree (ul_style_str);
2405 ul_style_str = xstrdup (optarg);
2408 case 138: /* filter stdin */
2409 input_filter_stdin = optarg;
2412 case 139: /* extra options for the printer spooler */
2413 printer_options = optarg;
2416 case 140: /* slicing */
2418 slice = atoi (optarg);
2420 FATAL ((stderr, _("slice must be greater than zero")));
2423 case 141: /* help-highlight */
2427 case 142: /* States color? */
2431 states_color = atoi (optarg);
2434 case 143: /* mark-wrapped-lines */
2437 xfree (mark_wrapped_lines_style_name);
2438 mark_wrapped_lines_style_name = xstrdup (optarg);
2441 /* Set the system default. */
2442 mark_wrapped_lines_style = MWLS_BOX;
2445 case 144: /* adjust margins */
2446 margins_spec = optarg;
2449 case 145: /* N-up x-pad */
2450 nup_xpad = atoi (optarg);
2453 case 146: /* N-up y-pad */
2454 nup_ypad = atoi (optarg);
2457 case 147: /* word wrap */
2458 line_end = LE_WORD_WRAP;
2461 case 148: /* horizontal column height */
2462 horizontal_column_height = atof (optarg);
2463 formfeed_type = FORMFEED_HCOLUMN;
2466 case 149: /* PostScript language level */
2467 pslevel = atoi (optarg);
2470 case 150: /* rotate even-numbered pages */
2471 rotate_even_pages = 1;
2474 case 151: /* highlight style */
2475 xfree (states_highlight_style);
2476 states_highlight_style = xstrdup (optarg);
2479 case 152: /* N-up colunwise */
2483 case 153: /* swap even page margins */
2484 swap_even_page_margins = 1;
2487 case 154: /* extended return values */
2488 extended_return_values = 1;
2491 case 155: /* footer */
2492 page_footer = optarg;
2495 case 156: /* continuous page numbers */
2496 continuous_page_numbers = 1;
2499 case '?': /* Errors found during getopt_long(). */
2501 fprintf (stderr, _("Try `%s --help' for more information.\n"),
2507 printf ("Hey! main() didn't handle option \"%c\" (%d)", c, c);
2509 printf (" with arg %s", optarg);
2511 FATAL ((stderr, "This is a bug!"));
2522 Usage: %s [OPTION]... [FILE]...\n\
2523 Mandatory arguments to long options are mandatory for short options too.\n\
2524 -# an alias for option -n, --copies\n\
2525 -1 same as --columns=1\n\
2526 -2 same as --columns=2\n\
2527 --columns=NUM specify the number of columns per page\n\
2528 -a, --pages=PAGES specify which pages are printed\n\
2529 -A, --file-align=ALIGN align separate input files to ALIGN\n\
2530 -b, --header=HEADER set page header\n\
2531 -B, --no-header no page headers\n\
2532 -c, --truncate-lines cut long lines (default is to wrap)\n\
2533 -C[START], --line-numbers[=START]\n\
2534 precede each line with its line number\n\
2535 -d an alias for option --printer\n\
2536 -D, --setpagedevice=KEY[:VALUE]\n\
2537 pass a page device definition to output\n\
2538 -e[CHAR], --escapes[=CHAR] enable special escape interpretation\n"),
2542 -E[LANG], --highlight[=LANG] highlight source code\n"));
2545 -f, --font=NAME use font NAME for body text\n\
2546 -F, --header-font=NAME use font NAME for header texts\n\
2547 -g, --print-anyway nothing (compatibility option)\n\
2548 -G same as --fancy-header\n\
2549 --fancy-header[=NAME] select fancy page header\n\
2550 -h, --no-job-header suppress the job header page\n\
2551 -H[NUM], --highlight-bars[=NUM] specify how high highlight bars are\n\
2552 -i, --indent=NUM set line indent to NUM characters\n\
2553 -I, --filter=CMD read input files through input filter CMD\n\
2554 -j, --borders print borders around columns\n\
2555 -J, an alias for option --title\n\
2556 -k, --page-prefeed enable page prefeed\n\
2557 -K, --no-page-prefeed disable page prefeed\n\
2558 -l, --lineprinter simulate lineprinter, this is an alias for:\n\
2559 --lines-per-page=66, --no-header, --portrait,\n\
2563 -L, --lines-per-page=NUM specify how many lines are printed on each page\n\
2564 -m, --mail send mail upon completion\n\
2565 -M, --media=NAME use output media NAME\n\
2566 -n, --copies=NUM print NUM copies of each page\n\
2567 -N, --newline=NL select the newline character. Possible\n\
2568 values for NL are: n (`\\n') and r (`\\r').\n\
2569 -o an alias for option --output\n\
2570 -O, --missing-characters list missing characters\n\
2571 -p, --output=FILE leave output to file FILE. If FILE is `-',\n\
2572 leave output to stdout.\n\
2573 -P, --printer=NAME print output to printer NAME\n\
2574 -q, --quiet, --silent be really quiet\n\
2575 -r, --landscape print in landscape mode\n\
2576 -R, --portrait print in portrait mode\n"));
2579 -s, --baselineskip=NUM set baselineskip to NUM\n\
2580 -S, --statusdict=KEY[:VALUE]\n\
2581 pass a statusdict definition to the output\n\
2582 -t, --title=TITLE set banner page's job title to TITLE. Option\n\
2583 sets also the name of the input file stdin.\n\
2584 -T, --tabsize=NUM set tabulator size to NUM\n\
2585 -u[TEXT], --underlay[=TEXT] print TEXT under every page\n\
2586 -U, --nup=NUM print NUM logical pages on each output page\n\
2587 -v, --verbose tell what we are doing\n\
2588 -V, --version print version number\n\
2589 -w, --language=LANG set output language to LANG\n\
2590 -W, --options=APP,OPTION pass option OPTION to helper application APP\n\
2591 -X, --encoding=NAME use input encoding NAME\n\
2592 -z, --no-formfeed do not interpret form feed characters\n\
2593 -Z, --pass-through pass through PostScript and PCL files\n\
2594 without any modifications\n"));
2596 printf (_("Long-only options:\n\
2597 --color[=bool] create color outputs with states\n\
2598 --continuous-page-numbers count page numbers across input files. Don't\n\
2599 restart numbering at beginning of each file.\n\
2600 --download-font=NAME download font NAME\n\
2601 --extended-return-values enable extended return values\n\
2602 --filter-stdin=NAME specify how stdin is shown to the input filter\n\
2603 --footer=FOOTER set page footer\n\
2604 --h-column-height=HEIGHT set the horizontal column height to HEIGHT\n\
2605 --help print this help and exit\n"));
2608 --help-highlight describe all supported --highlight languages\n\
2610 --highlight-bar-gray=NUM print highlight bars with gray NUM (0 - 1)\n\
2611 --list-media list names of all known media\n\
2612 --margins=LEFT:RIGHT:TOP:BOTTOM\n\
2613 adjust page marginals\n\
2614 --mark-wrapped-lines[STYLE]\n\
2615 mark wrapped lines in the output with STYLE\n\
2616 --non-printable-format=FMT specify how non-printable chars are printed\n"));
2619 --nup-columnwise layout pages in the N-up printing columnwise\n\
2620 --nup-xpad=NUM set the page x-padding of N-up printing to NUM\n\
2621 --nup-ypad=NUM set the page y-padding of N-up printing to NUM\n\
2622 --page-label-format=FMT set page label format to FMT\n\
2623 --ps-level=LEVEL set the PostScript language level that enscript\n\
2625 --printer-options=OPTIONS pass extra options to the printer command\n\
2626 --rotate-even-pages rotate even-numbered pages 180 degrees\n"));
2629 --slice=NUM print vertical slice NUM\n\
2630 --style=STYLE use highlight style STYLE\n\
2631 --swap-even-page-margins swap left and right side margins for each even\n\
2633 --toc print table of contents\n\
2634 --ul-angle=ANGLE set underlay text's angle to ANGLE\n\
2635 --ul-font=NAME print underlays with font NAME\n\
2636 --ul-gray=NUM print underlays with gray value NUM\n\
2637 --ul-position=POS set underlay's starting position to POS\n\
2638 --ul-style=STYLE print underlays with style STYLE\n\
2639 --word-wrap wrap long lines from word boundaries\n\
2642 printf (_("\nReport bugs to <%s>.\n"), PACKAGE_BUGREPORT);
2650 Copyright (C) 1995-2003, 2007, 2008, 2009, 2010 Free Software Foundation, Inc.\n\
2651 %s comes with NO WARRANTY, to the extent permitted by law.\n\
2652 You may redistribute copies of %s under the terms of the GNU\n\
2653 General Public License, version 3 or, at your option, any later version.\n\
2654 For more information about these matters, see the files named COPYING.\n",