Changeset 1393 in kBuild
- Timestamp:
- Mar 7, 2008 2:05:46 AM (17 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/kmk/kmkbuiltin/md5sum.c
r1329 r1393 48 48 { 49 49 fprintf(pOut, 50 "usage: md5sum [-bt] file(s)\n"50 "usage: md5sum [-bt] [-o list-file] file(s)\n" 51 51 " or: md5sum [-btwq] -c list-file(s)\n" 52 52 " or: md5sum [-btq] -C MD5 file\n" … … 59 59 " -t, --text Read files in text mode.\n" 60 60 " -p, --progress Show progress indicator on large files.\n" 61 " -o, --output Name of the output list file. Useful with -p.\n" 61 62 " -q, --status Be quiet.\n" 62 63 " -w, --warn Ignored. Always warn, unless quiet.\n" … … 558 559 * @param fQuiet Whether to be quiet or verbose about errors. 559 560 * @param fProgress Whether to show an progress indicator on large files. 560 */ 561 static int md5sum_file(const char *pszFilename, unsigned fText, unsigned fQuiet, unsigned fProgress) 561 * @param pOutput Where to write the list. Progress is always written to stdout. 562 */ 563 static int md5sum_file(const char *pszFilename, unsigned fText, unsigned fQuiet, unsigned fProgress, FILE *pOutput) 562 564 { 563 565 int rc; … … 571 573 { 572 574 unsigned char Digest[16]; 575 576 if (fProgress && pOutput) 577 fprintf(stdout, "%s: ", pszFilename); 578 573 579 rc = calc_md5sum(pvFile, Digest, fProgress); 574 580 close_file(pvFile); 581 582 if (fProgress && pOutput) 583 { 584 size_t cch = strlen(pszFilename) + 2; 585 while (cch-- > 0) 586 fputc('\b', stdout); 587 } 588 575 589 if (!rc) 576 590 { 577 591 char szDigest[36]; 578 592 digest_to_string(Digest, szDigest); 593 if (pOutput) 594 { 595 fprintf(pOutput, "%s %s%s\n", szDigest, fText ? "" : "*", pszFilename); 596 fflush(pOutput); 597 } 579 598 fprintf(stdout, "%s %s%s\n", szDigest, fText ? "" : "*", pszFilename); 580 599 fflush(stdout); … … 613 632 int fProgress = 0; 614 633 int fNoMoreOptions = 0; 634 const char *pszOutput = NULL; 635 FILE *pOutput = NULL; 615 636 616 637 g_progname = argv[0]; … … 646 667 else if (!strcmp(psz, "-check-file")) 647 668 psz = "C"; 669 else if (!strcmp(psz, "-output")) 670 psz = "o"; 648 671 else if (!strcmp(psz, "-progress")) 649 672 psz = "p"; … … 726 749 } 727 750 751 /* 752 * Output file. 753 */ 754 case 'o': 755 { 756 if (fChecking) 757 { 758 errx(1, "'-o' cannot be used with -c or -C!"); 759 return 1; 760 } 761 762 if (psz[1]) 763 pszOutput = &psz[1]; 764 else if (i + 1 < argc) 765 pszOutput = argv[++i]; 766 else 767 { 768 errx(1, "'-o' is missing the file name!"); 769 return 1; 770 } 771 772 psz = "\0"; 773 break; 774 } 775 728 776 default: 729 777 errx(1, "Invalid option '%c'! (%s)", *psz, argv[i]); … … 735 783 rc |= check_files(argv[i], fText, fBinaryTextOpt, fQuiet, fProgress && !fQuiet); 736 784 else 737 rc |= md5sum_file(argv[i], fText, fQuiet, fProgress && !fQuiet); 785 { 786 /* lazily open the output if specified. */ 787 if (pszOutput) 788 { 789 if (pOutput) 790 fclose(pOutput); 791 pOutput = fopen(pszOutput, "w"); 792 if (!pOutput) 793 { 794 rc = err(1, "fopen(\"%s\", \"w\") failed", pszOutput); 795 break; 796 } 797 pszOutput = NULL; 798 } 799 800 rc |= md5sum_file(argv[i], fText, fQuiet, fProgress && !fQuiet, pOutput); 801 } 738 802 i++; 739 803 } 740 804 805 if (pOutput) 806 fclose(pOutput); 741 807 return rc; 742 808 }
Note:
See TracChangeset
for help on using the changeset viewer.