chiark / gitweb /
new FOR_TRA etc. macros; initial hooks for resolver
[trains.git] / hostside / record.c
index 074135b657d027c2884d024ad29b80566935bf11..e247e2fddfa2688cac9128b6cf36c936f4832a39 100644 (file)
@@ -49,14 +49,11 @@ found:
 }
 
 Segment *record_pname2seg(const char *pname) {
-  int i;
-  const SegmentInfo *segi;
-  
-  for (i=0, segi=info_segments;
-       i<NUM_SEGMENTS;
-       i++, segi++)
+  SEG_IV;
+
+  FOR_SEG
     if (!strcmp(segi->pname, pname))
-      return segments + i;
+      return seg;
   
   return 0; /* silently discard data for segments no longer in the layout */
 }
@@ -138,17 +135,17 @@ void record_seg_has(Segment *seg, int backw, Train *tra) {
 
 void record_seg_at(Segment *seg, const char *movposcombpname) {
   const SegPosCombInfo *spci;
-  int i;
+  int poscomb;
   
-  for (i=0, spci=seg->i->poscombs;
-       i<seg->i->n_poscombs;
-       i++, spci++)
+  for (poscomb=0, spci=seg->i->poscombs;
+       poscomb < seg->i->n_poscombs;
+       poscomb++, spci++)
     if (!strcmp(spci->pname, movposcombpname))
       goto found;
   return;
   
 found:
-  seg->movposcomb= i;
+  seg->movposcomb= poscomb;
 }
 
 /*---------- speed curves ----------*/
@@ -211,12 +208,9 @@ static int speedcurveentry_compare(const void *av, const void *bv) {
 }
 
 static void sort_curves(void) {
-  int i;
-  Train *tra;
-  
-  for (i=0, tra=trains;
-       i<n_trains;
-       i++, tra++) {
+  TRA_IV;
+
+  FOR_TRA {
     if (tra->accel.curve) {
       if (tra->accel.curvesz < 2)
        die("config: speed curve too short for %s", tra->pname);
@@ -250,10 +244,11 @@ static void *alloc_some(void *mapbase, int *offset, size_t sz, int count) {
 }
 
 static void alloc(void) {
-  Train *tra; Segment *seg; const SegmentInfo *segi;
+  TRA_IV;
+  SEG_IV;
   void *mapbase=0;
   char **trap;
-  int i, phase, offset, datalen=0;
+  int phase, offset, datalen=0;
 
 #define ALLOC(array,count) \
   ((array)= alloc_some(mapbase,&offset,sizeof(*(array)),(count)))
@@ -281,9 +276,7 @@ static void alloc(void) {
       break;
 
     ALLOC(trains, n_trains);
-    for (i=0, tra=trains, trap=train_pnames;
-        i<n_trains;
-        i++, tra++, trap++) {
+    FOR_TRAIN(tra, trap=train_pnames, trap++) {
       char *pname;
       ALLOC(pname, strlen(*trap)+1);
       if (phase) {
@@ -297,9 +290,7 @@ static void alloc(void) {
 
     ALLOC(segments, info_nsegments);
     if (phase)
-      for (i=0, seg=segments, segi=info_segments;
-          i<NUM_SEGMENTS;
-          i++, seg++, segi++) {
+      FOR_SEG {
        seg->owner= 0;
        seg->movposcomb= -1;
        seg->i= segi;