Debian Codegraph @

texmf-dist/doc/latex/register/reg_list.pl

raw
1 #!/usr/bin/env perl
2 ###############################################################################
3 #
4 # File: reg_list.pl
5 # RCS: $Header: /doc_tools/register/reg_list.pl 1.2 2004/08/16 23:37:07 lovell Exp $
6 # Description: Output a table (per function) of CSR's in offset order
7 # Author: Matthew Lovell
8 # Created: Mon Mar 31 16:50:05 2003
9 # Modified: Mon Aug 16 17:36:19 2004
10 # Language: CPerl
11 #
12 # (C) Copyright 2003, Matthew Lovell, all rights reserved.
13 #
14 ###############################################################################
15
16 use lib("$ENV{WJ_HOME}/docs/common",
17 "$ENV{WJ_HOME}/docs/common");
18
19 use Getopt::Long;
20 use FileHandle;
21 use Reg_macro;
22
23
24 # Parameters controlling execution
25 my $params =
26 {
27 file => "", # LaTeX file to parse
28 list => 0, # just list files
29 table => 0, # produce table files
30 Make => 0, # dependency extraction
31 };
32
33
34 $DEBUG = 0;
35
36 ###############################################################################
37 # M A I N #
38 ###############################################################################
39
40 # read options and get files from command-line
41 get_input_opts($params);
42 $REG_DEBUG = 1 if ($DEBUG);
43
44 my @files = get_tex_files($params->{file}, $params->{Make});
45
46 if ($DEBUG or $params->{list}) {
47 print "\nFile tree\n";
48 print "----------------------------\n";
49 print join("\n",@files) . "\n\n";
50 exit if ($params->{list});
51 }
52
53
54 #
55 # Just output Makefile dependencies and exit
56 #
57 if ($params->{Make}) {
58 print_depends_list($params->{file},
59 @files);
60 exit(0);
61 }
62
63
64 #
65 # ...otherwise, go on to extract some register information
66 #
67
68 my @reg_data = ();
69
70 for (@files) {
71 get_regs($_,\@reg_data)
72 }
73
74 my $reg_hash = build_reg_hash(\@reg_data);
75
76 if (!$params->{table}) {
77 print_reg_list($reg_hash);
78 } else {
79 make_reg_files($params->{file}, $reg_hash);
80 }
81
82
83 exit($REG_ERRORS);
84
85 ###############################################################################
86 # S U B R O U T I N E S #
87 ###############################################################################
88
89
90 # Print out file dependencies in a format suitable for use by
91 # GNU make. Makefile rules should be setup to update this
92 # information as necessary.
93 #
94 # Arguments: .tex filename
95 # array of dependencies
96 #
97 sub print_depends_list {
98 my ($file, @depends) = @_;
99
100 my @setup_files = qw[preamble.sty];
101
102 # separate all .error files
103 my @error_files = grep { $_ =~ /\.error$/ } @depends;
104
105 # separate all .func files
106 my @func_files = grep { $_ =~ /\.func$/ } @depends;
107
108 # ensure output is on STDOUT
109 select STDOUT;
110
111 my $aux_file, $dvi_file, $d_file, $ps_file;
112 ($aux_file = $file) =~ s/\.tex$/.aux/;
113 ($dvi_file = $file) =~ s/\.tex$/.dvi/;
114 ($ps_file = $file) =~ s/\.tex$/.ps/;
115 ($d_file = $file) =~ s/\.tex$/.d/;
116
117
118 print "#\n";
119 print "# Generated dependency file. Do NOT check into HMS !!\n";
120 print "#\n\n";
121
122 # Print out dependency list for the .aux file itself
123 print "$aux_file $dvi_file : \\\n";
124 map { print "\t$_ \\\n" } @setup_files;
125 map { print "\t$_ \\\n" } @error_files;
126 map { print "\t$_ \\\n" } @func_files;
127
128 foreach my $file (@depends) {
129 next if ($file =~ m/\.(?:error|func)$/);
130 next if ($file =~ m/logo\.eps/);
131 print "\t$file \\\n";
132 }
133 print "\n";
134
135
136 # Repeat for the .d file, leaving out unneeded files
137 print "$d_file : \\\n";
138
139 foreach my $file (@depends) {
140 next if ($file =~ m/\.(?:error|func)$/);
141 next if ($file =~ m/\.eps$/);
142 print "\t$file \\\n";
143 }
144 print "\n\n";
145
146
147 } # print_depends_list
148
149
150
151 # Print out register names in offset order to STDOUT. Used to
152 # ensure script is acting correctly.
153 #
154 # Arguments: reference to hash constructed by build_reg_hash
155 #
156 sub print_reg_list {
157 my ($reg_hash) = @_;
158
159 my @functions = keys %$reg_hash;
160
161 print "\n";
162 for my $func (sort @functions) {
163
164 print "Function $func Registers\n";
165 print "-" x 80 . "\n";
166
167 for my $offset (sort { hex($a) <=> hex($b) } keys %{$reg_hash->{$func}}) {
168 my $output = "";
169 if ($offset =~ /^unk/) {
170 $output = sprintf(" ? %-50s %-20s",
171 $reg_hash->{$func}{$offset}{long_name},
172 $reg_hash->{$func}{$offset}{short_name}
173 );
174 } else {
175 $output = sprintf("%03x %-50s %-20s",
176 hex($offset),
177 $reg_hash->{$func}{$offset}{long_name},
178 $reg_hash->{$func}{$offset}{short_name}
179 );
180 }
181
182 print "$output\n";
183 }
184
185 print "\n\n";
186 }
187
188 } # print_reg_list
189
190
191
192 # Output a LaTeX longtable listing registers in each function.
193 #
194 # Arguments: name of latex file parsed, used as the root for
195 # the table files names
196 #
197 # reference to hash created by build_reg_hash
198 #
199 sub make_reg_files {
200 my ($orig_file, $reg_hash) = @_;
201
202 my @functions = keys %$reg_hash;
203 for my $func (sort @functions) {
204
205 my $filename = $orig_file =~ s/\.tex$//;
206 $filename = $orig_file . ".func$func";
207
208 my $file = new FileHandle ">$filename";
209 if (!defined $file) {
210 print STDERR "#ERROR reg_list.pl Unable to open $filename for writing!";
211 die;
212 }
213
214 for my $offset (sort { hex($a) <=> hex($b) } keys %{$reg_hash->{$func}}) {
215
216 my $name = $reg_hash->{$func}{$offset}{long_name};
217 if (defined $reg_hash->{$func}{$offset}{short_name}) {
218 $name .= " ($reg_hash->{$func}{$offset}{short_name})";
219 }
220
221 my $pageref = "";
222 if (exists $reg_hash->{$func}{$offset}{label}) {
223 $pageref = '\pageref{' . $reg_hash->{$func}{$offset}{label} . '}';
224 }
225
226 if ($offset =~ /^unk/) {
227 printf $file "\\texttt{?} & %s & %s \\\\\n",
228 $name, $pageref;
229 } else {
230 printf $file "\\texttt{0x%03x} & %s & %s \\\\\n",
231 hex($offset), $name, $pageref;
232 }
233
234 }
235
236 close $file;
237
238 }
239
240
241 } # make_reg_files
242
243
244 # Retrieve the input parms passed to this script and set the proper
245 # options. Some global variables may be set by this subroutine.
246 #
247 # Arguments: reference to parameters hash
248 #
249 sub get_input_opts {
250 my ($params) = @_;
251 my $help = 0;
252
253 # Setup for GetOptions
254 $Getopt::Long::autoabbrev = 1;
255 $Getopt::Long::ignorecase = 0;
256 $Getopt::Long::order = $PERMUTE;
257
258 my @optl = ();
259 push(@optl,
260 "help", \$help, # show usage information
261 "debug", \$DEBUG, # show debug information
262 "file=s", \$params->{file}, # LaTeX file to parse
263
264 "list", \$params->{list},
265 "table", \$params->{table},
266 "Make", \$params->{Make},
267 );
268
269 GetOptions(@optl);
270
271 if ($help) {
272 print_usage_and_die();
273 }
274
275 if ($params->{file} eq "") {
276 print "Must specify a LaTeX file. Use --help for usage info.\n";
277 exit(1);
278 }
279
280
281 return;
282 } # get_input_opts
283
284
285 sub print_usage_and_die {
286 $usage = <<"@@USAGE_INFO";
287 Register (CSR) Lister
288
289 This script parses all register/CSR diagrams found in a LaTeX document.
290 The document can include or import sub-documents; the script will follow
291 the tree.
292
293 By default, a human-readable list of registers, ordered by offset
294 within each function, is printed to STDOUT. If the -table option is
295 given, files are written with a similar table formatted for inclusion
296 in a LaTeX document. The filenames will have the same root as the
297 file specified on the command-line, but with an extension of
298
299 .func<function>
300
301 for each non-empty function encountered during parsing.
302
303 Usage:
304
305 reg_list.pl -file <.tex file>
306 ( [-table] | [-list] | [-Make] )
307 [-debug] [-help]
308
309
310 <.tex file> LaTeX file to parse
311
312 Mutually exclusive
313 ------------------
314 -table Produce LaTeX table output, no STDOUT output
315 -list Show the file tree of <.tex file>, then quit
316 -Make Produce makefile dependencies for specified LaTeX file
317
318
319 Other options
320 -------------
321 -debug Show parsing debug information
322 -help Print this stuff
323
324
325 @@USAGE_INFO
326
327 print $usage;
328 exit(1);
329 } # print_usage_and_die