another unsigned char cast in os2cp.c. code clean-up in os/2 geniconv.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549
diff --git a/src/core/os2/geniconv/geniconv.c b/src/core/os2/geniconv/geniconv.c
index b11b749..c76a398 100644
--- a/src/core/os2/geniconv/geniconv.c
+++ b/src/core/os2/geniconv/geniconv.c
@@ -25,34 +25,31 @@
Andrey Vasilkin, 2016.
*/
-#define INCL_DOSMODULEMGR /* Module Manager values */
-#define INCL_DOSERRORS /* Error values */
+#define INCL_DOSMODULEMGR /* Module Manager */
+#define INCL_DOSERRORS /* Error values */
#include <os2.h>
#include "geniconv.h"
/*#define DEBUG*/
-
#ifdef DEBUG
# include <stdio.h>
-# define debug(s,...) printf(__func__"(): "##s"\n" ,##__VA_ARGS__)
+# define iconv_debug(s,...) printf(__func__"(): "##s"\n" ,##__VA_ARGS__)
#else
-# define debug(s,...) do {} while (0)
+# define iconv_debug(s,...) do {} while (0)
#endif
/* Exports from os2iconv.c */
-extern iconv_t _System os2_iconv_open(const char* tocode, const char* fromcode);
-extern size_t _System os2_iconv(iconv_t cd, char* * inbuf,
- size_t *inbytesleft, char* * outbuf,
- size_t *outbytesleft);
-extern int _System os2_iconv_close(iconv_t cd);
+extern iconv_t _System os2_iconv_open (const char* tocode, const char* fromcode);
+extern size_t _System os2_iconv (iconv_t cd,
+ char **inbuf, size_t *inbytesleft,
+ char **outbuf, size_t *outbytesleft);
+extern int _System os2_iconv_close (iconv_t cd);
/* Functions pointers types */
-typedef iconv_t _System (*FNICONV_OPEN)(const char* tocode, const char* fromcode);
-typedef size_t _System (*FNICONV)(iconv_t cd, char* * inbuf,
- size_t *inbytesleft, char* * outbuf,
- size_t *outbytesleft);
-typedef int _System (*FNICONV_CLOSE)(iconv_t cd);
+typedef iconv_t (_System *FNICONV_OPEN)(const char*, const char*);
+typedef size_t (_System *FNICONV) (iconv_t, char **, size_t *, char **, size_t *);
+typedef int (_System *FNICONV_CLOSE)(iconv_t);
/* Used DLL module handle */
static HMODULE hmIconv = NULLHANDLE;
@@ -62,41 +59,42 @@ static FNICONV fn_iconv = NULL;
static FNICONV_CLOSE fn_iconv_close = NULL;
-static BOOL _loadDLL(PSZ pszName, PSZ pszIconvOpen, PSZ pszIconv,
- PSZ pszIconvClose)
+static BOOL _loadDLL(const char *dllname,
+ const char *sym_iconvopen,
+ const char *sym_iconv,
+ const char *sym_iconvclose)
{
- ULONG ulRC;
- CHAR acError[256];
+ ULONG rc;
+ char error[256];
- ulRC = DosLoadModule(acError, sizeof(acError), pszName, &hmIconv);
- if (ulRC != NO_ERROR) {
- debug("DLL not loaded: %s", &acError);
+ rc = DosLoadModule(error, sizeof(error), dllname, &hmIconv);
+ if (rc != NO_ERROR) {
+ iconv_debug("DLL %s not loaded: %s", dllname, error);
return FALSE;
}
- do {
- ulRC = DosQueryProcAddr(hmIconv, 0, pszIconvOpen, (PFN *)&fn_iconv_open);
- if (ulRC != NO_ERROR) {
- debug("Error: cannot find entry %s in %s", pszIconvOpen, pszName);
- break;
- }
-
- ulRC = DosQueryProcAddr(hmIconv, 0, pszIconv, (PFN *)&fn_iconv);
- if (ulRC != NO_ERROR) {
- debug("Error: cannot find entry %s in %s", pszIconv, pszName);
- break;
- }
-
- ulRC = DosQueryProcAddr(hmIconv, 0, pszIconvClose, (PFN *)&fn_iconv_close);
- if (ulRC != NO_ERROR) {
- debug("Error: cannot find entry %s in %s", pszIconvClose, pszName);
- break;
- }
-
- debug("DLL %s used", pszName);
- return TRUE;
- } while (FALSE);
+ rc = DosQueryProcAddr(hmIconv, 0, sym_iconvopen, (PFN *)&fn_iconv_open);
+ if (rc != NO_ERROR) {
+ iconv_debug("Error: cannot find entry %s in %s", sym_iconvopen, dllname);
+ goto fail;
+ }
+
+ rc = DosQueryProcAddr(hmIconv, 0, sym_iconv, (PFN *)&fn_iconv);
+ if (rc != NO_ERROR) {
+ iconv_debug("Error: cannot find entry %s in %s", sym_iconv, dllname);
+ goto fail;
+ }
+
+ rc = DosQueryProcAddr(hmIconv, 0, sym_iconvclose, (PFN *)&fn_iconv_close);
+ if (rc != NO_ERROR) {
+ iconv_debug("Error: cannot find entry %s in %s", sym_iconvclose, dllname);
+ goto fail;
+ }
+
+ iconv_debug("DLL %s used", dllname);
+ return TRUE;
+ fail:
DosFreeModule(hmIconv);
hmIconv = NULLHANDLE;
return FALSE;
@@ -104,15 +102,16 @@ static BOOL _loadDLL(PSZ pszName, PSZ pszIconvOpen, PSZ pszIconv,
static void _init(void)
{
- if (fn_iconv_open != NULL) /* Already was initialized */
- return;
+ if (fn_iconv_open != NULL) {
+ return; /* Already initialized */
+ }
/* Try to load kiconv.dll, iconv2.dll or iconv.dll */
if (!_loadDLL("KICONV", "_libiconv_open", "_libiconv", "_libiconv_close") &&
!_loadDLL("ICONV2", "_libiconv_open", "_libiconv", "_libiconv_close") &&
!_loadDLL("ICONV", "_iconv_open", "_iconv", "_iconv_close") ) {
/* No DLL was loaded - use OS/2 conversion objects API */
- debug("Uni*() API used");
+ iconv_debug("Uni*() API used");
fn_iconv_open = os2_iconv_open;
fn_iconv = os2_iconv;
fn_iconv_close = os2_iconv_close;
diff --git a/src/core/os2/geniconv/geniconv.h b/src/core/os2/geniconv/geniconv.h
index 377a1e6..f66c615 100644
--- a/src/core/os2/geniconv/geniconv.h
+++ b/src/core/os2/geniconv/geniconv.h
@@ -58,27 +58,27 @@ size_t libiconv (iconv_t cd, char **inbuf, size_t *inbytesleft,
/* System codepage <-> UTF-8
*
* StrUTF8()
- * Coverts string from system cp to UTF-8 (fToUTF8 is not 0) or from UTF-8 to
- * the system cp (fToUTF8 is 0). Converted ASCIIZ string will be placed at the
- * buffer pcDst, up to cbDst - 1 (for sys->utf8) or 2 (for utf8->sys) bytes.
- * Returns the number of bytes written into pcDst, not counting the terminating
+ * Converts string from system cp to UTF-8 (to_utf8 is not 0) or from UTF-8 to
+ * the system cp (to_utf8 is 0). Converted ASCIIZ string will be placed at the
+ * buffer dst, up to c_dst - 1 (for sys->utf8) or 2 (for utf8->sys) bytes.
+ * Returns the number of bytes written into dst, not counting the terminating
* 0 byte(s) or -1 on error.
*/
-int StrUTF8(int fToUTF8, char *pcDst, int cbDst, char *pcSrc, int cbSrc);
+int StrUTF8(int to_utf8, char *dst, int c_dst, char *src, int c_src);
/* StrUTF8New()
- * Coverts string from system cp to UTF-8 (fToUTF8 is not 0) or from UTF-8 to
- * the system cp (fToUTF8 is 0). Memory for the new string is obtained by
+ * Converts string from system cp to UTF-8 (to_utf8 is not 0) or from UTF-8
+ * to the system cp (to_utf8 is 0). Memory for the new string is obtained by
* using libc malloc().
* Returns converted string, terminating two bytes 0 is appended to the result.
* Returns null on error.
*/
-char *StrUTF8New(int fToUTF8, char *pcStr, int cbStr);
+char *StrUTF8New(int to_utf8, char *str, int c_str);
/* StrUTF8Free()
- * Deallocates the memory block located by StrUTF8New() (just libc free()).
+ * Deallocates the memory block allocated by StrUTF8New() (just libc free()).
*/
-void StrUTF8Free(char *pszStr);
+void StrUTF8Free(char *str);
#endif /* GENICONV_H */
diff --git a/src/core/os2/geniconv/os2cp.c b/src/core/os2/geniconv/os2cp.c
index 3e571f8..4b71265 100644
--- a/src/core/os2/geniconv/os2cp.c
+++ b/src/core/os2/geniconv/os2cp.c
@@ -315,30 +315,30 @@ char *os2cpToName(unsigned long cp)
if (cp == SYSTEM_CP) {
ULONG aulCP[3];
ULONG cCP;
-
- if (DosQueryCp(sizeof(aulCP), aulCP, &cCP) != NO_ERROR)
+ if (DosQueryCp(sizeof(aulCP), aulCP, &cCP) != NO_ERROR) {
return NULL;
-
+ }
cp = aulCP[0];
}
- if (aCP2Name[0].ulCode > cp || aCP2Name[ulHi].ulCode < cp)
+ if (aCP2Name[0].ulCode > cp || aCP2Name[ulHi].ulCode < cp) {
return NULL;
-
- if (aCP2Name[0].ulCode == cp)
+ }
+ if (aCP2Name[0].ulCode == cp) {
return aCP2Name[0].pszName;
-
- if (aCP2Name[ulHi].ulCode == cp)
+ }
+ if (aCP2Name[ulHi].ulCode == cp) {
return aCP2Name[ulHi].pszName;
+ }
while ((ulHi - ulLo) > 1) {
ulNext = (ulLo + ulHi) / 2;
- if (aCP2Name[ulNext].ulCode < cp)
+ if (aCP2Name[ulNext].ulCode < cp) {
ulLo = ulNext;
- else if (aCP2Name[ulNext].ulCode > cp)
+ } else if (aCP2Name[ulNext].ulCode > cp) {
ulHi = ulNext;
- else {
+ } else {
lFound = ulNext;
break;
}
@@ -360,46 +360,51 @@ unsigned long os2cpFromName(char *cp)
if (cp == NULL) {
ULONG aulCP[3];
ULONG cCP;
-
return (DosQueryCp(sizeof(aulCP), aulCP, &cCP) != NO_ERROR)? 0 : aulCP[0];
}
- while (SDL_isspace(*cp))
+ while (SDL_isspace((unsigned char) *cp)) {
cp++;
+ }
pcEnd = SDL_strchr(cp, ' ');
- if (pcEnd == NULL)
+ if (pcEnd == NULL) {
pcEnd = SDL_strchr(cp, '\0');
-
+ }
ulNext = pcEnd - cp;
- if (ulNext >= sizeof(acBuf))
+ if (ulNext >= sizeof(acBuf)) {
return 0;
+ }
SDL_memcpy(acBuf, cp, ulNext);
acBuf[ulNext] = '\0';
SDL_strupr(acBuf);
lCmp = SDL_strcmp(aName2CP[0].pszName, acBuf);
- if (lCmp > 0)
+ if (lCmp > 0) {
return 0;
- else if (lCmp == 0)
+ }
+ if (lCmp == 0) {
return aName2CP[0].ulCode;
+ }
lCmp = SDL_strcmp(aName2CP[ulHi].pszName, acBuf);
- if (lCmp < 0)
+ if (lCmp < 0) {
return 0;
- else if (lCmp == 0)
+ }
+ if (lCmp == 0) {
return aName2CP[ulHi].ulCode;
+ }
while ((ulHi - ulLo) > 1) {
ulNext = (ulLo + ulHi) / 2;
lCmp = SDL_strcmp(aName2CP[ulNext].pszName, acBuf);
- if (lCmp < 0)
+ if (lCmp < 0) {
ulLo = ulNext;
- else if (lCmp > 0)
+ } else if (lCmp > 0) {
ulHi = ulNext;
- else {
+ } else {
lFound = ulNext;
break;
}
diff --git a/src/core/os2/geniconv/os2iconv.c b/src/core/os2/geniconv/os2iconv.c
index c24cc54..ac5a282 100644
--- a/src/core/os2/geniconv/os2iconv.c
+++ b/src/core/os2/geniconv/os2iconv.c
@@ -103,27 +103,28 @@ static int uconv_open(const char *code, UconvObject *uobj)
if (rc != ULS_SUCCESS) {
unsigned long cp = os2cpFromName((char *)code);
char cp_name[16];
-
- if (cp != 0 && SDL_snprintf(cp_name, sizeof(cp_name), "IBM-%u", cp) > 0)
+ if (cp != 0 && SDL_snprintf(cp_name, sizeof(cp_name), "IBM-%u", cp) > 0) {
rc = _createUconvObj(cp_name, uobj);
+ }
}
return rc;
}
-extern iconv_t _System os2_iconv_open(const char* tocode, const char* fromcode)
+iconv_t _System os2_iconv_open(const char* tocode, const char* fromcode)
{
UconvObject uo_tocode;
UconvObject uo_fromcode;
int rc;
iuconv_obj *iuobj;
- if (tocode == NULL)
+ if (tocode == NULL) {
tocode = "";
-
- if (fromcode == NULL)
+ }
+ if (fromcode == NULL) {
fromcode = "";
+ }
if (SDL_strcasecmp(tocode, fromcode) != 0) {
rc = uconv_open(fromcode, &uo_fromcode);
@@ -131,7 +132,6 @@ extern iconv_t _System os2_iconv_open(const char* tocode, const char* fromcode)
errno = EINVAL;
return (iconv_t)(-1);
}
-
rc = uconv_open(tocode, &uo_tocode);
if (rc != ULS_SUCCESS) {
UniFreeUconvObject(uo_fromcode);
@@ -155,9 +155,9 @@ extern iconv_t _System os2_iconv_open(const char* tocode, const char* fromcode)
return iuobj;
}
-extern size_t _System os2_iconv(iconv_t cd, char* * inbuf,
- size_t *inbytesleft,
- char* * outbuf, size_t *outbytesleft)
+size_t _System os2_iconv(iconv_t cd,
+ char **inbuf, size_t *inbytesleft ,
+ char **outbuf, size_t *outbytesleft)
{
UconvObject uo_tocode = ((iuconv_obj *)(cd))->uo_tocode;
UconvObject uo_fromcode = ((iuconv_obj *)(cd))->uo_fromcode;
@@ -183,12 +183,12 @@ extern size_t _System os2_iconv(iconv_t cd, char* * inbuf,
DosRequestMutexSem(((iuconv_obj *)(cd))->hMtx, SEM_INDEFINITE_WAIT);
#endif
- if (uo_tocode && uo_fromcode &&
- (((iuconv_obj *)cd)->buf_len >> 1) < *inbytesleft) {
- if (((iuconv_obj *)cd)->buf != NULL)
+ if (uo_tocode && uo_fromcode && (((iuconv_obj *)cd)->buf_len >> 1) < *inbytesleft) {
+ if (((iuconv_obj *)cd)->buf != NULL) {
SDL_free(((iuconv_obj *)cd)->buf);
+ }
((iuconv_obj *)cd)->buf_len = *inbytesleft << 1;
- ((iuconv_obj *)cd)->buf = (UniChar *)SDL_malloc(((iuconv_obj *)cd)->buf_len);
+ ((iuconv_obj *)cd)->buf = (UniChar *) SDL_malloc(((iuconv_obj *)cd)->buf_len);
}
if (uo_fromcode) {
@@ -205,8 +205,9 @@ extern size_t _System os2_iconv(iconv_t cd, char* * inbuf,
rc = UniUconvToUcs(uo_fromcode, (void **)inbuf, inbytesleft,
uc_str, uc_str_len, &nonIdenticalConv);
uc_buf_len = uc_buf_len << 1;
- if (!uo_tocode)
+ if (!uo_tocode) {
*outbytesleft = uc_buf_len;
+ }
if (rc != ULS_SUCCESS) {
errno = EILSEQ;
@@ -216,8 +217,9 @@ extern size_t _System os2_iconv(iconv_t cd, char* * inbuf,
goto done;
}
- if (!uo_tocode)
+ if (!uo_tocode) {
return nonIdenticalConv;
+ }
uc_buf = ((iuconv_obj *)cd)->buf;
uc_buf_len = ((iuconv_obj *)cd)->buf_len - uc_buf_len;
@@ -266,14 +268,16 @@ int _System os2_iconv_close(iconv_t cd)
#ifdef ICONV_THREAD_SAFE
DosCloseMutexSem(((iuconv_obj *)cd)->hMtx);
#endif
- if (((iuconv_obj *)cd)->uo_tocode != NULL)
+ if (((iuconv_obj *)cd)->uo_tocode != NULL) {
UniFreeUconvObject(((iuconv_obj *)cd)->uo_tocode);
- if (((iuconv_obj *)cd)->uo_fromcode != NULL)
+ }
+ if (((iuconv_obj *)cd)->uo_fromcode != NULL) {
UniFreeUconvObject(((iuconv_obj *)cd)->uo_fromcode);
+ }
- if (((iuconv_obj *)cd)->buf != NULL)
+ if (((iuconv_obj *)cd)->buf != NULL) {
SDL_free(((iuconv_obj *)cd)->buf);
-
+ }
SDL_free(cd);
return 0;
diff --git a/src/core/os2/geniconv/sys2utf8.c b/src/core/os2/geniconv/sys2utf8.c
index fb96430..577cd5a 100644
--- a/src/core/os2/geniconv/sys2utf8.c
+++ b/src/core/os2/geniconv/sys2utf8.c
@@ -30,40 +30,42 @@
#define SDL_free free
#endif
-int StrUTF8(int fToUTF8, char *pcDst, int cbDst, char *pcSrc, int cbSrc)
+int StrUTF8(int to_utf8, char *dst, int c_dst, char *src, int c_src)
{
size_t rc;
- char *pcDstStart = pcDst;
+ char *dststart = dst;
iconv_t cd;
- char *pszToCP, *pszFromCP;
- int fError = 0;
+ char *tocp, *fromcp;
+ int err = 0;
- if (cbDst < 4)
+ if (c_dst < 4) {
return -1;
+ }
- if (fToUTF8) {
- pszToCP = "UTF-8";
- pszFromCP = "";
+ if (to_utf8) {
+ tocp = "UTF-8";
+ fromcp = "";
} else {
- pszToCP = "";
- pszFromCP = "UTF-8";
+ tocp = "";
+ fromcp = "UTF-8";
}
- cd = iconv_open(pszToCP, pszFromCP);
- if (cd == (iconv_t)-1)
+ cd = iconv_open(tocp, fromcp);
+ if (cd == (iconv_t)-1) {
return -1;
+ }
- while (cbSrc > 0) {
- rc = iconv(cd, &pcSrc, (size_t *)&cbSrc, &pcDst, (size_t *)&cbDst);
+ while (c_src > 0) {
+ rc = iconv(cd, &src, (size_t *)&c_src, &dst, (size_t *)&c_dst);
if (rc == (size_t)-1) {
if (errno == EILSEQ) {
/* Try to skip invalid character */
- pcSrc++;
- cbSrc--;
+ src++;
+ c_src--;
continue;
}
- fError = 1;
+ err = 1;
break;
}
}
@@ -71,45 +73,47 @@ int StrUTF8(int fToUTF8, char *pcDst, int cbDst, char *pcSrc, int cbSrc)
iconv_close(cd);
/* Write trailing ZERO (1 byte for UTF-8, 2 bytes for the system cp) */
- if (fToUTF8) {
- if (cbDst < 1) {
- pcDst--;
- fError = 1; /* The destination buffer overflow */
+ if (to_utf8) {
+ if (c_dst < 1) {
+ dst--;
+ err = 1; /* The destination buffer overflow */
}
- *pcDst = '\0';
+ *dst = '\0';
} else {
- if (cbDst < 2) {
- pcDst -= (cbDst == 0)? 2 : 1;
- fError = 1; /* The destination buffer overflow */
+ if (c_dst < 2) {
+ dst -= (c_dst == 0) ? 2 : 1;
+ err = 1; /* The destination buffer overflow */
}
- *((short *)pcDst) = '\0';
+ *((short *)dst) = '\0';
}
- return (fError) ? -1 : (pcDst - pcDstStart);
+ return (err) ? -1 : (dst - dststart);
}
-char *StrUTF8New(int fToUTF8, char *pcStr, int cbStr)
+char *StrUTF8New(int to_utf8, char *str, int c_str)
{
- int cbNewStr = (((cbStr > 4)? cbStr : 4) + 1) * 2;
- char *pszNewStr = (char *) SDL_malloc(cbNewStr);
+ int c_newstr = (((c_str > 4) ? c_str : 4) + 1) * 2;
+ char * newstr = (char *) SDL_malloc(c_newstr);
- if (pszNewStr == NULL)
+ if (newstr == NULL) {
return NULL;
+ }
- cbNewStr = StrUTF8(fToUTF8, pszNewStr, cbNewStr, pcStr, cbStr);
- if (cbNewStr != -1) {
- pcStr = (char *) SDL_realloc(pszNewStr, cbNewStr + ((fToUTF8)? 1 : sizeof(short)));
- if (pcStr)
- return pcStr;
+ c_newstr = StrUTF8(to_utf8, newstr, c_newstr, str, c_str);
+ if (c_newstr != -1) {
+ str = (char *) SDL_realloc(newstr, c_newstr + ((to_utf8) ? 1 : sizeof(short)));
+ if (str) {
+ return str;
+ }
}
- SDL_free(pszNewStr);
+ SDL_free(newstr);
return NULL;
}
-void StrUTF8Free(char *pszStr)
+void StrUTF8Free(char *str)
{
- SDL_free(pszStr);
+ SDL_free(str);
}
/* vi: set ts=4 sw=4 expandtab: */