1 dnl-----------------------------------------------------------------------
3 dnl Karls M4 macros for the signal system used by gtk--
5 dnl Copyright (C) 1998-2002 The gtkmm Development Team
7 dnl Currently maintained by Tero Pulkkinen. <terop@modeemi.cs.tut.fi>
9 dnl This library is free software; you can redistribute it and/or
10 dnl modify it under the terms of the GNU Library General Public
11 dnl License as published by the Free Software Foundation; either
12 dnl version 2 of the License, or (at your option) any later version.
14 dnl This library is distributed in the hope that it will be useful,
15 dnl but WITHOUT ANY WARRANTY; without even the implied warranty of
16 dnl MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
17 dnl Library General Public License for more details.
19 dnl You should have received a copy of the GNU Library General Public
20 dnl License along with this library; if not, write to the Free
21 dnl Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
23 dnl-----------------------------------------------------------------------
24 dnl Recursion prevention. (Don't attempt to understand why this works!)
27 pushdef([DIVERSION],divnum)dnl
30 ifdef([__template_macros__],[],[
31 define(__template_macros__)
32 dnl-----------------------------------------------------------------------
36 dnl M4 macros for general sanity
39 dnl M4 Quotas are hard to work with, so use braces like autoconf
40 dnl (which are matched by vi, emacs)
45 dnl M4 comments conflict with compiler directives
48 dnl BRACE(text) => [text]
49 dnl When we want something to appear with braces
50 define([BRACE],[[[$*]]])
54 dnl If a macro generates an output with commas we need to protect it
55 dnl from being broken down and interpreted
60 dnl lowercase a string
61 define([LOWER],[translit([$*],[ABCDEFGHIJKLMNOPQRSTUVWXYZ],[abcdefghijklmnopqrstuvwxyz])])
65 dnl uppercase a string
66 define([UPPER],[translit([$*],[abcdefghijklmnopqrstuvwxyz],[ABCDEFGHIJKLMNOPQRSTUVWXYZ])])
67 define([UPPER_SAFE],[translit([$*],[abcdefghijklmnopqrstuvwxyz.-],[ABCDEFGHIJKLMNOPQRSTUVWXYZ__])])
71 dnl extract the basename of a string
72 define([BASENAME],[patsubst([$*],[^.*/],[])])
76 dnl extract the basename of a string
77 define([M4NAME],[patsubst(BASENAME([$*]),[\.m4$],[])])
80 dnl M4 defines $# very badly (empty list=1). So we need a better one
81 define([NUM],[ifelse(len([$*]),0,0,[$#])])
84 dnl IF(cond,string1,string2)
85 dnl places string1 if length (without spaces) of cond is zero,
87 define([IF],[ifelse(len(PROT(translit([$1],[ ]))),0,[$3],[$2])])
88 dnl define([IF],[ifelse(len(PROT(patsubst([$1],[ ]))),0,[$3],[$2])])
91 dnl minclude(filename)
92 dnl This includes only the macros from a file but throws away the output.
93 dnl Used to take the macros from a file without getting it extra output.
94 define([minclude],[IF([$1],[dnl
95 pushdef([CURRENT_DIVERSION],divnum)dnl
98 divert(CURRENT_DIVERSION)dnl
99 popdef([CURRENT_DIVERSION])dnl],[[minclude]])])
102 dnl makes the current filename into a string approprate for use as
103 dnl C identified define. (Defaults to this library name)
105 dnl example: (filename test.hh.m4)
106 dnl __header__ => SIGCXX_TEST_H
107 dnl __header__(MYHEAD) => MYHEAD_TEST_H
108 dnl define([__header__],[ifelse($1,,[SIGCXX],UPPER($1))[_]UPPER(patsubst(translit(BASENAME(__file__),[.-],[__]),[_m4],[]))])
109 define([__header__],[ifelse($1,,[_GLIBMM],UPPER($1))[_]UPPER_SAFE(M4NAME(__file__))])
112 dnl Set of M4 macros for variable argument template building
115 dnl ARGS(name,number)
116 dnl Builds a comma seperated protected list of numbered names
117 dnl Use this as short hand to specify arguement names
119 dnl ARGS(arg,3) => ARG1,ARG2,ARG3
120 define([_ARGS],[ifelse(eval($2<$3),0,[$1$2],[$1$2,_ARGS($1,eval($2+1),$3)])])
121 define([ARGS],[ifelse(eval($2>0),1,[PROT(_ARGS(UPPER([$1]),1,$2))],[PROT])])
124 dnl LIST(string1,string2,...)
125 dnl These are intended for making extended argument lists
126 dnl parameters are in pairs, the first is output if the
127 dnl 2nd is nonzero length, the process is then repeated
128 dnl with the next set of arguments.
130 dnl Macro expansions that expand to result in commas must call
131 dnl PROT to prevent permature expansion. ARG* macros do
132 dnl this automatically. (If unsure, add braces until it stops
133 dnl interpreting inter macros, remove one set of braces, if
134 dnl still not right use PROT)
136 dnl (LIST is probably the most useful macro in the set.)
137 define([LIST],[ifelse($#,0,,$#,1,[$1],[$1],,[LIST(shift($@))],[__LIST($@)])])
138 define([__LIST],[ifelse($#,0,,$#,1,[$1],[$1[]ifelse([$2],,,[[,]])__LIST(shift($@))])])
141 dnl ARG_LOOP(macro_name,seperator,argument_list)
142 dnl Very powerful macro for construction of list of variables
143 dnl formated in specify ways. To use define a macro taking
144 dnl one variable which is called the format. The second argument
145 dnl is a seperator which will appear between each argument.
146 dnl The rest is then interpreted as arguments to form the list.
149 dnl define([FOO],[foo([$1])])
150 dnl ARG_LOOP([FOO],[[, ]],A,B,C)
152 dnl Gives: foo(A), foo(B), foo(C)
154 define([_ARG_LOOP],[dnl
155 ifelse(NUM($*),0,,NUM($*),1,[dnl
156 indir(LOOP_FORMAT,[$1])],[dnl
157 indir(LOOP_FORMAT,[$1])[]LOOP_SEPERATOR[]_ARG_LOOP(shift($*))])])
159 define([ARG_LOOP],[dnl
160 pushdef([LOOP_FORMAT],[[$1]])dnl
161 pushdef([LOOP_SEPERATOR],[$2])dnl
162 _ARG_LOOP(shift(shift($*)))[]dnl
163 popdef([LOOP_FORMAT])dnl
164 popdef([LOOP_SEPERATOR])dnl
169 dnl Define some useful formats for use with ARG_LOOP.
170 define([FORMAT_ARG_CLASS],[class [$1]])
171 define([FORMAT_ARG_BOTH],[[$1] LOWER([$1])])
172 define([FORMAT_ARG_REF],[Type<[$1]>::ref LOWER([$1])])
173 define([FORMAT_ARG_TYPE],[[$1]])
174 define([FORMAT_ARG_NAME],[LOWER($1)])
175 define([FORMAT_ARG_CBNAME],[LOWER($1)_])
176 define([FORMAT_ARG_CBDECL],[[$1] LOWER([$1])_;])
177 define([FORMAT_ARG_CBINIT],[LOWER([$1])_(LOWER([$1]))])
181 dnl The following functions generate various types of parameter lists
182 dnl For parameter lists
183 dnl ARG_CLASS([P1,P2]) -> class P1,class P2
184 dnl ARG_BOTH([P1,P2]) -> P1 p1,P2 p2
185 dnl ARG_TYPE([P1,P2]) -> P1,P2
186 dnl ARG_NAME([P1,P2]) -> p1,p2
187 dnl For callback lists
188 dnl ARG_CBNAME([C1,C2]) -> c1_,c2_
189 dnl ARG_CBINIT([C1,C2]) -> c1_(c1),c2_(c2)
190 dnl ARG_CBDECL([C1,C2]) -> C1 c1_; C2 c2_;
192 define([ARG_CLASS],[PROT(ARG_LOOP([FORMAT_ARG_CLASS],[[,]],$*))])
193 define([ARG_BOTH],[PROT(ARG_LOOP([FORMAT_ARG_BOTH],[[,]],$*))])
194 define([ARG_REF],[PROT(ARG_LOOP([FORMAT_ARG_REF],[[,]],$*))])
195 define([ARG_TYPE],[PROT([$*])])
196 define([ARG_NAME],[PROT(LOWER($*))])
197 define([ARG_CBNAME],[PROT(ARG_LOOP([FORMAT_ARG_CBNAME],[[,]],$*))])
198 define([ARG_CBDECL],[PROT(ARG_LOOP([FORMAT_ARG_CBDECL],[ ],$*))])
199 define([ARG_CBINIT],[PROT(ARG_LOOP([FORMAT_ARG_CBINIT],[[,]],$*))])
204 dnl Removes unnecessary <> with empty templates
205 dnl (occasionally useful)
206 define([T_DROP],[ifelse([$1],<>,,[$*])])
209 dnl DROP(string,drop)
210 dnl Removes unnecessary strings if they match drop
211 dnl (occasionally useful)
212 define([DROP],[ifelse([$1],[$2],,[$*])])
216 dnl places a #line statement if __debug__ set
217 dnl Use this at top of macro template and following
218 dnl macros that contain newlines.
221 dnl LINE(]__line__[)dnl
222 define([LINE],[ifdef([__debug__],[#line $1 "]__file__["
225 dnl-----------------------------------------------------------------------
226 dnl End of recursion protection. Do not put anything below this line.
229 popdef([DIVERSION])dnl