xc-translit.m4 provides transliteration macros with well defined behavior.
[platform/upstream/c-ares.git] / m4 / xc-translit.m4
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 1
23
24
25 dnl XC_SH_TR_SH (expression)
26 dnl -------------------------------------------------
27 dnl Shell execution time transliteration of 'expression'
28 dnl argument, where all non-alfanumeric characters are
29 dnl converted to the underscore '_' character.
30 dnl Normal shell expansion and substitution takes place
31 dnl for given 'expression' at shell execution time before
32 dnl transliteration is applied to it.
33
34 AC_DEFUN([XC_SH_TR_SH],
35 [`echo "$1" | sed 's/[[^a-zA-Z0-9_]]/_/g'`])
36
37
38 dnl XC_SH_TR_SH_EX (expression, [extra])
39 dnl -------------------------------------------------
40 dnl Like XC_SH_TR_SH but transliterating characters
41 dnl given in 'extra' argument to lowercase 'p'. For
42 dnl example [*+], [*], and [+] are valid 'extra' args.
43
44 AC_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
50 dnl XC_M4_TR_SH (expression)
51 dnl -------------------------------------------------
52 dnl m4 execution time transliteration of 'expression'
53 dnl argument, where all non-alfanumeric characters are
54 dnl converted to the underscore '_' character.
55
56 AC_DEFUN([XC_M4_TR_SH],
57 [patsubst([$1], [[^a-zA-Z0-9_]], [_])])
58
59
60 dnl XC_M4_TR_SH_EX (expression, [extra])
61 dnl -------------------------------------------------
62 dnl Like XC_M4_TR_SH but transliterating characters
63 dnl given in 'extra' argument to lowercase 'p'. For
64 dnl example [*+], [*], and [+] are valid 'extra' args.
65
66 AC_DEFUN([XC_M4_TR_SH_EX],
67 [ifelse([$2], [],
68   [XC_M4_TR_SH([$1])],
69   [patsubst(patsubst([[$1]], [[$2]], [p]), [[^a-zA-Z0-9_]], [_])])])
70
71
72 dnl XC_SH_TR_CPP (expression)
73 dnl -------------------------------------------------
74 dnl Shell execution time transliteration of 'expression'
75 dnl argument, where all non-alfanumeric characters are
76 dnl converted to the underscore '_' character and alnum
77 dnl characters are converted to uppercase.
78 dnl Normal shell expansion and substitution takes place
79 dnl for given 'expression' at shell execution time before
80 dnl transliteration is applied to it.
81
82 AC_DEFUN([XC_SH_TR_CPP],
83 [`echo "$1" | dnl
84 sed 'y/abcdefghijklmnopqrstuvwxyz/ABCDEFGHIJKLMNOPQRSTUVWXYZ/' | dnl
85 sed 's/[[^A-Z0-9_]]/_/g'`])
86
87
88 dnl XC_SH_TR_CPP_EX (expression, [extra])
89 dnl -------------------------------------------------
90 dnl Like XC_SH_TR_CPP but transliterating characters
91 dnl given in 'extra' argument to uppercase 'P'. For
92 dnl example [*+], [*], and [+] are valid 'extra' args.
93
94 AC_DEFUN([XC_SH_TR_CPP_EX],
95 [ifelse([$2], [],
96   [XC_SH_TR_CPP([$1])],
97   [`echo "$1" | dnl
98 sed 's/[[$2]]/P/g' | dnl
99 sed 'y/abcdefghijklmnopqrstuvwxyz/ABCDEFGHIJKLMNOPQRSTUVWXYZ/' | dnl
100 sed 's/[[^A-Z0-9_]]/_/g'`])])
101
102
103 dnl XC_M4_TR_CPP (expression)
104 dnl -------------------------------------------------
105 dnl m4 execution time transliteration of 'expression'
106 dnl argument, where all non-alfanumeric characters are
107 dnl converted to the underscore '_' character and alnum
108 dnl characters are converted to uppercase.
109
110 AC_DEFUN([XC_M4_TR_CPP],
111 [patsubst(translit([[$1]],
112                    [abcdefghijklmnopqrstuvwxyz],
113                    [ABCDEFGHIJKLMNOPQRSTUVWXYZ]),
114           [[^A-Z0-9_]], [_])])
115
116
117 dnl XC_M4_TR_CPP_EX (expression, [extra])
118 dnl -------------------------------------------------
119 dnl Like XC_M4_TR_CPP but transliterating characters
120 dnl given in 'extra' argument to uppercase 'P'. For
121 dnl example [*+], [*], and [+] are valid 'extra' args.
122
123 AC_DEFUN([XC_M4_TR_CPP_EX],
124 [ifelse([$2], [],
125   [XC_M4_TR_CPP([$1])],
126   [patsubst(translit(patsubst([[[$1]]], [[$2]], [P]),
127                      [abcdefghijklmnopqrstuvwxyz],
128                      [ABCDEFGHIJKLMNOPQRSTUVWXYZ]),
129             [[^A-Z0-9_]], [_])])])
130