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

  1. #include "header.h"
  2. #if PC
  3.   #include <bios.h>
  4. #endif
  5. #include "file.h"
  6.  
  7. unsigned long coreleft(void);
  8.  
  9. /* functions included:
  10.            getipfile
  11.         getstgdat
  12.                 getCyclelen
  13.         getseqdat
  14.         getmcldat
  15.         getusrstr
  16. */
  17.  
  18. /********************************/
  19. /*     function: getipfile    */
  20. /********************************/
  21. /* there are 2 times when getipfile is called:
  22.     1/  to open a batch i/p file
  23.     2/  to open animal data files.
  24.    in case 1/, if file can't be found, do prompt for another file,
  25.    but it isn't mandatory to have one (if none given, then interactive
  26.    use assumed).
  27.    in case 2/, don't ask user for new filename:  just exit w/error msg.
  28.    the user doesn't know anything about which files are correct to use.
  29.  
  30.    returns 0 if good file opened,
  31.    else returns 1. */
  32. getipfile (ipfil, pfp, iptype, ftype)
  33.   char *ipfil;        /* the name of the file finally opened    */
  34.   FILE **pfp;
  35.   char iptype;        /* filename supplied (F) or entered    */
  36.               /* interactively (I)            */
  37.   char ftype;        /* C=cycle stage dat
  38.                I=input file (batch mode)
  39.                S=cell sequence dat            */
  40. {
  41.   int go, help, mandatory;
  42.   char fname[2*FILELEN];
  43. #if PC
  44.   int val;
  45. #endif
  46.  
  47.   switch (ftype) {
  48.   case 'I':
  49.     mandatory = 0;
  50.     break;
  51.   case 'S':
  52.   case 'C':
  53.     mandatory = 1;
  54.     break;
  55.   default: /* shouldn't */
  56. #if PC
  57.     clrscr1(1);
  58.     gotoxy(1, 5);
  59.     cprintf("%sgetipfile:  Illegal ftype=<%c>", tab, ftype);
  60.     gotoxy(1, 7);
  61.     cprintf("%s            Sorry, aborting.", tab);
  62.     printexit(329);
  63. #else
  64.     printf("\tgetipfile:  Illegal ftype=<%c>\n", ftype);
  65.     printf("\t            Sorry, aborting.\n");
  66. #endif
  67.   } /* switch */
  68.  
  69. #if (DEBUG > 4)
  70. #if PC
  71.   clrscr1(1);
  72.   gotoxy(1, 5);
  73.   cprintf("%sin getipfile:", tab);
  74.   gotoxy(1, 7);
  75.   cprintf("%sipfil=<%s>", tab2, ipfil);
  76.   gotoxy(1, 8);
  77.   cprintf("%siptype=<%c>", tab2, iptype);
  78.   gotoxy(1, 9);
  79.   cprintf("%sftype=<%c>", tab2, ftype);
  80.   hitreturn(1);
  81. #endif
  82. #endif
  83.   if (iptype == 'F')
  84.     /* filename supplied in var ipfile */
  85.     strcpy(fname, ipfil);
  86.   else {
  87.     /* get a filename interactively;
  88.        user-friendly asking-message printed by calling function    */
  89. #if PC
  90.     val = getusrstr(fname);
  91.     if (HARDCOPY)
  92.       fprintf(stdprn, "%s\n", fname);
  93.     if (val) return(val);
  94. #else
  95.     getusrstr(fname);
  96. #endif
  97.     if (FILEq && FILECOPY)
  98.       fprintf(fpout, "%s\n", fname);
  99.   }
  100.  
  101.   /* strip input string of leading/trailing whitespace */
  102.   stripwhitesp(&fname[0]);
  103.  
  104.   go = 1;
  105.   while (go && ((*pfp = fopen(fname, "r"))==NULL)) {
  106.     if ((ftype=='C') || (ftype=='S')) {
  107. #if (DEBUG > 4)
  108. #if PC
  109.       clrscr1(1);
  110.       gotoxy(1, 5);
  111.       cprintf("%sfile <%s> not opened", tab, fname);
  112.       hitreturn(1);
  113. #else
  114.       printf("\tfile <%s> not opened\n", fname);
  115. #endif
  116. #endif
  117.       helpipfil(ftype);
  118.       printexit(330);
  119.     } else {
  120.       if (fname[0]=='?') {
  121.     help = 1;
  122.     helpipfil1(ipfil);
  123.       } else {
  124.     help = 0;
  125.       }
  126.     }
  127.  
  128.     if (! mandatory) {
  129. #if PC
  130.       clrscr1(3);
  131.       gotoxy(1, 1);
  132.       if (! help) {
  133.     printf("%s%s: File ", tab, ERRSTR);
  134.     printf("<%s> cannot be opened.", fname);
  135.     gotoxy(1, 2);
  136.       }
  137.       cprintf("%sPlease enter a new filename, or", tab);
  138.       gotoxy(1, 3);
  139.       cprintf("%s  type <Enter> if no file is desired.", tab);
  140.       clrscr1(2);
  141.       cprintf("%sNew filename:", tab);
  142.       gotoxy(1, 2);
  143.       highvideo();
  144.       cprintf("%s%c%c%c ", tab2, HBAR, HBAR, RTRI);
  145.       normvideo();
  146.       val = getusrstr(fname);
  147.       stripwhitesp(&fname[0]);
  148.       if (HARDCOPY) {
  149.     if (! help) {
  150.       fprintf(stdprn, "\n\t%s: File ", ERRSTR);
  151.       fprintf(stdprn, "<%s> cannot be opened.\n", fname);
  152.     }
  153.     fprintf(stdprn, "\tPlease enter a new filename, or\n");
  154.     fprintf(stdprn, "\t  type <Enter> if no file is desired.\n");
  155.     fprintf(stdprn, "\t\t==> ");
  156.     fprintf(stdprn, "%s\n", fname);
  157.       }
  158.       if (val) return(val);
  159. #else
  160.       if (! help) {
  161.     printf("\n\t%s: File ", ERRSTR);
  162.     printf("<%s> cannot be opened.\n", fname);
  163.       }
  164.       printf("\tPlease enter a new filename, or\n");
  165.       printf("\t  type <Enter> if no file is desired.\n");
  166.       printf("\t\t==> ");
  167.       getusrstr(fname);
  168.       stripwhitesp(&fname[0]);
  169. #endif
  170.       if (FILEq && FILECOPY) {
  171.     if (! help) {
  172.       fprintf(fpout, "\n\t%s: File ", ERRSTR);
  173.       fprintf(fpout, "<%s> cannot be opened.\n", fname);
  174.     }
  175.     fprintf(fpout, "\tPlease enter a new filename, or");
  176.     fprintf(fpout, "\t  type <Enter> if no file is desired.\n");
  177.     fprintf(fpout, "\t\t==> ");
  178.     fprintf(fpout, "%s\n", fname);
  179.       }
  180.       /* not mandatory:  can enter no filename */
  181.       if (strlen(fname)==0)
  182.     go = 0;
  183.  
  184.     } else {         /* mandatory: animal file: fail! */
  185. #if PC
  186.       clrscr1(1);
  187.       gotoxy(1, 5);
  188.       cprintf("%sgetipfile:  Internal error: File <%s> ", tab, fname);
  189.       cprintf("cannot be opened.");
  190.       gotoxy(1, 7);
  191.       cprintf("%s            Sorry, aborting.", tab);
  192.       if (HARDCOPY) {
  193.     fprintf(stdprn, "\t%s:  Internal error: File <%s> ", ERRSTR, fname);
  194.     fprintf(stdprn, "cannot be opened.\n\tSorry, aborting.\n\n");
  195.       }
  196. #else
  197.       printf("\t%s:  Internal error: File <%s> ", ERRSTR, fname);
  198.       printf("cannot be opened.\n\tSorry, aborting.\n\n");
  199. #endif
  200.       if (FILEq && FILECOPY) {
  201.     fprintf(fpout, "\t%s:  Internal error: File <%s> ", ERRSTR, fname);
  202.     fprintf(fpout, "cannot be opened.\n\tSorry, aborting.\n\n");
  203.       }
  204.       printexit(331);
  205.     } /* if mandatory */
  206.   } /* while */
  207.  
  208. #if (DEBUG > 4)
  209. #if PC
  210.   clrscr1(1);
  211.   gotoxy(1, 5);
  212.   cprintf("%sgetipfile: done with while loop", tab);
  213.   hitreturn(1);
  214. #else
  215.   printf("\tgetipfile: done with while loop\n");
  216. #endif
  217. #endif
  218.  
  219.   if (go==0) {
  220.     /* no file necessary */
  221. #if PC
  222.     clrscr1(3);
  223.     cprintf("%sNo batch file opened; input must be entered interactively.", tab);
  224.     if (HARDCOPY)
  225.       fprintf(stdprn, "\n\tNo batch file opened; input must be entered interactively.\n");
  226.     hitreturn(1);
  227. #else
  228.     printf("\n\tNo batch file opened; input must be entered interactively.\n");
  229. #endif
  230.     if (FILEq && FILECOPY)
  231.       fprintf(fpout, "\n\tNo batch file opened; input must be entered interactively.\n");
  232.  
  233. #if (DEBUG > 4)
  234. #if PC
  235.     clrscr1(1);
  236.     gotoxy(1, 5);
  237.     cprintf("%sfile <%s> not opened", tab, fname);
  238.     hitreturn(1);
  239. #else
  240.     printf("\tfile <%s> not opened\n", fname);
  241. #endif
  242. #endif
  243.     return(1);
  244.   } else {
  245. #if (DEBUG > 4)
  246. #if PC
  247.     clrscr1(1);
  248.     gotoxy(1, 5);
  249.     cprintf("%sfile <%s> opened", tab, fname);
  250.     hitreturn(1);
  251. #else
  252.     printf("\tfile <%s> opened\n", fname);
  253. #endif
  254. #endif
  255.     return(0);        /* good file opened */
  256.   } /* *pfp != NULL */
  257. } /* getipfile */
  258.  
  259. /********************************/
  260. /*     function: getstgdat    */
  261. /********************************/
  262. /* reads from the file xxx.stg to get the cycle stage data */
  263. getstgdat (stgfil, fpstg)
  264.   char *stgfil;
  265.   FILE *fpstg;
  266. {
  267.   int i;
  268.   static int once=0;    /* =1 if malloc'd once already        */
  269. #if (DEBUG > 4)
  270.   long int j;
  271. #endif
  272.  
  273.   /* if gotstgdat at least once already, free up allo'c space */
  274.   if (once) {
  275.     free1((char *) stage);
  276. #if (DEBUG > 4)
  277. #if PC
  278.     clrscr1(1);
  279.     gotoxy(1, 3);
  280.     cprintf("%sgetstgdat:  free(stage)", tab);
  281.     hitreturn(1);
  282. #else
  283.     printf("\tgetstgdat:  free(stage)\n");
  284. #endif
  285.   } else {
  286. #if PC
  287.     clrscr1(1);
  288. #else
  289.     printf("\tgetstgdat:  stage not freed\n");
  290. #endif
  291. #endif
  292.   } /* else */
  293.  
  294.   /* read cycle time - this is in days */
  295.   fscanf(fpstg, "%lf", &CycleTime);
  296.   /* DefaultCycleTime is always that value read from the *.stg file */
  297.   DefaultCycleTime = CycleTime;
  298. #if PC
  299.   printCycleTime();        /* turn on Cycle Length annunciator */
  300. #endif
  301.   OldCycleTime = CycleTime;        /* initialize OldCycleTime */
  302.   fscanf(fpstg, "%d", &NumStages);
  303.   MaxStage = NumStages - 1;
  304.  
  305. #if (PC && (DEBUG > 4))
  306.   makeactivewin(1);
  307.   gotoxy(1, 5);
  308.   cprintf("%sgetstgdat:  getting data from file <%s>", tab, stgfil);
  309.   gotoxy(1, 6);
  310.   cprintf("%s            CycleTime = <%lf>", tab, CycleTime);
  311.   gotoxy(1, 7);
  312.   cprintf("%s            NumStages = <%d>", tab, NumStages);
  313.   gotoxy (1, 8);
  314.   cprintf("%sgetstgdat:  beg: core left = %lu", tab, coreleft());
  315.   hitreturn(1);
  316. #endif
  317.  
  318.   /* allocate NumStages spaces for stage lengths */
  319.   stage = (double *) malloc((unsigned) (NumStages * sizeof(double)));
  320.   if (stage==NULL) {
  321. #if PC
  322.     makeactivewin(1);
  323.     gotoxy(1, 9);
  324.     cprintf("%sgetstgdat:  malloc returns NULL on stage", tab);
  325. #else
  326.     printf("\tgetstgdat:  malloc returns NULL on stage\n");
  327. #endif
  328.     printexit(332);
  329.   } /* if */
  330.  
  331. #if (PC && (DEBUG > 4))
  332.   makeactivewin(1);
  333.   gotoxy(1, 9);
  334.   cprintf("%sgetstgdat:  mid: core left = %lu", tab, coreleft());
  335.   hitreturn(1);
  336. #endif
  337.  
  338.   /* read stage lengths (these are in % of CycleTime) and convert to days */
  339.   for ( i=0; i<NumStages; i++ ) {
  340.     fscanf(fpstg, "%lf", &stage[i]);
  341.     stage[i] = stage[i] * CycleTime / 100;
  342. #if (DEBUG > 4)
  343. #if PC
  344.     makeactivewin(1);
  345.     gotoxy(1, 10);
  346.     clreol1(1);
  347.     gotoxy(1, 10);
  348.     cprintf("%sgetstgdat:  stage[%d]=<%lf>", tab, i, stage[i]);
  349.     for ( j=0; j<TIME; j++);
  350. #else
  351.     printf("\t         :  stage[%d]=<%lf>\n", i, stage[i]);
  352. #endif
  353. #endif
  354.   } /* for i */
  355.  
  356.   /* read epididymis transit times (this is days) */
  357.   fscanf(fpstg, "%lf", &EpiTime);
  358.  
  359. #if (PC && (DEBUG > 4))
  360.   makeactivewin(1);
  361.   gotoxy(1, 11);
  362.   cprintf("%sgetstgdat:  EpiTime = <%lf>", tab, EpiTime);
  363.   gotoxy(1, 12);
  364.   cprintf("%sgetstgdat:  end: core left = %lu", tab, coreleft());
  365.   hitreturn(1);
  366. #endif
  367.  
  368.   once = 1;
  369.   return(0);
  370. } /* getstgdat */
  371.  
  372. /********************************/
  373. /*     function: getCyclelen    */
  374. /********************************/
  375. /* asks user to input new CycleTime, or use default */
  376. getCyclelen ()
  377. {
  378.   char dummy[MAXLEN];        /* user input string */
  379.   int i, val, ok;
  380.  
  381.   ok = 0;
  382.   while (! ok) {
  383. #if PC
  384.     clrscr1(2);
  385.     cprintf("%sNew Cycle Length (in days):", tab);
  386.     gotoxy(1, 2);
  387.     highvideo();
  388.     cprintf("%s%c%c%c ", tab2, HBAR, HBAR, RTRI);
  389.     normvideo();
  390.     val = getusrstr(dummy);
  391.     if (HARDCOPY) {
  392.       fprintf(stdprn, "\n\tNew Cycle Length (in days):\n");
  393.       fprintf(stdprn, "\t\t==> %s\n\n", dummy);
  394.     }
  395.     if (val) return(val);        /* keyboard accel pressed */
  396. #else
  397.     printf("\n\tNew Cycle Length (in days):\n");
  398.     printf("\t\t==> ");
  399.     getusrstr(dummy);
  400. #endif
  401.  
  402.     if (FILEq && FILECOPY) {
  403.       fprintf(fpout, "\n\tNew Cycle Length (in days):\n");
  404.       fprintf(fpout, "\t\t==> %s\n\n", dummy);
  405.     }
  406.     switch (dummy[0]) {
  407.     case '?':
  408.       helpcyclelenip();
  409.       break;
  410.     default:  /* it's a new Cycle length, if it's a valid # */
  411.       if (! numstrq(dummy)) {
  412. #if PC
  413.         clrscr1(3);
  414.         cprintf("%s%s:  Invalid number syntax <%s>", tab, ERRSTR, dummy);
  415.         if (HARDCOPY) {
  416.           fprintf(stdprn, "\t%s:  Invalid number syntax <%s>.\n",
  417.                   ERRSTR, dummy);
  418.         }
  419. #else
  420.         printf("\t%s:  Invalid number syntax <%s>.\n", ERRSTR, dummy);
  421. #endif
  422.         if (FILEq && FILECOPY) {
  423.           fprintf(fpout, "\t%s:  Invalid number syntax <%s>.\n",
  424.                   ERRSTR, dummy);
  425.         }
  426.       } else {  /* it's a valid number input */
  427.     OldCycleTime = CycleTime;
  428.         CycleTime = atof(dummy);
  429.     ok = 1;
  430.     NewCycleTime = 1;        /* global var */
  431.     /* set Cycle length annunciator */
  432. #if PC
  433.     printCycleTime();
  434. #endif
  435.     /* transform old stage[i] vals (days) to new ones */
  436.     for ( i=0; i<NumStages; i++ )
  437.       stage[i] = stage[i] * CycleTime / OldCycleTime;
  438.       } /* if numstr) */
  439.     } /* dummy != ? */
  440.   } /* while ! ok */
  441.   return(0);
  442. } /* getCyclelen */
  443.  
  444. /********************************/
  445. /*     function: getseqdat    */
  446. /********************************/
  447. /* reads from the file xxx.seq to get the cell sequence data */
  448. getseqdat (seqfil, fpseq)
  449.   char *seqfil;
  450.   FILE *fpseq;
  451. {
  452.   int i;        /* char array indices            */
  453.   char temp[MAXLEN];    /* temp str: holds CellNames         */
  454.   static int once=0;    /* =1 if gotseqdat once already        */
  455. #if (DEBUG > 4)
  456.   long int j;
  457. #endif
  458.  
  459.   /* if gotseqdat at least once already, free up alloc'd space */
  460.   if (once) {
  461.     /* free each CellNames[i], incl. CellNames[MaxCellSeq+1] =
  462.        CellNames[NumCellSeq] = Epididymis */
  463.     for ( i=0; i<=NumCellSeq; i++ ) {
  464.       free1((char *) CellNames[i]);
  465. #if (DEBUG > 4)
  466. #if PC
  467.       clrscr1(1);
  468.       gotoxy(1, 2);
  469.       clreol1(1);
  470.       gotoxy(1, 2);
  471.       cprintf("%sgetseqdat:  free(CellNames[%d])", tab, i);
  472.       for ( j=0; j<TIME; j++ );
  473. #else
  474.       printf("\tgetseqdat:  free(CellNames[%d])\n", i);
  475. #endif
  476. #endif
  477.     } /* for i */
  478.  
  479.     /* free CellNames ptr itself */
  480.     free1((char *) CellNames);
  481. #if (DEBUG > 4)
  482. #if PC
  483.     makeactivewin(1);
  484.     gotoxy(1, 3);
  485.     cprintf("%sgetseqdat:  free(CellNames)", tab);
  486. #else
  487.     printf("\tgetseqdat:  free(CellNames)\n");
  488. #endif
  489. #endif
  490.  
  491.   } else {
  492. #if PC
  493.     clrscr1(1);
  494. #else
  495.     printf("\tgetseqdat:  CellNames not freed\n");
  496. #endif
  497.   } /* else */
  498.  
  499.   /* determine number of cells in cell sequence */
  500.   NumCellSeq = 0;
  501.   while (fscanf(fpseq, "%s", temp) != EOF)
  502.     NumCellSeq++;
  503.   /* subtract epididymis time and CycleStart: not part of the cycle */
  504.   NumCellSeq -= 2;
  505.   MaxCellIndex = NumCellSeq - 1;
  506.  
  507. #if (DEBUG > 4)
  508. #if PC
  509.   makeactivewin(1);
  510.   gotoxy(1, 4);
  511.   cprintf("%sgetseqdat:  getting data from file <%s>", tab, seqfil);
  512.   gotoxy(1, 5);
  513.   cprintf("%sgetseqdat:   NumCellSeq=%d", tab, NumCellSeq);
  514.   gotoxy(1, 6);
  515.   cprintf("%s           MaxCellIndex=%d", tab, MaxCellIndex);
  516.   gotoxy(1, 7);
  517.   cprintf("%sgetseqdat:  beg: core left = %lu", tab, coreleft());
  518.   hitreturn(1);
  519. #else
  520.   printf("\tgetseqdat:   NumCellSeq=%d\n", NumCellSeq);
  521.   printf("\t           MaxCellIndex=%d\n", MaxCellIndex);
  522. #endif
  523. #endif
  524.  
  525.   /* allocate NumCellSeq+1 spaces for cell names, "+1" for epididymis */
  526.   CellNames = (char **) malloc((unsigned) ((NumCellSeq+1) * sizeof(char *)));
  527.   if (CellNames==NULL) {
  528. #if PC
  529.     makeactivewin(1);
  530.     gotoxy(1, 8);
  531.     cprintf("%sgetseqdat:  malloc returns NULL on CellNames", tab);
  532. #else
  533.     printf("\tgetseqdat:  malloc returns NULL on CellNames\n");
  534. #endif
  535.     printexit(333);
  536.   } /* if */
  537.  
  538. #if (PC && (DEBUG > 4))
  539.   makeactivewin(1);
  540.   gotoxy(1, 8);
  541.   cprintf("%sgetseqdat:  mid: core left = %lu", tab, coreleft());
  542.   hitreturn(1);
  543. #endif
  544.  
  545.   /* read cell name strings from *.seq file, assign to CellNames[i] */
  546.   rewind(fpseq);
  547.   for ( i=0; i<NumCellSeq; i++ ) {
  548.     fscanf(fpseq, "%s", temp);
  549.     strupper(temp);
  550.     CellNames[i] = strdup(temp);    /* does AUTOmagic malloc */
  551.     if (CellNames[i]==NULL) {
  552. #if PC
  553.       makeactivewin(1);
  554.       gotoxy(1, 9);
  555.       clreol1(1);
  556.       gotoxy(1, 9);
  557.       cprintf("%sgetseqdat:  strdup returns NULL on CellNames[%d]", tab, i);
  558. #else
  559.       printf("\tgetseqdat:  strdup returns NULL on CellNames[%d]\n", i);
  560. #endif
  561.       printexit(334);
  562.     } /* if */
  563.  
  564. #if (DEBUG > 4)
  565. #if PC
  566.     makeactivewin(1);
  567.     gotoxy(1, 9);
  568.     clreol1(1);
  569.     gotoxy(1, 9);
  570.     cprintf("%sgetseqdat:           temp=<%s>", tab, temp);
  571.     gotoxy(1, 10);
  572.     clreol1(1);
  573.     gotoxy(1, 10);
  574.     cprintf("%s            CellNames[%2d]=<%s>", tab, i, CellNames[i]);
  575.     for ( j=0; j<TIME; j++ );
  576. #else
  577.     printf("\tgetseqdat:           temp=<%s>\n", temp);
  578.     printf("\t            CellNames[%2d]=<%s>\n", i, CellNames[i]);
  579. #endif
  580. #endif
  581.   } /* for i */
  582.  
  583.   /* get "epididymis" name string */
  584.   fscanf(fpseq, "%s", temp);
  585.   CellNames[MaxCellIndex+1] = strdup(temp);    /* does AUTOmagic malloc */
  586.   if (CellNames[MaxCellIndex+1]==NULL) {
  587. #if PC
  588.     makeactivewin(1);
  589.     gotoxy(1, 11);
  590.     cprintf("%sgetseqdat:  strdup returns NULL on CellNames[%d]",
  591.         tab, MaxCellIndex+1);
  592. #else
  593.     printf("\tgetseqdat:  strdup returns NULL on CellNames[%d]\n",
  594.        MaxCellIndex+1);
  595. #endif
  596.     printexit(335);
  597.   } /* if */
  598.  
  599.   /* get CycleStart cell # */
  600.   fscanf(fpseq, "%d", &CycleStart);
  601.  
  602. #if (PC && (DEBUG > 4))
  603.   makeactivewin(1);
  604.   gotoxy(1, 11);
  605.   cprintf("%sgetseqdat:  end: core left = %lu", tab, coreleft());
  606.   hitreturn(1);
  607. #endif
  608.  
  609.   once = 1;
  610.   return(0);
  611. } /* getseqdat */
  612.  
  613. /********************************/
  614. /*     function: getmcldat    */
  615. /********************************/
  616. /* reads from file xxx.mcl to get data on stages which have
  617.    >1 possible cell, depending on which third of the stage
  618.    the movement ends up in */
  619. getmcldat (mclfil, fpmcl)
  620.   char *mclfil;
  621.   FILE *fpmcl;
  622. {
  623.   int i, j;
  624.   char temp[MAXLEN];        /* temp string for cellnames     */
  625.   static int once=0;        /* =1 if malloc'd once already    */
  626. #if (DEBUG > 4)
  627.   long int k;
  628. #endif
  629.  
  630.   /* if gotmcldat at least once already, free up alloc'd space */
  631.   if (once) {
  632.     /* free up each MultiCellNames[i][j] */
  633.     for ( i=0; i<NumMultiCells; i++ ) {
  634.       for ( j=0; j<3; j++ ) {
  635.     free1((char *) MultiCellNames[i][j]);
  636. #if (DEBUG > 4)
  637. #if PC
  638.     clrscr1(1);
  639.     gotoxy(1, 2);
  640.     clreol1(1);
  641.     gotoxy(1, 2);
  642.     cprintf("%sgetmcldat:  free(MultiCellNames[%d][%d])", tab, i, j);
  643.     for ( k=0; k<TIME; k++ );
  644. #else
  645.     printf("\tgetmcldat:  free(MultiCellNames[%d][%d])\n", i, j);
  646. #endif
  647. #endif
  648.       } /* for j */
  649.     } /* for i */
  650.  
  651.     /* free each MultiCellNames[i] and MultiCellNames[i][j] */
  652.     for ( i=0; i<NumMultiCells; i++ ) {
  653.       free1((char *) MultiCellNames[i]);
  654. #if (DEBUG > 4)
  655. #if PC
  656.       makeactivewin(1);
  657.       gotoxy(1, 3);
  658.       clreol1(1);
  659.       gotoxy(1, 3);
  660.       cprintf("%sgetmcldat:  free(MultiCellNames[%d])", tab, i);
  661.       for ( k=0; k<TIME; k++ );
  662. #else
  663.       printf("\tgetmcldat:  free(MultiCellNames[%d])\n", i);
  664. #endif
  665. #endif
  666.     } /* for i */
  667.  
  668.     /* free MultiCellNames itself */
  669.     free1((char *) MultiCellNames);
  670. #if (DEBUG > 4)
  671. #if PC
  672.     makeactivewin(1);
  673.     gotoxy(1, 4);
  674.     cprintf("%sgetmcldat:  free(MultiCellNames)", tab);
  675. #else
  676.     printf("\tgetmcldat:  free(MultiCellNames)\n");
  677. #endif
  678. #endif
  679.  
  680.   } else {
  681. #if PC
  682.     clrscr1(1);
  683. #else
  684.     printf("\tgetmcldat:  MultiCellNames not freed\n");
  685. #endif
  686.   } /* else */
  687.  
  688.   /* get new multicell data */
  689.   fscanf(fpmcl, "%d", &NumMultiCells);
  690.  
  691. #if (DEBUG > 4)
  692. #if PC
  693.   makeactivewin(1);
  694.   gotoxy(1, 6);
  695.   cprintf("%sgetmcldat:  getting data from file <%s>", tab, mclfil);
  696.   gotoxy(1, 7);
  697.   cprintf("%sgetmcldat:  NumMultiCells=%d", tab, NumMultiCells);
  698.   gotoxy(1, 8);
  699.   cprintf("%sgetmcldat:  beg: core left = %lu", tab, coreleft());
  700.   hitreturn(1);
  701. #else
  702.   printf("\tgetmcldat:  NumMultiCells=%d\n", NumMultiCells);
  703. #endif
  704. #endif
  705.  
  706.   /* allocate NumMultiCells spaces for cell names */
  707.   MultiCellNames =
  708.     (char ***) malloc((unsigned) (NumMultiCells * sizeof(char *)));
  709.   if (MultiCellNames==NULL) {
  710. #if PC
  711.     makeactivewin(1);
  712.     gotoxy(1, 9);
  713.     cprintf("%sgetmcldat:  malloc returns NULL on MultiCellNames", tab);
  714. #else
  715.     printf("\tgetmcldat:  malloc returns NULL on MultiCellNames\n");
  716. #endif
  717.     printexit(336);
  718.   } /* if */
  719.  
  720.   for ( i=0; i<NumMultiCells; i++ ) {
  721.     MultiCellNames[i] = (char **) malloc((unsigned) (3 * sizeof(char *)));
  722.       /* 3 because there are 3 thirds in a stage, depending on where the
  723.      movement ends in the stage, use MultiCellName[i][third] */
  724.     if (MultiCellNames[i]==NULL) {
  725. #if PC
  726.       makeactivewin(1);
  727.       gotoxy(1, 9);
  728.       cprintf("%sgetmcldat:  malloc returns NULL on MultiCellNames[%d]",
  729.           tab, i);
  730. #else
  731.       printf("\tgetmcldat:  malloc returns NULL on MultiCellNames[%d]\n", i);
  732. #endif
  733.       printexit(337);
  734.     } /* if */
  735.   } /* for i */
  736.  
  737. #if (PC && (DEBUG > 4))
  738.   makeactivewin(1);
  739.   gotoxy(1, 9);
  740.   cprintf("%sgetmcldat:  mid: core left = %lu", tab, coreleft());
  741.   hitreturn(1);
  742. #endif
  743.  
  744.   for ( i=0; i<NumMultiCells; i++ ) {
  745.     for ( j=0; j<3; j++ ) {
  746.       fscanf(fpmcl, "%s", temp);
  747.       strupper(temp);
  748.       MultiCellNames[i][j] = strdup(temp);    /* does AUTOmagic malloc */
  749.       if (MultiCellNames[i][j]==NULL) {
  750. #if PC
  751.     makeactivewin(1);
  752.     gotoxy(1, 10);
  753.     cprintf("%sgetmcldat:  strdup returns NULL on MultiCellNames[%d][%d]",
  754.           tab, i, j);
  755. #else
  756.     printf("\tgetmcldat:  strdup returns NULL on MultiCellNames[%d][%d]\n",
  757.          i, j);
  758. #endif
  759.     printexit(338);
  760.       } /* if */
  761. #if (DEBUG > 4)
  762. #if PC
  763.       makeactivewin(1);
  764.       gotoxy(1, 10);
  765.       clreol1(1);
  766.       gotoxy(1, 10);
  767.       cprintf("%sgetmcldat:                  temp=<%s>", tab, temp);
  768.       gotoxy(1, 11);
  769.       clreol1(1);
  770.       gotoxy(1, 11);
  771.       cprintf("%s            MultiCellNames[%d][%d]=<%s>",
  772.            tab, i, j, MultiCellNames[i][j]);
  773.       for ( k=0; k<TIME; k++ );
  774. #else
  775.       printf("\tgetmcldat: \n");
  776. #endif
  777. #endif
  778.     } /* for j */
  779.   } /* for i */
  780.  
  781. #if (PC && (DEBUG > 4))
  782.   makeactivewin(1);
  783.   gotoxy(1, 12);
  784.   cprintf("%sgetmcldat:  end: core left = %lu", tab, coreleft());
  785.   hitreturn(1);
  786. #endif
  787.  
  788.   once = 1;
  789.   return(0);
  790. } /* getmcldat */
  791.  
  792. #if PC
  793. /********************************/
  794. /*     function: getusrstr    */
  795. /********************************/
  796. /* gets one user input string: PC version
  797.    checks to see if an F-key was typed
  798.  
  799.    bioskey() described in turbo c v2.0 ref guide
  800.    bit manipulations from _the peter norton programmer's
  801.    guide to the ibm pc_, pp127-135, microsoft press, 1985
  802.  
  803.    return 0 if string input
  804.    return 100+k if F-k pressed */
  805. getusrstr (input)
  806.   char *input;        /* char str input if no F key    */
  807. {
  808.   int key;        /* 32-bit val of key pressed     */
  809.   int keylo;        /* key bits 0-7            */
  810.   int keyhi;        /* key bits 8-15        */
  811.   int i, go, x, y;
  812.  
  813.   i = 0;
  814.   go = 1;
  815.   y = wherey();
  816.   while (go) {
  817.     while (bioskey(1)==0);        /* sit & spin */
  818.     x = wherex();
  819.     key = bioskey(0);
  820.     keylo = key & 0x000000FF;
  821.     keyhi = (key & 0x0000FF00) >> 8;    /* right shift 8 bits */
  822.     switch (keylo) {
  823.     case 0:    /* Fkey? */
  824.       switch (keyhi) {
  825.       case 59:        /* F1 */
  826.     return(101);
  827.       case 60:        /* F2 */
  828.     return(102);
  829.       case 61:        /* F3 */
  830.     return(103);
  831.       case 62:        /* F4 */
  832.     return(104);
  833.       case 63:        /* F5 */
  834.     return(105);
  835.       case 64:        /* F6 */
  836.     return(106);
  837.       case 65:        /* F7 */
  838.     return(107);
  839.       case 66:        /* F8 */
  840.     return(108);
  841.       case 67:        /* F9 */
  842.     return(109);
  843.       case 68:        /* F10 */
  844.     return(110);
  845.       default:        /* undefined special key */
  846.     input[0] = '\0';
  847.     return(200);
  848.       } /* switch */
  849.     case 8:    /* backspace */
  850.       if (i > 0) {
  851.     i--;
  852.     gotoxy(x-1, y);
  853.     clreol1(2);
  854.     gotoxy(x-1, y);
  855.       }
  856.       break;
  857.     case 10:
  858.     case 13:    /* CR/LF = return */
  859.       input[i] = '\0';
  860.       return(0);    /* success: got string */
  861.     case 9:
  862.     case 32:    /* kill spaces and tabs: single string input */
  863.       gotoxy(x, y);
  864.       printf("%c", keylo);
  865.       break;
  866.     default:    /* ASCII char */
  867.       gotoxy(x, y);
  868.       printf("%c", keylo);
  869.       input[i++] = keylo;
  870.     } /* switch keylo */
  871.   } /* while */
  872. } /* getusrstr */
  873.  
  874. #else
  875.  
  876. /********************************/
  877. /*     function: getusrstr    */
  878. /********************************/
  879. /* gets one user input string */
  880. getusrstr (input)
  881.   char *input;
  882. {
  883.   int i;
  884.   char c;
  885.  
  886.   i = 0;
  887.   while ((c=getc(stdin)) != '\n')
  888.     if (c != ' ')
  889.       input[i++] = c;
  890.   input[i] = '\0';
  891. } /* getusrstr */
  892. #endif
  893.