#! /usr/bin/perl # # This script is used for formatting the GNO FAQ. # # $Id: mkfaq,v 1.10 1998/01/22 14:53:10 gdr Exp $ # $src = "FAQ.gno.src"; # the name of the FAQ source file $dest = "csa2g.FAQ.txt"; # the name of the text output file $html = "csa2g.FAQ.html"; # the name of the html output file $ContactName = "Devin Reade"; $ContactEmail = "gdr\@eddore.myrias.com"; $totalSections = 0; # the number of sections in the FAQ $totalQuestions = 0; $currentQuestion = 0; $tocLines = 0; # number of lines in table of contents $lastmapping = 0; # used in &map() $SectionNumber = 0; # number of the current section $MaxSections = 0; # total number of sections # # open the output files # open (outfp, "> $dest") || die("couldn't open output file $dest"); open (outfp2, "> $html") || die("couldn't open output file $html"); $faq = "GNO Frequently Asked Questions (FAQ) List"; printf(outfp2 "\n" . "
\n" . "\n", $version, $date, $time); } elsif (/^%Header-end%\s*$/) { $in_header = 0; printf(outfp2 "\n
\n", &mapnum(&map($num)), &map($num), $htmlQuestion{&map($num)}) } else { $rest =~ s,Q\#(\d+), 'Q#'.&map($1).'',ge; $rest =~ s/^\t//; printf(outfp2 "%s\n", $rest); } } else { $line =~ s,Q\#(\d+),'Q#'.&map($1). '',ge; $line =~ s/^\t//; # replace http:// and ftp:// with the link equivalents $line =~ s,(http|ftp)://(\S+),''.$1.'://'.$2.'',ge; # $line =~ s,ftp://(\S+),'http://'.$1.'',ge; printf (outfp2 "%s", $line); } } sub mapnum { local($num); $num = @_[0]; $num =~ s/\./_/g; return $num } # # &fmt (tabs, text) # # This routine formats the specified text to fall within 76 columns, # and indents the text with the specified number of tabs (considered # to be 8 characters wide). # # The first line will _not_ be preceeded by any tabs, even though # the length will be calculated as if it is. # sub fmt { local (@array, $tabs, $line, $columns, $result, $tablen, $linelen); local ($word, $len, $i); $tabs = int(@_[0]); $line = @_[1]; $columns = 76; # maximum column number to print $tablen = 8; # spaces per tab $line =~ s/\s+/ /g; @array = split ("[ \t]+", $line); $result = ''; $linelen = 0; for ($i = 0; $i < $tabs; $i++) { $linelen += $tablen; } foreach $word (@array) { $len = length($word); if ($columns - $linelen > $len) { # add it into the current line if ($linelen == $tablen * $tabs) { $result .= $word; $linelen += $len; } else { $result .= ' ' . $word; $linelen += $len + 1; } } else { # start a new line $result .= "\n"; $linelen = 0; for ($i = 0; $i < $tabs; $i++) { $result .= "\t"; $linelen += $tablen; } $result .= $word; $linelen += $len; } } return $result; } # # Translates HTML special character sequences into their "escaped" formats # sub text2html { local($line); $line = @_[0]; $line =~ s/</g; $line =~ s/>/>/g; $line =~ s/"/"/g; return $line; }