Fossil SCM

Added (--args -) to read from stdin. Theoretically now also strips windows newlines, but i do not have a broken editor to test that with ;).

stephan 2011-10-05 08:00 trunk
Commit 080d27a6b2bcf684bd266b313b4618bff9298a14
1 file changed +19 -2
+19 -2
--- src/main.c
+++ src/main.c
@@ -249,11 +249,12 @@
249249
unsigned int nLine; /* Number of lines in the file*/
250250
unsigned int i, j, k; /* Loop counters */
251251
int n; /* Number of bytes in one line */
252252
char *z; /* General use string pointer */
253253
char **newArgv; /* New expanded g.argv under construction */
254
-
254
+ char const * zFileName; /* input file name */
255
+ FILE * zInFile; /* input FILE */
255256
for(i=1; i<g.argc-1; i++){
256257
z = g.argv[i];
257258
if( z[0]!='-' ) continue;
258259
z++;
259260
if( z[0]=='-' ) z++;
@@ -260,11 +261,23 @@
260261
if( z[0]==0 ) return; /* Stop searching at "--" */
261262
if( fossil_strcmp(z, "args")==0 ) break;
262263
}
263264
if( i>=g.argc-1 ) return;
264265
265
- blob_read_from_file(&file, g.argv[i+1]);
266
+ zFileName = g.argv[i+1];
267
+ zInFile = (0==strcmp("-",zFileName))
268
+ ? stdin
269
+ : fopen(zFileName,"rb");
270
+ if(!zInFile){
271
+ fossil_panic("Cannot open -args file [%s]", zFileName);
272
+ }else{
273
+ blob_read_from_channel(&file, zInFile, -1);
274
+ if(stdin != zInFile){
275
+ fclose(zInFile);
276
+ }
277
+ zInFile = NULL;
278
+ }
266279
z = blob_str(&file);
267280
for(k=0, nLine=1; z[k]; k++) if( z[k]=='\n' ) nLine++;
268281
newArgv = fossil_malloc( sizeof(char*)*(g.argc + nLine*2) );
269282
for(j=0; j<i; j++) newArgv[j] = g.argv[j];
270283
@@ -271,10 +284,14 @@
271284
blob_rewind(&file);
272285
while( (n = blob_line(&file, &line))>0 ){
273286
if( n<=1 ) continue;
274287
z = blob_buffer(&line);
275288
z[n-1] = 0;
289
+ if((n>1) && ('\r'==z[n-2])){
290
+ if(n==2) continue /*empty line*/;
291
+ z[n-2] = 0;
292
+ }
276293
newArgv[j++] = z;
277294
if( z[0]=='-' ){
278295
for(k=1; z[k] && !fossil_isspace(z[k]); k++){}
279296
if( z[k] ){
280297
z[k] = 0;
281298
--- src/main.c
+++ src/main.c
@@ -249,11 +249,12 @@
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,11 +261,23 @@
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,10 +284,14 @@
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
--- src/main.c
+++ src/main.c
@@ -249,11 +249,12 @@
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 char const * zFileName; /* input file name */
255 FILE * zInFile; /* input FILE */
256 for(i=1; i<g.argc-1; i++){
257 z = g.argv[i];
258 if( z[0]!='-' ) continue;
259 z++;
260 if( z[0]=='-' ) z++;
@@ -260,11 +261,23 @@
261 if( z[0]==0 ) return; /* Stop searching at "--" */
262 if( fossil_strcmp(z, "args")==0 ) break;
263 }
264 if( i>=g.argc-1 ) return;
265
266 zFileName = g.argv[i+1];
267 zInFile = (0==strcmp("-",zFileName))
268 ? stdin
269 : fopen(zFileName,"rb");
270 if(!zInFile){
271 fossil_panic("Cannot open -args file [%s]", zFileName);
272 }else{
273 blob_read_from_channel(&file, zInFile, -1);
274 if(stdin != zInFile){
275 fclose(zInFile);
276 }
277 zInFile = NULL;
278 }
279 z = blob_str(&file);
280 for(k=0, nLine=1; z[k]; k++) if( z[k]=='\n' ) nLine++;
281 newArgv = fossil_malloc( sizeof(char*)*(g.argc + nLine*2) );
282 for(j=0; j<i; j++) newArgv[j] = g.argv[j];
283
@@ -271,10 +284,14 @@
284 blob_rewind(&file);
285 while( (n = blob_line(&file, &line))>0 ){
286 if( n<=1 ) continue;
287 z = blob_buffer(&line);
288 z[n-1] = 0;
289 if((n>1) && ('\r'==z[n-2])){
290 if(n==2) continue /*empty line*/;
291 z[n-2] = 0;
292 }
293 newArgv[j++] = z;
294 if( z[0]=='-' ){
295 for(k=1; z[k] && !fossil_isspace(z[k]); k++){}
296 if( z[k] ){
297 z[k] = 0;
298

Keyboard Shortcuts

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