modifed strtok & wcstok in msvcrt so that crtdll can use it.

new private support functions _lasttoken and _wlasttoken to support strtok and wcstok respectively.
fixed lib/msvcrt/stdio/vfscanf.c to remove unnecessary globals.

svn path=/trunk/; revision=5142
This commit is contained in:
Royce Mitchell III 2003-07-16 21:54:22 +00:00
parent a94bc96529
commit 1a9bda60e7
10 changed files with 108 additions and 31 deletions

View file

@ -1,3 +1,10 @@
2003-07-16 Royce Mitchell III <royce3@ev1.net>
* modifed strtok & wcstok in msvcrt so that crtdll can use it.
* new private support functions _lasttoken and _wlasttoken to support
strtok and wcstok respectively.
* fixed lib/msvcrt/stdio/vfscanf.c to remove unnecessary globals.
2003-07-16 Royce Mitchell III <royce3@ev1.net>
* fixed warnings at lib/msvcrt/stdio/fputs.c:79

View file

@ -1,4 +1,4 @@
# $Id: makefile,v 1.57 2003/07/15 19:27:24 royce Exp $
# $Id: makefile,v 1.58 2003/07/16 21:54:22 royce Exp $
PATH_TO_TOP = ../..
@ -353,7 +353,7 @@ STDIO_OBJECTS = \
$(PATH_TO_MSVCRT)/stdio/tmpnam.o \
$(PATH_TO_MSVCRT)/stdio/ungetc.o \
stdio/vfprintf.o \
stdio/vfscanf.o \
$(PATH_TO_MSVCRT)/stdio/vfscanf.o \
stdio/vfwprint.o \
$(PATH_TO_MSVCRT)/stdio/vprintf.o \
$(PATH_TO_MSVCRT)/stdio/vscanf.o \
@ -398,7 +398,8 @@ STDLIB_OBJECTS = \
$(PATH_TO_MSVCRT)/stdlib/wcstomb.o \
STRING_OBJECTS = \
string/strtok.o \
string/lasttok.o \
$(PATH_TO_MSVCRT)/string/strtok.o \
string/str_old.o \
string/strerror.o \
@ -440,7 +441,9 @@ TIME_OBJECTS = \
$(PATH_TO_MSVCRT)/time/strtime.o \
time/tz_vars.o \
WSTRING_OBJECTS =
WSTRING_OBJECTS = \
$(PATH_TO_MSVCRT)/wstring/wcstok.o \
wchar/wlasttok.o
# wchar/wcscoll.o \
# wchar/wcstod.o \

View file

@ -0,0 +1,12 @@
#include <msvcrt/string.h>
/*
* This is a CRTDLL internal function to return the lasttoken
* bit of data used by strtok. The reason for it's existence is
* so that CRTDLL can use MSVCRT's implementation of strtok.
*/
char** _lasttoken()
{
static char *lasttoken = NULL;
return &lasttoken;
}

View file

@ -0,0 +1,12 @@
#include <msvcrt/wchar.h>
/*
* This is a CRTDLL internal function to return the lasttoken
* bit of data used by wcstok. The reason for it's existence is
* so that CRTDLL can use MSVCRT's implementation of wcstok.
*/
wchar_t** _wlasttoken()
{
static wchar_t *wlasttoken = NULL;
return &wlasttoken;
}

View file

@ -1,4 +1,4 @@
# $Id: Makefile,v 1.37 2003/07/16 13:29:01 royce Exp $
# $Id: Makefile,v 1.38 2003/07/16 21:54:22 royce Exp $
PATH_TO_TOP = ../..
@ -400,6 +400,7 @@ STDLIB_OBJECTS = \
stdlib/wtoi64.o
STRING_OBJECTS = \
string/lasttok.o \
string/memicmp.o \
string/strcoll.o \
string/strdup.o \
@ -452,7 +453,8 @@ WSTRING_OBJECTS = \
wstring/wcsstr.o \
wstring/wcstok.o \
wstring/wcsupr.o \
wstring/wcsxfrm.o
wstring/wcsxfrm.o \
wstring/wlasttok.o
OBJECTS = \
$(CONIO_OBJECTS) \

View file

