17 #include "compress_string.h"
19 #include "panda_getopt.h"
20 #include "preprocess_argv.h"
26 <<
" punzip file.pz [file2.pz file3.pz ...]\n"
27 <<
" punzip -c <file >dest_file\n"
28 <<
" punzip -o dest_file file.pz\n\n"
30 <<
"This program reverses the operation of a previous pzip command. It\n"
31 <<
"uncompresses the contents of the named source file(s) and removes the .pz\n"
36 main(
int argc,
char **argv) {
42 const char *optstr =
"o:ch";
45 bool got_dest_filename =
false;
46 bool use_stdout =
false;
48 preprocess_argv(argc, argv);
49 int flag = getopt(argc, argv, optstr);
55 got_dest_filename =
true;
68 flag = getopt(argc, argv, optstr);
76 cerr <<
"No filenames allowed in conjunction with -c.\n";
80 bool success = decompress_stream(cin, cout);
82 cerr <<
"Failure compressing standard input\n";
93 if (got_dest_filename && argc > 2) {
94 cerr <<
"Only one input file allowed in conjunction with -o.\n";
99 for (
int i = 1; i < argc; i++) {
101 if (!got_dest_filename && source_file.
get_extension() !=
"pz") {
103 <<
" doesn't end in .pz; can't derive filename of output file.\n";
108 if (!got_dest_filename) {
113 pifstream read_stream;
115 if (!source_file.
open_read(read_stream)) {
116 cerr <<
"Couldn't read: " << source_file << endl;
121 pofstream write_stream;
123 if (!dest_file.
open_write(write_stream,
true)) {
124 cerr <<
"Failed to open: " << dest_file << endl;
128 cerr << dest_file <<
"\n";
129 bool success = decompress_stream(read_stream, write_stream);
132 write_stream.close();
135 cerr <<
"Failure decompressing " << source_file <<
"\n";
140 if (!got_dest_filename) {
141 source_file.unlink();
string get_fullpath_wo_extension() const
Returns the full filename–directory and basename parts–except for the extension.
bool unlink() const
Permanently deletes the file associated with the filename, if possible.
void set_binary()
Indicates that the filename represents a binary file.
bool open_read(ifstream &stream) const
Opens the indicated ifstream for reading the file, if possible.
The name of a file, such as a texture file or an Egg file.
bool open_write(ofstream &stream, bool truncate=true) const
Opens the indicated ifstream for writing the file, if possible.
string get_extension() const
Returns the file extension.
static Filename from_os_specific(const string &os_specific, Type type=T_general)
This named constructor returns a Panda-style filename (that is, using forward slashes, and no drive letter) based on the supplied filename string that describes a filename in the local system conventions (for instance, on Windows, it may use backslashes or begin with a drive letter and a colon).