| 1 | /* $Id: char.cpp,v 1.13 2000-03-23 23:06:51 sandervl Exp $ */ | 
|---|
| 2 |  | 
|---|
| 3 | /* | 
|---|
| 4 | * Win32 character API functions for OS/2 | 
|---|
| 5 | * | 
|---|
| 6 | * Copyright 1998 Sander van Leeuwen | 
|---|
| 7 | * Copyright 1998 Patrick Haller | 
|---|
| 8 | * Copyright 1998 Peter Fitzsimmons | 
|---|
| 9 | * | 
|---|
| 10 | * | 
|---|
| 11 | * Project Odin Software License can be found in LICENSE.TXT | 
|---|
| 12 | * | 
|---|
| 13 | */ | 
|---|
| 14 |  | 
|---|
| 15 |  | 
|---|
| 16 | #include <odin.h> | 
|---|
| 17 | #include <odinwrap.h> | 
|---|
| 18 | #include <os2sel.h> | 
|---|
| 19 |  | 
|---|
| 20 | #include "user32.h" | 
|---|
| 21 |  | 
|---|
| 22 | #include <wctype.h> /* towupper, towlower support */ | 
|---|
| 23 |  | 
|---|
| 24 | #define DBG_LOCALLOG    DBG_char | 
|---|
| 25 | #include "dbglocal.h" | 
|---|
| 26 |  | 
|---|
| 27 |  | 
|---|
| 28 | ODINDEBUGCHANNEL(USER32-CHAR) | 
|---|
| 29 |  | 
|---|
| 30 | //****************************************************************************** | 
|---|
| 31 | //****************************************************************************** | 
|---|
| 32 | LPSTR WIN32API CharLowerA( LPSTR arg1) | 
|---|
| 33 | { | 
|---|
| 34 | dprintf2(("USER32:  OS2CharLowerA\n")); | 
|---|
| 35 | return O32_CharLower(arg1); | 
|---|
| 36 | } | 
|---|
| 37 | //****************************************************************************** | 
|---|
| 38 | //****************************************************************************** | 
|---|
| 39 | DWORD WIN32API CharLowerBuffA( LPSTR arg1, DWORD  arg2) | 
|---|
| 40 | { | 
|---|
| 41 | dprintf2(("USER32:  OS2CharLowerBuffA\n")); | 
|---|
| 42 | return O32_CharLowerBuff(arg1, arg2); | 
|---|
| 43 | } | 
|---|
| 44 | //****************************************************************************** | 
|---|
| 45 | //****************************************************************************** | 
|---|
| 46 | DWORD WIN32API CharLowerBuffW(LPWSTR x,DWORD buflen) | 
|---|
| 47 | { | 
|---|
| 48 | DWORD done=0; | 
|---|
| 49 |  | 
|---|
| 50 | dprintf2(("USER32: CharLowerBuffW(%08xh,%08xh)\n", | 
|---|
| 51 | x, | 
|---|
| 52 | buflen)); | 
|---|
| 53 |  | 
|---|
| 54 | if (!x) | 
|---|
| 55 | return 0; /* YES */ | 
|---|
| 56 |  | 
|---|
| 57 | while (*x && (buflen--)) | 
|---|
| 58 | { | 
|---|
| 59 | *x=towlower(*x); | 
|---|
| 60 | x++; | 
|---|
| 61 | done++; | 
|---|
| 62 | } | 
|---|
| 63 |  | 
|---|
| 64 | return done; | 
|---|
| 65 | } | 
|---|
| 66 | //****************************************************************************** | 
|---|
| 67 | //****************************************************************************** | 
|---|
| 68 | LPWSTR WIN32API CharLowerW( LPWSTR x) | 
|---|
| 69 | { | 
|---|
| 70 | dprintf2(("USER32: CharLowerW(%08xh)\n", | 
|---|
| 71 | x)); | 
|---|
| 72 |  | 
|---|
| 73 | if (HIWORD(x)) | 
|---|
| 74 | { | 
|---|
| 75 | LPWSTR s = x; | 
|---|
| 76 | while (*s) | 
|---|
| 77 | { | 
|---|
| 78 | *s=towlower(*s); | 
|---|
| 79 | s++; | 
|---|
| 80 | } | 
|---|
| 81 | return x; | 
|---|
| 82 | } | 
|---|
| 83 | else | 
|---|
| 84 | return (LPWSTR)((UINT)towlower(LOWORD(x))); | 
|---|
| 85 | } | 
|---|
| 86 | //****************************************************************************** | 
|---|
| 87 | //****************************************************************************** | 
|---|
| 88 | LPSTR WIN32API CharNextA( LPCSTR arg1) | 
|---|
| 89 | { | 
|---|
| 90 | dprintf2(("USER32: OS2CharNextA(%08xh)\n", | 
|---|
| 91 | arg1)); | 
|---|
| 92 |  | 
|---|
| 93 | return O32_CharNext(arg1); | 
|---|
| 94 | } | 
|---|
| 95 | //****************************************************************************** | 
|---|
| 96 | //****************************************************************************** | 
|---|
| 97 | LPWSTR WIN32API CharNextW(LPCWSTR x) | 
|---|
| 98 | { | 
|---|
| 99 | dprintf2(("USER32: OS2CharNextW(%08xh)\n", | 
|---|
| 100 | x)); | 
|---|
| 101 |  | 
|---|
| 102 | if (*x) | 
|---|
| 103 | return (LPWSTR)(x+1); | 
|---|
| 104 | else | 
|---|
| 105 | return (LPWSTR)x; | 
|---|
| 106 | } | 
|---|
| 107 | //****************************************************************************** | 
|---|
| 108 | //****************************************************************************** | 
|---|
| 109 | LPSTR WIN32API CharPrevA( LPCSTR arg1, LPCSTR  arg2) | 
|---|
| 110 | { | 
|---|
| 111 | dprintf2(("USER32:  OS2CharPrevA\n")); | 
|---|
| 112 | return O32_CharPrev(arg1, arg2); | 
|---|
| 113 | } | 
|---|
| 114 | //****************************************************************************** | 
|---|
| 115 | //****************************************************************************** | 
|---|
| 116 | LPWSTR WIN32API CharPrevW(LPCWSTR start, | 
|---|
| 117 | LPCWSTR x) | 
|---|
| 118 | { | 
|---|
| 119 | dprintf2(("USER32: OS2CharPrevW(%08xh,%08xh)\n", | 
|---|
| 120 | start, | 
|---|
| 121 | x)); | 
|---|
| 122 |  | 
|---|
| 123 | /* FIXME: add DBCS / codepage stuff */ | 
|---|
| 124 | if (x>start) | 
|---|
| 125 | return (LPWSTR)(x-1); | 
|---|
| 126 | else | 
|---|
| 127 | return (LPWSTR)x; | 
|---|
| 128 | } | 
|---|
| 129 | //****************************************************************************** | 
|---|
| 130 | //****************************************************************************** | 
|---|
| 131 | BOOL WIN32API CharToOemA( LPCSTR arg1, LPSTR  arg2) | 
|---|
| 132 | { | 
|---|
| 133 | dprintf2(("USER32:  OS2CharToOemA\n")); | 
|---|
| 134 | return O32_CharToOem(arg1, arg2); | 
|---|
| 135 | } | 
|---|
| 136 | //****************************************************************************** | 
|---|
| 137 | //****************************************************************************** | 
|---|
| 138 | BOOL WIN32API CharToOemBuffA( LPCSTR arg1, LPSTR arg2, DWORD  arg3) | 
|---|
| 139 | { | 
|---|
| 140 | dprintf2(("USER32:  OS2CharToOemBuffA\n")); | 
|---|
| 141 | return O32_CharToOemBuff(arg1, arg2, arg3); | 
|---|
| 142 | } | 
|---|
| 143 | //****************************************************************************** | 
|---|
| 144 | //****************************************************************************** | 
|---|
| 145 | BOOL WIN32API CharToOemBuffW( LPCWSTR arg1, LPSTR arg2, DWORD  arg3) | 
|---|
| 146 | { | 
|---|
| 147 | dprintf2(("USER32:  OS2CharToOemBuffW DOESN'T WORK\n")); | 
|---|
| 148 | // NOTE: This will not work as is (needs UNICODE support) | 
|---|
| 149 | return 0; | 
|---|
| 150 | //    return O32_CharToOemBuff(arg1, arg2, arg3); | 
|---|
| 151 | } | 
|---|
| 152 | //****************************************************************************** | 
|---|
| 153 | //****************************************************************************** | 
|---|
| 154 | BOOL WIN32API CharToOemW( LPCWSTR arg1, LPSTR  arg2) | 
|---|
| 155 | { | 
|---|
| 156 | dprintf2(("USER32:  OS2CharToOemW DOESN'T WORK\n")); | 
|---|
| 157 | // NOTE: This will not work as is (needs UNICODE support) | 
|---|
| 158 | return 0; | 
|---|
| 159 | //    return O32_CharToOem(arg1, arg2); | 
|---|
| 160 | } | 
|---|
| 161 | //****************************************************************************** | 
|---|
| 162 | //****************************************************************************** | 
|---|
| 163 | LPSTR WIN32API CharUpperA( LPSTR arg1) | 
|---|
| 164 | { | 
|---|
| 165 | LPSTR rc; | 
|---|
| 166 |  | 
|---|
| 167 | if((int)arg1 >> 16 != 0) { | 
|---|
| 168 | dprintf2(("USER32:  OS2CharUpperA %s\n", arg1)); | 
|---|
| 169 | } | 
|---|
| 170 | else { | 
|---|
| 171 | dprintf2(("USER32:  OS2CharUpperA %X\n", arg1)); | 
|---|
| 172 | } | 
|---|
| 173 |  | 
|---|
| 174 | rc = O32_CharUpper(arg1); | 
|---|
| 175 |  | 
|---|
| 176 | if((int)rc >> 16 != 0) { | 
|---|
| 177 | dprintf2(("USER32:  OS2CharUpperA %s\n", rc)); | 
|---|
| 178 | } | 
|---|
| 179 | else { | 
|---|
| 180 | dprintf2(("USER32:  OS2CharUpperA %X\n", rc)); | 
|---|
| 181 | } | 
|---|
| 182 |  | 
|---|
| 183 | return(rc); | 
|---|
| 184 | } | 
|---|
| 185 | //****************************************************************************** | 
|---|
| 186 | //****************************************************************************** | 
|---|
| 187 | DWORD WIN32API CharUpperBuffA( LPSTR arg1, DWORD  arg2) | 
|---|
| 188 | { | 
|---|
| 189 | dprintf2(("USER32:  OS2CharUpperBuffA\n")); | 
|---|
| 190 | return O32_CharUpperBuff(arg1, arg2); | 
|---|
| 191 | } | 
|---|
| 192 | //****************************************************************************** | 
|---|
| 193 | //****************************************************************************** | 
|---|
| 194 | DWORD WIN32API CharUpperBuffW(LPWSTR x, DWORD buflen) | 
|---|
| 195 | { | 
|---|
| 196 | DWORD done=0; | 
|---|
| 197 |  | 
|---|
| 198 | dprintf2(("USER32: OS2CharUpperBuffW(%08xh,%08xh)\n", | 
|---|
| 199 | x, | 
|---|
| 200 | buflen)); | 
|---|
| 201 |  | 
|---|
| 202 | if (!x) | 
|---|
| 203 | return 0; /* YES */ | 
|---|
| 204 |  | 
|---|
| 205 | while (*x && (buflen--)) | 
|---|
| 206 | { | 
|---|
| 207 | *x=towupper(*x); | 
|---|
| 208 | x++; | 
|---|
| 209 | done++; | 
|---|
| 210 | } | 
|---|
| 211 |  | 
|---|
| 212 | return done; | 
|---|
| 213 | } | 
|---|
| 214 | //****************************************************************************** | 
|---|
| 215 | //****************************************************************************** | 
|---|
| 216 | ODINFUNCTION1(LPWSTR,CharUpperW,LPWSTR,x) | 
|---|
| 217 | { | 
|---|
| 218 | if (HIWORD(x)) | 
|---|
| 219 | { | 
|---|
| 220 | LPWSTR s = x; | 
|---|
| 221 |  | 
|---|
| 222 | while (*s) | 
|---|
| 223 | { | 
|---|
| 224 | *s=towupper(*s); | 
|---|
| 225 | s++; | 
|---|
| 226 | } | 
|---|
| 227 | return x; | 
|---|
| 228 | } | 
|---|
| 229 | else | 
|---|
| 230 | return (LPWSTR)((UINT)towupper(LOWORD(x))); | 
|---|
| 231 | } | 
|---|
| 232 | //****************************************************************************** | 
|---|
| 233 | //****************************************************************************** | 
|---|
| 234 | LPSTR WIN32API CharNextExA( WORD codepage, LPCSTR ptr, DWORD flags ) | 
|---|
| 235 | { | 
|---|
| 236 | if (!*ptr) return (LPSTR)ptr; | 
|---|
| 237 | //    if (O32_IsDBCSLeadByteEx( codepage, *ptr )) return (LPSTR)(ptr + 2); | 
|---|
| 238 | return (LPSTR)(ptr + 1); | 
|---|
| 239 | } | 
|---|
| 240 | //****************************************************************************** | 
|---|
| 241 | //****************************************************************************** | 
|---|
| 242 | LPSTR WIN32API CharPrevExA(WORD codepage, LPCSTR start, LPCSTR ptr, DWORD flags) | 
|---|
| 243 | { | 
|---|
| 244 | while (*start && (start < ptr)) | 
|---|
| 245 | { | 
|---|
| 246 | LPCSTR next = CharNextExA(codepage, start, flags); | 
|---|
| 247 | if (next > ptr) break; | 
|---|
| 248 | start = next; | 
|---|
| 249 | } | 
|---|
| 250 | return (LPSTR)start; | 
|---|
| 251 | } | 
|---|
| 252 | /***************************************************************************** | 
|---|
| 253 | * Name      : LPSTR WIN32API CharNextExW | 
|---|
| 254 | * Purpose   : The CharNextExA function retrieves the address of the next | 
|---|
| 255 | *             character in a string. This function can handle strings | 
|---|
| 256 | *             consisting of either single- or multi-byte characters. | 
|---|
| 257 | * Parameters: | 
|---|
| 258 | * Variables : | 
|---|
| 259 | * Result    : If the function succeeds, the return value is a pointer to the | 
|---|
| 260 | *             next character in the string, or to the terminating null character | 
|---|
| 261 | *             if at the end of the string. | 
|---|
| 262 | *             If lpCurrentChar points to the terminating null character, the | 
|---|
| 263 | *             return value is equal to lpCurrentChar. | 
|---|
| 264 | * Remark    : | 
|---|
| 265 | * Status    : UNTESTED STUB | 
|---|
| 266 | * | 
|---|
| 267 | * Author    : Patrick Haller [Thu, 1998/02/26 11:55] | 
|---|
| 268 | *****************************************************************************/ | 
|---|
| 269 |  | 
|---|
| 270 | LPWSTR WIN32API CharNextExW(WORD   CodePage, | 
|---|
| 271 | LPCWSTR lpCurrentChar, | 
|---|
| 272 | DWORD  dwFlags) | 
|---|
| 273 | { | 
|---|
| 274 | dprintf2(("USER32:CharNextExW(%u,%08xh,%08x) not implemented.\n", | 
|---|
| 275 | CodePage, | 
|---|
| 276 | lpCurrentChar, | 
|---|
| 277 | dwFlags)); | 
|---|
| 278 |  | 
|---|
| 279 | return (NULL); | 
|---|
| 280 | } | 
|---|
| 281 |  | 
|---|
| 282 |  | 
|---|
| 283 | /***************************************************************************** | 
|---|
| 284 | * Name      : LPSTR WIN32API CharPrevExW | 
|---|
| 285 | * Purpose   : The CharPrevExA function retrieves the address of the preceding | 
|---|
| 286 | *             character in a string. This function can handle strings | 
|---|
| 287 | *             consisting of either single- or multi-byte characters. | 
|---|
| 288 | * Parameters: | 
|---|
| 289 | * Variables : | 
|---|
| 290 | * Result    : If the function succeeds, the return value is a pointer to the | 
|---|
| 291 | *             preceding character in the string, or to the first character in | 
|---|
| 292 | *             the string if the lpCurrentChar parameter equals the lpStart parameter. | 
|---|
| 293 | * Remark    : | 
|---|
| 294 | * Status    : UNTESTED STUB | 
|---|
| 295 | * | 
|---|
| 296 | * Author    : Patrick Haller [Thu, 1998/02/26 11:55] | 
|---|
| 297 | *****************************************************************************/ | 
|---|
| 298 |  | 
|---|
| 299 | LPWSTR WIN32API CharPrevExW(WORD CodePage, | 
|---|
| 300 | LPCWSTR lpStart, | 
|---|
| 301 | LPCWSTR lpCurrentChar, | 
|---|
| 302 | DWORD  dwFlags) | 
|---|
| 303 | { | 
|---|
| 304 | dprintf2(("USER32:CharPrevExW(%u,%08xh,%08xh,%08x) not implemented.\n", | 
|---|
| 305 | CodePage, | 
|---|
| 306 | lpStart, | 
|---|
| 307 | lpCurrentChar, | 
|---|
| 308 | dwFlags)); | 
|---|
| 309 |  | 
|---|
| 310 | return (NULL); | 
|---|
| 311 | } | 
|---|
| 312 | //****************************************************************************** | 
|---|
| 313 | //****************************************************************************** | 
|---|
| 314 | BOOL WIN32API IsCharAlphaA( CHAR arg1) | 
|---|
| 315 | { | 
|---|
| 316 | dprintf(("USER32:  OS2IsCharAlphaA\n")); | 
|---|
| 317 | return O32_IsCharAlpha(arg1); | 
|---|
| 318 | } | 
|---|
| 319 | //****************************************************************************** | 
|---|
| 320 | //****************************************************************************** | 
|---|
| 321 | BOOL WIN32API IsCharAlphaNumericA( CHAR arg1) | 
|---|
| 322 | { | 
|---|
| 323 | dprintf(("USER32:  OS2IsCharAlphaNumericA\n")); | 
|---|
| 324 | return O32_IsCharAlphaNumeric(arg1); | 
|---|
| 325 | } | 
|---|
| 326 | //****************************************************************************** | 
|---|
| 327 | //****************************************************************************** | 
|---|
| 328 | BOOL WIN32API IsCharAlphaNumericW( WCHAR arg1) | 
|---|
| 329 | { | 
|---|
| 330 | dprintf(("USER32:  OS2IsCharAlphaNumericW\n")); | 
|---|
| 331 | // NOTE: This will not work as is (needs UNICODE support) | 
|---|
| 332 | return O32_IsCharAlphaNumeric((CHAR)arg1); | 
|---|
| 333 | } | 
|---|
| 334 | //****************************************************************************** | 
|---|
| 335 | //****************************************************************************** | 
|---|
| 336 | BOOL WIN32API IsCharAlphaW( WCHAR arg1) | 
|---|
| 337 | { | 
|---|
| 338 | dprintf(("USER32:  OS2IsCharAlphaW\n")); | 
|---|
| 339 | // NOTE: This will not work as is (needs UNICODE support) | 
|---|
| 340 | return O32_IsCharAlpha((CHAR)arg1); | 
|---|
| 341 | } | 
|---|
| 342 | //****************************************************************************** | 
|---|
| 343 | //****************************************************************************** | 
|---|
| 344 | BOOL WIN32API IsCharLowerA( CHAR arg1) | 
|---|
| 345 | { | 
|---|
| 346 | dprintf(("USER32:  OS2IsCharLowerA\n")); | 
|---|
| 347 | return O32_IsCharLower(arg1); | 
|---|
| 348 | } | 
|---|
| 349 | //****************************************************************************** | 
|---|
| 350 | //****************************************************************************** | 
|---|
| 351 | BOOL WIN32API IsCharLowerW( WCHAR arg1) | 
|---|
| 352 | { | 
|---|
| 353 | dprintf(("USER32:  OS2IsCharLowerW\n")); | 
|---|
| 354 | // NOTE: This will not work as is (needs UNICODE support) | 
|---|
| 355 | return O32_IsCharLower((CHAR)arg1); | 
|---|
| 356 | } | 
|---|
| 357 | //****************************************************************************** | 
|---|
| 358 | //****************************************************************************** | 
|---|
| 359 | BOOL WIN32API IsCharUpperA( CHAR arg1) | 
|---|
| 360 | { | 
|---|
| 361 | dprintf(("USER32:  OS2IsCharUpperA\n")); | 
|---|
| 362 | return O32_IsCharUpper(arg1); | 
|---|
| 363 | } | 
|---|
| 364 | //****************************************************************************** | 
|---|
| 365 | //****************************************************************************** | 
|---|
| 366 | BOOL WIN32API IsCharUpperW( WCHAR arg1) | 
|---|
| 367 | { | 
|---|
| 368 | dprintf(("USER32:  OS2IsCharUpperW\n")); | 
|---|
| 369 | // NOTE: This will not work as is (needs UNICODE support) | 
|---|
| 370 | return O32_IsCharUpper((CHAR)arg1); | 
|---|
| 371 | } | 
|---|
| 372 | //****************************************************************************** | 
|---|
| 373 | //****************************************************************************** | 
|---|
| 374 | BOOL WIN32API OemToCharA( LPCSTR arg1, LPSTR  arg2) | 
|---|
| 375 | { | 
|---|
| 376 | dprintf(("USER32:  OS2OemToCharA\n")); | 
|---|
| 377 | return O32_OemToChar(arg1, arg2); | 
|---|
| 378 | } | 
|---|
| 379 | //****************************************************************************** | 
|---|
| 380 | //****************************************************************************** | 
|---|
| 381 | BOOL WIN32API OemToCharBuffA( LPCSTR arg1, LPSTR arg2, DWORD  arg3) | 
|---|
| 382 | { | 
|---|
| 383 | dprintf(("USER32:  OS2OemToCharBuffA\n")); | 
|---|
| 384 | return O32_OemToCharBuff(arg1, arg2, arg3); | 
|---|
| 385 | } | 
|---|
| 386 | //****************************************************************************** | 
|---|
| 387 | //****************************************************************************** | 
|---|
| 388 | BOOL WIN32API OemToCharBuffW(LPCSTR arg1, LPWSTR arg2, DWORD  arg3) | 
|---|
| 389 | { | 
|---|
| 390 | dprintf(("USER32: OemToCharBuffW DOESN'T WORK \n")); | 
|---|
| 391 | // NOTE: This will not work as is (needs UNICODE support) | 
|---|
| 392 | return 0; | 
|---|
| 393 | //    return O32_OemToCharBuff(arg1, arg2, arg3); | 
|---|
| 394 | } | 
|---|
| 395 | //****************************************************************************** | 
|---|
| 396 | //****************************************************************************** | 
|---|
| 397 | BOOL WIN32API OemToCharW( LPCSTR arg1, LPWSTR  arg2) | 
|---|
| 398 | { | 
|---|
| 399 | dprintf(("USER32:  OS2OemToCharW DOESN'T WORK\n")); | 
|---|
| 400 | // NOTE: This will not work as is (needs UNICODE support) | 
|---|
| 401 | return 0; | 
|---|
| 402 | //    return O32_OemToChar(arg1, arg2); | 
|---|
| 403 | } | 
|---|