bison-patches
[Top][All Lists]
Advanced

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

10-fyi-m4-backend.patch


From: Akim Demaille
Subject: 10-fyi-m4-backend.patch
Date: Tue, 05 Feb 2002 11:05:30 +0100

Index: ChangeLog
from  Akim Demaille  <address@hidden>
        Give a try to M4 as a back end.
        
        * lib/readpipe.c: New, from wdiff.
        * src/Makefile.am (DEFS): Define PKGDATADIR, not BISON_SIMPLE and
        BISON_HAIRY.
        * src/system.h (BISON_HAIRY, BISON_SIMPLE): Remove the DOS and VMS
        specific values.  Now it is m4 that performs the lookup.
        * src/parse-skel.y: Remove.
        * src/muscle_tab.c, src/muscle_tab.h (muscles_m4_output): New.
        * src/output.c (actions_output, guards_output)
        (token_definitions_output): No longer keeps track of the output
        line number, hence remove the second argument.
        (guards_output): Check against the guard member of a rule, not the
        action member.
        Adjust callers.
        (output_skeleton): Don't look for the skeleton location, let m4 do
        that.
        Create `/tmp/muscles.m4'.  This is temporary, a proper temporary
        file will be used.
        Invoke `m4' on m4sugar.m4, muscles.m4, and the skeleton.
        (prepare): Given that for the time being changesyntax is not
        usable in M4, rename the muscles using `-' to `_'.
        Define `defines_flag', `output_parser_name' and `output_header_name'.
        * src/output.h (actions_output, guards_output)
        (token_definitions_output): Adjust prototypes.
        * src/scan-skel.l: Instead of scanning the skeletons, it now
        processes the output of m4: `__oline__' and `#output'.
        * data/bison.simple: Adjust to be used by M4(sugar).
        * tests/Makefile.am: Use check_SCRIPTS to make sure `bison' is up
        to date.
        * tests/bison.in: Use the secrete envvar `BISON_PKGDATADIR'
        instead of the dead `BISON_SIMPLE' and `BISON_HAIRY'.
        * data/m4sugar/m4sugar.m4, data/m4sugar/version.m4: New,
        shamelessly stolen from CVS Autoconf.
        
        
Index: lib/Makefile.am
--- lib/Makefile.am Sun, 27 Jan 2002 20:40:44 +0100 akim
+++ lib/Makefile.am Mon, 04 Feb 2002 18:43:59 +0100 akim
@@ -1,4 +1,4 @@
-## Copyright 2001, 2002 Free Software Foundation, Inc.
+## Copyright (C) 2001, 2002 Free Software Foundation, Inc.
 
 ## This program is free software; you can redistribute it and/or modify
 ## it under the terms of the GNU General Public License as published by
@@ -39,7 +39,8 @@
   getopt.h getopt.c getopt1.c \
   hash.h hash.c \
   quote.h quote.c quotearg.h quotearg.c \
-  xalloc.h xmalloc.c xstrdup.c xstrndup.c
+  xalloc.h xmalloc.c xstrdup.c xstrndup.c \
+  readpipe.c
 
 # Implementation of bitsets
 libbison_a_SOURCES += \
Index: src/Makefile.am
--- src/Makefile.am Mon, 04 Feb 2002 17:19:57 +0100 akim
+++ src/Makefile.am Mon, 04 Feb 2002 22:49:31 +0100 akim
@@ -1,4 +1,4 @@
-## Copyright 2001 Free Software Foundation, Inc.
+## Copyright (C) 2001, 2002 Free Software Foundation, Inc.
 
 ## This program is free software; you can redistribute it and/or modify
 ## it under the terms of the GNU General Public License as published by
@@ -18,8 +18,7 @@
 AUTOMAKE_OPTIONS = ../lib/ansi2knr
 
 DEFS = @DEFS@ \
-  -DBISON_SIMPLE=\"$(pkgdatadir)/bison.simple\" \
-  -DBISON_HAIRY=\"$(pkgdatadir)/bison.hairy\" \
+  -DPKGDATADIR=\"$(pkgdatadir)\" \
   -DLOCALEDIR=\"$(datadir)/locale\"
 
 CFLAGS = @CFLAGS@ $(WARNING_CFLAGS) $(WERROR_CFLAGS)
@@ -45,9 +44,9 @@
     muscle_tab.h muscle_tab.c \
     options.h options.c \
     print.c reader.c reduce.c symtab.c warshall.c vcg.c \
-    skeleton.h parse-skel.h parse-skel.y scan-skel.l
+    scan-skel.l
 
-BUILT_SOURCES = parse-skel.c scan-skel.c
+BUILT_SOURCES = scan-skel.c
 
 EXTRA_bison_SOURCES = vmsgetargs.c
 
Index: src/muscle_tab.c
--- src/muscle_tab.c Mon, 04 Feb 2002 18:07:03 +0100 akim
+++ src/muscle_tab.c Mon, 04 Feb 2002 19:13:36 +0100 akim
@@ -92,3 +92,26 @@
   muscle_entry_t *result = hash_lookup (muscle_table, &pair);
   return result ? result->value : NULL;
 }
+
+
+/* Output the definition of all the current muscles into a list of
+   m4_defines.  */
+
+static void
+muscle_m4_output (muscle_entry_t *entry, FILE *out)
+{
+  fprintf (out, "m4_define([b4_%s],\n", entry->key);
+  fprintf (out, "          [[%s]])\n\n\n", entry->value);
+}
+
+
+/* Output the definition of all the current muscles into a list of
+   m4_defines.  */
+
+void
+muscles_m4_output (FILE *out)
+{
+  hash_do_for_each (muscle_table,
+                   (Hash_processor) muscle_m4_output,
+                   out);
+}
Index: src/muscle_tab.h
--- src/muscle_tab.h Sun, 30 Dec 2001 18:57:29 +0100 akim
+++ src/muscle_tab.h Mon, 04 Feb 2002 18:12:32 +0100 akim
@@ -1,5 +1,5 @@
 /* Definitions for macrotab.c and callers, part of bison,
-   Copyright 2001 Free Software Foundation, Inc.
+   Copyright (C) 2001, 2002 Free Software Foundation, Inc.
 
    This file is part of Bison, the GNU Compiler Compiler.
 
@@ -54,5 +54,8 @@
   obstack_1grow (&muscle_obstack, 0);                                  \
   muscle_insert (Key, obstack_finish (&muscle_obstack));               \
 }
+
+
+void muscles_m4_output PARAMS ((FILE *out));
 
 #endif /* not MUSCLE_TAB_H_ */
Index: src/output.c
--- src/output.c Mon, 04 Feb 2002 17:19:57 +0100 akim
+++ src/output.c Mon, 04 Feb 2002 22:51:20 +0100 akim
@@ -90,6 +90,7 @@
 
 #include "system.h"
 #include "quotearg.h"
+#include "error.h"
 #include "getargs.h"
 #include "files.h"
 #include "gram.h"
@@ -101,7 +102,13 @@
 #include "symtab.h"
 #include "conflicts.h"
 #include "muscle_tab.h"
-#include "skeleton.h"
+
+/* From lib/readpipe.h.  */
+FILE *readpipe PARAMS ((const char *, ...));
+
+/* From src/scan-skel.l. */
+int skel_lex PARAMS ((void));
+extern FILE *skel_in;
 
 static int nvectors;
 static int nentries;
@@ -504,7 +511,7 @@
 `-----------------------------*/
 
 void
-actions_output (FILE *out, size_t *line)
+actions_output (FILE *out)
 {
   int rule;
   for (rule = 1; rule < nrules + 1; ++rule)
@@ -523,14 +530,6 @@
        fprintf (out, "{ %s%s }\n    break;\n\n",
                 rules[rule].action,
                 yacc_flag ? ";" : "");
-
-       /* We always output 4 '\n' per action.  */
-       *line += 4;
-       /* Plus one if !no_lines_flag.  */
-       if (!no_lines_flag)
-         ++*line;
-       /* Get the number of lines written by the user.  */
-       *line += get_lines_number (rules[rule].action);
       }
 }
 
@@ -540,11 +539,11 @@
 `----------------------------*/
 
 void
-guards_output (FILE *out, size_t *line)
+guards_output (FILE *out)
 {
   int rule;
   for (rule = 1; rule < nrules + 1; ++rule)
-    if (rules[rule].action)
+    if (rules[rule].guard)
       {
        fprintf (out, "  case %d:\n", rule);
 
@@ -555,14 +554,6 @@
                                   muscle_find ("filename")));
        fprintf (out, "{ %s; }\n    break;\n\n",
                 rules[rule].guard);
-
-       /* We always output 4 '\n' per action.  */
-       *line += 4;
-       /* Plus one if !no_lines_flag.  */
-       if (!no_lines_flag)
-         ++*line;
-       /* Get the number of lines written by the user.  */
-       *line += get_lines_number (rules[rule].guard);
       }
 }
 
@@ -572,7 +563,7 @@
 `---------------------------------------*/
 
 void
-token_definitions_output (FILE *out, size_t *line)
+token_definitions_output (FILE *out)
 {
   int i;
   for (i = 0; i < ntokens; ++i)
@@ -603,14 +594,10 @@
 
       fprintf (out, "# define %s\t%d\n",
               symbol->tag, number);
-      ++*line;
       if (semantic_parser)
-       {
-         /* FIXME: This is probably wrong, and should be just as
-            above. --akim.  */
-         fprintf (out, "# define T%s\t%d\n", symbol->tag, symbol->value);
-         ++*line;
-       }
+       /* FIXME: This is probably wrong, and should be just as
+          above. --akim.  */
+       fprintf (out, "# define T%s\t%d\n", symbol->tag, symbol->value);
     }
 }
 
@@ -972,14 +959,57 @@
   if (!skeleton)
     {
       if (semantic_parser)
-       skeleton = skeleton_find ("BISON_HAIRY", BISON_HAIRY);
+       skeleton = "bison.hairy";
       else
-       skeleton = skeleton_find ("BISON_SIMPLE", BISON_SIMPLE);
+       skeleton = "bison.simple";
     }
 
   /* Parse the skeleton file and output the needed parsers.  */
   muscle_insert ("skeleton", skeleton);
-  process_skeleton (skeleton);
+
+  /* Store the definition of all the muscles. */
+  {
+    FILE *muscles_m4 = xfopen ("/tmp/muscles.m4", "w");
+    /* There are no comments, especially not `#': we do want M4 expansion
+       after `#': think of CPP macros!  */
+    fprintf (muscles_m4, "m4_changecom()\n");
+    fprintf (muscles_m4, "m4_init()\n");
+
+    fprintf (muscles_m4, "m4_define([b4_actions], \n[[");
+    actions_output (muscles_m4);
+    fprintf (muscles_m4, "]])\n\n");
+
+    fprintf (muscles_m4, "m4_define([b4_guards], \n[[");
+    guards_output (muscles_m4);
+    fprintf (muscles_m4, "]])\n\n");
+
+    fprintf (muscles_m4, "m4_define([b4_tokendef], \n[[");
+    token_definitions_output (muscles_m4);
+    fprintf (muscles_m4, "]])\n\n");
+
+    muscles_m4_output (muscles_m4);
+
+    fprintf (muscles_m4, "m4_wrap([m4_divert_pop(0)])\n");
+    fprintf (muscles_m4, "m4_divert_push(0)dnl\n");
+    xfclose (muscles_m4);
+  }
+
+  /* Invoke m4 on the definition of the muscles, and the skeleton. */
+  {
+    const char *bison_pkgdatadir = getenv ("BISON_PKGDATADIR");
+    if (!bison_pkgdatadir)
+      bison_pkgdatadir = PKGDATADIR;
+    skel_in = readpipe ("m4",
+                       "-I",
+                       bison_pkgdatadir,
+                       "m4sugar/m4sugar.m4",
+                       "/tmp/muscles.m4",
+                       skeleton,
+                       NULL);
+    if (!skel_in)
+      error (EXIT_FAILURE, errno, "cannot run m4");
+    skel_lex ();
+  }
 }
 
 static void
@@ -992,20 +1022,23 @@
   MUSCLE_INSERT_INT ("debug", debug_flag);
   MUSCLE_INSERT_INT ("final", final_state);
   MUSCLE_INSERT_INT ("maxtok", max_user_token_number);
-  MUSCLE_INSERT_INT ("error-verbose", error_verbose);
+  MUSCLE_INSERT_INT ("error_verbose", error_verbose);
   MUSCLE_INSERT_STRING ("prefix", spec_name_prefix ? spec_name_prefix : "yy");
 
   /* FIXME: This is wrong: the muscles should decide whether they hold
      a copy or not, but the situation is too obscure currently.  */
-  MUSCLE_INSERT_STRING ("output-infix", output_infix ? output_infix : "");
-  MUSCLE_INSERT_STRING ("output-prefix", short_base_name);
+  MUSCLE_INSERT_STRING ("output_infix", output_infix ? output_infix : "");
+  MUSCLE_INSERT_STRING ("output_prefix", short_base_name);
+  MUSCLE_INSERT_STRING ("output_parser_name", parser_file_name);
+  MUSCLE_INSERT_STRING ("output_header_name", spec_defines_file);
 
   MUSCLE_INSERT_INT ("nnts", nvars);
   MUSCLE_INSERT_INT ("nrules", nrules);
   MUSCLE_INSERT_INT ("nstates", nstates);
   MUSCLE_INSERT_INT ("ntokens", ntokens);
 
-  MUSCLE_INSERT_INT ("locations-flag", locations_flag);
+  MUSCLE_INSERT_INT ("locations_flag", locations_flag);
+  MUSCLE_INSERT_INT ("defines_flag", defines_flag);
 }
 
 /*-------------------------.
@@ -1015,14 +1048,13 @@
 static void
 header_output (void)
 {
-  size_t dummy_line;
   FILE *out = xfopen (spec_defines_file, "w");
   char *macro_name = compute_header_macro ();
 
   fprintf (out, "#ifndef %s\n", macro_name);
   fprintf (out, "# define %s\n\n", macro_name);
 
-  token_definitions_output (out, &dummy_line);
+  token_definitions_output (out);
   fprintf (out, "\
 #ifndef YYSTYPE\n\
 typedef %s
@@ -1097,7 +1129,8 @@
   output_skeleton ();
 
   /* Output the header if needed. */
-  if (defines_flag)
+
+  if (0)
     header_output ();
 
   free (rules + 1);
Index: src/output.h
--- src/output.h Sun, 30 Dec 2001 21:07:37 +0100 akim
+++ src/output.h Mon, 04 Feb 2002 19:46:02 +0100 akim
@@ -28,9 +28,9 @@
 
 size_t get_lines_number PARAMS ((const char *s));
 
-void actions_output PARAMS ((FILE *out, size_t *line));
-void guards_output PARAMS ((FILE *out, size_t *line));
-void token_definitions_output PARAMS ((FILE *out, size_t *line));
+void actions_output PARAMS ((FILE *out));
+void guards_output PARAMS ((FILE *out));
+void token_definitions_output PARAMS ((FILE *out));
 
 extern struct obstack muscle_obstack;
 
Index: src/scan-skel.l
--- src/scan-skel.l Wed, 09 Jan 2002 12:30:44 +0100 akim
+++ src/scan-skel.l Mon, 04 Feb 2002 21:26:46 +0100 akim
@@ -1,6 +1,5 @@
-                                                             /* -*- C -*- */
-/* Scan Bison Skeletons.
-   Copyright (C) 2001  Free Software Foundation, Inc.
+/* Scan Bison Skeletons.                                       -*- C -*-
+   Copyright (C) 2001, 2002  Free Software Foundation, Inc.
 
    This file is part of Bison, the GNU Compiler Compiler.
 
@@ -19,77 +18,26 @@
    Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
    02111-1307, USA.  */
 
-%option debug nodefault noyywrap nounput
+%option nodefault noyywrap nounput
 %option prefix="skel_" outfile="lex.yy.c"
 
-/* If we enable
-
-   %option yylineno
-
-   Then we have warning: `yy_flex_realloc' defined but not used.
-   Seems like a Flex bug to me: Why the heck yylineno would trigger
-   the REJECT exception???  */
-
 %{
 #include "system.h"
-#include "skeleton.h"
-#include "parse-skel.h"
-%}
-
-%{
-/* Each time we match a string, move the end cursor to its end. */
-#define YY_USER_ACTION  yylloc->last_column += yyleng;
+#include "files.h"
+int skel_lex PARAMS ((void));
+static int yylineno = 1;
 %}
 %%
