From: ian Date: Tue, 24 Jun 2008 21:34:45 +0000 (+0000) Subject: Abortive change to feature arrangements. X-Git-Url: http://www.chiark.greenend.org.uk/ucgi/~ijackson/git?a=commitdiff_plain;h=ee9056538930930ae8cabc3431466ae286ecf8bd;p=trains.git Abortive change to feature arrangements. Was going to - change features to be named rather than lettered - make realtime not deal with the names at all But this is actually tedious. Instead if we need another level of indirection for the UI we'll add one then. So commit this now and immediately revert it. --- diff --git a/hostside/realtime.h b/hostside/realtime.h index bd67a7a..52f12dd 100644 --- a/hostside/realtime.h +++ b/hostside/realtime.h @@ -71,32 +71,19 @@ 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 transmitting */ + * pi.l is 0 if not applicable */ typedef struct FeaturesAddr { struct FeaturesAddr *next; - int addr, cbitmap; + int addr; + unsigned current, permitted; /* nmra features */ 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 c514a09..6048a80 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; } -inverted { STRT INVERTED; } +minus { STRT MINUS; } step { STRT STEP; } stops { STRT STOPS; } home { STRT HOME; } diff --git a/hostside/record-y.y b/hostside/record-y.y index 8ddbe8b..8692449 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 INVERTED STEP STOPS HOME END +%token TRAIN FEATURE SEG IS AT HAS MINUS 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 ($2) record_feature_nmrafeat($2,$4,$5); + { if ($4) record_feature_nmrafeat($4,$5); } | FEATURE feature IS feataddr STEP NUM - { if ($2) record_feature_motor($2,$4,$6); + { if ($4) record_feature_motor($4,$6); } backwards: /* empty */ { $$= 0; } | '-' { $$= 1; } inverted: /* empty */ { $$= 0; } - | INVERTED { $$= 1; } + | MINUS { $$= 1; } segments: { cur_train= (void*)-1; } | backwards seg { record_train_home(cur_train,$1,$2); } segments ident: TRAIN | SEG - | IS | AT | HAS | INVERTED | STEP | STOPS | HOME + | IS | AT | HAS | MINUS | STEP | STOPS | HOME | END | IDENT | FEATLETTER @@ -86,7 +86,8 @@ dbl: DBL seg: ident { $$= record_pname2seg($1); } train: ident { $$= record_pname2train($1); } -feature: ident FEATLETTER { $$= record_pname2feature($1,$2); } +feature: ident ident { record_feature_public($1,$2); } + | ident MINUS { record_feature_private(); } feataddr: NUM { $$= record_feataddr($1); } end: END NL diff --git a/hostside/record.c b/hostside/record.c index f22d5b0..fc65d09 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,9 +21,10 @@ #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; @@ -92,40 +93,20 @@ FeaturesAddr *record_feataddr(int num) { return node; } -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]); - - 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)); +static void record_feature_freeold(void) { + free(feat_train); + free(feat_feat); +} - feat->a= 0; - feat->bitval= 0; - feat->speedstep= 0; +void record_feature_public(const char *name, const char *feat) { + record_feature_freeold(); + feat_train= mstrdup(name); + feat_feat= mstrdup(feat); +} - return feat; +void record_feature_private(void) { + record_feature_freeold(); + feat_train= feat_feat= 0; } /*---------- zone allocator for strings ----------*/