1 |
|
|
/* |
2 |
|
|
Teem: Tools to process and visualize scientific data and images . |
3 |
|
|
Copyright (C) 2013, 2012, 2011, 2010, 2009 University of Chicago |
4 |
|
|
Copyright (C) 2008, 2007, 2006, 2005 Gordon Kindlmann |
5 |
|
|
Copyright (C) 2004, 2003, 2002, 2001, 2000, 1999, 1998 University of Utah |
6 |
|
|
|
7 |
|
|
This library is free software; you can redistribute it and/or |
8 |
|
|
modify it under the terms of the GNU Lesser General Public License |
9 |
|
|
(LGPL) as published by the Free Software Foundation; either |
10 |
|
|
version 2.1 of the License, or (at your option) any later version. |
11 |
|
|
The terms of redistributing and/or modifying this software also |
12 |
|
|
include exceptions to the LGPL that facilitate static linking. |
13 |
|
|
|
14 |
|
|
This library is distributed in the hope that it will be useful, |
15 |
|
|
but WITHOUT ANY WARRANTY; without even the implied warranty of |
16 |
|
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
17 |
|
|
Lesser General Public License for more details. |
18 |
|
|
|
19 |
|
|
You should have received a copy of the GNU Lesser General Public License |
20 |
|
|
along with this library; if not, write to Free Software Foundation, Inc., |
21 |
|
|
51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA |
22 |
|
|
*/ |
23 |
|
|
|
24 |
|
|
#include <teem/unrrdu.h> |
25 |
|
|
|
26 |
|
|
/* learning columns |
27 |
|
|
#include <sys/types.h> |
28 |
|
|
#include <sys/ioctl.h> |
29 |
|
|
*/ |
30 |
|
|
|
31 |
|
|
#define UNU "unu" |
32 |
|
|
|
33 |
|
|
int |
34 |
|
|
main(int argc, const char **argv) { |
35 |
|
|
int i, ret; |
36 |
|
|
const char *me; |
37 |
|
|
char *argv0 = NULL; |
38 |
|
|
hestParm *hparm; |
39 |
|
|
airArray *mop; |
40 |
|
|
|
41 |
|
|
me = argv[0]; |
42 |
|
|
|
43 |
|
|
/* parse environment variables first, in case they break nrrdDefault* |
44 |
|
|
or nrrdState* variables in a way that nrrdSanity() should see */ |
45 |
|
|
nrrdDefaultGetenv(); |
46 |
|
|
nrrdStateGetenv(); |
47 |
|
|
|
48 |
|
|
/* if user hasn't tried to set nrrdStateKindNoop by an environment |
49 |
|
|
variable, we set it to false, since its probably what people expect */ |
50 |
|
|
if (!getenv(nrrdEnvVarStateKindNoop)) { |
51 |
|
|
nrrdStateKindNoop = AIR_FALSE; |
52 |
|
|
} |
53 |
|
|
|
54 |
|
|
/* if user hasn't tried to set nrrdStateKeyValuePairsPropagate by an envvar, |
55 |
|
|
we set it to true, since that's probably what unu users expect */ |
56 |
|
|
if (!getenv(nrrdEnvVarStateKeyValuePairsPropagate)) { |
57 |
|
|
nrrdStateKeyValuePairsPropagate = AIR_TRUE; |
58 |
|
|
} |
59 |
|
|
|
60 |
|
|
/* no harm done in making sure we're sane */ |
61 |
|
|
nrrdSanityOrDie(me); |
62 |
|
|
|
63 |
|
|
mop = airMopNew(); |
64 |
|
|
hparm = hestParmNew(); |
65 |
|
|
airMopAdd(mop, hparm, (airMopper)hestParmFree, airMopAlways); |
66 |
|
|
hparm->elideSingleEnumType = AIR_TRUE; |
67 |
|
|
hparm->elideSingleOtherType = AIR_TRUE; |
68 |
|
|
hparm->elideSingleOtherDefault = AIR_TRUE; |
69 |
|
|
hparm->elideSingleNonExistFloatDefault = AIR_TRUE; |
70 |
|
|
hparm->elideMultipleNonExistFloatDefault = AIR_TRUE; |
71 |
|
|
hparm->elideSingleEmptyStringDefault = AIR_TRUE; |
72 |
|
|
hparm->elideMultipleEmptyStringDefault = AIR_TRUE; |
73 |
|
|
hparm->columns = unrrduDefNumColumns; |
74 |
|
|
/* learning columns |
75 |
|
|
if (1) { |
76 |
|
|
struct winsize ws; |
77 |
|
|
ioctl(1, TIOCGWINSZ, &ws); |
78 |
|
|
hparm->columns = ws.ws_col - 1; |
79 |
|
|
} |
80 |
|
|
*/ |
81 |
|
|
hparm->greedySingleString = AIR_TRUE; |
82 |
|
|
|
83 |
|
|
/* if there are no arguments, then we give general usage information */ |
84 |
|
|
if (1 >= argc) { |
85 |
|
|
unrrduUsageUnu("unu", hparm); |
86 |
|
|
airMopError(mop); |
87 |
|
|
exit(1); |
88 |
|
|
} |
89 |
|
|
/* else, we see if its --version */ |
90 |
|
|
if (!strcmp("--version", argv[1])) { |
91 |
|
|
char vbuff[AIR_STRLEN_LARGE]; |
92 |
|
|
airTeemVersionSprint(vbuff); |
93 |
|
|
printf("%s\n", vbuff); |
94 |
|
|
exit(0); |
95 |
|
|
} |
96 |
|
|
/* else, we should see if they're asking for a command we know about */ |
97 |
|
|
for (i=0; unrrduCmdList[i]; i++) { |
98 |
|
|
if (!strcmp(argv[1], unrrduCmdList[i]->name)) { |
99 |
|
|
break; |
100 |
|
|
} |
101 |
|
|
if (!strcmp("--help", argv[1]) |
102 |
|
|
&& !strcmp("about", unrrduCmdList[i]->name)) { |
103 |
|
|
break; |
104 |
|
|
} |
105 |
|
|
} |
106 |
|
|
/* unrrduCmdList[] is NULL-terminated */ |
107 |
|
|
if (unrrduCmdList[i]) { |
108 |
|
|
/* yes, we have that command */ |
109 |
|
|
/* initialize variables used by the various commands */ |
110 |
|
|
argv0 = AIR_CALLOC(strlen(UNU) + strlen(argv[1]) + 2, char); |
111 |
|
|
airMopMem(mop, &argv0, airMopAlways); |
112 |
|
|
sprintf(argv0, "%s %s", UNU, argv[1]); |
113 |
|
|
|
114 |
|
|
/* run the individual unu program, saving its exit status */ |
115 |
|
|
ret = unrrduCmdList[i]->main(argc-2, argv+2, argv0, hparm); |
116 |
|
|
} else { |
117 |
|
|
fprintf(stderr, "%s: unrecognized command \"%s\"; type \"%s\" for " |
118 |
|
|
"complete list\n", me, argv[1], me); |
119 |
|
|
ret = 1; |
120 |
|
|
} |
121 |
|
|
|
122 |
|
|
airMopDone(mop, ret); |
123 |
|
|
return ret; |
124 |
|
|
} |