Changeset 2105
- Timestamp:
- 03/28/08 23:04:21 (2 months ago)
- Files:
-
- libswish3/trunk/src/swish_isw.c (modified) (6 diffs)
- libswish3/trunk/src/swish_lint.c (modified) (8 diffs)
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
libswish3/trunk/src/swish_isw.c
r1913 r2105 17 17 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA 18 18 */ 19 19 20 20 /* report on the isw* functions for any decimal character value. 21 21 * … … 35 35 #include <locale.h> 36 36 37 void report(char *locale, int n); 38 void usage(); 39 int main(int argc, char **argv); 37 void report( 38 char *locale, 39 int n 40 ); 41 void usage( 42 ); 43 int main( 44 int argc, 45 char **argv 46 ); 40 47 41 char *types[] = 42 { 48 char *types[] = { 43 49 "alnum", "cntrl", "ideogram", "print", "special", 44 50 "alpha", "digit", "lower", "punct", "upper", … … 46 52 }; 47 53 48 int ntypes = 15;54 int ntypes = 15; 49 55 50 56 int 51 main(int argc, char **argv) 57 main( 58 int argc, 59 char **argv 60 ) 52 61 { 53 int i, n;54 char *curlocale, *locale;62 int i, n; 63 char *curlocale, *locale; 55 64 56 65 if (argc == 1) 57 66 usage(); 58 59 67 60 68 locale = getenv("LC_ALL"); … … 62 70 setlocale(LC_ALL, locale); 63 71 curlocale = strdup(locale); 64 65 66 for (i = 1; i < argc; i++) 67 { 68 72 73 for (i = 1; i < argc; i++) { 74 69 75 if (!iswdigit(argv[i][0])) 70 err(1, "arg %s is not a positive integer\n", argv[i]);71 72 n = (int) strtol(argv[i], (char **)NULL, 10);76 err(1, "arg %s is not a positive integer\n", argv[i]); 77 78 n = (int)strtol(argv[i], (char **)NULL, 10); 73 79 74 80 report(curlocale, n); … … 79 85 } 80 86 81 void usage() 87 void 88 usage( 89 ) 82 90 { 83 91 printf("usage: swish_isw N\n\n"); … … 88 96 } 89 97 90 void 91 report(char *locale, int n) 98 void 99 report( 100 char *locale, 101 int n 102 ) 92 103 { 93 104 int j; 94 105 95 106 setlocale(LC_ALL, locale); 96 107 printf("locale: %s\n", setlocale(LC_ALL, NULL)); 97 108 98 109 printf("%lc %d \\x%04x\n", n, n, n); 99 100 for (j = 0; j < ntypes; j++) 101 { 110 111 for (j = 0; j < ntypes; j++) { 102 112 printf("%10s => %d\n", types[j], iswctype(n, wctype(types[j]))); 103 113 } libswish3/trunk/src/swish_lint.c
r2098 r2105 17 17 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA 18 18 */ 19 19 20 20 /* swish_lint.c -- test libswish3 */ 21 21 … … 31 31 #include "libswish3.h" 32 32 33 int debug = 0; 34 35 int main(int argc, char **argv); 36 int usage(); 37 void handler(swish_ParserData * parser_data); 38 void libxml2_version(); 39 void swish_version(); 40 41 int twords = 0; 33 int debug = 0; 34 35 int main( 36 int argc, 37 char **argv 38 ); 39 int usage( 40 ); 41 void handler( 42 swish_ParserData *parser_data 43 ); 44 void libxml2_version( 45 ); 46 void swish_version( 47 ); 48 49 int twords = 0; 42 50 43 51 extern int SWISH_DEBUG; 44 52 45 static struct option longopts[] = 46 { 53 static struct option longopts[] = { 47 54 {"config", required_argument, 0, 'c'}, 48 {"debug", required_argument, 0, 'd'},49 {"help", no_argument, 0, 'h'},55 {"debug", required_argument, 0, 'd'}, 56 {"help", no_argument, 0, 'h'}, 50 57 {0, 0, 0, 0} 51 58 }; 52 59 53 54 void libxml2_version() 55 { 56 printf("libxml2 version: %s\n", LIBXML_DOTTED_VERSION); 57 } 58 59 void swish_version() 60 void 61 libxml2_version( 62 ) 63 { 64 printf("libxml2 version: %s\n", LIBXML_DOTTED_VERSION); 65 } 66 67 void 68 swish_version( 69 ) 60 70 { 61 71 printf("libswish3 version %s\n", SWISH_LIB_VERSION); … … 63 73 } 64 74 65 int 66 usage() 67 { 68 69 char * descr = "swish_lint is an example program for using libswish3\n"; 75 int 76 usage( 77 ) 78 { 79 80 char *descr = "swish_lint is an example program for using libswish3\n"; 70 81 printf("swish_lint [opts] [- | file(s)]\n"); 71 82 printf("opts:\n --config conf_file.xml\n --debug [lvl]\n --help\n"); … … 76 87 } 77 88 78 void 79 handler(swish_ParserData * parser_data) 80 { 81 82 /* return; */ 89 void 90 handler( 91 swish_ParserData *parser_data 92 ) 93 { 94 95 /* 96 return; 97 */ 83 98 84 99 printf("nwords: %d\n", parser_data->docinfo->nwords); 85 100 86 101 if (SWISH_DEBUG) 87 102 swish_mem_debug(); 88 103 89 104 twords += parser_data->docinfo->nwords; 90 105 91 106 if (SWISH_DEBUG & SWISH_DEBUG_DOCINFO) 92 107 swish_debug_docinfo(parser_data->docinfo); 93 108 94 109 if (SWISH_DEBUG & SWISH_DEBUG_WORDLIST) 95 110 swish_debug_wordlist(parser_data->wordlist); 96 111 97 112 if (SWISH_DEBUG & SWISH_DEBUG_NAMEDBUFFER) { 98 swish_debug_nb(parser_data->properties, (xmlChar*)"Property"); 99 swish_debug_nb(parser_data->metanames, (xmlChar*)"MetaName"); 100 } 101 } 102 103 int 104 main(int argc, char **argv) 105 { 106 int i, ch; 107 extern char *optarg; 108 extern int optind; 109 int option_index; 110 int files; 111 int overwrite; 112 char *etime; 113 double start_time; 114 xmlChar *config_file = NULL; 115 swish_3 *s3; 116 117 option_index = 0; 118 files = 0; 119 overwrite = 0; 120 start_time = swish_time_elapsed(); 121 s3 = swish_init_swish3( &handler, NULL ); 122 123 while ((ch = getopt_long(argc, argv, "c:d:f:h", longopts, &option_index)) != -1) 124 { 125 /* printf("switch is %c\n", ch); */ 126 /* printf("optarg is %s\n", optarg); */ 127 /* printf("optind = %d\n", optind); */ 128 129 switch (ch) 130 { 131 case 0: /* If this option set a flag, do nothing else now. */ 113 swish_debug_nb(parser_data->properties, (xmlChar *)"Property"); 114 swish_debug_nb(parser_data->metanames, (xmlChar *)"MetaName"); 115 } 116 } 117 118 int 119 main( 120 int argc, 121 char **argv 122 ) 123 { 124 int i, ch; 125 extern char *optarg; 126 extern int optind; 127 int option_index; 128 int files; 129 int overwrite; 130 char *etime; 131 double start_time; 132 xmlChar *config_file = NULL; 133 swish_3 *s3; 134 135 option_index = 0; 136 files = 0; 137 overwrite = 0; 138 start_time = swish_time_elapsed(); 139 s3 = swish_init_swish3(&handler, NULL); 140 141 while ((ch = getopt_long(argc, argv, "c:d:f:h", longopts, &option_index)) != -1) { 142 143 switch (ch) { 144 case 0: /* If this option set a flag, do nothing else now. */ 132 145 if (longopts[option_index].flag != 0) 133 146 break; … … 138 151 break; 139 152 140 case 'c': /* should we set up default config first ? then override141 * here ? */153 case 'c': /* should we set up default config first ? then override 154 * here ? */ 142 155 143 156 //printf("optarg = %s\n", optarg); 144 config_file = swish_xstrdup( (xmlChar*)optarg ); 145 break; 146 157 config_file = swish_xstrdup((xmlChar *)optarg); 158 break; 147 159 148 160 case 'd': … … 152 164 err(1, "-d option requires a positive integer as argument\n"); 153 165 154 SWISH_DEBUG = (int) strtol(optarg, (char **) NULL, 10); 155 break; 156 166 SWISH_DEBUG = (int)strtol(optarg, (char **)NULL, 10); 167 break; 157 168 158 169 case 'o': … … 168 179 169 180 } 170 171 if (config_file != NULL) 172 { 181 182 if (config_file != NULL) { 173 183 s3->config = swish_add_config(config_file, s3->config); 174 184 } 175 185 176 186 i = optind; 177 178 /* die with no args */ 179 if (!i || i >= argc) 180 { 181 swish_free_swish3( s3 ); 187 188 /* 189 die with no args 190 */ 191 if (!i || i >= argc) { 192 swish_free_swish3(s3); 182 193 usage(); 183 194 184 195 } 185 186 if (SWISH_DEBUG == 20) 187 { 188 swish_debug_config(s3->config); 189 } 190 191 for (; i < argc; i++) 192 { 193 194 if (argv[i][0] != '-') 195 { 196 197 if (SWISH_DEBUG == 20) { 198 swish_debug_config(s3->config); 199 } 200 201 for (; i < argc; i++) { 202 203 if (argv[i][0] != '-') { 196 204 197 205 printf("~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~\n"); 198 206 printf("parse_file for %s\n", argv[i]); 199 if (! swish_parse_file(s3, (unsigned char *)argv[i]))207 if (!swish_parse_file(s3, (unsigned char *)argv[i])) 200 208 files++; 201 209 202 210 } 203 else if (argv[i][0] == '-' && !argv[i][1]) 204 { 211 else if (argv[i][0] == '-' && !argv[i][1]) { 205 212 206 213 printf("reading from stdin\n"); … … 217 224 printf("%s total time\n\n", etime); 218 225 swish_xfree(etime); 219 220 swish_free_swish3( s3);226 227 swish_free_swish3(s3); 221 228 222 229 if (config_file != NULL) 223 230 swish_xfree(config_file); 224 225 231 226 232 return (0); 227 233 }
