2 * This file is part of DisOrder
3 * Copyright (C) 2008 Richard Kettlewell
5 * This program is free software: you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation, either version 3 of the License, or
8 * (at your option) any later version.
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
15 * You should have received a copy of the GNU General Public License
16 * along with this program. If not, see <http://www.gnu.org/licenses/>.
19 /** @file lib/macros.h
20 * @brief Macro expansion
28 /** @brief One node in a macro expansion parse tree */
30 /** @brief Next element or NULL at end of list */
33 /** @brief Node type, @ref MX_TEXT or @ref MX_EXPANSION. */
36 /** @brief Filename containing this node */
39 /** @brief Line number at start of this node */
42 /** @brief Plain text (if @p type is @ref MX_TEXT) */
45 /** @brief Expansion name (if @p type is @ref MX_EXPANSION) */
48 /** @brief Argument count (if @p type is @ref MX_EXPANSION) */
51 /** @brief Argument values, parsed recursively (or NULL if @p nargs is 0) */
52 const struct mx_node **args;
55 /** @brief Text node */
58 /** @brief Expansion node */
59 #define MX_EXPANSION 1
61 const struct mx_node *mx_parse(const char *filename,
65 char *mx_dump(const struct mx_node *m);
68 /** @brief Callback for simple expansions
69 * @param nargs Number of arguments
70 * @param args Pointer to array of arguments
71 * @param output Where to send output
73 * @return 0 on success, non-zero on error
75 typedef int mx_simple_callback(int nargs,
80 /** @brief Callback for magic expansions
81 * @param nargs Number of arguments
82 * @param args Pointer to array of arguments
83 * @param output Where to send output
85 * @return 0 on success, non-zero on error
87 typedef int mx_magic_callback(int nargs,
88 const struct mx_node **args,
92 void mx_register(const char *name,
95 mx_simple_callback *callback);
96 void mx_register_magic(const char *name,
99 mx_magic_callback *callback);
100 int mx_register_macro(const char *name,
103 const struct mx_node *definition);
105 void mx_register_builtin(void);
106 void mx_search_path(const char *s);
107 char *mx_find(const char *name, int report);
109 int mx_expand_file(const char *path,
112 int mx_expand(const struct mx_node *m,
115 int mx_expandstr(const struct mx_node *m,
119 const struct mx_node *mx_rewrite(const struct mx_node *definition,
121 const struct mx_node *mx_rewritel(const struct mx_node *m,
124 int mx_str2bool(const char *s);
125 const char *mx_bool2str(int n);
126 int mx_bool_result(struct sink *output, int result);
128 #endif /* MACROS_H */