[ros-diffs] [cwittich] 32093: rewrote alias handling in cmd for doskey compatibility implemented AddConsoleAliasA, GetConsoleAliasesLengthA, GetConsoleAliasesLengthW halfplemented: AddConsoleAliasW, GetConsoleAliasW, GetConsoleAliasesW

cwittich at svn.reactos.org cwittich at svn.reactos.org
Sat Feb 2 22:06:54 CET 2008


Author: cwittich
Date: Sun Feb  3 00:06:53 2008
New Revision: 32093

URL: http://svn.reactos.org/svn/reactos?rev=32093&view=rev
Log:
rewrote alias handling in cmd for doskey compatibility
implemented AddConsoleAliasA, GetConsoleAliasesLengthA, GetConsoleAliasesLengthW
halfplemented: AddConsoleAliasW, GetConsoleAliasW, GetConsoleAliasesW

Modified:
    trunk/reactos/base/shell/cmd/alias.c
    trunk/reactos/base/shell/cmd/cmd.c
    trunk/reactos/base/shell/cmd/cmd.h
    trunk/reactos/dll/win32/kernel32/misc/console.c
    trunk/reactos/include/psdk/wincon.h

Modified: trunk/reactos/base/shell/cmd/alias.c
URL: http://svn.reactos.org/svn/reactos/trunk/reactos/base/shell/cmd/alias.c?rev=32093&r1=32092&r2=32093&view=diff
==============================================================================
--- trunk/reactos/base/shell/cmd/alias.c (original)
+++ trunk/reactos/base/shell/cmd/alias.c Sun Feb  3 00:06:53 2008
@@ -27,26 +27,15 @@
  *
  *    02-Apr-2005 (Magnus Olsen) <magnus at greatlord.com>)
  *        Remove all hardcode string to En.rc
- */
+ *
+ *    02-Feb-2008 (Christoph von Wittich) <christoph_vw at reactos.org>)
+ *        rewrote alias handling for doskey compat
+  */
 
 
 #include <precomp.h>
 
 #ifdef FEATURE_ALIASES
-
-typedef struct tagALIAS
-{
-	struct tagALIAS *next;
-	LPTSTR lpName;
-	LPTSTR lpSubst;
-	DWORD  dwUsed;
-} ALIAS, *LPALIAS;
-
-
-static LPALIAS lpFirst = NULL;
-static LPALIAS lpLast = NULL;
-static DWORD   dwUsed = 0;
-
 
 /* module internal functions */
 /* strlwr only for first word in string */
@@ -61,245 +50,117 @@
 	}
 }
 
