File:  [gforth] / gforth / doc / makedoc.fs
Revision 1.5: download - view: text, annotated - select for diffs
Sat Sep 23 15:47:06 2000 UTC (23 years, 6 months ago) by anton
Branches: MAIN
CVS tags: v0-5-0, HEAD
changed FSF address in copyright messages

    1: \ create a documentation file
    2: 
    3: \ Copyright (C) 1995,1999 Free Software Foundation, Inc.
    4: 
    5: \ This file is part of Gforth.
    6: 
    7: \ Gforth is free software; you can redistribute it and/or
    8: \ modify it under the terms of the GNU General Public License
    9: \ as published by the Free Software Foundation; either version 2
   10: \ of the License, or (at your option) any later version.
   11: 
   12: \ This program is distributed in the hope that it will be useful,
   13: \ but WITHOUT ANY WARRANTY; without even the implied warranty of
   14: \ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
   15: \ GNU General Public License for more details.
   16: 
   17: \ You should have received a copy of the GNU General Public License
   18: \ along with this program; if not, write to the Free Software
   19: \ Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111, USA.
   20: 
   21: 
   22: \ the stack effect of loading this file is: ( addr u -- )
   23: \ it takes the name of the doc-file to be generated.
   24: 
   25: \ the forth source must have the following format:
   26: \  .... name ( stack-effect ) \ [prefix-] wordset [pronounciation]
   27: \ \G description ...
   28: 
   29: \ The output is a file of entries that look like this:
   30: \ make-doc [--prefix]-entry name stack-effect ) wordset [pronounciation]
   31: \ description
   32: \
   33: \ (i.e., the entry is terminated by an empty line or the end-of-file)
   34: 
   35: \ this stuff uses the same mechanism as etags.fs, i.e., the
   36: \ documentation is generated during compilation using a deferred
   37: \ HEADER. It should be possible to use this togeter with etags.fs.
   38: 
   39: \ This is not very general. Input should come from stream files,
   40: \ otherwise the results are unpredictable. It also does not detect
   41: \ errors in the input (e.g., if there is something else on the
   42: \ definition line) and reacts strangely to them.
   43: 
   44: \ possible improvements: we could analyse the defining word and guess
   45: \ the stack effect. This would be handy for variables. Unfortunately,
   46: \ we have to look back in the input buffer; we cannot use the cfa
   47: \ because it does not exist when header is called.
   48: 
   49: \ This is ANS Forth with the following serious environmental
   50: \ dependences: the variable LAST must contain a pointer to the last
   51: \ header, NAME>STRING must convert that pointer to a string, and
   52: \ HEADER must be a deferred word that is called to create the name.
   53: 
   54: 
   55: r/w create-file throw value doc-file-id
   56: \ contains the file-id of the documentation file
   57: 
   58: s" \ automatically generated by makedoc.fs" doc-file-id write-line throw
   59: 
   60: : >fileCR ( c-addr u -- )
   61:     doc-file-id write-line throw ;
   62: : >file    ( c-addr u -- )
   63:     doc-file-id write-file throw ;
   64: 
   65: : \G ( -- )
   66:     source >in @ /string >fileCR
   67:     source >in ! drop ; immediate
   68: 
   69: : put-doc-entry ( -- )
   70:     locals-list @ 0=	\ not in a colon def, i.e., not a local name
   71:     last @ 0<> and	\ not an anonymous (i.e. noname) header
   72:     if
   73: 	s" " >fileCR
   74: 	s" make-doc " >file
   75: 	>in @ >r
   76: 	[char] ( parse 2drop
   77: 	[char] ) parse
   78: 	[char] \ parse 2drop
   79: 	>in @
   80: 	bl word  dup c@
   81: 	IF
   82: 	    dup count 1- chars + c@ [char] - =
   83: 	    IF
   84: 		s" --" >file
   85: 		count >file drop
   86: 	    ELSE
   87: 		drop >in !
   88: 	    THEN
   89: 	ELSE
   90: 	    drop >in !
   91: 	THEN
   92: 	last @ name>string >file
   93: 	>file
   94: 	s"  )" >file
   95: 	POSTPONE \g
   96: 	r> >in !
   97:     endif ;
   98: 
   99: : (doc-header) ( -- )
  100:     defers header
  101:     put-doc-entry ;
  102: 
  103: ' (doc-header) IS header

FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>