1 //
2 // NAME
3 //
4 // load the content of an inverted index.
5 //
6 // SYNOPSIS
7 //
8 // mifluzload file
9 //
10 // DESCRIPTION
11 //
12 // mifluzload reads from <b>stdout</b> a complete ascii description
13 // of the <b>file</b> inverted index using the <i>WordList::Read</i>
14 // method.
15 //
16 // ENVIRONMENT
17 //
18 // <b>MIFLUZ_CONFIG</b>
19 // file name of configuration file read by WordContext(3). Defaults to
20 // <b>~/.mifluz.</b>
21 //
22 //
23 // END
24 //
25 // Part of the ht://Dig package <http://www.htdig.org/>
26 // Copyright (c) 1999, 2000, 2001 The ht://Dig Group
27 // For copyright details, see the file COPYING in your distribution
28 // or the GNU General Public License version 2 or later
29 // <http://www.gnu.org/copyleft/gpl.html>
30 //
31
32 #ifdef HAVE_CONFIG_H
33 #include "config.h"
34 #endif /* HAVE_CONFIG_H */
35
36 #include <stdlib.h>
37 #include <unistd.h>
38 #ifdef HAVE_GETOPT_H
39 #include <getopt.h>
40 #endif /* HAVE_GETOPT_H */
41 #include <locale.h>
42
43 #include <htString.h>
44 #include <WordContext.h>
45 #include <WordList.h>
46
action(WordContext * context,const String & file)47 static void action(WordContext* context, const String& file)
48 {
49 WordList *words = context->List();
50 if(words->Open(file, O_RDWR | O_TRUNC) != OK) exit(1);
51 if(words->Read(stdin) < 0) exit(1);
52 if(words->Close() != OK) exit(1);
53 delete words;
54 }
55
usage()56 static void usage()
57 {
58 fprintf(stderr, "usage: mifluzload [-zv] file\n");
59 exit(1);
60 }
61
main(int argc,char * argv[])62 int main(int argc, char *argv[])
63 {
64 if(argc < 2) usage();
65
66 setlocale(LC_ALL, "");
67
68
69
70 // extern char *optarg;
71 extern int optind;
72 int ch;
73 bool isCompress=false;
74 bool isV=false;
75 while ((ch = getopt(argc, argv, "zvM:")) != EOF) {
76 switch (ch) {
77 case 'z':
78 isCompress=true;
79 break;
80 case 'v':
81 {
82 isV=true;
83
84 }
85 break;
86 case 'M':
87 {
88 char *milo= (char*)malloc(strlen(optarg) + 32);
89 sprintf(milo, "MIFLUZ_CONFIG=%s", optarg);
90 if(putenv(milo) < 0) {
91 perror("putenv");
92 exit(1);
93 }
94 }
95 break;
96 default:
97 usage();
98 break;
99 }
100 }
101
102 //
103 // Mandatory to create global data needed for the library.
104 //
105 WordContext *context = new WordContext();
106 if(!context) exit(1);
107
108 Configuration& config = context->GetConfiguration();
109 context->ReInitialize();
110 if (isCompress)
111 config.Add("wordlist_compress", "true");
112
113 if (isV)
114 {
115 int value = config.Value("wordlist_verbose", 0);
116 value++;
117 char value_string[64];
118 sprintf(value_string, "%d", value);
119 config.Add("wordlist_verbose", value_string);
120 }
121 action(context, argv[optind]);
122 delete context;
123 }
124
125