Fossil SCM

Merge the --args FILENAME patch into trunk.

drh 2011-10-04 23:07 UTC trunk merge
Commit c0274f996266aefd4e7566245ecf4d4433e22cf3
1 file changed +59
+59
--- src/main.c
+++ src/main.c
@@ -231,10 +231,66 @@
231231
return 0;
232232
}
233233
return 1+(cnt>1);
234234
}
235235
236
+/*
237
+** Search g.argv for arguments "--args FILENAME". If found, then
238
+** (1) remove the two arguments from g.argv
239
+** (2) Read the file FILENAME
240
+** (3) Use the contents of FILE to replace the two removed arguments:
241
+** (a) Ignore blank lines in the file
242
+** (b) Each non-empty line of the file is an argument, except
243
+** (c) If the line begins with "-" and contains a space, it is broken
244
+** into two arguments at the space.
245
+*/
246
+static void expand_args_option(void){
247
+ Blob file = empty_blob; /* Content of the file */
248
+ Blob line = empty_blob; /* One line of the file */
249
+ unsigned int nLine; /* Number of lines in the file*/
250
+ unsigned int i, j, k; /* Loop counters */
251
+ int n; /* Number of bytes in one line */
252
+ char *z; /* General use string pointer */
253
+ char **newArgv; /* New expanded g.argv under construction */
254
+
255
+ for(i=1; i<g.argc-1; i++){
256
+ z = g.argv[i];
257
+ if( z[0]!='-' ) continue;
258
+ z++;
259
+ if( z[0]=='-' ) z++;
260
+ if( z[0]==0 ) return; /* Stop searching at "--" */
261
+ if( fossil_strcmp(z, "args")==0 ) break;
262
+ }
263
+ if( i>=g.argc-1 ) return;
264
+
265
+ blob_read_from_file(&file, g.argv[i+1]);
266
+ z = blob_str(&file);
267
+ for(k=0, nLine=1; z[k]; k++) if( z[k]=='\n' ) nLine++;
268
+ newArgv = fossil_malloc( sizeof(char*)*(g.argc + nLine*2) );
269
+ for(j=0; j<i; j++) newArgv[j] = g.argv[j];
270
+
271
+ blob_rewind(&file);
272
+ while( (n = blob_line(&file, &line))>0 ){
273
+ if( n<=1 ) continue;
274
+ z = blob_buffer(&line);
275
+ z[n-1] = 0;
276
+ newArgv[j++] = z;
277
+ if( z[0]=='-' ){
278
+ for(k=1; z[k] && !fossil_isspace(z[k]); k++){}
279
+ if( z[k] ){
280
+ z[k] = 0;
281
+ k++;
282
+ if( z[k] ) newArgv[j++] = &z[k];
283
+ }
284
+ }
285
+ }
286
+ i += 2;
287
+ while( i<g.argc ) newArgv[j++] = g.argv[i++];
288
+ newArgv[j] = 0;
289
+ g.argc = j;
290
+ g.argv = newArgv;
291
+}
236292
237293
/*
238294
** This procedure runs first.
239295
*/
240296
int main(int argc, char **argv){
@@ -245,10 +301,13 @@
245301
246302
sqlite3_config(SQLITE_CONFIG_LOG, fossil_sqlite_log, 0);
247303
g.now = time(0);
248304
g.argc = argc;
249305
g.argv = argv;
306
+ expand_args_option();
307
+ argc = g.argc;
308
+ argv = g.argv;
250309
for(i=0; i<argc; i++) g.argv[i] = fossil_mbcs_to_utf8(argv[i]);
251310
if( getenv("GATEWAY_INTERFACE")!=0 && !find_option("nocgi", 0, 0)){
252311
zCmdName = "cgi";
253312
}else if( argc<2 ){
254313
fossil_fatal("Usage: %s COMMAND ...\n"
255314
--- src/main.c
+++ src/main.c
@@ -231,10 +231,66 @@
231 return 0;
232 }
233 return 1+(cnt>1);
234 }
235
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
236
237 /*
238 ** This procedure runs first.
239 */
240 int main(int argc, char **argv){
@@ -245,10 +301,13 @@
245
246 sqlite3_config(SQLITE_CONFIG_LOG, fossil_sqlite_log, 0);
247 g.now = time(0);
248 g.argc = argc;
249 g.argv = argv;
 
 
 
250 for(i=0; i<argc; i++) g.argv[i] = fossil_mbcs_to_utf8(argv[i]);
251 if( getenv("GATEWAY_INTERFACE")!=0 && !find_option("nocgi", 0, 0)){
252 zCmdName = "cgi";
253 }else if( argc<2 ){
254 fossil_fatal("Usage: %s COMMAND ...\n"
255
--- src/main.c
+++ src/main.c
@@ -231,10 +231,66 @@
231 return 0;
232 }
233 return 1+(cnt>1);
234 }
235
236 /*
237 ** Search g.argv for arguments "--args FILENAME". If found, then
238 ** (1) remove the two arguments from g.argv
239 ** (2) Read the file FILENAME
240 ** (3) Use the contents of FILE to replace the two removed arguments:
241 ** (a) Ignore blank lines in the file
242 ** (b) Each non-empty line of the file is an argument, except
243 ** (c) If the line begins with "-" and contains a space, it is broken
244 ** into two arguments at the space.
245 */
246 static void expand_args_option(void){
247 Blob file = empty_blob; /* Content of the file */
248 Blob line = empty_blob; /* One line of the file */
249 unsigned int nLine; /* Number of lines in the file*/
250 unsigned int i, j, k; /* Loop counters */
251 int n; /* Number of bytes in one line */
252 char *z; /* General use string pointer */
253 char **newArgv; /* New expanded g.argv under construction */
254
255 for(i=1; i<g.argc-1; i++){
256 z = g.argv[i];
257 if( z[0]!='-' ) continue;
258 z++;
259 if( z[0]=='-' ) z++;
260 if( z[0]==0 ) return; /* Stop searching at "--" */
261 if( fossil_strcmp(z, "args")==0 ) break;
262 }
263 if( i>=g.argc-1 ) return;
264
265 blob_read_from_file(&file, g.argv[i+1]);
266 z = blob_str(&file);
267 for(k=0, nLine=1; z[k]; k++) if( z[k]=='\n' ) nLine++;
268 newArgv = fossil_malloc( sizeof(char*)*(g.argc + nLine*2) );
269 for(j=0; j<i; j++) newArgv[j] = g.argv[j];
270
271 blob_rewind(&file);
272 while( (n = blob_line(&file, &line))>0 ){
273 if( n<=1 ) continue;
274 z = blob_buffer(&line);
275 z[n-1] = 0;
276 newArgv[j++] = z;
277 if( z[0]=='-' ){
278 for(k=1; z[k] && !fossil_isspace(z[k]); k++){}
279 if( z[k] ){
280 z[k] = 0;
281 k++;
282 if( z[k] ) newArgv[j++] = &z[k];
283 }
284 }
285 }
286 i += 2;
287 while( i<g.argc ) newArgv[j++] = g.argv[i++];
288 newArgv[j] = 0;
289 g.argc = j;
290 g.argv = newArgv;
291 }
292
293 /*
294 ** This procedure runs first.
295 */
296 int main(int argc, char **argv){
@@ -245,10 +301,13 @@
301
302 sqlite3_config(SQLITE_CONFIG_LOG, fossil_sqlite_log, 0);
303 g.now = time(0);
304 g.argc = argc;
305 g.argv = argv;
306 expand_args_option();
307 argc = g.argc;
308 argv = g.argv;
309 for(i=0; i<argc; i++) g.argv[i] = fossil_mbcs_to_utf8(argv[i]);
310 if( getenv("GATEWAY_INTERFACE")!=0 && !find_option("nocgi", 0, 0)){
311 zCmdName = "cgi";
312 }else if( argc<2 ){
313 fossil_fatal("Usage: %s COMMAND ...\n"
314

Keyboard Shortcuts

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