Panda3D
Loading...
Searching...
No Matches
build_patch.cxx
Go to the documentation of this file.
1/**
2 * PANDA 3D SOFTWARE
3 * Copyright (c) Carnegie Mellon University. All rights reserved.
4 *
5 * All use of this software is subject to the terms of the revised BSD
6 * license. You should have received a copy of this license along
7 * with this source code in a file named "LICENSE."
8 *
9 * @file build_patch.cxx
10 */
11
12#include "pandabase.h"
13#include "panda_getopt.h"
14#include "preprocess_argv.h"
15#include "patchfile.h"
16#include "filename.h"
17
18using std::cerr;
19using std::endl;
20
21void
22usage() {
23 cerr << "Usage: build_patch [opts] <old_file> <new_file>" << endl;
24}
25
26void
27help() {
28 usage();
29 cerr << "\n"
30 "This program generates a patch file that describes the differences\n"
31 "between any two source files. The patch file can later be used to\n"
32 "construct <new_file>, given <old_file>. Arbitrary file types, including\n"
33 "binary files, are supported.\n\n"
34
35 "The patching algorithm can get very slow for very large files. As an\n"
36 "optimization, if the input files are both Panda Multifiles, the patcher\n"
37 "will by default patch them on a per-subfile basis, which has the potential\n"
38 "to be much faster. The -c option will forbid this and force the patcher\n"
39 "to work on the full file.\n\n"
40
41 "Options:\n\n"
42
43 " -o output_name\n"
44 " Specify the filename of the patch file to generate.\n\n"
45
46 " -c\n"
47 " Always generate patches against the complete file, even if the\n"
48 " input files appear to be multifiles.\n\n"
49
50 " -f footprint_length\n"
51 " Specify the footprint length for the patching algorithm.\n\n";
52}
53
54int
55main(int argc, char **argv) {
56 Filename patch_file;
57 bool complete_file = false;
58 int footprint_length = 0;
59
60 // extern char *optarg;
61 extern int optind;
62 static const char *optflags = "o:cf:h";
63 preprocess_argv(argc, argv);
64 int flag = getopt(argc, argv, optflags);
65 Filename rel_path;
66 while (flag != EOF) {
67 switch (flag) {
68 case 'o':
69 patch_file = optarg;
70 break;
71
72 case 'c':
73 complete_file = true;
74 break;
75
76 case 'f':
77 footprint_length = atoi(optarg);
78 break;
79
80 case 'h':
81 help();
82 return 1;
83 case '?':
84 usage();
85 return 1;
86 default:
87 cerr << "Unhandled switch: " << flag << endl;
88 break;
89 }
90 flag = getopt(argc, argv, optflags);
91 }
92 argc -= (optind - 1);
93 argv += (optind - 1);
94
95 if (argc < 3) {
96 usage();
97 return 1;
98 }
99
100 Filename src_file = Filename::from_os_specific(argv[1]);
101 src_file.set_binary();
102
103 Filename dest_file = Filename::from_os_specific(argv[2]);
104 dest_file.set_binary();
105
106 if (patch_file.empty()) {
107 patch_file = dest_file.get_fullpath() + ".pch";
108 }
109 Patchfile pfile;
110
111 pfile.set_allow_multifile(!complete_file);
112 if (footprint_length != 0) {
113 cerr << "Footprint length is " << footprint_length << "\n";
114 pfile.set_footprint_length(footprint_length);
115 }
116
117 cerr << "Building patch file to convert " << src_file << " to "
118 << dest_file << endl;
119 if (pfile.build(src_file, dest_file, patch_file) == false) {
120 cerr << "build patch failed" << endl;
121 return 1;
122 }
123
124 return 0;
125}
The name of a file, such as a texture file or an Egg file.
Definition filename.h:44
void set_binary()
Indicates that the filename represents a binary file.
Definition filename.I:414
std::string get_fullpath() const
Returns the entire filename: directory, basename, extension.
Definition filename.I:338
static Filename from_os_specific(const std::string &os_specific, Type type=T_general)
This named constructor returns a Panda-style filename (that is, using forward slashes,...
Definition filename.cxx:328
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
void preprocess_argv(int &argc, char **&argv)
Processes the argc, argv pair as needed before passing it to getopt().
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.