-
 static VOID
 PrintAlias (VOID)
 {
-	LPALIAS ptr = lpFirst;
-	while (ptr)
-	{
-		ConOutPrintf (_T("%s=%s\n"), ptr->lpName, ptr->lpSubst);
-		ptr = ptr->next;
-	}
-}
-
-
-static VOID
-DeleteAlias (LPTSTR pszName)
-{
-	LPALIAS ptr = lpFirst;
-	LPALIAS prev = NULL;
-
-	while (ptr)
-	{
-		if (!_tcsicmp (ptr->lpName, pszName))
+	LPTSTR Aliases;
+	LPTSTR ptr;
+	DWORD len;
+
+	len = GetConsoleAliasesLength(_T("cmd.exe"));
+	if (len <= 0)
+		return;
+
+	/* allocate memory for an extra \0 char to make parsing easier */
+	ptr = cmd_alloc(len + sizeof(TCHAR));
+	if (!ptr)
+		return;
+
+	Aliases = ptr;
+
+	ZeroMemory(Aliases, len + sizeof(TCHAR));
+
+	if (GetConsoleAliases(Aliases, len, _T("cmd.exe")) != 0)
+	{
+		while (*Aliases != '\0')
 		{
-			if (prev)
-				prev->next = ptr->next;
-			else
-				lpFirst = ptr->next;
-			cmd_free (ptr->lpName);
-			cmd_free (ptr->lpSubst);
-			cmd_free (ptr);
-			return;
+			ConOutPrintf(_T("%s\n"), Aliases);
+			Aliases = Aliases + lstrlen(Aliases);
+			Aliases++;
 		}
-		prev = ptr;
-		ptr = ptr->next;
-	}
-}
-
-
-static VOID
-AddAlias (LPTSTR name, LPTSTR subst)
-{
-	LPALIAS ptr = lpFirst;
-	LPALIAS prev, entry;
-	LPTSTR s;
-
-	while (ptr)
-	{
-		if (!_tcsicmp (ptr->lpName, name))
-		{
-			s = (LPTSTR)cmd_alloc ((_tcslen (subst) + 1)*sizeof(TCHAR));
-			if (!s)
-			{
-				error_out_of_memory ();
-				return;
-			}
-
-			cmd_free (ptr->lpSubst);
-			ptr->lpSubst = s;
-			_tcscpy (ptr->lpSubst, subst);
-			return;
-		}
-		ptr = ptr->next;
-	}
-
-	ptr = (LPALIAS)cmd_alloc (sizeof (ALIAS));
-	if (!ptr)
-		return;
-
-	ptr->next = 0;
-
-	ptr->lpName = (LPTSTR)cmd_alloc ((_tcslen (name) + 1)*sizeof(TCHAR));
-	if (!ptr->lpName)
-	{
-		error_out_of_memory ();
-		cmd_free (ptr);
-		return;
-	}
-	_tcscpy (ptr->lpName, name);
-
-	ptr->lpSubst = (LPTSTR)cmd_alloc ((_tcslen (subst) + 1)*sizeof(TCHAR));
-	if (!ptr->lpSubst)
-	{
-		error_out_of_memory ();
-		cmd_free (ptr->lpName);
-		cmd_free (ptr);
-		return;
-	}
-	_tcscpy (ptr->lpSubst, subst);
-
-	/* it's necessary for recursive substitution */
-	partstrlwr (ptr->lpSubst);
-
-	ptr->dwUsed = 0;
-
-	/* Alias table must be sorted!
-	 * Here a little example:
-	 *   command line = "ls -c"
-	 * If the entries are
-	 *   ls=dir
-	 *   ls -c=ls /w
-	 * command line will be expanded to "dir -c" which is not correct.
-	 * If the entries are sortet as
-	 *   ls -c=ls /w
-	 *   ls=dir
-	 * it will be expanded to "dir /w" which is a valid DOS command.
-	 */
-	entry = lpFirst;
-	prev = 0;
-	while (entry)
-	{
-		if (_tcsicmp (ptr->lpName, entry->lpName) > 0)
-		{
-			if (prev)
-			{
-				prev->next = ptr;
-				ptr->next = entry;
-			}
-			else
-			{
-				ptr->next = entry;
-				lpFirst = ptr;
-			}
-			return;
-		}
-		prev = entry;
-		entry = entry->next;
-	}
-
-	/* The new entry is the smallest (or the first) and must be
-	 * added to the end of the list.
-	 */
-	if (!lpFirst)
-		lpFirst = ptr;
-	else
-		lpLast->next = ptr;
-	lpLast = ptr;
-
-	return;
-}
-
-
-VOID InitializeAlias (VOID)
-{
-	lpFirst = NULL;
-	lpLast = NULL;
-	dwUsed = 0;
-}
-
-VOID DestroyAlias (VOID)
-{
-        if (lpFirst == NULL)
-                return;
-
-        while (lpFirst->next != NULL)
-        {
-                lpLast = lpFirst;
-                lpFirst = lpLast->next;
-
-                cmd_free (lpLast->lpName);
-                cmd_free (lpLast->lpSubst);
-                cmd_free (lpLast);
-        }
-
-        cmd_free (lpFirst->lpName);
-        cmd_free (lpFirst->lpSubst);
-        cmd_free (lpFirst);
-
-        lpFirst = NULL;
-        lpLast = NULL;
-        dwUsed = 0;
+	}
+	cmd_free(ptr);
 }
 
 /* specified routines */
 VOID ExpandAlias (LPTSTR cmd, INT maxlen)
 {
-	unsigned n = 0,
-		m,
-		i,
-		len;
-	short d = 1;
-	LPALIAS ptr = lpFirst;
-
-	dwUsed++;
-	if (dwUsed == 0)
-	{
-		while (ptr)
-			ptr->dwUsed = 0;
-		ptr = lpFirst;
-		dwUsed = 1;
-	}
-
-	/* skipping white spaces */
-	while (_istspace (cmd[n]))
-		n++;
-
-	partstrlwr (&cmd[n]);
-
-	if (!_tcsncmp (&cmd[n], _T("NOALIAS"), 7) &&
-	    (_istspace (cmd[n + 7]) || cmd[n + 7] == _T('\0')))
-	{
-		memmove (cmd, &cmd[n + 7], (_tcslen (&cmd[n + 7]) + 1) * sizeof (TCHAR));
-		return;
-	}
-
-	/* substitution loop */
-	while (d)
-	{
-		d = 0;
-		while (ptr)
+	LPTSTR buffer;
+	TCHAR* position;
+	LPTSTR Token;
+	LPTSTR tmp;
+	LPTSTR ip, cp;
+	BOOL   bModeSetA = FALSE;
+
+	tmp = cmd_alloc(maxlen);
+	if (!tmp)
+		return;
+	_tcscpy(tmp, cmd);
+
+	Token = _tcstok(tmp, _T(" ")); /* first part is the macro name */
+	if (!Token)
+	{
+		cmd_free(tmp);
+		return;
+	}
+
+	buffer = cmd_alloc(maxlen);
+	if (!buffer)
+	{
+		cmd_free(tmp);
+		return;
+	}
+	
+	if (GetConsoleAlias(Token, buffer, maxlen, _T("cmd.exe")) == 0)
+	{
+		cmd_free(tmp);
+		cmd_free(buffer);
+		return;
+	}
+
+	Token = _tcstok (NULL, _T(" "));
+
+	ZeroMemory(cmd, maxlen);
+	position = _tcsstr(buffer, _T("$*"));
+	if (position)
+	{
+		_tcsncpy(cmd, buffer, (INT) (position - buffer) - 1);
+		if (Token)
 		{
-			len = _tcslen (ptr->lpName);
-			if (!_tcsncmp (&cmd[n], ptr->lpName, len) &&
-			    (_istspace (cmd[n + len]) || cmd[n + len] == _T('\0')) &&
-				ptr->dwUsed != dwUsed)
+			_tcscat(cmd, _T(" "));
+			_tcscat(cmd, Token);
+		}
+	}
+	else
+	{
+		_tcscpy(cmd, buffer);
+	}
+
+	ip = cp = cmd;
+
+	while (*ip)
+	{
+		if ( (*ip == _T('%')) || (*ip == _T('!')) )
+		{
+			UINT envNameLen;
+			LPCTSTR envVal = GetParsedEnvVar ( ip, &envNameLen, bModeSetA );
+			if ( envVal )
 			{
-				m = _tcslen (ptr->lpSubst);
-				if ((int)(_tcslen (cmd) - len + m - n) > maxlen)
-				{
-					ConErrResPuts(STRING_ALIAS_ERROR);
-
-					/* the parser won't cause any problems with an empty line */
-					cmd[0] = _T('\0');
-				}
-				else
-				{
-					memmove (&cmd[m], &cmd[n + len], (_tcslen(&cmd[n + len]) + 1) * sizeof (TCHAR));
-					for (i = 0; i < m; i++)
-						cmd[i] = ptr->lpSubst[i];
-					ptr->dwUsed = dwUsed;
-					/* whitespaces are removed! */
-					n = 0;
-					d = 1;
-				}
+				ip += envNameLen;
+				cp = _stpcpy ( cp, envVal );
 			}
-			ptr = ptr->next;
 		}
-	}
-}
-
+
+		if (*ip != _T('\0') && (_istcntrl (*ip)))
+			*ip = _T(' ');
+		*cp++ = *ip++;
+	}
+	*cp = _T('\0');
+
+	cmd_free(buffer);
+	cmd_free(tmp);
+
+}
 
 INT CommandAlias (LPTSTR cmd, LPTSTR param)
 {
@@ -334,9 +195,9 @@
 	partstrlwr (param);
 
 	if (ptr[0] == _T('\0'))
-		DeleteAlias (param);
+		AddConsoleAlias(param, NULL, _T("cmd.exe"));
 	else
-		AddAlias (param, ptr);
+		AddConsoleAlias(param, ptr, _T("cmd.exe"));
 
 	return 0;
 }

