Commit in reactos on MAIN
bootdata/hivesys.inf+11.54 -> 1.55
subsys/system/cmd/misc.c+5-41.4 -> 1.5
                 /where.c+92-1701.2 -> 1.3
+98-174
3 modified files
Jens Collin <jens.collin@lakhei.com>
Add PATHEXT env var and use it to locate command

reactos/bootdata
hivesys.inf 1.54 -> 1.55
diff -u -r1.54 -r1.55
--- hivesys.inf	20 Jun 2004 12:18:08 -0000	1.54
+++ hivesys.inf	11 Jul 2004 16:13:42 -0000	1.55
@@ -103,6 +103,7 @@
 HKLM,"SYSTEM\CurrentControlSet\Control\Session Manager\Environment","windir",0x00020000,"%SystemRoot%"
 HKLM,"SYSTEM\CurrentControlSet\Control\Session Manager\Environment","TEMP",0x00020000,"%SystemDrive%\TEMP"
 HKLM,"SYSTEM\CurrentControlSet\Control\Session Manager\Environment","TMP",0x00020000,"%SystemDrive%\TEMP"
+HKLM,"SYSTEM\CurrentControlSet\Control\Session Manager\Environment","PATHEXT",0x00020000,".COM;.EXE;.BAT;.CMD"
 
 ; Known DLLs
 HKLM,"SYSTEM\CurrentControlSet\Control\Session Manager\KnownDlls","DllDirectory",0x00020000,"%SystemRoot%\system32"

reactos/subsys/system/cmd
misc.c 1.4 -> 1.5
diff -u -r1.4 -r1.5
--- misc.c	30 Apr 2004 16:52:42 -0000	1.4
+++ misc.c	11 Jul 2004 16:13:44 -0000	1.5
@@ -133,7 +133,7 @@
 		return FALSE;
 	}
 	_tcscpy (q, entry);
-		
+
 	oldarg = *arg;
 	*arg = realloc (oldarg, (*ac + 2) * sizeof (LPTSTR));
 	if (NULL == *arg)
@@ -359,7 +359,8 @@
 
 BOOL IsValidFileName (LPCTSTR pszPath)
 {
-	return (GetFileAttributes (pszPath) != 0xFFFFFFFF);
+	DWORD attr = GetFileAttributes (pszPath);
+	return (attr != 0xFFFFFFFF && (! (attr & FILE_ATTRIBUTE_DIRECTORY)) );
 }
 
 
@@ -513,7 +514,7 @@
 		ConInKey (&ir);
                 cKey = _totlower (ir.Event.KeyEvent.uChar.AsciiChar);
                 if (_tcschr (szKeys, cKey[0]) == NULL)
-                        cKey = 0;                        
+                        cKey = 0;
 
 
 	}
@@ -582,7 +583,7 @@
 		ConInKey (&ir);
                 cKey = _totlower (ir.Event.KeyEvent.uChar.AsciiChar);
                 if (_tcschr (szKeys, cKey[0]) == NULL)
-                        cKey = 0;                        
+                        cKey = 0;
 
 
 	}

reactos/subsys/system/cmd
where.c 1.2 -> 1.3
diff -u -r1.2 -r1.3
--- where.c	7 Aug 2003 09:27:42 -0000	1.2
+++ where.c	11 Jul 2004 16:13:44 -0000	1.3
@@ -67,6 +67,11 @@
  *
  *    20-Apr-1999 (Eric Kohl <ekohl@abo.rhein-zeitung.de>)
  *        Some minor changes and improvements.
+ *
+
+ *    10-Jul-2004 (Jens Collin <jens.collin@lakhei.com>)
+ *        Fixed searxhing for files with specific extensions in PATHEXT order..
+ *
  */
 
 #include "config.h"
@@ -82,29 +87,23 @@
 #define ENV_BUFFER_SIZE  1024
 
 
-static LPTSTR ext[]  = {_T(".bat"), _T(".cmd"), _T(".com"), _T(".exe")};
-static INT nExtCount = sizeof(ext) / sizeof(LPTSTR);
-
-
 /* searches for file using path info. */
 
 BOOL
