better command-line parameters

This commit is contained in:
David Rose 2007-02-28 18:24:35 +00:00
parent 01136dc823
commit 2b22c30352
2 changed files with 49 additions and 12 deletions

View File

@ -27,7 +27,7 @@
void void
usage() { usage() {
cerr << "Usage: build_patch [-f] <old_file> <new_file>" << endl; cerr << "Usage: build_patch [opts] <old_file> <new_file>" << endl;
} }
void void
@ -42,23 +42,45 @@ help() {
"The patching algorithm can get very slow for very large files. As an\n" "The patching algorithm can get very slow for very large files. As an\n"
"optimization, if the input files are both Panda Multifiles, the patcher\n" "optimization, if the input files are both Panda Multifiles, the patcher\n"
"will by default patch them on a per-subfile basis, which has the potential\n" "will by default patch them on a per-subfile basis, which has the potential\n"
"to be much faster. The -f option will forbid this and force the patcher\n" "to be much faster. The -c option will forbid this and force the patcher\n"
"to work on the full file.\n\n"; "to work on the full file.\n\n"
"Options:\n\n"
" -o output_name\n"
" Specify the filename of the patch file to generate.\n\n"
" -c\n"
" Always generate patches against the complete file, even if the\n"
" input files appear to be multifiles.\n\n"
" -f footprint_length\n"
" Specify the footprint length for the patching algorithm.\n\n";
} }
int int
main(int argc, char *argv[]) { main(int argc, char *argv[]) {
bool full_file = false; Filename patch_file;
bool complete_file = false;
int footprint_length = 0;
// extern char *optarg; // extern char *optarg;
extern int optind; extern int optind;
static const char *optflags = "fh"; static const char *optflags = "o:cf:h";
int flag = getopt(argc, argv, optflags); int flag = getopt(argc, argv, optflags);
Filename rel_path; Filename rel_path;
while (flag != EOF) { while (flag != EOF) {
switch (flag) { switch (flag) {
case 'o':
patch_file = optarg;
break;
case 'c':
complete_file = true;
break;
case 'f': case 'f':
full_file = true; footprint_length = atoi(optarg);
break; break;
case 'h': case 'h':
@ -87,10 +109,16 @@ main(int argc, char *argv[]) {
Filename dest_file = Filename::from_os_specific(argv[2]); Filename dest_file = Filename::from_os_specific(argv[2]);
dest_file.set_binary(); dest_file.set_binary();
Filename patch_file = dest_file.get_fullpath() + ".pch"; if (patch_file.empty()) {
patch_file = dest_file.get_fullpath() + ".pch";
}
Patchfile pfile; Patchfile pfile;
pfile.set_allow_multifile(!full_file); pfile.set_allow_multifile(!complete_file);
if (footprint_length != 0) {
cerr << "Footprint length is " << footprint_length << "\n";
pfile.set_footprint_length(footprint_length);
}
cerr << "Building patch file to convert " << src_file << " to " cerr << "Building patch file to convert " << src_file << " to "
<< dest_file << endl; << dest_file << endl;

View File

@ -469,12 +469,21 @@ kill_files(int argc, char *argv[]) {
} }
} }
if (!multifile->repack()) { bool okflag = true;
cerr << "Failed to write " << multifile_name << ".\n";
return false; if (multifile->needs_repack()) {
if (!multifile->repack()) {
cerr << "Failed to write " << multifile_name << ".\n";
okflag = false;
}
} else {
if (!multifile->flush()) {
cerr << "Failed to write " << multifile_name << ".\n";
okflag = false;
}
} }
return true; return okflag;
} }
const char * const char *