Modified: trunk/reactos/base/shell/cmd/cmd.c
URL: http://svn.reactos.org/svn/reactos/trunk/reactos/base/shell/cmd/cmd.c?rev=32093&r1=32092&r2=32093&view=diff
==============================================================================
--- trunk/reactos/base/shell/cmd/cmd.c (original)
+++ trunk/reactos/base/shell/cmd/cmd.c Sun Feb  3 00:06:53 2008
@@ -789,7 +789,6 @@
 		nRedirFlags |= ERROR_APPEND;
 		_tcscpy(err, bc->Err);
 	}
-
 
 	/* Set up the initial conditions ... */
 	/* preserve STDIN, STDOUT and STDERR handles */
@@ -1774,10 +1773,6 @@
 	InitLastPath ();
 #endif
 
-#ifdef FATURE_ALIASES
-	InitializeAlias ();
-#endif
-
 	if (argc >= 2)
 	{
 		for (i = 1; i < argc; i++)
@@ -1898,10 +1893,6 @@
 		ParseCommandLine (_T("\\cmdexit.bat"));
 	}
 
-#ifdef FEATURE_ALIASES
-	DestroyAlias ();
-#endif
-
 #ifdef FEATURE_DIECTORY_STACK
 	/* destroy directory stack */
 	DestroyDirectoryStack ();

