static char *range;
static unsigned int c;
-static int RANGE(int SCAN,int N ) {
- return ( SCAN == N ) && *(range+c) == 0;
+static int RANGE(int s,int n ) {
+ return ( s == n ) && *(range+c) == 0;
}
static int setup_sources(char **argv,int i,int n) {
p->to = filestat.st_size;
// Process any range variation
if ( range && *(++range) ) {
- unsigned int a,b;
- if ( RANGE( sscanf( range, "%u-%u%n", &a, &b, &c ), 2 ) ) {
- p->from = a;
- p->to = b;
- } else if ( RANGE( sscanf( range, "%u--%u%n", &a, &b, &c ), 2 ) ) {
- p->from = a;
- p->to -= b;
- } else if ( RANGE( sscanf( range, "%u-%n", &a, &c ), 1 ) ) {
- p->from = a;
- } else if ( RANGE( sscanf( range, "%u%n", &a, &c ), 1 ) ) {
- p->from = a;
- } else if ( RANGE( sscanf( range, "-%u%n", &b, &c ), 1 ) ) {
- p->to = b;
- } else if ( RANGE( sscanf( range, "--%u%n", &b, &c ), 1 ) ) {
- p->to -= b;
- } else if ( RANGE( sscanf( range, "-%n", &c), 0 ) ) {
- // Acceptable as "start-end" range
+ int a,b;
+ if ( 0 ) {
+ } else if ( RANGE( sscanf( range, "%d:%d%n", &a, &b, &c ), 2 )) {
+ p->from = ( a < 0 )? ( p->to + a ) : a;
+ p->to = ( b < 0 )? ( p->to + b ) : b;
+ } else if ( RANGE( sscanf( range, "%d+%d%n", &a, &b, &c ), 2 )) {
+ p->from = ( a < 0 )? ( p->to + a ) : a;
+ p->to = ( ( b < 0 )? p->to : p->from ) + b;
+ } else if ( RANGE( sscanf( range, "%d+%n", &a, &c ), 1 )) {
+ p->from = ( a < 0 )? ( p->to + a ) : a;
+ } else if ( RANGE( sscanf( range, ":%d%n", &b, &c ), 1 )) {
+ p->to = ( b < 0 )? ( p->to + b ) : b;
+ } else if ( RANGE( sscanf( range, "%d:%n", &a, &c ), 1 )) {
+ p->from = ( a < 0 )? ( p->to + a ) : a;
+ } else if ( RANGE( sscanf( range, "%d%n", &a, &c ), 1 )) {
+ if ( a < 0 ) {
+ p->from = p->to + a;
+ } else {
+ p->to = p->from + a;
+ }
+ } else if ( RANGE( sscanf( range, ":%n", &c), 0 ) ) {
+ // to end from start
} else {
fprintf( stderr, "** BAD RANGE: %s\n", argv[i] );
return 1;
}
}
+ if ( p->from >= p->to ||
+ p->from >= filestat.st_size || p->to > filestat.st_size ) {
+ fprintf( stderr, "** BAD RANGE: %s [%ld:%ld]\n",
+ argv[i], p->from, p->to );
+ return 1;
+ }
p->start = sources.size; // the fusefile position of fragment
sources.size += p->to - p->from;
#if DEBUG