"Fossies" - the Fresh Open Source Software Archive

Member "recoll-1.26.3/index/subtreelist.cpp" (4 Sep 2019, 3159 Bytes) of package /linux/privat/recoll-1.26.3.tar.gz:


As a special service "Fossies" has tried to format the requested source page into HTML format using (guessed) C and C++ source code syntax highlighting (style: standard) with prefixed line numbers and code folding option. Alternatively you can here view or download the uninterpreted source code file. For more information about "subtreelist.cpp" see the Fossies "Dox" file reference documentation.

    1 /* Copyright (C) 2007 J.F.Dockes
    2  *   This program is free software; you can redistribute it and/or modify
    3  *   it under the terms of the GNU General Public License as published by
    4  *   the Free Software Foundation; either version 2 of the License, or
    5  *   (at your option) any later version.
    6  *
    7  *   This program is distributed in the hope that it will be useful,
    8  *   but WITHOUT ANY WARRANTY; without even the implied warranty of
    9  *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
   10  *   GNU General Public License for more details.
   11  *
   12  *   You should have received a copy of the GNU General Public License
   13  *   along with this program; if not, write to the
   14  *   Free Software Foundation, Inc.,
   15  * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
   16  */
   17 
   18 #ifndef TEST_SUBTREELIST
   19 #include "autoconfig.h"
   20 
   21 #include <memory>
   22 
   23 #include "cstr.h"
   24 #include "rcldb.h"
   25 #include "searchdata.h"
   26 #include "rclquery.h"
   27 #include "subtreelist.h"
   28 #include "log.h"
   29 
   30 bool subtreelist(RclConfig *config, const string& top, 
   31          vector<string>& paths)
   32 {
   33     LOGDEB("subtreelist: top: ["  << (top) << "]\n" );
   34     Rcl::Db rcldb(config);
   35     if (!rcldb.open(Rcl::Db::DbRO)) {
   36     LOGERR("subtreelist: can't open database in ["  << (config->getDbDir()) << "]: "  << (rcldb.getReason()) << "\n" );
   37     return false;
   38     }
   39 
   40     Rcl::SearchData *sd = new Rcl::SearchData(Rcl::SCLT_OR, cstr_null);
   41     std::shared_ptr<Rcl::SearchData> rq(sd);
   42 
   43     sd->addClause(new Rcl::SearchDataClausePath(top, false));
   44 
   45     Rcl::Query query(&rcldb);
   46     query.setQuery(rq);
   47     int cnt = query.getResCnt();
   48 
   49     for (int i = 0; i < cnt; i++) {
   50     Rcl::Doc doc;
   51     if (!query.getDoc(i, doc))
   52         break;
   53     string path = fileurltolocalpath(doc.url);
   54     if (!path.empty())
   55         paths.push_back(path);
   56     }
   57     return true;
   58 }
   59 
   60 #else // TEST
   61 
   62 
   63 #include <stdio.h>
   64 #include <stdlib.h>
   65 #include <errno.h>
   66 #include <string.h>
   67 
   68 #include <iostream>
   69 #include <vector>
   70 #include <string>
   71 using namespace std;
   72 
   73 #include "subtreelist.h"
   74 #include "rclconfig.h"
   75 #include "rclinit.h"
   76 
   77 static char *thisprog;
   78 static char usage [] =
   79 " <path> : list document paths in this tree\n"
   80 ;
   81 static void
   82 Usage(void)
   83 {
   84     cerr << thisprog <<  ": usage:" << endl << usage;
   85     exit(1);
   86 }
   87 
   88 static int     op_flags;
   89 #define OPT_o     0x2 
   90 
   91 int main(int argc, char **argv)
   92 {
   93     string top;
   94 
   95     thisprog = argv[0];
   96     argc--; argv++;
   97 
   98     while (argc > 0 && **argv == '-') {
   99         (*argv)++;
  100         if (!(**argv))
  101             /* Cas du "adb - core" */
  102             Usage();
  103         while (**argv)
  104             switch (*(*argv)++) {
  105             default: Usage();   break;
  106             }
  107     argc--; argv++;
  108     }
  109     if (argc < 1)
  110     Usage();
  111     top = *argv++;argc--;
  112     string reason;
  113     RclConfig *config = recollinit(0, 0, 0, reason, 0);
  114     if (!config || !config->ok()) {
  115     fprintf(stderr, "Recoll init failed: %s\n", reason.c_str());
  116     exit(1);
  117     }
  118 
  119     vector<string> paths;
  120     if (!subtreelist(config, top, paths)) {
  121     cerr << "subtreelist failed" << endl;
  122     exit(1);
  123     }
  124     for (vector<string>::const_iterator it = paths.begin(); 
  125      it != paths.end(); it++) {
  126     cout << *it << endl;
  127     }
  128     exit(0);
  129 }
  130 #endif
  131