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

  1. /* template.c  27-3-92  template locator for the Beagle Explorer */
  2. /*** Beagle Explorer: Version 3.1  Copyright (c) 1990, 1991, 1992  Tom Ray ***/
  3.  
  4. #include "beagle.h"
  5. #include "externb.h"
  6.  
  7. extern FILE  *info;
  8. HWND         whte;
  9. TRANSACTION  *ptte;
  10.  
  11. int   min_temp_siz;
  12. char  genepath[41], genefile[13], genotype[4];
  13. struct use_template  *t;
  14.  
  15. int template(void)
  16. {   int  i;
  17.     static int  first = 1;
  18.     char  t;
  19.     HWND  whins;
  20.  
  21.     if(first)
  22.     {   first = 0;
  23.         sprintf(genepath,"c:\\tierra\\gb");
  24.         sprintf(genefile,"0080.gen");
  25.         sprintf(genotype,"aaa");
  26.         min_temp_siz = 3;
  27.     }
  28.     while(1) {
  29.     whte = wigen(2,4,4,58,FRDOUBLE,"templates");
  30.     ptte = vpreload(4,0,NULLF,NULLF,NULLF,NULLF);
  31.     for(i = 0; i <= 3; i++) (*(ptte->def))[i].use_ext = TRUE;
  32.     vdeffld(ptte,0,STRING,0,1, "genebank path =",-1,40,NULL,genepath,NO);
  33.     vdeffld(ptte,1,STRING,1,1, "genefile name =",-1,12,NULL,genefile,NO);
  34.     vdeffld(ptte,2,STRING,2,1, "genotype      =",-1, 3,NULL,genotype,NO);
  35.     vdeffld(ptte,3,INTEGER,3,1,"min temp size =",-1, 3,NULL,&min_temp_siz,NO);
  36.     whins = wiinv(23,13,
  37.         "\x1e\x1f, or Enter to select; Esc to exit; Ctrl-Enter to run");
  38.     visible(whte,YES,YES);
  39.     ptte->fld_valfn = temp_info_chk;
  40.     if(DWSUCCESS == vread(ptte,whte,YES))
  41.     {   vdelete(whte,NONE); vdelete(whins,NONE);
  42.         for (t = 0; t < PLOIDY; t++)
  43.             templat(t);
  44.     }
  45.     else
  46.     {   vdelete(whte,NONE); vdelete(whins,NONE);
  47.         return 1;
  48.     }
  49.     }
  50.     vdelete(whins,NONE);
  51.     return 1;
  52. }
  53.  
  54. int temp_info_chk(TRANSACTION  *tp)
  55. {   int     success;
  56.     char    path[80];
  57.     head_t  head;
  58.     indx_t  *indx;
  59.  
  60.     if(tp->cur_fld == 0)
  61.     {   getcwd(path,79);
  62.         success = chdir(genepath);
  63.         chdir(path);
  64.         if(success)
  65.         {   wierror(2,45,"directory not found");
  66.             return FALSE;
  67.         }
  68.         sprintf(path,"%s/opcode.map", genepath);
  69.         info = fopen(path,"r");
  70.         if(info == NULL)
  71.         {   wierror(2,45,"opcode.map not found");
  72.             return FALSE;
  73.         }
  74.         fclose(info);
  75.         return TRUE;
  76.     }
  77.     if(tp->cur_fld == 1)
  78.     {   sprintf(path,"%s/%s", genepath, genefile);
  79.         info = fopen(path,"r");
  80.         if(info == NULL)
  81.         {   wierror(2,45,"file not found");
  82.             return FALSE;
  83.         }
  84.         fclose(info);
  85.         return TRUE;
  86.     }
  87.     if(tp->cur_fld == 2)
  88.     {   sprintf(path,"%s/%s", genepath, genefile);
  89.         if (!(info = fopen(path, "rb")))
  90.         {   wierror(2,45,"file not found");
  91.             return FALSE;
  92.         }
  93.         head = read_head(info);
  94.         indx = read_indx(info, &head);
  95.         fclose(info);
  96.         if (find_gen(indx, genotype, head.n) == head.n)
  97.         {   wierror(2,45,"genotype not contained in file");
  98.             farfree(indx);
  99.             return FALSE;
  100.         }
  101.         farfree(indx);
  102.     }
  103.     return TRUE;
  104. }
  105.  
  106. void templat(int  track)
  107. {   int  c = 0, i, gsize, start = 0, site = 0, tail_size, array_size = 10;
  108.     int  otnum = 6;
  109.     FpInst  genome;
  110.     FILE  *info;
  111.     char  data[85], error[110];
  112.  
  113.     templ = (ArgInstDef  *) calloc(otnum, sizeof(ArgInstDef));
  114.     Tnum = 0;
  115.     sprintf(data,"%s/opcode.map", genepath);
  116.     GetAMap(data);
  117. /*
  118.     info = fopen(data,"r");
  119.     if(info == NULL)
  120.         wierror(2,45,"opcode.map not found");
  121.     fgets(data, 84, info);
  122.     while (strlen(data) > 3)
  123.     {   if (!GetAMap(data))
  124.         {   sprintf(error, "bad IMapFile line: %s", data);
  125.             wierror(2,10,error);
  126.         }
  127.         if (fgets(data, 84, info) == NULL)
  128.             break ;
  129.     }
  130.     fclose(info);
  131.     qsort(aid,INSTNUM,sizeof(ArgInstDef),aid_compare);
  132. */
  133.     for (i = 0; i < INSTNUM; i++)
  134.     {   if (   !strcmp(aid[i].mn, "jmp")  || !strcmp(aid[i].mn, "jmpb")
  135.             || !strcmp(aid[i].mn, "call") || !strcmp(aid[i].mn, "adr")
  136.             || !strcmp(aid[i].mn, "adrb") || !strcmp(aid[i].mn, "adrf"))
  137.         {   Tnum++;
  138.             if (Tnum > otnum)
  139.             {   templ = (ArgInstDef  *) realloc(templ,
  140.                     Tnum * sizeof(ArgInstDef));
  141.                 otnum = Tnum;
  142.             } 
  143.             templ[Tnum - 1] = aid[i];
  144.         }
  145.         if (!strcmp(aid[i].mn, "nop_0"))
  146.             Nop0 = i;
  147.         if (!strcmp(aid[i].mn, "nop_1"))
  148.             Nop1 = i;
  149.     }
  150.  
  151.     t = (struct use_template  *) calloc(10, sizeof(struct use_template));
  152.     sscanf(genefile, "%d", &gsize);
  153.     tail_size = gsize;
  154.     genome = get_gentype(genepath, genefile, genotype);
  155.     while(find_next_use_template(genome, start, tail_size, &site, track))
  156.     {   if(c >= array_size)
  157.         {   array_size += 10;
  158.             t = (struct use_template  *)
  159.                 realloc(t, array_size * sizeof(struct use_template));
  160.         }
  161.         t[c].locus = site;
  162. #if PLOIDY == 1
  163.         inst_name((int)(genome + site)->inst, t[c].inst);
  164. #else /* PLOIDY > 1 */
  165.         inst_name((int)(genome + site)[track]->inst, t[c].inst);
  166. #endif /* PLOIDY == 1 */
  167.         t[c].size =
  168.             get_template_size(genome + site + 1, gsize - site - 1, track);
  169.         for(i = 1; i <= t[c].size; i++)
  170. #if PLOIDY == 1
  171.             t[c].template[i - 1] = inst_letter((genome+site+i)->inst);
  172. #else /* PLOIDY > 1 */
  173.             t[c].template[i - 1] = inst_letter((genome+site+i)[track]->inst);
  174. #endif /* PLOIDY == 1 */
  175.         t[c].template[t[c].size] = 0;
  176.         start = site + t[c].size;
  177.         tail_size = gsize - start;
  178.         c++;
  179.     }
  180.     logical(c);
  181.     free(t);
  182.     free(genome);
  183. }
  184.  
  185. void logical(int  c)
  186. {   HWND      winl, whins;
  187.     int       i, p = c - 1;
  188.  
  189.     winl = vcreat(c,40,NORML,YES);
  190.     if(c > 21) { vwind(winl,21,40,0,0); p = 20; }
  191.     else vwind(winl,c,40,0,0);
  192.     vlocate(winl,2,8);
  193.     vframe(winl,NORML,FRSINGLE);
  194.     for(i = 0; i < c; i++)
  195.         vatputf(winl, i, 2, "locus: %6d, %-6.6s %-15s",
  196.             t[i].locus, t[i].inst, t[i].template); 
  197.     visible(winl,YES,YES);
  198.     whins = wiinv(23,31, "Esc to continue");
  199.     scroll(p,winl);
  200.     vdelete(whins,NONE);
  201.     vdelete(winl,NONE); 
  202. }
  203.