Author: jgardou Date: Thu Sep 30 18:56:42 2010 New Revision: 48944
URL: http://svn.reactos.org/svn/reactos?rev=48944&view=rev Log: Merge 48942
Modified: branches/cmake-bringup/base/applications/cmdutils/doskey/ (props changed) branches/cmake-bringup/base/applications/cmdutils/doskey/doskey.c branches/cmake-bringup/base/applications/cmdutils/doskey/doskey.h
Propchange: branches/cmake-bringup/base/applications/cmdutils/doskey/ ------------------------------------------------------------------------------ --- svn:mergeinfo (added) +++ svn:mergeinfo Thu Sep 30 18:56:42 2010 @@ -1,0 +1,5 @@ +/branches/header-work/base/applications/cmdutils/doskey:45691-47721 +/branches/reactos-yarotows/base/applications/cmdutils/doskey:46372,46848,46966,47800,48026,48064 +/branches/ros-amd64-bringup/base/applications/cmdutils/doskey:36852 +/branches/ros-amd64-bringup/reactos/base/applications/cmdutils/doskey:34711-34712,34741,34743,34770,34780-34782,34803,34812,34839,34842,34864,34870,34874,34877,34908-34909,34917,34965,35323-35324,35347-35348,35361,35436,35509,35515,35588,35655,35683,35739,35746,35762,35771,35777,35781,35789,35805,35823,35827,35902,35904-35906,35942,35947-35949,35952-35953,35966,36011-36013,36172,36360,36380,36388-36389,36393,36397,36443,36445,36475,36502-36503,36505,36570,36614,36852,36898-36899,36930,36936,36949,36951,36958,36961,36964,36969,36972,36987-36988,36990,36992,37019,37322-37323,37333-37334,37434,37472,37475,37536,37820-37821,37868-37869,37873,37990-37991,38013-38014,38092,38100,38148-38151,38264-38265,38268,38355,39151,39333,39335,39345,39639,40120,40122-40123,40125,40127-40128,40155,40247,40324,40608,40753,40926-40928,40986-40987,40989,40991,40993,40995-40996,41000-41001,41027-41030,41044-41045,41047-41050,41052,41070,41082-41086,41097-41098,41101,41449,41479-41480,41483-41485,41499-41500,41502,41531,41536,41540,41546-41547,41549,43080,43426,43451,43454,43506,43566,43574,43598,43600-43602,43604-43605,43677,43682,43757,43775,43836,43838-43840,43852,43857-43858,43860,43905-43907,43952,43954,43965,43969,43979,43981,43992,44002,44036-44037,44039-44040,44044-44045,44053,44065,44095,44123,44143-44144,44205,44238,44257,44259,44294,44338-44339,44385,44389,44391,44426,44460,44467-44468,44470-44471,44499,44501,44503-44504,44506,44510-44512,44521,44523-44526,44530,44540,44601,44634,44639,44772,44818,45124,45126-45127,45430,46394,46404,46478,46511,46523-46524,46526,46534-46535,46537-46539,46589,46805,46868,47472,47846-47847,47878,47882 +/trunk/reactos/base/applications/cmdutils/doskey:48236-48828,48884,48942
Modified: branches/cmake-bringup/base/applications/cmdutils/doskey/doskey.c URL: http://svn.reactos.org/svn/reactos/branches/cmake-bringup/base/applications/... ============================================================================== --- branches/cmake-bringup/base/applications/cmdutils/doskey/doskey.c [iso-8859-1] (original) +++ branches/cmake-bringup/base/applications/cmdutils/doskey/doskey.c [iso-8859-1] Thu Sep 30 18:56:42 2010 @@ -1,11 +1,23 @@ #include <windows.h> #include <stdio.h> -#include <tchar.h> +#include <wchar.h> +#include <assert.h> #include "doskey.h"
#define MAX_STRING 2000 -TCHAR szStringBuf[MAX_STRING]; -LPTSTR pszExeName = _T("cmd.exe"); +WCHAR szStringBuf[MAX_STRING]; +LPWSTR pszExeName = L"cmd.exe"; + +/* Function pointers */ +typedef DWORD (WINAPI *GetConsoleCommandHistoryW_t) (LPWSTR sCommands, DWORD nBufferLength, LPWSTR sExeName); +typedef DWORD (WINAPI *GetConsoleCommandHistoryLengthW_t) (LPWSTR sExeName); +typedef BOOL (WINAPI *SetConsoleNumberOfCommandsW_t)(DWORD nNumber, LPWSTR sExeName); +typedef VOID (WINAPI *ExpungeConsoleCommandHistoryW_t)(LPWSTR sExeName); + +GetConsoleCommandHistoryW_t pGetConsoleCommandHistoryW; +GetConsoleCommandHistoryLengthW_t pGetConsoleCommandHistoryLengthW; +SetConsoleNumberOfCommandsW_t pSetConsoleNumberOfCommandsW; +ExpungeConsoleCommandHistoryW_t pExpungeConsoleCommandHistoryW;
static VOID SetInsert(DWORD dwFlag) { @@ -18,79 +30,74 @@
static VOID PrintHistory(VOID) { - DWORD Length = GetConsoleCommandHistoryLength(pszExeName); - DWORD BufferLength; + DWORD Length = pGetConsoleCommandHistoryLengthW(pszExeName); PBYTE HistBuf; - TCHAR *Hist; - TCHAR *HistEnd; - - /* On Windows, the ANSI version of GetConsoleCommandHistory requires - * a buffer twice as large as the actual history length. */ - BufferLength = Length * (sizeof(WCHAR) / sizeof(TCHAR)) * sizeof(BYTE); + WCHAR *Hist; + WCHAR *HistEnd;
HistBuf = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, - BufferLength); + Length); if (!HistBuf) return; - Hist = (TCHAR *)HistBuf; - HistEnd = (TCHAR *)&HistBuf[Length]; - - if (GetConsoleCommandHistory(Hist, BufferLength, pszExeName)) - for (; Hist < HistEnd; Hist += _tcslen(Hist) + 1) - _tprintf(_T("%s\n"), Hist); + Hist = (WCHAR *)HistBuf; + HistEnd = (WCHAR *)&HistBuf[Length]; + + if (pGetConsoleCommandHistoryW(Hist, Length, pszExeName)) + for (; Hist < HistEnd; Hist += wcslen(Hist) + 1) + wprintf(L"%s\n", Hist);
HeapFree(GetProcessHeap(), 0, HistBuf); }
-static INT SetMacro(LPTSTR definition) -{ - TCHAR *name, *nameend, *text, temp; +static INT SetMacro(LPWSTR definition) +{ + WCHAR *name, *nameend, *text, temp;
name = definition; - while (*name == _T(' ')) + while (*name == L' ') name++;
/* error if no '=' found */ - if ((nameend = _tcschr(name, _T('='))) != NULL) + if ((nameend = wcschr(name, L'=')) != NULL) { text = nameend + 1; - while (*text == _T(' ')) + while (*text == L' ') text++;
- while (nameend > name && nameend[-1] == _T(' ')) + while (nameend > name && nameend[-1] == L' ') nameend--;
/* Split rest into name and substitute */ temp = *nameend; - *nameend = _T('\0'); + *nameend = L'\0'; /* Don't allow spaces in the name, since such a macro would be unusable */ - if (!_tcschr(name, _T(' ')) && AddConsoleAlias(name, text, pszExeName)) + if (!wcschr(name, L' ') && AddConsoleAlias(name, text, pszExeName)) return 0; *nameend = temp; }
LoadString(GetModuleHandle(NULL), IDS_INVALID_MACRO_DEF, szStringBuf, MAX_STRING); - _tprintf(szStringBuf, definition); + wprintf(szStringBuf, definition); return 1; }
-static VOID PrintMacros(LPTSTR pszExeName, LPTSTR Indent) +static VOID PrintMacros(LPWSTR pszExeName, LPWSTR Indent) { DWORD Length = GetConsoleAliasesLength(pszExeName); PBYTE AliasBuf; - TCHAR *Alias; - TCHAR *AliasEnd; + WCHAR *Alias; + WCHAR *AliasEnd;
AliasBuf = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, Length * sizeof(BYTE)); if (!AliasBuf) return; - Alias = (TCHAR *)AliasBuf; - AliasEnd = (TCHAR *)&AliasBuf[Length]; + Alias = (WCHAR *)AliasBuf; + AliasEnd = (WCHAR *)&AliasBuf[Length];
if (GetConsoleAliases(Alias, Length * sizeof(BYTE), pszExeName)) - for (; Alias < AliasEnd; Alias += _tcslen(Alias) + 1) - _tprintf(_T("%s%s\n"), Indent, Alias); + for (; Alias < AliasEnd; Alias += wcslen(Alias) + 1) + wprintf(L"%s%s\n", Indent, Alias);
HeapFree(GetProcessHeap(), 0, AliasBuf); } @@ -99,51 +106,47 @@ { DWORD Length = GetConsoleAliasExesLength(); PBYTE ExeNameBuf; - TCHAR *ExeName; - TCHAR *ExeNameEnd; + WCHAR *ExeName; + WCHAR *ExeNameEnd;
ExeNameBuf = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, Length * sizeof(BYTE)); if (!ExeNameBuf) return; - ExeName = (TCHAR *)ExeNameBuf; - ExeNameEnd = (TCHAR *)&ExeNameBuf[Length]; + ExeName = (WCHAR *)ExeNameBuf; + ExeNameEnd = (WCHAR *)&ExeNameBuf[Length];
if (GetConsoleAliasExes(ExeName, Length * sizeof(BYTE))) { - for (; ExeName < ExeNameEnd; ExeName += _tcslen(ExeName) + 1) - { - _tprintf(_T("[%s]\n"), ExeName); - PrintMacros(ExeName, _T(" ")); - _tprintf(_T("\n")); + for (; ExeName < ExeNameEnd; ExeName += wcslen(ExeName) + 1) + { + wprintf(L"[%s]\n", ExeName); + PrintMacros(ExeName, L" "); + wprintf(L"\n"); } }
HeapFree(GetProcessHeap(), 0, ExeNameBuf); }
-static VOID ReadFromFile(LPTSTR param) +static VOID ReadFromFile(LPWSTR param) { FILE* fp; - TCHAR line[MAX_PATH]; - - fp = _tfopen(param, _T("r")); + WCHAR line[MAX_PATH]; + + fp = _wfopen(param, L"r"); if (!fp) { -#ifdef UNICODE _wperror(param); -#else - perror(param); -#endif return; }
- while ( _fgetts(line, MAX_PATH, fp) != NULL) + while ( fgetws(line, MAX_PATH, fp) != NULL) { /* Remove newline character */ - TCHAR *end = &line[_tcslen(line) - 1]; - if (*end == _T('\n')) - *end = _T('\0'); + WCHAR *end = &line[wcslen(line) - 1]; + if (*end == L'\n') + *end = L'\0';
if (*line) SetMacro(line); @@ -154,43 +157,53 @@ }
/* Get the start and end of the next command-line argument. */ -static BOOL GetArg(TCHAR **pStart, TCHAR **pEnd) +static BOOL GetArg(WCHAR **pStart, WCHAR **pEnd) { BOOL bInQuotes = FALSE; - TCHAR *p = *pEnd; - p += _tcsspn(p, _T(" \t")); + WCHAR *p = *pEnd; + p += wcsspn(p, L" \t"); if (!*p) return FALSE; *pStart = p; do { - if (!bInQuotes && (*p == _T(' ') || *p == _T('\t'))) + if (!bInQuotes && (*p == L' ' || *p == L'\t')) break; - bInQuotes ^= (*p++ == _T('"')); + bInQuotes ^= (*p++ == L'"'); } while (*p); *pEnd = p; return TRUE; }
/* Remove starting and ending quotes from a string, if present */ -static LPTSTR RemoveQuotes(LPTSTR str) -{ - TCHAR *end; - if (*str == _T('"') && *(end = str + _tcslen(str) - 1) == _T('"')) +static LPWSTR RemoveQuotes(LPWSTR str) +{ + WCHAR *end; + if (*str == L'"' && *(end = str + wcslen(str) - 1) == L'"') { str++; - *end = _T('\0'); + *end = L'\0'; } return str; }
int -_tmain(VOID) +wmain(VOID) { /* Get the full command line using GetCommandLine(). We can't just use argv, * because then a parameter like "gotoroot=cd " wouldn't be passed completely. */ - TCHAR *pArgStart; - TCHAR *pArgEnd = GetCommandLine(); + WCHAR *pArgStart; + WCHAR *pArgEnd = GetCommandLine(); + HMODULE hKernel32 = LoadLibraryW(L"kernel32.dll"); + + /* Get function pointers */ + pGetConsoleCommandHistoryW = (GetConsoleCommandHistoryW_t)GetProcAddress( hKernel32, "GetConsoleCommandHistoryW"); + pGetConsoleCommandHistoryLengthW = (GetConsoleCommandHistoryLengthW_t)GetProcAddress( hKernel32, "GetConsoleCommandHistoryLengthW"); + pSetConsoleNumberOfCommandsW = (SetConsoleNumberOfCommandsW_t)GetProcAddress( hKernel32, "SetConsoleNumberOfCommandsW"); + pExpungeConsoleCommandHistoryW = (ExpungeConsoleCommandHistoryW_t)GetProcAddress( hKernel32, "ExpungeConsoleCommandHistoryW"); + + assert(pGetConsoleCommandHistoryW && pGetConsoleCommandHistoryLengthW && + pSetConsoleNumberOfCommandsW && pSetConsoleNumberOfCommandsW);
/* Skip the application name */ GetArg(&pArgStart, &pArgEnd); @@ -198,55 +211,55 @@ while (GetArg(&pArgStart, &pArgEnd)) { /* NUL-terminate this argument to make processing easier */ - TCHAR tmp = *pArgEnd; - *pArgEnd = _T('\0'); - - if (!_tcscmp(pArgStart, _T("/?"))) + WCHAR tmp = *pArgEnd; + *pArgEnd = L'\0'; + + if (!wcscmp(pArgStart, L"/?")) { LoadString(GetModuleHandle(NULL), IDS_HELP, szStringBuf, MAX_STRING); - _tprintf(szStringBuf); + wprintf(szStringBuf); break; } - else if (!_tcsnicmp(pArgStart, _T("/EXENAME="), 9)) + else if (!_wcsnicmp(pArgStart, L"/EXENAME=", 9)) { pszExeName = RemoveQuotes(pArgStart + 9); } - else if (!_tcsicmp(pArgStart, _T("/H")) || - !_tcsicmp(pArgStart, _T("/HISTORY"))) + else if (!wcsicmp(pArgStart, L"/H") || + !wcsicmp(pArgStart, L"/HISTORY")) { PrintHistory(); } - else if (!_tcsnicmp(pArgStart, _T("/LISTSIZE="), 10)) - { - SetConsoleNumberOfCommands(_ttoi(pArgStart + 10), pszExeName); - } - else if (!_tcsicmp(pArgStart, _T("/REINSTALL"))) - { - ExpungeConsoleCommandHistory(pszExeName); - } - else if (!_tcsicmp(pArgStart, _T("/INSERT"))) + else if (!_wcsnicmp(pArgStart, L"/LISTSIZE=", 10)) + { + pSetConsoleNumberOfCommandsW(_wtoi(pArgStart + 10), pszExeName); + } + else if (!wcsicmp(pArgStart, L"/REINSTALL")) + { + pExpungeConsoleCommandHistoryW(pszExeName); + } + else if (!wcsicmp(pArgStart, L"/INSERT")) { SetInsert(ENABLE_INSERT_MODE); } - else if (!_tcsicmp(pArgStart, _T("/OVERSTRIKE"))) + else if (!wcsicmp(pArgStart, L"/OVERSTRIKE")) { SetInsert(0); } - else if (!_tcsicmp(pArgStart, _T("/M")) || - !_tcsicmp(pArgStart, _T("/MACROS"))) - { - PrintMacros(pszExeName, _T("")); - } - else if (!_tcsnicmp(pArgStart, _T("/M:"), 3) || - !_tcsnicmp(pArgStart, _T("/MACROS:"), 8)) - { - LPTSTR exe = RemoveQuotes(_tcschr(pArgStart, _T(':')) + 1); - if (!_tcsicmp(exe, _T("ALL"))) + else if (!wcsicmp(pArgStart, L"/M") || + !wcsicmp(pArgStart, L"/MACROS")) + { + PrintMacros(pszExeName, L""); + } + else if (!_wcsnicmp(pArgStart, L"/M:", 3) || + !_wcsnicmp(pArgStart, L"/MACROS:", 8)) + { + LPWSTR exe = RemoveQuotes(wcschr(pArgStart, L':') + 1); + if (!wcsicmp(exe, L"ALL")) PrintAllMacros(); else - PrintMacros(exe, _T("")); - } - else if (!_tcsnicmp(pArgStart, _T("/MACROFILE="), 11)) + PrintMacros(exe, L""); + } + else if (!_wcsnicmp(pArgStart, L"/MACROFILE=", 11)) { ReadFromFile(RemoveQuotes(pArgStart + 11)); }
Modified: branches/cmake-bringup/base/applications/cmdutils/doskey/doskey.h URL: http://svn.reactos.org/svn/reactos/branches/cmake-bringup/base/applications/... ============================================================================== --- branches/cmake-bringup/base/applications/cmdutils/doskey/doskey.h [iso-8859-1] (original) +++ branches/cmake-bringup/base/applications/cmdutils/doskey/doskey.h [iso-8859-1] Thu Sep 30 18:56:42 2010 @@ -23,11 +23,6 @@ BOOL WINAPI AddConsoleAliasW(LPWSTR, LPWSTR, LPWSTR); #define AddConsoleAlias TNAME(AddConsoleAlias) #endif -#ifndef ExpungeConsoleCommandHistory -BOOL WINAPI ExpungeConsoleCommandHistoryA(LPSTR); -BOOL WINAPI ExpungeConsoleCommandHistoryW(LPWSTR); -#define ExpungeConsoleCommandHistory TNAME(ExpungeConsoleCommandHistory) -#endif #ifndef GetConsoleAliases DWORD WINAPI GetConsoleAliasesA(LPSTR, DWORD, LPSTR); DWORD WINAPI GetConsoleAliasesW(LPWSTR, DWORD, LPWSTR); @@ -48,20 +43,5 @@ DWORD WINAPI GetConsoleAliasExesLengthW(VOID); #define GetConsoleAliasExesLength TNAME(GetConsoleAliasExesLength) #endif -#ifndef GetConsoleCommandHistory -DWORD WINAPI GetConsoleCommandHistoryA(LPSTR, DWORD, LPSTR); -DWORD WINAPI GetConsoleCommandHistoryW(LPWSTR, DWORD, LPWSTR); -#define GetConsoleCommandHistory TNAME(GetConsoleCommandHistory) -#endif -#ifndef GetConsoleCommandHistoryLength -DWORD WINAPI GetConsoleCommandHistoryLengthA(LPSTR); -DWORD WINAPI GetConsoleCommandHistoryLengthW(LPWSTR); -#define GetConsoleCommandHistoryLength TNAME(GetConsoleCommandHistoryLength) -#endif -#ifndef SetConsoleNumberOfCommands -BOOL WINAPI SetConsoleNumberOfCommandsA(DWORD, LPSTR); -BOOL WINAPI SetConsoleNumberOfCommandsW(DWORD, LPWSTR); -#define SetConsoleNumberOfCommands TNAME(SetConsoleNumberOfCommands) -#endif
#endif /* RC_INVOKED */