1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199
|
//
// htload.cc
//
// htload: A utility to read ASCII text versions of the document
// and/or word databases. These can be used by external programs,
// edited, or used as a platform and version-independent form of the DB.
//
// Part of the ht://Dig package <http://www.htdig.org/>
// Copyright (c) 1999-2004 The ht://Dig Group
// For copyright details, see the file COPYING in your distribution
// or the GNU Library General Public License (LGPL) version 2 or later
// <http://www.gnu.org/copyleft/lgpl.html>
//
// $Id: htload.cc,v 1.6 2004/05/28 13:15:25 lha Exp $
//
#ifdef HAVE_CONFIG_H
#include "htconfig.h"
#endif /* HAVE_CONFIG_H */
#include "WordContext.h"
#include "HtURLCodec.h"
#include "HtWordList.h"
#include "HtConfiguration.h"
#include "DocumentDB.h"
#include "defaults.h"
#include <errno.h>
#ifndef _MSC_VER /* _WIN32 */
#include <unistd.h>
#endif
// If we have this, we probably want it.
#ifdef HAVE_GETOPT_H
#include <getopt.h>
#elif HAVE_GETOPT_LOCAL
#include <getopt_local.h>
#endif
int verbose = 0;
void usage();
void reportError(char *msg);
//*****************************************************************************
// int main(int ac, char **av)
//
int main(int ac, char **av)
{
int do_words = 1;
int do_docs = 1;
int alt_work_area = 0;
String configfile = DEFAULT_CONFIG_FILE;
int c;
extern char *optarg;
while ((c = getopt(ac, av, "vdwc:a")) != -1)
{
switch (c)
{
case 'c':
configfile = optarg;
break;
case 'v':
verbose++;
break;
case 'a':
alt_work_area++;
break;
case 'w':
do_words = 0;
break;
case 'd':
do_docs = 0;
break;
case '?':
usage();
break;
}
}
HtConfiguration* config= HtConfiguration::config();
config->Defaults(&defaults[0]);
if (access((char*)configfile, R_OK) < 0)
{
reportError(form("Unable to find configuration file '%s'",
configfile.get()));
}
config->Read(configfile);
//
// Check url_part_aliases and common_url_parts for
// errors.
String url_part_errors = HtURLCodec::instance()->ErrMsg();
if (url_part_errors.length() != 0)
reportError(form("Invalid url_part_aliases or common_url_parts: %s",
url_part_errors.get()));
// We may need these through the methods we call
if (alt_work_area != 0)
{
String configValue;
configValue = config->Find("word_db");
if (configValue.length() != 0)
{
configValue << ".work";
config->Add("word_db", configValue);
}
configValue = config->Find("doc_db");
if (configValue.length() != 0)
{
configValue << ".work";
config->Add("doc_db", configValue);
}
configValue = config->Find("doc_index");
if (configValue.length() != 0)
{
configValue << ".work";
config->Add("doc_index", configValue);
}
configValue = config->Find("doc_excerpt");
if (configValue.length() != 0)
{
configValue << ".work";
config->Add("doc_excerpt", configValue);
}
}
if (do_docs)
{
const String doc_list = config->Find("doc_list");
DocumentDB docs;
if (docs.Open(config->Find("doc_db"), config->Find("doc_index"),
config->Find("doc_excerpt")) == OK)
{
docs.LoadDB(doc_list, verbose);
docs.Close();
}
}
if (do_words)
{
// Initialize htword
WordContext::Initialize(*config);
const String word_dump = config->Find("word_dump");
HtWordList words(*config);
if(words.Open(config->Find("word_db"), O_RDWR) == OK) {
words.Load(word_dump);
words.Close();
}
}
return 0;
}
//*****************************************************************************
// void usage()
// Display program usage information
//
void usage()
{
cout << "usage: htload [-v][-d][-w][-a][-c configfile]\n";
cout << "This program is part of ht://Dig " << VERSION << "\n\n";
cout << "Options:\n";
cout << "\t-v\tVerbose mode. This increases the verbosity of the\n";
cout << "\t\tprogram. Using more than 2 is probably only useful\n";
cout << "\t\tfor debugging purposes. The default verbose mode\n";
cout << "\t\tgives a progress on what it is doing and where it is.\n\n";
cout << "\t-d\tDo NOT load the document database.\n\n";
cout << "\t-w\tDo NOT load the word database.\n\n";
cout << "\t-a\tUse alternate work files.\n";
cout << "\t\tTells htload to append .work to the database files \n";
cout << "\t\tallowing it to operate on a second set of databases.\n";
cout << "\t-c configfile\n";
cout << "\t\tUse the specified configuration file instead on the\n";
cout << "\t\tdefault.\n\n";
exit(0);
}
//*****************************************************************************
// Report an error and die
//
void reportError(char *msg)
{
cout << "htload: " << msg << "\n\n";
exit(1);
}
|