-
Notifications
You must be signed in to change notification settings - Fork 11
/
getatt
executable file
·163 lines (138 loc) · 4.64 KB
/
getatt
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
#! /usr/bin/env perl
# This script requires that Perl be in the path, and that the
# environment variable SST_DIR be set to the location of the prolat
# binary.
$C = 1;
$fortran = 0;
$prologue = 0;
$name = "";
$name_section = 0;
$key = "";
$unix_script = 0;
$cmt = quotemeta( "*" );
# Read switches.
while ( $_ = $ARGV[0], /^-/ ) {
shift;
last if /^--$/;
if ( /^-f/ ) { $fortran = 1; $C = 0; };
if ( /^-u/ ) { $unix_script = 1; $cmt = quotemeta( "#" ); };
if ( /^-att/ ) { $key = "att" };
if ( /^-class/ ) { $key = "class" };
}
# Set up pattern for matching language-dependent lines.
$language_symbol = "c";
if ( $fortran ) { $language_symbol = "f"; }
if ( $unix_script ) {
$lang = $cmt . "[fc]";
$thislang = quotemeta( "#" . $language_symbol );
} else {
$lang = "[fc]";
$thislang = quotemeta( $language_symbol );
}
# Read input lines.
line: while (<>) {
# Skip language-specific lines that aren't wanted.
if ( /^$lang/ ) {
next line if ( !/^$thislang/ );
# Put "*" in first column.
s/^$thislang/\*/;
}
# Detect end of prologue.
if ( /^$cmt$key--/o ) {
$prologue = 0;
# Append "*-" to prologue text and save the whole prologue as an element
# in the "pro" associative array.
$pro{ $name } = $text . "*-\n";
# Clear the name ready for next prologue.
$name = "";
}
# Process the prologue contents.
if ( $prologue ) {
# Remove trailing blanks.
s/ *$//;
# Convert/remove sections that don't appear in external documentation.
if ( $unix_script ) {
;
} elsif ( !$key && $C ) {
s/^($cmt *)Synopsis:$/$1Invocation:/;
s/^($cmt *)Parameters:$/$1Arguments:/;
} elsif ( !$key && $fortran ) {
s/^($cmt *)Synopsis:$/$1Invocation:/;
s/^($cmt *)Parameters:$/$1Arguments:/;
} elsif ( $key =~ /att/ ) {
s/^($cmt *)Synopsis:$/$1Invocation:/;
} elsif ( $key =~ /class/ ) {
s/^($cmt *)Constructor Function:$/$1Invocation:/;
}
# Skip the contents of these sections...
if ( /^$cmt *Type:$/ ||
/^$cmt *Class Membership:$/ ||
/^$cmt *Copyright:$/ ) {
while ( <> ) { if ( /^ *$/ ) { next line } };
}
# Remove any #include directives from the C Synopsis (Invocation) section.
if ( !$key && $C && !$unix_script ) {
if ( /^$cmt *Invocation:$/ ) {
while ( <> && /^$cmt *#include/ ) {};
}
}
# If in the "Name:" section, search for the routine name, noting when
# found.
if ( $name_section && ( ( $name ) = /^. *([^ ]*) *$/ ) ) {
$name_section = 0;
};
# Detect the "Name:" line itself.
if ( /^$cmt *Name:$/ ) { $name_section = 1 };
# Change to use the standard comment character "*".
s/^$cmt/\*/;
# Append each prologue line to the end of the prologue text.
$text = $text . $_;
}
# Detect start of prologue and initialise prologue text.
if ( /^$cmt$key\+\+/o ) {
$prologue = 1;
$name_section = 0;
$text = "*+\n";
};
}
# Output prologues in alphabetical order to a scratch file.
open( TEMP, '>/tmp/getatt' );
foreach $name ( sort( keys( %pro ) ) ) { print( TEMP $pro{ $name } ); }
close( TEMP );
# Write the names to a log file, escaping special (to Latex) characters.
open( NAMES, '>getatt.labels' );
foreach $name ( sort( keys( %pro ) ) ) {
$name =~ s/_/\\_/g;
$name =~ s/\>/\$\>\$/g;
$name =~ s/\</\$\<\$/g;
print( NAMES $name );
}
close( NAMES );
# Run PROLAT on the scratch file and then delete it.
print( STDERR
`rm -f /tmp/prolat.tex;
\$SST_DIR/prolat in=/tmp/getatt atask=f single=f page=f document=f out=/tmp/prolat.tex;
rm -f /tmp/getatt`
);
# Read the output from PROLAT and edit the Latex macro invocations into
# their final form.
open( LATEX, '/tmp/prolat.tex' );
while( <LATEX> ) {
if ( $unix_script ) {
;
} elsif ( !$key && $C ) {
s/\\sstinvocation\{/\\sstsynopsis{/;
s/\\sstarguments\{/\\sstparameters{/;
} elsif ( $key =~ /att/ ) {
s/\\sstinvocation\{/\\sstattributetype{/;
} elsif ( $key =~ /class/ ) {
s/\\sstinvocation\{/\\sstconstructor{/;
}
# Fix up constructs that don't otherwise convert to HTML properly.
s/\{\\tt \'\}/'/g;
s/\{\\tt \"\}/{\\tt{\"}}/g;
print;
}
close( LATEX );
# Delete the output file from PROLAT.
print( STDERR `rm -f /tmp/prolat.tex` );