head     1.5;
branch   ;
access   ;
symbols  ;
locks    lee:1.5;
comment  @# @;


1.5
date     95.09.08.19.20.12;  author lee;  state Exp;
branches ;
next     1.4;

1.4
date     95.05.20.22.15.47;  author lee;  state Exp;
branches ;
next     1.3;

1.3
date     94.07.13.23.33.00;  author lee;  state Exp;
branches ;
next     1.2;

1.2
date     94.07.13.23.26.57;  author lee;  state Exp;
branches ;
next     1.1;

1.1
date     94.06.26.23.59.36;  author lee;  state Exp;
branches ;
next     ;


desc
@Generate sgml documentation from comments in the files
@


1.5
log
@Handle multiple classes.
been to the office and back.
@
text
@#! /bin/sh

# $Id: mkdocfromc,v 1.1 95/09/08 19:19:10 lee Exp Locker: lee $

/bin/rm -f Categories
mkdir Categories

for dir in h liblqerror liblqtext liblqutil lqtext menu
do
    i=../src/$i
    echo "**** $dir **** "
    if test -d "$i/."
    then
	find $i -type f -name '*.c' -print | xargs cat |
	sed -n -e '/<Function>/,/^{/p' |
	sed -e '/^{/s@@@@</Decl>@@' \
	    -e '/\/\*ARGSUSED[0-9]*\*\//d' \
	    -e 's@@^ *\*/ *@@<Decl>@@' \
	    -e 's@@^/\* *@@@@' \
	    -e '/<Name>.*[^>]$/s/$/<\/Name>/' \
	    -e 's@@^[ 	]*\*[ 	]*@@@@' \
	    -e 's/<\([a-z][a-z0-9]*\.h\)>/\&lt;\1\&gt;/g' \
	| mawk '

BEGIN {
    Initialize()
}

(NR == 1) {
    SomethingThere = 1
}

/<Entry>/ {
    InEntry = 1;
    sub(/<Entry>/, "<Entry dir=\"'"$dir"'\">")
    sub(/><Entry/, ">\n<Entry")
    Text($0)
    next
}

/<\/Decl>/ {
    InEntry = 0
    Text(sprintf("%s\n</Entry>", $0))
    Initialize()
    next
}

/<\/Entry>/ {
    if (!InEntry) {
	next
    }
}

/<Function>/ {
    if (!InEntry) {
	Text("<Entry dir=\"'"$dir"'\">")
	InEntry = 1
	Text($0)
	next
    }
}

/<Class>/ {
    Class = $0
    sub(/^ *<Class>[ 	]*/, "", Class)
    gotClass = 1
    if (gotName) {
	StartPrinting()
    }
}

/<Name>/ {
    Name = $0
    sub(/^.*<Name>[ 	]*/, "", Name)
    sub(/[ 	]*<\/Name>.*$/, "", Name)
    gotName = 1
    if (gotClass) {
	StartPrinting()
    }
}

{
    Text($0)
}

function Initialize()
{
    if (SavedLineCount) {
	StartPrinting()
    }

    if (FileName) {
	close(FileName)
    }
    InEntry = 0
    SomethingThere = 0
    Class = "Other"
    Name = "Other"
    FileName = "not-set-yet"
    SavedLineCount = 0
    printing = 0
    gotName = 0
    gotClass = 0
    OtherClasses = ""
}

function Text(Line)
{
    if (printing) {
	print Line >> FileName
    } else {
	Lines[++SavedLineCount] = Line
    }
}

function StartPrinting(			i)
{
    if (Class ~ /,/) {
	OtherClasses = Class
	sub(/[^,]*, */, "", OtherClasses)
	sub(/[ 	]*,.*$/, "", Class)
    }
    system("mkdir -p \"Categories/" Class "\"" )

    FileName = "Categories/" Class "/" Name
    gsub(/ /, "_", FileName);
    printf "**** %s\n", FileName
    s = \
"test -f \"" FileName "\" || ( echo '"'"'<!DOCTYPE File SYSTEM \"doc.dtd\"><File>'"'"' > \"" FileName "\"; echo \"Created " FileName "\" 1>&2 )"

    system(s)

    for (i = 1; i <= SavedLineCount; i++) {
	print Lines[i] >> FileName
    }
    printing = 1
    SavedLineCount = 0
}

END {
    if (SomethingThere) {
	if (!printing) {
	    StartPrinting()
	}
    } else {
	print "**** empty"
    }

    if (OtherClasses != "") {
	n = split(OtherClasses, Names, /[ 	]*,[ 	]*/)
	while (n > 0) {
	    printf "** %s links to %s\n", FileName, Names[n]
	    n--;
	}
    }
}
	'
    fi
done
@


1.4
log
@wow, a separate file for each function.
@
text
@d3 1
a3 1
# $Id: mkdocfromc,v 1.3 94/07/13 23:33:00 lee Exp Locker: lee $
d5 2
a6 1
/bin/rm -f Categories/*
d8 1
a8 1
for i in ../src/*lq*
d10 3
a12 2
    echo "**** $i **** "
    if test -d "$i"
d22 1
d26 1
a26 10
    InEntry = 0
    SomethingThere = 0
    Class = "Other"
    Name = "Other"
    FileName = "not-set-yet"
    SavedLineCount = 0
    printing = 0
    gotName = 0
    gotClass = 0
    OtherClasses = ""
d35 1
d44 1
d48 5
a52 1
/<\/Entry>/ { if (!InEntry) { next } }
d56 1
a56 1
	Text("<Entry>")
d86 21
d126 1
d129 1
a129 1
"test -f \"" FileName "\" || echo '"'"'<!DOCTYPE File SYSTEM \"doc.dtd\"><File>'"'"' > \"" FileName "\""
@


1.3
log
@Include first <Function>.
Put <Entry> and <Function> on lines of their own.
@
text
@d3 1
a3 1
# $Id$
d5 2
a11 1
	N=text/`basename $i`.doc
d21 1
d25 8
a35 1
    printf "<!DOCTYPE File SYSTEM \"doc.dtd\"><File>\n"
d39 13
a51 2
/<Entry>/ { InEntry = 1; print; next }
/<\/Decl>/ { InEntry = 0; printf "%s\n</Entry>", $0; next }
d53 29
a81 1
/<Function>/ { if (!InEntry) { print "<Entry>"; InEntry = 1; print; next } }
d83 1
a83 1
    print
d86 32
d120 5
a124 1
	print "</File>"
d126 8
d135 1
a135 9
	' | sed -e 's/><Entry>/>\
<Entry>/' > "$N"
	if test -s "$N"
	then
	    ls -l "$N"
	else
	    echo "[$i empty]"
	    rm "$N"
	fi
@


1.2
log
@Better handling of <decl> and of empty files.
@
text
@d3 2
a27 1
    next
d33 1
a33 1
/<Function>/ { if (!InEntry) { printf "<Entry>"; InEntry = 1; print; next } }
@


1.1
log
@Initial revision
@
text
@d8 1
a8 1
	N=`basename $i`.doc
d10 1
a10 3
	sed -n -e '1i\
<!DOCTYPE File SYSTEM "doc.dtd"><File>
'	    -e '/<Function>/,/^{/p' |
d20 1
d23 5
a27 1
/<!DOCTYPE/ { print; next }
d30 1
a30 1
/<\/Decl>/ { InEntry = 0; printf "%s</Entry>", $0; next }
d32 1
a32 1
/<Function>/ { if (!InEntry) { printf "<Entry>"; InEntry = 1 } }
d36 8
a43 1
	' > "$N"
@
