wine/programs/winedbg debugger.h debug.l dbg.y

Alexandre Julliard julliard at wine.codeweavers.com
Thu Nov 17 05:04:27 CST 2005


ChangeSet ID:	21304
CVSROOT:	/opt/cvs-commit
Module name:	wine
Changes by:	julliard at winehq.org	2005/11/17 05:04:27

Modified files:
	programs/winedbg: debugger.h debug.l dbg.y 

Log message:
	Eric Pouech <eric.pouech at wanadoo.fr>
	Simplification of lex's input reading.

Patch: http://cvs.winehq.org/patch.py?id=21304

Old revision  New revision  Changes     Path
 1.31          1.32          +1 -1       wine/programs/winedbg/debugger.h
 1.16          1.17          +14 -11     wine/programs/winedbg/debug.l
 1.28          1.29          +25 -55     wine/programs/winedbg/dbg.y

Index: wine/programs/winedbg/debugger.h
diff -u -p wine/programs/winedbg/debugger.h:1.31 wine/programs/winedbg/debugger.h:1.32
--- wine/programs/winedbg/debugger.h:1.31	17 Nov 2005 11: 4:27 -0000
+++ wine/programs/winedbg/debugger.h	17 Nov 2005 11: 4:27 -0000
@@ -268,7 +268,7 @@ extern int              break_add_condit
 extern void             parser(const char*);
 extern void             parser_handle(HANDLE);
 extern int              input_read_line(const char* pfx, char* buffer, int size);
-extern int              input_fetch_entire_line(const char* pfx, char** line, size_t* alloc, BOOL check_nl);
+extern int              input_fetch_entire_line(const char* pfx, char** line);
 
   /* debug.l */
 extern void             lexeme_flush(void);
