mifluzload.cc

Go to the documentation of this file.
00001 //
00002 // NAME
00003 // 
00004 // load the content of an inverted index.
00005 //
00006 // SYNOPSIS
00007 //
00008 // mifluzload file
00009 //
00010 // DESCRIPTION
00011 //
00012 // mifluzload reads from <b>stdout</b> a complete ascii description
00013 // of the <b>file</b> inverted index using the <i>WordList::Read</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 #include <locale.h>
00042 
00043 #include <htString.h>
00044 #include <WordContext.h>
00045 #include <WordList.h>
00046 
00047 static void action(WordContext* context, const String& file)
00048 {
00049   WordList *words = context->List();
00050   if(words->Open(file, O_RDWR | O_TRUNC) != OK) exit(1);
00051   if(words->Read(stdin) < 0) exit(1);
00052   if(words->Close() != OK) exit(1);
00053   delete words;
00054 }
00055 
00056 static void usage()
00057 {
00058   fprintf(stderr, "usage: mifluzload [-zv] file\n");
00059   exit(1);
00060 }
00061 
00062 int main(int argc, char *argv[])
00063 {
00064   if(argc < 2) usage();
00065 
00066   setlocale(LC_ALL, "");
00067 
00068   
00069 
00070   //  extern char *optarg;
00071   extern int optind;
00072   int ch;
00073 bool isCompress=false;
00074 bool isV=false;
00075   while ((ch = getopt(argc, argv, "zvM:")) != EOF) {
00076     switch (ch) {
00077     case 'z':
00078       isCompress=true;
00079       break;
00080     case 'v':
00081       {
00082         isV=true;
00083         
00084       }
00085       break;
00086     case 'M':
00087       {
00088         char *milo= (char*)malloc(strlen(optarg) + 32);
00089         sprintf(milo, "MIFLUZ_CONFIG=%s", optarg);
00090         if(putenv(milo) < 0) {
00091           perror("putenv");
00092           exit(1);
00093         }
00094       }
00095       break;
00096     default:
00097       usage();
00098       break;
00099     }
00100   }
00101 
00102 //
00103   // Mandatory to create global data needed for the library.
00104   //
00105   WordContext *context = new WordContext();
00106   if(!context) exit(1);
00107 
00108   Configuration& config = context->GetConfiguration();
00109   context->ReInitialize();
00110   if (isCompress)
00111    config.Add("wordlist_compress", "true");
00112 
00113   if (isV)
00114   {
00115         int value = config.Value("wordlist_verbose", 0);
00116         value++;
00117         char value_string[64];
00118         sprintf(value_string, "%d", value);
00119         config.Add("wordlist_verbose", value_string);
00120   }
00121   action(context, argv[optind]);
00122   delete context;
00123 }
00124 

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