MKtermsort.sh 6.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165
  1. #!/bin/sh
  2. # $Id: MKtermsort.sh,v 1.10 2008/07/12 20:22:54 tom Exp $
  3. #
  4. # MKtermsort.sh -- generate indirection vectors for the various sort methods
  5. #
  6. ##############################################################################
  7. # Copyright (c) 1998-2003,2008 Free Software Foundation, Inc. #
  8. # #
  9. # Permission is hereby granted, free of charge, to any person obtaining a #
  10. # copy of this software and associated documentation files (the "Software"), #
  11. # to deal in the Software without restriction, including without limitation #
  12. # the rights to use, copy, modify, merge, publish, distribute, distribute #
  13. # with modifications, sublicense, and/or sell copies of the Software, and to #
  14. # permit persons to whom the Software is furnished to do so, subject to the #
  15. # following conditions: #
  16. # #
  17. # The above copyright notice and this permission notice shall be included in #
  18. # all copies or substantial portions of the Software. #
  19. # #
  20. # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR #
  21. # IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, #
  22. # FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL #
  23. # THE ABOVE COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER #
  24. # LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING #
  25. # FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER #
  26. # DEALINGS IN THE SOFTWARE. #
  27. # #
  28. # Except as contained in this notice, the name(s) of the above copyright #
  29. # holders shall not be used in advertising or otherwise to promote the sale, #
  30. # use or other dealings in this Software without prior written #
  31. # authorization. #
  32. ##############################################################################
  33. #
  34. # The output of this script is C source for nine arrays that list three sort
  35. # orders for each of the three different classes of terminfo capabilities.
  36. #
  37. # keep the order independent of locale:
  38. if test "${LANGUAGE+set}" = set; then LANGUAGE=C; export LANGUAGE; fi
  39. if test "${LANG+set}" = set; then LANG=C; export LANG; fi
  40. if test "${LC_ALL+set}" = set; then LC_ALL=C; export LC_ALL; fi
  41. if test "${LC_MESSAGES+set}" = set; then LC_MESSAGES=C; export LC_MESSAGES; fi
  42. if test "${LC_CTYPE+set}" = set; then LC_CTYPE=C; export LC_CTYPE; fi
  43. if test "${LC_COLLATE+set}" = set; then LC_COLLATE=C; export LC_COLLATE; fi
  44. #
  45. AWK=${1-awk}
  46. DATA=${2-../include/Caps}
  47. data=data$$
  48. trap 'rm -f $data' 1 2 5 15
  49. sed -e 's/[ ][ ]*/ /g' < $DATA >$data
  50. DATA=$data
  51. echo "/*";
  52. echo " * termsort.c --- sort order arrays for use by infocmp.";
  53. echo " *";
  54. echo " * Note: this file is generated using MKtermsort.sh, do not edit by hand.";
  55. echo " */";
  56. echo "static const PredIdx bool_terminfo_sort[] = {";
  57. $AWK <$DATA '
  58. BEGIN {i = 0;}
  59. /^#/ {next;}
  60. $3 == "bool" {printf("%s\t%d\n", $2, i++);}
  61. ' | sort | $AWK '{print "\t", $2, ",\t/* ", $1, " */";}';
  62. echo "};";
  63. echo "";
  64. echo "static const PredIdx num_terminfo_sort[] = {";
  65. $AWK <$DATA '
  66. BEGIN {i = 0;}
  67. /^#/ {next;}
  68. $3 == "num" {printf("%s\t%d\n", $2, i++);}
  69. ' | sort | $AWK '{print "\t", $2, ",\t/* ", $1, " */";}';
  70. echo "};";
  71. echo "";
  72. echo "static const PredIdx str_terminfo_sort[] = {";
  73. $AWK <$DATA '
  74. BEGIN {i = 0;}
  75. /^#/ {next;}
  76. $3 == "str" {printf("%s\t%d\n", $2, i++);}
  77. ' | sort | $AWK '{print "\t", $2, ",\t/* ", $1, " */";}';
  78. echo "};";
  79. echo "";
  80. echo "static const PredIdx bool_variable_sort[] = {";
  81. $AWK <$DATA '
  82. BEGIN {i = 0;}
  83. /^#/ {next;}
  84. $3 == "bool" {printf("%s\t%d\n", $1, i++);}
  85. ' | sort | $AWK '{print "\t", $2, ",\t/* ", $1, " */";}';
  86. echo "};";
  87. echo "";
  88. echo "static const PredIdx num_variable_sort[] = {";
  89. $AWK <$DATA '
  90. BEGIN {i = 0;}
  91. /^#/ {next;}
  92. $3 == "num" {printf("%s\t%d\n", $1, i++);}
  93. ' | sort | $AWK '{print "\t", $2, ",\t/* ", $1, " */";}';
  94. echo "};";
  95. echo "";
  96. echo "static const PredIdx str_variable_sort[] = {";
  97. $AWK <$DATA '
  98. BEGIN {i = 0;}
  99. /^#/ {next;}
  100. $3 == "str" {printf("%s\t%d\n", $1, i++);}
  101. ' | sort | $AWK '{print "\t", $2, ",\t/* ", $1, " */";}';
  102. echo "};";
  103. echo "";
  104. echo "static const PredIdx bool_termcap_sort[] = {";
  105. $AWK <$DATA '
  106. BEGIN {i = 0;}
  107. /^#/ {next;}
  108. $3 == "bool" {printf("%s\t%d\n", $4, i++);}
  109. ' | sort | $AWK '{print "\t", $2, ",\t/* ", $1, " */";}';
  110. echo "};";
  111. echo "";
  112. echo "static const PredIdx num_termcap_sort[] = {";
  113. $AWK <$DATA '
  114. BEGIN {i = 0;}
  115. /^#/ {next;}
  116. $3 == "num" {printf("%s\t%d\n", $4, i++);}
  117. ' | sort | $AWK '{print "\t", $2, ",\t/* ", $1, " */";}';
  118. echo "};";
  119. echo "";
  120. echo "static const PredIdx str_termcap_sort[] = {";
  121. $AWK <$DATA '
  122. BEGIN {i = 0;}
  123. /^#/ {next;}
  124. $3 == "str" {printf("%s\t%d\n", $4, i++);}
  125. ' | sort | $AWK '{print "\t", $2, ",\t/* ", $1, " */";}';
  126. echo "};";
  127. echo "";
  128. echo "static const bool bool_from_termcap[] = {";
  129. $AWK <$DATA '
  130. $3 == "bool" && substr($7, 1, 1) == "-" {print "\tFALSE,\t/* ", $2, " */";}
  131. $3 == "bool" && substr($7, 1, 1) == "Y" {print "\tTRUE,\t/* ", $2, " */";}
  132. '
  133. echo "};";
  134. echo "";
  135. echo "static const bool num_from_termcap[] = {";
  136. $AWK <$DATA '
  137. $3 == "num" && substr($7, 1, 1) == "-" {print "\tFALSE,\t/* ", $2, " */";}
  138. $3 == "num" && substr($7, 1, 1) == "Y" {print "\tTRUE,\t/* ", $2, " */";}
  139. '
  140. echo "};";
  141. echo "";
  142. echo "static const bool str_from_termcap[] = {";
  143. $AWK <$DATA '
  144. $3 == "str" && substr($7, 1, 1) == "-" {print "\tFALSE,\t/* ", $2, " */";}
  145. $3 == "str" && substr($7, 1, 1) == "Y" {print "\tTRUE,\t/* ", $2, " */";}
  146. '
  147. echo "};";
  148. echo "";
  149. rm -f $data