4 # uncomment the following to run from named file
5 #$test_data = "sample.txt";
7 $faq_url = "http://www.freeciv.org/wiki/FAQ";
19 open(FILE
, ">$faq_file") || die ("Cannot open file $faq_file for writing.\n");
24 # read data and write toc
31 print "File $faq_file has been written successfully\n";
33 # collect table of contents
38 if ( &clearTo
("FAQ") || &clearTo
("Contents") ) { die "No TOC found\n"; }
44 Freeciv Frequently Asked Questions (FAQ)
54 &readLine
|| die "Data runout reading TOC\n";
55 if ( $line =~ /^\s*$/ )
60 if ( $line =~ /^\s*(.) ([\.\d]+) (.+)$/ )
62 #handle section or question
66 my $pattern = " \\$type";
67 $line =~ s/$pattern//;
70 push( @sections, $name );
72 if ( $l != $num ) { die "Section $l number is $num\n"; }
73 push( @sectStrings, [] );
77 my $ref = $sectStrings[-1];
90 &readLine
|| return 1;
91 if ( $line =~ /^\s*$_[0]$/ ) { last; }
96 # get line, required blank
99 if ( ! &readLine
) { die "Data runout in processBlankLine\n"; }
100 if ( $line!~/^\s*$/ ) { die "processBlankLine read '$line'\n"; }
103 # write answer section
110 my $type = &readGraph
;
111 # handle section or question
114 print FILE
"-------\n\n";
115 if ( $graph[0] eq $sections[$ix] )
117 $sName = $sections[$ix];
118 my $nr = $sectStrings[$ix];
125 my $num = shift( @nums );
136 # read paragraph, return type
138 # 1: other (part of answer)
139 # 2: section or question
142 &readLine
|| die "Data runout in readGraph\n";
143 if ( $line eq "" ) { die "Expecting graph, read blank line\n"; }
145 if ( $line =~ /^\s*^_+$/ ) { return 0; }
149 &readLine
|| die "Data runout in readGraph\n";
150 if ( $line eq "" ) { last; }
151 if ( $line !~ /^\s*_+$/ )
153 push( @graph, $line );
162 if ( &editTag
) { return 2; }
166 # test for and remove edit tag
169 # look for on last line
170 if ( $graph[-1] =~ s/ \[[^]]*\] Edit$// ) { return 1; }
171 if ( 2 > @graph ) { return 0; }
172 if ( $graph[-1] =~ m/^\[[^]]*\] Edit$/ )
178 if ( $graph[-1]eq"Edit" && $graph[-2]=~s/ \[[^]]*\]$// )
189 if ( defined $_[0] ) { print FILE
"$_[0] "; }
192 my $data = shift( @graph );
193 print FILE
"$data\n";
205 print "using test data $test_data\n";
206 open ( MYDATA
, $test_data );
210 print "using url $faq_url\n";
211 @content = `lynx -nolist -dump "$faq_url"`;
213 my $count = @content;
214 print( "$count lines of content\n" );
220 if ( $contentLine < @content )
222 $line = $content[$contentLine++];