27 <<
" punzip file.pz [file2.pz file3.pz ...]\n" 28 <<
" punzip -c <file >dest_file\n" 29 <<
" punzip -o dest_file file.pz\n\n" 31 <<
"This program reverses the operation of a previous pzip command. It\n" 32 <<
"uncompresses the contents of the named source file(s) and removes the .pz\n" 37 main(
int argc,
char **argv) {
40 const char *optstr =
"o:ch";
43 bool got_dest_filename =
false;
44 bool use_stdout =
false;
47 int flag = getopt(argc, argv, optstr);
53 got_dest_filename =
true;
66 flag = getopt(argc, argv, optstr);
74 cerr <<
"No filenames allowed in conjunction with -c.\n";
78 bool success = decompress_stream(cin, cout);
80 cerr <<
"Failure compressing standard input\n";
91 if (got_dest_filename && argc > 2) {
92 cerr <<
"Only one input file allowed in conjunction with -o.\n";
97 for (
int i = 1; i < argc; i++) {
99 if (!got_dest_filename && source_file.
get_extension() !=
"pz") {
101 <<
" doesn't end in .pz; can't derive filename of output file.\n";
106 if (!got_dest_filename) {
111 pifstream read_stream;
113 if (!source_file.
open_read(read_stream)) {
114 cerr <<
"Couldn't read: " << source_file << endl;
119 pofstream write_stream;
121 if (!dest_file.
open_write(write_stream,
true)) {
122 cerr <<
"Failed to open: " << dest_file << endl;
126 cerr << dest_file <<
"\n";
127 bool success = decompress_stream(read_stream, write_stream);
130 write_stream.close();
133 cerr <<
"Failure decompressing " << source_file <<
"\n";
138 if (!got_dest_filename) {
139 source_file.unlink();
bool open_write(std::ofstream &stream, bool truncate=true) const
Opens the indicated ifstream for writing the file, if possible.
void set_binary()
Indicates that the filename represents a binary file.
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
bool open_read(std::ifstream &stream) const
Opens the indicated ifstream for reading the file, if possible.
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
The name of a file, such as a texture file or an Egg file.
bool unlink() const
Permanently deletes the file associated with the filename, if possible.
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
std::string get_extension() const
Returns the file extension.
void preprocess_argv(int &argc, char **&argv)
Processes the argc, argv pair as needed before passing it to getopt().
std::string get_fullpath_wo_extension() const
Returns the full filename–directory and basename parts–except for the extension.
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
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,...