mirror of
https://git.tartarus.org/simon/putty.git
synced 2025-01-09 09:27:59 +00:00
New centralised helper function dup_mb_to_wc().
PuTTY's main mb_to_wc() function is all very well for embedding in fiddly data pipelines, but for the simple job of turning a C string into a C wide string, really I want something much more like dupprintf. So here is one. I've had to put it in a new separate source file miscucs.c rather than throwing it into misc.c, because misc.c is linked into tools that don't also include a module providing the internal Unicode API (winucs or uxucs). The new miscucs.c appears only in Unicode-using tools.
This commit is contained in:
parent
9bea08a298
commit
7762d71226
4
Recipe
4
Recipe
@ -203,10 +203,10 @@ TERMINAL = terminal wcwidth ldiscucs logging tree234 minibidi
|
|||||||
|
|
||||||
# GUI front end and terminal emulator (putty, puttytel).
|
# GUI front end and terminal emulator (putty, puttytel).
|
||||||
GUITERM = TERMINAL window windlg winctrls sizetip winucs winprint
|
GUITERM = TERMINAL window windlg winctrls sizetip winucs winprint
|
||||||
+ winutils wincfg sercfg winhelp winjump
|
+ winutils wincfg sercfg winhelp winjump miscucs
|
||||||
|
|
||||||
# Same thing on Unix.
|
# Same thing on Unix.
|
||||||
UXTERM = TERMINAL uxcfg sercfg uxucs uxprint timing callback
|
UXTERM = TERMINAL uxcfg sercfg uxucs uxprint timing callback miscucs
|
||||||
GTKTERM = UXTERM gtkwin gtkcfg gtkdlg gtkfont gtkcols xkeysym
|
GTKTERM = UXTERM gtkwin gtkcfg gtkdlg gtkfont gtkcols xkeysym
|
||||||
OSXTERM = UXTERM osxwin osxdlg osxctrls
|
OSXTERM = UXTERM osxwin osxdlg osxctrls
|
||||||
|
|
||||||
|
9
misc.h
9
misc.h
@ -39,6 +39,15 @@ char *dupprintf(const char *fmt, ...)
|
|||||||
char *dupvprintf(const char *fmt, va_list ap);
|
char *dupvprintf(const char *fmt, va_list ap);
|
||||||
void burnstr(char *string);
|
void burnstr(char *string);
|
||||||
|
|
||||||
|
/* String-to-Unicode converters that auto-allocate the destination and
|
||||||
|
* work around the rather deficient interface of mb_to_wc.
|
||||||
|
*
|
||||||
|
* These actually live in miscucs.c, not misc.c (the distinction being
|
||||||
|
* that the former is only linked into tools that also have the main
|
||||||
|
* Unicode support). */
|
||||||
|
wchar_t *dup_mb_to_wc_c(int codepage, int flags, const char *string, int len);
|
||||||
|
wchar_t *dup_mb_to_wc(int codepage, int flags, const char *string);
|
||||||
|
|
||||||
int toint(unsigned);
|
int toint(unsigned);
|
||||||
|
|
||||||
char *fgetline(FILE *fp);
|
char *fgetline(FILE *fp);
|
||||||
|
28
miscucs.c
Normal file
28
miscucs.c
Normal file
@ -0,0 +1,28 @@
|
|||||||
|
/*
|
||||||
|
* Centralised Unicode-related helper functions, separate from misc.c
|
||||||
|
* so that they can be omitted from tools that aren't including
|
||||||
|
* Unicode handling.
|
||||||
|
*/
|
||||||
|
|
||||||
|
#include "putty.h"
|
||||||
|
#include "misc.h"
|
||||||
|
|
||||||
|
wchar_t *dup_mb_to_wc_c(int codepage, int flags, const char *string, int len)
|
||||||
|
{
|
||||||
|
int mult;
|
||||||
|
for (mult = 1 ;; mult++) {
|
||||||
|
wchar_t *ret = snewn(mult*len + 2, wchar_t);
|
||||||
|
int outlen;
|
||||||
|
outlen = mb_to_wc(codepage, flags, string, len, ret, mult*len + 1);
|
||||||
|
if (outlen < mult*len+1) {
|
||||||
|
ret[outlen] = L'\0';
|
||||||
|
return ret;
|
||||||
|
}
|
||||||
|
sfree(ret);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
wchar_t *dup_mb_to_wc(int codepage, int flags, const char *string)
|
||||||
|
{
|
||||||
|
return dup_mb_to_wc_c(codepage, flags, string, strlen(string));
|
||||||
|
}
|
Loading…
Reference in New Issue
Block a user