1# This is a snarfer for guile version 1.6
2# Copyright (C) 2002, 2007 Free Software Foundation, Inc.
3#
4# Written by Sergey Poznyakoff
5#
6#  This program is free software; you can redistribute it and/or modify
7#  it under the terms of the GNU General Public License as published by
8#  the Free Software Foundation; either version 3 of the License, or
9#  (at your option) any later version.
10#
11#  This program is distributed in the hope that it will be useful,
12#  but WITHOUT ANY WARRANTY; without even the implied warranty of
13#  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14#  GNU General Public License for more details.
15#
16#  You should have received a copy of the GNU General Public License
17#  along with this program; if not, write to the Free Software Foundation,
18#  Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
19
20BEGIN {
21      cname = ""
22}
23
24function flush() {
25	 if (cname == "")
26	    return;
27	 if (arg_req + arg_opt + arg_var != numargs)
28	    error(cname " incorrectly defined as taking " numargs " arguments")
29
30	 print "\f" cname
31	 print "@c snarfed from " loc_source ":" loc_line
32	 printf "@deffn {Scheme procedure} %s", cname
33	 for (i = 1; i <= numargs; i++)
34	     printf(" %s", arglist[i])
35	 print ""
36	 print docstring
37	 print "@end deffn\n"
38
39	 delete argpos
40	 delete arglist
41	 cname = ""
42}
43
44function error(s) {
45	 print loc_source ":" loc_line ": " s > "/dev/stderr"
46	 exit 1
47}
48
49state == 0 && /{/ {
50	flush()
51	cname = $3
52	next
53}
54
55state == 0 && /fname/ { fname = $2; next }
56state == 0 && /type/ { type = $2; next }
57state == 0 && /location/ { loc_source = $2; loc_line = $3 }
58state == 0 && /arglist/ {
59	match($0, "\\(.*\\)")
60	s = substr($0,RSTART+1,RLENGTH-2)
61	numargs = split(s, a, ",")
62	for (i = 1; i <= numargs; i++) {
63	    m = split(a[i], b, "[ \t]*")
64	    if (b[1] == "") {
65	       t = b[2]
66	       n = b[3]
67	       m--
68	    } else {
69	       t = b[1]
70	       n = b[2]
71	    }
72	    if (m > 2 || t != "SCM")
73	       error(cname ": wrong argument type for arg " i " " t)
74	    arglist[i] = n
75	}
76}
77state == 0 && /argsig/ { arg_req = $2; arg_opt = $3; arg_var = $4 }
78
79state == 0 && /.*\"/    {
80        gsub("\"\"", "")
81	gsub("\\\\n", "\n")
82	match($0,"\".*\"")
83	docstring = substr($0,RSTART+1,RLENGTH-2)
84}
85
86/argpos/ { argpos[$2] = $3 }
87
88END {
89	flush()
90}
91