Annotation of gforth/doc/makedoc.fs, revision 1.10

1.1       anton       1: \ create a documentation file
                      2: 
1.10    ! anton       3: \ Copyright (C) 1995,1999,2000,2003,2004 Free Software Foundation, Inc.
1.1       anton       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
1.5       anton      19: \ Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111, USA.
1.1       anton      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:
1.2       pazsan     26: \  .... name ( stack-effect ) \ [prefix-] wordset [pronounciation]
1.1       anton      27: \ \G description ...
                     28: 
1.3       crook      29: \ The output is a file of entries that look like this:
                     30: \ make-doc [--prefix]-entry name stack-effect ) wordset [pronounciation]
1.1       anton      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: 
1.3       crook      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: 
1.1       anton      65: : \G ( -- )
1.3       crook      66:     source >in @ /string >fileCR
1.1       anton      67:     source >in ! drop ; immediate
                     68: 
                     69: : put-doc-entry ( -- )
1.9       anton      70:     dpp @ normal-dp =   \ not defining locals
1.7       anton      71:     latest 0<> and     \ not an anonymous (i.e. noname) header
1.1       anton      72:     if
1.3       crook      73:        s" " >fileCR
                     74:        s" make-doc " >file
1.2       pazsan     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
1.3       crook      84:                s" --" >file
                     85:                count >file drop
1.2       pazsan     86:            ELSE
                     87:                drop >in !
                     88:            THEN
                     89:        ELSE
                     90:            drop >in !
                     91:        THEN
1.7       anton      92:        latest name>string >file
1.3       crook      93:        >file
                     94:        s"  )" >file
1.1       anton      95:        POSTPONE \g
1.2       pazsan     96:        r> >in !
1.1       anton      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>