Changeset 2104
- Timestamp:
- 03/28/08 23:00:02 (2 months ago)
- Files:
-
- libswish3/trunk/src/libswish3/analyzer.c (modified) (2 diffs)
- libswish3/trunk/src/libswish3/config.c (modified) (2 diffs)
- libswish3/trunk/src/libswish3/mem.c (modified) (5 diffs)
- libswish3/trunk/src/libswish3/parser.c (modified) (2 diffs)
- libswish3/trunk/src/libswish3/swish.c (modified) (4 diffs)
- libswish3/trunk/src/swish_words.c (modified) (5 diffs)
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
libswish3/trunk/src/libswish3/analyzer.c
r2103 r2104 55 55 56 56 a->stash = NULL; 57 58 if (SWISH_DEBUG & SWISH_DEBUG_MEMORY) { 59 SWISH_DEBUG_MSG("analyzer ptr 0x%x", (int)a); 60 } 57 61 58 62 return a; … … 75 79 if (SWISH_DEBUG & SWISH_DEBUG_MEMORY) { 76 80 SWISH_DEBUG_MSG("free analyzer"); 81 swish_mem_debug(); 77 82 } 78 83 swish_xfree(a); libswish3/trunk/src/libswish3/config.c
r2103 r2104 158 158 SWISH_DEBUG_MSG("freeing config"); 159 159 SWISH_DEBUG_MSG("ptr addr: 0x%x %d", (int)config, (int)config); 160 swish_mem_debug(); 160 161 } 161 162 … … 207 208 /* misc default flags */ 208 209 config->flags->tokenize = 1; 210 211 if (SWISH_DEBUG & SWISH_DEBUG_MEMORY) { 212 SWISH_DEBUG_MSG("config ptr 0x%x", (int)config); 213 } 209 214 210 215 return config; libswish3/trunk/src/libswish3/mem.c
r2103 r2104 71 71 72 72 memcount++; 73 if (SWISH_DEBUG > 20)73 if (SWISH_DEBUG & SWISH_DEBUG_MEMORY) { 74 74 SWISH_DEBUG_MSG("memcount = %ld", memcount); 75 SWISH_DEBUG_MSG("xmalloc address: 0x%x", (int)ptr); 76 } 75 77 76 78 return ptr; … … 83 85 { 84 86 memcount++; 85 if (SWISH_DEBUG > 20)87 if (SWISH_DEBUG & SWISH_DEBUG_MEMORY) 86 88 SWISH_DEBUG_MSG("memcount = %ld", memcount); 87 89 return (xmlStrdup(ptr)); … … 95 97 { 96 98 memcount++; 97 if (SWISH_DEBUG > 20)99 if (SWISH_DEBUG & SWISH_DEBUG_MEMORY) 98 100 SWISH_DEBUG_MSG("memcount = %ld", memcount); 99 101 return (xmlStrndup(ptr, len)); … … 110 112 return; 111 113 } 114 115 if (SWISH_DEBUG & SWISH_DEBUG_MEMORY) 116 SWISH_DEBUG_MSG("freeing %s 0x%x", ptr, (int)ptr); 112 117 113 118 xmlFree(ptr); … … 115 120 memcount--; 116 121 117 if (SWISH_DEBUG > 20)122 if (SWISH_DEBUG & SWISH_DEBUG_MEMORY) 118 123 SWISH_DEBUG_MSG("memcount = %ld", memcount); 119 124 } libswish3/trunk/src/libswish3/parser.c
r2103 r2104 256 256 */ 257 257 get_env_vars(); 258 259 if (SWISH_DEBUG & SWISH_DEBUG_MEMORY) { 260 SWISH_DEBUG_MSG("parser ptr 0x%x", (int)p); 261 } 258 262 259 263 return p; … … 265 269 ) 266 270 { 271 if (SWISH_DEBUG & SWISH_DEBUG_MEMORY) { 272 SWISH_DEBUG_MSG("freeing parser"); 273 swish_mem_debug(); 274 } 267 275 if (p->ref_cnt != 0) { 268 276 SWISH_WARN("parser ref_cnt != 0: %d\n", p->ref_cnt); libswish3/trunk/src/libswish3/swish.c
r2103 r2104 41 41 s3->parser->ref_cnt++; 42 42 s3->stash = stash; 43 44 if (SWISH_DEBUG & SWISH_DEBUG_MEMORY) { 45 SWISH_DEBUG_MSG("s3 ptr 0x%x", (int)s3); 46 } 47 43 48 return s3; 44 49 } … … 51 56 s3->parser->ref_cnt--; 52 57 if (s3->parser->ref_cnt < 1) { 53 /* SWISH_DEBUG_MSG("freeing parser"); */54 58 swish_free_parser(s3->parser); 55 59 } … … 57 61 s3->analyzer->ref_cnt--; 58 62 if (s3->analyzer->ref_cnt < 1) { 59 /* SWISH_DEBUG_MSG("freeing analyzer"); */60 63 swish_free_analyzer(s3->analyzer); 61 64 } … … 63 66 s3->config->ref_cnt--; 64 67 if (s3->config->ref_cnt < 1) { 65 /* SWISH_DEBUG_MSG("freeing config"); */66 68 swish_free_config(s3->config); 67 69 } 68 70 69 /* SWISH_DEBUG_MSG("freeing s3"); */70 71 if (s3->ref_cnt != 0) { 71 72 SWISH_WARN("s3 ref_cnt != 0: %d\n", s3->ref_cnt); 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);
