New Y command and some fixes.
authorEric Kohl <eric.kohl@reactos.org>
Fri, 5 Nov 1999 20:41:17 +0000 (20:41 +0000)
committerEric Kohl <eric.kohl@reactos.org>
Fri, 5 Nov 1999 20:41:17 +0000 (20:41 +0000)
svn path=/trunk/; revision=753

rosapps/cmdutils/makefile
rosapps/cmdutils/more.c
rosapps/cmdutils/y.c [new file with mode: 0644]

index bbf679f..3065aa2 100644 (file)
@@ -2,7 +2,7 @@
 #  ReactOS cmdutils makefile
 #
 
 #  ReactOS cmdutils makefile
 #
 
-TARGET=more.exe tee.exe
+TARGET=more.exe tee.exe y.exe
 
 all: $(TARGET)
 
 
 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
 
        $(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)
 
 
 clean: $(CLEAN_FILES:%=%_clean)
 
index a13609d..bd340da 100644 (file)
@@ -36,6 +36,17 @@ GetScreenSize (PSHORT maxx, PSHORT maxy)
                *maxy = csbi.dwSize.Y;
 }
 
                *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)
 {
 static VOID
 ConInKey (VOID)
 {
@@ -86,11 +97,18 @@ int main (int argc, char **argv)
 
        len = _tcslen (msg);
        hStdIn = GetStdHandle(STD_INPUT_HANDLE);
 
        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);
 
        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);
        GetScreenSize(&maxx,&maxy);
 
        buff=malloc(maxx);
diff --git a/rosapps/cmdutils/y.c b/rosapps/cmdutils/y.c
new file mode 100644 (file)
index 0000000..82f6c17
--- /dev/null
@@ -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;
+}