passthrough.test: Use sed instead of tail.
[enscript.git] / src / main.c
index 7fb75c3..a9175db 100644 (file)
@@ -6,22 +6,20 @@
  */
 
 /*
- * This file is part of GNU enscript.
+ * This file is part of GNU Enscript.
  *
- * This program is free software; you can redistribute it and/or modify
+ * Enscript is free software: you can redistribute it and/or modify
  * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation; either version 2, or (at your option)
- * any later version.
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
  *
- * This program is distributed in the hope that it will be useful,
+ * Enscript is distributed in the hope that it will be useful,
  * but WITHOUT ANY WARRANTY; without even the implied warranty of
  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  * GNU General Public License for more details.
  *
  * You should have received a copy of the GNU General Public License
- * along with this program; see the file COPYING.  If not, write to
- * the Free Software Foundation, 51 Franklin Street, Fifth Floor,
- * Boston, MA 02110-1301, USA.
+ * along with Enscript.  If not, see <http://www.gnu.org/licenses/>.
  */
 
 #include "gsint.h"
@@ -60,8 +58,6 @@ static void version ();
 char *program;                 /* Program's name, used for messages. */
 FILE *ofp = NULL;              /* Output file. */
 void *printer_context;         /* Context for the printer. */
-char *version_string = NULL;   /* Enscript's version string. */
-char *ps_version_string = NULL;        /* Version string for PS procsets. */
 char *date_string = NULL;      /* Preformatted time string. */
 struct tm run_tm;              /* Time when program is run. */
 struct tm mod_tm;              /* Last modification time for current file. */
@@ -948,19 +944,6 @@ main (int argc, char *argv[])
   /* Make getopt_long() to use our modified programname. */
   argv[0] = program;
 
-  /* Create version strings. */
-
-  buffer_clear (&buffer);
-  buffer_append (&buffer, "GNU ");
-  buffer_append (&buffer, PACKAGE);
-  buffer_append (&buffer, " ");
-  buffer_append (&buffer, VERSION);
-  version_string = buffer_copy (&buffer);
-
-  ps_version_string = xstrdup (VERSION);
-  cp = strrchr (ps_version_string, '.');
-  *cp = ' ';
-
   /* Create the default TOC format string.  Wow, this is cool! */
   /* xgettext:no-c-format */
   toc_fmt_string = _("$3v $-40N $3% pages $4L lines  $E $C");
@@ -1102,10 +1085,8 @@ _("This is probably an installation error.  Please, try to rebuild:")));
                  ERROR ((stderr, _("\tmake")));
                  ERROR ((stderr, _("\tmake check")));
                  ERROR ((stderr, _("\tmake install")));
-                 ERROR ((stderr,
-_("or set the environment variable `ENSCRIPT_LIBRARY' to point to your")));
-                 ERROR ((stderr,
-_("library directory.")));
+                 ERROR ((stderr, _("or set the environment variable `ENSCRIPT_LIBRARY'"
+                       " to point to your library directory.")));
                  exit (1);
                }
 
@@ -1129,10 +1110,10 @@ _("library directory.")));
     }
 
   /* Site config. */
-  (void) read_config (SYSCONFDIR, "enscriptsite.cfg");
+  read_config (SYSCONFDIR, "enscriptsite.cfg");
 
   /* Personal config. */
-  (void) read_config (passwd->pw_dir, ".enscriptrc");
+  read_config (cp, ".enscriptrc");
 
   /*
    * Options.
@@ -1546,9 +1527,13 @@ name             width\theight\tllx\tlly\turx\tury\n\
       buffer_append (&cmd, intbuf);
       buffer_append (&cmd, " ");
 
-      buffer_append (&cmd, "-Ddocument_title=\"");
-      buffer_append (&cmd, title);
-      buffer_append (&cmd, "\" ");
+      buffer_append (&cmd, "-Ddocument_title=\'");
+      if ((cp = shell_escape (title)) != NULL)
+       {
+         buffer_append (&cmd, cp);
+         free (cp);
+       }
+      buffer_append (&cmd, "\' ");
 
       buffer_append (&cmd, "-Dtoc=");
       buffer_append (&cmd, toc ? "1" : "0");
@@ -1565,8 +1550,14 @@ name             width\theight\tllx\tlly\turx\tury\n\
       /* Append input files. */
       for (i = optind; i < argc; i++)
        {
-         buffer_append (&cmd, " ");
-         buffer_append (&cmd, argv[i]);
+         char *cp;
+         if ((cp = shell_escape (argv[i])) != NULL)
+           {
+             buffer_append (&cmd, " \'");
+             buffer_append (&cmd, cp);
+             buffer_append (&cmd, "\'");
+             free (cp);
+           }
        }
 
       /* And do the job. */
@@ -1627,7 +1618,7 @@ name             width\theight\tllx\tlly\turx\tury\n\
                                 buffer_ptr (opts), buffer_len (opts));
            }
 
-         buffer_append (&buffer, " \"%s\"");
+         buffer_append (&buffer, " \'%s\'");
 
          input_filter = buffer_copy (&buffer);
          input_filter_stdin = "-";
@@ -1763,8 +1754,15 @@ name             width\theight\tllx\tlly\turx\tury\n\
        real_total_pages = total_pages;
 
       /* We did something, tell what.  */
