OpenCores
URL https://opencores.org/ocsvn/or1k/or1k/trunk

Subversion Repositories or1k

[/] [or1k/] [trunk/] [rtems-20020807/] [doc/] [tools/] [texi2www/] [texi2dvi] - Blame information for rev 1771

Go to most recent revision | Details | Compare with Previous | View Log

Line No. Rev Author Line
1 1026 ivang
#!/usr/bin/perl
2
#
3
#  texi2dvi,v 1.5 2002/01/17 21:47:47 joel Exp
4
#
5
 
6
$version = <
7
Jan 2 1996
8
END_VERSION
9
 
10
$copyright = <
11
texi2dvi - converts texinfo to dvi
12
Copyright (C) 1996 Tim Singletary
13
 
14
This program is freely distributable under the terms of the GNU
15
GENERAL PUBLIC LICENSE.  In particular, modified versions of this
16
program must retain this copyright notice and must remain freely
17
distributable.
18
END_COPYRIGHT
19
 
20
$usage = <
21
Usage: texi2dvi [option ...] texinfo_file ...
22
  -k (-nocleanup) -- don't ``rm -f'' the intermediate files.
23
  -v (-verbose) -- print additional output.
24
  -copyright -- print the copyright and die.
25
  -version -- print the version and die.
26
Generates a .dvi file from each texinfo (.texi or .texinfo) file.
27
Understands texi2www extensions (\@gif, etc.).
28
END_USAGE
29
 
30
unless ($tex = $ENV{TEX}) {$tex = tex;}
31
unless ($texindex = $ENV{TEXINDEX}) {$texindex = texindex;}
32
$texinputs = $ENV{TEXINPUTS};
33
 
34
$cleanup = 1;
35
while ($ARGV[0] =~ /^-/) {
36
    $_ = shift;
37
    if (/-k$/ || /-nocleanup/) {$cleanup = 0; next;}
38
    if (/-v$/ || /-verbose/) {$verbose = 1; next;}
39
    if (/-d$/ || /-vv$/ || /-debug/)   {$verbose = 2; next;}
40
    if (/-copyright/) {die $copyright;}
41
    if (/-version/) {die $version;}
42
    die $usage;
43
}
44
 
45
$font_prefix = "xx";
46
while (&prefix_in_use($font_prefix)) {
47
    ++$font_prefix;
48
    if (length($font_prefix) > 2) {
49
        $font_prefix = "aa";
50
    }
51
}
52
 
53
$unique_base = "_" . $$ . "a-";
54
while (&prefix_in_use($unique_base)) {++$unique_base;}
55
 
56
print "Generated files will begin with \`$unique_base\'\n" if $verbose;
57
 
58
$arg_index = 'a';
59
foreach $raw_texi (@ARGV) {
60
    $base = $unique_base . $arg_index;
61
    ++$arg_index;
62
 
63
    # $tawtexifile is a texinfo file; suffix must be either `.texi' or
64
    # `.texinfo'.  If arg is in a different directory, adjust
65
    # TEXINPUTS environment variable to include that (and the current)
66
    # directory.
67
    unless ($raw_texi =~ /(.*).texi(nfo)?$/) {
68
        print "skipping $raw_texi -- has unknown extension!\n";
69
        next;
70
    }
71
    $raw_texi_base = $1;
72
    if ($raw_texi_base =~ m|^(.*)/([^/]*)$|) {
73
        $raw_texi_base = $2;
74
        $ENV{TEXINPUTS} = ".:$1:$texinputs";
75
    } else {
76
        $ENV{TEXINPUTS} = ".:$texinputs";
77
    }
78
 
79
    unless (-r $raw_texi) {
80
        print "skipping $raw_texi -- not readable or doesn't exist!\n";
81
        next;
82
    }
83
 
84
    # Preprocesses the $rawtexifile (because of @gif{} and other extensions)
85
    $processed_texi = "$base.texi";
86
    print "Preprocessing $raw_texi into $processed_texi:\n" if $verbose;
87
    &preprocess_texinfo($raw_texi,$processed_texi,$base);
88
 
89
    print "$tex $processed_texi\n" if $verbose;
90
    if (system("$tex $processed_texi") == 0) {
91
 
92
        # @possible_index_file = <$base.??>; only works for the
93
        # first value of $base ... so,
94
        opendir(DIR,".") || die "Couldn't read current directory -- $!\n";
95
        @possible_index_files = ();
96
        while ($_ = readdir(DIR)) {
97
            if (/^$base\...$/) {
98
              push(@possible_index_files,$_);
99
            }
100
        }
101
        closedir(DIR);
102
 
103
        @index_files = ();
104
        foreach $possible_index_file (@possible_index_files) {
105
            print "DEBUG: possible_index_file $possible_index_file\n"
106
                                                           if ($verbose > 1);
107
            next unless (-s $possible_index_file);
108
            push(@index_files,$possible_index_file);
109
        }
110
 
111
        if (@index_files > 0) {
112
            $texindex_cmd =  "$texindex " . join(' ',@index_files);
113
            print "$texindex_cmd\n" if $verbose;
114
            if (system($texindex_cmd) == 0) {
115
                print "$tex $processed_texi\n" if $verbose;
116
                system("$tex $processed_texi");
117
            }
118
        }
119
    }
120
 
121
    # At this point, $base.dvi should exist -- rename it
122
    # to $raw_texi_base.dvi
123
    if (-e "$base.dvi") {
124
        rename("$base.dvi","$raw_texi_base.dvi")
125
            || die "rename $base.dvi $raw_texi_base.dvi -- $!\n";
126
    }
127
}
128
if ($cleanup) {unlink(<$base*>);}
129
 
