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