1divert(-1) dnl -*- m4 -*-
2# This file is part of Mailfromd.
3# Copyright (C) 2007-2021 Sergey Poznyakoff
4#
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, or (at your option)
8# any later version.
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#
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/>.
17
18changecom(/*,*/)
19
20/* ------------------------------
21 * Simulate --prefix-builtins.
22 * Borrowed from Autoconf
23 * ------------------------------- */
24
25define(`m4_define',   defn(`define'))
26define(`m4_defn',     defn(`defn'))
27define(`m4_undefine', defn(`undefine'))
28
29m4_undefine(`define')
30m4_undefine(`defn')
31m4_undefine(`undefine')
32
33/* m4_copy(SRC, DST)
34 * -----------------
35 * Define DST as the definition of SRC.
36 * What's the difference between:
37 * 1. m4_copy(`from', `to')
38 * 2. m4_define(`to', `from($@)')
39 * Well, obviously 1 is more expensive in space.  Maybe 2 is more expensive
40 * in time, but because of the space cost of 1, it's not that obvious.
41 * Nevertheless, one huge difference is the handling of `$0'.  If `from'
42 * uses `$0', then with 1, `to''s `$0' is `to', while it is `from' in 2.
43 * The user will certainly prefer to see `to'.
44 */
45m4_define(`m4_copy',
46`m4_define(`$2', m4_defn(`$1'))')
47
48/* m4_rename(SRC, DST)
49 * -------------------
50 * Rename the macro SRC as DST.
51 */
52m4_define(`m4_rename',
53`m4_copy(`$1', `$2')m4_undefine(`$1')')
54
55/* m4_rename_m4(MACRO-NAME)
56 * ------------------------
57 * Rename MACRO-NAME as m4_MACRO-NAME.
58 */
59m4_define(`m4_rename_m4',
60`m4_rename(`$1', `m4_$1')')
61
62/* Some m4 internals have names colliding with tokens we might use.
63 * Rename them a` la `m4 --prefix-builtins'.
64 */
65m4_rename_m4(`builtin')
66m4_rename_m4(`changecom')
67m4_rename_m4(`changequote')
68m4_rename_m4(`debugfile')
69m4_rename_m4(`debugmode')
70m4_rename_m4(`decr')
71m4_rename_m4(`divert')
72m4_rename_m4(`divnum')
73m4_rename_m4(`dumpdef')
74m4_rename_m4(`errprint')
75m4_rename_m4(`esyscmd')
76m4_rename_m4(`eval')
77m4_rename_m4(`format')
78m4_rename_m4(`ifdef')
79m4_rename_m4(`ifelse')
80m4_rename_m4(`include')
81m4_rename_m4(`incr')
82m4_rename_m4(`index')
83m4_rename_m4(`indir')
84m4_rename_m4(`len')
85m4_rename(`m4exit', `m4_exit')
86m4_rename(`m4wrap', `m4_wrap')
87m4_rename_m4(`maketemp')
88m4_rename_m4(`patsubst')
89m4_rename_m4(`popdef')
90m4_rename_m4(`pushdef')
91m4_rename_m4(`regexp')
92m4_rename_m4(`shift')
93m4_rename_m4(`sinclude')
94m4_rename_m4(`substr')
95m4_rename_m4(`symbols')
96m4_rename_m4(`syscmd')
97m4_rename_m4(`sysval')
98m4_rename_m4(`traceoff')
99m4_rename_m4(`traceon')
100m4_rename_m4(`translit')
101m4_rename_m4(`undivert')
102m4_rename_m4(`dnl')
103m4_rename_m4(`__line__')
104m4_rename_m4(`__file__')
105
106/* defined(X) -- Return true if the optional argument X is passed to
107   the function */
108m4_define(`defined',``$'#>@$1')
109
110/* printf(FMT, ...) */
111m4_define(`printf',`echo sprintf($*)')
112
113m4_define(`_', `m4_ifelse($#,1,`gettext($1)',``_'')')
114m4_define(`N_', `m4_ifelse($#,1,`$1',``N_'')')
115
116m4_dnl string_list_iterate(LIST, DELIM, VAR, CODE)
117m4_dnl
118m4_dnl This is a convenience macro to compensate for the lack of
119m4_dnl arrays in MFL.
120m4_dnl
121m4_dnl LIST is a string conceptually composed of elements delimited with
122m4_dnl DELIM.  The macro extracts each element, assigns it to the string
123m4_dnl variable VAR and executes MFL code CODE.
124m4_dnl
125m4_define(`string_list_iterate',`
126  if $1 != ""
127    m4_pushdef(`ITR',`__$1_itr')
128    m4_pushdef(`POS',`__$1_pos')
129    loop for string ITR $1 . $2
130              number POS index(ITR, $2),
131         while POS != -1,
132         set ITR substr(ITR, POS + 1)
133         set POS index(ITR, $2)
134    do
135      set $3 substr(ITR, 0, POS)
136      $4
137    done
138    m4_popdef(`POS')
139    m4_popdef(`ITR')
140  fi')
141
142m4_ifdef(`MF_AUTOHEADER',`
143m4_divert(0)m4_dnl
144/* -*- buffer-read-only: t -*- vi: set ro:
145   THIS FILE IS GENERATED AUTOMATICALLY.  PLEASE DO NOT EDIT.
146*/
147m4_divert(-1)')
148
149m4_divert(0)m4_dnl
150