winedbg: Rewrote the file handling to use SearchPath instead of home grown version.
This commit is contained in:
parent
d990c0d8e5
commit
6a0568a11a
|
@ -28,13 +28,6 @@
|
||||||
|
|
||||||
#include "debugger.h"
|
#include "debugger.h"
|
||||||
|
|
||||||
struct search_list
|
|
||||||
{
|
|
||||||
char* path;
|
|
||||||
struct search_list* next;
|
|
||||||
};
|
|
||||||
|
|
||||||
|
|
||||||
struct open_file_list
|
struct open_file_list
|
||||||
{
|
{
|
||||||
char* path;
|
char* path;
|
||||||
|
@ -47,45 +40,55 @@ struct open_file_list
|
||||||
|
|
||||||
static struct open_file_list* source_ofiles;
|
static struct open_file_list* source_ofiles;
|
||||||
|
|
||||||
static struct search_list* source_list_head;
|
static char* search_path; /* = NULL; */
|
||||||
static char source_current_file[PATH_MAX];
|
static char source_current_file[PATH_MAX];
|
||||||
static int source_start_line = -1;
|
static int source_start_line = -1;
|
||||||
static int source_end_line = -1;
|
static int source_end_line = -1;
|
||||||
|
|
||||||
void source_show_path(void)
|
void source_show_path(void)
|
||||||
{
|
{
|
||||||
struct search_list* sl;
|
const char* ptr;
|
||||||
|
const char* next;
|
||||||
|
|
||||||
dbg_printf("Search list:\n");
|
dbg_printf("Search list:\n");
|
||||||
for (sl = source_list_head; sl; sl = sl->next) dbg_printf("\t%s\n", sl->path);
|
for (ptr = search_path; ptr; ptr = next)
|
||||||
|
{
|
||||||
|
next = strchr(ptr, ';');
|
||||||
|
if (next)
|
||||||
|
dbg_printf("\t%.*s\n", next++ - ptr, ptr);
|
||||||
|
else
|
||||||
|
dbg_printf("\t%s\n", ptr);
|
||||||
|
}
|
||||||
dbg_printf("\n");
|
dbg_printf("\n");
|
||||||
}
|
}
|
||||||
|
|
||||||
void source_add_path(const char* path)
|
void source_add_path(const char* path)
|
||||||
{
|
{
|
||||||
struct search_list* sl;
|
char* new;
|
||||||
|
unsigned size;
|
||||||
|
|
||||||
if (!(sl = HeapAlloc(GetProcessHeap(), 0, sizeof(struct search_list))))
|
size = strlen(path) + 1;
|
||||||
return;
|
if (search_path)
|
||||||
|
{
|
||||||
sl->next = source_list_head;
|
unsigned pos = HeapSize(GetProcessHeap(), 0, search_path);
|
||||||
sl->path = strcpy(HeapAlloc(GetProcessHeap(), 0, strlen(path) + 1), path);
|
new = HeapReAlloc(GetProcessHeap(), 0, search_path, pos + size);
|
||||||
source_list_head = sl;
|
if (!new || !pos) return;
|
||||||
|
new[pos - 1] = ';';
|
||||||
|
strcpy(&new[pos], path);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
new = HeapAlloc(GetProcessHeap(), 0, size);
|
||||||
|
if (!new) return;
|
||||||
|
strcpy(new, path);
|
||||||
|
}
|
||||||
|
search_path = new;
|
||||||
}
|
}
|
||||||
|
|
||||||
void source_nuke_path(void)
|
void source_nuke_path(void)
|
||||||
{
|
{
|
||||||
struct search_list* sl;
|
HeapFree(GetProcessHeap(), 0, search_path);
|
||||||
struct search_list* nxt;
|
search_path = NULL;
|
||||||
|
|
||||||
for (sl = source_list_head; sl; sl = nxt)
|
|
||||||
{
|
|
||||||
nxt = sl->next;
|
|
||||||
HeapFree(GetProcessHeap(), 0, sl->path);
|
|
||||||
HeapFree(GetProcessHeap(), 0, sl);
|
|
||||||
}
|
|
||||||
|
|
||||||
source_list_head = NULL;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
static void* source_map_file(const char* name, HANDLE* hMap, unsigned* size)
|
static void* source_map_file(const char* name, HANDLE* hMap, unsigned* size)
|
||||||
|
@ -128,9 +131,7 @@ static int source_display(const char* sourcefile, int start, int end)
|
||||||
const char* basename = NULL;
|
const char* basename = NULL;
|
||||||
char* pnt;
|
char* pnt;
|
||||||
int rtn;
|
int rtn;
|
||||||
struct search_list* sl;
|
|
||||||
HANDLE hMap;
|
HANDLE hMap;
|
||||||
DWORD status;
|
|
||||||
char tmppath[PATH_MAX];
|
char tmppath[PATH_MAX];
|
||||||
|
|
||||||
/*
|
/*
|
||||||
|
@ -157,21 +158,20 @@ static int source_display(const char* sourcefile, int start, int end)
|
||||||
/*
|
/*
|
||||||
* Crapola. We need to try and open the file.
|
* Crapola. We need to try and open the file.
|
||||||
*/
|
*/
|
||||||
status = GetFileAttributes(sourcefile);
|
strcpy(tmppath, sourcefile);
|
||||||
if (status != INVALID_FILE_ATTRIBUTES)
|
if (GetFileAttributes(sourcefile) == INVALID_FILE_ATTRIBUTES &&
|
||||||
|
(!search_path || !SearchPathA(search_path, sourcefile, NULL, MAX_PATH, tmppath, NULL)))
|
||||||
{
|
{
|
||||||
strcpy(tmppath, sourcefile);
|
if (dbg_interactiveP)
|
||||||
}
|
|
||||||
else if ((status = GetFileAttributes(basename)) != INVALID_FILE_ATTRIBUTES)
|
|
||||||
{
|
|
||||||
strcpy(tmppath, basename);
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
for (sl = source_list_head; sl; sl = sl->next)
|
|
||||||
{
|
{
|
||||||
strcpy(tmppath, sl->path);
|
char zbuf[256];
|
||||||
if (tmppath[strlen(tmppath) - 1] != '/' && tmppath[strlen(tmppath) - 1] != '\\')
|
/*
|
||||||
|
* Still couldn't find it. Ask user for path to add.
|
||||||
|
*/
|
||||||
|
snprintf(zbuf, sizeof(zbuf), "Enter path to file '%s': ", sourcefile);
|
||||||
|
input_read_line(zbuf, tmppath, sizeof(tmppath));
|
||||||
|
|
||||||
|
if (tmppath[strlen(tmppath) - 1] != '/')
|
||||||
{
|
{
|
||||||
strcat(tmppath, "/");
|
strcat(tmppath, "/");
|
||||||
}
|
}
|
||||||
|
@ -179,55 +179,24 @@ static int source_display(const char* sourcefile, int start, int end)
|
||||||
* Now append the base file name.
|
* Now append the base file name.
|
||||||
*/
|
*/
|
||||||
strcat(tmppath, basename);
|
strcat(tmppath, basename);
|
||||||
|
|
||||||
status = GetFileAttributes(tmppath);
|
|
||||||
if (status != INVALID_FILE_ATTRIBUTES) break;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (sl == NULL)
|
if (GetFileAttributes(tmppath) == INVALID_FILE_ATTRIBUTES)
|
||||||
{
|
{
|
||||||
if (dbg_interactiveP)
|
/*
|
||||||
{
|
* OK, I guess the user doesn't really want to see it
|
||||||
char zbuf[256];
|
* after all.
|
||||||
/*
|
*/
|
||||||
* Still couldn't find it. Ask user for path to add.
|
ol = HeapAlloc(GetProcessHeap(), 0, sizeof(*ol));
|
||||||
*/
|
ol->path = strcpy(HeapAlloc(GetProcessHeap(), 0, strlen(sourcefile) + 1), sourcefile);
|
||||||
snprintf(zbuf, sizeof(zbuf), "Enter path to file '%s': ", sourcefile);
|
ol->real_path = NULL;
|
||||||
input_read_line(zbuf, tmppath, sizeof(tmppath));
|
ol->next = source_ofiles;
|
||||||
|
ol->nlines = 0;
|
||||||
if (tmppath[strlen(tmppath) - 1] != '/')
|
ol->linelist = NULL;
|
||||||
{
|
ol->size = 0;
|
||||||
strcat(tmppath, "/");
|
source_ofiles = ol;
|
||||||
}
|
dbg_printf("Unable to open file '%s'\n", tmppath);
|
||||||
/*
|
return FALSE;
|
||||||
* Now append the base file name.
|
|
||||||
*/
|
|
||||||
strcat(tmppath, basename);
|
|
||||||
|
|
||||||
status = GetFileAttributes(tmppath);
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
status = INVALID_FILE_ATTRIBUTES;
|
|
||||||
strcpy(tmppath, sourcefile);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (status == INVALID_FILE_ATTRIBUTES)
|
|
||||||
{
|
|
||||||
/*
|
|
||||||
* OK, I guess the user doesn't really want to see it
|
|
||||||
* after all.
|
|
||||||
*/
|
|
||||||
ol = HeapAlloc(GetProcessHeap(), 0, sizeof(*ol));
|
|
||||||
ol->path = strcpy(HeapAlloc(GetProcessHeap(), 0, strlen(sourcefile) + 1), sourcefile);
|
|
||||||
ol->real_path = NULL;
|
|
||||||
ol->next = source_ofiles;
|
|
||||||
ol->nlines = 0;
|
|
||||||
ol->linelist = NULL;
|
|
||||||
source_ofiles = ol;
|
|
||||||
dbg_printf("Unable to open file '%s'\n", tmppath);
|
|
||||||
return FALSE;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
/*
|
/*
|
||||||
|
|
Loading…
Reference in New Issue