chiark / gitweb /
Abortive change to feature arrangements.
authorian <ian>
Tue, 24 Jun 2008 21:34:45 +0000 (21:34 +0000)
committerian <ian>
Tue, 24 Jun 2008 21:34:45 +0000 (21:34 +0000)
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.

hostside/realtime.h
hostside/record-l.l
hostside/record-y.y
hostside/record.c

index bd67a7a92b43c6d3ac4ccc26c79c3586295ceeed..52f12dde607a13694284251e2f903a51b0552af6 100644 (file)
@@ -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 ----------*/
index c514a098ad660078ecb399dee81c6b63c0eafee8..6048a805318d942d66a1080fff5ec646798d1b6a 100644 (file)
@@ -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; }
index 8ddbe8ba73d658a5ea3d3b0c74ac4bb849c0a89f..8692449d75edf2f653178ffb613bcc2de62573b5 100644 (file)
@@ -17,7 +17,7 @@ static Train *cur_train;
   double dbl;
 }
 
-%token <name>  TRAIN FEATURE SEG  IS AT HAS INVERTED STEP STOPS HOME  END
+%token <name>  TRAIN FEATURE SEG  IS AT HAS MINUS STEP STOPS HOME  END
 %token <name>  IDENT FEATLETTER
 %token <name>  NL
 %token <num>   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
index f22d5b0c04571ab3d0633014c25655df44b3e266..fc65d0994713ca5b02ab7aa2be10f1ce9a46280f 100644 (file)
@@ -10,8 +10,8 @@
  *  train <trainpn> stops <step> at <distance> after <milliseconds>
  *  seg <segpn> has [-]<ownerpn> [inverted]
  *  seg <segpn> at <movposcomb>
- *  feature <trainorfeatpn> <letter> is <addr> <nmranum>
- *  feature <trainorfeatpn> <letter> is <addr> step [-]<nmranum>
+ *  feature <trainpn> <featpn>|- is <addr> <nmranum>
+ *  feature <trainpn> <featpn>|- is <addr> step [-]<nmranum>
  *
  * speed is floating point in m/s
  */
 #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 ----------*/