groff
[Top][All Lists]
Advanced

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

[Groff] Re: problem with pre-grohtml


From: Gaius Mulley
Subject: [Groff] Re: problem with pre-grohtml
Date: Thu, 19 Jul 2001 14:53:58 +0100

Werner writes:

> Both should work.  It's documented in the SYNOPSIS section of all
> groff programs that you can have a space between a flag and its
> argument.

> Indeed, `-P-D -Pdoc' doesn't work yet with -Thtml (it permutes the
> values).  Please fix this also.

ahh ok, here are the patches for this fix. The moral of the story is to
use getopt and friends wherever possible :-)

Gaius


--- groff-cvs/src/preproc/html/pre-html.cc      Tue Jul 17 14:17:06 2001
+++ groff-html/src/preproc/html/pre-html.cc     Thu Jul 19 14:36:03 2001
@@ -102,6 +102,7 @@
 static int   vertical_offset= DEFAULT_VERTICAL_OFFSET;
 static char *image_template = NULL;             // image template filename
 static int   troff_arg      = 0;                // troff arg index
+static char *command_prefix = NULL;             // optional prefix for some 
installations.
 static char *image_dir      = NULL;             // user specified image 
directory
 #if defined(DEBUGGING)
 static int   debug          = FALSE;
@@ -1151,7 +1152,7 @@
 char **addZ (int argc, char *argv[])
 {
   char **new_argv = (char **)malloc((argc+2)*sizeof(char *));
-  int   i=0;
+  int    i=0;
 
   if (new_argv == NULL)
     sys_fatal("malloc");
@@ -1241,7 +1242,7 @@
 char **addps4html (int argc, char *argv[])
 {
   char **new_argv = (char **)malloc((argc+2)*sizeof(char *));
-  int   i=0;
+  int    i=0;
 
   if (new_argv == NULL)
     sys_fatal("malloc");
@@ -1329,43 +1330,61 @@
 }
 
 /*
- *  scanArguments - scans for -P-i, -P-o, -P-D and -P-I arguments.
+ *  scanArguments - scans for all arguments including -P-i, -P-o, -P-D and 
-P-I. It returns
+ *                  the argument index of the first non option.
  */
 
 int scanArguments (int argc, char **argv)
 {
-  int i=1;
-
-  while (i<argc) {
-    if (strncmp(argv[i], "-D", 2) == 0) {
-      image_dir = (char *)(argv[i]+2);
-    } else if (strncmp(argv[i], "-I", 2) == 0) {
-      image_template = (char *)(argv[i]+2);
-    } else if (strncmp(argv[i], "-i", 2) == 0) {
-      image_res = atoi((char *)(argv[i]+2));
-    } else if (strncmp(argv[i], "-o", 2) == 0) {
-      vertical_offset = atoi((char *)(argv[i]+2));
-    } else if ((strcmp(argv[i], "-v") == 0)
-              || (strcmp(argv[i], "--version") == 0)) {
+  int c;
+  static const struct option long_options[] = {
+    { "help", no_argument, 0, CHAR_MAX + 1 },
+    { "version", no_argument, 0, 'v' },
+    { NULL, 0, 0, 0 }
+  };
+  while ((c = getopt_long(argc, argv, "+o:i:I:D:F:vd?lrn", long_options, NULL))
+        != EOF)
+    switch(c) {
+    case 'v':
       printf("GNU pre-grohtml (groff) version %s\n", Version_string);
       exit(0);
-    } else if ((strcmp(argv[i], "-h") == 0)
-              || (strcmp(argv[i], "--help") == 0)
-              || (strcmp(argv[i], "-?") == 0)) {
-      usage(stdout);
-      exit(0);
-    } else if (strcmp(argv[i], TROFF_COMMAND) == 0) {
-      /* remember troff argument number */
-      troff_arg = i;
+    case 'D':
+      image_dir = optarg;
+      break;
+    case 'I':
+      image_template = optarg;
+      break;
+    case 'i':
+      image_res = atoi(optarg);
+      break;
+    case 'o':
+      vertical_offset = atoi(optarg);
+      break;
+    case 'd':
 #if defined(DEBUGGING)
-    } else if (strcmp(argv[i], "-d") == 0) {
       debug = TRUE;
 #endif
-    } else if (argv[i][0] != '-') {
-      return( i );
+      break;
+    case CHAR_MAX + 1: // --help
+      usage(stdout);
+      exit(0);
+      break;
+    case '?':
+      usage(stderr);
+      exit(1);
+      break;
+    default:
+      break;
     }
-    i++;
+
+  while (optind < argc) {
+    if (strcmp(argv[optind], "troff") == 0)
+      troff_arg = optind;
+    else if (argv[optind][0] != '-')
+      return optind;
+    optind++;
   }
+
   return( argc );
 }
 
--- groff-cvs/src/devices/grohtml/post-html.cc  Thu Jul 12 23:11:03 2001
+++ groff-html/src/devices/grohtml/post-html.cc Thu Jul 19 14:35:04 2001
@@ -2900,6 +2900,9 @@
     case 'r':
       auto_rule = FALSE;
       break;
+    case 'd':
+      /* handled by pre-html */
+      break;
     case 'o':
       /* handled by pre-html */
       break;
--- groff-cvs/src/roff/groff/groff.cc   Tue Jul 17 14:17:06 2001
+++ groff-html/src/roff/groff/groff.cc  Thu Jul 19 14:39:59 2001
@@ -77,6 +77,7 @@
   const char *get_name();
   void append_arg(const char *, const char * = 0);
   void insert_arg(const char *);
+  void insert_args(string s);
   void clear_args();
   char **get_argv();
   void print(int is_last, FILE *fp);
@@ -283,14 +284,10 @@
 
   if (predriver && !zflag) {
     commands[TROFF_INDEX].insert_arg(commands[TROFF_INDEX].get_name());
-    const char *p = Pargs.contents();
-    const char *end = p + Pargs.length();
-    while (p < end) {
-      // pass the device arguments to the predrivers as well
-      commands[TROFF_INDEX].insert_arg(p);
-      p = strchr(p, '\0') + 1;
-    }
     commands[TROFF_INDEX].set_name(predriver);
+
+    // pass the device arguments to the predrivers as well
+    commands[TROFF_INDEX].insert_args(Pargs);
   }
 
   const char *real_driver = 0;
@@ -547,6 +544,31 @@
   str += '\0';
   str += args;
   args = str;
+}
+
+void possible_command::insert_args (string s)
+{
+  const char *p   =     s.contents();
+  const char *end = p + s.length();
+  int   l=0;
+  int   i, j;
+
+  if (p >= end)
+    return;
+
+  // find the total number of arguments in our string
+  do {
+    l++;
+    p = strchr(p, '\0') + 1;
+  } while (p < end);
+
+  // now insert each argument preserving the order
+  for (i=l-1; i>=0; i--) {
+    p = s.contents();
+    for (j=0; j<i; j++)
+      p = strchr(p, '\0') + 1;
+    insert_arg(p);
+  }
 }
 
 void possible_command::build_argv()

reply via email to

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