X-Git-Url: http://git.hcoop.net/bpt/guile.git/blobdiff_plain/11a5232f86bdaa4bde2177b96b7ba2457e670daa..cb1cfc42a4f5ac4d60a64b425795432a0388ad7e:/libguile/guile-snarf.awk.in diff --git a/libguile/guile-snarf.awk.in b/libguile/guile-snarf.awk.in index e99ed18f8..107e4fc7d 100644 --- a/libguile/guile-snarf.awk.in +++ b/libguile/guile-snarf.awk.in @@ -1,25 +1,41 @@ +# Copyright (C) 1999, 2000, 2001 Free Software Foundation, Inc. +# +# This program is free software; you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation; either version 2, or (at your option) +# any later version. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with this software; see the file COPYING. If not, write to +# the Free Software Foundation, Inc., 59 Temple Place, Suite 330, +# Boston, MA 02111-1307 USA +# # Written by Greg J. Badros, # 12-Dec-1999 BEGIN { FS="|"; - dot_doc_file = ARGV[1]; ARGV[1] = ""; - ARGC = 0; + dot_doc_file = ARGV[1]; ARGV[1] = "-"; std_err = "/dev/stderr"; # be sure to put something in the files to help make out print ""; printf "" > dot_doc_file; } -/^[ \t]*%%%/ { copy = $0; - gsub(/[ \t]*%%%/, "", copy); - gsub(/\$\$\$.*$/, "", copy); +/^[ \t]*SCM_SNARF_INIT_START/ { copy = $0; + gsub(/[ \t]*SCM_SNARF_INIT_START/, "", copy); + gsub(/SCM_SNARF_DOC_START.*$/, "", copy); print copy; } -/\$\$\$/,/@@@/ { copy = $0; - if (match(copy,/\$\$\$R/)) { registering = 1; } +/SCM_SNARF_DOC_START/,/SCM_SNARF_DOCSTRING_START/ { copy = $0; + if (match(copy,/SCM_SNARF_DOC_STARTR/)) { registering = 1; } else {registering = 0; } - gsub(/.*\$\$\$./,"", copy); - gsub(/@@@.*/,"",copy); + gsub(/.*SCM_SNARF_DOC_START./,"", copy); + gsub(/SCM_SNARF_DOCSTRING_START.*/,"",copy); gsub(/[ \t]+/," ", copy); sub(/^[ \t]*/,"(", copy); gsub(/\"/,"",copy); @@ -33,6 +49,7 @@ BEGIN { FS="|"; sub(/^[ \t]*/,"",location); sub(/[ \t]*$/,"",location); sub(/: /,":",location); + sub(/^\.\//,"",location); # Now whittle copy down to just the $1 field # (but do not use $1, since it hasn't been # altered by the above regexps) @@ -40,28 +57,77 @@ BEGIN { FS="|"; sub(/ \)/,")",copy); # Now `copy' contains the nice scheme proc "prototype", e.g. # (set-car! pair value) + # Since this is destined to become Texinfo source, + # quote any `@'s that occur in the prototype. + gsub(/\@/,"@@",copy); # print copy > "/dev/stderr"; # for debugging + sub(/^\(/,"",copy); + sub(/\)[ \t]*$/,"",copy); proc_and_args = copy; curr_function_proto = copy; + proc_name = copy; + sub(/ .*$/,"",proc_name); sub(/[^ \n]* /,"",proc_and_args); - sub(/\)[ \t]*/,"",proc_and_args); split(proc_and_args,args," "); # now args is an array of the arguments # args[1] is the formal name of the first argument, etc. if (numargs != numactuals && !registering) - { print location ":*** `" copy "' is improperly registered as having " numactuals " arguments" > std_err; } - print " \n" copy (registering?")":"") > dot_doc_file ; } + { print location ":*** `" curr_function_proto "' is improperly registered as having " numactuals " arguments" > std_err; } + # Build a nicer function prototype than curr_function_proto + # that shows optional and rest arguments. + nicer_function_proto = proc_name; + if (!registering) { + optional_args_tail = ""; + for (i = 1; i <= $2; i++) { + nicer_function_proto = nicer_function_proto " " args[i]; + } + for (; i <= $2 + $3; i++) { + nicer_function_proto = nicer_function_proto " [" args[i]; + optional_args_tail = optional_args_tail "]"; + } + nicer_function_proto = nicer_function_proto optional_args_tail; + if ($4 != 0) { + nicer_function_proto = nicer_function_proto " . " args[i]; + } + } + # Now produce Texinfo format output. + print "\n " proc_name > dot_doc_file; + print "@c snarfed from " location > dot_doc_file; + print "@deffn primitive " nicer_function_proto > dot_doc_file; +} + +/SCM_SNARF_DOCSTRING_START/,/SCM_SNARF_DOCSTRING_END.*$/ { copy = $0; + + # Trim everything up to and including + # SCM_SNARF_DOCSTRING_START marker. + gsub(/.*SCM_SNARF_DOCSTRING_START/,"",copy); + + # Trim leading whitespace and opening quote. + sub(/^[ \t]*\"?/,"", copy); + + # Trim closing quote and trailing whitespace, or + # closing quote and whitespace followed by the + # SCM_SNARF_DOCSTRING_END marker. + sub(/[ \t]*\"?[ \t]*$/,"", copy); + sub(/[ \t]*\"?[ \t]*SCM_SNARF_DOCSTRING_END.*$/,"", copy); + + # Replace escaped characters. + gsub(/\\n/,"\n",copy); + gsub(/\\\"/,"\"",copy); + gsub(/\\\\/,"\\",copy); -/@@@/,/@!!!.*$/ { copy = $0; - gsub(/.*@@@/,"",copy); - sub(/^[ \t]*"?/,"", copy); - sub(/\"?[ \t]*@!!!.*$/,"", copy); - gsub(/\\\"/,"\"",copy); - gsub(/[ \t]*$/,"", copy); - if (copy != "") { print copy > dot_doc_file } + # Some docstrings end each line with "\n", while + # others don't. Therefore we always strip off one "\n" + # if present at the end of the line. Docstrings must + # therefore always use "\n\n" to indicate a blank line. + if (copy != "") + { + sub(/[ \t]*\n$/, "", copy); + print copy > dot_doc_file; + } } -/@!!![ \t]/ { print "[" location "]" >> dot_doc_file; } +/SCM_SNARF_DOCSTRING_END[ \t]*/ { print "@end deffn" >> dot_doc_file; } /\*&\*&\*&\*SCM_ARG_BETTER_BE_IN_POSITION/ { copy = $0; sub(/.*\*&\*&\*&\*SCM_ARG_BETTER_BE_IN_POSITION\([ \t]*/,"",copy);