Search
lxdream.org :: lxdream/src/tools/actparse.c :: diff
lxdream 0.9.1
released Jun 29
Download Now
filename src/tools/actparse.c
changeset 736:a02d1475ccfd
prev561:533f6b478071
next948:545c85cc56f1
author nkeynes
date Mon Jul 14 07:44:42 2008 +0000 (12 years ago)
permissions -rw-r--r--
last change Re-indent everything consistently
Fix include guards for consistency as well
file annotate diff log raw
1.1 --- a/src/tools/actparse.c Tue Jan 01 05:08:38 2008 +0000
1.2 +++ b/src/tools/actparse.c Mon Jul 14 07:44:42 2008 +0000
1.3 @@ -42,41 +42,41 @@
1.4
1.5 // Strip c-style comments
1.6 while( *p ) {
1.7 - if( *p == '/' && *(p+1) == '*' ) {
1.8 - p+=2;
1.9 - while( *p ) {
1.10 - if( *p == '*' && *(p+1) == '/' ) {
1.11 - p+=2;
1.12 - break;
1.13 - }
1.14 - p++;
1.15 - }
1.16 - } else if( *p == '/' && *(p+1) == '/' ) {
1.17 - p+=2;
1.18 - while( *p && *p != '\n' ) {
1.19 - p++;
1.20 - }
1.21 - } else {
1.22 - *q++ = *p++;
1.23 - }
1.24 + if( *p == '/' && *(p+1) == '*' ) {
1.25 + p+=2;
1.26 + while( *p ) {
1.27 + if( *p == '*' && *(p+1) == '/' ) {
1.28 + p+=2;
1.29 + break;
1.30 + }
1.31 + p++;
1.32 + }
1.33 + } else if( *p == '/' && *(p+1) == '/' ) {
1.34 + p+=2;
1.35 + while( *p && *p != '\n' ) {
1.36 + p++;
1.37 + }
1.38 + } else {
1.39 + *q++ = *p++;
1.40 + }
1.41 }
1.42 *q = '\0';
1.43 strcpy( operation, g_strstrip(opclean) );
1.44
1.45 for( i=0; i<rules->rule_count; i++ ) {
1.46 - if( strcasecmp(rules->rules[i]->format, operation) == 0 ) {
1.47 - if( actions->actions[i] != NULL ) {
1.48 - fprintf( stderr, "Duplicate actions for operation '%s'\n", operation );
1.49 - return -1;
1.50 - }
1.51 - actions->actions[i] = act;
1.52 - return 0;
1.53 - }
1.54 + if( strcasecmp(rules->rules[i]->format, operation) == 0 ) {
1.55 + if( actions->actions[i] != NULL ) {
1.56 + fprintf( stderr, "Duplicate actions for operation '%s'\n", operation );
1.57 + return -1;
1.58 + }
1.59 + actions->actions[i] = act;
1.60 + return 0;
1.61 + }
1.62 }
1.63 fprintf(stderr, "No operation found matching '%s'\n", operation );
1.64 return -1;
1.65 }
1.66 -
1.67 +
1.68
1.69 struct actionset *parse_action_file( struct ruleset *rules, FILE *f )
1.70 {
1.71 @@ -84,7 +84,7 @@
1.72 struct stat st;
1.73 char *text;
1.74 int i, length;
1.75 -
1.76 +
1.77 memset( actions, 0, sizeof( struct actionset ) );
1.78 /* Read whole file in (for convenience) */
1.79 fstat( fileno(f), &st );
1.80 @@ -95,47 +95,47 @@
1.81 yyline = 0;
1.82 actions->pretext = text;
1.83 for( i=0; i<length; i++ ) {
1.84 - if( text[i] == '\n' ) {
1.85 - yyline++;
1.86 - if( i+3 < length && text[i+1] == '%' && text[i+2] == '%' ) {
1.87 - text[i+1] = '\0';
1.88 - i+=3;
1.89 - break;
1.90 - }
1.91 - }
1.92 + if( text[i] == '\n' ) {
1.93 + yyline++;
1.94 + if( i+3 < length && text[i+1] == '%' && text[i+2] == '%' ) {
1.95 + text[i+1] = '\0';
1.96 + i+=3;
1.97 + break;
1.98 + }
1.99 + }
1.100 }
1.101
1.102 char *operation = &text[i];
1.103 for( ; i<length; i++ ) {
1.104 - if( text[i] == '\n' ) {
1.105 - yyline++;
1.106 - if( i+3 < length && text[i+1] == '%' && text[i+2] == '%' ) {
1.107 - i+=3;
1.108 - break;
1.109 - }
1.110 - }
1.111 -
1.112 - if( text[i] == '{' && text[i+1] == ':' ) {
1.113 - text[i] = '\0';
1.114 - i+=2;
1.115 - char *action = &text[i];
1.116 - for( ;i<length; i++ ) {
1.117 - if( text[i] == ':' && text[i+1] == '}' ) {
1.118 - text[i] = '\0';
1.119 - i++;
1.120 - if( add_action( actions, rules, operation, action ) != 0 ) {
1.121 - free(actions);
1.122 - free(text);
1.123 - return NULL;
1.124 - }
1.125 - operation = &text[i+1];
1.126 - break;
1.127 - }
1.128 - }
1.129 - }
1.130 + if( text[i] == '\n' ) {
1.131 + yyline++;
1.132 + if( i+3 < length && text[i+1] == '%' && text[i+2] == '%' ) {
1.133 + i+=3;
1.134 + break;
1.135 + }
1.136 + }
1.137 +
1.138 + if( text[i] == '{' && text[i+1] == ':' ) {
1.139 + text[i] = '\0';
1.140 + i+=2;
1.141 + char *action = &text[i];
1.142 + for( ;i<length; i++ ) {
1.143 + if( text[i] == ':' && text[i+1] == '}' ) {
1.144 + text[i] = '\0';
1.145 + i++;
1.146 + if( add_action( actions, rules, operation, action ) != 0 ) {
1.147 + free(actions);
1.148 + free(text);
1.149 + return NULL;
1.150 + }
1.151 + operation = &text[i+1];
1.152 + break;
1.153 + }
1.154 + }
1.155 + }
1.156 }
1.157
1.158 actions->posttext = &text[i];
1.159 -
1.160 +
1.161 return actions;
1.162 }
.