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 ;).
Commit
080d27a6b2bcf684bd266b313b4618bff9298a14
Parent
6092935ff28e81c…
1 file changed
+19
-2
+19
-2
| --- src/main.c | ||
| +++ src/main.c | ||
| @@ -249,11 +249,12 @@ | ||
| 249 | 249 | unsigned int nLine; /* Number of lines in the file*/ |
| 250 | 250 | unsigned int i, j, k; /* Loop counters */ |
| 251 | 251 | int n; /* Number of bytes in one line */ |
| 252 | 252 | char *z; /* General use string pointer */ |
| 253 | 253 | char **newArgv; /* New expanded g.argv under construction */ |
| 254 | - | |
| 254 | + char const * zFileName; /* input file name */ | |
| 255 | + FILE * zInFile; /* input FILE */ | |
| 255 | 256 | for(i=1; i<g.argc-1; i++){ |
| 256 | 257 | z = g.argv[i]; |
| 257 | 258 | if( z[0]!='-' ) continue; |
| 258 | 259 | z++; |
| 259 | 260 | if( z[0]=='-' ) z++; |
| @@ -260,11 +261,23 @@ | ||
| 260 | 261 | if( z[0]==0 ) return; /* Stop searching at "--" */ |
| 261 | 262 | if( fossil_strcmp(z, "args")==0 ) break; |
| 262 | 263 | } |
| 263 | 264 | if( i>=g.argc-1 ) return; |
| 264 | 265 | |
| 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 | + } | |
| 266 | 279 | z = blob_str(&file); |
| 267 | 280 | for(k=0, nLine=1; z[k]; k++) if( z[k]=='\n' ) nLine++; |
| 268 | 281 | newArgv = fossil_malloc( sizeof(char*)*(g.argc + nLine*2) ); |
| 269 | 282 | for(j=0; j<i; j++) newArgv[j] = g.argv[j]; |
| 270 | 283 | |
| @@ -271,10 +284,14 @@ | ||
| 271 | 284 | blob_rewind(&file); |
| 272 | 285 | while( (n = blob_line(&file, &line))>0 ){ |
| 273 | 286 | if( n<=1 ) continue; |
| 274 | 287 | z = blob_buffer(&line); |
| 275 | 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 | + } | |
| 276 | 293 | newArgv[j++] = z; |
| 277 | 294 | if( z[0]=='-' ){ |
| 278 | 295 | for(k=1; z[k] && !fossil_isspace(z[k]); k++){} |
| 279 | 296 | if( z[k] ){ |
| 280 | 297 | z[k] = 0; |
| 281 | 298 |
| --- 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 |