xc-translit.m4 5.7 KB

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