ReactOS  0.4.15-dev-313-g8fde48b
logevent.c File Reference
#include <windows.h>
#include <stdlib.h>
#include <stdio.h>
#include <string.h>
#include <malloc.h>
#include <tchar.h>
#include <stdarg.h>
Include dependency graph for logevent.c:

Go to the source code of this file.

Functions

void Usage (VOID)
 
void WriteEvent (VOID)
 
static BOOL ParseCmdline (int argc, TCHAR **argv)
 
int main (int argc, char **argv)
 

Variables

TCHARm_MachineName = NULL
 
TCHARm_Text = "No User Event Text"
 
TCHARm_Source = "User Event"
 
WORD m_Severity = EVENTLOG_INFORMATION_TYPE
 
WORD m_Category = 0
 
DWORD m_EventID = 1
 

Function Documentation

◆ main()

int main ( int argc  ,
char **  argv 
)

Definition at line 199 of file logevent.c.

200 {
201  if (ParseCmdline(argc, argv))
202  WriteEvent ();
203 
204  return 0;
205 }
static int argc
Definition: ServiceArgs.c:12
static BOOL ParseCmdline(int argc, TCHAR **argv)
Definition: logevent.c:89
#define argv
Definition: mplay32.c:18
void WriteEvent(VOID)
Definition: logevent.c:60

◆ ParseCmdline()

static BOOL ParseCmdline ( int  argc,
TCHAR **  argv 
)
static

Definition at line 89 of file logevent.c.

90 {
91  INT i;
93  BOOL FoundEventText;
95 
96  if (argc < 2) {
97  ShowUsage = TRUE;
98  } else {
99  ShowUsage = FALSE;
100  }
101 
102  FoundEventText = FALSE;
104 
105  for (i = 1; i < argc; i++) {
106  if (argv[i][0] == '-' || argv[i][0] == '/') {
107  switch (argv[i][1]) {
108  case 's':
109  case 'S':
110  switch (argv[i + 1][0])
111  {
112  case 's':
113  case 'S':
115  i++;
116  break;
117  case 'i':
118  case 'I':
120  i++;
121  break;
122  case 'w':
123  case 'W':
125  i++;
126  break;
127  case 'e':
128  case 'E':
130  i++;
131  break;
132  case 'f':
133  case 'F':
135  i++;
136  break;
137  default:
138  printf("Bad option %s.\n", argv[i]);
139  Usage();
140  return FALSE;
141  }
142  break;
143  case 'm':
144  case 'M':
145  m_MachineName = argv[i + 1];
146  i++;
147  break;
148  case 'r':
149  case 'R':
150  m_Source = argv[i + 1];
151  i++;
152  break;
153  case 'c':
154  case 'C':
155  m_Category = atoi(argv[i + 1]);
156  i++;
157  break;
158  case 'e':
159  case 'E':
160  m_EventID = atoi(argv[i + 1]);
161  i++;
162  break;
163  case '?':
164  ShowUsage = TRUE;
165  break;
166  default:
167  printf("Bad option %s.\n", argv[i]);
168  Usage();
169  return FALSE;
170  }
171  if (InvalidOption) {
172  printf("Bad option format %s.\n", argv[i]);
173  return FALSE;
174  }
175  } else {
176  if (FoundEventText) {
177  printf("Bad parameter %s.\n", argv[i]);
178  return FALSE;
179  } else {
180  m_Text = argv[i];
181  FoundEventText = TRUE;
182  }
183  }
184  }
185 
186  if ((!ShowUsage) && (!FoundEventText)) {
187  printf("The event text must be specified.\n");
188  return FALSE;
189  }
190 
191  if (ShowUsage) {
192  Usage();
193  return FALSE;
194  }
195 
196  return TRUE;
197 }
TCHAR * m_MachineName
Definition: logevent.c:34
static int argc
Definition: ServiceArgs.c:12
#define TRUE
Definition: types.h:120
#define argv
Definition: mplay32.c:18
void Usage(VOID)
Definition: logevent.c:42
int32_t INT
Definition: typedefs.h:57
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 EVENTLOG_ERROR_TYPE
Definition: winnt_old.h:2630
unsigned int BOOL
Definition: ntddk_ex.h:94
#define EVENTLOG_SUCCESS
Definition: winnt_old.h:2629
#define EVENTLOG_INFORMATION_TYPE
Definition: winnt_old.h:2632
#define EVENTLOG_WARNING_TYPE
Definition: winnt_old.h:2631
TCHAR * m_Text
Definition: logevent.c:35
WORD m_Severity
Definition: logevent.c:37
static void ShowUsage(int ExitCode)
Definition: msiexec.c:59
TCHAR * m_Source
Definition: logevent.c:36
_Check_return_ int __cdecl atoi(_In_z_ const char *_Str)
WORD m_Category
Definition: logevent.c:38
DWORD m_EventID
Definition: logevent.c:39
#define printf
Definition: config.h:203

Referenced by main().

◆ Usage()

void Usage ( VOID  )

Definition at line 42 of file logevent.c.

43 {
44  fputs("Usage: logevent.exe [-m \\MachineName] [options] \"Event Text\"", stderr);
45  fputs("\n\n", stderr);
46  fputs("Options:\n", stderr);
47  fputs(" -s Severity one of:\n", stderr);
48  fputs(" \t(S)uccess\n", stderr);
49  fputs(" \t(I)nformation\n", stderr);
50  fputs(" \t(W)arning\n", stderr);
51  fputs(" \t(E)rror\n", stderr);
52  fputs(" \t(F)ailure\n", stderr);
53  fputs(" -r Source\n", stderr);
54  fputs(" -c Category number\n", stderr);
55  fputs(" -e Event ID\n", stderr);
56  fputs(" /? Help\n", stderr);
57 }
FILE * stderr
_Check_return_opt_ _CRTIMP int __cdecl fputs(_In_z_ const char *_Str, _Inout_ FILE *_File)

Referenced by ParseCmdline().

◆ WriteEvent()

void WriteEvent ( VOID  )

Definition at line 60 of file logevent.c.

61 {
62  HANDLE hAppLog;
63  BOOL bSuccess;
64  LPCTSTR arrLogEntry[] = { m_Text }; //writing just one entry
65 
66  /* Get a handle to the Application event log */
67  hAppLog = RegisterEventSource(
68  (LPCSTR)m_MachineName, /* machine */
69  (LPCSTR)m_Source); /* source name */
70 
71  /* Now report the event, which will add this event to the event log */
73  hAppLog, /* event-log handle */
74  m_Severity, /* event type */
75  m_Category, /* category */
76  m_EventID, /* event ID */
77  NULL, /* no user SID */
78  1, /* number of substitution strings */
79  0, /* no binary data */
80  arrLogEntry, /* string array */
81  NULL); /* address of data */
82 
83  DeregisterEventSource(hAppLog);
84 
85  return;
86 }
TCHAR * m_MachineName
Definition: logevent.c:34
const CHAR * LPCTSTR
Definition: xmlstorage.h:193
static BOOLEAN bSuccess
Definition: drive.cpp:419
unsigned int BOOL
Definition: ntddk_ex.h:94
smooth NULL
Definition: ftsmooth.c:416
const char * LPCSTR
Definition: xmlstorage.h:183
TCHAR * m_Text
Definition: logevent.c:35
WORD m_Severity
Definition: logevent.c:37
#define ReportEvent
Definition: winbase.h:3739
#define RegisterEventSource
Definition: winbase.h:3734
BOOL WINAPI DeregisterEventSource(IN HANDLE hEventLog)
Definition: eventlog.c:473
TCHAR * m_Source
Definition: logevent.c:36
WORD m_Category
Definition: logevent.c:38
DWORD m_EventID
Definition: logevent.c:39

Referenced by main().

Variable Documentation

◆ m_Category

WORD m_Category = 0

Definition at line 38 of file logevent.c.

Referenced by ParseCmdline(), and WriteEvent().

◆ m_EventID

DWORD m_EventID = 1

Definition at line 39 of file logevent.c.

Referenced by ParseCmdline(), and WriteEvent().

◆ m_MachineName

TCHAR* m_MachineName = NULL

Definition at line 34 of file logevent.c.

Referenced by ParseCmdline(), and WriteEvent().

◆ m_Severity

Definition at line 37 of file logevent.c.

Referenced by ParseCmdline(), and WriteEvent().

◆ m_Source

TCHAR* m_Source = "User Event"

Definition at line 36 of file logevent.c.

Referenced by ParseCmdline(), and WriteEvent().

◆ m_Text

TCHAR* m_Text = "No User Event Text"