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
|
||||||
@ -424,54 +425,54 @@ static bool checktopdirs(RclConfig *config, vector<string>& nonexist)
|
|||||||
string thisprog;
|
string thisprog;
|
||||||
|
|
||||||
static const char usage [] =
|
static const char usage [] =
|
||||||
"\n"
|
"\n"
|
||||||
"recollindex [-h] \n"
|
"recollindex [-h] \n"
|
||||||
" Print help\n"
|
" Print help\n"
|
||||||
"recollindex [-z|-Z] [-k]\n"
|
"recollindex [-z|-Z] [-k]\n"
|
||||||
" Index everything according to configuration file\n"
|
" Index everything according to configuration file\n"
|
||||||
" -z : reset database before starting indexing\n"
|
" -z : reset database before starting indexing\n"
|
||||||
" -Z : in place reset: consider all documents as changed. Can also\n"
|
" -Z : in place reset: consider all documents as changed. Can also\n"
|
||||||
" be combined with -i or -r but not -m\n"
|
" be combined with -i or -r but not -m\n"
|
||||||
" -k : retry files on which we previously failed\n"
|
" -k : retry files on which we previously failed\n"
|
||||||
#ifdef RCL_MONITOR
|
#ifdef RCL_MONITOR
|
||||||
"recollindex -m [-w <secs>] -x [-D] [-C]\n"
|
"recollindex -m [-w <secs>] -x [-D] [-C]\n"
|
||||||
" Perform real time indexing. Don't become a daemon if -D is set.\n"
|
" Perform real time indexing. Don't become a daemon if -D is set.\n"
|
||||||
" -w sets number of seconds to wait before starting.\n"
|
" -w sets number of seconds to wait before starting.\n"
|
||||||
" -C disables monitoring config for changes/reexecuting.\n"
|
" -C disables monitoring config for changes/reexecuting.\n"
|
||||||
" -n disables initial incremental indexing (!and purge!).\n"
|
" -n disables initial incremental indexing (!and purge!).\n"
|
||||||
#ifndef DISABLE_X11MON
|
#ifndef DISABLE_X11MON
|
||||||
" -x disables exit on end of x11 session\n"
|
" -x disables exit on end of x11 session\n"
|
||||||
#endif /* DISABLE_X11MON */
|
#endif /* DISABLE_X11MON */
|
||||||
#endif /* RCL_MONITOR */
|
#endif /* RCL_MONITOR */
|
||||||
"recollindex -e [<filepath [path ...]>]\n"
|
"recollindex -e [<filepath [path ...]>]\n"
|
||||||
" Purge data for individual files. No stem database updates.\n"
|
" Purge data for individual files. No stem database updates.\n"
|
||||||
" Reads paths on stdin if none is given as argument.\n"
|
" Reads paths on stdin if none is given as argument.\n"
|
||||||
"recollindex -i [-f] [-Z] [<filepath [path ...]>]\n"
|
"recollindex -i [-f] [-Z] [<filepath [path ...]>]\n"
|
||||||
" Index individual files. No database purge or stem database updates\n"
|
" Index individual files. No database purge or stem database updates\n"
|
||||||
" Will read paths on stdin if none is given as argument\n"
|
" Will read paths on stdin if none is given as argument\n"
|
||||||
" -f : ignore skippedPaths and skippedNames while doing this\n"
|
" -f : ignore skippedPaths and skippedNames while doing this\n"
|
||||||
"recollindex -r [-K] [-f] [-Z] [-p pattern] <top> \n"
|
"recollindex -r [-K] [-f] [-Z] [-p pattern] <top> \n"
|
||||||
" Recursive partial reindex. \n"
|
" Recursive partial reindex. \n"
|
||||||
" -p : filter file names, multiple instances are allowed, e.g.: \n"
|
" -p : filter file names, multiple instances are allowed, e.g.: \n"
|
||||||
" -p *.odt -p *.pdf\n"
|
" -p *.odt -p *.pdf\n"
|
||||||
" -K : skip previously failed files (they are retried by default)\n"
|
" -K : skip previously failed files (they are retried by default)\n"
|
||||||
"recollindex -l\n"
|
"recollindex -l\n"
|
||||||
" List available stemming languages\n"
|
" List available stemming languages\n"
|
||||||
"recollindex -s <lang>\n"
|
"recollindex -s <lang>\n"
|
||||||
" Build stem database for additional language <lang>\n"
|
" Build stem database for additional language <lang>\n"
|
||||||
"recollindex -E\n"
|
"recollindex -E\n"
|
||||||
" Check configuration file for topdirs and other paths existence\n"
|
" Check configuration file for topdirs and other paths existence\n"
|
||||||
#ifdef FUTURE_IMPROVEMENT
|
#ifdef FUTURE_IMPROVEMENT
|
||||||
"recollindex -W\n"
|
"recollindex -W\n"
|
||||||
" Process the Web queue\n"
|
" Process the Web queue\n"
|
||||||
#endif
|
#endif
|
||||||
#ifdef RCL_USE_ASPELL
|
#ifdef RCL_USE_ASPELL
|
||||||
"recollindex -S\n"
|
"recollindex -S\n"
|
||||||
" Build aspell spelling dictionary.>\n"
|
" Build aspell spelling dictionary.>\n"
|
||||||
#endif
|
#endif
|
||||||
"Common options:\n"
|
"Common options:\n"
|
||||||
" -c <configdir> : specify config directory, overriding $RECOLL_CONFDIR\n"
|
" -c <configdir> : specify config directory, overriding $RECOLL_CONFDIR\n"
|
||||||
;
|
;
|
||||||
|
|
||||||
static void
|
static void
|
||||||
Usage(FILE *where = stderr)
|
Usage(FILE *where = stderr)
|
||||||
@ -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