Fixed some line reading functions.
This commit is contained in:
parent
1858d5309b
commit
4041c6b686
|
@ -36,7 +36,7 @@ static int DEBUG_FetchFromLine(const char* pfx, char* buf, int size);
|
|||
|
||||
#define YY_INPUT(buf,result,max_size) \
|
||||
if ( (result = DEBUG_FetchFromLine("Wine-dbg>", buf, max_size)) < 0 ) \
|
||||
YY_FATAL_ERROR( "ReadLine() in flex scanner failed" );
|
||||
YY_FATAL_ERROR( "FetchFromLine() in flex scanner failed" );
|
||||
|
||||
#define YY_NO_UNPUT
|
||||
|
||||
|
@ -227,7 +227,7 @@ static int DEBUG_FetchEntireLine(const char* pfx, char** line, size_t* allo
|
|||
do
|
||||
{
|
||||
if (!ReadFile(DEBUG_hParserInput, buf_line, sizeof(buf_line) - 1, &nread, NULL) || nread == 0)
|
||||
break;
|
||||
break;
|
||||
buf_line[nread] = '\0';
|
||||
|
||||
if (check_nl && len == 0 && nread == 1 && buf_line[0] == '\n')
|
||||
|
@ -246,9 +246,7 @@ static int DEBUG_FetchEntireLine(const char* pfx, char** line, size_t* allo
|
|||
{
|
||||
*line = HeapReAlloc(GetProcessHeap(), 0, *line, *alloc = 1);
|
||||
**line = '\0';
|
||||
strcpy(*line + len, buf_line);
|
||||
len += nread;
|
||||
} while (nread == 0 || buf_line[nread - 1] != '\n');
|
||||
}
|
||||
|
||||
/* Remove leading and trailing whitespace from the line */
|
||||
stripwhite(*line);
|
||||
|
@ -294,10 +292,14 @@ int DEBUG_ReadLine(const char* pfx, char* buf, int size)
|
|||
size_t len = 0;
|
||||
|
||||
DEBUG_FetchEntireLine(pfx, &line, &len, FALSE);
|
||||
len = min(size, len);
|
||||
memcpy(buf, line, len - 1);
|
||||
len = strlen(line);
|
||||
/* remove trailing \n */
|
||||
if (len > 0 && line[len - 1] == '\n') len--;
|
||||
len = min(size - 1, len);
|
||||
memcpy(buf, line, len);
|
||||
buf[len] = '\0';
|
||||
return len - 1;
|
||||
HeapFree(GetProcessHeap(), 0, line);
|
||||
return 1;
|
||||
}
|
||||
|
||||
static char** local_symbols /* = NULL */;
|
||||
|
|
|
@ -110,7 +110,7 @@ static void* DEBUG_MapFile(const char* name, HANDLE* hMap, unsigned* size)
|
|||
{
|
||||
HANDLE hFile;
|
||||
|
||||
hFile = CreateFile(name, GENERIC_READ, FILE_SHARE_READ, NULL,
|
||||
hFile = CreateFile(name, GENERIC_READ, FILE_SHARE_READ, NULL,
|
||||
OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, NULL);
|
||||
if (hFile == INVALID_HANDLE_VALUE) return (void*)-1;
|
||||
if (size != NULL && (*size = GetFileSize(hFile, NULL)) == -1) return (void*)-1;
|
||||
|
@ -152,13 +152,13 @@ DEBUG_DisplaySource(char * sourcefile, int start, int end)
|
|||
HANDLE hMap;
|
||||
DWORD status;
|
||||
char tmppath[PATH_MAX];
|
||||
|
||||
|
||||
/*
|
||||
* First see whether we have the file open already. If so, then
|
||||
* use that, otherwise we have to try and open it.
|
||||
*/
|
||||
ol = DEBUG_SearchOpenFile(sourcefile);
|
||||
|
||||
|
||||
if ( ol == NULL )
|
||||
{
|
||||
/*
|
||||
|
@ -171,10 +171,10 @@ DEBUG_DisplaySource(char * sourcefile, int start, int end)
|
|||
basename = sourcefile;
|
||||
else
|
||||
basename++;
|
||||
|
||||
|
||||
ol = DEBUG_SearchOpenFile(basename);
|
||||
}
|
||||
|
||||
|
||||
if ( ol == NULL )
|
||||
{
|
||||
/*
|
||||
|
@ -202,11 +202,11 @@ DEBUG_DisplaySource(char * sourcefile, int start, int end)
|
|||
* Now append the base file name.
|
||||
*/
|
||||
strcat(tmppath, basename);
|
||||
|
||||
|
||||
status = GetFileAttributes(tmppath);
|
||||
if ( status != -1 ) break;
|
||||
}
|
||||
|
||||
|
||||
if ( sl == NULL )
|
||||
{
|
||||
if (DEBUG_InteractiveP)
|
||||
|
@ -217,12 +217,7 @@ DEBUG_DisplaySource(char * sourcefile, int start, int end)
|
|||
*/
|
||||
sprintf(zbuf, "Enter path to file '%s': ", sourcefile);
|
||||
DEBUG_ReadLine(zbuf, tmppath, sizeof(tmppath));
|
||||
|
||||
if ( tmppath[strlen(tmppath)-1] == '\n' )
|
||||
{
|
||||
tmppath[strlen(tmppath)-1] = '\0';
|
||||
}
|
||||
|
||||
|
||||
if ( tmppath[strlen(tmppath)-1] != '/' )
|
||||
{
|
||||
strcat(tmppath, "/");
|
||||
|
@ -231,7 +226,7 @@ DEBUG_DisplaySource(char * sourcefile, int start, int end)
|
|||
* Now append the base file name.
|
||||
*/
|
||||
strcat(tmppath, basename);
|
||||
|
||||
|
||||
status = GetFileAttributes(tmppath);
|
||||
}
|
||||
else
|
||||
|
@ -239,7 +234,7 @@ DEBUG_DisplaySource(char * sourcefile, int start, int end)
|
|||
status = -1;
|
||||
strcpy(tmppath, sourcefile);
|
||||
}
|
||||
|
||||
|
||||
if ( status == -1 )
|
||||
{
|
||||
/*
|
||||
|
@ -269,7 +264,7 @@ DEBUG_DisplaySource(char * sourcefile, int start, int end)
|
|||
ol->linelist = NULL;
|
||||
ol->size = 0;
|
||||
ofiles = ol;
|
||||
|
||||
|
||||
addr = DEBUG_MapFile(tmppath, &hMap, &ol->size);
|
||||
if ( addr == (char *) -1 )
|
||||
{
|
||||
|
@ -287,10 +282,10 @@ DEBUG_DisplaySource(char * sourcefile, int start, int end)
|
|||
ol->nlines++;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
ol->nlines++;
|
||||
ol->linelist = (unsigned int*) DBG_alloc( ol->nlines * sizeof(unsigned int) );
|
||||
|
||||
|
||||
nlines = 0;
|
||||
pnt = addr;
|
||||
ol->linelist[nlines++] = 0;
|
||||
|
@ -302,7 +297,7 @@ DEBUG_DisplaySource(char * sourcefile, int start, int end)
|
|||
}
|
||||
}
|
||||
ol->linelist[nlines++] = pnt - addr;
|
||||
|
||||
|
||||
}
|
||||
else
|
||||
{
|
||||
|
@ -324,7 +319,7 @@ DEBUG_DisplaySource(char * sourcefile, int start, int end)
|
|||
{
|
||||
continue;
|
||||
}
|
||||
|
||||
|
||||
rtn = TRUE;
|
||||
memset(&buffer, 0, sizeof(buffer));
|
||||
if ( ol->linelist[i+1] != ol->linelist[i] )
|
||||
|
@ -334,7 +329,7 @@ DEBUG_DisplaySource(char * sourcefile, int start, int end)
|
|||
}
|
||||
DEBUG_Printf(DBG_CHN_MESG,"%d\t%s\n", i + 1, buffer);
|
||||
}
|
||||
|
||||
|
||||
DEBUG_UnmapFile(addr, hMap);
|
||||
return rtn;
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue