1: /* $Header: ngsrch.c,v 4.3 85/05/01 11:44:51 lwall Exp $
   2:  *
   3:  * $Log:	ngsrch.c,v $
   4:  * Revision 4.3  85/05/01  11:44:51  lwall
   5:  * Baseline for release with 4.3bsd.
   6:  *
   7:  */
   8: 
   9: #include "EXTERN.h"
  10: #include "common.h"
  11: #include "rcstuff.h"
  12: #include "final.h"
  13: #include "search.h"
  14: #include "rn.h"
  15: #include "util.h"
  16: #include "term.h"
  17: #include "rcln.h"
  18: #include "INTERN.h"
  19: #include "ngsrch.h"
  20: 
  21: #ifdef NGSORONLY
  22:     COMPEX ngcompex;
  23: #endif
  24: 
  25: void
  26: ngsrch_init()
  27: {
  28: #ifdef ZEROGLOB
  29:     init_compex(&ngcompex);
  30: #endif	/* ZEROGLOB */
  31:     ;
  32: }
  33: 
  34: #ifdef NGSEARCH
  35: int
  36: ng_search(patbuf,get_cmd)
  37: char *patbuf;               /* if patbuf != buf, get_cmd must */
  38: int get_cmd;                /*   be set to FALSE!!! */
  39: {
  40:     char *pattern;          /* unparsed pattern */
  41:     register char cmdchr = *patbuf; /* what kind of search? */
  42:     register char *s;
  43:     bool backward = cmdchr == '?';  /* direction of search */
  44: 
  45:     int_count = 0;
  46:     if (get_cmd && buf == patbuf)
  47:     if (!finish_command(FALSE))     /* get rest of command */
  48:         return NGS_ABORT;
  49:     for (pattern = patbuf+1; *pattern == ' '; pattern++) ;
  50:     if (*pattern) {
  51:     ng_doread = FALSE;
  52:     }
  53:     s = rindex(pattern,cmdchr);
  54:     if (s != Nullch && *(s-1) != '\\') {
  55:     *s++ = '\0';
  56:     if (index(s,'r') != Nullch)
  57:         ng_doread = TRUE;
  58:     }
  59:     if ((s = ng_comp(&ngcompex,pattern,TRUE,TRUE)) != Nullch) {
  60:                     /* compile regular expression */
  61:     printf("\n%s\n",s) FLUSH;
  62:     return NGS_ABORT;
  63:     }
  64:     fputs("\nSearching...",stdout) FLUSH;   /* give them something to read */
  65:     fflush(stdout);
  66:     for (;;) {
  67:     if (int_count) {
  68:         int_count = 0;
  69:         return NGS_INTR;
  70:     }
  71:     if (backward) {
  72:         if (ng > 0)
  73:         --ng;
  74:         else
  75:         ng = nextrcline;
  76:     }
  77:     else {
  78:         if (ng >= nextrcline)
  79:         ng = 0;
  80:         else
  81:         ++ng;
  82:     }
  83:     if (ng == current_ng)
  84:         return NGS_NOTFOUND;
  85:     if (ng == nextrcline || toread[ng] < TR_NONE || !ng_wanted())
  86:         continue;
  87:     if (toread[ng] == TR_NONE)
  88:         set_toread(ng);
  89: 
  90:     if (toread[ng] > TR_NONE)
  91:         return NGS_FOUND;
  92:     else if (toread[ng] == TR_NONE)
  93:         if (ng_doread)
  94:         return NGS_FOUND;
  95:         else
  96:         printf("\n[0 unread in %s--skipping]",rcline[ng]) FLUSH;
  97:     }
  98: }
  99: 
 100: bool
 101: ng_wanted()
 102: {
 103:     return execute(&ngcompex,rcline[ng]) != Nullch;
 104: }
 105: #endif
 106: 
 107: #ifdef NGSORONLY
 108: char *
 109: ng_comp(compex,pattern,RE,fold)
 110: COMPEX *compex;
 111: char *pattern;
 112: bool RE;
 113: bool fold;
 114: {
 115:     char ng_pattern[128];
 116:     register char *s = pattern, *d = ng_pattern;
 117: 
 118:     if (!*s)
 119:     return Nullch;          /* reuse old pattern */
 120:     for (; *s; s++) {
 121:     if (*s == '.') {
 122:         *d++ = '\\';
 123:         *d++ = *s;
 124:     }
 125:     else if (*s == '?') {
 126:         *d++ = '.';
 127:     }
 128:     else if (*s == '*') {
 129:         *d++ = '.';
 130:         *d++ = *s;
 131:     }
 132:     else if (strnEQ(s,"all",3)) {
 133:         *d++ = '.';
 134:         *d++ = '*';
 135:         s += 2;
 136:     }
 137:     else
 138:         *d++ = *s;
 139:     }
 140:     *d = '\0';
 141:     return compile(compex,ng_pattern,RE,fold);
 142: }
 143: #endif

Defined functions

ng_comp defined in line 108; used 4 times
ng_search defined in line 35; used 2 times
ng_wanted defined in line 100; used 2 times
ngsrch_init defined in line 25; used 2 times
Last modified: 1987-03-16
Generated: 2016-12-26
Generated by src2html V0.67
page hit count: 2610
Valid CSS Valid XHTML 1.0 Strict