-%{
-  /* At each yylex invocation, mark the current position as the
-     start of the next token.  */
-  LOCATION_STEP (*yylloc);
-%}
-
-"%%{line}"          { return LINE; }
-"%%{skeleton-line}" { return SLINE; }
-
-"%%{section}" { return SECTION; }
-
-"%%{guards}"   { return GUARDS; }
-"%%{actions}"  { return ACTIONS; }
-"%%{tokendef}" { return TOKENS; }
-
-  /* Muscle.  */
-"%%{"[a-zA-Z][0-9a-zA-Z_-]+"}" {
-  yylval->string = xstrndup (yytext + 3, yyleng - 4);
-  return MUSCLE;
-}
-
-  /* String.  */
-"%%\"".*"\"" {
-  yylval->string = xstrndup (yytext + 3, yyleng - 4);
-  return STRING;
-}
-
-  /* End of line.  */
-"\n" {
-  LOCATION_LINES (*yylloc, yyleng);
-  return '\n';
-}
-
-  /* White spaces.  */
-[\t ]+ {
-  yylval->string = yytext;
-  return BLANKS;
-}
-
-  /* Plain Characters.  */
-[^%\n]+ {
-  yylval->string = yytext;
-  return RAW;
-}
-
-  /* Plain Character.  */
-. {
-  yylval->character = *yytext;
-  return CHARACTER;
-}
+  /* This is an approximation, but we don't need more. */
+^"#output \""[^\"]+\"\n        {
+     yytext[yyleng - 2] = '\0';
+     skel_out = xfopen (yytext + strlen ("#output \""), "w");
+     yylineno = 1;
+   }
+
+"__oline__"      fprintf (yyout, "%d", yylineno);
+[^_\n]+          ECHO;
+\n+              yylineno += yyleng; ECHO;
+.                ECHO;
 
 %%
Index: src/system.h
--- src/system.h Sat, 26 Jan 2002 15:02:41 +0100 akim
+++ src/system.h Mon, 04 Feb 2002 22:47:46 +0100 akim
@@ -273,25 +273,6 @@
 # endif /* ! MSDOS */
 #endif /* ! VMS */
 
-#if defined (VMS) & !defined (__VMS_POSIX)
-# ifndef BISON_SIMPLE
-#  define BISON_SIMPLE "GNU_BISON:[000000]BISON.SIMPLE"
-# endif
-# ifndef BISON_HAIRY
-#  define BISON_HARIRY "GNU_BISON:[000000]BISON.HAIRY"
-# endif
-#endif
-
-#if defined (_MSC_VER)
-# ifndef BISON_SIMPLE
-#  define BISON_SIMPLE "c:/usr/local/lib/bison.simple"
-# endif
-# ifndef BISON_HAIRY
-#  define BISON_HAIRY "c:/usr/local/lib/bison.hairy"
-# endif
-#endif
-
-
 /* As memcpy, but for shorts.  */
 #define shortcpy(Dest, Src, Num) \
   memcpy (Dest, Src, Num * sizeof (short))
Index: data/Makefile.am
--- data/Makefile.am Mon, 04 Feb 2002 17:19:57 +0100 akim
+++ data/Makefile.am Mon, 04 Feb 2002 22:45:32 +0100 akim
@@ -16,3 +16,6 @@
 ## 02111-1307  USA
 
 dist_pkgdata_DATA = bison.simple bison.hairy bison.c++
+
+m4sugardir = $(pkgdatadir)/m4sugar
+dist_m4sugar_DATA = m4sugar/m4sugar.m4 m4sugar/version.m4
Index: data/bison.simple
--- data/bison.simple Mon, 04 Feb 2002 17:19:57 +0100 akim
+++ data/bison.simple Mon, 04 Feb 2002 22:25:53 +0100 akim
@@ -1,10 +1,36 @@
-%%{section} %%{output-prefix} %%{output-infix} %%".c"
-/* -*- C -*- */
+m4_divert(-1)
 
-/* A Bison parser, made from %%{filename}
-   by GNU bison %%{version}.  */
+# m4_define_default(MACRO, VALUE)
+# -------------------------------
+# Define MACRO to VALUE, unless already defined.
+m4_define([m4_define_default],
+[m4_ifdef([$1], [], [m4_define($@)])])
 
-/* Skeleton output parser for bison,
+m4_define_default([b4_input_suffix], [.y])
+
+m4_define_default([b4_output_parser_suffix],
+[m4_translit(b4_input_suffix, [yY], [cC])])
+
+m4_define_default([b4_output_parser_name],
+[b4_output_prefix[]b4_output_infix[]b4_output_parser_suffix[]])
+
+
+m4_define_default([b4_output_header_suffix],
+[m4_translit(b4_input_suffix, [yY], [hH])])
+
+m4_define_default([b4_output_header_name],
+[b4_output_prefix[]b4_output_infix[]b4_output_header_suffix[]])
+
+m4_define_default([b4_header_guard],
+                  [m4_bpatsubst(m4_toupper([BISON_]b4_output_header_name),
+                                [[^ABCDEFGHIJKLMNOPQRSTUVWXYZ]], [_])])
+
+m4_divert(0)dnl
+#output "b4_output_parser_name"
+/* A Bison parser, made from b4_filename
+   by GNU bison b4_version.  */
+
+/* Skeleton output parser for Bison,
    Copyright 1984, 1989, 1990, 2000, 2001, 2002 Free Software Foundation, Inc.
 
    This program is free software; you can redistribute it and/or modify
@@ -36,31 +62,32 @@
 #define YYBISON        1
 
 /* Pure parsers.  */
-#define YYPURE %%{pure}
+#define YYPURE b4_pure
 
 /* Using locations.  */
-#define YYLSP_NEEDED %%{locations-flag}
+#define YYLSP_NEEDED b4_locations_flag
 
-/* If NAME_PREFIX is specified substitute the variables and functions
+m4_if(b4_prefix[], [yy], [],
+[/* If NAME_PREFIX is specified substitute the variables and functions
    names.  */
-#define yyparse %%{prefix}parse
-#define yylex   %%{prefix}lex
-#define yyerror %%{prefix}error
-#define yylval  %%{prefix}lval
-#define yychar  %%{prefix}char
-#define yydebug %%{prefix}debug
-#define yynerrs %%{prefix}nerrs
+#define yyparse b4_prefix[]parse
+#define yylex   b4_prefix[]lex
+#define yyerror b4_prefix[]error
+#define yylval  b4_prefix[]lval
+#define yychar  b4_prefix[]char
+#define yydebug b4_prefix[]debug
+#define yynerrs b4_prefix[]nerrs
 #if YYLSP_NEEDED
-# define yylloc %%{prefix}lloc
+# define yylloc b4_prefix[]lloc
 #endif
-
+])
 
 /* Copy the user declarations.  */
-%%{prologue}
+b4_prologue
 
 /* Enabling traces.  */
 #ifndef YYDEBUG
-# define YYDEBUG %%{debug}
+# define YYDEBUG b4_debug
 #endif
 
 /* Enabling verbose error messages.  */
@@ -68,11 +95,11 @@
 # undef YYERROR_VERBOSE
 # define YYERROR_VERBOSE 1
 #else
-# define YYERROR_VERBOSE %%{error-verbose}
+# define YYERROR_VERBOSE b4_error_verbose
 #endif
 
 #ifndef YYSTYPE
-typedef %%{stype} yystype;
+typedef b4_stype yystype;
 # define YYSTYPE yystype
 #endif
 
@@ -84,11 +111,11 @@
   int last_line;
   int last_column;
 } yyltype;
-# define YYLTYPE %%{ltype}
+# define YYLTYPE b4_ltype
 #endif
 
-/* Line %%{skeleton-line} of %%{skeleton}.  */
-#line %%{line} "%%{parser-file-name}"
+/* Line __line__ of __file__.  */
+#line __oline__ "b4_output_parser_name"
 
 /* All symbols defined below should begin with yy or YY, to avoid
    infringing on user name space.  This should be done even for local
@@ -185,118 +212,118 @@
 #endif /* ! defined (yyoverflow) || YYERROR_VERBOSE */
 
 /* Tokens.  */
-%%{tokendef}
+b4_tokendef
 
 /* YYFINAL -- State number of the termination state. */
-#define YYFINAL  %%{final}
-#define YYFLAG  %%{flag}
-#define YYLAST   %%{last}
+#define YYFINAL  b4_final
+#define YYFLAG  b4_flag
+#define YYLAST   b4_last
 
 /* YYNTOKENS -- Number of terminals. */
-#define YYNTOKENS  %%{ntokens}
+#define YYNTOKENS  b4_ntokens
 /* YYNNTS -- Number of nonterminals. */
-#define YYNNTS  %%{nnts}
+#define YYNNTS  b4_nnts
 /* YYNRULES -- Number of rules. */
-#define YYNRULES  %%{nrules}
+#define YYNRULES  b4_nrules
 /* YYNRULES -- Number of states. */
-#define YYNSTATES  %%{nstates}
-#define YYMAXUTOK  %%{maxtok}
+#define YYNSTATES  b4_nstates
+#define YYMAXUTOK  b4_maxtok
 
 /* YYTRANSLATE(YYLEX) -- Bison symbol number corresponding to YYLEX.  */
-#define YYTRANSLATE(x) ((unsigned)(x) <= %%{maxtok} ? yytranslate[x] : 
%%{nsym})
+#define YYTRANSLATE(x) ((unsigned)(x) <= b4_maxtok ? yytranslate[[x]] : 
b4_nsym)
 
-/* YYTRANSLATE[YYLEX] -- Bison symbol number corresponding to YYLEX.  */
-static const char yytranslate[] =
+/* YYTRANSLATE[[YYLEX]] -- Bison symbol number corresponding to YYLEX.  */
+static const char yytranslate[[]] =
 {
-  %%{translate}
+  b4_translate
 };
 
 #if YYDEBUG
-/* YYPRHS[YYN] -- Index of the first RHS symbol of rule number YYN in
+/* YYPRHS[[YYN]] -- Index of the first RHS symbol of rule number YYN in
    YYRHS.  */
-static const short yyprhs[] =
+static const short yyprhs[[]] =
 {
-  %%{prhs}
+  b4_prhs
 };
 
 /* YYRHS -- A `-1'-separated list of the rules' RHS. */
-static const short yyrhs[] =
+static const short yyrhs[[]] =
 {
-  %%{rhs}
+  b4_rhs
 };
 
-/* YYRLINE[YYN] -- source line where rule number YYN was defined.  */
-static const short yyrline[] =
+/* YYRLINE[[YYN]] -- source line where rule number YYN was defined.  */
+static const short yyrline[[]] =
 {
-  %%{rline}
+  b4_rline
 };
 #endif
 
 #if (YYDEBUG) || YYERROR_VERBOSE
-/* YYTNME[SYMBOL-NUM] -- String name of the symbol SYMBOL-NUM.
+/* YYTNME[[SYMBOL-NUM]] -- String name of the symbol SYMBOL-NUM.
    First, the terminals, then, starting at YYNTOKENS, nonterminals. */
-static const char *const yytname[] =
+static const char *const yytname[[]] =
 {
-  %%{tname}
+  b4_tname
 };
 #endif
 
-/* YYTOKNUM[YYN] -- Index in YYTNAME corresponding to YYLEX.  */
-static const short yytoknum[] =
+/* YYTOKNUM[[YYN]] -- Index in YYTNAME corresponding to YYLEX.  */
+static const short yytoknum[[]] =
 {
-  %%{toknum}
+  b4_toknum
 };
 
-/* YYR1[YYN] -- Symbol number of symbol that rule YYN derives.  */
-static const short yyr1[] =
+/* YYR1[[YYN]] -- Symbol number of symbol that rule YYN derives.  */
+static const short yyr1[[]] =
 {
-  %%{r1}
+  b4_r1
 };
 
-/* YYR2[YYN] -- Number of symbols composing right hand side of rule YYN.  */
-static const short yyr2[] =
+/* YYR2[[YYN]] -- Number of symbols composing right hand side of rule YYN.  */
+static const short yyr2[[]] =
 {
-  %%{r2}
+  b4_r2
 };
 
