Fossil SCM

Make sure that sqlite3_strglob() is available and use it: Less code duplication

jan.nijtmans 2014-01-21 21:42 trunk merge
Commit 7829abd8935f2ccf51f95cc512d38ffa0700097a
4 files changed +5 -5 +5 -5 +2 -62 +2 -62
+5 -5
--- auto.def
+++ auto.def
@@ -41,17 +41,17 @@
4141
# the code below will append -ldl to LIBS.
4242
#
4343
foreach extralibs {{} {-ldl}} {
4444
4545
# Locate the system SQLite by searching for sqlite3_open(). Then check
46
- # if sqlite3_wal_checkpoint() can be found as well. If we can find
47
- # open() but not wal_checkpoint(), then the system SQLite is too old
48
- # to link against fossil.
46
+ # if sqlite3_strglob() can be found as well. If we can find open() but
47
+ # not strglob(), then the system SQLite is too old to link against
48
+ # fossil.
4949
#
5050
if {[cc-check-function-in-lib sqlite3_open sqlite3 $extralibs]} {
51
- if {![cc-check-function-in-lib sqlite3_wal_checkpoint sqlite3 $extralibs]} {
52
- user-error "system sqlite3 too old (require >= 3.7.0)"
51
+ if {![cc-check-function-in-lib sqlite3_strglob sqlite3 $extralibs]} {
52
+ user-error "system sqlite3 too old (require >= 3.7.17)"
5353
}
5454
5555
# Success. Update symbols and return.
5656
#
5757
define USE_SYSTEM_SQLITE 1
5858
--- auto.def
+++ auto.def
@@ -41,17 +41,17 @@
41 # the code below will append -ldl to LIBS.
42 #
43 foreach extralibs {{} {-ldl}} {
44
45 # Locate the system SQLite by searching for sqlite3_open(). Then check
46 # if sqlite3_wal_checkpoint() can be found as well. If we can find
47 # open() but not wal_checkpoint(), then the system SQLite is too old
48 # to link against fossil.
49 #
50 if {[cc-check-function-in-lib sqlite3_open sqlite3 $extralibs]} {
51 if {![cc-check-function-in-lib sqlite3_wal_checkpoint sqlite3 $extralibs]} {
52 user-error "system sqlite3 too old (require >= 3.7.0)"
53 }
54
55 # Success. Update symbols and return.
56 #
57 define USE_SYSTEM_SQLITE 1
58
--- auto.def
+++ auto.def
@@ -41,17 +41,17 @@
41 # the code below will append -ldl to LIBS.
42 #
43 foreach extralibs {{} {-ldl}} {
44
45 # Locate the system SQLite by searching for sqlite3_open(). Then check
46 # if sqlite3_strglob() can be found as well. If we can find open() but
47 # not strglob(), then the system SQLite is too old to link against
48 # fossil.
49 #
50 if {[cc-check-function-in-lib sqlite3_open sqlite3 $extralibs]} {
51 if {![cc-check-function-in-lib sqlite3_strglob sqlite3 $extralibs]} {
52 user-error "system sqlite3 too old (require >= 3.7.17)"
53 }
54
55 # Success. Update symbols and return.
56 #
57 define USE_SYSTEM_SQLITE 1
58
+5 -5
--- auto.def
+++ auto.def
@@ -41,17 +41,17 @@
4141
# the code below will append -ldl to LIBS.
4242
#
4343
foreach extralibs {{} {-ldl}} {
4444
4545
# Locate the system SQLite by searching for sqlite3_open(). Then check
46
- # if sqlite3_wal_checkpoint() can be found as well. If we can find
47
- # open() but not wal_checkpoint(), then the system SQLite is too old
48
- # to link against fossil.
46
+ # if sqlite3_strglob() can be found as well. If we can find open() but
47
+ # not strglob(), then the system SQLite is too old to link against
48
+ # fossil.
4949
#
5050
if {[cc-check-function-in-lib sqlite3_open sqlite3 $extralibs]} {
51
- if {![cc-check-function-in-lib sqlite3_wal_checkpoint sqlite3 $extralibs]} {
52
- user-error "system sqlite3 too old (require >= 3.7.0)"
51
+ if {![cc-check-function-in-lib sqlite3_strglob sqlite3 $extralibs]} {
52
+ user-error "system sqlite3 too old (require >= 3.7.17)"
5353
}
5454
5555
# Success. Update symbols and return.
5656
#
5757
define USE_SYSTEM_SQLITE 1
5858
--- auto.def
+++ auto.def
@@ -41,17 +41,17 @@
41 # the code below will append -ldl to LIBS.
42 #
43 foreach extralibs {{} {-ldl}} {
44
45 # Locate the system SQLite by searching for sqlite3_open(). Then check
46 # if sqlite3_wal_checkpoint() can be found as well. If we can find
47 # open() but not wal_checkpoint(), then the system SQLite is too old
48 # to link against fossil.
49 #
50 if {[cc-check-function-in-lib sqlite3_open sqlite3 $extralibs]} {
51 if {![cc-check-function-in-lib sqlite3_wal_checkpoint sqlite3 $extralibs]} {
52 user-error "system sqlite3 too old (require >= 3.7.0)"
53 }
54
55 # Success. Update symbols and return.
56 #
57 define USE_SYSTEM_SQLITE 1
58
--- auto.def
+++ auto.def
@@ -41,17 +41,17 @@
41 # the code below will append -ldl to LIBS.
42 #
43 foreach extralibs {{} {-ldl}} {
44
45 # Locate the system SQLite by searching for sqlite3_open(). Then check
46 # if sqlite3_strglob() can be found as well. If we can find open() but
47 # not strglob(), then the system SQLite is too old to link against
48 # fossil.
49 #
50 if {[cc-check-function-in-lib sqlite3_open sqlite3 $extralibs]} {
51 if {![cc-check-function-in-lib sqlite3_strglob sqlite3 $extralibs]} {
52 user-error "system sqlite3 too old (require >= 3.7.17)"
53 }
54
55 # Success. Update symbols and return.
56 #
57 define USE_SYSTEM_SQLITE 1
58
+2 -62
--- src/glob.c
+++ src/glob.c
@@ -154,71 +154,11 @@
154154
** characters.
155155
**
156156
** [^...] Matches one character not in the enclosed list.
157157
*/
158158
int strglob(const char *zGlob, const char *z){
159
- int c, c2;
160
- int invert;
161
- int seen;
162
-
163
- while( (c = (*(zGlob++)))!=0 ){
164
- if( c=='*' ){
165
- while( (c=(*(zGlob++))) == '*' || c=='?' ){
166
- if( c=='?' && (*(z++))==0 ) return 0;
167
- }
168
- if( c==0 ){
169
- return 1;
170
- }else if( c=='[' ){
171
- while( *z && strglob(zGlob-1,z)==0 ){
172
- z++;
173
- }
174
- return (*z)!=0;
175
- }
176
- while( (c2 = (*(z++)))!=0 ){
177
- while( c2!=c ){
178
- c2 = *(z++);
179
- if( c2==0 ) return 0;
180
- }
181
- if( strglob(zGlob,z) ) return 1;
182
- }
183
- return 0;
184
- }else if( c=='?' ){
185
- if( (*(z++))==0 ) return 0;
186
- }else if( c=='[' ){
187
- int prior_c = 0;
188
- seen = 0;
189
- invert = 0;
190
- c = *(z++);
191
- if( c==0 ) return 0;
192
- c2 = *(zGlob++);
193
- if( c2=='^' ){
194
- invert = 1;
195
- c2 = *(zGlob++);
196
- }
197
- if( c2==']' ){
198
- if( c==']' ) seen = 1;
199
- c2 = *(zGlob++);
200
- }
201
- while( c2 && c2!=']' ){
202
- if( c2=='-' && zGlob[0]!=']' && zGlob[0]!=0 && prior_c>0 ){
203
- c2 = *(zGlob++);
204
- if( c>=prior_c && c<=c2 ) seen = 1;
205
- prior_c = 0;
206
- }else{
207
- if( c==c2 ){
208
- seen = 1;
209
- }
210
- prior_c = c2;
211
- }
212
- c2 = *(zGlob++);
213
- }
214
- if( c2==0 || (seen ^ invert)==0 ) return 0;
215
- }else{
216
- if( c!=(*(z++)) ) return 0;
217
- }
218
- }
219
- return *z==0;
159
+ return sqlite3_strglob(zGlob, z)==0;
220160
}
221161
222162
/*
223163
** Return true (non-zero) if zString matches any of the patterns in
224164
** the Glob. The value returned is actually a 1-based index of the pattern
@@ -228,11 +168,11 @@
228168
*/
229169
int glob_match(Glob *pGlob, const char *zString){
230170
int i;
231171
if( pGlob==0 ) return 0;
232172
for(i=0; i<pGlob->nPattern; i++){
233
- if( strglob(pGlob->azPattern[i], zString) ) return i+1;
173
+ if( sqlite3_strglob(pGlob->azPattern[i], zString)==0 ) return i+1;
234174
}
235175
return 0;
236176
}
237177
238178
/*
239179
--- src/glob.c
+++ src/glob.c
@@ -154,71 +154,11 @@
154 ** characters.
155 **
156 ** [^...] Matches one character not in the enclosed list.
157 */
158 int strglob(const char *zGlob, const char *z){
159 int c, c2;
160 int invert;
161 int seen;
162
163 while( (c = (*(zGlob++)))!=0 ){
164 if( c=='*' ){
165 while( (c=(*(zGlob++))) == '*' || c=='?' ){
166 if( c=='?' && (*(z++))==0 ) return 0;
167 }
168 if( c==0 ){
169 return 1;
170 }else if( c=='[' ){
171 while( *z && strglob(zGlob-1,z)==0 ){
172 z++;
173 }
174 return (*z)!=0;
175 }
176 while( (c2 = (*(z++)))!=0 ){
177 while( c2!=c ){
178 c2 = *(z++);
179 if( c2==0 ) return 0;
180 }
181 if( strglob(zGlob,z) ) return 1;
182 }
183 return 0;
184 }else if( c=='?' ){
185 if( (*(z++))==0 ) return 0;
186 }else if( c=='[' ){
187 int prior_c = 0;
188 seen = 0;
189 invert = 0;
190 c = *(z++);
191 if( c==0 ) return 0;
192 c2 = *(zGlob++);
193 if( c2=='^' ){
194 invert = 1;
195 c2 = *(zGlob++);
196 }
197 if( c2==']' ){
198 if( c==']' ) seen = 1;
199 c2 = *(zGlob++);
200 }
201 while( c2 && c2!=']' ){
202 if( c2=='-' && zGlob[0]!=']' && zGlob[0]!=0 && prior_c>0 ){
203 c2 = *(zGlob++);
204 if( c>=prior_c && c<=c2 ) seen = 1;
205 prior_c = 0;
206 }else{
207 if( c==c2 ){
208 seen = 1;
209 }
210 prior_c = c2;
211 }
212 c2 = *(zGlob++);
213 }
214 if( c2==0 || (seen ^ invert)==0 ) return 0;
215 }else{
216 if( c!=(*(z++)) ) return 0;
217 }
218 }
219 return *z==0;
220 }
221
222 /*
223 ** Return true (non-zero) if zString matches any of the patterns in
224 ** the Glob. The value returned is actually a 1-based index of the pattern
@@ -228,11 +168,11 @@
228 */
229 int glob_match(Glob *pGlob, const char *zString){
230 int i;
231 if( pGlob==0 ) return 0;
232 for(i=0; i<pGlob->nPattern; i++){
233 if( strglob(pGlob->azPattern[i], zString) ) return i+1;
234 }
235 return 0;
236 }
237
238 /*
239
--- src/glob.c
+++ src/glob.c
@@ -154,71 +154,11 @@
154 ** characters.
155 **
156 ** [^...] Matches one character not in the enclosed list.
157 */
158 int strglob(const char *zGlob, const char *z){
159 return sqlite3_strglob(zGlob, z)==0;
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
160 }
161
162 /*
163 ** Return true (non-zero) if zString matches any of the patterns in
164 ** the Glob. The value returned is actually a 1-based index of the pattern
@@ -228,11 +168,11 @@
168 */
169 int glob_match(Glob *pGlob, const char *zString){
170 int i;
171 if( pGlob==0 ) return 0;
172 for(i=0; i<pGlob->nPattern; i++){
173 if( sqlite3_strglob(pGlob->azPattern[i], zString)==0 ) return i+1;
174 }
175 return 0;
176 }
177
178 /*
179
+2 -62
--- src/glob.c
+++ src/glob.c
@@ -154,71 +154,11 @@
154154
** characters.
155155
**
156156
** [^...] Matches one character not in the enclosed list.
157157
*/
158158
int strglob(const char *zGlob, const char *z){
159
- int c, c2;
160
- int invert;
161
- int seen;
162
-
163
- while( (c = (*(zGlob++)))!=0 ){
164
- if( c=='*' ){
165
- while( (c=(*(zGlob++))) == '*' || c=='?' ){
166
- if( c=='?' && (*(z++))==0 ) return 0;
167
- }
168
- if( c==0 ){
169
- return 1;
170
- }else if( c=='[' ){
171
- while( *z && strglob(zGlob-1,z)==0 ){
172
- z++;
173
- }
174
- return (*z)!=0;
175
- }
176
- while( (c2 = (*(z++)))!=0 ){
177
- while( c2!=c ){
178
- c2 = *(z++);
179
- if( c2==0 ) return 0;
180
- }
181
- if( strglob(zGlob,z) ) return 1;
182
- }
183
- return 0;
184
- }else if( c=='?' ){
185
- if( (*(z++))==0 ) return 0;
186
- }else if( c=='[' ){
187
- int prior_c = 0;
188
- seen = 0;
189
- invert = 0;
190
- c = *(z++);
191
- if( c==0 ) return 0;
192
- c2 = *(zGlob++);
193
- if( c2=='^' ){
194
- invert = 1;
195
- c2 = *(zGlob++);
196
- }
197
- if( c2==']' ){
198
- if( c==']' ) seen = 1;
199
- c2 = *(zGlob++);
200
- }
201
- while( c2 && c2!=']' ){
202
- if( c2=='-' && zGlob[0]!=']' && zGlob[0]!=0 && prior_c>0 ){
203
- c2 = *(zGlob++);
204
- if( c>=prior_c && c<=c2 ) seen = 1;
205
- prior_c = 0;
206
- }else{
207
- if( c==c2 ){
208
- seen = 1;
209
- }
210
- prior_c = c2;
211
- }
212
- c2 = *(zGlob++);
213
- }
214
- if( c2==0 || (seen ^ invert)==0 ) return 0;
215
- }else{
216
- if( c!=(*(z++)) ) return 0;
217
- }
218
- }
219
- return *z==0;
159
+ return sqlite3_strglob(zGlob, z)==0;
220160
}
221161
222162
/*
223163
** Return true (non-zero) if zString matches any of the patterns in
224164
** the Glob. The value returned is actually a 1-based index of the pattern
@@ -228,11 +168,11 @@
228168
*/
229169
int glob_match(Glob *pGlob, const char *zString){
230170
int i;
231171
if( pGlob==0 ) return 0;
232172
for(i=0; i<pGlob->nPattern; i++){
233
- if( strglob(pGlob->azPattern[i], zString) ) return i+1;
173
+ if( sqlite3_strglob(pGlob->azPattern[i], zString)==0 ) return i+1;
234174
}
235175
return 0;
236176
}
237177
238178
/*
239179
--- src/glob.c
+++ src/glob.c
@@ -154,71 +154,11 @@
154 ** characters.
155 **
156 ** [^...] Matches one character not in the enclosed list.
157 */
158 int strglob(const char *zGlob, const char *z){
159 int c, c2;
160 int invert;
161 int seen;
162
163 while( (c = (*(zGlob++)))!=0 ){
164 if( c=='*' ){
165 while( (c=(*(zGlob++))) == '*' || c=='?' ){
166 if( c=='?' && (*(z++))==0 ) return 0;
167 }
168 if( c==0 ){
169 return 1;
170 }else if( c=='[' ){
171 while( *z && strglob(zGlob-1,z)==0 ){
172 z++;
173 }
174 return (*z)!=0;
175 }
176 while( (c2 = (*(z++)))!=0 ){
177 while( c2!=c ){
178 c2 = *(z++);
179 if( c2==0 ) return 0;
180 }
181 if( strglob(zGlob,z) ) return 1;
182 }
183 return 0;
184 }else if( c=='?' ){
185 if( (*(z++))==0 ) return 0;
186 }else if( c=='[' ){
187 int prior_c = 0;
188 seen = 0;
189 invert = 0;
190 c = *(z++);
191 if( c==0 ) return 0;
192 c2 = *(zGlob++);
193 if( c2=='^' ){
194 invert = 1;
195 c2 = *(zGlob++);
196 }
197 if( c2==']' ){
198 if( c==']' ) seen = 1;
199 c2 = *(zGlob++);
200 }
201 while( c2 && c2!=']' ){
202 if( c2=='-' && zGlob[0]!=']' && zGlob[0]!=0 && prior_c>0 ){
203 c2 = *(zGlob++);
204 if( c>=prior_c && c<=c2 ) seen = 1;
205 prior_c = 0;
206 }else{
207 if( c==c2 ){
208 seen = 1;
209 }
210 prior_c = c2;
211 }
212 c2 = *(zGlob++);
213 }
214 if( c2==0 || (seen ^ invert)==0 ) return 0;
215 }else{
216 if( c!=(*(z++)) ) return 0;
217 }
218 }
219 return *z==0;
220 }
221
222 /*
223 ** Return true (non-zero) if zString matches any of the patterns in
224 ** the Glob. The value returned is actually a 1-based index of the pattern
@@ -228,11 +168,11 @@
228 */
229 int glob_match(Glob *pGlob, const char *zString){
230 int i;
231 if( pGlob==0 ) return 0;
232 for(i=0; i<pGlob->nPattern; i++){
233 if( strglob(pGlob->azPattern[i], zString) ) return i+1;
234 }
235 return 0;
236 }
237
238 /*
239
--- src/glob.c
+++ src/glob.c
@@ -154,71 +154,11 @@
154 ** characters.
155 **
156 ** [^...] Matches one character not in the enclosed list.
157 */
158 int strglob(const char *zGlob, const char *z){
159 return sqlite3_strglob(zGlob, z)==0;
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
160 }
161
162 /*
163 ** Return true (non-zero) if zString matches any of the patterns in
164 ** the Glob. The value returned is actually a 1-based index of the pattern
@@ -228,11 +168,11 @@
168 */
169 int glob_match(Glob *pGlob, const char *zString){
170 int i;
171 if( pGlob==0 ) return 0;
172 for(i=0; i<pGlob->nPattern; i++){
173 if( sqlite3_strglob(pGlob->azPattern[i], zString)==0 ) return i+1;
174 }
175 return 0;
176 }
177
178 /*
179

Keyboard Shortcuts

Open search /
Next entry (timeline) j
Previous entry (timeline) k
Open focused entry Enter
Show this help ?
Toggle theme Top nav button