1: #include "parms.h"
   2: #include "structs.h"
   3: 
   4: #ifdef  RCSIDENT
   5: static char rcsid[] = "$Header: tsearch.c,v 1.7 85/01/18 15:39:59 notes Rel $";
   6: #endif	RCSIDENT
   7: 
   8: /*
   9:  *	tsearch(io, fromnum, grabstring)
  10:  *		search notetitles from note #fromnum back towards 1
  11:  *	looking for the string in io->xstring. If that string is
  12:  *	empty or grabstring is true, prompt the user for a string.
  13:  *
  14:  *	Returns:	0 if searched and not found
  15:  *			>0 the note number which matched
  16:  *			-1 null string to search for.
  17:  *
  18:  *	Original coding:	Ray Essick	January 1982
  19:  *	Modified:		Malcolm Slaney	July 1982
  20:  *		to separate the gathering of a string and
  21:  *		the actual search. A Good plan. (RBE)
  22:  */
  23: 
  24: tsearch (io, fromnum, grabstring)
  25: struct io_f *io;
  26: {
  27:     register int    i;
  28: 
  29:     if (grabstring || io -> xstring[0] == '\0')
  30:     {
  31:     at (-1, 1);
  32:     printf ("Search String: ");
  33:     i = gline (io -> xstring, TITLEN);      /* grab one */
  34:     at (-1, 1);
  35:     printf ("%*s", i + 16, " ");            /* clear the line */
  36:     if (i == 1)
  37:     {
  38:         io -> xstring[0] = '\0';
  39:         return (-1);
  40:     }
  41:     }
  42:     at (0, 1);
  43:     fromnum = findtitle (io, fromnum, FALSE);
  44:     if (intflag)
  45:     {
  46:     intflag = 0;                    /* don't recatch this one */
  47:     printf ("Search aborted");
  48:     }
  49:     if (fromnum > 0)
  50:     return (fromnum);
  51:     else
  52:     printf ("%s: Not Found", io -> xstring);
  53:     return 0;
  54: }
  55: 
  56: findtitle (io, fromnum, anchored)
  57: struct io_f *io;
  58: int     fromnum;
  59: int     anchored;                   /* true if anchored search */
  60: {
  61:     struct note_f   note;               /* hold note descr */
  62:     register int    i,
  63:                     j,
  64:                     xlength;
  65:     register int    nlength;                /* how far into title */
  66: 
  67:     for (j = 0; io -> xstring[j]; j++)          /* force lower case */
  68:     io -> xstring[j] = tolcase (io -> xstring[j]);
  69:     if (io -> xstring[0] == '\0')           /* if empty then */
  70:     return (-1);                    /* don't search */
  71:     xlength = strlen (io -> xstring);
  72:     if (xlength >= TITLEN)
  73:     xlength = TITLEN - 1;               /* only so far */
  74:     if (fromnum > io -> descr.d_nnote)
  75:     fromnum = io -> descr.d_nnote;
  76: 
  77:     intflag = 0;                    /* catch interupts */
  78:     while (fromnum > 0)
  79:     {
  80:     getnrec (io, fromnum, &note);           /* grab descriptor */
  81:     if (note.n_stat & DELETED)
  82:     {
  83:         fromnum--;
  84:         continue;                   /* skip this one */
  85:     }
  86:     for (j = 0; j < TITLEN && note.ntitle[j]; j++)
  87:         note.ntitle[j] = tolcase (note.ntitle[j]);
  88:     if (anchored)
  89:     {
  90:         nlength = 1;                /* must start at LHS */
  91:     }
  92:     else
  93:     {
  94:         nlength = TITLEN + 1 - xlength;     /* let it float */
  95:     }
  96:     for (j = 0; j < nlength; j++)
  97:     {
  98:         for (i = 0; i < xlength && (j + i) < TITLEN; i++)
  99:         {
 100: #ifdef  notdef
 101:         if (note.ntitle[j + i] == '\0')
 102:         {
 103:             /*
 104: 		     * something for strings running off the end
 105: 		     * mostly for USENET title truncation
 106: 		     */
 107:         }
 108: #endif	notdef
 109:         if (io -> xstring[i] != note.ntitle[j + i])
 110:         {                   /* true at eostring */
 111:             i = (-1);               /* not here */
 112:             break;
 113:         }
 114:         }
 115:         if (i != -1)                /* matched */
 116:         return fromnum;
 117:     }
 118:     fromnum--;                  /* try next note */
 119:     if (intflag)
 120:         break;                  /* interupt */
 121:     }
 122:     return (0);
 123: }

Defined functions

findtitle defined in line 56; used 3 times

Defined variables

rcsid defined in line 5; never used
Last modified: 1985-01-19
Generated: 2016-12-26
Generated by src2html V0.67
page hit count: 2512
Valid CSS Valid XHTML 1.0 Strict