00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032 #ifdef HAVE_CONFIG_H
00033 #include "config.h"
00034 #endif
00035
00036 #include <stdlib.h>
00037 #include <unistd.h>
00038 #ifdef HAVE_GETOPT_H
00039 #include <getopt.h>
00040 #endif
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
00099
00100 WordContext *context = new WordContext();
00101 if(!context) exit(1);
00102 action(context, argv[optind], ¶ms);
00103 delete context;
00104 }
00105