2 * Y.C - Y external command.
4 * clone from 4nt y command
6 * 02 Oct 1999 (Paolo Pantaleo)
12 #define BUFF_SIZE 4096
19 VOID
ConErrPrintf (LPTSTR szFormat
, ...)
22 TCHAR szOut
[BUFF_SIZE
];
25 va_start (arg_ptr
, szFormat
);
26 _vstprintf (szOut
, szFormat
, arg_ptr
);
29 WriteFile (GetStdHandle (STD_ERROR_HANDLE
), szOut
, _tcslen(szOut
), &dwWritten
, NULL
);
34 VOID
ConOutPuts (LPTSTR szText
)
38 WriteFile (GetStdHandle (STD_OUTPUT_HANDLE
), szText
, _tcslen(szText
), &dwWritten
, NULL
);
39 WriteFile (GetStdHandle (STD_OUTPUT_HANDLE
), "\n", 1, &dwWritten
, NULL
);
43 int main (int argc
, char **argv
)
47 HANDLE hConsoleIn
, hConsoleOut
, hFile
;
49 DWORD dwRead
,dwWritten
;
51 WIN32_FIND_DATA FindData
;
53 hConsoleIn
= GetStdHandle(STD_INPUT_HANDLE
);
54 hConsoleOut
= GetStdHandle(STD_OUTPUT_HANDLE
);
56 if (_tcsncmp (argv
[1], _T("/?"), 2) == 0)
58 ConOutPuts(_T("copy stdin to stdout and then files to stdout\n"
62 "files files to copy to stdout"));
69 bRet
= ReadFile(hConsoleIn
,buff
,sizeof(buff
),&dwRead
,NULL
);
72 WriteFile(hConsoleOut
,buff
,dwRead
,&dwWritten
,NULL
);
74 } while(dwRead
>0 && bRet
);
80 for (i
= 1; i
< argc
; i
++)
82 hFind
=FindFirstFile(argv
[i
],&FindData
);
84 if (hFind
==INVALID_HANDLE_VALUE
)
86 ConErrPrintf("File not found - %s\n",argv
[i
]);
92 hFile
= CreateFile(FindData
.cFileName
,
96 FILE_ATTRIBUTE_NORMAL
,NULL
);
98 if(hFile
== INVALID_HANDLE_VALUE
)
100 ConErrPrintf("File not found - %s\n",FindData
.cFileName
);
106 bRet
= ReadFile(hFile
,buff
,sizeof(buff
),&dwRead
,NULL
);
108 if (dwRead
>0 && bRet
)
109 WriteFile(hConsoleOut
,buff
,dwRead
,&dwWritten
,NULL
);
111 } while(dwRead
>0 && bRet
);
116 while(FindNextFile(hFind
,&FindData
));