@ -103,25 +103,21 @@ unsigned long int __strtoul_internal (const char *__nptr, char **__endptr, int
# define flockfile(S) /* nothing */
# define funlockfile(S) /* nothing */
char *wp = NULL; /* Workspace. */
size_t wpmax = 0; /* Maximal size of workspace. */
size_t wpsize = 0; /* Currently used bytes in workspace. */
void ADDW(int Ch) \
{
if (wpsize == wpmax)
{
char *old = wp;
wpmax = UCHAR_MAX > 2 * wpmax ? UCHAR_MAX : 2 * wpmax;
wp = (char *) malloc (wpmax);
if (old != NULL) {
memcpy (wp, old, wpsize);
free(old);
}
}
wp[wpsize++] = (Ch);
}
# define ADDW(Ch) \
do{ \
if (wpsize == wpmax) \
{ \
char *old = wp; \
wpmax = UCHAR_MAX > 2 * wpmax ? UCHAR_MAX : 2 * wpmax; \
wp = (char *) malloc (wpmax); \
if (old != NULL) \
{ \
memcpy (wp, old, wpsize); \
free(old); \
} \
} \
wp[wpsize++] = (Ch); \
}while(0)
int __vfscanf (FILE *s, const char *format, va_list argptr)
@ -165,6 +161,9 @@ int __vfscanf (FILE *s, const char *format, va_list argptr)
available anymore. */
int skip_space = 0;
/* Workspace. */
char *wp = NULL; /* Workspace. */
size_t wpmax = 0; /* Maximal size of workspace. */
size_t wpsize = 0; /* Currently used bytes in workspace. */
char *tw; /* Temporary pointer. */
#ifdef __va_copy

View file

@ -0,0 +1,14 @@
#include <msvcrt/internal/tls.h>
/*
* This is an MSVCRT internal function to return the lasttoken
* bit of data used by strtok. The reason for it's existence is
* so that CRTDLL can use the strtok source code in the same
* file.
*/
char** _lasttoken()
{
PTHREADDATA ptd = GetThreadData();
_assert(ptd);
return &(ptd->lasttoken);
}

View file

@ -2,6 +2,8 @@
#include <msvcrt/string.h>
#include <msvcrt/internal/tls.h>
char** _lasttoken(); /* lasttok.c */
/*
* @implemented
*/
@ -10,9 +12,14 @@ char* strtok(char* s, const char* delim)
const char *spanp;
int c, sc;
char *tok;
#if 1
char ** lasttoken = _lasttoken();
#else
PTHREADDATA ThreadData = GetThreadData();
char ** lasttoken = &ThreadData->lasttoken;
#endif
if (s == NULL && (s = ThreadData->lasttoken) == NULL)
if (s == NULL && (s = *lasttoken) == NULL)
return (NULL);
/*
@ -26,7 +33,7 @@ char* strtok(char* s, const char* delim)
}
if (c == 0) { /* no non-delimiter characters */
ThreadData->lasttoken = NULL;
*lasttoken = NULL;
return (NULL);
}
tok = s - 1;
@ -44,7 +51,7 @@ char* strtok(char* s, const char* delim)
s = NULL;
else
s[-1] = 0;
ThreadData->lasttoken = s;
*lasttoken = s;
return (tok);
}
} while (sc != 0);

View file

@ -1,6 +1,8 @@
#include <msvcrt/string.h>
#include <msvcrt/internal/tls.h>
wchar_t** _wlasttoken(); /* wlasttok.c */
/*
* @implemented
*/
@ -9,9 +11,14 @@ wchar_t *wcstok(wchar_t *s, const wchar_t *ct)
const wchar_t *spanp;
int c, sc;
wchar_t *tok;
#if 1
wchar_t ** wlasttoken = _wlasttoken();
#else
PTHREADDATA ThreadData = GetThreadData();
wchar_t ** wlasttoken = &ThreadData->wlasttoken;
#endif
if (s == NULL && (s = ThreadData->wlasttoken) == NULL)
if (s == NULL && (s = *wlasttoken) == NULL)
return (NULL);
/*
@ -26,7 +33,7 @@ wchar_t *wcstok(wchar_t *s, const wchar_t *ct)
}
if (c == 0) { /* no non-ctiter characters */
ThreadData->wlasttoken = NULL;
*wlasttoken = NULL;
return (NULL);
}
tok = s - 2;
@ -45,7 +52,7 @@ wchar_t *wcstok(wchar_t *s, const wchar_t *ct)
s = NULL;
else
s[-1] = 0;
ThreadData->wlasttoken = s;
*wlasttoken = s;
return (tok);
}
spanp+=2;

View file

@ -0,0 +1,14 @@
#include <msvcrt/internal/tls.h>
/*
* This is an MSVCRT internal function to return the lasttoken
* bit of data used by wcstok. The reason for it's existence is
* so that CRTDLL can use the wcstok source code in the same
* file.
*/
wchar_t** _wlasttoken()
{
PTHREADDATA ptd = GetThreadData();
_assert(ptd);
return &(ptd->wlasttoken);
}