* eval.c (scm_ceval, scm_deval): Check for wrong number of args
[bpt/guile.git] / libguile / guile-snarf.awk.in
CommitLineData
e8e9b690
GB
1# Written by Greg J. Badros, <gjb@cs.washington.edu>
2# 12-Dec-1999
3
4BEGIN { FS="|";
f7736e9a 5 dot_doc_file = ARGV[1]; ARGV[1] = "-";
11a5232f 6 std_err = "/dev/stderr";
e8e9b690
GB
7 # be sure to put something in the files to help make out
8 print "";
9 printf "" > dot_doc_file;
10}
11
3c6d9d71
DH
12/^[ \t]*SCM_SNARF_INIT_START/ { copy = $0;
13 gsub(/[ \t]*SCM_SNARF_INIT_START/, "", copy);
14 gsub(/SCM_SNARF_DOC_START.*$/, "", copy);
e8e9b690
GB
15 print copy; }
16
3c6d9d71
DH
17/SCM_SNARF_DOC_START/,/SCM_SNARF_DOCSTRING_START/ { copy = $0;
18 if (match(copy,/SCM_SNARF_DOC_STARTR/)) { registering = 1; }
e8e9b690 19 else {registering = 0; }
3c6d9d71
DH
20 gsub(/.*SCM_SNARF_DOC_START./,"", copy);
21 gsub(/SCM_SNARF_DOCSTRING_START.*/,"",copy);
e8e9b690
GB
22 gsub(/[ \t]+/," ", copy);
23 sub(/^[ \t]*/,"(", copy);
24 gsub(/\"/,"",copy);
c751e5e3 25 sub(/\([ \t]*void[ \t]*\)/,"()", copy);
e8e9b690
GB
26 sub(/ \(/," ",copy);
27 numargs = gsub(/SCM /,"", copy);
28 numcommas = gsub(/,/,"", copy);
29 numactuals = $2 + $3 + $4;
30 location = $5;
31 gsub(/\"/,"",location);
32 sub(/^[ \t]*/,"",location);
33 sub(/[ \t]*$/,"",location);
34 sub(/: /,":",location);
9d29e990 35 sub(/^\.\//,"",location);
c751e5e3
GB
36 # Now whittle copy down to just the $1 field
37 # (but do not use $1, since it hasn't been
38 # altered by the above regexps)
e8e9b690
GB
39 gsub(/[ \t]*\|.*$/,"",copy);
40 sub(/ \)/,")",copy);
c751e5e3
GB
41 # Now `copy' contains the nice scheme proc "prototype", e.g.
42 # (set-car! pair value)
25703850
NJ
43 # Since this is destined to become Texinfo source,
44 # quote any `@'s that occur in the prototype.
45 gsub(/\@/,"@@",copy);
c751e5e3 46 # print copy > "/dev/stderr"; # for debugging
9d29e990
NJ
47 sub(/^\(/,"",copy);
48 sub(/\)[ \t]*$/,"",copy);
c751e5e3
GB
49 proc_and_args = copy;
50 curr_function_proto = copy;
9d29e990
NJ
51 proc_name = copy;
52 sub(/ .*$/,"",proc_name);
c751e5e3 53 sub(/[^ \n]* /,"",proc_and_args);
c751e5e3
GB
54 split(proc_and_args,args," ");
55 # now args is an array of the arguments
56 # args[1] is the formal name of the first argument, etc.
e8e9b690 57 if (numargs != numactuals && !registering)
9d29e990
NJ
58 { print location ":*** `" curr_function_proto "' is improperly registered as having " numactuals " arguments" > std_err; }
59 # Build a nicer function prototype than curr_function_proto
60 # that shows optional and rest arguments.
61 nicer_function_proto = proc_name;
62 if (!registering) {
63 optional_args_tail = "";
64 for (i = 1; i <= $2; i++) {
65 nicer_function_proto = nicer_function_proto " " args[i];
66 }
67 for (; i <= $2 + $3; i++) {
68 nicer_function_proto = nicer_function_proto " [" args[i];
69 optional_args_tail = optional_args_tail "]";
70 }
71 nicer_function_proto = nicer_function_proto optional_args_tail;
72 if ($4 != 0) {
73 nicer_function_proto = nicer_function_proto " . " args[i];
74 }
75 }
76 # Now produce Texinfo format output.
77 print "\n\f" proc_name > dot_doc_file;
78 print "@c snarfed from " location > dot_doc_file;
79 print "@deffn primitive " nicer_function_proto > dot_doc_file;
80}
e8e9b690 81
3c6d9d71
DH
82/SCM_SNARF_DOCSTRING_START/,/SCM_SNARF_DOCSTRING_END.*$/ { copy = $0;
83 gsub(/.*SCM_SNARF_DOCSTRING_START/,"",copy);
9d29e990 84 sub(/^[ \t]*\"?/,"", copy);
3c6d9d71 85 sub(/\"?[ \t]*SCM_SNARF_DOCSTRING_END.*$/,"", copy);
9d29e990
NJ
86 gsub(/\\n\\n\"?/,"\n",copy);
87 gsub(/\\n\"?[ \t]*$/,"",copy);
88 gsub(/\\\"/,"\"",copy);
e8e9b690 89 gsub(/[ \t]*$/,"", copy);
c751e5e3
GB
90 if (copy != "") { print copy > dot_doc_file }
91 }
92
9d29e990 93/SCM_SNARF_DOCSTRING_END[ \t]/ { print "@end deffn" >> dot_doc_file; }
e8e9b690 94
c751e5e3
GB
95/\*&\*&\*&\*SCM_ARG_BETTER_BE_IN_POSITION/ { copy = $0;
96 sub(/.*\*&\*&\*&\*SCM_ARG_BETTER_BE_IN_POSITION\([ \t]*/,"",copy);
97 if (copy ~ /\"/) { next }
98 gsub(/[ \t]*,[ \t]*/,":",copy);
99 sub(/[ \t]*\).*/,"",copy);
100 split(copy,argpos,":");
101 argname = argpos[1];
102 pos = argpos[2];
103 if (pos ~ /[A-Za-z]/) { next }
104 if (pos ~ /^[ \t]*$/) { next }
105 if (argname ~ / /) { next }
106 line = argpos[3];
107# print pos " " args[pos] " vs. " argname > "/dev/stderr";
108 if (args[pos] != argname) { print filename ":" line ":*** Argument name/number mismatch in `" curr_function_proto "' -- " argname " is not formal #" pos > "/dev/stderr"; }
109 }