home *** CD-ROM | disk | FTP | other *** search
/ Collection of Hack-Phreak Scene Programs / cleanhpvac.zip / cleanhpvac / TIERRA40.ZIP / BEAGLE / BREAD.C < prev    next >
C/C++ Source or Header  |  1992-09-11  |  3KB  |  98 lines

  1. /* bread.c  27-3-92  reads tierra.run data */
  2. /*** Beagle Explorer: Version 3.1  Copyright (c) 1990, 1991, 1992  Tom Ray ***/
  3.  
  4. #include "stdio.h"
  5. #include "string.h"
  6. #include "ctype.h"
  7.  
  8. typedef unsigned int   Uint;
  9. typedef unsigned long  Ulong;
  10.  
  11. struct last_out {
  12.     Ulong  time;
  13.     Ulong  ctime;
  14.     char   bd;
  15.     Uint   size;
  16.     char   label[4];
  17.     } ;
  18.  
  19. int t_read(char  data[], struct last_out  *lo, int  *first, int  *genotypes)
  20. {   struct last_out  ti;
  21.     int    nargs;
  22.     char   v2[9], v3[9], v4[9];
  23.  
  24.     sscanf(data,"%s", v2);
  25.     if(!strcmp(v2,"num_sp")) return 0;
  26.     nargs = sscanf(data,"%lx%s%s%s", &ti.time, v2, v3, v4);
  27.     if(*first)
  28.     {   *first = 0;
  29.         if(nargs == 4) *genotypes = 1;
  30.         else *genotypes = 0;
  31.         lo->time += ti.time;     /* assumes lo structure initialized to zero */
  32.         if(lo->time >= 1000000L)
  33.         {   lo->time %= 1000000L;
  34.             lo->ctime++;
  35.         }
  36.         lo->bd = v2[0];
  37.         sscanf(v3,"%u", &lo->size);
  38.         if(*genotypes) strcpy(lo->label,v4);
  39.         else strcpy(lo->label,"");
  40.     }
  41.     else
  42.     {   lo->time += ti.time;
  43.         if(lo->time >= 1000000L)
  44.         {   lo->time %= 1000000L;
  45.             lo->ctime++;
  46.         }
  47.         if(*genotypes) switch(nargs)
  48.         {   case 1: break;
  49.             case 2:
  50.             {   if(isdigit(v2[0]))
  51.                 {   sscanf(v2,"%u", &lo->size); break; }
  52.                 else
  53.                 {   if(strlen(v2) == 1)
  54.                     {   lo->bd = v2[0]; break; }
  55.                     else
  56.                     {   strcpy(lo->label,v2); break; }
  57.                 }
  58.             }
  59.             case 3:
  60.             {   if(isdigit(v2[0]))
  61.                 {   sscanf(v2,"%u", &lo->size);
  62.                     strcpy(lo->label,v3);
  63.                 }
  64.                 else
  65.                 {   lo->bd = v2[0];
  66.                     if(isdigit(v3[0]))
  67.                         sscanf(v3,"%u", &lo->size);
  68.                     else
  69.                         strcpy(lo->label,v3);
  70.                 }
  71.                 break;
  72.             }
  73.             case 4:
  74.             {   lo->bd = v2[0];
  75.                 sscanf(v3,"%u", &lo->size);
  76.                 strcpy(lo->label,v4);
  77.                 break;
  78.             }
  79.         }
  80.         else switch(nargs)
  81.         {   case 1: break;
  82.             case 2:
  83.             {   if(isdigit(v2[0]))
  84.                     sscanf(v2,"%u", &lo->size);
  85.                 else
  86.                     lo->bd = v2[0];
  87.                 break;
  88.             }
  89.             case 3:
  90.             {   lo->bd = v2[0];
  91.                 sscanf(v3,"%u", &lo->size);
  92.                 break;
  93.             }
  94.         }
  95.     }
  96.     return 1;
  97. }
  98.