Changeset 92 for trunk/markup_stats.cxx


Ignore:
Timestamp:
Apr 8, 2008, 9:53:53 AM (11 years ago)
Author:
cameron
Message:

Passing buffer pointers/lgths to markup actions.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/markup_stats.cxx

    r91 r92  
    8686int last_buffer_rel_pos = 0;
    8787
    88 void LastItemAction(int start_pos, int end_pos, int buffer_rel_pos) {
    89 #ifdef DEBUG
    90         if (start_pos < last_item_stop) {
    91                 printf("Anomaly start_pos %i < last_item_stop_pos %i \n", start_pos, last_item_stop);
    92                 printf("rel_positions: last = %i, this = %i\n", last_buffer_rel_pos, buffer_rel_pos);
    93         }
    94 #endif
    95         last_item_start = start_pos;
    96         last_item_stop = end_pos;
    97         last_buffer_rel_pos = buffer_rel_pos;
    98 }
    9988
    10089/* Action routine for an XML comment in "<!--"  "-->" brackets. */
    10190template <CodeUnit_Base C>
    102 inline void ParsingEngine<C>::Comment_action(int start_pos, int end_pos) {
     91inline void ParsingEngine<C>::Comment_action(unsigned char * item, int lgth) {
    10392        comment_count +=1;
    104         comment_length += end_pos - start_pos;
    105         LastItemAction(start_pos, end_pos, buffer_rel_pos);
     93        comment_length += lgth;
    10694}
    10795
    10896/* Action routine called upon recognizing "<![CDATA[" to start a CDATA section. */
    10997template <CodeUnit_Base C>
    110 inline void ParsingEngine<C>::CDATA_start_action(int pos) {
    111         CDATA_start_pos = pos - 9;
     98inline void ParsingEngine<C>::CDATA_start_action(unsigned char * CDATA_ptr){
     99        CDATA_start_pos = AbsPos() - 9;
    112100        CDATA_start_count +=1;
    113         LastItemAction(pos-9, pos, buffer_rel_pos);
    114101}
    115102
    116103/* Action routine called upon recognizing "]]>" to end a CDATA section. */
    117104template <CodeUnit_Base C>
    118 inline void ParsingEngine<C>::CDATA_end_action(int pos) {
     105inline void ParsingEngine<C>::CDATA_end_action(unsigned char * CDATA_end_ptr) {
    119106        CDATA_end_count +=1;
    120         CDATA_length += pos - CDATA_start_pos;
    121         LastItemAction(pos-3, pos, buffer_rel_pos);
     107        CDATA_length += AbsPos() - CDATA_start_pos;
    122108}
    123109
    124110/* Action routine for an XML processing instruction enclosed in "<?" and "?>" brackets. */
    125111template <CodeUnit_Base C>
    126 inline void ParsingEngine<C>::PI_action(int start_pos, int end_pos) {
     112inline void ParsingEngine<C>::PI_action(unsigned char * item, int lgth) {
    127113        PI_count +=1;
    128         PI_length += end_pos - start_pos;
    129         LastItemAction(start_pos, end_pos, buffer_rel_pos);
     114        PI_length += lgth;
    130115}
    131116
    132117/* Action routine for an empty element enclosed in "<" and "/>" brackets. */
    133118template <CodeUnit_Base C>
    134 inline void ParsingEngine<C>::EmptyElement_action(int start_pos, int end_pos) {
     119inline void ParsingEngine<C>::EmptyElement_action(unsigned char * item, int lgth) {
    135120        empty_elem_count +=1;
    136         empty_elem_length += end_pos - start_pos;
    137         LastItemAction(start_pos, end_pos, buffer_rel_pos);
     121        empty_elem_length += lgth;
    138122}
    139123
    140124/* Action routine for a start tag enclosed in "<" and ">" brackets. */
    141125template <CodeUnit_Base C>
    142 inline void ParsingEngine<C>::StartTag_action(int start_pos, int end_pos) {
     126inline void ParsingEngine<C>::StartTag_action(unsigned char * item, int lgth) {
    143127        start_tag_count +=1;
    144         start_tag_length += end_pos - start_pos;
     128        start_tag_length += lgth;
    145129        nesting_depth += 1;
    146130        if (nesting_depth > max_nesting_depth) max_nesting_depth = nesting_depth;
    147         LastItemAction(start_pos, end_pos, buffer_rel_pos);
    148131}
    149132
    150133/* Action routine for an end tag enclosed in "</" and ">" brackets. */
    151134template <CodeUnit_Base C>
    152 inline void ParsingEngine<C>::EndTag_action(int start_pos, int end_pos) {
     135inline void ParsingEngine<C>::EndTag_action(unsigned char * item, int lgth) {
    153136        end_tag_count +=1;
    154         end_tag_length += end_pos - start_pos;
     137        end_tag_length += lgth;
    155138        nesting_depth -= 1;
    156         LastItemAction(start_pos, end_pos, buffer_rel_pos);
    157139}
    158140
    159141/* Action routine for an error item */
    160142template <CodeUnit_Base C>
    161 inline void ParsingEngine<C>::Error_action(int start_pos, int end_pos) {
     143inline void ParsingEngine<C>::Error_action(unsigned char * item, int lgth) {
    162144        error_item_count +=1;
    163         error_item_length += end_pos - start_pos;
    164         printf("Error: illegal markup at positions %i through %i.\n", start_pos, end_pos);
    165         printf("length = %i; buffer_rel_pos = %i\n", end_pos - start_pos, buffer_rel_pos);
    166         printf("last_item from %i to %i (rel_pos = %i)\n",
    167                last_item_start, last_item_stop, last_buffer_rel_pos);
    168 
    169         cout << string((char *) GetCodeUnitPtr(start_pos), end_pos+1 - start_pos) << endl;
    170 
    171 
    172 
     145        error_item_length += lgth;
     146        printf("Error: illegal markup at positions %i of length %i.\n", AbsPos()-lgth, lgth);
     147        cout << string((char *) item, lgth) << endl;
    173148}
    174149
    175150/* Action routine for a text item */
    176151template <CodeUnit_Base C>
    177 inline void ParsingEngine<C>::Text_action(int start_pos, int end_pos) {
     152inline void ParsingEngine<C>::Text_action(unsigned char * item, int lgth) {
    178153        text_item_count +=1;
    179         text_item_length += end_pos - start_pos;
    180         LastItemAction(start_pos, end_pos, buffer_rel_pos);
    181 }
    182 
    183 template <CodeUnit_Base C>
    184 inline void ParsingEngine<C>::Reference_action(int start_pos, int end_pos) {
     154        text_item_length += lgth;
     155}
     156
     157template <CodeUnit_Base C>
     158inline void ParsingEngine<C>::Reference_action(unsigned char * item, int lgth) {
    185159        reference_count +=1;
    186         reference_length += end_pos - start_pos;
    187         LastItemAction(start_pos, end_pos, buffer_rel_pos);
     160        reference_length += lgth;
    188161}
    189162
     
    212185   opening "<" of a start tag or empty element tag. */
    213186template <CodeUnit_Base C>
    214 inline void ParsingEngine<C>::ElementName_action(int start_pos, int end_pos) {
     187inline void ParsingEngine<C>::ElementName_action(unsigned char * item, int lgth) {
    215188}
    216189
     
    218191   after the opening "<?" of a processing instruction. */
    219192template <CodeUnit_Base C>
    220 inline void ParsingEngine<C>::PI_Target_action(int start_pos, int end_pos) {
     193inline void ParsingEngine<C>::PI_Target_action(unsigned char * item, int lgth) {
    221194}
    222195
     
    224197   a element start tag or an empty element tag. */
    225198template <CodeUnit_Base C>
    226 inline void ParsingEngine<C>::AttributeValue_action(int name_start, int name_end,
    227                                   int val_start, int val_end) {
     199inline void ParsingEngine<C>::AttributeValue_action(unsigned char * name, int name_lgth,
     200                                 unsigned char * val, int val_lgth) {
    228201        total_attribute_count+=1;
    229         total_att_name_length += name_end - name_start;
    230         total_att_value_length += val_end - val_start;
     202        total_att_name_length += name_lgth;
     203        total_att_value_length += val_lgth;
    231204}
    232205
     
    234207   a element start tag or an empty element tag. */
    235208template <CodeUnit_Base C>
    236 inline void ParsingEngine<C>::Namespace_action(int name_start, int name_end,
    237                              int URI_start, int URI_end) {
     209inline void ParsingEngine<C>::Namespace_action(unsigned char * name, int name_lgth,
     210                             unsigned char * URI, int URI_lgth) {
    238211        namespace_count+=1;
    239         total_namespace_name_length += name_end - name_start;
    240         total_namespace_URI_length += URI_end - URI_start;
     212        total_namespace_name_length += name_lgth;
     213        total_namespace_URI_length += URI_lgth;
    241214}
    242215
     
    270243#endif
    271244}
     245
     246template <CodeUnit_Base C>
     247inline void ParsingEngine<C>::Doctype_action(unsigned char * item, int lgth) {
     248#ifdef SHOW_DTD_ACTIONS
     249        printf("Document Type:\n");
     250        cout << string((char *) item, lgth) <<endl;
     251#endif
     252}
     253
     254template <CodeUnit_Base C>
     255inline void ParsingEngine<C>::PEReference_action(unsigned char * item, int lgth) {
     256}
     257
     258template <CodeUnit_Base C>
     259inline void ParsingEngine<C>::Elementdecl_action(unsigned char * item, int lgth) {
     260#ifdef SHOW_DTD_ACTIONS
     261        printf("Elementdecl:\n");
     262        cout << string((char *) item, lgth) <<endl;
     263#endif
     264}
     265
     266template <CodeUnit_Base C>
     267inline void ParsingEngine<C>::AttlistDecl_action(unsigned char * item, int lgth) {
     268#ifdef SHOW_DTD_ACTIONS
     269        printf("AttlistDecl:\n");
     270        cout << string((char *) item, lgth) <<endl;
     271#endif
     272}
     273
     274template <CodeUnit_Base C>
     275inline void ParsingEngine<C>::Entitydecl_action(unsigned char * entity_name, int entity_name_lgth, unsigned char * item, int lgth) {
     276#ifdef SHOW_DTD_ACTIONS
     277        printf("Entitydecl:\n");
     278        cout << string((char *) item, lgth) <<endl;
     279#endif
     280}
     281
     282template <CodeUnit_Base C>
     283inline void ParsingEngine<C>::Notationdecl_action(unsigned char * item, int lgth) {
     284#ifdef SHOW_DTD_ACTIONS
     285        printf("Notationdecl:\n");
     286        cout << string((char *) item, lgth) <<endl;
     287#endif
     288}
     289
     290template <CodeUnit_Base C>
     291inline void ParsingEngine<C>::Prolog_action(unsigned char * item, int lgth) {
     292#ifdef SHOW_DTD_ACTIONS
     293        printf("Prolog:\n");
     294        cout << string((char *) item, lgth) <<endl;
     295#endif
     296}
     297
    272298
    273299#define print_stats(stat_string, count, total_lgth) \
     
    276302        else if (count == 1) printf(" of length %i.\n", total_lgth);\
    277303        else printf("s of avg. lgth %i.\n", total_lgth/count);
    278 
    279 
    280 template <CodeUnit_Base C>
    281 inline void ParsingEngine<C>::Doctype_action(int start_pos, int end_pos) {
    282 #ifdef SHOW_DTD_ACTIONS
    283         printf("Document Type:\n");
    284         cout << string((char *) GetCodeUnitPtr(start_pos), end_pos-start_pos) <<endl;
    285 #endif
    286 }
    287 
    288 template <CodeUnit_Base C>
    289 inline void ParsingEngine<C>::PEReference_action(int start_pos, int end_pos) {
    290 }
    291 
    292 template <CodeUnit_Base C>
    293 inline void ParsingEngine<C>::Elementdecl_action(int start_pos, int end_pos) {
    294 #ifdef SHOW_DTD_ACTIONS
    295         printf("Elementdecl:\n");
    296         cout << string((char *) GetCodeUnitPtr(start_pos), end_pos-start_pos) <<endl;
    297 #endif
    298 }
    299 
    300 template <CodeUnit_Base C>
    301 inline void ParsingEngine<C>::AttlistDecl_action(int start_pos, int end_pos) {
    302 #ifdef SHOW_DTD_ACTIONS
    303         printf("AttlistDecl:\n");
    304         cout << string((char *) GetCodeUnitPtr(start_pos), end_pos-start_pos) <<endl;
    305 #endif
    306 }
    307 
    308 template <CodeUnit_Base C>
    309 inline void ParsingEngine<C>::Entitydecl_action(int entity_name_start, int entity_name_end, int start_pos, int end_pos) {
    310 #ifdef SHOW_DTD_ACTIONS
    311         printf("Entitydecl:\n");
    312         cout << string((char *) GetCodeUnitPtr(start_pos), end_pos-start_pos) <<endl;
    313 #endif
    314 }
    315 
    316 template <CodeUnit_Base C>
    317 inline void ParsingEngine<C>::Notationdecl_action(int start_pos, int end_pos) {
    318 #ifdef SHOW_DTD_ACTIONS
    319         printf("Notationdecl:\n");
    320         cout << string((char *) GetCodeUnitPtr(start_pos), end_pos-start_pos) <<endl;
    321 #endif
    322 }
    323 
    324 template <CodeUnit_Base C>
    325 inline void ParsingEngine<C>::Prolog_action(int start_pos, int end_pos) {
    326 #ifdef SHOW_DTD_ACTIONS
    327         printf("Prolog:\n");
    328         cout << string((char *) GetCodeUnitPtr(start_pos), end_pos-start_pos) <<endl;
    329 #endif
    330 }
    331304
    332305int
Note: See TracChangeset for help on using the changeset viewer.