CMD Enhancements:

- Fixed UNICODE build.
- Make the DIR /W behave like in Windows.
- Fixed various problems with command input going mad when the screen contents have scrolled.

svn path=/trunk/; revision=9252
This commit is contained in:
Filip Navara 2004-04-30 16:52:42 +00:00
parent 8352c9c082
commit c7eed44a94
8 changed files with 243 additions and 130 deletions

View file

@ -1,4 +1,4 @@
/* $Id: cmd.c,v 1.11 2004/04/26 20:26:15 gdalsnes Exp $ /* $Id: cmd.c,v 1.12 2004/04/30 16:52:41 navaraf Exp $
* *
* CMD.C - command-line interface. * CMD.C - command-line interface.
* *
@ -119,6 +119,9 @@
* *
* 23-Feb-2001 (Carl Nettelblad <cnettel@hem.passagen.se>) * 23-Feb-2001 (Carl Nettelblad <cnettel@hem.passagen.se>)
* %envvar% replacement conflicted with for. * %envvar% replacement conflicted with for.
*
* 30-Apr-2004 (Filip Navara <xnavara@volny.cz>)
* Make MakeSureDirectoryPathExistsEx unicode safe.
*/ */
#include "config.h" #include "config.h"
@ -178,34 +181,32 @@ WORD wDefColor; /* default color */
* *
* FIXME: maybe put this in a header/library where everyone can use it????? * FIXME: maybe put this in a header/library where everyone can use it?????
*/ */
BOOL WINAPI MakeSureDirectoryPathExistsEx(LPCSTR DirPath, BOOL FileAtEnd) BOOL WINAPI MakeSureDirectoryPathExistsEx(LPCTSTR DirPath, BOOL FileAtEnd)
{ {
char Path[MAX_PATH]; TCHAR Path[MAX_PATH];
char *SlashPos = Path; TCHAR *SlashPos = Path;
char Slash; TCHAR Slash;
BOOL bRes; BOOL bRes;
strcpy(Path, DirPath); _tcscpy(Path, DirPath);
while ((SlashPos = _tcspbrk(SlashPos + 1, _T("\\/"))))
while((SlashPos=strpbrk(SlashPos+1,"\\/")))
{ {
Slash = *SlashPos; Slash = *SlashPos;
*SlashPos = 0; *SlashPos = 0;
bRes = CreateDirectoryA(Path, NULL); bRes = CreateDirectory(Path, NULL);
if (bRes == FALSE && GetLastError() != ERROR_ALREADY_EXISTS) if (bRes == FALSE && GetLastError() != ERROR_ALREADY_EXISTS)
{ {
return FALSE; return FALSE;
} }
*SlashPos = Slash; *SlashPos = Slash;
if (*(SlashPos + 1) == 0) return TRUE; if (*(SlashPos + 1) == 0) return TRUE;
} }
if (!FileAtEnd) if (!FileAtEnd)
{ {
bRes = CreateDirectoryA(Path, NULL); bRes = CreateDirectory(Path, NULL);
if (bRes == FALSE && GetLastError() != ERROR_ALREADY_EXISTS) if (bRes == FALSE && GetLastError() != ERROR_ALREADY_EXISTS)
{ {
return FALSE; return FALSE;

View file

@ -92,6 +92,9 @@
* input queue when you pressed <RETURN>. This sometimes caused * input queue when you pressed <RETURN>. This sometimes caused
* some very strange effects. * some very strange effects.
* Fixed some command line editing annoyances. * Fixed some command line editing annoyances.
*
* 30-Apr-2004 (Filip Navara <xnavara@volny.cz>)
* Fixed problems when the screen was scrolled away.
*/ */
#include "config.h" #include "config.h"
@ -133,6 +136,7 @@ VOID ReadCommand (LPTSTR str, INT maxlen)
SHORT orgy; SHORT orgy;
SHORT curx; /*current x/y cursor position*/ SHORT curx; /*current x/y cursor position*/
SHORT cury; SHORT cury;
SHORT tempscreen;
INT count; /*used in some for loops*/ INT count; /*used in some for loops*/
INT current = 0; /*the position of the cursor in the string (str)*/ INT current = 0; /*the position of the cursor in the string (str)*/
INT charcount = 0;/*chars in the string (str)*/ INT charcount = 0;/*chars in the string (str)*/
@ -149,6 +153,7 @@ VOID ReadCommand (LPTSTR str, INT maxlen)
PrintPrompt(); PrintPrompt();
GetCursorXY (&orgx, &orgy); GetCursorXY (&orgx, &orgy);
GetCursorXY (&curx, &cury);
memset (str, 0, maxlen * sizeof (TCHAR)); memset (str, 0, maxlen * sizeof (TCHAR));
@ -179,6 +184,8 @@ VOID ReadCommand (LPTSTR str, INT maxlen)
ClearCommandLine (str, maxlen, orgx, orgy); ClearCommandLine (str, maxlen, orgx, orgy);
current = charcount = 0; current = charcount = 0;
curx = orgx;
cury = orgy;
bContinue=TRUE; bContinue=TRUE;
break; break;
} }
@ -192,6 +199,7 @@ VOID ReadCommand (LPTSTR str, INT maxlen)
History_del_current_entry(str); History_del_current_entry(str);
current = charcount = _tcslen (str); current = charcount = _tcslen (str);
ConOutPrintf (_T("%s"), str); ConOutPrintf (_T("%s"), str);
GetCursorXY (&curx, &cury);
bContinue=TRUE; bContinue=TRUE;
break; break;
} }
@ -222,12 +230,15 @@ VOID ReadCommand (LPTSTR str, INT maxlen)
if (GetCursorX () != 0) if (GetCursorX () != 0)
{ {
ConOutPrintf (_T("\b \b")); ConOutPrintf (_T("\b \b"));
curx--;
} }
else else
{ {
SetCursorXY ((SHORT)(maxx - 1), (SHORT)(GetCursorY () - 1)); SetCursorXY ((SHORT)(maxx - 1), (SHORT)(GetCursorY () - 1));
ConOutChar (_T(' ')); ConOutChar (_T(' '));
SetCursorXY ((SHORT)(maxx - 1), (SHORT)(GetCursorY () - 1)); SetCursorXY ((SHORT)(maxx - 1), (SHORT)(GetCursorY () - 1));
cury--;
curx = maxx - 1;
} }
} }
else else
@ -235,9 +246,16 @@ VOID ReadCommand (LPTSTR str, INT maxlen)
for (count = current - 1; count < charcount; count++) for (count = current - 1; count < charcount; count++)
str[count] = str[count + 1]; str[count] = str[count + 1];
if (GetCursorX () != 0) if (GetCursorX () != 0)
{
SetCursorXY ((SHORT)(GetCursorX () - 1), GetCursorY ()); SetCursorXY ((SHORT)(GetCursorX () - 1), GetCursorY ());
curx--;
}
else else
{
SetCursorXY ((SHORT)(maxx - 1), (SHORT)(GetCursorY () - 1)); SetCursorXY ((SHORT)(maxx - 1), (SHORT)(GetCursorY () - 1));
cury--;
curx = maxx - 1;
}
GetCursorXY (&curx, &cury); GetCursorXY (&curx, &cury);
ConOutPrintf (_T("%s "), &str[current - 1]); ConOutPrintf (_T("%s "), &str[current - 1]);
SetCursorXY (curx, cury); SetCursorXY (curx, cury);
@ -271,6 +289,8 @@ VOID ReadCommand (LPTSTR str, INT maxlen)
if (current != 0) if (current != 0)
{ {
SetCursorXY (orgx, orgy); SetCursorXY (orgx, orgy);
curx = orgx;
cury = orgy;
current = 0; current = 0;
} }
break; break;
@ -281,6 +301,7 @@ VOID ReadCommand (LPTSTR str, INT maxlen)
{ {
SetCursorXY (orgx, orgy); SetCursorXY (orgx, orgy);
ConOutPrintf (_T("%s"), str); ConOutPrintf (_T("%s"), str);
GetCursorXY (&curx, &cury);
current = charcount; current = charcount;
} }
break; break;
@ -295,6 +316,7 @@ VOID ReadCommand (LPTSTR str, INT maxlen)
if (wLastKey != VK_TAB) if (wLastKey != VK_TAB)
{ {
/* if first TAB, complete filename*/ /* if first TAB, complete filename*/
tempscreen = charcount;
CompleteFilename (str, charcount); CompleteFilename (str, charcount);
charcount = _tcslen (str); charcount = _tcslen (str);
current = charcount; current = charcount;
@ -305,12 +327,24 @@ VOID ReadCommand (LPTSTR str, INT maxlen)
SetCursorXY (orgx, orgy); SetCursorXY (orgx, orgy);
ConOutPrintf (_T("%s"), str); ConOutPrintf (_T("%s"), str);
if ((charcount > (USHORT)(maxx - orgx)) && (orgy == maxy + 1))
orgy--; if (tempscreen > charcount)
{
GetCursorXY (&curx, &cury);
for (count = tempscreen - charcount; count--; )
ConOutChar (_T(' '));
SetCursorXY (curx, cury);
}
else
{
if (((charcount + orgx) / maxx) + orgy > maxy - 1)
orgy += maxy - ((charcount + orgx) / maxx + orgy + 1);
}
/* set cursor position */ /* set cursor position */
SetCursorXY ((orgx + current) % maxx, SetCursorXY ((orgx + current) % maxx,
orgy + (orgx + current) / maxx); orgy + (orgx + current) / maxx);
GetCursorXY (&curx, &cury);
} }
else else
{ {
@ -324,6 +358,7 @@ VOID ReadCommand (LPTSTR str, INT maxlen)
/* set cursor position */ /* set cursor position */
SetCursorXY ((orgx + current) % maxx, SetCursorXY ((orgx + current) % maxx,
orgy + (orgx + current) / maxx); orgy + (orgx + current) / maxx);
GetCursorXY (&curx, &cury);
} }
} }
@ -366,6 +401,8 @@ VOID ReadCommand (LPTSTR str, INT maxlen)
case VK_ESCAPE: case VK_ESCAPE:
/* clear str Make this callable! */ /* clear str Make this callable! */
ClearCommandLine (str, maxlen, orgx, orgy); ClearCommandLine (str, maxlen, orgx, orgy);
curx = orgx;
cury = orgy;
current = charcount = 0; current = charcount = 0;
break; break;
@ -379,7 +416,10 @@ VOID ReadCommand (LPTSTR str, INT maxlen)
ClearCommandLine (str, maxlen, orgx, orgy); ClearCommandLine (str, maxlen, orgx, orgy);
History (-1, str); History (-1, str);
current = charcount = _tcslen (str); current = charcount = _tcslen (str);
if (((charcount + orgx) / maxx) + orgy > maxy - 1)
orgy += maxy - ((charcount + orgx) / maxx + orgy + 1);
ConOutPrintf (_T("%s"), str); ConOutPrintf (_T("%s"), str);
GetCursorXY (&curx, &cury);
#endif #endif
break; break;
@ -389,7 +429,10 @@ VOID ReadCommand (LPTSTR str, INT maxlen)
ClearCommandLine (str, maxlen, orgx, orgy); ClearCommandLine (str, maxlen, orgx, orgy);
History (1, str); History (1, str);
current = charcount = _tcslen (str); current = charcount = _tcslen (str);
if (((charcount + orgx) / maxx) + orgy > maxy - 1)
orgy += maxy - ((charcount + orgx) / maxx + orgy + 1);
ConOutPrintf (_T("%s"), str); ConOutPrintf (_T("%s"), str);
GetCursorXY (&curx, &cury);
#endif #endif
break; break;
@ -399,9 +442,16 @@ VOID ReadCommand (LPTSTR str, INT maxlen)
{ {
current--; current--;
if (GetCursorX () == 0) if (GetCursorX () == 0)
{
SetCursorXY ((SHORT)(maxx - 1), (SHORT)(GetCursorY () - 1)); SetCursorXY ((SHORT)(maxx - 1), (SHORT)(GetCursorY () - 1));
curx = maxx - 1;
cury--;
}
else else
{
SetCursorXY ((SHORT)(GetCursorX () - 1), GetCursorY ()); SetCursorXY ((SHORT)(GetCursorX () - 1), GetCursorY ());
curx--;
}
} }
else else
{ {
@ -419,52 +469,19 @@ VOID ReadCommand (LPTSTR str, INT maxlen)
{ {
current++; current++;
if (GetCursorX () == maxx - 1) if (GetCursorX () == maxx - 1)
{
SetCursorXY (0, (SHORT)(GetCursorY () + 1)); SetCursorXY (0, (SHORT)(GetCursorY () + 1));
curx = 0;
cury++;
}
else else
{
SetCursorXY ((SHORT)(GetCursorX () + 1), GetCursorY ()); SetCursorXY ((SHORT)(GetCursorX () + 1), GetCursorY ());
curx++;
}
} }
break; break;
#if 0
#ifdef FEATURE_HISTORY
/*!!!WARNING!!!*/
/*this will only work as long as the two if statement
evaluates the same expression and a break is included
in each if statement.
This can be used for any combination using CTRL.
For other combinations is needed another system*/
case 'K':
/*add the current command line to the history*/
if (ir.Event.KeyEvent.dwControlKeyState &
(LEFT_CTRL_PRESSED|RIGHT_CTRL_PRESSED))
{
if (str[0])
History(0,str);
ClearCommandLine (str, maxlen, orgx, orgy);
current = charcount = 0;
break;
}
case 'D':
if (ir.Event.KeyEvent.dwControlKeyState &
(LEFT_CTRL_PRESSED|RIGHT_CTRL_PRESSED))
{
ClearCommandLine (str, maxlen, orgx, orgy);
History_del_current_entry(str);
current = charcount = _tcslen (str);
ConOutPrintf (_T("%s"), str);
break;
}
#endif/*FEATURE_HISTORY*/
#endif/*0*/
default: default:
#ifdef _UNICODE #ifdef _UNICODE
ch = ir.Event.KeyEvent.uChar.UnicodeChar; ch = ir.Event.KeyEvent.uChar.UnicodeChar;
@ -477,22 +494,24 @@ VOID ReadCommand (LPTSTR str, INT maxlen)
/* insert character into string... */ /* insert character into string... */
if (bInsert && current != charcount) if (bInsert && current != charcount)
{ {
/* If this character insertion will cause screen scrolling,
* adjust the saved origin of the command prompt. */
tempscreen = _tcslen(str + current) + curx;
if ((tempscreen % maxx) == (maxx - 1) &&
(tempscreen / maxx) + cury == (maxy - 1))
{
orgy--;
cury--;
}
for (count = charcount; count > current; count--) for (count = charcount; count > current; count--)
str[count] = str[count - 1]; str[count] = str[count - 1];
str[current++] = ch; str[current++] = ch;
if (GetCursorX () == maxx - 1) if (curx == maxx - 1)
{ curx = 0, cury++;
curx = 0;
cury = GetCursorY () + 1;
}
else else
{
GetCursorXY (&curx, &cury);
curx++; curx++;
}
ConOutPrintf (_T("%s"), &str[current - 1]); ConOutPrintf (_T("%s"), &str[current - 1]);
if ((_tcslen (str) > (USHORT)(maxx - orgx)) && (orgy == maxy + 1))
cury--;
SetCursorXY (curx, cury); SetCursorXY (curx, cury);
charcount++; charcount++;
} }
@ -501,10 +520,14 @@ VOID ReadCommand (LPTSTR str, INT maxlen)
if (current == charcount) if (current == charcount)
charcount++; charcount++;
str[current++] = ch; str[current++] = ch;
if (GetCursorX () == maxx - 1 && GetCursorY () == maxy - 1)
orgy--, cury--;
if (GetCursorX () == maxx - 1)
curx = 0, cury++;
else
curx++;
ConOutChar (ch); ConOutChar (ch);
} }
if ((_tcslen (str) > (USHORT)(maxx - orgx)) && (orgy == maxy + 1))
orgy--;
} }
#if 0 #if 0
else else

