Back to home page

MITgcm

 
 

    


Warning, /doc/old_doc/api_reference/protex is written in an unsupported language. File is not indexed.

view on githubraw file Latest commit ad38444b on 2018-01-31 20:35:48 UTC
cedb4b86df Ed H*0001 #! /usr/bin/env perl
                0002 #
                0003 #
                0004 #BOP
                0005 #
                0006 # !ROUTINE: ProTeX v. 2.00 - Translates DAO Prologues to LaTeX
                0007 #
                0008 # !INTERFACE:
                0009 #         protex [-hbACFS7] ] [+-nlsxf] [src_file(s)]
                0010 #
                0011 # !DESCRIPTION:
                0012 #         Perl filter to produce a \LaTeX compatible document 
                0013 #         from a DAO Fortran source code with standard Pro\TeX 
                0014 #         prologues. If source files are not specified it
                0015 #         reads from stdin; output is always to stdout.
                0016 # 
                0017 # \noindent        
                0018 # {\bf Command Line Switches:} \vspace{0.2cm}
                0019 #
                0020 # \begin{center}
                0021 # \begin{tabular}{|c|l|} \hline \hline
5eef09f930 Ed H*0022 #   -h    & Help mode: list command line options   \\ \hline
                0023 #   -b    & Bare mode, meaning no preamble, etc.  \\ \hline
                0024 #   -i    & internal mode: omit prologues marked !BOPI  \\ \hline
                0025 #   +/-n  & New Page for each subsection (wastes paper) \\ \hline
                0026 #   +/-l  & Listing mode, default is prologues only \\ \hline
                0027 #   +/-s  & Shut-up mode, i.e., ignore any code from BOC to EOC \\ \hline
                0028 #   +/-x  & No LaTeX mode, i.e., put !DESCRIPTION: in verbatim mode \\ \hline
                0029 #   +/-f  & No source file info \\ \hline
                0030 #   -A    & Ada code \\ \hline
                0031 #   -C    & C++ code \\ \hline
                0032 #   -F    & F90 code (default) \\ \hline
                0033 #   -7    & F77 code \\ \hline
                0034 #   -S    & Shell script \\ \hline \hline
                0035 #   -v    & Verbosity level (default=99) \\ \hline \hline
cedb4b86df Ed H*0036 # \end{tabular}
                0037 # \end{center}
                0038 #
                0039 # The options can appear in any order.  The options, -h and -b, affect
                0040 # the input from all files listed on command-line input.  Each of the
                0041 # remaining options effects only the input from the files listed after
                0042 # the option and prior to any overriding option.  The plus sign
                0043 # turns off the option.  For example, the command-line input,
                0044 # \bv
                0045 #      protex -bnS File1 -F File2.f +n File3.f
                0046 # \ev
                0047 # will cause the option, {\tt -n} to affect the input from the files,
                0048 # {\tt File} and {\tt File2.f}, but not from {\tt File3.f}.  The
                0049 # {\tt -S} option is implemented for {\tt File1} but is overridden by
                0050 # the {\tt -F} for files {\tt File2.f} and {\tt File3.f}.
                0051 #
                0052 #
                0053 # !SEE ALSO:
                0054 #         For a more detailed description of ProTeX functionality,
                0055 #         DAO Prologue and other conventions, consult:
                0056 #
                0057 #           Sawyer, W., and A. da Silva, 1997: ProTeX: A Sample 
                0058 #           Fortran 90 Source Code Documentation System.
                0059 #           DAO Office Note 97-11
                0060 #         
                0061 #
                0062 # !REVISION HISTORY:
                0063 #
                0064 #  20Dec1995  da Silva  First experimental version
                0065 #  10Nov1996  da Silva  First internal release (v1.01)
                0066 #  28Jun1997  da Silva  Modified so that !DESCRIPTION can appear after
                0067 #             !INTERFACE, and !INPUT PARAMETERS etc. changed to italics.
                0068 #  02Jul1997  Sawyer    Added shut-up mode
                0069 #  20Oct1997  Sawyer    Added support for shell scripts
                0070 #  11Mar1998  Sawyer    Added: file name, date in header, C, script support
                0071 #  05Aug1998  Sawyer    Fixed LPChang-bug-support-for-files-with-underscores
                0072 #  10Oct1998  da Silva  Introduced -f option for removing source file info
                0073 #                       from subsection, etc.  Added help (WS).
                0074 #  06Dec1999  C. Redder Added LaTeX command "\label{sec:prologues}" just 
                0075 #                       after the beginning of the proglogue section.
                0076 #  13Dec1999  C. Redder Increased flexbility in command-line
                0077 #                       interface.  The options can appear in any
                0078 #                       order which will allow the user to implement
                0079 #                       options for select files.
                0080 #  01Feb1999  C. Redder Added \usepackage commands to preamble of latex
                0081 #                       document to include the packages amsmath, epsfig
                0082 #                       and hangcaption.
                0083 #  10May2000  C. Redder Revised LaTeX command "\label{sec:prologues}"
                0084 #                       to "\label{app:ProLogues}"
                0085 #  10/10/2002 da Silva  Introduced ARGUMENTS keyword, touch ups.
                0086 #
                0087 #  15Jan2003  R. Staufer  Modified table of contents to print only section headers - no descriptions
                0088 #
                0089 #  25Feb2003  R. Staufer  Added BOPI/EOPI and -i (internal) switch to provide the option of omitting prologue information from output files.
                0090 #
                0091 #EOP
                0092 #----------------------------------------------------------------------------
                0093 
                0094 # Keep this if you don't know what it does...
                0095 # -------------------------------------------
