home *** CD-ROM | disk | FTP | other *** search
/ ProfitPress Mega CDROM2 …eeware (MSDOS)(1992)(Eng) / ProfitPress-MegaCDROM2.B6I / MISC / EDUCATIO / STAGES12.ZIP / INPUTS2.C < prev    next >
Encoding:
C/C++ Source or Header  |  1991-04-16  |  19.6 KB  |  788 lines

  1. #include "header.h"
  2. #if PC
  3.   #include <bios.h>
  4. #endif
  5. #include "file.h"
  6.  
  7. /* functions included:
  8.         getusrstrlist
  9.         getusrcells
  10.         getusrdays
  11.         getfileip
  12.         parsecellstr
  13.         getcellstg
  14. */
  15.  
  16. #if PC
  17. /********************************/
  18. /*     function: getusrstrlist    */
  19. /********************************/
  20. /* gets a list user-input strings: PC version
  21.  
  22.    return 0 if string input
  23.    return 100+k if F-k pressed */
  24. getusrstrlist (strings, pnum)
  25.   char strings[][MAXIPLEN];    /* list of strings if no F key  */
  26.   int *pnum;            /* num of strings in list     */
  27. {
  28.   int key;            /* 32-bit val of key pressed     */
  29.   int keylo;            /* key bits 0-7            */
  30.   int keyhi;            /* key bits 8-15        */
  31.   int i, j, k, any, go, x, y, laststr;
  32.   int splast;            /* flag: =1 if last ch=whitesp  */
  33.   int xlast;            /* last x pos of old line     */
  34.   int newln;            /* = # of new lines needed    */
  35.   char input[2*MAXLEN];        /* for reading i/p linearly    */
  36.  
  37.   i = 0;
  38.   *pnum = 0;
  39.   y = wherey();
  40.   splast = 0;
  41.   xlast = 0;
  42.   newln = 0;
  43.   go = 1;
  44.   while (go) {
  45.     while (bioskey(1)==0);        /* sit & spin */
  46.     x = wherex();
  47.     key = bioskey(0);
  48.     keylo = key & 0x000000FF;
  49.     keyhi = (key & 0x0000FF00) >> 8;    /* right shift 8 bits */
  50.     switch (keylo) {
  51.     case 0:    /* Fkey? */
  52.       switch (keyhi) {
  53.       case 59:        /* F1 */
  54.     return(101);
  55.       case 60:        /* F2 */
  56.     return(102);
  57.       case 61:        /* F3 */
  58.     return(103);
  59.       case 62:        /* F4 */
  60.     return(104);
  61.       case 63:        /* F5 */
  62.     return(105);
  63.       case 64:        /* F6 */
  64.     return(106);
  65.       case 65:        /* F7 */
  66.     return(107);
  67.       case 66:        /* F8 */
  68.     return(108);
  69.       case 67:        /* F9 */
  70.     return(109);
  71.       case 68:        /* F10 */
  72.     return(110);
  73.       default:        /* undefined special key */
  74.     strings[0][0] = '\0';
  75.     return(200);
  76.       } /* switch keyhi */
  77.     case 8:    /* backspace */
  78.       if (i > 0) {
  79.     i--;        /* back up over flat array */
  80.     splast = 0;
  81.     if (x==5) {    /* only way for x==5 is to be on a new line */
  82.       gotoxy(5, y);
  83.       clreol1(2);
  84.       newln--;        /* back up a line */
  85.       x = xlast;
  86.       y--;
  87.       gotoxy(x, y);
  88.     } else {
  89.       if (!newln && (x <= 21)) {
  90.         /* on orig line, don't back up over request-for-i/p msg */
  91.         gotoxy(21, y);
  92.       } else {
  93.         gotoxy(x-1, y);
  94.         clreol1(2);
  95.         gotoxy(x-1, y);
  96.       }
  97.     }
  98.       }
  99.       break;
  100.     case 32:    /* space */
  101.     case 9:    /* tab */
  102.       /* whitespace: if first, print a space; else ignore it */
  103.       splast = 1;        /* flag: =1: last ch was whitesp */
  104.       cprintf(" ");
  105.       input[i++] = ' ';
  106.       break;
  107.     case 10:
  108.     case 13:    /* CR/LF = return */
  109.       input[i] = '\0';
  110.       laststr = i;
  111.       go = 0;
  112.       gotoxy(x, y);
  113.       cprintf("%c", keylo);
  114.       input[i++] = keylo;
  115.       break;
  116.     default:    /* other ASCII char */
  117.       if (splast && (x >= 65)) {
  118.     /* end of substring, and near eol:  good time to start new line */
  119.     xlast = x-1;
  120.     y++;
  121.     newln++;    /* incr # lines used */
  122.     x = 5;
  123.       }
  124.       splast = 0;
  125.       gotoxy(x, y);
  126.       cprintf("%c", keylo);
  127.       /* first build flat array of input, so can ^H over it */
  128.       input[i++] = keylo;
  129.     } /* switch keylo */
  130.   } /* while go */
  131.  
  132.   /* now build array of strings from input */
  133.   i = j = 0;
  134.   any = 0;
  135.   for ( k=0; k<=laststr; k++ ) {
  136.     if (whitespq(input[k])) {    /* whitespace=space/tab/CR    */
  137.       if (any && j) {
  138.     strings[i][j] = '\0';    /* end this cellname str    */
  139.     (*pnum)++;
  140.     i++;            /* start next cellname str    */
  141.     j = 0;
  142.       }
  143.     } else { /* ! whitespace */
  144.       any = 1;
  145.       strings[i][j++] = input[k];    /* build new cellname    */
  146.     }
  147.   } /* for i */
  148.   return(0);
  149. } /* getusrstrlist */
  150.  
  151. #else
  152.  
  153. /********************************/
  154. /*     function: getusrstrlist    */
  155. /********************************/
  156. /* gets a list user-input strings
  157.    pnum = number of substrings within the "strings" string */
  158. getusrstrlist (strings, pnum)
  159.   char strings[][MAXIPLEN];
  160.   int *pnum;
  161. {
  162.   int i, j, any, go;
  163.   char c;
  164.  
  165.   i = 0;
  166.   j = 0;
  167.   any = 0;
  168.   *pnum = 0;
  169.   go = 1;
  170.   while (go && (c=getc(stdin)) != '\n') {
  171.     /* build array of cellnames */
  172.     if (whitespq(c)) {        /* whitespace = space or tab */
  173.       if (any) {
  174.     strings[i][j] = '\0';    /* end this cellname str     */
  175.     (*pnum)++;        /* incr # trials         */
  176.     i++;            /* start next cellname str     */
  177.       }
  178.       j = 0;
  179.       /* skip whitespace */
  180.       while (whitespq(c=getc(stdin)));
  181.  
  182.       if (c != '\n') {        /* if more besides whitesp...    */
  183.     any = 1;
  184.     strings[i][j++] = c;    /* build new cellname str    */
  185.       } else {            /* last chars were just whitesp */
  186.     go = 0;        
  187.     (*pnum)--;
  188.       }
  189.     } else { /* ! whitespq */
  190.       any = 1;
  191.       strings[i][j++] = c;    /* build this cellname str    */
  192.     } /* if */
  193.   } /* while */
  194.  
  195.   (*pnum)++;
  196.   strings[i][j] = '\0';        /* end the last cellname str    */
  197. } /* getusrstrlist */
  198. #endif
  199.  
  200. /********************************/
  201. /*     function: getusrcells    */
  202. /********************************/
  203. /* gets list of initial cell names interactively
  204.  
  205.    if PC: returns 0 if cellstr ok
  206.            100+k if special key pressed (e.g., F-key) */
  207. getusrcells (cellstrs, ptrials)
  208.   char cellstrs[][MAXIPLEN];
  209.   int *ptrials;
  210. {
  211.   int i, stop, ok;
  212.   int stgdaton;        /* =1 if stg dat on screen    */
  213.   int seqdaton;        /* =1 if seq dat on screen     */
  214.   int dum1, dum2, dum4;    /* dummy vars for parsecellstr    */
  215.   char dum3[MAXLEN];    /* dummy str for parsecellstr    */
  216.   /* dummy array of strings so cellstrs isn't wiped out if user wants
  217.      to use same cells over again */
  218.   char dummy[MAXIP][MAXIPLEN];
  219. #if PC
  220.   int any, val;
  221. #endif
  222.  
  223.   if (strcmp(Animal, "None")==0) {
  224. #if PC
  225.     topline(" Cell Input Menu ");
  226.     clrscr1(1);
  227.     gotoxy(1, 5);
  228.     cprintf("%sNo animal has been selected yet.", tab);
  229.     gotoxy(1, 6);
  230.     cprintf("%sPlease use the Animal Menu to select an animal.", tab);
  231.     if (HARDCOPY) {
  232.       fprintf(stdprn, "\n\tNo animal has been selected yet.\n");
  233.       fprintf(stdprn, "\tPlease use the Animal Menu to select an animal.\n");
  234.     }
  235.     hitreturn(1);
  236. #else
  237.     printf("\n\tNo animal has been selected yet.\n");
  238.     printf("\tPlease use the Animal Menu to select an animal.\n");
  239. #endif
  240.     if (FILEq && FILECOPY) {
  241.       fprintf(fpout, "\n\tNo animal has been selected yet.\n");
  242.       fprintf(fpout, "\tPlease use the Animal Menu to select an animal.\n");
  243.     }
  244.     return(103);    /* goto animalmenu */
  245.   }
  246.  
  247.   ok = 0;
  248.   cellmenu();
  249. #if PC
  250.   stgdaton = 0;
  251.   seqdaton = 0;
  252. #endif
  253.   while (! ok) {
  254. #if PC
  255.     clrscr1(2);
  256.     cprintf("%sInitial cell name, or menu choice (F for menu):", tab);
  257.     gotoxy(1, 2);
  258.     highvideo();
  259.     cprintf("%s%c%c%c ", tab2, HBAR, HBAR, RTRI);
  260.     normvideo();
  261.     val = getusrstrlist(dummy, &dum4);
  262. #if (DEBUG > 4)
  263. #if PC
  264.   clrscr1(1);
  265.   gotoxy(1, 5);
  266.   cprintf("%sgetusrcells:  val=%d  dummy=<%s>", tab, val, dummy[0]);
  267.   hitreturn(1);
  268. #else
  269.   printf("\tgetusrcells: val=%d  dummy=<%s>\n", val, dummy[0]);
  270. #endif
  271. #endif
  272.  
  273.     if (HARDCOPY) {
  274.       fprintf(stdprn, "\n\tInitial cell name, or menu choice ");
  275.       fprintf(stdprn, "(F for menu):\n\t\t==> ");
  276.       for ( i=0; i<dum4; i++ )
  277.     fprintf(stdprn, "%s ", dummy[i]);
  278.       fprintf(stdprn, "\n");
  279.     }
  280.     if (val==108) {
  281.       togglepr();
  282.       if (stgdaton) printstgdatHARD();
  283.       if (seqdaton) printseqdatHARD();
  284.     } else {
  285.       if (val) return(val);
  286.     }
  287. #else
  288.     printf("\n\tInitial cell name, or menu choice (F for menu):\n");
  289.     printf("\t\t==> ");
  290.     getusrstrlist(dummy, &dum4);
  291. #endif
  292.     if (FILEq && FILECOPY) {
  293.       fprintf(fpout, "\n\tInitial cell name, or menu choice ");
  294.       fprintf(fpout, "(F for menu):\n\t\t==> ");
  295.       for ( i=0; i<dum4; i++ )
  296.     fprintf(fpout, "%s ", dummy[i]);
  297.       fprintf(fpout, "\n");
  298.     }
  299.  
  300.     stop = 0;
  301.     if (dummy[0][1]=='\0') {
  302.       stop = 1;
  303.       /* user input is prob a char-accel */
  304.       switch (toupper1(dummy[0][0])) {
  305.       case 'A':        /* general menu */
  306.     return(101);
  307.       case 'B':        /* goto help menu */
  308.     return(102);
  309.       case 'C':        /* goto animalmenu */
  310.     return(103);
  311.       case 'D':        /* goto cycle length menu */
  312.     return(104);
  313.       case 'E':        /* display menu */
  314.     return(114);
  315.       case 'F':        /* cell input menu */
  316.     cellmenu();
  317. #if PC
  318.     stgdaton = 0;
  319.     seqdaton = 0;
  320. #endif
  321.     break;
  322.       case 'G':        /* days input menu */
  323.     return(106);
  324.       case 'H':
  325.     printstgdat();
  326. #if PC
  327.     stgdaton = 1;
  328.     seqdaton = 0;
  329. #endif
  330.     break;
  331.       case 'I':
  332.     printseqdat();
  333. #if PC
  334.     seqdaton = 1;
  335.     stgdaton = 0;
  336. #endif
  337.     break;
  338.       case 'X':
  339.     printexit(7);
  340.       case '?':
  341.     helpcellip();
  342. #if PC
  343.     stgdaton = 0;
  344.     seqdaton = 0;
  345. #endif
  346.     break;
  347.       default:     /* not a char-accel: parse it */
  348.     stop = 0;
  349.       } /* switch */
  350.     } /* if */
  351.  
  352.     if (! stop) {    /* parse input... */
  353.       ok = dum4;    /* if no trials, then ok=0 too */
  354. #if PC
  355.       any = 0;
  356. #endif
  357.       for ( i=0; i<dum4; i++ ) {
  358.     strupper(dummy[i]);
  359.  
  360. #if (DEBUG > 4)
  361. #if PC
  362.   clrscr1(1);
  363.   gotoxy(1, 5);
  364.   cprintf("%sgetusrcells:  dummy[i]=<%s>", tab, dummy[i]);
  365.   hitreturn(1);
  366. #else
  367.   printf("\tgetusrcells:  dummy[i]=<%s>\n", dummy[i]);
  368. #endif
  369. #endif
  370.  
  371.     if (! parsecellstr(dummy[i], &dum1, &dum2, dum3)) {
  372. #if PC
  373.       if (! any)
  374.         clrscr1(3);
  375.       if ((any+1) >= MSGLNS) {
  376.         hitreturn(3);
  377.         clrscr1(3);
  378.         any = 0;
  379.       }
  380.       gotoxy(1, any+1);
  381.       any++;
  382.       cprintf("%s%s:  Invalid cell ", tab, ERRSTR);
  383.       cprintf("syntax <%s>.", dummy[i]);
  384. #if (DEBUG > 4)
  385.       gotoxy(1, any+1);
  386.       cprintf("%sgetusrcells: dummy[i]=<%s>", tab, dummy[i]);
  387. #endif
  388.       if (HARDCOPY) {
  389.         fprintf(stdprn, "\t%s:  Invalid cell ", ERRSTR);
  390.         fprintf(stdprn, "syntax <%s>.\n", dummy[i]);
  391.       }
  392. #else
  393.       printf("\t%s:  Invalid cell ", ERRSTR);
  394.       printf("syntax <%s>.\n", dummy[i]);
  395. #endif
  396.       if (FILEq && FILECOPY) {
  397.         fprintf(fpout, "\t%s:  Invalid cell ", ERRSTR);
  398.         fprintf(fpout, "syntax <%s>.\n", dummy[i]);
  399.       }
  400.       ok = ok && 0;
  401.     } else
  402.       strcpy(cellstrs[i], dummy[i]);
  403.       } /* for i */
  404.  
  405.     } /* if ! stop */
  406.  
  407.   } /* while !ok */
  408.   *ptrials = dum4;
  409.   return(0);
  410. } /* getusrcells */
  411.  
  412. /********************************/
  413. /*     function: getusrdays    */
  414. /********************************/
  415. /* gets list of days interactively
  416.    if PC: returns 0 if number ok; 100+k if F-key pressed */
  417. getusrdays (cellstrs, daystrs, trials)
  418.   char cellstrs[][MAXIPLEN], daystrs[][MAXIPLEN];
  419.   int trials;
  420. {
  421.   int i, stop, ok, count, diff;
  422.   char dummy[MAXIP][MAXIPLEN];
  423. #if PC
  424.   int any, j, val;
  425.   int stgdaton;            /* =1 if stg data on screen    */
  426.   int seqdaton;            /* =1 if seq data on screen    */
  427. #endif
  428.  
  429.   if (strcmp(Animal, "None")==0) {
  430. #if PC
  431.     topline(" Days Input Menu ");
  432.     clrscr1(1);
  433.     gotoxy(1, 5);
  434.     cprintf("%sNo animal has been selected yet.", tab);
  435.     gotoxy(1, 6);
  436.     cprintf("%sPlease use the Animal Menu to select an animal.", tab);
  437.     if (HARDCOPY) {
  438.       fprintf(stdprn, "\n\tNo animal has been selected yet.\n");
  439.       fprintf(stdprn, "\tPlease use the Animal Menu to select an animal.\n");
  440.     }
  441.     hitreturn(1);
  442. #else
  443.     printf("\n\tNo animal has been selected yet.\n");
  444.     printf("\tPlease use the Animal Menu to select an animal.\n");
  445. #endif
  446.     if (FILEq && FILECOPY) {
  447.       fprintf(fpout, "\n\tNo animal has been selected yet.\n");
  448.       fprintf(fpout, "\tPlease use the Animal Menu to select an animal.\n");
  449.     }
  450.     return(103);    /* goto animalmenu */
  451.   } /* if */
  452.  
  453.   if (trials==0) {
  454. #if PC
  455.     clrscr1(1);
  456.     gotoxy(1, 5);
  457.     cprintf("%sNo initial cells have been selected yet.", tab);
  458.     gotoxy(1, 6);
  459.     cprintf("%sPlease use the Cell Input Menu to select initial cells.", tab);
  460.     if (HARDCOPY) {
  461.       fprintf(stdprn, "\n\tNo initial cells have been selected yet.\n");
  462.       fprintf(stdprn, "\tPlease use the Cell Input Menu to select initial cells.\n");
  463.     }
  464.     hitreturn(1);
  465. #else
  466.     printf("\n\tNo initial cells have been selected yet.\n");
  467.     printf("\tPlease use the Cell Input Menu to select initial cells.\n");
  468. #endif
  469.     if (FILEq && FILECOPY) {
  470.       fprintf(fpout, "\n\tNo initial cells have been selected yet.\n");
  471.       fprintf(fpout, "\tPlease use the Cell Input Menu to select initial cells.\n");
  472.     }
  473.     return(105);    /* goto cell input */
  474.   } /* if */
  475.  
  476.   ok = 0;
  477.   printusrcells(cellstrs, trials);
  478. #if PC
  479.   stgdaton = 0;
  480.   seqdaton = 0;
  481. #endif
  482.   daysmenu();
  483.   while (! ok) {
  484. #if PC
  485.     clrscr1(2);
  486.     cprintf("%sNumber of days, or menu choice (G for menu):", tab);
  487.     gotoxy(1, 2);
  488.     highvideo();
  489.     cprintf("%s%c%c%c ", tab2, HBAR, HBAR, RTRI);
  490.     normvideo();
  491.     val = getusrstrlist(dummy, &count);
  492.     if (HARDCOPY) {
  493.       fprintf(stdprn, "\n\tNumber of days, or menu choice ");
  494.       fprintf(stdprn, "(G for menu):\n\t\t==> ");
  495.       for ( i=0; i<count; i++ )
  496.     fprintf(stdprn, "%s ", dummy[i]);
  497.       fprintf(stdprn, "\n");
  498.     }
  499.     if (val==108) {
  500.       togglepr();
  501.       if (stgdaton) printstgdatHARD();
  502.       if (seqdaton) printseqdatHARD();
  503.     } else {
  504.       if (val) return(val);
  505.     }
  506. #else
  507.     printf("\n\tNumber of days, or menu choice (G for menu):\n");
  508.     printf("\t\t==> ");
  509.     getusrstrlist(dummy, &count);
  510. #endif
  511.     if (FILEq && FILECOPY) {
  512.       fprintf(fpout, "\n\Number of days, or menu choice ");
  513.       fprintf(fpout, "(G for menu):\n\t\t==> ");
  514.       for ( i=0; i<count; i++ )
  515.     fprintf(fpout, "%s ", dummy[i]);
  516.       fprintf(fpout, "\n");
  517.     }
  518.  
  519.     /* echo the days ip to file and printer */
  520.  
  521.     stop = 0;
  522.     if (dummy[0][1]=='\0') {
  523.       /* user input is prob a char-accel */
  524.       stop = 1;
  525.       switch (toupper1(dummy[0][0])) {
  526.       case 'A':        /* general menu */
  527.     return(101);
  528.       case 'B':        /* help menu */
  529.     return(102);
  530.       case 'C':        /* animal menu */
  531.     return(103);
  532.       case 'D':        /* cycle length menu */
  533.     return(104);
  534.       case 'E':        /* display menu */
  535.     return(114);
  536.       case 'F':        /* cell input menu */
  537.     return(105);
  538.       case 'G':        /* days input menu */
  539.     daysmenu();
  540. #if PC
  541.     stgdaton = 0;
  542.     seqdaton = 0;
  543. #endif
  544.     break;
  545.       case 'H':
  546.     printstgdat();
  547. #if PC
  548.     stgdaton = 1;
  549.     seqdaton = 0;
  550. #endif
  551.     break;
  552.       case 'I':
  553.     printseqdat();
  554. #if PC
  555.     seqdaton = 1;
  556.     stgdaton = 0;
  557. #endif
  558.     break;
  559.       case 'J':        /* show input cells */
  560.     printusrcells(cellstrs, trials);
  561.     break;
  562.       case 'X':
  563.     printexit(6);
  564.       case '?':
  565.     helpdaysip();
  566. #if PC
  567.     stgdaton = 0;
  568.     seqdaton = 0;
  569. #endif
  570.     break;
  571.       default:     /* not a char-accel: parse it */
  572.     stop = 0;
  573.     break;
  574.       } /* switch */
  575.     } /* if */
  576.  
  577.     if (! stop) {
  578.       diff = trials - count;
  579. #if PC
  580.       clrscr1(3);
  581. #endif
  582.       if (diff > 0) {
  583.     ok = 0;
  584. #if PC
  585.     cprintf("%s%s:  List of days ", tab, ERRSTR);
  586.     cprintf("is %d too short.", diff);
  587.     if (HARDCOPY) {
  588.       fprintf(stdprn, "\t%s:  List of days ", ERRSTR);
  589.       fprintf(stdprn, "is %d too short.\n", diff);
  590.     }
  591. #else
  592.     printf("\t%s:  List of days ", ERRSTR);
  593.     printf("is %d too short.\n", diff);
  594. #endif
  595.     if (FILEq && FILECOPY) {
  596.       fprintf(fpout, "\t%s:  List of days ", ERRSTR);
  597.       fprintf(fpout, "is %d too short.\n", diff);
  598.     }
  599.       } /* if diff */
  600.       if (diff < 0) {
  601. #if PC
  602.     cprintf("%s%s:  List of days ", tab, ERRSTR);
  603.     cprintf("is %d too long.", abs(diff));
  604.     if (HARDCOPY) {
  605.       fprintf(stdprn, "\t%s:  List of days ", ERRSTR);
  606.       fprintf(stdprn, "is %d too long.\n", abs(diff));
  607.     }
  608. #else
  609.     printf("\t%s:  List of days ", ERRSTR);
  610.     printf("is %d too long.\n", abs(diff));
  611. #endif
  612.     if (FILEq && FILECOPY) {
  613.       fprintf(fpout, "\t%s:  List of days ", ERRSTR);
  614.       fprintf(fpout, "is %d too long.\n", abs(diff));
  615.     }
  616.       } /* if diff */
  617.       if (diff==0) ok = 1;
  618. #if PC
  619.       j = 0;
  620.       any = 0;
  621. #endif
  622.       for ( i=0; i<count; i++ ) {
  623.     if (! numstrq(dummy[i])) {
  624. #if PC
  625.       if (! any) {
  626.         if (diff)    /* line 1 has "list of days too..." */
  627.           j = 2;
  628.         else
  629.           j = 1;
  630.       }
  631.       any++;
  632.       if (j >= MSGLNS) {
  633.         hitreturn(3);
  634.         clrscr1(3);
  635.         /* but now after clrscr, go to line 1 */
  636.         j = 1;
  637.       }
  638.       gotoxy(1, j);
  639.       clreol1(3);
  640.       gotoxy(1, j++);
  641.       cprintf("%s%s:  Invalid number ", tab, ERRSTR);
  642.       cprintf("syntax <%s>.", dummy[i]);
  643.       if (HARDCOPY) {
  644.         fprintf(stdprn, "\t%s:  Invalid numb", ERRSTR);
  645.         fprintf(stdprn, "er syntax <%s>.\n", dummy[i]);
  646.       }
  647. #else
  648.       printf("\t%s:  Invalid numb", ERRSTR);
  649.       printf("er syntax <%s>.\n", dummy[i]);
  650. #endif
  651.       if (FILEq && FILECOPY) {
  652.         fprintf(fpout, "\t%s:  Invalid numb", ERRSTR);
  653.         fprintf(fpout, "er syntax <%s>.\n", dummy[i]);
  654.       }
  655.       ok = ok && 0;
  656.     } else
  657.       strcpy(daystrs[i], dummy[i]);
  658.       } /* for */
  659.       if (! ok) count = 0;
  660.     } /* if ! stop */
  661.   } /* while !ok */
  662.   return(0);
  663. } /* getusrdays */
  664.  
  665. /********************************/
  666. /*     function: getfileip    */
  667. /********************************/
  668. /* gets initial cells and days from a file, batch-mode style
  669.    returns 1 while not EOF
  670.    returns 0 if EOF */
  671. getfileip (cellstr, daystr, fpin)
  672.   char *cellstr, *daystr;
  673.   FILE *fpin;
  674. {
  675.   if (fscanf(fpin, "%s %s", cellstr, daystr) != EOF) {
  676.     strupper(cellstr);
  677.     return(1);
  678.   } else
  679.     return(0);
  680. } /* getfileip */
  681.  
  682. /********************************/
  683. /*     function: parsecellstr    */
  684. /********************************/
  685. /* parses the user-input cellname:
  686.    1/ checks validity (match any from the cell sequence file?)
  687.    2/ if so, finds its cell sequence # and stage #, returns 1
  688.    3/ if not, returns 0 */
  689. parsecellstr (str, pseq, pst, opstr)
  690.   char *str;
  691.   int *pseq, *pst;
  692.   char *opstr;
  693. {
  694.   int i, found;
  695.  
  696.   /* look for the cell string in the list of known cell names*/
  697.   i = 0;
  698.   found = 0;
  699.   while ((! found) && (i <= MaxCellIndex)) {
  700.     if (strcmp(str, CellNames[i++])==0) {
  701.       found = 1;
  702.       *pseq = --i;             /* cell sequence # */
  703.       *pst = getcellstg(CellNames[i]);    /* cell stage # */
  704.       if (*pst==-1)            /* bad cell name format */
  705.     found = 0;            /* shouldn't happen!    */
  706.     }
  707.   }
  708.  
  709.   if ((! found) && (i > MaxCellIndex)) {
  710.     sprintf(opstr, "       %s:  Unrecognized input cell <%s>",
  711.         ERRSTR, str);
  712.     *pseq = INVALID;
  713.     *pst = INVALID;
  714.     return(0);    /* not ok */
  715.   } else {
  716.     sprintf(opstr, " ");
  717.     return(1);    /* ok */
  718.   }
  719. } /* parsecellstr */
  720.  
  721. /********************************/
  722. /*     function: getcellstg    */
  723. /********************************/
  724. /* parses a cell's namestring to extract its stage number.
  725.    this assumes all cells are named in the syntax:
  726.    name-nn    where nn is the stage number
  727.    if bad cell syntax discovered, return INVALID
  728.    else return stage number
  729.  
  730.    the special case of epididymis has to be handled separately */
  731. getcellstg (str)
  732.   char *str;
  733. {
  734.   int len, i, j;
  735.   char temp[10];        /* holds digits of the stage # */
  736. #if PC
  737.   static int k=1;
  738. #endif
  739.  
  740. #if (DEBUG > 4)
  741. #if PC
  742.   clrscr1(1);
  743.   gotoxy(1, 5);
  744.   cprintf("%sgetcellstage:  str=<%s>", tab, str);
  745.   hitreturn(1);
  746. #else
  747.   printf("\tgetcellstage:  str=<%s>\n", str);
  748. #endif
  749. #endif
  750.  
  751.   if (strcmp(str, CellNames[MaxCellIndex+1])==0)
  752.     return(MaxCellIndex+1);    /* in epididymis */
  753.  
  754.   len = strlen(str);
  755.   i = 0;
  756.   while ((i <= len) && (str[i++] != '-'));
  757.   if (str[--i] != '-') {
  758. #if PC
  759.     if (k >= MSGLNS) {
  760.       hitreturn(3);
  761.       clrscr1(3);
  762.       k = 1;
  763.     }
  764.     msgwin();
  765.     gotoxy(1, k);
  766.     clreol1(1);
  767.     gotoxy(1, k++);
  768.     cprintf("%s%s:  Bad cell name <%s>: `-' expected", tab, ERRSTR, str);
  769.     if (HARDCOPY) {
  770.       fprintf(stdprn, "\t%s:  Bad cell name <%s>: ", ERRSTR, str);
  771.       fprintf(stdprn, "`-' expected\n");
  772.     }
  773. #else
  774.     printf("\t%s:  Bad cell name <%s>: `-' expected\n", ERRSTR, str);
  775. #endif
  776.     if (FILEq && FILECOPY) {
  777.       fprintf(fpout, "\t%s:  Bad cell name <%s>: ", ERRSTR, str);
  778.       fprintf(fpout, "`-' expected\n");
  779.     }
  780.     return(INVALID);
  781.   } else {
  782.     j = 0;
  783.     while (i <= len)
  784.       temp[j++] = str[++i];
  785.     return(atoi(temp));
  786.   }
  787. } /* getcellstg */
  788.