Changeset 7 for trunk/ruleset.c


Ignore:
Timestamp:
Aug 15, 2008, 10:15:27 AM (6 years ago)
Author:
marius
Message:

bugfix and updates

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/ruleset.c

    r6 r7  
    1717 * Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA. 
    1818 */ 
    19  
    2019#include <time.h> 
    2120#include <expat.h> 
     
    2322#include <string.h> 
    2423 
     24#include "main.h" 
    2525#include "list.h" 
    2626#include "strlist.h" 
    27 #include "main.h" 
    2827#include "ruleset.h" 
    2928 
     
    3332 
    3433// External Vars 
    35 extern int      debug; 
    36 extern strList  *keyStrings; 
    37 extern strList  *valStrings; 
    38 extern strList  *patternStrings; 
     34extern memphisOpt   *opts; 
     35extern strList      *keyStrings; 
     36extern strList      *valStrings; 
     37extern strList      *patternStrings; 
    3938 
    4039// Pointers to work with 
     
    4342char        **stringStack; 
    4443 
    45 // Counts 
    46 int     cntCfgRule = 0; 
    47  
    4844/** 
    4945 * cfgStartElement: 
    50  * @userdata:  Void 
    51  * @name:  The element name 
    52  * @attributes: The element attribs 
    53  * 
    54  * called when the start of an element has been detected. 
     46 * @userdata:   cfgRules struct to work with 
     47 * @name:       The element name 
     48 * @atts:       The element attributes 
     49 * 
     50 * Called when the start of an element has been detected. 
    5551 */ 
    5652static void XMLCALL 
    5753cfgStartElement(void *userData, const char *name, const char **atts) { 
    5854    cfgRules *ruleset = (cfgRules *)userData; 
    59     if (debug > 1) 
     55    if (opts->debug > 1) 
    6056        fprintf(stdout,"cfgStartElement\n"); 
    6157 
     
    6359    if (strcmp((char *) name, "rules") == 0) { 
    6460        // Init Ruleset 
    65         ruleset = malloc(sizeof(cfgRules)); 
    6661        ruleset->data = NULL; 
    6762        ruleset->scale=1; 
     
    6964         
    7065        while (*atts != NULL) { 
    71             if(strcmp((char *) *(atts), "data") == 0) { 
    72                 size_t c = strlen((char *) *(atts +1)) +1; 
    73                 ruleset->data = malloc(c); 
    74                 strncpy((char *) ruleset->data, (char *) *(atts +1), c); 
    75             } else if(strcmp((char *) *(atts), "scale") == 0) { 
    76                 sscanf((char *) *(atts +1),"%f",&ruleset->scale); 
     66            if(strcmp((char *) *(atts), "background") == 0) { 
     67                sscanf((char *) *(atts+1),"#%2x%2x%2x", 
     68                                    (unsigned int *)&ruleset->background[0], 
     69                                    (unsigned int *)&ruleset->background[1], 
     70                                    (unsigned int *)&ruleset->background[2]); 
    7771            } 
    7872            atts+=2; 
     
    9589        stringStack = malloc(MAXSTACK*sizeof(char *)); 
    9690        int c; 
    97          
    98 #ifdef DEBUG         
    99         new->d = ruleset->depth; 
    100          
    101         int h; 
    102         for(h=0;h<ruleset->depth;h++){ 
    103             fprintf(stdout,"-"); 
    104         } 
    105         fprintf(stdout,"rule\n"); 
    106 #endif         
    10791         
    10892        // Populate Rule 
     
    164148        ruleset->cntElse++; 
    165149        ruleset->depth++; 
    166          
    167 #ifdef DEBUG         
    168         new->d = ruleset->depth; 
    169          
    170         int h; 
    171         for(h=0;h<ruleset->depth;h++){ 
    172             fprintf(stdout,"-"); 
    173         } 
    174         fprintf(stdout,"else\n"); 
    175 #endif         
    176150    } 
    177151    // Parsing Polygone, etc. 
     
    221195/** 
    222196 * cfgEndElement: 
    223  * @userData:  Void 
    224  * @name:  The element name 
    225  * 
    226  * called when the end of an element has been detected. 
     197 * @userdata:   cfgRules struct to work with 
     198 * @name:       The element name 
     199 * 
     200 * Called when the end of an element has been detected. 
    227201 */ 
    228202static void XMLCALL 
    229203cfgEndElement(void *userData, const char *name) { 
    230204    cfgRules *ruleset = (cfgRules *)userData; 
    231     if (debug > 1) 
     205    if (opts->debug > 1) 
    232206        fprintf(stdout,"cfgEndElement\n"); 
    233207         
     
    249223 
    250224/** 
    251  * rulesetRead 
     225 * rulesetRead: 
     226 * @filename:   Filename of the rule file 
     227 * 
     228 * Called to parse rules in the rulefile. Returns a cfgRules struct. 
    252229 */ 
    253230cfgRules* rulesetRead(char *filename) { 
    254     if (debug > 1) 
     231    if (opts->debug > 1) 
    255232        fprintf(stdout,"rulesetRead\n"); 
    256233     
     
    277254    ruleset->cntRule = 0; 
    278255    ruleset->cntElse = 0; 
     256     
     257     
     258    if (opts->debug > 0) { 
     259        fprintf(stdout," Ruleset parsing"); 
     260        fflush(stdout); 
     261    } 
    279262     
    280263    long start = (long)clock(); 
     
    310293    fclose(fd); 
    311294     
    312     if (debug > 0) 
    313         fprintf(stdout," Ruleset parsing done. (%i/%i) [%fs]\n", 
     295    if (opts->debug > 0) 
     296        fprintf(stdout," done. (%i/%i) [%fs]\n", 
    314297                ruleset->cntRule, ruleset->cntElse, 
    315298                ((long)clock()-start)/(double)CLOCKS_PER_SEC);    
Note: See TracChangeset for help on using the changeset viewer.