Changeset 2184
- Timestamp:
- 10/24/08 15:05:31 (3 months ago)
- Files:
-
- libswish3/trunk/src/libswish3/libswish3.h (modified) (2 diffs)
- libswish3/trunk/src/libswish3/parser.c (modified) (20 diffs)
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
libswish3/trunk/src/libswish3/libswish3.h
r2178 r2184 100 100 #define SWISH_PROP_DESCRIPTION "swishdescription" 101 101 #define SWISH_TOKENPOS_BUMPER "\3" 102 #define SWISH_DOT '.' 103 #define SWISH_SPACE ' ' 102 104 103 105 /* built-in id values */ … … 357 359 swish_TagStack *metastack; // stacks for tracking the tag => metaname 358 360 swish_TagStack *propstack; // stacks for tracking the tag => property 361 swish_TagStack *tagstack; // stacks for tracking xml/html tag tree 359 362 xmlParserCtxtPtr ctxt; // so we can free at end 360 363 swish_TokenIterator *token_iterator; // token container libswish3/trunk/src/libswish3/parser.c
r2177 r2184 211 211 static xmlChar *flatten_tag_stack( 212 212 xmlChar *baked, 213 swish_TagStack *stack 213 swish_TagStack *stack, 214 char flatten_join 214 215 ); 215 216 static void add_stack_to_prop_buf( … … 220 221 swish_TagStack *stack, 221 222 xmlChar *raw, 222 xmlChar *baked 223 xmlChar *baked, 224 char flatten_join 223 225 ); 224 226 static swish_Tag *pop_tag_stack( … … 231 233 static void free_swishTag( 232 234 swish_Tag * st 235 ); 236 static void 237 free_swishTagStack( 238 swish_TagStack *stack 233 239 ); 234 240 … … 298 304 299 305 if (SWISH_DEBUG & SWISH_DEBUG_PARSER) { 300 SWISH_DEBUG_MSG(" tag: %s (%s)", tag, parser_data->tag);306 SWISH_DEBUG_MSG(" tag: %s parser->tag: %s ", tag, parser_data->tag); 301 307 if (atts != NULL) { 302 308 SWISH_DEBUG_MSG(" has attributes [%d]", xmlStrlen((xmlChar *)atts)); … … 679 685 swish_ParserData *parser_data; 680 686 parser_data = (swish_ParserData *)data; 687 688 if (SWISH_DEBUG & SWISH_DEBUG_PARSER) 689 SWISH_DEBUG_MSG("<%s>", tag); 681 690 682 691 if (parser_data->tag != NULL) … … 684 693 685 694 parser_data->tag = build_tag(parser_data, (xmlChar *)tag, (xmlChar **)atts); 686 695 687 696 if (SWISH_DEBUG & SWISH_DEBUG_PARSER) 688 697 SWISH_DEBUG_MSG("checking config for '%s' in watched tags", parser_data->tag); 698 699 /* all tags on tagstack */ 700 701 if (parser_data->tag == NULL) { 702 push_tag_stack(parser_data->tagstack, (xmlChar *)tag, (xmlChar *)tag, SWISH_DOT); 703 } 704 else { 705 push_tag_stack(parser_data->tagstack, (xmlChar *)tag, parser_data->tag, SWISH_DOT); 706 } 689 707 690 708 /* … … 698 716 xmlBufferEmpty(parser_data->prop_buf); 699 717 700 push_tag_stack(parser_data->propstack, (xmlChar *)tag, parser_data->tag );718 push_tag_stack(parser_data->propstack, (xmlChar *)tag, parser_data->tag, SWISH_SPACE); 701 719 702 720 if (SWISH_DEBUG & SWISH_DEBUG_PARSER) … … 714 732 parser_data->metastack->head->context); 715 733 716 push_tag_stack(parser_data->metastack, (xmlChar *)tag, parser_data->tag );734 push_tag_stack(parser_data->metastack, (xmlChar *)tag, parser_data->tag, SWISH_SPACE); 717 735 } 718 736 … … 733 751 parser_data = (swish_ParserData *)data; 734 752 753 if (SWISH_DEBUG & SWISH_DEBUG_PARSER) 754 SWISH_DEBUG_MSG("</%s>", tag); 755 735 756 /* 736 757 * lowercase all names for comparison against metanames (which are … … 744 765 if (SWISH_DEBUG & SWISH_DEBUG_PARSER) 745 766 SWISH_DEBUG_MSG(" endElement(%s) (%s)", (xmlChar *)tag, parser_data->tag); 767 768 if (parser_data->tag == NULL) 769 return; 746 770 747 771 if ((st = pop_tag_stack_on_match(parser_data->propstack, (xmlChar *)tag)) != NULL) { … … 757 781 free_swishTag(st); 758 782 } 783 784 // always pop the raw tagstack 785 st = pop_tag_stack(parser_data->tagstack); 786 free_swishTag(st); 759 787 760 788 } … … 1041 1069 ptr->metastack->count = 0; 1042 1070 push_tag_stack(ptr->metastack, (xmlChar *)SWISH_DEFAULT_METANAME, 1043 (xmlChar *)SWISH_DEFAULT_METANAME );1071 (xmlChar *)SWISH_DEFAULT_METANAME, SWISH_SPACE); 1044 1072 1045 1073 ptr->propstack = (swish_TagStack *)swish_xmalloc(sizeof(swish_TagStack)); … … 1048 1076 ptr->propstack->temp = NULL; 1049 1077 ptr->propstack->count = 0; 1050 push_tag_stack(ptr->propstack, (xmlChar *)"_", (xmlChar *)"_"); 1078 push_tag_stack(ptr->propstack, (xmlChar *)"_", (xmlChar *)"_", SWISH_SPACE); 1079 1080 ptr->tagstack = (swish_TagStack *)swish_xmalloc(sizeof(swish_TagStack)); 1081 ptr->tagstack->name = "TagStack"; 1082 ptr->tagstack->head = NULL; 1083 ptr->tagstack->temp = NULL; 1084 ptr->tagstack->count = 0; 1085 push_tag_stack(ptr->tagstack, (xmlChar *)".", (xmlChar *)".", SWISH_DOT); 1051 1086 1052 1087 /* … … 1089 1124 1090 1125 static void 1126 free_swishTagStack( 1127 swish_TagStack *stack 1128 ) 1129 { 1130 swish_Tag *st; 1131 1132 while ((st = pop_tag_stack(stack)) != NULL) { 1133 if (SWISH_DEBUG & SWISH_DEBUG_PARSER) 1134 SWISH_DEBUG_MSG("%s %d POP %s [%s] [%s]", stack->name, 1135 stack->count, st->raw, st->baked, st->context); 1136 1137 free_swishTag(st); 1138 } 1139 1140 if (SWISH_DEBUG & SWISH_DEBUG_PARSER) 1141 SWISH_DEBUG_MSG("freeing stack %s", stack->name); 1142 1143 swish_xfree(stack); 1144 } 1145 1146 static void 1091 1147 free_parser_data( 1092 1148 swish_ParserData *ptr 1093 1149 ) 1094 1150 { 1095 swish_Tag *st;1096 1151 1097 1152 if (SWISH_DEBUG & SWISH_DEBUG_PARSER) … … 1106 1161 * Pop the stacks 1107 1162 */ 1108 while ((st = pop_tag_stack(ptr->metastack)) != NULL) { 1109 if (SWISH_DEBUG & SWISH_DEBUG_PARSER) 1110 SWISH_DEBUG_MSG("%s %d POP %s [%s] [%s]", ptr->metastack->name, 1111 ptr->metastack->count, st->raw, st->baked, st->context); 1112 1113 free_swishTag(st); 1114 } 1115 1116 if (SWISH_DEBUG & SWISH_DEBUG_PARSER) 1117 SWISH_DEBUG_MSG("freeing swish_ParserData metastack"); 1118 1119 swish_xfree(ptr->metastack); 1120 1121 while ((st = pop_tag_stack(ptr->propstack)) != NULL) { 1122 if (SWISH_DEBUG & SWISH_DEBUG_PARSER) 1123 SWISH_DEBUG_MSG("%s %d POP %s [%s] [%s]", ptr->propstack->name, 1124 ptr->propstack->count, st->raw, st->baked, st->context); 1125 1126 free_swishTag(st); 1127 } 1128 1129 if (SWISH_DEBUG & SWISH_DEBUG_PARSER) 1130 SWISH_DEBUG_MSG("freeing swish_ParserData propstack"); 1131 1132 swish_xfree(ptr->propstack); 1163 free_swishTagStack(ptr->metastack); 1164 free_swishTagStack(ptr->propstack); 1165 free_swishTagStack(ptr->tagstack); 1166 1167 /* free named buffers */ 1133 1168 1134 1169 if (SWISH_DEBUG & SWISH_DEBUG_PARSER) … … 1965 2000 1966 2001 push_tag_stack(parser_data->metastack, (xmlChar *)SWISH_DEFAULT_METANAME, 1967 (xmlChar *)SWISH_DEFAULT_METANAME );2002 (xmlChar *)SWISH_DEFAULT_METANAME, SWISH_SPACE); 1968 2003 1969 2004 if (SWISH_DEBUG & SWISH_DEBUG_PARSER) … … 2090 2125 flatten_tag_stack( 2091 2126 xmlChar *baked, 2092 swish_TagStack *stack 2127 swish_TagStack *stack, 2128 char flatten_join 2093 2129 ) 2094 2130 { … … 2111 2147 for (; stack->temp != NULL; stack->temp = stack->temp->next) { 2112 2148 size = 2113 ((xmlStrlen(flat) + (xmlStrlen(stack->temp->baked)) * sizeof(xmlChar))) + 2; 2149 ( 2150 (xmlStrlen(flat)*sizeof(xmlChar)) + 2151 (xmlStrlen(stack->temp->baked)*sizeof(xmlChar)) + 2152 3 // flatten_join + nulls 2153 ); 2154 2114 2155 tmp = swish_xmalloc(size); 2115 if (snprintf((char *)tmp, size, "%s %s", (char *)flat, (char *)stack->temp->baked) 2156 2157 if (snprintf((char *)tmp, size, "%s%c%s", (char *)flat, flatten_join, (char *)stack->temp->baked) 2116 2158 > 0) { 2117 2159 if (flat != NULL) … … 2188 2230 swish_TagStack *stack, 2189 2231 xmlChar *raw, 2190 xmlChar *baked 2232 xmlChar *baked, 2233 char flatten_join 2191 2234 ) 2192 2235 { … … 2213 2256 2214 2257 /* create context */ 2215 thistag->context = flatten_tag_stack(NULL, stack );2258 thistag->context = flatten_tag_stack(NULL, stack, flatten_join); 2216 2259 2217 2260 if (SWISH_DEBUG & SWISH_DEBUG_PARSER) {
