mirror of
https://github.com/reactos/reactos.git
synced 2024-12-26 00:54:40 +00:00
New Y command and some fixes.
svn path=/trunk/; revision=753
This commit is contained in:
parent
18a01fd10d
commit
6758f479ef
3 changed files with 146 additions and 3 deletions
|
@ -2,7 +2,7 @@
|
|||
# ReactOS cmdutils makefile
|
||||
#
|
||||
|
||||
TARGET=more.exe tee.exe
|
||||
TARGET=more.exe tee.exe y.exe
|
||||
|
||||
all: $(TARGET)
|
||||
|
||||
|
@ -17,6 +17,9 @@ tee.exe: tee.o
|
|||
$(CC) tee.o -lkernel32 -lcrtdll -o tee.exe
|
||||
$(NM) --numeric-sort tee.exe > tee.sym
|
||||
|
||||
y.exe: y.o
|
||||
$(CC) y.o -lkernel32 -lcrtdll -o y.exe
|
||||
$(NM) --numeric-sort y.exe > y.sym
|
||||
|
||||
clean: $(CLEAN_FILES:%=%_clean)
|
||||
|
||||
|
|
|
@ -36,6 +36,17 @@ GetScreenSize (PSHORT maxx, PSHORT maxy)
|
|||
*maxy = csbi.dwSize.Y;
|
||||
}
|
||||
|
||||
|
||||
static
|
||||
VOID ConOutPuts (LPTSTR szText)
|
||||
{
|
||||
DWORD dwWritten;
|
||||
|
||||
WriteFile (GetStdHandle (STD_OUTPUT_HANDLE), szText, _tcslen(szText), &dwWritten, NULL);
|
||||
WriteFile (GetStdHandle (STD_OUTPUT_HANDLE), "\n", 1, &dwWritten, NULL);
|
||||
}
|
||||
|
||||
|
||||
static VOID
|
||||
ConInKey (VOID)
|
||||
{
|
||||
|
@ -86,11 +97,18 @@ int main (int argc, char **argv)
|
|||
|
||||
len = _tcslen (msg);
|
||||
hStdIn = GetStdHandle(STD_INPUT_HANDLE);
|
||||
hKeyboard = CreateFile ("CONIN$", GENERIC_READ,
|
||||
0,NULL,OPEN_ALWAYS,0,0);
|
||||
hStdOut = GetStdHandle(STD_OUTPUT_HANDLE);
|
||||
hStdErr = GetStdHandle(STD_ERROR_HANDLE);
|
||||
|
||||
if (_tcsncmp (argv[1], _T("/?"), 2) == 0)
|
||||
{
|
||||
ConOutPuts(_T("Help text still missing!!"));
|
||||
return 0;
|
||||
}
|
||||
|
||||
hKeyboard = CreateFile ("CONIN$", GENERIC_READ,
|
||||
0,NULL,OPEN_ALWAYS,0,0);
|
||||
|
||||
GetScreenSize(&maxx,&maxy);
|
||||
|
||||
buff=malloc(maxx);
|
||||
|
|
122
rosapps/cmdutils/y.c
Normal file
122
rosapps/cmdutils/y.c
Normal file
|
@ -0,0 +1,122 @@
|
|||
/*
|
||||
* Y.C - Y external command.
|
||||
*
|
||||
* clone from 4nt y command
|
||||
*
|
||||
* 02 Oct 1999 (Paolo Pantaleo)
|
||||
* started
|
||||
*
|
||||
*
|
||||
*/
|
||||
|
||||
#define BUFF_SIZE 4096
|
||||
|
||||
#include <windows.h>
|
||||
#include <stdio.h>
|
||||
#include <tchar.h>
|
||||
|
||||
static
|
||||
VOID ConErrPrintf (LPTSTR szFormat, ...)
|
||||
{
|
||||
DWORD dwWritten;
|
||||
TCHAR szOut[BUFF_SIZE];
|
||||
va_list arg_ptr;
|
||||
|
||||
va_start (arg_ptr, szFormat);
|
||||
_vstprintf (szOut, szFormat, arg_ptr);
|
||||
va_end (arg_ptr);
|
||||
|
||||
WriteFile (GetStdHandle (STD_ERROR_HANDLE), szOut, _tcslen(szOut), &dwWritten, NULL);
|
||||
}
|
||||
|
||||
|
||||
static
|
||||
VOID ConOutPuts (LPTSTR szText)
|
||||
{
|
||||
DWORD dwWritten;
|
||||
|
||||
WriteFile (GetStdHandle (STD_OUTPUT_HANDLE), szText, _tcslen(szText), &dwWritten, NULL);
|
||||
WriteFile (GetStdHandle (STD_OUTPUT_HANDLE), "\n", 1, &dwWritten, NULL);
|
||||
}
|
||||
|
||||
|
||||
int main (int argc, char **argv)
|
||||
{
|
||||
INT i;
|
||||
HANDLE hFind;
|
||||
HANDLE hConsoleIn, hConsoleOut, hFile;
|
||||
char buff[BUFF_SIZE];
|
||||
DWORD dwRead,dwWritten;
|
||||
BOOL bRet;
|
||||
WIN32_FIND_DATA FindData;
|
||||
|
||||
hConsoleIn = GetStdHandle(STD_INPUT_HANDLE);
|
||||
hConsoleOut = GetStdHandle(STD_OUTPUT_HANDLE);
|
||||
|
||||
if (_tcsncmp (argv[1], _T("/?"), 2) == 0)
|
||||
{
|
||||
ConOutPuts(_T("copy stdin to stdout and then files to stdout\n"
|
||||
"\n"
|
||||
"Y [files]\n"
|
||||
"\n"
|
||||
"files files to copy to stdout"));
|
||||
return 0;
|
||||
}
|
||||
|
||||
/*stdin to stdout*/
|
||||
do
|
||||
{
|
||||
bRet = ReadFile(hConsoleIn,buff,sizeof(buff),&dwRead,NULL);
|
||||
|
||||
if (dwRead>0 && bRet)
|
||||
WriteFile(hConsoleOut,buff,dwRead,&dwWritten,NULL);
|
||||
|
||||
} while(dwRead>0 && bRet);
|
||||
|
||||
|
||||
/*files to stdout*/
|
||||
Sleep(0);
|
||||
|
||||
for (i = 1; i < argc; i++)
|
||||
{
|
||||
hFind=FindFirstFile(argv[i],&FindData);
|
||||
|
||||
if (hFind==INVALID_HANDLE_VALUE)
|
||||
{
|
||||
ConErrPrintf("File not found - %s\n",argv[i]);
|
||||
continue;
|
||||
}
|
||||
|
||||
do
|
||||
{
|
||||
hFile = CreateFile(FindData.cFileName,
|
||||
GENERIC_READ,
|
||||
FILE_SHARE_READ,NULL,
|
||||
OPEN_EXISTING,
|
||||
FILE_ATTRIBUTE_NORMAL,NULL);
|
||||
|
||||
if(hFile == INVALID_HANDLE_VALUE)
|
||||
{
|
||||
ConErrPrintf("File not found - %s\n",FindData.cFileName);
|
||||
continue;
|
||||
}
|
||||
|
||||
do
|
||||
{
|
||||
bRet = ReadFile(hFile,buff,sizeof(buff),&dwRead,NULL);
|
||||
|
||||
if (dwRead>0 && bRet)
|
||||
WriteFile(hConsoleOut,buff,dwRead,&dwWritten,NULL);
|
||||
|
||||
} while(dwRead>0 && bRet);
|
||||
|
||||
CloseHandle(hFile);
|
||||
|
||||
}
|
||||
while(FindNextFile(hFind,&FindData));
|
||||
|
||||
FindClose(hFile);
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
Loading…
Reference in a new issue