-/* YYDEFACT[S] -- default rule to reduce with in state S when YYTABLE
+/* YYDEFACT[[S]] -- default rule to reduce with in state S when YYTABLE
    doesn't specify something else to do.  Zero means the default is an
    error.  */
-static const short yydefact[] =
+static const short yydefact[[]] =
 {
-  %%{defact}
+  b4_defact
 };
 
-/* YYPGOTO[NTERM-NUM]. */
-static const short yydefgoto[] =
+/* YYPGOTO[[NTERM-NUM]]. */
+static const short yydefgoto[[]] =
 {
-  %%{defgoto}
+  b4_defgoto
 };
 
-/* YYPACT[STATE-NUM] -- Index in YYTABLE of the portion describing
+/* YYPACT[[STATE-NUM]] -- Index in YYTABLE of the portion describing
    STATE-NUM.  */
-static const short yypact[] =
+static const short yypact[[]] =
 {
-  %%{pact}
+  b4_pact
 };
 
-/* YYPGOTO[NTERM-NUM].  */
-static const short yypgoto[] =
+/* YYPGOTO[[NTERM-NUM]].  */
+static const short yypgoto[[]] =
 {
-  %%{pgoto}
+  b4_pgoto
 };
 
-/* YYTABLE[YYPACT[STATE-NUM]].  What to do in state STATE-NUM.  If
+/* YYTABLE[[YYPACT[STATE-NUM]]].  What to do in state STATE-NUM.  If
    positive, shift that token.  If negative, reduce the rule which
    number is the opposite.  If zero, do what YYDEFACT says.  */
-static const short yytable[] =
+static const short yytable[[]] =
 {
-  %%{table}
+  b4_table
 };
 
-static const short yycheck[] =
+static const short yycheck[[]] =
 {
-  %%{check}
+  b4_check
 };
 
 
@@ -367,8 +394,8 @@
 
 #ifndef YYLLOC_DEFAULT
 # define YYLLOC_DEFAULT(Current, Rhs, N)               \
-   Current.last_line   = Rhs[N].last_line;     \
-   Current.last_column = Rhs[N].last_column;
+   Current.last_line   = Rhs[[N]].last_line;   \
+   Current.last_column = Rhs[[N]].last_column;
 #endif
 
 /* YYLEX -- calling `yylex' with the right arguments.  */
@@ -408,10 +435,8 @@
   if (yydebug)                                 \
     YYFPRINTF Args;                            \
 } while (0)
-/* Nonzero means print parse trace. [The following comment makes no
-   sense to me.  Could someone clarify it?  --akim] Since this is
-   uninitialized, it does not stop multiple parsers from coexisting.
-   */
+/* Nonzero means print parse trace.  Since this is uninitialized, it
+   does not stop multiple parsers from coexisting.  */
 int yydebug;
 #else /* !YYDEBUG */
 # define YYDPRINTF(Args)
@@ -419,7 +444,7 @@
 
 /* YYINITDEPTH -- initial size of the parser's stacks.  */
 #ifndef        YYINITDEPTH
-# define YYINITDEPTH %%{initdepth}
+# define YYINITDEPTH b4_initdepth
 #endif
 
 /* YYMAXDEPTH -- maximum size the stacks can grow to (effective only
@@ -434,7 +459,7 @@
 #endif
 
 #ifndef YYMAXDEPTH
-# define YYMAXDEPTH %%{maxdepth}
+# define YYMAXDEPTH b4_maxdepth
 #endif
 
 
@@ -582,7 +607,7 @@
 int
 yyparse (YYPARSE_PARAM_ARG)
      YYPARSE_PARAM_DECL
-{
+{[
   /* If reentrant, generate the variables here.  */
 #if YYPURE
   YY_DECL_VARIABLES
@@ -902,14 +927,14 @@ yyreduce:
     }
 #endif
   switch (yyn)
-    {
-      %%{actions}
+    ]{
+      b4_actions
     }
 
-/* Line %%{skeleton-line} of %%{skeleton}.  */
-#line %%{line} "%%{parser-file-name}"
+/* Line __line__ of __file__.  */
+#line __oline__ "b4_output_parser_name"
 
-  yyvsp -= yylen;
+[  yyvsp -= yylen;
   yyssp -= yylen;
 #if YYLSP_NEEDED
   yylsp -= yylen;
@@ -1136,6 +1161,39 @@ yyreturn:
     YYSTACK_FREE (yyss);
 #endif
   return yyresult;
-}
+]}
+
+b4_epilogue
+m4_if(b4_defines_flag, 0, [],
+[#output "b4_output_header_name"
+#ifndef b4_header_guard
+# define b4_header_guard
+
+b4_tokendef
+
+#ifndef YYSTYPE
+typedef b4_stype
+yystype;
+# define YYSTYPE yystype
+#endif
+
+m4_if(b4_pure, [0],
+[extern YYSTYPE b4_prefix[]lval;])
+
+m4_if(b4_locations_flag, [0], [],
+[#ifndef YYLTYPE
+typedef struct yyltype
+{
+  int first_line;
+  int first_column;
+  int last_line;
+  int last_column;
+} yyltype;
+# define YYLTYPE yyltype
+#endif
 
-%%{epilogue}
+m4_if(b4_pure, [0],
+[extern YYLTYPE b4_prefix[]lloc;])
+])
+#endif /* not b4_header_guard */
+])
Index: tests/Makefile.am
--- tests/Makefile.am Sun, 06 Jan 2002 20:24:03 +0100 akim
+++ tests/Makefile.am Mon, 04 Feb 2002 22:56:08 +0100 akim
@@ -20,7 +20,7 @@
 
 EXTRA_DIST = $(TESTSUITE_AT) testsuite
 
-DISTCLEANFILES       = atconfig bison
+DISTCLEANFILES       = atconfig $(check_SCRIPTS)
 MAINTAINERCLEANFILES = Makefile.in $(TESTSUITE)
 
 ## ------------ ##
@@ -65,6 +65,8 @@ clean-local:
 
 check-local: atconfig atlocal $(TESTSUITE)
        $(SHELL) $(TESTSUITE)
+
+check_SCRIPTS = bison
 
 # Run the test suite on the *installed* tree.
 installcheck-local:
Index: tests/bison.in
--- tests/bison.in Mon, 04 Feb 2002 17:19:57 +0100 akim
+++ tests/bison.in Mon, 04 Feb 2002 22:56:37 +0100 akim
@@ -1,11 +1,8 @@
-#! /bin/sh
+#! @SHELL@
 # @configure_input@
 # Wrapper around a non installed bison to make it work as an installed one.
 
 # We want to use the files shipped with Bison.
-BISON_SIMPLE='@abs_top_srcdir@/data/bison.simple'
-export BISON_SIMPLE
-BISON_HAIRY='@abs_top_srcdir@/data/bison.hairy'
-export BISON_HAIRY
-
+BISON_PKGDATADIR='@abs_top_srcdir@/data'
+export BISON_PKGDATADIR
 exec '@abs_top_builddir@/src/bison' ${1+"$@"}
