xf.li | 6c8fc1e | 2023-08-12 00:11:09 -0700 | [diff] [blame] | 1 | #--------------------------------------------------------------------------- |
| 2 | # |
| 3 | # xc-translit.m4 |
| 4 | # |
| 5 | # Copyright (c) 2011 - 2022, 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 | |
| 27 | dnl XC_SH_TR_SH (expression) |
| 28 | dnl ------------------------------------------------- |
| 29 | dnl Shell execution time transliteration of 'expression' |
| 30 | dnl argument, where all non-alfanumeric characters are |
| 31 | dnl converted to the underscore '_' character. |
| 32 | dnl Normal shell expansion and substitution takes place |
| 33 | dnl for given 'expression' at shell execution time before |
| 34 | dnl transliteration is applied to it. |
| 35 | |
| 36 | AC_DEFUN([XC_SH_TR_SH], |
| 37 | [`echo "$1" | sed 's/[[^a-zA-Z0-9_]]/_/g'`]) |
| 38 | |
| 39 | |
| 40 | dnl XC_SH_TR_SH_EX (expression, [extra]) |
| 41 | dnl ------------------------------------------------- |
| 42 | dnl Like XC_SH_TR_SH but transliterating characters |
| 43 | dnl given in 'extra' argument to lowercase 'p'. For |
| 44 | dnl example [*+], [*], and [+] are valid 'extra' args. |
| 45 | |
| 46 | AC_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 | |
| 52 | dnl XC_M4_TR_SH (expression) |
| 53 | dnl ------------------------------------------------- |
| 54 | dnl m4 execution time transliteration of 'expression' |
| 55 | dnl argument, where all non-alfanumeric characters are |
| 56 | dnl converted to the underscore '_' character. |
| 57 | |
| 58 | AC_DEFUN([XC_M4_TR_SH], |
| 59 | [patsubst(XC_QPATSUBST(XC_QUOTE($1), |
| 60 | [[^a-zA-Z0-9_]], [_]), |
| 61 | [\(_\(.*\)_\)], [\2])]) |
| 62 | |
| 63 | |
| 64 | dnl XC_M4_TR_SH_EX (expression, [extra]) |
| 65 | dnl ------------------------------------------------- |
| 66 | dnl Like XC_M4_TR_SH but transliterating characters |
| 67 | dnl given in 'extra' argument to lowercase 'p'. For |
| 68 | dnl example [*+], [*], and [+] are valid 'extra' args. |
| 69 | |
| 70 | AC_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 | |
| 80 | dnl XC_SH_TR_CPP (expression) |
| 81 | dnl ------------------------------------------------- |
| 82 | dnl Shell execution time transliteration of 'expression' |
| 83 | dnl argument, where all non-alfanumeric characters are |
| 84 | dnl converted to the underscore '_' character and alnum |
| 85 | dnl characters are converted to uppercase. |
| 86 | dnl Normal shell expansion and substitution takes place |
| 87 | dnl for given 'expression' at shell execution time before |
| 88 | dnl transliteration is applied to it. |
| 89 | |
| 90 | AC_DEFUN([XC_SH_TR_CPP], |
| 91 | [`echo "$1" | dnl |
| 92 | sed 'y/abcdefghijklmnopqrstuvwxyz/ABCDEFGHIJKLMNOPQRSTUVWXYZ/' | dnl |
| 93 | sed 's/[[^A-Z0-9_]]/_/g'`]) |
| 94 | |
| 95 | |
| 96 | dnl XC_SH_TR_CPP_EX (expression, [extra]) |
| 97 | dnl ------------------------------------------------- |
| 98 | dnl Like XC_SH_TR_CPP but transliterating characters |
| 99 | dnl given in 'extra' argument to uppercase 'P'. For |
| 100 | dnl example [*+], [*], and [+] are valid 'extra' args. |
| 101 | |
| 102 | AC_DEFUN([XC_SH_TR_CPP_EX], |
| 103 | [ifelse([$2], [], |
| 104 | [XC_SH_TR_CPP([$1])], |
| 105 | [`echo "$1" | dnl |
| 106 | sed 's/[[$2]]/P/g' | dnl |
| 107 | sed 'y/abcdefghijklmnopqrstuvwxyz/ABCDEFGHIJKLMNOPQRSTUVWXYZ/' | dnl |
| 108 | sed 's/[[^A-Z0-9_]]/_/g'`])]) |
| 109 | |
| 110 | |
| 111 | dnl XC_M4_TR_CPP (expression) |
| 112 | dnl ------------------------------------------------- |
| 113 | dnl m4 execution time transliteration of 'expression' |
| 114 | dnl argument, where all non-alfanumeric characters are |
| 115 | dnl converted to the underscore '_' character and alnum |
| 116 | dnl characters are converted to uppercase. |
| 117 | |
| 118 | AC_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 | |
| 126 | dnl XC_M4_TR_CPP_EX (expression, [extra]) |
| 127 | dnl ------------------------------------------------- |
| 128 | dnl Like XC_M4_TR_CPP but transliterating characters |
| 129 | dnl given in 'extra' argument to uppercase 'P'. For |
| 130 | dnl example [*+], [*], and [+] are valid 'extra' args. |
| 131 | |
| 132 | AC_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 | |
| 144 | dnl XC_QUOTE (expression) |
| 145 | dnl ------------------------------------------------- |
| 146 | dnl Expands to quoted result of 'expression' expansion. |
| 147 | |
| 148 | AC_DEFUN([XC_QUOTE], |
| 149 | [[$@]]) |
| 150 | |
| 151 | |
| 152 | dnl XC_QPATSUBST (string, regexp[, repl]) |
| 153 | dnl ------------------------------------------------- |
| 154 | dnl Expands to quoted result of 'patsubst' expansion. |
| 155 | |
| 156 | AC_DEFUN([XC_QPATSUBST], |
| 157 | [XC_QUOTE(patsubst([$1], [$2], [$3]))]) |
| 158 | |
| 159 | |
| 160 | dnl XC_QTRANSLIT (string, chars, repl) |
| 161 | dnl ------------------------------------------------- |
| 162 | dnl Expands to quoted result of 'translit' expansion. |
| 163 | |
| 164 | AC_DEFUN([XC_QTRANSLIT], |
| 165 | [XC_QUOTE(translit([$1], [$2], [$3]))]) |