Modified: trunk/reactos/base/shell/cmd/cmd.h
URL: http://svn.reactos.org/svn/reactos/trunk/reactos/base/shell/cmd/cmd.h?rev=32093&r1=32092&r2=32093&view=diff
==============================================================================
--- trunk/reactos/base/shell/cmd/cmd.h (original)
+++ trunk/reactos/base/shell/cmd/cmd.h Sun Feb  3 00:06:53 2008
@@ -67,11 +67,8 @@
 
 
 /* Prototypes for ALIAS.C */
-VOID InitializeAlias (VOID);
-VOID DestroyAlias (VOID);
 VOID ExpandAlias (LPTSTR, INT);
 INT CommandAlias (LPTSTR, LPTSTR);
-
 
 /* Prototypes for ATTRIB.C */
 INT CommandAttrib (LPTSTR, LPTSTR);
@@ -130,6 +127,8 @@
 VOID PrintCommandList (VOID);
 VOID PrintCommandListDetail (VOID);
 
+
+LPCTSTR GetParsedEnvVar ( LPCTSTR varName, UINT* varNameLen, BOOL ModeSetA );
 
 /* Prototypes for COLOR.C */
 VOID SetScreenColor(WORD wArgColor, BOOL bFill);

Modified: trunk/reactos/dll/win32/kernel32/misc/console.c
URL: http://svn.reactos.org/svn/reactos/trunk/reactos/dll/win32/kernel32/misc/console.c?rev=32093&r1=32092&r2=32093&view=diff
==============================================================================
--- trunk/reactos/dll/win32/kernel32/misc/console.c (original)
+++ trunk/reactos/dll/win32/kernel32/misc/console.c Sun Feb  3 00:06:53 2008
@@ -19,11 +19,22 @@
 #define NDEBUG
 #include <debug.h>
 
+typedef struct tagALIAS
+{
+	struct tagALIAS *next;
+	LPWSTR lpName;
+	LPWSTR lpSubst;
+	DWORD  dwUsed;
+} ALIAS, *LPALIAS;
+
+static LPALIAS lpFirst = NULL;
+static LPALIAS lpLast = NULL;
+
 extern BOOL WINAPI DefaultConsoleCtrlHandler(DWORD Event);
 extern __declspec(noreturn) VOID CALLBACK ConsoleControlDispatcher(DWORD CodeAndFlag);
 extern RTL_CRITICAL_SECTION ConsoleLock;
 extern BOOL WINAPI IsDebuggerPresent(VOID);
-
+static VOID partstrlwr (LPWSTR str);
 
 /* GLOBALS *******************************************************************/
 
@@ -32,6 +43,19 @@
 static PHANDLER_ROUTINE* CtrlHandlers = NULL;
 static ULONG NrCtrlHandlers = 0;
 static WCHAR InputExeName[MAX_PATH + 1] = L"";
+
+/* module internal functions */
+/* strlwr only for first word in string */
+static VOID
+partstrlwr (LPWSTR str)
+{
+	LPWSTR c = str;
+	while (*c && !iswspace (*c) && *c != L'=')
+	{
+		*c = towlower (*c);
+		c++;
+	}
+}
 
 /* Default Console Control Handler *******************************************/
 
