groff
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[Groff] (no subject)


From: Bernd Warken
Subject: [Groff] (no subject)
Date: Thu, 16 Mar 2000 00:30:19 +0100

The following patch implements long options for groff using
getopt_long(3).  I decided to give each existing single character
option a unique long option equivalent.

This approach is minimally invasive because such long options are
internally translated into their equivalent, such that they need not a
be considered in the switch statement.  Moreover, as only short options
are passed on, the existing infrastructure is not affected.

I tried to use the GNU standard option names, but the following names
might be discutable:

define-string (?set-string?)
set-register (?define-register?)
macro-package (?)
number-of-first-page (?)
no-eqn-newlines (?)
append-stdin (?stdin?)
to-stdout (?stdout?)
...(?)

Bernd Warken <address@hidden>

#######################################################

--- groff.cc.orig       Thu Mar 16 00:21:32 2000
+++ groff.cc    Thu Mar 16 00:51:50 2000
@@ -25,6 +25,7 @@
 #include <stdlib.h>
 #include <signal.h>
 #include <errno.h>
+#include <getopt.h>
 
 #include "lib.h"
 #include "assert.h"
@@ -109,19 +110,78 @@
   int iflag = 0;
   int Xflag = 0;
   int safer_flag = 1;
-  int opt;
+
+  int opt, longopt_index;
+  static struct option long_options[] = {
+    // Long options with a corresponding short option are internally
+    // replaced by their short equivalent.
+    // Format: {long_option_name, has_arg, 0, short_option_char}
+    // Such long options 
+    {"ascii", 0, 0, 'a'},
+    {"debug", 0, 0, 'b'},
+    {"compat", 0, 0, 'C'},
+    {"define-string", 1, 0, 'd'},
+    {"eqn", 0, 0, 'e'},
+    {"ignore-errors", 0, 0, 'E'},
+    {"font-family", 1, 0, 'f'},
+    {"font-dir", 1, 0, 'F'},
+    {"grn", 0, 0, 'g'},
+    {"help", 0, 0, 'h'},
+    {"append-stdin", 0, 0, 'i'},
+    {"soelim-dir", 1, 0, 'I'},
+    {"print", 0, 0, 'l'},
+    {"print-arg", 1, 0, 'L'},
+    {"macro-package", 1, 0, 'm'},
+    {"macro-dir", 1, 0, 'M'},
+    {"number-of-first-page", 1, 0, 'n'},
+    {"no-eqn-newlines", 0, 0, 'N'},
+    {"output-pages", 1, 0, 'o'},
+    {"pic", 0, 0, 'p'},
+    {"postproc-arg", 1, 0, 'P'},
+    {"set-register", 1, 0, 'r'},
+    {"refer", 0, 0, 'R'},
+    {"soelim", 0, 0, 's'},
+    {"safer", 0, 0, 'S'},
+    {"tbl", 0, 0, 't'},
+    {"device", 1, 0, 'T'},
+    {"unsafe", 0, 0, 'U'},
+    {"version", 0, 0, 'v'},
+    {"to-stdout", 0, 0, 'V'},
+    {"warning", 1, 0, 'w'},
+    {"no-warning", 1, 0, 'W'},
+    {"xditview", 0, 0, 'X'},
+    {"no-output", 0, 0, 'z'},
+    {"no-postproc", 0, 0, 'Z'},
+
+    // Long options without a corresponding short option
+    // Format: {long_option_name, has_arg, 0, 0}
+    //
+    // (none implemented at the moment)
+
+    // last element must be all 0
+    {0, 0, 0, 0}
+  }; 
+
   const char *command_prefix = getenv("GROFF_COMMAND_PREFIX");
   if (!command_prefix)
     command_prefix = PROG_PREFIX;
   commands[TROFF_INDEX].set_name(command_prefix, "troff");
-  while ((opt = getopt(argc, argv,
-                      "abCd:eEf:F:ghiI:lL:m:M:n:No:pP:r:RsStT:UvVw:W:XzZ"))
-        != EOF) {
+
+  while ((opt = getopt_long(argc, argv,
+                           "abCd:eEf:F:ghiI:lL:m:M:n:No:pP:r:RsStT:UvVw:W:XzZ",
+                           long_options, &longopt_index
+                           )
+         ) != EOF
+        )
+  {
     char buf[3];
     buf[0] = '-';
     buf[1] = opt;
     buf[2] = '\0';
     switch (opt) {
+    case 0:
+      // handle long options without a corresponding single-character option
+      break;
     case 'i':
       iflag = 1;
       break;


reply via email to

[Prev in Thread] Current Thread [Next in Thread]