/* compress/decompress a file */ static void handle_file(char *file, struct stat *sbp) { off_t usize, gsize; char outfile[PATH_MAX]; infile = file; if (dflag) { usize = file_uncompress(file, outfile, sizeof(outfile)); #ifndef SMALL if (vflag && tflag) print_test(file, usize != -1); #endif if (usize == -1) return; gsize = sbp->st_size; } else { gsize = file_compress(file, outfile, sizeof(outfile)); if (gsize == -1) return; usize = sbp->st_size; } #ifndef SMALL if (vflag && !tflag) print_verbage(file, (cflag) ? NULL : outfile, usize, gsize); #endif }
/* ======================================================================== PURPOSE : */ int splitFiles (const char *sourceFilePath, const char *destDir) { stJAndSHeader *splitHdr = NULL; FILE *fileHdl = NULL; char splitName[_MAX_DIR]; short nErr = EZERO; sprintf ( splitName, "%s%s", sourceFilePath, ".CAT" ); if ((nErr = file_uncompress( sourceFilePath, splitName)) != 0) // @1 { String msg = String("Failed uncompress from ") + sourceFilePath + " to "+ splitName; throw std::exception ( msg.c_str() ); return nErr; } // Clear any outstanding errors errno = EZERO; // Get memory for the split header structure if ((splitHdr = (stJAndSHeader*)malloc(sizeof(stJAndSHeader))) != NULL) { // Open the join file... if ((fileHdl = fopen (splitName, "rb")) != NULL) { // Populate the header from the join file if (readHeader (splitHdr, fileHdl) == 0) { String strDestDir ( destDir ); if ( strDestDir.back() != '\\' && strDestDir.back() != '/' ) strDestDir.push_back ( '/' ); // ... and split out all the files. extractFiles ( strDestDir.c_str(), splitHdr, fileHdl ); } fclose(fileHdl); } free (splitHdr); } else throw std::exception ("Insufficient memory"); _unlink (splitName); // For debugging only #ifdef DEBUG_MODE printHeader (stdout,splitHdr); #endif return errno; }
int main( int argc, char *argv[]) { int copyout = 0; int uncompr = 0; gzFile file; char *bname, outmode[20]; strcpy(outmode, "wb6 "); prog = argv[0]; bname = strrchr(argv[0], '/'); if (bname) bname++; else bname = argv[0]; argc--, argv++; if (!strcmp(bname, "gunzip")) uncompr = 1; else if (!strcmp(bname, "zcat")) copyout = uncompr = 1; while (argc > 0) { if (strcmp(*argv, "-c") == 0) copyout = 1; else if (strcmp(*argv, "-d") == 0) uncompr = 1; else if (strcmp(*argv, "-f") == 0) outmode[3] = 'f'; else if (strcmp(*argv, "-h") == 0) outmode[3] = 'h'; else if (strcmp(*argv, "-r") == 0) outmode[3] = 'R'; else if ((*argv)[0] == '-' && (*argv)[1] >= '1' && (*argv)[1] <= '9' && (*argv)[2] == 0) outmode[2] = (*argv)[1]; else break; argc--, argv++; } if (outmode[3] == ' ') outmode[3] = 0; if (argc == 0) { SET_BINARY_MODE(stdin); SET_BINARY_MODE(stdout); if (uncompr) { file = gzdopen(fileno(stdin), "rb"); if (file == NULL) error("can't gzdopen stdin"); gz_uncompress(file, stdout); } else { file = gzdopen(fileno(stdout), outmode); if (file == NULL) error("can't gzdopen stdout"); gz_compress(stdin, file); } } else { if (copyout) { SET_BINARY_MODE(stdout); } do { if (uncompr) { if (copyout) { file = gzopen(*argv, "rb"); if (file == NULL) fprintf(stderr, "%s: can't gzopen %s\n", prog, *argv); else gz_uncompress(file, stdout); } else { file_uncompress(*argv); } } else { if (copyout) { FILE * in = fopen(*argv, "rb"); if (in == NULL) { perror(*argv); } else { file = gzdopen(fileno(stdout), outmode); if (file == NULL) error("can't gzdopen stdout"); gz_compress(in, file); } } else { file_compress(*argv, outmode); } } } while (argv++, --argc); } return 0; }