annotate src/protocols/msn/msn-utils.c @ 19794:b22d13f55232

[gaim-migrate @ 16684] change the code of SOAP Action,Now using a stupid way to do the soap, wish to implement it in a clean way! borrow a strptime to parse the timestamp received from MSN Server. committed by MaYuan<mayuan2006@gmail.com> committer: Ethan Blanton <elb@pidgin.im>
author Ma Yuan <mayuan2006@gmail.com>
date Thu, 10 Aug 2006 04:38:13 +0000
parents 8b4653986e8e
children a8d00b8dae40
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
13627
3cfdf1653a64 [gaim-migrate @ 16014]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
1 /**
3cfdf1653a64 [gaim-migrate @ 16014]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
2 * @file msn-utils.c Utility functions
3cfdf1653a64 [gaim-migrate @ 16014]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
3 *
3cfdf1653a64 [gaim-migrate @ 16014]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
4 * gaim
3cfdf1653a64 [gaim-migrate @ 16014]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
5 *
3cfdf1653a64 [gaim-migrate @ 16014]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
6 * Gaim is the legal property of its developers, whose names are too numerous
3cfdf1653a64 [gaim-migrate @ 16014]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
7 * to list here. Please refer to the COPYRIGHT file distributed with this
3cfdf1653a64 [gaim-migrate @ 16014]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
8 * source distribution.
3cfdf1653a64 [gaim-migrate @ 16014]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
9 *
3cfdf1653a64 [gaim-migrate @ 16014]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
10 * This program is free software; you can redistribute it and/or modify
3cfdf1653a64 [gaim-migrate @ 16014]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
11 * it under the terms of the GNU General Public License as published by
3cfdf1653a64 [gaim-migrate @ 16014]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
12 * the Free Software Foundation; either version 2 of the License, or
3cfdf1653a64 [gaim-migrate @ 16014]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
13 * (at your option) any later version.
3cfdf1653a64 [gaim-migrate @ 16014]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
14 *
3cfdf1653a64 [gaim-migrate @ 16014]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
15 * This program is distributed in the hope that it will be useful,
3cfdf1653a64 [gaim-migrate @ 16014]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
16 * but WITHOUT ANY WARRANTY; without even the implied warranty of
3cfdf1653a64 [gaim-migrate @ 16014]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
3cfdf1653a64 [gaim-migrate @ 16014]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
18 * GNU General Public License for more details.
3cfdf1653a64 [gaim-migrate @ 16014]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
19 *
3cfdf1653a64 [gaim-migrate @ 16014]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
20 * You should have received a copy of the GNU General Public License
3cfdf1653a64 [gaim-migrate @ 16014]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
21 * along with this program; if not, write to the Free Software
3cfdf1653a64 [gaim-migrate @ 16014]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
22 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
3cfdf1653a64 [gaim-migrate @ 16014]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
23 */
3cfdf1653a64 [gaim-migrate @ 16014]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
24 #include "msn.h"
3cfdf1653a64 [gaim-migrate @ 16014]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
25 #include "msn-utils.h"
19794
b22d13f55232 [gaim-migrate @ 16684]
Ma Yuan <mayuan2006@gmail.com>
parents: 19788
diff changeset
26 #include "time.h"
19785
852b32710df0 [gaim-migrate @ 16507]
Ma Yuan <mayuan2006@gmail.com>
parents: 19784
diff changeset
27 //#include <openssl/md5.h>
13627
3cfdf1653a64 [gaim-migrate @ 16014]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
28
3cfdf1653a64 [gaim-migrate @ 16014]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
29 void
3cfdf1653a64 [gaim-migrate @ 16014]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
30 msn_parse_format(const char *mime, char **pre_ret, char **post_ret)
3cfdf1653a64 [gaim-migrate @ 16014]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
31 {
3cfdf1653a64 [gaim-migrate @ 16014]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
32 char *cur;
3cfdf1653a64 [gaim-migrate @ 16014]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
33 GString *pre = g_string_new(NULL);
3cfdf1653a64 [gaim-migrate @ 16014]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
34 GString *post = g_string_new(NULL);
3cfdf1653a64 [gaim-migrate @ 16014]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
35 unsigned int colors[3];
3cfdf1653a64 [gaim-migrate @ 16014]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
36
3cfdf1653a64 [gaim-migrate @ 16014]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
37 if (pre_ret != NULL) *pre_ret = NULL;
3cfdf1653a64 [gaim-migrate @ 16014]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
38 if (post_ret != NULL) *post_ret = NULL;
3cfdf1653a64 [gaim-migrate @ 16014]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
39
3cfdf1653a64 [gaim-migrate @ 16014]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
40 cur = strstr(mime, "FN=");
3cfdf1653a64 [gaim-migrate @ 16014]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
41
3cfdf1653a64 [gaim-migrate @ 16014]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
42 if (cur && (*(cur = cur + 3) != ';'))
3cfdf1653a64 [gaim-migrate @ 16014]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
43 {
3cfdf1653a64 [gaim-migrate @ 16014]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
44 pre = g_string_append(pre, "<FONT FACE=\"");
3cfdf1653a64 [gaim-migrate @ 16014]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
45
3cfdf1653a64 [gaim-migrate @ 16014]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
46 while (*cur && *cur != ';')
3cfdf1653a64 [gaim-migrate @ 16014]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
47 {
3cfdf1653a64 [gaim-migrate @ 16014]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
48 pre = g_string_append_c(pre, *cur);
3cfdf1653a64 [gaim-migrate @ 16014]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
49 cur++;
3cfdf1653a64 [gaim-migrate @ 16014]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
50 }
3cfdf1653a64 [gaim-migrate @ 16014]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
51
3cfdf1653a64 [gaim-migrate @ 16014]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
52 pre = g_string_append(pre, "\">");
3cfdf1653a64 [gaim-migrate @ 16014]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
53 post = g_string_prepend(post, "</FONT>");
3cfdf1653a64 [gaim-migrate @ 16014]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
54 }
3cfdf1653a64 [gaim-migrate @ 16014]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
55
3cfdf1653a64 [gaim-migrate @ 16014]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
56 cur = strstr(mime, "EF=");
3cfdf1653a64 [gaim-migrate @ 16014]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
57
3cfdf1653a64 [gaim-migrate @ 16014]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
58 if (cur && (*(cur = cur + 3) != ';'))
3cfdf1653a64 [gaim-migrate @ 16014]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
59 {
3cfdf1653a64 [gaim-migrate @ 16014]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
60 while (*cur && *cur != ';')
3cfdf1653a64 [gaim-migrate @ 16014]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
61 {
3cfdf1653a64 [gaim-migrate @ 16014]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
62 pre = g_string_append_c(pre, '<');
3cfdf1653a64 [gaim-migrate @ 16014]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
63 pre = g_string_append_c(pre, *cur);
3cfdf1653a64 [gaim-migrate @ 16014]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
64 pre = g_string_append_c(pre, '>');
3cfdf1653a64 [gaim-migrate @ 16014]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
65 post = g_string_prepend_c(post, '>');
3cfdf1653a64 [gaim-migrate @ 16014]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
66 post = g_string_prepend_c(post, *cur);
3cfdf1653a64 [gaim-migrate @ 16014]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
67 post = g_string_prepend_c(post, '/');
3cfdf1653a64 [gaim-migrate @ 16014]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
68 post = g_string_prepend_c(post, '<');
3cfdf1653a64 [gaim-migrate @ 16014]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
69 cur++;
3cfdf1653a64 [gaim-migrate @ 16014]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
70 }
3cfdf1653a64 [gaim-migrate @ 16014]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
71 }
3cfdf1653a64 [gaim-migrate @ 16014]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
72
3cfdf1653a64 [gaim-migrate @ 16014]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
73 cur = strstr(mime, "CO=");
3cfdf1653a64 [gaim-migrate @ 16014]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
74
3cfdf1653a64 [gaim-migrate @ 16014]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
75 if (cur && (*(cur = cur + 3) != ';'))
3cfdf1653a64 [gaim-migrate @ 16014]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
76 {
3cfdf1653a64 [gaim-migrate @ 16014]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
77 int i;
3cfdf1653a64 [gaim-migrate @ 16014]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
78
3cfdf1653a64 [gaim-migrate @ 16014]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
79 i = sscanf(cur, "%02x%02x%02x;", &colors[0], &colors[1], &colors[2]);
3cfdf1653a64 [gaim-migrate @ 16014]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
80
3cfdf1653a64 [gaim-migrate @ 16014]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
81 if (i > 0)
3cfdf1653a64 [gaim-migrate @ 16014]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
82 {
3cfdf1653a64 [gaim-migrate @ 16014]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
83 char tag[64];
3cfdf1653a64 [gaim-migrate @ 16014]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
84
3cfdf1653a64 [gaim-migrate @ 16014]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
85 if (i == 1)
3cfdf1653a64 [gaim-migrate @ 16014]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
86 {
3cfdf1653a64 [gaim-migrate @ 16014]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
87 colors[1] = 0;
3cfdf1653a64 [gaim-migrate @ 16014]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
88 colors[2] = 0;
3cfdf1653a64 [gaim-migrate @ 16014]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
89 }
3cfdf1653a64 [gaim-migrate @ 16014]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
90 else if (i == 2)
3cfdf1653a64 [gaim-migrate @ 16014]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
91 {
3cfdf1653a64 [gaim-migrate @ 16014]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
92 unsigned int temp = colors[0];
3cfdf1653a64 [gaim-migrate @ 16014]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
93
3cfdf1653a64 [gaim-migrate @ 16014]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
94 colors[0] = colors[1];
3cfdf1653a64 [gaim-migrate @ 16014]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
95 colors[1] = temp;
3cfdf1653a64 [gaim-migrate @ 16014]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
96 colors[2] = 0;
3cfdf1653a64 [gaim-migrate @ 16014]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
97 }
3cfdf1653a64 [gaim-migrate @ 16014]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
98 else if (i == 3)
3cfdf1653a64 [gaim-migrate @ 16014]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
99 {
3cfdf1653a64 [gaim-migrate @ 16014]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
100 unsigned int temp = colors[2];
3cfdf1653a64 [gaim-migrate @ 16014]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
101
3cfdf1653a64 [gaim-migrate @ 16014]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
102 colors[2] = colors[0];
3cfdf1653a64 [gaim-migrate @ 16014]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
103 colors[0] = temp;
3cfdf1653a64 [gaim-migrate @ 16014]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
104 }
3cfdf1653a64 [gaim-migrate @ 16014]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
105
3cfdf1653a64 [gaim-migrate @ 16014]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
106 g_snprintf(tag, sizeof(tag),
3cfdf1653a64 [gaim-migrate @ 16014]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
107 "<FONT COLOR=\"#%02hhx%02hhx%02hhx\">",
3cfdf1653a64 [gaim-migrate @ 16014]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
108 colors[0], colors[1], colors[2]);
3cfdf1653a64 [gaim-migrate @ 16014]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
109
3cfdf1653a64 [gaim-migrate @ 16014]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
110 pre = g_string_append(pre, tag);
3cfdf1653a64 [gaim-migrate @ 16014]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
111 post = g_string_prepend(post, "</FONT>");
3cfdf1653a64 [gaim-migrate @ 16014]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
112 }
3cfdf1653a64 [gaim-migrate @ 16014]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
113 }
3cfdf1653a64 [gaim-migrate @ 16014]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
114
3cfdf1653a64 [gaim-migrate @ 16014]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
115 cur = g_strdup(gaim_url_decode(pre->str));
3cfdf1653a64 [gaim-migrate @ 16014]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
116 g_string_free(pre, TRUE);
3cfdf1653a64 [gaim-migrate @ 16014]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
117
3cfdf1653a64 [gaim-migrate @ 16014]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
118 if (pre_ret != NULL)
3cfdf1653a64 [gaim-migrate @ 16014]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
119 *pre_ret = cur;
3cfdf1653a64 [gaim-migrate @ 16014]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
120 else
3cfdf1653a64 [gaim-migrate @ 16014]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
121 g_free(cur);
3cfdf1653a64 [gaim-migrate @ 16014]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
122
3cfdf1653a64 [gaim-migrate @ 16014]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
123 cur = g_strdup(gaim_url_decode(post->str));
3cfdf1653a64 [gaim-migrate @ 16014]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
124 g_string_free(post, TRUE);
3cfdf1653a64 [gaim-migrate @ 16014]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
125
3cfdf1653a64 [gaim-migrate @ 16014]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
126 if (post_ret != NULL)
3cfdf1653a64 [gaim-migrate @ 16014]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
127 *post_ret = cur;
3cfdf1653a64 [gaim-migrate @ 16014]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
128 else
3cfdf1653a64 [gaim-migrate @ 16014]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
129 g_free(cur);
3cfdf1653a64 [gaim-migrate @ 16014]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
130 }
3cfdf1653a64 [gaim-migrate @ 16014]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
131
3cfdf1653a64 [gaim-migrate @ 16014]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
132 /*
3cfdf1653a64 [gaim-migrate @ 16014]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
133 * We need this because we're only supposed to encode spaces in the font
3cfdf1653a64 [gaim-migrate @ 16014]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
134 * names. gaim_url_encode() isn't acceptable.
3cfdf1653a64 [gaim-migrate @ 16014]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
135 */
3cfdf1653a64 [gaim-migrate @ 16014]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
136 static const char *
3cfdf1653a64 [gaim-migrate @ 16014]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
137 encode_spaces(const char *str)
3cfdf1653a64 [gaim-migrate @ 16014]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
138 {
3cfdf1653a64 [gaim-migrate @ 16014]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
139 static char buf[BUF_LEN];
3cfdf1653a64 [gaim-migrate @ 16014]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
140 const char *c;
3cfdf1653a64 [gaim-migrate @ 16014]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
141 char *d;
3cfdf1653a64 [gaim-migrate @ 16014]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
142
3cfdf1653a64 [gaim-migrate @ 16014]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
143 g_return_val_if_fail(str != NULL, NULL);
3cfdf1653a64 [gaim-migrate @ 16014]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
144
3cfdf1653a64 [gaim-migrate @ 16014]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
145 for (c = str, d = buf; *c != '\0'; c++)
3cfdf1653a64 [gaim-migrate @ 16014]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
146 {
3cfdf1653a64 [gaim-migrate @ 16014]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
147 if (*c == ' ')
3cfdf1653a64 [gaim-migrate @ 16014]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
148 {
3cfdf1653a64 [gaim-migrate @ 16014]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
149 *d++ = '%';
3cfdf1653a64 [gaim-migrate @ 16014]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
150 *d++ = '2';
3cfdf1653a64 [gaim-migrate @ 16014]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
151 *d++ = '0';
3cfdf1653a64 [gaim-migrate @ 16014]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
152 }
3cfdf1653a64 [gaim-migrate @ 16014]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
153 else
3cfdf1653a64 [gaim-migrate @ 16014]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
154 *d++ = *c;
3cfdf1653a64 [gaim-migrate @ 16014]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
155 }
3cfdf1653a64 [gaim-migrate @ 16014]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
156
3cfdf1653a64 [gaim-migrate @ 16014]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
157 return buf;
3cfdf1653a64 [gaim-migrate @ 16014]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
158 }
3cfdf1653a64 [gaim-migrate @ 16014]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
159
3cfdf1653a64 [gaim-migrate @ 16014]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
160 /*
3cfdf1653a64 [gaim-migrate @ 16014]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
161 * Taken from the zephyr plugin.
3cfdf1653a64 [gaim-migrate @ 16014]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
162 * This parses HTML formatting (put out by one of the gtkimhtml widgets
3cfdf1653a64 [gaim-migrate @ 16014]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
163 * and converts it to msn formatting. It doesn't deal with the tag closing,
3cfdf1653a64 [gaim-migrate @ 16014]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
164 * but gtkimhtml widgets give valid html.
3cfdf1653a64 [gaim-migrate @ 16014]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
165 * It currently deals properly with <b>, <u>, <i>, <font face=...>,
3cfdf1653a64 [gaim-migrate @ 16014]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
166 * <font color=...>.
3cfdf1653a64 [gaim-migrate @ 16014]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
167 * It ignores <font back=...> and <font size=...>
3cfdf1653a64 [gaim-migrate @ 16014]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
168 */
3cfdf1653a64 [gaim-migrate @ 16014]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
169 void
3cfdf1653a64 [gaim-migrate @ 16014]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
170 msn_import_html(const char *html, char **attributes, char **message)
3cfdf1653a64 [gaim-migrate @ 16014]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
171 {
3cfdf1653a64 [gaim-migrate @ 16014]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
172 int len, retcount = 0;
3cfdf1653a64 [gaim-migrate @ 16014]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
173 const char *c;
3cfdf1653a64 [gaim-migrate @ 16014]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
174 char *msg;
3cfdf1653a64 [gaim-migrate @ 16014]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
175 char *fontface = NULL;
3cfdf1653a64 [gaim-migrate @ 16014]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
176 char fonteffect[4];
3cfdf1653a64 [gaim-migrate @ 16014]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
177 char fontcolor[7];
3cfdf1653a64 [gaim-migrate @ 16014]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
178
3cfdf1653a64 [gaim-migrate @ 16014]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
179 g_return_if_fail(html != NULL);
3cfdf1653a64 [gaim-migrate @ 16014]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
180 g_return_if_fail(attributes != NULL);
3cfdf1653a64 [gaim-migrate @ 16014]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
181 g_return_if_fail(message != NULL);
3cfdf1653a64 [gaim-migrate @ 16014]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
182
3cfdf1653a64 [gaim-migrate @ 16014]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
183 len = strlen(html);
3cfdf1653a64 [gaim-migrate @ 16014]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
184 msg = g_malloc0(len + 1);
3cfdf1653a64 [gaim-migrate @ 16014]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
185
3cfdf1653a64 [gaim-migrate @ 16014]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
186 memset(fontcolor, 0, sizeof(fontcolor));
3cfdf1653a64 [gaim-migrate @ 16014]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
187 strcat(fontcolor, "0");
3cfdf1653a64 [gaim-migrate @ 16014]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
188 memset(fonteffect, 0, sizeof(fonteffect));
3cfdf1653a64 [gaim-migrate @ 16014]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
189
3cfdf1653a64 [gaim-migrate @ 16014]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
190 for (c = html; *c != '\0';)
3cfdf1653a64 [gaim-migrate @ 16014]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
191 {
3cfdf1653a64 [gaim-migrate @ 16014]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
192 if (*c == '<')
3cfdf1653a64 [gaim-migrate @ 16014]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
193 {
3cfdf1653a64 [gaim-migrate @ 16014]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
194 if (!g_ascii_strncasecmp(c + 1, "br>", 3))
3cfdf1653a64 [gaim-migrate @ 16014]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
195 {
3cfdf1653a64 [gaim-migrate @ 16014]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
196 msg[retcount++] = '\r';
3cfdf1653a64 [gaim-migrate @ 16014]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
197 msg[retcount++] = '\n';
3cfdf1653a64 [gaim-migrate @ 16014]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
198 c += 4;
3cfdf1653a64 [gaim-migrate @ 16014]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
199 }
3cfdf1653a64 [gaim-migrate @ 16014]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
200 else if (!g_ascii_strncasecmp(c + 1, "i>", 2))
3cfdf1653a64 [gaim-migrate @ 16014]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
201 {
3cfdf1653a64 [gaim-migrate @ 16014]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
202 strcat(fonteffect, "I");
3cfdf1653a64 [gaim-migrate @ 16014]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
203 c += 3;
3cfdf1653a64 [gaim-migrate @ 16014]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
204 }
3cfdf1653a64 [gaim-migrate @ 16014]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
205 else if (!g_ascii_strncasecmp(c + 1, "b>", 2))
3cfdf1653a64 [gaim-migrate @ 16014]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
206 {
3cfdf1653a64 [gaim-migrate @ 16014]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
207 strcat(fonteffect, "B");
3cfdf1653a64 [gaim-migrate @ 16014]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
208 c += 3;
3cfdf1653a64 [gaim-migrate @ 16014]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
209 }
3cfdf1653a64 [gaim-migrate @ 16014]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
210 else if (!g_ascii_strncasecmp(c + 1, "u>", 2))
3cfdf1653a64 [gaim-migrate @ 16014]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
211 {
3cfdf1653a64 [gaim-migrate @ 16014]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
212 strcat(fonteffect, "U");
3cfdf1653a64 [gaim-migrate @ 16014]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
213 c += 3;
3cfdf1653a64 [gaim-migrate @ 16014]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
214 }
3cfdf1653a64 [gaim-migrate @ 16014]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
215 else if (!g_ascii_strncasecmp(c + 1, "s>", 2))
3cfdf1653a64 [gaim-migrate @ 16014]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
216 {
3cfdf1653a64 [gaim-migrate @ 16014]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
217 strcat(fonteffect, "S");
3cfdf1653a64 [gaim-migrate @ 16014]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
218 c += 3;
3cfdf1653a64 [gaim-migrate @ 16014]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
219 }
3cfdf1653a64 [gaim-migrate @ 16014]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
220 else if (!g_ascii_strncasecmp(c + 1, "a href=\"", 8))
3cfdf1653a64 [gaim-migrate @ 16014]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
221 {
3cfdf1653a64 [gaim-migrate @ 16014]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
222 c += 9;
3cfdf1653a64 [gaim-migrate @ 16014]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
223
3cfdf1653a64 [gaim-migrate @ 16014]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
224 if (!g_ascii_strncasecmp(c, "mailto:", 7))
3cfdf1653a64 [gaim-migrate @ 16014]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
225 c += 7;
3cfdf1653a64 [gaim-migrate @ 16014]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
226
3cfdf1653a64 [gaim-migrate @ 16014]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
227 while ((*c != '\0') && g_ascii_strncasecmp(c, "\">", 2))
3cfdf1653a64 [gaim-migrate @ 16014]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
228 msg[retcount++] = *c++;
3cfdf1653a64 [gaim-migrate @ 16014]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
229
3cfdf1653a64 [gaim-migrate @ 16014]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
230 if (*c != '\0')
3cfdf1653a64 [gaim-migrate @ 16014]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
231 c += 2;
3cfdf1653a64 [gaim-migrate @ 16014]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
232
3cfdf1653a64 [gaim-migrate @ 16014]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
233 /* ignore descriptive string */
3cfdf1653a64 [gaim-migrate @ 16014]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
234 while ((*c != '\0') && g_ascii_strncasecmp(c, "</a>", 4))
3cfdf1653a64 [gaim-migrate @ 16014]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
235 c++;
3cfdf1653a64 [gaim-migrate @ 16014]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
236
3cfdf1653a64 [gaim-migrate @ 16014]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
237 if (*c != '\0')
3cfdf1653a64 [gaim-migrate @ 16014]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
238 c += 4;
3cfdf1653a64 [gaim-migrate @ 16014]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
239 }
3cfdf1653a64 [gaim-migrate @ 16014]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
240 else if (!g_ascii_strncasecmp(c + 1, "font", 4))
3cfdf1653a64 [gaim-migrate @ 16014]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
241 {
3cfdf1653a64 [gaim-migrate @ 16014]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
242 c += 5;
3cfdf1653a64 [gaim-migrate @ 16014]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
243
3cfdf1653a64 [gaim-migrate @ 16014]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
244 while ((*c != '\0') && !g_ascii_strncasecmp(c, " ", 1))
3cfdf1653a64 [gaim-migrate @ 16014]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
245 c++;
3cfdf1653a64 [gaim-migrate @ 16014]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
246
3cfdf1653a64 [gaim-migrate @ 16014]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
247 if (!g_ascii_strncasecmp(c, "color=\"#", 7))
3cfdf1653a64 [gaim-migrate @ 16014]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
248 {
3cfdf1653a64 [gaim-migrate @ 16014]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
249 c += 8;
3cfdf1653a64 [gaim-migrate @ 16014]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
250
3cfdf1653a64 [gaim-migrate @ 16014]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
251 fontcolor[0] = *(c + 4);
3cfdf1653a64 [gaim-migrate @ 16014]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
252 fontcolor[1] = *(c + 5);
3cfdf1653a64 [gaim-migrate @ 16014]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
253 fontcolor[2] = *(c + 2);
3cfdf1653a64 [gaim-migrate @ 16014]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
254 fontcolor[3] = *(c + 3);
3cfdf1653a64 [gaim-migrate @ 16014]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
255 fontcolor[4] = *c;
3cfdf1653a64 [gaim-migrate @ 16014]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
256 fontcolor[5] = *(c + 1);
3cfdf1653a64 [gaim-migrate @ 16014]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
257
3cfdf1653a64 [gaim-migrate @ 16014]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
258 c += 8;
3cfdf1653a64 [gaim-migrate @ 16014]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
259 }
3cfdf1653a64 [gaim-migrate @ 16014]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
260 else if (!g_ascii_strncasecmp(c, "face=\"", 6))
3cfdf1653a64 [gaim-migrate @ 16014]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
261 {
3cfdf1653a64 [gaim-migrate @ 16014]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
262 const char *end = NULL;
3cfdf1653a64 [gaim-migrate @ 16014]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
263 const char *comma = NULL;
3cfdf1653a64 [gaim-migrate @ 16014]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
264 unsigned int namelen = 0;
3cfdf1653a64 [gaim-migrate @ 16014]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
265
3cfdf1653a64 [gaim-migrate @ 16014]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
266 c += 6;
3cfdf1653a64 [gaim-migrate @ 16014]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
267 end = strchr(c, '\"');
3cfdf1653a64 [gaim-migrate @ 16014]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
268 comma = strchr(c, ',');
3cfdf1653a64 [gaim-migrate @ 16014]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
269
3cfdf1653a64 [gaim-migrate @ 16014]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
270 if (comma == NULL || comma > end)
3cfdf1653a64 [gaim-migrate @ 16014]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
271 namelen = (unsigned int)(end - c);
3cfdf1653a64 [gaim-migrate @ 16014]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
272 else
3cfdf1653a64 [gaim-migrate @ 16014]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
273 namelen = (unsigned int)(comma - c);
3cfdf1653a64 [gaim-migrate @ 16014]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
274
3cfdf1653a64 [gaim-migrate @ 16014]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
275 fontface = g_strndup(c, namelen);
3cfdf1653a64 [gaim-migrate @ 16014]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
276 c = end + 2;
3cfdf1653a64 [gaim-migrate @ 16014]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
277 }
3cfdf1653a64 [gaim-migrate @ 16014]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
278 else
3cfdf1653a64 [gaim-migrate @ 16014]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
279 {
3cfdf1653a64 [gaim-migrate @ 16014]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
280 /* Drop all unrecognized/misparsed font tags */
3cfdf1653a64 [gaim-migrate @ 16014]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
281 while ((*c != '\0') && g_ascii_strncasecmp(c, "\">", 2))
3cfdf1653a64 [gaim-migrate @ 16014]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
282 c++;
3cfdf1653a64 [gaim-migrate @ 16014]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
283
3cfdf1653a64 [gaim-migrate @ 16014]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
284 if (*c != '\0')
3cfdf1653a64 [gaim-migrate @ 16014]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
285 c += 2;
3cfdf1653a64 [gaim-migrate @ 16014]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
286 }
3cfdf1653a64 [gaim-migrate @ 16014]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
287 }
3cfdf1653a64 [gaim-migrate @ 16014]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
288 else
3cfdf1653a64 [gaim-migrate @ 16014]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
289 {
3cfdf1653a64 [gaim-migrate @ 16014]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
290 while ((*c != '\0') && (*c != '>'))
3cfdf1653a64 [gaim-migrate @ 16014]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
291 c++;
3cfdf1653a64 [gaim-migrate @ 16014]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
292 if (*c != '\0')
3cfdf1653a64 [gaim-migrate @ 16014]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
293 c++;
3cfdf1653a64 [gaim-migrate @ 16014]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
294 }
3cfdf1653a64 [gaim-migrate @ 16014]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
295 }
3cfdf1653a64 [gaim-migrate @ 16014]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
296 else if (*c == '&')
3cfdf1653a64 [gaim-migrate @ 16014]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
297 {
3cfdf1653a64 [gaim-migrate @ 16014]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
298 if (!g_ascii_strncasecmp(c, "&lt;", 4))
3cfdf1653a64 [gaim-migrate @ 16014]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
299 {
3cfdf1653a64 [gaim-migrate @ 16014]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
300 msg[retcount++] = '<';
3cfdf1653a64 [gaim-migrate @ 16014]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
301 c += 4;
3cfdf1653a64 [gaim-migrate @ 16014]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
302 }
3cfdf1653a64 [gaim-migrate @ 16014]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
303 else if (!g_ascii_strncasecmp(c, "&gt;", 4))
3cfdf1653a64 [gaim-migrate @ 16014]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
304 {
3cfdf1653a64 [gaim-migrate @ 16014]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
305 msg[retcount++] = '>';
3cfdf1653a64 [gaim-migrate @ 16014]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
306 c += 4;
3cfdf1653a64 [gaim-migrate @ 16014]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
307 }
3cfdf1653a64 [gaim-migrate @ 16014]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
308 else if (!g_ascii_strncasecmp(c, "&nbsp;", 6))
3cfdf1653a64 [gaim-migrate @ 16014]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
309 {
3cfdf1653a64 [gaim-migrate @ 16014]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
310 msg[retcount++] = ' ';
3cfdf1653a64 [gaim-migrate @ 16014]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
311 c += 6;
3cfdf1653a64 [gaim-migrate @ 16014]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
312 }
3cfdf1653a64 [gaim-migrate @ 16014]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
313 else if (!g_ascii_strncasecmp(c, "&quot;", 6))
3cfdf1653a64 [gaim-migrate @ 16014]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
314 {
3cfdf1653a64 [gaim-migrate @ 16014]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
315 msg[retcount++] = '"';
3cfdf1653a64 [gaim-migrate @ 16014]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
316 c += 6;
3cfdf1653a64 [gaim-migrate @ 16014]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
317 }
3cfdf1653a64 [gaim-migrate @ 16014]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
318 else if (!g_ascii_strncasecmp(c, "&amp;", 5))
3cfdf1653a64 [gaim-migrate @ 16014]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
319 {
3cfdf1653a64 [gaim-migrate @ 16014]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
320 msg[retcount++] = '&';
3cfdf1653a64 [gaim-migrate @ 16014]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
321 c += 5;
3cfdf1653a64 [gaim-migrate @ 16014]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
322 }
3cfdf1653a64 [gaim-migrate @ 16014]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
323 else if (!g_ascii_strncasecmp(c, "&apos;", 6))
3cfdf1653a64 [gaim-migrate @ 16014]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
324 {
3cfdf1653a64 [gaim-migrate @ 16014]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
325 msg[retcount++] = '\'';
3cfdf1653a64 [gaim-migrate @ 16014]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
326 c += 6;
3cfdf1653a64 [gaim-migrate @ 16014]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
327 }
3cfdf1653a64 [gaim-migrate @ 16014]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
328 else
3cfdf1653a64 [gaim-migrate @ 16014]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
329 msg[retcount++] = *c++;
3cfdf1653a64 [gaim-migrate @ 16014]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
330 }
3cfdf1653a64 [gaim-migrate @ 16014]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
331 else
3cfdf1653a64 [gaim-migrate @ 16014]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
332 msg[retcount++] = *c++;
3cfdf1653a64 [gaim-migrate @ 16014]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
333 }
3cfdf1653a64 [gaim-migrate @ 16014]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
334
3cfdf1653a64 [gaim-migrate @ 16014]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
335 if (fontface == NULL)
3cfdf1653a64 [gaim-migrate @ 16014]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
336 fontface = g_strdup("MS Sans Serif");
3cfdf1653a64 [gaim-migrate @ 16014]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
337
3cfdf1653a64 [gaim-migrate @ 16014]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
338 *attributes = g_strdup_printf("FN=%s; EF=%s; CO=%s; PF=0",
3cfdf1653a64 [gaim-migrate @ 16014]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
339 encode_spaces(fontface),
3cfdf1653a64 [gaim-migrate @ 16014]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
340 fonteffect, fontcolor);
3cfdf1653a64 [gaim-migrate @ 16014]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
341 *message = g_strdup(msg);
3cfdf1653a64 [gaim-migrate @ 16014]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
342
3cfdf1653a64 [gaim-migrate @ 16014]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
343 g_free(fontface);
3cfdf1653a64 [gaim-migrate @ 16014]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
344 g_free(msg);
3cfdf1653a64 [gaim-migrate @ 16014]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
345 }
3cfdf1653a64 [gaim-migrate @ 16014]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
346
3cfdf1653a64 [gaim-migrate @ 16014]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
347 void
3cfdf1653a64 [gaim-migrate @ 16014]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
348 msn_parse_socket(const char *str, char **ret_host, int *ret_port)
3cfdf1653a64 [gaim-migrate @ 16014]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
349 {
3cfdf1653a64 [gaim-migrate @ 16014]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
350 char *host;
3cfdf1653a64 [gaim-migrate @ 16014]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
351 char *c;
3cfdf1653a64 [gaim-migrate @ 16014]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
352 int port;
3cfdf1653a64 [gaim-migrate @ 16014]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
353
3cfdf1653a64 [gaim-migrate @ 16014]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
354 host = g_strdup(str);
3cfdf1653a64 [gaim-migrate @ 16014]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
355
19784
bc30c6270d9f [gaim-migrate @ 16473]
Ma Yuan <mayuan2006@gmail.com>
parents: 13627
diff changeset
356 if ((c = strchr(host, ':')) != NULL){
13627
3cfdf1653a64 [gaim-migrate @ 16014]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
357 *c = '\0';
3cfdf1653a64 [gaim-migrate @ 16014]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
358 port = atoi(c + 1);
19784
bc30c6270d9f [gaim-migrate @ 16473]
Ma Yuan <mayuan2006@gmail.com>
parents: 13627
diff changeset
359 }else{
bc30c6270d9f [gaim-migrate @ 16473]
Ma Yuan <mayuan2006@gmail.com>
parents: 13627
diff changeset
360 port = 1863;
13627
3cfdf1653a64 [gaim-migrate @ 16014]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
361 }
3cfdf1653a64 [gaim-migrate @ 16014]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
362
3cfdf1653a64 [gaim-migrate @ 16014]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
363 *ret_host = host;
3cfdf1653a64 [gaim-migrate @ 16014]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
364 *ret_port = port;
3cfdf1653a64 [gaim-migrate @ 16014]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
365 }
19794
b22d13f55232 [gaim-migrate @ 16684]
Ma Yuan <mayuan2006@gmail.com>
parents: 19788
diff changeset
366 /***************************************************************************
b22d13f55232 [gaim-migrate @ 16684]
Ma Yuan <mayuan2006@gmail.com>
parents: 19788
diff changeset
367 * MSN Time Related Funciton
b22d13f55232 [gaim-migrate @ 16684]
Ma Yuan <mayuan2006@gmail.com>
parents: 19788
diff changeset
368 ***************************************************************************/
b22d13f55232 [gaim-migrate @ 16684]
Ma Yuan <mayuan2006@gmail.com>
parents: 19788
diff changeset
369 #if 0
b22d13f55232 [gaim-migrate @ 16684]
Ma Yuan <mayuan2006@gmail.com>
parents: 19788
diff changeset
370 int
b22d13f55232 [gaim-migrate @ 16684]
Ma Yuan <mayuan2006@gmail.com>
parents: 19788
diff changeset
371 msn_convert_iso8601(const char *timestr,struct tm tm_time)
b22d13f55232 [gaim-migrate @ 16684]
Ma Yuan <mayuan2006@gmail.com>
parents: 19788
diff changeset
372 {
b22d13f55232 [gaim-migrate @ 16684]
Ma Yuan <mayuan2006@gmail.com>
parents: 19788
diff changeset
373 char temp[64];
b22d13f55232 [gaim-migrate @ 16684]
Ma Yuan <mayuan2006@gmail.com>
parents: 19788
diff changeset
374 struct tm ctime;
b22d13f55232 [gaim-migrate @ 16684]
Ma Yuan <mayuan2006@gmail.com>
parents: 19788
diff changeset
375 time_t ts;
19784
bc30c6270d9f [gaim-migrate @ 16473]
Ma Yuan <mayuan2006@gmail.com>
parents: 13627
diff changeset
376
19794
b22d13f55232 [gaim-migrate @ 16684]
Ma Yuan <mayuan2006@gmail.com>
parents: 19788
diff changeset
377 gaim_debug_info("MaYuan","convert string is{%s}\n",timestr);
b22d13f55232 [gaim-migrate @ 16684]
Ma Yuan <mayuan2006@gmail.com>
parents: 19788
diff changeset
378 tzset();
b22d13f55232 [gaim-migrate @ 16684]
Ma Yuan <mayuan2006@gmail.com>
parents: 19788
diff changeset
379 /*copy string first*/
b22d13f55232 [gaim-migrate @ 16684]
Ma Yuan <mayuan2006@gmail.com>
parents: 19788
diff changeset
380 memset(temp, 0, sizeof(temp));
b22d13f55232 [gaim-migrate @ 16684]
Ma Yuan <mayuan2006@gmail.com>
parents: 19788
diff changeset
381 strncpy(temp, timestr, strlen(timestr));
b22d13f55232 [gaim-migrate @ 16684]
Ma Yuan <mayuan2006@gmail.com>
parents: 19788
diff changeset
382
b22d13f55232 [gaim-migrate @ 16684]
Ma Yuan <mayuan2006@gmail.com>
parents: 19788
diff changeset
383 /*convert via strptime()*/
b22d13f55232 [gaim-migrate @ 16684]
Ma Yuan <mayuan2006@gmail.com>
parents: 19788
diff changeset
384 memset(&ctime, 0, sizeof(struct tm));
b22d13f55232 [gaim-migrate @ 16684]
Ma Yuan <mayuan2006@gmail.com>
parents: 19788
diff changeset
385 strptime(temp, "%d %b %Y %T %Z", &ctime);
b22d13f55232 [gaim-migrate @ 16684]
Ma Yuan <mayuan2006@gmail.com>
parents: 19788
diff changeset
386 ts = mktime(&ctime) - timezone;
b22d13f55232 [gaim-migrate @ 16684]
Ma Yuan <mayuan2006@gmail.com>
parents: 19788
diff changeset
387 localtime_r(&ts, tm_time);
b22d13f55232 [gaim-migrate @ 16684]
Ma Yuan <mayuan2006@gmail.com>
parents: 19788
diff changeset
388 }
b22d13f55232 [gaim-migrate @ 16684]
Ma Yuan <mayuan2006@gmail.com>
parents: 19788
diff changeset
389 #endif
b22d13f55232 [gaim-migrate @ 16684]
Ma Yuan <mayuan2006@gmail.com>
parents: 19788
diff changeset
390
b22d13f55232 [gaim-migrate @ 16684]
Ma Yuan <mayuan2006@gmail.com>
parents: 19788
diff changeset
391 /***************************************************************************
b22d13f55232 [gaim-migrate @ 16684]
Ma Yuan <mayuan2006@gmail.com>
parents: 19788
diff changeset
392 * MSN Challenge Computing Function
b22d13f55232 [gaim-migrate @ 16684]
Ma Yuan <mayuan2006@gmail.com>
parents: 19788
diff changeset
393 ***************************************************************************/
19785
852b32710df0 [gaim-migrate @ 16507]
Ma Yuan <mayuan2006@gmail.com>
parents: 19784
diff changeset
394 /*check the edian of system*/
852b32710df0 [gaim-migrate @ 16507]
Ma Yuan <mayuan2006@gmail.com>
parents: 19784
diff changeset
395 int
852b32710df0 [gaim-migrate @ 16507]
Ma Yuan <mayuan2006@gmail.com>
parents: 19784
diff changeset
396 isBigEndian(void)
852b32710df0 [gaim-migrate @ 16507]
Ma Yuan <mayuan2006@gmail.com>
parents: 19784
diff changeset
397 {
852b32710df0 [gaim-migrate @ 16507]
Ma Yuan <mayuan2006@gmail.com>
parents: 19784
diff changeset
398 short int word = 0x0100;
852b32710df0 [gaim-migrate @ 16507]
Ma Yuan <mayuan2006@gmail.com>
parents: 19784
diff changeset
399 char *byte = (char *)&word;
852b32710df0 [gaim-migrate @ 16507]
Ma Yuan <mayuan2006@gmail.com>
parents: 19784
diff changeset
400
852b32710df0 [gaim-migrate @ 16507]
Ma Yuan <mayuan2006@gmail.com>
parents: 19784
diff changeset
401 return(byte[0]);
852b32710df0 [gaim-migrate @ 16507]
Ma Yuan <mayuan2006@gmail.com>
parents: 19784
diff changeset
402 }
852b32710df0 [gaim-migrate @ 16507]
Ma Yuan <mayuan2006@gmail.com>
parents: 19784
diff changeset
403
852b32710df0 [gaim-migrate @ 16507]
Ma Yuan <mayuan2006@gmail.com>
parents: 19784
diff changeset
404 /*swap utility*/
852b32710df0 [gaim-migrate @ 16507]
Ma Yuan <mayuan2006@gmail.com>
parents: 19784
diff changeset
405 unsigned int
852b32710df0 [gaim-migrate @ 16507]
Ma Yuan <mayuan2006@gmail.com>
parents: 19784
diff changeset
406 swapInt(unsigned int dw)
852b32710df0 [gaim-migrate @ 16507]
Ma Yuan <mayuan2006@gmail.com>
parents: 19784
diff changeset
407 {
852b32710df0 [gaim-migrate @ 16507]
Ma Yuan <mayuan2006@gmail.com>
parents: 19784
diff changeset
408 unsigned int tmp;
852b32710df0 [gaim-migrate @ 16507]
Ma Yuan <mayuan2006@gmail.com>
parents: 19784
diff changeset
409 tmp = (dw & 0x000000FF);
852b32710df0 [gaim-migrate @ 16507]
Ma Yuan <mayuan2006@gmail.com>
parents: 19784
diff changeset
410 tmp = ((dw & 0x0000FF00) >> 0x08) | (tmp << 0x08);
852b32710df0 [gaim-migrate @ 16507]
Ma Yuan <mayuan2006@gmail.com>
parents: 19784
diff changeset
411 tmp = ((dw & 0x00FF0000) >> 0x10) | (tmp << 0x08);
852b32710df0 [gaim-migrate @ 16507]
Ma Yuan <mayuan2006@gmail.com>
parents: 19784
diff changeset
412 tmp = ((dw & 0xFF000000) >> 0x18) | (tmp << 0x08);
852b32710df0 [gaim-migrate @ 16507]
Ma Yuan <mayuan2006@gmail.com>
parents: 19784
diff changeset
413 return(tmp);
852b32710df0 [gaim-migrate @ 16507]
Ma Yuan <mayuan2006@gmail.com>
parents: 19784
diff changeset
414 }
852b32710df0 [gaim-migrate @ 16507]
Ma Yuan <mayuan2006@gmail.com>
parents: 19784
diff changeset
415
852b32710df0 [gaim-migrate @ 16507]
Ma Yuan <mayuan2006@gmail.com>
parents: 19784
diff changeset
416 /*
19788
8b4653986e8e [gaim-migrate @ 16600]
Ma Yuan <mayuan2006@gmail.com>
parents: 19785
diff changeset
417 * Handle MSN Chanllege computation
19785
852b32710df0 [gaim-migrate @ 16507]
Ma Yuan <mayuan2006@gmail.com>
parents: 19784
diff changeset
418 *This algorithm reference with http://msnpiki.msnfanatic.com/index.php/MSNP11:Challenges
852b32710df0 [gaim-migrate @ 16507]
Ma Yuan <mayuan2006@gmail.com>
parents: 19784
diff changeset
419 */
852b32710df0 [gaim-migrate @ 16507]
Ma Yuan <mayuan2006@gmail.com>
parents: 19784
diff changeset
420 #define BUFSIZE 256
852b32710df0 [gaim-migrate @ 16507]
Ma Yuan <mayuan2006@gmail.com>
parents: 19784
diff changeset
421 void
852b32710df0 [gaim-migrate @ 16507]
Ma Yuan <mayuan2006@gmail.com>
parents: 19784
diff changeset
422 msn_handle_chl(char *input, char *output)
852b32710df0 [gaim-migrate @ 16507]
Ma Yuan <mayuan2006@gmail.com>
parents: 19784
diff changeset
423 {
852b32710df0 [gaim-migrate @ 16507]
Ma Yuan <mayuan2006@gmail.com>
parents: 19784
diff changeset
424 GaimCipher *cipher;
852b32710df0 [gaim-migrate @ 16507]
Ma Yuan <mayuan2006@gmail.com>
parents: 19784
diff changeset
425 GaimCipherContext *context;
852b32710df0 [gaim-migrate @ 16507]
Ma Yuan <mayuan2006@gmail.com>
parents: 19784
diff changeset
426 char *productKey = MSNP13_WLM_PRODUCT_KEY,
852b32710df0 [gaim-migrate @ 16507]
Ma Yuan <mayuan2006@gmail.com>
parents: 19784
diff changeset
427 *productID = MSNP13_WLM_PRODUCT_ID,
852b32710df0 [gaim-migrate @ 16507]
Ma Yuan <mayuan2006@gmail.com>
parents: 19784
diff changeset
428 *hexChars = "0123456789abcdef",
852b32710df0 [gaim-migrate @ 16507]
Ma Yuan <mayuan2006@gmail.com>
parents: 19784
diff changeset
429 buf[BUFSIZE];
852b32710df0 [gaim-migrate @ 16507]
Ma Yuan <mayuan2006@gmail.com>
parents: 19784
diff changeset
430 unsigned char md5Hash[16], *newHash;
852b32710df0 [gaim-migrate @ 16507]
Ma Yuan <mayuan2006@gmail.com>
parents: 19784
diff changeset
431 unsigned int *md5Parts, *chlStringParts, newHashParts[5];
852b32710df0 [gaim-migrate @ 16507]
Ma Yuan <mayuan2006@gmail.com>
parents: 19784
diff changeset
432
852b32710df0 [gaim-migrate @ 16507]
Ma Yuan <mayuan2006@gmail.com>
parents: 19784
diff changeset
433 long long nHigh=0, nLow=0;
852b32710df0 [gaim-migrate @ 16507]
Ma Yuan <mayuan2006@gmail.com>
parents: 19784
diff changeset
434
852b32710df0 [gaim-migrate @ 16507]
Ma Yuan <mayuan2006@gmail.com>
parents: 19784
diff changeset
435 int i, bigEndian;
852b32710df0 [gaim-migrate @ 16507]
Ma Yuan <mayuan2006@gmail.com>
parents: 19784
diff changeset
436
852b32710df0 [gaim-migrate @ 16507]
Ma Yuan <mayuan2006@gmail.com>
parents: 19784
diff changeset
437 /* Determine our endianess */
852b32710df0 [gaim-migrate @ 16507]
Ma Yuan <mayuan2006@gmail.com>
parents: 19784
diff changeset
438 bigEndian = isBigEndian();
852b32710df0 [gaim-migrate @ 16507]
Ma Yuan <mayuan2006@gmail.com>
parents: 19784
diff changeset
439
852b32710df0 [gaim-migrate @ 16507]
Ma Yuan <mayuan2006@gmail.com>
parents: 19784
diff changeset
440 /* Create the MD5 hash by using Gaim MD5 algorithm*/
852b32710df0 [gaim-migrate @ 16507]
Ma Yuan <mayuan2006@gmail.com>
parents: 19784
diff changeset
441 cipher = gaim_ciphers_find_cipher("md5");
852b32710df0 [gaim-migrate @ 16507]
Ma Yuan <mayuan2006@gmail.com>
parents: 19784
diff changeset
442 context = gaim_cipher_context_new(cipher, NULL);
852b32710df0 [gaim-migrate @ 16507]
Ma Yuan <mayuan2006@gmail.com>
parents: 19784
diff changeset
443
852b32710df0 [gaim-migrate @ 16507]
Ma Yuan <mayuan2006@gmail.com>
parents: 19784
diff changeset
444 gaim_cipher_context_append(context, (const guchar *)input,
852b32710df0 [gaim-migrate @ 16507]
Ma Yuan <mayuan2006@gmail.com>
parents: 19784
diff changeset
445 strlen(input));
852b32710df0 [gaim-migrate @ 16507]
Ma Yuan <mayuan2006@gmail.com>
parents: 19784
diff changeset
446 gaim_cipher_context_append(context, (const guchar *)productKey,
852b32710df0 [gaim-migrate @ 16507]
Ma Yuan <mayuan2006@gmail.com>
parents: 19784
diff changeset
447 strlen(productKey));
852b32710df0 [gaim-migrate @ 16507]
Ma Yuan <mayuan2006@gmail.com>
parents: 19784
diff changeset
448 gaim_cipher_context_digest(context, sizeof(md5Hash), md5Hash, NULL);
852b32710df0 [gaim-migrate @ 16507]
Ma Yuan <mayuan2006@gmail.com>
parents: 19784
diff changeset
449 gaim_cipher_context_destroy(context);
852b32710df0 [gaim-migrate @ 16507]
Ma Yuan <mayuan2006@gmail.com>
parents: 19784
diff changeset
450
852b32710df0 [gaim-migrate @ 16507]
Ma Yuan <mayuan2006@gmail.com>
parents: 19784
diff changeset
451 /* Split it into four integers */
852b32710df0 [gaim-migrate @ 16507]
Ma Yuan <mayuan2006@gmail.com>
parents: 19784
diff changeset
452 md5Parts = (unsigned int *)md5Hash;
852b32710df0 [gaim-migrate @ 16507]
Ma Yuan <mayuan2006@gmail.com>
parents: 19784
diff changeset
453 for(i=0; i<4; i++){
852b32710df0 [gaim-migrate @ 16507]
Ma Yuan <mayuan2006@gmail.com>
parents: 19784
diff changeset
454 /* check for endianess */
852b32710df0 [gaim-migrate @ 16507]
Ma Yuan <mayuan2006@gmail.com>
parents: 19784
diff changeset
455 if(bigEndian)
852b32710df0 [gaim-migrate @ 16507]
Ma Yuan <mayuan2006@gmail.com>
parents: 19784
diff changeset
456 md5Parts[i] = swapInt(md5Parts[i]);
852b32710df0 [gaim-migrate @ 16507]
Ma Yuan <mayuan2006@gmail.com>
parents: 19784
diff changeset
457
852b32710df0 [gaim-migrate @ 16507]
Ma Yuan <mayuan2006@gmail.com>
parents: 19784
diff changeset
458 /* & each integer with 0x7FFFFFFF */
852b32710df0 [gaim-migrate @ 16507]
Ma Yuan <mayuan2006@gmail.com>
parents: 19784
diff changeset
459 /* and save one unmodified array for later */
852b32710df0 [gaim-migrate @ 16507]
Ma Yuan <mayuan2006@gmail.com>
parents: 19784
diff changeset
460 newHashParts[i] = md5Parts[i];
852b32710df0 [gaim-migrate @ 16507]
Ma Yuan <mayuan2006@gmail.com>
parents: 19784
diff changeset
461 md5Parts[i] &= 0x7FFFFFFF;
852b32710df0 [gaim-migrate @ 16507]
Ma Yuan <mayuan2006@gmail.com>
parents: 19784
diff changeset
462 }
852b32710df0 [gaim-migrate @ 16507]
Ma Yuan <mayuan2006@gmail.com>
parents: 19784
diff changeset
463
852b32710df0 [gaim-migrate @ 16507]
Ma Yuan <mayuan2006@gmail.com>
parents: 19784
diff changeset
464 /* make a new string and pad with '0' */
852b32710df0 [gaim-migrate @ 16507]
Ma Yuan <mayuan2006@gmail.com>
parents: 19784
diff changeset
465 snprintf(buf, BUFSIZE-5, "%s%s", input, productID);
852b32710df0 [gaim-migrate @ 16507]
Ma Yuan <mayuan2006@gmail.com>
parents: 19784
diff changeset
466 i = strlen(buf);
852b32710df0 [gaim-migrate @ 16507]
Ma Yuan <mayuan2006@gmail.com>
parents: 19784
diff changeset
467 memset(&buf[i], '0', 8 - (i % 8));
852b32710df0 [gaim-migrate @ 16507]
Ma Yuan <mayuan2006@gmail.com>
parents: 19784
diff changeset
468 buf[i + (8 - (i % 8))]='\0';
852b32710df0 [gaim-migrate @ 16507]
Ma Yuan <mayuan2006@gmail.com>
parents: 19784
diff changeset
469
852b32710df0 [gaim-migrate @ 16507]
Ma Yuan <mayuan2006@gmail.com>
parents: 19784
diff changeset
470 /* split into integers */
852b32710df0 [gaim-migrate @ 16507]
Ma Yuan <mayuan2006@gmail.com>
parents: 19784
diff changeset
471 chlStringParts = (unsigned int *)buf;
852b32710df0 [gaim-migrate @ 16507]
Ma Yuan <mayuan2006@gmail.com>
parents: 19784
diff changeset
472
852b32710df0 [gaim-migrate @ 16507]
Ma Yuan <mayuan2006@gmail.com>
parents: 19784
diff changeset
473 /* this is magic */
852b32710df0 [gaim-migrate @ 16507]
Ma Yuan <mayuan2006@gmail.com>
parents: 19784
diff changeset
474 for (i=0; i<(strlen(buf)/4)-1; i+=2){
852b32710df0 [gaim-migrate @ 16507]
Ma Yuan <mayuan2006@gmail.com>
parents: 19784
diff changeset
475 long long temp;
852b32710df0 [gaim-migrate @ 16507]
Ma Yuan <mayuan2006@gmail.com>
parents: 19784
diff changeset
476
852b32710df0 [gaim-migrate @ 16507]
Ma Yuan <mayuan2006@gmail.com>
parents: 19784
diff changeset
477 if(bigEndian){
852b32710df0 [gaim-migrate @ 16507]
Ma Yuan <mayuan2006@gmail.com>
parents: 19784
diff changeset
478 chlStringParts[i] = swapInt(chlStringParts[i]);
852b32710df0 [gaim-migrate @ 16507]
Ma Yuan <mayuan2006@gmail.com>
parents: 19784
diff changeset
479 chlStringParts[i+1] = swapInt(chlStringParts[i+1]);
852b32710df0 [gaim-migrate @ 16507]
Ma Yuan <mayuan2006@gmail.com>
parents: 19784
diff changeset
480 }
852b32710df0 [gaim-migrate @ 16507]
Ma Yuan <mayuan2006@gmail.com>
parents: 19784
diff changeset
481
852b32710df0 [gaim-migrate @ 16507]
Ma Yuan <mayuan2006@gmail.com>
parents: 19784
diff changeset
482 temp=(md5Parts[0] * (((0x0E79A9C1 * (long long)chlStringParts[i]) % 0x7FFFFFFF)+nHigh) + md5Parts[1])%0x7FFFFFFF;
852b32710df0 [gaim-migrate @ 16507]
Ma Yuan <mayuan2006@gmail.com>
parents: 19784
diff changeset
483 nHigh=(md5Parts[2] * (((long long)chlStringParts[i+1]+temp) % 0x7FFFFFFF) + md5Parts[3]) % 0x7FFFFFFF;
852b32710df0 [gaim-migrate @ 16507]
Ma Yuan <mayuan2006@gmail.com>
parents: 19784
diff changeset
484 nLow=nLow + nHigh + temp;
852b32710df0 [gaim-migrate @ 16507]
Ma Yuan <mayuan2006@gmail.com>
parents: 19784
diff changeset
485 }
852b32710df0 [gaim-migrate @ 16507]
Ma Yuan <mayuan2006@gmail.com>
parents: 19784
diff changeset
486 nHigh=(nHigh+md5Parts[1]) % 0x7FFFFFFF;
852b32710df0 [gaim-migrate @ 16507]
Ma Yuan <mayuan2006@gmail.com>
parents: 19784
diff changeset
487 nLow=(nLow+md5Parts[3]) % 0x7FFFFFFF;
852b32710df0 [gaim-migrate @ 16507]
Ma Yuan <mayuan2006@gmail.com>
parents: 19784
diff changeset
488
852b32710df0 [gaim-migrate @ 16507]
Ma Yuan <mayuan2006@gmail.com>
parents: 19784
diff changeset
489 newHashParts[0]^=nHigh;
852b32710df0 [gaim-migrate @ 16507]
Ma Yuan <mayuan2006@gmail.com>
parents: 19784
diff changeset
490 newHashParts[1]^=nLow;
852b32710df0 [gaim-migrate @ 16507]
Ma Yuan <mayuan2006@gmail.com>
parents: 19784
diff changeset
491 newHashParts[2]^=nHigh;
852b32710df0 [gaim-migrate @ 16507]
Ma Yuan <mayuan2006@gmail.com>
parents: 19784
diff changeset
492 newHashParts[3]^=nLow;
852b32710df0 [gaim-migrate @ 16507]
Ma Yuan <mayuan2006@gmail.com>
parents: 19784
diff changeset
493
852b32710df0 [gaim-migrate @ 16507]
Ma Yuan <mayuan2006@gmail.com>
parents: 19784
diff changeset
494 /* swap more bytes if big endian */
852b32710df0 [gaim-migrate @ 16507]
Ma Yuan <mayuan2006@gmail.com>
parents: 19784
diff changeset
495 for(i=0; i<4 && bigEndian; i++)
852b32710df0 [gaim-migrate @ 16507]
Ma Yuan <mayuan2006@gmail.com>
parents: 19784
diff changeset
496 newHashParts[i] = swapInt(newHashParts[i]);
852b32710df0 [gaim-migrate @ 16507]
Ma Yuan <mayuan2006@gmail.com>
parents: 19784
diff changeset
497
852b32710df0 [gaim-migrate @ 16507]
Ma Yuan <mayuan2006@gmail.com>
parents: 19784
diff changeset
498 /* make a string of the parts */
852b32710df0 [gaim-migrate @ 16507]
Ma Yuan <mayuan2006@gmail.com>
parents: 19784
diff changeset
499 newHash = (unsigned char *)newHashParts;
852b32710df0 [gaim-migrate @ 16507]
Ma Yuan <mayuan2006@gmail.com>
parents: 19784
diff changeset
500
852b32710df0 [gaim-migrate @ 16507]
Ma Yuan <mayuan2006@gmail.com>
parents: 19784
diff changeset
501 /* convert to hexadecimal */
852b32710df0 [gaim-migrate @ 16507]
Ma Yuan <mayuan2006@gmail.com>
parents: 19784
diff changeset
502 for (i=0; i<16; i++)
852b32710df0 [gaim-migrate @ 16507]
Ma Yuan <mayuan2006@gmail.com>
parents: 19784
diff changeset
503 {
852b32710df0 [gaim-migrate @ 16507]
Ma Yuan <mayuan2006@gmail.com>
parents: 19784
diff changeset
504 output[i*2]=hexChars[(newHash[i]>>4)&0xF];
852b32710df0 [gaim-migrate @ 16507]
Ma Yuan <mayuan2006@gmail.com>
parents: 19784
diff changeset
505 output[(i*2)+1]=hexChars[newHash[i]&0xF];
852b32710df0 [gaim-migrate @ 16507]
Ma Yuan <mayuan2006@gmail.com>
parents: 19784
diff changeset
506 }
852b32710df0 [gaim-migrate @ 16507]
Ma Yuan <mayuan2006@gmail.com>
parents: 19784
diff changeset
507
852b32710df0 [gaim-migrate @ 16507]
Ma Yuan <mayuan2006@gmail.com>
parents: 19784
diff changeset
508 output[32]='\0';
852b32710df0 [gaim-migrate @ 16507]
Ma Yuan <mayuan2006@gmail.com>
parents: 19784
diff changeset
509
852b32710df0 [gaim-migrate @ 16507]
Ma Yuan <mayuan2006@gmail.com>
parents: 19784
diff changeset
510 // gaim_debug_info("MaYuan","chl output{%s}\n",output);
852b32710df0 [gaim-migrate @ 16507]
Ma Yuan <mayuan2006@gmail.com>
parents: 19784
diff changeset
511 }
852b32710df0 [gaim-migrate @ 16507]
Ma Yuan <mayuan2006@gmail.com>
parents: 19784
diff changeset
512
19794
b22d13f55232 [gaim-migrate @ 16684]
Ma Yuan <mayuan2006@gmail.com>
parents: 19788
diff changeset
513 #if (!defined(_XOPEN_SOURCE))||defined(_WIN32)
b22d13f55232 [gaim-migrate @ 16684]
Ma Yuan <mayuan2006@gmail.com>
parents: 19788
diff changeset
514
b22d13f55232 [gaim-migrate @ 16684]
Ma Yuan <mayuan2006@gmail.com>
parents: 19788
diff changeset
515 #ifndef __P
b22d13f55232 [gaim-migrate @ 16684]
Ma Yuan <mayuan2006@gmail.com>
parents: 19788
diff changeset
516 # if defined (__GNUC__) || (defined (__STDC__) && __STDC__)
b22d13f55232 [gaim-migrate @ 16684]
Ma Yuan <mayuan2006@gmail.com>
parents: 19788
diff changeset
517 # define __P(args) args
b22d13f55232 [gaim-migrate @ 16684]
Ma Yuan <mayuan2006@gmail.com>
parents: 19788
diff changeset
518 # else
b22d13f55232 [gaim-migrate @ 16684]
Ma Yuan <mayuan2006@gmail.com>
parents: 19788
diff changeset
519 # define __P(args) ()
b22d13f55232 [gaim-migrate @ 16684]
Ma Yuan <mayuan2006@gmail.com>
parents: 19788
diff changeset
520 # endif /* GCC. */
b22d13f55232 [gaim-migrate @ 16684]
Ma Yuan <mayuan2006@gmail.com>
parents: 19788
diff changeset
521 #endif /* Not __P. */
b22d13f55232 [gaim-migrate @ 16684]
Ma Yuan <mayuan2006@gmail.com>
parents: 19788
diff changeset
522
b22d13f55232 [gaim-migrate @ 16684]
Ma Yuan <mayuan2006@gmail.com>
parents: 19788
diff changeset
523 #if ! HAVE_LOCALTIME_R && ! defined localtime_r
b22d13f55232 [gaim-migrate @ 16684]
Ma Yuan <mayuan2006@gmail.com>
parents: 19788
diff changeset
524 # ifdef _LIBC
b22d13f55232 [gaim-migrate @ 16684]
Ma Yuan <mayuan2006@gmail.com>
parents: 19788
diff changeset
525 # define localtime_r __localtime_r
b22d13f55232 [gaim-migrate @ 16684]
Ma Yuan <mayuan2006@gmail.com>
parents: 19788
diff changeset
526 # else
b22d13f55232 [gaim-migrate @ 16684]
Ma Yuan <mayuan2006@gmail.com>
parents: 19788
diff changeset
527 /* Approximate localtime_r as best we can in its absence. */
b22d13f55232 [gaim-migrate @ 16684]
Ma Yuan <mayuan2006@gmail.com>
parents: 19788
diff changeset
528 # define localtime_r my_localtime_r
b22d13f55232 [gaim-migrate @ 16684]
Ma Yuan <mayuan2006@gmail.com>
parents: 19788
diff changeset
529 static struct tm *localtime_r __P ((const time_t *, struct tm *));
b22d13f55232 [gaim-migrate @ 16684]
Ma Yuan <mayuan2006@gmail.com>
parents: 19788
diff changeset
530 static struct tm *
b22d13f55232 [gaim-migrate @ 16684]
Ma Yuan <mayuan2006@gmail.com>
parents: 19788
diff changeset
531 localtime_r (t, tp)
b22d13f55232 [gaim-migrate @ 16684]
Ma Yuan <mayuan2006@gmail.com>
parents: 19788
diff changeset
532 const time_t *t;
b22d13f55232 [gaim-migrate @ 16684]
Ma Yuan <mayuan2006@gmail.com>
parents: 19788
diff changeset
533 struct tm *tp;
b22d13f55232 [gaim-migrate @ 16684]
Ma Yuan <mayuan2006@gmail.com>
parents: 19788
diff changeset
534 {
b22d13f55232 [gaim-migrate @ 16684]
Ma Yuan <mayuan2006@gmail.com>
parents: 19788
diff changeset
535 struct tm *l = localtime (t);
b22d13f55232 [gaim-migrate @ 16684]
Ma Yuan <mayuan2006@gmail.com>
parents: 19788
diff changeset
536 if (! l)
b22d13f55232 [gaim-migrate @ 16684]
Ma Yuan <mayuan2006@gmail.com>
parents: 19788
diff changeset
537 return 0;
b22d13f55232 [gaim-migrate @ 16684]
Ma Yuan <mayuan2006@gmail.com>
parents: 19788
diff changeset
538 *tp = *l;
b22d13f55232 [gaim-migrate @ 16684]
Ma Yuan <mayuan2006@gmail.com>
parents: 19788
diff changeset
539 return tp;
b22d13f55232 [gaim-migrate @ 16684]
Ma Yuan <mayuan2006@gmail.com>
parents: 19788
diff changeset
540 }
b22d13f55232 [gaim-migrate @ 16684]
Ma Yuan <mayuan2006@gmail.com>
parents: 19788
diff changeset
541 # endif /* ! _LIBC */
b22d13f55232 [gaim-migrate @ 16684]
Ma Yuan <mayuan2006@gmail.com>
parents: 19788
diff changeset
542 #endif /* ! HAVE_LOCALTIME_R && ! defined (localtime_r) */
b22d13f55232 [gaim-migrate @ 16684]
Ma Yuan <mayuan2006@gmail.com>
parents: 19788
diff changeset
543
b22d13f55232 [gaim-migrate @ 16684]
Ma Yuan <mayuan2006@gmail.com>
parents: 19788
diff changeset
544
b22d13f55232 [gaim-migrate @ 16684]
Ma Yuan <mayuan2006@gmail.com>
parents: 19788
diff changeset
545 #define match_char(ch1, ch2) if (ch1 != ch2) return NULL
b22d13f55232 [gaim-migrate @ 16684]
Ma Yuan <mayuan2006@gmail.com>
parents: 19788
diff changeset
546
b22d13f55232 [gaim-migrate @ 16684]
Ma Yuan <mayuan2006@gmail.com>
parents: 19788
diff changeset
547 #if defined __GNUC__ && __GNUC__ >= 2
b22d13f55232 [gaim-migrate @ 16684]
Ma Yuan <mayuan2006@gmail.com>
parents: 19788
diff changeset
548 # define match_string(cs1, s2) \
b22d13f55232 [gaim-migrate @ 16684]
Ma Yuan <mayuan2006@gmail.com>
parents: 19788
diff changeset
549 ({ size_t len = strlen (cs1); \
b22d13f55232 [gaim-migrate @ 16684]
Ma Yuan <mayuan2006@gmail.com>
parents: 19788
diff changeset
550 int result = strncasecmp ((cs1), (s2), len) == 0; \
b22d13f55232 [gaim-migrate @ 16684]
Ma Yuan <mayuan2006@gmail.com>
parents: 19788
diff changeset
551 if (result) (s2) += len; \
b22d13f55232 [gaim-migrate @ 16684]
Ma Yuan <mayuan2006@gmail.com>
parents: 19788
diff changeset
552 result; })
b22d13f55232 [gaim-migrate @ 16684]
Ma Yuan <mayuan2006@gmail.com>
parents: 19788
diff changeset
553 #else
b22d13f55232 [gaim-migrate @ 16684]
Ma Yuan <mayuan2006@gmail.com>
parents: 19788
diff changeset
554 /* Oh come on. Get a reasonable compiler. */
b22d13f55232 [gaim-migrate @ 16684]
Ma Yuan <mayuan2006@gmail.com>
parents: 19788
diff changeset
555 # define match_string(cs1, s2) \
b22d13f55232 [gaim-migrate @ 16684]
Ma Yuan <mayuan2006@gmail.com>
parents: 19788
diff changeset
556 (strncasecmp ((cs1), (s2), strlen (cs1)) ? 0 : ((s2) += strlen (cs1), 1))
b22d13f55232 [gaim-migrate @ 16684]
Ma Yuan <mayuan2006@gmail.com>
parents: 19788
diff changeset
557 #endif
b22d13f55232 [gaim-migrate @ 16684]
Ma Yuan <mayuan2006@gmail.com>
parents: 19788
diff changeset
558
b22d13f55232 [gaim-migrate @ 16684]
Ma Yuan <mayuan2006@gmail.com>
parents: 19788
diff changeset
559 /* We intentionally do not use isdigit() for testing because this will
b22d13f55232 [gaim-migrate @ 16684]
Ma Yuan <mayuan2006@gmail.com>
parents: 19788
diff changeset
560 lead to problems with the wide character version. */
b22d13f55232 [gaim-migrate @ 16684]
Ma Yuan <mayuan2006@gmail.com>
parents: 19788
diff changeset
561 #define get_number(from, to, n) \
b22d13f55232 [gaim-migrate @ 16684]
Ma Yuan <mayuan2006@gmail.com>
parents: 19788
diff changeset
562 do { \
b22d13f55232 [gaim-migrate @ 16684]
Ma Yuan <mayuan2006@gmail.com>
parents: 19788
diff changeset
563 int __n = n; \
b22d13f55232 [gaim-migrate @ 16684]
Ma Yuan <mayuan2006@gmail.com>
parents: 19788
diff changeset
564 val = 0; \
b22d13f55232 [gaim-migrate @ 16684]
Ma Yuan <mayuan2006@gmail.com>
parents: 19788
diff changeset
565 while (*rp == ' ') \
b22d13f55232 [gaim-migrate @ 16684]
Ma Yuan <mayuan2006@gmail.com>
parents: 19788
diff changeset
566 ++rp; \
b22d13f55232 [gaim-migrate @ 16684]
Ma Yuan <mayuan2006@gmail.com>
parents: 19788
diff changeset
567 if ((*rp < '0') || (*rp > '9')) \
b22d13f55232 [gaim-migrate @ 16684]
Ma Yuan <mayuan2006@gmail.com>
parents: 19788
diff changeset
568 return NULL; \
b22d13f55232 [gaim-migrate @ 16684]
Ma Yuan <mayuan2006@gmail.com>
parents: 19788
diff changeset
569 do { \
b22d13f55232 [gaim-migrate @ 16684]
Ma Yuan <mayuan2006@gmail.com>
parents: 19788
diff changeset
570 val *= 10; \
b22d13f55232 [gaim-migrate @ 16684]
Ma Yuan <mayuan2006@gmail.com>
parents: 19788
diff changeset
571 val += *rp++ - '0'; \
b22d13f55232 [gaim-migrate @ 16684]
Ma Yuan <mayuan2006@gmail.com>
parents: 19788
diff changeset
572 } while ((--__n > 0) && (val * 10 <= to) && (*rp >= '0') && (*rp <= '9')); \
b22d13f55232 [gaim-migrate @ 16684]
Ma Yuan <mayuan2006@gmail.com>
parents: 19788
diff changeset
573 if ((val < from) || (val > to)) \
b22d13f55232 [gaim-migrate @ 16684]
Ma Yuan <mayuan2006@gmail.com>
parents: 19788
diff changeset
574 return NULL; \
b22d13f55232 [gaim-migrate @ 16684]
Ma Yuan <mayuan2006@gmail.com>
parents: 19788
diff changeset
575 } while (0)
b22d13f55232 [gaim-migrate @ 16684]
Ma Yuan <mayuan2006@gmail.com>
parents: 19788
diff changeset
576
b22d13f55232 [gaim-migrate @ 16684]
Ma Yuan <mayuan2006@gmail.com>
parents: 19788
diff changeset
577 #ifdef _NL_CURRENT
b22d13f55232 [gaim-migrate @ 16684]
Ma Yuan <mayuan2006@gmail.com>
parents: 19788
diff changeset
578 # define get_alt_number(from, to, n) \
b22d13f55232 [gaim-migrate @ 16684]
Ma Yuan <mayuan2006@gmail.com>
parents: 19788
diff changeset
579 ({ \
b22d13f55232 [gaim-migrate @ 16684]
Ma Yuan <mayuan2006@gmail.com>
parents: 19788
diff changeset
580 __label__ do_normal; \
b22d13f55232 [gaim-migrate @ 16684]
Ma Yuan <mayuan2006@gmail.com>
parents: 19788
diff changeset
581 if (*decided != raw) \
b22d13f55232 [gaim-migrate @ 16684]
Ma Yuan <mayuan2006@gmail.com>
parents: 19788
diff changeset
582 { \
b22d13f55232 [gaim-migrate @ 16684]
Ma Yuan <mayuan2006@gmail.com>
parents: 19788
diff changeset
583 const char *alts = _NL_CURRENT (LC_TIME, ALT_DIGITS); \
b22d13f55232 [gaim-migrate @ 16684]
Ma Yuan <mayuan2006@gmail.com>
parents: 19788
diff changeset
584 int __n = n; \
b22d13f55232 [gaim-migrate @ 16684]
Ma Yuan <mayuan2006@gmail.com>
parents: 19788
diff changeset
585 int any = 0; \
b22d13f55232 [gaim-migrate @ 16684]
Ma Yuan <mayuan2006@gmail.com>
parents: 19788
diff changeset
586 while (*rp == ' ') \
b22d13f55232 [gaim-migrate @ 16684]
Ma Yuan <mayuan2006@gmail.com>
parents: 19788
diff changeset
587 ++rp; \
b22d13f55232 [gaim-migrate @ 16684]
Ma Yuan <mayuan2006@gmail.com>
parents: 19788
diff changeset
588 val = 0; \
b22d13f55232 [gaim-migrate @ 16684]
Ma Yuan <mayuan2006@gmail.com>
parents: 19788
diff changeset
589 do { \
b22d13f55232 [gaim-migrate @ 16684]
Ma Yuan <mayuan2006@gmail.com>
parents: 19788
diff changeset
590 val *= 10; \
b22d13f55232 [gaim-migrate @ 16684]
Ma Yuan <mayuan2006@gmail.com>
parents: 19788
diff changeset
591 while (*alts != '\0') \
b22d13f55232 [gaim-migrate @ 16684]
Ma Yuan <mayuan2006@gmail.com>
parents: 19788
diff changeset
592 { \
b22d13f55232 [gaim-migrate @ 16684]
Ma Yuan <mayuan2006@gmail.com>
parents: 19788
diff changeset
593 size_t len = strlen (alts); \
b22d13f55232 [gaim-migrate @ 16684]
Ma Yuan <mayuan2006@gmail.com>
parents: 19788
diff changeset
594 if (strncasecmp (alts, rp, len) == 0) \
b22d13f55232 [gaim-migrate @ 16684]
Ma Yuan <mayuan2006@gmail.com>
parents: 19788
diff changeset
595 break; \
b22d13f55232 [gaim-migrate @ 16684]
Ma Yuan <mayuan2006@gmail.com>
parents: 19788
diff changeset
596 alts += len + 1; \
b22d13f55232 [gaim-migrate @ 16684]
Ma Yuan <mayuan2006@gmail.com>
parents: 19788
diff changeset
597 ++val; \
b22d13f55232 [gaim-migrate @ 16684]
Ma Yuan <mayuan2006@gmail.com>
parents: 19788
diff changeset
598 } \
b22d13f55232 [gaim-migrate @ 16684]
Ma Yuan <mayuan2006@gmail.com>
parents: 19788
diff changeset
599 if (*alts == '\0') \
b22d13f55232 [gaim-migrate @ 16684]
Ma Yuan <mayuan2006@gmail.com>
parents: 19788
diff changeset
600 { \
b22d13f55232 [gaim-migrate @ 16684]
Ma Yuan <mayuan2006@gmail.com>
parents: 19788
diff changeset
601 if (*decided == not && ! any) \
b22d13f55232 [gaim-migrate @ 16684]
Ma Yuan <mayuan2006@gmail.com>
parents: 19788
diff changeset
602 goto do_normal; \
b22d13f55232 [gaim-migrate @ 16684]
Ma Yuan <mayuan2006@gmail.com>
parents: 19788
diff changeset
603 /* If we haven't read anything it's an error. */ \
b22d13f55232 [gaim-migrate @ 16684]
Ma Yuan <mayuan2006@gmail.com>
parents: 19788
diff changeset
604 if (! any) \
b22d13f55232 [gaim-migrate @ 16684]
Ma Yuan <mayuan2006@gmail.com>
parents: 19788
diff changeset
605 return NULL; \
b22d13f55232 [gaim-migrate @ 16684]
Ma Yuan <mayuan2006@gmail.com>
parents: 19788
diff changeset
606 /* Correct the premature multiplication. */ \
b22d13f55232 [gaim-migrate @ 16684]
Ma Yuan <mayuan2006@gmail.com>
parents: 19788
diff changeset
607 val /= 10; \
b22d13f55232 [gaim-migrate @ 16684]
Ma Yuan <mayuan2006@gmail.com>
parents: 19788
diff changeset
608 break; \
b22d13f55232 [gaim-migrate @ 16684]
Ma Yuan <mayuan2006@gmail.com>
parents: 19788
diff changeset
609 } \
b22d13f55232 [gaim-migrate @ 16684]
Ma Yuan <mayuan2006@gmail.com>
parents: 19788
diff changeset
610 else \
b22d13f55232 [gaim-migrate @ 16684]
Ma Yuan <mayuan2006@gmail.com>
parents: 19788
diff changeset
611 *decided = loc; \
b22d13f55232 [gaim-migrate @ 16684]
Ma Yuan <mayuan2006@gmail.com>
parents: 19788
diff changeset
612 } while (--__n > 0 && val * 10 <= to); \
b22d13f55232 [gaim-migrate @ 16684]
Ma Yuan <mayuan2006@gmail.com>
parents: 19788
diff changeset
613 if (val < from || val > to) \
b22d13f55232 [gaim-migrate @ 16684]
Ma Yuan <mayuan2006@gmail.com>
parents: 19788
diff changeset
614 return NULL; \
b22d13f55232 [gaim-migrate @ 16684]
Ma Yuan <mayuan2006@gmail.com>
parents: 19788
diff changeset
615 } \
b22d13f55232 [gaim-migrate @ 16684]
Ma Yuan <mayuan2006@gmail.com>
parents: 19788
diff changeset
616 else \
b22d13f55232 [gaim-migrate @ 16684]
Ma Yuan <mayuan2006@gmail.com>
parents: 19788
diff changeset
617 { \
b22d13f55232 [gaim-migrate @ 16684]
Ma Yuan <mayuan2006@gmail.com>
parents: 19788
diff changeset
618 do_normal: \
b22d13f55232 [gaim-migrate @ 16684]
Ma Yuan <mayuan2006@gmail.com>
parents: 19788
diff changeset
619 get_number (from, to, n); \
b22d13f55232 [gaim-migrate @ 16684]
Ma Yuan <mayuan2006@gmail.com>
parents: 19788
diff changeset
620 } \
b22d13f55232 [gaim-migrate @ 16684]
Ma Yuan <mayuan2006@gmail.com>
parents: 19788
diff changeset
621 0; \
b22d13f55232 [gaim-migrate @ 16684]
Ma Yuan <mayuan2006@gmail.com>
parents: 19788
diff changeset
622 })
b22d13f55232 [gaim-migrate @ 16684]
Ma Yuan <mayuan2006@gmail.com>
parents: 19788
diff changeset
623 #else
b22d13f55232 [gaim-migrate @ 16684]
Ma Yuan <mayuan2006@gmail.com>
parents: 19788
diff changeset
624 # define get_alt_number(from, to, n) \
b22d13f55232 [gaim-migrate @ 16684]
Ma Yuan <mayuan2006@gmail.com>
parents: 19788
diff changeset
625 /* We don't have the alternate representation. */ \
b22d13f55232 [gaim-migrate @ 16684]
Ma Yuan <mayuan2006@gmail.com>
parents: 19788
diff changeset
626 get_number(from, to, n)
b22d13f55232 [gaim-migrate @ 16684]
Ma Yuan <mayuan2006@gmail.com>
parents: 19788
diff changeset
627 #endif
b22d13f55232 [gaim-migrate @ 16684]
Ma Yuan <mayuan2006@gmail.com>
parents: 19788
diff changeset
628
b22d13f55232 [gaim-migrate @ 16684]
Ma Yuan <mayuan2006@gmail.com>
parents: 19788
diff changeset
629 #define recursive(new_fmt) \
b22d13f55232 [gaim-migrate @ 16684]
Ma Yuan <mayuan2006@gmail.com>
parents: 19788
diff changeset
630 (*(new_fmt) != '\0' \
b22d13f55232 [gaim-migrate @ 16684]
Ma Yuan <mayuan2006@gmail.com>
parents: 19788
diff changeset
631 && (rp = strptime_internal (rp, (new_fmt), tm, decided, era_cnt)) != NULL)
b22d13f55232 [gaim-migrate @ 16684]
Ma Yuan <mayuan2006@gmail.com>
parents: 19788
diff changeset
632
b22d13f55232 [gaim-migrate @ 16684]
Ma Yuan <mayuan2006@gmail.com>
parents: 19788
diff changeset
633
b22d13f55232 [gaim-migrate @ 16684]
Ma Yuan <mayuan2006@gmail.com>
parents: 19788
diff changeset
634 #ifdef _LIBC
b22d13f55232 [gaim-migrate @ 16684]
Ma Yuan <mayuan2006@gmail.com>
parents: 19788
diff changeset
635 /* This is defined in locale/C-time.c in the GNU libc. */
b22d13f55232 [gaim-migrate @ 16684]
Ma Yuan <mayuan2006@gmail.com>
parents: 19788
diff changeset
636 extern const struct locale_data _nl_C_LC_TIME;
b22d13f55232 [gaim-migrate @ 16684]
Ma Yuan <mayuan2006@gmail.com>
parents: 19788
diff changeset
637 extern const unsigned short int __mon_yday[2][13];
b22d13f55232 [gaim-migrate @ 16684]
Ma Yuan <mayuan2006@gmail.com>
parents: 19788
diff changeset
638
b22d13f55232 [gaim-migrate @ 16684]
Ma Yuan <mayuan2006@gmail.com>
parents: 19788
diff changeset
639 # define weekday_name (&_nl_C_LC_TIME.values[_NL_ITEM_INDEX (DAY_1)].string)
b22d13f55232 [gaim-migrate @ 16684]
Ma Yuan <mayuan2006@gmail.com>
parents: 19788
diff changeset
640 # define ab_weekday_name \
b22d13f55232 [gaim-migrate @ 16684]
Ma Yuan <mayuan2006@gmail.com>
parents: 19788
diff changeset
641 (&_nl_C_LC_TIME.values[_NL_ITEM_INDEX (ABDAY_1)].string)
b22d13f55232 [gaim-migrate @ 16684]
Ma Yuan <mayuan2006@gmail.com>
parents: 19788
diff changeset
642 # define month_name (&_nl_C_LC_TIME.values[_NL_ITEM_INDEX (MON_1)].string)
b22d13f55232 [gaim-migrate @ 16684]
Ma Yuan <mayuan2006@gmail.com>
parents: 19788
diff changeset
643 # define ab_month_name (&_nl_C_LC_TIME.values[_NL_ITEM_INDEX (ABMON_1)].string)
b22d13f55232 [gaim-migrate @ 16684]
Ma Yuan <mayuan2006@gmail.com>
parents: 19788
diff changeset
644 # define HERE_D_T_FMT (_nl_C_LC_TIME.values[_NL_ITEM_INDEX (D_T_FMT)].string)
b22d13f55232 [gaim-migrate @ 16684]
Ma Yuan <mayuan2006@gmail.com>
parents: 19788
diff changeset
645 # define HERE_D_FMT (_nl_C_LC_TIME.values[_NL_ITEM_INDEX (D_FMT)].string)
b22d13f55232 [gaim-migrate @ 16684]
Ma Yuan <mayuan2006@gmail.com>
parents: 19788
diff changeset
646 # define HERE_AM_STR (_nl_C_LC_TIME.values[_NL_ITEM_INDEX (AM_STR)].string)
b22d13f55232 [gaim-migrate @ 16684]
Ma Yuan <mayuan2006@gmail.com>
parents: 19788
diff changeset
647 # define HERE_PM_STR (_nl_C_LC_TIME.values[_NL_ITEM_INDEX (PM_STR)].string)
b22d13f55232 [gaim-migrate @ 16684]
Ma Yuan <mayuan2006@gmail.com>
parents: 19788
diff changeset
648 # define HERE_T_FMT_AMPM \
b22d13f55232 [gaim-migrate @ 16684]
Ma Yuan <mayuan2006@gmail.com>
parents: 19788
diff changeset
649 (_nl_C_LC_TIME.values[_NL_ITEM_INDEX (T_FMT_AMPM)].string)
b22d13f55232 [gaim-migrate @ 16684]
Ma Yuan <mayuan2006@gmail.com>
parents: 19788
diff changeset
650 # define HERE_T_FMT (_nl_C_LC_TIME.values[_NL_ITEM_INDEX (T_FMT)].string)
b22d13f55232 [gaim-migrate @ 16684]
Ma Yuan <mayuan2006@gmail.com>
parents: 19788
diff changeset
651
b22d13f55232 [gaim-migrate @ 16684]
Ma Yuan <mayuan2006@gmail.com>
parents: 19788
diff changeset
652 # define strncasecmp(s1, s2, n) __strncasecmp (s1, s2, n)
b22d13f55232 [gaim-migrate @ 16684]
Ma Yuan <mayuan2006@gmail.com>
parents: 19788
diff changeset
653 #else
b22d13f55232 [gaim-migrate @ 16684]
Ma Yuan <mayuan2006@gmail.com>
parents: 19788
diff changeset
654 static char const weekday_name[][10] =
b22d13f55232 [gaim-migrate @ 16684]
Ma Yuan <mayuan2006@gmail.com>
parents: 19788
diff changeset
655 {
b22d13f55232 [gaim-migrate @ 16684]
Ma Yuan <mayuan2006@gmail.com>
parents: 19788
diff changeset
656 "Sunday", "Monday", "Tuesday", "Wednesday",
b22d13f55232 [gaim-migrate @ 16684]
Ma Yuan <mayuan2006@gmail.com>
parents: 19788
diff changeset
657 "Thursday", "Friday", "Saturday"
b22d13f55232 [gaim-migrate @ 16684]
Ma Yuan <mayuan2006@gmail.com>
parents: 19788
diff changeset
658 };
b22d13f55232 [gaim-migrate @ 16684]
Ma Yuan <mayuan2006@gmail.com>
parents: 19788
diff changeset
659 static char const ab_weekday_name[][4] =
b22d13f55232 [gaim-migrate @ 16684]
Ma Yuan <mayuan2006@gmail.com>
parents: 19788
diff changeset
660 {
b22d13f55232 [gaim-migrate @ 16684]
Ma Yuan <mayuan2006@gmail.com>
parents: 19788
diff changeset
661 "Sun", "Mon", "Tue", "Wed", "Thu", "Fri", "Sat"
b22d13f55232 [gaim-migrate @ 16684]
Ma Yuan <mayuan2006@gmail.com>
parents: 19788
diff changeset
662 };
b22d13f55232 [gaim-migrate @ 16684]
Ma Yuan <mayuan2006@gmail.com>
parents: 19788
diff changeset
663 static char const month_name[][10] =
b22d13f55232 [gaim-migrate @ 16684]
Ma Yuan <mayuan2006@gmail.com>
parents: 19788
diff changeset
664 {
b22d13f55232 [gaim-migrate @ 16684]
Ma Yuan <mayuan2006@gmail.com>
parents: 19788
diff changeset
665 "January", "February", "March", "April", "May", "June",
b22d13f55232 [gaim-migrate @ 16684]
Ma Yuan <mayuan2006@gmail.com>
parents: 19788
diff changeset
666 "July", "August", "September", "October", "November", "December"
b22d13f55232 [gaim-migrate @ 16684]
Ma Yuan <mayuan2006@gmail.com>
parents: 19788
diff changeset
667 };
b22d13f55232 [gaim-migrate @ 16684]
Ma Yuan <mayuan2006@gmail.com>
parents: 19788
diff changeset
668 static char const ab_month_name[][4] =
b22d13f55232 [gaim-migrate @ 16684]
Ma Yuan <mayuan2006@gmail.com>
parents: 19788
diff changeset
669 {
b22d13f55232 [gaim-migrate @ 16684]
Ma Yuan <mayuan2006@gmail.com>
parents: 19788
diff changeset
670 "Jan", "Feb", "Mar", "Apr", "May", "Jun",
b22d13f55232 [gaim-migrate @ 16684]
Ma Yuan <mayuan2006@gmail.com>
parents: 19788
diff changeset
671 "Jul", "Aug", "Sep", "Oct", "Nov", "Dec"
b22d13f55232 [gaim-migrate @ 16684]
Ma Yuan <mayuan2006@gmail.com>
parents: 19788
diff changeset
672 };
b22d13f55232 [gaim-migrate @ 16684]
Ma Yuan <mayuan2006@gmail.com>
parents: 19788
diff changeset
673 # define HERE_D_T_FMT "%a %b %e %H:%M:%S %Y"
b22d13f55232 [gaim-migrate @ 16684]
Ma Yuan <mayuan2006@gmail.com>
parents: 19788
diff changeset
674 # define HERE_D_FMT "%m/%d/%y"
b22d13f55232 [gaim-migrate @ 16684]
Ma Yuan <mayuan2006@gmail.com>
parents: 19788
diff changeset
675 # define HERE_AM_STR "AM"
b22d13f55232 [gaim-migrate @ 16684]
Ma Yuan <mayuan2006@gmail.com>
parents: 19788
diff changeset
676 # define HERE_PM_STR "PM"
b22d13f55232 [gaim-migrate @ 16684]
Ma Yuan <mayuan2006@gmail.com>
parents: 19788
diff changeset
677 # define HERE_T_FMT_AMPM "%I:%M:%S %p"
b22d13f55232 [gaim-migrate @ 16684]
Ma Yuan <mayuan2006@gmail.com>
parents: 19788
diff changeset
678 # define HERE_T_FMT "%H:%M:%S"
b22d13f55232 [gaim-migrate @ 16684]
Ma Yuan <mayuan2006@gmail.com>
parents: 19788
diff changeset
679
b22d13f55232 [gaim-migrate @ 16684]
Ma Yuan <mayuan2006@gmail.com>
parents: 19788
diff changeset
680 const unsigned short int __mon_yday[2][13] =
b22d13f55232 [gaim-migrate @ 16684]
Ma Yuan <mayuan2006@gmail.com>
parents: 19788
diff changeset
681 {
b22d13f55232 [gaim-migrate @ 16684]
Ma Yuan <mayuan2006@gmail.com>
parents: 19788
diff changeset
682 /* Normal years. */
b22d13f55232 [gaim-migrate @ 16684]
Ma Yuan <mayuan2006@gmail.com>
parents: 19788
diff changeset
683 { 0, 31, 59, 90, 120, 151, 181, 212, 243, 273, 304, 334, 365 },
b22d13f55232 [gaim-migrate @ 16684]
Ma Yuan <mayuan2006@gmail.com>
parents: 19788
diff changeset
684 /* Leap years. */
b22d13f55232 [gaim-migrate @ 16684]
Ma Yuan <mayuan2006@gmail.com>
parents: 19788
diff changeset
685 { 0, 31, 60, 91, 121, 152, 182, 213, 244, 274, 305, 335, 366 }
b22d13f55232 [gaim-migrate @ 16684]
Ma Yuan <mayuan2006@gmail.com>
parents: 19788
diff changeset
686 };
b22d13f55232 [gaim-migrate @ 16684]
Ma Yuan <mayuan2006@gmail.com>
parents: 19788
diff changeset
687 #endif
b22d13f55232 [gaim-migrate @ 16684]
Ma Yuan <mayuan2006@gmail.com>
parents: 19788
diff changeset
688
b22d13f55232 [gaim-migrate @ 16684]
Ma Yuan <mayuan2006@gmail.com>
parents: 19788
diff changeset
689 /* Status of lookup: do we use the locale data or the raw data? */
b22d13f55232 [gaim-migrate @ 16684]
Ma Yuan <mayuan2006@gmail.com>
parents: 19788
diff changeset
690 enum locale_status { not, loc, raw };
b22d13f55232 [gaim-migrate @ 16684]
Ma Yuan <mayuan2006@gmail.com>
parents: 19788
diff changeset
691
b22d13f55232 [gaim-migrate @ 16684]
Ma Yuan <mayuan2006@gmail.com>
parents: 19788
diff changeset
692
b22d13f55232 [gaim-migrate @ 16684]
Ma Yuan <mayuan2006@gmail.com>
parents: 19788
diff changeset
693 #ifndef __isleap
b22d13f55232 [gaim-migrate @ 16684]
Ma Yuan <mayuan2006@gmail.com>
parents: 19788
diff changeset
694 /* Nonzero if YEAR is a leap year (every 4 years,
b22d13f55232 [gaim-migrate @ 16684]
Ma Yuan <mayuan2006@gmail.com>
parents: 19788
diff changeset
695 except every 100th isn't, and every 400th is). */
b22d13f55232 [gaim-migrate @ 16684]
Ma Yuan <mayuan2006@gmail.com>
parents: 19788
diff changeset
696 # define __isleap(year) \
b22d13f55232 [gaim-migrate @ 16684]
Ma Yuan <mayuan2006@gmail.com>
parents: 19788
diff changeset
697 ((year) % 4 == 0 && ((year) % 100 != 0 || (year) % 400 == 0))
b22d13f55232 [gaim-migrate @ 16684]
Ma Yuan <mayuan2006@gmail.com>
parents: 19788
diff changeset
698 #endif
b22d13f55232 [gaim-migrate @ 16684]
Ma Yuan <mayuan2006@gmail.com>
parents: 19788
diff changeset
699
b22d13f55232 [gaim-migrate @ 16684]
Ma Yuan <mayuan2006@gmail.com>
parents: 19788
diff changeset
700 /* Compute the day of the week. */
b22d13f55232 [gaim-migrate @ 16684]
Ma Yuan <mayuan2006@gmail.com>
parents: 19788
diff changeset
701 static void
b22d13f55232 [gaim-migrate @ 16684]
Ma Yuan <mayuan2006@gmail.com>
parents: 19788
diff changeset
702 day_of_the_week (struct tm *tm)
b22d13f55232 [gaim-migrate @ 16684]
Ma Yuan <mayuan2006@gmail.com>
parents: 19788
diff changeset
703 {
b22d13f55232 [gaim-migrate @ 16684]
Ma Yuan <mayuan2006@gmail.com>
parents: 19788
diff changeset
704 /* We know that January 1st 1970 was a Thursday (= 4). Compute the
b22d13f55232 [gaim-migrate @ 16684]
Ma Yuan <mayuan2006@gmail.com>
parents: 19788
diff changeset
705 the difference between this data in the one on TM and so determine
b22d13f55232 [gaim-migrate @ 16684]
Ma Yuan <mayuan2006@gmail.com>
parents: 19788
diff changeset
706 the weekday. */
b22d13f55232 [gaim-migrate @ 16684]
Ma Yuan <mayuan2006@gmail.com>
parents: 19788
diff changeset
707 int corr_year = 1900 + tm->tm_year - (tm->tm_mon < 2);
b22d13f55232 [gaim-migrate @ 16684]
Ma Yuan <mayuan2006@gmail.com>
parents: 19788
diff changeset
708 int wday = (-473
b22d13f55232 [gaim-migrate @ 16684]
Ma Yuan <mayuan2006@gmail.com>
parents: 19788
diff changeset
709 + (365 * (tm->tm_year - 70))
b22d13f55232 [gaim-migrate @ 16684]
Ma Yuan <mayuan2006@gmail.com>
parents: 19788
diff changeset
710 + (corr_year / 4)
b22d13f55232 [gaim-migrate @ 16684]
Ma Yuan <mayuan2006@gmail.com>
parents: 19788
diff changeset
711 - ((corr_year / 4) / 25) + ((corr_year / 4) % 25 < 0)
b22d13f55232 [gaim-migrate @ 16684]
Ma Yuan <mayuan2006@gmail.com>
parents: 19788
diff changeset
712 + (((corr_year / 4) / 25) / 4)
b22d13f55232 [gaim-migrate @ 16684]
Ma Yuan <mayuan2006@gmail.com>
parents: 19788
diff changeset
713 + __mon_yday[0][tm->tm_mon]
b22d13f55232 [gaim-migrate @ 16684]
Ma Yuan <mayuan2006@gmail.com>
parents: 19788
diff changeset
714 + tm->tm_mday - 1);
b22d13f55232 [gaim-migrate @ 16684]
Ma Yuan <mayuan2006@gmail.com>
parents: 19788
diff changeset
715 tm->tm_wday = ((wday % 7) + 7) % 7;
b22d13f55232 [gaim-migrate @ 16684]
Ma Yuan <mayuan2006@gmail.com>
parents: 19788
diff changeset
716 }
b22d13f55232 [gaim-migrate @ 16684]
Ma Yuan <mayuan2006@gmail.com>
parents: 19788
diff changeset
717
b22d13f55232 [gaim-migrate @ 16684]
Ma Yuan <mayuan2006@gmail.com>
parents: 19788
diff changeset
718 /* Compute the day of the year. */
b22d13f55232 [gaim-migrate @ 16684]
Ma Yuan <mayuan2006@gmail.com>
parents: 19788
diff changeset
719 static void
b22d13f55232 [gaim-migrate @ 16684]
Ma Yuan <mayuan2006@gmail.com>
parents: 19788
diff changeset
720 day_of_the_year (struct tm *tm)
b22d13f55232 [gaim-migrate @ 16684]
Ma Yuan <mayuan2006@gmail.com>
parents: 19788
diff changeset
721 {
b22d13f55232 [gaim-migrate @ 16684]
Ma Yuan <mayuan2006@gmail.com>
parents: 19788
diff changeset
722 tm->tm_yday = (__mon_yday[__isleap (1900 + tm->tm_year)][tm->tm_mon]
b22d13f55232 [gaim-migrate @ 16684]
Ma Yuan <mayuan2006@gmail.com>
parents: 19788
diff changeset
723 + (tm->tm_mday - 1));
b22d13f55232 [gaim-migrate @ 16684]
Ma Yuan <mayuan2006@gmail.com>
parents: 19788
diff changeset
724 }
b22d13f55232 [gaim-migrate @ 16684]
Ma Yuan <mayuan2006@gmail.com>
parents: 19788
diff changeset
725
b22d13f55232 [gaim-migrate @ 16684]
Ma Yuan <mayuan2006@gmail.com>
parents: 19788
diff changeset
726 static char *
b22d13f55232 [gaim-migrate @ 16684]
Ma Yuan <mayuan2006@gmail.com>
parents: 19788
diff changeset
727 #ifdef _LIBC
b22d13f55232 [gaim-migrate @ 16684]
Ma Yuan <mayuan2006@gmail.com>
parents: 19788
diff changeset
728 internal_function
b22d13f55232 [gaim-migrate @ 16684]
Ma Yuan <mayuan2006@gmail.com>
parents: 19788
diff changeset
729 #endif
b22d13f55232 [gaim-migrate @ 16684]
Ma Yuan <mayuan2006@gmail.com>
parents: 19788
diff changeset
730 strptime_internal __P ((const char *rp, const char *fmt, struct tm *tm,
b22d13f55232 [gaim-migrate @ 16684]
Ma Yuan <mayuan2006@gmail.com>
parents: 19788
diff changeset
731 enum locale_status *decided, int era_cnt));
b22d13f55232 [gaim-migrate @ 16684]
Ma Yuan <mayuan2006@gmail.com>
parents: 19788
diff changeset
732
b22d13f55232 [gaim-migrate @ 16684]
Ma Yuan <mayuan2006@gmail.com>
parents: 19788
diff changeset
733 static char *
b22d13f55232 [gaim-migrate @ 16684]
Ma Yuan <mayuan2006@gmail.com>
parents: 19788
diff changeset
734 #ifdef _LIBC
b22d13f55232 [gaim-migrate @ 16684]
Ma Yuan <mayuan2006@gmail.com>
parents: 19788
diff changeset
735 internal_function
b22d13f55232 [gaim-migrate @ 16684]
Ma Yuan <mayuan2006@gmail.com>
parents: 19788
diff changeset
736 #endif
b22d13f55232 [gaim-migrate @ 16684]
Ma Yuan <mayuan2006@gmail.com>
parents: 19788
diff changeset
737 strptime_internal (rp, fmt, tm, decided, era_cnt)
b22d13f55232 [gaim-migrate @ 16684]
Ma Yuan <mayuan2006@gmail.com>
parents: 19788
diff changeset
738 const char *rp;
b22d13f55232 [gaim-migrate @ 16684]
Ma Yuan <mayuan2006@gmail.com>
parents: 19788
diff changeset
739 const char *fmt;
b22d13f55232 [gaim-migrate @ 16684]
Ma Yuan <mayuan2006@gmail.com>
parents: 19788
diff changeset
740 struct tm *tm;
b22d13f55232 [gaim-migrate @ 16684]
Ma Yuan <mayuan2006@gmail.com>
parents: 19788
diff changeset
741 enum locale_status *decided;
b22d13f55232 [gaim-migrate @ 16684]
Ma Yuan <mayuan2006@gmail.com>
parents: 19788
diff changeset
742 int era_cnt;
b22d13f55232 [gaim-migrate @ 16684]
Ma Yuan <mayuan2006@gmail.com>
parents: 19788
diff changeset
743 {
b22d13f55232 [gaim-migrate @ 16684]
Ma Yuan <mayuan2006@gmail.com>
parents: 19788
diff changeset
744 const char *rp_backup;
b22d13f55232 [gaim-migrate @ 16684]
Ma Yuan <mayuan2006@gmail.com>
parents: 19788
diff changeset
745 int cnt;
b22d13f55232 [gaim-migrate @ 16684]
Ma Yuan <mayuan2006@gmail.com>
parents: 19788
diff changeset
746 size_t val;
b22d13f55232 [gaim-migrate @ 16684]
Ma Yuan <mayuan2006@gmail.com>
parents: 19788
diff changeset
747 int have_I, is_pm;
b22d13f55232 [gaim-migrate @ 16684]
Ma Yuan <mayuan2006@gmail.com>
parents: 19788
diff changeset
748 int century, want_century;
b22d13f55232 [gaim-migrate @ 16684]
Ma Yuan <mayuan2006@gmail.com>
parents: 19788
diff changeset
749 int want_era;
b22d13f55232 [gaim-migrate @ 16684]
Ma Yuan <mayuan2006@gmail.com>
parents: 19788
diff changeset
750 int have_wday, want_xday;
b22d13f55232 [gaim-migrate @ 16684]
Ma Yuan <mayuan2006@gmail.com>
parents: 19788
diff changeset
751 int have_yday;
b22d13f55232 [gaim-migrate @ 16684]
Ma Yuan <mayuan2006@gmail.com>
parents: 19788
diff changeset
752 int have_mon, have_mday;
b22d13f55232 [gaim-migrate @ 16684]
Ma Yuan <mayuan2006@gmail.com>
parents: 19788
diff changeset
753 #ifdef _NL_CURRENT
b22d13f55232 [gaim-migrate @ 16684]
Ma Yuan <mayuan2006@gmail.com>
parents: 19788
diff changeset
754 size_t num_eras;
b22d13f55232 [gaim-migrate @ 16684]
Ma Yuan <mayuan2006@gmail.com>
parents: 19788
diff changeset
755 #endif
b22d13f55232 [gaim-migrate @ 16684]
Ma Yuan <mayuan2006@gmail.com>
parents: 19788
diff changeset
756 struct era_entry *era;
b22d13f55232 [gaim-migrate @ 16684]
Ma Yuan <mayuan2006@gmail.com>
parents: 19788
diff changeset
757
b22d13f55232 [gaim-migrate @ 16684]
Ma Yuan <mayuan2006@gmail.com>
parents: 19788
diff changeset
758 have_I = is_pm = 0;
b22d13f55232 [gaim-migrate @ 16684]
Ma Yuan <mayuan2006@gmail.com>
parents: 19788
diff changeset
759 century = -1;
b22d13f55232 [gaim-migrate @ 16684]
Ma Yuan <mayuan2006@gmail.com>
parents: 19788
diff changeset
760 want_century = 0;
b22d13f55232 [gaim-migrate @ 16684]
Ma Yuan <mayuan2006@gmail.com>
parents: 19788
diff changeset
761 want_era = 0;
b22d13f55232 [gaim-migrate @ 16684]
Ma Yuan <mayuan2006@gmail.com>
parents: 19788
diff changeset
762 era = NULL;
b22d13f55232 [gaim-migrate @ 16684]
Ma Yuan <mayuan2006@gmail.com>
parents: 19788
diff changeset
763
b22d13f55232 [gaim-migrate @ 16684]
Ma Yuan <mayuan2006@gmail.com>
parents: 19788
diff changeset
764 have_wday = want_xday = have_yday = have_mon = have_mday = 0;
b22d13f55232 [gaim-migrate @ 16684]
Ma Yuan <mayuan2006@gmail.com>
parents: 19788
diff changeset
765
b22d13f55232 [gaim-migrate @ 16684]
Ma Yuan <mayuan2006@gmail.com>
parents: 19788
diff changeset
766 while (*fmt != '\0')
b22d13f55232 [gaim-migrate @ 16684]
Ma Yuan <mayuan2006@gmail.com>
parents: 19788
diff changeset
767 {
b22d13f55232 [gaim-migrate @ 16684]
Ma Yuan <mayuan2006@gmail.com>
parents: 19788
diff changeset
768 /* A white space in the format string matches 0 more or white
b22d13f55232 [gaim-migrate @ 16684]
Ma Yuan <mayuan2006@gmail.com>
parents: 19788
diff changeset
769 space in the input string. */
b22d13f55232 [gaim-migrate @ 16684]
Ma Yuan <mayuan2006@gmail.com>
parents: 19788
diff changeset
770 if (isspace (*fmt))
b22d13f55232 [gaim-migrate @ 16684]
Ma Yuan <mayuan2006@gmail.com>
parents: 19788
diff changeset
771 {
b22d13f55232 [gaim-migrate @ 16684]
Ma Yuan <mayuan2006@gmail.com>
parents: 19788
diff changeset
772 while (isspace (*rp))
b22d13f55232 [gaim-migrate @ 16684]
Ma Yuan <mayuan2006@gmail.com>
parents: 19788
diff changeset
773 ++rp;
b22d13f55232 [gaim-migrate @ 16684]
Ma Yuan <mayuan2006@gmail.com>
parents: 19788
diff changeset
774 ++fmt;
b22d13f55232 [gaim-migrate @ 16684]
Ma Yuan <mayuan2006@gmail.com>
parents: 19788
diff changeset
775 continue;
b22d13f55232 [gaim-migrate @ 16684]
Ma Yuan <mayuan2006@gmail.com>
parents: 19788
diff changeset
776 }
b22d13f55232 [gaim-migrate @ 16684]
Ma Yuan <mayuan2006@gmail.com>
parents: 19788
diff changeset
777
b22d13f55232 [gaim-migrate @ 16684]
Ma Yuan <mayuan2006@gmail.com>
parents: 19788
diff changeset
778 /* Any character but `%' must be matched by the same character
b22d13f55232 [gaim-migrate @ 16684]
Ma Yuan <mayuan2006@gmail.com>
parents: 19788
diff changeset
779 in the iput string. */
b22d13f55232 [gaim-migrate @ 16684]
Ma Yuan <mayuan2006@gmail.com>
parents: 19788
diff changeset
780 if (*fmt != '%')
b22d13f55232 [gaim-migrate @ 16684]
Ma Yuan <mayuan2006@gmail.com>
parents: 19788
diff changeset
781 {
b22d13f55232 [gaim-migrate @ 16684]
Ma Yuan <mayuan2006@gmail.com>
parents: 19788
diff changeset
782 match_char (*fmt++, *rp++);
b22d13f55232 [gaim-migrate @ 16684]
Ma Yuan <mayuan2006@gmail.com>
parents: 19788
diff changeset
783 continue;
b22d13f55232 [gaim-migrate @ 16684]
Ma Yuan <mayuan2006@gmail.com>
parents: 19788
diff changeset
784 }
b22d13f55232 [gaim-migrate @ 16684]
Ma Yuan <mayuan2006@gmail.com>
parents: 19788
diff changeset
785
b22d13f55232 [gaim-migrate @ 16684]
Ma Yuan <mayuan2006@gmail.com>
parents: 19788
diff changeset
786 ++fmt;
b22d13f55232 [gaim-migrate @ 16684]
Ma Yuan <mayuan2006@gmail.com>
parents: 19788
diff changeset
787 #ifndef _NL_CURRENT
b22d13f55232 [gaim-migrate @ 16684]
Ma Yuan <mayuan2006@gmail.com>
parents: 19788
diff changeset
788 /* We need this for handling the `E' modifier. */
b22d13f55232 [gaim-migrate @ 16684]
Ma Yuan <mayuan2006@gmail.com>
parents: 19788
diff changeset
789 start_over:
b22d13f55232 [gaim-migrate @ 16684]
Ma Yuan <mayuan2006@gmail.com>
parents: 19788
diff changeset
790 #endif
b22d13f55232 [gaim-migrate @ 16684]
Ma Yuan <mayuan2006@gmail.com>
parents: 19788
diff changeset
791
b22d13f55232 [gaim-migrate @ 16684]
Ma Yuan <mayuan2006@gmail.com>
parents: 19788
diff changeset
792 /* Make back up of current processing pointer. */
b22d13f55232 [gaim-migrate @ 16684]
Ma Yuan <mayuan2006@gmail.com>
parents: 19788
diff changeset
793 rp_backup = rp;
b22d13f55232 [gaim-migrate @ 16684]
Ma Yuan <mayuan2006@gmail.com>
parents: 19788
diff changeset
794
b22d13f55232 [gaim-migrate @ 16684]
Ma Yuan <mayuan2006@gmail.com>
parents: 19788
diff changeset
795 switch (*fmt++)
b22d13f55232 [gaim-migrate @ 16684]
Ma Yuan <mayuan2006@gmail.com>
parents: 19788
diff changeset
796 {
b22d13f55232 [gaim-migrate @ 16684]
Ma Yuan <mayuan2006@gmail.com>
parents: 19788
diff changeset
797 case '%':
b22d13f55232 [gaim-migrate @ 16684]
Ma Yuan <mayuan2006@gmail.com>
parents: 19788
diff changeset
798 /* Match the `%' character itself. */
b22d13f55232 [gaim-migrate @ 16684]
Ma Yuan <mayuan2006@gmail.com>
parents: 19788
diff changeset
799 match_char ('%', *rp++);
b22d13f55232 [gaim-migrate @ 16684]
Ma Yuan <mayuan2006@gmail.com>
parents: 19788
diff changeset
800 break;
b22d13f55232 [gaim-migrate @ 16684]
Ma Yuan <mayuan2006@gmail.com>
parents: 19788
diff changeset
801 case 'a':
b22d13f55232 [gaim-migrate @ 16684]
Ma Yuan <mayuan2006@gmail.com>
parents: 19788
diff changeset
802 case 'A':
b22d13f55232 [gaim-migrate @ 16684]
Ma Yuan <mayuan2006@gmail.com>
parents: 19788
diff changeset
803 /* Match day of week. */
b22d13f55232 [gaim-migrate @ 16684]
Ma Yuan <mayuan2006@gmail.com>
parents: 19788
diff changeset
804 for (cnt = 0; cnt < 7; ++cnt)
b22d13f55232 [gaim-migrate @ 16684]
Ma Yuan <mayuan2006@gmail.com>
parents: 19788
diff changeset
805 {
b22d13f55232 [gaim-migrate @ 16684]
Ma Yuan <mayuan2006@gmail.com>
parents: 19788
diff changeset
806 #ifdef _NL_CURRENT
b22d13f55232 [gaim-migrate @ 16684]
Ma Yuan <mayuan2006@gmail.com>
parents: 19788
diff changeset
807 if (*decided !=raw)
b22d13f55232 [gaim-migrate @ 16684]
Ma Yuan <mayuan2006@gmail.com>
parents: 19788
diff changeset
808 {
b22d13f55232 [gaim-migrate @ 16684]
Ma Yuan <mayuan2006@gmail.com>
parents: 19788
diff changeset
809 if (match_string (_NL_CURRENT (LC_TIME, DAY_1 + cnt), rp))
b22d13f55232 [gaim-migrate @ 16684]
Ma Yuan <mayuan2006@gmail.com>
parents: 19788
diff changeset
810 {
b22d13f55232 [gaim-migrate @ 16684]
Ma Yuan <mayuan2006@gmail.com>
parents: 19788
diff changeset
811 if (*decided == not
b22d13f55232 [gaim-migrate @ 16684]
Ma Yuan <mayuan2006@gmail.com>
parents: 19788
diff changeset
812 && strcmp (_NL_CURRENT (LC_TIME, DAY_1 + cnt),
b22d13f55232 [gaim-migrate @ 16684]
Ma Yuan <mayuan2006@gmail.com>
parents: 19788
diff changeset
813 weekday_name[cnt]))
b22d13f55232 [gaim-migrate @ 16684]
Ma Yuan <mayuan2006@gmail.com>
parents: 19788
diff changeset
814 *decided = loc;
b22d13f55232 [gaim-migrate @ 16684]
Ma Yuan <mayuan2006@gmail.com>
parents: 19788
diff changeset
815 break;
b22d13f55232 [gaim-migrate @ 16684]
Ma Yuan <mayuan2006@gmail.com>
parents: 19788
diff changeset
816 }
b22d13f55232 [gaim-migrate @ 16684]
Ma Yuan <mayuan2006@gmail.com>
parents: 19788
diff changeset
817 if (match_string (_NL_CURRENT (LC_TIME, ABDAY_1 + cnt), rp))
b22d13f55232 [gaim-migrate @ 16684]
Ma Yuan <mayuan2006@gmail.com>
parents: 19788
diff changeset
818 {
b22d13f55232 [gaim-migrate @ 16684]
Ma Yuan <mayuan2006@gmail.com>
parents: 19788
diff changeset
819 if (*decided == not
b22d13f55232 [gaim-migrate @ 16684]
Ma Yuan <mayuan2006@gmail.com>
parents: 19788
diff changeset
820 && strcmp (_NL_CURRENT (LC_TIME, ABDAY_1 + cnt),
b22d13f55232 [gaim-migrate @ 16684]
Ma Yuan <mayuan2006@gmail.com>
parents: 19788
diff changeset
821 ab_weekday_name[cnt]))
b22d13f55232 [gaim-migrate @ 16684]
Ma Yuan <mayuan2006@gmail.com>
parents: 19788
diff changeset
822 *decided = loc;
b22d13f55232 [gaim-migrate @ 16684]
Ma Yuan <mayuan2006@gmail.com>
parents: 19788
diff changeset
823 break;
b22d13f55232 [gaim-migrate @ 16684]
Ma Yuan <mayuan2006@gmail.com>
parents: 19788
diff changeset
824 }
b22d13f55232 [gaim-migrate @ 16684]
Ma Yuan <mayuan2006@gmail.com>
parents: 19788
diff changeset
825 }
b22d13f55232 [gaim-migrate @ 16684]
Ma Yuan <mayuan2006@gmail.com>
parents: 19788
diff changeset
826 #endif
b22d13f55232 [gaim-migrate @ 16684]
Ma Yuan <mayuan2006@gmail.com>
parents: 19788
diff changeset
827 if (*decided != loc
b22d13f55232 [gaim-migrate @ 16684]
Ma Yuan <mayuan2006@gmail.com>
parents: 19788
diff changeset
828 && (match_string (weekday_name[cnt], rp)
b22d13f55232 [gaim-migrate @ 16684]
Ma Yuan <mayuan2006@gmail.com>
parents: 19788
diff changeset
829 || match_string (ab_weekday_name[cnt], rp)))
b22d13f55232 [gaim-migrate @ 16684]
Ma Yuan <mayuan2006@gmail.com>
parents: 19788
diff changeset
830 {
b22d13f55232 [gaim-migrate @ 16684]
Ma Yuan <mayuan2006@gmail.com>
parents: 19788
diff changeset
831 *decided = raw;
b22d13f55232 [gaim-migrate @ 16684]
Ma Yuan <mayuan2006@gmail.com>
parents: 19788
diff changeset
832 break;
b22d13f55232 [gaim-migrate @ 16684]
Ma Yuan <mayuan2006@gmail.com>
parents: 19788
diff changeset
833 }
b22d13f55232 [gaim-migrate @ 16684]
Ma Yuan <mayuan2006@gmail.com>
parents: 19788
diff changeset
834 }
b22d13f55232 [gaim-migrate @ 16684]
Ma Yuan <mayuan2006@gmail.com>
parents: 19788
diff changeset
835 if (cnt == 7)
b22d13f55232 [gaim-migrate @ 16684]
Ma Yuan <mayuan2006@gmail.com>
parents: 19788
diff changeset
836 /* Does not match a weekday name. */
b22d13f55232 [gaim-migrate @ 16684]
Ma Yuan <mayuan2006@gmail.com>
parents: 19788
diff changeset
837 return NULL;
b22d13f55232 [gaim-migrate @ 16684]
Ma Yuan <mayuan2006@gmail.com>
parents: 19788
diff changeset
838 tm->tm_wday = cnt;
b22d13f55232 [gaim-migrate @ 16684]
Ma Yuan <mayuan2006@gmail.com>
parents: 19788
diff changeset
839 have_wday = 1;
b22d13f55232 [gaim-migrate @ 16684]
Ma Yuan <mayuan2006@gmail.com>
parents: 19788
diff changeset
840 break;
b22d13f55232 [gaim-migrate @ 16684]
Ma Yuan <mayuan2006@gmail.com>
parents: 19788
diff changeset
841 case 'b':
b22d13f55232 [gaim-migrate @ 16684]
Ma Yuan <mayuan2006@gmail.com>
parents: 19788
diff changeset
842 case 'B':
b22d13f55232 [gaim-migrate @ 16684]
Ma Yuan <mayuan2006@gmail.com>
parents: 19788
diff changeset
843 case 'h':
b22d13f55232 [gaim-migrate @ 16684]
Ma Yuan <mayuan2006@gmail.com>
parents: 19788
diff changeset
844 /* Match month name. */
b22d13f55232 [gaim-migrate @ 16684]
Ma Yuan <mayuan2006@gmail.com>
parents: 19788
diff changeset
845 for (cnt = 0; cnt < 12; ++cnt)
b22d13f55232 [gaim-migrate @ 16684]
Ma Yuan <mayuan2006@gmail.com>
parents: 19788
diff changeset
846 {
b22d13f55232 [gaim-migrate @ 16684]
Ma Yuan <mayuan2006@gmail.com>
parents: 19788
diff changeset
847 #ifdef _NL_CURRENT
b22d13f55232 [gaim-migrate @ 16684]
Ma Yuan <mayuan2006@gmail.com>
parents: 19788
diff changeset
848 if (*decided !=raw)
b22d13f55232 [gaim-migrate @ 16684]
Ma Yuan <mayuan2006@gmail.com>
parents: 19788
diff changeset
849 {
b22d13f55232 [gaim-migrate @ 16684]
Ma Yuan <mayuan2006@gmail.com>
parents: 19788
diff changeset
850 if (match_string (_NL_CURRENT (LC_TIME, MON_1 + cnt), rp))
b22d13f55232 [gaim-migrate @ 16684]
Ma Yuan <mayuan2006@gmail.com>
parents: 19788
diff changeset
851 {
b22d13f55232 [gaim-migrate @ 16684]
Ma Yuan <mayuan2006@gmail.com>
parents: 19788
diff changeset
852 if (*decided == not
b22d13f55232 [gaim-migrate @ 16684]
Ma Yuan <mayuan2006@gmail.com>
parents: 19788
diff changeset
853 && strcmp (_NL_CURRENT (LC_TIME, MON_1 + cnt),
b22d13f55232 [gaim-migrate @ 16684]
Ma Yuan <mayuan2006@gmail.com>
parents: 19788
diff changeset
854 month_name[cnt]))
b22d13f55232 [gaim-migrate @ 16684]
Ma Yuan <mayuan2006@gmail.com>
parents: 19788
diff changeset
855 *decided = loc;
b22d13f55232 [gaim-migrate @ 16684]
Ma Yuan <mayuan2006@gmail.com>
parents: 19788
diff changeset
856 break;
b22d13f55232 [gaim-migrate @ 16684]
Ma Yuan <mayuan2006@gmail.com>
parents: 19788
diff changeset
857 }
b22d13f55232 [gaim-migrate @ 16684]
Ma Yuan <mayuan2006@gmail.com>
parents: 19788
diff changeset
858 if (match_string (_NL_CURRENT (LC_TIME, ABMON_1 + cnt), rp))
b22d13f55232 [gaim-migrate @ 16684]
Ma Yuan <mayuan2006@gmail.com>
parents: 19788
diff changeset
859 {
b22d13f55232 [gaim-migrate @ 16684]
Ma Yuan <mayuan2006@gmail.com>
parents: 19788
diff changeset
860 if (*decided == not
b22d13f55232 [gaim-migrate @ 16684]
Ma Yuan <mayuan2006@gmail.com>
parents: 19788
diff changeset
861 && strcmp (_NL_CURRENT (LC_TIME, ABMON_1 + cnt),
b22d13f55232 [gaim-migrate @ 16684]
Ma Yuan <mayuan2006@gmail.com>
parents: 19788
diff changeset
862 ab_month_name[cnt]))
b22d13f55232 [gaim-migrate @ 16684]
Ma Yuan <mayuan2006@gmail.com>
parents: 19788
diff changeset
863 *decided = loc;
b22d13f55232 [gaim-migrate @ 16684]
Ma Yuan <mayuan2006@gmail.com>
parents: 19788
diff changeset
864 break;
b22d13f55232 [gaim-migrate @ 16684]
Ma Yuan <mayuan2006@gmail.com>
parents: 19788
diff changeset
865 }
b22d13f55232 [gaim-migrate @ 16684]
Ma Yuan <mayuan2006@gmail.com>
parents: 19788
diff changeset
866 }
b22d13f55232 [gaim-migrate @ 16684]
Ma Yuan <mayuan2006@gmail.com>
parents: 19788
diff changeset
867 #endif
b22d13f55232 [gaim-migrate @ 16684]
Ma Yuan <mayuan2006@gmail.com>
parents: 19788
diff changeset
868 if (match_string (month_name[cnt], rp)
b22d13f55232 [gaim-migrate @ 16684]
Ma Yuan <mayuan2006@gmail.com>
parents: 19788
diff changeset
869 || match_string (ab_month_name[cnt], rp))
b22d13f55232 [gaim-migrate @ 16684]
Ma Yuan <mayuan2006@gmail.com>
parents: 19788
diff changeset
870 {
b22d13f55232 [gaim-migrate @ 16684]
Ma Yuan <mayuan2006@gmail.com>
parents: 19788
diff changeset
871 *decided = raw;
b22d13f55232 [gaim-migrate @ 16684]
Ma Yuan <mayuan2006@gmail.com>
parents: 19788
diff changeset
872 break;
b22d13f55232 [gaim-migrate @ 16684]
Ma Yuan <mayuan2006@gmail.com>
parents: 19788
diff changeset
873 }
b22d13f55232 [gaim-migrate @ 16684]
Ma Yuan <mayuan2006@gmail.com>
parents: 19788
diff changeset
874 }
b22d13f55232 [gaim-migrate @ 16684]
Ma Yuan <mayuan2006@gmail.com>
parents: 19788
diff changeset
875 if (cnt == 12)
b22d13f55232 [gaim-migrate @ 16684]
Ma Yuan <mayuan2006@gmail.com>
parents: 19788
diff changeset
876 /* Does not match a month name. */
b22d13f55232 [gaim-migrate @ 16684]
Ma Yuan <mayuan2006@gmail.com>
parents: 19788
diff changeset
877 return NULL;
b22d13f55232 [gaim-migrate @ 16684]
Ma Yuan <mayuan2006@gmail.com>
parents: 19788
diff changeset
878 tm->tm_mon = cnt;
b22d13f55232 [gaim-migrate @ 16684]
Ma Yuan <mayuan2006@gmail.com>
parents: 19788
diff changeset
879 want_xday = 1;
b22d13f55232 [gaim-migrate @ 16684]
Ma Yuan <mayuan2006@gmail.com>
parents: 19788
diff changeset
880 break;
b22d13f55232 [gaim-migrate @ 16684]
Ma Yuan <mayuan2006@gmail.com>
parents: 19788
diff changeset
881 case 'c':
b22d13f55232 [gaim-migrate @ 16684]
Ma Yuan <mayuan2006@gmail.com>
parents: 19788
diff changeset
882 /* Match locale's date and time format. */
b22d13f55232 [gaim-migrate @ 16684]
Ma Yuan <mayuan2006@gmail.com>
parents: 19788
diff changeset
883 #ifdef _NL_CURRENT
b22d13f55232 [gaim-migrate @ 16684]
Ma Yuan <mayuan2006@gmail.com>
parents: 19788
diff changeset
884 if (*decided != raw)
b22d13f55232 [gaim-migrate @ 16684]
Ma Yuan <mayuan2006@gmail.com>
parents: 19788
diff changeset
885 {
b22d13f55232 [gaim-migrate @ 16684]
Ma Yuan <mayuan2006@gmail.com>
parents: 19788
diff changeset
886 if (!recursive (_NL_CURRENT (LC_TIME, D_T_FMT)))
b22d13f55232 [gaim-migrate @ 16684]
Ma Yuan <mayuan2006@gmail.com>
parents: 19788
diff changeset
887 {
b22d13f55232 [gaim-migrate @ 16684]
Ma Yuan <mayuan2006@gmail.com>
parents: 19788
diff changeset
888 if (*decided == loc)
b22d13f55232 [gaim-migrate @ 16684]
Ma Yuan <mayuan2006@gmail.com>
parents: 19788
diff changeset
889 return NULL;
b22d13f55232 [gaim-migrate @ 16684]
Ma Yuan <mayuan2006@gmail.com>
parents: 19788
diff changeset
890 else
b22d13f55232 [gaim-migrate @ 16684]
Ma Yuan <mayuan2006@gmail.com>
parents: 19788
diff changeset
891 rp = rp_backup;
b22d13f55232 [gaim-migrate @ 16684]
Ma Yuan <mayuan2006@gmail.com>
parents: 19788
diff changeset
892 }
b22d13f55232 [gaim-migrate @ 16684]
Ma Yuan <mayuan2006@gmail.com>
parents: 19788
diff changeset
893 else
b22d13f55232 [gaim-migrate @ 16684]
Ma Yuan <mayuan2006@gmail.com>
parents: 19788
diff changeset
894 {
b22d13f55232 [gaim-migrate @ 16684]
Ma Yuan <mayuan2006@gmail.com>
parents: 19788
diff changeset
895 if (*decided == not &&
b22d13f55232 [gaim-migrate @ 16684]
Ma Yuan <mayuan2006@gmail.com>
parents: 19788
diff changeset
896 strcmp (_NL_CURRENT (LC_TIME, D_T_FMT), HERE_D_T_FMT))
b22d13f55232 [gaim-migrate @ 16684]
Ma Yuan <mayuan2006@gmail.com>
parents: 19788
diff changeset
897 *decided = loc;
b22d13f55232 [gaim-migrate @ 16684]
Ma Yuan <mayuan2006@gmail.com>
parents: 19788
diff changeset
898 want_xday = 1;
b22d13f55232 [gaim-migrate @ 16684]
Ma Yuan <mayuan2006@gmail.com>
parents: 19788
diff changeset
899 break;
b22d13f55232 [gaim-migrate @ 16684]
Ma Yuan <mayuan2006@gmail.com>
parents: 19788
diff changeset
900 }
b22d13f55232 [gaim-migrate @ 16684]
Ma Yuan <mayuan2006@gmail.com>
parents: 19788
diff changeset
901 *decided = raw;
b22d13f55232 [gaim-migrate @ 16684]
Ma Yuan <mayuan2006@gmail.com>
parents: 19788
diff changeset
902 }
b22d13f55232 [gaim-migrate @ 16684]
Ma Yuan <mayuan2006@gmail.com>
parents: 19788
diff changeset
903 #endif
b22d13f55232 [gaim-migrate @ 16684]
Ma Yuan <mayuan2006@gmail.com>
parents: 19788
diff changeset
904 if (!recursive (HERE_D_T_FMT))
b22d13f55232 [gaim-migrate @ 16684]
Ma Yuan <mayuan2006@gmail.com>
parents: 19788
diff changeset
905 return NULL;
b22d13f55232 [gaim-migrate @ 16684]
Ma Yuan <mayuan2006@gmail.com>
parents: 19788
diff changeset
906 want_xday = 1;
b22d13f55232 [gaim-migrate @ 16684]
Ma Yuan <mayuan2006@gmail.com>
parents: 19788
diff changeset
907 break;
b22d13f55232 [gaim-migrate @ 16684]
Ma Yuan <mayuan2006@gmail.com>
parents: 19788
diff changeset
908 case 'C':
b22d13f55232 [gaim-migrate @ 16684]
Ma Yuan <mayuan2006@gmail.com>
parents: 19788
diff changeset
909 /* Match century number. */
b22d13f55232 [gaim-migrate @ 16684]
Ma Yuan <mayuan2006@gmail.com>
parents: 19788
diff changeset
910 #ifdef _NL_CURRENT
b22d13f55232 [gaim-migrate @ 16684]
Ma Yuan <mayuan2006@gmail.com>
parents: 19788
diff changeset
911 match_century:
b22d13f55232 [gaim-migrate @ 16684]
Ma Yuan <mayuan2006@gmail.com>
parents: 19788
diff changeset
912 #endif
b22d13f55232 [gaim-migrate @ 16684]
Ma Yuan <mayuan2006@gmail.com>
parents: 19788
diff changeset
913 get_number (0, 99, 2);
b22d13f55232 [gaim-migrate @ 16684]
Ma Yuan <mayuan2006@gmail.com>
parents: 19788
diff changeset
914 century = val;
b22d13f55232 [gaim-migrate @ 16684]
Ma Yuan <mayuan2006@gmail.com>
parents: 19788
diff changeset
915 want_xday = 1;
b22d13f55232 [gaim-migrate @ 16684]
Ma Yuan <mayuan2006@gmail.com>
parents: 19788
diff changeset
916 break;
b22d13f55232 [gaim-migrate @ 16684]
Ma Yuan <mayuan2006@gmail.com>
parents: 19788
diff changeset
917 case 'd':
b22d13f55232 [gaim-migrate @ 16684]
Ma Yuan <mayuan2006@gmail.com>
parents: 19788
diff changeset
918 case 'e':
b22d13f55232 [gaim-migrate @ 16684]
Ma Yuan <mayuan2006@gmail.com>
parents: 19788
diff changeset
919 /* Match day of month. */
b22d13f55232 [gaim-migrate @ 16684]
Ma Yuan <mayuan2006@gmail.com>
parents: 19788
diff changeset
920 get_number (1, 31, 2);
b22d13f55232 [gaim-migrate @ 16684]
Ma Yuan <mayuan2006@gmail.com>
parents: 19788
diff changeset
921 tm->tm_mday = val;
b22d13f55232 [gaim-migrate @ 16684]
Ma Yuan <mayuan2006@gmail.com>
parents: 19788
diff changeset
922 have_mday = 1;
b22d13f55232 [gaim-migrate @ 16684]
Ma Yuan <mayuan2006@gmail.com>
parents: 19788
diff changeset
923 want_xday = 1;
b22d13f55232 [gaim-migrate @ 16684]
Ma Yuan <mayuan2006@gmail.com>
parents: 19788
diff changeset
924 break;
b22d13f55232 [gaim-migrate @ 16684]
Ma Yuan <mayuan2006@gmail.com>
parents: 19788
diff changeset
925 case 'F':
b22d13f55232 [gaim-migrate @ 16684]
Ma Yuan <mayuan2006@gmail.com>
parents: 19788
diff changeset
926 if (!recursive ("%Y-%m-%d"))
b22d13f55232 [gaim-migrate @ 16684]
Ma Yuan <mayuan2006@gmail.com>
parents: 19788
diff changeset
927 return NULL;
b22d13f55232 [gaim-migrate @ 16684]
Ma Yuan <mayuan2006@gmail.com>
parents: 19788
diff changeset
928 want_xday = 1;
b22d13f55232 [gaim-migrate @ 16684]
Ma Yuan <mayuan2006@gmail.com>
parents: 19788
diff changeset
929 break;
b22d13f55232 [gaim-migrate @ 16684]
Ma Yuan <mayuan2006@gmail.com>
parents: 19788
diff changeset
930 case 'x':
b22d13f55232 [gaim-migrate @ 16684]
Ma Yuan <mayuan2006@gmail.com>
parents: 19788
diff changeset
931 #ifdef _NL_CURRENT
b22d13f55232 [gaim-migrate @ 16684]
Ma Yuan <mayuan2006@gmail.com>
parents: 19788
diff changeset
932 if (*decided != raw)
b22d13f55232 [gaim-migrate @ 16684]
Ma Yuan <mayuan2006@gmail.com>
parents: 19788
diff changeset
933 {
b22d13f55232 [gaim-migrate @ 16684]
Ma Yuan <mayuan2006@gmail.com>
parents: 19788
diff changeset
934 if (!recursive (_NL_CURRENT (LC_TIME, D_FMT)))
b22d13f55232 [gaim-migrate @ 16684]
Ma Yuan <mayuan2006@gmail.com>
parents: 19788
diff changeset
935 {
b22d13f55232 [gaim-migrate @ 16684]
Ma Yuan <mayuan2006@gmail.com>
parents: 19788
diff changeset
936 if (*decided == loc)
b22d13f55232 [gaim-migrate @ 16684]
Ma Yuan <mayuan2006@gmail.com>
parents: 19788
diff changeset
937 return NULL;
b22d13f55232 [gaim-migrate @ 16684]
Ma Yuan <mayuan2006@gmail.com>
parents: 19788
diff changeset
938 else
b22d13f55232 [gaim-migrate @ 16684]
Ma Yuan <mayuan2006@gmail.com>
parents: 19788
diff changeset
939 rp = rp_backup;
b22d13f55232 [gaim-migrate @ 16684]
Ma Yuan <mayuan2006@gmail.com>
parents: 19788
diff changeset
940 }
b22d13f55232 [gaim-migrate @ 16684]
Ma Yuan <mayuan2006@gmail.com>
parents: 19788
diff changeset
941 else
b22d13f55232 [gaim-migrate @ 16684]
Ma Yuan <mayuan2006@gmail.com>
parents: 19788
diff changeset
942 {
b22d13f55232 [gaim-migrate @ 16684]
Ma Yuan <mayuan2006@gmail.com>
parents: 19788
diff changeset
943 if (*decided == not
b22d13f55232 [gaim-migrate @ 16684]
Ma Yuan <mayuan2006@gmail.com>
parents: 19788
diff changeset
944 && strcmp (_NL_CURRENT (LC_TIME, D_FMT), HERE_D_FMT))
b22d13f55232 [gaim-migrate @ 16684]
Ma Yuan <mayuan2006@gmail.com>
parents: 19788
diff changeset
945 *decided = loc;
b22d13f55232 [gaim-migrate @ 16684]
Ma Yuan <mayuan2006@gmail.com>
parents: 19788
diff changeset
946 want_xday = 1;
b22d13f55232 [gaim-migrate @ 16684]
Ma Yuan <mayuan2006@gmail.com>
parents: 19788
diff changeset
947 break;
b22d13f55232 [gaim-migrate @ 16684]
Ma Yuan <mayuan2006@gmail.com>
parents: 19788
diff changeset
948 }
b22d13f55232 [gaim-migrate @ 16684]
Ma Yuan <mayuan2006@gmail.com>
parents: 19788
diff changeset
949 *decided = raw;
b22d13f55232 [gaim-migrate @ 16684]
Ma Yuan <mayuan2006@gmail.com>
parents: 19788
diff changeset
950 }
b22d13f55232 [gaim-migrate @ 16684]
Ma Yuan <mayuan2006@gmail.com>
parents: 19788
diff changeset
951 #endif
b22d13f55232 [gaim-migrate @ 16684]
Ma Yuan <mayuan2006@gmail.com>
parents: 19788
diff changeset
952 /* Fall through. */
b22d13f55232 [gaim-migrate @ 16684]
Ma Yuan <mayuan2006@gmail.com>
parents: 19788
diff changeset
953 case 'D':
b22d13f55232 [gaim-migrate @ 16684]
Ma Yuan <mayuan2006@gmail.com>
parents: 19788
diff changeset
954 /* Match standard day format. */
b22d13f55232 [gaim-migrate @ 16684]
Ma Yuan <mayuan2006@gmail.com>
parents: 19788
diff changeset
955 if (!recursive (HERE_D_FMT))
b22d13f55232 [gaim-migrate @ 16684]
Ma Yuan <mayuan2006@gmail.com>
parents: 19788
diff changeset
956 return NULL;
b22d13f55232 [gaim-migrate @ 16684]
Ma Yuan <mayuan2006@gmail.com>
parents: 19788
diff changeset
957 want_xday = 1;
b22d13f55232 [gaim-migrate @ 16684]
Ma Yuan <mayuan2006@gmail.com>
parents: 19788
diff changeset
958 break;
b22d13f55232 [gaim-migrate @ 16684]
Ma Yuan <mayuan2006@gmail.com>
parents: 19788
diff changeset
959 case 'k':
b22d13f55232 [gaim-migrate @ 16684]
Ma Yuan <mayuan2006@gmail.com>
parents: 19788
diff changeset
960 case 'H':
b22d13f55232 [gaim-migrate @ 16684]
Ma Yuan <mayuan2006@gmail.com>
parents: 19788
diff changeset
961 /* Match hour in 24-hour clock. */
b22d13f55232 [gaim-migrate @ 16684]
Ma Yuan <mayuan2006@gmail.com>
parents: 19788
diff changeset
962 get_number (0, 23, 2);
b22d13f55232 [gaim-migrate @ 16684]
Ma Yuan <mayuan2006@gmail.com>
parents: 19788
diff changeset
963 tm->tm_hour = val;
b22d13f55232 [gaim-migrate @ 16684]
Ma Yuan <mayuan2006@gmail.com>
parents: 19788
diff changeset
964 have_I = 0;
b22d13f55232 [gaim-migrate @ 16684]
Ma Yuan <mayuan2006@gmail.com>
parents: 19788
diff changeset
965 break;
b22d13f55232 [gaim-migrate @ 16684]
Ma Yuan <mayuan2006@gmail.com>
parents: 19788
diff changeset
966 case 'I':
b22d13f55232 [gaim-migrate @ 16684]
Ma Yuan <mayuan2006@gmail.com>
parents: 19788
diff changeset
967 /* Match hour in 12-hour clock. */
b22d13f55232 [gaim-migrate @ 16684]
Ma Yuan <mayuan2006@gmail.com>
parents: 19788
diff changeset
968 get_number (1, 12, 2);
b22d13f55232 [gaim-migrate @ 16684]
Ma Yuan <mayuan2006@gmail.com>
parents: 19788
diff changeset
969 tm->tm_hour = val % 12;
b22d13f55232 [gaim-migrate @ 16684]
Ma Yuan <mayuan2006@gmail.com>
parents: 19788
diff changeset
970 have_I = 1;
b22d13f55232 [gaim-migrate @ 16684]
Ma Yuan <mayuan2006@gmail.com>
parents: 19788
diff changeset
971 break;
b22d13f55232 [gaim-migrate @ 16684]
Ma Yuan <mayuan2006@gmail.com>
parents: 19788
diff changeset
972 case 'j':
b22d13f55232 [gaim-migrate @ 16684]
Ma Yuan <mayuan2006@gmail.com>
parents: 19788
diff changeset
973 /* Match day number of year. */
b22d13f55232 [gaim-migrate @ 16684]
Ma Yuan <mayuan2006@gmail.com>
parents: 19788
diff changeset
974 get_number (1, 366, 3);
b22d13f55232 [gaim-migrate @ 16684]
Ma Yuan <mayuan2006@gmail.com>
parents: 19788
diff changeset
975 tm->tm_yday = val - 1;
b22d13f55232 [gaim-migrate @ 16684]
Ma Yuan <mayuan2006@gmail.com>
parents: 19788
diff changeset
976 have_yday = 1;
b22d13f55232 [gaim-migrate @ 16684]
Ma Yuan <mayuan2006@gmail.com>
parents: 19788
diff changeset
977 break;
b22d13f55232 [gaim-migrate @ 16684]
Ma Yuan <mayuan2006@gmail.com>
parents: 19788
diff changeset
978 case 'm':
b22d13f55232 [gaim-migrate @ 16684]
Ma Yuan <mayuan2006@gmail.com>
parents: 19788
diff changeset
979 /* Match number of month. */
b22d13f55232 [gaim-migrate @ 16684]
Ma Yuan <mayuan2006@gmail.com>
parents: 19788
diff changeset
980 get_number (1, 12, 2);
b22d13f55232 [gaim-migrate @ 16684]
Ma Yuan <mayuan2006@gmail.com>
parents: 19788
diff changeset
981 tm->tm_mon = val - 1;
b22d13f55232 [gaim-migrate @ 16684]
Ma Yuan <mayuan2006@gmail.com>
parents: 19788
diff changeset
982 have_mon = 1;
b22d13f55232 [gaim-migrate @ 16684]
Ma Yuan <mayuan2006@gmail.com>
parents: 19788
diff changeset
983 want_xday = 1;
b22d13f55232 [gaim-migrate @ 16684]
Ma Yuan <mayuan2006@gmail.com>
parents: 19788
diff changeset
984 break;
b22d13f55232 [gaim-migrate @ 16684]
Ma Yuan <mayuan2006@gmail.com>
parents: 19788
diff changeset
985 case 'M':
b22d13f55232 [gaim-migrate @ 16684]
Ma Yuan <mayuan2006@gmail.com>
parents: 19788
diff changeset
986 /* Match minute. */
b22d13f55232 [gaim-migrate @ 16684]
Ma Yuan <mayuan2006@gmail.com>
parents: 19788
diff changeset
987 get_number (0, 59, 2);
b22d13f55232 [gaim-migrate @ 16684]
Ma Yuan <mayuan2006@gmail.com>
parents: 19788
diff changeset
988 tm->tm_min = val;
b22d13f55232 [gaim-migrate @ 16684]
Ma Yuan <mayuan2006@gmail.com>
parents: 19788
diff changeset
989 break;
b22d13f55232 [gaim-migrate @ 16684]
Ma Yuan <mayuan2006@gmail.com>
parents: 19788
diff changeset
990 case 'n':
b22d13f55232 [gaim-migrate @ 16684]
Ma Yuan <mayuan2006@gmail.com>
parents: 19788
diff changeset
991 case 't':
b22d13f55232 [gaim-migrate @ 16684]
Ma Yuan <mayuan2006@gmail.com>
parents: 19788
diff changeset
992 /* Match any white space. */
b22d13f55232 [gaim-migrate @ 16684]
Ma Yuan <mayuan2006@gmail.com>
parents: 19788
diff changeset
993 while (isspace (*rp))
b22d13f55232 [gaim-migrate @ 16684]
Ma Yuan <mayuan2006@gmail.com>
parents: 19788
diff changeset
994 ++rp;
b22d13f55232 [gaim-migrate @ 16684]
Ma Yuan <mayuan2006@gmail.com>
parents: 19788
diff changeset
995 break;
b22d13f55232 [gaim-migrate @ 16684]
Ma Yuan <mayuan2006@gmail.com>
parents: 19788
diff changeset
996 case 'p':
b22d13f55232 [gaim-migrate @ 16684]
Ma Yuan <mayuan2006@gmail.com>
parents: 19788
diff changeset
997 /* Match locale's equivalent of AM/PM. */
b22d13f55232 [gaim-migrate @ 16684]
Ma Yuan <mayuan2006@gmail.com>
parents: 19788
diff changeset
998 #ifdef _NL_CURRENT
b22d13f55232 [gaim-migrate @ 16684]
Ma Yuan <mayuan2006@gmail.com>
parents: 19788
diff changeset
999 if (*decided != raw)
b22d13f55232 [gaim-migrate @ 16684]
Ma Yuan <mayuan2006@gmail.com>
parents: 19788
diff changeset
1000 {
b22d13f55232 [gaim-migrate @ 16684]
Ma Yuan <mayuan2006@gmail.com>
parents: 19788
diff changeset
1001 if (match_string (_NL_CURRENT (LC_TIME, AM_STR), rp))
b22d13f55232 [gaim-migrate @ 16684]
Ma Yuan <mayuan2006@gmail.com>
parents: 19788
diff changeset
1002 {
b22d13f55232 [gaim-migrate @ 16684]
Ma Yuan <mayuan2006@gmail.com>
parents: 19788
diff changeset
1003 if (strcmp (_NL_CURRENT (LC_TIME, AM_STR), HERE_AM_STR))
b22d13f55232 [gaim-migrate @ 16684]
Ma Yuan <mayuan2006@gmail.com>
parents: 19788
diff changeset
1004 *decided = loc;
b22d13f55232 [gaim-migrate @ 16684]
Ma Yuan <mayuan2006@gmail.com>
parents: 19788
diff changeset
1005 break;
b22d13f55232 [gaim-migrate @ 16684]
Ma Yuan <mayuan2006@gmail.com>
parents: 19788
diff changeset
1006 }
b22d13f55232 [gaim-migrate @ 16684]
Ma Yuan <mayuan2006@gmail.com>
parents: 19788
diff changeset
1007 if (match_string (_NL_CURRENT (LC_TIME, PM_STR), rp))
b22d13f55232 [gaim-migrate @ 16684]
Ma Yuan <mayuan2006@gmail.com>
parents: 19788
diff changeset
1008 {
b22d13f55232 [gaim-migrate @ 16684]
Ma Yuan <mayuan2006@gmail.com>
parents: 19788
diff changeset
1009 if (strcmp (_NL_CURRENT (LC_TIME, PM_STR), HERE_PM_STR))
b22d13f55232 [gaim-migrate @ 16684]
Ma Yuan <mayuan2006@gmail.com>
parents: 19788
diff changeset
1010 *decided = loc;
b22d13f55232 [gaim-migrate @ 16684]
Ma Yuan <mayuan2006@gmail.com>
parents: 19788
diff changeset
1011 is_pm = 1;
b22d13f55232 [gaim-migrate @ 16684]
Ma Yuan <mayuan2006@gmail.com>
parents: 19788
diff changeset
1012 break;
b22d13f55232 [gaim-migrate @ 16684]
Ma Yuan <mayuan2006@gmail.com>
parents: 19788
diff changeset
1013 }
b22d13f55232 [gaim-migrate @ 16684]
Ma Yuan <mayuan2006@gmail.com>
parents: 19788
diff changeset
1014 *decided = raw;
b22d13f55232 [gaim-migrate @ 16684]
Ma Yuan <mayuan2006@gmail.com>
parents: 19788
diff changeset
1015 }
b22d13f55232 [gaim-migrate @ 16684]
Ma Yuan <mayuan2006@gmail.com>
parents: 19788
diff changeset
1016 #endif
b22d13f55232 [gaim-migrate @ 16684]
Ma Yuan <mayuan2006@gmail.com>
parents: 19788
diff changeset
1017 if (!match_string (HERE_AM_STR, rp))
b22d13f55232 [gaim-migrate @ 16684]
Ma Yuan <mayuan2006@gmail.com>
parents: 19788
diff changeset
1018 if (match_string (HERE_PM_STR, rp))
b22d13f55232 [gaim-migrate @ 16684]
Ma Yuan <mayuan2006@gmail.com>
parents: 19788
diff changeset
1019 is_pm = 1;
b22d13f55232 [gaim-migrate @ 16684]
Ma Yuan <mayuan2006@gmail.com>
parents: 19788
diff changeset
1020 else
b22d13f55232 [gaim-migrate @ 16684]
Ma Yuan <mayuan2006@gmail.com>
parents: 19788
diff changeset
1021 return NULL;
b22d13f55232 [gaim-migrate @ 16684]
Ma Yuan <mayuan2006@gmail.com>
parents: 19788
diff changeset
1022 break;
b22d13f55232 [gaim-migrate @ 16684]
Ma Yuan <mayuan2006@gmail.com>
parents: 19788
diff changeset
1023 case 'r':
b22d13f55232 [gaim-migrate @ 16684]
Ma Yuan <mayuan2006@gmail.com>
parents: 19788
diff changeset
1024 #ifdef _NL_CURRENT
b22d13f55232 [gaim-migrate @ 16684]
Ma Yuan <mayuan2006@gmail.com>
parents: 19788
diff changeset
1025 if (*decided != raw)
b22d13f55232 [gaim-migrate @ 16684]
Ma Yuan <mayuan2006@gmail.com>
parents: 19788
diff changeset
1026 {
b22d13f55232 [gaim-migrate @ 16684]
Ma Yuan <mayuan2006@gmail.com>
parents: 19788
diff changeset
1027 if (!recursive (_NL_CURRENT (LC_TIME, T_FMT_AMPM)))
b22d13f55232 [gaim-migrate @ 16684]
Ma Yuan <mayuan2006@gmail.com>
parents: 19788
diff changeset
1028 {
b22d13f55232 [gaim-migrate @ 16684]
Ma Yuan <mayuan2006@gmail.com>
parents: 19788
diff changeset
1029 if (*decided == loc)
b22d13f55232 [gaim-migrate @ 16684]
Ma Yuan <mayuan2006@gmail.com>
parents: 19788
diff changeset
1030 return NULL;
b22d13f55232 [gaim-migrate @ 16684]
Ma Yuan <mayuan2006@gmail.com>
parents: 19788
diff changeset
1031 else
b22d13f55232 [gaim-migrate @ 16684]
Ma Yuan <mayuan2006@gmail.com>
parents: 19788
diff changeset
1032 rp = rp_backup;
b22d13f55232 [gaim-migrate @ 16684]
Ma Yuan <mayuan2006@gmail.com>
parents: 19788
diff changeset
1033 }
b22d13f55232 [gaim-migrate @ 16684]
Ma Yuan <mayuan2006@gmail.com>
parents: 19788
diff changeset
1034 else
b22d13f55232 [gaim-migrate @ 16684]
Ma Yuan <mayuan2006@gmail.com>
parents: 19788
diff changeset
1035 {
b22d13f55232 [gaim-migrate @ 16684]
Ma Yuan <mayuan2006@gmail.com>
parents: 19788
diff changeset
1036 if (*decided == not &&
b22d13f55232 [gaim-migrate @ 16684]
Ma Yuan <mayuan2006@gmail.com>
parents: 19788
diff changeset
1037 strcmp (_NL_CURRENT (LC_TIME, T_FMT_AMPM),
b22d13f55232 [gaim-migrate @ 16684]
Ma Yuan <mayuan2006@gmail.com>
parents: 19788
diff changeset
1038 HERE_T_FMT_AMPM))
b22d13f55232 [gaim-migrate @ 16684]
Ma Yuan <mayuan2006@gmail.com>
parents: 19788
diff changeset
1039 *decided = loc;
b22d13f55232 [gaim-migrate @ 16684]
Ma Yuan <mayuan2006@gmail.com>
parents: 19788
diff changeset
1040 break;
b22d13f55232 [gaim-migrate @ 16684]
Ma Yuan <mayuan2006@gmail.com>
parents: 19788
diff changeset
1041 }
b22d13f55232 [gaim-migrate @ 16684]
Ma Yuan <mayuan2006@gmail.com>
parents: 19788
diff changeset
1042 *decided = raw;
b22d13f55232 [gaim-migrate @ 16684]
Ma Yuan <mayuan2006@gmail.com>
parents: 19788
diff changeset
1043 }
b22d13f55232 [gaim-migrate @ 16684]
Ma Yuan <mayuan2006@gmail.com>
parents: 19788
diff changeset
1044 #endif
b22d13f55232 [gaim-migrate @ 16684]
Ma Yuan <mayuan2006@gmail.com>
parents: 19788
diff changeset
1045 if (!recursive (HERE_T_FMT_AMPM))
b22d13f55232 [gaim-migrate @ 16684]
Ma Yuan <mayuan2006@gmail.com>
parents: 19788
diff changeset
1046 return NULL;
b22d13f55232 [gaim-migrate @ 16684]
Ma Yuan <mayuan2006@gmail.com>
parents: 19788
diff changeset
1047 break;
b22d13f55232 [gaim-migrate @ 16684]
Ma Yuan <mayuan2006@gmail.com>
parents: 19788
diff changeset
1048 case 'R':
b22d13f55232 [gaim-migrate @ 16684]
Ma Yuan <mayuan2006@gmail.com>
parents: 19788
diff changeset
1049 if (!recursive ("%H:%M"))
b22d13f55232 [gaim-migrate @ 16684]
Ma Yuan <mayuan2006@gmail.com>
parents: 19788
diff changeset
1050 return NULL;
b22d13f55232 [gaim-migrate @ 16684]
Ma Yuan <mayuan2006@gmail.com>
parents: 19788
diff changeset
1051 break;
b22d13f55232 [gaim-migrate @ 16684]
Ma Yuan <mayuan2006@gmail.com>
parents: 19788
diff changeset
1052 case 's':
b22d13f55232 [gaim-migrate @ 16684]
Ma Yuan <mayuan2006@gmail.com>
parents: 19788
diff changeset
1053 {
b22d13f55232 [gaim-migrate @ 16684]
Ma Yuan <mayuan2006@gmail.com>
parents: 19788
diff changeset
1054 /* The number of seconds may be very high so we cannot use
b22d13f55232 [gaim-migrate @ 16684]
Ma Yuan <mayuan2006@gmail.com>
parents: 19788
diff changeset
1055 the `get_number' macro. Instead read the number
b22d13f55232 [gaim-migrate @ 16684]
Ma Yuan <mayuan2006@gmail.com>
parents: 19788
diff changeset
1056 character for character and construct the result while
b22d13f55232 [gaim-migrate @ 16684]
Ma Yuan <mayuan2006@gmail.com>
parents: 19788
diff changeset
1057 doing this. */
b22d13f55232 [gaim-migrate @ 16684]
Ma Yuan <mayuan2006@gmail.com>
parents: 19788
diff changeset
1058 time_t secs = 0;
b22d13f55232 [gaim-migrate @ 16684]
Ma Yuan <mayuan2006@gmail.com>
parents: 19788
diff changeset
1059 if (*rp < '0' || *rp > '9')
b22d13f55232 [gaim-migrate @ 16684]
Ma Yuan <mayuan2006@gmail.com>
parents: 19788
diff changeset
1060 /* We need at least one digit. */
b22d13f55232 [gaim-migrate @ 16684]
Ma Yuan <mayuan2006@gmail.com>
parents: 19788
diff changeset
1061 return NULL;
b22d13f55232 [gaim-migrate @ 16684]
Ma Yuan <mayuan2006@gmail.com>
parents: 19788
diff changeset
1062
b22d13f55232 [gaim-migrate @ 16684]
Ma Yuan <mayuan2006@gmail.com>
parents: 19788
diff changeset
1063 do
b22d13f55232 [gaim-migrate @ 16684]
Ma Yuan <mayuan2006@gmail.com>
parents: 19788
diff changeset
1064 {
b22d13f55232 [gaim-migrate @ 16684]
Ma Yuan <mayuan2006@gmail.com>
parents: 19788
diff changeset
1065 secs *= 10;
b22d13f55232 [gaim-migrate @ 16684]
Ma Yuan <mayuan2006@gmail.com>
parents: 19788
diff changeset
1066 secs += *rp++ - '0';
b22d13f55232 [gaim-migrate @ 16684]
Ma Yuan <mayuan2006@gmail.com>
parents: 19788
diff changeset
1067 }
b22d13f55232 [gaim-migrate @ 16684]
Ma Yuan <mayuan2006@gmail.com>
parents: 19788
diff changeset
1068 while (*rp >= '0' && *rp <= '9');
b22d13f55232 [gaim-migrate @ 16684]
Ma Yuan <mayuan2006@gmail.com>
parents: 19788
diff changeset
1069
b22d13f55232 [gaim-migrate @ 16684]
Ma Yuan <mayuan2006@gmail.com>
parents: 19788
diff changeset
1070 if (localtime_r (&secs, tm) == NULL)
b22d13f55232 [gaim-migrate @ 16684]
Ma Yuan <mayuan2006@gmail.com>
parents: 19788
diff changeset
1071 /* Error in function. */
b22d13f55232 [gaim-migrate @ 16684]
Ma Yuan <mayuan2006@gmail.com>
parents: 19788
diff changeset
1072 return NULL;
b22d13f55232 [gaim-migrate @ 16684]
Ma Yuan <mayuan2006@gmail.com>
parents: 19788
diff changeset
1073 }
b22d13f55232 [gaim-migrate @ 16684]
Ma Yuan <mayuan2006@gmail.com>
parents: 19788
diff changeset
1074 break;
b22d13f55232 [gaim-migrate @ 16684]
Ma Yuan <mayuan2006@gmail.com>
parents: 19788
diff changeset
1075 case 'S':
b22d13f55232 [gaim-migrate @ 16684]
Ma Yuan <mayuan2006@gmail.com>
parents: 19788
diff changeset
1076 get_number (0, 61, 2);
b22d13f55232 [gaim-migrate @ 16684]
Ma Yuan <mayuan2006@gmail.com>
parents: 19788
diff changeset
1077 tm->tm_sec = val;
b22d13f55232 [gaim-migrate @ 16684]
Ma Yuan <mayuan2006@gmail.com>
parents: 19788
diff changeset
1078 break;
b22d13f55232 [gaim-migrate @ 16684]
Ma Yuan <mayuan2006@gmail.com>
parents: 19788
diff changeset
1079 case 'X':
b22d13f55232 [gaim-migrate @ 16684]
Ma Yuan <mayuan2006@gmail.com>
parents: 19788
diff changeset
1080 #ifdef _NL_CURRENT
b22d13f55232 [gaim-migrate @ 16684]
Ma Yuan <mayuan2006@gmail.com>
parents: 19788
diff changeset
1081 if (*decided != raw)
b22d13f55232 [gaim-migrate @ 16684]
Ma Yuan <mayuan2006@gmail.com>
parents: 19788
diff changeset
1082 {
b22d13f55232 [gaim-migrate @ 16684]
Ma Yuan <mayuan2006@gmail.com>
parents: 19788
diff changeset
1083 if (!recursive (_NL_CURRENT (LC_TIME, T_FMT)))
b22d13f55232 [gaim-migrate @ 16684]
Ma Yuan <mayuan2006@gmail.com>
parents: 19788
diff changeset
1084 {
b22d13f55232 [gaim-migrate @ 16684]
Ma Yuan <mayuan2006@gmail.com>
parents: 19788
diff changeset
1085 if (*decided == loc)
b22d13f55232 [gaim-migrate @ 16684]
Ma Yuan <mayuan2006@gmail.com>
parents: 19788
diff changeset
1086 return NULL;
b22d13f55232 [gaim-migrate @ 16684]
Ma Yuan <mayuan2006@gmail.com>
parents: 19788
diff changeset
1087 else
b22d13f55232 [gaim-migrate @ 16684]
Ma Yuan <mayuan2006@gmail.com>
parents: 19788
diff changeset
1088 rp = rp_backup;
b22d13f55232 [gaim-migrate @ 16684]
Ma Yuan <mayuan2006@gmail.com>
parents: 19788
diff changeset
1089 }
b22d13f55232 [gaim-migrate @ 16684]
Ma Yuan <mayuan2006@gmail.com>
parents: 19788
diff changeset
1090 else
b22d13f55232 [gaim-migrate @ 16684]
Ma Yuan <mayuan2006@gmail.com>
parents: 19788
diff changeset
1091 {
b22d13f55232 [gaim-migrate @ 16684]
Ma Yuan <mayuan2006@gmail.com>
parents: 19788
diff changeset
1092 if (strcmp (_NL_CURRENT (LC_TIME, T_FMT), HERE_T_FMT))
b22d13f55232 [gaim-migrate @ 16684]
Ma Yuan <mayuan2006@gmail.com>
parents: 19788
diff changeset
1093 *decided = loc;
b22d13f55232 [gaim-migrate @ 16684]
Ma Yuan <mayuan2006@gmail.com>
parents: 19788
diff changeset
1094 break;
b22d13f55232 [gaim-migrate @ 16684]
Ma Yuan <mayuan2006@gmail.com>
parents: 19788
diff changeset
1095 }
b22d13f55232 [gaim-migrate @ 16684]
Ma Yuan <mayuan2006@gmail.com>
parents: 19788
diff changeset
1096 *decided = raw;
b22d13f55232 [gaim-migrate @ 16684]
Ma Yuan <mayuan2006@gmail.com>
parents: 19788
diff changeset
1097 }
b22d13f55232 [gaim-migrate @ 16684]
Ma Yuan <mayuan2006@gmail.com>
parents: 19788
diff changeset
1098 #endif
b22d13f55232 [gaim-migrate @ 16684]
Ma Yuan <mayuan2006@gmail.com>
parents: 19788
diff changeset
1099 /* Fall through. */
b22d13f55232 [gaim-migrate @ 16684]
Ma Yuan <mayuan2006@gmail.com>
parents: 19788
diff changeset
1100 case 'T':
b22d13f55232 [gaim-migrate @ 16684]
Ma Yuan <mayuan2006@gmail.com>
parents: 19788
diff changeset
1101 if (!recursive (HERE_T_FMT))
b22d13f55232 [gaim-migrate @ 16684]
Ma Yuan <mayuan2006@gmail.com>
parents: 19788
diff changeset
1102 return NULL;
b22d13f55232 [gaim-migrate @ 16684]
Ma Yuan <mayuan2006@gmail.com>
parents: 19788
diff changeset
1103 break;
b22d13f55232 [gaim-migrate @ 16684]
Ma Yuan <mayuan2006@gmail.com>
parents: 19788
diff changeset
1104 case 'u':
b22d13f55232 [gaim-migrate @ 16684]
Ma Yuan <mayuan2006@gmail.com>
parents: 19788
diff changeset
1105 get_number (1, 7, 1);
b22d13f55232 [gaim-migrate @ 16684]
Ma Yuan <mayuan2006@gmail.com>
parents: 19788
diff changeset
1106 tm->tm_wday = val % 7;
b22d13f55232 [gaim-migrate @ 16684]
Ma Yuan <mayuan2006@gmail.com>
parents: 19788
diff changeset
1107 have_wday = 1;
b22d13f55232 [gaim-migrate @ 16684]
Ma Yuan <mayuan2006@gmail.com>
parents: 19788
diff changeset
1108 break;
b22d13f55232 [gaim-migrate @ 16684]
Ma Yuan <mayuan2006@gmail.com>
parents: 19788
diff changeset
1109 case 'g':
b22d13f55232 [gaim-migrate @ 16684]
Ma Yuan <mayuan2006@gmail.com>
parents: 19788
diff changeset
1110 get_number (0, 99, 2);
b22d13f55232 [gaim-migrate @ 16684]
Ma Yuan <mayuan2006@gmail.com>
parents: 19788
diff changeset
1111 /* XXX This cannot determine any field in TM. */
b22d13f55232 [gaim-migrate @ 16684]
Ma Yuan <mayuan2006@gmail.com>
parents: 19788
diff changeset
1112 break;
b22d13f55232 [gaim-migrate @ 16684]
Ma Yuan <mayuan2006@gmail.com>
parents: 19788
diff changeset
1113 case 'G':
b22d13f55232 [gaim-migrate @ 16684]
Ma Yuan <mayuan2006@gmail.com>
parents: 19788
diff changeset
1114 if (*rp < '0' || *rp > '9')
b22d13f55232 [gaim-migrate @ 16684]
Ma Yuan <mayuan2006@gmail.com>
parents: 19788
diff changeset
1115 return NULL;
b22d13f55232 [gaim-migrate @ 16684]
Ma Yuan <mayuan2006@gmail.com>
parents: 19788
diff changeset
1116 /* XXX Ignore the number since we would need some more
b22d13f55232 [gaim-migrate @ 16684]
Ma Yuan <mayuan2006@gmail.com>
parents: 19788
diff changeset
1117 information to compute a real date. */
b22d13f55232 [gaim-migrate @ 16684]
Ma Yuan <mayuan2006@gmail.com>
parents: 19788
diff changeset
1118 do
b22d13f55232 [gaim-migrate @ 16684]
Ma Yuan <mayuan2006@gmail.com>
parents: 19788
diff changeset
1119 ++rp;
b22d13f55232 [gaim-migrate @ 16684]
Ma Yuan <mayuan2006@gmail.com>
parents: 19788
diff changeset
1120 while (*rp >= '0' && *rp <= '9');
b22d13f55232 [gaim-migrate @ 16684]
Ma Yuan <mayuan2006@gmail.com>
parents: 19788
diff changeset
1121 break;
b22d13f55232 [gaim-migrate @ 16684]
Ma Yuan <mayuan2006@gmail.com>
parents: 19788
diff changeset
1122 case 'U':
b22d13f55232 [gaim-migrate @ 16684]
Ma Yuan <mayuan2006@gmail.com>
parents: 19788
diff changeset
1123 case 'V':
b22d13f55232 [gaim-migrate @ 16684]
Ma Yuan <mayuan2006@gmail.com>
parents: 19788
diff changeset
1124 case 'W':
b22d13f55232 [gaim-migrate @ 16684]
Ma Yuan <mayuan2006@gmail.com>
parents: 19788
diff changeset
1125 get_number (0, 53, 2);
b22d13f55232 [gaim-migrate @ 16684]
Ma Yuan <mayuan2006@gmail.com>
parents: 19788
diff changeset
1126 /* XXX This cannot determine any field in TM without some
b22d13f55232 [gaim-migrate @ 16684]
Ma Yuan <mayuan2006@gmail.com>
parents: 19788
diff changeset
1127 information. */
b22d13f55232 [gaim-migrate @ 16684]
Ma Yuan <mayuan2006@gmail.com>
parents: 19788
diff changeset
1128 break;
b22d13f55232 [gaim-migrate @ 16684]
Ma Yuan <mayuan2006@gmail.com>
parents: 19788
diff changeset
1129 case 'w':
b22d13f55232 [gaim-migrate @ 16684]
Ma Yuan <mayuan2006@gmail.com>
parents: 19788
diff changeset
1130 /* Match number of weekday. */
b22d13f55232 [gaim-migrate @ 16684]
Ma Yuan <mayuan2006@gmail.com>
parents: 19788
diff changeset
1131 get_number (0, 6, 1);
b22d13f55232 [gaim-migrate @ 16684]
Ma Yuan <mayuan2006@gmail.com>
parents: 19788
diff changeset
1132 tm->tm_wday = val;
b22d13f55232 [gaim-migrate @ 16684]
Ma Yuan <mayuan2006@gmail.com>
parents: 19788
diff changeset
1133 have_wday = 1;
b22d13f55232 [gaim-migrate @ 16684]
Ma Yuan <mayuan2006@gmail.com>
parents: 19788
diff changeset
1134 break;
b22d13f55232 [gaim-migrate @ 16684]
Ma Yuan <mayuan2006@gmail.com>
parents: 19788
diff changeset
1135 case 'y':
b22d13f55232 [gaim-migrate @ 16684]
Ma Yuan <mayuan2006@gmail.com>
parents: 19788
diff changeset
1136 #ifdef _NL_CURRENT
b22d13f55232 [gaim-migrate @ 16684]
Ma Yuan <mayuan2006@gmail.com>
parents: 19788
diff changeset
1137 match_year_in_century:
b22d13f55232 [gaim-migrate @ 16684]
Ma Yuan <mayuan2006@gmail.com>
parents: 19788
diff changeset
1138 #endif
b22d13f55232 [gaim-migrate @ 16684]
Ma Yuan <mayuan2006@gmail.com>
parents: 19788
diff changeset
1139 /* Match year within century. */
b22d13f55232 [gaim-migrate @ 16684]
Ma Yuan <mayuan2006@gmail.com>
parents: 19788
diff changeset
1140 get_number (0, 99, 2);
b22d13f55232 [gaim-migrate @ 16684]
Ma Yuan <mayuan2006@gmail.com>
parents: 19788
diff changeset
1141 /* The "Year 2000: The Millennium Rollover" paper suggests that
b22d13f55232 [gaim-migrate @ 16684]
Ma Yuan <mayuan2006@gmail.com>
parents: 19788
diff changeset
1142 values in the range 69-99 refer to the twentieth century. */
b22d13f55232 [gaim-migrate @ 16684]
Ma Yuan <mayuan2006@gmail.com>
parents: 19788
diff changeset
1143 tm->tm_year = val >= 69 ? val : val + 100;
b22d13f55232 [gaim-migrate @ 16684]
Ma Yuan <mayuan2006@gmail.com>
parents: 19788
diff changeset
1144 /* Indicate that we want to use the century, if specified. */
b22d13f55232 [gaim-migrate @ 16684]
Ma Yuan <mayuan2006@gmail.com>
parents: 19788
diff changeset
1145 want_century = 1;
b22d13f55232 [gaim-migrate @ 16684]
Ma Yuan <mayuan2006@gmail.com>
parents: 19788
diff changeset
1146 want_xday = 1;
b22d13f55232 [gaim-migrate @ 16684]
Ma Yuan <mayuan2006@gmail.com>
parents: 19788
diff changeset
1147 break;
b22d13f55232 [gaim-migrate @ 16684]
Ma Yuan <mayuan2006@gmail.com>
parents: 19788
diff changeset
1148 case 'Y':
b22d13f55232 [gaim-migrate @ 16684]
Ma Yuan <mayuan2006@gmail.com>
parents: 19788
diff changeset
1149 /* Match year including century number. */
b22d13f55232 [gaim-migrate @ 16684]
Ma Yuan <mayuan2006@gmail.com>
parents: 19788
diff changeset
1150 get_number (0, 9999, 4);
b22d13f55232 [gaim-migrate @ 16684]
Ma Yuan <mayuan2006@gmail.com>
parents: 19788
diff changeset
1151 tm->tm_year = val - 1900;
b22d13f55232 [gaim-migrate @ 16684]
Ma Yuan <mayuan2006@gmail.com>
parents: 19788
diff changeset
1152 want_century = 0;
b22d13f55232 [gaim-migrate @ 16684]
Ma Yuan <mayuan2006@gmail.com>
parents: 19788
diff changeset
1153 want_xday = 1;
b22d13f55232 [gaim-migrate @ 16684]
Ma Yuan <mayuan2006@gmail.com>
parents: 19788
diff changeset
1154 break;
b22d13f55232 [gaim-migrate @ 16684]
Ma Yuan <mayuan2006@gmail.com>
parents: 19788
diff changeset
1155 case 'Z':
b22d13f55232 [gaim-migrate @ 16684]
Ma Yuan <mayuan2006@gmail.com>
parents: 19788
diff changeset
1156 /* XXX How to handle this? */
b22d13f55232 [gaim-migrate @ 16684]
Ma Yuan <mayuan2006@gmail.com>
parents: 19788
diff changeset
1157 break;
b22d13f55232 [gaim-migrate @ 16684]
Ma Yuan <mayuan2006@gmail.com>
parents: 19788
diff changeset
1158 case 'E':
b22d13f55232 [gaim-migrate @ 16684]
Ma Yuan <mayuan2006@gmail.com>
parents: 19788
diff changeset
1159 #ifdef _NL_CURRENT
b22d13f55232 [gaim-migrate @ 16684]
Ma Yuan <mayuan2006@gmail.com>
parents: 19788
diff changeset
1160 switch (*fmt++)
b22d13f55232 [gaim-migrate @ 16684]
Ma Yuan <mayuan2006@gmail.com>
parents: 19788
diff changeset
1161 {
b22d13f55232 [gaim-migrate @ 16684]
Ma Yuan <mayuan2006@gmail.com>
parents: 19788
diff changeset
1162 case 'c':
b22d13f55232 [gaim-migrate @ 16684]
Ma Yuan <mayuan2006@gmail.com>
parents: 19788
diff changeset
1163 /* Match locale's alternate date and time format. */
b22d13f55232 [gaim-migrate @ 16684]
Ma Yuan <mayuan2006@gmail.com>
parents: 19788
diff changeset
1164 if (*decided != raw)
b22d13f55232 [gaim-migrate @ 16684]
Ma Yuan <mayuan2006@gmail.com>
parents: 19788
diff changeset
1165 {
b22d13f55232 [gaim-migrate @ 16684]
Ma Yuan <mayuan2006@gmail.com>
parents: 19788
diff changeset
1166 const char *fmt = _NL_CURRENT (LC_TIME, ERA_D_T_FMT);
b22d13f55232 [gaim-migrate @ 16684]
Ma Yuan <mayuan2006@gmail.com>
parents: 19788
diff changeset
1167
b22d13f55232 [gaim-migrate @ 16684]
Ma Yuan <mayuan2006@gmail.com>
parents: 19788
diff changeset
1168 if (*fmt == '\0')
b22d13f55232 [gaim-migrate @ 16684]
Ma Yuan <mayuan2006@gmail.com>
parents: 19788
diff changeset
1169 fmt = _NL_CURRENT (LC_TIME, D_T_FMT);
b22d13f55232 [gaim-migrate @ 16684]
Ma Yuan <mayuan2006@gmail.com>
parents: 19788
diff changeset
1170
b22d13f55232 [gaim-migrate @ 16684]
Ma Yuan <mayuan2006@gmail.com>
parents: 19788
diff changeset
1171 if (!recursive (fmt))
b22d13f55232 [gaim-migrate @ 16684]
Ma Yuan <mayuan2006@gmail.com>
parents: 19788
diff changeset
1172 {
b22d13f55232 [gaim-migrate @ 16684]
Ma Yuan <mayuan2006@gmail.com>
parents: 19788
diff changeset
1173 if (*decided == loc)
b22d13f55232 [gaim-migrate @ 16684]
Ma Yuan <mayuan2006@gmail.com>
parents: 19788
diff changeset
1174 return NULL;
b22d13f55232 [gaim-migrate @ 16684]
Ma Yuan <mayuan2006@gmail.com>
parents: 19788
diff changeset
1175 else
b22d13f55232 [gaim-migrate @ 16684]
Ma Yuan <mayuan2006@gmail.com>
parents: 19788
diff changeset
1176 rp = rp_backup;
b22d13f55232 [gaim-migrate @ 16684]
Ma Yuan <mayuan2006@gmail.com>
parents: 19788
diff changeset
1177 }
b22d13f55232 [gaim-migrate @ 16684]
Ma Yuan <mayuan2006@gmail.com>
parents: 19788
diff changeset
1178 else
b22d13f55232 [gaim-migrate @ 16684]
Ma Yuan <mayuan2006@gmail.com>
parents: 19788
diff changeset
1179 {
b22d13f55232 [gaim-migrate @ 16684]
Ma Yuan <mayuan2006@gmail.com>
parents: 19788
diff changeset
1180 if (strcmp (fmt, HERE_D_T_FMT))
b22d13f55232 [gaim-migrate @ 16684]
Ma Yuan <mayuan2006@gmail.com>
parents: 19788
diff changeset
1181 *decided = loc;
b22d13f55232 [gaim-migrate @ 16684]
Ma Yuan <mayuan2006@gmail.com>
parents: 19788
diff changeset
1182 want_xday = 1;
b22d13f55232 [gaim-migrate @ 16684]
Ma Yuan <mayuan2006@gmail.com>
parents: 19788
diff changeset
1183 break;
b22d13f55232 [gaim-migrate @ 16684]
Ma Yuan <mayuan2006@gmail.com>
parents: 19788
diff changeset
1184 }
b22d13f55232 [gaim-migrate @ 16684]
Ma Yuan <mayuan2006@gmail.com>
parents: 19788
diff changeset
1185 *decided = raw;
b22d13f55232 [gaim-migrate @ 16684]
Ma Yuan <mayuan2006@gmail.com>
parents: 19788
diff changeset
1186 }
b22d13f55232 [gaim-migrate @ 16684]
Ma Yuan <mayuan2006@gmail.com>
parents: 19788
diff changeset
1187 /* The C locale has no era information, so use the
b22d13f55232 [gaim-migrate @ 16684]
Ma Yuan <mayuan2006@gmail.com>
parents: 19788
diff changeset
1188 normal representation. */
b22d13f55232 [gaim-migrate @ 16684]
Ma Yuan <mayuan2006@gmail.com>
parents: 19788
diff changeset
1189 if (!recursive (HERE_D_T_FMT))
b22d13f55232 [gaim-migrate @ 16684]
Ma Yuan <mayuan2006@gmail.com>
parents: 19788
diff changeset
1190 return NULL;
b22d13f55232 [gaim-migrate @ 16684]
Ma Yuan <mayuan2006@gmail.com>
parents: 19788
diff changeset
1191 want_xday = 1;
b22d13f55232 [gaim-migrate @ 16684]
Ma Yuan <mayuan2006@gmail.com>
parents: 19788
diff changeset
1192 break;
b22d13f55232 [gaim-migrate @ 16684]
Ma Yuan <mayuan2006@gmail.com>
parents: 19788
diff changeset
1193 case 'C':
b22d13f55232 [gaim-migrate @ 16684]
Ma Yuan <mayuan2006@gmail.com>
parents: 19788
diff changeset
1194 if (*decided != raw)
b22d13f55232 [gaim-migrate @ 16684]
Ma Yuan <mayuan2006@gmail.com>
parents: 19788
diff changeset
1195 {
b22d13f55232 [gaim-migrate @ 16684]
Ma Yuan <mayuan2006@gmail.com>
parents: 19788
diff changeset
1196 if (era_cnt >= 0)
b22d13f55232 [gaim-migrate @ 16684]
Ma Yuan <mayuan2006@gmail.com>
parents: 19788
diff changeset
1197 {
b22d13f55232 [gaim-migrate @ 16684]
Ma Yuan <mayuan2006@gmail.com>
parents: 19788
diff changeset
1198 era = _nl_select_era_entry (era_cnt);
b22d13f55232 [gaim-migrate @ 16684]
Ma Yuan <mayuan2006@gmail.com>
parents: 19788
diff changeset
1199 if (match_string (era->era_name, rp))
b22d13f55232 [gaim-migrate @ 16684]
Ma Yuan <mayuan2006@gmail.com>
parents: 19788
diff changeset
1200 {
b22d13f55232 [gaim-migrate @ 16684]
Ma Yuan <mayuan2006@gmail.com>
parents: 19788
diff changeset
1201 *decided = loc;
b22d13f55232 [gaim-migrate @ 16684]
Ma Yuan <mayuan2006@gmail.com>
parents: 19788
diff changeset
1202 break;
b22d13f55232 [gaim-migrate @ 16684]
Ma Yuan <mayuan2006@gmail.com>
parents: 19788
diff changeset
1203 }
b22d13f55232 [gaim-migrate @ 16684]
Ma Yuan <mayuan2006@gmail.com>
parents: 19788
diff changeset
1204 else
b22d13f55232 [gaim-migrate @ 16684]
Ma Yuan <mayuan2006@gmail.com>
parents: 19788
diff changeset
1205 return NULL;
b22d13f55232 [gaim-migrate @ 16684]
Ma Yuan <mayuan2006@gmail.com>
parents: 19788
diff changeset
1206 }
b22d13f55232 [gaim-migrate @ 16684]
Ma Yuan <mayuan2006@gmail.com>
parents: 19788
diff changeset
1207 else
b22d13f55232 [gaim-migrate @ 16684]
Ma Yuan <mayuan2006@gmail.com>
parents: 19788
diff changeset
1208 {
b22d13f55232 [gaim-migrate @ 16684]
Ma Yuan <mayuan2006@gmail.com>
parents: 19788
diff changeset
1209 num_eras = _NL_CURRENT_WORD (LC_TIME,
b22d13f55232 [gaim-migrate @ 16684]
Ma Yuan <mayuan2006@gmail.com>
parents: 19788
diff changeset
1210 _NL_TIME_ERA_NUM_ENTRIES);
b22d13f55232 [gaim-migrate @ 16684]
Ma Yuan <mayuan2006@gmail.com>
parents: 19788
diff changeset
1211 for (era_cnt = 0; era_cnt < (int) num_eras;
b22d13f55232 [gaim-migrate @ 16684]
Ma Yuan <mayuan2006@gmail.com>
parents: 19788
diff changeset
1212 ++era_cnt, rp = rp_backup)
b22d13f55232 [gaim-migrate @ 16684]
Ma Yuan <mayuan2006@gmail.com>
parents: 19788
diff changeset
1213 {
b22d13f55232 [gaim-migrate @ 16684]
Ma Yuan <mayuan2006@gmail.com>
parents: 19788
diff changeset
1214 era = _nl_select_era_entry (era_cnt);
b22d13f55232 [gaim-migrate @ 16684]
Ma Yuan <mayuan2006@gmail.com>
parents: 19788
diff changeset
1215 if (match_string (era->era_name, rp))
b22d13f55232 [gaim-migrate @ 16684]
Ma Yuan <mayuan2006@gmail.com>
parents: 19788
diff changeset
1216 {
b22d13f55232 [gaim-migrate @ 16684]
Ma Yuan <mayuan2006@gmail.com>
parents: 19788
diff changeset
1217 *decided = loc;
b22d13f55232 [gaim-migrate @ 16684]
Ma Yuan <mayuan2006@gmail.com>
parents: 19788
diff changeset
1218 break;
b22d13f55232 [gaim-migrate @ 16684]
Ma Yuan <mayuan2006@gmail.com>
parents: 19788
diff changeset
1219 }
b22d13f55232 [gaim-migrate @ 16684]
Ma Yuan <mayuan2006@gmail.com>
parents: 19788
diff changeset
1220 }
b22d13f55232 [gaim-migrate @ 16684]
Ma Yuan <mayuan2006@gmail.com>
parents: 19788
diff changeset
1221 if (era_cnt == (int) num_eras)
b22d13f55232 [gaim-migrate @ 16684]
Ma Yuan <mayuan2006@gmail.com>
parents: 19788
diff changeset
1222 {
b22d13f55232 [gaim-migrate @ 16684]
Ma Yuan <mayuan2006@gmail.com>
parents: 19788
diff changeset
1223 era_cnt = -1;
b22d13f55232 [gaim-migrate @ 16684]
Ma Yuan <mayuan2006@gmail.com>
parents: 19788
diff changeset
1224 if (*decided == loc)
b22d13f55232 [gaim-migrate @ 16684]
Ma Yuan <mayuan2006@gmail.com>
parents: 19788
diff changeset
1225 return NULL;
b22d13f55232 [gaim-migrate @ 16684]
Ma Yuan <mayuan2006@gmail.com>
parents: 19788
diff changeset
1226 }
b22d13f55232 [gaim-migrate @ 16684]
Ma Yuan <mayuan2006@gmail.com>
parents: 19788
diff changeset
1227 else
b22d13f55232 [gaim-migrate @ 16684]
Ma Yuan <mayuan2006@gmail.com>
parents: 19788
diff changeset
1228 break;
b22d13f55232 [gaim-migrate @ 16684]
Ma Yuan <mayuan2006@gmail.com>
parents: 19788
diff changeset
1229 }
b22d13f55232 [gaim-migrate @ 16684]
Ma Yuan <mayuan2006@gmail.com>
parents: 19788
diff changeset
1230
b22d13f55232 [gaim-migrate @ 16684]
Ma Yuan <mayuan2006@gmail.com>
parents: 19788
diff changeset
1231 *decided = raw;
b22d13f55232 [gaim-migrate @ 16684]
Ma Yuan <mayuan2006@gmail.com>
parents: 19788
diff changeset
1232 }
b22d13f55232 [gaim-migrate @ 16684]
Ma Yuan <mayuan2006@gmail.com>
parents: 19788
diff changeset
1233 /* The C locale has no era information, so use the
b22d13f55232 [gaim-migrate @ 16684]
Ma Yuan <mayuan2006@gmail.com>
parents: 19788
diff changeset
1234 normal representation. */
b22d13f55232 [gaim-migrate @ 16684]
Ma Yuan <mayuan2006@gmail.com>
parents: 19788
diff changeset
1235 goto match_century;
b22d13f55232 [gaim-migrate @ 16684]
Ma Yuan <mayuan2006@gmail.com>
parents: 19788
diff changeset
1236 case 'y':
b22d13f55232 [gaim-migrate @ 16684]
Ma Yuan <mayuan2006@gmail.com>
parents: 19788
diff changeset
1237 if (*decided == raw)
b22d13f55232 [gaim-migrate @ 16684]
Ma Yuan <mayuan2006@gmail.com>
parents: 19788
diff changeset
1238 goto match_year_in_century;
b22d13f55232 [gaim-migrate @ 16684]
Ma Yuan <mayuan2006@gmail.com>
parents: 19788
diff changeset
1239
b22d13f55232 [gaim-migrate @ 16684]
Ma Yuan <mayuan2006@gmail.com>
parents: 19788
diff changeset
1240 get_number(0, 9999, 4);
b22d13f55232 [gaim-migrate @ 16684]
Ma Yuan <mayuan2006@gmail.com>
parents: 19788
diff changeset
1241 tm->tm_year = val;
b22d13f55232 [gaim-migrate @ 16684]
Ma Yuan <mayuan2006@gmail.com>
parents: 19788
diff changeset
1242 want_era = 1;
b22d13f55232 [gaim-migrate @ 16684]
Ma Yuan <mayuan2006@gmail.com>
parents: 19788
diff changeset
1243 want_xday = 1;
b22d13f55232 [gaim-migrate @ 16684]
Ma Yuan <mayuan2006@gmail.com>
parents: 19788
diff changeset
1244 break;
b22d13f55232 [gaim-migrate @ 16684]
Ma Yuan <mayuan2006@gmail.com>
parents: 19788
diff changeset
1245 case 'Y':
b22d13f55232 [gaim-migrate @ 16684]
Ma Yuan <mayuan2006@gmail.com>
parents: 19788
diff changeset
1246 if (*decided != raw)
b22d13f55232 [gaim-migrate @ 16684]
Ma Yuan <mayuan2006@gmail.com>
parents: 19788
diff changeset
1247 {
b22d13f55232 [gaim-migrate @ 16684]
Ma Yuan <mayuan2006@gmail.com>
parents: 19788
diff changeset
1248 num_eras = _NL_CURRENT_WORD (LC_TIME,
b22d13f55232 [gaim-migrate @ 16684]
Ma Yuan <mayuan2006@gmail.com>
parents: 19788
diff changeset
1249 _NL_TIME_ERA_NUM_ENTRIES);
b22d13f55232 [gaim-migrate @ 16684]
Ma Yuan <mayuan2006@gmail.com>
parents: 19788
diff changeset
1250 for (era_cnt = 0; era_cnt < (int) num_eras;
b22d13f55232 [gaim-migrate @ 16684]
Ma Yuan <mayuan2006@gmail.com>
parents: 19788
diff changeset
1251 ++era_cnt, rp = rp_backup)
b22d13f55232 [gaim-migrate @ 16684]
Ma Yuan <mayuan2006@gmail.com>
parents: 19788
diff changeset
1252 {
b22d13f55232 [gaim-migrate @ 16684]
Ma Yuan <mayuan2006@gmail.com>
parents: 19788
diff changeset
1253 era = _nl_select_era_entry (era_cnt);
b22d13f55232 [gaim-migrate @ 16684]
Ma Yuan <mayuan2006@gmail.com>
parents: 19788
diff changeset
1254 if (recursive (era->era_format))
b22d13f55232 [gaim-migrate @ 16684]
Ma Yuan <mayuan2006@gmail.com>
parents: 19788
diff changeset
1255 break;
b22d13f55232 [gaim-migrate @ 16684]
Ma Yuan <mayuan2006@gmail.com>
parents: 19788
diff changeset
1256 }
b22d13f55232 [gaim-migrate @ 16684]
Ma Yuan <mayuan2006@gmail.com>
parents: 19788
diff changeset
1257 if (era_cnt == (int) num_eras)
b22d13f55232 [gaim-migrate @ 16684]
Ma Yuan <mayuan2006@gmail.com>
parents: 19788
diff changeset
1258 {
b22d13f55232 [gaim-migrate @ 16684]
Ma Yuan <mayuan2006@gmail.com>
parents: 19788
diff changeset
1259 era_cnt = -1;
b22d13f55232 [gaim-migrate @ 16684]
Ma Yuan <mayuan2006@gmail.com>
parents: 19788
diff changeset
1260 if (*decided == loc)
b22d13f55232 [gaim-migrate @ 16684]
Ma Yuan <mayuan2006@gmail.com>
parents: 19788
diff changeset
1261 return NULL;
b22d13f55232 [gaim-migrate @ 16684]
Ma Yuan <mayuan2006@gmail.com>
parents: 19788
diff changeset
1262 else
b22d13f55232 [gaim-migrate @ 16684]
Ma Yuan <mayuan2006@gmail.com>
parents: 19788
diff changeset
1263 rp = rp_backup;
b22d13f55232 [gaim-migrate @ 16684]
Ma Yuan <mayuan2006@gmail.com>
parents: 19788
diff changeset
1264 }
b22d13f55232 [gaim-migrate @ 16684]
Ma Yuan <mayuan2006@gmail.com>
parents: 19788
diff changeset
1265 else
b22d13f55232 [gaim-migrate @ 16684]
Ma Yuan <mayuan2006@gmail.com>
parents: 19788
diff changeset
1266 {
b22d13f55232 [gaim-migrate @ 16684]
Ma Yuan <mayuan2006@gmail.com>
parents: 19788
diff changeset
1267 *decided = loc;
b22d13f55232 [gaim-migrate @ 16684]
Ma Yuan <mayuan2006@gmail.com>
parents: 19788
diff changeset
1268 era_cnt = -1;
b22d13f55232 [gaim-migrate @ 16684]
Ma Yuan <mayuan2006@gmail.com>
parents: 19788
diff changeset
1269 break;
b22d13f55232 [gaim-migrate @ 16684]
Ma Yuan <mayuan2006@gmail.com>
parents: 19788
diff changeset
1270 }
b22d13f55232 [gaim-migrate @ 16684]
Ma Yuan <mayuan2006@gmail.com>
parents: 19788
diff changeset
1271
b22d13f55232 [gaim-migrate @ 16684]
Ma Yuan <mayuan2006@gmail.com>
parents: 19788
diff changeset
1272 *decided = raw;
b22d13f55232 [gaim-migrate @ 16684]
Ma Yuan <mayuan2006@gmail.com>
parents: 19788
diff changeset
1273 }
b22d13f55232 [gaim-migrate @ 16684]
Ma Yuan <mayuan2006@gmail.com>
parents: 19788
diff changeset
1274 get_number (0, 9999, 4);
b22d13f55232 [gaim-migrate @ 16684]
Ma Yuan <mayuan2006@gmail.com>
parents: 19788
diff changeset
1275 tm->tm_year = val - 1900;
b22d13f55232 [gaim-migrate @ 16684]
Ma Yuan <mayuan2006@gmail.com>
parents: 19788
diff changeset
1276 want_century = 0;
b22d13f55232 [gaim-migrate @ 16684]
Ma Yuan <mayuan2006@gmail.com>
parents: 19788
diff changeset
1277 want_xday = 1;
b22d13f55232 [gaim-migrate @ 16684]
Ma Yuan <mayuan2006@gmail.com>
parents: 19788
diff changeset
1278 break;
b22d13f55232 [gaim-migrate @ 16684]
Ma Yuan <mayuan2006@gmail.com>
parents: 19788
diff changeset
1279 case 'x':
b22d13f55232 [gaim-migrate @ 16684]
Ma Yuan <mayuan2006@gmail.com>
parents: 19788
diff changeset
1280 if (*decided != raw)
b22d13f55232 [gaim-migrate @ 16684]
Ma Yuan <mayuan2006@gmail.com>
parents: 19788
diff changeset
1281 {
b22d13f55232 [gaim-migrate @ 16684]
Ma Yuan <mayuan2006@gmail.com>
parents: 19788
diff changeset
1282 const char *fmt = _NL_CURRENT (LC_TIME, ERA_D_FMT);
b22d13f55232 [gaim-migrate @ 16684]
Ma Yuan <mayuan2006@gmail.com>
parents: 19788
diff changeset
1283
b22d13f55232 [gaim-migrate @ 16684]
Ma Yuan <mayuan2006@gmail.com>
parents: 19788
diff changeset
1284 if (*fmt == '\0')
b22d13f55232 [gaim-migrate @ 16684]
Ma Yuan <mayuan2006@gmail.com>
parents: 19788
diff changeset
1285 fmt = _NL_CURRENT (LC_TIME, D_FMT);
b22d13f55232 [gaim-migrate @ 16684]
Ma Yuan <mayuan2006@gmail.com>
parents: 19788
diff changeset
1286
b22d13f55232 [gaim-migrate @ 16684]
Ma Yuan <mayuan2006@gmail.com>
parents: 19788
diff changeset
1287 if (!recursive (fmt))
b22d13f55232 [gaim-migrate @ 16684]
Ma Yuan <mayuan2006@gmail.com>
parents: 19788
diff changeset
1288 {
b22d13f55232 [gaim-migrate @ 16684]
Ma Yuan <mayuan2006@gmail.com>
parents: 19788
diff changeset
1289 if (*decided == loc)
b22d13f55232 [gaim-migrate @ 16684]
Ma Yuan <mayuan2006@gmail.com>
parents: 19788
diff changeset
1290 return NULL;
b22d13f55232 [gaim-migrate @ 16684]
Ma Yuan <mayuan2006@gmail.com>
parents: 19788
diff changeset
1291 else
b22d13f55232 [gaim-migrate @ 16684]
Ma Yuan <mayuan2006@gmail.com>
parents: 19788
diff changeset
1292 rp = rp_backup;
b22d13f55232 [gaim-migrate @ 16684]
Ma Yuan <mayuan2006@gmail.com>
parents: 19788
diff changeset
1293 }
b22d13f55232 [gaim-migrate @ 16684]
Ma Yuan <mayuan2006@gmail.com>
parents: 19788
diff changeset
1294 else
b22d13f55232 [gaim-migrate @ 16684]
Ma Yuan <mayuan2006@gmail.com>
parents: 19788
diff changeset
1295 {
b22d13f55232 [gaim-migrate @ 16684]
Ma Yuan <mayuan2006@gmail.com>
parents: 19788
diff changeset
1296 if (strcmp (fmt, HERE_D_FMT))
b22d13f55232 [gaim-migrate @ 16684]
Ma Yuan <mayuan2006@gmail.com>
parents: 19788
diff changeset
1297 *decided = loc;
b22d13f55232 [gaim-migrate @ 16684]
Ma Yuan <mayuan2006@gmail.com>
parents: 19788
diff changeset
1298 break;
b22d13f55232 [gaim-migrate @ 16684]
Ma Yuan <mayuan2006@gmail.com>
parents: 19788
diff changeset
1299 }
b22d13f55232 [gaim-migrate @ 16684]
Ma Yuan <mayuan2006@gmail.com>
parents: 19788
diff changeset
1300 *decided = raw;
b22d13f55232 [gaim-migrate @ 16684]
Ma Yuan <mayuan2006@gmail.com>
parents: 19788
diff changeset
1301 }
b22d13f55232 [gaim-migrate @ 16684]
Ma Yuan <mayuan2006@gmail.com>
parents: 19788
diff changeset
1302 if (!recursive (HERE_D_FMT))
b22d13f55232 [gaim-migrate @ 16684]
Ma Yuan <mayuan2006@gmail.com>
parents: 19788
diff changeset
1303 return NULL;
b22d13f55232 [gaim-migrate @ 16684]
Ma Yuan <mayuan2006@gmail.com>
parents: 19788
diff changeset
1304 break;
b22d13f55232 [gaim-migrate @ 16684]
Ma Yuan <mayuan2006@gmail.com>
parents: 19788
diff changeset
1305 case 'X':
b22d13f55232 [gaim-migrate @ 16684]
Ma Yuan <mayuan2006@gmail.com>
parents: 19788
diff changeset
1306 if (*decided != raw)
b22d13f55232 [gaim-migrate @ 16684]
Ma Yuan <mayuan2006@gmail.com>
parents: 19788
diff changeset
1307 {
b22d13f55232 [gaim-migrate @ 16684]
Ma Yuan <mayuan2006@gmail.com>
parents: 19788
diff changeset
1308 const char *fmt = _NL_CURRENT (LC_TIME, ERA_T_FMT);
b22d13f55232 [gaim-migrate @ 16684]
Ma Yuan <mayuan2006@gmail.com>
parents: 19788
diff changeset
1309
b22d13f55232 [gaim-migrate @ 16684]
Ma Yuan <mayuan2006@gmail.com>
parents: 19788
diff changeset
1310 if (*fmt == '\0')
b22d13f55232 [gaim-migrate @ 16684]
Ma Yuan <mayuan2006@gmail.com>
parents: 19788
diff changeset
1311 fmt = _NL_CURRENT (LC_TIME, T_FMT);
b22d13f55232 [gaim-migrate @ 16684]
Ma Yuan <mayuan2006@gmail.com>
parents: 19788
diff changeset
1312
b22d13f55232 [gaim-migrate @ 16684]
Ma Yuan <mayuan2006@gmail.com>
parents: 19788
diff changeset
1313 if (!recursive (fmt))
b22d13f55232 [gaim-migrate @ 16684]
Ma Yuan <mayuan2006@gmail.com>
parents: 19788
diff changeset
1314 {
b22d13f55232 [gaim-migrate @ 16684]
Ma Yuan <mayuan2006@gmail.com>
parents: 19788
diff changeset
1315 if (*decided == loc)
b22d13f55232 [gaim-migrate @ 16684]
Ma Yuan <mayuan2006@gmail.com>
parents: 19788
diff changeset
1316 return NULL;
b22d13f55232 [gaim-migrate @ 16684]
Ma Yuan <mayuan2006@gmail.com>
parents: 19788
diff changeset
1317 else
b22d13f55232 [gaim-migrate @ 16684]
Ma Yuan <mayuan2006@gmail.com>
parents: 19788
diff changeset
1318 rp = rp_backup;
b22d13f55232 [gaim-migrate @ 16684]
Ma Yuan <mayuan2006@gmail.com>
parents: 19788
diff changeset
1319 }
b22d13f55232 [gaim-migrate @ 16684]
Ma Yuan <mayuan2006@gmail.com>
parents: 19788
diff changeset
1320 else
b22d13f55232 [gaim-migrate @ 16684]
Ma Yuan <mayuan2006@gmail.com>
parents: 19788
diff changeset
1321 {
b22d13f55232 [gaim-migrate @ 16684]
Ma Yuan <mayuan2006@gmail.com>
parents: 19788
diff changeset
1322 if (strcmp (fmt, HERE_T_FMT))
b22d13f55232 [gaim-migrate @ 16684]
Ma Yuan <mayuan2006@gmail.com>
parents: 19788
diff changeset
1323 *decided = loc;
b22d13f55232 [gaim-migrate @ 16684]
Ma Yuan <mayuan2006@gmail.com>
parents: 19788
diff changeset
1324 break;
b22d13f55232 [gaim-migrate @ 16684]
Ma Yuan <mayuan2006@gmail.com>
parents: 19788
diff changeset
1325 }
b22d13f55232 [gaim-migrate @ 16684]
Ma Yuan <mayuan2006@gmail.com>
parents: 19788
diff changeset
1326 *decided = raw;
b22d13f55232 [gaim-migrate @ 16684]
Ma Yuan <mayuan2006@gmail.com>
parents: 19788
diff changeset
1327 }
b22d13f55232 [gaim-migrate @ 16684]
Ma Yuan <mayuan2006@gmail.com>
parents: 19788
diff changeset
1328 if (!recursive (HERE_T_FMT))
b22d13f55232 [gaim-migrate @ 16684]
Ma Yuan <mayuan2006@gmail.com>
parents: 19788
diff changeset
1329 return NULL;
b22d13f55232 [gaim-migrate @ 16684]
Ma Yuan <mayuan2006@gmail.com>
parents: 19788
diff changeset
1330 break;
b22d13f55232 [gaim-migrate @ 16684]
Ma Yuan <mayuan2006@gmail.com>
parents: 19788
diff changeset
1331 default:
b22d13f55232 [gaim-migrate @ 16684]
Ma Yuan <mayuan2006@gmail.com>
parents: 19788
diff changeset
1332 return NULL;
b22d13f55232 [gaim-migrate @ 16684]
Ma Yuan <mayuan2006@gmail.com>
parents: 19788
diff changeset
1333 }
b22d13f55232 [gaim-migrate @ 16684]
Ma Yuan <mayuan2006@gmail.com>
parents: 19788
diff changeset
1334 break;
b22d13f55232 [gaim-migrate @ 16684]
Ma Yuan <mayuan2006@gmail.com>
parents: 19788
diff changeset
1335 #else
b22d13f55232 [gaim-migrate @ 16684]
Ma Yuan <mayuan2006@gmail.com>
parents: 19788
diff changeset
1336 /* We have no information about the era format. Just use
b22d13f55232 [gaim-migrate @ 16684]
Ma Yuan <mayuan2006@gmail.com>
parents: 19788
diff changeset
1337 the normal format. */
b22d13f55232 [gaim-migrate @ 16684]
Ma Yuan <mayuan2006@gmail.com>
parents: 19788
diff changeset
1338 if (*fmt != 'c' && *fmt != 'C' && *fmt != 'y' && *fmt != 'Y'
b22d13f55232 [gaim-migrate @ 16684]
Ma Yuan <mayuan2006@gmail.com>
parents: 19788
diff changeset
1339 && *fmt != 'x' && *fmt != 'X')
b22d13f55232 [gaim-migrate @ 16684]
Ma Yuan <mayuan2006@gmail.com>
parents: 19788
diff changeset
1340 /* This is an illegal format. */
b22d13f55232 [gaim-migrate @ 16684]
Ma Yuan <mayuan2006@gmail.com>
parents: 19788
diff changeset
1341 return NULL;
b22d13f55232 [gaim-migrate @ 16684]
Ma Yuan <mayuan2006@gmail.com>
parents: 19788
diff changeset
1342
b22d13f55232 [gaim-migrate @ 16684]
Ma Yuan <mayuan2006@gmail.com>
parents: 19788
diff changeset
1343 goto start_over;
b22d13f55232 [gaim-migrate @ 16684]
Ma Yuan <mayuan2006@gmail.com>
parents: 19788
diff changeset
1344 #endif
b22d13f55232 [gaim-migrate @ 16684]
Ma Yuan <mayuan2006@gmail.com>
parents: 19788
diff changeset
1345 case 'O':
b22d13f55232 [gaim-migrate @ 16684]
Ma Yuan <mayuan2006@gmail.com>
parents: 19788
diff changeset
1346 switch (*fmt++)
b22d13f55232 [gaim-migrate @ 16684]
Ma Yuan <mayuan2006@gmail.com>
parents: 19788
diff changeset
1347 {
b22d13f55232 [gaim-migrate @ 16684]
Ma Yuan <mayuan2006@gmail.com>
parents: 19788
diff changeset
1348 case 'd':
b22d13f55232 [gaim-migrate @ 16684]
Ma Yuan <mayuan2006@gmail.com>
parents: 19788
diff changeset
1349 case 'e':
b22d13f55232 [gaim-migrate @ 16684]
Ma Yuan <mayuan2006@gmail.com>
parents: 19788
diff changeset
1350 /* Match day of month using alternate numeric symbols. */
b22d13f55232 [gaim-migrate @ 16684]
Ma Yuan <mayuan2006@gmail.com>
parents: 19788
diff changeset
1351 get_alt_number (1, 31, 2);
b22d13f55232 [gaim-migrate @ 16684]
Ma Yuan <mayuan2006@gmail.com>
parents: 19788
diff changeset
1352 tm->tm_mday = val;
b22d13f55232 [gaim-migrate @ 16684]
Ma Yuan <mayuan2006@gmail.com>
parents: 19788
diff changeset
1353 have_mday = 1;
b22d13f55232 [gaim-migrate @ 16684]
Ma Yuan <mayuan2006@gmail.com>
parents: 19788
diff changeset
1354 want_xday = 1;
b22d13f55232 [gaim-migrate @ 16684]
Ma Yuan <mayuan2006@gmail.com>
parents: 19788
diff changeset
1355 break;
b22d13f55232 [gaim-migrate @ 16684]
Ma Yuan <mayuan2006@gmail.com>
parents: 19788
diff changeset
1356 case 'H':
b22d13f55232 [gaim-migrate @ 16684]
Ma Yuan <mayuan2006@gmail.com>
parents: 19788
diff changeset
1357 /* Match hour in 24-hour clock using alternate numeric
b22d13f55232 [gaim-migrate @ 16684]
Ma Yuan <mayuan2006@gmail.com>
parents: 19788
diff changeset
1358 symbols. */
b22d13f55232 [gaim-migrate @ 16684]
Ma Yuan <mayuan2006@gmail.com>
parents: 19788
diff changeset
1359 get_alt_number (0, 23, 2);
b22d13f55232 [gaim-migrate @ 16684]
Ma Yuan <mayuan2006@gmail.com>
parents: 19788
diff changeset
1360 tm->tm_hour = val;
b22d13f55232 [gaim-migrate @ 16684]
Ma Yuan <mayuan2006@gmail.com>
parents: 19788
diff changeset
1361 have_I = 0;
b22d13f55232 [gaim-migrate @ 16684]
Ma Yuan <mayuan2006@gmail.com>
parents: 19788
diff changeset
1362 break;
b22d13f55232 [gaim-migrate @ 16684]
Ma Yuan <mayuan2006@gmail.com>
parents: 19788
diff changeset
1363 case 'I':
b22d13f55232 [gaim-migrate @ 16684]
Ma Yuan <mayuan2006@gmail.com>
parents: 19788
diff changeset
1364 /* Match hour in 12-hour clock using alternate numeric
b22d13f55232 [gaim-migrate @ 16684]
Ma Yuan <mayuan2006@gmail.com>
parents: 19788
diff changeset
1365 symbols. */
b22d13f55232 [gaim-migrate @ 16684]
Ma Yuan <mayuan2006@gmail.com>
parents: 19788
diff changeset
1366 get_alt_number (1, 12, 2);
b22d13f55232 [gaim-migrate @ 16684]
Ma Yuan <mayuan2006@gmail.com>
parents: 19788
diff changeset
1367 tm->tm_hour = val - 1;
b22d13f55232 [gaim-migrate @ 16684]
Ma Yuan <mayuan2006@gmail.com>
parents: 19788
diff changeset
1368 have_I = 1;
b22d13f55232 [gaim-migrate @ 16684]
Ma Yuan <mayuan2006@gmail.com>
parents: 19788
diff changeset
1369 break;
b22d13f55232 [gaim-migrate @ 16684]
Ma Yuan <mayuan2006@gmail.com>
parents: 19788
diff changeset
1370 case 'm':
b22d13f55232 [gaim-migrate @ 16684]
Ma Yuan <mayuan2006@gmail.com>
parents: 19788
diff changeset
1371 /* Match month using alternate numeric symbols. */
b22d13f55232 [gaim-migrate @ 16684]
Ma Yuan <mayuan2006@gmail.com>
parents: 19788
diff changeset
1372 get_alt_number (1, 12, 2);
b22d13f55232 [gaim-migrate @ 16684]
Ma Yuan <mayuan2006@gmail.com>
parents: 19788
diff changeset
1373 tm->tm_mon = val - 1;
b22d13f55232 [gaim-migrate @ 16684]
Ma Yuan <mayuan2006@gmail.com>
parents: 19788
diff changeset
1374 have_mon = 1;
b22d13f55232 [gaim-migrate @ 16684]
Ma Yuan <mayuan2006@gmail.com>
parents: 19788
diff changeset
1375 want_xday = 1;
b22d13f55232 [gaim-migrate @ 16684]
Ma Yuan <mayuan2006@gmail.com>
parents: 19788
diff changeset
1376 break;
b22d13f55232 [gaim-migrate @ 16684]
Ma Yuan <mayuan2006@gmail.com>
parents: 19788
diff changeset
1377 case 'M':
b22d13f55232 [gaim-migrate @ 16684]
Ma Yuan <mayuan2006@gmail.com>
parents: 19788
diff changeset
1378 /* Match minutes using alternate numeric symbols. */
b22d13f55232 [gaim-migrate @ 16684]
Ma Yuan <mayuan2006@gmail.com>
parents: 19788
diff changeset
1379 get_alt_number (0, 59, 2);
b22d13f55232 [gaim-migrate @ 16684]
Ma Yuan <mayuan2006@gmail.com>
parents: 19788
diff changeset
1380 tm->tm_min = val;
b22d13f55232 [gaim-migrate @ 16684]
Ma Yuan <mayuan2006@gmail.com>
parents: 19788
diff changeset
1381 break;
b22d13f55232 [gaim-migrate @ 16684]
Ma Yuan <mayuan2006@gmail.com>
parents: 19788
diff changeset
1382 case 'S':
b22d13f55232 [gaim-migrate @ 16684]
Ma Yuan <mayuan2006@gmail.com>
parents: 19788
diff changeset
1383 /* Match seconds using alternate numeric symbols. */
b22d13f55232 [gaim-migrate @ 16684]
Ma Yuan <mayuan2006@gmail.com>
parents: 19788
diff changeset
1384 get_alt_number (0, 61, 2);
b22d13f55232 [gaim-migrate @ 16684]
Ma Yuan <mayuan2006@gmail.com>
parents: 19788
diff changeset
1385 tm->tm_sec = val;
b22d13f55232 [gaim-migrate @ 16684]
Ma Yuan <mayuan2006@gmail.com>
parents: 19788
diff changeset
1386 break;
b22d13f55232 [gaim-migrate @ 16684]
Ma Yuan <mayuan2006@gmail.com>
parents: 19788
diff changeset
1387 case 'U':
b22d13f55232 [gaim-migrate @ 16684]
Ma Yuan <mayuan2006@gmail.com>
parents: 19788
diff changeset
1388 case 'V':
b22d13f55232 [gaim-migrate @ 16684]
Ma Yuan <mayuan2006@gmail.com>
parents: 19788
diff changeset
1389 case 'W':
b22d13f55232 [gaim-migrate @ 16684]
Ma Yuan <mayuan2006@gmail.com>
parents: 19788
diff changeset
1390 get_alt_number (0, 53, 2);
b22d13f55232 [gaim-migrate @ 16684]
Ma Yuan <mayuan2006@gmail.com>
parents: 19788
diff changeset
1391 /* XXX This cannot determine any field in TM without
b22d13f55232 [gaim-migrate @ 16684]
Ma Yuan <mayuan2006@gmail.com>
parents: 19788
diff changeset
1392 further information. */
b22d13f55232 [gaim-migrate @ 16684]
Ma Yuan <mayuan2006@gmail.com>
parents: 19788
diff changeset
1393 break;
b22d13f55232 [gaim-migrate @ 16684]
Ma Yuan <mayuan2006@gmail.com>
parents: 19788
diff changeset
1394 case 'w':
b22d13f55232 [gaim-migrate @ 16684]
Ma Yuan <mayuan2006@gmail.com>
parents: 19788
diff changeset
1395 /* Match number of weekday using alternate numeric symbols. */
b22d13f55232 [gaim-migrate @ 16684]
Ma Yuan <mayuan2006@gmail.com>
parents: 19788
diff changeset
1396 get_alt_number (0, 6, 1);
b22d13f55232 [gaim-migrate @ 16684]
Ma Yuan <mayuan2006@gmail.com>
parents: 19788
diff changeset
1397 tm->tm_wday = val;
b22d13f55232 [gaim-migrate @ 16684]
Ma Yuan <mayuan2006@gmail.com>
parents: 19788
diff changeset
1398 have_wday = 1;
b22d13f55232 [gaim-migrate @ 16684]
Ma Yuan <mayuan2006@gmail.com>
parents: 19788
diff changeset
1399 break;
b22d13f55232 [gaim-migrate @ 16684]
Ma Yuan <mayuan2006@gmail.com>
parents: 19788
diff changeset
1400 case 'y':
b22d13f55232 [gaim-migrate @ 16684]
Ma Yuan <mayuan2006@gmail.com>
parents: 19788
diff changeset
1401 /* Match year within century using alternate numeric symbols. */
b22d13f55232 [gaim-migrate @ 16684]
Ma Yuan <mayuan2006@gmail.com>
parents: 19788
diff changeset
1402 get_alt_number (0, 99, 2);
b22d13f55232 [gaim-migrate @ 16684]
Ma Yuan <mayuan2006@gmail.com>
parents: 19788
diff changeset
1403 tm->tm_year = val >= 69 ? val : val + 100;
b22d13f55232 [gaim-migrate @ 16684]
Ma Yuan <mayuan2006@gmail.com>
parents: 19788
diff changeset
1404 want_xday = 1;
b22d13f55232 [gaim-migrate @ 16684]
Ma Yuan <mayuan2006@gmail.com>
parents: 19788
diff changeset
1405 break;
b22d13f55232 [gaim-migrate @ 16684]
Ma Yuan <mayuan2006@gmail.com>
parents: 19788
diff changeset
1406 default:
b22d13f55232 [gaim-migrate @ 16684]
Ma Yuan <mayuan2006@gmail.com>
parents: 19788
diff changeset
1407 return NULL;
b22d13f55232 [gaim-migrate @ 16684]
Ma Yuan <mayuan2006@gmail.com>
parents: 19788
diff changeset
1408 }
b22d13f55232 [gaim-migrate @ 16684]
Ma Yuan <mayuan2006@gmail.com>
parents: 19788
diff changeset
1409 break;
b22d13f55232 [gaim-migrate @ 16684]
Ma Yuan <mayuan2006@gmail.com>
parents: 19788
diff changeset
1410 default:
b22d13f55232 [gaim-migrate @ 16684]
Ma Yuan <mayuan2006@gmail.com>
parents: 19788
diff changeset
1411 return NULL;
b22d13f55232 [gaim-migrate @ 16684]
Ma Yuan <mayuan2006@gmail.com>
parents: 19788
diff changeset
1412 }
b22d13f55232 [gaim-migrate @ 16684]
Ma Yuan <mayuan2006@gmail.com>
parents: 19788
diff changeset
1413 }
b22d13f55232 [gaim-migrate @ 16684]
Ma Yuan <mayuan2006@gmail.com>
parents: 19788
diff changeset
1414
b22d13f55232 [gaim-migrate @ 16684]
Ma Yuan <mayuan2006@gmail.com>
parents: 19788
diff changeset
1415 if (have_I && is_pm)
b22d13f55232 [gaim-migrate @ 16684]
Ma Yuan <mayuan2006@gmail.com>
parents: 19788
diff changeset
1416 tm->tm_hour += 12;
b22d13f55232 [gaim-migrate @ 16684]
Ma Yuan <mayuan2006@gmail.com>
parents: 19788
diff changeset
1417
b22d13f55232 [gaim-migrate @ 16684]
Ma Yuan <mayuan2006@gmail.com>
parents: 19788
diff changeset
1418 if (century != -1)
b22d13f55232 [gaim-migrate @ 16684]
Ma Yuan <mayuan2006@gmail.com>
parents: 19788
diff changeset
1419 {
b22d13f55232 [gaim-migrate @ 16684]
Ma Yuan <mayuan2006@gmail.com>
parents: 19788
diff changeset
1420 if (want_century)
b22d13f55232 [gaim-migrate @ 16684]
Ma Yuan <mayuan2006@gmail.com>
parents: 19788
diff changeset
1421 tm->tm_year = tm->tm_year % 100 + (century - 19) * 100;
b22d13f55232 [gaim-migrate @ 16684]
Ma Yuan <mayuan2006@gmail.com>
parents: 19788
diff changeset
1422 else
b22d13f55232 [gaim-migrate @ 16684]
Ma Yuan <mayuan2006@gmail.com>
parents: 19788
diff changeset
1423 /* Only the century, but not the year. Strange, but so be it. */
b22d13f55232 [gaim-migrate @ 16684]
Ma Yuan <mayuan2006@gmail.com>
parents: 19788
diff changeset
1424 tm->tm_year = (century - 19) * 100;
b22d13f55232 [gaim-migrate @ 16684]
Ma Yuan <mayuan2006@gmail.com>
parents: 19788
diff changeset
1425 }
b22d13f55232 [gaim-migrate @ 16684]
Ma Yuan <mayuan2006@gmail.com>
parents: 19788
diff changeset
1426
b22d13f55232 [gaim-migrate @ 16684]
Ma Yuan <mayuan2006@gmail.com>
parents: 19788
diff changeset
1427 #ifdef _NL_CURRENT
b22d13f55232 [gaim-migrate @ 16684]
Ma Yuan <mayuan2006@gmail.com>
parents: 19788
diff changeset
1428 if (era_cnt != -1)
b22d13f55232 [gaim-migrate @ 16684]
Ma Yuan <mayuan2006@gmail.com>
parents: 19788
diff changeset
1429 {
b22d13f55232 [gaim-migrate @ 16684]
Ma Yuan <mayuan2006@gmail.com>
parents: 19788
diff changeset
1430 era = _nl_select_era_entry(era_cnt);
b22d13f55232 [gaim-migrate @ 16684]
Ma Yuan <mayuan2006@gmail.com>
parents: 19788
diff changeset
1431 if (want_era)
b22d13f55232 [gaim-migrate @ 16684]
Ma Yuan <mayuan2006@gmail.com>
parents: 19788
diff changeset
1432 tm->tm_year = (era->start_date[0]
b22d13f55232 [gaim-migrate @ 16684]
Ma Yuan <mayuan2006@gmail.com>
parents: 19788
diff changeset
1433 + ((tm->tm_year - era->offset)
b22d13f55232 [gaim-migrate @ 16684]
Ma Yuan <mayuan2006@gmail.com>
parents: 19788
diff changeset
1434 * era->absolute_direction));
b22d13f55232 [gaim-migrate @ 16684]
Ma Yuan <mayuan2006@gmail.com>
parents: 19788
diff changeset
1435 else
b22d13f55232 [gaim-migrate @ 16684]
Ma Yuan <mayuan2006@gmail.com>
parents: 19788
diff changeset
1436 /* Era start year assumed. */
b22d13f55232 [gaim-migrate @ 16684]
Ma Yuan <mayuan2006@gmail.com>
parents: 19788
diff changeset
1437 tm->tm_year = era->start_date[0];
b22d13f55232 [gaim-migrate @ 16684]
Ma Yuan <mayuan2006@gmail.com>
parents: 19788
diff changeset
1438 }
b22d13f55232 [gaim-migrate @ 16684]
Ma Yuan <mayuan2006@gmail.com>
parents: 19788
diff changeset
1439 else
b22d13f55232 [gaim-migrate @ 16684]
Ma Yuan <mayuan2006@gmail.com>
parents: 19788
diff changeset
1440 #endif
b22d13f55232 [gaim-migrate @ 16684]
Ma Yuan <mayuan2006@gmail.com>
parents: 19788
diff changeset
1441 if (want_era)
b22d13f55232 [gaim-migrate @ 16684]
Ma Yuan <mayuan2006@gmail.com>
parents: 19788
diff changeset
1442 return NULL;
b22d13f55232 [gaim-migrate @ 16684]
Ma Yuan <mayuan2006@gmail.com>
parents: 19788
diff changeset
1443
b22d13f55232 [gaim-migrate @ 16684]
Ma Yuan <mayuan2006@gmail.com>
parents: 19788
diff changeset
1444 if (want_xday && !have_wday)
b22d13f55232 [gaim-migrate @ 16684]
Ma Yuan <mayuan2006@gmail.com>
parents: 19788
diff changeset
1445 {
b22d13f55232 [gaim-migrate @ 16684]
Ma Yuan <mayuan2006@gmail.com>
parents: 19788
diff changeset
1446 if ( !(have_mon && have_mday) && have_yday)
b22d13f55232 [gaim-migrate @ 16684]
Ma Yuan <mayuan2006@gmail.com>
parents: 19788
diff changeset
1447 {
b22d13f55232 [gaim-migrate @ 16684]
Ma Yuan <mayuan2006@gmail.com>
parents: 19788
diff changeset
1448 /* We don't have tm_mon and/or tm_mday, compute them. */
b22d13f55232 [gaim-migrate @ 16684]
Ma Yuan <mayuan2006@gmail.com>
parents: 19788
diff changeset
1449 int t_mon = 0;
b22d13f55232 [gaim-migrate @ 16684]
Ma Yuan <mayuan2006@gmail.com>
parents: 19788
diff changeset
1450 while (__mon_yday[__isleap(1900 + tm->tm_year)][t_mon] <= tm->tm_yday)
b22d13f55232 [gaim-migrate @ 16684]
Ma Yuan <mayuan2006@gmail.com>
parents: 19788
diff changeset
1451 t_mon++;
b22d13f55232 [gaim-migrate @ 16684]
Ma Yuan <mayuan2006@gmail.com>
parents: 19788
diff changeset
1452 if (!have_mon)
b22d13f55232 [gaim-migrate @ 16684]
Ma Yuan <mayuan2006@gmail.com>
parents: 19788
diff changeset
1453 tm->tm_mon = t_mon - 1;
b22d13f55232 [gaim-migrate @ 16684]
Ma Yuan <mayuan2006@gmail.com>
parents: 19788
diff changeset
1454 if (!have_mday)
b22d13f55232 [gaim-migrate @ 16684]
Ma Yuan <mayuan2006@gmail.com>
parents: 19788
diff changeset
1455 tm->tm_mday =
b22d13f55232 [gaim-migrate @ 16684]
Ma Yuan <mayuan2006@gmail.com>
parents: 19788
diff changeset
1456 (tm->tm_yday
b22d13f55232 [gaim-migrate @ 16684]
Ma Yuan <mayuan2006@gmail.com>
parents: 19788
diff changeset
1457 - __mon_yday[__isleap(1900 + tm->tm_year)][t_mon - 1] + 1);
b22d13f55232 [gaim-migrate @ 16684]
Ma Yuan <mayuan2006@gmail.com>
parents: 19788
diff changeset
1458 }
b22d13f55232 [gaim-migrate @ 16684]
Ma Yuan <mayuan2006@gmail.com>
parents: 19788
diff changeset
1459 day_of_the_week (tm);
b22d13f55232 [gaim-migrate @ 16684]
Ma Yuan <mayuan2006@gmail.com>
parents: 19788
diff changeset
1460 }
b22d13f55232 [gaim-migrate @ 16684]
Ma Yuan <mayuan2006@gmail.com>
parents: 19788
diff changeset
1461 if (want_xday && !have_yday)
b22d13f55232 [gaim-migrate @ 16684]
Ma Yuan <mayuan2006@gmail.com>
parents: 19788
diff changeset
1462 day_of_the_year (tm);
b22d13f55232 [gaim-migrate @ 16684]
Ma Yuan <mayuan2006@gmail.com>
parents: 19788
diff changeset
1463
b22d13f55232 [gaim-migrate @ 16684]
Ma Yuan <mayuan2006@gmail.com>
parents: 19788
diff changeset
1464 return (char *) rp;
b22d13f55232 [gaim-migrate @ 16684]
Ma Yuan <mayuan2006@gmail.com>
parents: 19788
diff changeset
1465 }
b22d13f55232 [gaim-migrate @ 16684]
Ma Yuan <mayuan2006@gmail.com>
parents: 19788
diff changeset
1466
b22d13f55232 [gaim-migrate @ 16684]
Ma Yuan <mayuan2006@gmail.com>
parents: 19788
diff changeset
1467
b22d13f55232 [gaim-migrate @ 16684]
Ma Yuan <mayuan2006@gmail.com>
parents: 19788
diff changeset
1468 char *
b22d13f55232 [gaim-migrate @ 16684]
Ma Yuan <mayuan2006@gmail.com>
parents: 19788
diff changeset
1469 msn_strptime (buf, format, tm)
b22d13f55232 [gaim-migrate @ 16684]
Ma Yuan <mayuan2006@gmail.com>
parents: 19788
diff changeset
1470 const char *buf;
b22d13f55232 [gaim-migrate @ 16684]
Ma Yuan <mayuan2006@gmail.com>
parents: 19788
diff changeset
1471 const char *format;
b22d13f55232 [gaim-migrate @ 16684]
Ma Yuan <mayuan2006@gmail.com>
parents: 19788
diff changeset
1472 struct tm *tm;
b22d13f55232 [gaim-migrate @ 16684]
Ma Yuan <mayuan2006@gmail.com>
parents: 19788
diff changeset
1473 {
b22d13f55232 [gaim-migrate @ 16684]
Ma Yuan <mayuan2006@gmail.com>
parents: 19788
diff changeset
1474 enum locale_status decided;
b22d13f55232 [gaim-migrate @ 16684]
Ma Yuan <mayuan2006@gmail.com>
parents: 19788
diff changeset
1475
b22d13f55232 [gaim-migrate @ 16684]
Ma Yuan <mayuan2006@gmail.com>
parents: 19788
diff changeset
1476 #ifdef _NL_CURRENT
b22d13f55232 [gaim-migrate @ 16684]
Ma Yuan <mayuan2006@gmail.com>
parents: 19788
diff changeset
1477 decided = not;
b22d13f55232 [gaim-migrate @ 16684]
Ma Yuan <mayuan2006@gmail.com>
parents: 19788
diff changeset
1478 #else
b22d13f55232 [gaim-migrate @ 16684]
Ma Yuan <mayuan2006@gmail.com>
parents: 19788
diff changeset
1479 decided = raw;
b22d13f55232 [gaim-migrate @ 16684]
Ma Yuan <mayuan2006@gmail.com>
parents: 19788
diff changeset
1480 #endif
b22d13f55232 [gaim-migrate @ 16684]
Ma Yuan <mayuan2006@gmail.com>
parents: 19788
diff changeset
1481 return strptime_internal (buf, format, tm, &decided, -1);
b22d13f55232 [gaim-migrate @ 16684]
Ma Yuan <mayuan2006@gmail.com>
parents: 19788
diff changeset
1482 }
b22d13f55232 [gaim-migrate @ 16684]
Ma Yuan <mayuan2006@gmail.com>
parents: 19788
diff changeset
1483 #else
b22d13f55232 [gaim-migrate @ 16684]
Ma Yuan <mayuan2006@gmail.com>
parents: 19788
diff changeset
1484 #define msn_strptime strptime
b22d13f55232 [gaim-migrate @ 16684]
Ma Yuan <mayuan2006@gmail.com>
parents: 19788
diff changeset
1485 #endif