Fossil SCM

Prototype for a TH1 glob_match command.

mistachkin 2015-05-27 03:26 UTC trunk
Commit f3ae47900256b85361393419fb396f56f61121c5
2 files changed +37 +9
--- src/th_main.c
+++ src/th_main.c
@@ -1324,10 +1324,46 @@
13241324
Th_Trace("[setting %s%#h] => %d<br />\n", strict ? "strict " : "",
13251325
argl[nArg], argv[nArg], rc);
13261326
}
13271327
return rc;
13281328
}
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
+}
13291365
13301366
/*
13311367
** TH1 command: regexp ?-nocase? ?--? exp string
13321368
**
13331369
** Checks the string against the specified regular expression and returns
@@ -1553,10 +1589,11 @@
15531589
{"combobox", comboboxCmd, 0},
15541590
{"date", dateCmd, 0},
15551591
{"decorate", wikiCmd, (void*)&aFlags[2]},
15561592
{"enable_output", enableOutputCmd, 0},
15571593
{"getParameter", getParameterCmd, 0},
1594
+ {"glob_match", globMatchCmd, 0},
15581595
{"globalState", globalStateCmd, 0},
15591596
{"httpize", httpizeCmd, 0},
15601597
{"hascap", hascapCmd, (void*)&zeroInt},
15611598
{"hasfeature", hasfeatureCmd, 0},
15621599
{"html", putsCmd, (void*)&aFlags[0]},
15631600
--- 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 @@
129129
* combobox
130130
* date
131131
* decorate
132132
* enable_output
133133
* getParameter
134
+ * glob_match
134135
* globalState
135136
* hascap
136137
* hasfeature
137138
* html
138139
* htmlize
@@ -243,10 +244,18 @@
243244
244245
* getParameter NAME ?DEFAULT?
245246
246247
Returns the value of the specified query parameter or the specified
247248
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.
248257
249258
<a name="globalState"></a>TH1 globalState Command
250259
-------------------------------------------------
251260
252261
* globalState NAME ?DEFAULT?
253262
--- 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

Keyboard Shortcuts

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