1 dnl-----------------------------------------------------------------------
3 dnl Karls M4 macros for the signal system used by gtk--
5 dnl Copyright (C) 1998 Karl Nelson <kenelson@ece.ucdavis.edu>
8 dnl Currently maintained by Tero Pulkkinen. <terop@modeemi.cs.tut.fi>
10 dnl This library is free software; you can redistribute it and/or
11 dnl modify it under the terms of the GNU Library General Public
12 dnl License as published by the Free Software Foundation; either
13 dnl version 2 of the License, or (at your option) any later version.
15 dnl This library is distributed in the hope that it will be useful,
16 dnl but WITHOUT ANY WARRANTY; without even the implied warranty of
17 dnl MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
18 dnl Library General Public License for more details.
20 dnl You should have received a copy of the GNU Library General Public
21 dnl License along with this library; if not, write to the Free
22 dnl Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
24 dnl-----------------------------------------------------------------------
25 dnl Recursion prevention. (Don't attempt to understand why this works!)
28 pushdef([DIVERSION],divnum)dnl
31 ifdef([__template_macros__],[],[
32 define(__template_macros__)
33 dnl-----------------------------------------------------------------------
37 dnl M4 macros for general sanity
40 dnl M4 Quotas are hard to work with, so use braces like autoconf
41 dnl (which are matched by vi, emacs)
46 dnl M4 comments conflict with compiler directives
49 dnl BRACE(text) => [text]
50 dnl When we want something to appear with braces
51 define([BRACE],[[[$*]]])
55 dnl If a macro generates an output with commas we need to protect it
56 dnl from being broken down and interpreted
61 dnl lowercase a string
62 define([LOWER],[translit([$*],[ABCDEFGHIJKLMNOPQRSTUVWXYZ],[abcdefghijklmnopqrstuvwxyz])])
66 dnl uppercase a string
67 define([UPPER],[translit([$*],[abcdefghijklmnopqrstuvwxyz],[ABCDEFGHIJKLMNOPQRSTUVWXYZ])])
68 define([UPPER_SAFE],[translit([$*],[abcdefghijklmnopqrstuvwxyz.-],[ABCDEFGHIJKLMNOPQRSTUVWXYZ__])])
72 dnl extract the basename of a string
73 define([BASENAME],[patsubst([$*],[^.*/],[])])
77 dnl extract the basename of a string
78 define([M4NAME],[patsubst(BASENAME([$*]),[\.m4$],[])])
81 dnl M4 defines $# very badly (empty list=1). So we need a better one
82 define([NUM],[ifelse(len([$*]),0,0,[$#])])
85 dnl IF(cond,string1,string2)
86 dnl places string1 if length (without spaces) of cond is zero,
88 define([IF],[ifelse(len(PROT(translit([$1],[ ]))),0,[$3],[$2])])
89 dnl define([IF],[ifelse(len(PROT(patsubst([$1],[ ]))),0,[$3],[$2])])
92 dnl minclude(filename)
93 dnl This includes only the macros from a file but throws away the output.
94 dnl Used to take the macros from a file without getting it extra output.
95 define([minclude],[IF([$1],[dnl
96 pushdef([CURRENT_DIVERSION],divnum)dnl
99 divert(CURRENT_DIVERSION)dnl
100 popdef([CURRENT_DIVERSION])dnl],[[minclude]])])
103 dnl makes the current filename into a string approprate for use as
104 dnl C identified define. (Defaults to this library name)
106 dnl example: (filename test.hh.m4)
107 dnl __header__ => SIGCXX_TEST_H
108 dnl __header__(MYHEAD) => MYHEAD_TEST_H
109 dnl define([__header__],[ifelse($1,,[SIGCXX],UPPER($1))[_]UPPER(patsubst(translit(BASENAME(__file__),[.-],[__]),[_m4],[]))])
110 define([__header__],[ifelse($1,,[SIGCXX],UPPER($1))[_]UPPER_SAFE(M4NAME(__file__))])
113 dnl Set of M4 macros for variable argument template building
116 dnl ARGS(name,number)
117 dnl Builds a comma seperated protected list of numbered names
118 dnl Use this as short hand to specify arguement names
120 dnl ARGS(arg,3) => ARG1,ARG2,ARG3
121 define([_ARGS],[ifelse(eval($2<$3),0,[$1$2],[$1$2,_ARGS($1,eval($2+1),$3)])])
122 define([ARGS],[ifelse(eval($2>0),1,[PROT(_ARGS(UPPER([$1]),1,$2))],[PROT])])
125 dnl LIST/C_LIST(string1,cond1,string2,cond2,...)
126 dnl These are intended for making extended argument lists
127 dnl parameters are in pairs, the first is output if the
128 dnl 2nd is nonzero length, the process is then repeated
129 dnl with the next set of arguments.
131 dnl Macro expansions that expand to result in commas must call
132 dnl PROT to prevent permature expansion. ARG* macros do
133 dnl this automatically. (If unsure, add braces until it stops
134 dnl interpreting inter macros, remove one set of braces, if
135 dnl still not right use PROT)
137 dnl C_LIST adds a comma in front
138 dnl (LIST is probably the most useful macro in the set.)
139 define([LIST],[ifelse($#,1,,len([$2]),0,[LIST(shift(shift($@)))],len([$1]),0,[LIST(shift(shift($@)))],[[$1]C_LIST(shift(shift($@)))])])
141 define([C_LIST],[ifelse($#,1,,len([$2]),0,[C_LIST(shift(shift($@)))],len([$1]),0,[C_LIST(shift(shift($@)))],[,[$1]C_LIST(shift(shift($@)))])])
144 dnl ARG_LOOP(macro_name,seperator,argument_list)
145 dnl Very powerful macro for construction of list of variables
146 dnl formated in specify ways. To use define a macro taking
147 dnl one variable which is called the format. The second argument
148 dnl is a seperator which will appear between each argument.
149 dnl The rest is then interpreted as arguments to form the list.
152 dnl define([FOO],[foo([$1])])
153 dnl ARG_LOOP([FOO],[[, ]],A,B,C)
155 dnl Gives: foo(A), foo(B), foo(C)
157 define([_ARG_LOOP],[dnl
158 ifelse(NUM($*),0,,NUM($*),1,[dnl
159 indir(LOOP_FORMAT,[$1])],[dnl
160 indir(LOOP_FORMAT,[$1])[]LOOP_SEPERATOR[]_ARG_LOOP(shift($*))])])
162 define([ARG_LOOP],[dnl
163 pushdef([LOOP_FORMAT],[[$1]])dnl
164 pushdef([LOOP_SEPERATOR],[$2])dnl
165 _ARG_LOOP(shift(shift($*)))[]dnl
166 popdef([LOOP_FORMAT])dnl
167 popdef([LOOP_SEPERATOR])dnl
172 dnl Define some useful formats for use with ARG_LOOP.
173 define([FORMAT_ARG_CLASS],[class [$1]])
174 define([FORMAT_ARG_BOTH],[[$1] LOWER([$1])])
175 define([FORMAT_ARG_REF],[typename Trait<[$1]>::ref LOWER([$1])])
176 define([FORMAT_ARG_TYPE],[[$1]])
177 define([FORMAT_ARG_NAME],[LOWER($1)])
178 define([FORMAT_ARG_CBNAME],[LOWER($1)_])
179 define([FORMAT_ARG_CBDECL],[[$1] LOWER([$1])_;])
180 define([FORMAT_ARG_CBINIT],[LOWER([$1])_(LOWER([$1]))])
184 dnl The following functions generate various types of parameter lists
185 dnl For parameter lists
186 dnl ARG_CLASS([P1,P2]) -> class P1,class P2
187 dnl ARG_BOTH([P1,P2]) -> P1 p1,P2 p2
188 dnl ARG_TYPE([P1,P2]) -> P1,P2
189 dnl ARG_NAME([P1,P2]) -> p1,p2
190 dnl For callback lists
191 dnl ARG_CBNAME([C1,C2]) -> c1_,c2_
192 dnl ARG_CBINIT([C1,C2]) -> c1_(c1),c2_(c2)
193 dnl ARG_CBDECL([C1,C2]) -> C1 c1_; C2 c2_;
195 define([ARG_CLASS],[PROT(ARG_LOOP([FORMAT_ARG_CLASS],[[,]],$*))])
196 define([ARG_BOTH],[PROT(ARG_LOOP([FORMAT_ARG_BOTH],[[,]],$*))])
197 define([ARG_REF],[PROT(ARG_LOOP([FORMAT_ARG_REF],[[,]],$*))])
198 define([ARG_TYPE],[PROT([$*])])
199 define([ARG_NAME],[PROT(LOWER($*))])
200 define([ARG_CBNAME],[PROT(ARG_LOOP([FORMAT_ARG_CBNAME],[[,]],$*))])
201 define([ARG_CBDECL],[PROT(ARG_LOOP([FORMAT_ARG_CBDECL],[ ],$*))])
202 define([ARG_CBINIT],[PROT(ARG_LOOP([FORMAT_ARG_CBINIT],[[,]],$*))])
206 dnl C_* - the same with a comma in front
207 dnl (we should obsolete these, LIST is better)
208 define([C_ARG_CLASS], [ifelse(NUM($*),0,,[,ARG_CLASS($*)])])
209 define([C_ARG_BOTH],[ifelse(NUM($*),0,,[,ARG_BOTH($*)])])
210 define([C_ARG_TYPE],[ifelse(NUM($*),0,,[,ARG_TYPE($*)])])
211 define([C_ARG_NAME],[ifelse(NUM($*),0,,[,ARG_NAME($*)])])
212 define([C_ARG_CBNAME],[ifelse(NUM($*),0,,[,ARG_CNAME($*)])])
213 define([C_ARG_CBINIT],[ifelse(NUM($*),0,,[,ARG_INIT($*)])])
217 dnl Removes unnecessary <> with empty templates
218 dnl (occasionally useful)
219 define([T_DROP],[ifelse([$1],<>,,[$*])])
222 dnl DROP(string,drop)
223 dnl Removes unnecessary strings if they match drop
224 dnl (occasionally useful)
225 define([DROP],[ifelse([$1],[$2],,[$*])])
229 dnl places a #line statement if __debug__ set
230 dnl Use this at top of macro template and following
231 dnl macros that contain newlines.
234 dnl LINE(]__line__[)dnl
235 define([LINE],[ifdef([__debug__],[#line $1 "]__file__["
238 dnl-----------------------------------------------------------------------
240 dnl Libsigc++ macros to simpilify typing of internal macros
242 define([TYPEDEF_RTYPE],[
246 #ifdef SIGC_CXX_PARTIAL_SPEC
249 typedef typename Trait<$1>::type $2;
252 define([__SLOT__],[dnl
253 ifelse([$2$3],,[Slot0<$1>],
254 [$3],,[Slot[]NUM($2)<$1,$2>],
255 [$2],,[Slot[]NUM($3)<$1,$3>],
256 [Slot[]eval(NUM($2)+NUM($3))<$1,$2,$3>])])
258 define([QT_FIREWALL],[dnl
259 // Qt steals a method name.
271 define([END_QT_FIREWALL],[dnl
278 dnl-----------------------------------------------------------------------
279 dnl End of recursion protection. Do not put anything below this line.
282 popdef([DIVERSION])dnl