Changeset 2184

Show
Ignore:
Timestamp:
10/24/08 15:05:31 (3 months ago)
Author:
karpet
Message:

add raw tagstack to parser_data. this is to allow for metanames or properties with syntax like foo.bar.baz so that you can precisely identify data in dom context. the feature is not done, but this passes all tests so am committing as is for now

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • libswish3/trunk/src/libswish3/libswish3.h

    r2178 r2184  
    100100#define SWISH_PROP_DESCRIPTION     "swishdescription" 
    101101#define SWISH_TOKENPOS_BUMPER      "\3" 
     102#define SWISH_DOT                  '.' 
     103#define SWISH_SPACE                ' ' 
    102104 
    103105/* built-in id values */ 
     
    357359    swish_TagStack        *metastack;          // stacks for tracking the tag => metaname 
    358360    swish_TagStack        *propstack;          // stacks for tracking the tag => property 
     361    swish_TagStack        *tagstack;           // stacks for tracking xml/html tag tree 
    359362    xmlParserCtxtPtr       ctxt;               // so we can free at end 
    360363    swish_TokenIterator   *token_iterator;     // token container 
  • libswish3/trunk/src/libswish3/parser.c

    r2177 r2184  
    211211static xmlChar *flatten_tag_stack( 
    212212    xmlChar *baked, 
    213     swish_TagStack *stack 
     213    swish_TagStack *stack, 
     214    char flatten_join 
    214215); 
    215216static void add_stack_to_prop_buf( 
     
    220221    swish_TagStack *stack, 
    221222    xmlChar *raw, 
    222     xmlChar *baked 
     223    xmlChar *baked, 
     224    char flatten_join 
    223225); 
    224226static swish_Tag *pop_tag_stack( 
     
    231233static void free_swishTag( 
    232234    swish_Tag * st 
     235); 
     236static void 
     237free_swishTagStack( 
     238    swish_TagStack *stack 
    233239); 
    234240 
     
    298304 
    299305    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); 
    301307        if (atts != NULL) { 
    302308            SWISH_DEBUG_MSG(" has attributes [%d]", xmlStrlen((xmlChar *)atts)); 
     
    679685    swish_ParserData *parser_data; 
    680686    parser_data = (swish_ParserData *)data; 
     687     
     688    if (SWISH_DEBUG & SWISH_DEBUG_PARSER) 
     689        SWISH_DEBUG_MSG("<%s>", tag); 
    681690 
    682691    if (parser_data->tag != NULL) 
     
    684693 
    685694    parser_data->tag = build_tag(parser_data, (xmlChar *)tag, (xmlChar **)atts); 
    686  
     695         
    687696    if (SWISH_DEBUG & SWISH_DEBUG_PARSER) 
    688697        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    } 
    689707 
    690708/* 
     
    698716        xmlBufferEmpty(parser_data->prop_buf); 
    699717 
    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); 
    701719 
    702720        if (SWISH_DEBUG & SWISH_DEBUG_PARSER) 
     
    714732                     parser_data->metastack->head->context); 
    715733 
    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); 
    717735    } 
    718736 
     
    733751    parser_data = (swish_ParserData *)data; 
    734752 
     753    if (SWISH_DEBUG & SWISH_DEBUG_PARSER) 
     754        SWISH_DEBUG_MSG("</%s>", tag); 
     755         
    735756/* 
    736757* lowercase all names for comparison against metanames (which are 
     
    744765    if (SWISH_DEBUG & SWISH_DEBUG_PARSER) 
    745766        SWISH_DEBUG_MSG(" endElement(%s) (%s)", (xmlChar *)tag, parser_data->tag); 
     767         
     768    if (parser_data->tag == NULL) 
     769        return; 
    746770 
    747771    if ((st = pop_tag_stack_on_match(parser_data->propstack, (xmlChar *)tag)) != NULL) { 
     
    757781        free_swishTag(st); 
    758782    } 
     783     
     784    // always pop the raw tagstack 
     785    st = pop_tag_stack(parser_data->tagstack); 
     786    free_swishTag(st); 
    759787 
    760788} 
     
    10411069    ptr->metastack->count = 0; 
    10421070    push_tag_stack(ptr->metastack, (xmlChar *)SWISH_DEFAULT_METANAME, 
    1043                    (xmlChar *)SWISH_DEFAULT_METANAME); 
     1071                   (xmlChar *)SWISH_DEFAULT_METANAME, SWISH_SPACE); 
    10441072 
    10451073    ptr->propstack = (swish_TagStack *)swish_xmalloc(sizeof(swish_TagStack)); 
     
    10481076    ptr->propstack->temp = NULL; 
    10491077    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); 
    10511086 
    10521087/* 
     
    10891124 
    10901125static void 
     1126free_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 
     1146static void 
    10911147free_parser_data( 
    10921148    swish_ParserData *ptr 
    10931149) 
    10941150{ 
    1095     swish_Tag *st; 
    10961151 
    10971152    if (SWISH_DEBUG & SWISH_DEBUG_PARSER) 
     
    11061161* Pop the stacks  
    11071162*/ 
    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 */ 
    11331168 
    11341169    if (SWISH_DEBUG & SWISH_DEBUG_PARSER) 
     
    19652000 
    19662001    push_tag_stack(parser_data->metastack, (xmlChar *)SWISH_DEFAULT_METANAME, 
    1967                    (xmlChar *)SWISH_DEFAULT_METANAME); 
     2002                   (xmlChar *)SWISH_DEFAULT_METANAME, SWISH_SPACE); 
    19682003 
    19692004    if (SWISH_DEBUG & SWISH_DEBUG_PARSER) 
     
    20902125flatten_tag_stack( 
    20912126    xmlChar *baked, 
    2092     swish_TagStack *stack 
     2127    swish_TagStack *stack, 
     2128    char flatten_join 
    20932129) 
    20942130{ 
     
    21112147    for (; stack->temp != NULL; stack->temp = stack->temp->next) { 
    21122148        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             
    21142155        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) 
    21162158            > 0) { 
    21172159            if (flat != NULL) 
     
    21882230    swish_TagStack *stack, 
    21892231    xmlChar *raw, 
    2190     xmlChar *baked 
     2232    xmlChar *baked, 
     2233    char flatten_join 
    21912234) 
    21922235{ 
     
    22132256 
    22142257/*  create context */ 
    2215     thistag->context = flatten_tag_stack(NULL, stack); 
     2258    thistag->context = flatten_tag_stack(NULL, stack, flatten_join); 
    22162259 
    22172260    if (SWISH_DEBUG & SWISH_DEBUG_PARSER) {