View file

@ -1,4 +1,4 @@
/* $Id: console.c,v 1.4 2003/08/13 05:18:40 jimtabor Exp $ /* $Id: console.c,v 1.5 2004/04/30 16:52:41 navaraf Exp $
* *
* CONSOLE.C - console input/output functions. * CONSOLE.C - console input/output functions.
* *
@ -106,8 +106,8 @@ VOID ConInString (LPTSTR lpInput, DWORD dwLength)
DWORD i; DWORD i;
PCHAR pBuf; PCHAR pBuf;
#ifdef UNICODE #ifdef _UNICODE
pBuf = (PCHAR)alloca(dwLength); pBuf = (PCHAR)malloc(dwLength);
#else #else
pBuf = lpInput; pBuf = lpInput;
#endif #endif
@ -132,6 +132,10 @@ VOID ConInString (LPTSTR lpInput, DWORD dwLength)
} }
} }
#ifdef _UNICODE
free(pBuf);
#endif
SetConsoleMode (hFile, dwOldMode); SetConsoleMode (hFile, dwOldMode);
} }
@ -169,7 +173,7 @@ VOID ConPuts(LPTSTR szText, DWORD nStdHandle)
len = _tcslen(szText); len = _tcslen(szText);
#ifdef _UNICODE #ifdef _UNICODE
pBuf = alloca(len + 1); pBuf = malloc(len + 1);
len = WideCharToMultiByte(CP_ACP, 0, szText, len + 1, pBuf, len + 1, NULL, NULL) - 1; len = WideCharToMultiByte(CP_ACP, 0, szText, len + 1, pBuf, len + 1, NULL, NULL) - 1;
#else #else
pBuf = szText; pBuf = szText;
@ -184,6 +188,9 @@ VOID ConPuts(LPTSTR szText, DWORD nStdHandle)
1, 1,
&dwWritten, &dwWritten,
NULL); NULL);
#ifdef UNICODE
free(pBuf);
#endif
} }
VOID ConOutPuts (LPTSTR szText) VOID ConOutPuts (LPTSTR szText)
@ -201,7 +208,7 @@ VOID ConPrintf(LPTSTR szFormat, va_list arg_ptr, DWORD nStdHandle)
len = _vstprintf (szOut, szFormat, arg_ptr); len = _vstprintf (szOut, szFormat, arg_ptr);
#ifdef _UNICODE #ifdef _UNICODE
pBuf = alloca(len + 1); pBuf = malloc(len + 1);
len = WideCharToMultiByte(CP_ACP, 0, szOut, len + 1, pBuf, len + 1, NULL, NULL) - 1; len = WideCharToMultiByte(CP_ACP, 0, szOut, len + 1, pBuf, len + 1, NULL, NULL) - 1;
#else #else
pBuf = szOut; pBuf = szOut;
@ -211,6 +218,9 @@ VOID ConPrintf(LPTSTR szFormat, va_list arg_ptr, DWORD nStdHandle)
len, len,
&dwWritten, &dwWritten,
NULL); NULL);
#ifdef UNICODE
free(pBuf);
#endif
} }

View file

@ -1,4 +1,4 @@
/* $Id: dir.c,v 1.8 2004/01/28 17:47:27 gvg Exp $ /* $Id: dir.c,v 1.9 2004/04/30 16:52:41 navaraf Exp $
* *
* DIR.C - dir internal command. * DIR.C - dir internal command.
* *
@ -116,6 +116,9 @@
* *
* 28-Jan-2004 (Michael Fritscher <michael@fritscher.net>) * 28-Jan-2004 (Michael Fritscher <michael@fritscher.net>)
* Fix for /p, so it is working under Windows in GUI-mode, too. * Fix for /p, so it is working under Windows in GUI-mode, too.
*
* 30-Apr-2004 (Filip Navara <xnavara@volny.cz>)
* Fix /w to print long names.
*/ */
#include "config.h" #include "config.h"
@ -131,10 +134,6 @@
#include "cmd.h" #include "cmd.h"
typedef BOOL STDCALL
(*PGETFREEDISKSPACEEX)(LPCTSTR, PULARGE_INTEGER, PULARGE_INTEGER, PULARGE_INTEGER);
/* flag definitions */ /* flag definitions */
enum enum
{ {
@ -150,6 +149,10 @@ enum
}; };
typedef BOOL STDCALL
(*PGETFREEDISKSPACEEX)(LPCTSTR, PULARGE_INTEGER, PULARGE_INTEGER, PULARGE_INTEGER);
/* Globally save the # of dirs, files and bytes, /* Globally save the # of dirs, files and bytes,
* probabaly later pass them to functions. Rob Lake */ * probabaly later pass them to functions. Rob Lake */
static ULONG recurse_dir_cnt; static ULONG recurse_dir_cnt;
@ -282,19 +285,36 @@ DirReadParam (LPTSTR line, LPTSTR *param, LPDWORD lpFlags)
{ {
if (*param) if (*param)
{ {
error_too_many_parameters (*param); error_too_many_parameters (line);
return FALSE; return FALSE;
} }
*param = line; *param = line;
/* skip to end of line or next whitespace or next / */ /* skip to end of line or next whitespace or next / */
if (*line != _T('\"'))
{
while (*line && !_istspace (*line) && *line != _T('/')) while (*line && !_istspace (*line) && *line != _T('/'))
line++; line++;
/* if end of line, return */ /* if end of line, return */
if (!*line) if (!*line)
return TRUE; return TRUE;
}
else
{
/* skip over the initial quote */
(*param)++;
line++;
while (*line && *line != _T('"'))
line++;
if (*line == _T('"'))
*line = 0;
else
return TRUE;
}
/* if parameter, remember to process it later */ /* if parameter, remember to process it later */
if (*line == _T('/')) if (*line == _T('/'))
@ -843,6 +863,8 @@ DirList (LPTSTR szPath, LPTSTR szFilespec, LPINT pLine, DWORD dwFlags)
ULONG filecount = 0; ULONG filecount = 0;
ULONG dircount = 0; ULONG dircount = 0;
INT count; INT count;
USHORT screenwidth;
INT longestfname = 0;
bytecount.QuadPart = 0; bytecount.QuadPart = 0;
@ -869,6 +891,34 @@ DirList (LPTSTR szPath, LPTSTR szFilespec, LPINT pLine, DWORD dwFlags)
return 0; return 0;
} }
/* Get the size of longest filename for wide listing. FN */
if (dwFlags & DIR_WIDE && (dwFlags & DIR_BARE) == 0)
{
do
{
if (_tcslen(file.cFileName) > longestfname)
{
longestfname = _tcslen(file.cFileName);
/* Directories get extra brackets around them. */
if (file.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY)
longestfname += 2;
}
}
while (FindNextFile (hFile, &file));
FindClose (hFile);
hFile = FindFirstFile (szFullPath, &file);
/* Count the highest number of columns */
GetScreenSize(&screenwidth, 0);
/* For counting columns of output */
count = 0;
/* Increase by the number of spaces behind file name */
longestfname += 3;
}
/* moved down here because if we are recursively searching and /* moved down here because if we are recursively searching and
* don't find any files, we don't want just to print * don't find any files, we don't want just to print
* Directory of C:\SOMEDIR * Directory of C:\SOMEDIR
@ -885,9 +935,6 @@ DirList (LPTSTR szPath, LPTSTR szFilespec, LPINT pLine, DWORD dwFlags)
return 1; return 1;
} }
/* For counting columns of output */
count = 0;
do do
{ {
/* next file, if user doesn't want all files */ /* next file, if user doesn't want all files */
@ -907,26 +954,23 @@ DirList (LPTSTR szPath, LPTSTR szFilespec, LPINT pLine, DWORD dwFlags)
if (file.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY) if (file.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY)
{ {
if (file.cAlternateFileName[0] == _T('\0'))
_stprintf (buffer, _T("[%s]"), file.cFileName); _stprintf (buffer, _T("[%s]"), file.cFileName);
else
_stprintf (buffer, _T("[%s]"), file.cAlternateFileName);
dircount++; dircount++;
} }
else else
{ {
if (file.cAlternateFileName[0] == _T('\0'))
_stprintf (buffer, _T("%s"), file.cFileName); _stprintf (buffer, _T("%s"), file.cFileName);
else
_stprintf (buffer, _T("%s"), file.cAlternateFileName);
filecount++; filecount++;
} }
ConOutPrintf (_T("%-15s"), buffer); ConOutPrintf (_T("%*s"), - longestfname, buffer);
count++; count++;
if (count == 5) /* output as much columns as fits on the screen */
if (count >= (screenwidth / longestfname))
{ {
/* output 5 columns */ /* print the new line only if we aren't on the
* last column, in this case it wraps anyway */
if (count * longestfname != screenwidth)
ConOutPrintf (_T("\n")); ConOutPrintf (_T("\n"));
if (IncLine (pLine, dwFlags)) if (IncLine (pLine, dwFlags))
return 1; return 1;

View file

@ -1,4 +1,4 @@
/* $Id: echo.c,v 1.2 2003/08/07 09:27:42 hbirr Exp $ /* $Id: echo.c,v 1.3 2004/04/30 16:52:41 navaraf Exp $
* *
* ECHO.C - internal echo commands. * ECHO.C - internal echo commands.
* *
@ -42,13 +42,13 @@ INT CommandEcho (LPTSTR cmd, LPTSTR param)
if (!_tcsncmp (param, _T("/?"), 2)) if (!_tcsncmp (param, _T("/?"), 2))
{ {
ConOutPuts ("Displays a message or switches command echoing on or off.\n" ConOutPuts (_T("Displays a message or switches command echoing on or off.\n"
"\n" "\n"
" ECHO [ON | OFF]\n" " ECHO [ON | OFF]\n"
" ECHO [message]\n" " ECHO [message]\n"
" ECHO. prints an empty line\n" " ECHO. prints an empty line\n"
"\n" "\n"
"Type ECHO without a parameter to display the current ECHO setting."); "Type ECHO without a parameter to display the current ECHO setting."));
return 0; return 0;
} }

View file

@ -11,6 +11,9 @@
* *
* 25-Jan-1999 (Eric Kohl <ekohl@abo.rhein-zeitung.de>) * 25-Jan-1999 (Eric Kohl <ekohl@abo.rhein-zeitung.de>)
* Cleanup. Unicode safe! * Cleanup. Unicode safe!
*
* 30-Apr-2004 (Filip Navara <xnavara@volny.cz>)
* Make the file listing readable when there is a lot of long names.
*/ */
#include "config.h" #include "config.h"
@ -217,6 +220,8 @@ BOOL ShowCompletionMatches (LPTSTR str, INT charcount)
TCHAR path[MAX_PATH]; TCHAR path[MAX_PATH];
TCHAR fname[MAX_PATH]; TCHAR fname[MAX_PATH];
TCHAR directory[MAX_PATH]; TCHAR directory[MAX_PATH];
INT longestfname = 0;
SHORT screenwidth;
/* expand current file name */ /* expand current file name */
count = charcount - 1; count = charcount - 1;
@ -283,9 +288,33 @@ BOOL ShowCompletionMatches (LPTSTR str, INT charcount)
hFile = FindFirstFile (path, &file); hFile = FindFirstFile (path, &file);
if (hFile != INVALID_HANDLE_VALUE) if (hFile != INVALID_HANDLE_VALUE)
{ {
/* Get the size of longest filename first. */
do
{
if (_tcslen(file.cFileName) > longestfname)
{
longestfname = _tcslen(file.cFileName);
/* Directories get extra brackets around them. */
if (file.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY)
longestfname += 2;
}
}
while (FindNextFile (hFile, &file));
FindClose (hFile);
hFile = FindFirstFile (path, &file);
/* Count the highest number of columns */
GetScreenSize(&screenwidth, 0);
/* For counting columns of output */
count = 0;
/* Increase by the number of spaces behind file name */
longestfname += 3;
/* find anything */ /* find anything */
ConOutChar (_T('\n')); ConOutChar (_T('\n'));
count = 0;
do do
{ {
/* ignore . and .. */ /* ignore . and .. */
@ -298,10 +327,15 @@ BOOL ShowCompletionMatches (LPTSTR str, INT charcount)
else else
_tcscpy (fname, file.cFileName); _tcscpy (fname, file.cFileName);
ConOutPrintf (_T("%-14s"), fname); ConOutPrintf (_T("%*s"), - longestfname, fname);
if (++count == 5) count++;
/* output as much columns as fits on the screen */
if (count >= (screenwidth / longestfname))
{ {
ConOutChar (_T('\n')); /* print the new line only if we aren't on the
* last column, in this case it wraps anyway */
if (count * longestfname != screenwidth)
ConOutPrintf (_T("\n"));
count = 0; count = 0;
} }
} }

View file

@ -376,7 +376,7 @@ BOOL FileGetString (HANDLE hFile, LPTSTR lpBuffer, INT nBufferLength)
DWORD dwRead; DWORD dwRead;
INT len; INT len;
#ifdef _UNICODE #ifdef _UNICODE
lpString = alloca(nBufferLength); lpString = malloc(nBufferLength);
#else #else
lpString = lpBuffer; lpString = lpBuffer;
#endif #endif
@ -399,6 +399,7 @@ BOOL FileGetString (HANDLE hFile, LPTSTR lpBuffer, INT nBufferLength)
lpString[len++] = '\0'; lpString[len++] = '\0';
#ifdef _UNICODE #ifdef _UNICODE
MultiByteToWideChar(CP_ACP, 0, lpString, len, lpBuffer, len); MultiByteToWideChar(CP_ACP, 0, lpString, len, lpBuffer, len);
free(lpString);
#endif #endif
return TRUE; return TRUE;
} }

View file

@ -41,11 +41,11 @@ VOID ShortVersion (VOID)
VersionInfo.dwOSVersionInfoSize = sizeof(OSVERSIONINFO); VersionInfo.dwOSVersionInfoSize = sizeof(OSVERSIONINFO);
if (GetVersionEx(&VersionInfo) && 0 == _tcsnicmp(VersionInfo.szCSDVersion, _T("ReactOS"), 7)) if (GetVersionEx(&VersionInfo) && 0 == _tcsnicmp(VersionInfo.szCSDVersion, _T("ReactOS"), 7))
{ {
ConOutPrintf(_T("%s running on %s"), SHELLVER, VersionInfo.szCSDVersion); ConOutPrintf(_T("%S running on %s"), SHELLVER, VersionInfo.szCSDVersion);
} }
else else
{ {
ConOutPuts(SHELLVER); ConOutPrintf(_T("%S"), SHELLVER);
} }
ConOutPuts (_T("\n")); ConOutPuts (_T("\n"));
} }