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: #define dprintf if (0) printf 21: 22: chknote (io, noteid, note) 23: struct io_f *io; 24: struct id_f *noteid; 25: struct note_f *note; 26: { 27: register int i; 28: #ifdef IDCOMPAT 29: register int wantlen; /* length of wanted */ 30: register char *wantdomain; /* has "." */ 31: register int thislen; /* current id */ 32: register char *thisdomain; /* current id has . */ 33: register int shortlen; /* shorter */ 34: #endif IDCOMPAT 35: 36: #ifdef IDCOMPAT 37: wantlen = strlen (noteid -> sys); 38: wantdomain = index (noteid -> sys, '.'); 39: dprintf ("wantlen %d, wantdomain %s\n", wantlen, wantdomain); 40: #endif IDCOMPAT 41: 42: for (i = io -> descr.d_nnote; i > 0; i--) /* dups likely "new" */ 43: { /* so search backwards */ 44: getnrec (io, i, note); 45: dprintf("noteid->sys %s note->n_id.sys %s\n", 46: noteid->sys, note->n_id.sys); 47: if (note -> n_stat & DELETED) 48: continue; /* ignore deleted */ 49: if (noteid -> uniqid == note -> n_id.uniqid) /* cheap to do */ 50: { 51: if (strcmp (noteid -> sys, note -> n_id.sys) == 0)/* more costly */ 52: { 53: return (i); 54: } 55: #ifdef IDCOMPAT 56: /* 57: * check for truncated or otherwise mangled ids 58: * THIS CODE IS NOT WELL TESTED AND PROBABLY DOESN'T WORK 59: * QUITE RIGHT. 60: */ 61: thislen = strlen (note -> n_id.sys); 62: thisdomain = index (note -> n_id.sys, '.'); 63: shortlen = thislen < wantlen ? thislen : wantlen;/* get short */ 64: dprintf ("thislen %d, thisdomain %s, shortlen %d\n", 65: thislen, thisdomain, shortlen); 66: if (thisdomain == (char *) NULL || wantdomain == (char *) NULL) 67: { /* undomained */ 68: if (strncmp (note -> n_id.sys, noteid -> sys, shortlen) == 0) 69: return (i); /* found */ 70: } 71: if (shortlen == OLDSYSSZ - 1 || shortlen == OLDSYSSZ) 72: { /* old format chop */ 73: if (strncmp (note -> n_id.sys, noteid -> sys, shortlen) == 0) 74: return (i); /* found */ 75: } 76: #ifdef notdef 77: if (strncmp (note -> n_id.sys, noteid -> sys, OLDSYSSZ - 1) == 0) 78: { /* match in 1st 10 */ 79: return (i); 80: } 81: #endif notdef 82: #endif IDCOMPAT 83: } 84: } 85: return (0); /* not found */ 86: } 87: 88: /* 89: * chkresp(io, respid, note, notenum) 90: * check the specified response to see if a response exists with 91: * the specified unique identifier 92: * 93: * This too can be speeded up similarly to the chknote routine.. 94: * but we shall worry about it later..after it already works. 95: * 96: * Original Coding: Ray Essick December 1981 97: */ 98: 99: chkresp (io, respid, note, notenum) 100: struct io_f *io; 101: struct id_f *respid; 102: struct note_f *note; 103: { 104: struct resp_f rrec; 105: int roffset, 106: rrecnum; 107: register int i; 108: register int prec; 109: register int poffset; 110: #ifdef IDCOMPAT 111: register int wantlen; /* length of wanted */ 112: register char *wantdomain; /* has "." */ 113: register int thislen; /* current id */ 114: register char *thisdomain; /* current id has . */ 115: register int shortlen; /* shorter */ 116: #endif IDCOMPAT 117: 118: if (note -> n_nresp <= 0) /* no responses */ 119: return (0); /* so it can't be there */ 120: #ifdef IDCOMPAT 121: wantlen = strlen (respid -> sys); /* get constants */ 122: wantdomain = index (respid -> sys, '.'); 123: #endif IDCOMPAT 124: prec = note -> n_rindx; /* get first block */ 125: poffset = 0; 126: getrrec (io, prec, &rrec); 127: for (i = 1; i <= note -> n_nresp; i++) /* through responses */ 128: { 129: while (rrec.r_stat[poffset] & DELETED) 130: { /* skip deleted ones */ 131: if (++poffset == RESPSZ) 132: { 133: poffset = 0; 134: if ((prec = rrec.r_next) == -1) 135: return (0); /* broken chain */ 136: getrrec (io, prec, &rrec); /* passed this buffer */ 137: } 138: } 139: if (respid -> uniqid == rrec.r_id[poffset].uniqid) 140: { 141: if (strcmp (respid -> sys, rrec.r_id[poffset].sys) == 0) 142: { 143: return (i); /* return resp number */ 144: } 145: #ifdef IDCOMPAT 146: /* 147: * check for truncated and otherwise mangled id's 148: */ 149: thislen = strlen (rrec.r_id[poffset].sys); 150: thisdomain = index (rrec.r_id[poffset].sys, '.'); 151: shortlen = thislen < wantlen ? thislen : wantlen;/* shorter */ 152: if (thisdomain == (char *) NULL || wantdomain == (char *) NULL) 153: { /* undomained */ 154: if (strncmp (respid -> sys, rrec.r_id[poffset].sys, shortlen) == 0) 155: return (i); 156: } 157: if (shortlen == OLDSYSSZ - 1 || shortlen == OLDSYSSZ) 158: { /* old format chop */ 159: if (strncmp (respid -> sys, rrec.r_id[poffset].sys, shortlen) == 0) 160: return (i); 161: } 162: if (strncmp (respid -> sys, rrec.r_id[poffset].sys, OLDSYSSZ - 1) == 0) 163: { /* match first 10 */ 164: return (i); 165: } 166: #endif IDCOMPAT 167: } 168: rrec.r_stat[poffset] |= DELETED; /* force scan above */ 169: } 170: return (0); /* is not a response to this note */ 171: }