From 08a01c4da8013de69aaa215b4f640c9f756da52a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?G=C3=A9=20van=20Geldorp?= Date: Fri, 17 Jan 2003 18:04:08 +0000 Subject: [PATCH] Correctly expand wildcards in other directories svn path=/trunk/; revision=4023 --- rosapps/cmd/misc.c | 45 ++++++++++++++++++++++++++++++++++++++++++--- 1 file changed, 42 insertions(+), 3 deletions(-) diff --git a/rosapps/cmd/misc.c b/rosapps/cmd/misc.c index f0889ec0dca..86434638552 100644 --- a/rosapps/cmd/misc.c +++ b/rosapps/cmd/misc.c @@ -122,7 +122,7 @@ BOOL CheckCtrlBreak (INT mode) } /* add new entry for new argument */ -static BOOL add_entry (LPINT ac, LPTSTR **arg, LPTSTR entry) +static BOOL add_entry (LPINT ac, LPTSTR **arg, LPCTSTR entry) { LPTSTR q; LPTSTR *oldarg; @@ -149,18 +149,52 @@ static BOOL add_entry (LPINT ac, LPTSTR **arg, LPTSTR entry) return TRUE; } -static BOOL expand (LPINT ac, LPTSTR **arg, LPTSTR pattern) +static BOOL expand (LPINT ac, LPTSTR **arg, LPCTSTR pattern) { HANDLE hFind; WIN32_FIND_DATA FindData; BOOL ok; + LPCTSTR pathend; + LPTSTR dirpart, fullname; + pathend = _tcsrchr (pattern, _T('\\')); + if (NULL != pathend) + { + dirpart = malloc((pathend - pattern + 2) * sizeof(TCHAR)); + if (NULL == dirpart) + { + return FALSE; + } + memcpy(dirpart, pattern, pathend - pattern + 1); + dirpart[pathend - pattern + 1] = '\0'; + } + else + { + dirpart = NULL; + } hFind = FindFirstFile (pattern, &FindData); if (INVALID_HANDLE_VALUE != hFind) { do { - ok = add_entry(ac, arg, FindData.cFileName); + if (NULL != dirpart) + { + fullname = malloc((_tcslen(dirpart) + _tcslen(FindData.cFileName) + 1) * sizeof(TCHAR)); + if (NULL == fullname) + { + ok = FALSE; + } + else + { + _tcscat (_tcscpy (fullname, dirpart), FindData.cFileName); + ok = add_entry(ac, arg, fullname); + free (fullname); + } + } + else + { + ok = add_entry(ac, arg, FindData.cFileName); + } } while (FindNextFile (hFind, &FindData) && ok); FindClose (hFind); } @@ -169,6 +203,11 @@ static BOOL expand (LPINT ac, LPTSTR **arg, LPTSTR pattern) ok = add_entry(ac, arg, pattern); } + if (NULL != dirpart) + { + free (dirpart); + } + return ok; }