modules: huge simplification of module loading without libltdl.
[m4/ericb.git] / modules / modtest.c
blob2026431debfb00a33992a5d90675817019645043
1 /* GNU m4 -- A simple macro processor
2 Copyright (C) 1999-2001, 2003-2004, 2006-2008, 2010, 2013 Free
3 Software Foundation, Inc.
5 This file is part of GNU M4.
7 GNU M4 is free software: you can redistribute it and/or modify
8 it under the terms of the GNU General Public License as published by
9 the Free Software Foundation, either version 3 of the License, or
10 (at your option) any later version.
12 GNU M4 is distributed in the hope that it will be useful,
13 but WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 GNU General Public License for more details.
17 You should have received a copy of the GNU General Public License
18 along with this program. If not, see <http://www.gnu.org/licenses/>.
21 #include <config.h>
23 /* Build using only the exported interfaces, unless NDEBUG is set, in
24 which case use private symbols to speed things up as much as possible. */
25 #ifndef NDEBUG
26 # include <m4/m4module.h>
27 #else
28 # include "m4private.h"
29 #endif
31 extern bool export_test (const char *foo);
33 /* function macros blind side minargs maxargs */
34 #define builtin_functions \
35 BUILTIN (test, false, false, false, 0, 0)
37 #define BUILTIN(handler, macros, blind, side, min, max) M4BUILTIN (handler)
38 builtin_functions
39 #undef BUILTIN
41 static const m4_builtin m4_builtin_table[] =
43 #define BUILTIN(handler, macros, blind, side, min, max) \
44 M4BUILTIN_ENTRY (handler, #handler, macros, blind, side, min, max)
46 builtin_functions
47 #undef BUILTIN
49 { NULL, NULL, 0, 0, 0 },
52 static const m4_macro m4_macro_table[] =
54 /* name text min max */
55 { "__test__", "`modtest'", 0, 0 },
56 { "onearg", "$1", 1, 1 },
57 { "manyargs", "$@", 0, SIZE_MAX },
58 { NULL, NULL, 0, 0 },
63 /**
64 * modtest()
65 **/
66 void
67 include_modtest (m4 *context, m4_module *module, m4_obstack *obs)
69 const char *s = "Test module loaded.\n";
71 m4_install_builtins (context, module, m4_builtin_table);
72 m4_install_macros (context, module, m4_macro_table);
74 /* Don't depend on OBS so that the traces are the same when used
75 directly, or via a frozen file. */
76 fputs (s, stderr);
80 /**
81 * test()
82 **/
83 M4BUILTIN_HANDLER (test)
85 const char *s = "Test module called.";
87 assert (obs != 0);
88 obstack_grow (obs, s, strlen(s));
92 /**
93 * export_test()
94 **/
95 bool
96 export_test (const char *foo)
98 if (foo)
99 xfprintf (stderr, "%s\n", foo);
100 return (bool) (foo != 0);