|
|
1.1 ! root 1: #include "parms.h" ! 2: #include "structs.h" ! 3: ! 4: #ifdef RCSIDENT ! 5: static char rcsid[] = "$Header: find.c,v 1.7.0.3 85/04/05 15:22:05 notes Rel $"; ! 6: #endif RCSIDENT ! 7: ! 8: /* ! 9: * chknote(io, noteid, note) ! 10: * see if a copy of the note specified by noteid is in the notefile ! 11: * returns the number of the note (0 if no note) ! 12: * NOTE: this routine is rather inefficient - since it ! 13: * will go through the entire file to discover that the note is ! 14: * not in the notefile... This should be done over so that the ! 15: * access is run somewhat better/faster.. ! 16: * ! 17: * Original Coding: Ray Essick December 1981 ! 18: */ ! 19: ! 20: chknote (io, noteid, note) ! 21: struct io_f *io; ! 22: struct id_f *noteid; ! 23: struct note_f *note; ! 24: { ! 25: register int i; ! 26: #ifdef IDCOMPAT ! 27: register int wantlen; /* length of wanted */ ! 28: register char *wantdomain; /* has "." */ ! 29: register int thislen; /* current id */ ! 30: register char *thisdomain; /* current id has . */ ! 31: register int shortlen; /* shorter */ ! 32: #endif IDCOMPAT ! 33: ! 34: #ifdef IDCOMPAT ! 35: wantlen = strlen (noteid -> sys); ! 36: wantdomain = index (noteid -> sys, '.'); ! 37: #endif IDCOMPAT ! 38: ! 39: for (i = io -> descr.d_nnote; i > 0; i--) /* dups likely "new" */ ! 40: { /* so search backwards */ ! 41: getnrec (io, i, note); ! 42: if (note -> n_stat & DELETED) ! 43: continue; /* ignore deleted */ ! 44: if (noteid -> uniqid == note -> n_id.uniqid) /* cheap to do */ ! 45: { ! 46: if (strcmp (noteid -> sys, note -> n_id.sys) == 0)/* more costly */ ! 47: { ! 48: return (i); ! 49: } ! 50: #ifdef IDCOMPAT ! 51: /* ! 52: * check for truncated or otherwise mangled ids ! 53: * THIS CODE IS NOT WELL TESTED AND PROBABLY DOESN'T WORK ! 54: * QUITE RIGHT. ! 55: */ ! 56: thislen = strlen (note -> n_id.sys); ! 57: thisdomain = index (note -> n_id.sys, '.'); ! 58: shortlen = thislen < wantlen ? thislen : wantlen;/* get short */ ! 59: if (thisdomain == (char *) NULL || wantdomain == (char *) NULL) ! 60: { /* undomained */ ! 61: if (strncmp (note -> n_id.sys, noteid -> sys, shortlen) == 0) ! 62: return (i); /* found */ ! 63: } ! 64: if (shortlen == OLDSYSSZ - 1 || shortlen == OLDSYSSZ) ! 65: { /* old format chop */ ! 66: if (strncmp (note -> n_id.sys, noteid -> sys, shortlen) == 0) ! 67: return (i); /* found */ ! 68: } ! 69: if (strncmp (note -> n_id.sys, noteid -> sys, OLDSYSSZ - 1) == 0) ! 70: { /* match in 1st 10 */ ! 71: return (i); ! 72: } ! 73: #endif IDCOMPAT ! 74: } ! 75: } ! 76: return (0); /* not found */ ! 77: } ! 78: ! 79: /* ! 80: * chkresp(io, respid, note, notenum) ! 81: * check the specified response to see if a response exists with ! 82: * the specified unique identifier ! 83: * ! 84: * This too can be speeded up similarly to the chknote routine.. ! 85: * but we shall worry about it later..after it already works. ! 86: * ! 87: * Original Coding: Ray Essick December 1981 ! 88: */ ! 89: ! 90: chkresp (io, respid, note, notenum) ! 91: struct io_f *io; ! 92: struct id_f *respid; ! 93: struct note_f *note; ! 94: { ! 95: struct resp_f rrec; ! 96: int roffset, ! 97: rrecnum; ! 98: register int i; ! 99: register int prec; ! 100: register int poffset; ! 101: #ifdef IDCOMPAT ! 102: register int wantlen; /* length of wanted */ ! 103: register char *wantdomain; /* has "." */ ! 104: register int thislen; /* current id */ ! 105: register char *thisdomain; /* current id has . */ ! 106: register int shortlen; /* shorter */ ! 107: #endif IDCOMPAT ! 108: ! 109: if (note -> n_nresp <= 0) /* no responses */ ! 110: return (0); /* so it can't be there */ ! 111: #ifdef IDCOMPAT ! 112: wantlen = strlen (respid -> sys); /* get constants */ ! 113: wantdomain = index (respid -> sys, '.'); ! 114: #endif IDCOMPAT ! 115: prec = note -> n_rindx; /* get first block */ ! 116: poffset = 0; ! 117: getrrec (io, prec, &rrec); ! 118: for (i = 1; i <= note -> n_nresp; i++) /* through responses */ ! 119: { ! 120: while (rrec.r_stat[poffset] & DELETED) ! 121: { /* skip deleted ones */ ! 122: if (++poffset == RESPSZ) ! 123: { ! 124: poffset = 0; ! 125: if ((prec = rrec.r_next) == -1) ! 126: return (0); /* broken chain */ ! 127: getrrec (io, prec, &rrec); /* passed this buffer */ ! 128: } ! 129: } ! 130: if (respid -> uniqid == rrec.r_id[poffset].uniqid) ! 131: { ! 132: if (strcmp (respid -> sys, rrec.r_id[poffset].sys) == 0) ! 133: { ! 134: return (i); /* return resp number */ ! 135: } ! 136: #ifdef IDCOMPAT ! 137: /* ! 138: * check for truncated and otherwise mangled id's ! 139: */ ! 140: thislen = strlen (rrec.r_id[poffset].sys); ! 141: thisdomain = index (rrec.r_id[poffset].sys, '.'); ! 142: shortlen = thislen < wantlen ? thislen : wantlen;/* shorter */ ! 143: if (thisdomain == (char *) NULL || wantdomain == (char *) NULL) ! 144: { /* undomained */ ! 145: if (strncmp (respid -> sys, rrec.r_id[poffset].sys, shortlen) == 0) ! 146: return (i); ! 147: } ! 148: if (shortlen == OLDSYSSZ - 1 || shortlen == OLDSYSSZ) ! 149: { /* old format chop */ ! 150: if (strncmp (respid -> sys, rrec.r_id[poffset].sys, shortlen) == 0) ! 151: return (i); ! 152: } ! 153: if (strncmp (respid -> sys, rrec.r_id[poffset].sys, OLDSYSSZ - 1) == 0) ! 154: { /* match first 10 */ ! 155: return (i); ! 156: } ! 157: #endif IDCOMPAT ! 158: } ! 159: rrec.r_stat[poffset] |= DELETED; /* force scan above */ ! 160: } ! 161: return (0); /* is not a response to this note */ ! 162: }
This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.