Fix crash on startup if an LV2 plugin has a bad .ttl file.
[ardour.git] / libs / glibmm2 / glib / src / template.macros.m4
1 dnl-----------------------------------------------------------------------
2 dnl 
3 dnl Karls M4 macros for the signal system used by gtk--
4 dnl 
5 dnl  Copyright (C) 1998-2002 The gtkmm Development Team
6 dnl 
7 dnl  Currently maintained by Tero Pulkkinen. <terop@modeemi.cs.tut.fi>
8 dnl                                                         
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.
13 dnl 
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.
18 dnl 
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.
22 dnl 
23 dnl-----------------------------------------------------------------------
24 dnl  Recursion prevention.  (Don't attempt to understand why this works!) 
25 changequote(, )dnl
26 changequote([, ])dnl
27 pushdef([DIVERSION],divnum)dnl
28 divert(-1)dnl
29
30 ifdef([__template_macros__],[],[
31 define(__template_macros__)
32 dnl-----------------------------------------------------------------------
33
34
35 dnl
36 dnl  M4 macros for general sanity 
37 dnl
38
39 dnl  M4 Quotas are hard to work with, so use braces like autoconf
40 dnl    (which are matched by vi, emacs)
41 changequote(, )
42 changequote([, ])
43
44 dnl
45 dnl  M4 comments conflict with compiler directives
46 changecom(, )
47
48 dnl  BRACE(text) => [text]
49 dnl    When we want something to appear with braces 
50 define([BRACE],[[[$*]]])
51
52 dnl
53 dnl  PROT(macro)
54 dnl    If a macro generates an output with commas we need to protect it
55 dnl    from being broken down and interpreted
56 define([PROT],[[$*]])
57
58 dnl
59 dnl  LOWER(string)
60 dnl    lowercase a string
61 define([LOWER],[translit([$*],[ABCDEFGHIJKLMNOPQRSTUVWXYZ],[abcdefghijklmnopqrstuvwxyz])])
62
63 dnl
64 dnl  UPPER(string)
65 dnl    uppercase a string
66 define([UPPER],[translit([$*],[abcdefghijklmnopqrstuvwxyz],[ABCDEFGHIJKLMNOPQRSTUVWXYZ])])
67 define([UPPER_SAFE],[translit([$*],[abcdefghijklmnopqrstuvwxyz.-],[ABCDEFGHIJKLMNOPQRSTUVWXYZ__])])
68
69 dnl
70 dnl  BASENAME(string)
71 dnl    extract the basename of a string
72 define([BASENAME],[patsubst([$*],[^.*/],[])])
73
74 dnl
75 dnl  M4NAME(string)
76 dnl    extract the basename of a string
77 define([M4NAME],[patsubst(BASENAME([$*]),[\.m4$],[])])
78
79 dnl  NUM(arg,arg,...)
80 dnl    M4 defines $# very badly (empty list=1).  So we need a better one
81 define([NUM],[ifelse(len([$*]),0,0,[$#])])
82
83 dnl
84 dnl  IF(cond,string1,string2)
85 dnl    places string1 if length (without spaces) of cond is zero,
86 dnl    else string2
87 define([IF],[ifelse(len(PROT(translit([$1],[ ]))),0,[$3],[$2])])
88 dnl define([IF],[ifelse(len(PROT(patsubst([$1],[ ]))),0,[$3],[$2])])
89
90 dnl
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
96 divert(-1)
97 include($1)
98 divert(CURRENT_DIVERSION)dnl
99 popdef([CURRENT_DIVERSION])dnl],[[minclude]])])
100
101 dnl
102 dnl    makes the current filename into a string approprate for use as 
103 dnl    C identified define.  (Defaults to this library name)
104 dnl
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__))])
110
111 dnl
112 dnl Set of M4 macros for variable argument template building
113 dnl
114
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
118 dnl
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])])
122
123 dnl
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.
129 dnl
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)
135 dnl 
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($@))])])
139
140 dnl
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.
147 dnl
148 dnl   Example:
149 dnl     define([FOO],[foo([$1])])
150 dnl     ARG_LOOP([FOO],[[, ]],A,B,C)
151 dnl
152 dnl     Gives:  foo(A), foo(B), foo(C)
153 dnl 
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($*))])])
158
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
165 ])
166
167
168 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]))])
178
179
180 dnl
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_;
191 dnl
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],[[,]],$*))])
200
201
202 dnl
203 dnl T_DROP(string)
204 dnl   Removes unnecessary <> with empty templates
205 dnl   (occasionally useful)
206 define([T_DROP],[ifelse([$1],<>,,[$*])])
207
208 dnl
209 dnl DROP(string,drop)
210 dnl   Removes unnecessary strings if they match drop
211 dnl   (occasionally useful)
212 define([DROP],[ifelse([$1],[$2],,[$*])])
213
214 dnl
215 dnl LINE(linenum) 
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.
219 dnl
220 dnl   example:  
221 dnl      LINE(]__line__[)dnl
222 define([LINE],[ifdef([__debug__],[#line $1 "]__file__["
223 ])])
224
225 dnl-----------------------------------------------------------------------
226 dnl End of recursion protection.  Do not put anything below this line.
227 ])
228 divert(DIVERSION)dnl
229 popdef([DIVERSION])dnl