m4-patches
[Top][All Lists]
Advanced

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

FYI: 42-gary-module-api-tidy.patch


From: Gary V. Vaughan
Subject: FYI: 42-gary-module-api-tidy.patch
Date: Fri, 15 Aug 2003 15:06:41 +0100
User-agent: Mozilla/5.0 (X11; U; Linux i686; en-US; rv:1.5b) Gecko/20030804

Applied to HEAD.
--
  ())_.  Gary V. Vaughan    gary@(oranda.demon.co.uk|gnu.org)
  ( '/   Research Scientist http://www.oranda.demon.co.uk       ,_())____
  / )=   GNU Hacker         http://www.gnu.org/software/libtool  \'      `&
`(_~)_   Tech' Author       http://sources.redhat.com/autobook   =`---d__/
Index: ChangeLog
from  Gary V. Vaughan  <address@hidden>

        Still cleaning up the users' module API, by taking out the stuff
        that isn't used by any existing modules, and moving specialised
        functions out of libm4 and into the module they are used by.

        * m4/m4module.h (m4_skip_space): No need to export this.  Moved...
        * m4/utility.c (m4_skip_space): ...to here the home of its only
        use, made static and renamed to `skip_space'.  Changed all
        callers.
        * m4/m4module.h (m4_expand_ranges): Removed prototype.
        * m4/utility.c (m4_expand_ranges): Moved definition from here...
        * modules/m4.c (m4_expand_ranges): ...to here, and exported using
        ltdl.
        * modules/m4.h (m4_expand_ranges_func): For lt_dlsym import
        casting .
        * modules/gnu.c (builtin_syntax): Import and use in this
        builtin implementation.
        * m4/m4module.h (M4_DEBUG_PRINT1, M4_DEBUG_PRINT2, M4_DEBUG_PRINT3):
        Not used.  Deleted.
        * m4/macro.c (trace_flush): Except here where the macro is now
        manually inlined.
        * m4/m4module.h (M4_DEBUG_MESSAGE, M4_DEBUG_MESSAGE1)
        (M4_DEBUG_MESSAGE2, M4_DEBUG_MESSAGE3): Only used internally, so
        moved...
        * m4/m4private.h (M4_DEBUG_MESSAGE, M4_DEBUG_MESSAGE1)
        (M4_DEBUG_MESSAGE2, M4_DEBUG_MESSAGE3): ...to here.

Index: m4/m4module.h
===================================================================
RCS file: /cvsroot/m4/m4/m4/m4module.h,v
retrieving revision 1.65
diff -u -p -u -r1.65 m4module.h
--- m4/m4module.h 12 Aug 2003 15:33:56 -0000 1.65
+++ m4/m4module.h 15 Aug 2003 14:04:44 -0000
@@ -84,13 +84,11 @@ struct m4_macro
 
 extern boolean             m4_bad_argc       (m4 *, int, m4_symbol_value **,
                                       int, int);
-extern const char * m4_skip_space     (m4 *, const char *);
 extern boolean     m4_numeric_arg    (m4 *, int, m4_symbol_value **,
                                       int, int *);
 extern void        m4_dump_args      (m4 *, m4_obstack *, int,
                                       m4_symbol_value **, const char *,
                                       boolean);
-extern const char * m4_expand_ranges  (const char *, m4_obstack *);
 
 /* Error handling.  */
 #define M4ERROR(Arglist) (error Arglist)
@@ -269,42 +267,6 @@ extern int m4_debug_decode         (m4 *, const
 extern boolean m4_debug_set_output     (m4 *, const char *);
 extern void    m4_debug_message_prefix (m4 *);
 
-#define M4_DEBUG_PRINT1(C, Fmt, Arg1)                  M4_STMT_START { \
-      if (m4_get_debug_file (C) != NULL)                               \
-       fprintf (m4_get_debug_file (C), Fmt, Arg1);     } M4_STMT_END
-
-#define M4_DEBUG_PRINT2(Fmt, Arg1, Arg2)               M4_STMT_START { \
-      if (m4_get_debug_file (C) != NULL)                               \
-       fprintf (m4_get_debug_file (C), Fmt, Arg1, Arg2);} M4_STMT_END
-
-#define M4_DEBUG_PRINT3(Fmt, Arg1, Arg2, Arg3)         M4_STMT_START { \
-       if (m4_get_debug_file (C) != NULL)                              \
-       fprintf (m4_get_debug_file (C), Fmt, Arg1, Arg2, Arg3); } M4_STMT_END
-
-#define M4_DEBUG_MESSAGE(C, Fmt)                       M4_STMT_START { \
-      if (m4_get_debug_file (C) != NULL)                               \
-       {                                                               \
-         m4_debug_message_prefix (C);                                  \
-         fprintf (m4_get_debug_file (C), Fmt);                         \
-         putc ('\n', m4_get_debug_file (C));                           \
-       }                                               } M4_STMT_END
-
-#define M4_DEBUG_MESSAGE1(C, Fmt, Arg1)                        M4_STMT_START { 
\
-      if (m4_get_debug_file (C) != NULL)                               \
-       {                                                               \
-         m4_debug_message_prefix (C);                                  \
-         fprintf (m4_get_debug_file (C), Fmt, Arg1);                   \
-         putc ('\n', m4_get_debug_file (C));                           \
-       }                                               } M4_STMT_END
-
-#define M4_DEBUG_MESSAGE2(C, Fmt, Arg1, Arg2)          M4_STMT_START { \
-      if (m4_get_debug_file (C) != NULL)                               \
-       {                                                               \
-         m4_debug_message_prefix (C);                                  \
-         fprintf (m4_get_debug_file (C), Fmt, Arg1, Arg2);             \
-         putc ('\n', m4_get_debug_file (C));                           \
-       }                                               } M4_STMT_END
-
 
 
 /* --- SYNTAX TABLE DEFINITIONS --- */
@@ -339,7 +301,7 @@ enum {
   M4_SYNTAX_ALPHA              = (1 << 10),
   M4_SYNTAX_NUM                        = (1 << 11),
 
-  /* These values ARE bit masks to AND with categories above, a syntax entry
+  /* These values are bit masks to AND with categories above, a syntax entry
      may have any number of these in addition to a maximum of one of the
      values above.  */
   M4_SYNTAX_LQUOTE             = (1 << 12),
Index: m4/m4private.h
===================================================================
RCS file: /cvsroot/m4/m4/m4/m4private.h,v
retrieving revision 1.33
diff -u -p -u -r1.33 m4private.h
--- m4/m4private.h 7 Aug 2003 14:42:48 -0000 1.33
+++ m4/m4private.h 15 Aug 2003 14:04:44 -0000
@@ -293,6 +293,30 @@ struct m4__search_path_info {
 
 /* Other debug stuff.  */
 
+#define M4_DEBUG_MESSAGE(C, Fmt)                       M4_STMT_START { \
+      if (m4_get_debug_file (C) != NULL)                               \
+       {                                                               \
+         m4_debug_message_prefix (C);                                  \
+         fprintf (m4_get_debug_file (C), Fmt);                         \
+         putc ('\n', m4_get_debug_file (C));                           \
+       }                                               } M4_STMT_END
+
+#define M4_DEBUG_MESSAGE1(C, Fmt, Arg1)                        M4_STMT_START { 
\
+      if (m4_get_debug_file (C) != NULL)                               \
+       {                                                               \
+         m4_debug_message_prefix (C);                                  \
+         fprintf (m4_get_debug_file (C), Fmt, Arg1);                   \
+         putc ('\n', m4_get_debug_file (C));                           \
+       }                                               } M4_STMT_END
+
+#define M4_DEBUG_MESSAGE2(C, Fmt, Arg1, Arg2)          M4_STMT_START { \
+      if (m4_get_debug_file (C) != NULL)                               \
+       {                                                               \
+         m4_debug_message_prefix (C);                                  \
+         fprintf (m4_get_debug_file (C), Fmt, Arg1, Arg2);             \
+         putc ('\n', m4_get_debug_file (C));                           \
+       }                                               } M4_STMT_END
+
 #if DEBUG
 # define DEBUG_INPUT
 # define DEBUG_MACRO
Index: m4/macro.c
===================================================================
RCS file: /cvsroot/m4/m4/m4/macro.c,v
retrieving revision 1.36
diff -u -p -u -r1.36 macro.c
--- m4/macro.c 23 Jul 2003 16:20:50 -0000 1.36
+++ m4/macro.c 15 Aug 2003 14:04:44 -0000
@@ -539,7 +539,8 @@ trace_flush (m4 *context)
 
   obstack_1grow (&context->trace_messages, '\0');
   line = obstack_finish (&context->trace_messages);
-  M4_DEBUG_PRINT1 (context, "%s\n", line);
+  if (m4_get_debug_file (context))
+    fprintf (m4_get_debug_file (context), "%s\n", line);
   obstack_free (&context->trace_messages, line);
 }
 
Index: m4/utility.c
===================================================================
RCS file: /cvsroot/m4/m4/m4/utility.c,v
retrieving revision 1.34
diff -u -p -u -r1.34 utility.c
--- m4/utility.c 7 Aug 2003 14:28:29 -0000 1.34
+++ m4/utility.c 15 Aug 2003 14:04:44 -0000
@@ -25,6 +25,9 @@
 #include "m4private.h"
 
 
+static const char * skip_space (m4 *, const char *);
+
+
 
 /* Give friendly warnings if a builtin macro is passed an
    inappropriate number of arguments.  ARGC/ARGV are the arguments,
@@ -54,8 +57,8 @@ m4_bad_argc (m4 *context, int argc, m4_s
   return FALSE;
 }
 
-const char *
-m4_skip_space (m4 *context, const char *arg)
+static const char *
+skip_space (m4 *context, const char *arg)
 {
   while (m4_has_syntax (M4SYNTAX, *arg, M4_SYNTAX_SPACE))
     arg++;
@@ -72,8 +75,8 @@ m4_numeric_arg (m4 *context, int argc, m
   char *endp;
 
   if (*M4ARG (arg) == 0
-      || (*valuep = strtol (m4_skip_space (context, M4ARG (arg)), &endp, 10),
-         *m4_skip_space (context, endp) != 0))
+      || (*valuep = strtol (skip_space (context, M4ARG (arg)), &endp, 10),
+         *skip_space (context, endp) != 0))
     {
       M4WARN ((m4_get_warning_status_opt (context), 0,
               _("Warning: %s: argument %d non-numeric: %s"),
@@ -100,46 +103,4 @@ m4_dump_args (m4 *context, m4_obstack *o
 
       m4_shipout_string (context, obs, M4ARG (i), 0, quoted);
     }
-}
-
-/* For "translit", ranges are allowed in the second and third argument.
-   They are expanded in the following function, and the expanded strings,
-   without any ranges left, are used to translate the characters of the
-   first argument.  A single - (dash) can be included in the strings by
-   being the first or the last character in the string.  If the first
-   character in a range is after the first in the character set, the range
-   is made backwards, thus 9-0 is the string 9876543210.  */
-const char *
-m4_expand_ranges (const char *s, m4_obstack *obs)
-{
-  char from;
-  char to;
-
-  for (from = '\0'; *s != '\0'; from = *s++)
-    {
-      if (*s == '-' && from != '\0')
-       {
-         to = *++s;
-         if (to == '\0')
-           {
-              /* trailing dash */
-              obstack_1grow (obs, '-');
-              break;
-           }
-         else if (from <= to)
-           {
-             while (from++ < to)
-               obstack_1grow (obs, from);
-           }
-         else
-           {
-             while (--from >= to)
-               obstack_1grow (obs, from);
-           }
-       }
-      else
-       obstack_1grow (obs, *s);
-    }
-  obstack_1grow (obs, '\0');
-  return obstack_finish (obs);
 }
Index: modules/gnu.c
===================================================================
RCS file: /cvsroot/m4/m4/modules/gnu.c,v
retrieving revision 1.30
diff -u -p -u -r1.30 gnu.c
--- modules/gnu.c 12 Aug 2003 15:33:57 -0000 1.30
+++ modules/gnu.c 15 Aug 2003 14:04:44 -0000
@@ -181,17 +181,21 @@ M4BUILTIN_HANDLER (indir)
  **/
 M4BUILTIN_HANDLER (changesyntax)
 {
-  int i;
+  M4_MODULE_IMPORT (m4, m4_expand_ranges);
 
-  for (i = 1; i < argc; i++)
+  if (m4_expand_ranges)
     {
-      char key = *M4ARG (i);
-      if ((m4_set_syntax (M4SYNTAX, key,
-                         m4_expand_ranges (M4ARG (i)+1, obs)) < 0)
-         && (key != '\0'))
+      int i;
+      for (i = 1; i < argc; i++)
        {
-         M4ERROR ((m4_get_warning_status_opt (context), 0,
-                   _("Undefined syntax code %c"), key));
+         char key = *M4ARG (i);
+         if ((m4_set_syntax (M4SYNTAX, key,
+                             m4_expand_ranges (M4ARG (i)+1, obs)) < 0)
+             && (key != '\0'))
+           {
+             M4ERROR ((m4_get_warning_status_opt (context), 0,
+                       _("Undefined syntax code %c"), key));
+           }
        }
     }
 }
Index: modules/m4.c
===================================================================
RCS file: /cvsroot/m4/m4/modules/m4.c,v
retrieving revision 1.52
diff -u -p -u -r1.52 m4.c
--- modules/m4.c 12 Aug 2003 15:33:57 -0000 1.52
+++ modules/m4.c 15 Aug 2003 14:04:45 -0000
@@ -52,6 +52,7 @@ extern int errno;
 #define m4_set_sysval          m4_LTX_m4_set_sysval
 #define m4_sysval_flush                m4_LTX_m4_sysval_flush
 #define m4_dump_symbols                m4_LTX_m4_dump_symbols
+#define m4_expand_ranges       m4_LTX_m4_expand_ranges
 
 /* Maintain each of the builtins implemented in this modules along
    with their details in a single table for easy maintenance.
@@ -755,6 +756,47 @@ M4BUILTIN_HANDLER (substr)
   obstack_grow (obs, M4ARG (1) + start, length);
 }
 
+
+/* Ranges are expanded by the following function, and the expanded strings,
+   without any ranges left, are used to translate the characters of the
+   first argument.  A single - (dash) can be included in the strings by
+   being the first or the last character in the string.  If the first
+   character in a range is after the first in the character set, the range
+   is made backwards, thus 9-0 is the string 9876543210.  */
+const char *
+m4_expand_ranges (const char *s, m4_obstack *obs)
+{
+  char from;
+  char to;
+
+  for (from = '\0'; *s != '\0'; from = *s++)
+    {
+      if (*s == '-' && from != '\0')
+       {
+         to = *++s;
+         if (to == '\0')
+           {
+              /* trailing dash */
+              obstack_1grow (obs, '-');
+              break;
+           }
+         else if (from <= to)
+           {
+             while (from++ < to)
+               obstack_1grow (obs, from);
+           }
+         else
+           {
+             while (--from >= to)
+               obstack_1grow (obs, from);
+           }
+       }
+      else
+       obstack_1grow (obs, *s);
+    }
+  obstack_1grow (obs, '\0');
+  return obstack_finish (obs);
+}
 
 /* The macro "translit" translates all characters in the first argument,
    which are present in the second argument, into the corresponding
Index: modules/m4.h
===================================================================
RCS file: /cvsroot/m4/m4/modules/m4.h,v
retrieving revision 1.2
diff -u -p -u -r1.2 m4.h
--- modules/m4.h 12 Aug 2003 15:33:57 -0000 1.2
+++ modules/m4.h 15 Aug 2003 14:04:45 -0000
@@ -40,6 +40,7 @@ typedef void m4_sysval_flush_func (m4 *c
 typedef void m4_set_sysval_func (int value);
 typedef void m4_dump_symbols_func (m4 *context, m4_dump_symbol_data *data,
                int argc, m4_symbol_value **argv, boolean complain);
+typedef const char *m4_expand_ranges_func  (const char *s, m4_obstack *obs);
 
 END_C_DECLS
 

reply via email to

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