Index: branches/ariel/xmldumps-backup/mwbzutils/findpageidinbz2xml.c |
— | — | @@ -41,7 +41,7 @@ |
42 | 42 | return(0); |
43 | 43 | } |
44 | 44 | else { |
45 | | - fprintf(stderr,"failed to find the next frigging block marker\n"); |
| 45 | + fprintf(stderr,"Failed to find the next block marker\n"); |
46 | 46 | return(-1); |
47 | 47 | } |
48 | 48 | } |
— | — | @@ -91,7 +91,7 @@ |
92 | 92 | if (match_base_expr[1].rm_so >=0) { |
93 | 93 | hostname_length = match_base_expr[1].rm_eo - match_base_expr[1].rm_so; |
94 | 94 | if (hostname_length > sizeof(hostname)) { |
95 | | - fprintf(stderr,"very long hostname, giving up\n"); |
| 95 | + fprintf(stderr,"Very long hostname, giving up\n"); |
96 | 96 | break; |
97 | 97 | } |
98 | 98 | else { |
— | — | @@ -339,7 +339,7 @@ |
340 | 340 | hopefully that doesn't take forever. |
341 | 341 | */ |
342 | 342 | if (buffer_count>(20000000/BUFINSIZE) && rev_id) { |
343 | | - if (verbose) fprintf(stderr, "passed cutoff for using api\n"); |
| 343 | + if (verbose) fprintf(stderr, "passed retries cutoff for using api\n"); |
344 | 344 | if (use_api) { |
345 | 345 | page_id_found = get_page_id_from_rev_id_via_api(rev_id, fin); |
346 | 346 | } |
— | — | @@ -442,19 +442,23 @@ |
443 | 443 | /* if we're this close, we'll check this value and be done with it */ |
444 | 444 | if (iinfo->right_end -iinfo->left_end < (off_t)2) { |
445 | 445 | new_position = iinfo->left_end; |
| 446 | + if (verbose >= 2) fprintf(stderr," choosing new position (1) %"PRId64"\n",new_position); |
446 | 447 | iinfo->right_end = iinfo->left_end; |
447 | 448 | } |
448 | 449 | else { |
449 | 450 | if (iinfo->last_value < iinfo->value_wanted) { |
450 | | - if (verbose >=2) fprintf(stderr,"resetting left end\n"); |
| 451 | + if (verbose >= 2) fprintf(stderr,"resetting left end\n"); |
451 | 452 | iinfo->left_end = iinfo->last_position; |
452 | 453 | new_position = iinfo->last_position + interval; |
| 454 | + if (verbose >= 2) fprintf(stderr," choosing new position (2) %"PRId64"\n",new_position); |
453 | 455 | } |
454 | 456 | /* iinfo->last_value > iinfo->value_wanted */ |
455 | 457 | else { |
456 | 458 | if (verbose >=2) fprintf(stderr,"resetting right end\n"); |
457 | 459 | iinfo->right_end = iinfo->last_position; |
458 | 460 | new_position = iinfo->last_position - interval; |
| 461 | + if (new_position < 0) new_position = 0; |
| 462 | + if (verbose >= 2) fprintf(stderr," choosing new position (3) %"PRId64"\n",new_position); |
459 | 463 | } |
460 | 464 | } |
461 | 465 | res = get_first_page_id_after_offset(fin, new_position, pinfo, use_api, use_stub, stubfilename, verbose); |
— | — | @@ -550,7 +554,7 @@ |
551 | 555 | else if (optc=='v') |
552 | 556 | verbose++; |
553 | 557 | else if (optc==-1) break; |
554 | | - else usage(argv[0],"unknown option or other error\n"); |
| 558 | + else usage(argv[0],"Unknown option or other error\n"); |
555 | 559 | } |
556 | 560 | |
557 | 561 | if (! filename || ! page_id) { |
— | — | @@ -558,12 +562,12 @@ |
559 | 563 | } |
560 | 564 | |
561 | 565 | if (page_id <1) { |
562 | | - usage(argv[0], "please specify a page_id >= 1.\n"); |
| 566 | + usage(argv[0], "Please specify a page_id >= 1.\n"); |
563 | 567 | } |
564 | 568 | |
565 | 569 | fin = open (filename, O_RDONLY); |
566 | 570 | if (fin < 0) { |
567 | | - fprintf(stderr,"failed to open file %s for read\n", argv[1]); |
| 571 | + fprintf(stderr,"Failed to open file %s for read\n", argv[1]); |
568 | 572 | exit(1); |
569 | 573 | } |
570 | 574 | |
— | — | @@ -585,7 +589,7 @@ |
586 | 590 | iinfo.last_position = (off_t)0; |
587 | 591 | } |
588 | 592 | else { |
589 | | - fprintf(stderr,"failed to get anything useful from the beginning of the file even, bailing.\n"); |
| 593 | + fprintf(stderr,"Failed to find any page from start of file, exiting\n"); |
590 | 594 | exit(1); |
591 | 595 | } |
592 | 596 | if (pinfo.page_id == page_id) { |
— | — | @@ -593,18 +597,26 @@ |
594 | 598 | fprintf(stdout,"position:%"PRId64" page_id:%d\n",pinfo.position, pinfo.page_id); |
595 | 599 | exit(0); |
596 | 600 | } |
597 | | - |
| 601 | + if (pinfo.page_id > page_id) { |
| 602 | + fprintf(stderr,"Page requested is less than first page id in file\n"); |
| 603 | + exit(-1); |
| 604 | + } |
598 | 605 | while (1) { |
599 | 606 | res = do_iteration(&iinfo, fin, &pinfo, use_api, use_stub, stubfile, verbose); |
600 | | - /* things to check: bad return? interval is 0 bytes long? */ |
601 | | - if (iinfo.left_end == iinfo.right_end) { |
602 | | - fprintf(stdout,"position:%"PRId64" page_id:%d\n",pinfo.position, pinfo.page_id); |
603 | | - exit(0); |
604 | | - } |
605 | | - else if (res < 0) { |
606 | | - fprintf(stderr,"broken and quitting\n"); |
| 607 | + if (res < 0) { |
| 608 | + fprintf(stderr,"Error encountered during search\n"); |
607 | 609 | exit(-1); |
608 | 610 | } |
| 611 | + else if (iinfo.left_end == iinfo.right_end) { |
| 612 | + if ( pinfo.page_id <= page_id) { |
| 613 | + fprintf(stdout,"position:%"PRId64" page_id:%d\n",pinfo.position, pinfo.page_id); |
| 614 | + exit(0); |
| 615 | + } |
| 616 | + else { |
| 617 | + fprintf(stderr,"File does not contain requested page id\n"); |
| 618 | + exit(-1); |
| 619 | + } |
| 620 | + } |
609 | 621 | } |
610 | 622 | exit(0); |
611 | 623 | } |