home *** CD-ROM | disk | FTP | other *** search
- #include "header.h"
- #if PC
- #include <bios.h>
- #endif
- #include "file.h"
-
- /* functions included:
- getusrstrlist
- getusrcells
- getusrdays
- getfileip
- parsecellstr
- getcellstg
- */
-
- #if PC
- /********************************/
- /* function: getusrstrlist */
- /********************************/
- /* gets a list user-input strings: PC version
-
- return 0 if string input
- return 100+k if F-k pressed */
- getusrstrlist (strings, pnum)
- char strings[][MAXIPLEN]; /* list of strings if no F key */
- int *pnum; /* num of strings in list */
- {
- int key; /* 32-bit val of key pressed */
- int keylo; /* key bits 0-7 */
- int keyhi; /* key bits 8-15 */
- int i, j, k, any, go, x, y, laststr;
- int splast; /* flag: =1 if last ch=whitesp */
- int xlast; /* last x pos of old line */
- int newln; /* = # of new lines needed */
- char input[2*MAXLEN]; /* for reading i/p linearly */
-
- i = 0;
- *pnum = 0;
- y = wherey();
- splast = 0;
- xlast = 0;
- newln = 0;
- go = 1;
- while (go) {
- while (bioskey(1)==0); /* sit & spin */
- x = wherex();
- key = bioskey(0);
- keylo = key & 0x000000FF;
- keyhi = (key & 0x0000FF00) >> 8; /* right shift 8 bits */
- switch (keylo) {
- case 0: /* Fkey? */
- switch (keyhi) {
- case 59: /* F1 */
- return(101);
- case 60: /* F2 */
- return(102);
- case 61: /* F3 */
- return(103);
- case 62: /* F4 */
- return(104);
- case 63: /* F5 */
- return(105);
- case 64: /* F6 */
- return(106);
- case 65: /* F7 */
- return(107);
- case 66: /* F8 */
- return(108);
- case 67: /* F9 */
- return(109);
- case 68: /* F10 */
- return(110);
- default: /* undefined special key */
- strings[0][0] = '\0';
- return(200);
- } /* switch keyhi */
- case 8: /* backspace */
- if (i > 0) {
- i--; /* back up over flat array */
- splast = 0;
- if (x==5) { /* only way for x==5 is to be on a new line */
- gotoxy(5, y);
- clreol1(2);
- newln--; /* back up a line */
- x = xlast;
- y--;
- gotoxy(x, y);
- } else {
- if (!newln && (x <= 21)) {
- /* on orig line, don't back up over request-for-i/p msg */
- gotoxy(21, y);
- } else {
- gotoxy(x-1, y);
- clreol1(2);
- gotoxy(x-1, y);
- }
- }
- }
- break;
- case 32: /* space */
- case 9: /* tab */
- /* whitespace: if first, print a space; else ignore it */
- splast = 1; /* flag: =1: last ch was whitesp */
- cprintf(" ");
- input[i++] = ' ';
- break;
- case 10:
- case 13: /* CR/LF = return */
- input[i] = '\0';
- laststr = i;
- go = 0;
- gotoxy(x, y);
- cprintf("%c", keylo);
- input[i++] = keylo;
- break;
- default: /* other ASCII char */
- if (splast && (x >= 65)) {
- /* end of substring, and near eol: good time to start new line */
- xlast = x-1;
- y++;
- newln++; /* incr # lines used */
- x = 5;
- }
- splast = 0;
- gotoxy(x, y);
- cprintf("%c", keylo);
- /* first build flat array of input, so can ^H over it */
- input[i++] = keylo;
- } /* switch keylo */
- } /* while go */
-
- /* now build array of strings from input */
- i = j = 0;
- any = 0;
- for ( k=0; k<=laststr; k++ ) {
- if (whitespq(input[k])) { /* whitespace=space/tab/CR */
- if (any && j) {
- strings[i][j] = '\0'; /* end this cellname str */
- (*pnum)++;
- i++; /* start next cellname str */
- j = 0;
- }
- } else { /* ! whitespace */
- any = 1;
- strings[i][j++] = input[k]; /* build new cellname */
- }
- } /* for i */
- return(0);
- } /* getusrstrlist */
-
- #else
-
- /********************************/
- /* function: getusrstrlist */
- /********************************/
- /* gets a list user-input strings
- pnum = number of substrings within the "strings" string */
- getusrstrlist (strings, pnum)
- char strings[][MAXIPLEN];
- int *pnum;
- {
- int i, j, any, go;
- char c;
-
- i = 0;
- j = 0;
- any = 0;
- *pnum = 0;
- go = 1;
- while (go && (c=getc(stdin)) != '\n') {
- /* build array of cellnames */
- if (whitespq(c)) { /* whitespace = space or tab */
- if (any) {
- strings[i][j] = '\0'; /* end this cellname str */
- (*pnum)++; /* incr # trials */
- i++; /* start next cellname str */
- }
- j = 0;
- /* skip whitespace */
- while (whitespq(c=getc(stdin)));
-
- if (c != '\n') { /* if more besides whitesp... */
- any = 1;
- strings[i][j++] = c; /* build new cellname str */
- } else { /* last chars were just whitesp */
- go = 0;
- (*pnum)--;
- }
- } else { /* ! whitespq */
- any = 1;
- strings[i][j++] = c; /* build this cellname str */
- } /* if */
- } /* while */
-
- (*pnum)++;
- strings[i][j] = '\0'; /* end the last cellname str */
- } /* getusrstrlist */
- #endif
-
- /********************************/
- /* function: getusrcells */
- /********************************/
- /* gets list of initial cell names interactively
-
- if PC: returns 0 if cellstr ok
- 100+k if special key pressed (e.g., F-key) */
- getusrcells (cellstrs, ptrials)
- char cellstrs[][MAXIPLEN];
- int *ptrials;
- {
- int i, stop, ok;
- int stgdaton; /* =1 if stg dat on screen */
- int seqdaton; /* =1 if seq dat on screen */
- int dum1, dum2, dum4; /* dummy vars for parsecellstr */
- char dum3[MAXLEN]; /* dummy str for parsecellstr */
- /* dummy array of strings so cellstrs isn't wiped out if user wants
- to use same cells over again */
- char dummy[MAXIP][MAXIPLEN];
- #if PC
- int any, val;
- #endif
-
- if (strcmp(Animal, "None")==0) {
- #if PC
- topline(" Cell Input Menu ");
- clrscr1(1);
- gotoxy(1, 5);
- cprintf("%sNo animal has been selected yet.", tab);
- gotoxy(1, 6);
- cprintf("%sPlease use the Animal Menu to select an animal.", tab);
- if (HARDCOPY) {
- fprintf(stdprn, "\n\tNo animal has been selected yet.\n");
- fprintf(stdprn, "\tPlease use the Animal Menu to select an animal.\n");
- }
- hitreturn(1);
- #else
- printf("\n\tNo animal has been selected yet.\n");
- printf("\tPlease use the Animal Menu to select an animal.\n");
- #endif
- if (FILEq && FILECOPY) {
- fprintf(fpout, "\n\tNo animal has been selected yet.\n");
- fprintf(fpout, "\tPlease use the Animal Menu to select an animal.\n");
- }
- return(103); /* goto animalmenu */
- }
-
- ok = 0;
- cellmenu();
- #if PC
- stgdaton = 0;
- seqdaton = 0;
- #endif
- while (! ok) {
- #if PC
- clrscr1(2);
- cprintf("%sInitial cell name, or menu choice (F for menu):", tab);
- gotoxy(1, 2);
- highvideo();
- cprintf("%s%c%c%c ", tab2, HBAR, HBAR, RTRI);
- normvideo();
- val = getusrstrlist(dummy, &dum4);
- #if (DEBUG > 4)
- #if PC
- clrscr1(1);
- gotoxy(1, 5);
- cprintf("%sgetusrcells: val=%d dummy=<%s>", tab, val, dummy[0]);
- hitreturn(1);
- #else
- printf("\tgetusrcells: val=%d dummy=<%s>\n", val, dummy[0]);
- #endif
- #endif
-
- if (HARDCOPY) {
- fprintf(stdprn, "\n\tInitial cell name, or menu choice ");
- fprintf(stdprn, "(F for menu):\n\t\t==> ");
- for ( i=0; i<dum4; i++ )
- fprintf(stdprn, "%s ", dummy[i]);
- fprintf(stdprn, "\n");
- }
- if (val==108) {
- togglepr();
- if (stgdaton) printstgdatHARD();
- if (seqdaton) printseqdatHARD();
- } else {
- if (val) return(val);
- }
- #else
- printf("\n\tInitial cell name, or menu choice (F for menu):\n");
- printf("\t\t==> ");
- getusrstrlist(dummy, &dum4);
- #endif
- if (FILEq && FILECOPY) {
- fprintf(fpout, "\n\tInitial cell name, or menu choice ");
- fprintf(fpout, "(F for menu):\n\t\t==> ");
- for ( i=0; i<dum4; i++ )
- fprintf(fpout, "%s ", dummy[i]);
- fprintf(fpout, "\n");
- }
-
- stop = 0;
- if (dummy[0][1]=='\0') {
- stop = 1;
- /* user input is prob a char-accel */
- switch (toupper1(dummy[0][0])) {
- case 'A': /* general menu */
- return(101);
- case 'B': /* goto help menu */
- return(102);
- case 'C': /* goto animalmenu */
- return(103);
- case 'D': /* goto cycle length menu */
- return(104);
- case 'E': /* display menu */
- return(114);
- case 'F': /* cell input menu */
- cellmenu();
- #if PC
- stgdaton = 0;
- seqdaton = 0;
- #endif
- break;
- case 'G': /* days input menu */
- return(106);
- case 'H':
- printstgdat();
- #if PC
- stgdaton = 1;
- seqdaton = 0;
- #endif
- break;
- case 'I':
- printseqdat();
- #if PC
- seqdaton = 1;
- stgdaton = 0;
- #endif
- break;
- case 'X':
- printexit(7);
- case '?':
- helpcellip();
- #if PC
- stgdaton = 0;
- seqdaton = 0;
- #endif
- break;
- default: /* not a char-accel: parse it */
- stop = 0;
- } /* switch */
- } /* if */
-
- if (! stop) { /* parse input... */
- ok = dum4; /* if no trials, then ok=0 too */
- #if PC
- any = 0;
- #endif
- for ( i=0; i<dum4; i++ ) {
- strupper(dummy[i]);
-
- #if (DEBUG > 4)
- #if PC
- clrscr1(1);
- gotoxy(1, 5);
- cprintf("%sgetusrcells: dummy[i]=<%s>", tab, dummy[i]);
- hitreturn(1);
- #else
- printf("\tgetusrcells: dummy[i]=<%s>\n", dummy[i]);
- #endif
- #endif
-
- if (! parsecellstr(dummy[i], &dum1, &dum2, dum3)) {
- #if PC
- if (! any)
- clrscr1(3);
- if ((any+1) >= MSGLNS) {
- hitreturn(3);
- clrscr1(3);
- any = 0;
- }
- gotoxy(1, any+1);
- any++;
- cprintf("%s%s: Invalid cell ", tab, ERRSTR);
- cprintf("syntax <%s>.", dummy[i]);
- #if (DEBUG > 4)
- gotoxy(1, any+1);
- cprintf("%sgetusrcells: dummy[i]=<%s>", tab, dummy[i]);
- #endif
- if (HARDCOPY) {
- fprintf(stdprn, "\t%s: Invalid cell ", ERRSTR);
- fprintf(stdprn, "syntax <%s>.\n", dummy[i]);
- }
- #else
- printf("\t%s: Invalid cell ", ERRSTR);
- printf("syntax <%s>.\n", dummy[i]);
- #endif
- if (FILEq && FILECOPY) {
- fprintf(fpout, "\t%s: Invalid cell ", ERRSTR);
- fprintf(fpout, "syntax <%s>.\n", dummy[i]);
- }
- ok = ok && 0;
- } else
- strcpy(cellstrs[i], dummy[i]);
- } /* for i */
-
- } /* if ! stop */
-
- } /* while !ok */
- *ptrials = dum4;
- return(0);
- } /* getusrcells */
-
- /********************************/
- /* function: getusrdays */
- /********************************/
- /* gets list of days interactively
- if PC: returns 0 if number ok; 100+k if F-key pressed */
- getusrdays (cellstrs, daystrs, trials)
- char cellstrs[][MAXIPLEN], daystrs[][MAXIPLEN];
- int trials;
- {
- int i, stop, ok, count, diff;
- char dummy[MAXIP][MAXIPLEN];
- #if PC
- int any, j, val;
- int stgdaton; /* =1 if stg data on screen */
- int seqdaton; /* =1 if seq data on screen */
- #endif
-
- if (strcmp(Animal, "None")==0) {
- #if PC
- topline(" Days Input Menu ");
- clrscr1(1);
- gotoxy(1, 5);
- cprintf("%sNo animal has been selected yet.", tab);
- gotoxy(1, 6);
- cprintf("%sPlease use the Animal Menu to select an animal.", tab);
- if (HARDCOPY) {
- fprintf(stdprn, "\n\tNo animal has been selected yet.\n");
- fprintf(stdprn, "\tPlease use the Animal Menu to select an animal.\n");
- }
- hitreturn(1);
- #else
- printf("\n\tNo animal has been selected yet.\n");
- printf("\tPlease use the Animal Menu to select an animal.\n");
- #endif
- if (FILEq && FILECOPY) {
- fprintf(fpout, "\n\tNo animal has been selected yet.\n");
- fprintf(fpout, "\tPlease use the Animal Menu to select an animal.\n");
- }
- return(103); /* goto animalmenu */
- } /* if */
-
- if (trials==0) {
- #if PC
- clrscr1(1);
- gotoxy(1, 5);
- cprintf("%sNo initial cells have been selected yet.", tab);
- gotoxy(1, 6);
- cprintf("%sPlease use the Cell Input Menu to select initial cells.", tab);
- if (HARDCOPY) {
- fprintf(stdprn, "\n\tNo initial cells have been selected yet.\n");
- fprintf(stdprn, "\tPlease use the Cell Input Menu to select initial cells.\n");
- }
- hitreturn(1);
- #else
- printf("\n\tNo initial cells have been selected yet.\n");
- printf("\tPlease use the Cell Input Menu to select initial cells.\n");
- #endif
- if (FILEq && FILECOPY) {
- fprintf(fpout, "\n\tNo initial cells have been selected yet.\n");
- fprintf(fpout, "\tPlease use the Cell Input Menu to select initial cells.\n");
- }
- return(105); /* goto cell input */
- } /* if */
-
- ok = 0;
- printusrcells(cellstrs, trials);
- #if PC
- stgdaton = 0;
- seqdaton = 0;
- #endif
- daysmenu();
- while (! ok) {
- #if PC
- clrscr1(2);
- cprintf("%sNumber of days, or menu choice (G for menu):", tab);
- gotoxy(1, 2);
- highvideo();
- cprintf("%s%c%c%c ", tab2, HBAR, HBAR, RTRI);
- normvideo();
- val = getusrstrlist(dummy, &count);
- if (HARDCOPY) {
- fprintf(stdprn, "\n\tNumber of days, or menu choice ");
- fprintf(stdprn, "(G for menu):\n\t\t==> ");
- for ( i=0; i<count; i++ )
- fprintf(stdprn, "%s ", dummy[i]);
- fprintf(stdprn, "\n");
- }
- if (val==108) {
- togglepr();
- if (stgdaton) printstgdatHARD();
- if (seqdaton) printseqdatHARD();
- } else {
- if (val) return(val);
- }
- #else
- printf("\n\tNumber of days, or menu choice (G for menu):\n");
- printf("\t\t==> ");
- getusrstrlist(dummy, &count);
- #endif
- if (FILEq && FILECOPY) {
- fprintf(fpout, "\n\Number of days, or menu choice ");
- fprintf(fpout, "(G for menu):\n\t\t==> ");
- for ( i=0; i<count; i++ )
- fprintf(fpout, "%s ", dummy[i]);
- fprintf(fpout, "\n");
- }
-
- /* echo the days ip to file and printer */
-
- stop = 0;
- if (dummy[0][1]=='\0') {
- /* user input is prob a char-accel */
- stop = 1;
- switch (toupper1(dummy[0][0])) {
- case 'A': /* general menu */
- return(101);
- case 'B': /* help menu */
- return(102);
- case 'C': /* animal menu */
- return(103);
- case 'D': /* cycle length menu */
- return(104);
- case 'E': /* display menu */
- return(114);
- case 'F': /* cell input menu */
- return(105);
- case 'G': /* days input menu */
- daysmenu();
- #if PC
- stgdaton = 0;
- seqdaton = 0;
- #endif
- break;
- case 'H':
- printstgdat();
- #if PC
- stgdaton = 1;
- seqdaton = 0;
- #endif
- break;
- case 'I':
- printseqdat();
- #if PC
- seqdaton = 1;
- stgdaton = 0;
- #endif
- break;
- case 'J': /* show input cells */
- printusrcells(cellstrs, trials);
- break;
- case 'X':
- printexit(6);
- case '?':
- helpdaysip();
- #if PC
- stgdaton = 0;
- seqdaton = 0;
- #endif
- break;
- default: /* not a char-accel: parse it */
- stop = 0;
- break;
- } /* switch */
- } /* if */
-
- if (! stop) {
- diff = trials - count;
- #if PC
- clrscr1(3);
- #endif
- if (diff > 0) {
- ok = 0;
- #if PC
- cprintf("%s%s: List of days ", tab, ERRSTR);
- cprintf("is %d too short.", diff);
- if (HARDCOPY) {
- fprintf(stdprn, "\t%s: List of days ", ERRSTR);
- fprintf(stdprn, "is %d too short.\n", diff);
- }
- #else
- printf("\t%s: List of days ", ERRSTR);
- printf("is %d too short.\n", diff);
- #endif
- if (FILEq && FILECOPY) {
- fprintf(fpout, "\t%s: List of days ", ERRSTR);
- fprintf(fpout, "is %d too short.\n", diff);
- }
- } /* if diff */
- if (diff < 0) {
- #if PC
- cprintf("%s%s: List of days ", tab, ERRSTR);
- cprintf("is %d too long.", abs(diff));
- if (HARDCOPY) {
- fprintf(stdprn, "\t%s: List of days ", ERRSTR);
- fprintf(stdprn, "is %d too long.\n", abs(diff));
- }
- #else
- printf("\t%s: List of days ", ERRSTR);
- printf("is %d too long.\n", abs(diff));
- #endif
- if (FILEq && FILECOPY) {
- fprintf(fpout, "\t%s: List of days ", ERRSTR);
- fprintf(fpout, "is %d too long.\n", abs(diff));
- }
- } /* if diff */
- if (diff==0) ok = 1;
- #if PC
- j = 0;
- any = 0;
- #endif
- for ( i=0; i<count; i++ ) {
- if (! numstrq(dummy[i])) {
- #if PC
- if (! any) {
- if (diff) /* line 1 has "list of days too..." */
- j = 2;
- else
- j = 1;
- }
- any++;
- if (j >= MSGLNS) {
- hitreturn(3);
- clrscr1(3);
- /* but now after clrscr, go to line 1 */
- j = 1;
- }
- gotoxy(1, j);
- clreol1(3);
- gotoxy(1, j++);
- cprintf("%s%s: Invalid number ", tab, ERRSTR);
- cprintf("syntax <%s>.", dummy[i]);
- if (HARDCOPY) {
- fprintf(stdprn, "\t%s: Invalid numb", ERRSTR);
- fprintf(stdprn, "er syntax <%s>.\n", dummy[i]);
- }
- #else
- printf("\t%s: Invalid numb", ERRSTR);
- printf("er syntax <%s>.\n", dummy[i]);
- #endif
- if (FILEq && FILECOPY) {
- fprintf(fpout, "\t%s: Invalid numb", ERRSTR);
- fprintf(fpout, "er syntax <%s>.\n", dummy[i]);
- }
- ok = ok && 0;
- } else
- strcpy(daystrs[i], dummy[i]);
- } /* for */
- if (! ok) count = 0;
- } /* if ! stop */
- } /* while !ok */
- return(0);
- } /* getusrdays */
-
- /********************************/
- /* function: getfileip */
- /********************************/
- /* gets initial cells and days from a file, batch-mode style
- returns 1 while not EOF
- returns 0 if EOF */
- getfileip (cellstr, daystr, fpin)
- char *cellstr, *daystr;
- FILE *fpin;
- {
- if (fscanf(fpin, "%s %s", cellstr, daystr) != EOF) {
- strupper(cellstr);
- return(1);
- } else
- return(0);
- } /* getfileip */
-
- /********************************/
- /* function: parsecellstr */
- /********************************/
- /* parses the user-input cellname:
- 1/ checks validity (match any from the cell sequence file?)
- 2/ if so, finds its cell sequence # and stage #, returns 1
- 3/ if not, returns 0 */
- parsecellstr (str, pseq, pst, opstr)
- char *str;
- int *pseq, *pst;
- char *opstr;
- {
- int i, found;
-
- /* look for the cell string in the list of known cell names*/
- i = 0;
- found = 0;
- while ((! found) && (i <= MaxCellIndex)) {
- if (strcmp(str, CellNames[i++])==0) {
- found = 1;
- *pseq = --i; /* cell sequence # */
- *pst = getcellstg(CellNames[i]); /* cell stage # */
- if (*pst==-1) /* bad cell name format */
- found = 0; /* shouldn't happen! */
- }
- }
-
- if ((! found) && (i > MaxCellIndex)) {
- sprintf(opstr, " %s: Unrecognized input cell <%s>",
- ERRSTR, str);
- *pseq = INVALID;
- *pst = INVALID;
- return(0); /* not ok */
- } else {
- sprintf(opstr, " ");
- return(1); /* ok */
- }
- } /* parsecellstr */
-
- /********************************/
- /* function: getcellstg */
- /********************************/
- /* parses a cell's namestring to extract its stage number.
- this assumes all cells are named in the syntax:
- name-nn where nn is the stage number
- if bad cell syntax discovered, return INVALID
- else return stage number
-
- the special case of epididymis has to be handled separately */
- getcellstg (str)
- char *str;
- {
- int len, i, j;
- char temp[10]; /* holds digits of the stage # */
- #if PC
- static int k=1;
- #endif
-
- #if (DEBUG > 4)
- #if PC
- clrscr1(1);
- gotoxy(1, 5);
- cprintf("%sgetcellstage: str=<%s>", tab, str);
- hitreturn(1);
- #else
- printf("\tgetcellstage: str=<%s>\n", str);
- #endif
- #endif
-
- if (strcmp(str, CellNames[MaxCellIndex+1])==0)
- return(MaxCellIndex+1); /* in epididymis */
-
- len = strlen(str);
- i = 0;
- while ((i <= len) && (str[i++] != '-'));
- if (str[--i] != '-') {
- #if PC
- if (k >= MSGLNS) {
- hitreturn(3);
- clrscr1(3);
- k = 1;
- }
- msgwin();
- gotoxy(1, k);
- clreol1(1);
- gotoxy(1, k++);
- cprintf("%s%s: Bad cell name <%s>: `-' expected", tab, ERRSTR, str);
- if (HARDCOPY) {
- fprintf(stdprn, "\t%s: Bad cell name <%s>: ", ERRSTR, str);
- fprintf(stdprn, "`-' expected\n");
- }
- #else
- printf("\t%s: Bad cell name <%s>: `-' expected\n", ERRSTR, str);
- #endif
- if (FILEq && FILECOPY) {
- fprintf(fpout, "\t%s: Bad cell name <%s>: ", ERRSTR, str);
- fprintf(fpout, "`-' expected\n");
- }
- return(INVALID);
- } else {
- j = 0;
- while (i <= len)
- temp[j++] = str[++i];
- return(atoi(temp));
- }
- } /* getcellstg */