modifed strtok & wcstok in msvcrt so that crtdll can use it.
authorRoyce Mitchell III <royce3@ev1.net>
Wed, 16 Jul 2003 21:54:22 +0000 (21:54 +0000)
committerRoyce Mitchell III <royce3@ev1.net>
Wed, 16 Jul 2003 21:54:22 +0000 (21:54 +0000)
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

reactos/ChangeLog
reactos/lib/crtdll/makefile
reactos/lib/crtdll/string/lasttok.c [new file with mode: 0644]
reactos/lib/crtdll/wchar/wlasttok.c [new file with mode: 0644]
reactos/lib/msvcrt/Makefile
reactos/lib/msvcrt/stdio/vfscanf.c
reactos/lib/msvcrt/string/lasttok.c [new file with mode: 0644]
reactos/lib/msvcrt/string/strtok.c
reactos/lib/msvcrt/wstring/wcstok.c
reactos/lib/msvcrt/wstring/wlasttok.c [new file with mode: 0644]

index 115dd9e..f1d0b51 100644 (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
index d41905f..beef496 100644 (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 \
diff --git a/reactos/lib/crtdll/string/lasttok.c b/reactos/lib/crtdll/string/lasttok.c
new file mode 100644 (file)
index 0000000..144f283
--- /dev/null
@@ -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;
+}
diff --git a/reactos/lib/crtdll/wchar/wlasttok.c b/reactos/lib/crtdll/wchar/wlasttok.c
new file mode 100644 (file)
index 0000000..1365852
--- /dev/null
@@ -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;
+}
index 7c5cbbb..30918a6 100644 (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) \
index 8f9f13c..2d2cc54 100644 (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
diff --git a/reactos/lib/msvcrt/string/lasttok.c b/reactos/lib/msvcrt/string/lasttok.c
new file mode 100644 (file)
index 0000000..5b322e5
--- /dev/null
@@ -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);
+}
index bb9d6bd..c641784 100644 (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);
index 3e178f6..25f530e 100644 (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;
diff --git a/reactos/lib/msvcrt/wstring/wlasttok.c b/reactos/lib/msvcrt/wstring/wlasttok.c
new file mode 100644 (file)
index 0000000..41a93e4
--- /dev/null
@@ -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);
+}