Index: wine/programs/winedbg/debug.l
diff -u -p wine/programs/winedbg/debug.l:1.16 wine/programs/winedbg/debug.l:1.17
--- wine/programs/winedbg/debug.l:1.16	17 Nov 2005 11: 4:27 -0000
+++ wine/programs/winedbg/debug.l	17 Nov 2005 11: 4:27 -0000
@@ -33,24 +33,27 @@ static int read_input(const char* pfx, c
 {
     size_t      len;
 static char*  last_line = NULL;
-static size_t last_line_size = 0;
 static size_t last_line_idx = 0;
 
-    /* first alloc of our current buffer */
-    if (!last_line)
-    {
-        last_line = HeapAlloc(GetProcessHeap(), 0, last_line_size = 2);
-        assert(last_line);
-        last_line[0] = '\n';
-        last_line[1] = '\0';
-    }
-
     /* try first to fetch the remaining of an existing line */
     if (last_line_idx == 0)
     {
+        char* tmp = NULL;
         /* no remaining chars to be read from last line, grab a brand new line up to '\n' */
         lexeme_flush();
-        input_fetch_entire_line(pfx, &last_line, &last_line_size, TRUE);
+        len = input_fetch_entire_line(pfx, &tmp);
+        /* FIXME: should have a pair of buffers, and switch between the two, instead of
+         * reallocating a new one for each line
+         */
+        if (len == 0 || (len == 1 && tmp[0] == '\n') || (len == 2 && tmp[0] == '\r' && tmp[1] == '\n'))
+        {
+            HeapFree(GetProcessHeap(), 0, tmp);
+        }
+        else
+        {
+            HeapFree(GetProcessHeap(), 0, last_line);
+            last_line = tmp;
+        }
     }
 
     len = min(strlen(last_line + last_line_idx), size - 1);
Index: wine/programs/winedbg/dbg.y
diff -u -p wine/programs/winedbg/dbg.y:1.28 wine/programs/winedbg/dbg.y:1.29
--- wine/programs/winedbg/dbg.y:1.28	17 Nov 2005 11: 4:27 -0000
+++ wine/programs/winedbg/dbg.y	17 Nov 2005 11: 4:27 -0000
@@ -428,70 +428,47 @@ static WINE_EXCEPTION_FILTER(wine_dbg_cm
     return EXCEPTION_EXECUTE_HANDLER;
 }
 
-#ifndef whitespace
-#define whitespace(c) (((c) == ' ') || ((c) == '\t'))
-#endif
-
-/* Strip whitespace from the start and end of STRING. */
-static void stripwhite(char *string)
-{
-    int         i, last;
-
-    for (i = 0; whitespace(string[i]); i++);
-    if (i) strcpy(string, string + i);
-
-    last = i = strlen(string) - 1;
-    if (string[last] == '\n') i--;
-
-    while (i > 0 && whitespace(string[i])) i--;
-    if (string[last] == '\n')
-        string[++i] = '\n';
-    string[++i] = '\0';
-}
-
 static HANDLE dbg_parser_input;
 static HANDLE dbg_parser_output;
 
-int      input_fetch_entire_line(const char* pfx, char** line, size_t* alloc, BOOL check_nl)
+int      input_fetch_entire_line(const char* pfx, char** line)
 {
-    char 	buf_line[256];
-    DWORD	nread, nwritten;
-    size_t      len;
+    char        ch;
+    DWORD	nread;
+    size_t      len, alloc;
     
     /* as of today, console handles can be file handles... so better use file APIs rather than
      * console's
      */
-    WriteFile(dbg_parser_output, pfx, strlen(pfx), &nwritten, NULL);
+    WriteFile(dbg_parser_output, pfx, strlen(pfx), &nread, NULL);
+
+    if (*line)
+    {
+        alloc = HeapSize(GetProcessHeap(), 0, *line);
+        assert(alloc);
+    }
+    else
+    {
+        *line = HeapAlloc(GetProcessHeap(), 0, alloc = 16);
+        assert(*line);
+    }
 
     len = 0;
     do
     {
-	if (!ReadFile(dbg_parser_input, buf_line, sizeof(buf_line) - 1, &nread, NULL) || nread == 0)
+        if (!ReadFile(dbg_parser_input, &ch, 1, &nread, NULL) || nread == 0)
             break;
-	buf_line[nread] = '\0';
-
-        if (check_nl && len == 0 && nread == 1 && buf_line[0] == '\n')
-            return 0;
-
-        /* store stuff at the end of last_line */
-        if (len + nread + 1 > *alloc)
+        if (len + 2 > alloc)
         {
-            while (len + nread + 1 > *alloc) *alloc *= 2;
-            *line = dbg_heap_realloc(*line, *alloc);
+            while (len + 2 > alloc) alloc *= 2;
+            *line = dbg_heap_realloc(*line, alloc);
         }
-        strcpy(*line + len, buf_line);
-        len += nread;
-    } while (nread == 0 || buf_line[nread - 1] != '\n');
-
-    if (!len)
-    {
-        *line = HeapReAlloc(GetProcessHeap(), 0, *line, *alloc = 1);
-        **line = '\0';
+        (*line)[len++] = ch;
     }
+    while (ch != '\n');
+    (*line)[len] = '\0';
 
-    /* Remove leading and trailing whitespace from the line */
-    stripwhite(*line);
-    return 1;
+    return len;
 }
 
 int input_read_line(const char* pfx, char* buf, int size)
@@ -499,14 +476,7 @@ int input_read_line(const char* pfx, cha
     char*       line = NULL;
     size_t      len = 0;
 
-    /* first alloc of our current buffer */
-    line = HeapAlloc(GetProcessHeap(), 0, len = 2);
-    assert(line);
-    line[0] = '\n';
-    line[1] = '\0';		      
-
-    input_fetch_entire_line(pfx, &line, &len, FALSE);
-    len = strlen(line);
+    len = input_fetch_entire_line(pfx, &line);
     /* remove trailing \n */
     if (len > 0 && line[len - 1] == '\n') len--;
     len = min(size - 1, len);



More information about the wine-cvs mailing list