* ========== Copyright Header Begin ==========================================
* OpenSPARC T2 Processor File: rstzip2c.c
* Copyright (c) 2006 Sun Microsystems, Inc. All Rights Reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES.
* The above named program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public
* License version 2 as published by the Free Software Foundation.
* The above named program is distributed in the hope that it will be
* useful, but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* General Public License for more details.
* You should have received a copy of the GNU General Public
* License along with this work; if not, write to the Free Software
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA.
* ========== Copyright Header End ============================================
static char zipname
[] = "rstzip2";
static char unzipname
[] = "rstunzip2";
static char* exename
= zipname
;
void fprintUsage(FILE* fp
, int major
, int minor
) {
"Usage: %s [flags] [infile]\n"
"(version %d.%02d, compiled %s) Compress / Decompress RST trace files.\n"
" -n # decompress # records and exit (0=all, default=0)\n"
" -up compress as uniprocessor trace (for old RST format)\n"
" -mp compress as multiprocessor trace (for new RST format)\n"
" -s print compression statistics\n"
" -nogz do not apply gzip to the rstzip2 (de)compression\n"
" -o outfile write output to outfile (Default: stdout)\n"
" infile file to (de)compress (Default: stdin)\n"
"NOTES: The 'old' RST format refers to RST versions 1.09 and below.\n"
" Rstzip2 is incompatible with rstzip compressed files.\n"
"Example 1: rstzip2 -o file.rz2.gz file.rst\n"
"Example 2: rstunzip2 file.rz2.gz | trconv | less\n"
"Example 3: rstzip2 file.rst | rstunzip2 | trconv | less\n"
"Uses libz.a (version 1.1.3) written by Jean-loup Gailly and Mark Adler.\n"
exename
, major
, minor
, __DATE__
);
int main(int argc
, char* argv
[]) {
Rstzip2if
* rstzip
= new Rstzip2if
;
rstf_unionT
* rstbuf
= NULL
;
uint64_t decompress_nrecs
= 0;
char* pname
= strrchr(argv
[0], '/');
if (strcmp(argv
[0], unzipname
) == 0) {
if (strcmp(pname
+ 1, unzipname
) == 0) {
for (i
= 1; i
< argc
; i
++) {
if (strcmp(argv
[i
], "-d") == 0) {
} else if (strcmp(argv
[i
], "-n") == 0) {
decompress_nrecs
= strtoull(argv
[i
], NULL
, 10);
} else if (strcmp(argv
[i
], "-up") == 0) {
} else if (strcmp(argv
[i
], "-mp") == 0) {
} else if (strcmp(argv
[i
], "-s") == 0) {
} else if (strcmp(argv
[i
], "-nogz") == 0) {
} else if (strcmp(argv
[i
], "-h") == 0 ||
strcmp(argv
[i
], "-help") == 0) {
fprintUsage(stdout
, rstzip
->getMajorVersion(), rstzip
->getMinorVersion());
} else if (strcmp(argv
[i
], "-o") == 0) {
} else if (i
== argc
- 1) {
fprintUsage(stderr
, rstzip
->getMajorVersion(), rstzip
->getMinorVersion());
fprintf(stderr
, "Error: unknown input parameter %s\n", argv
[i
]);
if (exename
== unzipname
) {
outfp
= fopen(outfile
, "w");
fprintf(stderr
, "\nError: unable to open %s for writing.\n\n", outfile
);
infile
= (char*) malloc(2);
infp
= fopen(infile
, "r");
fprintf(stderr
, "\nError: unable to open %s for reading.\n\n", infile
);
fprintUsage(stderr
, rstzip
->getMajorVersion(), rstzip
->getMinorVersion());
outfile
= (char*) malloc(2);
rstbuf
= (rstf_unionT
*) malloc(BUFFERSIZE
* sizeof(rstf_unionT
));
nrecs
= fread(rstbuf
, sizeof(rstf_unionT
), BUFFERSIZE
, infp
);
if (rstbuf
[0].proto
.rtype
== RSTHEADER_T
) {
if ((rstbuf
[0].header
.majorVer
* 100) + rstbuf
[0].header
.minorVer
< 110) {
rstzip
->openRstzip(outfile
, BUFFERSIZE
, gzip
, stats
, numcpus
);
rstzip
->compress(rstbuf
, nrecs
);
nrecs
= fread(rstbuf
, sizeof(rstf_unionT
), BUFFERSIZE
, infp
);
rstzip
->openRstunzip(infile
, BUFFERSIZE
, gzip
, stats
);
nrecs
= rstzip
->decompress(rstbuf
, BUFFERSIZE
);
if (decompress_nrecs
> 0 && totalrecs
+ nrecs
> decompress_nrecs
) {
totalrecs
+= fwrite(rstbuf
, sizeof(rstf_unionT
), decompress_nrecs
- totalrecs
, outfp
);
totalrecs
+= fwrite(rstbuf
, sizeof(rstf_unionT
), nrecs
, outfp
);
nrecs
= rstzip
->decompress(rstbuf
, BUFFERSIZE
);
int main(int argc
, char* argv
[]) {
Rstzip2if
* rstzip
= NULL
;
rstf_unionT
* rstbuf
= NULL
;
uint64_t decompress_nrecs
= 0;
char* pname
= strrchr(argv
[0], '/');
if (strcmp(argv
[0], unzipname
) == 0) {
if (strcmp(pname
+ 1, unzipname
) == 0) {
for (i
= 1; i
< argc
; i
++) {
if (strcmp(argv
[i
], "-d") == 0) {
} else if (strcmp(argv
[i
], "-n") == 0) {
decompress_nrecs
= strtoull(argv
[i
], NULL
, 10);
} else if (strcmp(argv
[i
], "-up") == 0) {
} else if (strcmp(argv
[i
], "-mp") == 0) {
} else if (strcmp(argv
[i
], "-s") == 0) {
} else if (strcmp(argv
[i
], "-nogz") == 0) {
} else if (strcmp(argv
[i
], "-h") == 0) {
fprintUsage(stdout
, rz2_getMajorVersion(rstzip
), rz2_getMinorVersion(rstzip
));
} else if (strcmp(argv
[i
], "-o") == 0) {
} else if (i
== argc
- 1) {
fprintUsage(stderr
, rz2_getMajorVersion(rstzip
), rz2_getMinorVersion(rstzip
));
fprintf(stderr
, "Error: unknown input parameter %s\n", argv
[i
]);
if (exename
== unzipname
) {
outfp
= fopen(outfile
, "w");
fprintf(stderr
, "Error: unable to open %s for writing.\n", outfile
);
infile
= (char*) malloc(2);
infp
= fopen(infile
, "r");
fprintf(stderr
, "Error: unable to open %s for reading.\n", infile
);
outfile
= (char*) malloc(2);
rstbuf
= (rstf_unionT
*) malloc(BUFFERSIZE
* sizeof(rstf_unionT
));
nrecs
= fread(rstbuf
, sizeof(rstf_unionT
), BUFFERSIZE
, infp
);
if (rstbuf
[0].proto
.rtype
== RSTHEADER_T
) {
if ((rstbuf
[0].header
.majorVer
* 100) + rstbuf
[0].header
.minorVer
< 110) {
rstzip
= rz2_openRstzip(outfile
, BUFFERSIZE
, gzip
, stats
, numcpus
);
rz2_compress(rstzip
, rstbuf
, nrecs
);
nrecs
= fread(rstbuf
, sizeof(rstf_unionT
), BUFFERSIZE
, infp
);
rstzip
= rz2_openRstunzip(infile
, BUFFERSIZE
, gzip
, stats
);
nrecs
= rz2_decompress(rstzip
, rstbuf
, BUFFERSIZE
);
if (decompress_nrecs
> 0 && totalrecs
+ nrecs
> decompress_nrecs
) {
totalrecs
+= fwrite(rstbuf
, sizeof(rstf_unionT
), decompress_nrecs
- totalrecs
, outfp
);
totalrecs
+= fwrite(rstbuf
, sizeof(rstf_unionT
), nrecs
, outfp
);
nrecs
= rz2_decompress(rstzip
, rstbuf
, BUFFERSIZE
);
rz2_closeRstunzip(rstzip
);