/[MITgcm]/MITgcm/doc/api_reference/protex
ViewVC logotype

Contents of /MITgcm/doc/api_reference/protex

Parent Directory Parent Directory | Revision Log Revision Log | View Revision Graph Revision Graph


Revision 1.4 - (show annotations) (download)
Thu Apr 1 04:23:33 2004 UTC (20 years, 2 months ago) by edhill
Branch: MAIN
Changes since 1.3: +5 -10 lines
 o further protex-related cleanups

1 #! /usr/bin/env perl
2 #
3 # $Id: protex,v 1.3 2004/03/29 03:33:51 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 # \end{tabular}
37 # \end{center}
38 #
39 # The options can appear in any order. The options, -h and -b, affect
40 # the input from all files listed on command-line input. Each of the
41 # remaining options effects only the input from the files listed after
42 # the option and prior to any overriding option. The plus sign
43 # turns off the option. For example, the command-line input,
44 # \bv
45 # protex -bnS File1 -F File2.f +n File3.f
46 # \ev
47 # will cause the option, {\tt -n} to affect the input from the files,
48 # {\tt File} and {\tt File2.f}, but not from {\tt File3.f}. The
49 # {\tt -S} option is implemented for {\tt File1} but is overridden by
50 # the {\tt -F} for files {\tt File2.f} and {\tt File3.f}.
51 #
52 #
53 # !SEE ALSO:
54 # For a more detailed description of ProTeX functionality,
55 # DAO Prologue and other conventions, consult:
56 #
57 # Sawyer, W., and A. da Silva, 1997: ProTeX: A Sample
58 # Fortran 90 Source Code Documentation System.
59 # DAO Office Note 97-11
60 #
61 #
62 # !REVISION HISTORY:
63 #
64 # 20Dec1995 da Silva First experimental version
65 # 10Nov1996 da Silva First internal release (v1.01)
66 # 28Jun1997 da Silva Modified so that !DESCRIPTION can appear after
67 # !INTERFACE, and !INPUT PARAMETERS etc. changed to italics.
68 # 02Jul1997 Sawyer Added shut-up mode
69 # 20Oct1997 Sawyer Added support for shell scripts
70 # 11Mar1998 Sawyer Added: file name, date in header, C, script support
71 # 05Aug1998 Sawyer Fixed LPChang-bug-support-for-files-with-underscores
72 # 10Oct1998 da Silva Introduced -f option for removing source file info
73 # from subsection, etc. Added help (WS).
74 # 06Dec1999 C. Redder Added LaTeX command "\label{sec:prologues}" just
75 # after the beginning of the proglogue section.
76 # 13Dec1999 C. Redder Increased flexbility in command-line
77 # interface. The options can appear in any
78 # order which will allow the user to implement
79 # options for select files.
80 # 01Feb1999 C. Redder Added \usepackage commands to preamble of latex
81 # document to include the packages amsmath, epsfig
82 # and hangcaption.
83 # 10May2000 C. Redder Revised LaTeX command "\label{sec:prologues}"
84 # to "\label{app:ProLogues}"
85 # 10/10/2002 da Silva Introduced ARGUMENTS keyword, touch ups.
86 #
87 # 15Jan2003 R. Staufer Modified table of contents to print only section headers - no descriptions
88 #
89 # 25Feb2003 R. Staufer Added BOPI/EOPI and -i (internal) switch to provide the option of omitting prologue information from output files.
90 #
91 #EOP
92 #----------------------------------------------------------------------------
93
94 # Keep this if you don't know what it does...
95 # -------------------------------------------
96 $[ = 1; # set array base to 1
97 $, = ' '; # set output field separator
98 $\ = "\n"; # set output record separator
99
100 # Set valid options lists
101 # -----------------------
102 $GlobOptions = 'hb'; # Global options (i.e for all files)
103 $LangOptions = 'ACFS7'; # Options for setting programming languages
104 $SwOptions = 'flinsx'; # Options that can change for each input file
105 $RegOptions = "$GlobOptions$LangOptions";
106 # Scan for global options until first first
107 # file is processed.
108
109 # Scan for global options
110 # -----------------------
111 $NFiles = 0;
112 Arg:
113 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:
183 foreach $arg (@ARGV) {
184
185 # Scan for non-global command-line options
186 $option = &CheckOpts ( $arg, $RegOptions, $SwOptions, "quiet" ) + 1;
187 if ( $option ) {
188 &GetOpts ( $arg, $SwOptions );
189 &SetOpt ( $arg, $LangOptions );
190 next ARG;
191 }
192
193 # Determine the type of code, set corresponding search strings
194 $comment_string = '!'; # DEFAULT is FORTRAN
195 $boi_string = '!BOI';
196 $eoi_string = '!EOI';
197 $bop_string = '!BOP';
198 $eop_string = '!EOP';
199 $bopi_string = '!BOPI';
200 $eopi_string = '!EOPI';
201 $boc_string = '!BOC';
202 $eoc_string = '!EOC';
203
204 if ( $opt_7 ) { # f77
205 $comment_string = 'C'; # ---
206 $boi_string = 'CBOI';
207 $eoi_string = 'CEOI';
208 $bop_string = 'CBOP';
209 $eop_string = 'CEOP';
210 $bopi_string = 'CBOPI';
211 $eopi_string = 'CEOPI';
212 $boc_string = 'CBOC';
213 $eoc_string = 'CEOC';
214 }
215
216 if ( $opt_A ) { # ADA
217 $comment_string = '--'; # ---
218 $boi_string = '--BOI';
219 $eoi_string = '--EOI';
220 $bop_string = '--BOP';
221 $eop_string = '--EOP';
222 $bopi_string = '--BOPI';
223 $eopi_string = '--EOPI';
224 $boc_string = '--BOC';
225 $eoc_string = '--EOC';
226 }
227
228 if ( $opt_C ) {
229 $comment_string = '//'; # C
230 $boi_string = '//BOI'; # -
231 $eoi_string = '//EOI';
232 $bop_string = '//BOP';
233 $eop_string = '//EOP';
234 $bopi_string = '//BOPI';
235 $eopi_string = '//EOPI';
236 $boc_string = '//BOC';
237 $eoc_string = '//EOC';
238 }
239
240 if ( $opt_S ) { # Script
241 $comment_string = '#'; # ------
242 $boi_string = '#BOI';
243 $eoi_string = '#EOI';
244 $bop_string = '#BOP';
245 $eop_string = '#EOP';
246 $bopi_string = '#BOPI';
247 $eopi_string = '#EOPI';
248 $boc_string = '#BOC';
249 $eoc_string = '#EOC';
250 }
251
252 # Set file name parameters
253 $InputFile = $arg;
254 @all_path_components = split( /\//, $InputFile );
255 $FileBaseName = pop ( @all_path_components );
256 $FileBaseName =~ s/_/\\_/g;
257 if ( $InputFile eq "-" ) {$FileBaseName = "Standard Input";}
258
259 # Set date
260 $Date = `date`;
261
262 # Open current file
263 open ( InputFile, "$InputFile" )
264 or print STDERR "Unable to open $InputFile: $!";
265
266 # Print page header
267 chomp($Date);
268 # printf "\n\\markboth{Left}{Source File: %s, Date: %s}\n\n",
269 printf "\n\\markboth{Source File: %s}{Date: %s}\n\n",
270 $FileBaseName, $Date;
271
272 # Inner loop --- for processing each line of the input file
273 LINE:
274 while ( <InputFile> ) {
275 chop; # strip record separator
276
277 @Fld = split(' ', $_, 9999);
278
279 # Straight quote
280 if ($Fld[1] eq '!QUOTE:') {
281 for ($i = 2; $i <= $#Fld; $i++) {
282 printf '%s ', $Fld[$i];
283 }
284 print " ";
285 next LINE;
286 }
287
288 # Handle optional Title Page and Introduction
289 if ($Fld[1] eq $boi_string) {
290 print ' ';
291 $intro = 1;
292 next LINE;
293 }
294
295 if ($Fld[2] eq '!TITLE:') {
296 if ( $intro ) {
297 shift @Fld;
298 shift @Fld;
299 @title = @Fld;
300 $tpage = 1;
301 next LINE;
302 }
303 }
304
305 if ($Fld[2] eq '!AUTHORS:') {
306 if ( $intro ) {
307 shift @Fld;
308 shift @Fld;
309 @author = @Fld;
310 $tpage = 1;
311 next LINE;
312 }
313 }
314
315 if ($Fld[2] eq '!AFFILIATION:') {
316 if ( $intro ) {
317 shift @Fld;
318 shift @Fld;
319 @affiliation = @Fld;
320 $tpage = 1;
321 next LINE;
322 }
323 }
324
325 if ($Fld[2] eq '!DATE:') {
326 if ( $intro ) {
327 shift @Fld;
328 shift @Fld;
329 @date = @Fld;
330 $tpage = 1;
331 next LINE;
332 }
333 }
334
335 if ($Fld[2] eq '!INTRODUCTION:') {
336 if ( $intro ) {
337 &do_beg();
338 print ' ';
339 print '%..............................................';
340 shift @Fld;
341 shift @Fld;
342 print "\\section{@Fld}";
343 next LINE;
344 }
345 }
346
347
348 # End of introduction
349 if ($Fld[1] eq $eoi_string) {
350 print ' ';
351 print '%/////////////////////////////////////////////////////////////';
352 print "\\newpage";
353 $intro = 0;
354 next LINE;
355 }
356
357 # Beginning of prologue
358 if ($Fld[1] eq $bop_string) {
359 if ( $source ) { &do_eoc(); }
360 print ' ';
361 print '%/////////////////////////////////////////////////////////////';
362 &do_beg();
363 if ($first == 0) {
364 ### print "\\newpage";
365 print " ";
366 print "\\mbox{}\\hrulefill\\ ";
367 print " ";}
368 else {
369 unless($opt_b){
370 print
371 "\\section{Routine/Function Prologues} \\label{app:ProLogues}";
372 }
373 }
374 $first = 0;
375 $prologue = 1;
376 $verb = 0;
377 $source = 0;
378 &set_missing(); # no required keyword yet
379 next LINE;
380 }
381
382 # Beginning of internal prologue
383 if ($Fld[1] eq $bopi_string) {
384 if ($opt_i) {$prologue = 0;}
385 else {
386 if ($source) { &do_eoc(); }
387 print ' ';
388 print '%/////////////////////////////////////////////////////////////';
389 &do_beg();
390 if ($first ==0) {
391 ### print "\\newpage";
392 print " ";
393 print "\\mbox{}\\hrulefill\\";
394 print " ";}
395 else {
396 unless($opt_b) {
397 print
398 "\\section{Routine/Function Prologues} \\label{app:ProLogues}";
399 }
400 }
401 $first = 0;
402 $prologue = 1;
403 $verb = 0;
404 $source = 0;
405 &set_missing(); # no required keyword yet
406 next LINE;
407 }
408 }
409
410 # A new subroutine/function
411 if ($Fld[2] eq '!ROUTINE:' ) {
412 if ($prologue) {
413 shift @Fld;
414 shift @Fld;
415 $_ = join(' ', @Fld);
416 $name_is = $_;
417 s/_/\\_/g;
418 # Replace "_" with "\_"
419 if ( $opt_n && $not_first ) {
420 printf "\\newpage\n";
421 }
422 unless ($opt_f) {
423 printf "\\subsubsection{%s (File: %s)}\n\n", $_, $FileBaseName;
424 }
425 else {
426 printf "\\subsubsection{%s }\n\n", $_;
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 " +-n New Page for each subsection (wastes paper)";
904 print " +-l Listing mode, default is prologues only";
905 print " +-s Shut-up mode, i.e., ignore any code from BOC to EOC";
906 print " +-x No LaTeX mode, i.e., put !DESCRIPTION: in verbatim mode";
907 print " +-f No source file info";
908 print " -A Ada code";
909 print " -C C++ code";
910 print " -F F90 code";
911 print " -7 F77 code";
912 print " -S Shell script";
913 print " ";
914 print " The options can appear in any order. The options, -h and -b,";
915 print " affect the input from all files listed on command-line input.";
916 print " Each of the remaining options effects only the input from the";
917 print " files listed after the option and prior to any overriding";
918 print " option. The plus sign turns off the option.";
919 }
920
921 sub print_notice
922 {
923 print "% **** IMPORTANT NOTICE *****" ;
924 print "% This LaTeX file has been automatically produced by ProTeX v. 1.1";
925 print "% Any changes made to this file will likely be lost next time";
926 print "% this file is regenerated from its source. Send questions ";
927 print "% to Arlindo da Silva, dasilva\@gsfc.nasa.gov";
928 print " ";
929 }
930
931 sub print_preamble
932 {
933 unless ( $opt_b ) {
934 print "%------------------------ PREAMBLE --------------------------";
935 print "\\documentclass[11pt]{article}";
936 print "\\usepackage{amsmath}";
937 print "\\usepackage{epsfig}";
938 print "\\usepackage{hangcaption}";
939 print "\\textheight 9in";
940 print "\\topmargin 0pt";
941 print "\\headsep 1cm";
942 print "\\headheight 0pt";
943 print "\\textwidth 6in";
944 print "\\oddsidemargin 0in";
945 print "\\evensidemargin 0in";
946 print "\\marginparpush 0pt";
947 print "\\pagestyle{myheadings}";
948 print "\\markboth{}{}";
949 print "%-------------------------------------------------------------";
950 }
951
952 # in your main document before you include any protex-generated files
953 # for the first time, if you define these three variables as length
954 # settings (like this:)
955 # \newlength{\oldparskip}
956 # \newlength{\oldparindent}
957 # \newlength{\oldbaselineskip}
958 # then 1) comment in all the lines below, and 2) find the 3 reset lines
959 # further down and comment in them as well.
960 # then protex will override the paragraph and skip settings during
961 # the source sections, but will restore the original document settings
962 # at the end. if someone can figure out how to check to see if a
963 # latex variable exists, and do a conditional section, we could make
964 # this fully self-contained.
965 # nsc feb 2003
966
967 #print "\\setlength{\\oldparskip}{\\parskip}";
968 print "\\setlength{\\parskip}{0pt}";
969 #print "\\setlength{\\oldparindent}{\\parindent}";
970 print "\\setlength{\\parindent}{0pt}";
971 #print "\\setlength{\\oldbaselineskip}{\\baselineskip}";
972 print "\\setlength{\\baselineskip}{11pt}";
973 }
974
975
976 sub print_macros
977 {
978 print " ";
979 print "%--------------------- SHORT-HAND MACROS ----------------------";
980 print "\\def\\bv{\\begin{verbatim}}";
981 print "\\def\\ev\{\\end\{verbatim}}";
982 print "\\def\\be{\\begin{equation}}";
983 print "\\def\\ee{\\end{equation}}";
984 print "\\def\\bea{\\begin{eqnarray}}";
985 print "\\def\\eea{\\end{eqnarray}}";
986 print "\\def\\bi{\\begin{itemize}}";
987 print "\\def\\ei{\\end{itemize}}";
988 print "\\def\\bn{\\begin{enumerate}}";
989 print "\\def\\en{\\end{enumerate}}";
990 print "\\def\\bd{\\begin{description}}";
991 print "\\def\\ed{\\end{description}}";
992 print "\\def\\({\\left (}";
993 print "\\def\\){\\right )}";
994 print "\\def\\[{\\left [}";
995 print "\\def\\]{\\right ]}";
996 print "\\def\\<{\\left \\langle}";
997 print "\\def\\>{\\right \\rangle}";
998 print "\\def\\cI{{\\cal I}}";
999 print "\\def\\diag{\\mathop{\\rm diag}}";
1000 print "\\def\\tr{\\mathop{\\rm tr}}";
1001 print "%-------------------------------------------------------------";
1002 }
1003
1004
1005 sub do_beg
1006 {
1007 unless ( $opt_b ) {
1008 if ( $begdoc == 0 ) {
1009 if ( $tpage ) {
1010 print "\\title{@title}";
1011 print "\\author{{\\sc @author}\\\\ {\\em @affiliation}}";
1012 print "\\date{@date}";
1013 }
1014 print "\\begin{document}";
1015 if ( $tpage ) {
1016 print "\\maketitle";
1017 }
1018 print "\\tableofcontents";
1019 print "\\newpage";
1020 $begdoc = 1;
1021 }
1022 }
1023 }
1024
1025 sub do_eoc
1026 {
1027 print ' ';
1028 if ($verb) {
1029 &end_verbatim();
1030 }
1031 $source = 0;
1032 }
1033
1034
1035 sub set_missing
1036 {
1037 $have_name = 0; # have routine name?
1038 $have_desc = 0; # have description?
1039 $have_intf = 0; # have interface?
1040 $have_hist = 0; # have revision history?
1041 $name_is = "UNKNOWN";
1042 }
1043
1044 sub check_if_all_there
1045 {
1046 $have_name ||
1047 die "ProTeX: invalid prologue, missing !ROUTINE: or !IROUTINE: in <$name_is>";
1048
1049 $have_desc ||
1050 die "ProTeX: invalid prologue, missing !DESCRIPTION: in <$name_is>";
1051
1052 $have_intf ||
1053 die "ProTeX: invalid prologue, missing !INTERFACE: in <$name_is>";
1054
1055 $have_hist ||
1056 die "ProTeX: invalid prologue, missing !REVISION HISTORY: in <$name_is>";
1057 }

  ViewVC Help
Powered by ViewVC 1.1.22