Fossil SCM

Add the -one option to the 'glob_match' command.

mistachkin 2015-05-27 19:29 UTC th1GlobMatch
Commit f7d4c544cad47c8577906ebb5eee0b0cddc07fdc
2 files changed +20 -11 +3 -3
+20 -11
--- src/th_main.c
+++ src/th_main.c
@@ -1326,42 +1326,51 @@
13261326
}
13271327
return rc;
13281328
}
13291329
13301330
/*
1331
-** TH1 command: glob_match ?--? patternList string
1331
+** TH1 command: glob_match ?-one? ?--? patternList string
13321332
**
1333
-** Checks the string against the specified list of glob patterns and returns
1334
-** non-zero if there is a match.
1333
+** Checks the string against the specified glob pattern -OR- list of glob
1334
+** patterns and returns non-zero if there is a match.
13351335
*/
1336
-#define GLOB_MATCH_WRONGNUMARGS "glob_match ?--? patternList string"
1336
+#define GLOB_MATCH_WRONGNUMARGS "glob_match ?-one? ?--? patternList string"
13371337
static int globMatchCmd(
13381338
Th_Interp *interp,
13391339
void *p,
13401340
int argc,
13411341
const char **argv,
13421342
int *argl
13431343
){
13441344
int rc;
1345
+ int one = 0;
13451346
int nArg = 1;
13461347
Glob *pGlob = 0;
1347
- if( argc<3 || argc>4 ){
1348
+ if( argc<3 || argc>5 ){
13481349
return Th_WrongNumArgs(interp, GLOB_MATCH_WRONGNUMARGS);
1350
+ }
1351
+ if( fossil_strcmp(argv[nArg], "-one")==0 ){
1352
+ one = 1; nArg++;
13491353
}
13501354
if( fossil_strcmp(argv[nArg], "--")==0 ) nArg++;
13511355
if( nArg+2!=argc ){
13521356
return Th_WrongNumArgs(interp, GLOB_MATCH_WRONGNUMARGS);
13531357
}
1354
- pGlob = glob_create(argv[nArg]);
1355
- if( pGlob ){
1356
- Th_SetResultInt(interp, glob_match(pGlob, argv[nArg+1]));
1358
+ if( one ){
1359
+ Th_SetResultInt(interp, sqlite3_strglob(argv[nArg], argv[nArg+1])==0);
13571360
rc = TH_OK;
13581361
}else{
1359
- Th_SetResult(interp, "unable to create glob from pattern list", -1);
1360
- rc = TH_ERROR;
1362
+ pGlob = glob_create(argv[nArg]);
1363
+ if( pGlob ){
1364
+ Th_SetResultInt(interp, glob_match(pGlob, argv[nArg+1]));
1365
+ rc = TH_OK;
1366
+ }else{
1367
+ Th_SetResult(interp, "unable to create glob from pattern list", -1);
1368
+ rc = TH_ERROR;
1369
+ }
1370
+ glob_free(pGlob);
13611371
}
1362
- glob_free(pGlob);
13631372
return rc;
13641373
}
13651374
13661375
/*
13671376
** TH1 command: regexp ?-nocase? ?--? exp string
13681377
--- src/th_main.c
+++ src/th_main.c
@@ -1326,42 +1326,51 @@
1326 }
1327 return rc;
1328 }
1329
1330 /*
1331 ** TH1 command: glob_match ?--? patternList string
1332 **
1333 ** Checks the string against the specified list of glob patterns and returns
1334 ** non-zero if there is a match.
1335 */
1336 #define GLOB_MATCH_WRONGNUMARGS "glob_match ?--? patternList string"
1337 static int globMatchCmd(
1338 Th_Interp *interp,
1339 void *p,
1340 int argc,
1341 const char **argv,
1342 int *argl
1343 ){
1344 int rc;
 
1345 int nArg = 1;
1346 Glob *pGlob = 0;
1347 if( argc<3 || argc>4 ){
1348 return Th_WrongNumArgs(interp, GLOB_MATCH_WRONGNUMARGS);
 
 
 
1349 }
1350 if( fossil_strcmp(argv[nArg], "--")==0 ) nArg++;
1351 if( nArg+2!=argc ){
1352 return Th_WrongNumArgs(interp, GLOB_MATCH_WRONGNUMARGS);
1353 }
1354 pGlob = glob_create(argv[nArg]);
1355 if( pGlob ){
1356 Th_SetResultInt(interp, glob_match(pGlob, argv[nArg+1]));
1357 rc = TH_OK;
1358 }else{
1359 Th_SetResult(interp, "unable to create glob from pattern list", -1);
1360 rc = TH_ERROR;
 
 
 
 
 
 
 
1361 }
1362 glob_free(pGlob);
1363 return rc;
1364 }
1365
1366 /*
1367 ** TH1 command: regexp ?-nocase? ?--? exp string
1368
--- src/th_main.c
+++ src/th_main.c
@@ -1326,42 +1326,51 @@
1326 }
1327 return rc;
1328 }
1329
1330 /*
1331 ** TH1 command: glob_match ?-one? ?--? patternList string
1332 **
1333 ** Checks the string against the specified glob pattern -OR- list of glob
1334 ** patterns and returns non-zero if there is a match.
1335 */
1336 #define GLOB_MATCH_WRONGNUMARGS "glob_match ?-one? ?--? patternList string"
1337 static int globMatchCmd(
1338 Th_Interp *interp,
1339 void *p,
1340 int argc,
1341 const char **argv,
1342 int *argl
1343 ){
1344 int rc;
1345 int one = 0;
1346 int nArg = 1;
1347 Glob *pGlob = 0;
1348 if( argc<3 || argc>5 ){
1349 return Th_WrongNumArgs(interp, GLOB_MATCH_WRONGNUMARGS);
1350 }
1351 if( fossil_strcmp(argv[nArg], "-one")==0 ){
1352 one = 1; nArg++;
1353 }
1354 if( fossil_strcmp(argv[nArg], "--")==0 ) nArg++;
1355 if( nArg+2!=argc ){
1356 return Th_WrongNumArgs(interp, GLOB_MATCH_WRONGNUMARGS);
1357 }
1358 if( one ){
1359 Th_SetResultInt(interp, sqlite3_strglob(argv[nArg], argv[nArg+1])==0);
 
1360 rc = TH_OK;
1361 }else{
1362 pGlob = glob_create(argv[nArg]);
1363 if( pGlob ){
1364 Th_SetResultInt(interp, glob_match(pGlob, argv[nArg+1]));
1365 rc = TH_OK;
1366 }else{
1367 Th_SetResult(interp, "unable to create glob from pattern list", -1);
1368 rc = TH_ERROR;
1369 }
1370 glob_free(pGlob);
1371 }
 
1372 return rc;
1373 }
1374
1375 /*
1376 ** TH1 command: regexp ?-nocase? ?--? exp string
1377
+3 -3
--- www/th1.md
+++ www/th1.md
@@ -248,14 +248,14 @@
248248
default value when there is no matching query parameter.
249249
250250
<a name="glob_match"></a>TH1 glob_match Command
251251
-----------------------------------------------
252252
253
- * glob_match ?--? patternList string
253
+ * glob_match ?-one? ?--? patternList string
254254
255
-Checks the string against the specified list of glob patterns and
256
-returns non-zero if there is a match.
255
+Checks the string against the specified glob pattern -OR- list of glob
256
+patterns and returns non-zero if there is a match.
257257
258258
<a name="globalState"></a>TH1 globalState Command
259259
-------------------------------------------------
260260
261261
* globalState NAME ?DEFAULT?
262262
--- www/th1.md
+++ www/th1.md
@@ -248,14 +248,14 @@
248 default value when there is no matching query parameter.
249
250 <a name="glob_match"></a>TH1 glob_match Command
251 -----------------------------------------------
252
253 * glob_match ?--? patternList string
254
255 Checks the string against the specified list of glob patterns and
256 returns non-zero if there is a match.
257
258 <a name="globalState"></a>TH1 globalState Command
259 -------------------------------------------------
260
261 * globalState NAME ?DEFAULT?
262
--- www/th1.md
+++ www/th1.md
@@ -248,14 +248,14 @@
248 default value when there is no matching query parameter.
249
250 <a name="glob_match"></a>TH1 glob_match Command
251 -----------------------------------------------
252
253 * glob_match ?-one? ?--? patternList string
254
255 Checks the string against the specified glob pattern -OR- list of glob
256 patterns and returns non-zero if there is a match.
257
258 <a name="globalState"></a>TH1 globalState Command
259 -------------------------------------------------
260
261 * globalState NAME ?DEFAULT?
262

Keyboard Shortcuts

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