4 * Copyright 1993 Yngvi Sigurjonsson (yngvi@hafro.is)
5 * Copyright 1996 Marcus Meissner
22 #define ToUpper(c) toupper(c)
23 #define ToLower(c) tolower(c)
26 static const BYTE Oem2Ansi
[256] =
27 "\000\001\002\003\004\005\006\007\010\011\012\013\014\015\016\244"
28 "\020\021\022\023\266\247\026\027\030\031\032\033\034\035\036\037"
29 "\040\041\042\043\044\045\046\047\050\051\052\053\054\055\056\057"
30 "\060\061\062\063\064\065\066\067\070\071\072\073\074\075\076\077"
31 "\100\101\102\103\104\105\106\107\110\111\112\113\114\115\116\117"
32 "\120\121\122\123\124\125\126\127\130\131\132\133\134\135\136\137"
33 "\140\141\142\143\144\145\146\147\150\151\152\153\154\155\156\157"
34 "\160\161\162\163\164\165\166\167\170\171\172\173\174\175\176\177"
35 "\307\374\351\342\344\340\345\347\352\353\350\357\356\354\304\305"
36 "\311\346\306\364\366\362\373\371\377\326\334\242\243\245\120\203"
37 "\341\355\363\372\361\321\252\272\277\137\254\275\274\241\253\273"
38 "\137\137\137\246\246\246\246\053\053\246\246\053\053\053\053\053"
39 "\053\055\055\053\055\053\246\246\053\053\055\055\246\055\053\055"
40 "\055\055\055\053\053\053\053\053\053\053\053\137\137\246\137\137"
41 "\137\337\137\266\137\137\265\137\137\137\137\137\137\137\137\137"
42 "\137\261\137\137\137\137\367\137\260\225\267\137\156\262\137\137";
44 static const BYTE Ansi2Oem
[256] =
45 "\000\001\002\003\004\005\006\007\010\011\012\013\014\015\016\017"
46 "\020\021\022\023\024\025\026\027\030\031\032\033\034\035\036\037"
47 "\040\041\042\043\044\045\046\047\050\051\052\053\054\055\056\057"
48 "\060\061\062\063\064\065\066\067\070\071\072\073\074\075\076\077"
49 "\100\101\102\103\104\105\106\107\110\111\112\113\114\115\116\117"
50 "\120\121\122\123\124\125\126\127\130\131\132\133\134\135\136\137"
51 "\140\141\142\143\144\145\146\147\150\151\152\153\154\155\156\157"
52 "\160\161\162\163\164\165\166\167\170\171\172\173\174\175\176\177"
53 "\200\201\054\237\054\137\375\374\210\045\123\074\117\215\216\217"
54 "\220\140\047\042\042\371\055\137\230\231\163\076\157\235\236\131"
55 "\040\255\233\234\017\235\335\025\042\143\246\256\252\055\162\137"
56 "\370\361\375\063\047\346\024\372\054\061\247\257\254\253\137\250"
57 "\101\101\101\101\216\217\222\200\105\220\105\105\111\111\111\111"
58 "\104\245\117\117\117\117\231\170\117\125\125\125\232\131\137\341"
59 "\205\240\203\141\204\206\221\207\212\202\210\211\215\241\214\213"
60 "\144\244\225\242\223\157\224\366\157\227\243\226\201\171\137\230";
62 /* Funny to divide them between user and kernel. */
64 /* IsCharAlpha USER 433 */
65 BOOL16
IsCharAlpha16(CHAR ch
)
67 return isalpha(ch
); /* This is probably not right for NLS */
70 /* IsCharAlphanumeric USER 434 */
71 BOOL16
IsCharAlphanumeric16(CHAR ch
)
76 /* IsCharUpper USER 435 */
77 BOOL16
IsCharUpper16(CHAR ch
)
82 /* IsCharLower USER 436 */
83 BOOL16
IsCharLower16(CHAR ch
)
88 /***********************************************************************
89 * AnsiUpper (USER.431)
93 SEGPTR
WIN16_AnsiUpper( SEGPTR strOrChar
)
95 /* I am not sure if the locale stuff works with toupper, but then again
96 I am not sure if the Linux libc locale stuffs works at all */
98 /* uppercase only one char if strOrChar < 0x10000 */
99 if (HIWORD(strOrChar
))
101 char *s
= PTR_SEG_TO_LIN(strOrChar
);
108 else return (SEGPTR
)ToUpper( (int)strOrChar
);
112 LPSTR
AnsiUpper(LPSTR strOrChar
)
115 /* I am not sure if the locale stuff works with toupper, but then again
116 I am not sure if the Linux libc locale stuffs works at all */
126 /***********************************************************************
127 * AnsiUpperBuff (USER.437)
129 UINT
AnsiUpperBuff(LPSTR str
,UINT len
)
132 len
=(len
==0)?65536:len
;
135 str
[i
]=toupper(str
[i
]);
139 /***********************************************************************
140 * AnsiLower (USER.432)
144 SEGPTR
WIN16_AnsiLower(SEGPTR strOrChar
)
146 /* I am not sure if the locale stuff works with toupper, but then again
147 I am not sure if the Linux libc locale stuffs works at all */
149 /* lowercase only one char if strOrChar < 0x10000 */
150 if (HIWORD(strOrChar
))
152 char *s
= PTR_SEG_TO_LIN( strOrChar
);
159 else return (SEGPTR
)ToLower( (int)strOrChar
);
163 LPSTR
AnsiLower(LPSTR strOrChar
)
166 /* I am not sure if the locale stuff works with toupper, but then again
167 I am not sure if the Linux libc locale stuffs works at all */
177 /***********************************************************************
178 * AnsiLowerBuff (USER.438)
180 UINT
AnsiLowerBuff(LPSTR str
,UINT len
)
183 len
=(len
==0)?65536:len
;
187 str
[i
]=tolower(str
[i
]);
193 /* AnsiNext USER.472 */
194 SEGPTR
AnsiNext(SEGPTR current
)
196 return (*(char *)PTR_SEG_TO_LIN(current
)) ? current
+ 1 : current
;
199 /* AnsiPrev USER.473 */
200 SEGPTR
AnsiPrev( SEGPTR start
, SEGPTR current
)
202 return (current
==start
)?start
:current
-1;
206 /* AnsiToOem Keyboard.5 */
207 INT
AnsiToOem(LPCSTR lpAnsiStr
, LPSTR lpOemStr
)
209 dprintf_keyboard(stddeb
, "AnsiToOem: %s\n", lpAnsiStr
);
211 *lpOemStr
++=Ansi2Oem
[(unsigned char)(*lpAnsiStr
++)];
217 /* OemToAnsi Keyboard.6 */
218 BOOL
OemToAnsi(LPCSTR lpOemStr
, LPSTR lpAnsiStr
)
220 dprintf_keyboard(stddeb
, "OemToAnsi: %s\n", lpOemStr
);
222 *lpAnsiStr
++=Oem2Ansi
[(unsigned char)(*lpOemStr
++)];
228 /* AnsiToOemBuff Keyboard.134 */
229 void AnsiToOemBuff(LPCSTR lpAnsiStr
, LPSTR lpOemStr
, UINT nLength
)
232 for(i
=0;i
<nLength
;i
++)
233 lpOemStr
[i
]=Ansi2Oem
[(unsigned char)(lpAnsiStr
[i
])];
236 /* OemToAnsi Keyboard.135 */
237 void OemToAnsiBuff(LPCSTR lpOemStr
, LPSTR lpAnsiStr
, INT nLength
)
240 for(i
=0;i
<nLength
;i
++)
241 lpAnsiStr
[i
]=Oem2Ansi
[(unsigned char)(lpOemStr
[i
])];
245 /***********************************************************************
246 * OutputDebugString (KERNEL.115)
248 void OutputDebugString( LPCSTR str
)
251 char *p
, *buffer
= xmalloc( strlen(str
)+1 );
253 for (p
= buffer
; *str
; str
++) if (*str
!= '\r') *p
++ = *str
;
255 if ((p
> buffer
) && (p
[-1] == '\n')) p
[1] = '\0'; /* Remove trailing \n */
256 module
= MODULE_GetModuleName( GetExePtr(GetCurrentTask()) );
257 fprintf( stderr
, "OutputDebugString: %s says '%s'\n",
258 module
? module
: "???", buffer
);
262 /***********************************************************************
263 * CharNextA (USER32.28)
265 LPSTR
CharNext32A(LPCSTR x
)
267 if (*x
) return (LPSTR
)(x
+1);
268 else return (LPSTR
)x
;
271 /***********************************************************************
272 * CharNextExA (USER32.29)
274 LPSTR
CharNextEx32A(WORD codepage
,LPCSTR x
,DWORD flags
)
276 /* FIXME: add DBCS / codepage stuff */
277 if (*x
) return (LPSTR
)(x
+1);
278 else return (LPSTR
)x
;
281 /***********************************************************************
282 * CharNextExW (USER32.30)
284 LPWSTR
CharNextEx32W(WORD codepage
,LPCWSTR x
,DWORD flags
)
286 /* FIXME: add DBCS / codepage stuff */
287 if (*x
) return (LPWSTR
)(x
+1);
288 else return (LPWSTR
)x
;
291 /***********************************************************************
292 * CharNextW (USER32.31)
294 LPWSTR
CharNext32W(LPCWSTR x
)
296 if (*x
) return (LPWSTR
)(x
+1);
297 else return (LPWSTR
)x
;
300 /***********************************************************************
301 * CharPrevA (USER32.32)
303 LPSTR
CharPrev32A(LPCSTR start
,LPCSTR x
)
305 if (x
>start
) return (LPSTR
)(x
-1);
306 else return (LPSTR
)x
;
309 /***********************************************************************
310 * CharPrevExA (USER32.33)
312 LPSTR
CharPrevEx32A(WORD codepage
,LPCSTR start
,LPCSTR x
,DWORD flags
)
314 /* FIXME: add DBCS / codepage stuff */
315 if (x
>start
) return (LPSTR
)(x
-1);
316 else return (LPSTR
)x
;
319 /***********************************************************************
320 * CharPrevExW (USER32.34)
322 LPWSTR
CharPrevEx32W(WORD codepage
,LPCWSTR start
,LPCWSTR x
,DWORD flags
)
324 /* FIXME: add DBCS / codepage stuff */
325 if (x
>start
) return (LPWSTR
)(x
-1);
326 else return (LPWSTR
)x
;
329 /***********************************************************************
330 * CharPrevW (USER32.35)
332 LPWSTR
CharPrev32W(LPCWSTR start
,LPCWSTR x
)
334 if (x
>start
) return (LPWSTR
)(x
-1);
335 else return (LPWSTR
)x
;
338 /***********************************************************************
339 * CharLowerA (USER32.24)
340 * FIXME: handle current locale
342 LPSTR
CharLower32A(LPSTR x
)
356 else return (LPSTR
)tolower(LOWORD(x
));
359 /***********************************************************************
360 * CharLowerBuffA (USER32.25)
361 * FIXME: handle current locale
363 DWORD
CharLowerBuff32A(LPSTR x
,DWORD buflen
)
367 while (*x
&& (buflen
--))
376 /***********************************************************************
377 * CharLowerBuffW (USER32.26)
378 * FIXME: handle current locale
380 DWORD
CharLowerBuff32W(LPWSTR x
,DWORD buflen
)
384 while (*x
&& (buflen
--))
393 /***********************************************************************
394 * CharLowerW (USER32.27)
395 * FIXME: handle current locale
397 LPWSTR
CharLower32W(LPWSTR x
)
409 else return (LPWSTR
)tolower(LOWORD(x
));
412 /***********************************************************************
413 * CharUpperA (USER32.40)
414 * FIXME: handle current locale
416 LPSTR
CharUpper32A(LPSTR x
)
428 else return (LPSTR
)toupper(LOWORD(x
));
431 /***********************************************************************
432 * CharUpperBuffA (USER32.41)
433 * FIXME: handle current locale
435 DWORD
CharUpperBuff32A(LPSTR x
,DWORD buflen
)
439 while (*x
&& (buflen
--))
448 /***********************************************************************
449 * CharUpperBuffW (USER32.42)
450 * FIXME: handle current locale
452 DWORD
CharUpperBuff32W(LPWSTR x
,DWORD buflen
)
456 while (*x
&& (buflen
--))
465 /***********************************************************************
466 * CharUpperW (USER32.43)
467 * FIXME: handle current locale
469 LPWSTR
CharUpper32W(LPWSTR x
)
481 else return (LPWSTR
)toupper(LOWORD(x
));
484 /***********************************************************************
485 * IsCharAlphaA (USER32.330)
486 * FIXME: handle current locale
488 BOOL32
IsCharAlpha32A(CHAR x
)
493 /***********************************************************************
494 * IsCharAlphaNumericA (USER32.331)
495 * FIXME: handle current locale
497 BOOL32
IsCharAlphaNumeric32A(CHAR x
)
502 /***********************************************************************
503 * IsCharAlphaNumericW (USER32.332)
504 * FIXME: handle current locale
506 BOOL32
IsCharAlphaNumeric32W(WCHAR x
)
511 /***********************************************************************
512 * IsCharAlphaW (USER32.333)
513 * FIXME: handle current locale
515 BOOL32
IsCharAlpha32W(WCHAR x
)
520 /***********************************************************************
521 * IsCharAlphaW (USER32.334)
522 * FIXME: handle current locale
524 BOOL32
IsCharLower32A(CHAR x
)
529 /***********************************************************************
530 * IsCharAlphaW (USER32.335)
531 * FIXME: handle current locale
533 BOOL32
IsCharLower32W(WCHAR x
)
538 /***********************************************************************
539 * IsCharAlphaW (USER32.336)
540 * FIXME: handle current locale
542 BOOL32
IsCharUpper32A(CHAR x
)
547 /***********************************************************************
548 * IsCharAlphaW (USER32.337)
549 * FIXME: handle current locale
551 BOOL32
IsCharUpper32W(WCHAR x
)
556 /***********************************************************************
557 * CharToOemA (USER32.36)
559 BOOL32
CharToOem32A(LPSTR s
,LPSTR d
)
567 /***********************************************************************
568 * CharToOemBuffA (USER32.37)
570 BOOL32
CharToOemBuff32A(LPSTR s
,LPSTR d
,DWORD len
)
572 AnsiToOemBuff(s
,d
,len
);
576 /***********************************************************************
577 * CharToOemBuffW (USER32.38)
579 BOOL32
CharToOemBuff32W(LPCWSTR s
,LPSTR d
,DWORD len
)
581 LPSTR x
=STRING32_DupUniToAnsi(s
);
582 AnsiToOemBuff(x
,d
,len
);
586 /***********************************************************************
587 * CharToOemW (USER32.39)
589 BOOL32
CharToOem32W(LPCWSTR s
,LPSTR d
)
591 LPSTR x
=STRING32_DupUniToAnsi(s
);
596 /***********************************************************************
597 * OemToCharA (USER32.401)
599 BOOL32
OemToChar32A(LPSTR s
,LPSTR d
)
605 /***********************************************************************
606 * OemToCharBuffA (USER32.402)
608 BOOL32
OemToCharBuff32A(LPSTR s
,LPSTR d
,DWORD len
)
610 OemToAnsiBuff(s
,d
,len
);
614 /***********************************************************************
615 * OemToCharBuffW (USER32.403)
617 BOOL32
OemToCharBuff32W(LPCSTR s
,LPWSTR d
,DWORD len
)
619 LPSTR x
=(char*)xmalloc(strlen(s
));
620 OemToAnsiBuff((LPSTR
)s
,x
,len
);
621 STRING32_AnsiToUni(d
,x
);
625 /***********************************************************************
626 * OemToCharW (USER32.404)
628 BOOL32
OemToChar32W(LPCSTR s
,LPWSTR d
)
630 LPSTR x
=(char*)xmalloc(strlen(s
));
631 OemToAnsi((LPSTR
)s
,x
);
632 STRING32_AnsiToUni(d
,x
);
636 /***********************************************************************
637 * FormatMessageA (KERNEL32.138) Library Version
638 * FIXME: missing wrap,FROM_SYSTEM message-loading,
648 LPDWORD args
/* va_list *args */
653 DWORD width
= dwFlags
& FORMAT_MESSAGE_MAX_WIDTH_MASK
;
654 DWORD nolinefeed
= 0;
656 dprintf_resource(stddeb
,
657 "FormatMessage32A(0x%lx,%p,%ld,0x%lx,%p,%ld,%p)\n",
658 dwFlags
,lpSource
,dwMessageId
,dwLanguageId
,lpBuffer
,nSize
,args
661 fprintf(stdnimp
," - line wrapping not supported.\n");
663 if (dwFlags
& FORMAT_MESSAGE_FROM_STRING
)
664 from
= xstrdup((LPSTR
)lpSource
);
665 if (dwFlags
& FORMAT_MESSAGE_FROM_SYSTEM
) {
666 /* gather information from system message tables ... */
667 fprintf(stdnimp
," - FORMAT_MESSAGE_FROM_SYSTEM not implemented.\n");
669 if (dwFlags
& FORMAT_MESSAGE_FROM_HMODULE
) {
672 dwMessageId
&= 0xFFFF;
673 bufsize
=LoadMessage32A(0,dwMessageId
,dwLanguageId
,NULL
,100);
675 from
= (char*)xmalloc(bufsize
+1);
676 LoadMessage32A(0,dwMessageId
,dwLanguageId
,from
,bufsize
+1);
679 target
= (char*)xmalloc(100);
684 #define ADD_TO_T(c) \
686 if (t-target == talloced) {\
687 target = (char*)xrealloc(target,talloced*2);\
688 t = target+talloced;\
697 char *fmtstr
,*sprintfbuf
,*x
;
706 case '1':case '2':case '3':case '4':case '5':
707 case '6':case '7':case '8':case '9':
710 case '0':case '1':case '2':case '3':
711 case '4':case '5':case '6':case '7':
714 insertnr
=insertnr
*10+*f
-'0';
723 if (NULL
!=(x
=strchr(f
,'!'))) {
725 fmtstr
=xmalloc(strlen(f
)+2);
726 sprintf(fmtstr
,"%%%s",f
);
731 if (dwFlags
& FORMAT_MESSAGE_ARGUMENT_ARRAY
)
732 argliststart
=args
+insertnr
-1;
734 /* FIXME: not sure that this is
735 * correct for unix-c-varargs.
737 argliststart
=((DWORD
*)&args
)+insertnr
-1;
739 if (fmtstr
[strlen(fmtstr
)]=='s')
740 sprintfbuf
=(char*)xmalloc(strlen((LPSTR
)argliststart
[0])+1);
742 sprintfbuf
=(char*)xmalloc(100);
743 vsprintf(sprintfbuf
,fmtstr
,argliststart
);
755 default:ADD_TO_T(*f
++)
765 if (!nolinefeed
&& t
[-1]!='\n')
767 talloced
= strlen(target
)+1;
768 if (nSize
&& talloced
<nSize
) {
769 target
= (char*)xrealloc(target
,nSize
);
771 if (dwFlags
& FORMAT_MESSAGE_ALLOCATE_BUFFER
) {
772 /* nSize is the MINIMUM size */
773 *((LPVOID
*)lpBuffer
) = (LPVOID
)LocalAlloc32(GMEM_ZEROINIT
,talloced
);
774 memcpy(*(LPSTR
*)lpBuffer
,target
,talloced
);
776 strncpy(lpBuffer
,target
,nSize
);
778 if (from
) free(from
);
779 return (dwFlags
& FORMAT_MESSAGE_ALLOCATE_BUFFER
) ?
780 strlen(*(LPSTR
*)lpBuffer
):
784 /***********************************************************************
785 * FormatMessageA (KERNEL32.138) Emulator Version
788 WIN32_FormatMessage32A(DWORD
*args
) {
789 DWORD dwFlags
= args
[0];
790 LPCVOID lpSource
= (LPCVOID
)args
[1];
791 DWORD dwMessageId
= args
[2];
792 DWORD dwLanguageId
= args
[3];
793 LPSTR lpBuffer
= (LPSTR
)args
[4];
794 DWORD nSize
= args
[5];
797 /* convert possible varargs to an argument array look-a-like */
799 if (dwFlags
& FORMAT_MESSAGE_ARGUMENT_ARRAY
) {
800 xargs
=(DWORD
*)args
[6];
802 /* args[6] is a pointer to a pointer to the start of
803 * a list of arguments.
806 xargs
=(DWORD
*)(((DWORD
*)args
[6])[0]);
809 dwFlags
|=FORMAT_MESSAGE_ARGUMENT_ARRAY
;
811 return FormatMessage32A(