Fossil SCM

Assorted cleanups associated with [f74f7014], most notably making "fossil dif" work again despite the ambiguity with setting "diff-command"

andygoth 2017-09-27 03:23 trunk
Commit 2b6a34c7e45c16c75c90ee0c8cc5ad4a202d6008ed66701cc5552ea833719356
1 file changed +31 -20
+31 -20
--- src/dispatch.c
+++ src/dispatch.c
@@ -25,15 +25,15 @@
2525
#include "dispatch.h"
2626
2727
#if INTERFACE
2828
/*
2929
** An instance of this object defines everything we need to know about an
30
-** individual command or webpage.
30
+** individual command, webpage, or setting.
3131
*/
3232
struct CmdOrPage {
3333
const char *zName; /* Name. Webpages start with "/". Commands do not */
34
- void (*xFunc)(void); /* Function that implements the command or webpage */
34
+ void (*xFunc)(void); /* Implementation function, or NULL for settings */
3535
const char *zHelp; /* Raw help text */
3636
unsigned int eCmdFlags; /* Flags */
3737
};
3838
3939
/***************************************************************************
@@ -75,16 +75,16 @@
7575
*/
7676
#include "page_index.h"
7777
#define MX_COMMAND count(aCommand)
7878
7979
/*
80
-** Given a command or webpage name in zName, find the corresponding CmdOrPage
81
-** object and return a pointer to that object in *ppCmd.
80
+** Given a command, webpage, or setting name in zName, find the corresponding
81
+** CmdOrPage object and return a pointer to that object in *ppCmd.
8282
**
83
-** The eType field is CMDFLAG_COMMAND to lookup commands or CMDFLAG_WEBPAGE
84
-** to look up webpages or CMDFLAG_ANY to look for either. If the CMDFLAG_PREFIX
85
-** flag is set, then a prefix match is allowed.
83
+** The eType field is CMDFLAG_COMMAND to look up commands, CMDFLAG_WEBPAGE to
84
+** look up webpages, CMDFLAG_SETTING to look up settings, or CMDFLAG_ANY to look
85
+** for any. If the CMDFLAG_PREFIX bit is set, then a prefix match is allowed.
8686
**
8787
** Return values:
8888
** 0: Success. *ppCmd is set to the appropriate CmdOrPage
8989
** 1: Not found.
9090
** 2: Ambiguous. Two or more entries match.
@@ -114,14 +114,24 @@
114114
}
115115
if( (eType & CMDFLAG_PREFIX)!=0
116116
&& lwr<MX_COMMAND
117117
&& strncmp(zName, aCommand[lwr].zName, nName)==0
118118
){
119
- if( lwr<MX_COMMAND-1 && strncmp(zName, aCommand[lwr+1].zName, nName)==0 ){
120
- return 2; /* Ambiguous prefix */
121
- }else{
122
- *ppCmd = &aCommand[lwr];
119
+ /* An inexact prefix match was found. Scan the name table to try to find
120
+ * exactly one entry with this prefix and the requested type. */
121
+ for( mid=-1; lwr<MX_COMMAND
122
+ && strncmp(zName, aCommand[lwr].zName, nName)==0; ++lwr ){
123
+ if( aCommand[lwr].eCmdFlags & eType ){
124
+ if( mid<0 ){
125
+ mid = lwr; /* Potential ambiguous prefix */
126
+ }else{
127
+ return 2; /* Confirmed ambiguous prefix */
128
+ }
129
+ }
130
+ }
131
+ if( mid>=0 ){
132
+ *ppCmd = &aCommand[mid];
123133
return 0; /* Prefix match */
124134
}
125135
}
126136
return 1; /* Not found */
127137
}
@@ -541,22 +551,23 @@
541551
}
542552
543553
/*
544554
** COMMAND: help
545555
**
546
-** Usage: %fossil help COMMAND
547
-** or: %fossil COMMAND --help
556
+** Usage: %fossil help TOPIC
557
+** or: %fossil TOPIC --help
548558
**
549
-** Display information on how to use COMMAND. To display a list of
550
-** available commands use one of:
559
+** Display information on how to use TOPIC, which may be a command, webpage, or
560
+** setting. Webpage names begin with "/". To display a list of available
561
+** topics, use one of:
551562
**
552563
** %fossil help Show common commands
553564
** %fossil help -a|--all Show both common and auxiliary commands
554565
** %fossil help -s|--settings Show setting names
555566
** %fossil help -t|--test Show test commands only
556567
** %fossil help -x|--aux Show auxiliary commands only
557
-** %fossil help -w|--www Show list of WWW pages
568
+** %fossil help -w|--www Show list of webpages
558569
*/
559570
void help_cmd(void){
560571
int rc;
561572
int isPage = 0;
562573
const char *z;
@@ -564,12 +575,12 @@
564575
const char *zCmdOrPagePlural;
565576
const CmdOrPage *pCmd = 0;
566577
if( g.argc<3 ){
567578
z = g.argv[0];
568579
fossil_print(
569
- "Usage: %s help COMMAND\n"
570
- "Common COMMANDs: (use \"%s help -a|--all\" for a complete list)\n",
580
+ "Usage: %s help TOPIC\n"
581
+ "Common commands: (use \"%s help -a|--all\" for a complete list)\n",
571582
z, z);
572583
command_list(0, CMDFLAG_1ST_TIER);
573584
version_cmd();
574585
return;
575586
}
@@ -596,12 +607,12 @@
596607
isPage = ('/' == *g.argv[2]) ? 1 : 0;
597608
if(isPage){
598609
zCmdOrPage = "page";
599610
zCmdOrPagePlural = "pages";
600611
}else{
601
- zCmdOrPage = "command";
602
- zCmdOrPagePlural = "commands";
612
+ zCmdOrPage = "command or setting";
613
+ zCmdOrPagePlural = "commands and settings";
603614
}
604615
rc = dispatch_name_search(g.argv[2], CMDFLAG_ANY|CMDFLAG_PREFIX, &pCmd);
605616
if( rc==1 ){
606617
fossil_print("unknown %s: %s\nConsider using:\n", zCmdOrPage, g.argv[2]);
607618
fossil_print(" fossil help -a ;# show all commands\n");
608619
--- src/dispatch.c
+++ src/dispatch.c
@@ -25,15 +25,15 @@
25 #include "dispatch.h"
26
27 #if INTERFACE
28 /*
29 ** An instance of this object defines everything we need to know about an
30 ** individual command or webpage.
31 */
32 struct CmdOrPage {
33 const char *zName; /* Name. Webpages start with "/". Commands do not */
34 void (*xFunc)(void); /* Function that implements the command or webpage */
35 const char *zHelp; /* Raw help text */
36 unsigned int eCmdFlags; /* Flags */
37 };
38
39 /***************************************************************************
@@ -75,16 +75,16 @@
75 */
76 #include "page_index.h"
77 #define MX_COMMAND count(aCommand)
78
79 /*
80 ** Given a command or webpage name in zName, find the corresponding CmdOrPage
81 ** object and return a pointer to that object in *ppCmd.
82 **
83 ** The eType field is CMDFLAG_COMMAND to lookup commands or CMDFLAG_WEBPAGE
84 ** to look up webpages or CMDFLAG_ANY to look for either. If the CMDFLAG_PREFIX
85 ** flag is set, then a prefix match is allowed.
86 **
87 ** Return values:
88 ** 0: Success. *ppCmd is set to the appropriate CmdOrPage
89 ** 1: Not found.
90 ** 2: Ambiguous. Two or more entries match.
@@ -114,14 +114,24 @@
114 }
115 if( (eType & CMDFLAG_PREFIX)!=0
116 && lwr<MX_COMMAND
117 && strncmp(zName, aCommand[lwr].zName, nName)==0
118 ){
119 if( lwr<MX_COMMAND-1 && strncmp(zName, aCommand[lwr+1].zName, nName)==0 ){
120 return 2; /* Ambiguous prefix */
121 }else{
122 *ppCmd = &aCommand[lwr];
 
 
 
 
 
 
 
 
 
 
123 return 0; /* Prefix match */
124 }
125 }
126 return 1; /* Not found */
127 }
@@ -541,22 +551,23 @@
541 }
542
543 /*
544 ** COMMAND: help
545 **
546 ** Usage: %fossil help COMMAND
547 ** or: %fossil COMMAND --help
548 **
549 ** Display information on how to use COMMAND. To display a list of
550 ** available commands use one of:
 
551 **
552 ** %fossil help Show common commands
553 ** %fossil help -a|--all Show both common and auxiliary commands
554 ** %fossil help -s|--settings Show setting names
555 ** %fossil help -t|--test Show test commands only
556 ** %fossil help -x|--aux Show auxiliary commands only
557 ** %fossil help -w|--www Show list of WWW pages
558 */
559 void help_cmd(void){
560 int rc;
561 int isPage = 0;
562 const char *z;
@@ -564,12 +575,12 @@
564 const char *zCmdOrPagePlural;
565 const CmdOrPage *pCmd = 0;
566 if( g.argc<3 ){
567 z = g.argv[0];
568 fossil_print(
569 "Usage: %s help COMMAND\n"
570 "Common COMMANDs: (use \"%s help -a|--all\" for a complete list)\n",
571 z, z);
572 command_list(0, CMDFLAG_1ST_TIER);
573 version_cmd();
574 return;
575 }
@@ -596,12 +607,12 @@
596 isPage = ('/' == *g.argv[2]) ? 1 : 0;
597 if(isPage){
598 zCmdOrPage = "page";
599 zCmdOrPagePlural = "pages";
600 }else{
601 zCmdOrPage = "command";
602 zCmdOrPagePlural = "commands";
603 }
604 rc = dispatch_name_search(g.argv[2], CMDFLAG_ANY|CMDFLAG_PREFIX, &pCmd);
605 if( rc==1 ){
606 fossil_print("unknown %s: %s\nConsider using:\n", zCmdOrPage, g.argv[2]);
607 fossil_print(" fossil help -a ;# show all commands\n");
608
--- src/dispatch.c
+++ src/dispatch.c
@@ -25,15 +25,15 @@
25 #include "dispatch.h"
26
27 #if INTERFACE
28 /*
29 ** An instance of this object defines everything we need to know about an
30 ** individual command, webpage, or setting.
31 */
32 struct CmdOrPage {
33 const char *zName; /* Name. Webpages start with "/". Commands do not */
34 void (*xFunc)(void); /* Implementation function, or NULL for settings */
35 const char *zHelp; /* Raw help text */
36 unsigned int eCmdFlags; /* Flags */
37 };
38
39 /***************************************************************************
@@ -75,16 +75,16 @@
75 */
76 #include "page_index.h"
77 #define MX_COMMAND count(aCommand)
78
79 /*
80 ** Given a command, webpage, or setting name in zName, find the corresponding
81 ** CmdOrPage object and return a pointer to that object in *ppCmd.
82 **
83 ** The eType field is CMDFLAG_COMMAND to look up commands, CMDFLAG_WEBPAGE to
84 ** look up webpages, CMDFLAG_SETTING to look up settings, or CMDFLAG_ANY to look
85 ** for any. If the CMDFLAG_PREFIX bit is set, then a prefix match is allowed.
86 **
87 ** Return values:
88 ** 0: Success. *ppCmd is set to the appropriate CmdOrPage
89 ** 1: Not found.
90 ** 2: Ambiguous. Two or more entries match.
@@ -114,14 +114,24 @@
114 }
115 if( (eType & CMDFLAG_PREFIX)!=0
116 && lwr<MX_COMMAND
117 && strncmp(zName, aCommand[lwr].zName, nName)==0
118 ){
119 /* An inexact prefix match was found. Scan the name table to try to find
120 * exactly one entry with this prefix and the requested type. */
121 for( mid=-1; lwr<MX_COMMAND
122 && strncmp(zName, aCommand[lwr].zName, nName)==0; ++lwr ){
123 if( aCommand[lwr].eCmdFlags & eType ){
124 if( mid<0 ){
125 mid = lwr; /* Potential ambiguous prefix */
126 }else{
127 return 2; /* Confirmed ambiguous prefix */
128 }
129 }
130 }
131 if( mid>=0 ){
132 *ppCmd = &aCommand[mid];
133 return 0; /* Prefix match */
134 }
135 }
136 return 1; /* Not found */
137 }
@@ -541,22 +551,23 @@
551 }
552
553 /*
554 ** COMMAND: help
555 **
556 ** Usage: %fossil help TOPIC
557 ** or: %fossil TOPIC --help
558 **
559 ** Display information on how to use TOPIC, which may be a command, webpage, or
560 ** setting. Webpage names begin with "/". To display a list of available
561 ** topics, use one of:
562 **
563 ** %fossil help Show common commands
564 ** %fossil help -a|--all Show both common and auxiliary commands
565 ** %fossil help -s|--settings Show setting names
566 ** %fossil help -t|--test Show test commands only
567 ** %fossil help -x|--aux Show auxiliary commands only
568 ** %fossil help -w|--www Show list of webpages
569 */
570 void help_cmd(void){
571 int rc;
572 int isPage = 0;
573 const char *z;
@@ -564,12 +575,12 @@
575 const char *zCmdOrPagePlural;
576 const CmdOrPage *pCmd = 0;
577 if( g.argc<3 ){
578 z = g.argv[0];
579 fossil_print(
580 "Usage: %s help TOPIC\n"
581 "Common commands: (use \"%s help -a|--all\" for a complete list)\n",
582 z, z);
583 command_list(0, CMDFLAG_1ST_TIER);
584 version_cmd();
585 return;
586 }
@@ -596,12 +607,12 @@
607 isPage = ('/' == *g.argv[2]) ? 1 : 0;
608 if(isPage){
609 zCmdOrPage = "page";
610 zCmdOrPagePlural = "pages";
611 }else{
612 zCmdOrPage = "command or setting";
613 zCmdOrPagePlural = "commands and settings";
614 }
615 rc = dispatch_name_search(g.argv[2], CMDFLAG_ANY|CMDFLAG_PREFIX, &pCmd);
616 if( rc==1 ){
617 fossil_print("unknown %s: %s\nConsider using:\n", zCmdOrPage, g.argv[2]);
618 fossil_print(" fossil help -a ;# show all commands\n");
619

Keyboard Shortcuts

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