# # GAWK Program to extract all of the @name entities from # the document and create a table of contents page. # This file analyzes all of the files pointed to by the top # level file in the document structure. # BEGIN { level = 0 count = 0 } # Big limit here in that it is all not tied to the # inside comments concept. # Presumes one layer of includes only { if (NF == 2 && $1 == "\/\/@Include:") { incfile = $2 while ((getline < incfile) > 0) { if ($2 == "@name") { fil[count]= incfile lvl[count] = level nme[count] = compressstring(3) flnme[count++] = Svstr(3) } if (match ($1, "@name") > 0) { fil[count]= incfile lvl[count] = level nme[count] = compressstring(2) flnme[count++] = Svstr(2) } if ($1 == "\/\/@{") level++ if ($1 == "\/\/@}") level-- } close($2) } else { if ($2 == "@name") { fil[count]= FILENAME lvl[count] = level nme[count] = compressstring(3) flnme[count++] = Svstr(3) } if (match ($1, "@name") > 0) { fil[count]= FILENAME lvl[count] = level nme[count] = compressstring(2) flnme[count++] = Svstr(2) } if ($1 == "\/\/@{") level++ if ($1 == "\/\/@}") level-- } } END{ indent = 0 is = "" lv = 0 # Print the TOC Header print "" print "" print "" print "" print "" print "PegasusDocumentTOC" print "" print "" print "" print "

" print "

 

" print "

Contents

" print "" # The array contains Filename, lvl, section name # # Print an output for each line that represents the TOC HTML for that line for (x = 0; x <= count; x++) { print print "" if (lvl[x] != 0){ ft = " " nft = "" } else { ft = "" nft = "" } print "" print } # Print the closing section print "
# o # Introduction
#
" print ist(lvl[x])"\"o\"" " " print "" ft flnme[x] nft "
" print "
" print "" print "" print "" } # # functions # # Compress the $0 string, taking out all spaces from the pos defined # returns the result With quotes around it. function compressstring(pos){ out = "" for (i = pos; i <= NF; i++) out = out $i return out } # Simply duplicate the remainder of the $0 string and return it function Svstr(pos){ out = "" for (i = pos; i <= NF; i++) out = out " " $i return out } # create an indent string with length corresponding to the #indent count. 0 = zero length, 1, 3 char, etc. # uses the   to indent for the moment function ist (indent){ isstring = "" if (indent == 0) return "" for (i=1; i <= indent; i++) isstring = isstring "   " return isstring }