m4-commit
[Top][All Lists]
Advanced

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

[SCM] GNU M4 source repository branch, master, updated. cvs-readonly-29-


From: Eric Blake
Subject: [SCM] GNU M4 source repository branch, master, updated. cvs-readonly-29-ga9d31f3
Date: Mon, 10 Dec 2007 13:39:45 +0000

This is an automated email from the git hooks/post-receive script. It was
generated because a ref change was pushed to the repository containing
the project "GNU M4 source repository".

http://git.sv.gnu.org/gitweb/?p=m4.git;a=commitdiff;h=a9d31f373b211f8790ee4b79c5e85943bf9fab9e

The branch, master has been updated
       via  a9d31f373b211f8790ee4b79c5e85943bf9fab9e (commit)
      from  b8122b55893c4f55a4a64d65744ee78b67b5b6a5 (commit)

Those revisions listed above that are new to this repository have
not appeared on any other notification email; so we list those
revisions in full, below.

- Log -----------------------------------------------------------------
commit a9d31f373b211f8790ee4b79c5e85943bf9fab9e
Author: Eric Blake <address@hidden>
Date:   Sat Dec 8 21:05:11 2007 -0700

    Stage 6: convert builtins to push arg at a time.
    
    * m4/m4module.h (m4_shipout_text): Rename...
    (m4_divert_text): ...to this, to avoid confusion with m4_shipout_*
    that does not worry about sync lines.
    (m4_shipout_string_trunc): New prototype.
    * m4/output.c (m4_shipout_text): Rename...
    (m4_divert_text): ...to this.
    (m4_shipout_string): Move guts...
    (m4_shipout_string_trunc): ...to this new function.
    * m4/macro.c (m4_push_arg, m4_push_args): New functions.
    (expand_token, process_macro): Update callers.
    * m4/input.c (string_print): Likewise.
    * modules/m4.c (ifdef, ifelse, shift, substr, translit, divert):
    Likewise.
    * modules/gnu.c (patsubst): Likewise.
    (debuglen): Use SIZE_MAX for unlimited debug length.
    * src/main.c (main): Likewise.
    * m4/m4.c (m4_create): Default max_debug_length to SIZE_MAX, not
    zero.
    
    Signed-off-by: Eric Blake <address@hidden>

-----------------------------------------------------------------------

Summary of changes:
 ChangeLog     |   22 ++++++++++++++++++++++
 m4/input.c    |   19 ++++---------------
 m4/m4.c       |    1 +
 m4/m4module.h |   22 ++++++++++++++--------
 m4/macro.c    |   57 ++++++++++++++++++++++++++++++++++++++++++++++++++++++---
 m4/output.c   |   39 +++++++++++++++++++++++++++++++--------
 modules/gnu.c |    6 ++++--
 modules/m4.c  |   27 ++++++++++++++++-----------
 src/main.c    |    2 ++
 9 files changed, 148 insertions(+), 47 deletions(-)

diff --git a/ChangeLog b/ChangeLog
index 07b471d..e79d63a 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,25 @@
+2007-12-08  Eric Blake  <address@hidden>
+
+       Stage 6: convert builtins to push arg at a time.
+       * m4/m4module.h (m4_shipout_text): Rename...
+       (m4_divert_text): ...to this, to avoid confusion with m4_shipout_*
+       that does not worry about sync lines.
+       (m4_shipout_string_trunc): New prototype.
+       * m4/output.c (m4_shipout_text): Rename...
+       (m4_divert_text): ...to this.
+       (m4_shipout_string): Move guts...
+       (m4_shipout_string_trunc): ...to this new function.
+       * m4/macro.c (m4_push_arg, m4_push_args): New functions.
+       (expand_token, process_macro): Update callers.
+       * m4/input.c (string_print): Likewise.
+       * modules/m4.c (ifdef, ifelse, shift, substr, translit, divert):
+       Likewise.
+       * modules/gnu.c (patsubst): Likewise.
+       (debuglen): Use SIZE_MAX for unlimited debug length.
+       * src/main.c (main): Likewise.
+       * m4/m4.c (m4_create): Default max_debug_length to SIZE_MAX, not
+       zero.
+
 2007-12-07  Eric Blake  <address@hidden>
 
        Minor security fix: Quote output of mkstemp.
