6 #include <glib/gstrfuncs.h>
7 #include "tools/gendec.h"
11 struct action *new_action() {
12 struct action *action = malloc( sizeof( struct action ) );
13 memset( action, 0, sizeof( struct action ) );
17 int add_action( struct actionset *actions, struct ruleset *rules, char *operation, char *action )
19 char *act = g_strchomp(action);
21 char opclean[strlen(operation)];
22 char *p = operation, *q = opclean;
25 // Strip c-style comments
27 if( *p == '/' && *(p+1) == '*' ) {
30 if( *p == '*' && *(p+1) == '/' ) {
36 } else if( *p == '/' && *(p+1) == '/' ) {
38 while( *p && *p != '\n' ) {
46 strcpy( operation, g_strstrip(opclean) );
48 for( i=0; i<rules->rule_count; i++ ) {
49 if( strcasecmp(rules->rules[i]->format, operation) == 0 ) {
50 if( actions->actions[i] != NULL ) {
51 fprintf( stderr, "Duplicate actions for operation '%s'\n", operation );
54 actions->actions[i] = act;
58 fprintf(stderr, "No operation found matching '%s'\n", operation );
63 struct actionset *parse_action_file( struct ruleset *rules, FILE *f )
65 struct actionset *actions = malloc( sizeof(struct actionset ) );
70 memset( actions, 0, sizeof( struct actionset ) );
71 /* Read whole file in (for convenience) */
72 fstat( fileno(f), &st );
74 text = malloc( length+1 );
75 fread( text, length, 1, f );
78 actions->pretext = text;
79 for( i=0; i<length; i++ ) {
80 if( text[i] == '\n' ) {
82 if( i+3 < length && text[i+1] == '%' && text[i+2] == '%' ) {
90 char *operation = &text[i];
91 for( ; i<length; i++ ) {
92 if( text[i] == '\n' ) {
94 if( i+3 < length && text[i+1] == '%' && text[i+2] == '%' ) {
100 if( text[i] == '{' && text[i+1] == ':' ) {
103 char *action = &text[i];
104 for( ;i<length; i++ ) {
105 if( text[i] == ':' && text[i+1] == '}' ) {
108 if( add_action( actions, rules, operation, action ) != 0 ) {
113 operation = &text[i+1];
120 actions->posttext = &text[i];
.