Search
lxdream.org :: lxdream/src/tools/actparse.c :: diff
lxdream 0.9.1
released Jun 29
Download Now
filename src/tools/actparse.c
changeset 979:2cc7b486ea6c
prev969:3f178ca1398c
next981:79fcace1ab43
author nkeynes
date Wed Feb 04 00:58:54 2009 +0000 (13 years ago)
permissions -rw-r--r--
last change Emit #line directives in output to make debugging a little easier
file annotate diff log raw
1.1 --- a/src/tools/actparse.c Thu Jan 22 00:45:15 2009 +0000
1.2 +++ b/src/tools/actparse.c Wed Feb 04 00:58:54 2009 +0000
1.3 @@ -24,15 +24,7 @@
1.4 #include <glib/gstrfuncs.h>
1.5 #include "tools/gendec.h"
1.6
1.7 -static int yyline;
1.8 -
1.9 -struct action *new_action() {
1.10 - struct action *action = malloc( sizeof( struct action ) );
1.11 - memset( action, 0, sizeof( struct action ) );
1.12 - return action;
1.13 -}
1.14 -
1.15 -static int add_action( char **actions, struct ruleset *rules, char *operation, char *action )
1.16 +static int add_action( struct action *actions, struct ruleset *rules, char *operation, const char *file, int line, char *action )
1.17 {
1.18 char *act = g_strchomp(action);
1.19 char opclean[strlen(operation)+1];
1.20 @@ -60,16 +52,27 @@
1.21 }
1.22 }
1.23 *q = '\0';
1.24 -
1.25 +
1.26 + /* Drop any leading blank lines from the start of the action (and add them
1.27 + * to the line number ) */
1.28 + for( p=act; isspace(*p); p++ ) {
1.29 + if( *p == '\n' ) {
1.30 + act = p+1;
1.31 + line++;
1.32 + }
1.33 + }
1.34 +
1.35 strcpy( operation, g_strstrip(opclean) );
1.36
1.37 for( i=0; i<rules->rule_count; i++ ) {
1.38 if( strcasecmp(rules->rules[i]->format, operation) == 0 ) {
1.39 - if( actions[i] != NULL ) {
1.40 + if( actions[i].text != NULL ) {
1.41 fprintf( stderr, "Duplicate actions for operation '%s'\n", operation );
1.42 return -1;
1.43 }
1.44 - actions[i] = act;
1.45 + actions[i].filename = file;
1.46 + actions[i].lineno = line;
1.47 + actions[i].text = act;
1.48 return 0;
1.49 }
1.50 }
1.51 @@ -79,6 +82,7 @@
1.52
1.53 struct actionfile {
1.54 FILE *f;
1.55 + const char *filename;
1.56 char *text;
1.57 int length;
1.58 int yyposn;
1.59 @@ -97,14 +101,17 @@
1.60
1.61 actionfile_t af = malloc( sizeof(struct actionfile) );
1.62 af->f = f;
1.63 + af->filename = filename;
1.64 af->length = st.st_size+1;
1.65 af->text = malloc( st.st_size+1 );
1.66 fread( af->text, st.st_size, 1, f );
1.67 af->text[st.st_size] = '\0';
1.68 - af->yyline = 0;
1.69 + af->yyline = 1;
1.70 af->yyposn = 0;
1.71 af->rules = rules;
1.72 af->token.symbol = NONE;
1.73 + af->token.lineno = 1;
1.74 + af->token.filename = filename;
1.75
1.76 return af;
1.77 }
1.78 @@ -115,7 +122,7 @@
1.79 /* Destroy previous actions */
1.80 memset( af->token.actions, 0, sizeof(af->token.actions) );
1.81 }
1.82 -
1.83 + af->token.lineno = af->yyline;
1.84 if( af->yyposn == af->length ) {
1.85 af->token.symbol = END;
1.86 } else if( af->token.symbol == TEXT || /* ACTIONS must follow TEXT */
1.87 @@ -126,7 +133,7 @@
1.88 char *operation = &af->text[af->yyposn];
1.89 while( af->yyposn < af->length ) {
1.90 if( af->text[af->yyposn] == '\n' ) {
1.91 - yyline++;
1.92 + af->yyline++;
1.93 if( af->text[af->yyposn+1] == '%' && af->text[af->yyposn+2] == '%' ) {
1.94 af->yyposn += 3;
1.95 break;
1.96 @@ -135,18 +142,21 @@
1.97
1.98 if( af->text[af->yyposn] == '{' && af->text[af->yyposn+1] == ':' ) {
1.99 af->text[af->yyposn] = '\0';
1.100 + int line = af->yyline;
1.101 af->yyposn+=2;
1.102 char *action = &af->text[af->yyposn];
1.103 while( af->yyposn < af->length ) {
1.104 if( af->text[af->yyposn] == ':' && af->text[af->yyposn+1] == '}' ) {
1.105 af->text[af->yyposn] = '\0';
1.106 af->yyposn++;
1.107 - if( add_action( af->token.actions, af->rules, operation, action ) != 0 ) {
1.108 + if( add_action( af->token.actions, af->rules, operation, af->filename, line, action ) != 0 ) {
1.109 af->token.symbol = ERROR;
1.110 return &af->token;
1.111 }
1.112 operation = &af->text[af->yyposn+1];
1.113 break;
1.114 + } else if( af->text[af->yyposn] == '\n' ) {
1.115 + af->yyline++;
1.116 }
1.117 af->yyposn++;
1.118 }
.