Fossil SCM
Assorted cleanups associated with [f74f7014], most notably making "fossil dif" work again despite the ambiguity with setting "diff-command"
Commit
2b6a34c7e45c16c75c90ee0c8cc5ad4a202d6008ed66701cc5552ea833719356
Parent
fd9fd4c9e683a9d…
1 file changed
+31
-20
+31
-20
| --- src/dispatch.c | ||
| +++ src/dispatch.c | ||
| @@ -25,15 +25,15 @@ | ||
| 25 | 25 | #include "dispatch.h" |
| 26 | 26 | |
| 27 | 27 | #if INTERFACE |
| 28 | 28 | /* |
| 29 | 29 | ** An instance of this object defines everything we need to know about an |
| 30 | -** individual command or webpage. | |
| 30 | +** individual command, webpage, or setting. | |
| 31 | 31 | */ |
| 32 | 32 | struct CmdOrPage { |
| 33 | 33 | 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 */ | |
| 35 | 35 | const char *zHelp; /* Raw help text */ |
| 36 | 36 | unsigned int eCmdFlags; /* Flags */ |
| 37 | 37 | }; |
| 38 | 38 | |
| 39 | 39 | /*************************************************************************** |
| @@ -75,16 +75,16 @@ | ||
| 75 | 75 | */ |
| 76 | 76 | #include "page_index.h" |
| 77 | 77 | #define MX_COMMAND count(aCommand) |
| 78 | 78 | |
| 79 | 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. | |
| 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 | 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. | |
| 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 | 86 | ** |
| 87 | 87 | ** Return values: |
| 88 | 88 | ** 0: Success. *ppCmd is set to the appropriate CmdOrPage |
| 89 | 89 | ** 1: Not found. |
| 90 | 90 | ** 2: Ambiguous. Two or more entries match. |
| @@ -114,14 +114,24 @@ | ||
| 114 | 114 | } |
| 115 | 115 | if( (eType & CMDFLAG_PREFIX)!=0 |
| 116 | 116 | && lwr<MX_COMMAND |
| 117 | 117 | && strncmp(zName, aCommand[lwr].zName, nName)==0 |
| 118 | 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]; | |
| 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]; | |
| 123 | 133 | return 0; /* Prefix match */ |
| 124 | 134 | } |
| 125 | 135 | } |
| 126 | 136 | return 1; /* Not found */ |
| 127 | 137 | } |
| @@ -541,22 +551,23 @@ | ||
| 541 | 551 | } |
| 542 | 552 | |
| 543 | 553 | /* |
| 544 | 554 | ** COMMAND: help |
| 545 | 555 | ** |
| 546 | -** Usage: %fossil help COMMAND | |
| 547 | -** or: %fossil COMMAND --help | |
| 556 | +** Usage: %fossil help TOPIC | |
| 557 | +** or: %fossil TOPIC --help | |
| 548 | 558 | ** |
| 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: | |
| 551 | 562 | ** |
| 552 | 563 | ** %fossil help Show common commands |
| 553 | 564 | ** %fossil help -a|--all Show both common and auxiliary commands |
| 554 | 565 | ** %fossil help -s|--settings Show setting names |
| 555 | 566 | ** %fossil help -t|--test Show test commands only |
| 556 | 567 | ** %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 | |
| 558 | 569 | */ |
| 559 | 570 | void help_cmd(void){ |
| 560 | 571 | int rc; |
| 561 | 572 | int isPage = 0; |
| 562 | 573 | const char *z; |
| @@ -564,12 +575,12 @@ | ||
| 564 | 575 | const char *zCmdOrPagePlural; |
| 565 | 576 | const CmdOrPage *pCmd = 0; |
| 566 | 577 | if( g.argc<3 ){ |
| 567 | 578 | z = g.argv[0]; |
| 568 | 579 | 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", | |
| 571 | 582 | z, z); |
| 572 | 583 | command_list(0, CMDFLAG_1ST_TIER); |
| 573 | 584 | version_cmd(); |
| 574 | 585 | return; |
| 575 | 586 | } |
| @@ -596,12 +607,12 @@ | ||
| 596 | 607 | isPage = ('/' == *g.argv[2]) ? 1 : 0; |
| 597 | 608 | if(isPage){ |
| 598 | 609 | zCmdOrPage = "page"; |
| 599 | 610 | zCmdOrPagePlural = "pages"; |
| 600 | 611 | }else{ |
| 601 | - zCmdOrPage = "command"; | |
| 602 | - zCmdOrPagePlural = "commands"; | |
| 612 | + zCmdOrPage = "command or setting"; | |
| 613 | + zCmdOrPagePlural = "commands and settings"; | |
| 603 | 614 | } |
| 604 | 615 | rc = dispatch_name_search(g.argv[2], CMDFLAG_ANY|CMDFLAG_PREFIX, &pCmd); |
| 605 | 616 | if( rc==1 ){ |
| 606 | 617 | fossil_print("unknown %s: %s\nConsider using:\n", zCmdOrPage, g.argv[2]); |
| 607 | 618 | fossil_print(" fossil help -a ;# show all commands\n"); |
| 608 | 619 |
| --- 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 |