1#---------------------------------------------------------------------------
2#
3# xc-translit.m4
4#
5# Copyright (c) 2011 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#---------------------------------------------------------------------------
20
21# File version for 'aclocal' use. Keep it a single number.
22# serial 2
23
24
25dnl XC_SH_TR_SH (expression)
26dnl -------------------------------------------------
27dnl Shell execution time transliteration of 'expression'
28dnl argument, where all non-alfanumeric characters are
29dnl converted to the underscore '_' character.
30dnl Normal shell expansion and substitution takes place
31dnl for given 'expression' at shell execution time before
32dnl transliteration is applied to it.
33
34AC_DEFUN([XC_SH_TR_SH],
35[`echo "$1" | sed 's/[[^a-zA-Z0-9_]]/_/g'`])
36
37
38dnl XC_SH_TR_SH_EX (expression, [extra])
39dnl -------------------------------------------------
40dnl Like XC_SH_TR_SH but transliterating characters
41dnl given in 'extra' argument to lowercase 'p'. For
42dnl example [*+], [*], and [+] are valid 'extra' args.
43
44AC_DEFUN([XC_SH_TR_SH_EX],
45[ifelse([$2], [],
46  [XC_SH_TR_SH([$1])],
47  [`echo "$1" | sed 's/[[$2]]/p/g' | sed 's/[[^a-zA-Z0-9_]]/_/g'`])])
48
49
50dnl XC_M4_TR_SH (expression)
51dnl -------------------------------------------------
52dnl m4 execution time transliteration of 'expression'
53dnl argument, where all non-alfanumeric characters are
54dnl converted to the underscore '_' character.
55
56AC_DEFUN([XC_M4_TR_SH],
57[patsubst(XC_QPATSUBST(XC_QUOTE($1),
58                       [[^a-zA-Z0-9_]], [_]),
59          [\(_\(.*\)_\)], [\2])])
60
61
62dnl XC_M4_TR_SH_EX (expression, [extra])
63dnl -------------------------------------------------
64dnl Like XC_M4_TR_SH but transliterating characters
65dnl given in 'extra' argument to lowercase 'p'. For
66dnl example [*+], [*], and [+] are valid 'extra' args.
67
68AC_DEFUN([XC_M4_TR_SH_EX],
69[ifelse([$2], [],
70  [XC_M4_TR_SH([$1])],
71  [patsubst(XC_QPATSUBST(XC_QPATSUBST(XC_QUOTE($1),
72                                      [[$2]],
73                                      [p]),
74                         [[^a-zA-Z0-9_]], [_]),
75            [\(_\(.*\)_\)], [\2])])])
76
77
78dnl XC_SH_TR_CPP (expression)
79dnl -------------------------------------------------
80dnl Shell execution time transliteration of 'expression'
81dnl argument, where all non-alfanumeric characters are
82dnl converted to the underscore '_' character and alnum
83dnl characters are converted to uppercase.
84dnl Normal shell expansion and substitution takes place
85dnl for given 'expression' at shell execution time before
86dnl transliteration is applied to it.
87
88AC_DEFUN([XC_SH_TR_CPP],
89[`echo "$1" | dnl
90sed 'y/abcdefghijklmnopqrstuvwxyz/ABCDEFGHIJKLMNOPQRSTUVWXYZ/' | dnl
91sed 's/[[^A-Z0-9_]]/_/g'`])
92
93
94dnl XC_SH_TR_CPP_EX (expression, [extra])
95dnl -------------------------------------------------
96dnl Like XC_SH_TR_CPP but transliterating characters
97dnl given in 'extra' argument to uppercase 'P'. For
98dnl example [*+], [*], and [+] are valid 'extra' args.
99
100AC_DEFUN([XC_SH_TR_CPP_EX],
101[ifelse([$2], [],
102  [XC_SH_TR_CPP([$1])],
103  [`echo "$1" | dnl
104sed 's/[[$2]]/P/g' | dnl
105sed 'y/abcdefghijklmnopqrstuvwxyz/ABCDEFGHIJKLMNOPQRSTUVWXYZ/' | dnl
106sed 's/[[^A-Z0-9_]]/_/g'`])])
107
108
109dnl XC_M4_TR_CPP (expression)
110dnl -------------------------------------------------
111dnl m4 execution time transliteration of 'expression'
112dnl argument, where all non-alfanumeric characters are
113dnl converted to the underscore '_' character and alnum
114dnl characters are converted to uppercase.
115
116AC_DEFUN([XC_M4_TR_CPP],
117[patsubst(XC_QPATSUBST(XC_QTRANSLIT(XC_QUOTE($1),
118                                    [abcdefghijklmnopqrstuvwxyz],
119                                    [ABCDEFGHIJKLMNOPQRSTUVWXYZ]),
120                       [[^A-Z0-9_]], [_]),
121          [\(_\(.*\)_\)], [\2])])
122
123
124dnl XC_M4_TR_CPP_EX (expression, [extra])
125dnl -------------------------------------------------
126dnl Like XC_M4_TR_CPP but transliterating characters
127dnl given in 'extra' argument to uppercase 'P'. For
128dnl example [*+], [*], and [+] are valid 'extra' args.
129
130AC_DEFUN([XC_M4_TR_CPP_EX],
131[ifelse([$2], [],
132  [XC_M4_TR_CPP([$1])],
133  [patsubst(XC_QPATSUBST(XC_QTRANSLIT(XC_QPATSUBST(XC_QUOTE($1),
134                                                   [[$2]],
135                                                   [P]),
136                                      [abcdefghijklmnopqrstuvwxyz],
137                                      [ABCDEFGHIJKLMNOPQRSTUVWXYZ]),
138                         [[^A-Z0-9_]], [_]),
139            [\(_\(.*\)_\)], [\2])])])
140
141
142dnl XC_QUOTE (expression)
143dnl -------------------------------------------------
144dnl Expands to quoted result of 'expression' expansion.
145
146AC_DEFUN([XC_QUOTE],
147[[$@]])
148
149
150dnl XC_QPATSUBST (string, regexp[, repl])
151dnl -------------------------------------------------
152dnl Expands to quoted result of 'patsubst' expansion.
153
154AC_DEFUN([XC_QPATSUBST],
155[XC_QUOTE(patsubst([$1], [$2], [$3]))])
156
157
158dnl XC_QTRANSLIT (string, chars, repl)
159dnl -------------------------------------------------
160dnl Expands to quoted result of 'translit' expansion.
161
162AC_DEFUN([XC_QTRANSLIT],
163[XC_QUOTE(translit([$1], [$2], [$3]))])
164
165