-SearchForExecutable (LPCTSTR pFileName, LPTSTR pFullName)
+SearchForExecutableSingle (LPCTSTR pFileName, LPTSTR pFullName, LPTSTR pExtension)
 {
 	TCHAR  szPathBuffer[MAX_PATH];
 	LPTSTR pszBuffer = NULL;
 	DWORD  dwBuffer, len;
-	INT    n;
-	LPTSTR p,s,f;
-
-
-	/* initialize full name buffer */
+	LPTSTR s,f;
+	// initialize full name buffer
 	*pFullName = _T('\0');
 
 #ifdef _DEBUG
-	DebugPrintf (_T("SearchForExecutable: \'%s\'\n"), pFileName);
+	DebugPrintf (_T("SearchForExecutableSingle: \'%s\' with ext: \'%s\'\n"), pFileName, pExtension);
 #endif
 
+	// Check if valid directly on specified path
 	if (_tcschr (pFileName, _T('\\')) != NULL)
 	{
 		LPTSTR pFilePart;
@@ -120,47 +119,45 @@
 
 		if(pFilePart == 0)
 			return FALSE;
+		// Add extension and test file:
+		if (pExtension)
+			_tcscat(szPathBuffer, pExtension);
 
-
-                if (_tcschr (pFilePart, _T('.')) != NULL)
-                {
-#ifdef _DEBUG
-                        DebugPrintf (_T("Filename extension!\n"));
-#endif
-                        _tcscpy (pFullName, szPathBuffer);
-                        return TRUE;
-
-                }
-                else
-                {
+		if (IsValidFileName (szPathBuffer))
+		{
 #ifdef _DEBUG
-                        DebugPrintf (_T("No filename extension!\n"));
+			DebugPrintf (_T("Found: \'%s\'\n"), szPathBuffer);
 #endif
+			_tcscpy (pFullName, szPathBuffer);
+			return TRUE;
+		}
+		return FALSE;
+	}
 
-                        p = szPathBuffer + _tcslen (szPathBuffer);
+	// search in current directory
+	len = GetCurrentDirectory (MAX_PATH, szPathBuffer);
+	if (szPathBuffer[len - 1] != _T('\\'))
+	{
+		szPathBuffer[len] = _T('\\');
+		szPathBuffer[len + 1] = _T('\0');
+	}
+	_tcscat (szPathBuffer, pFileName);
 
-                        for (n = 0; n < nExtCount; n++)
-                        {
-                                _tcscpy (p, ext[n]);
+	if (pExtension)
+		_tcscat (szPathBuffer, pExtension);
 
+	if (IsValidFileName (szPathBuffer))
+	{
 #ifdef _DEBUG
-                                DebugPrintf (_T("Testing: \'%s\'\n"), szPathBuffer);
+		DebugPrintf (_T("Found: \'%s\'\n"), szPathBuffer);
 #endif
+		_tcscpy (pFullName, szPathBuffer);
+		return TRUE;
+	}
 
-                                if (IsValidFileName (szPathBuffer))
-                                {
-#ifdef _DEBUG
-                                        DebugPrintf (_T("Found: \'%s\'\n"), szPathBuffer);
-#endif
-                                        _tcscpy (pFullName, szPathBuffer);
-                                        return TRUE;
-                                }
-                        }
-                        return FALSE;
-                }
-        }
 
-	/* load environment varable PATH into buffer */
+
+	// load environment varable PATH into buffer
 	pszBuffer = (LPTSTR)malloc (ENV_BUFFER_SIZE * sizeof(TCHAR));
 	dwBuffer = GetEnvironmentVariable (_T("PATH"), pszBuffer, ENV_BUFFER_SIZE);
 	if (dwBuffer > ENV_BUFFER_SIZE)
@@ -169,102 +166,26 @@
 		GetEnvironmentVariable (_T("PATH"), pszBuffer, dwBuffer * sizeof (TCHAR));
 	}
 
