192 int opt_compress_level=Z_DEFAULT_COMPRESSION;
193 int zipfilenamearg = 0;
199 const char* password=NULL;
214 const char *p=argv[i]+1;
219 if ((c==
'o') || (c==
'O'))
221 if ((c==
'a') || (c==
'A'))
223 if ((c>=
'0') && (c<=
'9'))
224 opt_compress_level = c-
'0';
226 if (((c==
'p') || (c==
'P')) && (i+1<argc))
234 if (zipfilenamearg == 0)
240 buf = (
void*)malloc(size_buf);
243 printf(
"Error allocating memory\n");
247 if (zipfilenamearg==0)
255 strncpy(filename_try, argv[zipfilenamearg],
MAXFILENAME-1);
259 len=(
int)strlen(filename_try);
261 if (filename_try[i]==
'.')
265 strcat(filename_try,
".zip");
267 if (opt_overwrite==2)
274 if (opt_overwrite==0)
282 printf(
"The file %s exists. Overwrite ? [y]es, [n]o, [a]ppend : ",filename_try);
283 ret = scanf(
"%1s",answer);
289 if ((rep>=
'a') && (rep<=
'z'))
292 while ((rep!=
'Y') && (rep!=
'N') && (rep!=
'A'));
304 # ifdef USEWIN32IOAPI 307 zf =
zipOpen2(filename_try,(opt_overwrite==2) ? 2 : 0,NULL,&ffunc);
309 zf =
zipOpen(filename_try,(opt_overwrite==2) ? 2 : 0);
314 printf(
"error opening %s\n",filename_try);
318 printf(
"creating %s\n",filename_try);
320 for (i=zipfilenamearg+1;(i<argc) && (err==
ZIP_OK);i++)
322 if (!((((*(argv[i]))==
'-') || ((*(argv[i]))==
'/')) &&
323 ((argv[i][1]==
'o') || (argv[i][1]==
'O') ||
324 (argv[i][1]==
'a') || (argv[i][1]==
'A') ||
325 (argv[i][1]==
'p') || (argv[i][1]==
'P') ||
326 ((argv[i][1]>=
'0') || (argv[i][1]<=
'9'))) &&
327 (strlen(argv[i]) == 2)))
331 const char* filenameinzip = argv[i];
333 unsigned long crcFile=0;
348 if ((password != NULL) && (err==
ZIP_OK))
349 err =
getFileCrc(filenameinzip,buf,size_buf,&crcFile);
353 (opt_compress_level != 0) ? Z_DEFLATED : 0,
354 opt_compress_level,0,
360 printf(
"error in opening %s in zipfile\n",filenameinzip);
363 fin = fopen(filenameinzip,
"rb");
367 printf(
"error in opening %s for reading\n",filenameinzip);
375 size_read = (
int)fread(buf,1,size_buf,fin);
376 if (size_read < size_buf)
379 printf(
"error in reading %s\n",filenameinzip);
388 printf(
"error in writing %s in the zipfile\n",
393 }
while ((err ==
ZIP_OK) && (size_read>0));
404 printf(
"error in closing %s in the zipfile\n",
411 printf(
"error in closing %s\n",filename_try);
void fill_win32_filefunc(zlib_filefunc_def *pzlib_filefunc_def)
int getFileCrc(const char *filenameinzip, void *buf, unsigned long size_buf, unsigned long *result_crc)
zipFile ZEXPORT zipOpen(char *pathname, int append) const
int ZEXPORT zipWriteInFileInZip(zipFile file, const void *buf, unsigned len)
#define ZIP_INTERNALERROR
int check_exist_file(char *filename) const
uLong filetime(char *f, tm_zip *tmzip, uLong *dt)
int ZEXPORT zipCloseFileInZip(zipFile file)
zipFile ZEXPORT zipOpen2(char *pathname, int append, zipcharpc *globalcomment, zlib_filefunc_def *pzlib_filefunc_def) const
typedef int(ZCALLBACK *close_file_func) OF((voidpf opaque
int ZEXPORT zipOpenNewFileInZip3(zipFile file, const char *filename, const zip_fileinfo *zipfi, const void *extrafield_local, uInt size_extrafield_local, const void *extrafield_global, uInt size_extrafield_global, const char *comment, int method, int level, int raw, int windowBits, int memLevel, int strategy, const char *password, uLong crcForCrypting)
int ZEXPORT zipClose(zipFile file, const char *global_comment)