139
140
141
142
143
144
145
146
147
148
149
150
151
152
|
void *xPostEval; /* Optional, called after Tcl_Eval*(). */
void *pPostContext; /* Optional, provided to xPostEval(). */
};
#endif
struct Global {
int argc; char **argv; /* Command-line arguments to the program */
char *nameOfExe; /* Full path of executable. */
const char *zErrlog; /* Log errors to this file, if not NULL */
int isConst; /* True if the output is unchanging & cacheable */
const char *zVfsName; /* The VFS to use for database connections */
sqlite3 *db; /* The connection to the databases */
sqlite3 *dbConfig; /* Separate connection for global_config table */
char *zAuxSchema; /* Main repository aux-schema */
|
>
>
>
|
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
|
void *xPostEval; /* Optional, called after Tcl_Eval*(). */
void *pPostContext; /* Optional, provided to xPostEval(). */
};
#endif
struct Global {
int argc; char **argv; /* Command-line arguments to the program */
int argDashDashIndex; /* Index of the "--" flag in g.argv, if provided
** (else 0). Not valid until verify_all_options()
** or verify_all_options2() is called. */;
char *nameOfExe; /* Full path of executable. */
const char *zErrlog; /* Log errors to this file, if not NULL */
int isConst; /* True if the output is unchanging & cacheable */
const char *zVfsName; /* The VFS to use for database connections */
sqlite3 *db; /* The connection to the databases */
sqlite3 *dbConfig; /* Separate connection for global_config table */
char *zAuxSchema; /* Main repository aux-schema */
|
1044
1045
1046
1047
1048
1049
1050
1051
1052
1053
1054
1055
1056
1057
1058
1059
1060
1061
1062
1063
1064
1065
1066
1067
1068
1069
1070
1071
1072
1073
1074
1075
|
** flags). If fAllowDoubleDash is false then the "--" flag will
** trigger a fatal error exactly as if an unprocessed flag were
** encountered.
**
** Returns false (0) if fAllowDoubleDash is false or if "--" is not
** encountered. If fAllowDoubleDash is true and "--" is encountered,
** the argument index (in g.argv) at which "--" was encountered (and
** removed) is returned.
**
** Sidebar: the question of whether fAllowDoubleDash should be true or
** false would seem to boil down to: does the calling routine
** expect/allow arbitrary file/page/branch/whatever name arguments
** after its required arguments?
*/
static int verify_all_options_impl(int fAllowDoubleDash){
int i;
for(i=1; i<g.argc; i++){
const char * arg = g.argv[i];
if( arg[0]=='-' ){
if( arg[1]=='-' && arg[2]==0 ){
if(fAllowDoubleDash){
/* Remove "--" from the list and assume any following
** arguments are file names. */
remove_from_argv(i, 1);
return i;
}else{
fossil_fatal("The -- flag is not allowed here.");
}
}else if( arg[1]!=0 ){
fossil_fatal(
"unrecognized command-line option, or missing argument: %s",
arg);
|
|
>
|
|
1047
1048
1049
1050
1051
1052
1053
1054
1055
1056
1057
1058
1059
1060
1061
1062
1063
1064
1065
1066
1067
1068
1069
1070
1071
1072
1073
1074
1075
1076
1077
1078
1079
|
** flags). If fAllowDoubleDash is false then the "--" flag will
** trigger a fatal error exactly as if an unprocessed flag were
** encountered.
**
** Returns false (0) if fAllowDoubleDash is false or if "--" is not
** encountered. If fAllowDoubleDash is true and "--" is encountered,
** the argument index (in g.argv) at which "--" was encountered (and
** removed) is returned (that value will always be greater than 0).
**
** Sidebar: the question of whether fAllowDoubleDash should be true or
** false would seem to boil down to: does the calling routine
** expect/allow arbitrary file/page/branch/whatever name arguments
** after its required arguments?
*/
static int verify_all_options_impl(int fAllowDoubleDash){
int i;
g.argDashDashIndex = 0;
for(i=1; i<g.argc; i++){
const char * arg = g.argv[i];
if( arg[0]=='-' ){
if( arg[1]=='-' && arg[2]==0 ){
if(fAllowDoubleDash){
/* Remove "--" from the list and assume any following
** arguments are file names. */
remove_from_argv(i, 1);
return g.argDashDashIndex = i;
}else{
fossil_fatal("The -- flag is not allowed here.");
}
}else if( arg[1]!=0 ){
fossil_fatal(
"unrecognized command-line option, or missing argument: %s",
arg);
|
1093
1094
1095
1096
1097
1098
1099
1100
1101
1102
1103
1104
1105
1106
|
/*
** Identical to verify_all_options() except that it honors the "--"
** flag and returns true (non-0) if that flag was encountered/consumed.
*/
int verify_all_options2(void){
return verify_all_options_impl(1);
}
/*
** This function returns a human readable version string.
*/
const char *get_version(){
static const char version[] = RELEASE_VERSION " " MANIFEST_VERSION " "
MANIFEST_DATE " UTC";
|
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
|
1097
1098
1099
1100
1101
1102
1103
1104
1105
1106
1107
1108
1109
1110
1111
1112
1113
1114
1115
1116
1117
1118
1119
1120
1121
1122
1123
1124
1125
1126
1127
1128
1129
1130
1131
1132
1133
1134
1135
1136
1137
1138
1139
1140
1141
1142
1143
1144
1145
1146
1147
|
/*
** Identical to verify_all_options() except that it honors the "--"
** flag and returns true (non-0) if that flag was encountered/consumed.
*/
int verify_all_options2(void){
return verify_all_options_impl(1);
}
/*
** Expects nArgPos to be a valid index of g.argv. If nArgPos is a
** string with the value "-" and g.argDashDashIndex is greater than 0
** and <= nArgPos then the value "-" gets transformed to "./-". In all
** other cases, the value of g.argv[nArgPos] is returned as-is.
**
** The intention is that this function be called by commands which
** accept a filename argument for which "-" is interpreted as stdin or
** stdout. If the "--" flag was found BEFORE that filename flag then
** "-" is transformed such that it will be seen as a file named "./-"
** rather than "-" (stdin or stdout, depending on the context). Returns
** a string from g.argv or the static string "./-", so its lifetime is
** effectively that of the app.
*/
const char * get_dash_filename_arg(int nArgPos){
const char * zName;
assert(nArgPos < g.argc);
zName = g.argv[nArgPos];
if(zName!=0
&& g.argDashDashIndex>0 && g.argDashDashIndex<=nArgPos
&& fossil_strcmp("-",zName)==0){
zName = "./-";
}
return zName;
};
/*
** Only for debugging during "--"-related refactoring. To be deleted
** before merging with trunk.
*/
void dump_g_argv(){
int i;
for( i = 0; i < g.argc; ++i ){
fossil_print("\tg.argv[%d] = %s\n", i, g.argv[i]);
}
}
/*
** This function returns a human readable version string.
*/
const char *get_version(){
static const char version[] = RELEASE_VERSION " " MANIFEST_VERSION " "
MANIFEST_DATE " UTC";
|