recollindex: allow reading args from file arg to ease passing args on windows
This commit is contained in:
parent
9565663f09
commit
d28cb0230d
@ -47,6 +47,7 @@ using namespace std;
|
|||||||
#include "x11mon.h"
|
#include "x11mon.h"
|
||||||
#include "cancelcheck.h"
|
#include "cancelcheck.h"
|
||||||
#include "rcldb.h"
|
#include "rcldb.h"
|
||||||
|
#include "readfile.h"
|
||||||
#ifndef DISABLE_WEB_INDEXER
|
#ifndef DISABLE_WEB_INDEXER
|
||||||
#include "webqueue.h"
|
#include "webqueue.h"
|
||||||
#endif
|
#endif
|
||||||
@ -545,6 +546,26 @@ static void flushIdxReasons()
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static vector<string> argstovector(int argc, char **argv)
|
||||||
|
{
|
||||||
|
vector<string> args;
|
||||||
|
for (int i = 0; i < argc; i++) {
|
||||||
|
args.push_back(argv[i]);
|
||||||
|
}
|
||||||
|
return args;
|
||||||
|
}
|
||||||
|
static vector<string> fileToArgs(const string& fn)
|
||||||
|
{
|
||||||
|
string reason, data;
|
||||||
|
if (!file_to_string(fn, data, &reason)) {
|
||||||
|
cerr << "Failed reading args file " << fn << " errno " << errno << "\n";
|
||||||
|
exit(1);
|
||||||
|
}
|
||||||
|
vector<string> args;
|
||||||
|
stringToStrings(data, args);
|
||||||
|
return args;
|
||||||
|
}
|
||||||
|
|
||||||
int main(int argc, char **argv)
|
int main(int argc, char **argv)
|
||||||
{
|
{
|
||||||
string a_config;
|
string a_config;
|
||||||
@ -562,16 +583,27 @@ int main(int argc, char **argv)
|
|||||||
thisprog = path_absolute(argv[0]);
|
thisprog = path_absolute(argv[0]);
|
||||||
argc--; argv++;
|
argc--; argv++;
|
||||||
|
|
||||||
while (argc > 0 && **argv == '-') {
|
vector<string> args = argstovector(argc, argv);
|
||||||
(*argv)++;
|
|
||||||
if (!(**argv))
|
// Passing args through a temp file: this is used on Windows to
|
||||||
Usage();
|
// avoid issues with charsets in args (avoid using wmain)
|
||||||
while (**argv)
|
if (args.size() == 1 && args[0][0] != '-') {
|
||||||
switch (*(*argv)++) {
|
args = fileToArgs(args[0]);
|
||||||
|
}
|
||||||
|
|
||||||
|
unsigned int aremain = args.size();
|
||||||
|
unsigned int argidx = 0;
|
||||||
|
for (; argidx < args.size(); argidx++) {
|
||||||
|
const string& arg{args[argidx]};
|
||||||
|
aremain = args.size() - argidx;
|
||||||
|
if (arg[0] != '-') {
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
for (unsigned int cidx = 1; cidx < arg.size(); cidx++) {
|
||||||
|
switch (arg[cidx]) {
|
||||||
case 'b': op_flags |= OPT_b; break;
|
case 'b': op_flags |= OPT_b; break;
|
||||||
case 'c': op_flags |= OPT_c; if (argc < 2) Usage();
|
case 'c': op_flags |= OPT_c; if (aremain < 2) Usage();
|
||||||
a_config = *(++argv);
|
a_config = args[argidx+1]; argidx++; goto b1;
|
||||||
argc--; goto b1;
|
|
||||||
#ifdef RCL_MONITOR
|
#ifdef RCL_MONITOR
|
||||||
case 'C': op_flags |= OPT_C; break;
|
case 'C': op_flags |= OPT_C; break;
|
||||||
case 'D': op_flags |= OPT_D; break;
|
case 'D': op_flags |= OPT_D; break;
|
||||||
@ -587,27 +619,29 @@ int main(int argc, char **argv)
|
|||||||
case 'm': op_flags |= OPT_m; break;
|
case 'm': op_flags |= OPT_m; break;
|
||||||
case 'n': op_flags |= OPT_n; break;
|
case 'n': op_flags |= OPT_n; break;
|
||||||
case 'P': op_flags |= OPT_P; break;
|
case 'P': op_flags |= OPT_P; break;
|
||||||
case 'p': op_flags |= OPT_p; if (argc < 2) Usage();
|
case 'p': op_flags |= OPT_p; if (aremain < 2) Usage();
|
||||||
selpatterns.push_back(*(++argv));
|
selpatterns.push_back(args[argidx+1]); argidx++; goto b1;
|
||||||
argc--; goto b1;
|
|
||||||
case 'r': op_flags |= OPT_r; break;
|
case 'r': op_flags |= OPT_r; break;
|
||||||
case 'R': op_flags |= OPT_R; if (argc < 2) Usage();
|
case 'R': op_flags |= OPT_R; if (aremain < 2) Usage();
|
||||||
reasonsfile = *(++argv); argc--; goto b1;
|
reasonsfile = args[argidx+1]; argidx++; goto b1;
|
||||||
case 's': op_flags |= OPT_s; break;
|
case 's': op_flags |= OPT_s; break;
|
||||||
#ifdef RCL_USE_ASPELL
|
#ifdef RCL_USE_ASPELL
|
||||||
case 'S': op_flags |= OPT_S; break;
|
case 'S': op_flags |= OPT_S; break;
|
||||||
#endif
|
#endif
|
||||||
case 'w': op_flags |= OPT_w; if (argc < 2) Usage();
|
case 'w': op_flags |= OPT_w; if (aremain < 2) Usage();
|
||||||
if ((sscanf(*(++argv), "%d", &sleepsecs)) != 1)
|
if ((sscanf(args[argidx+1].c_str(), "%d", &sleepsecs)) != 1)
|
||||||
Usage();
|
Usage();
|
||||||
argc--; goto b1;
|
argidx++; goto b1;
|
||||||
case 'x': op_flags |= OPT_x; break;
|
case 'x': op_flags |= OPT_x; break;
|
||||||
case 'Z': op_flags |= OPT_Z; break;
|
case 'Z': op_flags |= OPT_Z; break;
|
||||||
case 'z': op_flags |= OPT_z; break;
|
case 'z': op_flags |= OPT_z; break;
|
||||||
default: Usage(); break;
|
default: Usage(); break;
|
||||||
}
|
}
|
||||||
b1: argc--; argv++;
|
|
||||||
}
|
}
|
||||||
|
b1:
|
||||||
|
;
|
||||||
|
}
|
||||||
|
|
||||||
if (op_flags & OPT_h)
|
if (op_flags & OPT_h)
|
||||||
Usage(stdout);
|
Usage(stdout);
|
||||||
#ifndef RCL_MONITOR
|
#ifndef RCL_MONITOR
|
||||||
@ -716,9 +750,9 @@ int main(int argc, char **argv)
|
|||||||
setMyPriority(config);
|
setMyPriority(config);
|
||||||
|
|
||||||
if (op_flags & OPT_r) {
|
if (op_flags & OPT_r) {
|
||||||
if (argc != 1)
|
if (aremain != 1)
|
||||||
Usage();
|
Usage();
|
||||||
string top = *argv++; argc--;
|
string top = args[argidx++]; aremain--;
|
||||||
bool status = recursive_index(config, top, selpatterns);
|
bool status = recursive_index(config, top, selpatterns);
|
||||||
if (confindexer && !confindexer->getReason().empty()) {
|
if (confindexer && !confindexer->getReason().empty()) {
|
||||||
addIdxReason("indexer", confindexer->getReason());
|
addIdxReason("indexer", confindexer->getReason());
|
||||||
@ -730,8 +764,7 @@ int main(int argc, char **argv)
|
|||||||
lockorexit(&pidfile, config);
|
lockorexit(&pidfile, config);
|
||||||
|
|
||||||
list<string> filenames;
|
list<string> filenames;
|
||||||
|
if (aremain == 0) {
|
||||||
if (argc == 0) {
|
|
||||||
// Read from stdin
|
// Read from stdin
|
||||||
char line[1024];
|
char line[1024];
|
||||||
while (fgets(line, 1023, stdin)) {
|
while (fgets(line, 1023, stdin)) {
|
||||||
@ -740,8 +773,8 @@ int main(int argc, char **argv)
|
|||||||
filenames.push_back(sl);
|
filenames.push_back(sl);
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
while (argc--) {
|
while (aremain--) {
|
||||||
filenames.push_back(*argv++);
|
filenames.push_back(args[argidx++]);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -773,7 +806,7 @@ int main(int argc, char **argv)
|
|||||||
} else if (op_flags & OPT_s) {
|
} else if (op_flags & OPT_s) {
|
||||||
if (argc != 1)
|
if (argc != 1)
|
||||||
Usage();
|
Usage();
|
||||||
string lang = *argv++; argc--;
|
string lang = args[argidx++]; aremain--;
|
||||||
exit(!createstemdb(config, lang));
|
exit(!createstemdb(config, lang));
|
||||||
#ifdef RCL_USE_ASPELL
|
#ifdef RCL_USE_ASPELL
|
||||||
} else if (op_flags & OPT_S) {
|
} else if (op_flags & OPT_S) {
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user