merged
authorA.M. Thurnherr <athurnherr@yahoo.com>
Thu, 05 Mar 2015 12:58:39 -0500
changeset 15 ebd8a4ddd7f2
parent 14 4097040ad31c (current diff)
parent 10 3dfa16523886 (diff)
child 16 6f2a161211ed
child 17 4b7486d77b39
merged
ANTSlib
ants.pl
antsio.pl
antsusage.pl
libGM.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
--- 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