guile-snarf.awk.in 3.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182
  1. # Written by Greg J. Badros, <gjb@cs.washington.edu>
  2. # 12-Dec-1999
  3. BEGIN { FS="|";
  4. dot_doc_file = ARGV[1]; ARGV[1] = "-";
  5. std_err = "/dev/stderr";
  6. # be sure to put something in the files to help make out
  7. print "";
  8. printf "" > dot_doc_file;
  9. }
  10. /^[ \t]*SCM__I/ { copy = $0;
  11. gsub(/[ \t]*SCM__I/, "", copy);
  12. gsub(/SCM__D.*$/, "", copy);
  13. print copy; }
  14. /SCM__D/,/SCM__S/ { copy = $0;
  15. if (match(copy,/SCM__DR/)) { registering = 1; }
  16. else {registering = 0; }
  17. gsub(/.*SCM__D./,"", copy);
  18. gsub(/SCM__S.*/,"",copy);
  19. gsub(/[ \t]+/," ", copy);
  20. sub(/^[ \t]*/,"(", copy);
  21. gsub(/\"/,"",copy);
  22. sub(/\([ \t]*void[ \t]*\)/,"()", copy);
  23. sub(/ \(/," ",copy);
  24. numargs = gsub(/SCM /,"", copy);
  25. numcommas = gsub(/,/,"", copy);
  26. numactuals = $2 + $3 + $4;
  27. location = $5;
  28. gsub(/\"/,"",location);
  29. sub(/^[ \t]*/,"",location);
  30. sub(/[ \t]*$/,"",location);
  31. sub(/: /,":",location);
  32. # Now whittle copy down to just the $1 field
  33. # (but do not use $1, since it hasn't been
  34. # altered by the above regexps)
  35. gsub(/[ \t]*\|.*$/,"",copy);
  36. sub(/ \)/,")",copy);
  37. # Now `copy' contains the nice scheme proc "prototype", e.g.
  38. # (set-car! pair value)
  39. # print copy > "/dev/stderr"; # for debugging
  40. proc_and_args = copy;
  41. curr_function_proto = copy;
  42. sub(/[^ \n]* /,"",proc_and_args);
  43. sub(/\)[ \t]*/,"",proc_and_args);
  44. split(proc_and_args,args," ");
  45. # now args is an array of the arguments
  46. # args[1] is the formal name of the first argument, etc.
  47. if (numargs != numactuals && !registering)
  48. { print location ":*** `" copy "' is improperly registered as having " numactuals " arguments" > std_err; }
  49. print " \n" copy (registering?")":"") > dot_doc_file ; }
  50. /SCM__S/,/SCM__E.*$/ { copy = $0;
  51. gsub(/.*SCM__S/,"",copy);
  52. sub(/^[ \t]*"?/,"", copy);
  53. sub(/\"?[ \t]*SCM__E.*$/,"", copy);
  54. gsub(/\\n\\n"?/,"\n",copy);
  55. gsub(/\\n"?[ \t]*$/,"",copy);
  56. gsub(/\\\"[ \t]*$/,"\"",copy);
  57. gsub(/[ \t]*$/,"", copy);
  58. if (copy != "") { print copy > dot_doc_file }
  59. }
  60. /SCM__E[ \t]/ { print "[" location "]" >> dot_doc_file; }
  61. /\*&\*&\*&\*SCM_ARG_BETTER_BE_IN_POSITION/ { copy = $0;
  62. sub(/.*\*&\*&\*&\*SCM_ARG_BETTER_BE_IN_POSITION\([ \t]*/,"",copy);
  63. if (copy ~ /\"/) { next }
  64. gsub(/[ \t]*,[ \t]*/,":",copy);
  65. sub(/[ \t]*\).*/,"",copy);
  66. split(copy,argpos,":");
  67. argname = argpos[1];
  68. pos = argpos[2];
  69. if (pos ~ /[A-Za-z]/) { next }
  70. if (pos ~ /^[ \t]*$/) { next }
  71. if (argname ~ / /) { next }
  72. line = argpos[3];
  73. # print pos " " args[pos] " vs. " argname > "/dev/stderr";
  74. if (args[pos] != argname) { print filename ":" line ":*** Argument name/number mismatch in `" curr_function_proto "' -- " argname " is not formal #" pos > "/dev/stderr"; }
  75. }