# HG changeset patch # User A.M. Thurnherr # Date 1425578319 18000 # Node ID ebd8a4ddd7f255ec273250b6969d7d7e3ff60fd7 # Parent 4097040ad31c1868f946ae349eed0880d192e506# Parent 3dfa16523886268e12e7e1829f91987a2c79294e merged diff --git a/ANTSlib b/ANTSlib diff --git a/ants.pl b/ants.pl diff --git a/antsio.pl b/antsio.pl --- a/antsio.pl +++ b/antsio.pl @@ -2,9 +2,9 @@ #====================================================================== # A N T S I O . P L # doc: Fri Jun 19 19:22:51 1998 -# dlm: Thu Aug 7 09:20:37 2014 +# dlm: Thu Mar 5 12:57:33 2015 # (c) 1998 A.M. Thurnherr -# uE-Info: 204 55 NIL 0 0 70 2 2 4 NIL ofnI +# uE-Info: 206 0 NIL 0 0 70 2 2 4 NIL ofnI #====================================================================== # HISTORY: @@ -202,8 +202,9 @@ # Jul 22, 2014: - BUG: antsPadIn was done after handling -S & -N # - removed antsPadIn flag (made it always be true) # Aug 7, 2014: - allow optional % in param name in &antsFileScanParam() +# Oct 29, 2014: - implemented abbreviated Layout and %PARAM definitions -# NOTES: +# GENERAL NOTES: # - %P was named without an ants-prefix because associative arrays # are rare (and perl supports multiple name spaces for the # different variable types) and to facilitate its use in @@ -211,6 +212,15 @@ # - copying of embedded (i.e. not appearing at start) headers is # required e.g. for subsample -i ... | list %some-param +# ABBREVIATED LAYOUT & PARAM DEFINITIONS +# - # definition [definition [...]] +# - definition := field_name | %PARAM_def +# - field_name := {string} +# - %PARAM_def := string{string|num} +# - implemented in October 2014 in order to make ANTS format easier to use for others +# - abbreviated and full headers must not be used together +# - abbreviated field definitions are additive (rather than replacing, as in the full headers) + # $antsIngoreInputParams: # - is eval'ed first time antsIn() is called (usually while parsing header) # - if it evaluates to TRUE, all input %PARAMS are ignored (even if it would @@ -311,12 +321,23 @@ #---------------------------------------------------------------------- +sub def_abbrev($) +{ + my($def) = @_; + if ($def =~ /^\{(\w+)\}$/) { + push(@Layout,$1); + } else { + my($name,$val) = ($def =~ /(\w+)\{([^\}]+)\}/); + $P{$name} = $val; + } +} + sub antsReCompile() # re-compile with funs { eval ' sub antsIn() { - my(@Layout); + local(@Layout); undef(@Layout); # needed, but unclear why undef($antsNewFile); # assume no new file @@ -418,8 +439,14 @@ do { push(@Layout,$1 eq "" ? undef : $1); } while ($\' =~ m/ \{([^\}]*)\}/); + } elsif (/^# (\{\w+\}|\w+\{[^\}]+\})+/) { # ABBREVIATED DEFINITIONS + my($match) = $1; my($rem) = $\'; + do { + def_abbrev($match); + ($match,$rem) = ($rem =~ /(\{\w+\}|\w+\{[^\}]+\})(.*)/); + } while ($match); } - + if (!($opt_Q || $antsNoHeaderCopy) && /^#ANTS#/) { # handle headers if (defined($antsHeadersPrinted)) { # embedded headers # The following is somewhat subtle because it must prevent embedded diff --git a/antsusage.pl b/antsusage.pl --- a/antsusage.pl +++ b/antsusage.pl @@ -2,9 +2,9 @@ #====================================================================== # A N T S U S A G E . P L # doc: Fri Jun 19 13:43:05 1998 -# dlm: Wed Jul 30 12:43:52 2014 +# dlm: Thu Mar 5 12:58:27 2015 # (c) 1998 A.M. Thurnherr -# uE-Info: 365 24 NIL 0 0 70 2 2 4 NIL ofnI +# uE-Info: 161 0 NIL 0 0 70 2 2 4 NIL ofnI #====================================================================== # HISTORY: @@ -156,6 +156,8 @@ # as expanded output (unexpanded should be produced only if the # expansion is empty) # Jul 30, 2014: - added special args to -U)sage output +# Jan 30, 2015: - added &antsFunOpt() +# Jan 31, 2015: - made it work # NOTES: # - ksh expands {}-arguments with commas in them!!! Use + instead @@ -663,4 +665,23 @@ } } +#---------------------------------------------------------------------- +# antsFunOpt(\$opt_x) parses the contents of $opt_x as follows: +# +# name(value) => $opt_x = 'name'; $name = "value"; +# name => no change +#---------------------------------------------------------------------- + +sub antsFunOpt(@) +{ + my($opt) = @_; + return unless defined($opt); + croak("antsusage.pl: antsFunOpt(@_): argument is not a ref\n") + unless ref($opt); + my($name,$param) = (${$opt} =~ m{^([^\)]+)\(([^\)]+)\)$}); + return unless defined($param); + eval(sprintf('$%s = "%s";',$name,$param)); + ${$opt} = $name; +} + 1; # return true diff --git a/libGM.pl b/libGM.pl