1: #include "parms.h"
   2: #include "structs.h"
   3: 
   4: #ifdef  RCSIDENT
   5: static char rcsid[] = "$Header: lrsp.c,v 1.7 85/01/18 15:16:05 notes Rel $";
   6: #endif	RCSIDENT
   7: 
   8: /*
   9:  *	this routine takes in a note number, the io descriptors and
  10:  *	and a LOGICAL response number to look for.
  11:  *	It the returns the physical response index locations.
  12:  *	It returns the response index record, and the offset within
  13:  *	that record for the correct response
  14:  *
  15:  *	Implemented the easy/cheap way. We just scan along the response
  16:  *	chain, counting up the undeleted responses.
  17:  *	Once we find the correct number, we return with the current
  18:  *	set of pointers. What could be easier?
  19:  *	In the event that we hit the end of responses before we find
  20:  *	the response we want (e.g. the dummy wanted a nonexistent response)
  21:  *	we return the index of the last response.
  22:  *
  23:  *	Returns:	0 if all goes well
  24:  *			-1 if bad logical response number
  25:  *
  26:  *	Ray Essick	May 22, 1981.
  27:  *
  28:  */
  29: 
  30: lrsp (io, notenum, resp, rrec, poffset, recnum)
  31: struct io_f *io;
  32: struct resp_f  *rrec;
  33: int    *recnum,
  34:        *poffset;
  35: {
  36:     struct note_f   nrec;               /* note descriptor */
  37:     int     prec;                   /* which physical response group we is looking in */
  38: 
  39:     getnrec (io, notenum, &nrec);           /* get the note info */
  40:     if (resp <= 0)
  41:     return (-1);                    /* that was dumb */
  42:     if (resp > nrec.n_nresp)
  43:     return (-1);                    /* this too was dumb of him */
  44:     prec = nrec.n_rindx;                /* record # of first response */
  45:     *poffset = 0;
  46: 
  47:     getrrec (io, prec, rrec);               /* first resp block */
  48:     while (resp > rrec -> r_last)           /* hi-speed along */
  49:     {
  50:     if ((prec = rrec -> r_next) == -1)
  51:         return (-1);                /* broken chain */
  52:     getrrec (io, prec, rrec);           /* passed this buffer */
  53:     }
  54:     /*
  55:      *	We should now be in the block that contains the response
  56:      */
  57:     {
  58:     register int    counted;
  59:     counted = (-1);                 /* active in this block */
  60:     *poffset = 0;                   /* start of block */
  61:     while (1)                   /* forever */
  62:     {
  63:         while (rrec -> r_stat[*poffset] & DELETED)  /* skip holes */
  64:         {
  65:         ++*poffset;             /* and try next */
  66:         x (*poffset == RESPSZ, "lrsp: r_last lied!");
  67:         }
  68:         counted++;                  /* a live one */
  69:         if (rrec -> r_first + counted == resp)  /* got it */
  70:         {
  71:         break;                  /* get out */
  72:         }
  73:         ++*poffset;                 /* on to next */
  74:         /*
  75: 	     * this above is legit since we KNOW the resp is in this
  76: 	     * block so we'll never go over the end
  77: 	     */
  78:     }
  79:     }
  80:     *recnum = prec;                 /* set up return */
  81:     return 0;
  82: }
Last modified: 1985-10-30
Generated: 2016-12-26
Generated by src2html V0.67
page hit count: 860
Valid CSS Valid XHTML 1.0 Strict