mirror of
https://github.com/reactos/reactos.git
synced 2025-01-03 21:09:19 +00:00
- Accept the parameters case-insensitive
- Replace the "/h" option by a "/?" option as described in the Usage text - Use a consistent indentation - Change the Usage text a bit svn path=/trunk/; revision=28936
This commit is contained in:
parent
a1a8df5ad2
commit
1540ce885b
1 changed files with 106 additions and 82 deletions
|
@ -32,58 +32,58 @@
|
|||
#include <tchar.h>
|
||||
#include <stdarg.h>
|
||||
|
||||
TCHAR* m_MachineName = NULL;
|
||||
TCHAR* m_Text = "No User Event Text";
|
||||
TCHAR* m_Source = "User Event";
|
||||
WORD m_Severity = EVENTLOG_INFORMATION_TYPE;
|
||||
WORD m_Category = 0;
|
||||
DWORD m_EventID = 1;
|
||||
TCHAR* m_MachineName = NULL;
|
||||
TCHAR* m_Text = "No User Event Text";
|
||||
TCHAR* m_Source = "User Event";
|
||||
WORD m_Severity = EVENTLOG_INFORMATION_TYPE;
|
||||
WORD m_Category = 0;
|
||||
DWORD m_EventID = 1;
|
||||
|
||||
void
|
||||
Usage(VOID)
|
||||
{
|
||||
fputs("logevent.exe [-m \\MachineName] [options] \"Event Text\"", stderr);
|
||||
fputs("\n", stderr);
|
||||
fputs(" Options:\n", stderr);
|
||||
fputs(" -s Severity one of :\n", stderr);
|
||||
fputs(" (S)uccess\n", stderr);
|
||||
fputs(" (I)nformation\n", stderr);
|
||||
fputs(" (W)arning\n", stderr);
|
||||
fputs(" (E)rror\n", stderr);
|
||||
fputs(" (F)ailure\n", stderr);
|
||||
fputs(" -r Source\n", stderr);
|
||||
fputs(" -c Category number\n", stderr);
|
||||
fputs(" -e Event ID\n", stderr);
|
||||
fputs(" /? Help\n", stderr);
|
||||
fputs("Usage: logevent.exe [-m \\MachineName] [options] \"Event Text\"", stderr);
|
||||
fputs("\n\n", stderr);
|
||||
fputs("Options:\n", stderr);
|
||||
fputs(" -s Severity one of:\n", stderr);
|
||||
fputs(" \t(S)uccess\n", stderr);
|
||||
fputs(" \t(I)nformation\n", stderr);
|
||||
fputs(" \t(W)arning\n", stderr);
|
||||
fputs(" \t(E)rror\n", stderr);
|
||||
fputs(" \t(F)ailure\n", stderr);
|
||||
fputs(" -r Source\n", stderr);
|
||||
fputs(" -c Category number\n", stderr);
|
||||
fputs(" -e Event ID\n", stderr);
|
||||
fputs(" /? Help\n", stderr);
|
||||
}
|
||||
|
||||
void
|
||||
WriteEvent (VOID)
|
||||
{
|
||||
HANDLE hAppLog;
|
||||
BOOL bSuccess;
|
||||
LPCTSTR arrLogEntry[] = { m_Text }; //writing just one entry
|
||||
HANDLE hAppLog;
|
||||
BOOL bSuccess;
|
||||
LPCTSTR arrLogEntry[] = { m_Text }; //writing just one entry
|
||||
|
||||
/* Get a handle to the Application event log */
|
||||
hAppLog = RegisterEventSource(
|
||||
(LPCSTR)m_MachineName, /* machine */
|
||||
(LPCSTR)m_Source); /* source name */
|
||||
/* Get a handle to the Application event log */
|
||||
hAppLog = RegisterEventSource(
|
||||
(LPCSTR)m_MachineName, /* machine */
|
||||
(LPCSTR)m_Source); /* source name */
|
||||
|
||||
/* Now report the event, which will add this event to the event log */
|
||||
bSuccess = ReportEvent(
|
||||
hAppLog, /* event-log handle */
|
||||
m_Severity, /* event type */
|
||||
m_Category, /* category */
|
||||
m_EventID, /* event ID */
|
||||
NULL, /* no user SID */
|
||||
1, /* number of substitution strings */
|
||||
0, /* no binary data */
|
||||
arrLogEntry, /* string array */
|
||||
NULL); /* address of data */
|
||||
/* Now report the event, which will add this event to the event log */
|
||||
bSuccess = ReportEvent(
|
||||
hAppLog, /* event-log handle */
|
||||
m_Severity, /* event type */
|
||||
m_Category, /* category */
|
||||
m_EventID, /* event ID */
|
||||
NULL, /* no user SID */
|
||||
1, /* number of substitution strings */
|
||||
0, /* no binary data */
|
||||
arrLogEntry, /* string array */
|
||||
NULL); /* address of data */
|
||||
|
||||
DeregisterEventSource(hAppLog);
|
||||
DeregisterEventSource(hAppLog);
|
||||
|
||||
return;
|
||||
return;
|
||||
}
|
||||
|
||||
/* Parse command line parameters */
|
||||
|
@ -92,7 +92,7 @@ static BOOL ParseCmdline(int argc, TCHAR **argv)
|
|||
INT i;
|
||||
BOOL ShowUsage;
|
||||
BOOL FoundEventText;
|
||||
BOOL InvalidOption;
|
||||
BOOL InvalidOption;
|
||||
|
||||
if (argc < 2) {
|
||||
ShowUsage = TRUE;
|
||||
|
@ -106,44 +106,68 @@ static BOOL ParseCmdline(int argc, TCHAR **argv)
|
|||
for (i = 1; i < argc; i++) {
|
||||
if (argv[i][0] == '-' || argv[i][0] == '/') {
|
||||
switch (argv[i][1]) {
|
||||
case 's':
|
||||
switch (argv[i + 1][0])
|
||||
{
|
||||
case 's':
|
||||
m_Severity = EVENTLOG_SUCCESS;
|
||||
i++;
|
||||
break;
|
||||
case 'i':
|
||||
m_Severity = EVENTLOG_INFORMATION_TYPE;
|
||||
i++;
|
||||
break;
|
||||
case 'w':
|
||||
m_Severity = EVENTLOG_WARNING_TYPE;
|
||||
i++;
|
||||
break;
|
||||
case 'e':
|
||||
m_Severity = EVENTLOG_ERROR_TYPE;
|
||||
i++;
|
||||
break;
|
||||
case 'f':
|
||||
m_Severity = EVENTLOG_ERROR_TYPE;
|
||||
i++;
|
||||
break;
|
||||
default:
|
||||
printf("Bad option %s.\n", argv[i]);
|
||||
Usage();
|
||||
return FALSE;
|
||||
}
|
||||
break;
|
||||
case 'm': m_MachineName = argv[i + 1]; i++; break;
|
||||
case 'r': m_Source = argv[i + 1]; i++; break;
|
||||
case 'c': m_Category = atoi(argv[i + 1]); i++; break;
|
||||
case 'e': m_EventID = atoi(argv[i + 1]); i++; break;
|
||||
case 'h': ShowUsage = TRUE; break;
|
||||
default:
|
||||
printf("Bad option %s.\n", argv[i]);
|
||||
Usage();
|
||||
return FALSE;
|
||||
case 's':
|
||||
case 'S':
|
||||
switch (argv[i + 1][0])
|
||||
{
|
||||
case 's':
|
||||
case 'S':
|
||||
m_Severity = EVENTLOG_SUCCESS;
|
||||
i++;
|
||||
break;
|
||||
case 'i':
|
||||
case 'I':
|
||||
m_Severity = EVENTLOG_INFORMATION_TYPE;
|
||||
i++;
|
||||
break;
|
||||
case 'w':
|
||||
case 'W':
|
||||
m_Severity = EVENTLOG_WARNING_TYPE;
|
||||
i++;
|
||||
break;
|
||||
case 'e':
|
||||
case 'E':
|
||||
m_Severity = EVENTLOG_ERROR_TYPE;
|
||||
i++;
|
||||
break;
|
||||
case 'f':
|
||||
case 'F':
|
||||
m_Severity = EVENTLOG_ERROR_TYPE;
|
||||
i++;
|
||||
break;
|
||||
default:
|
||||
printf("Bad option %s.\n", argv[i]);
|
||||
Usage();
|
||||
return FALSE;
|
||||
}
|
||||
break;
|
||||
case 'm':
|
||||
case 'M':
|
||||
m_MachineName = argv[i + 1];
|
||||
i++;
|
||||
break;
|
||||
case 'r':
|
||||
case 'R':
|
||||
m_Source = argv[i + 1];
|
||||
i++;
|
||||
break;
|
||||
case 'c':
|
||||
case 'C':
|
||||
m_Category = atoi(argv[i + 1]);
|
||||
i++;
|
||||
break;
|
||||
case 'e':
|
||||
case 'E':
|
||||
m_EventID = atoi(argv[i + 1]);
|
||||
i++;
|
||||
break;
|
||||
case '?':
|
||||
ShowUsage = TRUE;
|
||||
break;
|
||||
default:
|
||||
printf("Bad option %s.\n", argv[i]);
|
||||
Usage();
|
||||
return FALSE;
|
||||
}
|
||||
if (InvalidOption) {
|
||||
printf("Bad option format %s.\n", argv[i]);
|
||||
|
@ -154,7 +178,7 @@ static BOOL ParseCmdline(int argc, TCHAR **argv)
|
|||
printf("Bad parameter %s.\n", argv[i]);
|
||||
return FALSE;
|
||||
} else {
|
||||
m_Text = argv[i];
|
||||
m_Text = argv[i];
|
||||
FoundEventText = TRUE;
|
||||
}
|
||||
}
|
||||
|
@ -175,8 +199,8 @@ static BOOL ParseCmdline(int argc, TCHAR **argv)
|
|||
|
||||
int main(int argc, char **argv)
|
||||
{
|
||||
if (ParseCmdline(argc, argv))
|
||||
WriteEvent ();
|
||||
if (ParseCmdline(argc, argv))
|
||||
WriteEvent ();
|
||||
|
||||
return 0;
|
||||
return 0;
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue