Fossil SCM
Prototype for a TH1 glob_match command.
Commit
f3ae47900256b85361393419fb396f56f61121c5
Parent
d10b1e022af373b…
2 files changed
+37
+9
+37
| --- src/th_main.c | ||
| +++ src/th_main.c | ||
| @@ -1324,10 +1324,46 @@ | ||
| 1324 | 1324 | Th_Trace("[setting %s%#h] => %d<br />\n", strict ? "strict " : "", |
| 1325 | 1325 | argl[nArg], argv[nArg], rc); |
| 1326 | 1326 | } |
| 1327 | 1327 | return rc; |
| 1328 | 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 | +} | |
| 1329 | 1365 | |
| 1330 | 1366 | /* |
| 1331 | 1367 | ** TH1 command: regexp ?-nocase? ?--? exp string |
| 1332 | 1368 | ** |
| 1333 | 1369 | ** Checks the string against the specified regular expression and returns |
| @@ -1553,10 +1589,11 @@ | ||
| 1553 | 1589 | {"combobox", comboboxCmd, 0}, |
| 1554 | 1590 | {"date", dateCmd, 0}, |
| 1555 | 1591 | {"decorate", wikiCmd, (void*)&aFlags[2]}, |
| 1556 | 1592 | {"enable_output", enableOutputCmd, 0}, |
| 1557 | 1593 | {"getParameter", getParameterCmd, 0}, |
| 1594 | + {"glob_match", globMatchCmd, 0}, | |
| 1558 | 1595 | {"globalState", globalStateCmd, 0}, |
| 1559 | 1596 | {"httpize", httpizeCmd, 0}, |
| 1560 | 1597 | {"hascap", hascapCmd, (void*)&zeroInt}, |
| 1561 | 1598 | {"hasfeature", hasfeatureCmd, 0}, |
| 1562 | 1599 | {"html", putsCmd, (void*)&aFlags[0]}, |
| 1563 | 1600 |
| --- src/th_main.c | |
| +++ src/th_main.c | |
| @@ -1324,10 +1324,46 @@ | |
| 1324 | Th_Trace("[setting %s%#h] => %d<br />\n", strict ? "strict " : "", |
| 1325 | argl[nArg], argv[nArg], rc); |
| 1326 | } |
| 1327 | return rc; |
| 1328 | } |
| 1329 | |
| 1330 | /* |
| 1331 | ** TH1 command: regexp ?-nocase? ?--? exp string |
| 1332 | ** |
| 1333 | ** Checks the string against the specified regular expression and returns |
| @@ -1553,10 +1589,11 @@ | |
| 1553 | {"combobox", comboboxCmd, 0}, |
| 1554 | {"date", dateCmd, 0}, |
| 1555 | {"decorate", wikiCmd, (void*)&aFlags[2]}, |
| 1556 | {"enable_output", enableOutputCmd, 0}, |
| 1557 | {"getParameter", getParameterCmd, 0}, |
| 1558 | {"globalState", globalStateCmd, 0}, |
| 1559 | {"httpize", httpizeCmd, 0}, |
| 1560 | {"hascap", hascapCmd, (void*)&zeroInt}, |
| 1561 | {"hasfeature", hasfeatureCmd, 0}, |
| 1562 | {"html", putsCmd, (void*)&aFlags[0]}, |
| 1563 |
| --- src/th_main.c | |
| +++ src/th_main.c | |
| @@ -1324,10 +1324,46 @@ | |
| 1324 | Th_Trace("[setting %s%#h] => %d<br />\n", strict ? "strict " : "", |
| 1325 | argl[nArg], argv[nArg], rc); |
| 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 | ** |
| 1369 | ** Checks the string against the specified regular expression and returns |
| @@ -1553,10 +1589,11 @@ | |
| 1589 | {"combobox", comboboxCmd, 0}, |
| 1590 | {"date", dateCmd, 0}, |
| 1591 | {"decorate", wikiCmd, (void*)&aFlags[2]}, |
| 1592 | {"enable_output", enableOutputCmd, 0}, |
| 1593 | {"getParameter", getParameterCmd, 0}, |
| 1594 | {"glob_match", globMatchCmd, 0}, |
| 1595 | {"globalState", globalStateCmd, 0}, |
| 1596 | {"httpize", httpizeCmd, 0}, |
| 1597 | {"hascap", hascapCmd, (void*)&zeroInt}, |
| 1598 | {"hasfeature", hasfeatureCmd, 0}, |
| 1599 | {"html", putsCmd, (void*)&aFlags[0]}, |
| 1600 |
+9
| --- www/th1.md | ||
| +++ www/th1.md | ||
| @@ -129,10 +129,11 @@ | ||
| 129 | 129 | * combobox |
| 130 | 130 | * date |
| 131 | 131 | * decorate |
| 132 | 132 | * enable_output |
| 133 | 133 | * getParameter |
| 134 | + * glob_match | |
| 134 | 135 | * globalState |
| 135 | 136 | * hascap |
| 136 | 137 | * hasfeature |
| 137 | 138 | * html |
| 138 | 139 | * htmlize |
| @@ -243,10 +244,18 @@ | ||
| 243 | 244 | |
| 244 | 245 | * getParameter NAME ?DEFAULT? |
| 245 | 246 | |
| 246 | 247 | Returns the value of the specified query parameter or the specified |
| 247 | 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. | |
| 248 | 257 | |
| 249 | 258 | <a name="globalState"></a>TH1 globalState Command |
| 250 | 259 | ------------------------------------------------- |
| 251 | 260 | |
| 252 | 261 | * globalState NAME ?DEFAULT? |
| 253 | 262 |
| --- www/th1.md | |
| +++ www/th1.md | |
| @@ -129,10 +129,11 @@ | |
| 129 | * combobox |
| 130 | * date |
| 131 | * decorate |
| 132 | * enable_output |
| 133 | * getParameter |
| 134 | * globalState |
| 135 | * hascap |
| 136 | * hasfeature |
| 137 | * html |
| 138 | * htmlize |
| @@ -243,10 +244,18 @@ | |
| 243 | |
| 244 | * getParameter NAME ?DEFAULT? |
| 245 | |
| 246 | Returns the value of the specified query parameter or the specified |
| 247 | default value when there is no matching query parameter. |
| 248 | |
| 249 | <a name="globalState"></a>TH1 globalState Command |
| 250 | ------------------------------------------------- |
| 251 | |
| 252 | * globalState NAME ?DEFAULT? |
| 253 |
| --- www/th1.md | |
| +++ www/th1.md | |
| @@ -129,10 +129,11 @@ | |
| 129 | * combobox |
| 130 | * date |
| 131 | * decorate |
| 132 | * enable_output |
| 133 | * getParameter |
| 134 | * glob_match |
| 135 | * globalState |
| 136 | * hascap |
| 137 | * hasfeature |
| 138 | * html |
| 139 | * htmlize |
| @@ -243,10 +244,18 @@ | |
| 244 | |
| 245 | * getParameter NAME ?DEFAULT? |
| 246 | |
| 247 | Returns the value of the specified query parameter or the specified |
| 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 |