From 4576cf7285e4a880cc478c7e38537924578f3717 Mon Sep 17 00:00:00 2001 From: Jean-Francois Dockes Date: Thu, 6 Aug 2020 15:58:46 +0200 Subject: [PATCH] fileudi test driver: improve --- src/testmains/Makefile.am | 5 ++++- src/testmains/trfileudi.cpp | 40 ++++++++++++++++++++++++------------- src/utils/fileudi.cpp | 4 ++-- 3 files changed, 32 insertions(+), 17 deletions(-) diff --git a/src/testmains/Makefile.am b/src/testmains/Makefile.am index d4f5afd1..ee1e0a2d 100644 --- a/src/testmains/Makefile.am +++ b/src/testmains/Makefile.am @@ -38,7 +38,7 @@ AM_CPPFLAGS = -Wall -Wno-unused -std=c++11 \ $(DEFS) noinst_PROGRAMS = textsplit utf8iter fstreewalk rclconfig hldata unac mbox \ - circache wipedir mimetype pathut + circache wipedir mimetype pathut fileudi textsplit_SOURCES = trtextsplit.cpp textsplit_LDADD = ../librecoll.la @@ -52,6 +52,9 @@ mimetype_LDADD = ../librecoll.la utf8iter_SOURCES = trutf8iter.cpp utf8iter_LDADD = ../librecoll.la +fileudi_SOURCES = trfileudi.cpp +fileudi_LDADD = ../librecoll.la + fstreewalk_SOURCES = trfstreewalk.cpp fstreewalk_LDADD = ../librecoll.la diff --git a/src/testmains/trfileudi.cpp b/src/testmains/trfileudi.cpp index 9c169be6..d48d8470 100644 --- a/src/testmains/trfileudi.cpp +++ b/src/testmains/trfileudi.cpp @@ -20,25 +20,37 @@ #include "fileudi.h" -#include +#include + +#include #include using namespace std; int main(int argc, char **argv) { - string path="/usr/lib/toto.cpp"; - string ipath = "1:2:3:4:5:10"; + if (argc > 3) { + std::cerr << "Usage: trfileudi [ipath]\n"; + std::cerr << "Usage: trfileudi #reads stdin for paths\n"; + return 1; + } string udi; - make_udi(path, ipath, udi); - printf("udi [%s]\n", udi.c_str()); - path = "/some/much/too/looooooooooooooong/path/bla/bla/bla" - "/looooooooooooooong/path/bla/bla/bla/llllllllllllllllll" - "/looooooooooooooong/path/bla/bla/bla/llllllllllllllllll"; - ipath = "1:2:3:4:5:10" - "1:2:3:4:5:10" - "1:2:3:4:5:10"; - make_udi(path, ipath, udi); - printf("udi [%s]\n", udi.c_str()); + if (argc == 1) { + char buffer[2048]; + while (fgets(buffer, 2048, stdin)) { + std::string path(buffer, strlen(buffer)-1); + make_udi(path, "", udi); + std::cout << udi << "\n"; + } + return 0; + } else { + string path = argv[1]; + string ipath; + if (argc == 3) { + ipath = argv[2]; + } + make_udi(path, ipath, udi); + std::cout << udi << "\n"; + return 0; + } } - diff --git a/src/utils/fileudi.cpp b/src/utils/fileudi.cpp index 85a1f53a..4a77142f 100644 --- a/src/utils/fileudi.cpp +++ b/src/utils/fileudi.cpp @@ -16,8 +16,8 @@ */ #include "autoconfig.h" -#include #include +#include #include "fileudi.h" #include "md5.h" @@ -34,7 +34,7 @@ using std::string; void pathHash(const std::string &path, std::string &phash, unsigned int maxlen) { if (maxlen < HASHLEN) { - fprintf(stderr, "pathHash: internal error: requested len too small\n"); + std::cerr << "pathHash: internal error: requested len too small\n"; abort(); }