Changeset 2104 for libswish3/trunk/src/swish_words.c
- Timestamp:
- 03/28/08 23:00:02 (7 months ago)
- Files:
-
- libswish3/trunk/src/swish_words.c (modified) (5 diffs)
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
libswish3/trunk/src/swish_words.c
r2010 r2104 18 18 */ 19 19 20 21 20 /* test word parser */ 22 21 … … 28 27 #include <wctype.h> 29 28 #include <ctype.h> 30 #include <libxml/hash.h>31 29 #include <getopt.h> 32 30 33 31 #include "libswish3.h" 34 32 35 static struct option longopts[] = 36 { 33 static struct option longopts[] = { 37 34 {"file", required_argument, 0, 'f'}, 38 {"debug", required_argument, 0, 'd'},39 35 {"help", no_argument, 0, 'h'}, 40 36 {0, 0, 0, 0} 41 37 }; 42 38 43 void print_list(swish_WordList * list); 44 int main(int argc, char **argv); 45 int usage(); 39 40 int main( 41 int argc, 42 char **argv 43 ); 44 int usage( 45 ); 46 46 47 47 extern int SWISH_DEBUG; 48 48 49 50 49 int 51 usage() 50 usage( 51 ) 52 52 { 53 53 54 char *descr = "swish_words is an example program for testing the libswish3 tokenizer\n"; 54 char *descr = 55 "swish_words is an example program for testing the libswish3 tokenizer\n"; 55 56 printf("swish_words [opts] [string(s)]\n"); 56 printf("opts:\n --file file.txt\n --debug\n");57 printf("opts:\n --file file.txt\n"); 57 58 printf("\n%s\n\n", descr); 58 59 exit(1); … … 60 61 61 62 int 62 main(int argc, char **argv) 63 main( 64 int argc, 65 char **argv 66 ) 63 67 { 64 int i, ch;65 int option_index;66 extern char *optarg;67 extern int optind;68 xmlChar *string;68 int i, ch; 69 int option_index; 70 extern char *optarg; 71 extern int optind; 72 xmlChar *string; 69 73 swish_WordList *list; 70 xmlChar *meta; 71 swish_3 *s3; 74 xmlChar *meta; 75 swish_3 *s3; 76 77 meta = (xmlChar *)SWISH_DEFAULT_METANAME; 78 option_index = 0; 79 string = NULL; 72 80 73 meta = (xmlChar*)SWISH_DEFAULT_METANAME; 74 option_index = 0; 75 string = NULL; 81 s3 = swish_init_swish3(NULL, NULL); 76 82 77 while ((ch = getopt_long(argc, argv, "d:f:h", longopts, &option_index)) != -1) 78 { 79 /* printf("switch is %c\n", ch); */ 80 /* printf("optarg is %s\n", optarg); */ 81 /* printf("optind = %d\n", optind); */ 83 while ((ch = getopt_long(argc, argv, "f:h", longopts, &option_index)) != -1) { 82 84 83 switch (ch) 84 { 85 case 0: /* If this option set a flag, do nothing else now. */ 85 switch (ch) { 86 case 0: /* If this option set a flag, do nothing else now. */ 86 87 if (longopts[option_index].flag != 0) 87 88 break; … … 94 95 case 'f': 95 96 printf("reading %s\n", optarg); 96 97 string = swish_slurp_file((xmlChar *) optarg); 98 99 break; 100 101 case 'd': 102 printf("turning on debug mode: %s\n", optarg); 103 104 if (!isdigit(optarg[0])) 105 err(1, "-d option requires a positive integer as argument\n"); 106 107 SWISH_DEBUG = (int) strtol(optarg, (char **) NULL, 10); 97 string = swish_slurp_file((xmlChar *)optarg); 108 98 break; 109 99 … … 117 107 } 118 108 119 s3 = swish_init_swish3( NULL, NULL ); /* call after we have set optional debug flag */ 120 i = optind; 121 122 for (; i < argc; i++) 123 { 124 list = swish_tokenize( s3->analyzer, (xmlChar *) argv[i], 0, 0, meta, meta ); 109 i = optind; 110 111 for (; i < argc; i++) { 112 list = swish_tokenize(s3->analyzer, (xmlChar *)argv[i], 0, 0, meta, meta); 125 113 printf("parsed: %s\n", argv[i]); 126 114 swish_debug_wordlist(list); 115 list->ref_cnt--; 127 116 swish_free_wordlist(list); 128 117 } 129 130 if (string != NULL) 131 { 132 list = swish_tokenize( s3->analyzer, string, 0, 0, meta, meta ); 133 printf("parsed: %s\n", string); 134 swish_debug_wordlist(list); 118 119 if (string != NULL) { 120 list = swish_tokenize(s3->analyzer, string, 0, 0, meta, meta); 121 122 if (SWISH_DEBUG & SWISH_DEBUG_WORDLIST) 123 swish_debug_wordlist(list); 124 125 list->ref_cnt--; 135 126 swish_free_wordlist(list); 136 127 swish_xfree(string); 137 128 } 138 139 swish_free_swish3( s3 );129 130 swish_free_swish3(s3); 140 131 141 132 return (0);
