Commit 062033af115bff1587c009f5fc46a4db5b61767c
1 parent
ad53b5fa
Exists in
master
and in
3 other branches
Fixing warnings.
Adding new function for translate the windows error codes.
Showing
6 changed files
with
76 additions
and
18 deletions
Show diff stats
src/include/config.h.in
... | ... | @@ -36,11 +36,17 @@ |
36 | 36 | #undef PACKAGE_VERSION |
37 | 37 | #undef PACKAGE_RELEASE |
38 | 38 | |
39 | - /* Defaults */ | |
39 | + /* Default settings */ | |
40 | + | |
41 | + /** @brief The lib3270's default host URL */ | |
40 | 42 | #undef LIB3270_DEFAULT_HOST |
43 | + | |
41 | 44 | #undef LIB3270_DATADIR |
42 | 45 | |
43 | - /* Libraries */ | |
46 | + /** @brief the delay, in miliseconds, between the host unlocking the keyboard and lib3270 actually performing the unlock */ | |
47 | + #define UNLOCK_MS 350 | |
48 | + | |
49 | + /* Library options */ | |
44 | 50 | #undef HAVE_GNUC_VISIBILITY |
45 | 51 | #undef HAVE_LIBINTL |
46 | 52 | #undef HAVE_GETADDRINFO | ... | ... |
src/include/lib3270.h
... | ... | @@ -1234,7 +1234,7 @@ |
1234 | 1234 | * The value is in milliseconds; use 0 to turn off the delay completely. |
1235 | 1235 | * |
1236 | 1236 | * @param session lib3270 session. |
1237 | - * @param Delay in milliseconds. | |
1237 | + * @param delay Delay in milliseconds. | |
1238 | 1238 | * |
1239 | 1239 | */ |
1240 | 1240 | LIB3270_EXPORT int lib3270_set_unlock_delay(H3270 *session, unsigned int delay); |
... | ... | @@ -1256,7 +1256,6 @@ |
1256 | 1256 | |
1257 | 1257 | LIB3270_EXPORT void * lib3270_malloc(int len); |
1258 | 1258 | LIB3270_EXPORT void * lib3270_realloc(void *p, int len); |
1259 | -// LIB3270_EXPORT void * lib3270_replace(void **p, void *ptr); | |
1260 | 1259 | LIB3270_EXPORT void * lib3270_strdup(const char *str); |
1261 | 1260 | |
1262 | 1261 | #define LIB3270_AUTOPTR_FUNC_NAME(TypeName) lib3270_autoptr_cleanup_##TypeName |
... | ... | @@ -1287,17 +1286,6 @@ |
1287 | 1286 | LIB3270_EXPORT H3270 * lib3270_get_default_session_handle(void); |
1288 | 1287 | |
1289 | 1288 | /** |
1290 | - * Get resource string. | |
1291 | - * | |
1292 | - * @param first_element First element of resource path | |
1293 | - * @param ... Resource path (ends with NULL) | |
1294 | - * | |
1295 | - * @return Resource string (Release with lib3270_free()) | |
1296 | - * | |
1297 | - */ | |
1298 | - LIB3270_EXPORT char * lib3270_get_resource_string(H3270 *hSession, const char *first_element, ...); | |
1299 | - | |
1300 | - /** | |
1301 | 1289 | * Get library version. |
1302 | 1290 | * |
1303 | 1291 | * @return Version of active library as string. |
... | ... | @@ -1371,6 +1359,17 @@ |
1371 | 1359 | #ifdef WIN32 |
1372 | 1360 | LIB3270_EXPORT const char * lib3270_win32_strerror(int e); |
1373 | 1361 | LIB3270_EXPORT const char * lib3270_win32_local_charset(void); |
1362 | + | |
1363 | + /** | |
1364 | + * @brief Translate windows error code. | |
1365 | + * | |
1366 | + * @param lasterror Windows error code (from GetLastError()). | |
1367 | + * | |
1368 | + * @return String with translated message (release it with lib3270_free). | |
1369 | + * | |
1370 | + */ | |
1371 | + LIB3270_EXPORT char * lib3270_win32_translate_error_code(int lasterror); | |
1372 | + | |
1374 | 1373 | #endif // WIn32 |
1375 | 1374 | |
1376 | 1375 | /** | ... | ... |
src/lib3270/kybd.c
... | ... | @@ -113,7 +113,6 @@ static const unsigned char pa_xlate[] = |
113 | 113 | }; |
114 | 114 | #define PF_SZ (sizeof(pf_xlate)/sizeof(pf_xlate[0])) |
115 | 115 | #define PA_SZ (sizeof(pa_xlate)/sizeof(pa_xlate[0])) |
116 | -#define UNLOCK_MS 350 /* 0.35s after last unlock */ | |
117 | 116 | |
118 | 117 | static Boolean key_Character(H3270 *hSession, int code, Boolean with_ge, Boolean pasting,Boolean *skipped); |
119 | 118 | static int flush_ta(H3270 *hSession); | ... | ... |
src/lib3270/paste.c
... | ... | @@ -209,7 +209,7 @@ static int set_string(H3270 *hSession, const unsigned char *str) |
209 | 209 | } |
210 | 210 | str++; |
211 | 211 | |
212 | - if(IN_3270 && lib3270_get_toggle(hSession,LIB3270_TOGGLE_MARGINED_PASTE) && BA_TO_COL(hSession->cursor_addr) < data.orig_col) | |
212 | + if(IN_3270 && lib3270_get_toggle(hSession,LIB3270_TOGGLE_MARGINED_PASTE) && BA_TO_COL(hSession->cursor_addr) < ((unsigned int) data.orig_col)) | |
213 | 213 | { |
214 | 214 | if(!remargin(hSession,data.orig_col)) |
215 | 215 | last = 0; | ... | ... |
src/lib3270/session.c
... | ... | @@ -337,9 +337,15 @@ static void lib3270_session_init(H3270 *hSession, const char *model, const char |
337 | 337 | hSession->host_type = LIB3270_HOSTTYPE_DEFAULT; |
338 | 338 | hSession->colors = 16; |
339 | 339 | hSession->m3279 = 1; |
340 | - hSession->unlock_delay_ms = 350; // 0.35s after last unlock | |
341 | 340 | hSession->pointer = (unsigned short) LIB3270_POINTER_LOCKED; |
342 | 341 | |
342 | +#ifdef UNLOCK_MS | |
343 | + hSession->unlock_delay_ms = UNLOCK_MS; | |
344 | +#else | |
345 | + #error aqui | |
346 | + hSession->unlock_delay_ms = 350; | |
347 | +#endif // UNLOCK_MS | |
348 | + | |
343 | 349 | // CSD |
344 | 350 | for(f=0;f<4;f++) |
345 | 351 | hSession->csd[f] = hSession->saved_csd[f] = LIB3270_ANSI_CSD_US; | ... | ... |
src/lib3270/windows/util.c
... | ... | @@ -121,6 +121,54 @@ const char * inet_ntop(int af, const void *src, char *dst, socklen_t cnt) |
121 | 121 | } |
122 | 122 | #endif // HAVE_INET_NTOP |
123 | 123 | |
124 | +LIB3270_EXPORT char * lib3270_win32_translate_error_code(int lasterror) | |
125 | +{ | |
126 | + char * buffer = lib3270_malloc(4096); | |
127 | + | |
128 | + if(FormatMessage(FORMAT_MESSAGE_FROM_SYSTEM,NULL,lasterror,MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT),buffer,4096,NULL) == 0) | |
129 | + { | |
130 | + snprintf(buffer, 4095, _( "Windows error %d" ), e); | |
131 | + } | |
132 | + | |
133 | +#ifdef HAVE_ICONV | |
134 | + { | |
135 | + // Convert from windows codepage to UTF-8 pw3270´s default charset | |
136 | + iconv_t hConv = iconv_open("UTF-8",lib3270_win32_local_charset()); | |
137 | + | |
138 | + trace("[%s]",buffer); | |
139 | + | |
140 | + if(hConv == (iconv_t) -1) | |
141 | + { | |
142 | + lib3270_write_log(NULL,"iconv","%s: Error creating charset conversion",__FUNCTION__); | |
143 | + } | |
144 | + else | |
145 | + { | |
146 | + size_t in = strlen(buffer); | |
147 | + size_t out = (in << 1); | |
148 | + char * ptr; | |
149 | + char * outBuffer = (char *) malloc(out); | |
150 | + ICONV_CONST char * inBuffer = (ICONV_CONST char *) buffer; | |
151 | + | |
152 | + memset(ptr=outBuffer,0,out); | |
153 | + | |
154 | + iconv(hConv,NULL,NULL,NULL,NULL); // Reset state | |
155 | + | |
156 | + if(iconv(hConv,&inBuffer,&in,&ptr,&out) != ((size_t) -1)) | |
157 | + { | |
158 | + strncpy(buffer,outBuffer,4095); | |
159 | + } | |
160 | + | |
161 | + free(outBuffer); | |
162 | + | |
163 | + iconv_close(hConv); | |
164 | + } | |
165 | + | |
166 | + } | |
167 | +#endif // HAVE_ICONV | |
168 | + | |
169 | + return buffer; | |
170 | +} | |
171 | + | |
124 | 172 | // Decode a Win32 error number. |
125 | 173 | LIB3270_EXPORT const char * lib3270_win32_strerror(int e) |
126 | 174 | { | ... | ... |