ptrans: do not transform the translations input by the user (no path_canon()),

these could be foreign (windows x unix).
fileurltolocalpath: remove the '/' in front of a windows drive letter path even
when not built on Windows
Move all the dubious recoll-specific url code from the generic pathut to rclutil
This commit is contained in:
Jean-Francois Dockes
2022-05-18 08:47:02 +02:00
parent fbfa818a3a
commit be12db218b
8 changed files with 276 additions and 237 deletions
+4 -1
View File
@@ -39,7 +39,7 @@ AM_CPPFLAGS = -Wall -Wno-unused -std=c++11 \
$(DEFS)
noinst_PROGRAMS = plaintorich textsplit fstreewalk rclconfig hldata unac mbox \
circache wipedir mimetype fileudi x11mon trqrstore ecrontab rcldb
circache wipedir mimetype fileudi x11mon trqrstore ecrontab rcldb rclutil
ecrontab_SOURCES = trecrontab.cpp
ecrontab_LDADD = ../librecoll.la
@@ -68,6 +68,9 @@ rclconfig_LDADD = ../librecoll.la
rcldb_SOURCES = trrcldb.cpp
rcldb_LDADD = ../librecoll.la
rclutil_SOURCES = trrclutil.cpp
rclutil_LDADD = ../librecoll.la
textsplit_SOURCES = trtextsplit.cpp
textsplit_LDADD = ../librecoll.la
+65 -24
View File
@@ -1,6 +1,30 @@
#include "rclutil.h"
#include <getopt.h>
#include <iostream>
#include <map>
#include "pathut.h"
using namespace std;
static std::map<std::string, int> options {
{"path_to_thumb", 0},
{"url_encode", 0},
};
static const char *thisprog;
static void Usage(void)
{
string sopts;
for (const auto& opt: options) {
sopts += "--" + opt.first + "\n";
}
fprintf(stderr, "%s: usage: %s\n%s", thisprog, thisprog, sopts.c_str());
exit(1);
}
void path_to_thumb(const string& _input)
{
@@ -17,35 +41,52 @@ void path_to_thumb(const string& _input)
thumbPathForUrl(input, 7, path);
cout << path << endl;
}
const char *thisprog;
int main(int argc, const char **argv)
int main(int argc, char **argv)
{
thisprog = *argv++;
argc--;
thisprog = *argv;
std::vector<struct option> long_options;
string s;
vector<string>::const_iterator it;
#if 0
if (argc > 1) {
cerr << "Usage: thumbpath <filepath>" << endl;
exit(1);
for (auto& entry : options) {
struct option opt;
opt.name = entry.first.c_str();
opt.has_arg = 0;
opt.flag = &entry.second;
opt.val = 1;
long_options.push_back(opt);
}
string input;
if (argc == 1) {
input = *argv++;
if (input.empty()) {
cerr << "Usage: thumbpath <filepath>" << endl;
exit(1);
long_options.push_back({0, 0, 0, 0});
while (getopt_long(argc, argv, "", &long_options[0], nullptr) != -1) {
}
if (options["path_to_thumb"]) {
if (optind >= argc) {
cerr << "Usage: trrcutil --path_to_thumb <filepath>" << "\n";
return 1;
}
string input = argv[optind];
optind++;
if (optind != argc) {
return 1;
}
path_to_thumb(input);
} else {
while (getline(cin, input)) {
path_to_thumb(input);
} else if (options["url_encode"]) {
if (optind >= argc) {
cerr << "Usage: trsmallut --url_encode <arg> [offs=0]\n";
return 1;
}
string s = argv[optind];
optind++;
int offs = 0;
if (optind != argc) {
offs = atoi(argv[optind]);
optind++;
}
if (optind != argc) {
return 1;
}
cout << "url_encode(" << s << ", " << offs << ") -> [" << url_encode(s, offs) << "]\n";
} else {
Usage();
}
exit(0);
#endif
}