Fossil SCM
Add the -one option to the 'glob_match' command.
Commit
f7d4c544cad47c8577906ebb5eee0b0cddc07fdc
Parent
f3ae47900256b85…
2 files changed
+20
-11
+3
-3
+20
-11
| --- src/th_main.c | ||
| +++ src/th_main.c | ||
| @@ -1326,42 +1326,51 @@ | ||
| 1326 | 1326 | } |
| 1327 | 1327 | return rc; |
| 1328 | 1328 | } |
| 1329 | 1329 | |
| 1330 | 1330 | /* |
| 1331 | -** TH1 command: glob_match ?--? patternList string | |
| 1331 | +** TH1 command: glob_match ?-one? ?--? patternList string | |
| 1332 | 1332 | ** |
| 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. | |
| 1335 | 1335 | */ |
| 1336 | -#define GLOB_MATCH_WRONGNUMARGS "glob_match ?--? patternList string" | |
| 1336 | +#define GLOB_MATCH_WRONGNUMARGS "glob_match ?-one? ?--? patternList string" | |
| 1337 | 1337 | static int globMatchCmd( |
| 1338 | 1338 | Th_Interp *interp, |
| 1339 | 1339 | void *p, |
| 1340 | 1340 | int argc, |
| 1341 | 1341 | const char **argv, |
| 1342 | 1342 | int *argl |
| 1343 | 1343 | ){ |
| 1344 | 1344 | int rc; |
| 1345 | + int one = 0; | |
| 1345 | 1346 | int nArg = 1; |
| 1346 | 1347 | Glob *pGlob = 0; |
| 1347 | - if( argc<3 || argc>4 ){ | |
| 1348 | + if( argc<3 || argc>5 ){ | |
| 1348 | 1349 | return Th_WrongNumArgs(interp, GLOB_MATCH_WRONGNUMARGS); |
| 1350 | + } | |
| 1351 | + if( fossil_strcmp(argv[nArg], "-one")==0 ){ | |
| 1352 | + one = 1; nArg++; | |
| 1349 | 1353 | } |
| 1350 | 1354 | if( fossil_strcmp(argv[nArg], "--")==0 ) nArg++; |
| 1351 | 1355 | if( nArg+2!=argc ){ |
| 1352 | 1356 | return Th_WrongNumArgs(interp, GLOB_MATCH_WRONGNUMARGS); |
| 1353 | 1357 | } |
| 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); | |
| 1357 | 1360 | rc = TH_OK; |
| 1358 | 1361 | }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); | |
| 1361 | 1371 | } |
| 1362 | - glob_free(pGlob); | |
| 1363 | 1372 | return rc; |
| 1364 | 1373 | } |
| 1365 | 1374 | |
| 1366 | 1375 | /* |
| 1367 | 1376 | ** TH1 command: regexp ?-nocase? ?--? exp string |
| 1368 | 1377 |
| --- 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 @@ | ||
| 248 | 248 | default value when there is no matching query parameter. |
| 249 | 249 | |
| 250 | 250 | <a name="glob_match"></a>TH1 glob_match Command |
| 251 | 251 | ----------------------------------------------- |
| 252 | 252 | |
| 253 | - * glob_match ?--? patternList string | |
| 253 | + * glob_match ?-one? ?--? patternList string | |
| 254 | 254 | |
| 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. | |
| 257 | 257 | |
| 258 | 258 | <a name="globalState"></a>TH1 globalState Command |
| 259 | 259 | ------------------------------------------------- |
| 260 | 260 | |
| 261 | 261 | * globalState NAME ?DEFAULT? |
| 262 | 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 ?--? 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 |