-      MESSAGE (0, (stderr, _("[ %d pages * %d copy ]"), real_total_pages,
-                  num_copies));
+      char message[80];
+      snprintf(message, sizeof message, "%s%s%s%s%s",
+              "[ ",
+              ngettext("%d page", "%d pages", real_total_pages),
+              " * ",
+              ngettext("%d copy", "%d copies", num_copies),
+              " ]");
+      MESSAGE (0, (stderr, message, real_total_pages, num_copies));
+
       if (output_file == OUTPUT_FILE_NONE)
        MESSAGE (0, (stderr, _(" sent to %s\n"),
                     printer ? printer : _("printer")));
@@ -1774,7 +1772,11 @@ name             width\theight\tllx\tlly\turx\tury\n\
       if (num_truncated_lines)
        {
          retval |= 2;
-         MESSAGE (0, (stderr, _("%d lines were %s\n"), num_truncated_lines,
+         MESSAGE (0, (stderr,
+                      ngettext("%d line was %s\n",
+                               "%d lines were %s\n",
+                               num_truncated_lines),
+                      num_truncated_lines,
                       line_end == LE_TRUNCATE
                       ? _("truncated") : _("wrapped")));
        }
@@ -1782,7 +1784,10 @@ name             width\theight\tllx\tlly\turx\tury\n\
       if (num_missing_chars)
        {
          retval |= 4;
-         MESSAGE (0, (stderr, _("%d characters were missing\n"),
+         MESSAGE (0, (stderr,
+                      ngettext("%d character was missing\n",
+                               "%d characters were missing\n",
+                               num_missing_chars),
                       num_missing_chars));
          if (list_missing_characters)
            {
@@ -1794,7 +1799,10 @@ name             width\theight\tllx\tlly\turx\tury\n\
       if (num_non_printable_chars)
        {
          retval |= 8;
-         MESSAGE (0, (stderr, _("%d non-printable characters\n"),
+         MESSAGE (0, (stderr,
+                      ngettext("%d non-printable character\n",
+                               "%d non-printable characters\n",
+                               num_non_printable_chars),
                       num_non_printable_chars));
          if (list_missing_characters)
            {
@@ -1998,7 +2006,7 @@ handle_options (int argc, char *argv[])
       int i;
 
       c = getopt_long (argc, argv,
-                      "#: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:X:zZ",
+                      "#: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",
                       long_options, &option_index);
 
       if (c == -1)
@@ -2516,16 +2524,16 @@ Mandatory arguments to long options are mandatory for short options too.\n\
   -b, --header=HEADER        set page header\n\
   -B, --no-header            no page headers\n\
   -c, --truncate-lines       cut long lines (default is to wrap)\n\
-  -C, --line-numbers[=START]\n\
+  -C[START], --line-numbers[=START]\n\
                              precede each line with its line number\n\
   -d                         an alias for option --printer\n\
   -D, --setpagedevice=KEY[:VALUE]\n\
                              pass a page device definition to output\n\
-  -e, --escapes[=CHAR]       enable special escape interpretation\n"),
+  -e[CHAR], --escapes[=CHAR]       enable special escape interpretation\n"),
           program);
 
   printf (_("\
-  -E, --highlight[=LANG]     highlight source code\n"));
+  -E[LANG], --highlight[=LANG]     highlight source code\n"));
 
   printf (_("\
   -f, --font=NAME            use font NAME for body text\n\
@@ -2534,7 +2542,7 @@ Mandatory arguments to long options are mandatory for short options too.\n\
   -G                         same as --fancy-header\n\
       --fancy-header[=NAME]  select fancy page header\n\
   -h, --no-job-header        suppress the job header page\n\
-  -H, --highlight-bars=NUM   specify how high highlight bars are\n\
+  -H[NUM], --highlight-bars[=NUM]  specify how high highlight bars are\n\
   -i, --indent=NUM           set line indent to NUM characters\n\
   -I, --filter=CMD           read input files through input filter CMD\n\
   -j, --borders              print borders around columns\n\
@@ -2568,7 +2576,7 @@ Mandatory arguments to long options are mandatory for short options too.\n\
   -t, --title=TITLE          set banner page's job title to TITLE.  Option\n\
                              sets also the name of the input file stdin.\n\
   -T, --tabsize=NUM          set tabulator size to NUM\n\
-  -u, --underlay[=TEXT]      print TEXT under every page\n\
+  -u[TEXT], --underlay[=TEXT]      print TEXT under every page\n\
   -U, --nup=NUM              print NUM logical pages on each output page\n\
   -v, --verbose              tell what we are doing\n\
   -V, --version              print version number\n\
@@ -2625,7 +2633,7 @@ Mandatory arguments to long options are mandatory for short options too.\n\
   --word-wrap                wrap long lines from word boundaries\n\
 "));
 
-  printf (_("\nReport bugs to mtr@iki.fi.\n"));
+  printf (_("\nReport bugs to <%s>.\n"), PACKAGE_BUGREPORT);
 }
 
 
@@ -2633,10 +2641,12 @@ static void
 version ()
 {
   printf ("%s\n\
-Copyright (C) 2003 Markku Rossi.\n\
-GNU enscript comes with NO WARRANTY, to the extent permitted by law.\n\
-You may redistribute copies of GNU enscript under the terms of the GNU\n\
-General Public License.  For more information about these matters, see\n\
-the files named COPYING.\n",
-         version_string);
+Copyright (C) 1995-2003, 2007, 2008, 2009, 2010 Free Software Foundation, Inc.\n\
+%s comes with NO WARRANTY, to the extent permitted by law.\n\
+You may redistribute copies of %s under the terms of the GNU\n\
+General Public License, version 3 or, at your option, any later version.\n\
+For more information about these matters, see the files named COPYING.\n",
+         PACKAGE_STRING,
+         PACKAGE_NAME,
+         PACKAGE_NAME);
 }