Fossil SCM

Simplified the verify_all_options() porting strategy, such that -- is disallowed by default and routines which should/can support it need to call verify_all_options2() instead of us changing the signature of verify_all_options(). This will result in far fewer changes than the previous approach.

stephan 2019-09-27 09:55 UTC double-dash-flag
Commit a9b9b5bceea2f4d24aa9ac81d298d240ab17734b4ac66870b374f3d08a697b66
1 file changed +22 -9
+22 -9
--- src/main.c
+++ src/main.c
@@ -1037,24 +1037,22 @@
10371037
** Any remaining command-line argument begins with "-" print
10381038
** an error message and quit.
10391039
**
10401040
** If fAllowDoubleDash is true then if the flag "--" is found, it is
10411041
** removed from the list and arguments after that flag are not
1042
-** inspected by this function (they are assumed to be filenames, even
1043
-** if they syntactically look like flags). If fAllowDoubleDash is
1044
-** false then the "--" flag will trigger a fatal error exactly as if
1045
-** an unprocessed flag were encountered.
1042
+** inspected by this function (they are assumed to be
1043
+** file/wiki/branch/etc. names, even if they syntactically look like
1044
+** flags). If fAllowDoubleDash is false then the "--" flag will
1045
+** trigger a fatal error exactly as if an unprocessed flag were
1046
+** encountered.
10461047
**
10471048
** Sidebar: the question of whether fAllowDoubleDash should be true or
10481049
** false would seem to boil down to: does the calling routine
10491050
** expect/allow arbitrary file/page/branch/whatever name arguments
10501051
** after its required arguments?
1051
-**
1052
-** Once the "--" support is completed, this function will be renamed
1053
-** (back) to verify_all_options().
10541052
*/
1055
-void verify_all_options_porting_crutch(int fAllowDoubleDash){
1053
+static void verify_all_options_impl(int fAllowDoubleDash){
10561054
int i;
10571055
for(i=1; i<g.argc; i++){
10581056
const char * arg = g.argv[i];
10591057
if( arg[0]=='-' ){
10601058
if( arg[1]=='-' && arg[2]==0 ){
@@ -1073,12 +1071,27 @@
10731071
}
10741072
}
10751073
}
10761074
}
10771075
1076
+/*
1077
+** Must be called by all commands which process CLI flags, after
1078
+** consuming those flags (via find_option() and friends), to confirm
1079
+** that no unconsumed flags are still in the arguments list. If the
1080
+** command should/can honor the "--" flag, call verify_all_options2()
1081
+** instead.
1082
+*/
10781083
void verify_all_options(void){
1079
- verify_all_options_porting_crutch(0);
1084
+ verify_all_options_impl(0);
1085
+}
1086
+
1087
+/*
1088
+** Identical to verify_all_options() except that it honors the "--"
1089
+** flag.
1090
+*/
1091
+void verify_all_options2(void){
1092
+ verify_all_options_impl(1);
10801093
}
10811094
10821095
/*
10831096
** This function returns a human readable version string.
10841097
*/
10851098
--- src/main.c
+++ src/main.c
@@ -1037,24 +1037,22 @@
1037 ** Any remaining command-line argument begins with "-" print
1038 ** an error message and quit.
1039 **
1040 ** If fAllowDoubleDash is true then if the flag "--" is found, it is
1041 ** removed from the list and arguments after that flag are not
1042 ** inspected by this function (they are assumed to be filenames, even
1043 ** if they syntactically look like flags). If fAllowDoubleDash is
1044 ** false then the "--" flag will trigger a fatal error exactly as if
1045 ** an unprocessed flag were encountered.
 
1046 **
1047 ** Sidebar: the question of whether fAllowDoubleDash should be true or
1048 ** false would seem to boil down to: does the calling routine
1049 ** expect/allow arbitrary file/page/branch/whatever name arguments
1050 ** after its required arguments?
1051 **
1052 ** Once the "--" support is completed, this function will be renamed
1053 ** (back) to verify_all_options().
1054 */
1055 void verify_all_options_porting_crutch(int fAllowDoubleDash){
1056 int i;
1057 for(i=1; i<g.argc; i++){
1058 const char * arg = g.argv[i];
1059 if( arg[0]=='-' ){
1060 if( arg[1]=='-' && arg[2]==0 ){
@@ -1073,12 +1071,27 @@
1073 }
1074 }
1075 }
1076 }
1077
 
 
 
 
 
 
 
1078 void verify_all_options(void){
1079 verify_all_options_porting_crutch(0);
 
 
 
 
 
 
 
 
1080 }
1081
1082 /*
1083 ** This function returns a human readable version string.
1084 */
1085
--- src/main.c
+++ src/main.c
@@ -1037,24 +1037,22 @@
1037 ** Any remaining command-line argument begins with "-" print
1038 ** an error message and quit.
1039 **
1040 ** If fAllowDoubleDash is true then if the flag "--" is found, it is
1041 ** removed from the list and arguments after that flag are not
1042 ** inspected by this function (they are assumed to be
1043 ** file/wiki/branch/etc. names, even if they syntactically look like
1044 ** flags). If fAllowDoubleDash is false then the "--" flag will
1045 ** trigger a fatal error exactly as if an unprocessed flag were
1046 ** encountered.
1047 **
1048 ** Sidebar: the question of whether fAllowDoubleDash should be true or
1049 ** false would seem to boil down to: does the calling routine
1050 ** expect/allow arbitrary file/page/branch/whatever name arguments
1051 ** after its required arguments?
 
 
 
1052 */
1053 static void verify_all_options_impl(int fAllowDoubleDash){
1054 int i;
1055 for(i=1; i<g.argc; i++){
1056 const char * arg = g.argv[i];
1057 if( arg[0]=='-' ){
1058 if( arg[1]=='-' && arg[2]==0 ){
@@ -1073,12 +1071,27 @@
1071 }
1072 }
1073 }
1074 }
1075
1076 /*
1077 ** Must be called by all commands which process CLI flags, after
1078 ** consuming those flags (via find_option() and friends), to confirm
1079 ** that no unconsumed flags are still in the arguments list. If the
1080 ** command should/can honor the "--" flag, call verify_all_options2()
1081 ** instead.
1082 */
1083 void verify_all_options(void){
1084 verify_all_options_impl(0);
1085 }
1086
1087 /*
1088 ** Identical to verify_all_options() except that it honors the "--"
1089 ** flag.
1090 */
1091 void verify_all_options2(void){
1092 verify_all_options_impl(1);
1093 }
1094
1095 /*
1096 ** This function returns a human readable version string.
1097 */
1098

Keyboard Shortcuts

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