ReactOS  0.4.15-dev-1197-g8081ba9
y.c
Go to the documentation of this file.
1 /*
2  * Y.C - Y external command.
3  *
4  * clone from 4nt y command
5  *
6  * 02 Oct 1999 (Paolo Pantaleo)
7  * started
8  *
9  *
10  */
11 
12 #define BUFF_SIZE 4096
13 
14 #include <windows.h>
15 #include <stdio.h>
16 #include <tchar.h>
17 
18 static
19 VOID ConErrPrintf (LPTSTR szFormat, ...)
20 {
21  DWORD dwWritten;
22  TCHAR szOut[BUFF_SIZE];
23  va_list arg_ptr;
24 
25  va_start (arg_ptr, szFormat);
26  _vstprintf (szOut, szFormat, arg_ptr);
27  va_end (arg_ptr);
28 
29  WriteFile (GetStdHandle (STD_ERROR_HANDLE), szOut, _tcslen(szOut), &dwWritten, NULL);
30 }
31 
32 
33 static
35 {
36  DWORD dwWritten;
37 
39  WriteFile (GetStdHandle (STD_OUTPUT_HANDLE), "\n", 1, &dwWritten, NULL);
40 }
41 
42 
43 int main (int argc, char **argv)
44 {
45  INT i;
46  HANDLE hFind;
47  HANDLE hConsoleIn, hConsoleOut, hFile;
48  char buff[BUFF_SIZE];
49  DWORD dwRead,dwWritten;
50  BOOL bRet;
51  WIN32_FIND_DATA FindData;
52 
53  hConsoleIn = GetStdHandle(STD_INPUT_HANDLE);
54  hConsoleOut = GetStdHandle(STD_OUTPUT_HANDLE);
55 
56  if (argc == 2 && _tcsncmp (argv[1], _T("/?"), 2) == 0)
57  {
58  ConOutPuts(_T("copy stdin to stdout and then files to stdout\n"
59  "\n"
60  "Y [files]\n"
61  "\n"
62  "files files to copy to stdout"));
63  return 0;
64  }
65 
66  /*stdin to stdout*/
67  do
68  {
69  bRet = ReadFile(hConsoleIn,buff,sizeof(buff),&dwRead,NULL);
70 
71  if (dwRead>0 && bRet)
72  WriteFile(hConsoleOut,buff,dwRead,&dwWritten,NULL);
73 
74  } while(dwRead>0 && bRet);
75 
76 
77  /*files to stdout*/
78  Sleep(0);
79 
80  for (i = 1; i < argc; i++)
81  {
82  hFind=FindFirstFile(argv[i],&FindData);
83 
84  if (hFind==INVALID_HANDLE_VALUE)
85  {
86  ConErrPrintf("File not found - %s\n",argv[i]);
87  continue;
88  }
89 
90  do
91  {
92  hFile = CreateFile(FindData.cFileName,
97 
99  {
100  ConErrPrintf("File not found - %s\n",FindData.cFileName);
101  continue;
102  }
103 
104  do
105  {
106  bRet = ReadFile(hFile,buff,sizeof(buff),&dwRead,NULL);
107 
108  if (dwRead>0 && bRet)
109  WriteFile(hConsoleOut,buff,dwRead,&dwWritten,NULL);
110 
111  } while(dwRead>0 && bRet);
112 
114 
115  }
116  while(FindNextFile(hFind,&FindData));
117 
118  FindClose(hFind);
119  }
120 
121  return 0;
122 }
BOOL WINAPI WriteFile(IN HANDLE hFile, IN LPCVOID lpBuffer, IN DWORD nNumberOfBytesToWrite OPTIONAL, OUT LPDWORD lpNumberOfBytesWritten, IN LPOVERLAPPED lpOverlapped OPTIONAL)
Definition: rw.c:24
static int argc
Definition: ServiceArgs.c:12
#define CloseHandle
Definition: compat.h:487
VOID WINAPI DECLSPEC_HOTPATCH Sleep(IN DWORD dwMilliseconds)
Definition: synch.c:790
int main(int argc, char **argv)
Definition: y.c:43
#define _vstprintf
Definition: tchar.h:540
#define INVALID_HANDLE_VALUE
Definition: compat.h:479
HANDLE WINAPI GetStdHandle(IN DWORD nStdHandle)
Definition: console.c:200
#define BUFF_SIZE
Definition: y.c:12
#define argv
Definition: mplay32.c:18
int32_t INT
Definition: typedefs.h:58
CHAR * LPTSTR
Definition: xmlstorage.h:192
#define FILE_SHARE_READ
Definition: compat.h:136
GLsizei GLenum const GLvoid GLsizei GLenum GLbyte GLbyte GLbyte GLdouble GLdouble GLdouble GLfloat GLfloat GLfloat GLint GLint GLint GLshort GLshort GLshort GLubyte GLubyte GLubyte GLuint GLuint GLuint GLushort GLushort GLushort GLbyte GLbyte GLbyte GLbyte GLdouble GLdouble GLdouble GLdouble GLfloat GLfloat GLfloat GLfloat GLint GLint GLint GLint GLshort GLshort GLshort GLshort GLubyte GLubyte GLubyte GLubyte GLuint GLuint GLuint GLuint GLushort GLushort GLushort GLushort GLboolean const GLdouble const GLfloat const GLint const GLshort const GLbyte const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLdouble const GLfloat const GLfloat const GLint const GLint const GLshort const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort GLenum GLenum GLenum GLfloat GLenum GLint GLenum GLenum GLenum GLfloat GLenum GLenum GLint GLenum GLfloat GLenum GLint GLint GLushort GLenum GLenum GLfloat GLenum GLenum GLint GLfloat const GLubyte GLenum GLenum GLenum const GLfloat GLenum GLenum const GLint GLenum GLint GLint GLsizei GLsizei GLint GLenum GLenum const GLvoid GLenum GLenum const GLfloat GLenum GLenum const GLint GLenum GLenum const GLdouble GLenum GLenum const GLfloat GLenum GLenum const GLint GLsizei GLuint GLfloat GLuint GLbitfield GLfloat GLint GLuint GLboolean GLenum GLfloat GLenum GLbitfield GLenum GLfloat GLfloat GLint GLint const GLfloat GLenum GLfloat GLfloat GLint GLint GLfloat GLfloat GLint GLint const GLfloat GLint GLfloat GLfloat GLint GLfloat GLfloat GLint GLfloat GLfloat const GLdouble const GLfloat const GLdouble const GLfloat GLint i
Definition: glfuncs.h:248
#define va_end(ap)
Definition: acmsvcex.h:90
static const WCHAR szText[]
Definition: dialog.c:139
unsigned int BOOL
Definition: ntddk_ex.h:94
size_t __cdecl _tcslen(const _TCHAR *str)
Definition: tcslen.h:9
smooth NULL
Definition: ftsmooth.c:416
char * va_list
Definition: acmsvcex.h:78
#define FindFirstFile
Definition: winbase.h:3622
#define STD_INPUT_HANDLE
Definition: winbase.h:264
#define OPEN_EXISTING
Definition: compat.h:523
char TCHAR
Definition: xmlstorage.h:189
#define _T(x)
Definition: vfdio.h:22
#define FindNextFile
Definition: winbase.h:3628
#define STD_ERROR_HANDLE
Definition: winbase.h:266
unsigned long DWORD
Definition: ntddk_ex.h:95
#define FILE_ATTRIBUTE_NORMAL
Definition: compat.h:137
static VOID ConOutPuts(LPTSTR szText)
Definition: y.c:34
#define GENERIC_READ
Definition: compat.h:135
#define STD_OUTPUT_HANDLE
Definition: winbase.h:265
_In_ HANDLE hFile
Definition: mswsock.h:90
IN OUT PVCB OUT PDIRENT OUT PBCB IN BOOLEAN CreateFile
Definition: fatprocs.h:913
#define ReadFile(a, b, c, d, e)
Definition: compat.h:490
#define va_start(ap, A)
Definition: acmsvcex.h:91
static VOID ConErrPrintf(LPTSTR szFormat,...)
Definition: y.c:19
static unsigned char buff[32768]
Definition: fatten.c:17
int _tcsncmp(const _TCHAR *s1, const _TCHAR *s2, size_t n)
Definition: tcsncmp.h:9
BOOL WINAPI FindClose(HANDLE hFindFile)
Definition: find.c:502