+ file.close
+end
+
+# Extract documentation for each program and write out manuals.
+def documentprog (text)
+ header = text[0]
+ progtext = []
+ title = ""
+ brief = ""
+ text.each_with_index{|line,i|
+ if line =~ /^\.SH\s*\"(\S+) -- ([^\"]+)\"/
+ # Remember the title and short description. It may or may not
+ # be for a program.
+ title = $1
+ brief = $2
+ elsif line =~ /^\.SS\s*"SYNOPSIS"/
+ # Only a program has "SYNOPSIS".
+ progtext.push(header.gsub("m17nExProg",title))
+ progtext.push(".ad l\n.nh\n.SH NAME\n")
+ progtext.push(title + " - " + brief)
+ progtext.push(".SH SYNOPSIS")
+ elsif line =~ /^\.PD 0/
+ # Don't write this "inter-paragraph vertical distance" command
+ elsif line =~ /Print this message./
+ # This is always the end of description for a program.
+ if progtext.length > 0
+ file = open($doxywork+title+$manext,"w")
+ file.puts(progtext)
+ file.puts(line)
+ file.close
+ progtext = []
+ end
+ elsif progtext.length > 0
+ if line =~ /^\.SS\s*(.*)/
+ # Convert ".SS ..." to ".SH ..."
+ progtext.push(".SH " + $1)
+ else
+ progtext.push(line)
+ end
+ end
+ }
+end