Many hyperlinks are disabled.
Use anonymous login
to enable hyperlinks.
Overview
| Comment: | Simplify the implementation of the --args FILENAME patch, as requested by the FIXME comment. |
|---|---|
| Timelines: | family | ancestors | descendants | both | stephan-hack |
| Files: | files | file ages | folders |
| SHA1: |
eb8d989daebfce1fd22513bb3718b25b |
| User & Date: | drh 2011-10-04 23:03:17.321 |
| Original Comment: | Simplify the implementation of the --args FILENAME patch, as requested by the FIXME comment. |
Context
|
2011-10-20
| ||
| 14:39 | pulled in trunk for clean slate on subsequent changes. check-in: a37d80e8af user: stephan tags: stephan-hack | |
|
2011-10-04
| ||
| 23:07 | Merge the --args FILENAME patch into trunk. check-in: c0274f9962 user: drh tags: trunk | |
| 23:03 | Simplify the implementation of the --args FILENAME patch, as requested by the FIXME comment. check-in: eb8d989dae user: drh tags: stephan-hack | |
| 21:41 | Initial --args FILENAME patch. Impl seems over-complex to me, but works as described in the list thread. check-in: 8a6568c3a3 user: stephan tags: stephan-hack | |
Changes
Changes to src/main.c.
| ︙ | ︙ | |||
230 231 232 233 234 235 236 |
*pIndex = m;
return 0;
}
return 1+(cnt>1);
}
/*
| < | | | > | | > > | | | < < < < < < < < | | < < < < < < < < < < < < < > > > < | < < < > | < < < < | < < | | < < > | < < < < < | < < < < < < | < < < < < < | | | < < < < > | < < < < < < < < | | | > > > | | < | < > | < | > | < | < | | | < < < < < | < < < | < < < < < < < < < < | < < < | < < < | | 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 |
*pIndex = m;
return 0;
}
return 1+(cnt>1);
}
/*
** Search g.argv for arguments "--args FILENAME". If found, then
** (1) remove the two arguments from g.argv
** (2) Read the file FILENAME
** (3) Use the contents of FILE to replace the two removed arguments:
** (a) Ignore blank lines in the file
** (b) Each non-empty line of the file is an argument, except
** (c) If the line begins with "-" and contains a space, it is broken
** into two arguments at the space.
*/
static void expand_args_option(void){
Blob file = empty_blob; /* Content of the file */
Blob line = empty_blob; /* One line of the file */
unsigned int nLine; /* Number of lines in the file*/
unsigned int i, j, k; /* Loop counters */
int n; /* Number of bytes in one line */
char *z; /* General use string pointer */
char **newArgv; /* New expanded g.argv under construction */
for(i=1; i<g.argc-1; i++){
z = g.argv[i];
if( z[0]!='-' ) continue;
z++;
if( z[0]=='-' ) z++;
if( z[0]==0 ) return; /* Stop searching at "--" */
if( fossil_strcmp(z, "args")==0 ) break;
}
if( i>=g.argc-1 ) return;
blob_read_from_file(&file, g.argv[i+1]);
z = blob_str(&file);
for(k=0, nLine=1; z[k]; k++) if( z[k]=='\n' ) nLine++;
newArgv = fossil_malloc( sizeof(char*)*(g.argc + nLine*2) );
for(j=0; j<i; j++) newArgv[j] = g.argv[j];
blob_rewind(&file);
while( (n = blob_line(&file, &line))>0 ){
if( n<=1 ) continue;
z = blob_buffer(&line);
z[n-1] = 0;
newArgv[j++] = z;
if( z[0]=='-' ){
for(k=1; z[k] && !fossil_isspace(z[k]); k++){}
if( z[k] ){
z[k] = 0;
k++;
if( z[k] ) newArgv[j++] = &z[k];
}
}
}
i += 2;
while( i<g.argc ) newArgv[j++] = g.argv[i++];
newArgv[j] = 0;
g.argc = j;
g.argv = newArgv;
}
/*
** This procedure runs first.
*/
int main(int argc, char **argv){
const char *zCmdName = "unknown";
int idx;
int rc;
int i;
sqlite3_config(SQLITE_CONFIG_LOG, fossil_sqlite_log, 0);
g.now = time(0);
g.argc = argc;
g.argv = argv;
expand_args_option();
argc = g.argc;
argv = g.argv;
for(i=0; i<argc; i++) g.argv[i] = fossil_mbcs_to_utf8(argv[i]);
if( getenv("GATEWAY_INTERFACE")!=0 && !find_option("nocgi", 0, 0)){
zCmdName = "cgi";
}else if( argc<2 ){
fossil_fatal("Usage: %s COMMAND ...\n"
|
| ︙ | ︙ |