/src/term.sh

https://github.com/skoneka/screen · Shell · 173 lines · 146 code · 16 blank · 11 comment · 2 complexity · e15d67809ca7954ab32aa2d5a4356838 MD5 · raw file

  1. #! /bin/sh
  2. if test -z "$AWK"; then
  3. AWK=awk
  4. fi
  5. if test -z "$srcdir"; then
  6. srcdir=.
  7. fi
  8. LC_ALL=C
  9. export LC_ALL
  10. rm -f term.h
  11. cat << EOF > term.h
  12. /*
  13. * This file is automagically created from term.c -- DO NOT EDIT
  14. */
  15. #define T_FLG 0
  16. #define T_NUM 1
  17. #define T_STR 2
  18. extern int tgetent(char *, const char *);
  19. extern int tgetflag(char *);
  20. extern int tgetnum(char *);
  21. extern char *tgetstr(char *, char **);
  22. extern char *tgoto(const char *, int, int);
  23. extern int tputs(const char *, int, int (*)(int));
  24. struct term
  25. {
  26. char *tcname;
  27. int type;
  28. };
  29. union tcu
  30. {
  31. int flg;
  32. int num;
  33. char *str;
  34. };
  35. EOF
  36. #
  37. # SCO-Unix sufferers may need to use the following lines:
  38. # perl -p < ${srcdir}/term.c \
  39. # -e 's/"/"C/ if /"[A-Z]."/;' \
  40. # -e 'y/[a-z]/[A-Z]/ if /"/;' \
  41. #
  42. sed < ${srcdir}/term.c \
  43. -e '/"[A-Z]."/s/"/"C/' \
  44. -e '/"/y/abcdefghijklmnopqrstuvwxyz/ABCDEFGHIJKLMNOPQRSTUVWXYZ/' \
  45. | $AWK '
  46. /^ [{] ".*KMAPDEF[(].*$/{
  47. if (min == 0) min = s
  48. max = s;
  49. }
  50. /^ [{] ".*KMAPADEF[(].*$/{
  51. if (amin == 0) amin = s
  52. amax = s;
  53. }
  54. /^ [{] ".*KMAPMDEF[(].*$/{
  55. if (mmin == 0) mmin = s
  56. mmax = s;
  57. }
  58. /^ [{] ".*$/{
  59. a=substr($2,2,length($2)-3);
  60. b=substr($3,3,3);
  61. if (nolist == 0) {
  62. printf "#define d_%s d_tcs[%d].%s\n",a,s,b
  63. printf "#define D_%s (D_tcs[%d].%s)\n",a,s,b
  64. }
  65. s++;
  66. }
  67. /\/* define/{
  68. printf "#define %s %d\n",$3,s
  69. }
  70. /\/* nolist/{
  71. nolist = 1;
  72. }
  73. /\/* list/{
  74. nolist = 0;
  75. }
  76. END {
  77. printf "# define KMAPDEFSTART %d\n", min
  78. printf "# define NKMAPDEF %d\n", max-min+1
  79. printf "# define KMAPADEFSTART %d\n", amin
  80. printf "# define NKMAPADEF %d\n", amax-amin+1
  81. printf "# define KMAPMDEFSTART %d\n", mmin
  82. printf "# define NKMAPMDEF %d\n", mmax-mmin+1
  83. }
  84. ' | sed -e s/NUM/num/ -e s/STR/str/ -e s/FLG/flg/ \
  85. >> term.h
  86. rm -f kmapdef.c
  87. cat << EOF > kmapdef.c
  88. /*
  89. * This file is automagically created from term.c -- DO NOT EDIT
  90. */
  91. #include "config.h"
  92. EOF
  93. $AWK < ${srcdir}/term.c '
  94. /^ [{] ".*KMAP.*$/{
  95. for (i = 0; i < 3; i++) {
  96. q = $(5+i)
  97. if (substr(q, 1, 5) == "KMAPD") {
  98. if (min == 0) min = s
  99. max = s
  100. arr[s] = substr(q, 9, length(q)-9)
  101. }
  102. if (substr(q, 1, 5) == "KMAPA") {
  103. if (amin == 0) amin = s
  104. amax = s
  105. anarr[s] = substr(q, 10, length(q)-10)
  106. }
  107. if (substr(q, 1, 5) == "KMAPM") {
  108. if (mmin == 0) mmin = s
  109. mmax = s
  110. mnarr[s] = substr(q, 10, length(q)-10)
  111. }
  112. }
  113. }
  114. /^ [{] ".*$/{
  115. s++;
  116. }
  117. END {
  118. printf "char *kmapdef[] = {\n"
  119. for (s = min; s <= max; s++) {
  120. if (arr[s])
  121. printf "%s", arr[s]
  122. else
  123. printf "0"
  124. if (s < max)
  125. printf ",\n"
  126. else
  127. printf "\n"
  128. }
  129. printf "};\n\n"
  130. printf "char *kmapadef[] = {\n"
  131. for (s = amin; s <= amax; s++) {
  132. if (anarr[s])
  133. printf "%s", anarr[s]
  134. else
  135. printf "0"
  136. if (s < amax)
  137. printf ",\n"
  138. else
  139. printf "\n"
  140. }
  141. printf "};\n\n"
  142. printf "char *kmapmdef[] = {\n"
  143. for (s = mmin; s <= mmax; s++) {
  144. if (mnarr[s])
  145. printf "%s", mnarr[s]
  146. else
  147. printf "0"
  148. if (s < mmax)
  149. printf ",\n"
  150. else
  151. printf "\n"
  152. }
  153. printf "};\n"
  154. }
  155. ' >> kmapdef.c
  156. chmod a-w kmapdef.c
  157. chmod a-w term.h