diff --git a/m4/input.c b/m4/input.c
index e4228a9..fd0e677 100644
--- a/m4/input.c
+++ b/m4/input.c
@@ -477,21 +477,10 @@ static void
 string_print (m4_input_block *me, m4 *context, m4_obstack *obs)
 {
   bool quote = m4_is_debug_bit (context, M4_DEBUG_TRACE_QUOTE);
-  const char *lquote = m4_get_syntax_lquote (M4SYNTAX);
-  const char *rquote = m4_get_syntax_rquote (M4SYNTAX);
   size_t arg_length = m4_get_max_debug_arg_length_opt (context);
-  const char *text = me->u.u_s.str;
-  size_t len = me->u.u_s.len;
-
-  if (arg_length && arg_length < len)
-    len = arg_length;
-  if (quote)
-    obstack_grow (obs, lquote, strlen (lquote));
-  obstack_grow (obs, text, len);
-  if (len != me->u.u_s.len)
-    obstack_grow (obs, "...", 3);
-  if (quote)
-    obstack_grow (obs, rquote, strlen (rquote));
+
+  m4_shipout_string_trunc (context, obs, me->u.u_s.str, me->u.u_s.len,
+                          quote, &arg_length);
 }
 
 /* First half of m4_push_string ().  The pointer next points to the new
@@ -543,7 +532,7 @@ m4_push_string_finish (void)
       input_change = true;
     }
   else
-    obstack_free (current_input, next); /* people might leave garbage on it. */
+    obstack_free (current_input, next);
   next = NULL;
   return ret;
 }
diff --git a/m4/m4.c b/m4/m4.c
index 7de0f86..651a943 100644
--- a/m4/m4.c
+++ b/m4/m4.c
@@ -37,6 +37,7 @@ m4_create (void)
   obstack_init (&context->trace_messages);
 
   context->nesting_limit = DEFAULT_NESTING_LIMIT;
+  context->max_debug_arg_length = SIZE_MAX;
 
   context->search_path  = xzalloc (sizeof *context->search_path);
   m4__include_init (context);
diff --git a/m4/m4module.h b/m4/m4module.h
index f70d414..0bab08f 100644
--- a/m4/m4module.h
+++ b/m4/m4module.h
@@ -312,6 +312,10 @@ extern size_t      m4_arg_len              (m4_macro_args 
*, unsigned int);
 extern m4_builtin_func *m4_arg_func    (m4_macro_args *, unsigned int);
 extern m4_macro_args *m4_make_argv_ref (m4_macro_args *, const char *, size_t,
                                         bool, bool);
+extern void    m4_push_arg             (m4 *, m4_obstack *, m4_macro_args *,
+                                        unsigned int);
+extern void    m4_push_args            (m4 *, m4_obstack *, m4_macro_args *,
+                                        bool, bool);
 
 
 /* --- RUNTIME DEBUGGING --- */
@@ -448,14 +452,16 @@ extern    void    m4_input_print  (m4 *, m4_obstack *, 
m4_input_block *);
 
 /* --- OUTPUT MANAGEMENT --- */
 
-extern void    m4_output_init    (m4 *);
-extern void    m4_output_exit    (void);
-extern void    m4_output_text    (m4 *, const char *, size_t);
-extern void    m4_shipout_text   (m4 *, m4_obstack *, const char *, size_t,
-                                  int);
-extern void    m4_shipout_int    (m4_obstack *, int);
-extern void    m4_shipout_string (m4 *, m4_obstack *, const char *,
-                                  size_t, bool);
+extern void    m4_output_init          (m4 *);
+extern void    m4_output_exit          (void);
+extern void    m4_output_text          (m4 *, const char *, size_t);
+extern void    m4_divert_text          (m4 *, m4_obstack *, const char *,
+                                        size_t, int);
+extern void    m4_shipout_int          (m4_obstack *, int);
+extern void    m4_shipout_string       (m4 *, m4_obstack *, const char *,
+                                        size_t, bool);
+extern bool    m4_shipout_string_trunc (m4 *, m4_obstack *, const char *,
+                                        size_t, bool, size_t *);
 
 extern void    m4_make_diversion    (m4 *, int);
 extern void    m4_insert_diversion  (m4 *, int);
