forked from OctaForge/OctaBuild
remove usage of getopt (replace with manual handling until arg parser is complete)
This commit is contained in:
parent
4dc4669dd9
commit
f1af0b747e
40
main.cc
40
main.cc
|
@ -1,4 +1,3 @@
|
||||||
#include <unistd.h>
|
|
||||||
#include <pthread.h>
|
#include <pthread.h>
|
||||||
|
|
||||||
#include <ostd/types.hh>
|
#include <ostd/types.hh>
|
||||||
|
@ -533,33 +532,40 @@ int main(int argc, char **argv) {
|
||||||
|
|
||||||
ConstCharRange fcont;
|
ConstCharRange fcont;
|
||||||
|
|
||||||
int ac;
|
int posarg = argc;
|
||||||
while ((ac = getopt(argc, argv, "C:f:hj:e:E")) >= 0) {
|
for (int i = 1; i < argc; ++i) if (argv[i][0] == '-') {
|
||||||
switch (ac) {
|
char argn = argv[i][1];
|
||||||
|
if (argn == 'E') {
|
||||||
|
os.ignore_env = true;
|
||||||
|
continue;
|
||||||
|
} else if ((argn == 'h') || ((argv[i][2] == '\0') && ((i + 1) >= argc))) {
|
||||||
|
return ob_print_help(argv[0], (argn == 'h') ? ostd::out
|
||||||
|
: ostd::err, 0);
|
||||||
|
}
|
||||||
|
const char *val = (argv[i][2] == '\0') ? argv[++i] : &argv[i][2];
|
||||||
|
switch (argn) {
|
||||||
case 'C':
|
case 'C':
|
||||||
if (!ostd::directory_change(optarg))
|
if (!ostd::directory_change(val))
|
||||||
return os.error(1, "failed changing directory: %s", optarg);
|
return os.error(1, "failed changing directory: %s", val);
|
||||||
break;
|
break;
|
||||||
case 'f':
|
case 'f':
|
||||||
deffile = optarg;
|
deffile = val;
|
||||||
break;
|
break;
|
||||||
case 'e':
|
case 'e':
|
||||||
fcont = optarg;
|
fcont = val;
|
||||||
break;
|
break;
|
||||||
case 'h':
|
|
||||||
return ob_print_help(argv[0], ostd::out, 0);
|
|
||||||
case 'j': {
|
case 'j': {
|
||||||
int val = atoi(optarg);
|
int ival = atoi(val);
|
||||||
if (!val) val = ncpus;
|
if (!ival) ival = ncpus;
|
||||||
os.jobs = ostd::max(1, val);
|
os.jobs = ostd::max(1, ival);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
case 'E':
|
|
||||||
os.ignore_env = true;
|
|
||||||
break;
|
|
||||||
default:
|
default:
|
||||||
return ob_print_help(argv[0], ostd::err, 1);
|
return ob_print_help(argv[0], ostd::err, 1);
|
||||||
}
|
}
|
||||||
|
} else {
|
||||||
|
posarg = i;
|
||||||
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
tpool.init(os.jobs);
|
tpool.init(os.jobs);
|
||||||
|
@ -630,5 +636,5 @@ int main(int argc, char **argv) {
|
||||||
if (os.rules.empty())
|
if (os.rules.empty())
|
||||||
return os.error(1, "no targets");
|
return os.error(1, "no targets");
|
||||||
|
|
||||||
return os.exec_main((optind < argc) ? argv[optind] : "default");
|
return os.exec_main((posarg < argc) ? argv[posarg] : "default");
|
||||||
}
|
}
|
Loading…
Reference in a new issue