-	if (!(p = _tcsrchr (pFileName, _T('.'))) ||
-		_tcschr (p + 1, _T('\\')))
-	{
-		/* There is no extension ==> test all the extensions. */
-#ifdef _DEBUG
-		DebugPrintf (_T("No filename extension!\n"));
-#endif
 
-		/* search in current directory */
-		len = GetCurrentDirectory (MAX_PATH, szPathBuffer);
-		if (szPathBuffer[len - 1] != _T('\\'))
-		{
-			szPathBuffer[len] = _T('\\');
-			szPathBuffer[len + 1] = _T('\0');
-		}
-		_tcscat (szPathBuffer, pFileName);
-
-		p = szPathBuffer + _tcslen (szPathBuffer);
+	// search in PATH
+	s = pszBuffer;
+	while (s && *s)
+	{
+		f = _tcschr (s, _T(';'));
 
-		for (n = 0; n < nExtCount; n++)
+		if (f)
 		{
-			_tcscpy (p, ext[n]);
-
-#ifdef _DEBUG
-			DebugPrintf (_T("Testing: \'%s\'\n"), szPathBuffer);
-#endif
-
-			if (IsValidFileName (szPathBuffer))
-			{
-#ifdef _DEBUG
-				DebugPrintf (_T("Found: \'%s\'\n"), szPathBuffer);
-#endif
-				free (pszBuffer);
-				_tcscpy (pFullName, szPathBuffer);
-				return TRUE;
-			}
+			_tcsncpy (szPathBuffer, s, (size_t)(f-s));
+			szPathBuffer[f-s] = _T('\0');
+			s = f + 1;
 		}
-
-		/* search in PATH */
-		s = pszBuffer;
-		while (s && *s)
+		else
 		{
-			f = _tcschr (s, _T(';'));
-
-			if (f)
-			{
-				_tcsncpy (szPathBuffer, s, (size_t)(f-s));
-				szPathBuffer[f-s] = _T('\0');
-				s = f + 1;
-			}
-			else
-			{
-				_tcscpy (szPathBuffer, s);
-				s = NULL;
-			}
-
-			len = _tcslen(szPathBuffer);
-			if (szPathBuffer[len - 1] != _T('\\'))
-			{
-				szPathBuffer[len] = _T('\\');
-				szPathBuffer[len + 1] = _T('\0');
-			}
-			_tcscat (szPathBuffer, pFileName);
-
-			p = szPathBuffer + _tcslen (szPathBuffer);
-
-			for (n = 0; n < nExtCount; n++)
-			{
-				_tcscpy (p, ext[n]);
-
-#ifdef _DEBUG
-				DebugPrintf (_T("Testing: \'%s\'\n"), szPathBuffer);
-#endif
-
-				if (IsValidFileName (szPathBuffer))
-				{
-#ifdef _DEBUG
-					DebugPrintf (_T("Found: \'%s\'\n"), szPathBuffer);
-#endif
-					free (pszBuffer);
-					_tcscpy (pFullName, szPathBuffer);
-					return TRUE;
-				}
-			}
+			_tcscpy (szPathBuffer, s);
+			s = NULL;
 		}
-	}
-	else
-	{
-		/* There is an extension and it is in the last path component, */
-		/* so don't test all the extensions. */
-#ifdef _DEBUG
-		DebugPrintf (_T("Filename extension!\n"));
-#endif
 
-		/* search in current directory */
-		len = GetCurrentDirectory (MAX_PATH, szPathBuffer);
+		len = _tcslen(szPathBuffer);
 		if (szPathBuffer[len - 1] != _T('\\'))
 		{
 			szPathBuffer[len] = _T('\\');
@@ -272,9 +193,9 @@
 		}
 		_tcscat (szPathBuffer, pFileName);
 
-#ifdef _DEBUG
-		DebugPrintf (_T("Testing: \'%s\'\n"), szPathBuffer);
-#endif
+		if (pExtension)
+			_tcscat (szPathBuffer, pExtension);
+
 		if (IsValidFileName (szPathBuffer))
 		{
 #ifdef _DEBUG
@@ -284,50 +205,51 @@
 			_tcscpy (pFullName, szPathBuffer);
 			return TRUE;
 		}
+	}
+	free (pszBuffer);
+	return FALSE;
+}
 
 
-		/* search in PATH */
-		s = pszBuffer;
-		while (s && *s)
-		{
-			f = _tcschr (s, _T(';'));
-
-			if (f)
-			{
-				_tcsncpy (szPathBuffer, s, (size_t)(f-s));
-				szPathBuffer[f-s] = _T('\0');
-				s = f + 1;
-			}
-			else
-			{
-				_tcscpy (szPathBuffer, s);
-				s = NULL;
-			}
-
-			len = _tcslen(szPathBuffer);
-			if (szPathBuffer[len - 1] != _T('\\'))
-			{
-				szPathBuffer[len] = _T('\\');
-				szPathBuffer[len + 1] = _T('\0');
-			}
-			_tcscat (szPathBuffer, pFileName);
-
+BOOL
+SearchForExecutable (LPCTSTR pFileName, LPTSTR pFullName)
+{
+	LPTSTR pszBuffer = NULL;
+	LPTSTR pCh;
+	DWORD  dwBuffer;
 #ifdef _DEBUG
-			DebugPrintf (_T("Testing: \'%s\'\n"), szPathBuffer);
+	DebugPrintf (_T("SearchForExecutable: \'%s\'\n"), pFileName);
 #endif
-			if (IsValidFileName (szPathBuffer))
-			{
+	// check the filename directly
+	if (SearchForExecutableSingle(pFileName, pFullName, NULL))
+	{
+		return TRUE;
+	}
+
+	// load environment varable PATHEXT
+	pszBuffer = (LPTSTR)malloc (ENV_BUFFER_SIZE * sizeof(TCHAR));
+	dwBuffer = GetEnvironmentVariable (_T("PATHEXT"), pszBuffer, ENV_BUFFER_SIZE);
+	if (dwBuffer > ENV_BUFFER_SIZE)
+	{
+		pszBuffer = (LPTSTR)realloc (pszBuffer, dwBuffer * sizeof (TCHAR));
+		GetEnvironmentVariable (_T("PATHEXT"), pszBuffer, dwBuffer * sizeof (TCHAR));
+	}
+
 #ifdef _DEBUG
-				DebugPrintf (_T("Found: \'%s\'\n"), szPathBuffer);
+	DebugPrintf (_T("SearchForExecutable(): Loaded PATHEXT: %s\n"), pszBuffer);
 #endif
-				free (pszBuffer);
-				_tcscpy (pFullName, szPathBuffer);
-				return TRUE;
-			}
+
+	pCh = _tcstok(pszBuffer, ";");
+	while (pCh)
+	{
+		if (SearchForExecutableSingle(pFileName, pFullName, pCh))
+		{
+			free(pszBuffer);
+			return TRUE;
 		}
+		pCh = _tcstok(NULL, ";");
 	}
 
-	free (pszBuffer);
-
+	free(pszBuffer);
 	return FALSE;
 }
CVSspam 0.2.8