2
0

xc-translit.m4 5.7 KB

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