Commit | Line | Data |
---|---|---|
2b829bbb | 1 | # Copyright (C) 1999, 2000, 2001, 2006 Free Software Foundation, Inc. |
d6a35f3f MV |
2 | # |
3 | # This program is free software; you can redistribute it and/or modify | |
53befeb7 NJ |
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. | |
d6a35f3f | 7 | # |
53befeb7 NJ |
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. | |
d6a35f3f | 12 | # |
53befeb7 NJ |
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 | |
d6a35f3f | 17 | # |
e8e9b690 GB |
18 | # Written by Greg J. Badros, <gjb@cs.washington.edu> |
19 | # 12-Dec-1999 | |
20 | ||
21 | BEGIN { FS="|"; | |
f7736e9a | 22 | dot_doc_file = ARGV[1]; ARGV[1] = "-"; |
11a5232f | 23 | std_err = "/dev/stderr"; |
e8e9b690 GB |
24 | # be sure to put something in the files to help make out |
25 | print ""; | |
26 | printf "" > dot_doc_file; | |
27 | } | |
28 | ||
3c6d9d71 DH |
29 | /^[ \t]*SCM_SNARF_INIT_START/ { copy = $0; |
30 | gsub(/[ \t]*SCM_SNARF_INIT_START/, "", copy); | |
31 | gsub(/SCM_SNARF_DOC_START.*$/, "", copy); | |
e8e9b690 GB |
32 | print copy; } |
33 | ||
3c6d9d71 DH |
34 | /SCM_SNARF_DOC_START/,/SCM_SNARF_DOCSTRING_START/ { copy = $0; |
35 | if (match(copy,/SCM_SNARF_DOC_STARTR/)) { registering = 1; } | |
e8e9b690 | 36 | else {registering = 0; } |
3c6d9d71 DH |
37 | gsub(/.*SCM_SNARF_DOC_START./,"", copy); |
38 | gsub(/SCM_SNARF_DOCSTRING_START.*/,"",copy); | |
e8e9b690 GB |
39 | gsub(/[ \t]+/," ", copy); |
40 | sub(/^[ \t]*/,"(", copy); | |
41 | gsub(/\"/,"",copy); | |
c751e5e3 | 42 | sub(/\([ \t]*void[ \t]*\)/,"()", copy); |
e8e9b690 GB |
43 | sub(/ \(/," ",copy); |
44 | numargs = gsub(/SCM /,"", copy); | |
45 | numcommas = gsub(/,/,"", copy); | |
46 | numactuals = $2 + $3 + $4; | |
47 | location = $5; | |
48 | gsub(/\"/,"",location); | |
49 | sub(/^[ \t]*/,"",location); | |
50 | sub(/[ \t]*$/,"",location); | |
51 | sub(/: /,":",location); | |
9d29e990 | 52 | sub(/^\.\//,"",location); |
c751e5e3 GB |
53 | # Now whittle copy down to just the $1 field |
54 | # (but do not use $1, since it hasn't been | |
55 | # altered by the above regexps) | |
e8e9b690 GB |
56 | gsub(/[ \t]*\|.*$/,"",copy); |
57 | sub(/ \)/,")",copy); | |
c751e5e3 GB |
58 | # Now `copy' contains the nice scheme proc "prototype", e.g. |
59 | # (set-car! pair value) | |
25703850 NJ |
60 | # Since this is destined to become Texinfo source, |
61 | # quote any `@'s that occur in the prototype. | |
62 | gsub(/\@/,"@@",copy); | |
c751e5e3 | 63 | # print copy > "/dev/stderr"; # for debugging |
9d29e990 NJ |
64 | sub(/^\(/,"",copy); |
65 | sub(/\)[ \t]*$/,"",copy); | |
c751e5e3 GB |
66 | proc_and_args = copy; |
67 | curr_function_proto = copy; | |
9d29e990 NJ |
68 | proc_name = copy; |
69 | sub(/ .*$/,"",proc_name); | |
c751e5e3 | 70 | sub(/[^ \n]* /,"",proc_and_args); |
c751e5e3 GB |
71 | split(proc_and_args,args," "); |
72 | # now args is an array of the arguments | |
73 | # args[1] is the formal name of the first argument, etc. | |
e8e9b690 | 74 | if (numargs != numactuals && !registering) |
9d29e990 NJ |
75 | { print location ":*** `" curr_function_proto "' is improperly registered as having " numactuals " arguments" > std_err; } |
76 | # Build a nicer function prototype than curr_function_proto | |
77 | # that shows optional and rest arguments. | |
78 | nicer_function_proto = proc_name; | |
79 | if (!registering) { | |
80 | optional_args_tail = ""; | |
81 | for (i = 1; i <= $2; i++) { | |
82 | nicer_function_proto = nicer_function_proto " " args[i]; | |
83 | } | |
84 | for (; i <= $2 + $3; i++) { | |
85 | nicer_function_proto = nicer_function_proto " [" args[i]; | |
86 | optional_args_tail = optional_args_tail "]"; | |
87 | } | |
88 | nicer_function_proto = nicer_function_proto optional_args_tail; | |
89 | if ($4 != 0) { | |
90 | nicer_function_proto = nicer_function_proto " . " args[i]; | |
91 | } | |
92 | } | |
93 | # Now produce Texinfo format output. | |
94 | print "\n\f" proc_name > dot_doc_file; | |
95 | print "@c snarfed from " location > dot_doc_file; | |
96 | print "@deffn primitive " nicer_function_proto > dot_doc_file; | |
97 | } | |
e8e9b690 | 98 | |
7a095584 NJ |
99 | /SCM_SNARF_DOCSTRING_START/,/SCM_SNARF_DOCSTRING_END.*$/ { copy = $0; |
100 | ||
101 | # Trim everything up to and including | |
102 | # SCM_SNARF_DOCSTRING_START marker. | |
103 | gsub(/.*SCM_SNARF_DOCSTRING_START/,"",copy); | |
104 | ||
105 | # Trim leading whitespace and opening quote. | |
106 | sub(/^[ \t]*\"?/,"", copy); | |
107 | ||
108 | # Trim closing quote and trailing whitespace, or | |
109 | # closing quote and whitespace followed by the | |
110 | # SCM_SNARF_DOCSTRING_END marker. | |
111 | sub(/[ \t]*\"?[ \t]*$/,"", copy); | |
112 | sub(/[ \t]*\"?[ \t]*SCM_SNARF_DOCSTRING_END.*$/,"", copy); | |
113 | ||
114 | # Replace escaped characters. | |
115 | gsub(/\\n/,"\n",copy); | |
116 | gsub(/\\\"/,"\"",copy); | |
117 | gsub(/\\\\/,"\\",copy); | |
118 | ||
119 | # Some docstrings end each line with "\n", while | |
120 | # others don't. Therefore we always strip off one "\n" | |
121 | # if present at the end of the line. Docstrings must | |
122 | # therefore always use "\n\n" to indicate a blank line. | |
123 | if (copy != "") | |
124 | { | |
125 | sub(/[ \t]*\n$/, "", copy); | |
126 | print copy > dot_doc_file; | |
127 | } | |
c751e5e3 GB |
128 | } |
129 | ||
66418d34 | 130 | /SCM_SNARF_DOCSTRING_END[ \t]*/ { print "@end deffn" >> dot_doc_file; } |
e8e9b690 | 131 | |
c751e5e3 GB |
132 | /\*&\*&\*&\*SCM_ARG_BETTER_BE_IN_POSITION/ { copy = $0; |
133 | sub(/.*\*&\*&\*&\*SCM_ARG_BETTER_BE_IN_POSITION\([ \t]*/,"",copy); | |
134 | if (copy ~ /\"/) { next } | |
135 | gsub(/[ \t]*,[ \t]*/,":",copy); | |
136 | sub(/[ \t]*\).*/,"",copy); | |
137 | split(copy,argpos,":"); | |
138 | argname = argpos[1]; | |
139 | pos = argpos[2]; | |
140 | if (pos ~ /[A-Za-z]/) { next } | |
141 | if (pos ~ /^[ \t]*$/) { next } | |
142 | if (argname ~ / /) { next } | |
143 | line = argpos[3]; | |
144 | # print pos " " args[pos] " vs. " argname > "/dev/stderr"; | |
145 | if (args[pos] != argname) { print filename ":" line ":*** Argument name/number mismatch in `" curr_function_proto "' -- " argname " is not formal #" pos > "/dev/stderr"; } | |
146 | } |