xlsxwriter 0.0.2

Sign up to get free protection for your applications and to get access to all the features.
Files changed (112) hide show
  1. checksums.yaml +7 -0
  2. data/Rakefile +40 -0
  3. data/ext/xlsxwriter/chart.c +105 -0
  4. data/ext/xlsxwriter/chart.h +27 -0
  5. data/ext/xlsxwriter/extconf.rb +14 -0
  6. data/ext/xlsxwriter/format.c +67 -0
  7. data/ext/xlsxwriter/format.h +9 -0
  8. data/ext/xlsxwriter/libxlsxwriter/LICENSE.txt +89 -0
  9. data/ext/xlsxwriter/libxlsxwriter/Makefile +141 -0
  10. data/ext/xlsxwriter/libxlsxwriter/include/xlsxwriter.h +23 -0
  11. data/ext/xlsxwriter/libxlsxwriter/include/xlsxwriter/app.h +79 -0
  12. data/ext/xlsxwriter/libxlsxwriter/include/xlsxwriter/chart.h +1093 -0
  13. data/ext/xlsxwriter/libxlsxwriter/include/xlsxwriter/common.h +336 -0
  14. data/ext/xlsxwriter/libxlsxwriter/include/xlsxwriter/content_types.h +74 -0
  15. data/ext/xlsxwriter/libxlsxwriter/include/xlsxwriter/core.h +51 -0
  16. data/ext/xlsxwriter/libxlsxwriter/include/xlsxwriter/custom.h +52 -0
  17. data/ext/xlsxwriter/libxlsxwriter/include/xlsxwriter/drawing.h +111 -0
  18. data/ext/xlsxwriter/libxlsxwriter/include/xlsxwriter/format.h +1214 -0
  19. data/ext/xlsxwriter/libxlsxwriter/include/xlsxwriter/hash_table.h +76 -0
  20. data/ext/xlsxwriter/libxlsxwriter/include/xlsxwriter/packager.h +80 -0
  21. data/ext/xlsxwriter/libxlsxwriter/include/xlsxwriter/relationships.h +77 -0
  22. data/ext/xlsxwriter/libxlsxwriter/include/xlsxwriter/shared_strings.h +83 -0
  23. data/ext/xlsxwriter/libxlsxwriter/include/xlsxwriter/styles.h +77 -0
  24. data/ext/xlsxwriter/libxlsxwriter/include/xlsxwriter/theme.h +47 -0
  25. data/ext/xlsxwriter/libxlsxwriter/include/xlsxwriter/third_party/ioapi.h +215 -0
  26. data/ext/xlsxwriter/libxlsxwriter/include/xlsxwriter/third_party/queue.h +694 -0
  27. data/ext/xlsxwriter/libxlsxwriter/include/xlsxwriter/third_party/tmpfileplus.h +53 -0
  28. data/ext/xlsxwriter/libxlsxwriter/include/xlsxwriter/third_party/tree.h +801 -0
  29. data/ext/xlsxwriter/libxlsxwriter/include/xlsxwriter/third_party/zip.h +375 -0
  30. data/ext/xlsxwriter/libxlsxwriter/include/xlsxwriter/utility.h +166 -0
  31. data/ext/xlsxwriter/libxlsxwriter/include/xlsxwriter/workbook.h +751 -0
  32. data/ext/xlsxwriter/libxlsxwriter/include/xlsxwriter/worksheet.h +2641 -0
  33. data/ext/xlsxwriter/libxlsxwriter/include/xlsxwriter/xmlwriter.h +178 -0
  34. data/ext/xlsxwriter/libxlsxwriter/lib/.gitignore +0 -0
  35. data/ext/xlsxwriter/libxlsxwriter/src/Makefile +125 -0
  36. data/ext/xlsxwriter/libxlsxwriter/src/app.c +439 -0
  37. data/ext/xlsxwriter/libxlsxwriter/src/chart.c +3420 -0
  38. data/ext/xlsxwriter/libxlsxwriter/src/content_types.c +341 -0
  39. data/ext/xlsxwriter/libxlsxwriter/src/core.c +293 -0
  40. data/ext/xlsxwriter/libxlsxwriter/src/custom.c +224 -0
  41. data/ext/xlsxwriter/libxlsxwriter/src/drawing.c +746 -0
  42. data/ext/xlsxwriter/libxlsxwriter/src/format.c +728 -0
  43. data/ext/xlsxwriter/libxlsxwriter/src/hash_table.c +223 -0
  44. data/ext/xlsxwriter/libxlsxwriter/src/packager.c +877 -0
  45. data/ext/xlsxwriter/libxlsxwriter/src/relationships.c +242 -0
  46. data/ext/xlsxwriter/libxlsxwriter/src/shared_strings.c +264 -0
  47. data/ext/xlsxwriter/libxlsxwriter/src/styles.c +1086 -0
  48. data/ext/xlsxwriter/libxlsxwriter/src/theme.c +348 -0
  49. data/ext/xlsxwriter/libxlsxwriter/src/utility.c +512 -0
  50. data/ext/xlsxwriter/libxlsxwriter/src/workbook.c +1895 -0
  51. data/ext/xlsxwriter/libxlsxwriter/src/worksheet.c +4992 -0
  52. data/ext/xlsxwriter/libxlsxwriter/src/xmlwriter.c +355 -0
  53. data/ext/xlsxwriter/libxlsxwriter/third_party/minizip/Makefile +44 -0
  54. data/ext/xlsxwriter/libxlsxwriter/third_party/minizip/crypt.h +131 -0
  55. data/ext/xlsxwriter/libxlsxwriter/third_party/minizip/ioapi.c +247 -0
  56. data/ext/xlsxwriter/libxlsxwriter/third_party/minizip/ioapi.h +209 -0
  57. data/ext/xlsxwriter/libxlsxwriter/third_party/minizip/iowin32.c +456 -0
  58. data/ext/xlsxwriter/libxlsxwriter/third_party/minizip/iowin32.h +28 -0
  59. data/ext/xlsxwriter/libxlsxwriter/third_party/minizip/miniunz.c +660 -0
  60. data/ext/xlsxwriter/libxlsxwriter/third_party/minizip/minizip.c +520 -0
  61. data/ext/xlsxwriter/libxlsxwriter/third_party/minizip/mztools.c +291 -0
  62. data/ext/xlsxwriter/libxlsxwriter/third_party/minizip/mztools.h +37 -0
  63. data/ext/xlsxwriter/libxlsxwriter/third_party/minizip/unzip.c +2125 -0
  64. data/ext/xlsxwriter/libxlsxwriter/third_party/minizip/unzip.h +437 -0
  65. data/ext/xlsxwriter/libxlsxwriter/third_party/minizip/zip.c +2007 -0
  66. data/ext/xlsxwriter/libxlsxwriter/third_party/minizip/zip.h +367 -0
  67. data/ext/xlsxwriter/libxlsxwriter/third_party/tmpfileplus/Makefile +42 -0
  68. data/ext/xlsxwriter/libxlsxwriter/third_party/tmpfileplus/tmpfileplus.c +342 -0
  69. data/ext/xlsxwriter/libxlsxwriter/third_party/tmpfileplus/tmpfileplus.h +53 -0
  70. data/ext/xlsxwriter/workbook.c +257 -0
  71. data/ext/xlsxwriter/workbook.h +42 -0
  72. data/ext/xlsxwriter/workbook_properties.c +103 -0
  73. data/ext/xlsxwriter/workbook_properties.h +10 -0
  74. data/ext/xlsxwriter/worksheet.c +1064 -0
  75. data/ext/xlsxwriter/worksheet.h +74 -0
  76. data/ext/xlsxwriter/xlsxwriter.c +239 -0
  77. data/lib/xlsxwriter.rb +6 -0
  78. data/lib/xlsxwriter/version.rb +3 -0
  79. data/lib/xlsxwriter/worksheet.rb +72 -0
  80. data/test/run-test.rb +11 -0
  81. data/test/support/xlsx_comparable.rb +109 -0
  82. data/test/test-array-formula.rb +33 -0
  83. data/test/test-autofilter.rb +70 -0
  84. data/test/test-chart-area.rb +25 -0
  85. data/test/test-data.rb +65 -0
  86. data/test/test-default-row.rb +25 -0
  87. data/test/test-defined-name.rb +46 -0
  88. data/test/test-escapes.rb +33 -0
  89. data/test/test-fit-to-pages.rb +21 -0
  90. data/test/test-formatting.rb +137 -0
  91. data/test/test-gridlines.rb +15 -0
  92. data/test/test-hyperlink.rb +67 -0
  93. data/test/test-image.rb +84 -0
  94. data/test/test-merge-range.rb +18 -0
  95. data/test/test-misc.rb +29 -0
  96. data/test/test-optimize.rb +32 -0
  97. data/test/test-page-breaks.rb +13 -0
  98. data/test/test-page-setup.rb +28 -0
  99. data/test/test-panes.rb +45 -0
  100. data/test/test-print-area.rb +19 -0
  101. data/test/test-print-options.rb +61 -0
  102. data/test/test-print-scale.rb +12 -0
  103. data/test/test-properties.rb +51 -0
  104. data/test/test-protect.rb +27 -0
  105. data/test/test-repeat.rb +23 -0
  106. data/test/test-row-col-format.rb +35 -0
  107. data/test/test-set-selection.rb +13 -0
  108. data/test/test-set-start-page.rb +13 -0
  109. data/test/test-simple.rb +62 -0
  110. data/test/test-types.rb +17 -0
  111. data/test/xlsx-func-testcase.rb +36 -0
  112. metadata +228 -0
