Deleted Added
full compact
search.c (8870) search.c (26926)
1/*-
2 * Copyright (c) 1992, 1993
3 * The Regents of the University of California. All rights reserved.
4 *
5 * This code is derived from software contributed to Berkeley by
6 * Christos Zoulas of Cornell University.
7 *
8 * Redistribution and use in source and binary forms, with or without

--- 29 unchanged lines hidden (view full) ---

38static char sccsid[] = "@(#)search.c 8.1 (Berkeley) 6/4/93";
39#endif /* not lint && not SCCSID */
40
41/*
42 * search.c: History and character search functions
43 */
44#include "sys.h"
45#include <stdlib.h>
1/*-
2 * Copyright (c) 1992, 1993
3 * The Regents of the University of California. All rights reserved.
4 *
5 * This code is derived from software contributed to Berkeley by
6 * Christos Zoulas of Cornell University.
7 *
8 * Redistribution and use in source and binary forms, with or without

--- 29 unchanged lines hidden (view full) ---

38static char sccsid[] = "@(#)search.c 8.1 (Berkeley) 6/4/93";
39#endif /* not lint && not SCCSID */
40
41/*
42 * search.c: History and character search functions
43 */
44#include "sys.h"
45#include <stdlib.h>
46#ifdef REGEXEC
47#include <sys/types.h>
46#if defined(REGEX)
48#include <regex.h>
47#include <regex.h>
49#else
50#ifdef REGEXP
48#elif defined(REGEXP)
51#include <regexp.h>
52#endif
49#include <regexp.h>
50#endif
53#endif
54#include "el.h"
55
56/*
57 * Adjust cursor in vi mode to include the character under it
58 */
59#define EL_CURSOR(el) \
60 ((el)->el_line.cursor + (((el)->el_map.type == MAP_VI) && \
61 ((el)->el_map.current == (el)->el_map.alt)))

--- 40 unchanged lines hidden (view full) ---

102/* el_match():
103 * Return if string matches pattern
104 */
105protected int
106el_match(str, pat)
107 const char *str;
108 const char *pat;
109{
51#include "el.h"
52
53/*
54 * Adjust cursor in vi mode to include the character under it
55 */
56#define EL_CURSOR(el) \
57 ((el)->el_line.cursor + (((el)->el_map.type == MAP_VI) && \
58 ((el)->el_map.current == (el)->el_map.alt)))

--- 40 unchanged lines hidden (view full) ---

99/* el_match():
100 * Return if string matches pattern
101 */
102protected int
103el_match(str, pat)
104 const char *str;
105 const char *pat;
106{
110#ifdef REGEXEC
107#if defined (REGEX)
111 regex_t re;
108 regex_t re;
112#else
113#ifndef REGEXP
109 int rv;
110#elif defined (REGEXP)
111 regexp *rp;
112 int rv;
113#else
114 extern char *re_comp __P((const char *));
115 extern int re_exec __P((const char *));
114 extern char *re_comp __P((const char *));
115 extern int re_exec __P((const char *));
116#else
117 regexp *re;
118 int rv;
119#endif
116#endif
120#endif
121
122 if (strstr(str, pat) != NULL)
123 return 1;
117
118 if (strstr(str, pat) != NULL)
119 return 1;
124#ifdef REGEXEC
125 if (regcomp(&re, pat, REG_EXTENDED | REG_NOSUB) != 0)
126 return 0;
127 return (regexec(&re, str, 0, NULL, 0) == 0);
128#else
129#ifndef REGEXP
130 if (re_comp(pat) != NULL)
131 return 0;
132 else
133 return re_exec(str) == 1;
134#else
120
121#if defined(REGEX)
122 if (regcomp(&re, pat, 0) == 0) {
123 rv = regexec(&re, str, 0, NULL, 0) == 0;
124 regfree(&re);
125 } else {
126 rv = 0;
127 }
128 return rv;
129#elif defined(REGEXP)
135 if ((re = regcomp(pat)) != NULL) {
136 rv = regexec(re, str);
137 free((ptr_t) re);
130 if ((re = regcomp(pat)) != NULL) {
131 rv = regexec(re, str);
132 free((ptr_t) re);
138 }
139 else
133 } else {
140 rv = 0;
134 rv = 0;
135 }
141 return rv;
136 return rv;
137#else
138 if (re_comp(pat) != NULL)
139 return 0;
140 else
141 return re_exec(str) == 1;
142#endif
142#endif
143#endif
144}
145
146
147/* c_hmatch():
148 * return True if the pattern matches the prefix
149 */
150protected int
151c_hmatch(el, str)

--- 305 unchanged lines hidden (view full) ---

457 el->el_line.buffer[0] = '\0';
458 el->el_line.lastchar = el->el_line.buffer;
459 el->el_line.cursor = el->el_line.buffer;
460 re_refresh(el);
461 return CC_ERROR;
462 }
463#ifdef ANCHOR
464 if (el->el_search.patbuf[0] != '.' && el->el_search.patbuf[0] != '*') {
143}
144
145
146/* c_hmatch():
147 * return True if the pattern matches the prefix
148 */
149protected int
150c_hmatch(el, str)