1b5fb69d21 Ed H*0096 $[ = 1;                 # set array base to 1
                0097 $, = ' ';               # set output field separator
                0098 $\ = "\n";              # set output record separator
cedb4b86df Ed H*0099 
                0100 # Set valid options lists
                0101 # -----------------------
5eef09f930 Ed H*0102 $GlobOptions = 'hbv';    # Global options (i.e for all files)
1b5fb69d21 Ed H*0103 $LangOptions = 'ACFS7';  # Options for setting programming languages
                0104 $SwOptions   = 'flinsx'; # Options that can change for each input  file
                0105 $RegOptions  = "$GlobOptions$LangOptions";
cedb4b86df Ed H*0106                           # Scan for global options until first first
                0107                           #   file is processed.
                0108 
                0109 # Scan for global options
                0110 # -----------------------
1b5fb69d21 Ed H*0111 $NFiles = 0;
5eef09f930 Ed H*0112  Arg: foreach $arg (@ARGV) {
                0113      $option = &CheckOpts ( $arg, $RegOptions, $SwOptions ) + 1;
                0114      if ( $option ) {
                0115          $rc = &GetOpts    ( $arg, $GlobOptions );
                0116          next Arg;
                0117      }
                0118      else {
                0119          $NFiles++;
                0120      }
                0121  }
cedb4b86df Ed H*0122 
                0123 # If all input arguments are options, then assume the
                0124 # filename, "-", for the standard input
                0125 # --------------------------------------------------
1b5fb69d21 Ed H*0126 if ( $NFiles == 0 ) { push (@ARGV, "-"); } 
cedb4b86df Ed H*0127 
                0128 # Implement help option
                0129 # ---------------------
1b5fb69d21 Ed H*0130 if ( $opt_h ) {
                0131     &print_help();
                0132     exit();
                0133 }
cedb4b86df Ed H*0134 
                0135 # Optional Prologue Keywords
                0136 # --------------------------
1b5fb69d21 Ed H*0137 @keys = ( "!INTERFACE:",
                0138           "!USES:",
                0139           "!PUBLIC TYPES:",
                0140           "!PRIVATE TYPES:",
                0141           "!PUBLIC MEMBER FUNCTIONS:",
                0142           "!PRIVATE MEMBER FUNCTIONS:",
                0143           "!PUBLIC DATA MEMBERS:",
                0144           "!PARAMETERS:",
                0145           "!ARGUMENTS:",
                0146           "!DEFINED PARAMETERS:",
                0147           "!INPUT PARAMETERS:",
                0148           "!INPUT/OUTPUT PARAMETERS:",
                0149           "!OUTPUT PARAMETERS:",
                0150           "!RETURN VALUE:",
                0151           "!REVISION HISTORY:",
                0152           "!BUGS:",
                0153           "!SEE ALSO:",
                0154           "!SYSTEM ROUTINES:",
                0155           "!FILES USED:",
                0156           "!REMARKS:",
                0157           "!TO DO:",
                0158           "!CALLING SEQUENCE:",
                0159           "!AUTHOR:",
                0160           "!CALLED FROM:",
                0161           "!LOCAL VARIABLES:" );
cedb4b86df Ed H*0162 
                0163 # Initialize these for clarity
                0164 # ----------------------------
1b5fb69d21 Ed H*0165 $intro = 0;             # doing introduction?
                0166 $prologue = 0;          # doing prologue?
                0167 $first = 1;             # first prologue?
                0168 $source = 0;            # source code mode?
                0169 $verb = 0;              # verbatim mode?
                0170 $tpage = 0;             # title page?
                0171 $begdoc = 0;            # has \begin{document} been written?
cedb4b86df Ed H*0172 
                0173 # Initial LaTeX stuff
                0174 # -------------------
1b5fb69d21 Ed H*0175 &print_notice();
                0176 &print_preamble();      # \documentclass, text dimensions, etc.
                0177 &print_macros();        # short-hand LaTeX macros
cedb4b86df Ed H*0178 
                0179 # Main loop -- for each command-line argument
                0180 # -------------------------------------------
5eef09f930 Ed H*0181  ARG: foreach $arg (@ARGV) {
                0182      
                0183      # Scan for non-global command-line options
                0184      $option = &CheckOpts ( $arg, $RegOptions, $SwOptions, "quiet" ) + 1;
                0185      if ( $option ) {
                0186          &GetOpts  ( $arg, $SwOptions   );
                0187          &SetOpt   ( $arg, $LangOptions );
                0188          next ARG;
                0189      }
                0190      
                0191      # Determine the type of code, set corresponding search strings
                0192      $comment_string = '!';  # DEFAULT is FORTRAN
                0193      $boi_string = '!BOI';
                0194      $eoi_string = '!EOI';
                0195      $bop_string = '!BOP';
                0196      $eop_string = '!EOP';
                0197      $bopi_string = '!BOPI';
                0198      $eopi_string = '!EOPI';
                0199      $boc_string = '!BOC';
                0200      $eoc_string = '!EOC';
                0201      
                0202      if ( $opt_7 ) {            # f77
                0203          $comment_string = 'C';
                0204          $boi_string = 'CBOI';
                0205          $eoi_string = 'CEOI';
                0206          $bop_string = 'CBOP';
                0207          $eop_string = 'CEOP';
                0208          $bopi_string = 'CBOPI';
                0209          $eopi_string = 'CEOPI';
                0210          $boc_string = 'CBOC';
                0211          $eoc_string = 'CEOC';
                0212      }
                0213      
                0214      if ( $opt_A ) {            # ADA
                0215          $comment_string = '--';
                0216          $boi_string = '--BOI';
                0217          $eoi_string = '--EOI';
                0218          $bop_string = '--BOP';
                0219          $eop_string = '--EOP';
                0220          $bopi_string = '--BOPI';
                0221          $eopi_string = '--EOPI';
                0222          $boc_string = '--BOC';
                0223          $eoc_string = '--EOC';
                0224      }
                0225      
                0226      if ( $opt_C ) {
                0227          $comment_string = '//'; # C 
                0228          $boi_string = '//BOI';
                0229          $eoi_string = '//EOI';
                0230          $bop_string = '//BOP';
                0231          $eop_string = '//EOP';
                0232          $bopi_string = '//BOPI';
                0233          $eopi_string = '//EOPI';
                0234          $boc_string = '//BOC';
                0235          $eoc_string = '//EOC';
                0236      }
                0237      
                0238      if ( $opt_S ) {            # Script
                0239          $comment_string = '#';
                0240          $boi_string = '#BOI';
                0241          $eoi_string = '#EOI';
                0242          $bop_string = '#BOP';
                0243          $eop_string = '#EOP';
                0244          $bopi_string = '#BOPI'; 
                0245          $eopi_string = '#EOPI';
                0246          $boc_string = '#BOC';
                0247          $eoc_string = '#EOC';
                0248      }
                0249      
                0250      # Set file name parameters
                0251      $InputFile           = $arg;
                0252      @all_path_components = split( /\//, $InputFile     );
                0253      $FileBaseName        = pop  ( @all_path_components );
                0254      $FileBaseName        =~ s/_/\\_/g;
                0255      if ( $InputFile eq "-" ) {$FileBaseName = "Standard Input";}
                0256      
                0257      # Set date
                0258      $Date                = `date`;
                0259      
                0260      # Open current file
                0261      open ( InputFile, "$InputFile" )
                0262          or print STDERR "Unable to open $InputFile: $!";
                0263      
                0264      # Print page header
                0265      chomp($Date);
                0266      # printf "\n\\markboth{Left}{Source File: %s,  Date: %s}\n\n", 
                0267      printf "\n\\markboth{Source File: %s}{Date: %s}\n\n", 
                0268      $FileBaseName, $Date;
                0269      
                0270      # Inner loop --- for processing each line of the input file
                0271    LINE: while ( <InputFile> ) {
                0272        chop;     # strip record separator
                0273        
                0274        @Fld = split(' ', $_, 9999);
                0275        
                0276        # Straight quote
                0277        if ($Fld[1] eq '!QUOTE:') {
                0278            for ($i = 2; $i <= $#Fld; $i++) {
                0279                printf '%s ', $Fld[$i];
                0280            }
                0281            print " ";
                0282            next LINE;
                0283        }
                0284        
                0285        # Handle optional Title Page and Introduction
                0286        if ($Fld[1] eq $boi_string) {
                0287            print ' ';
                0288            $intro = 1;
                0289            next LINE;
                0290        }
                0291        
                0292        if ($Fld[2] eq '!TITLE:') {
                0293            if ( $intro ) {
                0294                shift @Fld;
                0295                shift @Fld;
                0296                @title = @Fld;
                0297                $tpage = 1;
                0298                next LINE;
                0299            }
                0300        }
                0301        
                0302        if ($Fld[2] eq '!AUTHORS:') {
                0303            if ( $intro ) {
                0304                shift @Fld;
                0305                shift @Fld;
                0306                @author = @Fld;
                0307                $tpage = 1;
                0308                next LINE;
                0309            }
                0310        }
                0311 
                0312        if ($Fld[2] eq '!AFFILIATION:') {
                0313            if ( $intro ) {
                0314                shift @Fld;
                0315                shift @Fld;
                0316                @affiliation = @Fld;
                0317                $tpage = 1;
                0318                next LINE;
                0319            }
                0320        }
                0321 
                0322        if ($Fld[2] eq '!DATE:') {
                0323            if ( $intro ) {
                0324                shift @Fld;
                0325                shift @Fld;
                0326                @date = @Fld;
                0327                $tpage = 1;
                0328                next LINE;
                0329            }
                0330        }
                0331        
                0332        if ($Fld[2] eq '!INTRODUCTION:') {
                0333            if ( $intro ) {
                0334                &do_beg();
                0335                print ' ';
                0336                print '%..............................................';
                0337                shift @Fld;
                0338                shift @Fld;
                0339                print "\\section{@Fld}";
                0340                next LINE;
                0341            }
                0342        }
                0343        
                0344        
                0345        # End of introduction
                0346        if ($Fld[1] eq $eoi_string) {
                0347            print ' ';
                0348            print '%/////////////////////////////////////////////////////////////';
                0349            print "\\newpage";
                0350            $intro = 0;
                0351            next LINE;
                0352        }
                0353        
                0354        # Beginning of prologue
                0355        if ( ($Fld[1] eq $bop_string) 
                0356             && (($Fld[2] eq "") || ($Fld[2] <= $opt_v)) )  {
                0357            if ( $source ) { &do_eoc(); }
                0358            print ' ';
                0359            print '%/////////////////////////////////////////////////////////////'; 
                0360            &do_beg();
                0361            $first = 0;
                0362            if ($first == 0) {
                0363                print " ";
                0364                print "\\mbox{}\\hrulefill\\ ";
                0365                print " ";}
                0366            else {
                0367                unless($opt_b){
                0368                    print 
                0369                        "\\section{Routine/Function Prologues} \\label{app:ProLogues}";
                0370                }
                0371            }
                0372            $first = 0;
                0373            $prologue = 1;
                0374            $verb = 0;
                0375            $source = 0;
                0376            &set_missing();   # no required keyword yet
                0377            next LINE;
                0378        }
                0379        
                0380        # Beginning of internal prologue
                0381        if ( ($Fld[1] eq $bopi_string)) {
                0382            if ($opt_i) {$prologue = 0;}
                0383            else {
                0384                if ($source) { &do_eoc(); }
                0385                print ' ';
                0386                print '%/////////////////////////////////////////////////////////////';  
                0387                &do_beg();
                0388                if ($first ==0) {
                0389                    ### print "\\newpage";
                0390                    print " ";
                0391                    print "\\mbox{}\\hrulefill\\";
                0392                    print " ";}
                0393                else {
                0394                    unless($opt_b) {
                0395                        print 
                0396                            "\\section{Routine/Function Prologues} \\label{app:ProLogues}";
                0397                    }
                0398                }
                0399                $first = 0;
                0400                $prologue = 1;
                0401                $verb = 0;
                0402                $source = 0;
                0403                &set_missing();    # no required keyword yet
                0404                next LINE;
                0405            }
                0406        }
                0407        
                0408        # A new subroutine/function
                0409        if ($Fld[2] eq '!ROUTINE:' ) { 
                0410            if ($prologue) {
                0411                shift @Fld;
                0412                shift @Fld;
                0413                $_ = join(' ', @Fld);
                0414                $name_is = $_;
                0415                s/_/\\_/g;
                0416                # Replace "_" with "\_"
                0417                if ( $opt_n && $not_first ) {
                0418                    printf "\\newpage\n";
                0419                }
                0420                unless ($opt_f) {
                0421                    printf "\\subsection{%s (File: %s)}\n\n", $_, $FileBaseName;
                0422                }
                0423                else {
                0424                    printf "\\subsection{%s}\n\n", $_;
                0425                    printf "\n{\\sf FILE:} %s\n\\medskip\n", $FileBaseName;
                0426                }
                0427                $have_name = 1;
                0428                $not_first = 1;
                0429                next LINE;
                0430            }
                0431        }
                0432        
                0433        # A new Module
                0434        if ($Fld[2] eq '!MODULE:' ) { 
                0435            if ($prologue) {
                0436                shift @Fld;
                0437                shift @Fld;
                0438                $_ = join(' ', @Fld);
                0439                $name_is = $_;
                0440                s/_/\\_/g;                         # Replace "_" with "\_"
                0441                if ( $opt_n && $not_first ) { printf "\\newpage\n"; }
                0442                unless($opt_f) {
                0443                    printf 
                0444                        "\\subsection{Fortran:  Module Interface %s (File: %s)}\n\n", 
                0445                        $_, $FileBaseName;
                0446                }
                0447                else {
                0448                    printf "\\subsection{Fortran:  Module Interface %s }\n\n", $_;
                0449                }
                0450                $have_name = 1;
                0451                $have_intf = 1;  # fake it, it does not need one.
                0452                $not_first = 1;
                0453                next LINE;
                0454            }
                0455        }
                0456        
                0457        # A new include file
                0458        if ($Fld[2] eq '!INCLUDE:' ) { 
                0459            if ($prologue) {
                0460                shift @Fld;
                0461                shift @Fld;
                0462                $_ = join(' ', @Fld);
                0463                $name_is = $_;
                0464                s/_/\\_/g;                         # Replace "_" with "\_"
                0465                if ( $opt_n && $not_first ) {
                0466                    printf "\\newpage\n";
                0467                }
                0468                unless($opt_f) {
                0469                    printf 
                0470                        "\\subsubsection{Include File %s (File: %s)}\n\n", 
                0471                        $_, $FileBaseName;}
                0472                else {
                0473                    printf "\\subsubsection{Include File %s }\n\n", $_;
                0474                }  
                0475                $have_name = 1;
                0476                $have_intf = 1;  # fake it, it does not need one.
                0477                $not_first = 1;
                0478                next LINE;
                0479            }
                0480        }
                0481        
                0482        # A new INTERNAL subroutine/function
                0483        if ($Fld[2] eq '!IROUTINE:') {            # Internal routine
                0484            if ($prologue) {
                0485                shift @Fld;
                0486                shift @Fld;
                0487                $_ = join(' ', @Fld);
                0488                $name_is = $_;
                0489                s/_/\\_/g;                        # Replace "_" with "\_"
                0490                @words = split " ", $_;
                0491                printf "\\subsubsection [$words[1]] {$_}\n\n";
                0492                $have_name = 1;
                0493                next LINE;
                0494            }
                0495        }
                0496        
                0497        # A new CLASS
                0498        if ($Fld[2] eq '!CLASS:' ) { 
                0499            if ($prologue) {
                0500                shift @Fld;
                0501                shift @Fld;
                0502                $_ = join(' ', @Fld);
                0503                $name_is = $_;
                0504                s/_/\\_/g;                         # Replace "_" with "\_"
                0505                if ( $opt_n && $not_first ) { printf "\\newpage\n"; }
                0506                unless($opt_f) {
                0507                    printf 
                0508                        "\\subsection{C++:  Class Interface %s (File: %s)}\n\n", 
                0509                        $_, $FileBaseName;}
                0510                else {
                0511                    printf "\\subsection{C++:  Class Interface %s }\n\n", $_;
                0512                }
                0513                $have_name = 1;
                0514                $have_intf = 1;  # fake it, it does not need one.
                0515                $not_first = 1;
                0516                next LINE;
                0517            }
                0518        }
                0519        
                0520        # A new Method
                0521        if ($Fld[2] eq '!METHOD:' ) { 
                0522            if ($prologue) {
                0523                shift @Fld;
                0524                shift @Fld;
                0525                $_ = join(' ', @Fld);
                0526                $name_is = $_;
                0527                s/_/\\_/g;                         # Replace "_" with "\_"
                0528                if ( $opt_n && $not_first ) { printf "\\newpage\n"; }
                0529                unless ($opt_f) {
                0530                    printf "\\subsubsection{%s (File: %s)}\n\n", $_, $FileBaseName;
                0531                }
                0532                else {
                0533                    printf "\\subsubsection{%s }\n\n", $_;
                0534                }
                0535                $have_name = 1;
                0536                $not_first = 1;
                0537                next LINE;
                0538            }
                0539        }
                0540        
                0541        # A new function
                0542        if ($Fld[2] eq '!FUNCTION:' ) { 
                0543            if ($prologue) {
                0544                shift @Fld;
                0545                shift @Fld;
                0546                $_ = join(' ', @Fld);
                0547                $name_is = $_;
                0548                s/_/\\_/g;                         # Replace "_" with "\_"
                0549                if ( $opt_n && $not_first ) {
                0550                    printf "\\newpage\n";
                0551                }
                0552                unless ($opt_f) {
                0553                    printf 
                0554                        "\\subsubsection{%s (File: %s)}\n\n",
                0555                        $_, $FileBaseName;
                0556                }
                0557                else {
                0558                    printf "\\subsubsection{%s }\n\n", $_;
                0559                }
                0560                $have_name = 1;
                0561                $not_first = 1;
                0562                next LINE;
                0563            }
                0564        }
                0565        
                0566        # Description: what follows will be regular LaTeX (no verbatim)
                0567        if (/!DESCRIPTION:/) {
                0568            if ($prologue) {
                0569                if ($verb) {
                0570                    &end_verbatim();
                0571                    printf "\n{\\sf DESCRIPTION: }\n\\medskip\n";
                0572                }
                0573                else {                          # probably never occurs
                0574                }
                0575                if ($opt_x) {
                0576                    &begin_verbatim();
                0577                    $first_verb = 1;
                0578                }
                0579                else {
                0580                    for ($i = 3; $i <= $#Fld; $i++) {
                0581                        printf '%s ', $Fld[$i];
                0582                    }
                0583                }
                0584                ### print " ";
                0585                $have_desc = 1;
                0586                next LINE;
                0587            }
                0588        }
                0589        
                0590        # Handle optional keywords (these will appear as verbatim)
                0591        if ($prologue) {
                0592          KEY:
                0593            foreach $key ( @keys ) {
                0594                if ( /$key/ ) {
                0595                    if ($verb) {
                0596                        &end_verbatim();
                0597                    }
                0598                    else {
                0599                        printf "\n\\medskip\n";
                0600                    }
                0601                    $k = sprintf('%s', $key);
                0602                    $ln = length($k);
                0603                    ###printf "\\subsubsection*{%s}\n", substr($k, 2, $ln - 1);
                0604                    ###printf "{\\Large \\em %s}\n", ucfirst lc substr($k, 2, $ln - 1);
                0605                    $_ = $key;
                0606                    printf "{\\sf %s}\n", substr($k, 2, $ln - 1); # san serif
                0607                    &begin_verbatim();
                0608                    $first_verb = 1;
                0609                    if ( $key eq "!INTERFACE:" )        { $have_intf = 1; }
                0610                    if ( $key eq "!CALLING SEQUENCE:" ) { $have_intf = 1; }
                0611                    if ( $key eq "!REVISION HISTORY:" ) { $have_hist = 1; }
                0612                    next LINE;
                0613                }
                0614            }
                0615        }
                0616        
                0617        # End of prologue
                0618        if ($Fld[1] eq $eop_string) {
                0619            if ($verb) {
                0620                &end_verbatim();
                0621            }
                0622            $prologue = 0;
                0623            # &check_if_all_there(); # check if all required keywords are there.
                0624            if ( $opt_l ) {
                0625                $Fld[1] = $boc_string;}
                0626            else {
                0627                next LINE;
                0628            }
                0629        }
                0630        
                0631        unless ( $opt_s ) {
                0632            
                0633            # End of Internal Prologue
                0634            if ($Fld[1] eq $eopi_string) {
                0635                if ($verb) {
                0636                    &end_verbatim();
                0637                }
                0638                $prologue = 0;
                0639                # &check_if_all_there(); # check if all required keywords are there.
                0640                if ($opt_l) {
                0641                    $Fld[1] = $boc_string;}
                0642                else { next LINE; }
                0643            }
                0644            
                0645            # Beginning of source code section
                0646            if ($Fld[1] eq $boc_string) {
                0647                print ' ';
                0648                print '%/////////////////////////////////////////////////////////////';
                0649                $first = 0;
                0650                $prologue = 0;
                0651                $source = 1;
                0652                ### printf "\\subsubsection*{CONTENTS:}\n\n", $Fld[3];
                0653                printf "{\\sf CONTENTS:}";
                0654                &begin_verbatim();
                0655                next LINE;
                0656            }
                0657            
                0658            # End of source code
                0659            if ($Fld[1] eq $eoc_string) {
                0660                &do_eoc();
                0661                $prologue = 0;
                0662                next LINE;
                0663            }
                0664        }
                0665        
                0666        # Prologue or Introduction, print regular line (except for !)
                0667        if ($prologue||$intro) {
                0668            if ( $verb && $#Fld == 1 && ( $Fld[1] eq $comment_string ) ) {
                0669                next LINE;                # to eliminate excessive blanks 
                0670            }
                0671            if ( $Fld[2] eq "\\ev" ) {
                0672                # special handling
                0673                $_ = $comment_string . " \\end{verbatim}";
                0674            }
                0675            s/^$comment_string/ /;       # replace comment string with blank
                0676            # $line = sprintf('%s', $_);   # not necessary -- comment str is absent
                0677            # $ln = length($line);         # not necessary -- comment str is absent
                0678            unless ( $first_verb ) { printf "\n "; }
                0679            printf '%s', $_;
                0680            # printf '%s', substr($line, 1, $ln - 1);     # comment str is absent
                0681            $first_verb = 0;
                0682            next LINE;
                0683        }
                0684        
                0685        # Source code: print the full line
                0686        if ($source) {
                0687            print $_;
                0688            next LINE;
                0689        }
                0690 
                0691    }  # end inner loop for processing each line of the input file
                0692 
                0693  }  # end main loop for each command-line argument
cedb4b86df Ed H*0694 
1b5fb69d21 Ed H*0695 print $_;
                0696 if ( $source ) { &do_eoc(); }     
                0697 print '%...............................................................';
cedb4b86df Ed H*0698 
1b5fb69d21 Ed H*0699 # see comment above where these are originally set.
                0700 #print "\\setlength{\\parskip}{\\oldparskip}";
                0701 #print "\\setlength{\\parindent}{\\oldparindent}";
                0702 #print "\\setlength{\\baselineskip}{\\oldbaselineskip}";
cedb4b86df Ed H*0703 
1b5fb69d21 Ed H*0704 unless ( $opt_b ) {
                0705     print "\\end{document}";
                0706 }
cedb4b86df Ed H*0707 
                0708 
                0709 #----------------------------------------------------------------------
                0710 
1b5fb69d21 Ed H*0711 sub begin_verbatim
                0712 {
52c38edbc1 Ed H*0713     printf "\n{\\footnotesize \\begin{verbatim} ";
1b5fb69d21 Ed H*0714     $verb = 1;
                0715     return 0;
                0716 }
                0717 
                0718 sub end_verbatim
                0719 {
                0720     printf "\\end{verbatim} }";
                0721     $verb = 0;
                0722     return 0;
                0723 }
                0724 
                0725 sub CheckOpts
                0726 {
                0727     # Checks options against a given list.  Outputs error message
                0728     # for any invalid option.
                0729     #
                0730     # Usage:
                0731     #    $rc = &CheckOpts ( options, valid_reg_options,
                0732     #                                valid_sw_options,
                0733     #                                quiet_mode )
                0734     #
                0735     #    character: options - options to be checked. (e.g. -df+x)  The
                0736     #                         list must begin with a positive or
                0737     #                         negative sign.  If no sign appears at the
                0738     #                         beginning or by itself, then the argument
                0739     #                         is not recognized as a list of options.
                0740     #    character: valid_reg_options - list of valid regular options.
                0741     #                         (i.e. options that are associated only
                0742     #                         eith negative sign.)
                0743     #    character: valid_sw_options - list of valid switch options.
                0744     #                         (i.e. options that can be associated with
                0745     #                         either a positive or negative sign.
                0746     #    logical:   quiet mode (optional) If true then print no error
                0747     #                         messages.
                0748     #    integer:   rc      - return code
                0749     #                         = -1 if the arguement, options, is
                0750     #                            not recognized as a list of options
                0751     #                         =  0 if all options are valid.
                0752     #                         >  0 for the number of invalid options.
                0753     
                0754     local($options,
                0755           $valid_reg_options,
                0756           $valid_sw_options,
cedb4b86df Ed H*0757            $quiet_mode ) = @_;
1b5fb69d21 Ed H*0758     
                0759     if ( $options eq "+" ||
                0760          $options eq "-" ) {return -1}
                0761     
                0762     local(@Options) = split( / */, $options );
                0763     if ( $Options[ $[ ] ne "-" &&
cedb4b86df Ed H*0764           $Options[ $[ ] ne "+" ) {return -1;}
1b5fb69d21 Ed H*0765     
                0766     local($option, $option_sign, $valid_list, $pos);
                0767     local($errs)    = 0;
                0768     foreach $option ( @Options ) {
                0769         if ( $option eq "-" ||
                0770              $option eq "+" ) {$option_sign = $option;}
                0771         else {
                0772             if ( $option_sign eq "-" ) {
                0773                 $valid_list = $valid_reg_options
                0774                     . $valid_sw_options;
                0775             }
                0776             else {
                0777                 $valid_list = $valid_sw_options;
                0778             }
                0779             $pos = index ($valid_list,$option); 
                0780             if ( $pos < $[ &&
                0781                  $quiet_mode ) {
                0782                 $errs++;
                0783                 print STDERR "Invalid option: $option_sign$option \n"; 
                0784                 
                0785             }
                0786         }
                0787     }
                0788     return $errs;
                0789 }
                0790 
                0791 
                0792 sub GetOpts
                0793 {
                0794     # Gets options.  If an option is valid,  then opt_[option] is
                0795     # set to 0 or 1 as a side effect if the option is preceeded by
                0796     # a positive or negative sign.
                0797     #
                0798     # Usage:
                0799     # $rc = &GetOpts ( options, valid_options )
                0800     #
                0801     # character: options - options to be checked. (e.g. -df+x)  The
                0802     #                      list must begin with a positive or
                0803     #                      negative sign.  If no sign appears at the
                0804     #                      beginning or by itself, then the argument
                0805     #                      is not recognized as a list of options.
                0806     # character: valid_options - list of valid options (e.g. dfhx)
                0807     # integer:   rc      - return code
                0808     #                      = -1 if the arguement, options, is
                0809     #                         not recognized as a list of options.
                0810     #                      =  0 otherwise
                0811 
                0812     local($options,$valid_options) = @_;
                0813     
                0814     if ( $options eq "+" ||
                0815          $options eq "-" ) {return -1}
                0816     
                0817     local(@Options)       = split( / */, $options );
                0818     if ( $Options[ $[ ] ne "-" &&
                0819          $Options[ $[ ] ne "+" ) {return -1;}
                0820     
                0821     local($option, $option_sign);
                0822     
                0823     foreach $option ( @Options ) {
                0824         
cedb4b86df Ed H*0825         if ( $option eq "-" ||
                0826              $option eq "+" ) {
1b5fb69d21 Ed H*0827             $option_sign = $option; }
                0828         
cedb4b86df Ed H*0829         else {
1b5fb69d21 Ed H*0830             
                0831             if ( index ($valid_options,$option) >= $[ ) {
                0832                 if ( $option_sign eq "-" ) {${"opt_$option"} = 1;}
                0833                 if ( $option_sign eq "+" ) {${"opt_$option"} = 0;};
                0834                 
                0835             }
                0836         }
                0837     }
                0838     return 0;
                0839 }
                0840 
                0841 
                0842 sub SetOpt
                0843 {
                0844     # Sets option flags.  For the last input option that is in a
                0845     # list, the flag opt_[option] is set to 1 as a side effect.
                0846     # For all other options in the list, opt_[option] is set to 0.
                0847     #
                0848     # Usage:
                0849     #    $rc = &SetOpt ( options, valid_options )
                0850     #
                0851     #    character: options - options to be checked. (e.g. -df+x)  The
                0852     #                         list must begin with a positive or
                0853     #                         negative sign.  If no sign appears at the
                0854     #                         beginning or by itself, then the argument
                0855     #                         is not recognized as a list of options.
                0856     #    character: valid_options - list of valid options (e.g. def )
                0857     #    integer:   rc      - return code
                0858     #                         = -1 if the arguement, options, is
                0859     #                            not recognized as a list of options.
                0860     #                         =  0 otherwise
                0861     #    Note: For the examples provided for the input arguments,
                0862     #          $opt_d = 0, $opt_e = 0, and $opt_f = 1, since the 
                0863     #          input option, -f, was the last in the argument,
                0864     #          option.
                0865 
                0866     local($options,$valid_options) = @_;
                0867     
                0868     if ( $options eq "+" ||
                0869          $options eq "-" ) {return -1}
                0870     
                0871     local(@Options)       = split( / */, $options       );
                0872     local(@ValidOptions)  = split( / */, $valid_options );
                0873     if ( $Options[ $[ ] ne "-" &&
                0874          $Options[ $[ ] ne "+" ) {return -1;}
                0875     
                0876     local($option, $option_sign);
                0877     
                0878     foreach $option ( @Options ) {
cedb4b86df Ed H*0879         if ( $option ne "-" &&
                0880              $option ne "+" ) {
1b5fb69d21 Ed H*0881             
                0882             if ( index ($valid_options,$option) >= $[ ) {
                0883                 foreach $valid_option (@ValidOptions ) {
                0884                     ${"opt_$valid_option"} = 0;
                0885                     
                0886                 }
                0887                 ${"opt_$option"} = 1;
                0888             }
                0889         }
                0890     }
                0891     return 0;
                0892 }
                0893 
                0894 
                0895 sub print_help
                0896 {
cedb4b86df Ed H*0897     print "Usage:     protex [-hbACFS] [+-nlsxf] [src_file(s)]";
                0898     print " ";
                0899     print " Options:";
                0900     print "     -h   Help mode: list command line options";
                0901     print "     -b   Bare mode, meaning no preamble, etc."; 
5eef09f930 Ed H*0902     print "     +-v  Verbosity level"; 
cedb4b86df Ed H*0903     print "     +-n  New Page for each subsection (wastes paper)";
                0904     print "     +-l  Listing mode, default is prologues only";
                0905     print "     +-s  Shut-up mode, i.e., ignore any code from BOC to EOC";
                0906     print "     +-x  No LaTeX mode, i.e., put !DESCRIPTION: in verbatim mode";
                0907     print "     +-f  No source file info";
                0908     print "     -A   Ada code";
                0909     print "     -C   C++ code";
                0910     print "     -F   F90 code";
5f36ff9e77 Ed H*0911     print "     -7   F77 code";
cedb4b86df Ed H*0912     print "     -S   Shell script";
                0913     print " ";
                0914     print "  The options can appear in any order.  The options, -h and -b,";
                0915     print "  affect the input from all files listed on command-line input.";
                0916     print "  Each of the remaining options effects only the input from the";
                0917     print "  files listed after the option and prior to any overriding";
                0918     print "  option.  The plus sign turns off the option."; 
1b5fb69d21 Ed H*0919 }
cedb4b86df Ed H*0920 
1b5fb69d21 Ed H*0921 sub print_notice
                0922 {
cedb4b86df Ed H*0923     print "%                **** IMPORTANT NOTICE *****" ;
                0924     print "% This LaTeX file has been automatically produced by ProTeX v. 1.1";
                0925     print "% Any changes made to this file will likely be lost next time";
                0926     print "% this file is regenerated from its source. Send questions ";
                0927     print "% to Arlindo da Silva, dasilva\@gsfc.nasa.gov";
                0928     print " ";
1b5fb69d21 Ed H*0929 }
cedb4b86df Ed H*0930 
1b5fb69d21 Ed H*0931 sub print_preamble
                0932 {
                0933     unless ( $opt_b ) {
                0934         print "%------------------------ PREAMBLE --------------------------";
                0935         print "\\documentclass[11pt]{article}";
                0936         print "\\usepackage{amsmath}";
                0937         print "\\usepackage{epsfig}";
                0938         print "\\usepackage{hangcaption}";
                0939         print "\\textheight     9in";
                0940         print "\\topmargin      0pt";
                0941         print "\\headsep        1cm";
                0942         print "\\headheight     0pt";
                0943         print "\\textwidth      6in";
                0944         print "\\oddsidemargin  0in";
                0945         print "\\evensidemargin 0in";
                0946         print "\\marginparpush  0pt";
                0947         print "\\pagestyle{myheadings}";
                0948         print "\\markboth{}{}";
                0949         print "%-------------------------------------------------------------";
                0950     }
cedb4b86df Ed H*0951 
                0952     # in your main document before you include any protex-generated files 
                0953     # for the first time, if you define these three variables as length 
                0954     # settings (like this:)
                0955     #   \newlength{\oldparskip}
                0956     #   \newlength{\oldparindent}
                0957     #   \newlength{\oldbaselineskip}
                0958     # then 1) comment in all the lines below, and 2) find the 3 reset lines
                0959     # further down and comment in them as well. 
                0960     # then protex will override the paragraph and skip settings during 
                0961     # the source sections, but will restore the original document settings 
                0962     # at the end.   if someone can figure out how to check to see if a
                0963     # latex variable exists, and do a conditional section, we could make
                0964     # this fully self-contained.
                0965     # nsc feb 2003
                0966 
                0967     #print "\\setlength{\\oldparskip}{\\parskip}";
                0968     print "\\setlength{\\parskip}{0pt}";
                0969     #print "\\setlength{\\oldparindent}{\\parindent}";
                0970     print "\\setlength{\\parindent}{0pt}";
                0971     #print "\\setlength{\\oldbaselineskip}{\\baselineskip}";
                0972     print "\\setlength{\\baselineskip}{11pt}";
1b5fb69d21 Ed H*0973 }
cedb4b86df Ed H*0974 
                0975 
1b5fb69d21 Ed H*0976 sub print_macros
                0977 {
cedb4b86df Ed H*0978     print " ";
                0979     print "%--------------------- SHORT-HAND MACROS ----------------------";
                0980     print "\\def\\bv{\\begin{verbatim}}";
                0981     print "\\def\\ev\{\\end\{verbatim}}";
                0982     print "\\def\\be{\\begin{equation}}";
                0983     print "\\def\\ee{\\end{equation}}";
                0984     print "\\def\\bea{\\begin{eqnarray}}";
                0985     print "\\def\\eea{\\end{eqnarray}}";
                0986     print "\\def\\bi{\\begin{itemize}}";
                0987     print "\\def\\ei{\\end{itemize}}";
                0988     print "\\def\\bn{\\begin{enumerate}}";
                0989     print "\\def\\en{\\end{enumerate}}";
                0990     print "\\def\\bd{\\begin{description}}";
                0991     print "\\def\\ed{\\end{description}}";
                0992     print "\\def\\({\\left (}";
                0993     print "\\def\\){\\right )}";
                0994     print "\\def\\[{\\left [}";
                0995     print "\\def\\]{\\right ]}";
                0996     print "\\def\\<{\\left  \\langle}";
                0997     print "\\def\\>{\\right \\rangle}";
                0998     print "\\def\\cI{{\\cal I}}";
                0999     print "\\def\\diag{\\mathop{\\rm diag}}";
                1000     print "\\def\\tr{\\mathop{\\rm tr}}";
                1001     print "%-------------------------------------------------------------";
1b5fb69d21 Ed H*1002 }
cedb4b86df Ed H*1003 
                1004 
1b5fb69d21 Ed H*1005 sub do_beg
                1006 {
cedb4b86df Ed H*1007     unless ( $opt_b ) {
1b5fb69d21 Ed H*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  
cedb4b86df Ed H*1034 
1b5fb69d21 Ed H*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>";
cedb4b86df Ed H*1048     
1b5fb69d21 Ed H*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 }