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