@@ -0,0 +1,28 @@
1
+ /* iowin32.h -- IO base function header for compress/uncompress .zip
2
+ Version 1.1, February 14h, 2010
3
+ part of the MiniZip project - ( http://www.winimage.com/zLibDll/minizip.html )
4
+
5
+ Copyright (C) 1998-2010 Gilles Vollant (minizip) ( http://www.winimage.com/zLibDll/minizip.html )
6
+
7
+ Modifications for Zip64 support
8
+ Copyright (C) 2009-2010 Mathias Svensson ( http://result42.com )
9
+
10
+ For more info read MiniZip_info.txt
11
+
12
+ */
13
+
14
+ #include <windows.h>
15
+
16
+
17
+ #ifdef __cplusplus
18
+ extern "C" {
19
+ #endif
20
+
21
+ void fill_win32_filefunc OF((zlib_filefunc_def* pzlib_filefunc_def));
22
+ void fill_win32_filefunc64 OF((zlib_filefunc64_def* pzlib_filefunc_def));
23
+ void fill_win32_filefunc64A OF((zlib_filefunc64_def* pzlib_filefunc_def));
24
+ void fill_win32_filefunc64W OF((zlib_filefunc64_def* pzlib_filefunc_def));
25
+
26
+ #ifdef __cplusplus
27
+ }
28
+ #endif
@@ -0,0 +1,660 @@
1
+ /*
2
+ miniunz.c
3
+ Version 1.1, February 14h, 2010
4
+ sample part of the MiniZip project - ( http://www.winimage.com/zLibDll/minizip.html )
5
+
6
+ Copyright (C) 1998-2010 Gilles Vollant (minizip) ( http://www.winimage.com/zLibDll/minizip.html )
7
+
8
+ Modifications of Unzip for Zip64
9
+ Copyright (C) 2007-2008 Even Rouault
10
+
11
+ Modifications for Zip64 support on both zip and unzip
12
+ Copyright (C) 2009-2010 Mathias Svensson ( http://result42.com )
13
+ */
14
+
15
+ #if (!defined(_WIN32)) && (!defined(WIN32)) && (!defined(__APPLE__))
16
+ #ifndef __USE_FILE_OFFSET64
17
+ #define __USE_FILE_OFFSET64
18
+ #endif
19
+ #ifndef __USE_LARGEFILE64
20
+ #define __USE_LARGEFILE64
21
+ #endif
22
+ #ifndef _LARGEFILE64_SOURCE
23
+ #define _LARGEFILE64_SOURCE
24
+ #endif
25
+ #ifndef _FILE_OFFSET_BIT
26
+ #define _FILE_OFFSET_BIT 64
27
+ #endif
28
+ #endif
29
+
30
+ #ifdef __APPLE__
31
+ // In darwin and perhaps other BSD variants off_t is a 64 bit value, hence no need for specific 64 bit functions
32
+ #define FOPEN_FUNC(filename, mode) fopen(filename, mode)
33
+ #define FTELLO_FUNC(stream) ftello(stream)
34
+ #define FSEEKO_FUNC(stream, offset, origin) fseeko(stream, offset, origin)
35
+ #else
36
+ #define FOPEN_FUNC(filename, mode) fopen64(filename, mode)
37
+ #define FTELLO_FUNC(stream) ftello64(stream)
38
+ #define FSEEKO_FUNC(stream, offset, origin) fseeko64(stream, offset, origin)
39
+ #endif
40
+
41
+
42
+ #include <stdio.h>
43
+ #include <stdlib.h>
44
+ #include <string.h>
45
+ #include <time.h>
46
+ #include <errno.h>
47
+ #include <fcntl.h>
48
+
49
+ #ifdef _WIN32
50
+ # include <direct.h>
51
+ # include <io.h>
52
+ #else
53
+ # include <unistd.h>
54
+ # include <utime.h>
55
+ #endif
56
+
57
+
58
+ #include "unzip.h"
59
+
60
+ #define CASESENSITIVITY (0)
61
+ #define WRITEBUFFERSIZE (8192)
62
+ #define MAXFILENAME (256)
63
+
64
+ #ifdef _WIN32
65
+ #define USEWIN32IOAPI
66
+ #include "iowin32.h"
67
+ #endif
68
+ /*
69
+ mini unzip, demo of unzip package
70
+
71
+ usage :
72
+ Usage : miniunz [-exvlo] file.zip [file_to_extract] [-d extractdir]
73
+
74
+ list the file in the zipfile, and print the content of FILE_ID.ZIP or README.TXT
75
+ if it exists
76
+ */
77
+
78
+
79
+ /* change_file_date : change the date/time of a file
80
+ filename : the filename of the file where date/time must be modified
81
+ dosdate : the new date at the MSDos format (4 bytes)
82
+ tmu_date : the SAME new date at the tm_unz format */
83
+ void change_file_date(filename,dosdate,tmu_date)
84
+ const char *filename;
85
+ uLong dosdate;
86
+ tm_unz tmu_date;
87
+ {
88
+ #ifdef _WIN32
89
+ HANDLE hFile;
90
+ FILETIME ftm,ftLocal,ftCreate,ftLastAcc,ftLastWrite;
91
+
92
+ hFile = CreateFileA(filename,GENERIC_READ | GENERIC_WRITE,
93
+ 0,NULL,OPEN_EXISTING,0,NULL);
94
+ GetFileTime(hFile,&ftCreate,&ftLastAcc,&ftLastWrite);
95
+ DosDateTimeToFileTime((WORD)(dosdate>>16),(WORD)dosdate,&ftLocal);
96
+ LocalFileTimeToFileTime(&ftLocal,&ftm);
97
+ SetFileTime(hFile,&ftm,&ftLastAcc,&ftm);
98
+ CloseHandle(hFile);
99
+ #else
100
+ #ifdef unix || __APPLE__
101
+ struct utimbuf ut;
102
+ struct tm newdate;
103
+ newdate.tm_sec = tmu_date.tm_sec;
104
+ newdate.tm_min=tmu_date.tm_min;
105
+ newdate.tm_hour=tmu_date.tm_hour;
106
+ newdate.tm_mday=tmu_date.tm_mday;
107
+ newdate.tm_mon=tmu_date.tm_mon;
108
+ if (tmu_date.tm_year > 1900)
109
+ newdate.tm_year=tmu_date.tm_year - 1900;
110
+ else
111
+ newdate.tm_year=tmu_date.tm_year ;
112
+ newdate.tm_isdst=-1;
113
+
114
+ ut.actime=ut.modtime=mktime(&newdate);
115
+ utime(filename,&ut);
116
+ #endif
117
+ #endif
118
+ }
119
+
120
+
121
+ /* mymkdir and change_file_date are not 100 % portable
122
+ As I don't know well Unix, I wait feedback for the unix portion */
123
+
124
+ int mymkdir(dirname)
125
+ const char* dirname;
126
+ {
127
+ int ret=0;
128
+ #ifdef _WIN32
129
+ ret = _mkdir(dirname);
130
+ #elif unix
131
+ ret = mkdir (dirname,0775);
132
+ #elif __APPLE__
133
+ ret = mkdir (dirname,0775);
134
+ #endif
135
+ return ret;
136
+ }
137
+
138
+ int makedir (newdir)
139
+ char *newdir;
140
+ {
141
+ char *buffer ;
142
+ char *p;
143
+ int len = (int)strlen(newdir);
144
+
145
+ if (len <= 0)
146
+ return 0;
147
+
148
+ buffer = (char*)malloc(len+1);
149
+ if (buffer==NULL)
150
+ {
151
+ printf("Error allocating memory\n");
152
+ return UNZ_INTERNALERROR;
153
+ }
154
+ strcpy(buffer,newdir);
155
+
156
+ if (buffer[len-1] == '/') {
157
+ buffer[len-1] = '\0';
158
+ }
159
+ if (mymkdir(buffer) == 0)
160
+ {
161
+ free(buffer);
162
+ return 1;
163
+ }
164
+
165
+ p = buffer+1;
166
+ while (1)
167
+ {
168
+ char hold;
169
+
170
+ while(*p && *p != '\\' && *p != '/')
171
+ p++;
172
+ hold = *p;
173
+ *p = 0;
174
+ if ((mymkdir(buffer) == -1) && (errno == ENOENT))
175
+ {
176
+ printf("couldn't create directory %s\n",buffer);
177
+ free(buffer);
178
+ return 0;
179
+ }
180
+ if (hold == 0)
181
+ break;
182
+ *p++ = hold;
183
+ }
184
+ free(buffer);
185
+ return 1;
186
+ }
187
+
188
+ void do_banner()
189
+ {
190
+ printf("MiniUnz 1.01b, demo of zLib + Unz package written by Gilles Vollant\n");
191
+ printf("more info at http://www.winimage.com/zLibDll/unzip.html\n\n");
192
+ }
193
+
194
+ void do_help()
195
+ {
196
+ printf("Usage : miniunz [-e] [-x] [-v] [-l] [-o] [-p password] file.zip [file_to_extr.] [-d extractdir]\n\n" \
197
+ " -e Extract without pathname (junk paths)\n" \
198
+ " -x Extract with pathname\n" \
199
+ " -v list files\n" \
200
+ " -l list files\n" \
201
+ " -d directory to extract into\n" \
202
+ " -o overwrite files without prompting\n" \
203
+ " -p extract crypted file using password\n\n");
204
+ }
205
+
206
+ void Display64BitsSize(ZPOS64_T n, int size_char)
207
+ {
208
+ /* to avoid compatibility problem , we do here the conversion */
209
+ char number[21];
210
+ int offset=19;
211
+ int pos_string = 19;
212
+ number[20]=0;
213
+ for (;;) {
214
+ number[offset]=(char)((n%10)+'0');
215
+ if (number[offset] != '0')
216
+ pos_string=offset;
217
+ n/=10;
218
+ if (offset==0)
219
+ break;
220
+ offset--;
221
+ }
222
+ {
223
+ int size_display_string = 19-pos_string;
224
+ while (size_char > size_display_string)
225
+ {
226
+ size_char--;
227
+ printf(" ");
228
+ }
229
+ }
230
+
231
+ printf("%s",&number[pos_string]);
232
+ }
233
+
234
+ int do_list(uf)
235
+ unzFile uf;
236
+ {
237
+ uLong i;
238
+ unz_global_info64 gi;
239
+ int err;
240
+
241
+ err = unzGetGlobalInfo64(uf,&gi);
242
+ if (err!=UNZ_OK)
243
+ printf("error %d with zipfile in unzGetGlobalInfo \n",err);
244
+ printf(" Length Method Size Ratio Date Time CRC-32 Name\n");
245
+ printf(" ------ ------ ---- ----- ---- ---- ------ ----\n");
246
+ for (i=0;i<gi.number_entry;i++)
247
+ {
248
+ char filename_inzip[256];
249
+ unz_file_info64 file_info;
250
+ uLong ratio=0;
251
+ const char *string_method;
252
+ char charCrypt=' ';
253
+ err = unzGetCurrentFileInfo64(uf,&file_info,filename_inzip,sizeof(filename_inzip),NULL,0,NULL,0);
254
+ if (err!=UNZ_OK)
255
+ {
256
+ printf("error %d with zipfile in unzGetCurrentFileInfo\n",err);
257
+ break;
258
+ }
259
+ if (file_info.uncompressed_size>0)
260
+ ratio = (uLong)((file_info.compressed_size*100)/file_info.uncompressed_size);
261
+
262
+ /* display a '*' if the file is crypted */
263
+ if ((file_info.flag & 1) != 0)
264
+ charCrypt='*';
265
+
266
+ if (file_info.compression_method==0)
267
+ string_method="Stored";
268
+ else
269
+ if (file_info.compression_method==Z_DEFLATED)
270
+ {
271
+ uInt iLevel=(uInt)((file_info.flag & 0x6)/2);
272
+ if (iLevel==0)
273
+ string_method="Defl:N";
274
+ else if (iLevel==1)
275
+ string_method="Defl:X";
276
+ else if ((iLevel==2) || (iLevel==3))
277
+ string_method="Defl:F"; /* 2:fast , 3 : extra fast*/
278
+ }
279
+ else
280
+ if (file_info.compression_method==Z_BZIP2ED)
281
+ {
282
+ string_method="BZip2 ";
283
+ }
284
+ else
285
+ string_method="Unkn. ";
286
+
287
+ Display64BitsSize(file_info.uncompressed_size,7);
288
+ printf(" %6s%c",string_method,charCrypt);
289
+ Display64BitsSize(file_info.compressed_size,7);
290
+ printf(" %3lu%% %2.2lu-%2.2lu-%2.2lu %2.2lu:%2.2lu %8.8lx %s\n",
291
+ ratio,
292
+ (uLong)file_info.tmu_date.tm_mon + 1,
293
+ (uLong)file_info.tmu_date.tm_mday,
294
+ (uLong)file_info.tmu_date.tm_year % 100,
295
+ (uLong)file_info.tmu_date.tm_hour,(uLong)file_info.tmu_date.tm_min,
296
+ (uLong)file_info.crc,filename_inzip);
297
+ if ((i+1)<gi.number_entry)
298
+ {
299
+ err = unzGoToNextFile(uf);
300
+ if (err!=UNZ_OK)
301
+ {
302
+ printf("error %d with zipfile in unzGoToNextFile\n",err);
303
+ break;
304
+ }
305
+ }
306
+ }
307
+
308
+ return 0;
309
+ }
310
+
311
+
312
+ int do_extract_currentfile(uf,popt_extract_without_path,popt_overwrite,password)
313
+ unzFile uf;
314
+ const int* popt_extract_without_path;
315
+ int* popt_overwrite;
316
+ const char* password;
317
+ {
318
+ char filename_inzip[256];
319
+ char* filename_withoutpath;
320
+ char* p;
321
+ int err=UNZ_OK;
322
+ FILE *fout=NULL;
323
+ void* buf;
324
+ uInt size_buf;
325
+
326
+ unz_file_info64 file_info;
327
+ uLong ratio=0;
328
+ err = unzGetCurrentFileInfo64(uf,&file_info,filename_inzip,sizeof(filename_inzip),NULL,0,NULL,0);
329
+
330
+ if (err!=UNZ_OK)
331
+ {
332
+ printf("error %d with zipfile in unzGetCurrentFileInfo\n",err);
333
+ return err;
334
+ }
335
+
336
+ size_buf = WRITEBUFFERSIZE;
337
+ buf = (void*)malloc(size_buf);
338
+ if (buf==NULL)
339
+ {
340
+ printf("Error allocating memory\n");
341
+ return UNZ_INTERNALERROR;
342
+ }
343
+
344
+ p = filename_withoutpath = filename_inzip;
345
+ while ((*p) != '\0')
346
+ {
347
+ if (((*p)=='/') || ((*p)=='\\'))
348
+ filename_withoutpath = p+1;
349
+ p++;
350
+ }
351
+
352
+ if ((*filename_withoutpath)=='\0')
353
+ {
354
+ if ((*popt_extract_without_path)==0)
355
+ {
356
+ printf("creating directory: %s\n",filename_inzip);
357
+ mymkdir(filename_inzip);
358
+ }
359
+ }
360
+ else
361
+ {
362
+ const char* write_filename;
363
+ int skip=0;
364
+
365
+ if ((*popt_extract_without_path)==0)
366
+ write_filename = filename_inzip;
367
+ else
368
+ write_filename = filename_withoutpath;
369
+
370
+ err = unzOpenCurrentFilePassword(uf,password);
371
+ if (err!=UNZ_OK)
372
+ {
373
+ printf("error %d with zipfile in unzOpenCurrentFilePassword\n",err);
374
+ }
375
+
376
+ if (((*popt_overwrite)==0) && (err==UNZ_OK))
377
+ {
378
+ char rep=0;
379
+ FILE* ftestexist;
380
+ ftestexist = FOPEN_FUNC(write_filename,"rb");
381
+ if (ftestexist!=NULL)
382
+ {
383
+ fclose(ftestexist);
384
+ do
385
+ {
386
+ char answer[128];
387
+ int ret;
388
+
389
+ printf("The file %s exists. Overwrite ? [y]es, [n]o, [A]ll: ",write_filename);
390
+ ret = scanf("%1s",answer);
391
+ if (ret != 1)
392
+ {
393
+ exit(EXIT_FAILURE);
394
+ }
395
+ rep = answer[0] ;
396
+ if ((rep>='a') && (rep<='z'))
397
+ rep -= 0x20;
398
+ }
399
+ while ((rep!='Y') && (rep!='N') && (rep!='A'));
400
+ }
401
+
402
+ if (rep == 'N')
403
+ skip = 1;
404
+
405
+ if (rep == 'A')
406
+ *popt_overwrite=1;
407
+ }
408
+
409
+ if ((skip==0) && (err==UNZ_OK))
410
+ {
411
+ fout=FOPEN_FUNC(write_filename,"wb");
412
+ /* some zipfile don't contain directory alone before file */
413
+ if ((fout==NULL) && ((*popt_extract_without_path)==0) &&
414
+ (filename_withoutpath!=(char*)filename_inzip))
415
+ {
416
+ char c=*(filename_withoutpath-1);
417
+ *(filename_withoutpath-1)='\0';
418
+ makedir(write_filename);
419
+ *(filename_withoutpath-1)=c;
420
+ fout=FOPEN_FUNC(write_filename,"wb");
421
+ }
422
+
423
+ if (fout==NULL)
424
+ {
425
+ printf("error opening %s\n",write_filename);
426
+ }
427
+ }
428
+
429
+ if (fout!=NULL)
430
+ {
431
+ printf(" extracting: %s\n",write_filename);
432
+
433
+ do
434
+ {
435
+ err = unzReadCurrentFile(uf,buf,size_buf);
436
+ if (err<0)
437
+ {
438
+ printf("error %d with zipfile in unzReadCurrentFile\n",err);
439
+ break;
440
+ }
441
+ if (err>0)
442
+ if (fwrite(buf,err,1,fout)!=1)
443
+ {
444
+ printf("error in writing extracted file\n");
445
+ err=UNZ_ERRNO;
446
+ break;
447
+ }
448
+ }
449
+ while (err>0);
450
+ if (fout)
451
+ fclose(fout);
452
+
453
+ if (err==0)
454
+ change_file_date(write_filename,file_info.dosDate,
455
+ file_info.tmu_date);
456
+ }
457
+
458
+ if (err==UNZ_OK)
459
+ {
460
+ err = unzCloseCurrentFile (uf);
461
+ if (err!=UNZ_OK)
462
+ {
463
+ printf("error %d with zipfile in unzCloseCurrentFile\n",err);
464
+ }
465
+ }
466
+ else
467
+ unzCloseCurrentFile(uf); /* don't lose the error */
468
+ }
469
+
470
+ free(buf);
471
+ return err;
472
+ }
473
+
474
+
475
+ int do_extract(uf,opt_extract_without_path,opt_overwrite,password)
476
+ unzFile uf;
477
+ int opt_extract_without_path;
478
+ int opt_overwrite;
479
+ const char* password;
480
+ {
481
+ uLong i;
482
+ unz_global_info64 gi;
483
+ int err;
484
+ FILE* fout=NULL;
485
+
486
+ err = unzGetGlobalInfo64(uf,&gi);
487
+ if (err!=UNZ_OK)
488
+ printf("error %d with zipfile in unzGetGlobalInfo \n",err);
489
+
490
+ for (i=0;i<gi.number_entry;i++)
491
+ {
492
+ if (do_extract_currentfile(uf,&opt_extract_without_path,
493
+ &opt_overwrite,
494
+ password) != UNZ_OK)
495
+ break;
496
+
497
+ if ((i+1)<gi.number_entry)
498
+ {
499
+ err = unzGoToNextFile(uf);
500
+ if (err!=UNZ_OK)
501
+ {
502
+ printf("error %d with zipfile in unzGoToNextFile\n",err);
503
+ break;
504
+ }
505
+ }
506
+ }
507
+
508
+ return 0;
509
+ }
510
+
511
+ int do_extract_onefile(uf,filename,opt_extract_without_path,opt_overwrite,password)
512
+ unzFile uf;
513
+ const char* filename;
514
+ int opt_extract_without_path;
515
+ int opt_overwrite;
516
+ const char* password;
517
+ {
518
+ int err = UNZ_OK;
519
+ if (unzLocateFile(uf,filename,CASESENSITIVITY)!=UNZ_OK)
520
+ {
521
+ printf("file %s not found in the zipfile\n",filename);
522
+ return 2;
523
+ }
524
+
525
+ if (do_extract_currentfile(uf,&opt_extract_without_path,
526
+ &opt_overwrite,
527
+ password) == UNZ_OK)
528
+ return 0;
529
+ else
530
+ return 1;
531
+ }
532
+
533
+
534
+ int main(argc,argv)
535
+ int argc;
536
+ char *argv[];
537
+ {
538
+ const char *zipfilename=NULL;
539
+ const char *filename_to_extract=NULL;
540
+ const char *password=NULL;
541
+ char filename_try[MAXFILENAME+16] = "";
542
+ int i;
543
+ int ret_value=0;
544
+ int opt_do_list=0;
545
+ int opt_do_extract=1;
546
+ int opt_do_extract_withoutpath=0;
547
+ int opt_overwrite=0;
548
+ int opt_extractdir=0;
549
+ const char *dirname=NULL;
550
+ unzFile uf=NULL;
551
+
552
+ do_banner();
553
+ if (argc==1)
554
+ {
555
+ do_help();
556
+ return 0;
557
+ }
558
+ else
559
+ {
560
+ for (i=1;i<argc;i++)
561
+ {
562
+ if ((*argv[i])=='-')
563
+ {
564
+ const char *p=argv[i]+1;
565
+
566
+ while ((*p)!='\0')
567
+ {
568
+ char c=*(p++);;
569
+ if ((c=='l') || (c=='L'))
570
+ opt_do_list = 1;
571
+ if ((c=='v') || (c=='V'))
572
+ opt_do_list = 1;
573
+ if ((c=='x') || (c=='X'))
574
+ opt_do_extract = 1;
575
+ if ((c=='e') || (c=='E'))
576
+ opt_do_extract = opt_do_extract_withoutpath = 1;
577
+ if ((c=='o') || (c=='O'))
578
+ opt_overwrite=1;
579
+ if ((c=='d') || (c=='D'))
580
+ {
581
+ opt_extractdir=1;
582
+ dirname=argv[i+1];
583
+ }
584
+
585
+ if (((c=='p') || (c=='P')) && (i+1<argc))
586
+ {
587
+ password=argv[i+1];
588
+ i++;
589
+ }
590
+ }
591
+ }
592
+ else
593
+ {
594
+ if (zipfilename == NULL)
595
+ zipfilename = argv[i];
596
+ else if ((filename_to_extract==NULL) && (!opt_extractdir))
597
+ filename_to_extract = argv[i] ;
598
+ }
599
+ }
600
+ }
601
+
602
+ if (zipfilename!=NULL)
603
+ {
604
+
605
+ # ifdef USEWIN32IOAPI
606
+ zlib_filefunc64_def ffunc;
607
+ # endif
608
+
609
+ strncpy(filename_try, zipfilename,MAXFILENAME-1);
610
+ /* strncpy doesnt append the trailing NULL, of the string is too long. */
611
+ filename_try[ MAXFILENAME ] = '\0';
612
+
613
+ # ifdef USEWIN32IOAPI
614
+ fill_win32_filefunc64A(&ffunc);
615
+ uf = unzOpen2_64(zipfilename,&ffunc);
616
+ # else
617
+ uf = unzOpen64(zipfilename);
618
+ # endif
619
+ if (uf==NULL)
620
+ {
621
+ strcat(filename_try,".zip");
622
+ # ifdef USEWIN32IOAPI
623
+ uf = unzOpen2_64(filename_try,&ffunc);
624
+ # else
625
+ uf = unzOpen64(filename_try);
626
+ # endif
627
+ }
628
+ }
629
+
630
+ if (uf==NULL)
631
+ {
632
+ printf("Cannot open %s or %s.zip\n",zipfilename,zipfilename);
633
+ return 1;
634
+ }
635
+ printf("%s opened\n",filename_try);
636
+
637
+ if (opt_do_list==1)
638
+ ret_value = do_list(uf);
639
+ else if (opt_do_extract==1)
640
+ {
641
+ #ifdef _WIN32
642
+ if (opt_extractdir && _chdir(dirname))
643
+ #else
644
+ if (opt_extractdir && chdir(dirname))
645
+ #endif
646
+ {
647
+ printf("Error changing into %s, aborting\n", dirname);
648
+ exit(-1);
649
+ }
650
+
651
+ if (filename_to_extract == NULL)
652
+ ret_value = do_extract(uf, opt_do_extract_withoutpath, opt_overwrite, password);
653
+ else
654
+ ret_value = do_extract_onefile(uf, filename_to_extract, opt_do_extract_withoutpath, opt_overwrite, password);
655
+ }
656
+
657
+ unzClose(uf);
658
+
659
+ return ret_value;
660
+ }