BSD 4_2 release
[unix-history] / usr / src / new / new / notes / src / lrsp.c
CommitLineData
0f4556f1
C
1static char *sccsid = "@(#)lrsp.c 1.1\t1/23/83";
2
3#include "parms.h"
4#include "structs.h"
5/*
6 * this routine takes in a note number, the io descriptors and
7 * and a LOGICAL response number to look for.
8 * It the returns the physical response index locations.
9 * It returns the response index record, and the offset within
10 * that record for the correct response
11 *
12 * Implemented the easy/cheap way. We just scan along the response
13 * chain, counting up the undeleted responses.
14 * Once we find the correct number, we return with the current
15 * set of pointers. What could be easier?
16 * In the event that we hit the end of responses before we find
17 * the response we want (e.g. the dummy wanted a nonexistent response)
18 * we return the index of the last response.
19 *
20 * Returns: 0 if all goes well
21 * -1 if bad logical response number
22 *
23 * Ray Essick May 22, 1981.
24 *
25 */
26
27lrsp (io, notenum, resp, rrec, poffset, recnum)
28struct io_f *io;
29struct resp_f *rrec;
30int *recnum,
31 *poffset;
32{
33 struct note_f nrec; /* note descriptor */
34 int prec; /* which physical response group we is looking in */
35
36 getnrec (io, notenum, &nrec); /* get the note info */
37 if (resp <= 0) {
38 return(-1); /* that was dumb */
39 }
40 if (resp > nrec.n_nresp) {
41 return(-1); /* this too was dumb of him */
42 }
43 prec = nrec.n_rindx; /* record # of first response */
44 *poffset = 0;
45
46 getrrec (io, prec, rrec); /* get the first response group */
47 while (resp) {
48 while (rrec->r_stat[*poffset] & DELETED) {
49 if (++*poffset == RESPSZ) {
50 *poffset = 0;
51 if ((prec = rrec->r_next) == -1) {
52 return(-1); /* broken chain */
53 }
54 getrrec (io, prec, rrec); /* passed this buffer */
55 }
56 }
57 if (--resp) {
58 rrec->r_stat[*poffset] |= DELETED; /* this is the wrong one. lets ignore it. */
59 }
60/* we can do this because we never write it back out to screw up others */
61 }
62 *recnum = prec; /* set up the response index for the return */
63 return(0);
64}