File: doc2texi.pl

package info (click to toggle)
gnuplot 3.7.2-4
  • links: PTS
  • area: main
  • in suites: woody
  • size: 6,212 kB
  • ctags: 4,635
  • sloc: ansic: 43,538; cpp: 970; makefile: 883; lisp: 661; sh: 578; asm: 539; objc: 379; csh: 297; pascal: 192; perl: 138
file content (129 lines) | stat: -rw-r--r-- 3,098 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
#!/usr/local/bin/perl
#
# $Id: doc2texi.pl,v 1.1.1.1 1998/04/15 19:16:44 lhecking Exp $
#
# doc2texi.pl : Converts Gnuplot .doc files to Texinfo format.
#
# George Ferguson, ferguson@cs.rochester.edu, 11 Feb 1991.
#
# Usage:
#	% doc2texi.pl gnuplot.doc >gnuplot.texinfo
#	% makeinfo --fill-column 80 gnuplot.texinfo
# Creates files "gnuplot.info" and "gnuplot.info-[123]".
#

$currentBook = $currentChapter = $currentSection = $currentSubsection = 0;
$verbatim = $table = 0;

while (<>) {
    if (/^([1-4]) (.*)$/) {	# section heading
	$table = 0;
	&endVerbatim;
	$numNodes += 1;
	$nodeLevel[$numNodes] = $1;
	$nodeTitle[$numNodes] = $2;
	$nodeText[$numNodes] = "";
	if ($1 == 1) {
	    $currentBook = $numNodes;
	} elsif ($1 == 2) {
	    $currentChapter = $numNodes;
	    $nodeMenu[$currentBook] .= "* $2::\n";
	} elsif ($1 == 3) {
	    $currentSection = $numNodes;
	    if ($nodeTitle[$currentChapter] eq "set-show") {
		$nodeTitle[$numNodes] = "set $2";	# override
		$nodeMenu[$currentChapter] .= "* set $2::\n";
	    } else {
		$nodeMenu[$currentChapter] .= "* $2::\n";
	    }
	} elsif ($1 == 4) {
	    $currentSubsection = $numNodes;
	    $nodeMenu[$currentSection] .= "* $2::\n";
	}
    } elsif (/^\?(.*)$/) {				# index entry
	if ($1 ne "") {
	    $nodeText[$numNodes] .= "\@cindex $1\n";
	}
    } elsif (/^\@start table/) {				# start table
	&startVerbatim;
	$table = 1;
    } elsif (/^\@end table/) {				# end table
	$table = 0;
	&endVerbatim;
    } elsif (/^#/ || /^%/) {				# table entry
	next;
    } elsif (/^ ( ?)(.*)$/) {				# text
	if ($1 eq " ") {
	    &startVerbatim;
	} else {
	    &endVerbatim;
	}
	$text = $2;
	$text =~ s/@/@@/g;
	$text =~ s/{/\@{/g;
	$text =~ s/}/\@}/g;
 	$text =~ s/\`([^`]*)\`/\@code{$1}/g;
	$nodeText[$numNodes] .= "$text\n";
    } elsif (/^$/) {					# blank line
	&endVerbatim;
	$nodeText[$numNodes] .= "\n";
    }
}

# Print texinfo header
print "\\input texinfo\n";
print "\@setfilename gnuplot.info\n";
print "\@settitle Gnuplot: An Interactive Plotting Program\n";
print "\n";
print "\@node Top\n";
print "\@top Gnuplot";
print "\n";
print "$nodeText[1]";
print "\@menu\n";
print "$nodeMenu[1]";
print "* General Index::\n";
print "\@end menu\n";
print "\n";

# Now output all the nodes
for ($i=2; $i <= $numNodes; $i++) {
    print "\@node $nodeTitle[$i]\n";
    if ($nodeLevel[$i] == 2) {
	print "\@chapter $nodeTitle[$i]\n";
    } elsif ($nodeLevel[$i] == 3) {
	print "\@section $nodeTitle[$i]\n";
    } elsif ($nodeLevel[$i] == 4) {
	print "\@subsection $nodeTitle[$i]\n";
    }
    print "$nodeText[$i]";
    if ($nodeMenu[$i] ne "") {
	print "\@menu\n";
	print $nodeMenu[$i];
	print "\@end menu\n";
    }
    print "\n";
}
# Print texinfo trailer
print "\n";
print "\@node General Index\n";
print "\@appendix General Index\n";
print "\n";
print "\@printindex cp\n";
print "\n";
print "\@bye\n";

#######################

sub startVerbatim {
    if (!$verbatim) {
	$nodeText[$numNodes] .= "\@example\n";
	$verbatim = 1;
    }
}

sub endVerbatim {
    if ($verbatim && !$table) {
	$nodeText[$numNodes] .= "\@end example\n";
	$verbatim = 0;
    }
}