antsusage.pl
changeset 35 d3f6ca34c4ea
parent 32 4c6434bb5124
child 47 dde46143288c
equal deleted inserted replaced
34:3f19926428a1 35:d3f6ca34c4ea
     1 #/usr/bin/perl
     1 #/usr/bin/perl
     2 #======================================================================
     2 #======================================================================
     3 #                    A N T S U S A G E . P L 
     3 #                    A N T S U S A G E . P L 
     4 #                    doc: Fri Jun 19 13:43:05 1998
     4 #                    doc: Fri Jun 19 13:43:05 1998
     5 #                    dlm: Wed Aug 30 16:21:35 2017
     5 #                    dlm: Wed Dec 13 09:09:58 2017
     6 #                    (c) 1998 A.M. Thurnherr
     6 #                    (c) 1998 A.M. Thurnherr
     7 #                    uE-Info: 164 80 NIL 0 0 70 2 2 4 NIL ofnI
     7 #                    uE-Info: 167 49 NIL 0 0 70 2 2 4 NIL ofnI
     8 #======================================================================
     8 #======================================================================
     9 
     9 
    10 # HISTORY:
    10 # HISTORY:
    11 #	Dec 30, 1998: - removed directory from $0
    11 #	Dec 30, 1998: - removed directory from $0
    12 #				  - added global -P option (pass comments)
    12 #				  - added global -P option (pass comments)
   160 #	Jan 31, 2015: - made it work
   160 #	Jan 31, 2015: - made it work
   161 #	May 15, 2015: - changed (()) semantics to expand only to existing files
   161 #	May 15, 2015: - changed (()) semantics to expand only to existing files
   162 #	Aug 24, 2016: - removed -ve number heuristics (unshifting a -- under certain conditions),
   162 #	Aug 24, 2016: - removed -ve number heuristics (unshifting a -- under certain conditions),
   163 #				  	which I believe is ancient
   163 #				  	which I believe is ancient
   164 #	Aug 30, 2017: - BUG: new (()) semantics did not work for single-value ranges
   164 #	Aug 30, 2017: - BUG: new (()) semantics did not work for single-value ranges
       
   165 #	Dec  9, 2017: - added -E, $antsSuppressCommonOptions
       
   166 #				  - common options cosmetics
       
   167 #	Dec 13, 2017: - BUG: common options cosmetics
   165 
   168 
   166 # NOTES:
   169 # NOTES:
   167 #	- ksh expands {}-arguments with commas in them!!! Use + instead
   170 #	- ksh expands {}-arguments with commas in them!!! Use + instead
   168 
   171 
   169 use Getopt::Std;
   172 use Getopt::Std;
   174 	} else {
   177 	} else {
   175 		print(STDERR "\n$0\n\n")
   178 		print(STDERR "\n$0\n\n")
   176 	}
   179 	}
   177 	if ($opt_U) {
   180 	if ($opt_U) {
   178 		print(STDERR "Options & Arguments: $antsCurUsage$_[0]\n\n" .
   181 		print(STDERR "Options & Arguments: $antsCurUsage$_[0]\n\n" .
   179 			"Common Options:\n" .
   182 			"Common Input Options:\n" .
       
   183 	            "\t[-I)nput <field-separator>]\n" .
       
   184 				"\t[-S)elect <addr-expr>] [-N)ums f[,...]] [-H)ead <n lines>]\n" .
       
   185 				"\t[-L)oad <lib,...>]\n" .
       
   186 				"\t[allows -E)mbedded layout changes]\n\n" .
       
   187 			"Common Output Options:\n" .
   180 				"\t[-F)ields {%P|f|[\$@]|[f]=expr}[,...]]\n" .
   188 				"\t[-F)ields {%P|f|[\$@]|[f]=expr}[,...]]\n" .
   181 				"\t[num for-M)at] [-C)anonical numbers] [-G)eographic lat/lon]\n" .
   189 				"\t[num for-M)at] [-C)anonical numbers] [-G)eographic lat/lon]\n" .
   182 				"\t[-A)ctivate output] [LaTeX -T)able output]\n" .
   190 				"\t[-A)ctivate output] [LaTeX -T)able output]\n" .
   183 				"\t[-S)elect <addr-expr>] [-N)ums f[,...]] [-H)ead <n lines>]\n" .
       
   184 				"\t[-P)ass comments] [-Q)uiet (no headers)] [-X (no new header)]\n" .
   191 				"\t[-P)ass comments] [-Q)uiet (no headers)] [-X (no new header)]\n" .
   185 				"\t[suppress -D)ependency checks & addition of new dependencies]\n" .
   192 				"\t[suppress -D)ependency checks & addition of new dependencies]\n" .
   186 				"\t[-L)oad <lib,...>]\n" .
   193 	            "\t[-O)utput <field-separator>] [output -R)ecord <separator>]\n\n" .
   187 	            "\t[-I)n field-sep] [-O)ut field-sep] [-R)ecord sep]\n\n" .
       
   188 			"Special Argument Expansion:\n" .
   194 			"Special Argument Expansion:\n" .
   189 				"\t@<file>:<field>\t\t\t<field> values in <file>\n" .
   195 				"\t@<file>:<field>\t\t\t<field> values in <file>\n" .
   190 				"\t#<from>-<to>[:<step>]\t\tenumerated values\n" .
   196 				"\t#<from>-<to>[:<step>]\t\tenumerated values\n" .
   191 				"\t[prefix]{<ranges>}[suffix]\texisting files (ranges: <from>[-<to>][+...])\n" .
   197 				"\t[prefix]{<ranges>}[suffix]\texisting files (ranges: <from>[-<to>][+...])\n" .
   192 				"\t[prefix]((<file>))[suffix]\tfiles, using <file> with ranges\n");
   198 				"\t[prefix]((<file>))[suffix]\tfiles, using <file> with ranges\n");
   198 
   204 
   199 # NB: "-" as first char in opts string disables common-option processing
   205 # NB: "-" as first char in opts string disables common-option processing
   200 
   206 
   201 sub antsUsage($$@) {									# handle options
   207 sub antsUsage($$@) {									# handle options
   202 	my($opts,$min,@usage) = @_;
   208 	my($opts,$min,@usage) = @_;
   203 	my($cOpts) = 'ADM:QN:XCGPH:UI:O:R:L:F:S:T';
   209 	my($cOpts) = 'ADEM:QN:XCGPH:UI:O:R:L:F:S:T';
   204 	my($d,$p);
   210 	my($d,$p);
   205 	$antsCurUsage .= "\n\t[print full -U)sage]";
   211 
       
   212 	if ($antsSuppressCommonOptions) {					# non-core utilites (e.g. LADCP_w) do not use common options
       
   213 		$cOpts = ''
       
   214 	} else {
       
   215 		$antsCurUsage .= "\n\t[print full -U)sage]"
       
   216 	}
       
   217 	
   206 	foreach my $uln (@usage) {
   218 	foreach my $uln (@usage) {
   207 		$antsCurUsage .= "\n\t$uln"						# suppress emtpy, e.g.
   219 		$antsCurUsage .= "\n\t$uln"						# suppress emtpy, e.g.
   208 			unless ($uln eq '');						# for interp. model usage
   220 			unless ($uln eq '');						# for interp. model usage
   209 	}
   221 	}
   210 
   222 
   254 
   266 
   255 		croak("$0: illegal option combination (-P & -Q)\n")
   267 		croak("$0: illegal option combination (-P & -Q)\n")
   256 			if ($opt_P && $opt_Q);
   268 			if ($opt_P && $opt_Q);
   257 
   269 
   258 		&antsActivateOut() if ($opt_A);					# activate output
   270 		&antsActivateOut() if ($opt_A);					# activate output
       
   271 
       
   272 		$antsAllowEmbeddedLayoutChange = $opt_E;		# allow embedded layout changes
   259 
   273 
   260 		if ($opt_T) {									# LaTeX table output
   274 		if ($opt_T) {									# LaTeX table output
   261 			croak("$0: illegal option combination (-T & -G)\n")
   275 			croak("$0: illegal option combination (-T & -G)\n")
   262 				if ($opt_G);
   276 				if ($opt_G);
   263 			croak("$0: illegal option combination (-T & -O)\n")
   277 			croak("$0: illegal option combination (-T & -O)\n")