mifluzdict.cc

Go to the documentation of this file.
00001 //
00002 // NAME
00003 // 
00004 // dump the dictionnary of an inverted index.
00005 //
00006 // SYNOPSIS
00007 //
00008 // mifluzdict file
00009 //
00010 // DESCRIPTION
00011 //
00012 // mifluzdict writes on <b>stdout</b> a complete ascii description
00013 // of the <b>file</b> inverted index using the <i>WordList::Write</i>
00014 // method. 
00015 //
00016 // ENVIRONMENT
00017 //
00018 // <b>MIFLUZ_CONFIG</b>
00019 // file name of configuration file read by WordContext(3). Defaults to
00020 // <b>~/.mifluz.</b> 
00021 // 
00022 // 
00023 // END
00024 //
00025 // Part of the ht://Dig package   <http://www.htdig.org/>
00026 // Copyright (c) 1999, 2000, 2001 The ht://Dig Group
00027 // For copyright details, see the file COPYING in your distribution
00028 // or the GNU General Public License version 2 or later
00029 // <http://www.gnu.org/copyleft/gpl.html>
00030 //
00031 
00032 #ifdef HAVE_CONFIG_H
00033 #include "config.h"
00034 #endif /* HAVE_CONFIG_H */
00035 
00036 #include <stdlib.h>
00037 #include <unistd.h>
00038 #ifdef HAVE_GETOPT_H
00039 #include <getopt.h>
00040 #endif /* HAVE_GETOPT_H */
00041 
00042 #include <htString.h>
00043 #include <WordContext.h>
00044 #include <WordList.h>
00045 #include <WordDict.h>
00046 #include <Configuration.h>
00047 
00048 typedef struct
00049 {
00050     String prefix;
00051 } params_t;
00052 
00053 static void action(WordContext* context, const String& file, params_t* params)
00054 {
00055   WordList *words = context->List();
00056   if(words->Open(file, O_RDONLY) != OK) exit(1);
00057   if(params->prefix.empty()) {
00058     if(words->WriteDict(stdout) != OK) exit(1);
00059   } else {
00060     WordDict *dict = words->Dict();
00061     WordDictCursor *cursor = dict->CursorPrefix(params->prefix);
00062     String word;
00063     WordDictRecord record;
00064     while(dict->NextPrefix(cursor, word, record) == 0) {
00065       printf("%s %d %d\n", (char*)word.get(), record.Id(), record.Count());
00066     }
00067   }
00068   if(words->Close() != OK) exit(1);
00069   delete words;
00070 }
00071 
00072 static void usage()
00073 {
00074   fprintf(stderr, "usage: mifluzdict [-p prefix] file\n");
00075   exit(1);
00076 }
00077 
00078 int main(int argc, char *argv[])
00079 {
00080   params_t params;
00081   extern char *optarg;
00082   extern int optind;
00083   int ch;
00084   while ((ch = getopt(argc, argv, "p:")) != EOF) {
00085     switch (ch) {
00086     case 'p':
00087       params.prefix = optarg;
00088       break;
00089     default:
00090       usage();
00091       break;
00092     }
00093   }
00094 
00095   if(optind != argc - 1) usage();
00096 
00097   //
00098   // Mandatory to create global data needed for the library.
00099   //
00100   WordContext *context = new WordContext();
00101   if(!context) exit(1);
00102   action(context, argv[optind], &params);
00103   delete context;
00104 }
00105 

Generated on Sun Jun 8 10:56:39 2008 for GNUmifluz by  doxygen 1.5.5