makelist 6.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258
  1. #!/bin/sh -
  2. # $NetBSD: makelist,v 1.18 2012/03/21 05:34:54 matt Exp $
  3. #
  4. # Copyright (c) 1992, 1993
  5. # The Regents of the University of California. All rights reserved.
  6. #
  7. # This code is derived from software contributed to Berkeley by
  8. # Christos Zoulas of Cornell University.
  9. #
  10. # Redistribution and use in source and binary forms, with or without
  11. # modification, are permitted provided that the following conditions
  12. # are met:
  13. # 1. Redistributions of source code must retain the above copyright
  14. # notice, this list of conditions and the following disclaimer.
  15. # 2. Redistributions in binary form must reproduce the above copyright
  16. # notice, this list of conditions and the following disclaimer in the
  17. # documentation and/or other materials provided with the distribution.
  18. # 3. Neither the name of the University nor the names of its contributors
  19. # may be used to endorse or promote products derived from this software
  20. # without specific prior written permission.
  21. #
  22. # THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
  23. # ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
  24. # IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
  25. # ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
  26. # FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
  27. # DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
  28. # OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
  29. # HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
  30. # LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
  31. # OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
  32. # SUCH DAMAGE.
  33. #
  34. # @(#)makelist 5.3 (Berkeley) 6/4/93
  35. # makelist.sh: Automatically generate header files...
  36. USAGE="Usage: $0 -n|-h|-e|-fc|-fh|-bc|-bh|-m <filenames>"
  37. if [ "x$1" = "x" ]
  38. then
  39. echo $USAGE 1>&2
  40. exit 1
  41. fi
  42. FLAG="$1"
  43. shift
  44. FILES="$@"
  45. case $FLAG in
  46. # generate foo.h file from foo.c
  47. #
  48. -n)
  49. cat << _EOF
  50. #include "config.h"
  51. #undef WIDECHAR
  52. #define NARROWCHAR
  53. #include "${FILES}"
  54. _EOF
  55. ;;
  56. -h)
  57. set - `echo $FILES | sed -e 's/\\./_/g'`
  58. hdr="_h_`basename $1`"
  59. cat $FILES | $AWK '
  60. BEGIN {
  61. printf("/* Automatically generated file, do not edit */\n");
  62. printf("#ifndef %s\n#define %s\n", "'$hdr'", "'$hdr'");
  63. }
  64. /\(\):/ {
  65. pr = substr($2, 1, 2);
  66. if (pr == "vi" || pr == "em" || pr == "ed") {
  67. name = substr($2, 1, length($2) - 3);
  68. #
  69. # XXX: need a space between name and prototype so that -fc and -fh
  70. # parsing is much easier
  71. #
  72. printf("protected el_action_t\t%s (EditLine *, Int);\n", name);
  73. }
  74. }
  75. END {
  76. printf("#endif /* %s */\n", "'$hdr'");
  77. }'
  78. ;;
  79. # generate help.c from various .c files
  80. #
  81. -bc)
  82. cat $FILES | $AWK '
  83. BEGIN {
  84. printf("/* Automatically generated file, do not edit */\n");
  85. printf("#include \"config.h\"\n#include \"el.h\"\n");
  86. printf("#include \"chartype.h\"\n");
  87. printf("private const struct el_bindings_t el_func_help[] = {\n");
  88. low = "abcdefghijklmnopqrstuvwxyz_";
  89. high = "ABCDEFGHIJKLMNOPQRSTUVWXYZ_";
  90. for (i = 1; i <= length(low); i++)
  91. tr[substr(low, i, 1)] = substr(high, i, 1);
  92. }
  93. /\(\):/ {
  94. pr = substr($2, 1, 2);
  95. if (pr == "vi" || pr == "em" || pr == "ed") {
  96. name = substr($2, 1, length($2) - 3);
  97. uname = "";
  98. fname = "";
  99. for (i = 1; i <= length(name); i++) {
  100. s = substr(name, i, 1);
  101. uname = uname tr[s];
  102. if (s == "_")
  103. s = "-";
  104. fname = fname s;
  105. }
  106. printf(" { %-30.30s %-30.30s\n","STR(\"" fname "\"),", uname ",");
  107. ok = 1;
  108. }
  109. }
  110. /^ \*/ {
  111. if (ok) {
  112. printf(" STR(\"");
  113. for (i = 2; i < NF; i++)
  114. printf("%s ", $i);
  115. printf("%s\") },\n", $i);
  116. ok = 0;
  117. }
  118. }
  119. END {
  120. printf("};\n");
  121. printf("\nprotected const el_bindings_t* help__get(void)");
  122. printf("{ return el_func_help; }\n");
  123. }'
  124. ;;
  125. # generate help.h from various .c files
  126. #
  127. -bh)
  128. $AWK '
  129. BEGIN {
  130. printf("/* Automatically generated file, do not edit */\n");
  131. printf("#ifndef _h_help_c\n#define _h_help_c\n");
  132. printf("protected const el_bindings_t *help__get(void);\n");
  133. printf("#endif /* _h_help_c */\n");
  134. }' /dev/null
  135. ;;
  136. # generate fcns.h from various .h files
  137. #
  138. -fh)
  139. cat $FILES | $AWK '/el_action_t/ { print $3 }' | \
  140. sort | tr '[a-z]' '[A-Z]' | $AWK '
  141. BEGIN {
  142. printf("/* Automatically generated file, do not edit */\n");
  143. printf("#ifndef _h_fcns_c\n#define _h_fcns_c\n");
  144. count = 0;
  145. }
  146. {
  147. printf("#define\t%-30.30s\t%3d\n", $1, count++);
  148. }
  149. END {
  150. printf("#define\t%-30.30s\t%3d\n", "EL_NUM_FCNS", count);
  151. printf("typedef el_action_t (*el_func_t)(EditLine *, Int);");
  152. printf("\nprotected const el_func_t* func__get(void);\n");
  153. printf("#endif /* _h_fcns_c */\n");
  154. }'
  155. ;;
  156. # generate fcns.c from various .h files
  157. #
  158. -fc)
  159. cat $FILES | $AWK '/el_action_t/ { print $3 }' | sort | $AWK '
  160. BEGIN {
  161. printf("/* Automatically generated file, do not edit */\n");
  162. printf("#include \"config.h\"\n#include \"el.h\"\n");
  163. printf("private const el_func_t el_func[] = {");
  164. maxlen = 80;
  165. needn = 1;
  166. len = 0;
  167. }
  168. {
  169. clen = 25 + 2;
  170. len += clen;
  171. if (len >= maxlen)
  172. needn = 1;
  173. if (needn) {
  174. printf("\n ");
  175. needn = 0;
  176. len = 4 + clen;
  177. }
  178. s = $1 ",";
  179. printf("%-26.26s ", s);
  180. }
  181. END {
  182. printf("\n};\n");
  183. printf("\nprotected const el_func_t* func__get(void) { return el_func; }\n");
  184. }'
  185. ;;
  186. # generate editline.c from various .c files
  187. #
  188. -e)
  189. echo "$FILES" | tr ' ' '\012' | $AWK '
  190. BEGIN {
  191. printf("/* Automatically generated file, do not edit */\n");
  192. printf("#define protected static\n");
  193. printf("#define SCCSID\n");
  194. }
  195. {
  196. printf("#include \"%s\"\n", $1);
  197. }'
  198. ;;
  199. # generate man page fragment from various .c files
  200. #
  201. -m)
  202. cat $FILES | $AWK '
  203. BEGIN {
  204. printf(".\\\" Section automatically generated with makelist\n");
  205. printf(".Bl -tag -width 4n\n");
  206. }
  207. /\(\):/ {
  208. pr = substr($2, 1, 2);
  209. if (pr == "vi" || pr == "em" || pr == "ed") {
  210. name = substr($2, 1, length($2) - 3);
  211. fname = "";
  212. for (i = 1; i <= length(name); i++) {
  213. s = substr(name, i, 1);
  214. if (s == "_")
  215. s = "-";
  216. fname = fname s;
  217. }
  218. printf(".It Ic %s\n", fname);
  219. ok = 1;
  220. }
  221. }
  222. /^ \*/ {
  223. if (ok) {
  224. for (i = 2; i < NF; i++)
  225. printf("%s ", $i);
  226. printf("%s.\n", $i);
  227. ok = 0;
  228. }
  229. }
  230. END {
  231. printf(".El\n");
  232. printf(".\\\" End of section automatically generated with makelist\n");
  233. }'
  234. ;;
  235. *)
  236. echo $USAGE 1>&2
  237. exit 1
  238. ;;
  239. esac