130
sub preprocess_texinfo
131
{
132
    local ($infile,$outfile,$b) = @_;
133
 
134
    open(IN,"<$infile") || die "Couldn't open $infile -- $!\n";
135
    open(OUT,">$outfile") || die "Couldn't open $outfile -- $!\n";
136
 
137
    $gif_index = 'a';
138
    while () {
139
 
140
        # @gif{gif} or @gif{html_gif, tex_gif}
141
        if (/(.*)\@gif\{([^{]*)\}(.*)/) {
142
            $prefix = $1;
143
            $arg = $2;
144
            $suffix = $3;
145
            print OUT "$prefix\n" if $prefix;
146
 
147
            while (1) {
148
                $gif_base = $b . $gif_index;
149
                last unless (-e $gif_base . ".gif");
150
                ++$gif_index;
151
            }
152
 
153
            $gif_file = '';
154
            if ($arg =~ /.*,(..*\.gif)/) {
155
                $gif_file = $1;
156
                $font_base = $gif_file;
157
            } else {
158
                $font_base = $arg;
159
                $gif_file = $gif_base . ".gif";
160
                print "Scaling $arg into $gif_file:\n" if $verbose;
161
                $scale_cmd = "giftopnm $arg | pnmscale 2 | pnmnlfilt 2 1 "
162
                    . "| ppmquant 255 | ppmtogif > $gif_file";
163
                print "$scale_cmd\n" if $verbose;
164
                if (system($scale_cmd) != 0) {
165
                    print "$scale_cmd failed\n";
166
                    $gif_file = '';
167
                }
168
            }
169
 
170
            if ($gif_file =~ /.*\.gif/) {
171
 
172
 
173
                $font_base =~ s|.*/||;
174
                $font_base =~ s|\..*||;
175
 
176
                # $font_base, due to bm2font requirements, can't be more
177
                # than six characters long and must consist entirely of
178
                # lower case letters.
179
                $font_base =~ s/[^a-z]//g;
180
                $font_base = $font_prefix . substr($font_base,0,5);
181
                while (&prefix_in_use($font_base)) {++$font_base;}
182
 
183
                $bm2font_cmd = "bm2font -f$font_base $gif_file";
184
                print "$bm2font_cmd\n" if $verbose;
185
                if (system($bm2font_cmd) != 0) {
186
                    print "$bm2font_cmd failed\n";
187
                } else {
188
                    print OUT "\@tex\n";
189
                    print OUT "\\input $font_base.tex\n";
190
                    print OUT "\\set$font_base\n";
191
                    print OUT "\@end tex\n";
192
                }
193
            }
194
 
195
            print OUT "$suffix \n" if $suffix;
196
        } else {
197
            print OUT "$_";
198
        }
199
    }
200
    close OUT;
201
    close IN;
202
}
203
 
204
sub prefix_in_use
205
{
206
    local ($p) = @_;
207
 
208
    # Returns true or false; returns true if any file in the current
209
    # directory begins with $p.  This function is here because
210
    # `<$p*>' only works for the first value of $p!
211
 
212
    opendir(DIR,".") || die "Couldn't read current directory -- $!\n";
213
    while ($_ = readdir(DIR)) {
214
        last if /^$p/;
215
    }
216
    closedir(DIR);
217
    $rc = /^$p/;
218
}

powered by: WebSVN 2.1.0

© copyright 1999-2025 OpenCores.org, equivalent to Oliscience, all rights reserved. OpenCores®, registered trademark.