update isl for isl_map_has_tuple_id
[barvinok.git] / zsolve / opts.c
blob34f849b1b953cc16c8ef2ea35f5b2e5345d68d74
1 /*
2 4ti2 -- A software package for algebraic, geometric and combinatorial
3 problems on linear spaces.
5 Copyright (C) 2006 4ti2 team.
6 Main author(s): Matthias Walter.
8 This program is free software; you can redistribute it and/or
9 modify it under the terms of the GNU General Public License
10 as published by the Free Software Foundation; either version 2
11 of the License, or (at your option) any later version.
13 This program is distributed in the hope that it will be useful,
14 but WITHOUT ANY WARRANTY; without even the implied warranty of
15 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 GNU General Public License for more details.
18 You should have received a copy of the GNU General Public License
19 along with this program; if not, write to the Free Software
20 Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
23 #include "banner.h"
24 #include "opts.h"
26 #include <stdio.h>
27 #include <stdlib.h>
28 #include <string.h>
29 #include <assert.h>
30 #include <unistd.h>
32 #ifdef __GNU_LIBRARY__
33 # include <getopt.h>
34 #endif
36 #include "defs.h"
38 extern int OVerbose;
39 extern int OLogging;
40 extern int OBackup;
41 extern bool OForce;
42 extern bool ORightHandSide;
43 extern bool OResume;
44 extern int BaseLength;
45 extern char *BaseName;
46 extern bool OHilbert;
47 extern bool OGraver;
49 // //
51 void printUsage(char *program)
53 assert(program);
55 puts(FORTY_TWO_BANNER);
57 printf("Usage: ");
58 if (OHilbert) { printf("hilbert"); }
59 else if (OGraver) { printf("graver"); }
60 else { printf("zsolve"); }
61 printf(" [options] PROJECT\n\n");
63 printf("[Basic options]\n");
64 // printf(" -f, --force computation regardless of existing PROJECT.(in)hom\n");
65 printf(" -i, --ignore system is homogeneous, regardless of PROJECT.rhs\n");
67 printf("\n[Logging options]\n");
68 printf(" -n, --logging=0 no logging (default)\n");
69 printf(" -l, --logging[=1] simple logging to PROJECT.log\n");
70 printf(" -ll, --logging=2 verbose logging to PROJECT.log\n");
71 printf(" -lll, --logging=3 very verbose logging to PROJECT.log\n");
73 printf("\n[Output options]\n");
74 printf(" -q, --quiet, --verbose=0 quiet mode\n");
75 printf(" -v, --verbose[=1] simple output (default)\n");
76 printf(" -vv, --verbose=2 verbose output\n");
77 printf(" -vvv, --verbose=3 very verbose output\n");
79 printf("\n[Backup options]\n");
80 printf(" -b[FREQ], --backup[=FREQ] frequently backup status to PROJECT.backup,\n where FREQ must be \"[1-9][0-9]*[mhd]\" for mins,\n hours or days. default is 1h\n");
81 printf(" -r, --resume resume from a backup like PROJECT.backup\n");
83 printf("\n[Other options]\n");
84 printf(" -h, --help display this help and exit\n");
86 printf("\n[Used files]\n\n");
87 printf("PROJECT.mat matrix\n");
88 printf("PROJECT.rhs right hand side (optional)\n");
89 //printf("PROJECT.rel relations (<, >, =, p)\n");
90 printf("PROJECT.rel relations (<, >, =)\n");
91 printf("PROJECT.sign sign of columns (optional)\n");
92 printf("PROJECT.lb lower bounds columns (optional)\n");
93 printf("PROJECT.ub upper bounds columns (optional)\n");
94 printf("PROJECT.backup backup file\n");
95 printf("PROJECT.zinhom inhomogeneous part of the solution\n");
96 printf("PROJECT.zhom homogeneous part of the solution\n");
97 printf("PROJECT.zfree free part of the solution\n");
99 exit(0);
102 // //
104 void getopts(int argc, char **argv)
106 int c;
107 char d;
109 #ifdef __GNU_LIBRARY__
110 static struct option long_options[] =
112 { "backup", optional_argument, NULL, 'b'},
113 { "data", no_argument, NULL, 'd'},
114 { "force", no_argument, NULL, 'f'},
115 { "help", no_argument, NULL, 'h'},
116 { "ignore", no_argument, NULL, 'i'},
117 { "logging", optional_argument, NULL, 'l'},
118 { "quiet", no_argument, NULL, 'q'},
119 { "resume", no_argument, NULL, 'r'},
120 { "verbose", optional_argument, NULL, 'v'},
121 { "hilbert", no_argument, NULL, 'H'},
122 { "graver", no_argument, NULL, 'G'}
124 #endif
126 OVerbose = 1;
127 OLogging = 0;
128 OBackup = 0;
129 OResume = false;
130 ORightHandSide = true;
131 OHilbert = false;
132 OGraver = false;
133 OForce = true;
135 #ifdef __GNU_LIBRARY__
136 while ((c = getopt_long(argc, argv, "b::d::fhinl::qrv::VHG", long_options, NULL)) != -1)
137 #else
138 while ((c = getopt(argc, argv, "b::d::fhinl::qrv::VHG")) != -1)
139 #endif
141 if (optarg!=NULL && optarg[0]=='=')
142 optarg++;
143 switch(c)
145 case 'f':
146 OForce = true;
147 break;
148 case 'i':
149 ORightHandSide = false;
150 break;
151 case 'H':
152 OHilbert = true;
153 break;
154 case 'G':
155 OGraver = true;
156 break;
157 case 'r':
158 OResume = true;
159 break;
160 case 'b':
161 if (optarg==NULL)
162 OBackup = 3600;
163 else
165 if (sscanf(optarg, "%d%c", &OBackup, &d)==2)
167 if (d=='m')
168 OBackup *= 60;
169 else if (d=='h')
170 OBackup *= 3600;
171 else if (d=='d')
172 OBackup *= 86400;
173 else if (d!='s')
175 printf("%s: invalid backup modifier %c\n", argv[0], d);
176 exit(1);
179 else
181 printf("%s: invalid backup argument -b%s\n", argv[0], optarg);
182 exit(1);
185 break;
186 case 'q':
187 OVerbose = 0;
188 break;
189 case 'v':
190 if (optarg==NULL || !strcmp(optarg, "1"))
191 OVerbose = 1;
192 else if (!strcmp(optarg, "2") || !strcmp(optarg, "v"))
193 OVerbose = 2;
194 else if (!strcmp(optarg, "3") || !strcmp(optarg, "vv"))
195 OVerbose = 3;
196 else if (!strcmp(optarg, "0"))
197 OVerbose = 0;
198 else
200 printf("%s: invalid verbose argument -v%s\n", argv[0], optarg);
201 exit(1);
203 break;
204 case 'n':
205 OLogging = 0;
206 break;
207 case 'l':
208 if (optarg==NULL || !strcmp(optarg, "1"))
209 OLogging = 1;
210 else if (!strcmp(optarg, "2") || !strcmp(optarg, "l"))
211 OLogging = 2;
212 else if (!strcmp(optarg, "3") || !strcmp(optarg, "ll"))
213 OLogging = 3;
214 else if (!strcmp(optarg, "0"))
215 OLogging = 0;
216 else
218 printf("%s: invalid verbose argument -v%s\n", argv[0], optarg);
219 exit(1);
221 break;
222 case 'h':
223 printUsage(argv[0]);
224 break;
225 case '?':
226 exit(1);
227 break;
228 default:
229 printf("c = %c, optarg = %s\n", c, optarg);
230 abort();
231 break;
235 if (OHilbert && OGraver)
237 printf("Input Error: A combination of --hilbert and --graver is not allowed!\n");
238 exit(1);
241 if (optind>=argc)
242 printUsage(argv[0]);
244 if (optind<argc-1) {
245 printf("Input Error: Only one project file is possible: You specified '%s' and '%s'!\n\n", argv[optind], argv[optind+1]);
246 exit(1);
249 BaseLength = strlen(argv[optind]);
250 BaseName = (char *)malloc((BaseLength+10)*sizeof(char));
251 if (BaseName==NULL)
253 fprintf(stderr, "Fatal Error (%s/%d): Could not allocate memory for BaseName!\n", __FILE__, __LINE__);
254 exit(1);
256 strcpy(BaseName, argv[optind]);
259 // //