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
=== modified file 'src/archive_module.xq.src/archive_module.h'
--- src/archive_module.xq.src/archive_module.h 2012-09-06 20:40:47 +0000
+++ src/archive_module.xq.src/archive_module.h 2013-02-18 22:02:23 +0000
@@ -210,7 +210,7 @@
210 protected:210 protected:
211 String theEntryPath;211 String theEntryPath;
212 String theEncoding;212 String theEncoding;
213 int theSize;213 long long theSize;
214 time_t theLastModified;214 time_t theLastModified;
215 String theCompression;215 String theCompression;
216 ArchiveEntryType theEntryType;216 ArchiveEntryType theEntryType;
@@ -223,7 +223,7 @@
223223
224 const String& getEncoding() const { return theEncoding; }224 const String& getEncoding() const { return theEncoding; }
225225
226 int getSize() const { return theSize; }226 long long getSize() const { return theSize; }
227227
228 const time_t& getLastModified() const { return theLastModified; }228 const time_t& getLastModified() const { return theLastModified; }
229 229
230230
=== added file 'src/archive_module.xq.src/strncasecmp.h'
--- src/archive_module.xq.src/strncasecmp.h 1970-01-01 00:00:00 +0000
+++ src/archive_module.xq.src/strncasecmp.h 2013-02-18 22:02:23 +0000
@@ -0,0 +1,68 @@
1/*
2 * Copyright (c) 1998 Kungliga Tekniska Högskolan
3 * (Royal Institute of Technology, Stockholm, Sweden).
4 * All rights reserved.
5 *
6 * Redistribution and use in source and binary forms, with or without
7 * modification, are permitted provided that the following conditions
8 * are met:
9 *
10 * 1. Redistributions of source code must retain the above copyright
11 * notice, this list of conditions and the following disclaimer.
12 *
13 * 2. Redistributions in binary form must reproduce the above copyright
14 * notice, this list of conditions and the following disclaimer in the
15 * documentation and/or other materials provided with the distribution.
16 *
17 * 3. Neither the name of the Institute nor the names of its contributors
18 * may be used to endorse or promote products derived from this software
19 * without specific prior written permission.
20 *
21 * THIS SOFTWARE IS PROVIDED BY THE INSTITUTE AND CONTRIBUTORS ``AS IS'' AND
22 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
23 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
24 * ARE DISCLAIMED. IN NO EVENT SHALL THE INSTITUTE OR CONTRIBUTORS BE LIABLE
25 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
26 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
27 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
28 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
29 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
30 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
31 * SUCH DAMAGE.
32 */
33
34#ifdef WIN32
35
36#include <string.h>
37#include <ctype.h>
38#include <stddef.h>
39
40int strcasecmp(const char *s1, const char *s2)
41{
42 const unsigned char *us1 = (const unsigned char *)s1, *us2 = (const unsigned char *)s2;
43
44 while (tolower(*us1) == tolower(*us2)) {
45 if (*us1++ == '\0')
46 return (0);
47 us2++;
48 }
49 return (tolower(*us1) - tolower(*us2));
50}
51
52int strncasecmp(const char *s1, const char *s2, size_t n)
53{
54 while(n > 0
55 && toupper((unsigned char)*s1) == toupper((unsigned char)*s2))
56 {
57 if(*s1 == '\0')
58 return 0;
59 s1++;
60 s2++;
61 n--;
62 }
63 if(n == 0)
64 return 0;
65 return toupper((unsigned char)*s1) - toupper((unsigned char)*s2);
66}
67
68#endif /* WIN32 */
069
=== modified file 'src/archive_module.xq.src/strptime.h'
--- src/archive_module.xq.src/strptime.h 2012-07-02 17:14:21 +0000
+++ src/archive_module.xq.src/strptime.h 2013-02-18 22:02:23 +0000
@@ -1,384 +1,448 @@
1/*
2 * Copyright (c) 1999 Kungliga Tekniska H?gskolan
3 * (Royal Institute of Technology, Stockholm, Sweden).
4 * All rights reserved.
5 *
6 * Redistribution and use in source and binary forms, with or without
7 * modification, are permitted provided that the following conditions
8 * are met:
9 *
10 * 1. Redistributions of source code must retain the above copyright
11 * notice, this list of conditions and the following disclaimer.
12 *
13 * 2. Redistributions in binary form must reproduce the above copyright
14 * notice, this list of conditions and the following disclaimer in the
15 * documentation and/or other materials provided with the distribution.
16 *
17 * 3. Neither the name of KTH nor the names of its contributors may be
18 * used to endorse or promote products derived from this software without
19 * specific prior written permission.
20 *
21 * THIS SOFTWARE IS PROVIDED BY KTH AND ITS CONTRIBUTORS ``AS IS'' AND ANY
22 * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
23 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
24 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL KTH OR ITS CONTRIBUTORS BE
25 * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
26 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
27 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR
28 * BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
29 * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
30 * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
31 * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */
32
33#ifdef WIN32
34
35
1#include <ctype.h>36#include <ctype.h>
2#include <string.h>37#include <string.h>
3#include <time.h>38#include <time.h>
4 39#include "strncasecmp.h"
5 40
6/*41
7 * We do not implement alternate representations. However, we always42static const char *abb_weekdays[] = {
8 * check whether a given modifier is allowed for a certain conversion.43 "Sun",
9 */44 "Mon",
10#define ALT_E 0x0145 "Tue",
11#define ALT_O 0x0246 "Wed",
12//#define LEGAL_ALT(x) { if (alt_format & ~(x)) return (0); }47 "Thu",
13#define LEGAL_ALT(x) { ; }48 "Fri",
14#define TM_YEAR_BASE (1970)49 "Sat",
15 50 NULL
16static int conv_num(const char **, int *, int, int);51};
17static int strncasecmp(char *s1, char *s2, size_t n);52
18 53static const char *full_weekdays[] = {
19static const char *day[7] = {54 "Sunday",
20 "Sunday", "Monday", "Tuesday", "Wednesday", "Thursday",55 "Monday",
21 "Friday", "Saturday"56 "Tuesday",
22};57 "Wednesday",
23static const char *abday[7] = {58 "Thursday",
24 "Sun","Mon","Tue","Wed","Thu","Fri","Sat"59 "Friday",
25};60 "Saturday",
26static const char *mon[12] = {61 NULL
27 "January", "February", "March", "April", "May", "June", "July",62};
28 "August", "September", "October", "November", "December"63
29};64static const char *abb_month[] = {
30static const char *abmon[12] = {65 "Jan",
31 "Jan", "Feb", "Mar", "Apr", "May", "Jun",66 "Feb",
32 "Jul", "Aug", "Sep", "Oct", "Nov", "Dec"67 "Mar",
33};68 "Apr",
34static const char *am_pm[2] = {69 "May",
35 "AM", "PM"70 "Jun",
36};71 "Jul",
37 72 "Aug",
38 73 "Sep",
39char * strptime(const char *buf, const char *fmt, struct tm *tm)74 "Oct",
75 "Nov",
76 "Dec",
77 NULL
78};
79
80static const char *full_month[] = {
81 "January",
82 "February",
83 "Mars",
84 "April",
85 "May",
86 "June",
87 "July",
88 "August",
89 "September",
90 "October",
91 "November",
92 "December",
93 NULL,
94};
95
96static const char *ampm[] = {
97 "am",
98 "pm",
99 NULL
100};
101
102/*
103 * Try to match `*buf' to one of the strings in `strs'. Return the
104 * index of the matching string (or -1 if none). Also advance buf.
105 */
106
107static int
108match_string (const char **buf, const char **strs)
109{
110 int i = 0;
111
112 for (i = 0; strs[i] != NULL; ++i) {
113 int len = strlen (strs[i]);
114
115 if (strncasecmp (*buf, strs[i], len) == 0) {
116 *buf += len;
117 return i;
118 }
119 }
120 return -1;
121}
122
123/*
124 * tm_year is relative this year */
125
126const int tm_year_base = 1900;
127
128/*
129 * Return TRUE iff `year' was a leap year.
130 */
131
132static int
133is_leap_year (int year)
134{
135 return (year % 4) == 0 && ((year % 100) != 0 || (year % 400) == 0);
136}
137
138/*
139 * Return the weekday [0,6] (0 = Sunday) of the first day of `year'
140 */
141
142static int
143first_day (int year)
144{
145 int ret = 4;
146
147 for (; year > 1970; --year)
148 ret = (ret + 365 + is_leap_year (year) ? 1 : 0) % 7;
149 return ret;
150}
151
152/*
153 * Set `timeptr' given `wnum' (week number [0, 53])
154 */
155
156static void
157set_week_number_sun (struct tm *timeptr, int wnum)
158{
159 int fday = first_day (timeptr->tm_year + tm_year_base);
160
161 timeptr->tm_yday = wnum * 7 + timeptr->tm_wday - fday;
162 if (timeptr->tm_yday < 0) {
163 timeptr->tm_wday = fday;
164 timeptr->tm_yday = 0;
165 }
166}
167
168/*
169 * Set `timeptr' given `wnum' (week number [0, 53])
170 */
171
172static void
173set_week_number_mon (struct tm *timeptr, int wnum)
174{
175 int fday = (first_day (timeptr->tm_year + tm_year_base) + 6) % 7;
176
177 timeptr->tm_yday = wnum * 7 + (timeptr->tm_wday + 6) % 7 - fday;
178 if (timeptr->tm_yday < 0) {
179 timeptr->tm_wday = (fday + 1) % 7;
180 timeptr->tm_yday = 0;
181 }
182}
183
184/*
185 * Set `timeptr' given `wnum' (week number [0, 53])
186 */
187
188static void
189set_week_number_mon4 (struct tm *timeptr, int wnum)
190{
191 int fday = (first_day (timeptr->tm_year + tm_year_base) + 6) % 7;
192 int offset = 0;
193
194 if (fday < 4)
195 offset += 7;
196
197 timeptr->tm_yday = offset + (wnum - 1) * 7 + timeptr->tm_wday - fday;
198 if (timeptr->tm_yday < 0) {
199 timeptr->tm_wday = fday;
200 timeptr->tm_yday = 0;
201 }
202}
203
204/*
205 *
206 */
207
208char *
209strptime (const char *buf, const char *format, struct tm *timeptr)
40{210{
41 char c;211 char c;
42 const char *bp;212
43 size_t len = 0;213 for (; (c = *format) != '\0'; ++format) {
44 int alt_format, i, split_year = 0;214 char *s;
45 215 int ret;
46 bp = buf;216
47217 if (isspace (c)) {
48 while ((c = *fmt) != '\0') 218 while (isspace (*buf))
49 {219 ++buf;
50 /* Clear `alternate' modifier prior to new conversion. */220 } else if (c == '%' && format[1] != '\0') {
51 alt_format = 0;221 c = *++format;
52 222 if (c == 'E' || c == 'O')
53 /* Eat up white-space. */223 c = *++format;
54 if (isspace(c)) 224 switch (c) {
55 {225 case 'A' :
56 while (isspace(*bp))226 ret = match_string (&buf, full_weekdays);
57 bp++;227 if (ret < 0)
58 228 return NULL;
59 fmt++;229 timeptr->tm_wday = ret;
60 continue;230 break;
61 }231 case 'a' :
62 232 ret = match_string (&buf, abb_weekdays);
63 if ((c = *fmt++) != '%')233 if (ret < 0)
64 goto literal;234 return NULL;
65 235 timeptr->tm_wday = ret;
66 236 break;
67again: switch (c = *fmt++) 237 case 'B' :
68 {238 ret = match_string (&buf, full_month);
69 case '%': /* "%%" is converted to "%". */239 if (ret < 0)
70 literal:240 return NULL;
71 if (c != *bp++)241 timeptr->tm_mon = ret;
72 return (0);242 break;
73 break;243 case 'b' :
74 244 case 'h' :
75 /* 245 ret = match_string (&buf, abb_month);
76 * "Alternative" modifiers. Just set the appropriate flag246 if (ret < 0)
77 * and start over again.247 return NULL;
78 */248 timeptr->tm_mon = ret;
79 case 'E': /* "%E?" alternative conversion modifier. */249 break;
80 LEGAL_ALT(0);250 case 'C' :
81 alt_format |= ALT_E;251 ret = strtol (buf, &s, 10);
82 goto again;252 if (s == buf)
83 253 return NULL;
84 case 'O': /* "%O?" alternative conversion modifier. */254 timeptr->tm_year = (ret * 100) - tm_year_base;
85 LEGAL_ALT(0);255 buf = s;
86 alt_format |= ALT_O;256 break;
87 goto again;257 case 'c' :
88 258 abort ();
89 /*259 case 'D' : /* %m/%d/%y */
90 * "Complex" conversion rules, implemented through recursion.260 s = strptime (buf, "%m/%d/%y", timeptr);
91 */261 if (s == NULL)
92 case 'c': /* Date and time, using the locale's format. */262 return NULL;
93 LEGAL_ALT(ALT_E);263 buf = s;
94 if (!(bp = strptime(bp, "%x %X", tm)))264 break;
95 return (0);265 case 'd' :
96 break;266 case 'e' :
97 267 ret = strtol (buf, &s, 10);
98 case 'D': /* The date as "%m/%d/%y". */268 if (s == buf)
99 LEGAL_ALT(0);269 return NULL;
100 if (!(bp = strptime(bp, "%m/%d/%y", tm)))270 timeptr->tm_mday = ret;
101 return (0);271 buf = s;
102 break;272 break;
103 273 case 'H' :
104 case 'R': /* The time as "%H:%M". */274 case 'k' :
105 LEGAL_ALT(0);275 ret = strtol (buf, &s, 10);
106 if (!(bp = strptime(bp, "%H:%M", tm)))276 if (s == buf)
107 return (0);277 return NULL;
108 break;278 timeptr->tm_hour = ret;
109 279 buf = s;
110 case 'r': /* The time in 12-hour clock representation. */280 break;
111 LEGAL_ALT(0);281 case 'I' :
112 if (!(bp = strptime(bp, "%I:%M:%S %p", tm)))282 case 'l' :
113 return (0);283 ret = strtol (buf, &s, 10);
114 break;284 if (s == buf)
115 285 return NULL;
116 case 'T': /* The time as "%H:%M:%S". */286 if (ret == 12)
117 LEGAL_ALT(0);287 timeptr->tm_hour = 0;
118 if (!(bp = strptime(bp, "%H:%M:%S", tm)))288 else
119 return (0);289 timeptr->tm_hour = ret;
120 break;290 buf = s;
121 291 break;
122 case 'X': /* The time, using the locale's format. */292 case 'j' :
123 LEGAL_ALT(ALT_E);293 ret = strtol (buf, &s, 10);
124 if (!(bp = strptime(bp, "%H:%M:%S", tm)))294 if (s == buf)
125 return (0);295 return NULL;
126 break;296 timeptr->tm_yday = ret - 1;
127 297 buf = s;
128 case 'x': /* The date, using the locale's format. */298 break;
129 LEGAL_ALT(ALT_E);299 case 'm' :
130 if (!(bp = strptime(bp, "%m/%d/%y", tm)))300 ret = strtol (buf, &s, 10);
131 return (0);301 if (s == buf)
132 break;302 return NULL;
133 303 timeptr->tm_mon = ret - 1;
134 /*304 buf = s;
135 * "Elementary" conversion rules.305 break;
136 */306 case 'M' :
137 case 'A': /* The day of week, using the locale's form. */307 ret = strtol (buf, &s, 10);
138 case 'a':308 if (s == buf)
139 LEGAL_ALT(0);309 return NULL;
140 for (i = 0; i < 7; i++) 310 timeptr->tm_min = ret;
141 {311 buf = s;
142 /* Full name. */312 break;
143 len = strlen(day[i]);313 case 'n' :
144 if (strncasecmp((char *)(day[i]), (char *)bp, len) == 0)314 if (*buf == '\n')
145 break;315 ++buf;
146 316 else
147 /* Abbreviated name. */317 return NULL;
148 len = strlen(abday[i]);318 break;
149 if (strncasecmp((char *)(abday[i]), (char *)bp, len) == 0)319 case 'p' :
150 break;320 ret = match_string (&buf, ampm);
151 }321 if (ret < 0)
152 322 return NULL;
153 /* Nothing matched. */323 if (timeptr->tm_hour == 0) {
154 if (i == 7)324 if (ret == 1)
155 return (0);325 timeptr->tm_hour = 12;
156 326 } else
157 tm->tm_wday = i;327 timeptr->tm_hour += 12;
158 bp += len;328 break;
159 break;329 case 'r' : /* %I:%M:%S %p */
160 330 s = strptime (buf, "%I:%M:%S %p", timeptr);
161 case 'B': /* The month, using the locale's form. */331 if (s == NULL)
162 case 'b':332 return NULL;
163 case 'h':333 buf = s;
164 LEGAL_ALT(0);334 break;
165 for (i = 0; i < 12; i++) 335 case 'R' : /* %H:%M */
166 {336 s = strptime (buf, "%H:%M", timeptr);
167 /* Full name. */337 if (s == NULL)
168338 return NULL;
169 len = strlen(mon[i]);339 buf = s;
170 if (strncasecmp((char *)(mon[i]), (char *)bp, len) == 0)340 break;
171 break;341 case 'S' :
172 342 ret = strtol (buf, &s, 10);
173 /* Abbreviated name. */343 if (s == buf)
174 len = strlen(abmon[i]);344 return NULL;
175 if (strncasecmp((char *)(abmon[i]),(char *) bp, len) == 0)345 timeptr->tm_sec = ret;
176 break;346 buf = s;
177 }347 break;
178 348 case 't' :
179 /* Nothing matched. */349 if (*buf == '\t')
180 if (i == 12)350 ++buf;
181 return (0);351 else
182 352 return NULL;
183 tm->tm_mon = i;353 break;
184 bp += len;354 case 'T' : /* %H:%M:%S */
185 break;355 case 'X' :
186 356 s = strptime (buf, "%H:%M:%S", timeptr);
187 case 'C': /* The century number. */357 if (s == NULL)
188 LEGAL_ALT(ALT_E);358 return NULL;
189 if (!(conv_num(&bp, &i, 0, 99)))359 buf = s;
190 return (0);360 break;
191 361 case 'u' :
192 if (split_year)362 ret = strtol (buf, &s, 10);
193 {363 if (s == buf)
194 tm->tm_year = (tm->tm_year % 100) + (i * 100);364 return NULL;
195 } else {365 timeptr->tm_wday = ret - 1;
196 tm->tm_year = i * 100;366 buf = s;
197 split_year = 1;367 break;
198 }368 case 'w' :
199 break;369 ret = strtol (buf, &s, 10);
200 370 if (s == buf)
201 case 'd': /* The day of month. */371 return NULL;
202 case 'e':372 timeptr->tm_wday = ret;
203 LEGAL_ALT(ALT_O);373 buf = s;
204 if (!(conv_num(&bp, &tm->tm_mday, 1, 31)))374 break;
205 return (0);375 case 'U' :
206 break;376 ret = strtol (buf, &s, 10);
207 377 if (s == buf)
208 case 'k': /* The hour (24-hour clock representation). */378 return NULL;
209 LEGAL_ALT(0);379 set_week_number_sun (timeptr, ret);
210 /* FALLTHROUGH */380 buf = s;
211 case 'H':381 break;
212 LEGAL_ALT(ALT_O);382 case 'V' :
213 if (!(conv_num(&bp, &tm->tm_hour, 0, 23)))383 ret = strtol (buf, &s, 10);
214 return (0);384 if (s == buf)
215 break;385 return NULL;
216 386 set_week_number_mon4 (timeptr, ret);
217 case 'l': /* The hour (12-hour clock representation). */387 buf = s;
218 LEGAL_ALT(0);388 break;
219 /* FALLTHROUGH */389 case 'W' :
220 case 'I':390 ret = strtol (buf, &s, 10);
221 LEGAL_ALT(ALT_O);391 if (s == buf)
222 if (!(conv_num(&bp, &tm->tm_hour, 1, 12)))392 return NULL;
223 return (0);393 set_week_number_mon (timeptr, ret);
224 if (tm->tm_hour == 12)394 buf = s;
225 tm->tm_hour = 0;395 break;
226 break;396 case 'x' :
227 397 s = strptime (buf, "%Y:%m:%d", timeptr);
228 case 'j': /* The day of year. */398 if (s == NULL)
229 LEGAL_ALT(0);399 return NULL;
230 if (!(conv_num(&bp, &i, 1, 366)))400 buf = s;
231 return (0);401 break;
232 tm->tm_yday = i - 1;402 case 'y' :
233 break;403 ret = strtol (buf, &s, 10);
234 404 if (s == buf)
235 case 'M': /* The minute. */405 return NULL;
236 LEGAL_ALT(ALT_O);406 if (ret < 70)
237 if (!(conv_num(&bp, &tm->tm_min, 0, 59)))407 timeptr->tm_year = 100 + ret;
238 return (0);408 else
239 break;409 timeptr->tm_year = ret;
240 410 buf = s;
241 case 'm': /* The month. */411 break;
242 LEGAL_ALT(ALT_O);412 case 'Y' :
243 if (!(conv_num(&bp, &i, 1, 12)))413 ret = strtol (buf, &s, 10);
244 return (0);414 if (s == buf)
245 tm->tm_mon = i - 1;415 return NULL;
246 break;416 timeptr->tm_year = ret - tm_year_base;
247 417 buf = s;
248// case 'p': /* The locale's equivalent of AM/PM. */418 break;
249// LEGAL_ALT(0);419 case 'Z' :
250// /* AM? */420 abort ();
251// if (strcasecmp(am_pm[0], bp) == 0) 421 case '\0' :
252// {422 --format;
253// if (tm->tm_hour > 11)423 /* FALLTHROUGH */
254// return (0);424 case '%' :
255//425 if (*buf == '%')
256// bp += strlen(am_pm[0]);426 ++buf;
257// break;427 else
258// }428 return NULL;
259// /* PM? */429 break;
260// else if (strcasecmp(am_pm[1], bp) == 0) 430 default :
261// {431 if (*buf == '%' || *++buf == c)
262// if (tm->tm_hour > 11)432 ++buf;
263// return (0);433 else
264//434 return NULL;
265// tm->tm_hour += 12;435 break;
266// bp += strlen(am_pm[1]);436 }
267// break;437 } else {
268// }438 if (*buf == c)
269//439 ++buf;
270// /* Nothing matched. */440 else
271// return (0);441 return NULL;
272 442 }
273 case 'S': /* The seconds. */443 }
274 LEGAL_ALT(ALT_O);444 return (char *)buf;
275 if (!(conv_num(&bp, &tm->tm_sec, 0, 61)))445}
276 return (0);446
277 break;447#endif /* WIN32 */
278
279 case 'U': /* The week of year, beginning on sunday. */
280 case 'W': /* The week of year, beginning on monday. */
281 LEGAL_ALT(ALT_O);
282 /*
283 * XXX This is bogus, as we can not assume any valid
284 * information present in the tm structure at this
285 * point to calculate a real value, so just check the
286 * range for now.
287 */
288 if (!(conv_num(&bp, &i, 0, 53)))
289 return (0);
290 break;
291
292 case 'w': /* The day of week, beginning on sunday. */
293 LEGAL_ALT(ALT_O);
294 if (!(conv_num(&bp, &tm->tm_wday, 0, 6)))
295 return (0);
296 break;
297
298 case 'Y': /* The year. */
299 LEGAL_ALT(ALT_E);
300 if (!(conv_num(&bp, &i, 0, 9999)))
301 return (0);
302
303 tm->tm_year = i - TM_YEAR_BASE;
304 break;
305
306 case 'y': /* The year within 100 years of the epoch. */
307 LEGAL_ALT(ALT_E | ALT_O);
308 if (!(conv_num(&bp, &i, 0, 99)))
309 return (0);
310
311 if (split_year)
312 {
313 tm->tm_year = ((tm->tm_year / 100) * 100) + i;
314 break;
315 }
316 split_year = 1;
317 if (i <= 68)
318 tm->tm_year = i + 2000 - TM_YEAR_BASE;
319 else
320 tm->tm_year = i + 1900 - TM_YEAR_BASE;
321 break;
322
323 /*
324 * Miscellaneous conversions.
325 */
326 case 'n': /* Any kind of white-space. */
327 case 't':
328 LEGAL_ALT(0);
329 while (isspace(*bp))
330 bp++;
331 break;
332
333
334 default: /* Unknown/unsupported conversion. */
335 return (0);
336 }
337
338
339 }
340
341 /* LINTED functional specification */
342 return ((char *)bp);
343}
344
345
346static int conv_num(const char **buf, int *dest, int llim, int ulim)
347{
348 int result = 0;
349
350 /* The limit also determines the number of valid digits. */
351 int rulim = ulim;
352
353 if (**buf < '0' || **buf > '9')
354 return (0);
355
356 do {
357 result *= 10;
358 result += *(*buf)++ - '0';
359 rulim /= 10;
360 } while ((result * 10 <= ulim) && rulim && **buf >= '0' && **buf <= '9');
361
362 if (result < llim || result > ulim)
363 return (0);
364
365 *dest = result;
366 return (1);
367}
368
369int strncasecmp(char *s1, char *s2, size_t n)
370{
371 if (n == 0)
372 return 0;
373
374 while (n-- != 0 && tolower(*s1) == tolower(*s2))
375 {
376 if (n == 0 || *s1 == '\0' || *s2 == '\0')
377 break;
378 s1++;
379 s2++;
380 }
381
382 return tolower(*(unsigned char *) s1) - tolower(*(unsigned char *) s2);
383}
384 448
385\ No newline at end of file449\ No newline at end of file

Subscribers

People subscribed via source and target branches

to all changes: