added some wide character support

svn path=/trunk/; revision=268
This commit is contained in:
Boudewijn Dekker 1999-02-25 21:33:50 +00:00
parent 7946500988
commit d58a6ad5d6
17 changed files with 411 additions and 31 deletions

View file

@ -315,5 +315,10 @@ int _doprnt(const char *fmt, va_list args, FILE *f)
return 0;
}
int _dowprnt(const wchar_t *fmt, va_list args, FILE *f)
{
return 0;
}

View file

@ -24,3 +24,26 @@ fprintf(register FILE *iop, const char *fmt, ...)
len = _doprnt(fmt, (&fmt)+1, iop);
return ferror(iop) ? EOF : len;
}
int
fwprintf(register FILE *iop, const wchar_t *fmt, ...)
{
int len;
wchar_t localbuf[BUFSIZ];
if (iop->_flag & _IONBF)
{
iop->_flag &= ~_IONBF;
iop->_ptr = iop->_base = localbuf;
iop->_bufsiz = BUFSIZ;
len = _dowprnt(fmt, (&fmt)+sizeof(wchar_t), iop);
fflush(iop);
iop->_flag |= _IONBF;
iop->_base = NULL;
iop->_bufsiz = 0;
iop->_cnt = 0;
}
else
len = _dowprnt(fmt, (va_list)(&fmt)+sizeof(wchar_t), iop);
return ferror(iop) ? EOF : len;
}

View file

@ -17,3 +17,17 @@ printf(const char *fmt, ...)
return ferror(stdout) ? EOF : len;
}
int wprintf(const wchar_t *fmt, ...)
{
int len;
len = _dowprnt(fmt, (&fmt)+sizeof(wchar_t), stdout);
/* People were confused when printf() didn't flush stdout,
so we'll do it to reduce confusion */
if (stdout->_flag & _IOLBF)
fflush(stdout);
return ferror(stdout) ? EOF : len;
}

View file

@ -17,3 +17,16 @@ sprintf(char *str, const char *fmt, ...)
*_strbuf._ptr = 0;
return len;
}
swprintf(wchar_t *str, const wchar_t *fmt, ...)
{
FILE _strbuf;
int len;
_strbuf._flag = _IOWRT|_IOSTRG;
_strbuf._ptr = str;
_strbuf._cnt = INT_MAX;
len = _dowprnt(fmt,(va_list) &(fmt)+sizeof(wchar_t), &_strbuf);
*_strbuf._ptr = 0;
return len;
}

View file

@ -25,3 +25,25 @@ vfprintf(FILE *f, const char *fmt, va_list ap)
len = _doprnt(fmt, ap, f);
return (ferror(f) ? EOF : len);
}
int vfwprintf(FILE *f, const wchar_t *fmt, va_list ap)
{
int len;
wchar_t localbuf[BUFSIZ];
if (f->_flag & _IONBF)
{
f->_flag &= ~_IONBF;
f->_ptr = f->_base = localbuf;
f->_bufsiz = BUFSIZ;
len = _dowprnt(fmt, ap, f);
(void)fflush(f);
f->_flag |= _IONBF;
f->_base = NULL;
f->_bufsiz = 0;
f->_cnt = 0;
}
else
len = _dowprnt(fmt, ap, f);
return (ferror(f) ? EOF : len);
}

View file

@ -11,3 +11,12 @@ vprintf(const char *fmt, va_list ap)
len = _doprnt(fmt, ap, stdout);
return (ferror(stdout) ? EOF : len);
}
int
vwprintf(const wchar_t *fmt, va_list ap)
{
int len;
len = _dowprnt(fmt, ap, stdout);
return (ferror(stdout) ? EOF : len);
}

View file

@ -17,3 +17,16 @@ vsprintf(char *str, const char *fmt, va_list ap)
*f._ptr = 0;
return len;
}
vswprintf(wchar_t *str, const wchar_t *fmt, va_list ap)
{
FILE f;
int len;
f._flag = _IOWRT|_IOSTRG;
f._ptr = str;
f._cnt = INT_MAX;
len = _dowprnt(fmt, ap, &f);
*f._ptr = 0;
return len;
}

View file

@ -4,7 +4,6 @@
#include <fcntl.h>
#include <libc/atexit.h>
void _exit(int _status);
struct __atexit *__atexit_ptr = 0;
@ -34,7 +33,7 @@ exit(int status)
void _exit(int _status)
{
//ExitProcess(_status);
ExitProcess(_status);
}
void _cexit( void )
@ -45,4 +44,4 @@ void _cexit( void )
void _c_exit( void )
{
// reset interup vectors
}
}

View file

@ -10,16 +10,9 @@
#include <stdlib.h>
#include <windows.h>
#undef fullpath
char *fullpath( char *absPath, const char *relPath, size_t maxLength )
{
return _fullpath(absPath,relPath,maxLength );
}
char *_fullpath( char *absPath, const char *relPath, size_t maxLength )
{
char *lpFilePart;
if ( GetFullPathName(relPath,maxLength,absPath,&lpFilePart) == 0 )
return NULL;

View file

@ -1,33 +1,23 @@
#include <windows.h>
#include <stdlib.h>
//#include <types.h>
#include <ddk/ntddk.h>
//#include <ddk/ntddk.h>
void* malloc(size_t _size)
{
return(HeapAlloc(GetProcessHeap(),
0,
_size));
return(HeapAlloc(GetProcessHeap(),0,_size));
}
void free(void* _ptr)
{
HeapFree(GetProcessHeap(),
0,
_ptr);
HeapFree(GetProcessHeap(),0,_ptr);
}
void* calloc(size_t _nmemb, size_t _size)
{
return(HeapAlloc(GetProcessHeap(),
HEAP_ZERO_MEMORY,
_nmemb*_size));
return(HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY,_nmemb*_size));
}
void* realloc(void* _ptr, size_t _size)
{
return(HeapReAlloc(GetProcessHeap(),
0,
_ptr,
_size));
return(HeapReAlloc(GetProcessHeap(),0, _ptr, _size));
}

View file

@ -0,0 +1,17 @@
#include <stdlib.h>
int mblen (const char* mbs, size_t sizeString)
{
return 0;
}
size_t mbstowcs (wchar_t* wcaDest, const char* mbsConvert, size_t size)
{
return 0;
}
int mbtowc (wchar_t* wcDest, const char* mbConvert, size_t size)
{
return 0;
}

View file

@ -0,0 +1,20 @@
#include <windows.h>
#include <stdlib.h>
void _seterrormode(int nMode)
{
SetErrorMode(nMode);
return;
}
void _beep(unsigned nFreq, unsigned dur)
{
Beep(nFreq,nDur);
return;
}
void _sleep(unsigned long ulTime)
{
Sleep(ulTime);
return;
}

View file

@ -3,9 +3,8 @@
#include <string.h>
int
putenv(const char *val)
_putenv(const char *val)
{
char buffer[1024];
@ -27,4 +26,4 @@ putenv(const char *val)

View file

@ -2,7 +2,7 @@
/* Copyright (C) 1994 DJ Delorie, see COPYING.DJ for details */
#include <math.h>
#include <stdlib.h>
#include <wchar.h>
double
strtod(const char *s, char **sret)
@ -95,3 +95,97 @@ strtod(const char *s, char **sret)
*sret = (char *)s;
return r * sign;
}
double
wcstod(const wchar_t *s, wchar_t **sret)
{
long double r; /* result */
int e; /* exponent */
long double d; /* scale */
int sign; /* +- 1.0 */
int esign;
int i;
int flags=0;
r = 0.0;
sign = 1;
e = 0;
esign = 1;
while ((*s == ' ') || (*s == '\t'))
s++;
if (*s == '+')
s++;
else if (*s == '-')
{
sign = -1;
s++;
}
while ((*s >= '0') && (*s <= '9'))
{
flags |= 1;
r *= 10.0;
r += *s - '0';
s++;
}
if (*s == '.')
{
d = 0.1L;
s++;
while ((*s >= '0') && (*s <= '9'))
{
flags |= 2;
r += d * (*s - '0');
s++;
d *= 0.1L;
}
}
if (flags == 0)
{
if (sret)
*sret = (wchar_t *)s;
return 0;
}
if ((*s == 'e') || (*s == 'E'))
{
s++;
if (*s == '+')
s++;
else if (*s == '-')
{
s++;
esign = -1;
}
if ((*s < '0') || (*s > '9'))
{
if (sret)
*sret = (wchar_t *)s;
return r;
}
while ((*s >= '0') && (*s <= '9'))
{
e *= 10;
e += *s - '0';
s++;
}
}
if (esign < 0)
for (i = 1; i <= e; i++)
r *= 0.1L;
else
for (i = 1; i <= e; i++)
r *= 10.0;
if (sret)
*sret = (wchar_t *)s;
return r * sign;
}

View file

@ -3,6 +3,7 @@
#include <ctype.h>
#include <errno.h>
#include <stdlib.h>
#include <wchar.h>
long
@ -89,3 +90,90 @@ strtol(const char *nptr, char **endptr, int base)
*endptr = any ? (char *)s - 1 : (char *)nptr;
return acc;
}
long
wcstol(const wchar_t *nptr, wchar_t **endptr, int base)
{
const wchar_t *s = nptr;
unsigned long acc;
int c;
unsigned long cutoff;
int neg = 0, any, cutlim;
/*
* Skip white space and pick up leading +/- sign if any.
* If base is 0, allow 0x for hex and 0 for octal, else
* assume decimal; if base is already 16, allow 0x.
*/
do {
c = *s++;
} while (isspace(c));
if (c == '-')
{
neg = 1;
c = *s++;
}
else if (c == '+')
c = *s++;
if ((base == 0 || base == 16) &&
c == '0' && (*s == 'x' || *s == 'X'))
{
c = s[1];
s += 2;
base = 16;
}
if (base == 0)
base = c == '0' ? 8 : 10;
/*
* Compute the cutoff value between legal numbers and illegal
* numbers. That is the largest legal value, divided by the
* base. An input number that is greater than this value, if
* followed by a legal input character, is too big. One that
* is equal to this value may be valid or not; the limit
* between valid and invalid numbers is then based on the last
* digit. For instance, if the range for longs is
* [-2147483648..2147483647] and the input base is 10,
* cutoff will be set to 214748364 and cutlim to either
* 7 (neg==0) or 8 (neg==1), meaning that if we have accumulated
* a value > 214748364, or equal but the next digit is > 7 (or 8),
* the number is too big, and we will return a range error.
*
* Set any if any `digits' consumed; make it negative to indicate
* overflow.
*/
cutoff = neg ? -(unsigned long)LONG_MIN : LONG_MAX;
cutlim = cutoff % (unsigned long)base;
cutoff /= (unsigned long)base;
for (acc = 0, any = 0;; c = *s++)
{
if (isdigit(c))
c -= '0';
else if (isalpha(c))
c -= isupper(c) ? 'A' - 10 : 'a' - 10;
else
break;
if (c >= base)
break;
if (any < 0 || acc > cutoff || (acc == cutoff && c > cutlim))
any = -1;
else
{
any = 1;
acc *= base;
acc += c;
}
}
if (any < 0)
{
acc = neg ? LONG_MIN : LONG_MAX;
errno = ERANGE;
}
else if (neg)
acc = -acc;
if (endptr != 0)
*endptr = any ? (wchar_t *)s - 1 : (wchar_t *)nptr;
return acc;
}

View file

@ -3,7 +3,7 @@
#include <ctype.h>
#include <errno.h>
#include <stdlib.h>
#include <libc/unconst.h>
#include <wchar.h>
/*
* Convert a string to an unsigned long integer.
@ -70,6 +70,70 @@ strtoul(const char *nptr, char **endptr, int base)
else if (neg)
acc = -acc;
if (endptr != 0)
*endptr = any ? unconst(s, char *) - 1 : unconst(nptr, char *);
*endptr = any ? (char *)s - 1 : (char *)nptr;
return acc;
}
unsigned long
wcstoul(const wchar_t *nptr, wchar_t **endptr, int base)
{
const wchar_t *s = nptr;
unsigned long acc;
int c;
unsigned long cutoff;
int neg = 0, any, cutlim;
/*
* See strtol for comments as to the logic used.
*/
do {
c = *s++;
} while (isspace(c));
if (c == '-')
{
neg = 1;
c = *s++;
}
else if (c == '+')
c = *s++;
if ((base == 0 || base == 16) &&
c == '0' && (*s == 'x' || *s == 'X'))
{
c = s[1];
s += 2;
base = 16;
}
if (base == 0)
base = c == '0' ? 8 : 10;
cutoff = (unsigned long)ULONG_MAX / (unsigned long)base;
cutlim = (unsigned long)ULONG_MAX % (unsigned long)base;
for (acc = 0, any = 0;; c = *s++)
{
if (isdigit(c))
c -= '0';
else if (isalpha(c))
c -= isupper(c) ? 'A' - 10 : 'a' - 10;
else
break;
if (c >= base)
break;
if (any < 0 || acc > cutoff || (acc == cutoff && c > cutlim))
any = -1;
else {
any = 1;
acc *= base;
acc += c;
}
}
if (any < 0)
{
acc = ULONG_MAX;
errno = ERANGE;
}
else if (neg)
acc = -acc;
if (endptr != 0)
*endptr = any ? (wchar_t *)s - 1 : (wchar_t *)nptr;
return acc;
}

View file

@ -0,0 +1,17 @@
#include <stdlib.h>
size_t wcstombs (char* mbsDest, const wchar_t* wsConvert, size_t size)
{
return 0;
}
int wctomb (char* mbDest, wchar_t wc)
{
return 0;
}
int mblen (const char* mbs, size_t sizeString)
{
return 0;
}