home *** CD-ROM | disk | FTP | other *** search
- /* genio.c 28-10-91 genebank input/output routines */
- /** Tierra Simulator V3.0: Copyright (c) 1991 Thomas S. Ray **/
-
- #include "license.h"
-
- #ifndef lint
- static char sccsid[] = "@(#)genio.c 2.9 10/8/91";
- #endif
-
- #include "tierra.h"
- #include "extern.h"
- #include <sys/types.h>
- #include <sys/stat.h>
- #include <errno.h>
-
- #define WritEcoS(bits) WritEcoF(bits, stdout)
-
- /*
- * open_ar - open a genebank archive
- *
- * file - the filename;
- * size - the creature size
- * format - a byte, usually the instruction set number
- * mode - 0 if the file exists its contents should be preserved,
- * 1+ if the file should be created (or truncated). mode > 1
- * is taken as the number of index entries to allocate
- * (will be rounded to the next highest # such that
- * index + header is a multiple of 1K)
- *
- * returns a pointer to a file opened for update, or NULL if unsuccessful.
- * open_ar fails if size or format are incompatible with the archive.
- */
-
- FILE *open_ar(file, size, format, mode)
- I8s *file, format;
- I16s size, mode;
- {
- FILE *fp;
- head_t head;
- struct stat *buf = (struct stat *) thcalloc(1, sizeof(struct stat));
-
- if (mode || stat(file, buf) == -1) {
- if (fp = fopen(file, "w+b")) {
- strcpy(head.magic, "tie");
- head.magic[3] = '0' + format;
- head.size = size;
- head.n = 0;
- head.n_alloc = (((int) ((sizeof(head_t) + mode * sizeof(indx_t)) /
- 1024.0) + 1) * 1024 - sizeof head) / sizeof(indx_t);
- head.g_off = sizeof(head_t) + head.n_alloc * sizeof(indx_t);
- write_head(fp, &head);
- }
- }
- else if (fp = fopen(file, "r+b")) {
- head = read_head(fp);
- if (head.size != size || head.magic[3] != format + '0' ||
- strncmp(head.magic, "tie", 3)) {
- fclose(fp);
- fp = NULL;
- errno = EINVAL;
- }
- }
- return fp;
- }
-
- /*
- * read_head - read header from a genebank archive
- */
-
- head_t read_head(fp)
- FILE *fp;
- {
- head_t t;
-
- if (!fseek(fp, 0, 0)) fread(&t, sizeof(head_t), 1, fp);
- else perror("read_head");
- return t;
- }
-
- /*
- * write_head - write header to a genebank archive
- */
-
- void write_head(fp, head)
- FILE *fp;
- head_t *head;
- {
- if (!fseek(fp, 0, 0)) fwrite(head, sizeof(head_t), 1, fp);
- else perror("write_head");
- }
-
- /*
- * read_indx - read the index from a genebank archive
- */
-
- indx_t *read_indx(fp, head)
- FILE *fp;
- head_t *head;
- {
- indx_t *t = 0;
-
- if (!fseek(fp, sizeof(head_t), 0)) {
- t = (indx_t *) thcalloc(head->n_alloc, sizeof(indx_t));
- fread(t, sizeof(indx_t), head->n, fp);
- }
- else perror("read_indx");
- return t;
- }
-
- /*
- * write_indx - write the index to a genebank archive
- */
-
- void write_indx(fp, head, indx)
- FILE *fp;
- head_t *head;
- indx_t *indx;
- {
- if (!fseek(fp, sizeof(head_t), 0)) {
- fwrite(indx, sizeof(indx_t), head->n_alloc, fp);
- }
- else perror("write_indx");
- }
-
- /*
- * find_gen - find the index of a genome in an archive by its 3 letter name
- *
- * will return n (number of genomes) if not found, otherwise the position
- * (0 - n-1) in archive
- */
-
- I32s find_gen(indx, gen, n)
- indx_t indx[];
- I8s *gen;
- I32s n;
- {
- I32s i;
-
- for (i=0; i<n; i++) if (!strncmp(indx[i].gen, gen, 3)) break;
- return i;
- }
-
- /*
- * get_gen - read a genome from genebank archive and return a pointer
- * to a struct g_list containing all saved info.
- *
- * fp - pointer to open archive file
- * head - archive header
- * indxn - index entry of desired genome
- * n - position of desired genome in archive
- *
- * reads the genome and reformats its other args into the form used
- * internally by tierra. the genotype must be in archive. n can be
- * determined by find_gen(). currently no error checking
- */
-
- Pgl get_gen(fp, head, indxn, n)
- FILE *fp;
- indx_t *indxn;
- head_t *head;
- I32s n;
- {
- Pgl t = (Pgl) thcalloc(1, sizeof(struct g_list));
-
- fseek(fp, head->g_off +
- (n * head->size * (sizeof(Instruction) + sizeof(GenBits))), 0);
- t->genome = (HpInst) thcalloc(head->size, sizeof(Instruction));
- t->gbits = (HpGenB) thcalloc(head->size, sizeof(GenBits));
- fread(t->genome, head->size * sizeof(Instruction), 1, fp);
- fread(t->gbits, head->size * sizeof(GenBits), 1, fp);
- t->gen.size = head->size;
- strncpy(t->gen.label, indxn->gen, 3);
- t->parent.size = indxn->psize;
- strncpy(t->parent.label, indxn->pgen, 3);
- t->bits = indxn->bits;
- t->d1 = indxn->d1;
- t->d2 = indxn->d2;
- t->originI = indxn->originI; t->originC = indxn->originC;
- t->MaxPropPop = (float) indxn->mpp / 10000.;
- t->MaxPropInst = (float) indxn->mpi / 10000.;
- t->ploidy = (indxn->pt & 0360) >> 4;
- t->track = indxn->pt & 017;
- return t;
- }
-
- /*
- * add_gen - replace or add a genotype to end of genebank archive
- *
- * fp - pointer to open archive file
- * head - header of archive
- * indx - index of archive
- * gen - genotype to be added
- *
- * reformats the genotype and replaces it in the archive, or adds it to
- * the end if not found. args head & indx are modified by this fn.
- * returns 0 on add, and 1 on replace.
- */
-
- I32s add_gen(fp, head, indx, gen)
- FILE *fp;
- head_t *head;
- indx_t **indx;
- Pgl gen;
- {
- Instruction *buf;
- int n, s;
-
- n = find_gen(*indx, gen->gen.label, head->n);
- if (n == head->n && head->n == head->n_alloc) {
- head->n_alloc += 1024 / sizeof(indx_t);
- *indx = (indx_t *) threalloc(*indx, head->n_alloc * sizeof(indx_t));
- fseek(fp, head->g_off, 0);
- buf = (Instruction *) thcalloc(s = head->size * head->n *
- sizeof(Instruction), 1);
- fread(buf, s, 1, fp);
- fseek(fp, head->g_off=sizeof(head_t)+head->n_alloc*sizeof(indx_t), 0);
- fwrite(buf, s, 1, fp);
- thfree(buf);
- }
- fseek(fp, head->g_off +
- (n * head->size * (sizeof(Instruction) + sizeof(GenBits))), 0);
- fwrite(gen->genome, head->size * sizeof(Instruction), 1, fp);
- fwrite(gen->gbits, head->size * sizeof(GenBits), 1, fp);
- strncpy((*indx)[n].gen, gen->gen.label, 3);
- (*indx)[n].psize = gen->parent.size;
- strncpy((*indx)[n].pgen, gen->parent.label, 3);
- (*indx)[n].bits = gen->bits;
- (*indx)[n].d1 = gen->d1;
- (*indx)[n].d2 = gen->d2;
- (*indx)[n].originI = gen->originI;
- (*indx)[n].originC = gen->originC;
- (*indx)[n].mpp = (short) (gen->MaxPropPop * 10000);
- (*indx)[n].mpi = (short) (gen->MaxPropInst * 10000);
- (*indx)[n].pt = (gen->ploidy << 4) + gen->track;
- head->n += n = n == head->n;
- write_head(fp, head);
- write_indx(fp, head, *indx);
- return !n;
- }
-
-
- /***** todo:
- combine & fix getasc?gen, writasc?file
- ?? replace getgen?format, writ?genfile w/ getgen, addgen in tierra
- *****/
-
- I16s GetAscGen(g, ifile)
- Pgl g;
- I8s ifile[];
- {
- I8s bit[4], chm[4], buf[81], *data, inst[9], *inst2;
- I16s t1, BufSiz = 512, ComSiz = 0, format;
- I32u sl = 0, sln;
- I32s j, k, p, a = 0, b = 0, sc = 1;
- I8u ti, *s, *t;
- FILE *inf;
-
- inf = fopen(ifile,"r");
- if(inf == NULL)
- { sprintf(mes[0],"GetAscGen: file %s not opened, exiting");
- FEMessage(1);
- while(hangup) ;
- exit(0);
- }
- data = (I8s *) thcalloc(85, sizeof(I8s));
- g->ploidy = (I8s) 1; /* default ploidy */
- fgets(data,84,inf); /* blank line */
- while(1)
- { fgets(data,84,inf);
- if(strlen(data) < 3) break; /* get a blank line and break */
- sscanf(data,"%s", buf);
- if(!strcmp(buf,"format:"))
- { sscanf(data,"%*s%hd%*s%lu", &format, &g->bits); continue; }
- if(!strcmp(buf,"genotype:"))
- { sscanf(data,"%*s%ld%s%*s%*s%ld%s", &g->gen.size,
- g->gen.label, &g->parent.size, g->parent.label);
- continue;
- }
- if(!strcmp(buf,"1st_daughter:"))
- { sscanf(data,"%*s%*s%ld%*s%ld%*s%ld%*s%hd",
- &g->d1.flags, &g->d1.inst, &g->d1.mov_daught, &t1);
- g->d1.BreedTrue = t1;
- continue;
- }
- if(!strcmp(buf,"2nd_daughter:"))
- { sscanf(data,"%*s%*s%ld%*s%ld%*s%ld%*s%hd",
- &g->d2.flags, &g->d2.inst, &g->d2.mov_daught, &t1);
- g->d2.BreedTrue = t1;
- continue;
- }
- if(!strcmp(buf,"InstExe.m:"))
- { sscanf(data,"%*s%ld%*s%ld%*s%ld",
- &g->originI.m, &g->originI.i, &g->originC);
- continue;
- }
- if(!strcmp(buf,"MaxPropPop:"))
- { sscanf(data,"%*s%f%*s%f", &g->MaxPropPop, &g->MaxPropInst);
- continue;
- }
- if(!strcmp(buf,"ploidy:"))
- { sscanf(data,"%*s%ld%*s%ld", &j, &k);
- g->ploidy = (I8s) j; g->track = (I8s) k;
- continue;
- }
- if(!strcmp(buf,"comments:"))
- {
- #ifdef COMMENTS
- g->comments = (I8s Fp) thcalloc(BufSiz, sizeof(I8s));
- ComSiz = sl = strlen(data + 9);
- while(ComSiz > BufSiz) {
- BufSiz += 512;
- g->comments = (I8s Fp) threalloc(g->comments, BufSiz);
- }
- strcpy(g->comments,data + 9);
- #endif
- /* TOM UFFNER: sl has not been initialized! */
- while(sl > 1) {
- fgets(data,84,inf);
- sln = strlen(data);
- #ifdef COMMENTS
- while(ComSiz + sln > BufSiz) {
- BufSiz += 512;
- g->comments = (I8s Fp) threalloc(g->comments, BufSiz);
- }
- strcpy(g->comments + ComSiz, data);
- ComSiz += sln;
- #endif
- sl = sln;
- }
- #ifdef COMMENTS
- sl = strlen(g->comments);
- g->comments = (I8s Fp) threalloc(g->comments, sl + 1);
- #endif
- break;
- }
- }
- g->genome = (HpInst) thcalloc(g->gen.size, sizeof(Instruction));
- g->gbits = (HpGenB) thcalloc(g->gen.size, sizeof(GenBits));
- for(p = 0; p < PLOIDY; p++)
- { if (p) fgets(data,84,inf);
- fgets(data,84,inf); fgets(data,84,inf);
- for(j = 0; j < g->gen.size; j++)
- { fgets(data,84,inf); sl = sscanf(data,"%s%*s%s%s", inst, chm, bit);
- if(sl > 1 && strlen(chm) == 3)
- { g->genome[j][p].read = chm[2] - '0';
- g->genome[j][p].write = chm[1] - '0';
- g->genome[j][p].exec = chm[0] - '0';
- }
- if(sl > 2 && strlen(bit) == 3)
- { if(bit[0] - '0')
- g->gbits[j][p] |= (I8s) 1;
- if(bit[1] - '0')
- g->gbits[j][p] |= (I8s) (1 << 1);
- if(bit[2] - '0')
- g->gbits[j][p] |= (I8s) (1 << 2);
- }
- for(k = 0; k < INSTNUM; k++)
- { if(!strcmp(inst,aid[k].mn))
- { ti = aid[k].op;
- break;
- }
- }
- if(k == INSTNUM)
- { sprintf(mes[0],"mnemonic %s not recognized", inst);
- FEMessage(1);
- ti = 0;
- }
- g->genome[j][p].inst = ti;
- }
- }
- fclose(inf);
- #ifdef IBM3090
- Ebcdic2Ascii(g->gen.label); Ebcdic2Ascii(g->parent.label);
- if(g->comments) Ebcdic2Ascii(g->comments);
- #endif
- return 1;
- }
-
- void WritAscFile(g, file)
- Pgl g;
- I8s *file;
- {
- I8s bit[4], chm[4];
- I16s t1;
- I16u di, t, j;
- I8s format = INST;
- long int tp;
- FILE *fp;
- #ifdef IBM3090
- I8s lbl[4], plbl[4], *comnts;
- #endif
-
- if (!strcmp(file, "-")) fp = stdout;
- else if (!(fp = fopen(file, "w")))
- { perror("WritAscFile");
- exit(1);
- }
- fprintf(fp, "\nformat: %hd bits: %lu ", format, g->bits);
- WritEcoF(g->bits, fp);
- #ifdef IBM3090
- strcpy(lbl,g->gen.label); strcpy(plbl,g->parent.label);
- Ascii2Ebcdic(lbl); Ascii2Ebcdic(plbl);
- fprintf(fp, "genotype: %04ld%s parent genotype: %04ld%s\n",
- g->gen.size, lbl, g->parent.size, plbl);
- #else
- fprintf(fp, "genotype: %04ld%s parent genotype: %04ld%s\n",
- g->gen.size, g->gen.label, g->parent.size, g->parent.label);
- #endif
- t1 = g->d1.BreedTrue;
- fprintf(fp, "1st_daughter: flags: %ld inst: %ld mov_daught: %ld \
- breed_true: %hd\n", g->d1.flags, g->d1.inst, g->d1.mov_daught, t1);
- t1 = g->d2.BreedTrue;
- fprintf(fp, "2nd_daughter: flags: %ld inst: %ld mov_daught: %ld \
- breed_true: %hd\n", g->d2.flags, g->d2.inst, g->d2.mov_daught, t1);
- tp = g->originC;
- fprintf(fp, "InstExe.m: %ld InstExe.i: %ld origin: %ld %s",
- g->originI.m, g->originI.i, g->originC, ctime(&tp));
- fprintf(fp, "MaxPropPop: %g MaxPropInst: %g\n", g->MaxPropPop,
- g->MaxPropInst);
- fprintf(fp, "ploidy: %ld track: %ld\n", (I32s) g->ploidy,
- (I32s) g->track);
- #ifdef COMMENTS
- if(g->comments) {
- #ifdef IBM3090
- t = strlen(g->comments);
- comnts = (I8s *) thcalloc(t + 1, sizeof(I8s));
- strcpy(comnts,g->comments);
- Ascii2Ebcdic(comnts);
- fprintf(fp, "comments:%s", comnts);
- thfree(comnts);
- #else
- fprintf(fp, "comments:%s", g->comments);
- #endif
- }
- else
- #endif
- fprintf(fp, "\n");
- chm[3] = bit[3] = 0;
- for (j = 0; j < PLOIDY; j++)
- { if(j) fprintf(fp,"\n");
- fprintf(fp, "track %ld: prot\n xwr\n", j);
- for (t = 0; t < g->gen.size; t++)
- { di = g->genome[t][j].inst;
- bit[0] = IsBit(g->gbits[t][j],0) ? '1' : '0';
- bit[1] = IsBit(g->gbits[t][j],1) ? '1' : '0';
- bit[2] = IsBit(g->gbits[t][j],2) ? '1' : '0';
- chm[0] = '0' + g->genome[t][j].exec;
- chm[1] = '0' + g->genome[t][j].write;
- chm[2] = '0' + g->genome[t][j].read;
- fprintf(fp,"%-8s; %s %s %02x %3u\n", aid[di].mn, chm, bit, di, t);
- }
- }
- }
-
- /*
- * WritGenFile - write old style genebank file
- *
- * replaces Writ1GenFile and Writ2GenFile...
- * warning: this function is obsolescent. use only to verify that the new
- * archive format works correctly.
- */
-
- void WritGenFile(g, file)
- Pgl g;
- I8s file[];
- {
- FILE *ouf;
- I16s prop;
- I8s format = INST;
-
- ouf = fopen(file,"wb");
- if(ouf == NULL)
- { sprintf(mes[0],"WritGenFile: file %s not opened, exiting", file);
- FEMessage(1);
- while(hangup) ;
- exit(0);
- }
- fwrite(&format, sizeof(I8s), 1, ouf);
- fwrite(&g->bits, sizeof(I32u), 1, ouf);
- fwrite(&g->gen, sizeof(struct genotype), 1, ouf);
- fwrite(&g->parent, sizeof(struct genotype), 1, ouf);
- fwrite(&g->d1, sizeof(struct metabolism), 1, ouf);
- fwrite(&g->d2, sizeof(struct metabolism), 1, ouf);
- fwrite(&g->originI, sizeof(struct event), 1, ouf);
- fwrite(&g->originC, sizeof(I32s), 1, ouf);
- prop = (I16s) 10000 * g->MaxPropPop;
- fwrite(&prop, sizeof(I16s), 1, ouf);
- prop = (I16s) 10000 * g->MaxPropInst;
- fwrite(&prop, sizeof(I16s), 1, ouf);
- #ifdef COMMENTS
- if (g->comments == NULL)
- #endif
- fwrite("\012\0", sizeof(I8s), 2, ouf); /* "\n", ebcdic compatible */
- #ifdef COMMENTS
- else {
- s = strlen(g->comments) + 1;
- fwrite(g->comments, sizeof(I8s), s, ouf);
- }
- #endif
- #if INST > 1
- fwrite(&g->ploidy, sizeof(I8s), 1, ouf);
- fwrite(&g->track, sizeof(I8s), 1, ouf);
- #endif
- fwrite(g->genome, sizeof(Instruction), g->gen.size, ouf);
- fwrite(g->gbits, sizeof(GenBits), g->gen.size, ouf);
- fclose(ouf);
- }
-
- /*
- * GetGenFormat - read old style genebank file
- *
- * replaces GetGen1Format and GetGen2Format...
- * warning: this function is obsolescent. use only to verify that the new
- * archive format works correctly.
- */
-
- I16s GetGenFormat(g,file)
- Pgl g;
- I8s file[];
- {
- FILE *inf;
- I8s c = 1, format;
- I16s prop;
- I32s t = 0, bufsiz = 512;
-
- inf = fopen(file,"rb");
- fread(&format, sizeof(I8s), 1, inf);
- fread(&g->bits, sizeof(I32u), 1, inf);
- fread(&g->gen, sizeof(struct genotype), 1, inf);
- fread(&g->parent, sizeof(struct genotype), 1, inf);
- fread(&g->d1, sizeof(struct metabolism), 1, inf);
- fread(&g->d2, sizeof(struct metabolism), 1, inf);
- fread(&g->originI, sizeof(struct event), 1, inf);
- fread(&g->originC, sizeof(I32s), 1, inf);
- fread(&prop, sizeof(I16s), 1, inf);
- g->MaxPropPop = (float) prop / 10000.;
- fread(&prop, sizeof(I16s), 1, inf);
- g->MaxPropInst = (float) prop / 10000.;
- g->comments = (I8s *) thcalloc(bufsiz,sizeof(I8s));
- do {
- c = getc(inf);
- g->comments[t++] = c;
- if (t >= bufsiz) {
- bufsiz += 512;
- g->comments = (I8s *) threalloc(g->comments,bufsiz);
- }
- }
- while(c);
- if(g->comments[0] == 10 && g->comments[1] == 0) {
- thfree(g->comments);
- g->comments = NULL;
- }
- else g->comments = (I8s *) threalloc(g->comments,t);
- #ifndef COMMENTS
- thfree(g->comments);
- g->comments = NULL;
- #endif
- #if INST > 1
- fread(&g->ploidy, sizeof(I8s), 1, inf);
- fread(&g->track, sizeof(I8s), 1, inf);
- #endif
- g->genome = (HpInst) thcalloc(g->gen.size,sizeof(Instruction));
- fread(g->genome, sizeof(Instruction), g->gen.size, inf);
- fclose(inf);
- return (I16s) format;
- }
-
- #ifdef IBM3090
- static unsigned char a2e[] = {
- 0000,0001,0002,0003,0067,0055,0056,0057,0026,0005,0045,0013,0014,0015,0016,
- 0017,0020,0021,0022,0023,0074,0075,0062,0046,0030,0031,0077,0047,0034,0035,
- 0036,0037,0100,0117,0177,0173,0133,0154,0120,0175,0115,0135,0134,0116,0153,
- 0140,0113,0141,0360,0361,0362,0363,0364,0365,0366,0367,0370,0371,0172,0136,
- 0114,0176,0156,0157,0174,0301,0302,0303,0304,0305,0306,0307,0310,0311,0321,
- 0322,0323,0324,0325,0326,0327,0330,0331,0342,0343,0344,0345,0346,0347,0350,
- 0351,0112,0340,0132,0137,0155,0171,0201,0202,0203,0204,0205,0206,0207,0210,
- 0211,0221,0222,0223,0224,0225,0226,0227,0230,0231,0242,0243,0244,0245,0246,
- 0247,0250,0251,0300,0152,0320,0241,0007,0040,0041,0042,0043,0044,0025,0006,
- 0027,0050,0051,0052,0053,0054,0011,0012,0033,0060,0061,0032,0063,0064,0065,
- 0066,0010,0070,0071,0072,0073,0004,0024,0076,0341,0101,0102,0103,0104,0105,
- 0106,0107,0110,0111,0121,0122,0123,0124,0125,0126,0127,0130,0131,0142,0143,
- 0144,0145,0146,0147,0150,0151,0160,0161,0162,0163,0164,0165,0166,0167,0170,
- 0200,0212,0213,0214,0215,0216,0217,0220,0232,0233,0234,0235,0236,0237,0240,
- 0252,0253,0254,0255,0256,0257,0260,0261,0262,0263,0264,0265,0266,0267,0270,
- 0271,0272,0273,0274,0275,0276,0277,0312,0313,0314,0315,0316,0317,0332,0333,
- 0334,0335,0336,0337,0352,0353,0354,0355,0356,0357,0372,0373,0374,0375,0376,
- 0377 };
-
- static unsigned char e2a[] = {
- 0000,0001,0002,0003,0234,0011,0206,0177,0227,0215,0216,0013,0014,0015,0016,
- 0017,0020,0021,0022,0023,0235,0205,0010,0207,0030,0031,0222,0217,0034,0035,
- 0036,0037,0200,0201,0202,0203,0204,0012,0027,0033,0210,0211,0212,0213,0214,
- 0005,0006,0007,0220,0221,0026,0223,0224,0225,0226,0004,0230,0231,0232,0233,
- 0024,0025,0236,0032,0040,0240,0241,0242,0243,0244,0245,0246,0247,0250,0133,
- 0056,0074,0050,0053,0041,0046,0251,0252,0253,0254,0255,0256,0257,0260,0261,
- 0135,0044,0052,0051,0073,0136,0055,0057,0262,0263,0264,0265,0266,0267,0270,
- 0271,0174,0054,0045,0137,0076,0077,0272,0273,0274,0275,0276,0277,0300,0301,
- 0302,0140,0072,0043,0100,0047,0075,0042,0303,0141,0142,0143,0144,0145,0146,
- 0147,0150,0151,0304,0305,0306,0307,0310,0311,0312,0152,0153,0154,0155,0156,
- 0157,0160,0161,0162,0313,0314,0315,0316,0317,0320,0321,0176,0163,0164,0165,
- 0166,0167,0170,0171,0172,0322,0323,0324,0325,0326,0327,0330,0331,0332,0333,
- 0334,0335,0336,0337,0340,0341,0342,0343,0344,0345,0346,0347,0173,0101,0102,
- 0103,0104,0105,0106,0107,0110,0111,0350,0351,0352,0353,0354,0355,0175,0112,
- 0113,0114,0115,0116,0117,0120,0121,0122,0356,0357,0360,0361,0362,0363,0134,
- 0237,0123,0124,0125,0126,0127,0130,0131,0132,0364,0365,0366,0367,0370,0371,
- 0060,0061,0062,0063,0064,0065,0066,0067,0070,0071,0372,0373,0374,0375,0376,
- 0377 };
-
- Ascii2Ebcdic(s) char *s; { while (*s = a2e[*s]) s++; }
- Ebcdic2Ascii(s) char *s; { while (*s = e2a[*s]) s++; }
- #endif
-
- void WritEcoF(bits, ouf)
- I32u bits;
- FILE *ouf;
- {
- static char s[6], *t[] = { "EX", " TC", " TP", " MF", " MT", " MB" };
- int i, j;
-
- for (i=0,j=0; i<6; i++,j=0) {
- if (IsBit(bits, 5 * i + 2)) s[j++] = 's';
- if (IsBit(bits, 5 * i + 3)) s[j++] = 'd';
- if (IsBit(bits, 5 * i + 4)) s[j++] = 'o';
- if (IsBit(bits, 5 * i + 5)) s[j++] = 'f';
- if (IsBit(bits, 5 * i + 6)) s[j++] = 'h';
- s[j] = 0;
- fprintf(ouf,"%s%s", t[i], s);
- }
- fprintf(ouf,"\n");
- }
-
- void SetBit(seed, bit, value)
- I32u *seed, bit, value;
- { if(value)
- (*seed) |= (1 << bit);
- else
- (*seed) &= (~(1 << bit));
- }
-