diff --git a/m4/macro.c b/m4/macro.c
index 56d43ac..b3080eb 100644
--- a/m4/macro.c
+++ b/m4/macro.c
@@ -167,7 +167,7 @@ expand_token (m4 *context, m4_obstack *obs, m4__token_type 
type,
                && BIT_TEST (SYMBOL_FLAGS (symbol), VALUE_BLIND_ARGS_BIT)
                && !m4__next_token_is_open (context)))
          {
-           m4_shipout_text (context, obs, text, len, line);
+           m4_divert_text (context, obs, text, len, line);
            /* The word just output is unquoted, but we can trust the
               heuristics of safe_quote.  */
            return m4__safe_quotes (M4SYNTAX);
@@ -183,7 +183,7 @@ expand_token (m4 *context, m4_obstack *obs, m4__token_type 
type,
       assert (!"INTERNAL ERROR: bad token type in expand_token ()");
       abort ();
     }
-  m4_shipout_text (context, obs, text, m4_get_symbol_value_len (token), line);
+  m4_divert_text (context, obs, text, m4_get_symbol_value_len (token), line);
   return result;
 }
 
@@ -533,7 +533,7 @@ process_macro (m4 *context, m4_symbol_value *value, 
m4_obstack *obs,
 
        case '*':               /* all arguments */
        case '@':               /* ... same, but quoted */
-         m4_dump_args (context, obs, 1, argv, ",", *text == '@');
+         m4_push_args (context, obs, argv, false, *text == '@');
          text++;
          break;
 
@@ -950,6 +950,57 @@ m4_make_argv_ref (m4_macro_args *argv, const char *argv0, 
size_t argv0_len,
   return new_argv;
 }
 
+/* Push argument INDEX from ARGV, which must be a text token, onto the
+   expansion stack OBS for rescanning.  */
+void
+m4_push_arg (m4 *context, m4_obstack *obs, m4_macro_args *argv,
+            unsigned int index)
+{
+  m4_symbol_value *value;
+
+  if (index == 0)
+    {
+      obstack_grow (obs, argv->argv0, argv->argv0_len);
+      return;
+    }
+  value = m4_arg_symbol (argv, index);
+  if (value == &empty_symbol)
+    return;
+  /* TODO handle builtin tokens?  */
+  assert (value->type == M4_SYMBOL_TEXT);
+  /* TODO push a reference, rather than copying data.  */
+  obstack_grow (obs, m4_get_symbol_value_text (value),
+               m4_get_symbol_value_len (value));
+}
+
+/* Push series of comma-separated arguments from ARGV, which should
+   all be text, onto the expansion stack OBS for rescanning.  If SKIP,
+   then don't push the first argument.  If QUOTE, also push quoting
+   around each arg.  */
+void
+m4_push_args (m4 *context, m4_obstack *obs, m4_macro_args *argv, bool skip,
+             bool quote)
+{
+  m4_symbol_value *value;
+  unsigned int i;
+  bool comma = false;
+
+  /* TODO push reference, rather than copying data.  */
+  for (i = skip ? 2 : 1; i < argv->argc; i++)
+    {
+      value = m4_arg_symbol (argv, i);
+      if (comma)
+       obstack_1grow (obs, ',');
+      else
+       comma = true;
+      /* TODO handle builtin tokens?  */
+      assert (value->type == M4_SYMBOL_TEXT);
+      m4_shipout_string (context, obs, m4_get_symbol_value_text (value),
+                        m4_get_symbol_value_len (value), quote);
+    }
+}
+
+
 /* Define these last, so that earlier uses can benefit from the macros
    in m4private.h.  */
 
diff --git a/m4/output.c b/m4/output.c
index 8089073..ab46994 100644
--- a/m4/output.c
+++ b/m4/output.c
@@ -463,8 +463,8 @@ m4_output_text (m4 *context, const char *text, size_t 
length)
    generates several output lines, or when several input lines do not
    generate any output.  */
 void
-m4_shipout_text (m4 *context, m4_obstack *obs,
-                const char *text, size_t length, int line)
+m4_divert_text (m4 *context, m4_obstack *obs, const char *text, size_t length,
+               int line)
 {
   static bool start_of_output_line = true;
   char linebuf[6 + INT_BUFSIZE_BOUND (unsigned long int)]; /* "#line nnnn" */
@@ -590,20 +590,43 @@ void
 m4_shipout_string (m4 *context, m4_obstack *obs, const char *s, size_t len,
                   bool quoted)
 {
-  assert (obs);
-  if (s == NULL)
-    s = "";
+  m4_shipout_string_trunc (context, obs, s, len, quoted, NULL);
+}
+
+/* Output the text S, of length LEN, to OBS.  If QUOTED, also output
+   current quote characters around S.  If LEN is SIZE_MAX, use the
+   string length of S instead.  If MAX_LEN, reduce *MAX_LEN by LEN.
+   If LEN is larger than *MAX_LEN, then truncate output and return
+   true; otherwise return false.  */
+bool
+m4_shipout_string_trunc (m4 *context, m4_obstack *obs, const char *s,
+                        size_t len, bool quoted, size_t *max_len)
+{
+  size_t max = max_len ? *max_len : SIZE_MAX;
 
+  assert (obs && s);
   if (len == SIZE_MAX)
     len = strlen (s);
-
   if (quoted)
     obstack_grow (obs, context->syntax->lquote.string,
                  context->syntax->lquote.length);
-  obstack_grow (obs, s, len);
+  if (len < max)
+    {
+      obstack_grow (obs, s, len);
+      max -= len;
+    }
+  else
+    {
+      obstack_grow (obs, s, max);
+      obstack_grow (obs, "...", 3);
+      max = 0;
+    }
   if (quoted)
     obstack_grow (obs, context->syntax->rquote.string,
                  context->syntax->rquote.length);
+  if (max_len)
+    *max_len = max;
+  return max == 0;
 }
 
 
@@ -864,7 +887,7 @@ m4_freeze_diversions (m4 *context, FILE *file)
                          _("cannot stat diversion"));
              /* FIXME - support 64-bit off_t with 32-bit long, and
                 fix frozen file format to support 64-bit integers.
-                This implies fixing shipout_text to take off_t.  */
+                This implies fixing m4_divert_text to take off_t.  */
              if (file_stat.st_size < 0
                  || file_stat.st_size != (unsigned long int) file_stat.st_size)
                m4_error (context, EXIT_FAILURE, errno, NULL,
diff --git a/modules/gnu.c b/modules/gnu.c
index 3c772c5..7205727 100644
--- a/modules/gnu.c
+++ b/modules/gnu.c
@@ -557,11 +557,13 @@ M4BUILTIN_HANDLER (debugfile)
 M4BUILTIN_HANDLER (debuglen)
 {
   int i;
+  size_t s;
   if (!m4_numeric_arg (context, M4ARG (0), M4ARG (1), &i))
     return;
   /* FIXME - make m4_numeric_arg more powerful - we want to accept
      suffixes, and limit the result to size_t.  */
-  m4_set_max_debug_arg_length_opt (context, i);
+  s = i <= 0 ? SIZE_MAX : i;
+  m4_set_max_debug_arg_length_opt (context, s);
 }
 
 /* On-the-fly control of the format of the tracing output.  It takes one
@@ -739,7 +741,7 @@ M4BUILTIN_HANDLER (patsubst)
      replacement, we need not waste time with it.  */
   if (!*pattern && !*replace)
     {
-      obstack_grow (obs, M4ARG (1), m4_arg_len (argv, 1));
+      m4_push_arg (context, obs, argv, 1);
       return;
     }
 
diff --git a/modules/m4.c b/modules/m4.c
index 8d9bb9a..1cad9cb 100644
--- a/modules/m4.c
+++ b/modules/m4.c
@@ -223,8 +223,8 @@ M4BUILTIN_HANDLER (popdef)
 
 M4BUILTIN_HANDLER (ifdef)
 {
-  unsigned int index = m4_symbol_lookup (M4SYMTAB, M4ARG (1)) ? 2 : 3;
-  obstack_grow (obs, M4ARG (index), m4_arg_len (argv, index));
+  m4_push_arg (context, obs, argv,
+              m4_symbol_lookup (M4SYMTAB, M4ARG (1)) ? 2 : 3);
 }
 
 M4BUILTIN_HANDLER (ifelse)
@@ -243,11 +243,11 @@ M4BUILTIN_HANDLER (ifelse)
   index = 1;
   argc--;
 
-  while (1)
+  while (true)
     {
       if (m4_arg_equal (argv, index, index + 1))
        {
-         obstack_grow (obs, M4ARG (index + 2), m4_arg_len (argv, index + 2));
+         m4_push_arg (context, obs, argv, index + 2);
          return;
        }
       switch (argc)
@@ -257,7 +257,7 @@ M4BUILTIN_HANDLER (ifelse)
 
        case 4:
        case 5:
-         obstack_grow (obs, M4ARG (index + 3), m4_arg_len (argv, index + 3));
+         m4_push_arg (context, obs, argv, index + 3);
          return;
 
        default:
@@ -561,8 +561,8 @@ M4BUILTIN_HANDLER (divert)
   if (argc >= 2 && !m4_numeric_arg (context, M4ARG (0), M4ARG (1), &i))
     return;
   m4_make_diversion (context, i);
-  m4_shipout_text (context, NULL, M4ARG (2), m4_arg_len (argv, 2),
-                  m4_get_current_line (context));
+  m4_divert_text (context, NULL, M4ARG (2), m4_arg_len (argv, 2),
+                 m4_get_current_line (context));
 }
 
 /* Expand to the current diversion number.  */
@@ -625,7 +625,7 @@ M4BUILTIN_HANDLER (dnl)
    output argument is quoted with the current quotes.  */
 M4BUILTIN_HANDLER (shift)
 {
-  m4_dump_args (context, obs, 2, argv, ",", true);
+  m4_push_args (context, obs, argv, true, true);
 }
 
 /* Change the current quotes.  The function set_quotes () lives in
@@ -716,9 +716,8 @@ m4_make_temp (m4 *context, m4_obstack *obs, const char 
*macro,
   obstack_grow (obs, tmp, qlen);
   obstack_grow (obs, pattern, len);
   for (i = 0; len > 0 && i < 6; i++)
-    if (pattern[len - i - 1] != 'X')
+    if (pattern[--len] != 'X')
       break;
-  len += 6 - i;
   obstack_grow0 (obs, "XXXXXX", 6 - i);
   name = (char *) obstack_base (obs) + qlen;
 
@@ -936,7 +935,7 @@ M4BUILTIN_HANDLER (substr)
 
   if (argc <= 2)
     {
-      obstack_grow (obs, str, m4_arg_len (argv, 1));
+      m4_push_arg (context, obs, argv, 1);
       return;
     }
 
@@ -1012,6 +1011,12 @@ M4BUILTIN_HANDLER (translit)
   char found[256] = {0};
   unsigned char ch;
 
+  if (argc <= 2)
+    {
+      m4_push_arg (context, obs, argv, 1);
+      return;
+    }
+
   from = M4ARG (2);
   if (strchr (from, '-') != NULL)
     {
diff --git a/src/main.c b/src/main.c
index 7c35e64..344db58 100644
--- a/src/main.c
+++ b/src/main.c
@@ -558,6 +558,8 @@ main (int argc, char *const *argv, char *const *envp)
          /* fall through */
        case 'l':
          size = size_opt (optarg, oi, optchar);
+         if (!size)
+           size = SIZE_MAX;
          m4_set_max_debug_arg_length_opt (context, size);
          break;
 


hooks/post-receive
--
GNU M4 source repository




reply via email to

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