/[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.3 - (show annotations) (download)
Mon Mar 29 03:33:51 2004 UTC (19 years, 6 months ago) by edhill
Branch: MAIN
Changes since 1.2: +834 -812 lines
 o new "poster children" for the API reference:
   - generic_advdiff
   - mnc

1 #! /usr/bin/env perl
2 #
3 # $Id: protex,v 1.2 2004/03/26 23:46:11 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\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\\bigskip";
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 if( /USES/ || /INPUT/ || /OUTPUT/ || /PARAMETERS/ ||
608 /VALUE/ || /ARGUMENTS/ ) {
609 printf "{\\em %s}\n", substr($k, 2, $ln - 1); } # italics
610 else {
611 printf "{\\sf %s}\n", substr($k, 2, $ln - 1); # san serif
612 }
613 &begin_verbatim();
614 $first_verb = 1;
615 if ( $key eq "!INTERFACE:" ) { $have_intf = 1; }
616 if ( $key eq "!CALLING SEQUENCE:" ) { $have_intf = 1; }
617 if ( $key eq "!REVISION HISTORY:" ) { $have_hist = 1; }
618 next LINE;
619 }
620 }
621 }
622
623 # End of prologue
624 if ($Fld[1] eq $eop_string) {
625 if ($verb) {
626 &end_verbatim();
627 }
628 $prologue = 0;
629 # &check_if_all_there(); # check if all required keywords are there.
630 if ( $opt_l ) {
631 $Fld[1] = $boc_string;}
632 else {
633 next LINE;
634 }
635 }
636
637 unless ( $opt_s ) {
638
639 # End of Internal Prologue
640 if ($Fld[1] eq $eopi_string) {
641 if ($verb) {
642 &end_verbatim();
643 }
644 $prologue = 0;
645 # &check_if_all_there(); # check if all required keywords are there.
646 if ($opt_l) {
647 $Fld[1] = $boc_string;}
648 else { next LINE; }
649 }
650
651 # Beginning of source code section
652 if ($Fld[1] eq $boc_string) {
653 print ' ';
654 print '%/////////////////////////////////////////////////////////////';
655 $first = 0;
656 $prologue = 0;
657 $source = 1;
658 ### printf "\\subsubsection*{CONTENTS:}\n\n", $Fld[3];
659 printf "{\\sf CONTENTS:}";
660 &begin_verbatim();
661 next LINE;
662 }
663
664 # End of source code
665 if ($Fld[1] eq $eoc_string) {
666 &do_eoc();
667 $prologue = 0;
668 next LINE;
669 }
670 }
671
672 # Prologue or Introduction, print regular line (except for !)
673 if ($prologue||$intro) {
674 if ( $verb && $#Fld == 1 && ( $Fld[1] eq $comment_string ) ) {
675 next LINE; # to eliminate excessive blanks
676 }
677 if ( $Fld[2] eq "\\ev" ) {
678 # special handling
679 $_ = $comment_string . " \\end{verbatim}";
680 }
681 s/^$comment_string/ /; # replace comment string with blank
682 # $line = sprintf('%s', $_); # not necessary -- comment str is absent
683 # $ln = length($line); # not necessary -- comment str is absent
684 unless ( $first_verb ) { printf "\n "; }
685 printf '%s', $_;
686 # printf '%s', substr($line, 1, $ln - 1); # comment str is absent
687 $first_verb = 0;
688 next LINE;
689 }
690
691 # Source code: print the full line
692 if ($source) {
693 print $_;
694 next LINE;
695 }
696
697 } # end inner loop for processing each line of the input file
698
699 } # end main loop for each command-line argument
700
701 print $_;
702 if ( $source ) { &do_eoc(); }
703 print '%...............................................................';
704
705 # see comment above where these are originally set.
706 #print "\\setlength{\\parskip}{\\oldparskip}";
707 #print "\\setlength{\\parindent}{\\oldparindent}";
708 #print "\\setlength{\\baselineskip}{\\oldbaselineskip}";
709
710 unless ( $opt_b ) {
711 print "\\end{document}";
712 }
713
714
715 #----------------------------------------------------------------------
716
717 sub begin_verbatim
718 {
719 printf "\n{\\small \\begin{verbatim} ";
720 $verb = 1;
721 return 0;
722 }
723
724 sub end_verbatim
725 {
726 printf "\\end{verbatim} }";
727 $verb = 0;
728 return 0;
729 }
730
731 sub CheckOpts
732 {
733 # Checks options against a given list. Outputs error message
734 # for any invalid option.
735 #
736 # Usage:
737 # $rc = &CheckOpts ( options, valid_reg_options,
738 # valid_sw_options,
739 # quiet_mode )
740 #
741 # character: options - options to be checked. (e.g. -df+x) The
742 # list must begin with a positive or
743 # negative sign. If no sign appears at the
744 # beginning or by itself, then the argument
745 # is not recognized as a list of options.
746 # character: valid_reg_options - list of valid regular options.
747 # (i.e. options that are associated only
748 # eith negative sign.)
749 # character: valid_sw_options - list of valid switch options.
750 # (i.e. options that can be associated with
751 # either a positive or negative sign.
752 # logical: quiet mode (optional) If true then print no error
753 # messages.
754 # integer: rc - return code
755 # = -1 if the arguement, options, is
756 # not recognized as a list of options
757 # = 0 if all options are valid.
758 # > 0 for the number of invalid options.
759
760 local($options,
761 $valid_reg_options,
762 $valid_sw_options,
763 $quiet_mode ) = @_;
764
765 if ( $options eq "+" ||
766 $options eq "-" ) {return -1}
767
768 local(@Options) = split( / */, $options );
769 if ( $Options[ $[ ] ne "-" &&
770 $Options[ $[ ] ne "+" ) {return -1;}
771
772 local($option, $option_sign, $valid_list, $pos);
773 local($errs) = 0;
774 foreach $option ( @Options ) {
775 if ( $option eq "-" ||
776 $option eq "+" ) {$option_sign = $option;}
777 else {
778 if ( $option_sign eq "-" ) {
779 $valid_list = $valid_reg_options
780 . $valid_sw_options;
781 }
782 else {
783 $valid_list = $valid_sw_options;
784 }
785 $pos = index ($valid_list,$option);
786 if ( $pos < $[ &&
787 $quiet_mode ) {
788 $errs++;
789 print STDERR "Invalid option: $option_sign$option \n";
790
791 }
792 }
793 }
794 return $errs;
795 }
796
797
798 sub GetOpts
799 {
800 # Gets options. If an option is valid, then opt_[option] is
801 # set to 0 or 1 as a side effect if the option is preceeded by
802 # a positive or negative sign.
803 #
804 # Usage:
805 # $rc = &GetOpts ( options, valid_options )
806 #
807 # character: options - options to be checked. (e.g. -df+x) The
808 # list must begin with a positive or
809 # negative sign. If no sign appears at the
810 # beginning or by itself, then the argument
811 # is not recognized as a list of options.
812 # character: valid_options - list of valid options (e.g. dfhx)
813 # integer: rc - return code
814 # = -1 if the arguement, options, is
815 # not recognized as a list of options.
816 # = 0 otherwise
817
818 local($options,$valid_options) = @_;
819
820 if ( $options eq "+" ||
821 $options eq "-" ) {return -1}
822
823 local(@Options) = split( / */, $options );
824 if ( $Options[ $[ ] ne "-" &&
825 $Options[ $[ ] ne "+" ) {return -1;}
826
827 local($option, $option_sign);
828
829 foreach $option ( @Options ) {
830
831 if ( $option eq "-" ||
832 $option eq "+" ) {
833 $option_sign = $option; }
834
835 else {
836
837 if ( index ($valid_options,$option) >= $[ ) {
838 if ( $option_sign eq "-" ) {${"opt_$option"} = 1;}
839 if ( $option_sign eq "+" ) {${"opt_$option"} = 0;};
840
841 }
842 }
843 }
844 return 0;
845 }
846
847
848 sub SetOpt
849 {
850 # Sets option flags. For the last input option that is in a
851 # list, the flag opt_[option] is set to 1 as a side effect.
852 # For all other options in the list, opt_[option] is set to 0.
853 #
854 # Usage:
855 # $rc = &SetOpt ( options, valid_options )
856 #
857 # character: options - options to be checked. (e.g. -df+x) The
858 # list must begin with a positive or
859 # negative sign. If no sign appears at the
860 # beginning or by itself, then the argument
861 # is not recognized as a list of options.
862 # character: valid_options - list of valid options (e.g. def )
863 # integer: rc - return code
864 # = -1 if the arguement, options, is
865 # not recognized as a list of options.
866 # = 0 otherwise
867 # Note: For the examples provided for the input arguments,
868 # $opt_d = 0, $opt_e = 0, and $opt_f = 1, since the
869 # input option, -f, was the last in the argument,
870 # option.
871
872 local($options,$valid_options) = @_;
873
874 if ( $options eq "+" ||
875 $options eq "-" ) {return -1}
876
877 local(@Options) = split( / */, $options );
878 local(@ValidOptions) = split( / */, $valid_options );
879 if ( $Options[ $[ ] ne "-" &&
880 $Options[ $[ ] ne "+" ) {return -1;}
881
882 local($option, $option_sign);
883
884 foreach $option ( @Options ) {
885 if ( $option ne "-" &&
886 $option ne "+" ) {
887
888 if ( index ($valid_options,$option) >= $[ ) {
889 foreach $valid_option (@ValidOptions ) {
890 ${"opt_$valid_option"} = 0;
891
892 }
893 ${"opt_$option"} = 1;
894 }
895 }
896 }
897 return 0;
898 }
899
900
901 sub print_help
902 {
903 print "Usage: protex [-hbACFS] [+-nlsxf] [src_file(s)]";
904 print " ";
905 print " Options:";
906 print " -h Help mode: list command line options";
907 print " -b Bare mode, meaning no preamble, etc.";
908 print " +-n New Page for each subsection (wastes paper)";
909 print " +-l Listing mode, default is prologues only";
910 print " +-s Shut-up mode, i.e., ignore any code from BOC to EOC";
911 print " +-x No LaTeX mode, i.e., put !DESCRIPTION: in verbatim mode";
912 print " +-f No source file info";
913 print " -A Ada code";
914 print " -C C++ code";
915 print " -F F90 code";
916 print " -7 F77 code";
917 print " -S Shell script";
918 print " ";
919 print " The options can appear in any order. The options, -h and -b,";
920 print " affect the input from all files listed on command-line input.";
921 print " Each of the remaining options effects only the input from the";
922 print " files listed after the option and prior to any overriding";
923 print " option. The plus sign turns off the option.";
924 }
925
926 sub print_notice
927 {
928 print "% **** IMPORTANT NOTICE *****" ;
929 print "% This LaTeX file has been automatically produced by ProTeX v. 1.1";
930 print "% Any changes made to this file will likely be lost next time";
931 print "% this file is regenerated from its source. Send questions ";
932 print "% to Arlindo da Silva, dasilva\@gsfc.nasa.gov";
933 print " ";
934 }
935
936 sub print_preamble
937 {
938 unless ( $opt_b ) {
939 print "%------------------------ PREAMBLE --------------------------";
940 print "\\documentclass[11pt]{article}";
941 print "\\usepackage{amsmath}";
942 print "\\usepackage{epsfig}";
943 print "\\usepackage{hangcaption}";
944 print "\\textheight 9in";
945 print "\\topmargin 0pt";
946 print "\\headsep 1cm";
947 print "\\headheight 0pt";
948 print "\\textwidth 6in";
949 print "\\oddsidemargin 0in";
950 print "\\evensidemargin 0in";
951 print "\\marginparpush 0pt";
952 print "\\pagestyle{myheadings}";
953 print "\\markboth{}{}";
954 print "%-------------------------------------------------------------";
955 }
956
957 # in your main document before you include any protex-generated files
958 # for the first time, if you define these three variables as length
959 # settings (like this:)
960 # \newlength{\oldparskip}
961 # \newlength{\oldparindent}
962 # \newlength{\oldbaselineskip}
963 # then 1) comment in all the lines below, and 2) find the 3 reset lines
964 # further down and comment in them as well.
965 # then protex will override the paragraph and skip settings during
966 # the source sections, but will restore the original document settings
967 # at the end. if someone can figure out how to check to see if a
968 # latex variable exists, and do a conditional section, we could make
969 # this fully self-contained.
970 # nsc feb 2003
971
972 #print "\\setlength{\\oldparskip}{\\parskip}";
973 print "\\setlength{\\parskip}{0pt}";
974 #print "\\setlength{\\oldparindent}{\\parindent}";
975 print "\\setlength{\\parindent}{0pt}";
976 #print "\\setlength{\\oldbaselineskip}{\\baselineskip}";
977 print "\\setlength{\\baselineskip}{11pt}";
978 }
979
980
981 sub print_macros
982 {
983 print " ";
984 print "%--------------------- SHORT-HAND MACROS ----------------------";
985 print "\\def\\bv{\\begin{verbatim}}";
986 print "\\def\\ev\{\\end\{verbatim}}";
987 print "\\def\\be{\\begin{equation}}";
988 print "\\def\\ee{\\end{equation}}";
989 print "\\def\\bea{\\begin{eqnarray}}";
990 print "\\def\\eea{\\end{eqnarray}}";
991 print "\\def\\bi{\\begin{itemize}}";
992 print "\\def\\ei{\\end{itemize}}";
993 print "\\def\\bn{\\begin{enumerate}}";
994 print "\\def\\en{\\end{enumerate}}";
995 print "\\def\\bd{\\begin{description}}";
996 print "\\def\\ed{\\end{description}}";
997 print "\\def\\({\\left (}";
998 print "\\def\\){\\right )}";
999 print "\\def\\[{\\left [}";
1000 print "\\def\\]{\\right ]}";
1001 print "\\def\\<{\\left \\langle}";
1002 print "\\def\\>{\\right \\rangle}";
1003 print "\\def\\cI{{\\cal I}}";
1004 print "\\def\\diag{\\mathop{\\rm diag}}";
1005 print "\\def\\tr{\\mathop{\\rm tr}}";
1006 print "%-------------------------------------------------------------";
1007 }
1008
1009
1010 sub do_beg
1011 {
1012 unless ( $opt_b ) {
1013 if ( $begdoc == 0 ) {
1014 if ( $tpage ) {
1015 print "\\title{@title}";
1016 print "\\author{{\\sc @author}\\\\ {\\em @affiliation}}";
1017 print "\\date{@date}";
1018 }
1019 print "\\begin{document}";
1020 if ( $tpage ) {
1021 print "\\maketitle";
1022 }
1023 print "\\tableofcontents";
1024 print "\\newpage";
1025 $begdoc = 1;
1026 }
1027 }
1028 }
1029
1030 sub do_eoc
1031 {
1032 print ' ';
1033 if ($verb) {
1034 &end_verbatim();
1035 }
1036 $source = 0;
1037 }
1038
1039
1040 sub set_missing
1041 {
1042 $have_name = 0; # have routine name?
1043 $have_desc = 0; # have description?
1044 $have_intf = 0; # have interface?
1045 $have_hist = 0; # have revision history?
1046 $name_is = "UNKNOWN";
1047 }
1048
1049 sub check_if_all_there
1050 {
1051 $have_name ||
1052 die "ProTeX: invalid prologue, missing !ROUTINE: or !IROUTINE: in <$name_is>";
1053
1054 $have_desc ||
1055 die "ProTeX: invalid prologue, missing !DESCRIPTION: in <$name_is>";
1056
1057 $have_intf ||
1058 die "ProTeX: invalid prologue, missing !INTERFACE: in <$name_is>";
1059
1060 $have_hist ||
1061 die "ProTeX: invalid prologue, missing !REVISION HISTORY: in <$name_is>";
1062 }

  ViewVC Help
Powered by ViewVC 1.1.22