1 /*	Copyright (C) 1995, 1996 Tom Lord
2  *
3  * This program is free software; you can redistribute it and/or modify
4  * it under the terms of the GNU Library General Public License as published by
5  * the Free Software Foundation; either version 2, or (at your option)
6  * any later version.
7  *
8  * This program is distributed in the hope that it will be useful,
9  * but WITHOUT ANY WARRANTY; without even the implied warranty of
10  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
11  * GNU Library General Public License for more details.
12  *
13  * You should have received a copy of the GNU Library General Public License
14  * along with this software; see the file COPYING.  If not, write to
15  * the Free Software Foundation, 59 Temple Place - Suite 330,
16  * Boston, MA 02111-1307, USA.
17  */
18 
19 
20 
21 #include "rxall.h"
22 #include "rxstr.h"
23 
24 
25 
26 #ifdef __STDC__
27 enum rx_answers
rx_str_vmfn(void * closure,unsigned const char ** burstp,int * lenp,int * offsetp,int start,int end,int need)28 rx_str_vmfn (void * closure, unsigned const char ** burstp, int * lenp, int * offsetp, int start, int end, int need)
29 #else
30 enum rx_answers
31 rx_str_vmfn (closure, burstp, lenp, offsetp, start, end, need)
32      void * closure;
33      unsigned const char ** burstp;
34      int * lenp;
35      int * offsetp;
36      int start;
37      int end;
38      int need;
39 #endif
40 {
41   struct rx_str_closure * strc;
42   strc = (struct rx_str_closure *)closure;
43 
44   if (   (need < 0)
45       || (need > strc->len))
46     return rx_no;
47 
48   *burstp = strc->str;
49   *lenp = strc->len;
50   *offsetp = 0;
51   return rx_yes;
52 }
53 
54 #ifdef __STDC__
55 enum rx_answers
rx_str_contextfn(void * closure,struct rexp_node * node,int start,int end,struct rx_registers * regs)56 rx_str_contextfn (void * closure, struct rexp_node * node, int start, int end, struct rx_registers * regs)
57 #else
58 enum rx_answers
59 rx_str_contextfn (closure, node, start, end, regs)
60      void * closure;
61      struct rexp_node * node;
62      int start;
63      int end;
64      struct rx_registers * regs;
65 #endif
66 {
67   struct rx_str_closure * strc;
68 
69   strc = (struct rx_str_closure *)closure;
70   switch (node->params.intval)
71     {
72     case '1': case '2': case '3': case '4': case '5':
73     case '6': case '7': case '8': case '9':
74       {
75 	int cmp;
76 	int regn;
77 	regn = node->params.intval - '0';
78 	if (   (regs[regn].rm_so == -1)
79 	    || ((end - start) != (regs[regn].rm_eo - regs[regn].rm_so)))
80 	  return rx_no;
81 	else
82 	  {
83 	    if (strc->rules.case_indep)
84 	      cmp = strncasecmp (strc->str + start,
85 				 strc->str + regs[regn].rm_so,
86 				 end - start);
87 	    else
88 	      cmp = strncmp (strc->str + start,
89 			     strc->str + regs[regn].rm_so,
90 			     end - start);
91 
92 	    return (!cmp
93 		    ? rx_yes
94 		    : rx_no);
95 	  }
96       }
97 
98     case '^':
99       {
100 	return ((   (start == end)
101 		 && (   ((start == 0) && !strc->rules.not_bol)
102 		     || (   (start > 0)
103 			 && strc->rules.newline_anchor
104 			 && (strc->str[start - 1] == '\n'))))
105 		? rx_yes
106 		: rx_no);
107       }
108 
109     case '$':
110       {
111 	return ((   (start == end)
112 		 && (   ((start == strc->len) && !strc->rules.not_eol)
113 		     || (   (start < strc->len)
114 			 && strc->rules.newline_anchor
115 			 && (strc->str[start] == '\n'))))
116 		? rx_yes
117 		: rx_no);
118       }
119 
120     case '<':
121     case '>':
122 
123     case 'B':
124     case 'b':
125 
126 
127     default:
128       return rx_bogus;
129     }
130 }
131