makelist.in 6.6 KB

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