Commit 2171f01cc3d1cb45759e6305896f5307a784e1b5
1 parent
4ac2fafe
Exists in
master
and in
5 other branches
Correcao na conversao de codepage em windows
Showing
2 changed files
with
28 additions
and
13 deletions
Show diff stats
src/include/lib3270.h
... | ... | @@ -211,6 +211,7 @@ |
211 | 211 | { |
212 | 212 | LIB3270_CONNECT_OPTION_DEFAULTS = 0x0000, /**< Default connection options */ |
213 | 213 | LIB3270_CONNECT_OPTION_SSL = 0x0001, /**< Secure connection */ |
214 | + LIB3270_CONNECT_OPTION_WAIT = 0x0002, /**< Wait for screen ready */ | |
214 | 215 | |
215 | 216 | } LIB3270_CONNECT_OPTION; |
216 | 217 | |
... | ... | @@ -1060,6 +1061,7 @@ |
1060 | 1061 | |
1061 | 1062 | #ifdef WIN32 |
1062 | 1063 | LIB3270_EXPORT const char * lib3270_win32_strerror(int e); |
1064 | + LIB3270_EXPORT const char * lib3270_win32_local_charset(void); | |
1063 | 1065 | #endif // WIn32 |
1064 | 1066 | |
1065 | 1067 | #ifdef __cplusplus | ... | ... |
src/lib3270/util.c
... | ... | @@ -160,16 +160,9 @@ LIB3270_EXPORT const char * lib3270_win32_strerror(int e) |
160 | 160 | return buffer; |
161 | 161 | } |
162 | 162 | |
163 | - trace("%s",buffer); | |
164 | - | |
165 | 163 | #ifdef HAVE_ICONV |
166 | 164 | { |
167 | 165 | // Convert from windows codepage to UTF-8 pw3270´s default charset |
168 | - char tmpbuffer[4096]; | |
169 | - size_t in = strlen(buffer); | |
170 | - size_t out = 4095; | |
171 | - char * ptr = tmpbuffer; | |
172 | - | |
173 | 166 | iconv_t hConv = iconv_open("UTF-8",lib3270_win32_local_charset()); |
174 | 167 | |
175 | 168 | trace("[%s]",buffer); |
... | ... | @@ -178,23 +171,43 @@ LIB3270_EXPORT const char * lib3270_win32_strerror(int e) |
178 | 171 | { |
179 | 172 | lib3270_write_log(NULL,"iconv","%s: Error creating charset conversion",__FUNCTION__); |
180 | 173 | } |
181 | - else if(iconv(hConv,(const char **) &buffer,&in,&ptr,&out) != ((size_t) -1)) | |
174 | + else | |
182 | 175 | { |
183 | - // strncpy(buffer,tmpbuffer,4096); | |
184 | - } | |
176 | + size_t in = strlen(buffer); | |
177 | + size_t out = (in << 1); | |
178 | + char * ptr; | |
179 | + char * outBuffer = (char *) malloc(out); | |
180 | + ICONV_CONST char * inBuffer = (ICONV_CONST char *) buffer; | |
185 | 181 | |
186 | - trace("[%s]",buffer); | |
182 | + memset(ptr=outBuffer,0,out); | |
183 | + | |
184 | + iconv(hConv,NULL,NULL,NULL,NULL); // Reset state | |
185 | + | |
186 | + if(iconv(hConv,&inBuffer,&in,&ptr,&out) != ((size_t) -1)) | |
187 | + { | |
188 | + strncpy(buffer,outBuffer,4095); | |
189 | + } | |
190 | + | |
191 | + free(outBuffer); | |
192 | + | |
193 | + iconv_close(hConv); | |
194 | + } | |
187 | 195 | |
188 | - iconv_close(hConv); | |
189 | 196 | } |
190 | 197 | #endif // HAVE_ICONV |
191 | 198 | |
192 | - trace("[%s]",buffer); | |
193 | 199 | return buffer; |
194 | 200 | } |
195 | 201 | |
196 | 202 | LIB3270_EXPORT const char * lib3270_win32_local_charset(void) |
197 | 203 | { |
204 | + // Reference: | |
205 | + // http://msdn.microsoft.com/en-us/library/windows/desktop/dd318070(v=vs.85).aspx | |
206 | + | |
207 | + #warning TODO: Use GetACP() to identify the correct code page | |
208 | + | |
209 | + trace("Windows CHARSET is %u",GetACP()); | |
210 | + | |
198 | 211 | return "CP1252"; |
199 | 212 | } |
200 | 213 | ... | ... |