@@ -141,16 +165,36 @@
 /* FUNCTIONS *****************************************************************/
 
 /*
- * @unimplemented
+ * @implemented
  */
 BOOL STDCALL
-AddConsoleAliasA (LPSTR Source,
-		  LPSTR Target,
-		  LPSTR ExeName)
-{
-  DPRINT1("AddConsoleAliasA(0x%x, 0x%x, 0x%x) UNIMPLEMENTED!\n", Source, Target, ExeName);
-  SetLastError(ERROR_CALL_NOT_IMPLEMENTED);
-  return FALSE;
+AddConsoleAliasA (LPCSTR lpSource,
+		  LPCSTR lpTarget,
+		  LPCSTR lpExeName)
+{
+    LPWSTR lpSourceW = NULL;
+	LPWSTR lpTargetW = NULL;
+	LPWSTR lpExeNameW = NULL;
+	BOOL bRetVal;
+
+	if (lpSource)
+		BasepAnsiStringToHeapUnicodeString(lpSource, (LPWSTR*) &lpSourceW);
+	if (lpTarget)
+		BasepAnsiStringToHeapUnicodeString(lpTarget, (LPWSTR*) &lpTargetW);
+	if (lpExeName)
+		BasepAnsiStringToHeapUnicodeString(lpExeName, (LPWSTR*) &lpExeNameW);
+
+	bRetVal = AddConsoleAliasW(lpSourceW, lpTargetW, lpExeNameW);
+	
+	/* Clean up */
+	if (lpSourceW)
+		RtlFreeHeap(GetProcessHeap(), 0, (LPWSTR*) lpSourceW);
+	if (lpTargetW)
+		RtlFreeHeap(GetProcessHeap(), 0, (LPWSTR*) lpTargetW);
+	if (lpExeNameW)
+		RtlFreeHeap(GetProcessHeap(), 0, (LPWSTR*) lpExeNameW);
+
+    return bRetVal;
 }
 
 
@@ -158,13 +202,129 @@
  * @unimplemented
  */
 BOOL STDCALL
-AddConsoleAliasW (LPWSTR Source,
-		  LPWSTR Target,
-		  LPWSTR ExeName)
-{
-  DPRINT1("AddConsoleAliasW(0x%x, 0x%x, 0x%x) UNIMPLEMENTED!\n", Source, Target, ExeName);
-  SetLastError(ERROR_CALL_NOT_IMPLEMENTED);
-  return FALSE;
+AddConsoleAliasW (LPCWSTR lpSource,
+		  LPCWSTR lpTarget,
+		  LPCWSTR lpExeName /* FIXME: currently ignored */)
+{
+	LPALIAS ptr = lpFirst;
+	LPALIAS prev = NULL;
+	LPALIAS entry = NULL;
+	LPWSTR s;
+
+	if (!lpTarget)
+	{
+		/* delete */
+		while (ptr)
+		{
+			if (!wcsicmp (ptr->lpName, lpSource))
+			{
+				if (prev)
+					prev->next = ptr->next;
+				else
+					lpFirst = ptr->next;
+				RtlFreeHeap (GetProcessHeap(), 0, ptr->lpName);
+				RtlFreeHeap (GetProcessHeap(), 0, ptr->lpSubst);
+				RtlFreeHeap (GetProcessHeap(), 0, ptr);
+				return TRUE;
+			}
+			prev = ptr;
+			ptr = ptr->next;
+		}
+	}
+	else
+	{
+		/* add */
+		while (ptr)
+		{
+			if (!wcsicmp (ptr->lpName, lpSource))
+			{
+				s = (LPWSTR) RtlAllocateHeap (GetProcessHeap(), 0, ((wcslen (lpTarget) + 1) * sizeof(WCHAR)));
+				if (!s)
+				{
+					return FALSE;
+				}
+
+				RtlFreeHeap (GetProcessHeap(), 0, ptr->lpSubst);
+				ptr->lpSubst = s;
+				wcscpy (ptr->lpSubst, lpTarget);
+				return TRUE;
+			}
+			ptr = ptr->next;
+		}
+
+		ptr = (LPALIAS) RtlAllocateHeap (GetProcessHeap(), 0, sizeof(ALIAS));
+		if (!ptr)
+			return FALSE;
+
+		ptr->next = 0;
+
+		ptr->lpName = (LPWSTR) RtlAllocateHeap (GetProcessHeap(), 0, ((wcslen (lpSource) + 1) * sizeof(WCHAR)));
+		if (!ptr->lpName)
+		{
+			RtlFreeHeap (GetProcessHeap(), 0, ptr);
+			return FALSE;
+		}
+		wcscpy (ptr->lpName, lpSource);
+
+		ptr->lpSubst = (LPWSTR) RtlAllocateHeap (GetProcessHeap(), 0, ((wcslen (lpTarget) + 1) * sizeof(WCHAR)));
+		if (!ptr->lpSubst)
+		{
+			RtlFreeHeap (GetProcessHeap(), 0, ptr->lpName);
+			RtlFreeHeap (GetProcessHeap(), 0, ptr);
+			return FALSE;
+		}
+		wcscpy (ptr->lpSubst, lpTarget);
+
+		/* it's necessary for recursive substitution */
+		partstrlwr (ptr->lpSubst);
+
+		ptr->dwUsed = 0;
+
+		/* Alias table must be sorted!
+		 * Here a little example:
+		 *   command line = "ls -c"
+		 * If the entries are
+		 *   ls=dir
+		 *   ls -c=ls /w
+		 * command line will be expanded to "dir -c" which is not correct.
+		 * If the entries are sortet as
+		 *   ls -c=ls /w
+		 *   ls=dir
+		 * it will be expanded to "dir /w" which is a valid DOS command.
+		 */
+		entry = lpFirst;
+		prev = 0;
+		while (entry)
+		{
+			if (wcsicmp (ptr->lpName, entry->lpName) > 0)
+
+			{
+				if (prev)
+				{
+					prev->next = ptr;
+					ptr->next = entry;
+				}
+				else
+				{
+					ptr->next = entry;
+					lpFirst = ptr;
+				}
+				return TRUE;
+			}
+			prev = entry;
+			entry = entry->next;
+		}
+
+		/* The new entry is the smallest (or the first) and must be
+		 * added to the end of the list.
+		 */
+		if (!lpFirst)
+			lpFirst = ptr;
+		else
+			lpLast->next = ptr;
+		lpLast = ptr;
+	}
+	return TRUE;
 }
 
 
@@ -252,20 +412,39 @@
 
 
 /*
- * @unimplemented
+ * @implemented
  */
 DWORD STDCALL
 GetConsoleAliasW (LPWSTR	lpSource,
 		  LPWSTR	lpTargetBuffer,
 		  DWORD		TargetBufferLength,
-		  LPWSTR	lpExeName)
-     /*
-      * Undocumented
-      */
-{
-  DPRINT1("GetConsoleAliasW(0x%p, 0x%p, 0x%x, 0x%p) UNIMPLEMENTED!\n", lpSource, lpTargetBuffer, TargetBufferLength, lpExeName);
-  SetLastError(ERROR_CALL_NOT_IMPLEMENTED);
-  return 0;
+		  LPWSTR	lpExeName) /* FIXME: currently ignored */
+{
+	DWORD dwRet = 0;
+
+	if (!lpTargetBuffer)
+		return 0;
+
+	LPALIAS ptr = lpFirst;
+	while (ptr)
+	{
+		if (wcscmp(ptr->lpName, lpSource) == 0)
+		{
+			if (TargetBufferLength >= wcslen(ptr->lpSubst) +1)
+			{
+				wcscpy(lpTargetBuffer, ptr->lpSubst);
+				dwRet = wcslen(ptr->lpSubst);
+				break;
+			}
+			else
+			{
+				return 0;
+			}
+		}
+		ptr = ptr->next;
+	}
+
+	return dwRet;
 }
 
 
@@ -277,9 +456,6 @@
 		  LPSTR	lpTargetBuffer,
 		  DWORD	TargetBufferLength,
 		  LPSTR	lpExeName)
-     /*
-      * Undocumented
-      */
 {
   DPRINT1("GetConsoleAliasA(0x%p, 0x%p, 0x%x, 0x%p) UNIMPLEMENTED!\n", lpSource, lpTargetBuffer, TargetBufferLength, lpExeName);
   SetLastError(ERROR_CALL_NOT_IMPLEMENTED);
@@ -293,9 +469,6 @@
 DWORD STDCALL
 GetConsoleAliasExesW (LPWSTR	lpExeNameBuffer,
 		      DWORD	ExeNameBufferLength)
-     /*
-      * Undocumented
-      */
 {
   DPRINT1("GetConsoleAliasExesW(0x%p, 0x%x) UNIMPLEMENTED!\n", lpExeNameBuffer, ExeNameBufferLength);
   SetLastError(ERROR_CALL_NOT_IMPLEMENTED);
@@ -309,9 +482,6 @@
 DWORD STDCALL
 GetConsoleAliasExesA (LPSTR	lpExeNameBuffer,
 		      DWORD	ExeNameBufferLength)
-     /*
-      * Undocumented
-      */
 {
   DPRINT1("GetConsoleAliasExesA(0x%p, 0x%x) UNIMPLEMENTED!\n", lpExeNameBuffer, ExeNameBufferLength);
   SetLastError(ERROR_CALL_NOT_IMPLEMENTED);
@@ -324,9 +494,6 @@
  */
 DWORD STDCALL
 GetConsoleAliasExesLengthA (VOID)
-     /*
-      * Undocumented
-      */
 {
   DPRINT1("GetConsoleAliasExesLengthA() UNIMPLEMENTED!\n");
   SetLastError(ERROR_CALL_NOT_IMPLEMENTED);
@@ -339,9 +506,6 @@
  */
 DWORD STDCALL
 GetConsoleAliasExesLengthW (VOID)
-     /*
-      * Undocumented
-      */
 {
   DPRINT1("GetConsoleAliasExesLengthW() UNIMPLEMENTED!\n");
   SetLastError(ERROR_CALL_NOT_IMPLEMENTED);
@@ -350,19 +514,35 @@
 
 
 /*
- * @unimplemented
+ * @implemented
  */
 DWORD STDCALL
 GetConsoleAliasesW (LPWSTR AliasBuffer,
 		    DWORD	AliasBufferLength,
-		    LPWSTR	ExeName)
-     /*
-      * Undocumented
-      */
-{
-  DPRINT1("GetConsoleAliasesW(0x%p, 0x%x, 0x%p) UNIMPLEMENTED!\n", AliasBuffer, AliasBufferLength, ExeName);
-  SetLastError(ERROR_CALL_NOT_IMPLEMENTED);
-  return 0;
+		    LPWSTR	ExeName)  /* FIXME: currently ignored */
+{
+	DWORD len;
+	WCHAR Buffer[MAX_PATH];
+	LPWSTR AliasPtr;
+
+	if (!AliasBuffer)
+		return 0;
+
+	AliasPtr = AliasBuffer;
+	len = GetConsoleAliasesLengthW (ExeName);
+	if (len > AliasBufferLength)
+		return 0;
+
+	LPALIAS ptr = lpFirst;
+	while (ptr)
+	{
+		swprintf(Buffer, L"%s=%s" , ptr->lpName, ptr->lpSubst);
+		wcscpy(AliasBuffer, Buffer);
+		AliasBuffer += wcslen(Buffer) + 1;
+		ptr = ptr->next;
+	}
+
+	return (INT) (AliasBuffer - AliasPtr);
 }
 
 
@@ -384,32 +564,43 @@
 
 
 /*
- * @unimplemented
+ * @implemented
  */
 DWORD STDCALL
-GetConsoleAliasesLengthW (LPWSTR lpExeName)
-     /*
-      * Undocumented
-      */
-{
-  DPRINT1("GetConsoleAliasesLengthW(0x%p) UNIMPLEMENTED!\n", lpExeName);
-  SetLastError(ERROR_CALL_NOT_IMPLEMENTED);
-  return 0;
-}
-
-
-/*
- * @unimplemented
+GetConsoleAliasesLengthW (LPWSTR lpExeName  /* FIXME: currently ignored */) 
+{
+	DWORD len = 0;
+	LPALIAS ptr = lpFirst;
+	while (ptr)
+	{
+		len += wcslen(ptr->lpName) * sizeof(WCHAR);
+		len += wcslen(ptr->lpSubst) * sizeof(WCHAR);
+		len += 2 * sizeof(WCHAR); /* '=' + '\0' */
+		ptr = ptr->next;
+	}
+	return len; 
+}
+
+
+/*
+ * @implemented
  */
 DWORD STDCALL
 GetConsoleAliasesLengthA (LPSTR lpExeName)
-     /*
-      * Undocumented
-      */
-{
-  DPRINT1("GetConsoleAliasesLengthA(0x%p) UNIMPLEMENTED!\n", lpExeName);
-  SetLastError(ERROR_CALL_NOT_IMPLEMENTED);
-  return 0;
+{
+	DWORD dwRetVal = 0;
+	LPWSTR lpExeNameW = NULL;
+
+	if (lpExeName)
+		BasepAnsiStringToHeapUnicodeString(lpExeName, (LPWSTR*) &lpExeNameW);
+
+	dwRetVal = (GetConsoleAliasesLengthW(lpExeNameW) / sizeof(WCHAR));
+	
+	/* Clean up */
+	if (lpExeNameW)
+		RtlFreeHeap(GetProcessHeap(), 0, (LPWSTR*) lpExeNameW);
+
+	return dwRetVal;
 }
 
 

Modified: trunk/reactos/include/psdk/wincon.h
URL: http://svn.reactos.org/svn/reactos/trunk/reactos/include/psdk/wincon.h?rev=32093&r1=32092&r2=32093&view=diff
==============================================================================
--- trunk/reactos/include/psdk/wincon.h (original)
+++ trunk/reactos/include/psdk/wincon.h Sun Feb  3 00:06:53 2008
@@ -167,6 +167,14 @@
 #if (_WIN32_WINNT >= 0x0501)
 #define ATTACH_PARENT_PROCESS (DWORD)-1
 BOOL WINAPI AttachConsole(DWORD);
+BOOL WINAPI AddConsoleAliasA(LPCSTR,LPCSTR,LPCSTR);
+BOOL WINAPI AddConsoleAliasW(LPCWSTR,LPCWSTR,LPCWSTR);
+DWORD WINAPI GetConsoleAliasA(LPSTR,LPSTR,DWORD,LPSTR);
+DWORD WINAPI GetConsoleAliasW(LPWSTR,LPWSTR,DWORD,LPWSTR);
+DWORD WINAPI GetConsoleAliasesA(LPSTR,DWORD,LPSTR);
+DWORD WINAPI GetConsoleAliasesW(LPWSTR,DWORD,LPWSTR);
+DWORD WINAPI GetConsoleAliasesLengthA(LPSTR);
+DWORD WINAPI GetConsoleAliasesLengthW(LPWSTR);
 #endif
 HANDLE WINAPI CreateConsoleScreenBuffer(DWORD,DWORD,CONST SECURITY_ATTRIBUTES*,DWORD,LPVOID);
 BOOL WINAPI FillConsoleOutputAttribute(HANDLE,WORD,DWORD,COORD,PDWORD);
@@ -225,6 +233,10 @@
 
 #ifdef UNICODE
 #define FillConsoleOutputCharacter FillConsoleOutputCharacterW
+#define AddConsoleAlias AddConsoleAliasW
+#define GetConsoleAlias GetConsoleAliasW
+#define GetConsoleAliases GetConsoleAliasesW
+#define GetConsoleAliasesLength GetConsoleAliasesLengthW
 #define GetConsoleTitle GetConsoleTitleW
 #define PeekConsoleInput PeekConsoleInputW
 #define ReadConsole ReadConsoleW
@@ -238,7 +250,11 @@
 #define WriteConsoleOutput WriteConsoleOutputW
 #define WriteConsoleOutputCharacter WriteConsoleOutputCharacterW
 #else
+#define AddConsoleAlias AddConsoleAliasA
 #define FillConsoleOutputCharacter FillConsoleOutputCharacterA
+#define GetConsoleAlias GetConsoleAliasA
+#define GetConsoleAliases GetConsoleAliasesA
+#define GetConsoleAliasesLength GetConsoleAliasesLengthA
 #define GetConsoleTitle GetConsoleTitleA
 #define PeekConsoleInput PeekConsoleInputA
 #define ReadConsole ReadConsoleA




More information about the Ros-diffs mailing list