Merge lp:~zorba-coders/zorba/archive-module-winfixes into lp:zorba/archive-module
- archive-module-winfixes
- Merge into archive-module
Status: | Superseded |
---|---|
Proposed branch: | lp:~zorba-coders/zorba/archive-module-winfixes |
Merge into: | lp:zorba/archive-module |
Diff against target: |
1110 lines (+540/-437) 4 files modified
src/archive_module.xq.src/archive_module.cpp (+25/-54) src/archive_module.xq.src/archive_module.h (+2/-2) src/archive_module.xq.src/strncasecmp.h (+68/-0) src/archive_module.xq.src/strptime.h (+445/-381) |
To merge this branch: | bzr merge lp:~zorba-coders/zorba/archive-module-winfixes |
Related bugs: |
Reviewer | Review Type | Date Requested | Status |
---|---|---|---|
Luis Rodriguez Gonzalez | Pending | ||
Matthias Brantner | Pending | ||
Review via email: mp+118010@code.launchpad.net |
This proposal has been superseded by a proposal from 2012-08-20.
Commit message
*Changed the strptime for an Apache licensed one.
*Fixed the comment of the setValues(struct archive_entry* aEntry) and added the size, removed the comment.
*Fixed the Windows Warnings messages.
*Replaced tabs for 2 spaces.
Description of the change
Chris Hillery (ceejatec) wrote : | # |
Zorba Build Bot (zorba-buildbot) wrote : | # |
Validation queue starting for merge proposal.
Log at: http://
Zorba Build Bot (zorba-buildbot) wrote : | # |
The attempt to merge lp:~zorba-coders/zorba/archive-module-winfixes into lp:zorba/archive-module failed. Below is the output from the failed tests.
CMake Error at /home/ceej/
Validation queue job archive-
finished. The final status was:
No tests were run - build or configure step must have failed.
Not commiting changes.
Error in read script: /home/ceej/
Chris Hillery (ceejatec) wrote : | # |
Ah, right, I still need to install a newer version of libarchive on the queue machine. Sorry.
Zorba Build Bot (zorba-buildbot) wrote : | # |
Validation queue starting for merge proposal.
Log at: http://
Zorba Build Bot (zorba-buildbot) wrote : | # |
The attempt to merge lp:~zorba-coders/zorba/archive-module-winfixes into lp:zorba/archive-module failed. Below is the output from the failed tests.
CMake Error at /home/ceej/
Validation queue job archive-
finished. The final status was:
No tests were run - build or configure step must have failed.
Not commiting changes.
Error in read script: /home/ceej/
Matthias Brantner (matthias-brantner) wrote : | # |
The following code could be factorized.
174 if(lSize > INT_MAX)
175 + lResult.
176 + else
177 + lResult.
- 43. By Matthias Brantner
-
- don't require bz2 on windows
- create last-modified attributes adjusting to UTC timezone Approved: Luis Rodriguez Gonzalez, Chris Hillery - 44. By [u'William Candillon <william.candillon@28msec.com>']
-
Minor documentation improvement. Approved: Matthias Brantner, William Candillon
- 45. By [u'luisrod <luisrod@LUISROD-LAP>']
-
- Added ability to create directories in archives
- Added testcases Approved: Matthias Brantner, Juan Zacarias - 46. By Luis Rodriguez Gonzalez
-
-Replaced open functions with old ones to make it work with Macports
- 47. By Luis Rodriguez Gonzalez
-
branch updated
Unmerged revisions
Preview Diff
1 | === modified file 'src/archive_module.xq.src/archive_module.cpp' |
2 | --- src/archive_module.xq.src/archive_module.cpp 2012-08-01 20:47:46 +0000 |
3 | +++ src/archive_module.xq.src/archive_module.cpp 2012-08-02 22:50:22 +0000 |
4 | @@ -189,14 +189,13 @@ |
5 | |
6 | if (archive_entry_size_is_set(aEntry)) |
7 | { |
8 | - //add a size variable |
9 | + theSize = archive_entry_size(aEntry); |
10 | } |
11 | |
12 | if (archive_entry_mtime_is_set(aEntry)) |
13 | { |
14 | theLastModified = archive_entry_mtime(aEntry); |
15 | } |
16 | - //check if it is encoded |
17 | } |
18 | |
19 | void |
20 | @@ -631,7 +630,7 @@ |
21 | while (lStream->good()) |
22 | { |
23 | lStream->read(lBuf, ZORBA_ARCHIVE_MAX_READ_BUF); |
24 | - archive_write_data(theArchive, lBuf, lStream->gcount()); |
25 | + archive_write_data(theArchive, lBuf, (size_t)lStream->gcount()); |
26 | } |
27 | |
28 | archive_entry_clear(theEntry); |
29 | @@ -647,8 +646,8 @@ |
30 | void |
31 | ArchiveFunction::ArchiveCompressor::close() |
32 | { |
33 | - archive_write_close(theArchive); |
34 | - archive_write_finish(theArchive); |
35 | + archive_write_close(theArchive); |
36 | + archive_write_finish(theArchive); |
37 | } |
38 | |
39 | std::stringstream* |
40 | @@ -847,7 +846,7 @@ |
41 | // remember the stream pos before leaving the function |
42 | if (lData->theSeekable) lData->thePos = lStream->tellg(); |
43 | |
44 | - return lStream->gcount(); |
45 | + return (long)lStream->gcount(); |
46 | } |
47 | |
48 | ArchiveItemSequence::ArchiveIterator::ArchiveIterator(zorba::Item& a) |
49 | @@ -866,10 +865,10 @@ |
50 | ArchiveFunction::throwError( |
51 | "ARCH9999", "internal error (couldn't create archive)"); |
52 | |
53 | - int lErr = archive_read_support_compression_all(theArchive); |
54 | + int lErr = archive_read_support_compression_all(theArchive); |
55 | ArchiveFunction::checkForError(lErr, 0, theArchive); |
56 | |
57 | - archive_read_support_format_all(theArchive); |
58 | + archive_read_support_format_all(theArchive); |
59 | ArchiveFunction::checkForError(lErr, 0, theArchive); |
60 | |
61 | if (theArchiveItem.isStreamable()) |
62 | @@ -885,7 +884,7 @@ |
63 | base64::attach(*theData.theStream); |
64 | } |
65 | |
66 | - lErr = archive_read_open( |
67 | + lErr = archive_read_open( |
68 | theArchive, &theData, 0, ArchiveItemSequence::readStream, 0); |
69 | |
70 | ArchiveFunction::checkForError(lErr, 0, theArchive); |
71 | @@ -1178,33 +1177,16 @@ |
72 | if (!lEntry) |
73 | return false; |
74 | |
75 | - /*while (true) |
76 | - { |
77 | - int lErr = archive_read_next_header(theArchive, &lEntry); |
78 | - |
79 | - if (lErr == ARCHIVE_EOF) return false; |
80 | - |
81 | - if (lErr != ARCHIVE_OK) |
82 | - { |
83 | - ArchiveFunction::checkForError(lErr, 0, theArchive); |
84 | - } |
85 | - |
86 | - if (theReturnAll) break; |
87 | - |
88 | - String lName = archive_entry_pathname(lEntry); |
89 | - if (theEntryNames.find(lName) != theEntryNames.end()) |
90 | - { |
91 | - break; |
92 | - } |
93 | - }*/ |
94 | - |
95 | String lResult; |
96 | |
97 | // reserve some space if we know the decompressed size |
98 | if (archive_entry_size_is_set(lEntry)) |
99 | { |
100 | long long lSize = archive_entry_size(lEntry); |
101 | - lResult.reserve(lSize); |
102 | + if (lSize > INT_MAX) |
103 | + lResult.reserve(INT_MAX); |
104 | + else |
105 | + lResult.reserve((int)lSize); |
106 | } |
107 | |
108 | char lBuf[ZORBA_ARCHIVE_MAX_READ_BUF]; |
109 | @@ -1231,7 +1213,7 @@ |
110 | while (lTranscoder.good()) |
111 | { |
112 | lTranscoder.read(buf, 1024); |
113 | - lTranscodedString.append(buf, lTranscoder.gcount()); |
114 | + lTranscodedString.append(buf, (zorba::String::size_type)lTranscoder.gcount()); |
115 | } |
116 | aRes = theFactory->createString(lTranscodedString); |
117 | } |
118 | @@ -1288,26 +1270,6 @@ |
119 | //NULL is EOF |
120 | if (!lEntry) |
121 | return false; |
122 | - |
123 | - /*while (true) |
124 | - { |
125 | - int lErr = archive_read_next_header(theArchive, &lEntry); |
126 | - |
127 | - if (lErr == ARCHIVE_EOF) return false; |
128 | - |
129 | - if (lErr != ARCHIVE_OK) |
130 | - { |
131 | - ArchiveFunction::checkForError(lErr, 0, theArchive); |
132 | - } |
133 | - |
134 | - if (theReturnAll) break; |
135 | - |
136 | - String lName = archive_entry_pathname(lEntry); |
137 | - if (theEntryNames.find(lName) != theEntryNames.end()) |
138 | - { |
139 | - break; |
140 | - } |
141 | - }*/ |
142 | |
143 | std::vector<unsigned char> lResult; |
144 | |
145 | @@ -1315,7 +1277,10 @@ |
146 | if (archive_entry_size_is_set(lEntry)) |
147 | { |
148 | long long lSize = archive_entry_size(lEntry); |
149 | - lResult.reserve(lSize); |
150 | + if(lSize > INT_MAX) |
151 | + lResult.reserve(INT_MAX); |
152 | + else |
153 | + lResult.reserve((int)lSize); |
154 | } |
155 | |
156 | std::vector<unsigned char> lBuf; |
157 | @@ -1431,7 +1396,10 @@ |
158 | if (archive_entry_size_is_set(lEntry)) |
159 | { |
160 | long long lSize = archive_entry_size(lEntry); |
161 | - lResult.reserve(lSize); |
162 | + if(lSize > INT_MAX) |
163 | + lResult.reserve(INT_MAX); |
164 | + else |
165 | + lResult.reserve((int)lSize); |
166 | } |
167 | |
168 | std::vector<unsigned char> lBuf; |
169 | @@ -1610,7 +1578,10 @@ |
170 | if (archive_entry_size_is_set(lEntry)) |
171 | { |
172 | long long lSize = archive_entry_size(lEntry); |
173 | - lResult.reserve(lSize); |
174 | + if(lSize > INT_MAX) |
175 | + lResult.reserve(INT_MAX); |
176 | + else |
177 | + lResult.reserve((int)lSize); |
178 | } |
179 | |
180 | std::vector<unsigned char> lBuf; |
181 | |
182 | === modified file 'src/archive_module.xq.src/archive_module.h' |
183 | --- src/archive_module.xq.src/archive_module.h 2012-08-01 20:47:46 +0000 |
184 | +++ src/archive_module.xq.src/archive_module.h 2012-08-02 22:50:22 +0000 |
185 | @@ -199,7 +199,7 @@ |
186 | protected: |
187 | String theEntryPath; |
188 | String theEncoding; |
189 | - int theSize; |
190 | + long long theSize; |
191 | time_t theLastModified; |
192 | String theCompression; |
193 | bool theSkipExtras; |
194 | @@ -211,7 +211,7 @@ |
195 | |
196 | const String& getEncoding() const { return theEncoding; } |
197 | |
198 | - int getSize() const { return theSize; } |
199 | + long long getSize() const { return theSize; } |
200 | |
201 | const time_t& getLastModified() const { return theLastModified; } |
202 | |
203 | |
204 | === added file 'src/archive_module.xq.src/strncasecmp.h' |
205 | --- src/archive_module.xq.src/strncasecmp.h 1970-01-01 00:00:00 +0000 |
206 | +++ src/archive_module.xq.src/strncasecmp.h 2012-08-02 22:50:22 +0000 |
207 | @@ -0,0 +1,68 @@ |
208 | +/* |
209 | + * Copyright (c) 1998 Kungliga Tekniska Högskolan |
210 | + * (Royal Institute of Technology, Stockholm, Sweden). |
211 | + * All rights reserved. |
212 | + * |
213 | + * Redistribution and use in source and binary forms, with or without |
214 | + * modification, are permitted provided that the following conditions |
215 | + * are met: |
216 | + * |
217 | + * 1. Redistributions of source code must retain the above copyright |
218 | + * notice, this list of conditions and the following disclaimer. |
219 | + * |
220 | + * 2. Redistributions in binary form must reproduce the above copyright |
221 | + * notice, this list of conditions and the following disclaimer in the |
222 | + * documentation and/or other materials provided with the distribution. |
223 | + * |
224 | + * 3. Neither the name of the Institute nor the names of its contributors |
225 | + * may be used to endorse or promote products derived from this software |
226 | + * without specific prior written permission. |
227 | + * |
228 | + * THIS SOFTWARE IS PROVIDED BY THE INSTITUTE AND CONTRIBUTORS ``AS IS'' AND |
229 | + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE |
230 | + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE |
231 | + * ARE DISCLAIMED. IN NO EVENT SHALL THE INSTITUTE OR CONTRIBUTORS BE LIABLE |
232 | + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL |
233 | + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS |
234 | + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) |
235 | + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT |
236 | + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY |
237 | + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF |
238 | + * SUCH DAMAGE. |
239 | + */ |
240 | + |
241 | +#ifdef WIN32 |
242 | + |
243 | +#include <string.h> |
244 | +#include <ctype.h> |
245 | +#include <stddef.h> |
246 | + |
247 | +int strcasecmp(const char *s1, const char *s2) |
248 | +{ |
249 | + const unsigned char *us1 = (const unsigned char *)s1, *us2 = (const unsigned char *)s2; |
250 | + |
251 | + while (tolower(*us1) == tolower(*us2)) { |
252 | + if (*us1++ == '\0') |
253 | + return (0); |
254 | + us2++; |
255 | + } |
256 | + return (tolower(*us1) - tolower(*us2)); |
257 | +} |
258 | + |
259 | +int strncasecmp(const char *s1, const char *s2, size_t n) |
260 | +{ |
261 | + while(n > 0 |
262 | + && toupper((unsigned char)*s1) == toupper((unsigned char)*s2)) |
263 | + { |
264 | + if(*s1 == '\0') |
265 | + return 0; |
266 | + s1++; |
267 | + s2++; |
268 | + n--; |
269 | + } |
270 | + if(n == 0) |
271 | + return 0; |
272 | + return toupper((unsigned char)*s1) - toupper((unsigned char)*s2); |
273 | +} |
274 | + |
275 | +#endif /* WIN32 */ |
276 | |
277 | === modified file 'src/archive_module.xq.src/strptime.h' |
278 | --- src/archive_module.xq.src/strptime.h 2012-07-02 17:14:21 +0000 |
279 | +++ src/archive_module.xq.src/strptime.h 2012-08-02 22:50:22 +0000 |
280 | @@ -1,384 +1,448 @@ |
281 | +/* |
282 | + * Copyright (c) 1999 Kungliga Tekniska H?gskolan |
283 | + * (Royal Institute of Technology, Stockholm, Sweden). |
284 | + * All rights reserved. |
285 | + * |
286 | + * Redistribution and use in source and binary forms, with or without |
287 | + * modification, are permitted provided that the following conditions |
288 | + * are met: |
289 | + * |
290 | + * 1. Redistributions of source code must retain the above copyright |
291 | + * notice, this list of conditions and the following disclaimer. |
292 | + * |
293 | + * 2. Redistributions in binary form must reproduce the above copyright |
294 | + * notice, this list of conditions and the following disclaimer in the |
295 | + * documentation and/or other materials provided with the distribution. |
296 | + * |
297 | + * 3. Neither the name of KTH nor the names of its contributors may be |
298 | + * used to endorse or promote products derived from this software without |
299 | + * specific prior written permission. |
300 | + * |
301 | + * THIS SOFTWARE IS PROVIDED BY KTH AND ITS CONTRIBUTORS ``AS IS'' AND ANY |
302 | + * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE |
303 | + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR |
304 | + * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL KTH OR ITS CONTRIBUTORS BE |
305 | + * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR |
306 | + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF |
307 | + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR |
308 | + * BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, |
309 | + * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR |
310 | + * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF |
311 | + * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ |
312 | + |
313 | +#ifdef WIN32 |
314 | + |
315 | + |
316 | #include <ctype.h> |
317 | #include <string.h> |
318 | -#include <time.h> |
319 | - |
320 | - |
321 | -/* |
322 | - * We do not implement alternate representations. However, we always |
323 | - * check whether a given modifier is allowed for a certain conversion. |
324 | - */ |
325 | -#define ALT_E 0x01 |
326 | -#define ALT_O 0x02 |
327 | -//#define LEGAL_ALT(x) { if (alt_format & ~(x)) return (0); } |
328 | -#define LEGAL_ALT(x) { ; } |
329 | -#define TM_YEAR_BASE (1970) |
330 | - |
331 | -static int conv_num(const char **, int *, int, int); |
332 | -static int strncasecmp(char *s1, char *s2, size_t n); |
333 | - |
334 | -static const char *day[7] = { |
335 | - "Sunday", "Monday", "Tuesday", "Wednesday", "Thursday", |
336 | - "Friday", "Saturday" |
337 | -}; |
338 | -static const char *abday[7] = { |
339 | - "Sun","Mon","Tue","Wed","Thu","Fri","Sat" |
340 | -}; |
341 | -static const char *mon[12] = { |
342 | - "January", "February", "March", "April", "May", "June", "July", |
343 | - "August", "September", "October", "November", "December" |
344 | -}; |
345 | -static const char *abmon[12] = { |
346 | - "Jan", "Feb", "Mar", "Apr", "May", "Jun", |
347 | - "Jul", "Aug", "Sep", "Oct", "Nov", "Dec" |
348 | -}; |
349 | -static const char *am_pm[2] = { |
350 | - "AM", "PM" |
351 | -}; |
352 | - |
353 | - |
354 | -char * strptime(const char *buf, const char *fmt, struct tm *tm) |
355 | -{ |
356 | - char c; |
357 | - const char *bp; |
358 | - size_t len = 0; |
359 | - int alt_format, i, split_year = 0; |
360 | - |
361 | - bp = buf; |
362 | - |
363 | - while ((c = *fmt) != '\0') |
364 | - { |
365 | - /* Clear `alternate' modifier prior to new conversion. */ |
366 | - alt_format = 0; |
367 | - |
368 | - /* Eat up white-space. */ |
369 | - if (isspace(c)) |
370 | - { |
371 | - while (isspace(*bp)) |
372 | - bp++; |
373 | - |
374 | - fmt++; |
375 | - continue; |
376 | - } |
377 | - |
378 | - if ((c = *fmt++) != '%') |
379 | - goto literal; |
380 | - |
381 | - |
382 | -again: switch (c = *fmt++) |
383 | - { |
384 | - case '%': /* "%%" is converted to "%". */ |
385 | - literal: |
386 | - if (c != *bp++) |
387 | - return (0); |
388 | - break; |
389 | - |
390 | - /* |
391 | - * "Alternative" modifiers. Just set the appropriate flag |
392 | - * and start over again. |
393 | - */ |
394 | - case 'E': /* "%E?" alternative conversion modifier. */ |
395 | - LEGAL_ALT(0); |
396 | - alt_format |= ALT_E; |
397 | - goto again; |
398 | - |
399 | - case 'O': /* "%O?" alternative conversion modifier. */ |
400 | - LEGAL_ALT(0); |
401 | - alt_format |= ALT_O; |
402 | - goto again; |
403 | - |
404 | - /* |
405 | - * "Complex" conversion rules, implemented through recursion. |
406 | - */ |
407 | - case 'c': /* Date and time, using the locale's format. */ |
408 | - LEGAL_ALT(ALT_E); |
409 | - if (!(bp = strptime(bp, "%x %X", tm))) |
410 | - return (0); |
411 | - break; |
412 | - |
413 | - case 'D': /* The date as "%m/%d/%y". */ |
414 | - LEGAL_ALT(0); |
415 | - if (!(bp = strptime(bp, "%m/%d/%y", tm))) |
416 | - return (0); |
417 | - break; |
418 | - |
419 | - case 'R': /* The time as "%H:%M". */ |
420 | - LEGAL_ALT(0); |
421 | - if (!(bp = strptime(bp, "%H:%M", tm))) |
422 | - return (0); |
423 | - break; |
424 | - |
425 | - case 'r': /* The time in 12-hour clock representation. */ |
426 | - LEGAL_ALT(0); |
427 | - if (!(bp = strptime(bp, "%I:%M:%S %p", tm))) |
428 | - return (0); |
429 | - break; |
430 | - |
431 | - case 'T': /* The time as "%H:%M:%S". */ |
432 | - LEGAL_ALT(0); |
433 | - if (!(bp = strptime(bp, "%H:%M:%S", tm))) |
434 | - return (0); |
435 | - break; |
436 | - |
437 | - case 'X': /* The time, using the locale's format. */ |
438 | - LEGAL_ALT(ALT_E); |
439 | - if (!(bp = strptime(bp, "%H:%M:%S", tm))) |
440 | - return (0); |
441 | - break; |
442 | - |
443 | - case 'x': /* The date, using the locale's format. */ |
444 | - LEGAL_ALT(ALT_E); |
445 | - if (!(bp = strptime(bp, "%m/%d/%y", tm))) |
446 | - return (0); |
447 | - break; |
448 | - |
449 | - /* |
450 | - * "Elementary" conversion rules. |
451 | - */ |
452 | - case 'A': /* The day of week, using the locale's form. */ |
453 | - case 'a': |
454 | - LEGAL_ALT(0); |
455 | - for (i = 0; i < 7; i++) |
456 | - { |
457 | - /* Full name. */ |
458 | - len = strlen(day[i]); |
459 | - if (strncasecmp((char *)(day[i]), (char *)bp, len) == 0) |
460 | - break; |
461 | - |
462 | - /* Abbreviated name. */ |
463 | - len = strlen(abday[i]); |
464 | - if (strncasecmp((char *)(abday[i]), (char *)bp, len) == 0) |
465 | - break; |
466 | - } |
467 | - |
468 | - /* Nothing matched. */ |
469 | - if (i == 7) |
470 | - return (0); |
471 | - |
472 | - tm->tm_wday = i; |
473 | - bp += len; |
474 | - break; |
475 | - |
476 | - case 'B': /* The month, using the locale's form. */ |
477 | - case 'b': |
478 | - case 'h': |
479 | - LEGAL_ALT(0); |
480 | - for (i = 0; i < 12; i++) |
481 | - { |
482 | - /* Full name. */ |
483 | - |
484 | - len = strlen(mon[i]); |
485 | - if (strncasecmp((char *)(mon[i]), (char *)bp, len) == 0) |
486 | - break; |
487 | - |
488 | - /* Abbreviated name. */ |
489 | - len = strlen(abmon[i]); |
490 | - if (strncasecmp((char *)(abmon[i]),(char *) bp, len) == 0) |
491 | - break; |
492 | - } |
493 | - |
494 | - /* Nothing matched. */ |
495 | - if (i == 12) |
496 | - return (0); |
497 | - |
498 | - tm->tm_mon = i; |
499 | - bp += len; |
500 | - break; |
501 | - |
502 | - case 'C': /* The century number. */ |
503 | - LEGAL_ALT(ALT_E); |
504 | - if (!(conv_num(&bp, &i, 0, 99))) |
505 | - return (0); |
506 | - |
507 | - if (split_year) |
508 | - { |
509 | - tm->tm_year = (tm->tm_year % 100) + (i * 100); |
510 | - } else { |
511 | - tm->tm_year = i * 100; |
512 | - split_year = 1; |
513 | - } |
514 | - break; |
515 | - |
516 | - case 'd': /* The day of month. */ |
517 | - case 'e': |
518 | - LEGAL_ALT(ALT_O); |
519 | - if (!(conv_num(&bp, &tm->tm_mday, 1, 31))) |
520 | - return (0); |
521 | - break; |
522 | - |
523 | - case 'k': /* The hour (24-hour clock representation). */ |
524 | - LEGAL_ALT(0); |
525 | - /* FALLTHROUGH */ |
526 | - case 'H': |
527 | - LEGAL_ALT(ALT_O); |
528 | - if (!(conv_num(&bp, &tm->tm_hour, 0, 23))) |
529 | - return (0); |
530 | - break; |
531 | - |
532 | - case 'l': /* The hour (12-hour clock representation). */ |
533 | - LEGAL_ALT(0); |
534 | - /* FALLTHROUGH */ |
535 | - case 'I': |
536 | - LEGAL_ALT(ALT_O); |
537 | - if (!(conv_num(&bp, &tm->tm_hour, 1, 12))) |
538 | - return (0); |
539 | - if (tm->tm_hour == 12) |
540 | - tm->tm_hour = 0; |
541 | - break; |
542 | - |
543 | - case 'j': /* The day of year. */ |
544 | - LEGAL_ALT(0); |
545 | - if (!(conv_num(&bp, &i, 1, 366))) |
546 | - return (0); |
547 | - tm->tm_yday = i - 1; |
548 | - break; |
549 | - |
550 | - case 'M': /* The minute. */ |
551 | - LEGAL_ALT(ALT_O); |
552 | - if (!(conv_num(&bp, &tm->tm_min, 0, 59))) |
553 | - return (0); |
554 | - break; |
555 | - |
556 | - case 'm': /* The month. */ |
557 | - LEGAL_ALT(ALT_O); |
558 | - if (!(conv_num(&bp, &i, 1, 12))) |
559 | - return (0); |
560 | - tm->tm_mon = i - 1; |
561 | - break; |
562 | - |
563 | -// case 'p': /* The locale's equivalent of AM/PM. */ |
564 | -// LEGAL_ALT(0); |
565 | -// /* AM? */ |
566 | -// if (strcasecmp(am_pm[0], bp) == 0) |
567 | -// { |
568 | -// if (tm->tm_hour > 11) |
569 | -// return (0); |
570 | -// |
571 | -// bp += strlen(am_pm[0]); |
572 | -// break; |
573 | -// } |
574 | -// /* PM? */ |
575 | -// else if (strcasecmp(am_pm[1], bp) == 0) |
576 | -// { |
577 | -// if (tm->tm_hour > 11) |
578 | -// return (0); |
579 | -// |
580 | -// tm->tm_hour += 12; |
581 | -// bp += strlen(am_pm[1]); |
582 | -// break; |
583 | -// } |
584 | -// |
585 | -// /* Nothing matched. */ |
586 | -// return (0); |
587 | - |
588 | - case 'S': /* The seconds. */ |
589 | - LEGAL_ALT(ALT_O); |
590 | - if (!(conv_num(&bp, &tm->tm_sec, 0, 61))) |
591 | - return (0); |
592 | - break; |
593 | - |
594 | - case 'U': /* The week of year, beginning on sunday. */ |
595 | - case 'W': /* The week of year, beginning on monday. */ |
596 | - LEGAL_ALT(ALT_O); |
597 | - /* |
598 | - * XXX This is bogus, as we can not assume any valid |
599 | - * information present in the tm structure at this |
600 | - * point to calculate a real value, so just check the |
601 | - * range for now. |
602 | - */ |
603 | - if (!(conv_num(&bp, &i, 0, 53))) |
604 | - return (0); |
605 | - break; |
606 | - |
607 | - case 'w': /* The day of week, beginning on sunday. */ |
608 | - LEGAL_ALT(ALT_O); |
609 | - if (!(conv_num(&bp, &tm->tm_wday, 0, 6))) |
610 | - return (0); |
611 | - break; |
612 | - |
613 | - case 'Y': /* The year. */ |
614 | - LEGAL_ALT(ALT_E); |
615 | - if (!(conv_num(&bp, &i, 0, 9999))) |
616 | - return (0); |
617 | - |
618 | - tm->tm_year = i - TM_YEAR_BASE; |
619 | - break; |
620 | - |
621 | - case 'y': /* The year within 100 years of the epoch. */ |
622 | - LEGAL_ALT(ALT_E | ALT_O); |
623 | - if (!(conv_num(&bp, &i, 0, 99))) |
624 | - return (0); |
625 | - |
626 | - if (split_year) |
627 | - { |
628 | - tm->tm_year = ((tm->tm_year / 100) * 100) + i; |
629 | - break; |
630 | - } |
631 | - split_year = 1; |
632 | - if (i <= 68) |
633 | - tm->tm_year = i + 2000 - TM_YEAR_BASE; |
634 | - else |
635 | - tm->tm_year = i + 1900 - TM_YEAR_BASE; |
636 | - break; |
637 | - |
638 | - /* |
639 | - * Miscellaneous conversions. |
640 | - */ |
641 | - case 'n': /* Any kind of white-space. */ |
642 | - case 't': |
643 | - LEGAL_ALT(0); |
644 | - while (isspace(*bp)) |
645 | - bp++; |
646 | - break; |
647 | - |
648 | - |
649 | - default: /* Unknown/unsupported conversion. */ |
650 | - return (0); |
651 | - } |
652 | - |
653 | - |
654 | - } |
655 | - |
656 | - /* LINTED functional specification */ |
657 | - return ((char *)bp); |
658 | -} |
659 | - |
660 | - |
661 | -static int conv_num(const char **buf, int *dest, int llim, int ulim) |
662 | -{ |
663 | - int result = 0; |
664 | - |
665 | - /* The limit also determines the number of valid digits. */ |
666 | - int rulim = ulim; |
667 | - |
668 | - if (**buf < '0' || **buf > '9') |
669 | - return (0); |
670 | - |
671 | - do { |
672 | - result *= 10; |
673 | - result += *(*buf)++ - '0'; |
674 | - rulim /= 10; |
675 | - } while ((result * 10 <= ulim) && rulim && **buf >= '0' && **buf <= '9'); |
676 | - |
677 | - if (result < llim || result > ulim) |
678 | - return (0); |
679 | - |
680 | - *dest = result; |
681 | - return (1); |
682 | -} |
683 | - |
684 | -int strncasecmp(char *s1, char *s2, size_t n) |
685 | -{ |
686 | - if (n == 0) |
687 | - return 0; |
688 | - |
689 | - while (n-- != 0 && tolower(*s1) == tolower(*s2)) |
690 | - { |
691 | - if (n == 0 || *s1 == '\0' || *s2 == '\0') |
692 | - break; |
693 | - s1++; |
694 | - s2++; |
695 | - } |
696 | - |
697 | - return tolower(*(unsigned char *) s1) - tolower(*(unsigned char *) s2); |
698 | -} |
699 | +#include <time.h> |
700 | +#include "strncasecmp.h" |
701 | + |
702 | + |
703 | +static const char *abb_weekdays[] = { |
704 | + "Sun", |
705 | + "Mon", |
706 | + "Tue", |
707 | + "Wed", |
708 | + "Thu", |
709 | + "Fri", |
710 | + "Sat", |
711 | + NULL |
712 | +}; |
713 | + |
714 | +static const char *full_weekdays[] = { |
715 | + "Sunday", |
716 | + "Monday", |
717 | + "Tuesday", |
718 | + "Wednesday", |
719 | + "Thursday", |
720 | + "Friday", |
721 | + "Saturday", |
722 | + NULL |
723 | +}; |
724 | + |
725 | +static const char *abb_month[] = { |
726 | + "Jan", |
727 | + "Feb", |
728 | + "Mar", |
729 | + "Apr", |
730 | + "May", |
731 | + "Jun", |
732 | + "Jul", |
733 | + "Aug", |
734 | + "Sep", |
735 | + "Oct", |
736 | + "Nov", |
737 | + "Dec", |
738 | + NULL |
739 | +}; |
740 | + |
741 | +static const char *full_month[] = { |
742 | + "January", |
743 | + "February", |
744 | + "Mars", |
745 | + "April", |
746 | + "May", |
747 | + "June", |
748 | + "July", |
749 | + "August", |
750 | + "September", |
751 | + "October", |
752 | + "November", |
753 | + "December", |
754 | + NULL, |
755 | +}; |
756 | + |
757 | +static const char *ampm[] = { |
758 | + "am", |
759 | + "pm", |
760 | + NULL |
761 | +}; |
762 | + |
763 | +/* |
764 | + * Try to match `*buf' to one of the strings in `strs'. Return the |
765 | + * index of the matching string (or -1 if none). Also advance buf. |
766 | + */ |
767 | + |
768 | +static int |
769 | +match_string (const char **buf, const char **strs) |
770 | +{ |
771 | + int i = 0; |
772 | + |
773 | + for (i = 0; strs[i] != NULL; ++i) { |
774 | + int len = strlen (strs[i]); |
775 | + |
776 | + if (strncasecmp (*buf, strs[i], len) == 0) { |
777 | + *buf += len; |
778 | + return i; |
779 | + } |
780 | + } |
781 | + return -1; |
782 | +} |
783 | + |
784 | +/* |
785 | + * tm_year is relative this year */ |
786 | + |
787 | +const int tm_year_base = 1900; |
788 | + |
789 | +/* |
790 | + * Return TRUE iff `year' was a leap year. |
791 | + */ |
792 | + |
793 | +static int |
794 | +is_leap_year (int year) |
795 | +{ |
796 | + return (year % 4) == 0 && ((year % 100) != 0 || (year % 400) == 0); |
797 | +} |
798 | + |
799 | +/* |
800 | + * Return the weekday [0,6] (0 = Sunday) of the first day of `year' |
801 | + */ |
802 | + |
803 | +static int |
804 | +first_day (int year) |
805 | +{ |
806 | + int ret = 4; |
807 | + |
808 | + for (; year > 1970; --year) |
809 | + ret = (ret + 365 + is_leap_year (year) ? 1 : 0) % 7; |
810 | + return ret; |
811 | +} |
812 | + |
813 | +/* |
814 | + * Set `timeptr' given `wnum' (week number [0, 53]) |
815 | + */ |
816 | + |
817 | +static void |
818 | +set_week_number_sun (struct tm *timeptr, int wnum) |
819 | +{ |
820 | + int fday = first_day (timeptr->tm_year + tm_year_base); |
821 | + |
822 | + timeptr->tm_yday = wnum * 7 + timeptr->tm_wday - fday; |
823 | + if (timeptr->tm_yday < 0) { |
824 | + timeptr->tm_wday = fday; |
825 | + timeptr->tm_yday = 0; |
826 | + } |
827 | +} |
828 | + |
829 | +/* |
830 | + * Set `timeptr' given `wnum' (week number [0, 53]) |
831 | + */ |
832 | + |
833 | +static void |
834 | +set_week_number_mon (struct tm *timeptr, int wnum) |
835 | +{ |
836 | + int fday = (first_day (timeptr->tm_year + tm_year_base) + 6) % 7; |
837 | + |
838 | + timeptr->tm_yday = wnum * 7 + (timeptr->tm_wday + 6) % 7 - fday; |
839 | + if (timeptr->tm_yday < 0) { |
840 | + timeptr->tm_wday = (fday + 1) % 7; |
841 | + timeptr->tm_yday = 0; |
842 | + } |
843 | +} |
844 | + |
845 | +/* |
846 | + * Set `timeptr' given `wnum' (week number [0, 53]) |
847 | + */ |
848 | + |
849 | +static void |
850 | +set_week_number_mon4 (struct tm *timeptr, int wnum) |
851 | +{ |
852 | + int fday = (first_day (timeptr->tm_year + tm_year_base) + 6) % 7; |
853 | + int offset = 0; |
854 | + |
855 | + if (fday < 4) |
856 | + offset += 7; |
857 | + |
858 | + timeptr->tm_yday = offset + (wnum - 1) * 7 + timeptr->tm_wday - fday; |
859 | + if (timeptr->tm_yday < 0) { |
860 | + timeptr->tm_wday = fday; |
861 | + timeptr->tm_yday = 0; |
862 | + } |
863 | +} |
864 | + |
865 | +/* |
866 | + * |
867 | + */ |
868 | + |
869 | +char * |
870 | +strptime (const char *buf, const char *format, struct tm *timeptr) |
871 | +{ |
872 | + char c; |
873 | + |
874 | + for (; (c = *format) != '\0'; ++format) { |
875 | + char *s; |
876 | + int ret; |
877 | + |
878 | + if (isspace (c)) { |
879 | + while (isspace (*buf)) |
880 | + ++buf; |
881 | + } else if (c == '%' && format[1] != '\0') { |
882 | + c = *++format; |
883 | + if (c == 'E' || c == 'O') |
884 | + c = *++format; |
885 | + switch (c) { |
886 | + case 'A' : |
887 | + ret = match_string (&buf, full_weekdays); |
888 | + if (ret < 0) |
889 | + return NULL; |
890 | + timeptr->tm_wday = ret; |
891 | + break; |
892 | + case 'a' : |
893 | + ret = match_string (&buf, abb_weekdays); |
894 | + if (ret < 0) |
895 | + return NULL; |
896 | + timeptr->tm_wday = ret; |
897 | + break; |
898 | + case 'B' : |
899 | + ret = match_string (&buf, full_month); |
900 | + if (ret < 0) |
901 | + return NULL; |
902 | + timeptr->tm_mon = ret; |
903 | + break; |
904 | + case 'b' : |
905 | + case 'h' : |
906 | + ret = match_string (&buf, abb_month); |
907 | + if (ret < 0) |
908 | + return NULL; |
909 | + timeptr->tm_mon = ret; |
910 | + break; |
911 | + case 'C' : |
912 | + ret = strtol (buf, &s, 10); |
913 | + if (s == buf) |
914 | + return NULL; |
915 | + timeptr->tm_year = (ret * 100) - tm_year_base; |
916 | + buf = s; |
917 | + break; |
918 | + case 'c' : |
919 | + abort (); |
920 | + case 'D' : /* %m/%d/%y */ |
921 | + s = strptime (buf, "%m/%d/%y", timeptr); |
922 | + if (s == NULL) |
923 | + return NULL; |
924 | + buf = s; |
925 | + break; |
926 | + case 'd' : |
927 | + case 'e' : |
928 | + ret = strtol (buf, &s, 10); |
929 | + if (s == buf) |
930 | + return NULL; |
931 | + timeptr->tm_mday = ret; |
932 | + buf = s; |
933 | + break; |
934 | + case 'H' : |
935 | + case 'k' : |
936 | + ret = strtol (buf, &s, 10); |
937 | + if (s == buf) |
938 | + return NULL; |
939 | + timeptr->tm_hour = ret; |
940 | + buf = s; |
941 | + break; |
942 | + case 'I' : |
943 | + case 'l' : |
944 | + ret = strtol (buf, &s, 10); |
945 | + if (s == buf) |
946 | + return NULL; |
947 | + if (ret == 12) |
948 | + timeptr->tm_hour = 0; |
949 | + else |
950 | + timeptr->tm_hour = ret; |
951 | + buf = s; |
952 | + break; |
953 | + case 'j' : |
954 | + ret = strtol (buf, &s, 10); |
955 | + if (s == buf) |
956 | + return NULL; |
957 | + timeptr->tm_yday = ret - 1; |
958 | + buf = s; |
959 | + break; |
960 | + case 'm' : |
961 | + ret = strtol (buf, &s, 10); |
962 | + if (s == buf) |
963 | + return NULL; |
964 | + timeptr->tm_mon = ret - 1; |
965 | + buf = s; |
966 | + break; |
967 | + case 'M' : |
968 | + ret = strtol (buf, &s, 10); |
969 | + if (s == buf) |
970 | + return NULL; |
971 | + timeptr->tm_min = ret; |
972 | + buf = s; |
973 | + break; |
974 | + case 'n' : |
975 | + if (*buf == '\n') |
976 | + ++buf; |
977 | + else |
978 | + return NULL; |
979 | + break; |
980 | + case 'p' : |
981 | + ret = match_string (&buf, ampm); |
982 | + if (ret < 0) |
983 | + return NULL; |
984 | + if (timeptr->tm_hour == 0) { |
985 | + if (ret == 1) |
986 | + timeptr->tm_hour = 12; |
987 | + } else |
988 | + timeptr->tm_hour += 12; |
989 | + break; |
990 | + case 'r' : /* %I:%M:%S %p */ |
991 | + s = strptime (buf, "%I:%M:%S %p", timeptr); |
992 | + if (s == NULL) |
993 | + return NULL; |
994 | + buf = s; |
995 | + break; |
996 | + case 'R' : /* %H:%M */ |
997 | + s = strptime (buf, "%H:%M", timeptr); |
998 | + if (s == NULL) |
999 | + return NULL; |
1000 | + buf = s; |
1001 | + break; |
1002 | + case 'S' : |
1003 | + ret = strtol (buf, &s, 10); |
1004 | + if (s == buf) |
1005 | + return NULL; |
1006 | + timeptr->tm_sec = ret; |
1007 | + buf = s; |
1008 | + break; |
1009 | + case 't' : |
1010 | + if (*buf == '\t') |
1011 | + ++buf; |
1012 | + else |
1013 | + return NULL; |
1014 | + break; |
1015 | + case 'T' : /* %H:%M:%S */ |
1016 | + case 'X' : |
1017 | + s = strptime (buf, "%H:%M:%S", timeptr); |
1018 | + if (s == NULL) |
1019 | + return NULL; |
1020 | + buf = s; |
1021 | + break; |
1022 | + case 'u' : |
1023 | + ret = strtol (buf, &s, 10); |
1024 | + if (s == buf) |
1025 | + return NULL; |
1026 | + timeptr->tm_wday = ret - 1; |
1027 | + buf = s; |
1028 | + break; |
1029 | + case 'w' : |
1030 | + ret = strtol (buf, &s, 10); |
1031 | + if (s == buf) |
1032 | + return NULL; |
1033 | + timeptr->tm_wday = ret; |
1034 | + buf = s; |
1035 | + break; |
1036 | + case 'U' : |
1037 | + ret = strtol (buf, &s, 10); |
1038 | + if (s == buf) |
1039 | + return NULL; |
1040 | + set_week_number_sun (timeptr, ret); |
1041 | + buf = s; |
1042 | + break; |
1043 | + case 'V' : |
1044 | + ret = strtol (buf, &s, 10); |
1045 | + if (s == buf) |
1046 | + return NULL; |
1047 | + set_week_number_mon4 (timeptr, ret); |
1048 | + buf = s; |
1049 | + break; |
1050 | + case 'W' : |
1051 | + ret = strtol (buf, &s, 10); |
1052 | + if (s == buf) |
1053 | + return NULL; |
1054 | + set_week_number_mon (timeptr, ret); |
1055 | + buf = s; |
1056 | + break; |
1057 | + case 'x' : |
1058 | + s = strptime (buf, "%Y:%m:%d", timeptr); |
1059 | + if (s == NULL) |
1060 | + return NULL; |
1061 | + buf = s; |
1062 | + break; |
1063 | + case 'y' : |
1064 | + ret = strtol (buf, &s, 10); |
1065 | + if (s == buf) |
1066 | + return NULL; |
1067 | + if (ret < 70) |
1068 | + timeptr->tm_year = 100 + ret; |
1069 | + else |
1070 | + timeptr->tm_year = ret; |
1071 | + buf = s; |
1072 | + break; |
1073 | + case 'Y' : |
1074 | + ret = strtol (buf, &s, 10); |
1075 | + if (s == buf) |
1076 | + return NULL; |
1077 | + timeptr->tm_year = ret - tm_year_base; |
1078 | + buf = s; |
1079 | + break; |
1080 | + case 'Z' : |
1081 | + abort (); |
1082 | + case '\0' : |
1083 | + --format; |
1084 | + /* FALLTHROUGH */ |
1085 | + case '%' : |
1086 | + if (*buf == '%') |
1087 | + ++buf; |
1088 | + else |
1089 | + return NULL; |
1090 | + break; |
1091 | + default : |
1092 | + if (*buf == '%' || *++buf == c) |
1093 | + ++buf; |
1094 | + else |
1095 | + return NULL; |
1096 | + break; |
1097 | + } |
1098 | + } else { |
1099 | + if (*buf == c) |
1100 | + ++buf; |
1101 | + else |
1102 | + return NULL; |
1103 | + } |
1104 | + } |
1105 | + return (char *)buf; |
1106 | +} |
1107 | + |
1108 | +#endif /* WIN32 */ |
1109 | |
1110 | \ No newline at end of file |
I've added lp:zorba/archive-module to the list of branches the validation queue watches, so let's see if this works.