Index: lib/readpipe.c
--- lib/readpipe.c Mon, 04 Feb 2002 23:18:49 +0100 akim
+++ lib/readpipe.c Mon, 04 Feb 2002 18:58:24 +0100 akim
@@ -0,0 +1,96 @@
+/* Open a pipe to read from a program without intermediary sh.
+   Copyright (C) 1992, 1997 Free Software Foundation, Inc.
+
+   This program is free software; you can redistribute it and/or modify
+   it under the terms of the GNU General Public License as published by
+   the Free Software Foundation; either version 2, or (at your option)
+   any later version.
+
+   This program is distributed in the hope that it will be useful,
+   but WITHOUT ANY WARRANTY; without even the implied warranty of
+   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+   GNU General Public License for more details.
+
+   You should have received a copy of the GNU General Public License
+   along with this program; if not, write to the Free Software Foundation,
+   Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.  */
+
+/* Written by David MacKenzie.  */
+
+#if HAVE_CONFIG_H
+# include <config.h>
+#endif
+
+#include <stdio.h>
+
+#if __STDC__
+#include <stdarg.h>
+#else
+#include <varargs.h>
+#endif
+
+#if HAVE_UNISTD_H
+# include <unistd.h>
+#endif
+
+/* Open a pipe to read from a program without intermediary sh.  Checks
+   PATH.  Sample use:
+
+   stream = readpipe ("progname", "arg1", "arg2", (char *) 0);
+
+   Return 0 on error.  */
+
+#if __STDC__
+FILE *
+readpipe (char *progname, ...)
+#else
+FILE *
+readpipe (va_alist)
+#endif
+{
+#if ! __STDC__
+  char *progname;
+#endif
+  int fds[2];
+  va_list ap;
+  char *args[100];
+  int argno = 0;
+
+  /* Copy arguments into `args'. */
+#if __STDC__
+  va_start (ap, progname);
+#else
+  va_start (ap);
+  progname = va_arg (ap, char *);
+#endif
+  args[argno++] = progname;
+  while ((args[argno++] = va_arg (ap, char *)) != NULL)
+    ;
+  va_end (ap);
+
+  if (pipe (fds) == -1)
+    return 0;
+
+  switch (fork ())
+    {
+    case 0:                    /* Child.  Write to pipe. */
+      close (fds[0]);          /* Not needed. */
+      if (fds[1] != 1)         /* Redirect 1 (stdout) only if needed.  */
+       {
+         close (1);            /* We don't want the old stdout. */
+         if (dup (fds[1]) == 0)/* Maybe stdin was closed. */
+           {
+             dup (fds[1]);     /* Guaranteed to dup to 1 (stdout). */
+             close (0);
+           }
+         close (fds[1]);       /* No longer needed. */
+       }
+      execvp (args[0], args);
+      _exit (2);               /* 2 for `cmp'. */
+    case -1:                   /* Error. */
+      return 0;
+    default:                   /* Parent.  Read from pipe. */
+      close (fds[1]);          /* Not needed. */
+      return fdopen (fds[0], "r");
+    }
+}
Index: data/m4sugar/m4sugar.m4
--- data/m4sugar/m4sugar.m4 Mon, 04 Feb 2002 23:18:49 +0100 akim
+++ data/m4sugar/m4sugar.m4 Tue, 13 Nov 2001 11:15:10 +0100 akim
@@ -0,0 +1,1796 @@
+divert(-1)#                                                  -*- Autoconf -*-
+# This file is part of Autoconf.
+# Base M4 layer.
+# Requires GNU M4.
+# Copyright 1999, 2000, 2001 Free Software Foundation, Inc.
+#
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 2, or (at your option)
+# any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program; if not, write to the Free Software
+# Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
+# 02111-1307, USA.
+#
+# As a special exception, the Free Software Foundation gives unlimited
+# permission to copy, distribute and modify the configure scripts that
+# are the output of Autoconf.  You need not follow the terms of the GNU
+# General Public License when using or distributing such scripts, even
+# though portions of the text of Autoconf appear in them.  The GNU
+# General Public License (GPL) does govern all other use of the material
+# that constitutes the Autoconf program.
+#
+# Certain portions of the Autoconf source text are designed to be copied
+# (in certain cases, depending on the input) into the output of
+# Autoconf.  We call these the "data" portions.  The rest of the Autoconf
+# source text consists of comments plus executable code that decides which
+# of the data portions to output in any given case.  We call these
+# comments and executable code the "non-data" portions.  Autoconf never
+# copies any of the non-data portions into its output.
+#
+# This special exception to the GPL applies to versions of Autoconf
+# released by the Free Software Foundation.  When you make and
+# distribute a modified version of Autoconf, you may extend this special
+# exception to the GPL to apply to your modified version as well, *unless*
+# your modified version has the potential to copy into its output some
+# of the text that was the non-data portion of the version that you started
+# with.  (In other words, unless your change moves or copies text from
+# the non-data portions to the data portions.)  If your modification has
+# such potential, you must delete any notice of this special exception
+# to the GPL from your modified version.
+#
+# Written by Akim Demaille.
+#
+
+# Set the quotes, whatever the current quoting system.
+changequote()
+changequote([, ])
+
+# Some old m4's don't support m4exit.  But they provide
+# equivalent functionality by core dumping because of the
+# long macros we define.
+ifdef([__gnu__], ,
+[errprint(M4sugar requires GNU M4. Install it before installing M4sugar or
+set the M4 environment variable to its path name.)
+m4exit(2)])
+
+
+## ------------------------------- ##
+## 1. Simulate --prefix-builtins.  ##
+## ------------------------------- ##
+
+# m4_define
+# m4_defn
+# m4_undefine
+define([m4_define],   defn([define]))
+define([m4_defn],     defn([defn]))
+define([m4_undefine], defn([undefine]))
+
+m4_undefine([define])
+m4_undefine([defn])
+m4_undefine([undefine])
+
+
+# m4_copy(SRC, DST)
+# -----------------
+# Define DST as the definition of SRC.
+# What's the difference between:
+# 1. m4_copy([from], [to])
+# 2. m4_define([from], [to($@)])
+# Well, obviously 1 is more expansive in space.  Maybe 2 is more expansive
+# in time, but because of the space cost of 1, it's not that obvious.
+# Nevertheless, one huge difference is the handling of `$0'.  If `from'
+# uses `$0', then with 1, `to''s `$0' is `to', while it is `from' in 2.
+# The user will certainly prefer see `from'.
+m4_define([m4_copy],
+[m4_define([$2], m4_defn([$1]))])
+
+
+# m4_rename(SRC, DST)
+# -------------------
+# Rename the macro SRC as DST.
+m4_define([m4_rename],
+[m4_copy([$1], [$2])m4_undefine([$1])])
+
+
+# m4_rename_m4(MACRO-NAME)
+# ------------------------
+# Rename MACRO-NAME as m4_MACRO-NAME.
+m4_define([m4_rename_m4],
+[m4_rename([$1], [m4_$1])])
+
+
+# m4_copy_unm4(m4_MACRO-NAME)
+# ---------------------------
+# Copy m4_MACRO-NAME as MACRO-NAME.
+m4_define([m4_copy_unm4],
+[m4_copy([$1], m4_bpatsubst([$1], [^m4_\(.*\)], [[\1]]))])
+
+
+# Some m4 internals have names colliding with tokens we might use.
+# Rename them a` la `m4 --prefix-builtins'.
+m4_rename_m4([builtin])
+m4_rename_m4([changecom])
+m4_rename_m4([changequote])
+m4_rename_m4([debugfile])
+m4_rename_m4([debugmode])
+m4_rename_m4([decr])
+m4_undefine([divert])
+m4_rename_m4([divnum])
+m4_rename_m4([dumpdef])
+m4_rename_m4([errprint])
+m4_rename_m4([esyscmd])
+m4_rename_m4([eval])
+m4_rename_m4([format])
+m4_rename_m4([ifdef])
+m4_rename([ifelse], [m4_if])
+m4_rename_m4([include])
+m4_rename_m4([incr])
+m4_rename_m4([index])
+m4_rename_m4([indir])
+m4_rename_m4([len])
+m4_rename([m4exit], [m4_exit])
+m4_rename([m4wrap], [m4_wrap])
+m4_rename_m4([maketemp])
+m4_rename([patsubst], [m4_bpatsubst])
+m4_undefine([popdef])
+m4_rename_m4([pushdef])
+m4_rename([regexp], [m4_bregexp])
+m4_rename_m4([shift])
+m4_rename_m4([sinclude])
+m4_rename_m4([substr])
+m4_rename_m4([symbols])
+m4_rename_m4([syscmd])
+m4_rename_m4([sysval])
+m4_rename_m4([traceoff])
+m4_rename_m4([traceon])
+m4_rename_m4([translit])
+m4_undefine([undivert])
+
+
+## ------------------- ##
+## 2. Error messages.  ##
+## ------------------- ##
+
+
+# m4_location
+# -----------
+m4_define([m4_location],
+[__file__:__line__])
+
+
+# m4_errprintn(MSG)
+# -----------------
+# Same as `errprint', but with the missing end of line.
+m4_define([m4_errprintn],
+[m4_errprint([$1
+])])
+
+
+# m4_warning(MSG)
+# ---------------
+# Warn the user.
+m4_define([m4_warning],
+[m4_errprintn(m4_location[: warning: $1])])
+
+
+# m4_fatal(MSG, [EXIT-STATUS])
+# ----------------------------
+# Fatal the user.                                                      :)
+m4_define([m4_fatal],
+[m4_errprintn(m4_location[: error: $1])dnl
+m4_expansion_stack_dump()dnl
+m4_exit(m4_if([$2],, 1, [$2]))])
+
+
+# m4_assert(EXPRESSION, [EXIT-STATUS = 1])
+# ----------------------------------------
+# This macro ensures that EXPRESSION evaluates to true, and exits if
+# EXPRESSION evaluates to false.
+m4_define([m4_assert],
+[m4_if(m4_eval([$1]), 0,
+       [m4_fatal([assert failed: $1], [$2])])])
+
+
+## ------------- ##
+## 3. Warnings.  ##
+## ------------- ##
+
+
+# m4_warning_ifelse(CATEGORY, IF-TRUE, IF-FALSE)
+# ----------------------------------------------
+# If the CATEGORY of warnings is enabled, expand IF_TRUE otherwise
+# IF-FALSE.
+#
+# The variable `m4_warnings' contains a comma separated list of
+# warnings which order is the converse from the one specified by
+# the user, i.e., if she specified `-W error,none,obsolete',
+# `m4_warnings' is `obsolete,none,error'.  We read it from left to
+# right, and:
+# - if none or noCATEGORY is met, run IF-FALSE
+# - if all or CATEGORY is met, run IF-TRUE
+# - if there is nothing left, run IF-FALSE.
+m4_define([m4_warning_ifelse],
+[_m4_warning_ifelse([$1], [$2], [$3], m4_warnings)])
+
+
+# _m4_warning_ifelse(CATEGORY, IF-TRUE, IF-FALSE, WARNING1, ...)
+# --------------------------------------------------------------
+# Implementation of the loop described above.
+m4_define([_m4_warning_ifelse],
+[m4_case([$4],
+         [$1],    [$2],
+         [all],   [$2],
+         [],      [$3],
+         [none],  [$3],
+         [no-$1], [$3],
+         [$0([$1], [$2], [$3], m4_shiftn(4, $@))])])
+
+
+# _m4_warning_error_ifelse(IF-TRUE, IF-FALSE)
+# -------------------------------------------
+# The same as m4_warning_ifelse, but scan for `error' only.
+m4_define([_m4_warning_error_ifelse],
+[__m4_warning_error_ifelse([$1], [$2], m4_warnings)])
+
+
+# __m4_warning_error_ifelse(IF-TRUE, IF-FALSE)
+# --------------------------------------------
+# The same as _m4_warning_ifelse, but scan for `error' only.
+m4_define([__m4_warning_error_ifelse],
+[m4_case([$3],
+         [error],    [$1],
+         [],         [$2],
+         [no-error], [$2],
+         [$0([$1], [$2], m4_shiftn(3, $@))])])
+
+
+
+# _m4_warn(MESSAGE)
+# -----------------
+# Report MESSAGE as a warning, unless the user requested -W error,
+# in which case report a fatal error.
+m4_define([_m4_warn],
+[_m4_warning_error_ifelse([m4_fatal([$1])],
+                          [m4_warning([$1])])])
+
+
+# m4_warn(CATEGORY, MESSAGE)
+# --------------------------
+# Report a MESSAGE to the autoconf user if the CATEGORY of warnings
+# is requested (in fact, not disabled).
+m4_define([m4_warn],
+[m4_warning_ifelse([$1], [_m4_warn([$2])])])
+
+
+
+
+## ------------------- ##
+## 4. File inclusion.  ##
+## ------------------- ##
+
+
+# We also want to neutralize include (and sinclude for symmetry),
+# but we want to extend them slightly: warn when a file is included
+# several times.  This is in general a dangerous operation because
+# quite nobody quotes the first argument of m4_define.
+#
+# For instance in the following case:
+#   m4_define(foo, [bar])
+# then a second reading will turn into
+#   m4_define(bar, [bar])
+# which is certainly not what was meant.
+
+# m4_include_unique(FILE)
+# -----------------------
+# Declare that the FILE was loading; and warn if it has already
+# been included.
+m4_define([m4_include_unique],
+[m4_ifdef([m4_include($1)],
+          [m4_warn([syntax], [file `$1' included several times])])dnl
+m4_define([m4_include($1)])])
+
+
+# m4_include(FILE)
+# ----------------
+# As the builtin include, but warns against multiple inclusions.
+m4_define([m4_include],
+[m4_include_unique([$1])dnl
+m4_builtin([include], [$1])])
+
+
+# m4_sinclude(FILE)
+# -----------------
+# As the builtin sinclude, but warns against multiple inclusions.
+m4_define([m4_sinclude],
+[m4_include_unique([$1])dnl
+m4_builtin([sinclude], [$1])])
+
+
+
+## ------------------------------------ ##
+## 5. Additional branching constructs.  ##
+## ------------------------------------ ##
+
+# Both `m4_ifval' and `m4_ifset' tests against the empty string.  The
+# difference is that `m4_ifset' is specialized on macros.
+#
+# In case of arguments of macros, eg $[1], it makes little difference.
+# In the case of a macro `FOO', you don't want to check `m4_ifval(FOO,
+# TRUE)', because if `FOO' expands with commas, there is a shifting of
+# the arguments.  So you want to run `m4_ifval([FOO])', but then you just
+# compare the *string* `FOO' against `', which, of course fails.
+#
+# So you want a variation of `m4_ifset' that expects a macro name as $[1].
+# If this macro is both defined and defined to a non empty value, then
+# it runs TRUE etc.
+
+
+# m4_ifval(COND, [IF-TRUE], [IF-FALSE])
+# -------------------------------------
+# If COND is not the empty string, expand IF-TRUE, otherwise IF-FALSE.
+# Comparable to m4_ifdef.
+m4_define([m4_ifval],
+[m4_if([$1], [], [$3], [$2])])
+
+
+# m4_n(TEXT)
+# ----------
+# If TEXT is not empty, return TEXT and a new line, otherwise nothing.
+m4_define([m4_n],
+[m4_if([$1],
+       [], [],
+           [$1
+])])
+
+
+# m4_ifvaln(COND, [IF-TRUE], [IF-FALSE])
+# --------------------------------------
+# Same as `m4_ifval', but add an extra newline to IF-TRUE or IF-FALSE
+# unless that argument is empty.
+m4_define([m4_ifvaln],
+[m4_if([$1],
+       [],   [m4_n([$3])],
+             [m4_n([$2])])])
+
+
+# m4_ifset(MACRO, [IF-TRUE], [IF-FALSE])
+# --------------------------------------
+# If MACRO has no definition, or of its definition is the empty string,
+# expand IF-FALSE, otherwise IF-TRUE.
+m4_define([m4_ifset],
+[m4_ifdef([$1],
+          [m4_if(m4_defn([$1]), [], [$3], [$2])],
+          [$3])])
+
+
+# m4_ifndef(NAME, [IF-NOT-DEFINED], [IF-DEFINED])
+# -----------------------------------------------
+m4_define([m4_ifndef],
+[m4_ifdef([$1], [$3], [$2])])
+
+
+# m4_case(SWITCH, VAL1, IF-VAL1, VAL2, IF-VAL2, ..., DEFAULT)
+# -----------------------------------------------------------
+# m4 equivalent of
+# switch (SWITCH)
+# {
+#   case VAL1:
+#     IF-VAL1;
+#     break;
+#   case VAL2:
+#     IF-VAL2;
+#     break;
+#   ...
+#   default:
+#     DEFAULT;
+#     break;
+# }.
+# All the values are optional, and the macro is robust to active
+# symbols properly quoted.
+m4_define([m4_case],
+[m4_if([$#], 0, [],
+       [$#], 1, [],
+       [$#], 2, [$2],
+       [$1], [$2], [$3],
+       [$0([$1], m4_shiftn(3, $@))])])
+
+
+# m4_bmatch(SWITCH, RE1, VAL1, RE2, VAL2, ..., DEFAULT)
+# -----------------------------------------------------
+# m4 equivalent of
+#
+# if (SWITCH =~ RE1)
+#   VAL1;
+# elif (SWITCH =~ RE2)
+#   VAL2;
+# elif ...
+#   ...
+# else
+#   DEFAULT
+#
+# All the values are optional, and the macro is robust to active symbols
+# properly quoted.
+m4_define([m4_bmatch],
+[m4_if([$#], 0, [],
+       [$#], 1, [],
+       [$#], 2, [$2],
+       m4_bregexp([$1], [$2]), -1, [$0([$1], m4_shiftn(3, $@))],
+       [$3])])
+
+
+
+## ---------------------------------------- ##
+## 6. Enhanced version of some primitives.  ##
+## ---------------------------------------- ##
+
+# m4_patsubsts(STRING, RE1, SUBST1, RE2, SUBST2, ...)
+# ---------------------------------------------------
+# m4 equivalent of
+#
+#   $_ = STRING;
+#   s/RE1/SUBST1/g;
+#   s/RE2/SUBST2/g;
+#   ...
+#
+# All the values are optional, and the macro is robust to active symbols
+# properly quoted.
+#
+# I would have liked to name this macro `m4_patsubst', unfortunately,
+# due to quotation problems, I need to double quote $1 below, therefore
+# the anchors are broken :(  I can't let users be trapped by that.
+m4_define([m4_bpatsubsts],
+[m4_if([$#], 0, [m4_fatal([$0: too few arguments: $#])],
+       [$#], 1, [m4_fatal([$0: too few arguments: $#: $1])],
+       [$#], 2, [m4_builtin([patsubst], $@)],
+       [$0(m4_builtin([patsubst], [[$1]], [$2], [$3]),
+           m4_shiftn(3, $@))])])
+
+
+
+# m4_do(STRING, ...)
+# ------------------
+# This macro invokes all its arguments (in sequence, of course).  It is
+# useful for making your macros more structured and readable by dropping
+# unecessary dnl's and have the macros indented properly.
+m4_define([m4_do],
+[m4_if($#, 0, [],
+       $#, 1, [$1],
+       [$1[]m4_do(m4_shift($@))])])
+
+
+# m4_default(EXP1, EXP2)
+# ----------------------
+# Returns EXP1 if non empty, otherwise EXP2.
+m4_define([m4_default],
+[m4_ifval([$1], [$1], [$2])])
+
+
+# m4_defn(NAME)
+# -------------
+# Unlike to the original, don't tolerate popping something which is
+# undefined.
+m4_define([m4_defn],
+[m4_ifndef([$1],
+           [m4_fatal([$0: undefined macro: $1])])dnl
+m4_builtin([defn], $@)])
+
+
+# _m4_dumpdefs_up(NAME)
+# ---------------------
+m4_define([_m4_dumpdefs_up],
+[m4_ifdef([$1],
+          [m4_pushdef([_m4_dumpdefs], m4_defn([$1]))dnl
+m4_dumpdef([$1])dnl
+m4_popdef([$1])dnl
+_m4_dumpdefs_up([$1])])])
+
+
+# _m4_dumpdefs_down(NAME)
+# -----------------------
+m4_define([_m4_dumpdefs_down],
+[m4_ifdef([_m4_dumpdefs],
+          [m4_pushdef([$1], m4_defn([_m4_dumpdefs]))dnl
+m4_popdef([_m4_dumpdefs])dnl
+_m4_dumpdefs_down([$1])])])
+
+
+# m4_dumpdefs(NAME)
+# -----------------
+# Similar to `m4_dumpdef(NAME)', but if NAME was m4_pushdef'ed, display its
+# value stack (most recent displayed first).
+m4_define([m4_dumpdefs],
+[_m4_dumpdefs_up([$1])dnl
+_m4_dumpdefs_down([$1])])
+
+
+# m4_popdef(NAME)
+# ---------------
+# Unlike to the original, don't tolerate popping something which is
+# undefined.
+m4_define([m4_popdef],
+[m4_ifndef([$1],
+           [m4_fatal([$0: undefined macro: $1])])dnl
+m4_builtin([popdef], $@)])
+
+
+# m4_quote(STRING)
+# ----------------
+# Return STRING quoted.
+#
+# It is important to realize the difference between `m4_quote(exp)' and
+# `[exp]': in the first case you obtain the quoted *result* of the
+# expansion of EXP, while in the latter you just obtain the string
+# `exp'.
+m4_define([m4_quote], [[$*]])
+m4_define([m4_dquote], [[[$*]]])
+
+
+# m4_noquote(STRING)
+# ------------------
+# Return the result of ignoring all quotes in STRING and invoking the
+# macros it contains.  Amongst other things useful for enabling macro
+# invocations inside strings with [] blocks (for instance regexps and
+# help-strings).
+m4_define([m4_noquote],
+[m4_changequote(-=<{,}>=-)$1-=<{}>=-m4_changequote([,])])
+
+
+# m4_shiftn(N, ...)
+# -----------------
+# Returns ... shifted N times.  Useful for recursive "varargs" constructs.
+m4_define([m4_shiftn],
+[m4_assert(($1 >= 0) && ($# > $1))dnl
+_m4_shiftn($@)])
+
+m4_define([_m4_shiftn],
+[m4_if([$1], 0,
+       [m4_shift($@)],
+       [_m4_shiftn(m4_eval([$1]-1), m4_shift(m4_shift($@)))])])
+
+
+# m4_undefine(NAME)
+# -----------------
+# Unlike to the original, don't tolerate undefining something which is
+# undefined.
+m4_define([m4_undefine],
+[m4_ifndef([$1],
+           [m4_fatal([$0: undefined macro: $1])])dnl
+m4_builtin([undefine], $@)])
+
+
+## -------------------------- ##
+## 7. Implementing m4 loops.  ##
+## -------------------------- ##
+
+
+# m4_for(VARIABLE, FIRST, LAST, [STEP = +/-1], EXPRESSION)
+# --------------------------------------------------------
+# Expand EXPRESSION defining VARIABLE to FROM, FROM + 1, ..., TO.
+# Both limits are included, and bounds are checked for consistency.
+m4_define([m4_for],
+[m4_case(m4_sign(m4_eval($3 - $2)),
+         1, [m4_assert(m4_sign(m4_default($4, 1)) == 1)],
+        -1, [m4_assert(m4_sign(m4_default($4, -1)) == -1)])dnl
+m4_pushdef([$1], [$2])dnl
+m4_if(m4_eval([$3 > $2]), 1,
+      [_m4_for([$1], [$3], m4_default([$4], 1), [$5])],
+      [_m4_for([$1], [$3], m4_default([$4], -1), [$5])])dnl
+m4_popdef([$1])])
+
+
+# _m4_for(VARIABLE, FIRST, LAST, STEP, EXPRESSION)
+# ------------------------------------------------
+# Core of the loop, no consistency checks.
+m4_define([_m4_for],
+[$4[]dnl
+m4_if($1, [$2], [],
+      [m4_define([$1], m4_eval($1+[$3]))_m4_for([$1], [$2], [$3], [$4])])])
+
+
+# Implementing `foreach' loops in m4 is much more tricky than it may
+# seem.  Actually, the example of a `foreach' loop in the m4
+# documentation is wrong: it does not quote the arguments properly,
+# which leads to undesired expansions.
+#
+# The example in the documentation is:
+#
+# | # foreach(VAR, (LIST), STMT)
+# | m4_define([foreach],
+# |        [m4_pushdef([$1])_foreach([$1], [$2], [$3])m4_popdef([$1])])
+# | m4_define([_arg1], [$1])
+# | m4_define([_foreach],
+# |          [m4_if([$2], [()], ,
+# |                 [m4_define([$1], _arg1$2)$3[]_foreach([$1],
+# |                                                        (shift$2),
+# |                                                        [$3])])])
+#
+# But then if you run
+#
+# | m4_define(a, 1)
+# | m4_define(b, 2)
+# | m4_define(c, 3)
+# | foreach([f], [([a], [(b], [c)])], [echo f
+# | ])
+#
+# it gives
+#
+#  => echo 1
+#  => echo (2,3)
+#
+# which is not what is expected.
+#
+# Of course the problem is that many quotes are missing.  So you add
+# plenty of quotes at random places, until you reach the expected
+# result.  Alternatively, if you are a quoting wizard, you directly
+# reach the following implementation (but if you really did, then
+# apply to the maintenance of m4sugar!).
+#
+# | # foreach(VAR, (LIST), STMT)
+# | m4_define([foreach], [m4_pushdef([$1])_foreach($@)m4_popdef([$1])])
+# | m4_define([_arg1], [[$1]])
+# | m4_define([_foreach],
+# |  [m4_if($2, [()], ,
+# |        [m4_define([$1], [_arg1$2])$3[]_foreach([$1],
+# |                                                 [(shift$2)],
+# |                                                 [$3])])])
+#
+# which this time answers
+#
+#  => echo a
+#  => echo (b
+#  => echo c)
+#
+# Bingo!
+#
+# Well, not quite.
+#
+# With a better look, you realize that the parens are more a pain than
+# a help: since anyway you need to quote properly the list, you end up
+# with always using an outermost pair of parens and an outermost pair
+# of quotes.  Rejecting the parens both eases the implementation, and
+# simplifies the use:
+#
+# | # foreach(VAR, (LIST), STMT)
+# | m4_define([foreach], [m4_pushdef([$1])_foreach($@)m4_popdef([$1])])
+# | m4_define([_arg1], [$1])
+# | m4_define([_foreach],
+# |  [m4_if($2, [], ,
+# |        [m4_define([$1], [_arg1($2)])$3[]_foreach([$1],
+# |                                                   [shift($2)],
+# |                                                   [$3])])])
+#
+#
+# Now, just replace the `$2' with `m4_quote($2)' in the outer `m4_if'
+# to improve robustness, and you come up with a quite satisfactory
+# implementation.
+
+
+# m4_foreach(VARIABLE, LIST, EXPRESSION)
+# --------------------------------------
+#
+# Expand EXPRESSION assigning each value of the LIST to VARIABLE.
+# LIST should have the form `item_1, item_2, ..., item_n', i.e. the
+# whole list must *quoted*.  Quote members too if you don't want them
+# to be expanded.
+#
+# This macro is robust to active symbols:
+#      | m4_define(active, [ACT, IVE])
+#      | m4_foreach(Var, [active, active], [-Var-])
+#     => -ACT--IVE--ACT--IVE-
+#
+#      | m4_foreach(Var, [[active], [active]], [-Var-])
+#     => -ACT, IVE--ACT, IVE-
+#
+#      | m4_foreach(Var, [[[active]], [[active]]], [-Var-])
+#     => -active--active-
+m4_define([m4_foreach],
+[m4_pushdef([$1])_m4_foreach($@)m4_popdef([$1])])
+
+# Low level macros used to define m4_foreach.
+m4_define([m4_car], [[$1]])
+m4_define([m4_car2], address@hidden)
+m4_define([_m4_foreach],
+[m4_if(m4_quote($2), [], [],
+       [m4_define([$1], [m4_car($2)])$3[]_m4_foreach([$1],
+                                                     m4_car2(m4_shift($2)),
+                                                     [$3])])])
+
+
+
+## --------------------------- ##
+## 8. More diversion support.  ##
+## --------------------------- ##
+
+
+# _m4_divert(DIVERSION-NAME or NUMBER)
+# ------------------------------------
+# If DIVERSION-NAME is the name of a diversion, return its number,
+# otherwise if is a NUMBER return it.
+m4_define([_m4_divert],
+[m4_ifdef([_m4_divert($1)],
+          [m4_indir([_m4_divert($1)])],
+          [$1])])
+
+# KILL is only used to suppress output.
+m4_define([_m4_divert(KILL)],           -1)
+
+
+# m4_divert(DIVERSION-NAME)
+# -------------------------
+# Change the diversion stream to DIVERSION-NAME.
+m4_define([m4_divert],
+[m4_define([m4_divert_stack],
+           m4_location[: $0: $1]m4_ifdef([m4_divert_stack], [
+m4_defn([m4_divert_stack])]))dnl
+m4_builtin([divert], _m4_divert([$1]))dnl
+])
+
+
+# m4_divert_push(DIVERSION-NAME)
+# ------------------------------
+# Change the diversion stream to DIVERSION-NAME, while stacking old values.
+m4_define([m4_divert_push],
+[m4_pushdef([m4_divert_stack],
+            m4_location[: $0: $1]m4_ifdef([m4_divert_stack], [
+m4_defn([m4_divert_stack])]))dnl
+m4_pushdef([_m4_divert_diversion], [$1])dnl
+m4_builtin([divert], _m4_divert(_m4_divert_diversion))dnl
+])
+
+
+# m4_divert_pop([DIVERSION-NAME])
+# -------------------------------
+# Change the diversion stream to its previous value, unstacking it.
+# If specified, verify we left DIVERSION-NAME.
+m4_define([m4_divert_pop],
+[m4_ifval([$1],
+     [m4_if(_m4_divert([$1]), m4_divnum, [],
+            [m4_fatal([$0($1): diversion mismatch: ]
+m4_defn([m4_divert_stack]))])])dnl
+m4_popdef([_m4_divert_diversion])dnl
+dnl m4_ifndef([_m4_divert_diversion],
+dnl           [m4_fatal([too many m4_divert_pop])])dnl
+m4_builtin([divert],
+           m4_ifdef([_m4_divert_diversion],
+                    [_m4_divert(_m4_divert_diversion)], -1))dnl
+m4_popdef([m4_divert_stack])dnl
+])
+
+
+# m4_divert_text(DIVERSION-NAME, CONTENT)
+# ---------------------------------------
+# Output CONTENT into DIVERSION-NAME (which may be a number actually).
+# An end of line is appended for free to CONTENT.
+m4_define([m4_divert_text],
+[m4_divert_push([$1])dnl
+$2
+m4_divert_pop([$1])dnl
+])
+
+
+# m4_divert_once(DIVERSION-NAME, CONTENT)
+# ---------------------------------------
+# Output once CONTENT into DIVERSION-NAME (which may be a number
+# actually).  An end of line is appended for free to CONTENT.
+m4_define([m4_divert_once],
+[m4_expand_once([m4_divert_text([$1], [$2])])])
+
+
+# m4_undivert(DIVERSION-NAME)
+# ---------------------------
+# Undivert DIVERSION-NAME.
+m4_define([m4_undivert],
+[m4_builtin([undivert], _m4_divert([$1]))])
+
+
+## -------------------------------------------- ##
+## 8. Defining macros with bells and whistles.  ##
+## -------------------------------------------- ##
+
+# `m4_defun' is basically `m4_define' but it equips the macro with the
+# needed machinery for `m4_require'.  A macro must be m4_defun'd if
+# either it is m4_require'd, or it m4_require's.
+#
+# Two things deserve attention and are detailed below:
+#  1. Implementation of m4_require
+#  2. Keeping track of the expansion stack
+#
+# 1. Implementation of m4_require
+# ===============================
+#
+# Of course m4_defun AC_PROVIDE's the macro, so that a macro which has
+# been expanded is not expanded again when m4_require'd, but the
+# difficult part is the proper expansion of macros when they are
+# m4_require'd.
+#
+# The implementation is based on two ideas, (i) using diversions to
+# prepare the expansion of the macro and its dependencies (by Fran├žois
+# Pinard), and (ii) expand the most recently m4_require'd macros _after_
+# the previous macros (by Axel Thimm).
+#
+#
+# The first idea: why using diversions?
+# -------------------------------------
+#
+# When a macro requires another, the other macro is expanded in new
+# diversion, GROW.  When the outer macro is fully expanded, we first
+# undivert the most nested diversions (GROW - 1...), and finally
+# undivert GROW.  To understand why we need several diversions,
+# consider the following example:
+#
+# | m4_defun([TEST1], [Test...REQUIRE([TEST2])1])
+# | m4_defun([TEST2], [Test...REQUIRE([TEST3])2])
+# | m4_defun([TEST3], [Test...3])
+#
+# Because m4_require is not required to be first in the outer macros, we
+# must keep the expansions of the various level of m4_require separated.
+# Right before executing the epilogue of TEST1, we have:
+#
+#         GROW - 2: Test...3
+#         GROW - 1: Test...2
+#         GROW:     Test...1
+#         BODY:
+#
+# Finally the epilogue of TEST1 undiverts GROW - 2, GROW - 1, and
+# GROW into the regular flow, BODY.
+#
+#         GROW - 2:
+#         GROW - 1:
+#         GROW:
+#         BODY:        Test...3; Test...2; Test...1
+#
+# (The semicolons are here for clarification, but of course are not
+# emitted.)  This is what Autoconf 2.0 (I think) to 2.13 (I'm sure)
+# implement.
+#
+#
+# The second idea: first required first out
+# -----------------------------------------
+#
+# The natural implementation of the idea above is buggy and produces
+# very surprising results in some situations.  Let's consider the
+# following example to explain the bug:
+#
+# | m4_defun([TEST1],  [REQUIRE([TEST2a])REQUIRE([TEST2b])])
+# | m4_defun([TEST2a], [])
+# | m4_defun([TEST2b], [REQUIRE([TEST3])])
+# | m4_defun([TEST3],  [REQUIRE([TEST2a])])
+# |
+# | AC_INIT
+# | TEST1
+#
+# The dependencies between the macros are:
+#
+#               3 --- 2b
+#              /        \              is m4_require'd by
+#             /          \       left -------------------- right
+#          2a ------------ 1
+#
+# If you strictly apply the rules given in the previous section you get:
+#
+#         GROW - 2: TEST3
+#         GROW - 1: TEST2a; TEST2b
+#         GROW:     TEST1
+#         BODY:
+#
+# (TEST2a, although required by TEST3 is not expanded in GROW - 3
+# because is has already been expanded before in GROW - 1, so it has
+# been AC_PROVIDE'd, so it is not expanded again) so when you undivert
+# the stack of diversions, you get:
+#
+#         GROW - 2:
+#         GROW - 1:
+#         GROW:
+#         BODY:        TEST3; TEST2a; TEST2b; TEST1
+#
+# i.e., TEST2a is expanded after TEST3 although the latter required the
+# former.
+#
+# Starting from 2.50, uses an implementation provided by Axel Thimm.
+# The idea is simple: the order in which macros are emitted must be the
+# same as the one in which macro are expanded.  (The bug above can
+# indeed be described as: a macro has been AC_PROVIDE'd, but it is
+# emitted after: the lack of correlation between emission and expansion
+# order is guilty).
+#
+# How to do that?  You keeping the stack of diversions to elaborate the
+# macros, but each time a macro is fully expanded, emit it immediately.
+#
+# In the example above, when TEST2a is expanded, but it's epilogue is
+# not run yet, you have:
+#
+#         GROW - 2:
+#         GROW - 1: TEST2a
+#         GROW:     Elaboration of TEST1
+#         BODY:
+#
+# The epilogue of TEST2a emits it immediately:
+#
+#         GROW - 2:
+#         GROW - 1:
+#         GROW:     Elaboration of TEST1
+#         BODY:     TEST2a
+#
+# TEST2b then requires TEST3, so right before the epilogue of TEST3, you
+# have:
+#
+#         GROW - 2: TEST3
+#         GROW - 1: Elaboration of TEST2b
+#         GROW:     Elaboration of TEST1
+#         BODY:      TEST2a
+#
+# The epilogue of TEST3 emits it:
+#
+#         GROW - 2:
+#         GROW - 1: Elaboration of TEST2b
+#         GROW:     Elaboration of TEST1
+#         BODY:     TEST2a; TEST3
+#
+# TEST2b is now completely expanded, and emitted:
+#
+#         GROW - 2:
+#         GROW - 1:
+#         GROW:     Elaboration of TEST1
+#         BODY:     TEST2a; TEST3; TEST2b
+#
+# and finally, TEST1 is finished and emitted:
+#
+#         GROW - 2:
+#         GROW - 1:
+#         GROW:
+#         BODY:     TEST2a; TEST3; TEST2b: TEST1
+#
+# The idea, is simple, but the implementation is a bit evolved.  If you
+# are like me, you will want to see the actual functioning of this
+# implementation to be convinced.  The next section gives the full
+# details.
+#
+#
+# The Axel Thimm implementation at work
+# -------------------------------------
+#
+# We consider the macros above, and this configure.ac:
+#
+#          AC_INIT
+#          TEST1
+#
+# You should keep the definitions of _m4_defun_pro, _m4_defun_epi, and
+# m4_require at hand to follow the steps.
+#
+# This implements tries not to assume that of the current diversion is
+# BODY, so as soon as a macro (m4_defun'd) is expanded, we first
+# record the current diversion under the name _m4_divert_dump (denoted
+# DUMP below for short).  This introduces an important difference with
+# the previous versions of Autoconf: you cannot use m4_require if you
+# were not inside an m4_defun'd macro, and especially, you cannot
+# m4_require directly from the top level.
+#
+# We have not tried to simulate the old behavior (better yet, we
+# diagnose it), because it is too dangerous: a macro m4_require'd from
+# the top level is expanded before the body of `configure', i.e., before
+# any other test was run.  I let you imagine the result of requiring
+# AC_STDC_HEADERS for instance, before AC_PROG_CC was actually run....
+#
+# After AC_INIT was run, the current diversion is BODY.
+# * AC_INIT was run
+#   DUMP:                undefined
+#   diversion stack:     BODY |-
+#
+# * TEST1 is expanded
+# The prologue of TEST1 sets AC_DIVERSION_DUMP, which is the diversion
+# where the current elaboration will be dumped, to the current
+# diversion.  It also m4_divert_push to GROW, where the full
+# expansion of TEST1 and its dependencies will be elaborated.
+#   DUMP:       BODY
+#   BODY:       empty
+#   diversions: GROW, BODY |-
+#
+# * TEST1 requires TEST2a: prologue
+# m4_require m4_divert_pushes another temporary diversion GROW - 1 (in
+# fact, the diversion whose number is one less than the current
+# diversion), and expands TEST2a in there.
+#   DUMP:       BODY
+#   BODY:       empty
+#   diversions: GROW-1, GROW, BODY |-
+#
+# * TEST2a is expanded.
+# Its prologue pushes the current diversion again.
+#   DUMP:       BODY
+#   BODY:       empty
+#   diversions: GROW - 1, GROW - 1, GROW, BODY |-
+# It is expanded in GROW - 1, and GROW - 1 is popped by the epilogue
+# of TEST2a.
+#   DUMP:        BODY
+#   BODY:        nothing
+#   GROW - 1:    TEST2a
+#   diversions:  GROW - 1, GROW, BODY |-
+#
+# * TEST1 requires TEST2a: epilogue
+# The content of the current diversion is appended to DUMP (and removed
+# from the current diversion).  A diversion is popped.
+#   DUMP:       BODY
+#   BODY:       TEST2a
+#   diversions: GROW, BODY |-
+#
+# * TEST1 requires TEST2b: prologue
+# m4_require pushes GROW - 1 and expands TEST2b.
+#   DUMP:       BODY
+#   BODY:       TEST2a
+#   diversions: GROW - 1, GROW, BODY |-
+#
+# * TEST2b is expanded.
+# Its prologue pushes the current diversion again.
+#   DUMP:       BODY
+#   BODY:       TEST2a
+#   diversions: GROW - 1, GROW - 1, GROW, BODY |-
+# The body is expanded here.
+#
+# * TEST2b requires TEST3: prologue
+# m4_require pushes GROW - 2 and expands TEST3.
+#   DUMP:       BODY
+#   BODY:       TEST2a
+#   diversions: GROW - 2, GROW - 1, GROW - 1, GROW, BODY |-
+#
+# * TEST3 is expanded.
+# Its prologue pushes the current diversion again.
+#   DUMP:       BODY
+#   BODY:       TEST2a
+#   diversions: GROW-2, GROW-2, GROW-1, GROW-1, GROW, BODY |-
+# TEST3 requires TEST2a, but TEST2a has already been AC_PROVIDE'd, so
+# nothing happens.  It's body is expanded here, and its epilogue pops a
+# diversion.
+#   DUMP:       BODY
+#   BODY:       TEST2a
+#   GROW - 2:   TEST3
+#   diversions: GROW - 2, GROW - 1, GROW - 1, GROW, BODY |-
+#
+# * TEST2b requires TEST3: epilogue
+# The current diversion is appended to DUMP, and a diversion is popped.
+#   DUMP:       BODY
+#   BODY:       TEST2a; TEST3
+#   diversions: GROW - 1, GROW - 1, GROW, BODY |-
+# The content of TEST2b is expanded here.
+#   DUMP:       BODY
+#   BODY:       TEST2a; TEST3
+#   GROW - 1:   TEST2b,
+#   diversions: GROW - 1, GROW - 1, GROW, BODY |-
+# The epilogue of TEST2b pops a diversion.
+#   DUMP:       BODY
+#   BODY:       TEST2a; TEST3
+#   GROW - 1:   TEST2b,
+#   diversions: GROW - 1, GROW, BODY |-
+#
+# * TEST1 requires TEST2b: epilogue
+# The current diversion is appended to DUMP, and a diversion is popped.
+#   DUMP:       BODY
+#   BODY:       TEST2a; TEST3; TEST2b
+#   diversions: GROW, BODY |-
+#
+# * TEST1 is expanded: epilogue
+# TEST1's own content is in GROW, and it's epilogue pops a diversion.
+#   DUMP:       BODY
+#   BODY:       TEST2a; TEST3; TEST2b
+#   GROW:       TEST1
+#   diversions: BODY |-
+# Here, the epilogue of TEST1 notices the elaboration is done because
+# DUMP and the current diversion are the same, it then undiverts
+# GROW by hand, and undefines DUMP.
+#   DUMP:       undefined
+#   BODY:       TEST2a; TEST3; TEST2b; TEST1
+#   diversions: BODY |-
+#
+#
+# 2. Keeping track of the expansion stack
+# =======================================
+#
+# When M4 expansion goes wrong it is often extremely hard to find the
+# path amongst macros that drove to the failure.  What is needed is
+# the stack of macro `calls'. One could imagine that GNU M4 would
+# maintain a stack of macro expansions, unfortunately it doesn't, so
+# we do it by hand.  This is of course extremely costly, but the help
+# this stack provides is worth it.  Nevertheless to limit the
+# performance penalty this is implemented only for m4_defun'd macros,
+# not for define'd macros.
+#
+# The scheme is simplistic: each time we enter an m4_defun'd macros,
+# we prepend its name in m4_expansion_stack, and when we exit the
+# macro, we remove it (thanks to pushdef/popdef).
+#
+# In addition, we want to use the expansion stack to detect circular
+# m4_require dependencies.  This means we need to browse the stack to
+# check whether a macro being expanded is m4_require'd.  For ease of
+# implementation, and certainly for the benefit of performances, we
+# don't browse the m4_expansion_stack, rather each time we expand a
+# macro FOO we define _m4_expanding(FOO).  Then m4_require(BAR) simply
+# needs to check whether _m4_expanding(BAR) is defined to diagnose a
+# circular dependency.
+#
+# To improve the diagnostic, in addition to keeping track of the stack
+# of macro calls, m4_expansion_stack also records the m4_require
+# stack.  Note that therefore an m4_defun'd macro being required will
+# appear twice in the stack: the first time because it is required,
+# the second because it is expanded.  We can avoid this, but it has
+# two small drawbacks: (i) the implementation is slightly more
+# complex, and (ii) it hides the difference between define'd macros
+# (which don't appear in m4_expansion_stack) and m4_defun'd macros
+# (which do).  The more debugging information, the better.
+
+
+# m4_expansion_stack_push(TEXT)
+# -----------------------------
+m4_define([m4_expansion_stack_push],
+[m4_pushdef([m4_expansion_stack],
+            [$1]m4_ifdef([m4_expansion_stack], [
+m4_defn([m4_expansion_stack])]))])
+
+
+# m4_expansion_stack_pop
+# ----------------------
+# Dump the expansion stack.
+m4_define([m4_expansion_stack_pop],
+[m4_popdef([m4_expansion_stack])])
+
+
+# m4_expansion_stack_dump
+# -----------------------
+# Dump the expansion stack.
+m4_define([m4_expansion_stack_dump],
+[m4_ifdef([m4_expansion_stack],
+          [m4_errprintn(m4_defn([m4_expansion_stack]))])dnl
+m4_errprintn(m4_location[: the top level])])
+
+
+# _m4_divert(GROW)
+# ----------------
+# This diversion is used by the m4_defun/m4_require machinery.  It is
+# important to keep room before GROW because for each nested
+# AC_REQUIRE we use an additional diversion (i.e., two m4_require's
+# will use GROW - 2.  More than 3 levels has never seemed to be
+# needed.)
+#
+# ...
+# - GROW - 2
+#   m4_require'd code, 2 level deep
+# - GROW - 1
+#   m4_require'd code, 1 level deep
+# - GROW
+#   m4_defun'd macros are elaborated here.
+
+m4_define([_m4_divert(GROW)],       10000)
+
+
+# _m4_defun_pro(MACRO-NAME)
+# -------------------------
+# The prologue for Autoconf macros.
+m4_define([_m4_defun_pro],
+[m4_expansion_stack_push(m4_defn([m4_location($1)])[: $1 is expanded 
from...])dnl
+m4_pushdef([_m4_expanding($1)])dnl
+m4_ifdef([_m4_divert_dump],
+         [m4_divert_push(m4_defn([_m4_divert_diversion]))],
+         [m4_copy([_m4_divert_diversion], [_m4_divert_dump])dnl
+m4_divert_push([GROW])])dnl
+])
+
+
+# _m4_defun_epi(MACRO-NAME)
+# -------------------------
+# The Epilogue for Autoconf macros.  MACRO-NAME only helps tracing
+# the PRO/EPI pairs.
+m4_define([_m4_defun_epi],
+[m4_divert_pop()dnl
+m4_if(_m4_divert_dump, _m4_divert_diversion,
+      [m4_undivert([GROW])dnl
+m4_undefine([_m4_divert_dump])])dnl
+m4_expansion_stack_pop()dnl
+m4_popdef([_m4_expanding($1)])dnl
+m4_provide([$1])dnl
+])
+
+
+# m4_defun(NAME, EXPANSION)
+# -------------------------
+# Define a macro which automatically provides itself.  Add machinery
+# so the macro automatically switches expansion to the diversion
+# stack if it is not already using it.  In this case, once finished,
+# it will bring back all the code accumulated in the diversion stack.
+# This, combined with m4_require, achieves the topological ordering of
+# macros.  We don't use this macro to define some frequently called
+# macros that are not involved in ordering constraints, to save m4
+# processing.
+m4_define([m4_defun],
+[m4_define([m4_location($1)], m4_location)dnl
+m4_define([$1],
+          [_m4_defun_pro([$1])$2[]_m4_defun_epi([$1])])])
+
+
+# m4_defun_once(NAME, EXPANSION)
+# ------------------------------
+# As m4_defun, but issues the EXPANSION only once, and warns if used
+# several times.
+m4_define([m4_defun_once],
+[m4_define([m4_location($1)], m4_location)dnl
+m4_define([$1],
+          [m4_provide_if([$1],
+                         [m4_warn([syntax], [$1 invoked multiple times])],
+                         [_m4_defun_pro([$1])$2[]_m4_defun_epi([$1])])])])
+
+
+# m4_pattern_forbid(ERE, [WHY])
+# -----------------------------
+# Declare that no token matching the extended regular expression ERE
+# should be seen in the output but if...
+m4_define([m4_pattern_forbid], [])
+
+
+# m4_pattern_allow(ERE)
+# ---------------------
+# ... but if that token matches the extended regular expression ERE.
+# Both used via traces.
+m4_define([m4_pattern_allow], [])
+
+
+## ----------------------------- ##
+## Dependencies between macros.  ##
+## ----------------------------- ##
+
+
+# m4_before(THIS-MACRO-NAME, CALLED-MACRO-NAME)
+# ---------------------------------------------
+m4_define([m4_before],
+[m4_provide_if([$2],
+               [m4_warn([syntax], [$2 was called before $1])])])
+
+
+# m4_require(NAME-TO-CHECK, [BODY-TO-EXPAND = NAME-TO-CHECK])
+# -----------------------------------------------------------
+# If NAME-TO-CHECK has never been expanded (actually, if it is not
+# m4_provide'd), expand BODY-TO-EXPAND *before* the current macro
+# expansion.  Once expanded, emit it in _m4_divert_dump.  Keep track
+# of the m4_require chain in m4_expansion_stack.
+#
+# The normal cases are:
+#
+# - NAME-TO-CHECK == BODY-TO-EXPAND
+#   Which you can use for regular macros with or without arguments, e.g.,
+#     m4_require([AC_PROG_CC], [AC_PROG_CC])
+#     m4_require([AC_CHECK_HEADERS(limits.h)], [AC_CHECK_HEADERS(limits.h)])
+#   which is just the same as
+#     m4_require([AC_PROG_CC])
+#     m4_require([AC_CHECK_HEADERS(limits.h)])
+#
+# - BODY-TO-EXPAND == m4_indir([NAME-TO-CHECK])
+#   In the case of macros with irregular names.  For instance:
+#     m4_require([AC_LANG_COMPILER(C)], [indir([AC_LANG_COMPILER(C)])])
+#   which means `if the macro named `AC_LANG_COMPILER(C)' (the parens are
+#   part of the name, it is not an argument) has not been run, then
+#   call it.'
+#   Had you used
+#     m4_require([AC_LANG_COMPILER(C)], [AC_LANG_COMPILER(C)])
+#   then m4_require would have tried to expand `AC_LANG_COMPILER(C)', i.e.,
+#   call the macro `AC_LANG_COMPILER' with `C' as argument.
+#
+#   You could argue that `AC_LANG_COMPILER', when it receives an argument
+#   such as `C' should dispatch the call to `AC_LANG_COMPILER(C)'.  But this
+#   `extension' prevents `AC_LANG_COMPILER' from having actual arguments that
+#   it passes to `AC_LANG_COMPILER(C)'.
+m4_define([m4_require],
+[m4_expansion_stack_push(m4_location[: $1 is required by...])dnl
+m4_ifdef([_m4_expanding($1)],
+         [m4_fatal([$0: circular dependency of $1])])dnl
+m4_ifndef([_m4_divert_dump],
+          [m4_fatal([$0: cannot be used outside of an m4_defun'd macro])])dnl
+m4_provide_if([$1],
+              [],
+              [m4_divert_push(m4_eval(m4_divnum - 1))dnl
+m4_default([$2], [$1])
+m4_divert(m4_defn([_m4_divert_dump]))dnl
+m4_undivert(m4_defn([_m4_divert_diversion]))dnl
+m4_divert_pop(m4_defn([_m4_divert_dump]))])dnl
+m4_provide_if([$1],
+              [],
+              [m4_warn([syntax],
+                       [$1 is m4_require'd but is not m4_defun'd])])dnl
+m4_expansion_stack_pop()dnl
+])
+
+
+# m4_expand_once(TEXT, [WITNESS = TEXT])
+# --------------------------------------
+# If TEXT has never been expanded, expand it *here*.  Use WITNESS as
+# as a memory that TEXT has already been expanded.
+m4_define([m4_expand_once],
+[m4_provide_if(m4_ifval([$2], [[$2]], [[$1]]),
+               [],
+               [m4_provide(m4_ifval([$2], [[$2]], [[$1]]))[]$1])])
+
+
+# m4_provide(MACRO-NAME)
+# ----------------------
+m4_define([m4_provide],
+[m4_define([m4_provide($1)])])
+
+
+# m4_provide_if(MACRO-NAME, IF-PROVIDED, IF-NOT-PROVIDED)
+# -------------------------------------------------------
+# If MACRO-NAME is provided do IF-PROVIDED, else IF-NOT-PROVIDED.
+# The purpose of this macro is to provide the user with a means to
+# check macros which are provided without letting her know how the
+# information is coded.
+m4_define([m4_provide_if],
+[m4_ifdef([m4_provide($1)],
+          [$2], [$3])])
+
+
+## -------------------- ##
+## 9. Text processing.  ##
+## -------------------- ##
+
+
+# m4_cr_letters
+# m4_cr_LETTERS
+# m4_cr_Letters
+# -------------
+m4_define([m4_cr_letters], [abcdefghijklmnopqrstuvwxyz])
+m4_define([m4_cr_LETTERS], [ABCDEFGHIJKLMNOPQRSTUVWXYZ])
+m4_define([m4_cr_Letters],
+m4_defn([m4_cr_letters])dnl
+m4_defn([m4_cr_LETTERS])dnl
+)
+
+
+# m4_cr_digits
+# ------------
+m4_define([m4_cr_digits], [0123456789])
+
+
+# m4_cr_symbols1 & m4_cr_symbols2
+# -------------------------------
+m4_define([m4_cr_symbols1],
+m4_defn([m4_cr_Letters])dnl
+_)
+
+m4_define([m4_cr_symbols2],
+m4_defn([m4_cr_symbols1])dnl
+m4_defn([m4_cr_digits])dnl
+)
+
+
+# m4_re_escape(STRING)
+# --------------------
+# Escape BRE active characters in STRING.
+m4_define([m4_re_escape],
+[m4_bpatsubst([$1],
+              [[][+*.]], [\\\&])])
+
+
+# m4_re_string
+# ------------
+# Regexp for `[a-zA-Z_0-9]*'
+m4_define([m4_re_string],
+m4_dquote(m4_defn([m4_cr_symbols2]))dnl
+[*]dnl
+)
+
+
+# m4_re_word
+# ----------
+# Regexp for `[a-zA-Z_][a-zA-Z_0-9]*'
+m4_define([m4_re_word],
+m4_dquote(m4_defn([m4_cr_symbols1]))dnl
+m4_defn([m4_re_string])dnl
+)
+
+
+# m4_tolower(STRING)
+# m4_toupper(STRING)
+# ------------------
+# These macros lowercase and uppercase strings.
+m4_define([m4_tolower],
+[m4_translit([$1], m4_defn([m4_cr_LETTERS]), m4_defn([m4_cr_letters]))])
+m4_define([m4_toupper],
+[m4_translit([$1], m4_defn([m4_cr_letters]), m4_defn([m4_cr_LETTERS]))])
+
+
+# m4_split(STRING, [REGEXP])
+# --------------------------
+#
+# Split STRING into an m4 list of quoted elements.  The elements are
+# quoted with [ and ].  Beginning spaces and end spaces *are kept*.
+# Use m4_strip to remove them.
+#
+# REGEXP specifies where to split.  Default is [\t ]+.
+#
+# Pay attention to the m4_changequotes.  Inner m4_changequotes exist for
+# obvious reasons (we want to insert square brackets).  Outer
+# m4_changequotes are needed because otherwise the m4 parser, when it
+# sees the closing bracket we add to the result, believes it is the
+# end of the body of the macro we define.
+#
+# Also, notice that $1 is quoted twice, since we want the result to
+# be quoted.  Then you should understand that the argument of
+# patsubst is ``STRING'' (i.e., with additional `` and '').
+#
+# This macro is safe on active symbols, i.e.:
+#   m4_define(active, ACTIVE)
+#   m4_split([active active ])end
+#   => [active], [active], []end
+
+m4_changequote(<<, >>)
+m4_define(<<m4_split>>,
+<<m4_changequote(``, '')dnl
+[dnl Can't use m4_default here instead of m4_if, because m4_default uses
+dnl [ and ] as quotes.
+m4_bpatsubst(````$1'''',
+            m4_if(``$2'',, ``[         ]+'', ``$2''),
+            ``], ['')]dnl
+m4_changequote([, ])>>)
+m4_changequote([, ])
+
+
+
+# m4_flatten(STRING)
+# ------------------
+# If STRING contains end of lines, replace them with spaces.  If there
+# are backslashed end of lines, remove them.  This macro is safe with
+# active symbols.
+#    m4_define(active, ACTIVE)
+#    m4_flatten([active
+#    act\
+#    ive])end
+#    => active activeend
+m4_define([m4_flatten],
+[m4_translit(m4_bpatsubst([[[$1]]], [\\
+]), [
+], [ ])])
+
+
+# m4_strip(STRING)
+# ----------------
+# Expands into STRING with tabs and spaces singled out into a single
+# space, and removing leading and trailing spaces.
+#
+# This macro is robust to active symbols.
+#    m4_define(active, ACTIVE)
+#    m4_strip([  active                active ])end
+#    => active activeend
+#
+# This macro is fun!  Because we want to preserve active symbols, STRING
+# must be quoted for each evaluation, which explains there are 4 levels
+# of brackets around $1 (don't forget that the result must be quoted
+# too, hence one more quoting than applications).
+#
+# Then notice the 2 last pattens: they are in charge of removing the
+# leading/trailing spaces.  Why not just `[^ ]'?  Because they are
+# applied to doubly quoted strings, i.e. more or less [[STRING]].  So
+# if there is a leading space in STRING, then it is the *third*
+# character, since there are two leading `['; equally for the last pattern.
+m4_define([m4_strip],
+[m4_bpatsubsts([[$1]],
+               [[      ]+], [ ],
+               [^\(..\) ],    [\1],
+               [ \(..\)$],    [\1])])
+
+
+# m4_normalize(STRING)
+# --------------------
+# Apply m4_flatten and m4_strip to STRING.
+#
+# The argument is quoted, so that the macro is robust to active symbols:
+#
+#    m4_define(active, ACTIVE)
+#    m4_normalize([  act\
+#    ive
+#    active ])end
+#    => active activeend
+
+m4_define([m4_normalize],
+[m4_strip(m4_flatten([$1]))])
+
+
+
+# m4_join(SEP, ARG1, ARG2...)
+# ---------------------------
+# Produce ARG1SEPARG2...SEPARGn.
+m4_defun([m4_join],
+[m4_case([$#],
+         [1], [],
+         [2], [[$2]],
+         [[$2][$1]$0([$1], m4_shiftn(2, $@))])])
+
+
+
+# m4_append(MACRO-NAME, STRING, [SEPARATOR])
+# ------------------------------------------
+# Redefine MACRO-NAME to hold its former content plus `SEPARATOR`'STRING'
+# at the end.  It is valid to use this macro with MACRO-NAME undefined,
+# in which case no SEPARATOR is added.  Be aware that the criterion is
+# `not being defined', and not `not being empty'.
+#
+# This macro is robust to active symbols.  It can be used to grow
+# strings.
+#
+#    | m4_define(active, ACTIVE)
+#    | m4_append([sentence], [This is an])
+#    | m4_append([sentence], [ active ])
+#    | m4_append([sentence], [symbol.])
+#    | sentence
+#    | m4_undefine([active])dnl
+#    | sentence
+#    => This is an ACTIVE symbol.
+#    => This is an active symbol.
+#
+# It can be used to define hooks.
+#
+#    | m4_define(active, ACTIVE)
+#    | m4_append([hooks], [m4_define([act1], [act2])])
+#    | m4_append([hooks], [m4_define([act2], [active])])
+#    | m4_undefine([active])
+#    | act1
+#    | hooks
+#    | act1
+#    => act1
+#    =>
+#    => active
+m4_define([m4_append],
+[m4_define([$1],
+           m4_ifdef([$1], [m4_defn([$1])$3])[$2])])
+
+
+# m4_append_uniq(MACRO-NAME, STRING, [SEPARATOR])
+# -----------------------------------------------
+# As `m4_append', but append only if not yet present.
+m4_define([m4_append_uniq],
+[m4_ifdef([$1],
+          [m4_bmatch([$3]m4_defn([$1])[$3], m4_re_escape([$3$2$3]), [],
+                     [m4_append($@)])],
+          [m4_append($@)])])
+
+
+# m4_foreach_quoted(VARIABLE, LIST, EXPRESSION)
+# ---------------------------------------------
+# FIXME: This macro should not exists.  Currently it's used only in
+# m4_wrap, which needs to be rewritten.  But it's godam hard.
+m4_define([m4_foreach_quoted],
+[m4_pushdef([$1], [])_m4_foreach_quoted($@)m4_popdef([$1])])
+
+# Low level macros used to define m4_foreach.
+m4_define([m4_car_quoted], [[$1]])
+m4_define([_m4_foreach_quoted],
+[m4_if($2, [()], ,
+       [m4_define([$1], [m4_car_quoted$2])$3[]_m4_foreach_quoted([$1],
+                                                               [(m4_shift$2)],
+                                                               [$3])])])
+
+
+# m4_text_wrap(STRING, [PREFIX], [FIRST-PREFIX], [WIDTH])
+# -------------------------------------------------------
+# Expands into STRING wrapped to hold in WIDTH columns (default = 79).
+# If prefix is set, each line is prefixed with it.  If FIRST-PREFIX is
+# specified, then the first line is prefixed with it.  As a special
+# case, if the length of the first prefix is greater than that of
+# PREFIX, then FIRST-PREFIX will be left alone on the first line.
+#
+# Typical outputs are:
+#
+# m4_text_wrap([Short string */], [   ], [/* ], 20)
+#  => /* Short string */
+#
+# m4_text_wrap([Much longer string */], [   ], [/* ], 20)
+#  => /* Much longer
+#  =>    string */
+#
+# m4_text_wrap([Short doc.], [          ], [  --short ], 30)
+#  =>   --short Short doc.
+#
+# m4_text_wrap([Short doc.], [          ], [  --too-wide ], 30)
+#  =>   --too-wide
+#  =>           Short doc.
+#
+# m4_text_wrap([Super long documentation.], [          ], [  --too-wide ], 30)
+#  =>   --too-wide
+#  =>    Super long
+#  =>    documentation.
+#
+# FIXME: there is no checking of a longer PREFIX than WIDTH, but do
+# we really want to bother with people trying each single corner
+# of a software?
+#
+# This macro does not leave a trailing space behind the last word,
+# what complicates it a bit.  The algorithm is stupid simple: all the
+# words are preceded by m4_Separator which is defined to empty for the
+# first word, and then ` ' (single space) for all the others.
+m4_define([m4_text_wrap],
+[m4_pushdef([m4_Prefix], m4_default([$2], []))dnl
+m4_pushdef([m4_Prefix1], m4_default([$3], [m4_Prefix]))dnl
+m4_pushdef([m4_Width], m4_default([$4], 79))dnl
+m4_pushdef([m4_Cursor], m4_len(m4_Prefix1))dnl
+m4_pushdef([m4_Separator], [])dnl
+m4_Prefix1[]dnl
+m4_if(m4_eval(m4_Cursor > m4_len(m4_Prefix)),
+      1, [m4_define([m4_Cursor], m4_len(m4_Prefix))
+m4_Prefix])[]dnl
+m4_foreach_quoted([m4_Word], (m4_split(m4_normalize([$1]))),
+[m4_define([m4_Cursor], m4_eval(m4_Cursor + m4_len(m4_Word) + 1))dnl
+dnl New line if too long, else insert a space unless it is the first
+dnl of the words.
+m4_if(m4_eval(m4_Cursor > m4_Width),
+      1, [m4_define([m4_Cursor],
+                    m4_eval(m4_len(m4_Prefix) + m4_len(m4_Word) + 1))]
+m4_Prefix,
+       [m4_Separator])[]dnl
+m4_Word[]dnl
+m4_define([m4_Separator], [ ])])dnl
+m4_popdef([m4_Separator])dnl
+m4_popdef([m4_Cursor])dnl
+m4_popdef([m4_Width])dnl
+m4_popdef([m4_Prefix1])dnl
+m4_popdef([m4_Prefix])dnl
+])
+
+
+# m4_text_box(MESSAGE, [FRAME-CHARACTER = `-'])
+# ---------------------------------------------
+m4_define([m4_text_box],
address@hidden:@@%:@ m4_bpatsubst([$1], [.], m4_if([$2], [], [[-]], [[$2]])) 
@%:@@%:@
address@hidden:@@%:@ $1 @%:@@%:@
address@hidden:@@%:@ m4_bpatsubst([$1], [.], m4_if([$2], [], [[-]], [[$2]])) 
@%:@@%:@[]dnl
+])
+
+
+
+## ----------------------- ##
+## 10. Number processing.  ##
+## ----------------------- ##
+
+# m4_sign(A)
+# ----------
+#
+# The sign of the integer A.
+m4_define([m4_sign],
+[m4_bmatch([$1],
+           [^-], -1,
+           [^0+], 0,
+                  1)])
+
+# m4_cmp(A, B)
+# ------------
+#
+# Compare two integers.
+# A < B -> -1
+# A = B ->  0
+# A > B ->  1
+m4_define([m4_cmp],
+[m4_sign(m4_eval([$1 - $2]))])
+
+
+# m4_list_cmp(A, B)
+# -----------------
+#
+# Compare the two lists of integers A and B.  For instance:
+#   m4_list_cmp((1, 0),     (1))    ->  0
+#   m4_list_cmp((1, 0),     (1, 0)) ->  0
+#   m4_list_cmp((1, 2),     (1, 0)) ->  1
+#   m4_list_cmp((1, 2, 3),  (1, 2)) ->  1
+#   m4_list_cmp((1, 2, -3), (1, 2)) -> -1
+#   m4_list_cmp((1, 0),     (1, 2)) -> -1
+#   m4_list_cmp((1),        (1, 2)) -> -1
+m4_define([m4_list_cmp],
+[m4_if([$1$2], [()()], 0,
+       [$1], [()], [$0((0), [$2])],
+       [$2], [()], [$0([$1], (0))],
+       [m4_case(m4_cmp(m4_car$1, m4_car$2),
+                -1, -1,
+                 1, 1,
+                 0, [$0((m4_shift$1), (m4_shift$2))])])])
+
+
+
+## ------------------------ ##
+## 11. Version processing.  ##
+## ------------------------ ##
+
+
+# m4_version_unletter(VERSION)
+# ----------------------------
+# Normalize beta version numbers with letters to numbers only for comparison.
+#
+#   Nl -> (N+1).-1.(l#)
+#
+#i.e., 2.14a -> 2.15.-1.1, 2.14b -> 2.15.-1.2, etc.
+# This macro is absolutely not robust to active macro, it expects
+# reasonable version numbers and is valid up to `z', no double letters.
+m4_define([m4_version_unletter],
+[m4_translit(m4_bpatsubsts([$1],
+                           [\([0-9]+\)\([abcdefghi]\)],
+                             [m4_eval(\1 + 1).-1.\2],
+                           [\([0-9]+\)\([jklmnopqrs]\)],
+                             [m4_eval(\1 + 1).-1.1\2],
+                           [\([0-9]+\)\([tuvwxyz]\)],
+                             [m4_eval(\1 + 1).-1.2\2]),
+             [abcdefghijklmnopqrstuvwxyz],
+             [12345678901234567890123456])])
+
+
+# m4_version_compare(VERSION-1, VERSION-2)
+# ----------------------------------------
+# Compare the two version numbers and expand into
+#  -1 if VERSION-1 < VERSION-2
+#   0 if           =
+#   1 if           >
+m4_define([m4_version_compare],
+[m4_list_cmp((m4_split(m4_version_unletter([$1]), [\.])),
+             (m4_split(m4_version_unletter([$2]), [\.])))])
+
+
+# m4_PACKAGE_NAME
+# m4_PACKAGE_TARNAME
+# m4_PACKAGE_VERSION
+# m4_PACKAGE_STRING
+# m4_PACKAGE_BUGREPORT
+# --------------------
+m4_include([m4sugar/version.m4])
+
+
+# m4_version_prereq(VERSION, [IF-OK], [IF-NOT = FAIL])
+# ----------------------------------------------------
+# Check this Autoconf version against VERSION.
+m4_define([m4_version_prereq],
+[m4_if(m4_version_compare(m4_defn([m4_PACKAGE_VERSION]), [$1]), -1,
+       [m4_default([$3],
+                   [m4_fatal([Autoconf version $1 or higher is required])])],
+       [$2])[]dnl
+])
+
+
+
+## ------------------- ##
+## 12. File handling.  ##
+## ------------------- ##
+
+
+# It is a real pity that M4 comes with no macros to bind a diversion
+# to a file.  So we have to deal without, which makes us a lot more
+# fragile that we should.
+
+
+# m4_file_append(FILE-NAME, CONTENT)
+# ----------------------------------
+m4_define([m4_file_append],
+[m4_syscmd([cat >>$1 <<_m4eof
+$2
+_m4eof
+])
+m4_if(m4_sysval, [0], [],
+      [m4_fatal([$0: cannot write: $1])])])
+
+
+
+## ------------------------ ##
+## 13. Setting M4sugar up.  ##
+## ------------------------ ##
+
+
+# m4_init
+# -------
+m4_define([m4_init],
+[# All the M4sugar macros start with `m4_', except `dnl' kept as is
+# for sake of simplicity.
+m4_pattern_forbid([^_?m4_])
+m4_pattern_forbid([^dnl$])
+
+# Check the divert push/pop perfect balance.
+m4_wrap([m4_ifdef([_m4_divert_diversion],
+                  [m4_fatal([$0: unbalanced m4_divert_push:]
+m4_defn([m4_divert_stack]))])[]])
+
+m4_divert_push([KILL])
+m4_wrap([m4_divert_pop([KILL])[]])
+])
Index: data/m4sugar/version.m4
--- data/m4sugar/version.m4 Mon, 04 Feb 2002 23:18:49 +0100 akim
+++ data/m4sugar/version.m4 Wed, 30 Jan 2002 22:10:14 +0100 akim
@@ -0,0 +1,9 @@
+# This file is part of -*- Autoconf -*-.
+# Version of Autoconf.
+# Copyright 1999, 2000, 2001 Free Software Foundation, Inc.
+
+m4_define([m4_PACKAGE_NAME],      [GNU Autoconf])
+m4_define([m4_PACKAGE_TARNAME],   [autoconf])
+m4_define([m4_PACKAGE_VERSION],   [2.52h])
+m4_define([m4_PACKAGE_STRING],    [GNU Autoconf 2.52h])
+m4_define([m4_PACKAGE_BUGREPORT], address@hidden)
Index: src/parse-skel.y
--- src/parse-skel.y Thu, 10 Jan 2002 20:53:27 +0100 akim
+++ src/parse-skel.y Mon, 04 Feb 2002 23:18:49 +0100 akim
@@ -1,231 +0,0 @@
-                                                             /* -*- C -*- */
-/* Parse Bison Skeletons.
-   Copyright (C) 2001  Free Software Foundation, Inc.
-
-   This file is part of Bison, the GNU Compiler Compiler.
-
-   Bison is free software; you can redistribute it and/or modify it
-   under the terms of the GNU General Public License as published by
-   the Free Software Foundation; either version 2, or (at your option)
-   any later version.
-
-   Bison is distributed in the hope that it will be useful, but
-   WITHOUT ANY WARRANTY; without even the implied warranty of
-   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
-   General Public License for more details.
-
-   You should have received a copy of the GNU General Public License
-   along with Bison; see the file COPYING.  If not, write to the Free
-   Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
-   02111-1307, USA.  */
-
-%debug
-%defines
-%verbose
-%locations
-%name-prefix="skel_"
-%pure-parser
-
-%{
-#include "system.h"
-#include "obstack.h"
-#include "quotearg.h"
-#include "files.h"
-#include "getargs.h"
-#include "output.h"
-#include "skeleton.h"
-#include "muscle_tab.h"
-
-#define YYERROR_VERBOSE 1
-
-/* Pass the control structure to YYPARSE but not YYLEX (yet?). */
-#define YYPARSE_PARAM skel_control
-/* YYPARSE receives SKEL_CONTROL as a void *.  Provide a correctly
-   typed access to it.  */
-#define yycontrol ((skel_control_t *) skel_control)
-
-FILE* parser = NULL;
-
-size_t output_line;
-size_t skeleton_line;
-
-static void merror PARAMS ((const char* error));
-
-/* Request detailed parse error messages, and pass them to
-   YLEVAL_ERROR. */
-#undef  yyerror
-#define yyerror(Msg) \
-        skel_error (yycontrol, &yylloc, Msg)
-
-/* When debugging our pure parser, we want to see values and locations
-   of the tokens.  */
-#define YYPRINT(File, Type, Value) \
-        yyprint (File, &yylloc, Type, &Value)
-static void yyprint (FILE *file, const yyltype *loc,
-                     int type, const yystype *value);
-%}
-
-%union
-{
-  char *string;
-  char character;
-  int  boolean;
-}
-
-/* Name of a muscle. */
-%token <string> MUSCLE
-/* A string dedicated to Bison (%%"foo").  */
-%token <string> STRING
-/* Raw data, to output directly. */
-%token <string> RAW
-/* Spaces. */
-%token <string> BLANKS
-/* Raw data, but char by char. */
-%token <character> CHARACTER
-
-%token LINE
-%token SLINE
-
-%token SECTION
-
-%token GUARDS
-%token TOKENS
-%token ACTIONS
-
-%type <string> string.1 string
-
-%start input
-
-%%
-input:
-     { LOCATION_RESET (yylloc) } skeleton
-  ;
-
-skeleton : /* Empty.  */    { }
-         | section skeleton { }
-;
-
-section : section.header section.body { }
-;
-
-section.header : SECTION BLANKS string '\n'
-{
-  char *name = $3;
-
-  /* Close the previous parser.  */
-  if (parser)
-    parser = (xfclose (parser), NULL);
-
-  /* Prepare the next parser to be output.  */
-  parser = xfopen (name, "w");
-  MUSCLE_INSERT_STRING ("parser-file-name", name);
-  XFREE (name);
-
-  ++skeleton_line;
-}
-;
-
-/* Either a literal string, or a muscle value.  */
-string.1:
-    STRING { $$ = $1; }
-  | MUSCLE { $$ = xstrdup (muscle_find ($1)); }
-  ;
-
-/* Either a literal string, or a muscle value, or the concatenation of
-   them.  */
-string:
-    string.1
-    { $$ = $1; }
-  | string BLANKS string.1
-    { $$ = stringappend ($1, $3); free ($1); free ($3); }
-  ;
-
-section.body
-: /* Empty.  */ { }
-| section.body '\n' { fputc ('\n', parser); ++output_line; ++skeleton_line; }
-| section.body LINE  { fprintf (parser, "%d", output_line); }
-| section.body SLINE { fprintf (parser, "%d", skeleton_line); }
-| section.body GUARDS { guards_output (parser, &output_line); }
-| section.body TOKENS { token_definitions_output (parser, &output_line); }
-| section.body ACTIONS { actions_output (parser, &output_line); }
-| section.body CHARACTER { fputc ($2, parser); }
-| section.body RAW       { fputs ($2, parser); }
-| section.body BLANKS    { fputs ($2, parser); }
-| section.body MUSCLE {
-  const char* value = muscle_find ($2);
-  if (value)
-    {
-      fputs (value, parser);
-      output_line += get_lines_number (value);
-    }
-  else
-    {
-      fprintf (parser, "%%{%s}", $2);
-      merror ($2);
-    }
-}
-;
-%%
-/*------------------------------------------------------------------.
-| When debugging the parser, display tokens' locations and values.  |
-`------------------------------------------------------------------*/
-
-static void
-yyprint (FILE *file,
-         const yyltype *loc, int type, const yystype *value)
-{
-  fputs (" (", file);
-  LOCATION_PRINT (file, *loc);
-  fputs (")", file);
-  switch (type)
-    {
-    case MUSCLE:
-    case STRING:
-    case RAW:
-    case BLANKS:
-      fprintf (file, " = %s", quotearg_style (c_quoting_style,
-                                             value->string));
-      break;
-
-    case CHARACTER:
-      fprintf (file, " = '%c'", value->character);
-      break;
-    }
-}
-
-
-static void
-merror (const char* error)
-{
-  printf ("line %d: %%{%s} undeclared.\n", skeleton_line, error);
-}
-
-void
-skel_error (skel_control_t *control,
-           const yyltype *loc, const char *msg)
-{
-  /* Neutralize GCC warnings for unused parameters. */
-  skel_control_t *c = control;
-  c++;
-  LOCATION_PRINT (stderr, *loc);
-  fprintf (stderr, "%s\n", msg);
-}
-
-void
-process_skeleton (const char* skel)
-{
-  /* Prepare a few things.  */
-  output_line = 1;
-  skeleton_line = 1;
-
-  /* Output.  */
-  skel_in = fopen (skel, "r");
-  /* FIXME: This is not acceptable for a release. */
-  skel__flex_debug = getenv ("BISON_TRACE_SCAN") ? 1 : 0;
-  skel_debug = getenv ("BISON_TRACE_PARSE") ? 1 : 0;
-  skel_parse (NULL);
-
-  /* Close the last parser.  */
-  if (parser)
-    parser = (xfclose (parser), NULL);
-}



reply via email to

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