1.1 --- a/src/tools/actparse.c Mon Jul 14 07:44:42 2008 +0000
1.2 +++ b/src/tools/actparse.c Tue Jan 13 11:56:28 2009 +0000
1.7 -int add_action( struct actionset *actions, struct ruleset *rules, char *operation, char *action )
1.8 +int add_action( char **actions, struct ruleset *rules, char *operation, char *action )
1.10 char *act = g_strchomp(action);
1.14 for( i=0; i<rules->rule_count; i++ ) {
1.15 if( strcasecmp(rules->rules[i]->format, operation) == 0 ) {
1.16 - if( actions->actions[i] != NULL ) {
1.17 + if( actions[i] != NULL ) {
1.18 fprintf( stderr, "Duplicate actions for operation '%s'\n", operation );
1.21 - actions->actions[i] = act;
1.26 @@ -77,65 +77,105 @@
1.30 +struct actionfile {
1.36 + struct ruleset *rules;
1.37 + struct actiontoken token;
1.40 -struct actionset *parse_action_file( struct ruleset *rules, FILE *f )
1.41 +actionfile_t action_file_open( const char *filename, struct ruleset *rules )
1.43 - struct actionset *actions = malloc( sizeof(struct actionset ) );
1.47 + FILE *f = fopen( filename, "ro" );
1.50 + fstat( fileno(f), &st );
1.52 + actionfile_t af = malloc( sizeof(struct actionfile) );
1.54 + af->length = st.st_size+1;
1.55 + af->text = malloc( st.st_size+1 );
1.56 + fread( af->text, st.st_size, 1, f );
1.57 + af->text[st.st_size] = '\0';
1.60 + af->rules = rules;
1.61 + af->token.symbol = NONE;
1.66 - memset( actions, 0, sizeof( struct actionset ) );
1.67 - /* Read whole file in (for convenience) */
1.68 - fstat( fileno(f), &st );
1.69 - length = st.st_size;
1.70 - text = malloc( length+1 );
1.71 - fread( text, length, 1, f );
1.72 - text[length] = '\0';
1.74 - actions->pretext = text;
1.75 - for( i=0; i<length; i++ ) {
1.76 - if( text[i] == '\n' ) {
1.78 - if( i+3 < length && text[i+1] == '%' && text[i+2] == '%' ) {
1.82 +actiontoken_t action_file_next( actionfile_t af )
1.84 + if( af->token.symbol == ACTIONS ) {
1.85 + /* Destroy previous actions */
1.86 + memset( af->token.actions, 0, sizeof(af->token.actions) );
1.89 + if( af->yyposn == af->length ) {
1.90 + af->token.symbol = END;
1.91 + } else if( af->token.symbol == TEXT || /* ACTIONS must follow TEXT */
1.92 + (af->token.symbol == NONE && af->text[af->yyposn] == '\%' && af->text[af->yyposn+1] == '%') ) {
1.93 + /* Begin action block */
1.94 + af->token.symbol = ACTIONS;
1.96 + char *operation = &af->text[af->yyposn];
1.97 + while( af->yyposn < af->length ) {
1.98 + if( af->text[af->yyposn] == '\n' ) {
1.100 + if( af->text[af->yyposn+1] == '%' && af->text[af->yyposn+2] == '%' ) {
1.106 + if( af->text[af->yyposn] == '{' && af->text[af->yyposn+1] == ':' ) {
1.107 + af->text[af->yyposn] = '\0';
1.109 + char *action = &af->text[af->yyposn];
1.110 + while( af->yyposn < af->length ) {
1.111 + if( af->text[af->yyposn] == ':' && af->text[af->yyposn+1] == '}' ) {
1.112 + af->text[af->yyposn] = '\0';
1.114 + if( add_action( af->token.actions, af->rules, operation, action ) != 0 ) {
1.115 + af->token.symbol = ERROR;
1.116 + return &af->token;
1.118 + operation = &af->text[af->yyposn+1];
1.128 - char *operation = &text[i];
1.129 - for( ; i<length; i++ ) {
1.130 - if( text[i] == '\n' ) {
1.132 - if( i+3 < length && text[i+1] == '%' && text[i+2] == '%' ) {
1.138 - if( text[i] == '{' && text[i+1] == ':' ) {
1.141 - char *action = &text[i];
1.142 - for( ;i<length; i++ ) {
1.143 - if( text[i] == ':' && text[i+1] == '}' ) {
1.146 - if( add_action( actions, rules, operation, action ) != 0 ) {
1.151 - operation = &text[i+1];
1.154 + af->token.symbol = TEXT;
1.155 + af->token.text = &af->text[af->yyposn];
1.156 + while( af->yyposn < af->length ) {
1.158 + if( af->text[af->yyposn-1] == '\n' ) {
1.160 + if( af->text[af->yyposn] == '%' && af->text[af->yyposn+1] == '%' ) {
1.161 + af->text[af->yyposn] = '\0';
1.168 + return &af->token;
1.171 - actions->posttext = &text[i];
1.172 +void action_file_close( actionfile_t af )
1.174 + free( af->text );