From 487741dae85bc792f9019b9bb46873b7b01a37f9 Mon Sep 17 00:00:00 2001 From: ian Date: Wed, 13 Feb 2008 18:39:23 +0000 Subject: [PATCH] also parse homes.record --- hostside/homes.record | 1 + hostside/record-i.h | 1 + hostside/record-l.l | 3 ++- hostside/record-y.y | 11 +++++++++-- hostside/record.c | 7 +++++++ hostside/safety.h | 2 ++ 6 files changed, 22 insertions(+), 3 deletions(-) create mode 100644 hostside/homes.record diff --git a/hostside/homes.record b/hostside/homes.record new file mode 100644 index 0000000..284fbf2 --- /dev/null +++ b/hostside/homes.record @@ -0,0 +1 @@ +train santafe home X5 X6 diff --git a/hostside/record-i.h b/hostside/record-i.h index eddb680..0da12a7 100644 --- a/hostside/record-i.h +++ b/hostside/record-i.h @@ -11,6 +11,7 @@ void record_train_at(Train *tra, int backw, Segment *seg, int maxi, int unc); void record_train_is(Train *tra, int addr, int head, int det, int tail); void record_train_step(Train *tra, int step, int speed, int upw, int downw); void record_train_step_count(void); +void record_train_home(Train *tra, int backw, Segment *seg); void record_seg_has(Segment *seg, int backw, Train *tra); void record_seg_at(Segment *seg, const char *movposcomb_pname); diff --git a/hostside/record-l.l b/hostside/record-l.l index 68edcb3..1422456 100644 --- a/hostside/record-l.l +++ b/hostside/record-l.l @@ -22,7 +22,8 @@ seg { STR SEG; } is { STR IS; } at { STR AT; } has { STR HAS; } -step { STR STEP; } +step { STR STEP; } +home { STR HOME; } end { STR END; } /* new keywords must be added to %token and ident: in record-y.y */ diff --git a/hostside/record-y.y b/hostside/record-y.y index 5a97fda..2a3cb7a 100644 --- a/hostside/record-y.y +++ b/hostside/record-y.y @@ -3,6 +3,8 @@ %{ #include "record-i.h" #include "record-l.h" + +static Train *cur_train; %} %union { @@ -12,7 +14,7 @@ int num; } -%token TRAIN SEG IS AT HAS STEP END IDENT +%token TRAIN SEG IS AT HAS STEP HOME END IDENT %token NL %token NUM @@ -37,6 +39,9 @@ line: /* empty */ | TRAIN train AT backwards seg ':' NUM '+' '-' NUM { if ($2) record_train_at($2,$4,$5,$7,$10); } + | TRAIN train { cur_train=$2; } HOME segments + { + } | TRAIN train STEP NUM '=' NUM NUM '/' NUM { if (!trains) record_train_step_count(); else if ($2) record_train_step($2,$4,$6,$7,$9); @@ -51,7 +56,9 @@ line: /* empty */ backwards: /* empty */ { return 0; } | '-' { return 1; } -ident: TRAIN | SEG | IS | AT | HAS | STEP | END | IDENT +segments: { cur_train= 0; } + | backwards seg { record_train_home(cur_train,$1,$2); } segments +ident: TRAIN | SEG | IS | AT | HAS | STEP | HOME | END | IDENT seg: ident { $$= record_pname2seg($1); } train: ident { $$= record_pname2train($1); } diff --git a/hostside/record.c b/hostside/record.c index bc2be62..074135b 100644 --- a/hostside/record.c +++ b/hostside/record.c @@ -7,6 +7,7 @@ * train at [-]:+- * train is ++ * train step = / + * train home [-] [-] [-] * seg has [-] * seg at * @@ -124,6 +125,12 @@ void record_train_at(Train *tra, int backw, Segment *seg, int maxi, int unc) { tra->backwards= backw; } +void record_train_home(Train *tra, int backw, Segment *seg) { + if (!tra) return; + seg->home= tra; + seg->ho_backwards= backw; +} + void record_seg_has(Segment *seg, int backw, Train *tra) { seg->owner= tra; seg->tr_backwards= backw; diff --git a/hostside/safety.h b/hostside/safety.h index a4806f9..d7dd847 100644 --- a/hostside/safety.h +++ b/hostside/safety.h @@ -66,8 +66,10 @@ struct Train { struct Segment { Train *owner; /* or 0 */ + Train *home; /* or 0 */ unsigned tr_backwards:1, /* train's motion is (would be) backwards wrt track */ + ho_backwards:1, /* home train has its front and rear backwards wrt track */ movfeat_moving:1, /* feature(s) have been told to change to movposcomb */ cm_autostop:1, /* train should stop on detection */ seg_inverted:1, /* polarity is inverted */ -- 2.30.2