2006-02-16 23:23:37 +00:00
|
|
|
/*
|
|
|
|
* MISC.C - misc. functions.
|
|
|
|
*
|
|
|
|
*
|
|
|
|
* History:
|
|
|
|
*
|
|
|
|
* 07/12/98 (Rob Lake)
|
|
|
|
* started
|
|
|
|
*
|
|
|
|
* 07/13/98 (Rob Lake)
|
|
|
|
* moved functions in here
|
|
|
|
*
|
|
|
|
* 27-Jul-1998 (John P Price <linux-guru@gcfl.net>)
|
|
|
|
* added config.h include
|
|
|
|
*
|
2007-05-05 11:32:25 +00:00
|
|
|
* 18-Dec-1998 (Eric Kohl)
|
2006-02-16 23:23:37 +00:00
|
|
|
* Changed split() to accept quoted arguments.
|
|
|
|
* Removed parse_firstarg().
|
|
|
|
*
|
2007-05-05 11:32:25 +00:00
|
|
|
* 23-Jan-1999 (Eric Kohl)
|
2006-02-16 23:23:37 +00:00
|
|
|
* Fixed an ugly bug in split(). In rare cases (last character
|
|
|
|
* of the string is a space) it ignored the NULL character and
|
|
|
|
* tried to add the following to the argument list.
|
|
|
|
*
|
2007-05-05 11:32:25 +00:00
|
|
|
* 28-Jan-1999 (Eric Kohl)
|
2006-02-16 23:23:37 +00:00
|
|
|
* FileGetString() seems to be working now.
|
|
|
|
*
|
2007-05-05 11:32:25 +00:00
|
|
|
* 06-Nov-1999 (Eric Kohl)
|
2006-02-16 23:23:37 +00:00
|
|
|
* Added PagePrompt() and FilePrompt().
|
|
|
|
*
|
|
|
|
* 30-Apr-2005 (Magnus Olsen) <magnus@greatlord.com>)
|
|
|
|
* Remove all hardcode string to En.rc
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include <precomp.h>
|
|
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
* get a character out-of-band and honor Ctrl-Break characters
|
|
|
|
*/
|
2009-08-02 17:38:27 +00:00
|
|
|
TCHAR
|
|
|
|
cgetchar (VOID)
|
2006-02-16 23:23:37 +00:00
|
|
|
{
|
|
|
|
HANDLE hInput = GetStdHandle (STD_INPUT_HANDLE);
|
|
|
|
INPUT_RECORD irBuffer;
|
|
|
|
DWORD dwRead;
|
2009-04-01 03:54:45 +00:00
|
|
|
|
2006-02-16 23:23:37 +00:00
|
|
|
do
|
|
|
|
{
|
|
|
|
ReadConsoleInput (hInput, &irBuffer, 1, &dwRead);
|
|
|
|
if ((irBuffer.EventType == KEY_EVENT) &&
|
|
|
|
(irBuffer.Event.KeyEvent.bKeyDown == TRUE))
|
|
|
|
{
|
|
|
|
if (irBuffer.Event.KeyEvent.dwControlKeyState &
|
|
|
|
(LEFT_CTRL_PRESSED | RIGHT_CTRL_PRESSED))
|
|
|
|
{
|
|
|
|
if (irBuffer.Event.KeyEvent.wVirtualKeyCode == 'C')
|
|
|
|
{
|
2009-04-01 03:54:45 +00:00
|
|
|
bCtrlBreak = TRUE;
|
|
|
|
break;
|
2006-02-16 23:23:37 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
else if ((irBuffer.Event.KeyEvent.wVirtualKeyCode == VK_SHIFT) ||
|
|
|
|
(irBuffer.Event.KeyEvent.wVirtualKeyCode == VK_MENU) ||
|
|
|
|
(irBuffer.Event.KeyEvent.wVirtualKeyCode == VK_CONTROL))
|
|
|
|
{
|
|
|
|
;
|
|
|
|
}
|
2007-10-19 23:21:45 +00:00
|
|
|
|
2006-02-16 23:23:37 +00:00
|
|
|
else
|
|
|
|
{
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
while (TRUE);
|
|
|
|
|
|
|
|
#ifndef _UNICODE
|
|
|
|
return irBuffer.Event.KeyEvent.uChar.AsciiChar;
|
|
|
|
#else
|
|
|
|
return irBuffer.Event.KeyEvent.uChar.UnicodeChar;
|
|
|
|
#endif /* _UNICODE */
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Takes a path in and returns it with the correct case of the letters
|
|
|
|
*/
|
|
|
|
VOID GetPathCase( TCHAR * Path, TCHAR * OutPath)
|
|
|
|
{
|
2007-08-26 23:56:05 +00:00
|
|
|
UINT i = 0;
|
2007-10-19 23:21:45 +00:00
|
|
|
TCHAR TempPath[MAX_PATH];
|
2006-02-16 23:23:37 +00:00
|
|
|
WIN32_FIND_DATA FindFileData;
|
|
|
|
HANDLE hFind;
|
|
|
|
_tcscpy(TempPath, _T(""));
|
|
|
|
_tcscpy(OutPath, _T(""));
|
|
|
|
|
2007-10-19 23:21:45 +00:00
|
|
|
|
2006-02-16 23:23:37 +00:00
|
|
|
for(i = 0; i < _tcslen(Path); i++)
|
|
|
|
{
|
|
|
|
if(Path[i] != _T('\\'))
|
|
|
|
{
|
|
|
|
_tcsncat(TempPath, &Path[i], 1);
|
|
|
|
if(i != _tcslen(Path) - 1)
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
/* Handle the base part of the path different.
|
|
|
|
Because if you put it into findfirstfile, it will
|
|
|
|
return your current folder */
|
|
|
|
if(_tcslen(TempPath) == 2 && TempPath[1] == _T(':'))
|
|
|
|
{
|
|
|
|
_tcscat(OutPath, TempPath);
|
|
|
|
_tcscat(OutPath, _T("\\"));
|
|
|
|
_tcscat(TempPath, _T("\\"));
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
hFind = FindFirstFile(TempPath,&FindFileData);
|
|
|
|
if(hFind == INVALID_HANDLE_VALUE)
|
|
|
|
{
|
|
|
|
_tcscpy(OutPath, Path);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
_tcscat(TempPath, _T("\\"));
|
|
|
|
_tcscat(OutPath, FindFileData.cFileName);
|
|
|
|
_tcscat(OutPath, _T("\\"));
|
2007-07-29 19:53:17 +00:00
|
|
|
FindClose(hFind);
|
2006-02-16 23:23:37 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Check if Ctrl-Break was pressed during the last calls
|
|
|
|
*/
|
|
|
|
|
|
|
|
BOOL CheckCtrlBreak (INT mode)
|
|
|
|
{
|
|
|
|
static BOOL bLeaveAll = FALSE; /* leave all batch files */
|
2009-03-20 23:16:12 +00:00
|
|
|
TCHAR options[4]; /* Yes, No, All */
|
2006-02-16 23:23:37 +00:00
|
|
|
TCHAR c;
|
|
|
|
|
|
|
|
switch (mode)
|
|
|
|
{
|
|
|
|
case BREAK_OUTOFBATCH:
|
|
|
|
bLeaveAll = 0;
|
|
|
|
return FALSE;
|
|
|
|
|
|
|
|
case BREAK_BATCHFILE:
|
|
|
|
if (bLeaveAll)
|
|
|
|
return TRUE;
|
|
|
|
|
|
|
|
if (!bCtrlBreak)
|
|
|
|
return FALSE;
|
|
|
|
|
2009-03-20 23:16:12 +00:00
|
|
|
LoadString(CMD_ModuleHandle, STRING_COPY_OPTION, options, 4);
|
|
|
|
|
2006-02-16 23:23:37 +00:00
|
|
|
/* we need to be sure the string arrives on the screen! */
|
|
|
|
do
|
2009-03-20 23:16:12 +00:00
|
|
|
{
|
|
|
|
ConOutResPuts(STRING_CANCEL_BATCH_FILE);
|
|
|
|
c = _totupper(cgetchar());
|
|
|
|
} while (!(_tcschr(options, c) || c == _T('\3')) || !c);
|
2006-02-16 23:23:37 +00:00
|
|
|
|
|
|
|
ConOutPuts (_T("\r\n"));
|
|
|
|
|
2009-03-20 23:16:12 +00:00
|
|
|
if (c == options[1])
|
2006-02-16 23:23:37 +00:00
|
|
|
return bCtrlBreak = FALSE; /* ignore */
|
|
|
|
|
|
|
|
/* leave all batch files */
|
2009-03-20 23:16:12 +00:00
|
|
|
bLeaveAll = ((c == options[2]) || (c == _T('\3')));
|
2006-02-16 23:23:37 +00:00
|
|
|
break;
|
|
|
|
|
|
|
|
case BREAK_INPUT:
|
|
|
|
if (!bCtrlBreak)
|
|
|
|
return FALSE;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* state processed */
|
|
|
|
bCtrlBreak = FALSE;
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* add new entry for new argument */
|
|
|
|
BOOL add_entry (LPINT ac, LPTSTR **arg, LPCTSTR entry)
|
|
|
|
{
|
|
|
|
LPTSTR q;
|
|
|
|
LPTSTR *oldarg;
|
|
|
|
|
2007-08-01 10:17:13 +00:00
|
|
|
q = cmd_alloc ((_tcslen(entry) + 1) * sizeof (TCHAR));
|
2006-02-16 23:23:37 +00:00
|
|
|
if (NULL == q)
|
|
|
|
{
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
2007-08-01 13:27:16 +00:00
|
|
|
_tcscpy (q, entry);
|
2006-02-16 23:23:37 +00:00
|
|
|
oldarg = *arg;
|
2007-08-01 10:17:13 +00:00
|
|
|
*arg = cmd_realloc (oldarg, (*ac + 2) * sizeof (LPTSTR));
|
2006-02-16 23:23:37 +00:00
|
|
|
if (NULL == *arg)
|
|
|
|
{
|
|
|
|
*arg = oldarg;
|
|
|
|
return FALSE;
|
|
|
|
}
|
2007-08-01 13:27:16 +00:00
|
|
|
|
2006-02-16 23:23:37 +00:00
|
|
|
/* save new entry */
|
|
|
|
(*arg)[*ac] = q;
|
|
|
|
(*arg)[++(*ac)] = NULL;
|
|
|
|
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
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)
|
|
|
|
{
|
2007-08-01 10:17:13 +00:00
|
|
|
dirpart = cmd_alloc((pathend - pattern + 2) * sizeof(TCHAR));
|
2006-02-16 23:23:37 +00:00
|
|
|
if (NULL == dirpart)
|
|
|
|
{
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
memcpy(dirpart, pattern, pathend - pattern + 1);
|
|
|
|
dirpart[pathend - pattern + 1] = _T('\0');
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
dirpart = NULL;
|
|
|
|
}
|
|
|
|
hFind = FindFirstFile (pattern, &FindData);
|
|
|
|
if (INVALID_HANDLE_VALUE != hFind)
|
|
|
|
{
|
|
|
|
do
|
|
|
|
{
|
|
|
|
if (NULL != dirpart)
|
|
|
|
{
|
2007-08-01 10:17:13 +00:00
|
|
|
fullname = cmd_alloc((_tcslen(dirpart) + _tcslen(FindData.cFileName) + 1) * sizeof(TCHAR));
|
2006-02-16 23:23:37 +00:00
|
|
|
if (NULL == fullname)
|
|
|
|
{
|
|
|
|
ok = FALSE;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
_tcscat (_tcscpy (fullname, dirpart), FindData.cFileName);
|
|
|
|
ok = add_entry(ac, arg, fullname);
|
2007-08-01 10:17:13 +00:00
|
|
|
cmd_free (fullname);
|
2006-02-16 23:23:37 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
ok = add_entry(ac, arg, FindData.cFileName);
|
|
|
|
}
|
|
|
|
} while (FindNextFile (hFind, &FindData) && ok);
|
|
|
|
FindClose (hFind);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
ok = add_entry(ac, arg, pattern);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (NULL != dirpart)
|
|
|
|
{
|
2007-08-01 10:17:13 +00:00
|
|
|
cmd_free (dirpart);
|
2006-02-16 23:23:37 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return ok;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* split - splits a line up into separate arguments, deliminators
|
|
|
|
* are spaces and slashes ('/').
|
|
|
|
*/
|
|
|
|
|
|
|
|
LPTSTR *split (LPTSTR s, LPINT args, BOOL expand_wildcards)
|
|
|
|
{
|
|
|
|
LPTSTR *arg;
|
|
|
|
LPTSTR start;
|
|
|
|
LPTSTR q;
|
|
|
|
INT ac;
|
|
|
|
INT len;
|
|
|
|
|
2007-08-01 10:17:13 +00:00
|
|
|
arg = cmd_alloc (sizeof (LPTSTR));
|
2006-02-16 23:23:37 +00:00
|
|
|
if (!arg)
|
|
|
|
return NULL;
|
|
|
|
*arg = NULL;
|
|
|
|
|
|
|
|
ac = 0;
|
|
|
|
while (*s)
|
|
|
|
{
|
2009-01-25 16:39:06 +00:00
|
|
|
BOOL bQuoted = FALSE;
|
|
|
|
|
2006-02-16 23:23:37 +00:00
|
|
|
/* skip leading spaces */
|
|
|
|
while (*s && (_istspace (*s) || _istcntrl (*s)))
|
|
|
|
++s;
|
|
|
|
|
|
|
|
start = s;
|
|
|
|
|
|
|
|
/* the first character can be '/' */
|
|
|
|
if (*s == _T('/'))
|
|
|
|
++s;
|
|
|
|
|
|
|
|
/* skip to next word delimiter or start of next option */
|
2009-01-25 16:39:06 +00:00
|
|
|
while (_istprint(*s) && (bQuoted || (!_istspace(*s) && *s != _T('/'))))
|
2006-02-16 23:23:37 +00:00
|
|
|
{
|
2009-01-25 16:39:06 +00:00
|
|
|
/* if quote (") then set bQuoted */
|
|
|
|
bQuoted ^= (*s == _T('\"'));
|
|
|
|
++s;
|
2006-02-16 23:23:37 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/* a word was found */
|
|
|
|
if (s != start)
|
|
|
|
{
|
2007-08-01 10:17:13 +00:00
|
|
|
q = cmd_alloc (((len = s - start) + 1) * sizeof (TCHAR));
|
2006-02-16 23:23:37 +00:00
|
|
|
if (!q)
|
|
|
|
{
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
memcpy (q, start, len * sizeof (TCHAR));
|
|
|
|
q[len] = _T('\0');
|
2009-01-25 16:39:06 +00:00
|
|
|
StripQuotes(q);
|
2006-02-16 23:23:37 +00:00
|
|
|
if (expand_wildcards && _T('/') != *start &&
|
|
|
|
(NULL != _tcschr(q, _T('*')) || NULL != _tcschr(q, _T('?'))))
|
|
|
|
{
|
|
|
|
if (! expand(&ac, &arg, q))
|
|
|
|
{
|
2007-08-01 10:17:13 +00:00
|
|
|
cmd_free (q);
|
2006-02-16 23:23:37 +00:00
|
|
|
freep (arg);
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
if (! add_entry(&ac, &arg, q))
|
|
|
|
{
|
2007-08-01 10:17:13 +00:00
|
|
|
cmd_free (q);
|
2006-02-16 23:23:37 +00:00
|
|
|
freep (arg);
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
}
|
2007-08-01 10:17:13 +00:00
|
|
|
cmd_free (q);
|
2006-02-16 23:23:37 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
*args = ac;
|
|
|
|
|
|
|
|
return arg;
|
|
|
|
}
|
|
|
|
|
2009-01-17 12:55:46 +00:00
|
|
|
/* splitspace() is a function which uses JUST spaces as delimeters. split() uses "/" AND spaces.
|
|
|
|
* The way it works is real similar to split(), search the difference ;)
|
|
|
|
* splitspace is needed for commands such as "move" where paths as C:\this/is\allowed/ are allowed
|
|
|
|
*/
|
|
|
|
LPTSTR *splitspace (LPTSTR s, LPINT args)
|
|
|
|
{
|
|
|
|
LPTSTR *arg;
|
|
|
|
LPTSTR start;
|
|
|
|
LPTSTR q;
|
|
|
|
INT ac;
|
|
|
|
INT len;
|
|
|
|
|
|
|
|
arg = cmd_alloc (sizeof (LPTSTR));
|
|
|
|
if (!arg)
|
|
|
|
return NULL;
|
|
|
|
*arg = NULL;
|
|
|
|
|
|
|
|
ac = 0;
|
|
|
|
while (*s)
|
|
|
|
{
|
2009-01-25 16:39:06 +00:00
|
|
|
BOOL bQuoted = FALSE;
|
|
|
|
|
2009-01-17 12:55:46 +00:00
|
|
|
/* skip leading spaces */
|
|
|
|
while (*s && (_istspace (*s) || _istcntrl (*s)))
|
|
|
|
++s;
|
|
|
|
|
|
|
|
start = s;
|
|
|
|
|
|
|
|
/* skip to next word delimiter or start of next option */
|
2009-01-25 16:39:06 +00:00
|
|
|
while (_istprint(*s) && (bQuoted || !_istspace(*s)))
|
2009-01-17 12:55:46 +00:00
|
|
|
{
|
2009-01-25 16:39:06 +00:00
|
|
|
/* if quote (") then set bQuoted */
|
|
|
|
bQuoted ^= (*s == _T('\"'));
|
|
|
|
++s;
|
2009-01-17 12:55:46 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/* a word was found */
|
|
|
|
if (s != start)
|
|
|
|
{
|
|
|
|
q = cmd_alloc (((len = s - start) + 1) * sizeof (TCHAR));
|
|
|
|
if (!q)
|
|
|
|
{
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
memcpy (q, start, len * sizeof (TCHAR));
|
|
|
|
q[len] = _T('\0');
|
2009-01-25 16:39:06 +00:00
|
|
|
StripQuotes(q);
|
2009-01-17 12:55:46 +00:00
|
|
|
if (! add_entry(&ac, &arg, q))
|
|
|
|
{
|
|
|
|
cmd_free (q);
|
|
|
|
freep (arg);
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
cmd_free (q);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
*args = ac;
|
|
|
|
|
|
|
|
return arg;
|
|
|
|
}
|
2006-02-16 23:23:37 +00:00
|
|
|
|
|
|
|
/*
|
|
|
|
* freep -- frees memory used for a call to split
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
VOID freep (LPTSTR *p)
|
|
|
|
{
|
|
|
|
LPTSTR *q;
|
|
|
|
|
|
|
|
if (!p)
|
|
|
|
return;
|
|
|
|
|
|
|
|
q = p;
|
|
|
|
while (*q)
|
2007-08-01 10:17:13 +00:00
|
|
|
cmd_free(*q++);
|
2006-02-16 23:23:37 +00:00
|
|
|
|
2007-08-01 10:17:13 +00:00
|
|
|
cmd_free(p);
|
2006-02-16 23:23:37 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
LPTSTR _stpcpy (LPTSTR dest, LPCTSTR src)
|
|
|
|
{
|
|
|
|
_tcscpy (dest, src);
|
|
|
|
return (dest + _tcslen (src));
|
|
|
|
}
|
|
|
|
|
2008-08-21 15:33:59 +00:00
|
|
|
VOID
|
|
|
|
StripQuotes(TCHAR *in)
|
|
|
|
{
|
|
|
|
TCHAR *out = in;
|
|
|
|
for (; *in; in++)
|
|
|
|
{
|
|
|
|
if (*in != _T('"'))
|
|
|
|
*out++ = *in;
|
|
|
|
}
|
|
|
|
*out = _T('\0');
|
|
|
|
}
|
|
|
|
|
2006-02-16 23:23:37 +00:00
|
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Checks if a path is valid (accessible)
|
|
|
|
*/
|
|
|
|
|
|
|
|
BOOL IsValidPathName (LPCTSTR pszPath)
|
|
|
|
{
|
|
|
|
TCHAR szOldPath[MAX_PATH];
|
|
|
|
BOOL bResult;
|
|
|
|
|
|
|
|
GetCurrentDirectory (MAX_PATH, szOldPath);
|
|
|
|
bResult = SetCurrentDirectory (pszPath);
|
|
|
|
|
|
|
|
SetCurrentDirectory (szOldPath);
|
|
|
|
|
|
|
|
return bResult;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Checks if a file exists (accessible)
|
|
|
|
*/
|
|
|
|
|
|
|
|
BOOL IsExistingFile (LPCTSTR pszPath)
|
|
|
|
{
|
|
|
|
DWORD attr = GetFileAttributes (pszPath);
|
|
|
|
return (attr != 0xFFFFFFFF && (! (attr & FILE_ATTRIBUTE_DIRECTORY)) );
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
BOOL IsExistingDirectory (LPCTSTR pszPath)
|
|
|
|
{
|
|
|
|
DWORD attr = GetFileAttributes (pszPath);
|
|
|
|
return (attr != 0xFFFFFFFF && (attr & FILE_ATTRIBUTE_DIRECTORY) );
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
BOOL FileGetString (HANDLE hFile, LPTSTR lpBuffer, INT nBufferLength)
|
|
|
|
{
|
|
|
|
LPSTR lpString;
|
|
|
|
DWORD dwRead;
|
2008-02-02 10:38:37 +00:00
|
|
|
INT len = 0;
|
2006-02-16 23:23:37 +00:00
|
|
|
#ifdef _UNICODE
|
2007-08-01 10:17:13 +00:00
|
|
|
lpString = cmd_alloc(nBufferLength);
|
2006-02-16 23:23:37 +00:00
|
|
|
#else
|
|
|
|
lpString = lpBuffer;
|
|
|
|
#endif
|
2009-03-02 20:00:26 +00:00
|
|
|
|
|
|
|
if (ReadFile(hFile, lpString, nBufferLength - 1, &dwRead, NULL))
|
2006-02-16 23:23:37 +00:00
|
|
|
{
|
2009-03-02 20:00:26 +00:00
|
|
|
/* break at new line*/
|
|
|
|
CHAR *end = memchr(lpString, '\n', dwRead);
|
|
|
|
len = dwRead;
|
|
|
|
if (end)
|
2006-02-16 23:23:37 +00:00
|
|
|
{
|
2009-03-02 20:00:26 +00:00
|
|
|
len = (end - lpString) + 1;
|
|
|
|
SetFilePointer(hFile, len - dwRead, NULL, FILE_CURRENT);
|
2006-02-16 23:23:37 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2009-03-02 20:00:26 +00:00
|
|
|
if (!len)
|
2007-08-01 22:50:58 +00:00
|
|
|
{
|
|
|
|
#ifdef _UNICODE
|
|
|
|
cmd_free(lpString);
|
|
|
|
#endif
|
2006-02-16 23:23:37 +00:00
|
|
|
return FALSE;
|
2007-08-01 22:50:58 +00:00
|
|
|
}
|
2006-02-16 23:23:37 +00:00
|
|
|
|
2009-02-28 18:00:38 +00:00
|
|
|
lpString[len++] = '\0';
|
2006-02-16 23:23:37 +00:00
|
|
|
#ifdef _UNICODE
|
2009-04-01 03:54:45 +00:00
|
|
|
MultiByteToWideChar(OutputCodePage, 0, lpString, -1, lpBuffer, len);
|
2007-08-01 10:17:13 +00:00
|
|
|
cmd_free(lpString);
|
2006-02-16 23:23:37 +00:00
|
|
|
#endif
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
INT PagePrompt (VOID)
|
|
|
|
{
|
|
|
|
INPUT_RECORD ir;
|
|
|
|
|
|
|
|
ConOutResPuts(STRING_MISC_HELP1);
|
|
|
|
|
|
|
|
RemoveBreakHandler ();
|
|
|
|
ConInDisable ();
|
|
|
|
|
|
|
|
do
|
|
|
|
{
|
|
|
|
ConInKey (&ir);
|
|
|
|
}
|
|
|
|
while ((ir.Event.KeyEvent.wVirtualKeyCode == VK_SHIFT) ||
|
|
|
|
(ir.Event.KeyEvent.wVirtualKeyCode == VK_MENU) ||
|
|
|
|
(ir.Event.KeyEvent.wVirtualKeyCode == VK_CONTROL));
|
|
|
|
|
|
|
|
AddBreakHandler ();
|
|
|
|
ConInEnable ();
|
|
|
|
|
|
|
|
if ((ir.Event.KeyEvent.wVirtualKeyCode == VK_ESCAPE) ||
|
|
|
|
((ir.Event.KeyEvent.wVirtualKeyCode == _T('C')) &&
|
|
|
|
(ir.Event.KeyEvent.dwControlKeyState & (LEFT_CTRL_PRESSED | RIGHT_CTRL_PRESSED))))
|
|
|
|
{
|
|
|
|
bCtrlBreak = TRUE;
|
|
|
|
return PROMPT_BREAK;
|
|
|
|
}
|
|
|
|
|
|
|
|
return PROMPT_YES;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2008-07-26 22:49:49 +00:00
|
|
|
INT FilePromptYN (UINT resID)
|
2006-02-16 23:23:37 +00:00
|
|
|
{
|
|
|
|
TCHAR szMsg[RC_STRING_MAX_SIZE];
|
|
|
|
// TCHAR cKey = 0;
|
|
|
|
// LPTSTR szKeys = _T("yna");
|
|
|
|
|
|
|
|
TCHAR szIn[10];
|
|
|
|
LPTSTR p;
|
|
|
|
|
2008-07-26 22:49:49 +00:00
|
|
|
if (resID != 0)
|
|
|
|
ConOutResPrintf (resID);
|
2006-02-16 23:23:37 +00:00
|
|
|
|
|
|
|
/* preliminary fix */
|
|
|
|
ConInString (szIn, 10);
|
|
|
|
ConOutPrintf (_T("\n"));
|
|
|
|
|
|
|
|
_tcsupr (szIn);
|
|
|
|
for (p = szIn; _istspace (*p); p++)
|
|
|
|
;
|
|
|
|
|
|
|
|
LoadString(CMD_ModuleHandle, STRING_CHOICE_OPTION, szMsg, RC_STRING_MAX_SIZE);
|
|
|
|
|
|
|
|
if (_tcsncmp(p, &szMsg[0], 1) == 0)
|
|
|
|
return PROMPT_YES;
|
|
|
|
else if (_tcsncmp(p, &szMsg[1], 1) == 0)
|
|
|
|
return PROMPT_NO;
|
|
|
|
#if 0
|
|
|
|
else if (*p == _T('\03'))
|
|
|
|
return PROMPT_BREAK;
|
|
|
|
#endif
|
|
|
|
|
|
|
|
return PROMPT_NO;
|
|
|
|
|
|
|
|
|
|
|
|
/* unfinished sollution */
|
|
|
|
#if 0
|
|
|
|
RemoveBreakHandler ();
|
|
|
|
ConInDisable ();
|
|
|
|
|
|
|
|
do
|
|
|
|
{
|
|
|
|
ConInKey (&ir);
|
|
|
|
cKey = _totlower (ir.Event.KeyEvent.uChar.AsciiChar);
|
|
|
|
if (_tcschr (szKeys, cKey[0]) == NULL)
|
|
|
|
cKey = 0;
|
|
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
while ((ir.Event.KeyEvent.wVirtualKeyCode == VK_SHIFT) ||
|
|
|
|
(ir.Event.KeyEvent.wVirtualKeyCode == VK_MENU) ||
|
|
|
|
(ir.Event.KeyEvent.wVirtualKeyCode == VK_CONTROL));
|
|
|
|
|
|
|
|
AddBreakHandler ();
|
|
|
|
ConInEnable ();
|
|
|
|
|
|
|
|
if ((ir.Event.KeyEvent.wVirtualKeyCode == VK_ESCAPE) ||
|
|
|
|
((ir.Event.KeyEvent.wVirtualKeyCode == 'C') &&
|
|
|
|
(ir.Event.KeyEvent.dwControlKeyState & (LEFT_CTRL_PRESSED | RIGHT_CTRL_PRESSED))))
|
|
|
|
return PROMPT_BREAK;
|
|
|
|
|
|
|
|
return PROMPT_YES;
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2008-07-26 22:49:49 +00:00
|
|
|
INT FilePromptYNA (UINT resID)
|
2006-02-16 23:23:37 +00:00
|
|
|
{
|
|
|
|
TCHAR szMsg[RC_STRING_MAX_SIZE];
|
|
|
|
// TCHAR cKey = 0;
|
|
|
|
// LPTSTR szKeys = _T("yna");
|
|
|
|
|
|
|
|
TCHAR szIn[10];
|
|
|
|
LPTSTR p;
|
|
|
|
|
2008-07-26 22:49:49 +00:00
|
|
|
if (resID != 0)
|
|
|
|
ConOutResPrintf (resID);
|
2006-02-16 23:23:37 +00:00
|
|
|
|
|
|
|
/* preliminary fix */
|
|
|
|
ConInString (szIn, 10);
|
|
|
|
ConOutPrintf (_T("\n"));
|
|
|
|
|
|
|
|
_tcsupr (szIn);
|
|
|
|
for (p = szIn; _istspace (*p); p++)
|
|
|
|
;
|
|
|
|
|
|
|
|
LoadString( CMD_ModuleHandle, STRING_COPY_OPTION, szMsg, RC_STRING_MAX_SIZE);
|
|
|
|
|
|
|
|
if (_tcsncmp(p, &szMsg[0], 1) == 0)
|
|
|
|
return PROMPT_YES;
|
|
|
|
else if (_tcsncmp(p, &szMsg[1], 1) == 0)
|
|
|
|
return PROMPT_NO;
|
|
|
|
else if (_tcsncmp(p, &szMsg[2], 1) == 0)
|
|
|
|
return PROMPT_ALL;
|
|
|
|
|
|
|
|
#if 0
|
|
|
|
else if (*p == _T('\03'))
|
|
|
|
return PROMPT_BREAK;
|
|
|
|
#endif
|
|
|
|
|
|
|
|
return PROMPT_NO;
|
|
|
|
|
|
|
|
|
|
|
|
/* unfinished sollution */
|
|
|
|
#if 0
|
|
|
|
RemoveBreakHandler ();
|
|
|
|
ConInDisable ();
|
|
|
|
|
|
|
|
do
|
|
|
|
{
|
|
|
|
ConInKey (&ir);
|
|
|
|
cKey = _totlower (ir.Event.KeyEvent.uChar.AsciiChar);
|
|
|
|
if (_tcschr (szKeys, cKey[0]) == NULL)
|
|
|
|
cKey = 0;
|
|
|
|
}
|
|
|
|
while ((ir.Event.KeyEvent.wVirtualKeyCode == VK_SHIFT) ||
|
|
|
|
(ir.Event.KeyEvent.wVirtualKeyCode == VK_MENU) ||
|
|
|
|
(ir.Event.KeyEvent.wVirtualKeyCode == VK_CONTROL));
|
|
|
|
|
|
|
|
AddBreakHandler ();
|
|
|
|
ConInEnable ();
|
|
|
|
|
|
|
|
if ((ir.Event.KeyEvent.wVirtualKeyCode == VK_ESCAPE) ||
|
|
|
|
((ir.Event.KeyEvent.wVirtualKeyCode == _T('C')) &&
|
|
|
|
(ir.Event.KeyEvent.dwControlKeyState & (LEFT_CTRL_PRESSED | RIGHT_CTRL_PRESSED))))
|
|
|
|
return PROMPT_BREAK;
|
|
|
|
|
|
|
|
return PROMPT_YES;
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
|
|
|
/* EOF */
|