chiark / gitweb /
Rewrite uaudio-schedule.c. It's now much simpler and should actually
[disorder] / lib / macros.h
CommitLineData
1dcdf455
RK
1/*
2 * This file is part of DisOrder
3 * Copyright (C) 2008 Richard Kettlewell
4 *
e7eb3a27 5 * This program is free software: you can redistribute it and/or modify
1dcdf455 6 * it under the terms of the GNU General Public License as published by
e7eb3a27 7 * the Free Software Foundation, either version 3 of the License, or
1dcdf455 8 * (at your option) any later version.
e7eb3a27
RK
9 *
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.
14 *
1dcdf455 15 * You should have received a copy of the GNU General Public License
e7eb3a27 16 * along with this program. If not, see <http://www.gnu.org/licenses/>.
1dcdf455
RK
17 */
18
19/** @file lib/macros.h
20 * @brief Macro expansion
21 */
22
23#ifndef MACROS_H
24#define MACROS_H
25
f640bcb3
RK
26struct sink;
27
1dcdf455
RK
28/** @brief One node in a macro expansion parse tree */
29struct mx_node {
30 /** @brief Next element or NULL at end of list */
31 struct mx_node *next;
32
33 /** @brief Node type, @ref MX_TEXT or @ref MX_EXPANSION. */
34 int type;
35
36 /** @brief Filename containing this node */
37 const char *filename;
38
39 /** @brief Line number at start of this node */
40 int line;
41
42 /** @brief Plain text (if @p type is @ref MX_TEXT) */
f5fdc06f 43 const char *text;
1dcdf455
RK
44
45 /** @brief Expansion name (if @p type is @ref MX_EXPANSION) */
f5fdc06f 46 const char *name;
1dcdf455
RK
47
48 /** @brief Argument count (if @p type is @ref MX_EXPANSION) */
49 int nargs;
50
51 /** @brief Argument values, parsed recursively (or NULL if @p nargs is 0) */
52 const struct mx_node **args;
53};
54
55/** @brief Text node */
56#define MX_TEXT 0
57
58/** @brief Expansion node */
59#define MX_EXPANSION 1
60
61const struct mx_node *mx_parse(const char *filename,
62 int line,
63 const char *input,
64 const char *end);
9dbb630e
RK
65char *mx_dump(const struct mx_node *m);
66
f640bcb3
RK
67
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
72 * @param u User data
73 * @return 0 on success, non-zero on error
74 */
75typedef int mx_simple_callback(int nargs,
76 char **args,
77 struct sink *output,
78 void *u);
79
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
84 * @param u User data
85 * @return 0 on success, non-zero on error
86 */
87typedef int mx_magic_callback(int nargs,
88 const struct mx_node **args,
89 struct sink *output,
90 void *u);
91
92void mx_register(const char *name,
93 int min,
94 int max,
95 mx_simple_callback *callback);
b36be3a1 96void mx_register_magic(const char *name,
f640bcb3
RK
97 int min,
98 int max,
99 mx_magic_callback *callback);
b36be3a1
RK
100int mx_register_macro(const char *name,
101 int nargs,
102 char **args,
103 const struct mx_node *definition);
f640bcb3
RK
104
105void mx_register_builtin(void);
dd0f422a 106void mx_search_path(const char *s);
f2d306b4 107char *mx_find(const char *name, int report);
f640bcb3
RK
108
109int mx_expand_file(const char *path,
110 struct sink *output,
111 void *u);
112int mx_expand(const struct mx_node *m,
113 struct sink *output,
114 void *u);
115int mx_expandstr(const struct mx_node *m,
116 char **sp,
b36be3a1
RK
117 void *u,
118 const char *what);
9faa7a88
RK
119const struct mx_node *mx_rewrite(const struct mx_node *definition,
120 hash *h);
121const struct mx_node *mx_rewritel(const struct mx_node *m,
122 ...);
f640bcb3
RK
123
124int mx_str2bool(const char *s);
125const char *mx_bool2str(int n);
71634563 126int mx_bool_result(struct sink *output, int result);
f640bcb3 127
1dcdf455
RK
128#endif /* MACROS_H */
129
130
131/*
132Local Variables:
133c-basic-offset:2
134comment-column:40
135fill-column:79
136indent-tabs-mode:nil
137End:
138*/