From 1ac3979c6c92f2e3cfc0bc191a963537bfca3b68 Mon Sep 17 00:00:00 2001 From: ian Date: Tue, 24 Jun 2008 21:35:21 +0000 Subject: [PATCH] Revert aborting feature changes as planned --- hostside/realtime.h | 19 ++++++++++++++--- hostside/record-l.l | 2 +- hostside/record-y.y | 13 ++++++------ hostside/record.c | 51 +++++++++++++++++++++++++++++++-------------- 4 files changed, 58 insertions(+), 27 deletions(-) diff --git a/hostside/realtime.h b/hostside/realtime.h index 52f12dd..bd67a7a 100644 --- a/hostside/realtime.h +++ b/hostside/realtime.h @@ -71,19 +71,32 @@ void retransmit_urgent_cancel(RetransmitUrgentNode *rn); #define FEATURESADDR_TRANSMITS 4 /* 0..2 are func0to4 func5to8 func9to12 and speed cmd - * pi.l is 0 if not applicable */ + * pi.l is 0 if not transmitting */ typedef struct FeaturesAddr { struct FeaturesAddr *next; - int addr; - unsigned current, permitted; /* nmra features */ + int addr, cbitmap; RetransmitRelaxedNode rn[FEATURESADDR_TRANSMITS]; } FeaturesAddr; +typedef struct { + FeaturesAddr *a; + int bitval; /* may have no or several bits set */ + int speedstep; /* -ve means backwards; 0 means not to use motor for feat */ +} FeaturesFeature; + +typedef struct FeaturesTarget { + struct FeaturesTarget *next; + char *pname; + char *featchs; /* null-terminated */ + FeaturesFeature **feats; /* same order as featchs */ +} FeaturesTarget; + extern int n_trains; extern Train *trains; extern Segment *segments; +extern FeaturesTarget *feattargs; extern FeaturesAddr *feataddrs; /*---------- global variables, in realtime.c ----------*/ diff --git a/hostside/record-l.l b/hostside/record-l.l index 6048a80..c514a09 100644 --- a/hostside/record-l.l +++ b/hostside/record-l.l @@ -23,7 +23,7 @@ feature { STRT FEATURE; } is { STRT IS; } at { STRT AT; } has { STRT HAS; } -minus { STRT MINUS; } +inverted { STRT INVERTED; } step { STRT STEP; } stops { STRT STOPS; } home { STRT HOME; } diff --git a/hostside/record-y.y b/hostside/record-y.y index 8692449..8ddbe8b 100644 --- a/hostside/record-y.y +++ b/hostside/record-y.y @@ -17,7 +17,7 @@ static Train *cur_train; double dbl; } -%token TRAIN FEATURE SEG IS AT HAS MINUS STEP STOPS HOME END +%token TRAIN FEATURE SEG IS AT HAS INVERTED STEP STOPS HOME END %token IDENT FEATLETTER %token NL %token NUM @@ -61,23 +61,23 @@ line: /* empty */ { if ($2) record_seg_at($2,$4); } | FEATURE feature IS feataddr NUM - { if ($4) record_feature_nmrafeat($4,$5); + { if ($2) record_feature_nmrafeat($2,$4,$5); } | FEATURE feature IS feataddr STEP NUM - { if ($4) record_feature_motor($4,$6); + { if ($2) record_feature_motor($2,$4,$6); } backwards: /* empty */ { $$= 0; } | '-' { $$= 1; } inverted: /* empty */ { $$= 0; } - | MINUS { $$= 1; } + | INVERTED { $$= 1; } segments: { cur_train= (void*)-1; } | backwards seg { record_train_home(cur_train,$1,$2); } segments ident: TRAIN | SEG - | IS | AT | HAS | MINUS | STEP | STOPS | HOME + | IS | AT | HAS | INVERTED | STEP | STOPS | HOME | END | IDENT | FEATLETTER @@ -86,8 +86,7 @@ dbl: DBL seg: ident { $$= record_pname2seg($1); } train: ident { $$= record_pname2train($1); } -feature: ident ident { record_feature_public($1,$2); } - | ident MINUS { record_feature_private(); } +feature: ident FEATLETTER { $$= record_pname2feature($1,$2); } feataddr: NUM { $$= record_feataddr($1); } end: END NL diff --git a/hostside/record.c b/hostside/record.c index fc65d09..f22d5b0 100644 --- a/hostside/record.c +++ b/hostside/record.c @@ -10,8 +10,8 @@ * train stops at after * seg has [-] [inverted] * seg at - * feature |- is - * feature |- is step [-] + * feature is + * feature is step [-] * * speed is floating point in m/s */ @@ -21,10 +21,9 @@ #include "record-i.h" #include "record-l.h" +FeaturesTarget *feattargs; FeaturesAddr *feataddrs; -static char *feat_train, *feat_feat; - /*---------- input and error handling ----------*/ static const char *filename; @@ -93,20 +92,40 @@ FeaturesAddr *record_feataddr(int num) { return node; } -static void record_feature_freeold(void) { - free(feat_train); - free(feat_feat); -} +FeaturesFeature *record_pname2feature(const char *name, const char *letter) { + FeaturesTarget **search, *node; + FeaturesFeature *feat; + char *p; + int l; + + if (!trains) return 0; /* 2nd pass only */ + assert(letter[0] && !letter[1]); -void record_feature_public(const char *name, const char *feat) { - record_feature_freeold(); - feat_train= mstrdup(name); - feat_feat= mstrdup(feat); -} + SLIST_FIND_OR_INSERT + (feattargs,search,node, !strcmp(name,node->pname), ({ + node->pname= mstrdup(name); + node->featchs= 0; + node->feats= 0; + })); + + l= node->featchs ? strlen(node->featchs) : 0; + if (l) { + p= strchr(node->featchs, letter[0]); + if (p) return node->feats[p - node->featchs]; + } + + node->featchs= mrealloc(node->featchs,l+2); + node->featchs[l]= letter[0]; + node->featchs[l+1]= 0; + + node->feats= mrealloc(node->feats, (l+1)*sizeof(*node->feats)); + node->feats[l]= feat= mmalloc(sizeof(*feat)); + + feat->a= 0; + feat->bitval= 0; + feat->speedstep= 0; -void record_feature_private(void) { - record_feature_freeold(); - feat_train= feat_feat= 0; + return feat; } /*---------- zone allocator for strings ----------*/ -- 2.30.2