From 5249698af33d21db7a4bd81d82c453fb53f4129a Mon Sep 17 00:00:00 2001 From: Eric Kohl Date: Sun, 12 Sep 1999 18:20:47 +0000 Subject: [PATCH] External TEE command. svn path=/trunk/; revision=658 --- rosapps/cmdutils/makefile | 46 ++++++++ rosapps/cmdutils/tee.c | 223 ++++++++++++++++++++++++++++++++++++++ 2 files changed, 269 insertions(+) create mode 100644 rosapps/cmdutils/makefile create mode 100644 rosapps/cmdutils/tee.c diff --git a/rosapps/cmdutils/makefile b/rosapps/cmdutils/makefile new file mode 100644 index 00000000000..59b0251fea9 --- /dev/null +++ b/rosapps/cmdutils/makefile @@ -0,0 +1,46 @@ +# +# ReactOS cmdutils makefile +# + +TARGET=tee.exe + +all: $(TARGET) + +OBJECTS = tee.o + +CLEAN_FILES = *.o *.exe *.sym *.coff + + +tee.exe: tee.o + $(CC) tee.o -lkernel32 -lcrtdll -o tee.exe + $(NM) --numeric-sort tee.exe > tee.sym + + +clean: $(CLEAN_FILES:%=%_clean) + +$(CLEAN_FILES:%=%_clean): %_clean: + - $(RM) $* + +.phony: clean $(CLEAN_FILES:%=%_clean) + + +floppy: $(TARGET:%=$(FLOPPY_DIR)/apps/%) + +$(TARGET:%=$(FLOPPY_DIR)/apps/%): $(FLOPPY_DIR)/apps/%: % +ifeq ($(DOSCLI),yes) + $(CP) $* $(FLOPPY_DIR)\apps\$* +else + $(CP) $* $(FLOPPY_DIR)/apps/$* +endif + + +dist: $(TARGET:%=../$(DIST_DIR)/%) + +$(TARGET:%=../$(DIST_DIR)/%): ../$(DIST_DIR)/%: % +ifeq ($(DOSCLI),yes) + $(CP) $* ..\$(DIST_DIR)\$* +else + $(CP) $* ../$(DIST_DIR)/$* +endif + +include ../rules.mak diff --git a/rosapps/cmdutils/tee.c b/rosapps/cmdutils/tee.c new file mode 100644 index 00000000000..f2981c96d7d --- /dev/null +++ b/rosapps/cmdutils/tee.c @@ -0,0 +1,223 @@ +/* + * TEE.C - external command. + * + * clone from 4nt tee command + * + * 01 Sep 1999 - Dr.F + * started + * + * + */ + + +#include +#include +#include +#include + + + +#define TEE_BUFFER_SIZE 8192 + +/*these are function that emulate the ones used in cmd*/ + +/*many of them are just copied in this file from their +original location*/ + +VOID ConOutPuts (LPTSTR szText) +{ + DWORD dwWritten; + + WriteFile (GetStdHandle (STD_OUTPUT_HANDLE), szText, _tcslen(szText), &dwWritten, NULL); +#if 0 + WriteFile (GetStdHandle (STD_OUTPUT_HANDLE), "\x0a\x0d", 2, &dwWritten, NULL); +#endif + WriteFile (GetStdHandle (STD_OUTPUT_HANDLE), "\n", 1, &dwWritten, NULL); +} + + +VOID ConErrPrintf (LPTSTR szFormat, ...) +{ + DWORD dwWritten; + TCHAR szOut[4096]; + 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); +} + + + +VOID error_sfile_not_found (LPTSTR f) +{ + ConErrPrintf (_T("Error opening file") _T(" - %s\n"), f); +} + + + + +VOID ConErrPuts (LPTSTR szText) +{ + ConErrPrintf("%s\n",szText ); +} + + +INT main (int argc,char **p) +{ + /*reading/writing buffer*/ + TCHAR buff[TEE_BUFFER_SIZE]; + + /*handle for file and console*/ + HANDLE hConsoleIn,hConsoleOut; + + /*bytes written by WriteFile and ReadFile*/ + DWORD dwRead,dwWritten; + + + BOOL bRet,bAppend=FALSE; + + + /*command line parsing stuff*/ + LPTSTR tmp; + INT i; + BOOL bQuote; + + /*file list implementation*/ + LPTSTR *files; + INT iFileCounter=0; + HANDLE *hFile; + + /*used to remove '"' (if any)*/ + INT add; + + DWORD dw; + + + if (argc < 2) + return 1; + + if (_tcsncmp (p[1], _T("/?"), 2) == 0) + { + ConOutPuts (_T("Copy standard input to both standard output and a file.\n" + "\n" + "TEE [/A] file...\n" + "\n" + " file One or more files that will receive output.\n" + " /A Append output to files.\n")); + return 0; + } + + files = malloc(sizeof(LPTSTR)*argc); + hFile = malloc(sizeof(HANDLE)*argc); + + hConsoleIn=GetStdHandle(STD_INPUT_HANDLE); + hConsoleOut=GetStdHandle(STD_OUTPUT_HANDLE); + + /*parse command line for /a and file name(s)*/ + for(i=1;i = sizeof(files) / sizeof(*files) ) + { + ConErrPrintf("too many files, maximum is %d\n",sizeof(files) / sizeof(*files)); + return 1; + } + */ + + files[iFileCounter++]= p[i]+add; + } + + /*open file(s)*/ + for(i=0;i0 && bRet) + { + for(i=0;i0 && bRet); + + for(i=0;i