1 |
#! /usr/bin/env perl |
2 |
# |
3 |
# $Id: protex,v 1.5 2004/04/01 05:00:06 edhill Exp $ |
4 |
# |
5 |
#BOP |
6 |
# |
7 |
# !ROUTINE: ProTeX v. 2.00 - Translates DAO Prologues to LaTeX |
8 |
# |
9 |
# !INTERFACE: |
10 |
# protex [-hbACFS7] ] [+-nlsxf] [src_file(s)] |
11 |
# |
12 |
# !DESCRIPTION: |
13 |
# Perl filter to produce a \LaTeX compatible document |
14 |
# from a DAO Fortran source code with standard Pro\TeX |
15 |
# prologues. If source files are not specified it |
16 |
# reads from stdin; output is always to stdout. |
17 |
# |
18 |
# \noindent |
19 |
# {\bf Command Line Switches:} \vspace{0.2cm} |
20 |
# |
21 |
# \begin{center} |
22 |
# \begin{tabular}{|c|l|} \hline \hline |
23 |
# -h & Help mode: list command line options \\ \hline |
24 |
# -b & Bare mode, meaning no preamble, etc. \\ \hline |
25 |
# -i & internal mode: omit prologues marked !BOPI \\ \hline |
26 |
# +/-n & New Page for each subsection (wastes paper) \\ \hline |
27 |
# +/-l & Listing mode, default is prologues only \\ \hline |
28 |
# +/-s & Shut-up mode, i.e., ignore any code from BOC to EOC \\ \hline |
29 |
# +/-x & No LaTeX mode, i.e., put !DESCRIPTION: in verbatim mode \\ \hline |
30 |
# +/-f & No source file info \\ \hline |
31 |
# -A & Ada code \\ \hline |
32 |
# -C & C++ code \\ \hline |
33 |
# -F & F90 code (default) \\ \hline |
34 |
# -7 & F77 code \\ \hline |
35 |
# -S & Shell script \\ \hline \hline |
36 |
# -v & Verbosity level (default=99) \\ \hline \hline |
37 |
# \end{tabular} |
38 |
# \end{center} |
39 |
# |
40 |
# The options can appear in any order. The options, -h and -b, affect |
41 |
# the input from all files listed on command-line input. Each of the |
42 |
# remaining options effects only the input from the files listed after |
43 |
# the option and prior to any overriding option. The plus sign |
44 |
# turns off the option. For example, the command-line input, |
45 |
# \bv |
46 |
# protex -bnS File1 -F File2.f +n File3.f |
47 |
# \ev |
48 |
# will cause the option, {\tt -n} to affect the input from the files, |
49 |
# {\tt File} and {\tt File2.f}, but not from {\tt File3.f}. The |
50 |
# {\tt -S} option is implemented for {\tt File1} but is overridden by |
51 |
# the {\tt -F} for files {\tt File2.f} and {\tt File3.f}. |
52 |
# |
53 |
# |
54 |
# !SEE ALSO: |
55 |
# For a more detailed description of ProTeX functionality, |
56 |
# DAO Prologue and other conventions, consult: |
57 |
# |
58 |
# Sawyer, W., and A. da Silva, 1997: ProTeX: A Sample |
59 |
# Fortran 90 Source Code Documentation System. |
60 |
# DAO Office Note 97-11 |
61 |
# |
62 |
# |
63 |
# !REVISION HISTORY: |
64 |
# |
65 |
# 20Dec1995 da Silva First experimental version |
66 |
# 10Nov1996 da Silva First internal release (v1.01) |
67 |
# 28Jun1997 da Silva Modified so that !DESCRIPTION can appear after |
68 |
# !INTERFACE, and !INPUT PARAMETERS etc. changed to italics. |
69 |
# 02Jul1997 Sawyer Added shut-up mode |
70 |
# 20Oct1997 Sawyer Added support for shell scripts |
71 |
# 11Mar1998 Sawyer Added: file name, date in header, C, script support |
72 |
# 05Aug1998 Sawyer Fixed LPChang-bug-support-for-files-with-underscores |
73 |
# 10Oct1998 da Silva Introduced -f option for removing source file info |
74 |
# from subsection, etc. Added help (WS). |
75 |
# 06Dec1999 C. Redder Added LaTeX command "\label{sec:prologues}" just |
76 |
# after the beginning of the proglogue section. |
77 |
# 13Dec1999 C. Redder Increased flexbility in command-line |
78 |
# interface. The options can appear in any |
79 |
# order which will allow the user to implement |
80 |
# options for select files. |
81 |
# 01Feb1999 C. Redder Added \usepackage commands to preamble of latex |
82 |
# document to include the packages amsmath, epsfig |
83 |
# and hangcaption. |
84 |
# 10May2000 C. Redder Revised LaTeX command "\label{sec:prologues}" |
85 |
# to "\label{app:ProLogues}" |
86 |
# 10/10/2002 da Silva Introduced ARGUMENTS keyword, touch ups. |
87 |
# |
88 |
# 15Jan2003 R. Staufer Modified table of contents to print only section headers - no descriptions |
89 |
# |
90 |
# 25Feb2003 R. Staufer Added BOPI/EOPI and -i (internal) switch to provide the option of omitting prologue information from output files. |
91 |
# |
92 |
#EOP |
93 |
#---------------------------------------------------------------------------- |
94 |
|
95 |
# Keep this if you don't know what it does... |
96 |
# ------------------------------------------- |
97 |
$[ = 1; # set array base to 1 |
98 |
$, = ' '; # set output field separator |
99 |
$\ = "\n"; # set output record separator |
100 |
|
101 |
# Set valid options lists |
102 |
# ----------------------- |
103 |
$GlobOptions = 'hbv'; # Global options (i.e for all files) |
104 |
$LangOptions = 'ACFS7'; # Options for setting programming languages |
105 |
$SwOptions = 'flinsx'; # Options that can change for each input file |
106 |
$RegOptions = "$GlobOptions$LangOptions"; |
107 |
# Scan for global options until first first |
108 |
# file is processed. |
109 |
|
110 |
# Scan for global options |
111 |
# ----------------------- |
112 |
$NFiles = 0; |
113 |
Arg: foreach $arg (@ARGV) { |
114 |
$option = &CheckOpts ( $arg, $RegOptions, $SwOptions ) + 1; |
115 |
if ( $option ) { |
116 |
$rc = &GetOpts ( $arg, $GlobOptions ); |
117 |
next Arg; |
118 |
} |
119 |
else { |
120 |
$NFiles++; |
121 |
} |
122 |
} |
123 |
|
124 |
# If all input arguments are options, then assume the |
125 |
# filename, "-", for the standard input |
126 |
# -------------------------------------------------- |
127 |
if ( $NFiles == 0 ) { push (@ARGV, "-"); } |
128 |
|
129 |
# Implement help option |
130 |
# --------------------- |
131 |
if ( $opt_h ) { |
132 |
&print_help(); |
133 |
exit(); |
134 |
} |
135 |
|
136 |
# Optional Prologue Keywords |
137 |
# -------------------------- |
138 |
@keys = ( "!INTERFACE:", |
139 |
"!USES:", |
140 |
"!PUBLIC TYPES:", |
141 |
"!PRIVATE TYPES:", |
142 |
"!PUBLIC MEMBER FUNCTIONS:", |
143 |
"!PRIVATE MEMBER FUNCTIONS:", |
144 |
"!PUBLIC DATA MEMBERS:", |
145 |
"!PARAMETERS:", |
146 |
"!ARGUMENTS:", |
147 |
"!DEFINED PARAMETERS:", |
148 |
"!INPUT PARAMETERS:", |
149 |
"!INPUT/OUTPUT PARAMETERS:", |
150 |
"!OUTPUT PARAMETERS:", |
151 |
"!RETURN VALUE:", |
152 |
"!REVISION HISTORY:", |
153 |
"!BUGS:", |
154 |
"!SEE ALSO:", |
155 |
"!SYSTEM ROUTINES:", |
156 |
"!FILES USED:", |
157 |
"!REMARKS:", |
158 |
"!TO DO:", |
159 |
"!CALLING SEQUENCE:", |
160 |
"!AUTHOR:", |
161 |
"!CALLED FROM:", |
162 |
"!LOCAL VARIABLES:" ); |
163 |
|
164 |
# Initialize these for clarity |
165 |
# ---------------------------- |
166 |
$intro = 0; # doing introduction? |
167 |
$prologue = 0; # doing prologue? |
168 |
$first = 1; # first prologue? |
169 |
$source = 0; # source code mode? |
170 |
$verb = 0; # verbatim mode? |
171 |
$tpage = 0; # title page? |
172 |
$begdoc = 0; # has \begin{document} been written? |
173 |
|
174 |
# Initial LaTeX stuff |
175 |
# ------------------- |
176 |
&print_notice(); |
177 |
&print_preamble(); # \documentclass, text dimensions, etc. |
178 |
&print_macros(); # short-hand LaTeX macros |
179 |
|
180 |
# Main loop -- for each command-line argument |
181 |
# ------------------------------------------- |
182 |
ARG: foreach $arg (@ARGV) { |
183 |
|
184 |
# Scan for non-global command-line options |
185 |
$option = &CheckOpts ( $arg, $RegOptions, $SwOptions, "quiet" ) + 1; |
186 |
if ( $option ) { |
187 |
&GetOpts ( $arg, $SwOptions ); |
188 |
&SetOpt ( $arg, $LangOptions ); |
189 |
next ARG; |
190 |
} |
191 |
|
192 |
# Determine the type of code, set corresponding search strings |
193 |
$comment_string = '!'; # DEFAULT is FORTRAN |
194 |
$boi_string = '!BOI'; |
195 |
$eoi_string = '!EOI'; |
196 |
$bop_string = '!BOP'; |
197 |
$eop_string = '!EOP'; |
198 |
$bopi_string = '!BOPI'; |
199 |
$eopi_string = '!EOPI'; |
200 |
$boc_string = '!BOC'; |
201 |
$eoc_string = '!EOC'; |
202 |
|
203 |
if ( $opt_7 ) { # f77 |
204 |
$comment_string = 'C'; |
205 |
$boi_string = 'CBOI'; |
206 |
$eoi_string = 'CEOI'; |
207 |
$bop_string = 'CBOP'; |
208 |
$eop_string = 'CEOP'; |
209 |
$bopi_string = 'CBOPI'; |
210 |
$eopi_string = 'CEOPI'; |
211 |
$boc_string = 'CBOC'; |
212 |
$eoc_string = 'CEOC'; |
213 |
} |
214 |
|
215 |
if ( $opt_A ) { # ADA |
216 |
$comment_string = '--'; |
217 |
$boi_string = '--BOI'; |
218 |
$eoi_string = '--EOI'; |
219 |
$bop_string = '--BOP'; |
220 |
$eop_string = '--EOP'; |
221 |
$bopi_string = '--BOPI'; |
222 |
$eopi_string = '--EOPI'; |
223 |
$boc_string = '--BOC'; |
224 |
$eoc_string = '--EOC'; |
225 |
} |
226 |
|
227 |
if ( $opt_C ) { |
228 |
$comment_string = '//'; # C |
229 |
$boi_string = '//BOI'; |
230 |
$eoi_string = '//EOI'; |
231 |
$bop_string = '//BOP'; |
232 |
$eop_string = '//EOP'; |
233 |
$bopi_string = '//BOPI'; |
234 |
$eopi_string = '//EOPI'; |
235 |
$boc_string = '//BOC'; |
236 |
$eoc_string = '//EOC'; |
237 |
} |
238 |
|
239 |
if ( $opt_S ) { # Script |
240 |
$comment_string = '#'; |
241 |
$boi_string = '#BOI'; |
242 |
$eoi_string = '#EOI'; |
243 |
$bop_string = '#BOP'; |
244 |
$eop_string = '#EOP'; |
245 |
$bopi_string = '#BOPI'; |
246 |
$eopi_string = '#EOPI'; |
247 |
$boc_string = '#BOC'; |
248 |
$eoc_string = '#EOC'; |
249 |
} |
250 |
|
251 |
# Set file name parameters |
252 |
$InputFile = $arg; |
253 |
@all_path_components = split( /\//, $InputFile ); |
254 |
$FileBaseName = pop ( @all_path_components ); |
255 |
$FileBaseName =~ s/_/\\_/g; |
256 |
if ( $InputFile eq "-" ) {$FileBaseName = "Standard Input";} |
257 |
|
258 |
# Set date |
259 |
$Date = `date`; |
260 |
|
261 |
# Open current file |
262 |
open ( InputFile, "$InputFile" ) |
263 |
or print STDERR "Unable to open $InputFile: $!"; |
264 |
|
265 |
# Print page header |
266 |
chomp($Date); |
267 |
# printf "\n\\markboth{Left}{Source File: %s, Date: %s}\n\n", |
268 |
printf "\n\\markboth{Source File: %s}{Date: %s}\n\n", |
269 |
$FileBaseName, $Date; |
270 |
|
271 |
# Inner loop --- for processing each line of the input file |
272 |
LINE: while ( <InputFile> ) { |
273 |
chop; # strip record separator |
274 |
|
275 |
@Fld = split(' ', $_, 9999); |
276 |
|
277 |
# Straight quote |
278 |
if ($Fld[1] eq '!QUOTE:') { |
279 |
for ($i = 2; $i <= $#Fld; $i++) { |
280 |
printf '%s ', $Fld[$i]; |
281 |
} |
282 |
print " "; |
283 |
next LINE; |
284 |
} |
285 |
|
286 |
# Handle optional Title Page and Introduction |
287 |
if ($Fld[1] eq $boi_string) { |
288 |
print ' '; |
289 |
$intro = 1; |
290 |
next LINE; |
291 |
} |
292 |
|
293 |
if ($Fld[2] eq '!TITLE:') { |
294 |
if ( $intro ) { |
295 |
shift @Fld; |
296 |
shift @Fld; |
297 |
@title = @Fld; |
298 |
$tpage = 1; |
299 |
next LINE; |
300 |
} |
301 |
} |
302 |
|
303 |
if ($Fld[2] eq '!AUTHORS:') { |
304 |
if ( $intro ) { |
305 |
shift @Fld; |
306 |
shift @Fld; |
307 |
@author = @Fld; |
308 |
$tpage = 1; |
309 |
next LINE; |
310 |
} |
311 |
} |
312 |
|
313 |
if ($Fld[2] eq '!AFFILIATION:') { |
314 |
if ( $intro ) { |
315 |
shift @Fld; |
316 |
shift @Fld; |
317 |
@affiliation = @Fld; |
318 |
$tpage = 1; |
319 |
next LINE; |
320 |
} |
321 |
} |
322 |
|
323 |
if ($Fld[2] eq '!DATE:') { |
324 |
if ( $intro ) { |
325 |
shift @Fld; |
326 |
shift @Fld; |
327 |
@date = @Fld; |
328 |
$tpage = 1; |
329 |
next LINE; |
330 |
} |
331 |
} |
332 |
|
333 |
if ($Fld[2] eq '!INTRODUCTION:') { |
334 |
if ( $intro ) { |
335 |
&do_beg(); |
336 |
print ' '; |
337 |
print '%..............................................'; |
338 |
shift @Fld; |
339 |
shift @Fld; |
340 |
print "\\section{@Fld}"; |
341 |
next LINE; |
342 |
} |
343 |
} |
344 |
|
345 |
|
346 |
# End of introduction |
347 |
if ($Fld[1] eq $eoi_string) { |
348 |
print ' '; |
349 |
print '%/////////////////////////////////////////////////////////////'; |
350 |
print "\\newpage"; |
351 |
$intro = 0; |
352 |
next LINE; |
353 |
} |
354 |
|
355 |
# Beginning of prologue |
356 |
if ( ($Fld[1] eq $bop_string) |
357 |
&& (($Fld[2] eq "") || ($Fld[2] <= $opt_v)) ) { |
358 |
if ( $source ) { &do_eoc(); } |
359 |
print ' '; |
360 |
print '%/////////////////////////////////////////////////////////////'; |
361 |
&do_beg(); |
362 |
$first = 0; |
363 |
if ($first == 0) { |
364 |
print " "; |
365 |
print "\\mbox{}\\hrulefill\\ "; |
366 |
print " ";} |
367 |
else { |
368 |
unless($opt_b){ |
369 |
print |
370 |
"\\section{Routine/Function Prologues} \\label{app:ProLogues}"; |
371 |
} |
372 |
} |
373 |
$first = 0; |
374 |
$prologue = 1; |
375 |
$verb = 0; |
376 |
$source = 0; |
377 |
&set_missing(); # no required keyword yet |
378 |
next LINE; |
379 |
} |
380 |
|
381 |
# Beginning of internal prologue |
382 |
if ( ($Fld[1] eq $bopi_string)) { |
383 |
if ($opt_i) {$prologue = 0;} |
384 |
else { |
385 |
if ($source) { &do_eoc(); } |
386 |
print ' '; |
387 |
print '%/////////////////////////////////////////////////////////////'; |
388 |
&do_beg(); |
389 |
if ($first ==0) { |
390 |
### print "\\newpage"; |
391 |
print " "; |
392 |
print "\\mbox{}\\hrulefill\\"; |
393 |
print " ";} |
394 |
else { |
395 |
unless($opt_b) { |
396 |
print |
397 |
"\\section{Routine/Function Prologues} \\label{app:ProLogues}"; |
398 |
} |
399 |
} |
400 |
$first = 0; |
401 |
$prologue = 1; |
402 |
$verb = 0; |
403 |
$source = 0; |
404 |
&set_missing(); # no required keyword yet |
405 |
next LINE; |
406 |
} |
407 |
} |
408 |
|
409 |
# A new subroutine/function |
410 |
if ($Fld[2] eq '!ROUTINE:' ) { |
411 |
if ($prologue) { |
412 |
shift @Fld; |
413 |
shift @Fld; |
414 |
$_ = join(' ', @Fld); |
415 |
$name_is = $_; |
416 |
s/_/\\_/g; |
417 |
# Replace "_" with "\_" |
418 |
if ( $opt_n && $not_first ) { |
419 |
printf "\\newpage\n"; |
420 |
} |
421 |
unless ($opt_f) { |
422 |
printf "\\subsection{%s (File: %s)}\n\n", $_, $FileBaseName; |
423 |
} |
424 |
else { |
425 |
printf "\\subsection{%s}\n\n", $_; |
426 |
printf "\n{\\sf FILE:} %s\n\\medskip\n", $FileBaseName; |
427 |
} |
428 |
$have_name = 1; |
429 |
$not_first = 1; |
430 |
next LINE; |
431 |
} |
432 |
} |
433 |
|
434 |
# A new Module |
435 |
if ($Fld[2] eq '!MODULE:' ) { |
436 |
if ($prologue) { |
437 |
shift @Fld; |
438 |
shift @Fld; |
439 |
$_ = join(' ', @Fld); |
440 |
$name_is = $_; |
441 |
s/_/\\_/g; # Replace "_" with "\_" |
442 |
if ( $opt_n && $not_first ) { printf "\\newpage\n"; } |
443 |
unless($opt_f) { |
444 |
printf |
445 |
"\\subsection{Fortran: Module Interface %s (File: %s)}\n\n", |
446 |
$_, $FileBaseName; |
447 |
} |
448 |
else { |
449 |
printf "\\subsection{Fortran: Module Interface %s }\n\n", $_; |
450 |
} |
451 |
$have_name = 1; |
452 |
$have_intf = 1; # fake it, it does not need one. |
453 |
$not_first = 1; |
454 |
next LINE; |
455 |
} |
456 |
} |
457 |
|
458 |
# A new include file |
459 |
if ($Fld[2] eq '!INCLUDE:' ) { |
460 |
if ($prologue) { |
461 |
shift @Fld; |
462 |
shift @Fld; |
463 |
$_ = join(' ', @Fld); |
464 |
$name_is = $_; |
465 |
s/_/\\_/g; # Replace "_" with "\_" |
466 |
if ( $opt_n && $not_first ) { |
467 |
printf "\\newpage\n"; |
468 |
} |
469 |
unless($opt_f) { |
470 |
printf |
471 |
"\\subsubsection{Include File %s (File: %s)}\n\n", |
472 |
$_, $FileBaseName;} |
473 |
else { |
474 |
printf "\\subsubsection{Include File %s }\n\n", $_; |
475 |
} |
476 |
$have_name = 1; |
477 |
$have_intf = 1; # fake it, it does not need one. |
478 |
$not_first = 1; |
479 |
next LINE; |
480 |
} |
481 |
} |
482 |
|
483 |
# A new INTERNAL subroutine/function |
484 |
if ($Fld[2] eq '!IROUTINE:') { # Internal routine |
485 |
if ($prologue) { |
486 |
shift @Fld; |
487 |
shift @Fld; |
488 |
$_ = join(' ', @Fld); |
489 |
$name_is = $_; |
490 |
s/_/\\_/g; # Replace "_" with "\_" |
491 |
@words = split " ", $_; |
492 |
printf "\\subsubsection [$words[1]] {$_}\n\n"; |
493 |
$have_name = 1; |
494 |
next LINE; |
495 |
} |
496 |
} |
497 |
|
498 |
# A new CLASS |
499 |
if ($Fld[2] eq '!CLASS:' ) { |
500 |
if ($prologue) { |
501 |
shift @Fld; |
502 |
shift @Fld; |
503 |
$_ = join(' ', @Fld); |
504 |
$name_is = $_; |
505 |
s/_/\\_/g; # Replace "_" with "\_" |
506 |
if ( $opt_n && $not_first ) { printf "\\newpage\n"; } |
507 |
unless($opt_f) { |
508 |
printf |
509 |
"\\subsection{C++: Class Interface %s (File: %s)}\n\n", |
510 |
$_, $FileBaseName;} |
511 |
else { |
512 |
printf "\\subsection{C++: Class Interface %s }\n\n", $_; |
513 |
} |
514 |
$have_name = 1; |
515 |
$have_intf = 1; # fake it, it does not need one. |
516 |
$not_first = 1; |
517 |
next LINE; |
518 |
} |
519 |
} |
520 |
|
521 |
# A new Method |
522 |
if ($Fld[2] eq '!METHOD:' ) { |
523 |
if ($prologue) { |
524 |
shift @Fld; |
525 |
shift @Fld; |
526 |
$_ = join(' ', @Fld); |
527 |
$name_is = $_; |
528 |
s/_/\\_/g; # Replace "_" with "\_" |
529 |
if ( $opt_n && $not_first ) { printf "\\newpage\n"; } |
530 |
unless ($opt_f) { |
531 |
printf "\\subsubsection{%s (File: %s)}\n\n", $_, $FileBaseName; |
532 |
} |
533 |
else { |
534 |
printf "\\subsubsection{%s }\n\n", $_; |
535 |
} |
536 |
$have_name = 1; |
537 |
$not_first = 1; |
538 |
next LINE; |
539 |
} |
540 |
} |
541 |
|
542 |
# A new function |
543 |
if ($Fld[2] eq '!FUNCTION:' ) { |
544 |
if ($prologue) { |
545 |
shift @Fld; |
546 |
shift @Fld; |
547 |
$_ = join(' ', @Fld); |
548 |
$name_is = $_; |
549 |
s/_/\\_/g; # Replace "_" with "\_" |
550 |
if ( $opt_n && $not_first ) { |
551 |
printf "\\newpage\n"; |
552 |
} |
553 |
unless ($opt_f) { |
554 |
printf |
555 |
"\\subsubsection{%s (File: %s)}\n\n", |
556 |
$_, $FileBaseName; |
557 |
} |
558 |
else { |
559 |
printf "\\subsubsection{%s }\n\n", $_; |
560 |
} |
561 |
$have_name = 1; |
562 |
$not_first = 1; |
563 |
next LINE; |
564 |
} |
565 |
} |
566 |
|
567 |
# Description: what follows will be regular LaTeX (no verbatim) |
568 |
if (/!DESCRIPTION:/) { |
569 |
if ($prologue) { |
570 |
if ($verb) { |
571 |
&end_verbatim(); |
572 |
printf "\n{\\sf DESCRIPTION: }\n\\medskip\n"; |
573 |
} |
574 |
else { # probably never occurs |
575 |
} |
576 |
if ($opt_x) { |
577 |
&begin_verbatim(); |
578 |
$first_verb = 1; |
579 |
} |
580 |
else { |
581 |
for ($i = 3; $i <= $#Fld; $i++) { |
582 |
printf '%s ', $Fld[$i]; |
583 |
} |
584 |
} |
585 |
### print " "; |
586 |
$have_desc = 1; |
587 |
next LINE; |
588 |
} |
589 |
} |
590 |
|
591 |
# Handle optional keywords (these will appear as verbatim) |
592 |
if ($prologue) { |
593 |
KEY: |
594 |
foreach $key ( @keys ) { |
595 |
if ( /$key/ ) { |
596 |
if ($verb) { |
597 |
&end_verbatim(); |
598 |
} |
599 |
else { |
600 |
printf "\n\\medskip\n"; |
601 |
} |
602 |
$k = sprintf('%s', $key); |
603 |
$ln = length($k); |
604 |
###printf "\\subsubsection*{%s}\n", substr($k, 2, $ln - 1); |
605 |
###printf "{\\Large \\em %s}\n", ucfirst lc substr($k, 2, $ln - 1); |
606 |
$_ = $key; |
607 |
printf "{\\sf %s}\n", substr($k, 2, $ln - 1); # san serif |
608 |
&begin_verbatim(); |
609 |
$first_verb = 1; |
610 |
if ( $key eq "!INTERFACE:" ) { $have_intf = 1; } |
611 |
if ( $key eq "!CALLING SEQUENCE:" ) { $have_intf = 1; } |
612 |
if ( $key eq "!REVISION HISTORY:" ) { $have_hist = 1; } |
613 |
next LINE; |
614 |
} |
615 |
} |
616 |
} |
617 |
|
618 |
# End of prologue |
619 |
if ($Fld[1] eq $eop_string) { |
620 |
if ($verb) { |
621 |
&end_verbatim(); |
622 |
} |
623 |
$prologue = 0; |
624 |
# &check_if_all_there(); # check if all required keywords are there. |
625 |
if ( $opt_l ) { |
626 |
$Fld[1] = $boc_string;} |
627 |
else { |
628 |
next LINE; |
629 |
} |
630 |
} |
631 |
|
632 |
unless ( $opt_s ) { |
633 |
|
634 |
# End of Internal Prologue |
635 |
if ($Fld[1] eq $eopi_string) { |
636 |
if ($verb) { |
637 |
&end_verbatim(); |
638 |
} |
639 |
$prologue = 0; |
640 |
# &check_if_all_there(); # check if all required keywords are there. |
641 |
if ($opt_l) { |
642 |
$Fld[1] = $boc_string;} |
643 |
else { next LINE; } |
644 |
} |
645 |
|
646 |
# Beginning of source code section |
647 |
if ($Fld[1] eq $boc_string) { |
648 |
print ' '; |
649 |
print '%/////////////////////////////////////////////////////////////'; |
650 |
$first = 0; |
651 |
$prologue = 0; |
652 |
$source = 1; |
653 |
### printf "\\subsubsection*{CONTENTS:}\n\n", $Fld[3]; |
654 |
printf "{\\sf CONTENTS:}"; |
655 |
&begin_verbatim(); |
656 |
next LINE; |
657 |
} |
658 |
|
659 |
# End of source code |
660 |
if ($Fld[1] eq $eoc_string) { |
661 |
&do_eoc(); |
662 |
$prologue = 0; |
663 |
next LINE; |
664 |
} |
665 |
} |
666 |
|
667 |
# Prologue or Introduction, print regular line (except for !) |
668 |
if ($prologue||$intro) { |
669 |
if ( $verb && $#Fld == 1 && ( $Fld[1] eq $comment_string ) ) { |
670 |
next LINE; # to eliminate excessive blanks |
671 |
} |
672 |
if ( $Fld[2] eq "\\ev" ) { |
673 |
# special handling |
674 |
$_ = $comment_string . " \\end{verbatim}"; |
675 |
} |
676 |
s/^$comment_string/ /; # replace comment string with blank |
677 |
# $line = sprintf('%s', $_); # not necessary -- comment str is absent |
678 |
# $ln = length($line); # not necessary -- comment str is absent |
679 |
unless ( $first_verb ) { printf "\n "; } |
680 |
printf '%s', $_; |
681 |
# printf '%s', substr($line, 1, $ln - 1); # comment str is absent |
682 |
$first_verb = 0; |
683 |
next LINE; |
684 |
} |
685 |
|
686 |
# Source code: print the full line |
687 |
if ($source) { |
688 |
print $_; |
689 |
next LINE; |
690 |
} |
691 |
|
692 |
} # end inner loop for processing each line of the input file |
693 |
|
694 |
} # end main loop for each command-line argument |
695 |
|
696 |
print $_; |
697 |
if ( $source ) { &do_eoc(); } |
698 |
print '%...............................................................'; |
699 |
|
700 |
# see comment above where these are originally set. |
701 |
#print "\\setlength{\\parskip}{\\oldparskip}"; |
702 |
#print "\\setlength{\\parindent}{\\oldparindent}"; |
703 |
#print "\\setlength{\\baselineskip}{\\oldbaselineskip}"; |
704 |
|
705 |
unless ( $opt_b ) { |
706 |
print "\\end{document}"; |
707 |
} |
708 |
|
709 |
|
710 |
#---------------------------------------------------------------------- |
711 |
|
712 |
sub begin_verbatim |
713 |
{ |
714 |
printf "\n{\\footnotesize \\begin{verbatim} "; |
715 |
$verb = 1; |
716 |
return 0; |
717 |
} |
718 |
|
719 |
sub end_verbatim |
720 |
{ |
721 |
printf "\\end{verbatim} }"; |
722 |
$verb = 0; |
723 |
return 0; |
724 |
} |
725 |
|
726 |
sub CheckOpts |
727 |
{ |
728 |
# Checks options against a given list. Outputs error message |
729 |
# for any invalid option. |
730 |
# |
731 |
# Usage: |
732 |
# $rc = &CheckOpts ( options, valid_reg_options, |
733 |
# valid_sw_options, |
734 |
# quiet_mode ) |
735 |
# |
736 |
# character: options - options to be checked. (e.g. -df+x) The |
737 |
# list must begin with a positive or |
738 |
# negative sign. If no sign appears at the |
739 |
# beginning or by itself, then the argument |
740 |
# is not recognized as a list of options. |
741 |
# character: valid_reg_options - list of valid regular options. |
742 |
# (i.e. options that are associated only |
743 |
# eith negative sign.) |
744 |
# character: valid_sw_options - list of valid switch options. |
745 |
# (i.e. options that can be associated with |
746 |
# either a positive or negative sign. |
747 |
# logical: quiet mode (optional) If true then print no error |
748 |
# messages. |
749 |
# integer: rc - return code |
750 |
# = -1 if the arguement, options, is |
751 |
# not recognized as a list of options |
752 |
# = 0 if all options are valid. |
753 |
# > 0 for the number of invalid options. |
754 |
|
755 |
local($options, |
756 |
$valid_reg_options, |
757 |
$valid_sw_options, |
758 |
$quiet_mode ) = @_; |
759 |
|
760 |
if ( $options eq "+" || |
761 |
$options eq "-" ) {return -1} |
762 |
|
763 |
local(@Options) = split( / */, $options ); |
764 |
if ( $Options[ $[ ] ne "-" && |
765 |
$Options[ $[ ] ne "+" ) {return -1;} |
766 |
|
767 |
local($option, $option_sign, $valid_list, $pos); |
768 |
local($errs) = 0; |
769 |
foreach $option ( @Options ) { |
770 |
if ( $option eq "-" || |
771 |
$option eq "+" ) {$option_sign = $option;} |
772 |
else { |
773 |
if ( $option_sign eq "-" ) { |
774 |
$valid_list = $valid_reg_options |
775 |
. $valid_sw_options; |
776 |
} |
777 |
else { |
778 |
$valid_list = $valid_sw_options; |
779 |
} |
780 |
$pos = index ($valid_list,$option); |
781 |
if ( $pos < $[ && |
782 |
$quiet_mode ) { |
783 |
$errs++; |
784 |
print STDERR "Invalid option: $option_sign$option \n"; |
785 |
|
786 |
} |
787 |
} |
788 |
} |
789 |
return $errs; |
790 |
} |
791 |
|
792 |
|
793 |
sub GetOpts |
794 |
{ |
795 |
# Gets options. If an option is valid, then opt_[option] is |
796 |
# set to 0 or 1 as a side effect if the option is preceeded by |
797 |
# a positive or negative sign. |
798 |
# |
799 |
# Usage: |
800 |
# $rc = &GetOpts ( options, valid_options ) |
801 |
# |
802 |
# character: options - options to be checked. (e.g. -df+x) The |
803 |
# list must begin with a positive or |
804 |
# negative sign. If no sign appears at the |
805 |
# beginning or by itself, then the argument |
806 |
# is not recognized as a list of options. |
807 |
# character: valid_options - list of valid options (e.g. dfhx) |
808 |
# integer: rc - return code |
809 |
# = -1 if the arguement, options, is |
810 |
# not recognized as a list of options. |
811 |
# = 0 otherwise |
812 |
|
813 |
local($options,$valid_options) = @_; |
814 |
|
815 |
if ( $options eq "+" || |
816 |
$options eq "-" ) {return -1} |
817 |
|
818 |
local(@Options) = split( / */, $options ); |
819 |
if ( $Options[ $[ ] ne "-" && |
820 |
$Options[ $[ ] ne "+" ) {return -1;} |
821 |
|
822 |
local($option, $option_sign); |
823 |
|
824 |
foreach $option ( @Options ) { |
825 |
|
826 |
if ( $option eq "-" || |
827 |
$option eq "+" ) { |
828 |
$option_sign = $option; } |
829 |
|
830 |
else { |
831 |
|
832 |
if ( index ($valid_options,$option) >= $[ ) { |
833 |
if ( $option_sign eq "-" ) {${"opt_$option"} = 1;} |
834 |
if ( $option_sign eq "+" ) {${"opt_$option"} = 0;}; |
835 |
|
836 |
} |
837 |
} |
838 |
} |
839 |
return 0; |
840 |
} |
841 |
|
842 |
|
843 |
sub SetOpt |
844 |
{ |
845 |
# Sets option flags. For the last input option that is in a |
846 |
# list, the flag opt_[option] is set to 1 as a side effect. |
847 |
# For all other options in the list, opt_[option] is set to 0. |
848 |
# |
849 |
# Usage: |
850 |
# $rc = &SetOpt ( options, valid_options ) |
851 |
# |
852 |
# character: options - options to be checked. (e.g. -df+x) The |
853 |
# list must begin with a positive or |
854 |
# negative sign. If no sign appears at the |
855 |
# beginning or by itself, then the argument |
856 |
# is not recognized as a list of options. |
857 |
# character: valid_options - list of valid options (e.g. def ) |
858 |
# integer: rc - return code |
859 |
# = -1 if the arguement, options, is |
860 |
# not recognized as a list of options. |
861 |
# = 0 otherwise |
862 |
# Note: For the examples provided for the input arguments, |
863 |
# $opt_d = 0, $opt_e = 0, and $opt_f = 1, since the |
864 |
# input option, -f, was the last in the argument, |
865 |
# option. |
866 |
|
867 |
local($options,$valid_options) = @_; |
868 |
|
869 |
if ( $options eq "+" || |
870 |
$options eq "-" ) {return -1} |
871 |
|
872 |
local(@Options) = split( / */, $options ); |
873 |
local(@ValidOptions) = split( / */, $valid_options ); |
874 |
if ( $Options[ $[ ] ne "-" && |
875 |
$Options[ $[ ] ne "+" ) {return -1;} |
876 |
|
877 |
local($option, $option_sign); |
878 |
|
879 |
foreach $option ( @Options ) { |
880 |
if ( $option ne "-" && |
881 |
$option ne "+" ) { |
882 |
|
883 |
if ( index ($valid_options,$option) >= $[ ) { |
884 |
foreach $valid_option (@ValidOptions ) { |
885 |
${"opt_$valid_option"} = 0; |
886 |
|
887 |
} |
888 |
${"opt_$option"} = 1; |
889 |
} |
890 |
} |
891 |
} |
892 |
return 0; |
893 |
} |
894 |
|
895 |
|
896 |
sub print_help |
897 |
{ |
898 |
print "Usage: protex [-hbACFS] [+-nlsxf] [src_file(s)]"; |
899 |
print " "; |
900 |
print " Options:"; |
901 |
print " -h Help mode: list command line options"; |
902 |
print " -b Bare mode, meaning no preamble, etc."; |
903 |
print " +-v Verbosity level"; |
904 |
print " +-n New Page for each subsection (wastes paper)"; |
905 |
print " +-l Listing mode, default is prologues only"; |
906 |
print " +-s Shut-up mode, i.e., ignore any code from BOC to EOC"; |
907 |
print " +-x No LaTeX mode, i.e., put !DESCRIPTION: in verbatim mode"; |
908 |
print " +-f No source file info"; |
909 |
print " -A Ada code"; |
910 |
print " -C C++ code"; |
911 |
print " -F F90 code"; |
912 |
print " -7 F77 code"; |
913 |
print " -S Shell script"; |
914 |
print " "; |
915 |
print " The options can appear in any order. The options, -h and -b,"; |
916 |
print " affect the input from all files listed on command-line input."; |
917 |
print " Each of the remaining options effects only the input from the"; |
918 |
print " files listed after the option and prior to any overriding"; |
919 |
print " option. The plus sign turns off the option."; |
920 |
} |
921 |
|
922 |
sub print_notice |
923 |
{ |
924 |
print "% **** IMPORTANT NOTICE *****" ; |
925 |
print "% This LaTeX file has been automatically produced by ProTeX v. 1.1"; |
926 |
print "% Any changes made to this file will likely be lost next time"; |
927 |
print "% this file is regenerated from its source. Send questions "; |
928 |
print "% to Arlindo da Silva, dasilva\@gsfc.nasa.gov"; |
929 |
print " "; |
930 |
} |
931 |
|
932 |
sub print_preamble |
933 |
{ |
934 |
unless ( $opt_b ) { |
935 |
print "%------------------------ PREAMBLE --------------------------"; |
936 |
print "\\documentclass[11pt]{article}"; |
937 |
print "\\usepackage{amsmath}"; |
938 |
print "\\usepackage{epsfig}"; |
939 |
print "\\usepackage{hangcaption}"; |
940 |
print "\\textheight 9in"; |
941 |
print "\\topmargin 0pt"; |
942 |
print "\\headsep 1cm"; |
943 |
print "\\headheight 0pt"; |
944 |
print "\\textwidth 6in"; |
945 |
print "\\oddsidemargin 0in"; |
946 |
print "\\evensidemargin 0in"; |
947 |
print "\\marginparpush 0pt"; |
948 |
print "\\pagestyle{myheadings}"; |
949 |
print "\\markboth{}{}"; |
950 |
print "%-------------------------------------------------------------"; |
951 |
} |
952 |
|
953 |
# in your main document before you include any protex-generated files |
954 |
# for the first time, if you define these three variables as length |
955 |
# settings (like this:) |
956 |
# \newlength{\oldparskip} |
957 |
# \newlength{\oldparindent} |
958 |
# \newlength{\oldbaselineskip} |
959 |
# then 1) comment in all the lines below, and 2) find the 3 reset lines |
960 |
# further down and comment in them as well. |
961 |
# then protex will override the paragraph and skip settings during |
962 |
# the source sections, but will restore the original document settings |
963 |
# at the end. if someone can figure out how to check to see if a |
964 |
# latex variable exists, and do a conditional section, we could make |
965 |
# this fully self-contained. |
966 |
# nsc feb 2003 |
967 |
|
968 |
#print "\\setlength{\\oldparskip}{\\parskip}"; |
969 |
print "\\setlength{\\parskip}{0pt}"; |
970 |
#print "\\setlength{\\oldparindent}{\\parindent}"; |
971 |
print "\\setlength{\\parindent}{0pt}"; |
972 |
#print "\\setlength{\\oldbaselineskip}{\\baselineskip}"; |
973 |
print "\\setlength{\\baselineskip}{11pt}"; |
974 |
} |
975 |
|
976 |
|
977 |
sub print_macros |
978 |
{ |
979 |
print " "; |
980 |
print "%--------------------- SHORT-HAND MACROS ----------------------"; |
981 |
print "\\def\\bv{\\begin{verbatim}}"; |
982 |
print "\\def\\ev\{\\end\{verbatim}}"; |
983 |
print "\\def\\be{\\begin{equation}}"; |
984 |
print "\\def\\ee{\\end{equation}}"; |
985 |
print "\\def\\bea{\\begin{eqnarray}}"; |
986 |
print "\\def\\eea{\\end{eqnarray}}"; |
987 |
print "\\def\\bi{\\begin{itemize}}"; |
988 |
print "\\def\\ei{\\end{itemize}}"; |
989 |
print "\\def\\bn{\\begin{enumerate}}"; |
990 |
print "\\def\\en{\\end{enumerate}}"; |
991 |
print "\\def\\bd{\\begin{description}}"; |
992 |
print "\\def\\ed{\\end{description}}"; |
993 |
print "\\def\\({\\left (}"; |
994 |
print "\\def\\){\\right )}"; |
995 |
print "\\def\\[{\\left [}"; |
996 |
print "\\def\\]{\\right ]}"; |
997 |
print "\\def\\<{\\left \\langle}"; |
998 |
print "\\def\\>{\\right \\rangle}"; |
999 |
print "\\def\\cI{{\\cal I}}"; |
1000 |
print "\\def\\diag{\\mathop{\\rm diag}}"; |
1001 |
print "\\def\\tr{\\mathop{\\rm tr}}"; |
1002 |
print "%-------------------------------------------------------------"; |
1003 |
} |
1004 |
|
1005 |
|
1006 |
sub do_beg |
1007 |
{ |
1008 |
unless ( $opt_b ) { |
1009 |
if ( $begdoc == 0 ) { |
1010 |
if ( $tpage ) { |
1011 |
print "\\title{@title}"; |
1012 |
print "\\author{{\\sc @author}\\\\ {\\em @affiliation}}"; |
1013 |
print "\\date{@date}"; |
1014 |
} |
1015 |
print "\\begin{document}"; |
1016 |
if ( $tpage ) { |
1017 |
print "\\maketitle"; |
1018 |
} |
1019 |
print "\\tableofcontents"; |
1020 |
print "\\newpage"; |
1021 |
$begdoc = 1; |
1022 |
} |
1023 |
} |
1024 |
} |
1025 |
|
1026 |
sub do_eoc |
1027 |
{ |
1028 |
print ' '; |
1029 |
if ($verb) { |
1030 |
&end_verbatim(); |
1031 |
} |
1032 |
$source = 0; |
1033 |
} |
1034 |
|
1035 |
|
1036 |
sub set_missing |
1037 |
{ |
1038 |
$have_name = 0; # have routine name? |
1039 |
$have_desc = 0; # have description? |
1040 |
$have_intf = 0; # have interface? |
1041 |
$have_hist = 0; # have revision history? |
1042 |
$name_is = "UNKNOWN"; |
1043 |
} |
1044 |
|
1045 |
sub check_if_all_there |
1046 |
{ |
1047 |
$have_name || |
1048 |
die "ProTeX: invalid prologue, missing !ROUTINE: or !IROUTINE: in <$name_is>"; |
1049 |
|
1050 |
$have_desc || |
1051 |
die "ProTeX: invalid prologue, missing !DESCRIPTION: in <$name_is>"; |
1052 |
|
1053 |
$have_intf || |
1054 |
die "ProTeX: invalid prologue, missing !INTERFACE: in <$name_is>"; |
1055 |
|
1056 |
$have_hist || |
1057 |
die "ProTeX: invalid prologue, missing !REVISION HISTORY: in <$name_is>"; |
1058 |
} |