linearize literate documentation of xhash.spad

xhash.spad is nearly a LaTeX file. Instead of noweb markup there is now
  )if LiterateDoc
and
  )endif
around the LaTeX part. To turn the .spad file into a .tex file,
one basically has to replace ")if LiterateDoc" by "\end{lstlisting}"
and ")endif" by "\begin{lstlisting}". The following awk code does
exactly that, but it also takes care of ")abbrev" appearing at the
beginning of the file and moves it into the first code chunk.
Furthermore, empty lines after ")endif" and empty lines before ")if
LiterateDoc" are moved from the code into the documentation part

Usage: awk -f totex.awk xhash.spad > xhash.tex

--- totex.awk
/^)abb[a-z]* / && abbrev_seen==0 {abbrev=$0; abbrev_seen=1; next}

/^$/ {emptyline++; next}

/^)if LiterateDoc/ {
    if (open_code) {print "\\end{lstlisting}"; open_code=0}
    while (emptyline>0) {print ""; emptyline--}
    open_literal=1
    open_code=0
    next
}

/^)endif/ {
    if (!open_literal) {print; next}
    open_literal=0
    open_code=1
    # swallow the following empty lines and only output something if
    # there is a non-empty line following.
    while (getline > 0) {
        if ($0 != "") {
            while (emptyline>0) {print ""; emptyline--}
            print "\\begin{lstlisting}[language=spad]"
            if (abbrev) {print abbrev; abbrev=""}
            print
            next
        }
        emptyline++
    }
    # coming here means EOF or error in reading
    next
}

{
    while (emptyline>0) {print ""; emptyline--}
    print
}

git-svn-id: https://fricas.svn.sourceforge.net/svnroot/fricas/trunk@1773 b0c55286-4f34-0410-a049-a1e7e93b0762