guile-snarf.awk.in 5.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147
  1. # Copyright (C) 1999, 2000, 2001, 2006 Free Software Foundation, Inc.
  2. #
  3. # This program is free software; you can redistribute it and/or modify
  4. # it under the terms of the GNU Lesser General Public License as
  5. # published by the Free Software Foundation; either version 3, or (at
  6. # your option) any later version.
  7. #
  8. # This program is distributed in the hope that it will be useful, but
  9. # WITHOUT ANY WARRANTY; without even the implied warranty of
  10. # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  11. # Lesser General Public License for more details.
  12. #
  13. # You should have received a copy of the GNU Lesser General Public
  14. # License along with this software; see the file COPYING.LESSER. If
  15. # not, write to the Free Software Foundation, Inc., 51 Franklin
  16. # Street, Fifth Floor, Boston, MA 02110-1301 USA
  17. #
  18. # Written by Greg J. Badros, <gjb@cs.washington.edu>
  19. # 12-Dec-1999
  20. BEGIN { FS="|";
  21. dot_doc_file = ARGV[1]; ARGV[1] = "-";
  22. std_err = "/dev/stderr";
  23. # be sure to put something in the files to help make out
  24. print "";
  25. printf "" > dot_doc_file;
  26. }
  27. /^[ \t]*SCM_SNARF_INIT_START/ { copy = $0;
  28. gsub(/[ \t]*SCM_SNARF_INIT_START/, "", copy);
  29. gsub(/SCM_SNARF_DOC_START.*$/, "", copy);
  30. print copy; }
  31. /SCM_SNARF_DOC_START/,/SCM_SNARF_DOCSTRING_START/ { copy = $0;
  32. if (match(copy,/SCM_SNARF_DOC_STARTR/)) { registering = 1; }
  33. else {registering = 0; }
  34. gsub(/.*SCM_SNARF_DOC_START./,"", copy);
  35. gsub(/SCM_SNARF_DOCSTRING_START.*/,"",copy);
  36. gsub(/[ \t]+/," ", copy);
  37. sub(/^[ \t]*/,"(", copy);
  38. gsub(/\"/,"",copy);
  39. sub(/\([ \t]*void[ \t]*\)/,"()", copy);
  40. sub(/ \(/," ",copy);
  41. numargs = gsub(/SCM /,"", copy);
  42. numcommas = gsub(/,/,"", copy);
  43. numactuals = $2 + $3 + $4;
  44. location = $5;
  45. gsub(/\"/,"",location);
  46. sub(/^[ \t]*/,"",location);
  47. sub(/[ \t]*$/,"",location);
  48. sub(/: /,":",location);
  49. sub(/^\.\//,"",location);
  50. # Now whittle copy down to just the $1 field
  51. # (but do not use $1, since it hasn't been
  52. # altered by the above regexps)
  53. gsub(/[ \t]*\|.*$/,"",copy);
  54. sub(/ \)/,")",copy);
  55. # Now `copy' contains the nice scheme proc "prototype", e.g.
  56. # (set-car! pair value)
  57. # Since this is destined to become Texinfo source,
  58. # quote any `@'s that occur in the prototype.
  59. gsub(/\@/,"@@",copy);
  60. # print copy > "/dev/stderr"; # for debugging
  61. sub(/^\(/,"",copy);
  62. sub(/\)[ \t]*$/,"",copy);
  63. proc_and_args = copy;
  64. curr_function_proto = copy;
  65. proc_name = copy;
  66. sub(/ .*$/,"",proc_name);
  67. sub(/[^ \n]* /,"",proc_and_args);
  68. split(proc_and_args,args," ");
  69. # now args is an array of the arguments
  70. # args[1] is the formal name of the first argument, etc.
  71. if (numargs != numactuals && !registering)
  72. { print location ":*** `" curr_function_proto "' is improperly registered as having " numactuals " arguments" > std_err; }
  73. # Build a nicer function prototype than curr_function_proto
  74. # that shows optional and rest arguments.
  75. nicer_function_proto = proc_name;
  76. if (!registering) {
  77. optional_args_tail = "";
  78. for (i = 1; i <= $2; i++) {
  79. nicer_function_proto = nicer_function_proto " " args[i];
  80. }
  81. for (; i <= $2 + $3; i++) {
  82. nicer_function_proto = nicer_function_proto " [" args[i];
  83. optional_args_tail = optional_args_tail "]";
  84. }
  85. nicer_function_proto = nicer_function_proto optional_args_tail;
  86. if ($4 != 0) {
  87. nicer_function_proto = nicer_function_proto " . " args[i];
  88. }
  89. }
  90. # Now produce Texinfo format output.
  91. print "\n " proc_name > dot_doc_file;
  92. print "@c snarfed from " location > dot_doc_file;
  93. print "@deffn primitive " nicer_function_proto > dot_doc_file;
  94. }
  95. /SCM_SNARF_DOCSTRING_START/,/SCM_SNARF_DOCSTRING_END.*$/ { copy = $0;
  96. # Trim everything up to and including
  97. # SCM_SNARF_DOCSTRING_START marker.
  98. gsub(/.*SCM_SNARF_DOCSTRING_START/,"",copy);
  99. # Trim leading whitespace and opening quote.
  100. sub(/^[ \t]*\"?/,"", copy);
  101. # Trim closing quote and trailing whitespace, or
  102. # closing quote and whitespace followed by the
  103. # SCM_SNARF_DOCSTRING_END marker.
  104. sub(/[ \t]*\"?[ \t]*$/,"", copy);
  105. sub(/[ \t]*\"?[ \t]*SCM_SNARF_DOCSTRING_END.*$/,"", copy);
  106. # Replace escaped characters.
  107. gsub(/\\n/,"\n",copy);
  108. gsub(/\\\"/,"\"",copy);
  109. gsub(/\\\\/,"\\",copy);
  110. # Some docstrings end each line with "\n", while
  111. # others don't. Therefore we always strip off one "\n"
  112. # if present at the end of the line. Docstrings must
  113. # therefore always use "\n\n" to indicate a blank line.
  114. if (copy != "")
  115. {
  116. sub(/[ \t]*\n$/, "", copy);
  117. print copy > dot_doc_file;
  118. }
  119. }
  120. /SCM_SNARF_DOCSTRING_END[ \t]*/ { print "@end deffn" >> dot_doc_file; }
  121. /\*&\*&\*&\*SCM_ARG_BETTER_BE_IN_POSITION/ { copy = $0;
  122. sub(/.*\*&\*&\*&\*SCM_ARG_BETTER_BE_IN_POSITION\([ \t]*/,"",copy);
  123. if (copy ~ /\"/) { next }
  124. gsub(/[ \t]*,[ \t]*/,":",copy);
  125. sub(/[ \t]*\).*/,"",copy);
  126. split(copy,argpos,":");
  127. argname = argpos[1];
  128. pos = argpos[2];
  129. if (pos ~ /[A-Za-z]/) { next }
  130. if (pos ~ /^[ \t]*$/) { next }
  131. if (argname ~ / /) { next }
  132. line = argpos[3];
  133. # print pos " " args[pos] " vs. " argname > "/dev/stderr";
  134. if (args[pos] != argname) { print filename ":" line ":*** Argument name/number mismatch in `" curr_function_proto "' -- " argname " is not formal #" pos > "/dev/stderr"; }
  135. }