diff --git a/src/testmains/Makefile.am b/src/testmains/Makefile.am index 2ca73e4a..6cd274ba 100644 --- a/src/testmains/Makefile.am +++ b/src/testmains/Makefile.am @@ -38,7 +38,7 @@ AM_CPPFLAGS = -Wall -Wno-unused -std=c++11 \ -D_GNU_SOURCE \ $(DEFS) -noinst_PROGRAMS = textsplit utf8iter fstreewalk rclconfig hldata unac mbox \ +noinst_PROGRAMS = plaintorich textsplit utf8iter fstreewalk rclconfig hldata unac mbox \ circache wipedir mimetype pathut fileudi x11mon trqrstore ecrontab ecrontab_SOURCES = trecrontab.cpp @@ -71,6 +71,9 @@ rclconfig_LDADD = ../librecoll.la textsplit_SOURCES = trtextsplit.cpp textsplit_LDADD = ../librecoll.la +plaintorich_SOURCES = trplaintorich.cpp +plaintorich_LDADD = ../librecoll.la + unac_SOURCES = trunac.cpp unac_LDADD = ../librecoll.la diff --git a/src/testmains/trplaintorich.cpp b/src/testmains/trplaintorich.cpp new file mode 100644 index 00000000..2a68b6c8 --- /dev/null +++ b/src/testmains/trplaintorich.cpp @@ -0,0 +1,148 @@ +/* Copyright (C) 2021-2021 J.F.Dockes + * + * License: LGPL 2.1 + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License as published by + * the Free Software Foundation; either version 2.1 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public License + * along with this program; if not, write to the + * Free Software Foundation, Inc., + * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. + */ + +// A test driver for the plaintorich highlighting module. +// Very incomplete yet, nothing about groups + +#include "autoconfig.h" + +#include "plaintorich.h" + +#include +#include +#include +#include +#include +#include +#include + +#include + +#include "readfile.h" +#include "log.h" + +using namespace std; + +#define OPT_H 0x1 +#define OPT_L 0x2 +#define OPT_t 0x4 + +static string thisprog; + +static string usage = + " plaintorich [opts] [filename]\n" + " -H : input is html\n" + " -L : set log level 0-6\n" + " -t term : add term to match. Must in index form (lowercase/unac)\n"; + ; + +static void +Usage(void) +{ + cerr << thisprog << ": usage:\n" << usage; + exit(1); +} + +static int op_flags; + +class TstPlainToRich : public PlainToRich { +public: + virtual string startMatch(unsigned int idx) { + (void)idx; +#if 0 + if (m_hdata) { + string s1, s2; + stringsToString >(m_hdata->groups[idx], s1); + stringsToString >( + m_hdata->ugroups[m_hdata->grpsugidx[idx]], s2); + LOGDEB2("Reslist startmatch: group " << s1 << " user group " << + s2 << "\n"); + } +#endif + return ""; + } + + virtual string endMatch() { + return ""; + } +}; + +int main(int argc, char **argv) +{ + int loglevel = 4; + HighlightData hldata; + bool ishtml{false}; + + thisprog = argv[0]; + argc--; argv++; + + while (argc > 0 && **argv == '-') { + (*argv)++; + if (!(**argv)) + /* Cas du "adb - core" */ + Usage(); + while (**argv) + switch (*(*argv)++) { + case 'H': ishtml = true; break; + case 'L': op_flags |= OPT_L; if (argc < 2) Usage(); + loglevel = atoi(*(++argv)); argc--; goto b1; + case 't': { + if (argc < 2) Usage(); + HighlightData::TermGroup tg; + tg.term = *(++argv); argc--; + hldata.index_term_groups.push_back(tg); + goto b1; + } + default: Usage(); break; + } + b1: argc--; argv++; + } + + Logger::getTheLog("")->setLogLevel(Logger::LogLevel(loglevel)); + + string inputdata, reason; + if (argc == 1) { + const char *filename = *argv++; argc--; + if (!file_to_string(filename, inputdata, &reason)) { + cerr << "Failed: file_to_string(" << filename << ") failed: " << reason << endl; + exit(1); + } + } else if (argc == 0) { + char buf[1024]; + int nread; + while ((nread = read(0, buf, 1024)) > 0) { + inputdata.append(buf, nread); + } + } else { + Usage(); + } + + + TstPlainToRich hiliter; + if (ishtml) { + hiliter.set_inputhtml(true); + } + std::list result; + hiliter.plaintorich(inputdata, result, hldata); + std::cout << *result.begin() << "\n"; + return 0; +} + +