xref: /curl/m4/xc-translit.m4 (revision 2bc1d775)
1#---------------------------------------------------------------------------
2#
3# xc-translit.m4
4#
5# Copyright (C), Daniel Stenberg <daniel@haxx.se>
6#
7# Permission to use, copy, modify, and distribute this software for any
8# purpose with or without fee is hereby granted, provided that the above
9# copyright notice and this permission notice appear in all copies.
10#
11# THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
12# WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
13# MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
14# ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
15# WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
16# ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
17# OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
18#
19# SPDX-License-Identifier: ISC
20#
21#---------------------------------------------------------------------------
22
23# File version for 'aclocal' use. Keep it a single number.
24# serial 2
25
26
27dnl XC_SH_TR_SH (expression)
28dnl -------------------------------------------------
29dnl Shell execution time transliteration of 'expression'
30dnl argument, where all non-alfanumeric characters are
31dnl converted to the underscore '_' character.
32dnl Normal shell expansion and substitution takes place
33dnl for given 'expression' at shell execution time before
34dnl transliteration is applied to it.
35
36AC_DEFUN([XC_SH_TR_SH],
37[`echo "$1" | sed 's/[[^a-zA-Z0-9_]]/_/g'`])
38
39
40dnl XC_SH_TR_SH_EX (expression, [extra])
41dnl -------------------------------------------------
42dnl Like XC_SH_TR_SH but transliterating characters
43dnl given in 'extra' argument to lowercase 'p'. For
44dnl example [*+], [*], and [+] are valid 'extra' args.
45
46AC_DEFUN([XC_SH_TR_SH_EX],
47[ifelse([$2], [],
48  [XC_SH_TR_SH([$1])],
49  [`echo "$1" | sed 's/[[$2]]/p/g' | sed 's/[[^a-zA-Z0-9_]]/_/g'`])])
50
51
52dnl XC_M4_TR_SH (expression)
53dnl -------------------------------------------------
54dnl m4 execution time transliteration of 'expression'
55dnl argument, where all non-alfanumeric characters are
56dnl converted to the underscore '_' character.
57
58AC_DEFUN([XC_M4_TR_SH],
59[patsubst(XC_QPATSUBST(XC_QUOTE($1),
60                       [[^a-zA-Z0-9_]], [_]),
61          [\(_\(.*\)_\)], [\2])])
62
63
64dnl XC_M4_TR_SH_EX (expression, [extra])
65dnl -------------------------------------------------
66dnl Like XC_M4_TR_SH but transliterating characters
67dnl given in 'extra' argument to lowercase 'p'. For
68dnl example [*+], [*], and [+] are valid 'extra' args.
69
70AC_DEFUN([XC_M4_TR_SH_EX],
71[ifelse([$2], [],
72  [XC_M4_TR_SH([$1])],
73  [patsubst(XC_QPATSUBST(XC_QPATSUBST(XC_QUOTE($1),
74                                      [[$2]],
75                                      [p]),
76                         [[^a-zA-Z0-9_]], [_]),
77            [\(_\(.*\)_\)], [\2])])])
78
79
80dnl XC_SH_TR_CPP (expression)
81dnl -------------------------------------------------
82dnl Shell execution time transliteration of 'expression'
83dnl argument, where all non-alfanumeric characters are
84dnl converted to the underscore '_' character and alnum
85dnl characters are converted to uppercase.
86dnl Normal shell expansion and substitution takes place
87dnl for given 'expression' at shell execution time before
88dnl transliteration is applied to it.
89
90AC_DEFUN([XC_SH_TR_CPP],
91[`echo "$1" | dnl
92sed 'y/abcdefghijklmnopqrstuvwxyz/ABCDEFGHIJKLMNOPQRSTUVWXYZ/' | dnl
93sed 's/[[^A-Z0-9_]]/_/g'`])
94
95
96dnl XC_SH_TR_CPP_EX (expression, [extra])
97dnl -------------------------------------------------
98dnl Like XC_SH_TR_CPP but transliterating characters
99dnl given in 'extra' argument to uppercase 'P'. For
100dnl example [*+], [*], and [+] are valid 'extra' args.
101
102AC_DEFUN([XC_SH_TR_CPP_EX],
103[ifelse([$2], [],
104  [XC_SH_TR_CPP([$1])],
105  [`echo "$1" | dnl
106sed 's/[[$2]]/P/g' | dnl
107sed 'y/abcdefghijklmnopqrstuvwxyz/ABCDEFGHIJKLMNOPQRSTUVWXYZ/' | dnl
108sed 's/[[^A-Z0-9_]]/_/g'`])])
109
110
111dnl XC_M4_TR_CPP (expression)
112dnl -------------------------------------------------
113dnl m4 execution time transliteration of 'expression'
114dnl argument, where all non-alfanumeric characters are
115dnl converted to the underscore '_' character and alnum
116dnl characters are converted to uppercase.
117
118AC_DEFUN([XC_M4_TR_CPP],
119[patsubst(XC_QPATSUBST(XC_QTRANSLIT(XC_QUOTE($1),
120                                    [abcdefghijklmnopqrstuvwxyz],
121                                    [ABCDEFGHIJKLMNOPQRSTUVWXYZ]),
122                       [[^A-Z0-9_]], [_]),
123          [\(_\(.*\)_\)], [\2])])
124
125
126dnl XC_M4_TR_CPP_EX (expression, [extra])
127dnl -------------------------------------------------
128dnl Like XC_M4_TR_CPP but transliterating characters
129dnl given in 'extra' argument to uppercase 'P'. For
130dnl example [*+], [*], and [+] are valid 'extra' args.
131
132AC_DEFUN([XC_M4_TR_CPP_EX],
133[ifelse([$2], [],
134  [XC_M4_TR_CPP([$1])],
135  [patsubst(XC_QPATSUBST(XC_QTRANSLIT(XC_QPATSUBST(XC_QUOTE($1),
136                                                   [[$2]],
137                                                   [P]),
138                                      [abcdefghijklmnopqrstuvwxyz],
139                                      [ABCDEFGHIJKLMNOPQRSTUVWXYZ]),
140                         [[^A-Z0-9_]], [_]),
141            [\(_\(.*\)_\)], [\2])])])
142
143
144dnl XC_QUOTE (expression)
145dnl -------------------------------------------------
146dnl Expands to quoted result of 'expression' expansion.
147
148AC_DEFUN([XC_QUOTE],
149[[$@]])
150
151
152dnl XC_QPATSUBST (string, regexp[, repl])
153dnl -------------------------------------------------
154dnl Expands to quoted result of 'patsubst' expansion.
155
156AC_DEFUN([XC_QPATSUBST],
157[XC_QUOTE(patsubst([$1], [$2], [$3]))])
158
159
160dnl XC_QTRANSLIT (string, chars, repl)
161dnl -------------------------------------------------
162dnl Expands to quoted result of 'translit' expansion.
163
164AC_DEFUN([XC_QTRANSLIT],
165[XC_QUOTE(translit([$1], [$2], [$3]))])
166