Merge lp:~zorba-coders/zorba/archive-module-winfixes into lp:zorba/archive-module

Proposed by Juan Zacarias
Status: Merged
Approved by: Chris Hillery
Approved revision: 47
Merged at revision: 47
Proposed branch: lp:~zorba-coders/zorba/archive-module-winfixes
Merge into: lp:zorba/archive-module
Diff against target: 926 lines (+512/-380)
3 files modified
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 (+442/-378)
To merge this branch: bzr merge lp:~zorba-coders/zorba/archive-module-winfixes
Reviewer Review Type Date Requested Status
Matthias Brantner Approve
Luis Rodriguez Gonzalez Approve
Review via email: mp+120438@code.launchpad.net

This proposal supersedes a proposal from 2012-08-02.

Commit message

Fixed Window warnings, and added size to the new zip file when updating or deleting

Description of the change

Fixed Window warnings, and added size to the new zip file when updating or deleting

To post a comment you must log in.
Revision history for this message
Chris Hillery (ceejatec) wrote : Posted in a previous version of this proposal

I've added lp:zorba/archive-module to the list of branches the validation queue watches, so let's see if this works.

Revision history for this message
Zorba Build Bot (zorba-buildbot) wrote : Posted in a previous version of this proposal
Revision history for this message
Zorba Build Bot (zorba-buildbot) wrote : Posted in a previous version of this proposal

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/zo/testing/zorbatest/tester/TarmacLander.cmake:274 (message):
  Validation queue job archive-module-winfixes-2012-08-03T00-52-57.193Z is
  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/zo/testing/zorbatest/tester/TarmacLander.cmake

Revision history for this message
Chris Hillery (ceejatec) wrote : Posted in a previous version of this proposal

Ah, right, I still need to install a newer version of libarchive on the queue machine. Sorry.

Revision history for this message
Zorba Build Bot (zorba-buildbot) wrote : Posted in a previous version of this proposal
Revision history for this message
Zorba Build Bot (zorba-buildbot) wrote : Posted in a previous version of this proposal

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/zo/testing/zorbatest/tester/TarmacLander.cmake:274 (message):
  Validation queue job archive-module-winfixes-2012-08-03T01-53-02.255Z is
  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/zo/testing/zorbatest/tester/TarmacLander.cmake

Revision history for this message
Matthias Brantner (matthias-brantner) wrote : Posted in a previous version of this proposal

The following code could be factorized.

174 if(lSize > INT_MAX)
175 + lResult.reserve(INT_MAX);
176 + else
177 + lResult.reserve((int)lSize);

Revision history for this message
Luis Rodriguez Gonzalez (kuraru) wrote :

Looks fine.

review: Approve
Revision history for this message
Matthias Brantner (matthias-brantner) :
review: Approve
Revision history for this message
Zorba Build Bot (zorba-buildbot) wrote :

Attempt to merge into lp:zorba/archive-module failed due to conflicts:

text conflict in src/archive_module.xq.src/archive_module.cpp

Revision history for this message
Chris Hillery (ceejatec) wrote :

Luis - please fix the merge conflict in archive_module.cpp. I tried to do it, but it looks like some of the changes were added independently on the module trunk and I'm not sure how to resolve the differences.

47. By Luis Rodriguez Gonzalez

branch updated

Revision history for this message
Luis Rodriguez Gonzalez (kuraru) wrote :

I just updated the branch.

Revision history for this message
Zorba Build Bot (zorba-buildbot) wrote :
Revision history for this message
Zorba Build Bot (zorba-buildbot) wrote :

Validation queue job archive-module-winfixes-2013-02-18T22-37-47.415Z is finished. The final status was:

All tests succeeded!

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'src/archive_module.xq.src/archive_module.h'
2--- src/archive_module.xq.src/archive_module.h 2012-09-06 20:40:47 +0000
3+++ src/archive_module.xq.src/archive_module.h 2013-02-18 22:02:23 +0000
4@@ -210,7 +210,7 @@
5 protected:
6 String theEntryPath;
7 String theEncoding;
8- int theSize;
9+ long long theSize;
10 time_t theLastModified;
11 String theCompression;
12 ArchiveEntryType theEntryType;
13@@ -223,7 +223,7 @@
14
15 const String& getEncoding() const { return theEncoding; }
16
17- int getSize() const { return theSize; }
18+ long long getSize() const { return theSize; }
19
20 const time_t& getLastModified() const { return theLastModified; }
21
22
23=== added file 'src/archive_module.xq.src/strncasecmp.h'
24--- src/archive_module.xq.src/strncasecmp.h 1970-01-01 00:00:00 +0000
25+++ src/archive_module.xq.src/strncasecmp.h 2013-02-18 22:02:23 +0000
26@@ -0,0 +1,68 @@
27+/*
28+ * Copyright (c) 1998 Kungliga Tekniska Högskolan
29+ * (Royal Institute of Technology, Stockholm, Sweden).
30+ * All rights reserved.
31+ *
32+ * Redistribution and use in source and binary forms, with or without
33+ * modification, are permitted provided that the following conditions
34+ * are met:
35+ *
36+ * 1. Redistributions of source code must retain the above copyright
37+ * notice, this list of conditions and the following disclaimer.
38+ *
39+ * 2. Redistributions in binary form must reproduce the above copyright
40+ * notice, this list of conditions and the following disclaimer in the
41+ * documentation and/or other materials provided with the distribution.
42+ *
43+ * 3. Neither the name of the Institute nor the names of its contributors
44+ * may be used to endorse or promote products derived from this software
45+ * without specific prior written permission.
46+ *
47+ * THIS SOFTWARE IS PROVIDED BY THE INSTITUTE AND CONTRIBUTORS ``AS IS'' AND
48+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
49+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
50+ * ARE DISCLAIMED. IN NO EVENT SHALL THE INSTITUTE OR CONTRIBUTORS BE LIABLE
51+ * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
52+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
53+ * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
54+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
55+ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
56+ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
57+ * SUCH DAMAGE.
58+ */
59+
60+#ifdef WIN32
61+
62+#include <string.h>
63+#include <ctype.h>
64+#include <stddef.h>
65+
66+int strcasecmp(const char *s1, const char *s2)
67+{
68+ const unsigned char *us1 = (const unsigned char *)s1, *us2 = (const unsigned char *)s2;
69+
70+ while (tolower(*us1) == tolower(*us2)) {
71+ if (*us1++ == '\0')
72+ return (0);
73+ us2++;
74+ }
75+ return (tolower(*us1) - tolower(*us2));
76+}
77+
78+int strncasecmp(const char *s1, const char *s2, size_t n)
79+{
80+ while(n > 0
81+ && toupper((unsigned char)*s1) == toupper((unsigned char)*s2))
82+ {
83+ if(*s1 == '\0')
84+ return 0;
85+ s1++;
86+ s2++;
87+ n--;
88+ }
89+ if(n == 0)
90+ return 0;
91+ return toupper((unsigned char)*s1) - toupper((unsigned char)*s2);
92+}
93+
94+#endif /* WIN32 */
95
96=== modified file 'src/archive_module.xq.src/strptime.h'
97--- src/archive_module.xq.src/strptime.h 2012-07-02 17:14:21 +0000
98+++ src/archive_module.xq.src/strptime.h 2013-02-18 22:02:23 +0000
99@@ -1,384 +1,448 @@
100+/*
101+ * Copyright (c) 1999 Kungliga Tekniska H?gskolan
102+ * (Royal Institute of Technology, Stockholm, Sweden).
103+ * All rights reserved.
104+ *
105+ * Redistribution and use in source and binary forms, with or without
106+ * modification, are permitted provided that the following conditions
107+ * are met:
108+ *
109+ * 1. Redistributions of source code must retain the above copyright
110+ * notice, this list of conditions and the following disclaimer.
111+ *
112+ * 2. Redistributions in binary form must reproduce the above copyright
113+ * notice, this list of conditions and the following disclaimer in the
114+ * documentation and/or other materials provided with the distribution.
115+ *
116+ * 3. Neither the name of KTH nor the names of its contributors may be
117+ * used to endorse or promote products derived from this software without
118+ * specific prior written permission.
119+ *
120+ * THIS SOFTWARE IS PROVIDED BY KTH AND ITS CONTRIBUTORS ``AS IS'' AND ANY
121+ * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
122+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
123+ * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL KTH OR ITS CONTRIBUTORS BE
124+ * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
125+ * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
126+ * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR
127+ * BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
128+ * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
129+ * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
130+ * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */
131+
132+#ifdef WIN32
133+
134+
135 #include <ctype.h>
136 #include <string.h>
137 #include <time.h>
138-
139-
140-/*
141- * We do not implement alternate representations. However, we always
142- * check whether a given modifier is allowed for a certain conversion.
143- */
144-#define ALT_E 0x01
145-#define ALT_O 0x02
146-//#define LEGAL_ALT(x) { if (alt_format & ~(x)) return (0); }
147-#define LEGAL_ALT(x) { ; }
148-#define TM_YEAR_BASE (1970)
149-
150-static int conv_num(const char **, int *, int, int);
151-static int strncasecmp(char *s1, char *s2, size_t n);
152-
153-static const char *day[7] = {
154- "Sunday", "Monday", "Tuesday", "Wednesday", "Thursday",
155- "Friday", "Saturday"
156-};
157-static const char *abday[7] = {
158- "Sun","Mon","Tue","Wed","Thu","Fri","Sat"
159-};
160-static const char *mon[12] = {
161- "January", "February", "March", "April", "May", "June", "July",
162- "August", "September", "October", "November", "December"
163-};
164-static const char *abmon[12] = {
165- "Jan", "Feb", "Mar", "Apr", "May", "Jun",
166- "Jul", "Aug", "Sep", "Oct", "Nov", "Dec"
167-};
168-static const char *am_pm[2] = {
169- "AM", "PM"
170-};
171-
172-
173-char * strptime(const char *buf, const char *fmt, struct tm *tm)
174+#include "strncasecmp.h"
175+
176+
177+static const char *abb_weekdays[] = {
178+ "Sun",
179+ "Mon",
180+ "Tue",
181+ "Wed",
182+ "Thu",
183+ "Fri",
184+ "Sat",
185+ NULL
186+};
187+
188+static const char *full_weekdays[] = {
189+ "Sunday",
190+ "Monday",
191+ "Tuesday",
192+ "Wednesday",
193+ "Thursday",
194+ "Friday",
195+ "Saturday",
196+ NULL
197+};
198+
199+static const char *abb_month[] = {
200+ "Jan",
201+ "Feb",
202+ "Mar",
203+ "Apr",
204+ "May",
205+ "Jun",
206+ "Jul",
207+ "Aug",
208+ "Sep",
209+ "Oct",
210+ "Nov",
211+ "Dec",
212+ NULL
213+};
214+
215+static const char *full_month[] = {
216+ "January",
217+ "February",
218+ "Mars",
219+ "April",
220+ "May",
221+ "June",
222+ "July",
223+ "August",
224+ "September",
225+ "October",
226+ "November",
227+ "December",
228+ NULL,
229+};
230+
231+static const char *ampm[] = {
232+ "am",
233+ "pm",
234+ NULL
235+};
236+
237+/*
238+ * Try to match `*buf' to one of the strings in `strs'. Return the
239+ * index of the matching string (or -1 if none). Also advance buf.
240+ */
241+
242+static int
243+match_string (const char **buf, const char **strs)
244+{
245+ int i = 0;
246+
247+ for (i = 0; strs[i] != NULL; ++i) {
248+ int len = strlen (strs[i]);
249+
250+ if (strncasecmp (*buf, strs[i], len) == 0) {
251+ *buf += len;
252+ return i;
253+ }
254+ }
255+ return -1;
256+}
257+
258+/*
259+ * tm_year is relative this year */
260+
261+const int tm_year_base = 1900;
262+
263+/*
264+ * Return TRUE iff `year' was a leap year.
265+ */
266+
267+static int
268+is_leap_year (int year)
269+{
270+ return (year % 4) == 0 && ((year % 100) != 0 || (year % 400) == 0);
271+}
272+
273+/*
274+ * Return the weekday [0,6] (0 = Sunday) of the first day of `year'
275+ */
276+
277+static int
278+first_day (int year)
279+{
280+ int ret = 4;
281+
282+ for (; year > 1970; --year)
283+ ret = (ret + 365 + is_leap_year (year) ? 1 : 0) % 7;
284+ return ret;
285+}
286+
287+/*
288+ * Set `timeptr' given `wnum' (week number [0, 53])
289+ */
290+
291+static void
292+set_week_number_sun (struct tm *timeptr, int wnum)
293+{
294+ int fday = first_day (timeptr->tm_year + tm_year_base);
295+
296+ timeptr->tm_yday = wnum * 7 + timeptr->tm_wday - fday;
297+ if (timeptr->tm_yday < 0) {
298+ timeptr->tm_wday = fday;
299+ timeptr->tm_yday = 0;
300+ }
301+}
302+
303+/*
304+ * Set `timeptr' given `wnum' (week number [0, 53])
305+ */
306+
307+static void
308+set_week_number_mon (struct tm *timeptr, int wnum)
309+{
310+ int fday = (first_day (timeptr->tm_year + tm_year_base) + 6) % 7;
311+
312+ timeptr->tm_yday = wnum * 7 + (timeptr->tm_wday + 6) % 7 - fday;
313+ if (timeptr->tm_yday < 0) {
314+ timeptr->tm_wday = (fday + 1) % 7;
315+ timeptr->tm_yday = 0;
316+ }
317+}
318+
319+/*
320+ * Set `timeptr' given `wnum' (week number [0, 53])
321+ */
322+
323+static void
324+set_week_number_mon4 (struct tm *timeptr, int wnum)
325+{
326+ int fday = (first_day (timeptr->tm_year + tm_year_base) + 6) % 7;
327+ int offset = 0;
328+
329+ if (fday < 4)
330+ offset += 7;
331+
332+ timeptr->tm_yday = offset + (wnum - 1) * 7 + timeptr->tm_wday - fday;
333+ if (timeptr->tm_yday < 0) {
334+ timeptr->tm_wday = fday;
335+ timeptr->tm_yday = 0;
336+ }
337+}
338+
339+/*
340+ *
341+ */
342+
343+char *
344+strptime (const char *buf, const char *format, struct tm *timeptr)
345 {
346 char c;
347- const char *bp;
348- size_t len = 0;
349- int alt_format, i, split_year = 0;
350-
351- bp = buf;
352-
353- while ((c = *fmt) != '\0')
354- {
355- /* Clear `alternate' modifier prior to new conversion. */
356- alt_format = 0;
357-
358- /* Eat up white-space. */
359- if (isspace(c))
360- {
361- while (isspace(*bp))
362- bp++;
363-
364- fmt++;
365- continue;
366- }
367-
368- if ((c = *fmt++) != '%')
369- goto literal;
370-
371-
372-again: switch (c = *fmt++)
373- {
374- case '%': /* "%%" is converted to "%". */
375- literal:
376- if (c != *bp++)
377- return (0);
378- break;
379-
380- /*
381- * "Alternative" modifiers. Just set the appropriate flag
382- * and start over again.
383- */
384- case 'E': /* "%E?" alternative conversion modifier. */
385- LEGAL_ALT(0);
386- alt_format |= ALT_E;
387- goto again;
388-
389- case 'O': /* "%O?" alternative conversion modifier. */
390- LEGAL_ALT(0);
391- alt_format |= ALT_O;
392- goto again;
393-
394- /*
395- * "Complex" conversion rules, implemented through recursion.
396- */
397- case 'c': /* Date and time, using the locale's format. */
398- LEGAL_ALT(ALT_E);
399- if (!(bp = strptime(bp, "%x %X", tm)))
400- return (0);
401- break;
402-
403- case 'D': /* The date as "%m/%d/%y". */
404- LEGAL_ALT(0);
405- if (!(bp = strptime(bp, "%m/%d/%y", tm)))
406- return (0);
407- break;
408-
409- case 'R': /* The time as "%H:%M". */
410- LEGAL_ALT(0);
411- if (!(bp = strptime(bp, "%H:%M", tm)))
412- return (0);
413- break;
414-
415- case 'r': /* The time in 12-hour clock representation. */
416- LEGAL_ALT(0);
417- if (!(bp = strptime(bp, "%I:%M:%S %p", tm)))
418- return (0);
419- break;
420-
421- case 'T': /* The time as "%H:%M:%S". */
422- LEGAL_ALT(0);
423- if (!(bp = strptime(bp, "%H:%M:%S", tm)))
424- return (0);
425- break;
426-
427- case 'X': /* The time, using the locale's format. */
428- LEGAL_ALT(ALT_E);
429- if (!(bp = strptime(bp, "%H:%M:%S", tm)))
430- return (0);
431- break;
432-
433- case 'x': /* The date, using the locale's format. */
434- LEGAL_ALT(ALT_E);
435- if (!(bp = strptime(bp, "%m/%d/%y", tm)))
436- return (0);
437- break;
438-
439- /*
440- * "Elementary" conversion rules.
441- */
442- case 'A': /* The day of week, using the locale's form. */
443- case 'a':
444- LEGAL_ALT(0);
445- for (i = 0; i < 7; i++)
446- {
447- /* Full name. */
448- len = strlen(day[i]);
449- if (strncasecmp((char *)(day[i]), (char *)bp, len) == 0)
450- break;
451-
452- /* Abbreviated name. */
453- len = strlen(abday[i]);
454- if (strncasecmp((char *)(abday[i]), (char *)bp, len) == 0)
455- break;
456- }
457-
458- /* Nothing matched. */
459- if (i == 7)
460- return (0);
461-
462- tm->tm_wday = i;
463- bp += len;
464- break;
465-
466- case 'B': /* The month, using the locale's form. */
467- case 'b':
468- case 'h':
469- LEGAL_ALT(0);
470- for (i = 0; i < 12; i++)
471- {
472- /* Full name. */
473-
474- len = strlen(mon[i]);
475- if (strncasecmp((char *)(mon[i]), (char *)bp, len) == 0)
476- break;
477-
478- /* Abbreviated name. */
479- len = strlen(abmon[i]);
480- if (strncasecmp((char *)(abmon[i]),(char *) bp, len) == 0)
481- break;
482- }
483-
484- /* Nothing matched. */
485- if (i == 12)
486- return (0);
487-
488- tm->tm_mon = i;
489- bp += len;
490- break;
491-
492- case 'C': /* The century number. */
493- LEGAL_ALT(ALT_E);
494- if (!(conv_num(&bp, &i, 0, 99)))
495- return (0);
496-
497- if (split_year)
498- {
499- tm->tm_year = (tm->tm_year % 100) + (i * 100);
500- } else {
501- tm->tm_year = i * 100;
502- split_year = 1;
503- }
504- break;
505-
506- case 'd': /* The day of month. */
507- case 'e':
508- LEGAL_ALT(ALT_O);
509- if (!(conv_num(&bp, &tm->tm_mday, 1, 31)))
510- return (0);
511- break;
512-
513- case 'k': /* The hour (24-hour clock representation). */
514- LEGAL_ALT(0);
515- /* FALLTHROUGH */
516- case 'H':
517- LEGAL_ALT(ALT_O);
518- if (!(conv_num(&bp, &tm->tm_hour, 0, 23)))
519- return (0);
520- break;
521-
522- case 'l': /* The hour (12-hour clock representation). */
523- LEGAL_ALT(0);
524- /* FALLTHROUGH */
525- case 'I':
526- LEGAL_ALT(ALT_O);
527- if (!(conv_num(&bp, &tm->tm_hour, 1, 12)))
528- return (0);
529- if (tm->tm_hour == 12)
530- tm->tm_hour = 0;
531- break;
532-
533- case 'j': /* The day of year. */
534- LEGAL_ALT(0);
535- if (!(conv_num(&bp, &i, 1, 366)))
536- return (0);
537- tm->tm_yday = i - 1;
538- break;
539-
540- case 'M': /* The minute. */
541- LEGAL_ALT(ALT_O);
542- if (!(conv_num(&bp, &tm->tm_min, 0, 59)))
543- return (0);
544- break;
545-
546- case 'm': /* The month. */
547- LEGAL_ALT(ALT_O);
548- if (!(conv_num(&bp, &i, 1, 12)))
549- return (0);
550- tm->tm_mon = i - 1;
551- break;
552-
553-// case 'p': /* The locale's equivalent of AM/PM. */
554-// LEGAL_ALT(0);
555-// /* AM? */
556-// if (strcasecmp(am_pm[0], bp) == 0)
557-// {
558-// if (tm->tm_hour > 11)
559-// return (0);
560-//
561-// bp += strlen(am_pm[0]);
562-// break;
563-// }
564-// /* PM? */
565-// else if (strcasecmp(am_pm[1], bp) == 0)
566-// {
567-// if (tm->tm_hour > 11)
568-// return (0);
569-//
570-// tm->tm_hour += 12;
571-// bp += strlen(am_pm[1]);
572-// break;
573-// }
574-//
575-// /* Nothing matched. */
576-// return (0);
577-
578- case 'S': /* The seconds. */
579- LEGAL_ALT(ALT_O);
580- if (!(conv_num(&bp, &tm->tm_sec, 0, 61)))
581- return (0);
582- break;
583-
584- case 'U': /* The week of year, beginning on sunday. */
585- case 'W': /* The week of year, beginning on monday. */
586- LEGAL_ALT(ALT_O);
587- /*
588- * XXX This is bogus, as we can not assume any valid
589- * information present in the tm structure at this
590- * point to calculate a real value, so just check the
591- * range for now.
592- */
593- if (!(conv_num(&bp, &i, 0, 53)))
594- return (0);
595- break;
596-
597- case 'w': /* The day of week, beginning on sunday. */
598- LEGAL_ALT(ALT_O);
599- if (!(conv_num(&bp, &tm->tm_wday, 0, 6)))
600- return (0);
601- break;
602-
603- case 'Y': /* The year. */
604- LEGAL_ALT(ALT_E);
605- if (!(conv_num(&bp, &i, 0, 9999)))
606- return (0);
607-
608- tm->tm_year = i - TM_YEAR_BASE;
609- break;
610-
611- case 'y': /* The year within 100 years of the epoch. */
612- LEGAL_ALT(ALT_E | ALT_O);
613- if (!(conv_num(&bp, &i, 0, 99)))
614- return (0);
615-
616- if (split_year)
617- {
618- tm->tm_year = ((tm->tm_year / 100) * 100) + i;
619- break;
620- }
621- split_year = 1;
622- if (i <= 68)
623- tm->tm_year = i + 2000 - TM_YEAR_BASE;
624- else
625- tm->tm_year = i + 1900 - TM_YEAR_BASE;
626- break;
627-
628- /*
629- * Miscellaneous conversions.
630- */
631- case 'n': /* Any kind of white-space. */
632- case 't':
633- LEGAL_ALT(0);
634- while (isspace(*bp))
635- bp++;
636- break;
637-
638-
639- default: /* Unknown/unsupported conversion. */
640- return (0);
641- }
642-
643-
644- }
645-
646- /* LINTED functional specification */
647- return ((char *)bp);
648-}
649-
650-
651-static int conv_num(const char **buf, int *dest, int llim, int ulim)
652-{
653- int result = 0;
654-
655- /* The limit also determines the number of valid digits. */
656- int rulim = ulim;
657-
658- if (**buf < '0' || **buf > '9')
659- return (0);
660-
661- do {
662- result *= 10;
663- result += *(*buf)++ - '0';
664- rulim /= 10;
665- } while ((result * 10 <= ulim) && rulim && **buf >= '0' && **buf <= '9');
666-
667- if (result < llim || result > ulim)
668- return (0);
669-
670- *dest = result;
671- return (1);
672-}
673-
674-int strncasecmp(char *s1, char *s2, size_t n)
675-{
676- if (n == 0)
677- return 0;
678-
679- while (n-- != 0 && tolower(*s1) == tolower(*s2))
680- {
681- if (n == 0 || *s1 == '\0' || *s2 == '\0')
682- break;
683- s1++;
684- s2++;
685- }
686-
687- return tolower(*(unsigned char *) s1) - tolower(*(unsigned char *) s2);
688-}
689+
690+ for (; (c = *format) != '\0'; ++format) {
691+ char *s;
692+ int ret;
693+
694+ if (isspace (c)) {
695+ while (isspace (*buf))
696+ ++buf;
697+ } else if (c == '%' && format[1] != '\0') {
698+ c = *++format;
699+ if (c == 'E' || c == 'O')
700+ c = *++format;
701+ switch (c) {
702+ case 'A' :
703+ ret = match_string (&buf, full_weekdays);
704+ if (ret < 0)
705+ return NULL;
706+ timeptr->tm_wday = ret;
707+ break;
708+ case 'a' :
709+ ret = match_string (&buf, abb_weekdays);
710+ if (ret < 0)
711+ return NULL;
712+ timeptr->tm_wday = ret;
713+ break;
714+ case 'B' :
715+ ret = match_string (&buf, full_month);
716+ if (ret < 0)
717+ return NULL;
718+ timeptr->tm_mon = ret;
719+ break;
720+ case 'b' :
721+ case 'h' :
722+ ret = match_string (&buf, abb_month);
723+ if (ret < 0)
724+ return NULL;
725+ timeptr->tm_mon = ret;
726+ break;
727+ case 'C' :
728+ ret = strtol (buf, &s, 10);
729+ if (s == buf)
730+ return NULL;
731+ timeptr->tm_year = (ret * 100) - tm_year_base;
732+ buf = s;
733+ break;
734+ case 'c' :
735+ abort ();
736+ case 'D' : /* %m/%d/%y */
737+ s = strptime (buf, "%m/%d/%y", timeptr);
738+ if (s == NULL)
739+ return NULL;
740+ buf = s;
741+ break;
742+ case 'd' :
743+ case 'e' :
744+ ret = strtol (buf, &s, 10);
745+ if (s == buf)
746+ return NULL;
747+ timeptr->tm_mday = ret;
748+ buf = s;
749+ break;
750+ case 'H' :
751+ case 'k' :
752+ ret = strtol (buf, &s, 10);
753+ if (s == buf)
754+ return NULL;
755+ timeptr->tm_hour = ret;
756+ buf = s;
757+ break;
758+ case 'I' :
759+ case 'l' :
760+ ret = strtol (buf, &s, 10);
761+ if (s == buf)
762+ return NULL;
763+ if (ret == 12)
764+ timeptr->tm_hour = 0;
765+ else
766+ timeptr->tm_hour = ret;
767+ buf = s;
768+ break;
769+ case 'j' :
770+ ret = strtol (buf, &s, 10);
771+ if (s == buf)
772+ return NULL;
773+ timeptr->tm_yday = ret - 1;
774+ buf = s;
775+ break;
776+ case 'm' :
777+ ret = strtol (buf, &s, 10);
778+ if (s == buf)
779+ return NULL;
780+ timeptr->tm_mon = ret - 1;
781+ buf = s;
782+ break;
783+ case 'M' :
784+ ret = strtol (buf, &s, 10);
785+ if (s == buf)
786+ return NULL;
787+ timeptr->tm_min = ret;
788+ buf = s;
789+ break;
790+ case 'n' :
791+ if (*buf == '\n')
792+ ++buf;
793+ else
794+ return NULL;
795+ break;
796+ case 'p' :
797+ ret = match_string (&buf, ampm);
798+ if (ret < 0)
799+ return NULL;
800+ if (timeptr->tm_hour == 0) {
801+ if (ret == 1)
802+ timeptr->tm_hour = 12;
803+ } else
804+ timeptr->tm_hour += 12;
805+ break;
806+ case 'r' : /* %I:%M:%S %p */
807+ s = strptime (buf, "%I:%M:%S %p", timeptr);
808+ if (s == NULL)
809+ return NULL;
810+ buf = s;
811+ break;
812+ case 'R' : /* %H:%M */
813+ s = strptime (buf, "%H:%M", timeptr);
814+ if (s == NULL)
815+ return NULL;
816+ buf = s;
817+ break;
818+ case 'S' :
819+ ret = strtol (buf, &s, 10);
820+ if (s == buf)
821+ return NULL;
822+ timeptr->tm_sec = ret;
823+ buf = s;
824+ break;
825+ case 't' :
826+ if (*buf == '\t')
827+ ++buf;
828+ else
829+ return NULL;
830+ break;
831+ case 'T' : /* %H:%M:%S */
832+ case 'X' :
833+ s = strptime (buf, "%H:%M:%S", timeptr);
834+ if (s == NULL)
835+ return NULL;
836+ buf = s;
837+ break;
838+ case 'u' :
839+ ret = strtol (buf, &s, 10);
840+ if (s == buf)
841+ return NULL;
842+ timeptr->tm_wday = ret - 1;
843+ buf = s;
844+ break;
845+ case 'w' :
846+ ret = strtol (buf, &s, 10);
847+ if (s == buf)
848+ return NULL;
849+ timeptr->tm_wday = ret;
850+ buf = s;
851+ break;
852+ case 'U' :
853+ ret = strtol (buf, &s, 10);
854+ if (s == buf)
855+ return NULL;
856+ set_week_number_sun (timeptr, ret);
857+ buf = s;
858+ break;
859+ case 'V' :
860+ ret = strtol (buf, &s, 10);
861+ if (s == buf)
862+ return NULL;
863+ set_week_number_mon4 (timeptr, ret);
864+ buf = s;
865+ break;
866+ case 'W' :
867+ ret = strtol (buf, &s, 10);
868+ if (s == buf)
869+ return NULL;
870+ set_week_number_mon (timeptr, ret);
871+ buf = s;
872+ break;
873+ case 'x' :
874+ s = strptime (buf, "%Y:%m:%d", timeptr);
875+ if (s == NULL)
876+ return NULL;
877+ buf = s;
878+ break;
879+ case 'y' :
880+ ret = strtol (buf, &s, 10);
881+ if (s == buf)
882+ return NULL;
883+ if (ret < 70)
884+ timeptr->tm_year = 100 + ret;
885+ else
886+ timeptr->tm_year = ret;
887+ buf = s;
888+ break;
889+ case 'Y' :
890+ ret = strtol (buf, &s, 10);
891+ if (s == buf)
892+ return NULL;
893+ timeptr->tm_year = ret - tm_year_base;
894+ buf = s;
895+ break;
896+ case 'Z' :
897+ abort ();
898+ case '\0' :
899+ --format;
900+ /* FALLTHROUGH */
901+ case '%' :
902+ if (*buf == '%')
903+ ++buf;
904+ else
905+ return NULL;
906+ break;
907+ default :
908+ if (*buf == '%' || *++buf == c)
909+ ++buf;
910+ else
911+ return NULL;
912+ break;
913+ }
914+ } else {
915+ if (*buf == c)
916+ ++buf;
917+ else
918+ return NULL;
919+ }
920+ }
921+ return (char *)buf;
922+}
923+
924+#endif /* WIN32 */
925
926\ No newline at end of file

Subscribers

People subscribed via source and target branches

to all changes: