ReactOS  0.4.14-dev-297-g23e575c
type.c File Reference
#include "precomp.h"
Include dependency graph for type.c:

Go to the source code of this file.

Functions

INT cmd_type (LPTSTR param)
 

Function Documentation

◆ cmd_type()

INT cmd_type ( LPTSTR  param)

Definition at line 34 of file type.c.

35 {
36  TCHAR buff[256];
37  HANDLE hFile, hConsoleOut;
38  DWORD dwRet;
39  INT argc,i;
40  LPTSTR *argv;
41  LPTSTR errmsg;
42  BOOL bPaging = FALSE;
43  BOOL bFirstTime = TRUE;
44 
45  hConsoleOut = GetStdHandle(STD_OUTPUT_HANDLE);
46 
47  if (!_tcsncmp(param, _T("/?"), 2))
48  {
50  return 0;
51  }
52 
53  if (!*param)
54  {
56  return 1;
57  }
58 
59  argv = split(param, &argc, TRUE, FALSE);
60 
61  for (i = 0; i < argc; i++)
62  {
63  if (argv[i][0] == _T('/') && _tcslen(argv[i]) == 2 && _totupper(argv[i][1]) == _T('P'))
64  {
65  bPaging = TRUE;
66  }
67  }
68 
69  for (i = 0; i < argc; i++)
70  {
71  if (argv[i][0] == _T('/') && _totupper(argv[i][1]) != _T('P'))
72  {
74  continue;
75  }
76  if (argv[i][0] == _T('/') && _tcslen(argv[i]) == 2 && _totupper(argv[i][1]) == _T('P'))
77  {
78  continue;
79  }
80 
81  nErrorLevel = 0;
82 
88 
90  {
94  NULL,
95  GetLastError(),
97  (LPTSTR) &errmsg,
98  0,
99  NULL);
100  ConErrPrintf (_T("%s - %s"), argv[i], errmsg);
101  LocalFree (errmsg);
102  nErrorLevel = 1;
103  continue;
104  }
105 
106  if (bPaging)
107  {
109  {
110  if (!ConOutPrintfPaging(bFirstTime, _T("%s"), buff))
111  {
112  bCtrlBreak = FALSE;
114  freep(argv);
115  return 0;
116  }
117  bFirstTime = FALSE;
118  }
119  }
120  else
121  {
122  while (ReadFile(hFile, buff, sizeof(buff), &dwRet, NULL) && dwRet > 0)
123  {
124  WriteFile(hConsoleOut, buff, dwRet, &dwRet, NULL);
125  if (bCtrlBreak)
126  {
127  bCtrlBreak = FALSE;
129  freep(argv);
130  return 0;
131  }
132  }
133  }
134 
136  }
137 
138  freep(argv);
139  return 0;
140 }
INT nErrorLevel
Definition: cmd.c:157
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 TRUE
Definition: types.h:120
#define CloseHandle
Definition: compat.h:398
#define LANG_NEUTRAL
Definition: nls.h:22
#define SUBLANG_DEFAULT
Definition: nls.h:168
#define ARRAYSIZE(array)
Definition: filtermapper.c:47
#define INVALID_HANDLE_VALUE
Definition: compat.h:391
DWORD WINAPI GetLastError(VOID)
Definition: except.c:1059
HANDLE WINAPI GetStdHandle(IN DWORD nStdHandle)
Definition: console.c:152
VOID ConOutResPaging(BOOL StartPaging, UINT resID)
Definition: console.c:182
#define FILE_SHARE_WRITE
Definition: nt_native.h:681
#define _totupper
Definition: tchar.h:1509
#define argv
Definition: mplay32.c:18
int32_t INT
Definition: typedefs.h:56
CHAR * LPTSTR
Definition: xmlstorage.h:192
#define FILE_SHARE_READ
Definition: compat.h:125
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 STRING_TYPE_HELP1
Definition: resource.h:184
unsigned int BOOL
Definition: ntddk_ex.h:94
#define ConErrResPrintf(uID,...)
Definition: console.h:51
VOID error_req_param_missing(VOID)
Definition: error.c:108
#define FORMAT_MESSAGE_ALLOCATE_BUFFER
Definition: winbase.h:400
size_t __cdecl _tcslen(const _TCHAR *str)
Definition: tcslen.h:9
static VOID freep(LPSTR *p)
Definition: cmdcons.c:98
smooth NULL
Definition: ftsmooth.c:416
EXPORT int errmsg(char *msg, va_alist)
Definition: comerr.c:192
#define FORMAT_MESSAGE_FROM_SYSTEM
Definition: winbase.h:404
VOID ConErrPrintf(LPTSTR szFormat,...)
Definition: tee.c:36
#define OPEN_EXISTING
Definition: compat.h:426
#define STRING_TYPE_ERROR1
Definition: resource.h:58
char TCHAR
Definition: xmlstorage.h:189
#define _T(x)
Definition: vfdio.h:22
GLfloat param
Definition: glext.h:5796
static LPSTR * split(LPSTR s, LPINT args)
Definition: cmdcons.c:163
unsigned long DWORD
Definition: ntddk_ex.h:95
static BOOL FileGetString(IN HANDLE hFile, IN ENCODING Encoding, IN OUT PVOID pCacheBuffer, IN DWORD CacheBufferLength, IN OUT PWCHAR *pBuffer, IN OUT PDWORD pnBufferLength, OUT PDWORD pdwReadBytes OPTIONAL, OUT PDWORD pdwReadChars OPTIONAL)
Definition: more.c:316
#define FormatMessage
Definition: winbase.h:3619
#define FILE_ATTRIBUTE_NORMAL
Definition: compat.h:126
#define GENERIC_READ
Definition: compat.h:124
#define STD_OUTPUT_HANDLE
Definition: winbase.h:265
_In_ HANDLE hFile
Definition: mswsock.h:90
BOOL __cdecl ConOutPrintfPaging(BOOL StartPaging, LPTSTR szFormat,...)
Definition: console.c:171
#define FORMAT_MESSAGE_IGNORE_INSERTS
Definition: winbase.h:401
IN OUT PVCB OUT PDIRENT OUT PBCB IN BOOLEAN CreateFile
Definition: fatprocs.h:904
HLOCAL NTAPI LocalFree(HLOCAL hMem)
Definition: heapmem.c:1577
#define MAKELANGID(p, s)
Definition: nls.h:15
BOOL WINAPI ReadFile(IN HANDLE hFile, IN LPVOID lpBuffer, IN DWORD nNumberOfBytesToRead, OUT LPDWORD lpNumberOfBytesRead OPTIONAL, IN LPOVERLAPPED lpOverlapped OPTIONAL)
Definition: rw.c:123
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 bCtrlBreak
Definition: cmd.c:154

Referenced by client_dde_callback().