Changeset 2132
- Timestamp:
- 04/16/08 08:14:47 (1 month ago)
- Files:
-
- libswish3/trunk/src/libswish3/libswish3.h (modified) (1 diff)
- libswish3/trunk/src/libswish3/parser.c (modified) (27 diffs)
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
libswish3/trunk/src/libswish3/libswish3.h
r2130 r2132 315 315 struct swish_Tag 316 316 { 317 xmlChar * name;318 xmlChar * metaname;317 xmlChar *raw; // tag as libxml2 sees it 318 xmlChar *baked; // tag as libswish3 sees it 319 319 xmlChar *context; 320 320 struct swish_Tag *next; libswish3/trunk/src/libswish3/parser.c
r2131 r2132 75 75 ); 76 76 77 static xmlChar *flatten_tag_stack(78 xmlChar *tag,79 swish_TagStack *stack80 );81 static void add_stack_to_prop_buf(82 xmlChar *tag,83 swish_ParserData *parser_data84 );85 static void push_tag_stack(86 swish_TagStack *stack,87 xmlChar *tag,88 xmlChar *metaname89 );90 static swish_Tag *pop_tag_stack(91 swish_TagStack *stack92 );93 static swish_Tag *pop_tag_stack_on_match(94 swish_TagStack *stack,95 xmlChar *tag96 );97 static void free_swishTag(98 swish_Tag * st99 );100 101 77 static void mystartDocument( 102 78 void *parser_data … … 232 208 ); 233 209 210 211 /* tag tracker */ 212 static xmlChar *flatten_tag_stack( 213 xmlChar *baked, 214 swish_TagStack *stack 215 ); 216 static void add_stack_to_prop_buf( 217 xmlChar *baked, 218 swish_ParserData *parser_data 219 ); 220 static void push_tag_stack( 221 swish_TagStack *stack, 222 xmlChar *raw, 223 xmlChar *baked 224 ); 225 static swish_Tag *pop_tag_stack( 226 swish_TagStack *stack 227 ); 228 static swish_Tag *pop_tag_stack_on_match( 229 swish_TagStack *stack, 230 xmlChar *raw 231 ); 232 static void free_swishTag( 233 swish_Tag * st 234 ); 235 236 /*********************************************************************** 237 * end prototypes 238 ***********************************************************************/ 239 234 240 swish_Parser * 235 241 swish_init_parser( … … 501 507 if (parser_data->s3->config->flags->context_as_meta) { 502 508 for (s->temp = s->head; s->temp != NULL; s->temp = s->temp->next) { 503 if (xmlStrEqual(s->temp-> name, metaname)) // already added509 if (xmlStrEqual(s->temp->baked, metaname)) // already added 504 510 continue; 505 511 506 swish_add_buf_to_nb(parser_data->metanames, s->temp-> name,512 swish_add_buf_to_nb(parser_data->metanames, s->temp->baked, 507 513 parser_data->meta_buf, (xmlChar *)SWISH_META_CONNECTOR, 0, 508 514 1); … … 691 697 SWISH_DEBUG_MSG(" %s = new metaname", parser_data->tag); 692 698 693 flush_buffer(parser_data, parser_data->metastack->head-> name,699 flush_buffer(parser_data, parser_data->metastack->head->baked, 694 700 parser_data->metastack->head->context); 695 701 … … 727 733 if ((st = pop_tag_stack_on_match(parser_data->propstack, (xmlChar *)tag)) != NULL) { 728 734 729 add_stack_to_prop_buf( parser_data->tag, parser_data);735 add_stack_to_prop_buf(st->baked, parser_data); 730 736 xmlBufferEmpty(parser_data->prop_buf); 731 737 free_swishTag(st); … … 734 740 if ((st = pop_tag_stack_on_match(parser_data->metastack, (xmlChar *)tag)) != NULL) { 735 741 736 flush_buffer(parser_data, st-> metaname, st->context);742 flush_buffer(parser_data, st->baked, st->context); 737 743 free_swishTag(st); 738 744 } … … 1100 1106 if (SWISH_DEBUG & SWISH_DEBUG_PARSER) 1101 1107 SWISH_DEBUG_MSG("%s %d POP %s [%s] [%s]", ptr->metastack->name, 1102 ptr->metastack->count, st-> name, st->metaname, st->context);1108 ptr->metastack->count, st->raw, st->baked, st->context); 1103 1109 1104 1110 free_swishTag(st); … … 1113 1119 if (SWISH_DEBUG & SWISH_DEBUG_PARSER) 1114 1120 SWISH_DEBUG_MSG("%s %d POP %s [%s] [%s]", ptr->propstack->name, 1115 ptr->propstack->count, st-> name, st->metaname, st->context);1121 ptr->propstack->count, st->raw, st->baked, st->context); 1116 1122 1117 1123 free_swishTag(st); … … 2027 2033 2028 2034 if (metaname == NULL) 2029 metaname = parser_data->metastack->head-> name;2035 metaname = parser_data->metastack->head->baked; 2030 2036 2031 2037 if (context == NULL) … … 2115 2121 for (stack->temp = stack->head; stack->temp != NULL; stack->temp = stack->temp->next) { 2116 2122 SWISH_DEBUG_MSG(" %d: count %d tagstack: %s", i++, stack->temp->n, 2117 stack->temp-> name);2123 stack->temp->raw); 2118 2124 2119 2125 } … … 2133 2139 static xmlChar * 2134 2140 flatten_tag_stack( 2135 xmlChar * tag,2141 xmlChar *baked, 2136 2142 swish_TagStack *stack 2137 2143 ) … … 2145 2151 stack->temp = stack->head; 2146 2152 2147 if ( tag!= NULL) {2148 flat = swish_xstrdup( tag);2153 if (baked != NULL) { 2154 flat = swish_xstrdup(baked); 2149 2155 } 2150 2156 else { 2151 flat = swish_xstrdup(stack->head-> name);2157 flat = swish_xstrdup(stack->head->baked); 2152 2158 stack->temp = stack->temp->next; 2153 2159 } 2154 2160 2155 2161 for (; stack->temp != NULL; stack->temp = stack->temp->next) { 2156 size = ((xmlStrlen(flat) + (xmlStrlen(stack->temp-> name)) * sizeof(xmlChar))) + 2;2162 size = ((xmlStrlen(flat) + (xmlStrlen(stack->temp->baked)) * sizeof(xmlChar))) + 2; 2157 2163 tmp = swish_xmalloc(size); 2158 if (snprintf((char *)tmp, size, "%s %s", (char *)flat, (char *)stack->temp-> name) > 0) {2164 if (snprintf((char *)tmp, size, "%s %s", (char *)flat, (char *)stack->temp->baked) > 0) { 2159 2165 if (flat != NULL) 2160 2166 swish_xfree(flat); … … 2163 2169 } 2164 2170 else { 2165 SWISH_CROAK("sprintf failed to concat %s -> %s", stack->temp-> name, flat);2171 SWISH_CROAK("sprintf failed to concat %s -> %s", stack->temp->baked, flat); 2166 2172 } 2167 2173 … … 2173 2179 static void 2174 2180 add_stack_to_prop_buf( 2175 xmlChar * tag,2181 xmlChar *baked, 2176 2182 swish_ParserData *parser_data 2177 2183 ) … … 2185 2191 2186 2192 if (SWISH_DEBUG & SWISH_DEBUG_PARSER) { 2187 SWISH_DEBUG_MSG("adding property %s to buffer", tag);2188 } 2189 2190 if ( tag!= NULL) {2191 prop = swish_hash_fetch(parser_data->s3->config->properties, tag);2193 SWISH_DEBUG_MSG("adding property %s to buffer", baked); 2194 } 2195 2196 if (baked != NULL) { 2197 prop = swish_hash_fetch(parser_data->s3->config->properties, baked); 2192 2198 2193 2199 /* … … 2197 2203 cleanwsp = 0; 2198 2204 2199 swish_add_buf_to_nb(parser_data->properties, tag, parser_data->prop_buf,2205 swish_add_buf_to_nb(parser_data->properties, baked, parser_data->prop_buf, 2200 2206 (xmlChar *)SWISH_PROP_CONNECTOR, cleanwsp, 0); 2201 2207 … … 2205 2211 // TODO configurable?? 2206 2212 for (stack->temp = stack->head; stack->temp != NULL; stack->temp = stack->temp->next) { 2207 if (xmlStrEqual(stack->temp-> name, (xmlChar *)"_"))2213 if (xmlStrEqual(stack->temp->baked, (xmlChar *)"_")) 2208 2214 continue; 2209 2215 2210 swish_add_buf_to_nb(parser_data->properties, stack->temp-> name, parser_data->prop_buf,2216 swish_add_buf_to_nb(parser_data->properties, stack->temp->baked, parser_data->prop_buf, 2211 2217 (xmlChar *)SWISH_PROP_CONNECTOR, cleanwsp, 0); 2212 2218 } … … 2220 2226 { 2221 2227 if (SWISH_DEBUG & SWISH_DEBUG_PARSER) { 2222 SWISH_DEBUG_MSG(" freeing swishTag: %s %s %s", st-> name, st->metaname, st->context);2228 SWISH_DEBUG_MSG(" freeing swishTag: %s %s %s", st->raw, st->baked, st->context); 2223 2229 } 2224 2230 2225 swish_xfree(st-> name);2226 swish_xfree(st-> metaname);2231 swish_xfree(st->raw); 2232 swish_xfree(st->baked); 2227 2233 swish_xfree(st->context); 2228 2234 swish_xfree(st); … … 2232 2238 push_tag_stack( 2233 2239 swish_TagStack *stack, 2234 xmlChar * tag,2235 xmlChar * metaname2240 xmlChar *raw, 2241 xmlChar *baked 2236 2242 ) 2237 2243 { … … 2240 2246 2241 2247 if (SWISH_DEBUG & SWISH_DEBUG_PARSER) { 2242 SWISH_DEBUG_MSG("%s PUSH: tag = '%s'", stack->name, tag);2248 SWISH_DEBUG_MSG("%s PUSH: tag = '%s'", stack->name, raw); 2243 2249 _debug_stack(stack); 2244 2250 } 2245 2251 2246 2252 //assign this tag to the struct 2247 thistag-> name = swish_xstrdup(tag);2248 2249 // the metaname (the normalized tag)2250 thistag-> metaname = swish_xstrdup(metaname);2253 thistag->raw = swish_xstrdup(raw); 2254 2255 // the normalized tag 2256 thistag->baked = swish_xstrdup(baked); 2251 2257 2252 2258 //increment counter … … 2280 2286 2281 2287 if (SWISH_DEBUG & SWISH_DEBUG_PARSER) { 2282 SWISH_DEBUG_MSG("%s POP: %s", stack->name, stack->head-> name);2288 SWISH_DEBUG_MSG("%s POP: %s", stack->name, stack->head->raw); 2283 2289 _debug_stack(stack); 2284 2290 … … 2288 2294 if (SWISH_DEBUG & SWISH_DEBUG_PARSER) { 2289 2295 SWISH_DEBUG_MSG("%s %d: popping '%s'", stack->name, stack->head->n, 2290 stack->head-> name);2296 stack->head->raw); 2291 2297 2292 2298 } … … 2303 2309 if (SWISH_DEBUG & SWISH_DEBUG_PARSER) { 2304 2310 SWISH_DEBUG_MSG("%s %d: popping '%s' will leave stack empty [%s]", 2305 stack->name, stack->head->n, stack->head-> name,2311 stack->name, stack->head->n, stack->head->raw, 2306 2312 stack->head->context); 2307 2313 … … 2337 2343 2338 2344 if (SWISH_DEBUG & SWISH_DEBUG_PARSER) { 2339 SWISH_DEBUG_MSG("%s: POP if %s matches %s", stack->name, tag, stack->head-> name);2345 SWISH_DEBUG_MSG("%s: POP if %s matches %s", stack->name, tag, stack->head->raw); 2340 2346 _debug_stack(stack); 2341 2347 } 2342 2348 2343 if (xmlStrEqual(stack->head-> name, tag)) {2349 if (xmlStrEqual(stack->head->raw, tag)) { 2344 2350 2345 2351 if (SWISH_DEBUG & SWISH_DEBUG_PARSER) { … … 2354 2360 2355 2361 if (SWISH_DEBUG & SWISH_DEBUG_PARSER) { 2356 SWISH_DEBUG_MSG("%s POPPED. tag = %s st-> name= %s", stack->name,2357 tag, st-> name);2362 SWISH_DEBUG_MSG("%s POPPED. tag = %s st->raw = %s", stack->name, 2363 tag, st->raw); 2358 2364 2359 2365 _debug_stack(stack); … … 2367 2373 else if (stack->count) { 2368 2374 if (SWISH_DEBUG & SWISH_DEBUG_PARSER) 2369 SWISH_DEBUG_MSG("%s head %s", stack->name, stack->head-> name);2375 SWISH_DEBUG_MSG("%s head %s", stack->name, stack->head->raw); 2370 2376 2371 2377 } … … 2384 2390 if (SWISH_DEBUG & SWISH_DEBUG_PARSER) { 2385 2391 if (st != NULL) 2386 SWISH_DEBUG_MSG("POP on match returning: %s", st-> name);2392 SWISH_DEBUG_MSG("POP on match returning: %s", st->raw); 2387 2393 else 2388 2394 SWISH_DEBUG_MSG("POP on match returning null");
