0
|
1 |
#!/usr/bin/perl
|
|
2 |
#======================================================================
|
|
3 |
# A N T S I O . P L
|
|
4 |
# doc: Fri Jun 19 19:22:51 1998
|
3
|
5 |
# dlm: Wed Oct 10 12:36:29 2012
|
0
|
6 |
# (c) 1998 A.M. Thurnherr
|
3
|
7 |
# uE-Info: 598 0 NIL 0 0 70 2 2 4 NIL ofnI
|
0
|
8 |
#======================================================================
|
|
9 |
|
|
10 |
# HISTORY:
|
|
11 |
# Jun 19, 1998: - created
|
|
12 |
# Dec 29, 1998: - added antsLineFlag and antsLinePrefix
|
|
13 |
# Dec 30, 1998: - added -P)assthrough option handling, arg to &antsFlush()
|
|
14 |
# Jan 02, 1999: - changed -P to -T and added -P)refix for [./fnr]
|
|
15 |
# Feb 17, 1999: - added &antsReadFile()
|
|
16 |
# Feb 25, 1999: - added &antsInfo()
|
|
17 |
# Mar 11, 1999: - set undefined ret-vals of &antsBufOut() to NaN
|
|
18 |
# Mar 12, 1999: - added FILE to &antsPrintHeaders()
|
|
19 |
# Mar 14, 1999: - BUG ensured that $ants_[0] was defined when
|
|
20 |
# typical &antsBufFull was called on empty buffer
|
|
21 |
# - added &antsPostFlush()
|
|
22 |
# - added &antsSetR_()
|
|
23 |
# - BUG padding by &antsSet_() was broken
|
|
24 |
# Mar 20, 1999: - added code to abort if file on cmdline does not exist
|
|
25 |
# - removed &antsReadFile()
|
|
26 |
# Oct 31, 1999: - BUG when using -I
|
|
27 |
# Dec 06, 1999: - made &antsInfo() respect -Q
|
|
28 |
# Mar 07, 2000: - adapted to -M
|
|
29 |
# Jul 31, 2000: - removed buffer auto growth unless $antsPadOut
|
|
30 |
# Aug 21, 2000: - allow for in-line comments on -T
|
|
31 |
# Aug 28, 2000: - added opt_Z to remove leading zeroes on output
|
|
32 |
# - added %P handling
|
|
33 |
# Sep 03, 2000: - documentation
|
|
34 |
# Sep 04, 2000: - ensure %PARAMS are not just whitespace strings
|
|
35 |
# Oct 31, 2000: - added &antsReplaceParam()
|
|
36 |
# Nov 07, 2000: - added &antsFileScanParam()
|
|
37 |
# Nov 10, 2000: - made to ignore DOS EOF (BLOERKS!!!)
|
|
38 |
# Nov 16, 2000: - added comment about antsIO() bypassing &antsBufOut()
|
|
39 |
# Nov 17, 2000: - made -P override header PARAMs
|
|
40 |
# Jan 16, 2001: - cosmetics
|
|
41 |
# Feb 19, 2001: - added $antsNoHeaderCopy for [data]
|
|
42 |
# Mar 8, 2001: - adapted to -G)range
|
|
43 |
# Mar 18, 2001: - BUG: -G had selected NaNs
|
|
44 |
# Mar 22, 2001: - added $antsNoEmbeddedHeaderCopy for [fields] [efields]
|
|
45 |
# Mar 28, 2001: - mark header info of utils used in pipelines
|
|
46 |
# Mar 31, 2001: - updated -G)range
|
|
47 |
# - adapted to -F)ields
|
|
48 |
# Apr 3, 2001: - added appendfields
|
|
49 |
# Apr 5, 2001: - removed string interpolation from &antsOut()
|
|
50 |
# - added prependfields
|
|
51 |
# May 15, 2001: - output NaN on undefined -F vals
|
|
52 |
# Jun 4, 2001: - allowd %PARAMs on -F
|
|
53 |
# Jun 19, 2001: - added pseudo param %FILE
|
|
54 |
# Jul 9, 2001: - added Active ANTS stuff
|
|
55 |
# Jul 10, 2001: - continued, split off &antsParseHeader()
|
|
56 |
# Jul 11, 2001: - continued
|
|
57 |
# Jul 13, 2001: - replace -F fields names on 1st use
|
|
58 |
# Jul 16, 2001: - moved fchmod call to &antsPrintHeaders(), c.f. [Split]
|
|
59 |
# Jul 19, 2001: - embedded error messages in pipeline
|
|
60 |
# - copy header on -ve -H
|
|
61 |
# Jul 24, 2001: - BUG: set $antsNewLayout on -F
|
|
62 |
# - BUG: remove % from -F layout
|
|
63 |
# - moved fnr lookup for -G from [antsusage.pl]
|
|
64 |
# Aug 1, 2001: - BUG: &antsIn() had not restored @ARGV on EOF
|
|
65 |
# Aug 3, 2001: - added &antsFileScanLayout()
|
|
66 |
# Aug 9, 2001: - BUG: $antsNewLayout was not set on prepend/append fields
|
|
67 |
# Aug 10, 2001: - added $opt_G to &antsFileIn()
|
|
68 |
# Aug 19, 2001: - BUG: &antsReplaceParam() re-written
|
|
69 |
# Aug 29, 2001: - BUG: made -r into -f && -r
|
|
70 |
# Oct 28, 2001: - BUG: handled antsLinePrefix on parseHeader
|
|
71 |
# Nov 22, 2001: - added $antsParseHeader flag
|
|
72 |
# Nov 28, 2001: - allowed %param in -G
|
|
73 |
# Dec 30, 2001: - added &antsExit()
|
|
74 |
# May 18, 2002: - added %BASENAME, %EXTN
|
|
75 |
# May 20, 2002: - added $antsNewFile
|
|
76 |
# Jun 22, 2002: - added $antsPadIn
|
|
77 |
# Jan 6, 2003: - added $antsGrex (-G regex support)
|
|
78 |
# Jan 8, 2003: - added &antsFileParams()
|
|
79 |
# Mar 4, 2003: - added %RECNO
|
|
80 |
# Apr 14, 2003: - BUG: antsReplaceParam() removed because in-stream
|
|
81 |
# %PARAMs are not generally handled correctly
|
|
82 |
# - BUG: antsFileScanParam() had returned the first
|
|
83 |
# value encountered, NOT the valid (last) one!!!
|
|
84 |
# Apr 24, 2003: - BUG: added default $antsPadIn = 1 (required for
|
|
85 |
# [gamma_n])
|
|
86 |
# May 8, 2003: - made antsFileIn() respect -N (for [gshear])
|
|
87 |
# Jul 1, 2004: - BUG: $antsBufNFields was not set when an empty file
|
|
88 |
# with valid #ANTS#FIELDS# was read
|
|
89 |
# Jul 9, 2004: - BUG: test of incompatible in-file field definitions
|
|
90 |
# did not work
|
|
91 |
# Dec 5, 2004: - BUG: Jul 1 fix did not work correctly in cases where
|
|
92 |
# subsequent #ANTS#FIELDS# lines would shrink the
|
|
93 |
# number of fields; new fix was not debugged!
|
|
94 |
# Jan 17, 2005: - removed path from active files and used perl -S
|
|
95 |
# Feb 8, 2005: - made activation-status copy more portable (i.e.
|
|
96 |
# independent of perl path)
|
|
97 |
# Mar 7, 2005: - added %DIRNAME (& cleaned up %BASENAME %EXTN)
|
|
98 |
# Nov 8, 2005: - changed -T to -P, -Z => -T, added -Z
|
|
99 |
# Nov 17, 2005: - BUG: antsPreFlush() flushed one too few ([fmedian])
|
|
100 |
# - BUG: antsFlagged was not set correctly any more
|
|
101 |
# Nov 18, 2005: - finally allowed %PARAMs bounds in -G
|
|
102 |
# Nov 21, 2005: - BUG: %PARAM bounds in -G had broken regexp capability
|
|
103 |
# Dec 7, 2005: - BUG: embedded layout overrode @antsFName if $antsNewLayout
|
|
104 |
# - replaced @antsFName by @antsLayout{In,Out}
|
|
105 |
# Dec 8, 2005: - Version 3.2 (see [HISTORY])
|
|
106 |
# Dec 12, 2005: - disable output padding in &antsOut() if new layout
|
|
107 |
# Dec 14, 2005: - made &antsAddParams() set %P
|
|
108 |
# - removed &antsReplaceParam()
|
|
109 |
# Dec 20, 2005: - BUG: empty field names in Layout replaced by undef
|
|
110 |
# - $# is buggy => implemented opt_M without $#
|
|
111 |
# Dec 23, 2005: - replaced defined(@array) (c.f. perlfunc(1))
|
|
112 |
# - BUG: -F did not work ok when @antsNewLayout was set
|
|
113 |
# Dec 29, 2005: - added $PARAMSonly to avoid output duplication on -F%param
|
|
114 |
# Dec 30, 2005: - changed &antsFileIn() EOF return
|
|
115 |
# Jan 3, 2006: - BUG: pseudo %PARAMs (e.g. BASENAME) were not set
|
|
116 |
# on EOF when buffer is not full
|
|
117 |
# - changed %FILE to %FILENAME
|
|
118 |
# - added support for -S)elect
|
|
119 |
# Jan 4, 2006: - BUG: empty strings were not output as NaN
|
|
120 |
# Jan 9, 2006: - removed line flagging code
|
|
121 |
# Jan 12, 2006: - replaced old -H)eader skip support with new -H)ead
|
|
122 |
# Jan 13, 2006: - new [antsexprs.pl]
|
|
123 |
# - removed -G handling (now done as -S)
|
|
124 |
# - renamed -T)rim to -C)anonical
|
|
125 |
# - removed -Z)ap handling
|
|
126 |
# Jan 14, 2006: - continued removing -G
|
|
127 |
# Jan 31, 2006: - BUG: selecting last field per record with -I produced
|
|
128 |
# an extraneous empty line
|
|
129 |
# May 18, 2006: - BUG: set pseudo-params before -S test, to allow e.g.
|
|
130 |
# -S %RECNO==3 to work
|
|
131 |
# - BUG: set %RECNO on partially full buffer
|
|
132 |
# - added %LINENO pseudo param
|
|
133 |
# Jun 27, 2006: - BUG: added formal param @ to allow antsOut(NaN) to be
|
|
134 |
# used in list -w
|
|
135 |
# - changed semantics of antsPadOut()
|
|
136 |
# Jul 1, 2006: - Version 3.3 [HISTORY]
|
|
137 |
# Jul 10, 2006: - removed fchmod (now in perl chmod)
|
|
138 |
# Jul 21, 2006: - removed obsolete code
|
|
139 |
# Jul 22, 2006: - shuffled &antsOut() to allow for -H0
|
|
140 |
# Jul 23, 2006: - BUG: -F%PARAM did not work any more
|
|
141 |
# Jul 28, 2006: - BUG: pseudo-params were set during header parsing of
|
|
142 |
# an empty file
|
|
143 |
# Jul 31, 2006: - BUG: @antsLayout was not set on 0-record files
|
|
144 |
# - code cleanup
|
|
145 |
# Aug 24, 2006: - added $antsIgnoreInputParams
|
|
146 |
# Aug 28, 2006: - made antsIgnoreInputParams into eva'ed expr for [bindata]
|
|
147 |
# Oct 26, 2006: - allowed for empty lines in &antsFileScanParams()
|
|
148 |
# Nov 10, 2006: - suppressed copying of layout even if embedded headers
|
|
149 |
# are copied
|
|
150 |
# Dec 17, 2007: - modified behavior of antsIgnoreInputParams (see NOTES below)
|
|
151 |
# Jan 16, 2007: - re-implemented changes to -P mandated by Dec 14, 2006
|
|
152 |
# changes to [antsusage.pl]
|
|
153 |
# May 31, 2007: - added support for -G)eographic coord format
|
|
154 |
# Nov 14, 2007: - maded -G work with %PARAMS
|
|
155 |
# - BUG: %FILENAME (& others) not set on %PARAMS-only files
|
|
156 |
# Nov 15, 2007: - BUG: -G had never worked correctly when selecting fields
|
|
157 |
# Feb 8, 2008: - moved number output formatting to fmtNum() [antsutils.pl]
|
|
158 |
# Mar 26, 2008: - modified/extended -F behavior
|
|
159 |
# Mar 28, 2008: - fiddled
|
|
160 |
# Apr 15, 2008: - BUG: pseudo params were not set during header parsing
|
|
161 |
# => e.g. %RECNO could not be used in ded addr-expr
|
|
162 |
# May 1, 2008: - BUG: embedded header copy also copied embedded layout
|
|
163 |
# re-definitions
|
|
164 |
# May 22, 2008: - BUG: $antsPadOut = 0 did not suppress padding as intended
|
|
165 |
# in presence of layout or new layout => add option of
|
|
166 |
# setting it to -1
|
|
167 |
# Jul 11, 2008: - BUG: file-name-related pseudo %PARAMs did not work
|
|
168 |
# correctly for input files without extensions
|
|
169 |
# - added %FILENAME -> %PATHNAME
|
|
170 |
# Jul 21, 2008: - fiddled with antsInfo()
|
|
171 |
# Jul 23, 2008: - added code to allow deleting %PARAMs by setting them
|
|
172 |
# to undef in [list]
|
|
173 |
# Jul 29, 2008: - BUG: removed code to strip leading/trailing spaces from
|
|
174 |
# %PARAMs (before, a %PARAM containing just spaces
|
|
175 |
# was deleted on an NCode/listNC combo --- there is
|
|
176 |
# an example in [ubtest/NCode.TF]
|
|
177 |
# Jun 10, 2009: - added duplicate-output-field sanity check
|
|
178 |
# Aug 1, 2009: - BUG: duplicate unnamed output files generated error
|
|
179 |
# Aug 23, 2009: - V4.0: added &antsAddDeps
|
|
180 |
# Aug 25, 2009: - BUG: '-' was added as a dep for STDIN
|
|
181 |
# Aug 27, 2009: - added pseudo %PARAM %DEPS
|
|
182 |
# Oct 3, 2009: - added $antsAllowEmbeddedLayoutChange
|
|
183 |
# Oct 12, 2009: - changed antsAddDeps() to ignore empty dependencies
|
|
184 |
# Oct 13, 2009: - removed antsAddDeps() defaults
|
|
185 |
# Oct 15, 2009: - replaced \n by \\n in antsAddParams(); primarily for listNC
|
|
186 |
# Nov 3, 2009: - BUG: <> dependencies were not set when $antsParseHeader was set to 0
|
|
187 |
# Nov 6, 2009: - BUG: stdin had sometimes produced empty dep
|
|
188 |
# Aug 15, 2010: - turned error on duplicate output fields into warning
|
|
189 |
# Aug 28, 2010: - moved dependency checks from [list] to here
|
|
190 |
# Oct 18, 2010: - disabled dependency checks for files in other directories
|
|
191 |
# Oct 19, 2010: - implemented &antsOut('EOF') to clear all static vars & other stuff to
|
|
192 |
# allow a single utility to output different ANTS files (used in
|
|
193 |
# LADCPproc)
|
|
194 |
# Apr 28, 2011: - added code to make all nans lowercase to antsIn()
|
|
195 |
# May 20, 2011: - BUG: %LINENO had not been reset between files any more
|
|
196 |
# May 22, 2011: - adapted to new antsCompileEditExpr()
|
|
197 |
# May 24: 2011: - BUG: forgot '$' in a variable (where???)
|
|
198 |
# Jul 28, 2011: - disabled adding of new deps on -D
|
|
199 |
# Apr 11, 2012: - improved layout-change error message
|
|
200 |
# Apr 26, 2012: - BUG: antsFileScanParam() was not properly anchored (%start_date matched %BT.start_date)
|
|
201 |
|
|
202 |
# NOTES:
|
|
203 |
# - %P was named without an ants-prefix because associative arrays
|
|
204 |
# are rare (and perl supports multiple name spaces for the
|
|
205 |
# different variable types) and to facilitate its use in
|
|
206 |
# [list]
|
|
207 |
# - copying of embedded (i.e. not appearing at start) headers is
|
|
208 |
# required e.g. for subsample -i ... | list %some-param
|
|
209 |
|
|
210 |
# $antsIngoreInputParams:
|
|
211 |
# - is eval'ed first time antsIn() is called (usually while parsing header)
|
|
212 |
# - if it evaluates to TRUE, all input %PARAMS are ignored (even if it would
|
|
213 |
# later eval to FALSE)
|
|
214 |
# - during header parsing, @ARGV only contains additional file arguments,
|
|
215 |
# i.e. setting $antsIgnoreInputParams = '@ARGV>0' before antsUsage() is
|
|
216 |
# called ignores all input %PARAMs if there is more than 1 file argument
|
|
217 |
|
|
218 |
#======================================================================
|
|
219 |
# Default Behaviour
|
|
220 |
#======================================================================
|
|
221 |
|
|
222 |
# Flags
|
|
223 |
|
|
224 |
$antsPadIn = 1; # fill with nan on input
|
|
225 |
$antsFixedFormat = 0; # remove leading & trailing stuff
|
|
226 |
$antsParseHeader = 1; # parse header on &antsUsage()
|
|
227 |
$antsIgnoreInputParams = 0; # ignore %PARAMs
|
|
228 |
$antsAllowEmbeddedLayoutChange = 0; # disallow layount changes
|
|
229 |
|
|
230 |
# Standard Fixed Size Buffer
|
|
231 |
|
|
232 |
sub antsBufFull() # default buffer full
|
|
233 |
{return $#ants_+1 == $antsBufSize;}
|
|
234 |
sub antsBufOut($) # default constructor
|
|
235 |
{return $ants_[$ants_][$_[0]]; }
|
|
236 |
|
|
237 |
# Setup Size 1 Buffer
|
|
238 |
|
|
239 |
$antsBufSize = 1; # default
|
|
240 |
$antsBufSkip = 1;
|
|
241 |
|
|
242 |
#======================================================================
|
|
243 |
# Interface
|
|
244 |
#======================================================================
|
|
245 |
|
|
246 |
sub antsInstallBufFull($)
|
|
247 |
{
|
|
248 |
eval "sub antsBufFull() { $_[0] }";
|
|
249 |
croak($@) if ($@);
|
|
250 |
&antsReCompile();
|
|
251 |
}
|
|
252 |
|
|
253 |
sub antsInstallBufOut($)
|
|
254 |
{
|
|
255 |
eval "sub antsBufOut(\$) { my(\$fnr)=\@_; $_[0] }";
|
|
256 |
croak($@) if ($@);
|
|
257 |
&antsReCompile();
|
|
258 |
}
|
|
259 |
|
|
260 |
sub antsActivateOut()
|
|
261 |
{
|
|
262 |
$antsActiveHeader = "#!/usr/bin/perl -S list\n" unless ($opt_Q);
|
|
263 |
}
|
|
264 |
|
|
265 |
#----------------------------------------------------------------------
|
|
266 |
# antsCheckDeps([filename]):
|
|
267 |
# - call only after header has been parsed
|
|
268 |
# - by default, tests current <> file
|
|
269 |
#----------------------------------------------------------------------
|
|
270 |
|
|
271 |
{ my($warned);
|
|
272 |
|
|
273 |
sub antsCheckDeps()
|
|
274 |
{
|
|
275 |
my($infile) = @_ ? $_[0] : $ARGV; # default: check current input
|
|
276 |
my($indir) = ($infile =~ m{^(.*)/[^/]*$});
|
|
277 |
# print(STDERR "checking dependencies of file $infile (deps = @antsDeps)\n");
|
|
278 |
|
|
279 |
return if ($opt_D); # suppress
|
|
280 |
return unless (@antsDeps); # no dependency info
|
|
281 |
return if defined($indir) && $indir ne '.'; # not in current directory
|
|
282 |
|
|
283 |
my(@stat) = stat($infile); # get time
|
|
284 |
return unless (@stat); # happens on stdin?
|
|
285 |
|
|
286 |
my($ctimef) = 10; my($ctime) = $stat[$ctimef];
|
|
287 |
for (my($d)=0; $d<=$#antsDeps; $d++) {
|
|
288 |
@stat = stat($antsDeps[$d]);
|
|
289 |
if (@stat) {
|
|
290 |
croak("$0: <$infile> is stale with respect to <$antsDeps[$d]>\n")
|
|
291 |
unless ($stat[$ctimef] <= $ctime);
|
|
292 |
} elsif (!$warned) {
|
|
293 |
&antsInfo("WARNING: dependency $antsDeps[$d] (&, possibly, others) not found");
|
|
294 |
$warned = 1;
|
|
295 |
}
|
|
296 |
}
|
|
297 |
}
|
|
298 |
} # static scope
|
|
299 |
|
|
300 |
sub antsParseHeader()
|
|
301 |
{
|
|
302 |
return if ($antsFixedFormat || !$antsParseHeader);
|
|
303 |
$antsDoParseHeader = 1; # glorks!
|
|
304 |
my($success) = &antsIn();
|
|
305 |
&antsCheckDeps();
|
|
306 |
return $success;
|
|
307 |
}
|
|
308 |
|
|
309 |
#----------------------------------------------------------------------
|
|
310 |
|
|
311 |
sub antsReCompile() # re-compile with funs
|
|
312 |
{ eval '
|
|
313 |
|
|
314 |
sub antsIn()
|
|
315 |
{
|
|
316 |
my(@Layout);
|
|
317 |
undef(@Layout); # needed, but unclear why
|
|
318 |
|
|
319 |
undef($antsNewFile); # assume no new file
|
|
320 |
|
|
321 |
unless ($antsHeaderParsed || $antsDoParseHeader) {
|
|
322 |
for (my($i)=0; $i<=$#ARGV; $i++) { # check file params
|
|
323 |
open($ARGV[$i]),croak("$0: $ARGV[$i]: $!\n")
|
|
324 |
unless (-f $ARGV[$i] && -r $ARGV[$i]);
|
|
325 |
}
|
|
326 |
&antsAddDeps($ARGV,@ARGV); # <> files
|
|
327 |
$antsCurHeader =~ s/\]/\] |/ # mark as pipeline
|
|
328 |
unless (-t 0);
|
|
329 |
$antsHeaderParsed = 1;
|
|
330 |
}
|
|
331 |
|
|
332 |
my(@tempARGV); # temporily remove non-file args
|
|
333 |
if ($antsDoParseHeader) {
|
|
334 |
my($ai) = $#ARGV;
|
|
335 |
while ($ai >= 0 && -f $ARGV[$ai]) { $ai-- }
|
|
336 |
# print(STDERR "before: @ARGV\n");
|
|
337 |
push(@tempARGV,splice(@ARGV,0,$ai+1));
|
|
338 |
# print(STDERR "after: @ARGV\n");
|
|
339 |
if ($#ARGV < 0 && -t 0) { # donot wait on stdin
|
|
340 |
push(@ARGV,@tempARGV);
|
|
341 |
$antsDoParseHeader=0;
|
|
342 |
return 0;
|
|
343 |
}
|
|
344 |
}
|
|
345 |
|
|
346 |
splice(@ants_,0,$antsBufSkip); # shift buffers
|
|
347 |
|
|
348 |
IN: until ($#ants_>=0 && &antsBufFull()) { # fill buffer; NEEDS RECOMPILE
|
|
349 |
|
|
350 |
if (defined($antsPeekBuffer)) { # from header parsing
|
|
351 |
$_ = $antsPeekBuffer;
|
|
352 |
$antsPeekBuffer = undef;
|
|
353 |
} else {
|
|
354 |
unless ($_ = <>) { # get next record
|
|
355 |
# EOF before buffer is full (can be partially filled)
|
|
356 |
unshift(@ARGV,@tempARGV); # restore ARGV list
|
|
357 |
|
|
358 |
@antsLayout = @Layout if (@Layout); # set last defined layout
|
|
359 |
$antsBufNFields = @antsLayout # adjust buffer width
|
|
360 |
if (@antsLayout > $antsBufNFields);
|
|
361 |
|
|
362 |
my($lastFile) = $P{PATHNAME};
|
|
363 |
$P{PATHNAME} = $ARGV; # set pseudo %PARAMs
|
|
364 |
($P{DIRNAME},$P{FILENAME}) =
|
|
365 |
($ARGV =~ m{^(.*)/([^/]+)$});
|
|
366 |
unless (defined($P{DIRNAME})) {
|
|
367 |
$P{DIRNAME} = ".";
|
|
368 |
$P{FILENAME} = $P{PATHNAME};
|
|
369 |
}
|
|
370 |
($P{BASENAME},$P{EXTN}) =
|
|
371 |
($P{FILENAME} =~ m{^([^\.]+)\.(.+)$});
|
|
372 |
unless (defined($P{EXTN})) {
|
|
373 |
$P{BASENAME} = $P{FILENAME};
|
|
374 |
$P{EXTN} = "";
|
|
375 |
}
|
|
376 |
$P{DEPS} = "@antsDeps";
|
|
377 |
|
|
378 |
return 0 if ($antsDoParseHeader); # empty file!!!
|
|
379 |
|
|
380 |
$P{RECNO} = -1 # set pseudo %PARAMs
|
|
381 |
unless defined($P{RECNO});
|
|
382 |
$P{RECNO}++;
|
|
383 |
$P{LINENO} = ($ARGV eq $lastFile) ? $P{LINENO}+1 : 0;
|
|
384 |
|
|
385 |
return 0; # return EOF
|
|
386 |
}
|
|
387 |
}
|
|
388 |
|
|
389 |
next IN if (length == 1 && ord == 26); # handle MS-DOG EOF
|
|
390 |
|
|
391 |
&antsActivateOut(),next IN # copy activation status
|
|
392 |
if (m{^#![^\s]*/perl\s.*list$});
|
|
393 |
|
|
394 |
exit(1) if (/^#ANTS#ERROR#/); # error in pipeline
|
|
395 |
|
|
396 |
if (/^#ANTS#PARAMS# ([^\{]+)\{([^\}]*)\}/) {
|
|
397 |
if (eval($antsIgnoreInputParams)) { # eval only 1st time
|
|
398 |
$antsIgnoreInputParams = 1;
|
|
399 |
next IN;
|
|
400 |
}
|
|
401 |
do {
|
|
402 |
if ($2 eq "") {
|
|
403 |
delete($P{$1});
|
|
404 |
} else {
|
|
405 |
$P{$1} = $2;
|
|
406 |
}
|
|
407 |
} while ($\' =~ m/ ([^\{]+)\{([^\}]*)\}/);
|
|
408 |
} elsif (/^#ANTS#DEPS# \{([^\}]*)\}/) { # handle dependencies
|
|
409 |
do { push(@antsDeps,$1); }
|
|
410 |
while ($\' =~ m/ \{([^\}]*)\}/);
|
|
411 |
} elsif (/^#ANTS# \[[^\]]*\] [^|]/) { # pipe-head => restart dependencies
|
|
412 |
undef(@antsDeps);
|
|
413 |
} elsif (/^#ANTS#FIELDS# \{([^\}]*)\}/) { # handle layout
|
|
414 |
undef(@Layout);
|
|
415 |
do {
|
|
416 |
push(@Layout,$1 eq "" ? undef : $1);
|
|
417 |
} while ($\' =~ m/ \{([^\}]*)\}/);
|
|
418 |
}
|
|
419 |
|
|
420 |
if (!($opt_Q || $antsNoHeaderCopy) && /^#ANTS#/) { # handle headers
|
|
421 |
if (defined($antsHeadersPrinted)) { # embedded headers
|
|
422 |
# The following is somewhat subtle because it must prevent embedded
|
|
423 |
# layout definitions to be copied 1) even if embedded headers are requested
|
|
424 |
# (because otherwise there will be embedded-layout-change errors) 2) but not
|
|
425 |
# if there has not been a layout defined already (ubtest common_opts);
|
|
426 |
print unless ($antsNoEmbeddedHeaderCopy ||
|
|
427 |
(/^#ANTS#FIELDS#/ && @antsLayout));
|
|
428 |
} else {
|
|
429 |
$antsOldHeaders .= $_;
|
|
430 |
}
|
|
431 |
next IN;
|
|
432 |
}
|
|
433 |
|
|
434 |
if (/^#/) { # handle non-header comments
|
|
435 |
&antsPrintHeaders(STDOUT,@antsNewLayout),print if ($opt_P);
|
|
436 |
next IN;
|
|
437 |
}
|
|
438 |
|
|
439 |
next IN if /^\s*$/; # skip empty lines
|
|
440 |
unless ($antsFixedFormat) {
|
|
441 |
s/^\s+//; # strip leading space
|
|
442 |
s/#.*$// unless ($opt_P); # strip trailing comments
|
|
443 |
s/\s+$//; # strip trailing space
|
|
444 |
}
|
|
445 |
|
|
446 |
# DONE WITH HEADER PARSING
|
|
447 |
|
|
448 |
croak("$0: embedded layout change when reading file $ARGV <@antsLayout> -> <@Layout>")
|
|
449 |
if (!$antsAllowEmbeddedLayoutChange && @Layout && @antsLayout && ("@Layout" ne "@antsLayout"));
|
|
450 |
|
|
451 |
@antsLayout = @Layout unless (@antsLayout);
|
|
452 |
|
|
453 |
$P{RECNO} = -1 unless defined($P{RECNO}); # set pseudo %PARAMs
|
|
454 |
$P{LINENO} = -1 unless defined($P{LINENO});
|
|
455 |
$P{DEPS} = "@antsDeps";
|
|
456 |
|
|
457 |
my($lastFile) = $P{PATHNAME};
|
|
458 |
$P{PATHNAME} = $ARGV;
|
|
459 |
($P{DIRNAME},$P{FILENAME}) =
|
|
460 |
($ARGV =~ m{^(.*)/([^/]+)$});
|
|
461 |
unless (defined($P{DIRNAME})) {
|
|
462 |
$P{DIRNAME} = ".";
|
|
463 |
$P{FILENAME} = $P{PATHNAME};
|
|
464 |
}
|
|
465 |
($P{BASENAME},$P{EXTN}) =
|
|
466 |
($P{FILENAME} =~ m{^([^\.]+)\.(.+)$});
|
|
467 |
unless (defined($P{EXTN})) {
|
|
468 |
$P{BASENAME} = $P{FILENAME};
|
|
469 |
$P{EXTN} = "";
|
|
470 |
}
|
|
471 |
|
|
472 |
if ($antsDoParseHeader) { # done parsing
|
|
473 |
unshift(@ARGV,@tempARGV);
|
|
474 |
$antsDoParseHeader = undef;
|
|
475 |
$antsPeekBuffer = $_;
|
|
476 |
$antsPadOut = $antsBufNFields = split($opt_I,$antsPeekBuffer);
|
|
477 |
return 1;
|
|
478 |
}
|
|
479 |
|
|
480 |
$P{RECNO}++; # update pseudo %PARAMs
|
|
481 |
$P{LINENO} = ($ARGV eq $lastFile) ? $P{LINENO}+1 : 0;
|
|
482 |
|
|
483 |
s/[Nn][Aa][Nn]/nan/g; # make all nans lower case
|
|
484 |
|
|
485 |
local(@in) = split($opt_I); # needs to be local for -S
|
|
486 |
if (defined($opt_S)) { # -S)elect
|
|
487 |
$opt_S = &antsCompileAddrExpr($opt_S,\'$in\')
|
|
488 |
unless ref($opt_S);
|
|
489 |
next IN unless (&$opt_S);
|
|
490 |
}
|
|
491 |
|
|
492 |
if (@antsNFNames) { # -N)ums
|
|
493 |
for (my($i)=0; $i<=$#antsNFNames; $i++) {
|
|
494 |
unless (defined($antsNfnr[$i])) {
|
|
495 |
if ($antsNFNames[$i] =~ /^%/) {
|
|
496 |
croak("$0: illegal -N option ($antsNFNames[$i] undefined)\n")
|
|
497 |
unless (defined($P{$\'}));
|
|
498 |
next IN unless (numberp($P{$\'}));
|
|
499 |
} else {
|
|
500 |
$antsNfnr[$i] = &fnr($antsNFNames[$i]);
|
|
501 |
next IN unless (numberp($in[$antsNfnr[$i]]));
|
|
502 |
}
|
|
503 |
} else {
|
|
504 |
next IN unless (numberp($in[$antsNfnr[$i]]));
|
|
505 |
}
|
|
506 |
}
|
|
507 |
}
|
|
508 |
|
|
509 |
chomp;
|
|
510 |
$antsLineBuf = $_; # save
|
|
511 |
|
|
512 |
push(@ants_,[@in]); # add to buffer
|
|
513 |
|
|
514 |
if ($#{$ants_[$#ants_]}+1 > $antsBufNFields) { # grow # of fields
|
|
515 |
$antsBufNFields = $#{$ants_[$#ants_]} + 1;
|
|
516 |
# print("antsBufNFields := $antsBufNFields --- $_");
|
|
517 |
if ($antsPadIn) {
|
|
518 |
for ($i=0; $i<$#ants_; $i++) {
|
|
519 |
push(@{$ants_[$i]},nan)
|
|
520 |
while ($#{$ants_[$i]}+1 < $antsBufNFields);
|
|
521 |
}
|
|
522 |
}
|
|
523 |
}
|
|
524 |
push(@{$ants_[$#ants_]},nan) # pad this
|
|
525 |
while ($antsPadIn && $#{$ants_[$#ants_]}+1 < $antsBufNFields);
|
|
526 |
}
|
|
527 |
|
|
528 |
$ants_ = ($#ants_ - $#ants_%2) / 2; # set current idx to centre
|
|
529 |
# print(STDERR "reading done; $#ants_+1 recs in buf, $ants_ is cur\n");
|
|
530 |
|
|
531 |
if ($antsLastFileName ne $ARGV) { # signal new file
|
|
532 |
$antsLastFileName = $ARGV;
|
|
533 |
$antsNewFile = 1;
|
|
534 |
}
|
|
535 |
|
|
536 |
return $#ants_+1; # ok
|
|
537 |
}
|
|
538 |
|
|
539 |
#----------------------------------------------------------------------
|
|
540 |
|
|
541 |
{ my(@ofn); # output layout # STATIC SCOPE
|
|
542 |
my(@OEparam); # -F %PARAMs
|
|
543 |
my(@OEfield); # -F fields
|
|
544 |
my(@OEexpr); # -F exprs (compiled)
|
|
545 |
my($EOparamsOnly); # nothing but %PARAMs in -F
|
|
546 |
|
|
547 |
sub antsOut(@)
|
|
548 |
{
|
|
549 |
my(@out) = @_;
|
|
550 |
if (@out == 1 && $out[0] eq "EOF") {
|
|
551 |
undef(@ofn); undef(@OEparam); undef(@OEfield); undef(@OEexpr); undef($EOparamsOnly);
|
|
552 |
undef($antsHeadersPrinted); undef(@antsOutExprs);
|
|
553 |
$antsPadOut = $antsBufNFields = @antsNewLayout; # NB: MUST BE SET BEFORE &antsOut("EOF");
|
|
554 |
return;
|
|
555 |
}
|
|
556 |
|
|
557 |
# STEP 0: PREPARE STUFF
|
|
558 |
|
|
559 |
@ofn = @antsNewLayout unless (@ofn); # output layout
|
|
560 |
@ofn = @antsLayout unless (@ofn);
|
|
561 |
|
|
562 |
# STEP 1: CONSTRUCT @out IF NEEDED
|
|
563 |
|
|
564 |
unless (@out > 0) {
|
|
565 |
for (my($fnr)=0; $fnr<$antsBufNFields; $fnr++) {
|
|
566 |
$out[$fnr] = &antsBufOut($fnr); # calc; NEEDS RECOMPILE
|
|
567 |
}
|
|
568 |
}
|
|
569 |
|
|
570 |
# STEP 2: HANDLE FIELD SELECTION (-F)
|
|
571 |
|
|
572 |
if (@antsOutExprs) {
|
|
573 |
|
|
574 |
unless ($antsOutExprsCompiled) { # parse/compile
|
|
575 |
my(@ofn_buf) = @ofn; # save current output layout
|
|
576 |
undef(@ofn);
|
|
577 |
|
|
578 |
$OEparamsOnly = 1;
|
|
579 |
for (my($if)=my($of)=0; $if<@antsOutExprs; $if++,$of++) {
|
3
|
580 |
# if ($antsOutExprs[$if] =~ m{^%([\w\.]+)$}) { # %PARAM
|
|
581 |
if ($antsOutExprs[$if] =~ m{^%([^=]+)$}) { # %PARAM
|
0
|
582 |
$ofn[$of] = $1;
|
|
583 |
$OEparam[$of] = 1;
|
|
584 |
} elsif ($antsOutExprs[$if] eq \'$@\') { # all fields
|
|
585 |
undef($OEparamsOnly);
|
|
586 |
for (my($i)=0; $i<@ofn_buf; $i++,$of++) {
|
|
587 |
$ofn[$of] = $ofn_buf[$i];
|
|
588 |
$OEfield[$of] = $i;
|
|
589 |
}
|
3
|
590 |
# } elsif ($antsOutExprs[$if] =~ m{^[\w\.]+$}) { # single field
|
|
591 |
} elsif ($antsOutExprs[$if] =~ m{^[^=]+$}) { # single field
|
|
592 |
undef($OEparamsOnly);
|
|
593 |
$ofn[$of] = $antsOutExprs[$if];
|
|
594 |
$OEfield[$of] = &outFnr($antsOutExprs[$if]);
|
0
|
595 |
} else { # expression
|
|
596 |
undef($OEparamsOnly);
|
|
597 |
my($expr);
|
3
|
598 |
($ofn[$of],$expr) = ($antsOutExprs[$if] =~ m{^([^=]*)=(.*)$});
|
0
|
599 |
croak("$0: cannot parse -F $antsOutExprs[$if]\n")
|
|
600 |
unless defined($expr);
|
|
601 |
my(@tmp) = @antsLayout;
|
|
602 |
@antsLayout = @ofn_buf;
|
|
603 |
$OEexpr[$of] = &antsCompileEditExpr($expr,\'$out_buf\');
|
|
604 |
@antsLayout = @tmp;
|
|
605 |
}
|
|
606 |
}
|
|
607 |
$antsOutExprsCompiled = 1;
|
|
608 |
}
|
|
609 |
|
|
610 |
local(@out_buf) = @out; # save current output data
|
|
611 |
undef(@out); # accessible from within exprs
|
|
612 |
|
|
613 |
for (my($f)=0; $f<@ofn; $f++) { # create @out according to -F
|
|
614 |
if ($OEparam[$f]) {
|
|
615 |
$out[$f] = $P{$ofn[$f]};
|
|
616 |
} elsif (defined($OEfield[$f])) {
|
|
617 |
$out[$f] = $out_buf[$OEfield[$f]];
|
|
618 |
} else {
|
|
619 |
$out[$f] = &{$OEexpr[$f]};
|
|
620 |
}
|
|
621 |
}
|
|
622 |
}
|
|
623 |
|
|
624 |
# STEP 3: PRINT HEADERS
|
|
625 |
|
|
626 |
if (@antsNewLayout || @antsOutExprs) {
|
|
627 |
&antsPrintHeaders(STDOUT,@ofn);
|
|
628 |
} else {
|
|
629 |
&antsPrintHeaders(STDOUT);
|
|
630 |
}
|
|
631 |
|
|
632 |
|
|
633 |
# STEP 4: DONE, DUE TO -H RUNNING OUT
|
|
634 |
|
|
635 |
&antsExit() if (defined($opt_H) && ($opt_H-- == 0));
|
|
636 |
|
|
637 |
|
|
638 |
# STEP 5: PRINT DATA
|
|
639 |
|
|
640 |
$antsPadOut = @ofn if ($antsPadOut >= 0 && @ofn);
|
|
641 |
push(@out,nan) while (@out < $antsPadOut);
|
|
642 |
|
|
643 |
my($outStr);
|
|
644 |
for (my($fnr)=0; $fnr<=$#out; $fnr++) {
|
|
645 |
$out[$fnr] =
|
|
646 |
fmtNum($out[$fnr],
|
|
647 |
@antsNewLayout ? $antsNewLayout[$fnr] : $antsLayout[$fnr]);
|
|
648 |
$outStr .= (defined($out[$fnr]) && $out[$fnr] ne "" ? $out[$fnr] : nan)
|
|
649 |
. ($fnr == $#out ? $opt_R : $opt_O);
|
|
650 |
}
|
|
651 |
print($outStr);
|
|
652 |
|
|
653 |
# STEP 6: DONE, DUE TO -F WITH PARAMS ONLY
|
|
654 |
|
|
655 |
&antsExit() if ($OEparamsOnly);
|
|
656 |
|
|
657 |
} # antsOut()
|
|
658 |
} # STATIC SCOPE
|
|
659 |
|
|
660 |
#----------------------------------------------------------------------
|
|
661 |
|
|
662 |
sub antsIO() # combine input and output
|
|
663 |
{ # NB: BYPASSES &antsBufOut()!
|
|
664 |
my($i);
|
|
665 |
for ($i=0; $i<$antsBufSkip && $i<=$#ants_; $i++) {
|
|
666 |
&antsOut(@{$ants_[$i]});
|
|
667 |
}
|
|
668 |
return &antsIn(); # re-fill
|
|
669 |
}
|
|
670 |
|
|
671 |
sub antsPreFlush() # pre-flush buffer to cur
|
|
672 |
{
|
|
673 |
my($i);
|
|
674 |
for ($i=0; $i<=$ants_; $i++) {
|
|
675 |
&antsOut(@{$ants_[$i]});
|
|
676 |
}
|
|
677 |
}
|
|
678 |
|
|
679 |
sub antsPostFlush() # post-flush buffer after cur
|
|
680 |
{
|
|
681 |
my($i);
|
|
682 |
for ($i=$ants_; $i<=$#ants_; $i++) {
|
|
683 |
&antsOut(@{$ants_[$i]});
|
|
684 |
}
|
|
685 |
}
|
|
686 |
|
|
687 |
sub antsFlush() # flush buffer
|
|
688 |
{
|
|
689 |
&antsOut(@{$ants_[0]}),shift(@ants_)
|
|
690 |
while ($#ants_ >= 0);
|
|
691 |
}'; die("antsReCompile: $@\n") if ($@); # re-compile functions
|
|
692 |
|
|
693 |
} # of antsReCompile()
|
|
694 |
|
|
695 |
&antsReCompile(); # compile
|
|
696 |
|
|
697 |
#----------------------------------------------------------------------
|
|
698 |
|
|
699 |
sub antsSetR_($$$) # set field in any rec
|
|
700 |
{ my($r,$f,$v) = @_;
|
|
701 |
$antsBufNFields = $f+1 # auto extension
|
|
702 |
if ($antsBufNFields-1 < $f);
|
|
703 |
while ($#{$ants_[$r]} < $f-1) {
|
|
704 |
push(@{$ants_[$r]},nan);
|
|
705 |
}
|
|
706 |
$ants_[$r][$f] = $v;
|
|
707 |
}
|
|
708 |
|
|
709 |
sub antsSet_($$) # set field in current rec
|
|
710 |
{ &antsSetR_($ants_,$_[0],$_[1]); }
|
|
711 |
|
|
712 |
#----------------------------------------------------------------------
|
|
713 |
|
|
714 |
{ my(%sExprs); # multiple layouts -> multiple compiled -S exprs
|
|
715 |
|
|
716 |
sub antsFileIn() # read from a file
|
|
717 |
{ my($f) = @_;
|
|
718 |
|
|
719 |
REDO:
|
|
720 |
return () unless ($_ = <$f>); # get next record (return EOF)
|
|
721 |
|
|
722 |
goto REDO if /^#/; # skip comments
|
|
723 |
goto REDO if /^\s*$/; # skip empty lines
|
|
724 |
s/^\s+//; # remove leading spaces
|
|
725 |
s/#.*$//; # remove trailing comments
|
|
726 |
|
|
727 |
local(@in) = split($opt_I); # needs to be local for -S
|
|
728 |
|
|
729 |
if (defined($opt_S)) { # -S)elect
|
|
730 |
$sExprs{$f} = &antsCompileAddrExpr($opt_S,'$in')
|
|
731 |
unless defined($sExprs{$f});
|
|
732 |
goto REDO unless (&{$sExprs{$f}});
|
|
733 |
}
|
|
734 |
|
|
735 |
if (@antsNFNames) { # handle -N)ums
|
|
736 |
for (my($i)=0; $i<=$#antsNFNames; $i++) {
|
|
737 |
if ($antsNFNames[$i] =~ /^%/) {
|
|
738 |
croak("$0: illegal -N option ($antsNFNames[$i] undefined)\n")
|
|
739 |
unless (defined($P{$'}));
|
|
740 |
goto REDO unless (numberp($P{$'}));
|
|
741 |
} else {
|
|
742 |
$antsNfnr[$i] = &fnr($antsNFNames[$i]);
|
|
743 |
goto REDO unless (numberp($in[$antsNfnr[$i]]));
|
|
744 |
}
|
|
745 |
}
|
|
746 |
}
|
|
747 |
|
|
748 |
return @in;
|
|
749 |
}
|
|
750 |
|
|
751 |
} # static scope
|
|
752 |
|
|
753 |
#======================================================================
|
|
754 |
# Utilities
|
|
755 |
#======================================================================
|
|
756 |
|
|
757 |
sub antsPrintHeaders($@) # handle headers
|
|
758 |
{
|
|
759 |
return if ($antsHeadersPrinted); # do only once
|
|
760 |
$antsHeadersPrinted = 1;
|
|
761 |
local(*fh,@newLayout) = @_;
|
|
762 |
|
|
763 |
if (@newLayout) { # check for duplicate field names
|
|
764 |
my(%fn);
|
|
765 |
for (my($i)=0; $i<=$#newLayout; $i++) {
|
|
766 |
next unless defined($newLayout[$i]) && $newLayout[$i] ne '';
|
|
767 |
if ($fn{$newLayout[$i]}) {
|
|
768 |
&antsInfo("duplicate output field <$newLayout[$i]> changed to <$newLayout[$i]_>");
|
|
769 |
$newLayout[$i] .= '_';
|
|
770 |
again;
|
|
771 |
}
|
|
772 |
$fn{$newLayout[$i]} = 1;
|
|
773 |
}
|
|
774 |
}
|
|
775 |
|
|
776 |
return if ($opt_Q); # suppress
|
|
777 |
|
|
778 |
if (defined($antsActiveHeader)) { # activate file
|
|
779 |
chmod(0777&~umask,*fh);
|
|
780 |
print(fh $antsActiveHeader);
|
|
781 |
}
|
|
782 |
|
|
783 |
print(fh $antsOldHeaders); # old headers
|
|
784 |
|
|
785 |
print(fh $antsCurHeader) unless ($opt_X); # new headers
|
|
786 |
print(fh $antsCurParams);
|
|
787 |
print(fh $antsCurDeps) unless ($opt_X);
|
|
788 |
if (@newLayout) {
|
|
789 |
print(fh "#ANTS#FIELDS# ");
|
|
790 |
for (my($i)=0; $i<=$#newLayout; $i++) {
|
|
791 |
print(fh "{$newLayout[$i]} ");
|
|
792 |
}
|
|
793 |
print(fh "\n");
|
|
794 |
}
|
|
795 |
|
|
796 |
|
|
797 |
}
|
|
798 |
|
|
799 |
sub antsExit()
|
|
800 |
{
|
|
801 |
&antsPrintHeaders(STDOUT,@antsNewLayout);
|
|
802 |
exit(0);
|
|
803 |
}
|
|
804 |
|
|
805 |
#----------------------------------------------------------------------
|
|
806 |
|
|
807 |
# NB: to use antsInfo in expressions, a return value of 1
|
|
808 |
# has been assumed!!!
|
|
809 |
|
|
810 |
sub antsInfo(@) # add info to header & STDERR
|
|
811 |
{
|
|
812 |
return 1 if ($opt_Q);
|
|
813 |
my($fmt,@args) = @_; # can't do it directly!!!
|
|
814 |
my($msg) = sprintf($fmt,@args);
|
|
815 |
$antsCurHeader .= "#ANTS# $0: $msg\n";
|
|
816 |
print(STDERR "$0: $msg\n");
|
|
817 |
return 1;
|
|
818 |
}
|
|
819 |
|
|
820 |
#----------------------------------------------------------------------
|
|
821 |
# %PARAM-related stuff
|
|
822 |
#----------------------------------------------------------------------
|
|
823 |
|
|
824 |
sub antsAddParams(@) # add params
|
|
825 |
{
|
|
826 |
my($i);
|
|
827 |
|
|
828 |
$antsCurParams .= "#ANTS#PARAMS#";
|
|
829 |
for ($i=0; $i<$#_; $i+=2) {
|
|
830 |
my($v) = $_[$i+1];
|
|
831 |
$v =~ s/\n/\\n/g;
|
|
832 |
$P{$_[$i]} = $v;
|
|
833 |
$antsCurParams .= " $_[$i]\{$v\}";
|
|
834 |
}
|
|
835 |
$antsCurParams .= "\n";
|
|
836 |
}
|
|
837 |
|
|
838 |
sub antsFileParams() # get params from file
|
|
839 |
{
|
|
840 |
my($f) = @_;
|
|
841 |
my(%P);
|
|
842 |
|
|
843 |
while ($_ = <$f>) { # get next record
|
|
844 |
if (/^#ANTS#PARAMS# ([^\{]+)\{([^\}]*)\}/) {
|
|
845 |
do {
|
|
846 |
$P{$1} = $2;
|
|
847 |
$P{$1} =~ s/^\s*//; # ensure non-null
|
|
848 |
} while ($' =~ m/ ([^\{]+)\{([^\}]*)\}/);
|
|
849 |
}
|
|
850 |
}
|
|
851 |
seek($f,0,0) || croak("$0: $@\n");
|
|
852 |
return %P;
|
|
853 |
}
|
|
854 |
|
|
855 |
# antsFileScanParam() only scans the 1st header!!!!
|
|
856 |
# empty lines are ok, though
|
|
857 |
|
|
858 |
sub antsFileScanParam() # find param in file
|
|
859 |
{
|
|
860 |
my($f,$pn) = @_;
|
|
861 |
my($val);
|
|
862 |
|
|
863 |
while ($_ = <$f>) { # get next record
|
|
864 |
last unless (/^#/ || /^\s*$/);
|
|
865 |
next unless (/^#ANTS#PARAMS# /);
|
|
866 |
$val = $1 if (/ $pn\{([^\}]*)\}/);
|
|
867 |
}
|
|
868 |
seek($f,0,0) || croak("$0: $@\n");
|
|
869 |
return $val;
|
|
870 |
}
|
|
871 |
|
|
872 |
#----------------------------------------------------------------------
|
|
873 |
# Layout-related stuff
|
|
874 |
#----------------------------------------------------------------------
|
|
875 |
|
|
876 |
sub antsFileLayout($) # return layout
|
|
877 |
{ my($f) = @_;
|
|
878 |
my(@lo);
|
|
879 |
|
|
880 |
while ($_ = <$f>) { # get next record
|
|
881 |
next unless (/^#ANTS#FIELDS# /);
|
|
882 |
@lo = split(' ',$');
|
|
883 |
}
|
|
884 |
seek($f,0,0) || croak("$0: $@\n");
|
|
885 |
for (my($i)=0; $i<=$#lo; $i++) {
|
|
886 |
$lo[$i] =~ s/^\{(.*)\}$/$1/;
|
|
887 |
}
|
|
888 |
return @lo;
|
|
889 |
}
|
|
890 |
|
|
891 |
sub antsFileScanFnr($$) # find fnr in file
|
|
892 |
{ my($f,$fn) = @_;
|
|
893 |
my(@lo) = &antsFileLayout($f);
|
|
894 |
|
|
895 |
for (my($f)=0; $f<=$#lo; $f++) {
|
|
896 |
return $f if ($fn eq $lo[$f]);
|
|
897 |
}
|
|
898 |
return undef;
|
|
899 |
}
|
|
900 |
|
|
901 |
#----------------------------------------------------------------------
|
|
902 |
# Deps-related stuff
|
|
903 |
#----------------------------------------------------------------------
|
|
904 |
|
|
905 |
sub antsAddDeps(@) # add Deps
|
|
906 |
{
|
|
907 |
my(@deps) = @_;
|
|
908 |
return if $opt_D || (@deps==1 && ($deps[0] eq '-' || $deps[0] eq '')); # STDIN
|
|
909 |
|
|
910 |
$antsCurDeps .= '#ANTS#DEPS#';
|
|
911 |
for (my($i)=0; $i<=$#deps; $i++) {
|
|
912 |
next if (length($deps[$i]) == 0);
|
|
913 |
$antsCurDeps .= " \{$deps[$i]\}";
|
|
914 |
}
|
|
915 |
$antsCurDeps .= "\n";
|
|
916 |
}
|
|
917 |
|
|
918 |
#======================================================================
|
|
919 |
|
|
920 |
1;
|