--- 305 unchanged lines hidden (view full) ---

456 el->el_line.buffer[0] = '\0';
457 el->el_line.lastchar = el->el_line.buffer;
458 el->el_line.cursor = el->el_line.buffer;
459 re_refresh(el);
460 return CC_ERROR;
461 }
462#ifdef ANCHOR
463 if (el->el_search.patbuf[0] != '.' && el->el_search.patbuf[0] != '*') {
465 (void) strcpy(tmpbuf, el->el_search.patbuf);
464 (void)strncpy(tmpbuf, el->el_search.patbuf, sizeof(tmpbuf) - 1);
466 el->el_search.patbuf[0] = '.';
467 el->el_search.patbuf[1] = '*';
465 el->el_search.patbuf[0] = '.';
466 el->el_search.patbuf[1] = '*';
468 (void) strcpy(&el->el_search.patbuf[2], tmpbuf);
467 (void)strncpy(&el->el_search.patbuf[2], tmpbuf,
468 sizeof(el->el_search.patbuf) - 3);
469 el->el_search.patlen++;
470 el->el_search.patbuf[el->el_search.patlen++] = '.';
471 el->el_search.patbuf[el->el_search.patlen++] = '*';
472 el->el_search.patbuf[el->el_search.patlen] = '\0';
473 }
474#endif
475 }
476 else {
477#ifdef ANCHOR
478 tmpbuf[tmplen++] = '.';
479 tmpbuf[tmplen++] = '*';
480#endif
481 tmpbuf[tmplen] = '\0';
469 el->el_search.patlen++;
470 el->el_search.patbuf[el->el_search.patlen++] = '.';
471 el->el_search.patbuf[el->el_search.patlen++] = '*';
472 el->el_search.patbuf[el->el_search.patlen] = '\0';
473 }
474#endif
475 }
476 else {
477#ifdef ANCHOR
478 tmpbuf[tmplen++] = '.';
479 tmpbuf[tmplen++] = '*';
480#endif
481 tmpbuf[tmplen] = '\0';
482 (void) strcpy(el->el_search.patbuf, tmpbuf);
482 (void)strncpy(el->el_search.patbuf, tmpbuf,
483 sizeof(el->el_search.patbuf) - 1);
483 el->el_search.patlen = tmplen;
484 }
485 el->el_state.lastcmd = (el_action_t) dir; /* avoid c_setpat */
486 el->el_line.cursor = el->el_line.lastchar = el->el_line.buffer;
487 if ((dir == ED_SEARCH_PREV_HISTORY ? ed_search_prev_history(el, 0) :
488 ed_search_next_history(el, 0)) == CC_ERROR) {
489 re_refresh(el);
490 return CC_ERROR;

--- 143 unchanged lines hidden ---
484 el->el_search.patlen = tmplen;
485 }
486 el->el_state.lastcmd = (el_action_t) dir; /* avoid c_setpat */
487 el->el_line.cursor = el->el_line.lastchar = el->el_line.buffer;
488 if ((dir == ED_SEARCH_PREV_HISTORY ? ed_search_prev_history(el, 0) :
489 ed_search_next_history(el, 0)) == CC_ERROR) {
490 re_refresh(el);
491 return CC_ERROR;

--- 143 unchanged lines hidden ---