You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

xc-translit.m4 5.7KB

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