/[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.5 - (show annotations) (download)
Thu Apr 1 05:00:06 2004 UTC (19 years, 11 months ago) by edhill
Branch: MAIN
Changes since 1.4: +4 -3 lines
 o add sections

1 #! /usr/bin/env perl
2 #
3 # $Id: protex,v 1.4 2004/04/01 04:23:33 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 "\\subsection{%s (File: %s)}\n\n", $_, $FileBaseName;
424 }
425 else {
426 printf "\\subsection{%s}\n\n", $_;
427 printf "\n{\\sf FILE:} %s\n\\medskip\n", $FileBaseName;
428 }
429 $have_name = 1;
430 $not_first = 1;
431 next LINE;
432 }
433 }
434
435 # A new Module
436 if ($Fld[2] eq '!MODULE:' ) {
437 if ($prologue) {
438 shift @Fld;
439 shift @Fld;
440 $_ = join(' ', @Fld);
441 $name_is = $_;
442 s/_/\\_/g; # Replace "_" with "\_"
443 if ( $opt_n && $not_first ) { printf "\\newpage\n"; }
444 unless($opt_f) {
445 printf
446 "\\subsection{Fortran: Module Interface %s (File: %s)}\n\n",
447 $_, $FileBaseName;
448 }
449 else {
450 printf "\\subsection{Fortran: Module Interface %s }\n\n", $_;
451 }
452 $have_name = 1;
453 $have_intf = 1; # fake it, it does not need one.
454 $not_first = 1;
455 next LINE;
456 }
457 }
458
459 # A new include file
460 if ($Fld[2] eq '!INCLUDE:' ) {
461 if ($prologue) {
462 shift @Fld;
463 shift @Fld;
464 $_ = join(' ', @Fld);
465 $name_is = $_;
466 s/_/\\_/g; # Replace "_" with "\_"
467 if ( $opt_n && $not_first ) {
468 printf "\\newpage\n";
469 }
470 unless($opt_f) {
471 printf
472 "\\subsubsection{Include File %s (File: %s)}\n\n",
473 $_, $FileBaseName;}
474 else {
475 printf "\\subsubsection{Include File %s }\n\n", $_;
476 }
477 $have_name = 1;
478 $have_intf = 1; # fake it, it does not need one.
479 $not_first = 1;
480 next LINE;
481 }
482 }
483
484 # A new INTERNAL subroutine/function
485 if ($Fld[2] eq '!IROUTINE:') { # Internal routine
486 if ($prologue) {
487 shift @Fld;
488 shift @Fld;
489 $_ = join(' ', @Fld);
490 $name_is = $_;
491 s/_/\\_/g; # Replace "_" with "\_"
492 @words = split " ", $_;
493 printf "\\subsubsection [$words[1]] {$_}\n\n";
494 $have_name = 1;
495 next LINE;
496 }
497 }
498
499 # A new CLASS
500 if ($Fld[2] eq '!CLASS:' ) {
501 if ($prologue) {
502 shift @Fld;
503 shift @Fld;
504 $_ = join(' ', @Fld);
505 $name_is = $_;
506 s/_/\\_/g; # Replace "_" with "\_"
507 if ( $opt_n && $not_first ) { printf "\\newpage\n"; }
508 unless($opt_f) {
509 printf
510 "\\subsection{C++: Class Interface %s (File: %s)}\n\n",
511 $_, $FileBaseName;}
512 else {
513 printf "\\subsection{C++: Class Interface %s }\n\n", $_;
514 }
515 $have_name = 1;
516 $have_intf = 1; # fake it, it does not need one.
517 $not_first = 1;
518 next LINE;
519 }
520 }
521
522 # A new Method
523 if ($Fld[2] eq '!METHOD:' ) {
524 if ($prologue) {
525 shift @Fld;
526 shift @Fld;
527 $_ = join(' ', @Fld);
528 $name_is = $_;
529 s/_/\\_/g; # Replace "_" with "\_"
530 if ( $opt_n && $not_first ) { printf "\\newpage\n"; }
531 unless ($opt_f) {
532 printf "\\subsubsection{%s (File: %s)}\n\n", $_, $FileBaseName;
533 }
534 else {
535 printf "\\subsubsection{%s }\n\n", $_;
536 }
537 $have_name = 1;
538 $not_first = 1;
539 next LINE;
540 }
541 }
542
543 # A new function
544 if ($Fld[2] eq '!FUNCTION:' ) {
545 if ($prologue) {
546 shift @Fld;
547 shift @Fld;
548 $_ = join(' ', @Fld);
549 $name_is = $_;
550 s/_/\\_/g; # Replace "_" with "\_"
551 if ( $opt_n && $not_first ) {
552 printf "\\newpage\n";
553 }
554 unless ($opt_f) {
555 printf
556 "\\subsubsection{%s (File: %s)}\n\n",
557 $_, $FileBaseName;
558 }
559 else {
560 printf "\\subsubsection{%s }\n\n", $_;
561 }
562 $have_name = 1;
563 $not_first = 1;
564 next LINE;
565 }
566 }
567
568 # Description: what follows will be regular LaTeX (no verbatim)
569 if (/!DESCRIPTION:/) {
570 if ($prologue) {
571 if ($verb) {
572 &end_verbatim();
573 printf "\n{\\sf DESCRIPTION: }\n\\medskip\n";
574 }
575 else { # probably never occurs
576 }
577 if ($opt_x) {
578 &begin_verbatim();
579 $first_verb = 1;
580 }
581 else {
582 for ($i = 3; $i <= $#Fld; $i++) {
583 printf '%s ', $Fld[$i];
584 }
585 }
586 ### print " ";
587 $have_desc = 1;
588 next LINE;
589 }
590 }
591
592 # Handle optional keywords (these will appear as verbatim)
593 if ($prologue) {
594 KEY:
595 foreach $key ( @keys ) {
596 if ( /$key/ ) {
597 if ($verb) {
598 &end_verbatim();
599 }
600 else {
601 printf "\n\\medskip\n";
602 }
603 $k = sprintf('%s', $key);
604 $ln = length($k);
605 ###printf "\\subsubsection*{%s}\n", substr($k, 2, $ln - 1);
606 ###printf "{\\Large \\em %s}\n", ucfirst lc substr($k, 2, $ln - 1);
607 $_ = $key;
608 printf "{\\sf %s}\n", substr($k, 2, $ln - 1); # san serif
609 &begin_verbatim();
610 $first_verb = 1;
611 if ( $key eq "!INTERFACE:" ) { $have_intf = 1; }
612 if ( $key eq "!CALLING SEQUENCE:" ) { $have_intf = 1; }
613 if ( $key eq "!REVISION HISTORY:" ) { $have_hist = 1; }
614 next LINE;
615 }
616 }
617 }
618
619 # End of prologue
620 if ($Fld[1] eq $eop_string) {
621 if ($verb) {
622 &end_verbatim();
623 }
624 $prologue = 0;
625 # &check_if_all_there(); # check if all required keywords are there.
626 if ( $opt_l ) {
627 $Fld[1] = $boc_string;}
628 else {
629 next LINE;
630 }
631 }
632
633 unless ( $opt_s ) {
634
635 # End of Internal Prologue
636 if ($Fld[1] eq $eopi_string) {
637 if ($verb) {
638 &end_verbatim();
639 }
640 $prologue = 0;
641 # &check_if_all_there(); # check if all required keywords are there.
642 if ($opt_l) {
643 $Fld[1] = $boc_string;}
644 else { next LINE; }
645 }
646
647 # Beginning of source code section
648 if ($Fld[1] eq $boc_string) {
649 print ' ';
650 print '%/////////////////////////////////////////////////////////////';
651 $first = 0;
652 $prologue = 0;
653 $source = 1;
654 ### printf "\\subsubsection*{CONTENTS:}\n\n", $Fld[3];
655 printf "{\\sf CONTENTS:}";
656 &begin_verbatim();
657 next LINE;
658 }
659
660 # End of source code
661 if ($Fld[1] eq $eoc_string) {
662 &do_eoc();
663 $prologue = 0;
664 next LINE;
665 }
666 }
667
668 # Prologue or Introduction, print regular line (except for !)
669 if ($prologue||$intro) {
670 if ( $verb && $#Fld == 1 && ( $Fld[1] eq $comment_string ) ) {
671 next LINE; # to eliminate excessive blanks
672 }
673 if ( $Fld[2] eq "\\ev" ) {
674 # special handling
675 $_ = $comment_string . " \\end{verbatim}";
676 }
677 s/^$comment_string/ /; # replace comment string with blank
678 # $line = sprintf('%s', $_); # not necessary -- comment str is absent
679 # $ln = length($line); # not necessary -- comment str is absent
680 unless ( $first_verb ) { printf "\n "; }
681 printf '%s', $_;
682 # printf '%s', substr($line, 1, $ln - 1); # comment str is absent
683 $first_verb = 0;
684 next LINE;
685 }
686
687 # Source code: print the full line
688 if ($source) {
689 print $_;
690 next LINE;
691 }
692
693 } # end inner loop for processing each line of the input file
694
695 } # end main loop for each command-line argument
696
697 print $_;
698 if ( $source ) { &do_eoc(); }
699 print '%...............................................................';
700
701 # see comment above where these are originally set.
702 #print "\\setlength{\\parskip}{\\oldparskip}";
703 #print "\\setlength{\\parindent}{\\oldparindent}";
704 #print "\\setlength{\\baselineskip}{\\oldbaselineskip}";
705
706 unless ( $opt_b ) {
707 print "\\end{document}";
708 }
709
710
711 #----------------------------------------------------------------------
712
713 sub begin_verbatim
714 {
715 printf "\n{\\footnotesize \\begin{verbatim} ";
716 $verb = 1;
717 return 0;
718 }
719
720 sub end_verbatim
721 {
722 printf "\\end{verbatim} }";
723 $verb = 0;
724 return 0;
725 }
726
727 sub CheckOpts
728 {
729 # Checks options against a given list. Outputs error message
730 # for any invalid option.
731 #
732 # Usage:
733 # $rc = &CheckOpts ( options, valid_reg_options,
734 # valid_sw_options,
735 # quiet_mode )
736 #
737 # character: options - options to be checked. (e.g. -df+x) The
738 # list must begin with a positive or
739 # negative sign. If no sign appears at the
740 # beginning or by itself, then the argument
741 # is not recognized as a list of options.
742 # character: valid_reg_options - list of valid regular options.
743 # (i.e. options that are associated only
744 # eith negative sign.)
745 # character: valid_sw_options - list of valid switch options.
746 # (i.e. options that can be associated with
747 # either a positive or negative sign.
748 # logical: quiet mode (optional) If true then print no error
749 # messages.
750 # integer: rc - return code
751 # = -1 if the arguement, options, is
752 # not recognized as a list of options
753 # = 0 if all options are valid.
754 # > 0 for the number of invalid options.
755
756 local($options,
757 $valid_reg_options,
758 $valid_sw_options,
759 $quiet_mode ) = @_;
760
761 if ( $options eq "+" ||
762 $options eq "-" ) {return -1}
763
764 local(@Options) = split( / */, $options );
765 if ( $Options[ $[ ] ne "-" &&
766 $Options[ $[ ] ne "+" ) {return -1;}
767
768 local($option, $option_sign, $valid_list, $pos);
769 local($errs) = 0;
770 foreach $option ( @Options ) {
771 if ( $option eq "-" ||
772 $option eq "+" ) {$option_sign = $option;}
773 else {
774 if ( $option_sign eq "-" ) {
775 $valid_list = $valid_reg_options
776 . $valid_sw_options;
777 }
778 else {
779 $valid_list = $valid_sw_options;
780 }
781 $pos = index ($valid_list,$option);
782 if ( $pos < $[ &&
783 $quiet_mode ) {
784 $errs++;
785 print STDERR "Invalid option: $option_sign$option \n";
786
787 }
788 }
789 }
790 return $errs;
791 }
792
793
794 sub GetOpts
795 {
796 # Gets options. If an option is valid, then opt_[option] is
797 # set to 0 or 1 as a side effect if the option is preceeded by
798 # a positive or negative sign.
799 #
800 # Usage:
801 # $rc = &GetOpts ( options, valid_options )
802 #
803 # character: options - options to be checked. (e.g. -df+x) The
804 # list must begin with a positive or
805 # negative sign. If no sign appears at the
806 # beginning or by itself, then the argument
807 # is not recognized as a list of options.
808 # character: valid_options - list of valid options (e.g. dfhx)
809 # integer: rc - return code
810 # = -1 if the arguement, options, is
811 # not recognized as a list of options.
812 # = 0 otherwise
813
814 local($options,$valid_options) = @_;
815
816 if ( $options eq "+" ||
817 $options eq "-" ) {return -1}
818
819 local(@Options) = split( / */, $options );
820 if ( $Options[ $[ ] ne "-" &&
821 $Options[ $[ ] ne "+" ) {return -1;}
822
823 local($option, $option_sign);
824
825 foreach $option ( @Options ) {
826
827 if ( $option eq "-" ||
828 $option eq "+" ) {
829 $option_sign = $option; }
830
831 else {
832
833 if ( index ($valid_options,$option) >= $[ ) {
834 if ( $option_sign eq "-" ) {${"opt_$option"} = 1;}
835 if ( $option_sign eq "+" ) {${"opt_$option"} = 0;};
836
837 }
838 }
839 }
840 return 0;
841 }
842
843
844 sub SetOpt
845 {
846 # Sets option flags. For the last input option that is in a
847 # list, the flag opt_[option] is set to 1 as a side effect.
848 # For all other options in the list, opt_[option] is set to 0.
849 #
850 # Usage:
851 # $rc = &SetOpt ( options, valid_options )
852 #
853 # character: options - options to be checked. (e.g. -df+x) The
854 # list must begin with a positive or
855 # negative sign. If no sign appears at the
856 # beginning or by itself, then the argument
857 # is not recognized as a list of options.
858 # character: valid_options - list of valid options (e.g. def )
859 # integer: rc - return code
860 # = -1 if the arguement, options, is
861 # not recognized as a list of options.
862 # = 0 otherwise
863 # Note: For the examples provided for the input arguments,
864 # $opt_d = 0, $opt_e = 0, and $opt_f = 1, since the
865 # input option, -f, was the last in the argument,
866 # option.
867
868 local($options,$valid_options) = @_;
869
870 if ( $options eq "+" ||
871 $options eq "-" ) {return -1}
872
873 local(@Options) = split( / */, $options );
874 local(@ValidOptions) = split( / */, $valid_options );
875 if ( $Options[ $[ ] ne "-" &&
876 $Options[ $[ ] ne "+" ) {return -1;}
877
878 local($option, $option_sign);
879
880 foreach $option ( @Options ) {
881 if ( $option ne "-" &&
882 $option ne "+" ) {
883
884 if ( index ($valid_options,$option) >= $[ ) {
885 foreach $valid_option (@ValidOptions ) {
886 ${"opt_$valid_option"} = 0;
887
888 }
889 ${"opt_$option"} = 1;
890 }
891 }
892 }
893 return 0;
894 }
895
896
897 sub print_help
898 {
899 print "Usage: protex [-hbACFS] [+-nlsxf] [src_file(s)]";
900 print " ";
901 print " Options:";
902 print " -h Help mode: list command line options";
903 print " -b Bare mode, meaning no preamble, etc.";
904 print " +-n New Page for each subsection (wastes paper)";
905 print " +-l Listing mode, default is prologues only";
906 print " +-s Shut-up mode, i.e., ignore any code from BOC to EOC";
907 print " +-x No LaTeX mode, i.e., put !DESCRIPTION: in verbatim mode";
908 print " +-f No source file info";
909 print " -A Ada code";
910 print " -C C++ code";
911 print " -F F90 code";
912 print " -7 F77 code";
913 print " -S Shell script";
914 print " ";
915 print " The options can appear in any order. The options, -h and -b,";
916 print " affect the input from all files listed on command-line input.";
917 print " Each of the remaining options effects only the input from the";
918 print " files listed after the option and prior to any overriding";
919 print " option. The plus sign turns off the option.";
920 }
921
922 sub print_notice
923 {
924 print "% **** IMPORTANT NOTICE *****" ;
925 print "% This LaTeX file has been automatically produced by ProTeX v. 1.1";
926 print "% Any changes made to this file will likely be lost next time";
927 print "% this file is regenerated from its source. Send questions ";
928 print "% to Arlindo da Silva, dasilva\@gsfc.nasa.gov";
929 print " ";
930 }
931
932 sub print_preamble
933 {
934 unless ( $opt_b ) {
935 print "%------------------------ PREAMBLE --------------------------";
936 print "\\documentclass[11pt]{article}";
937 print "\\usepackage{amsmath}";
938 print "\\usepackage{epsfig}";
939 print "\\usepackage{hangcaption}";
940 print "\\textheight 9in";
941 print "\\topmargin 0pt";
942 print "\\headsep 1cm";
943 print "\\headheight 0pt";
944 print "\\textwidth 6in";
945 print "\\oddsidemargin 0in";
946 print "\\evensidemargin 0in";
947 print "\\marginparpush 0pt";
948 print "\\pagestyle{myheadings}";
949 print "\\markboth{}{}";
950 print "%-------------------------------------------------------------";
951 }
952
953 # in your main document before you include any protex-generated files
954 # for the first time, if you define these three variables as length
955 # settings (like this:)
956 # \newlength{\oldparskip}
957 # \newlength{\oldparindent}
958 # \newlength{\oldbaselineskip}
959 # then 1) comment in all the lines below, and 2) find the 3 reset lines
960 # further down and comment in them as well.
961 # then protex will override the paragraph and skip settings during
962 # the source sections, but will restore the original document settings
963 # at the end. if someone can figure out how to check to see if a
964 # latex variable exists, and do a conditional section, we could make
965 # this fully self-contained.
966 # nsc feb 2003
967
968 #print "\\setlength{\\oldparskip}{\\parskip}";
969 print "\\setlength{\\parskip}{0pt}";
970 #print "\\setlength{\\oldparindent}{\\parindent}";
971 print "\\setlength{\\parindent}{0pt}";
972 #print "\\setlength{\\oldbaselineskip}{\\baselineskip}";
973 print "\\setlength{\\baselineskip}{11pt}";
974 }
975
976
977 sub print_macros
978 {
979 print " ";
980 print "%--------------------- SHORT-HAND MACROS ----------------------";
981 print "\\def\\bv{\\begin{verbatim}}";
982 print "\\def\\ev\{\\end\{verbatim}}";
983 print "\\def\\be{\\begin{equation}}";
984 print "\\def\\ee{\\end{equation}}";
985 print "\\def\\bea{\\begin{eqnarray}}";
986 print "\\def\\eea{\\end{eqnarray}}";
987 print "\\def\\bi{\\begin{itemize}}";
988 print "\\def\\ei{\\end{itemize}}";
989 print "\\def\\bn{\\begin{enumerate}}";
990 print "\\def\\en{\\end{enumerate}}";
991 print "\\def\\bd{\\begin{description}}";
992 print "\\def\\ed{\\end{description}}";
993 print "\\def\\({\\left (}";
994 print "\\def\\){\\right )}";
995 print "\\def\\[{\\left [}";
996 print "\\def\\]{\\right ]}";
997 print "\\def\\<{\\left \\langle}";
998 print "\\def\\>{\\right \\rangle}";
999 print "\\def\\cI{{\\cal I}}";
1000 print "\\def\\diag{\\mathop{\\rm diag}}";
1001 print "\\def\\tr{\\mathop{\\rm tr}}";
1002 print "%-------------------------------------------------------------";
1003 }
1004
1005
1006 sub do_beg
1007 {
1008 unless ( $opt_b ) {
1009 if ( $begdoc == 0 ) {
1010 if ( $tpage ) {
1011 print "\\title{@title}";
1012 print "\\author{{\\sc @author}\\\\ {\\em @affiliation}}";
1013 print "\\date{@date}";
1014 }
1015 print "\\begin{document}";
1016 if ( $tpage ) {
1017 print "\\maketitle";
1018 }
1019 print "\\tableofcontents";
1020 print "\\newpage";
1021 $begdoc = 1;
1022 }
1023 }
1024 }
1025
1026 sub do_eoc
1027 {
1028 print ' ';
1029 if ($verb) {
1030 &end_verbatim();
1031 }
1032 $source = 0;
1033 }
1034
1035
1036 sub set_missing
1037 {
1038 $have_name = 0; # have routine name?
1039 $have_desc = 0; # have description?
1040 $have_intf = 0; # have interface?
1041 $have_hist = 0; # have revision history?
1042 $name_is = "UNKNOWN";
1043 }
1044
1045 sub check_if_all_there
1046 {
1047 $have_name ||
1048 die "ProTeX: invalid prologue, missing !ROUTINE: or !IROUTINE: in <$name_is>";
1049
1050 $have_desc ||
1051 die "ProTeX: invalid prologue, missing !DESCRIPTION: in <$name_is>";
1052
1053 $have_intf ||
1054 die "ProTeX: invalid prologue, missing !INTERFACE: in <$name_is>";
1055
1056 $have_hist ||
1057 die "ProTeX: invalid prologue, missing !REVISION HISTORY: in <$name_is>";
1058 }

  ViewVC Help
Powered by ViewVC 1.1.22