Fossil SCM

Clean up the command-search logic.

drh 2014-07-16 22:17 trunk
Commit bcb7c7a9b1e947035ca41469de37e93bc7595bb8
2 files changed +7 -8 +2 -1
+7 -8
--- src/main.c
+++ src/main.c
@@ -298,15 +298,16 @@
298298
*/
299299
static int name_search(
300300
const char *zName, /* The name we are looking for */
301301
const NameMap *aMap, /* Search in this array */
302302
int nMap, /* Number of slots in aMap[] */
303
+ int iBegin, /* Lower bound on the array search */
303304
int *pIndex /* OUT: The index in aMap[] of the match */
304305
){
305306
int upr, lwr, cnt, m, i;
306307
int n = strlen(zName);
307
- lwr = 0;
308
+ lwr = iBegin;
308309
upr = nMap-1;
309310
while( lwr<=upr ){
310311
int mid, c;
311312
mid = (upr+lwr)/2;
312313
c = fossil_strcmp(zName, aMap[mid].zName);
@@ -318,11 +319,11 @@
318319
}else{
319320
lwr = mid + 1;
320321
}
321322
}
322323
for(m=cnt=0, i=upr-2; cnt<2 && i<=upr+3 && i<nMap; i++){
323
- if( i<0 ) continue;
324
+ if( i<iBegin ) continue;
324325
if( strncmp(zName, aMap[i].zName, n)==0 ){
325326
m = i;
326327
cnt++;
327328
}
328329
}
@@ -655,13 +656,11 @@
655656
}
656657
#ifndef _WIN32
657658
if( !is_valid_fd(2) ) fossil_panic("file descriptor 2 not open");
658659
/* if( is_valid_fd(3) ) fossil_warning("file descriptor 3 is open"); */
659660
#endif
660
- rc = name_search(zCmdName, aCommand + count(aWebpage),
661
- count(aCommand) - count(aWebpage), &idx);
662
- idx += count(aWebpage);
661
+ rc = name_search(zCmdName, aCommand, count(aCommand), FOSSIL_FIRST_CMD, &idx);
663662
if( rc==1 ){
664663
#ifdef FOSSIL_ENABLE_TH1_HOOKS
665664
if( !g.isHTTP && !g.fNoThHook ){
666665
rc = Th_CommandHook(zCmdName, 0);
667666
}else{
@@ -1017,11 +1016,11 @@
10171016
zCmdOrPagePlural = "pages";
10181017
}else{
10191018
zCmdOrPage = "command";
10201019
zCmdOrPagePlural = "commands";
10211020
}
1022
- rc = name_search(g.argv[2], aCommand, count(aCommand), &idx);
1021
+ rc = name_search(g.argv[2], aCommand, count(aCommand), 0, &idx);
10231022
if( rc==1 ){
10241023
fossil_print("unknown %s: %s\nAvailable %s:\n",
10251024
zCmdOrPage, g.argv[2], zCmdOrPagePlural);
10261025
command_list(0, isPage ? CMDFLAG_WEBPAGE : (0xff & ~CMDFLAG_WEBPAGE));
10271026
fossil_exit(1);
@@ -1061,11 +1060,11 @@
10611060
int rc, idx;
10621061
char *z, *s, *d;
10631062
char const * zCmdOrPage = ('/'==*zCmd) ? "page" : "command";
10641063
style_submenu_element("Command-List", "Command-List", "%s/help", g.zTop);
10651064
@ <h1>The "%s(zCmd)" %s(zCmdOrPage):</h1>
1066
- rc = name_search(zCmd, aCommand, count(aCommand), &idx);
1065
+ rc = name_search(zCmd, aCommand, count(aCommand), 0, &idx);
10671066
if( rc==1 ){
10681067
@ unknown command: %s(zCmd)
10691068
}else if( rc==2 ){
10701069
@ ambiguous command prefix: %s(zCmd)
10711070
}else{
@@ -1563,11 +1562,11 @@
15631562
}
15641563
15651564
/* Locate the method specified by the path and execute the function
15661565
** that implements that method.
15671566
*/
1568
- if( name_search(g.zPath, aWebpage, count(aWebpage), &idx) ){
1567
+ if( name_search(g.zPath, aWebpage, count(aWebpage), 0, &idx) ){
15691568
#ifdef FOSSIL_ENABLE_JSON
15701569
if(g.json.isJsonMode){
15711570
json_err(FSL_JSON_E_RESOURCE_NOT_FOUND,NULL,0);
15721571
}else
15731572
#endif
15741573
--- src/main.c
+++ src/main.c
@@ -298,15 +298,16 @@
298 */
299 static int name_search(
300 const char *zName, /* The name we are looking for */
301 const NameMap *aMap, /* Search in this array */
302 int nMap, /* Number of slots in aMap[] */
 
303 int *pIndex /* OUT: The index in aMap[] of the match */
304 ){
305 int upr, lwr, cnt, m, i;
306 int n = strlen(zName);
307 lwr = 0;
308 upr = nMap-1;
309 while( lwr<=upr ){
310 int mid, c;
311 mid = (upr+lwr)/2;
312 c = fossil_strcmp(zName, aMap[mid].zName);
@@ -318,11 +319,11 @@
318 }else{
319 lwr = mid + 1;
320 }
321 }
322 for(m=cnt=0, i=upr-2; cnt<2 && i<=upr+3 && i<nMap; i++){
323 if( i<0 ) continue;
324 if( strncmp(zName, aMap[i].zName, n)==0 ){
325 m = i;
326 cnt++;
327 }
328 }
@@ -655,13 +656,11 @@
655 }
656 #ifndef _WIN32
657 if( !is_valid_fd(2) ) fossil_panic("file descriptor 2 not open");
658 /* if( is_valid_fd(3) ) fossil_warning("file descriptor 3 is open"); */
659 #endif
660 rc = name_search(zCmdName, aCommand + count(aWebpage),
661 count(aCommand) - count(aWebpage), &idx);
662 idx += count(aWebpage);
663 if( rc==1 ){
664 #ifdef FOSSIL_ENABLE_TH1_HOOKS
665 if( !g.isHTTP && !g.fNoThHook ){
666 rc = Th_CommandHook(zCmdName, 0);
667 }else{
@@ -1017,11 +1016,11 @@
1017 zCmdOrPagePlural = "pages";
1018 }else{
1019 zCmdOrPage = "command";
1020 zCmdOrPagePlural = "commands";
1021 }
1022 rc = name_search(g.argv[2], aCommand, count(aCommand), &idx);
1023 if( rc==1 ){
1024 fossil_print("unknown %s: %s\nAvailable %s:\n",
1025 zCmdOrPage, g.argv[2], zCmdOrPagePlural);
1026 command_list(0, isPage ? CMDFLAG_WEBPAGE : (0xff & ~CMDFLAG_WEBPAGE));
1027 fossil_exit(1);
@@ -1061,11 +1060,11 @@
1061 int rc, idx;
1062 char *z, *s, *d;
1063 char const * zCmdOrPage = ('/'==*zCmd) ? "page" : "command";
1064 style_submenu_element("Command-List", "Command-List", "%s/help", g.zTop);
1065 @ <h1>The "%s(zCmd)" %s(zCmdOrPage):</h1>
1066 rc = name_search(zCmd, aCommand, count(aCommand), &idx);
1067 if( rc==1 ){
1068 @ unknown command: %s(zCmd)
1069 }else if( rc==2 ){
1070 @ ambiguous command prefix: %s(zCmd)
1071 }else{
@@ -1563,11 +1562,11 @@
1563 }
1564
1565 /* Locate the method specified by the path and execute the function
1566 ** that implements that method.
1567 */
1568 if( name_search(g.zPath, aWebpage, count(aWebpage), &idx) ){
1569 #ifdef FOSSIL_ENABLE_JSON
1570 if(g.json.isJsonMode){
1571 json_err(FSL_JSON_E_RESOURCE_NOT_FOUND,NULL,0);
1572 }else
1573 #endif
1574
--- src/main.c
+++ src/main.c
@@ -298,15 +298,16 @@
298 */
299 static int name_search(
300 const char *zName, /* The name we are looking for */
301 const NameMap *aMap, /* Search in this array */
302 int nMap, /* Number of slots in aMap[] */
303 int iBegin, /* Lower bound on the array search */
304 int *pIndex /* OUT: The index in aMap[] of the match */
305 ){
306 int upr, lwr, cnt, m, i;
307 int n = strlen(zName);
308 lwr = iBegin;
309 upr = nMap-1;
310 while( lwr<=upr ){
311 int mid, c;
312 mid = (upr+lwr)/2;
313 c = fossil_strcmp(zName, aMap[mid].zName);
@@ -318,11 +319,11 @@
319 }else{
320 lwr = mid + 1;
321 }
322 }
323 for(m=cnt=0, i=upr-2; cnt<2 && i<=upr+3 && i<nMap; i++){
324 if( i<iBegin ) continue;
325 if( strncmp(zName, aMap[i].zName, n)==0 ){
326 m = i;
327 cnt++;
328 }
329 }
@@ -655,13 +656,11 @@
656 }
657 #ifndef _WIN32
658 if( !is_valid_fd(2) ) fossil_panic("file descriptor 2 not open");
659 /* if( is_valid_fd(3) ) fossil_warning("file descriptor 3 is open"); */
660 #endif
661 rc = name_search(zCmdName, aCommand, count(aCommand), FOSSIL_FIRST_CMD, &idx);
 
 
662 if( rc==1 ){
663 #ifdef FOSSIL_ENABLE_TH1_HOOKS
664 if( !g.isHTTP && !g.fNoThHook ){
665 rc = Th_CommandHook(zCmdName, 0);
666 }else{
@@ -1017,11 +1016,11 @@
1016 zCmdOrPagePlural = "pages";
1017 }else{
1018 zCmdOrPage = "command";
1019 zCmdOrPagePlural = "commands";
1020 }
1021 rc = name_search(g.argv[2], aCommand, count(aCommand), 0, &idx);
1022 if( rc==1 ){
1023 fossil_print("unknown %s: %s\nAvailable %s:\n",
1024 zCmdOrPage, g.argv[2], zCmdOrPagePlural);
1025 command_list(0, isPage ? CMDFLAG_WEBPAGE : (0xff & ~CMDFLAG_WEBPAGE));
1026 fossil_exit(1);
@@ -1061,11 +1060,11 @@
1060 int rc, idx;
1061 char *z, *s, *d;
1062 char const * zCmdOrPage = ('/'==*zCmd) ? "page" : "command";
1063 style_submenu_element("Command-List", "Command-List", "%s/help", g.zTop);
1064 @ <h1>The "%s(zCmd)" %s(zCmdOrPage):</h1>
1065 rc = name_search(zCmd, aCommand, count(aCommand), 0, &idx);
1066 if( rc==1 ){
1067 @ unknown command: %s(zCmd)
1068 }else if( rc==2 ){
1069 @ ambiguous command prefix: %s(zCmd)
1070 }else{
@@ -1563,11 +1562,11 @@
1562 }
1563
1564 /* Locate the method specified by the path and execute the function
1565 ** that implements that method.
1566 */
1567 if( name_search(g.zPath, aWebpage, count(aWebpage), 0, &idx) ){
1568 #ifdef FOSSIL_ENABLE_JSON
1569 if(g.json.isJsonMode){
1570 json_err(FSL_JSON_E_RESOURCE_NOT_FOUND,NULL,0);
1571 }else
1572 #endif
1573
+2 -1
--- src/mkindex.c
+++ src/mkindex.c
@@ -283,11 +283,11 @@
283283
);
284284
for(i=0; i<nFixed /*&& aEntry[i].eType==1*/; i++){
285285
const char *z = aEntry[i].zPath;
286286
int n = strlen(z);
287287
int cmdFlags = (1==aEntry[i].eType) ? 0x01 : 0x08;
288
- if(0x01==cmdFlags){
288
+ if( 0x01==cmdFlags ){
289289
if( z[n-1]=='*' ){
290290
n--;
291291
cmdFlags = 0x02;
292292
}else if( memcmp(z, "test-", 5)==0 ){
293293
cmdFlags = 0x04;
@@ -303,10 +303,11 @@
303303
cmdFlags
304304
);
305305
if( aEntry[i].zIf ) printf("#endif\n");
306306
}
307307
printf("};\n");
308
+ printf("#define FOSSIL_FIRST_CMD (sizeof(aWebpage)/sizeof(aWebpage[0]))\n");
308309
for(i=0; i<nFixed; i++){
309310
char *z = aEntry[i].zHelp;
310311
if( z && z[0] ){
311312
if( aEntry[i].zIf ) printf("%s", aEntry[i].zIf);
312313
printf("static const char zHelp_%s[] = \n", aEntry[i].zFunc);
313314
--- src/mkindex.c
+++ src/mkindex.c
@@ -283,11 +283,11 @@
283 );
284 for(i=0; i<nFixed /*&& aEntry[i].eType==1*/; i++){
285 const char *z = aEntry[i].zPath;
286 int n = strlen(z);
287 int cmdFlags = (1==aEntry[i].eType) ? 0x01 : 0x08;
288 if(0x01==cmdFlags){
289 if( z[n-1]=='*' ){
290 n--;
291 cmdFlags = 0x02;
292 }else if( memcmp(z, "test-", 5)==0 ){
293 cmdFlags = 0x04;
@@ -303,10 +303,11 @@
303 cmdFlags
304 );
305 if( aEntry[i].zIf ) printf("#endif\n");
306 }
307 printf("};\n");
 
308 for(i=0; i<nFixed; i++){
309 char *z = aEntry[i].zHelp;
310 if( z && z[0] ){
311 if( aEntry[i].zIf ) printf("%s", aEntry[i].zIf);
312 printf("static const char zHelp_%s[] = \n", aEntry[i].zFunc);
313
--- src/mkindex.c
+++ src/mkindex.c
@@ -283,11 +283,11 @@
283 );
284 for(i=0; i<nFixed /*&& aEntry[i].eType==1*/; i++){
285 const char *z = aEntry[i].zPath;
286 int n = strlen(z);
287 int cmdFlags = (1==aEntry[i].eType) ? 0x01 : 0x08;
288 if( 0x01==cmdFlags ){
289 if( z[n-1]=='*' ){
290 n--;
291 cmdFlags = 0x02;
292 }else if( memcmp(z, "test-", 5)==0 ){
293 cmdFlags = 0x04;
@@ -303,10 +303,11 @@
303 cmdFlags
304 );
305 if( aEntry[i].zIf ) printf("#endif\n");
306 }
307 printf("};\n");
308 printf("#define FOSSIL_FIRST_CMD (sizeof(aWebpage)/sizeof(aWebpage[0]))\n");
309 for(i=0; i<nFixed; i++){
310 char *z = aEntry[i].zHelp;
311 if( z && z[0] ){
312 if( aEntry[i].zIf ) printf("%s", aEntry[i].zIf);
313 printf("static const char zHelp_%s[] = \n", aEntry[i].zFunc);
314

Keyboard Shortcuts

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