bug-m4
[Top][All Lists]
Advanced

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

Re: Command line options corresponding to changequote and changecom


From: Niels Möller
Subject: Re: Command line options corresponding to changequote and changecom
Date: Thu, 12 Sep 2013 16:02:01 +0200
User-agent: Gnus/5.13 (Gnus v5.13) Emacs/24.2 (usg-unix-v)

Eric Blake <address@hidden> writes:

>On 09/11/2013 05:58 AM, Niels Möller wrote:

>> Or generalizing this, a way to pass an arbitrary input fragment directly
>> on the command line would be nice too. Say,
>> 
>>   m4 -e "changecom(`;')" file.s
>
> In earlier versions of m4, 'm4 -e' did what 'm4 -i' does in other
> implementations (namely, trigger an interactive run where signals and
> buffering are changed).

I don't care very much about the option char. For consistency with other
types of command processors, -e (perl, sed, pike) and -c (sh, python)
seems like reasonable choices for a short option for passing "inline"
input data. And -c seems to be taken.

> In the meantime, I would not be opposed to the idea via a
> long option, as it definitely sounds useful.

A long option would be perfectly fine for my use case.

I still think it would make some sense with more specific options
affecting quote and comment characters. Since most other aspects of the
initial state can be modified on the command using the -D, -U, -P
options.

BTW, I remembered from looking at m4 source code years ago (some problem
with 8 bit characters, iirc), that GNU m4 was unusually well written and
easy to follow. So I checked it out, and below is a small patch for an
--input option (for lack of a better name). Unfortunately untested, I
ran the ./bootstrap script, but it failed failed after a while with

  configure.ac:158: the top level
  configure.ac:78: error: possibly undefined macro: LT_CONFIG_LTDL_DIR
        If this token and others are legitimate, please use m4_pattern_allow.
        See the Autoconf documentation.
  autoreconf: /usr/bin/autoconf failed with exit status: 1
  bootstrap: autoreconf failed

Some minor questions and comments on the code: It's a bit strange that
m4_push_string_init takes a context argument, but m4_push_string_finish
does not. The comment for process_file functions speaks about the
function returning true or false, but it returns void, instead the
true/false value is passed on to m4_push_file.

Regards,
/Niels

----8<----

diff --git a/src/main.c b/src/main.c
index 240e241..207b7ef 100644
--- a/src/main.c
+++ b/src/main.c
@@ -92,6 +92,7 @@ Operation modes:\n\
 "), stdout);
       fputs (_("\
   -b, --batch                  buffer output, process interrupts\n\
+      --input=FRAGMENT         process the input fragment as an input file\n\
   -c, --discard-comments       do not copy comments to the output\n\
   -E, --fatal-warnings         once: warnings become errors, twice: stop\n\
                                  execution at first error\n\
@@ -212,6 +213,7 @@ enum
   TRACEOFF_OPTION,                      /* no short opt */
   UNLOAD_MODULE_OPTION,                 /* no short opt */
   WORD_REGEXP_OPTION,                   /* deprecated, used to be -W */
+  INPUT_FRAGMENT_OPTION,
 
   HELP_OPTION,                          /* no short opt */
   VERSION_OPTION                        /* no short opt */
@@ -260,6 +262,7 @@ static const struct option long_options[] =
   {"traceoff", required_argument, NULL, TRACEOFF_OPTION},
   {"unload-module", required_argument, NULL, UNLOAD_MODULE_OPTION},
   {"word-regexp", required_argument, NULL, WORD_REGEXP_OPTION},
+  {"input", required_argument, NULL, INPUT_FRAGMENT_OPTION},
 
   {"help", no_argument, NULL, HELP_OPTION},
   {"version", no_argument, NULL, VERSION_OPTION},
@@ -321,6 +324,15 @@ process_file (m4 *context, const char *name)
   m4_macro_expand_input (context);
 }
 
+/* Process a string provided on the command line. */
+static void
+process_string (m4 *context, const char *input)
+{
+  m4_obstack *st
+    = m4_push_string_init (context, "command line", 0);
+  obstack_grow (st, input, strlen (input));
+  m4_push_string_finish ();    
+}
 
 /* Main entry point.  Parse arguments, load modules, then parse input.  */
 int
@@ -421,6 +433,7 @@ main (int argc, char *const *argv, char *const *envp)
         case SYNCOUTPUT_OPTION:
         case TRACEOFF_OPTION:
         case UNLOAD_MODULE_OPTION:
+       case INPUT_FRAGMENT_OPTION:
         defer:
           /* Arguments that cannot be handled until later are accumulated.  */
 
@@ -717,6 +730,9 @@ main (int argc, char *const *argv, char *const *envp)
           process_file (context, arg);
           break;
 
+       case INPUT_FRAGMENT_OPTION:
+         process_string (context, arg);
+         break;
         case DEBUGFILE_OPTION:
           if (!m4_debug_set_output (context, NULL, arg))
             m4_error (context, 0, errno, NULL, _("cannot set debug file %s"),

-- 
Niels Möller. PGP-encrypted email is preferred. Keyid C0B98E26.
Internet email is subject to wholesale government surveillance.



reply via email to

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