@@ -42,7 +42,7 @@ int main ( int argc, char *argv[] ) {
42
42
bool bShowGlobalFileStatistics = false;
43
43
unsigned long long slice_size = 0ULL ;
44
44
unsigned long long slice_number = 0ULL ;
45
- unsigned long long from_byte = 0ULL ;
45
+ unsigned long long from_byte = 1ULL ;
46
46
unsigned long long to_byte = 0ULL ;
47
47
unsigned long long to_byte_increment = 0ULL ;
48
48
@@ -351,12 +351,13 @@ int analyze_file(
351
351
352
352
}
353
353
354
+ if ( from_byte > file_size ) {
355
+ fprintf (stderr , "Error: file '%s' smaller than `-f %llu`.\n" , szFile , from_byte );
356
+ return 2 ;
357
+ }
358
+
354
359
// seek to from_byte position
355
- if ( from_byte > 0ULL ) {
356
- if ( from_byte > file_size ) {
357
- fprintf (stderr , "Error: file '%s' smaller than `-f %llu`.\n" , szFile , from_byte );
358
- return 2 ;
359
- }
360
+ if ( from_byte > 1ULL ) {
360
361
if ( 0 != fseeko ( hFile , from_byte - 1 , SEEK_SET ) ) {
361
362
fprintf (stderr , "Error: cannot seek file '%s' to position '%llu'.\n" , szFile , from_byte );
362
363
return 2 ;
@@ -369,7 +370,7 @@ int analyze_file(
369
370
if ( 0 == strlen (szFile ) ) {
370
371
// adjust buffer_length with STDIN if from_byte
371
372
// before entering the processing loop
372
- if ( from_byte > 0ULL ) {
373
+ if ( from_byte > 1ULL ) {
373
374
buffer_length = BUFFER_LENGTH ;
374
375
do {
375
376
@@ -385,8 +386,8 @@ int analyze_file(
385
386
bytes_read > 0 );
386
387
}
387
388
// from_byte may has been too big for STDIN input
388
- if ( from_byte > 0ULL &&
389
- total_bytes_read < ( from_byte - 1 )
389
+ if ( from_byte > 1ULL &&
390
+ total_bytes_read < from_byte
390
391
) {
391
392
fprintf (stderr , "Error: data input smaller (%llu bytes) than -f %llu\n" , (unsigned long long )total_bytes_read , from_byte );
392
393
return 2 ;
@@ -522,9 +523,7 @@ int analyze_file(
522
523
& sigma ,
523
524
& mean ,
524
525
& number_of_byte_buckets ,
525
- ( from_byte > 0ULL )?
526
- ( total_bytes_read - from_byte + 1 ):
527
- total_bytes_read
526
+ total_bytes_read - from_byte + 1
528
527
);
529
528
530
529
// fill circle's container matrix with zeros
@@ -548,12 +547,8 @@ int analyze_file(
548
547
list_bytes ,
549
548
number_of_byte_buckets ,
550
549
szFile ,
551
- ( from_byte > 0ULL )?
552
- ( total_bytes_read - from_byte + 1 ):
553
- total_bytes_read ,
554
- ( from_byte > 0ULL )?
555
- ( total_bytes_read - from_byte + 1 ):
556
- total_bytes_read ,
550
+ total_bytes_read - from_byte + 1 ,
551
+ total_bytes_read - from_byte + 1 ,
557
552
0ULL ,
558
553
0ULL ,
559
554
from_byte ,
@@ -742,15 +737,19 @@ void print_circle_on_screen(
742
737
printf ("file =\t%s" , szFile );
743
738
}
744
739
745
- if ( slice_size > 0 ) {
740
+ if ( slice_size > 0ULL ) {
746
741
printf ( " , [%llu-%llu] bytes, (slice %llu)" ,
747
742
total_bytes_read + 1 , total_bytes_read + total_size , slice_actual_number );
748
743
} else {
749
- if ( from_byte > 0 ||
750
- to_byte > 0 ) {
751
- // always consider the first byte as '1', not '0'
752
- // (0==slice_actual_number used as `-g` indicator)
753
- printf ( " , [%llu-%llu] bytes" , ( (from_byte > 0ULL )? from_byte : 1ULL ), (0 == slice_actual_number )?( (0 == to_byte )?(from_byte + total_bytes_read - 1 ):to_byte ):(total_bytes_read + total_size ) );
744
+ if ( from_byte > 1ULL ||
745
+ to_byte > 0ULL ) {
746
+ // first byte is 1, not 0
747
+ printf ( " , [%llu-%llu] bytes" ,
748
+ from_byte ,
749
+ (0ULL == slice_actual_number )? // 0ULL==slice_actual_number used as `-g` indicator
750
+ ( (0ULL == to_byte )?(from_byte + total_bytes_read - 1 ):to_byte ):
751
+ (total_bytes_read + total_size )
752
+ );
754
753
}
755
754
}
756
755
printf ("\n" );
0 commit comments