summaryrefslogtreecommitdiffstats
path: root/debian/htdig/htdig-3.2.0b6/htdb/mifluzload.cc
blob: 2cd5b31d6903dbd4192bcbab9575666d1a683658 (plain)
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
//
// NAME
// 
// load the content of an inverted index.
//
// SYNOPSIS
//
// mifluzload file
//
// DESCRIPTION
//
// mifluzload reads from <b>stdout</b> a complete ascii description
// of the <b>file</b> inverted index using the <i>WordList::Read</i>
// method. 
//
// ENVIRONMENT
//
// <b>MIFLUZ_CONFIG</b>
// file name of configuration file read by WordContext(3). Defaults to
// <b>~/.mifluz.</b> 
// 
// 
// END
//
// 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>
//

#ifdef HAVE_CONFIG_H
#include "htconfig.h"
#endif /* HAVE_CONFIG_H */

#include <stdlib.h>
#include <unistd.h>
#ifdef HAVE_GETOPT_H
#include <getopt.h>
#endif /* HAVE_GETOPT_H */
#include <locale.h>

#include <htString.h>
#include <WordContext.h>
#include <WordList.h>

static void action(WordContext* context, const String& file)
{
  WordList *words = context->List();
  if(words->Open(file, O_RDWR | O_TRUNC) != OK) exit(1);
  if(words->Read(stdin) < 0) exit(1);
  if(words->Close() != OK) exit(1);
  delete words;
}

static void usage()
{
  fprintf(stderr, "usage: mifluzload [-zv] file\n");
  exit(1);
}

int main(int argc, char *argv[])
{
  if(argc < 2) usage();

  setlocale(LC_ALL, "");

  //
  // Mandatory to create global data needed for the library.
  //
  WordContext *context = new WordContext();
  if(!context) exit(1);

  Configuration& config = context->GetConfiguration();

  //  extern char *optarg;
  extern int optind;
  int ch;
  while ((ch = getopt(argc, argv, "zv")) != EOF) {
    switch (ch) {
    case 'z':
      config.Add("wordlist_compress", "true");
      break;
    case 'v':
      {
	int value = config.Value("wordlist_verbose", 0);
	value++;
	char value_string[64];
	sprintf(value_string, "%d", value);
	config.Add("wordlist_verbose", value_string);
      }
      break;
    default:
      usage();
      break;
    }
  }

  context->ReInitialize();

  action(context, argv[optind]);
  delete context;
}