ReactOS 0.4.15-dev-7788-g1ad9096
misc.c File Reference
#include "precomp.h"
#include <stdio.h>
Include dependency graph for misc.c:

Go to the source code of this file.

Functions

DWORD ParseReasonCode (LPCWSTR code)
 
VOID DisplayError (DWORD dwError)
 

Variables

const DWORD defaultReason = SHTDN_REASON_MAJOR_OTHER | SHTDN_REASON_MINOR_OTHER
 
REASON shutdownReason []
 

Function Documentation

◆ DisplayError()

VOID DisplayError ( DWORD  dwError)

Definition at line 110 of file misc.c.

111{
113 NULL, dwError, LANG_USER_DEFAULT);
114 ConPrintf(StdErr, L"Error code: %lu\n", dwError);
115}
void ConPrintf(FILE *fp, LPCWSTR psz,...)
Definition: fc.c:20
#define StdErr
Definition: fc.c:15
#define NULL
Definition: types.h:112
#define L(x)
Definition: ntvdm.h:50
INT ConMsgPuts(IN PCON_STREAM Stream, IN DWORD dwFlags, IN LPCVOID lpSource OPTIONAL, IN DWORD dwMessageId, IN DWORD dwLanguageId)
Definition: outstream.c:837
#define LANG_USER_DEFAULT
Definition: tnerror.cpp:50
#define FORMAT_MESSAGE_FROM_SYSTEM
Definition: winbase.h:423

◆ ParseReasonCode()

DWORD ParseReasonCode ( LPCWSTR  code)

Definition at line 55 of file misc.c.

56{
57 PREASON reasonptr;
58 int majorCode = 0;
59 int minorCode = 0;
60 LPWSTR tmpPrefix = NULL;
61 size_t codeSize;
62
63 /* If no reason code is specified, use "Other (Unplanned)" as the default option */
64 if(code == NULL)
65 {
66 return defaultReason;
67 }
68 else
69 {
70 /* Store the size of the code so we can use it later */
71 codeSize = (size_t)wcslen(code);
72
73 /* A colon cannot be the first or last character in the reason code */
74 if ((code[0] == L':') || (code[codeSize] == L':'))
75 {
76 return defaultReason;
77 }
78
79 /* The minimum length that a reason code can be is 5-7 characters in length */
80 if ((codeSize < 5) || (codeSize > 7))
81 {
82 return defaultReason;
83 }
84
85 /* TODO: Add code for reason parsing here. */
86
87 /* Make sure that the major and minor codes are within size limits */
88 if ((majorCode > 7 ) || (majorCode < 0) ||
89 (minorCode > 20) || (minorCode < 0))
90 {
91 return defaultReason;
92 }
93
94 /* Figure out what flags to return */
95 for (reasonptr = shutdownReason ; reasonptr->prefix ; reasonptr++)
96 {
97 if ((majorCode == reasonptr->major) &&
98 (minorCode == reasonptr->minor) &&
99 (_wcsicmp(tmpPrefix, reasonptr->prefix) != 0))
100 {
101 return reasonptr->flag;
102 }
103 }
104 }
105
106 return defaultReason;
107}
const DWORD defaultReason
Definition: misc.c:13
REASON shutdownReason[]
Definition: misc.c:15
__kernel_size_t size_t
Definition: linux.h:237
_CRTIMP size_t __cdecl wcslen(_In_z_ const wchar_t *_Str)
_Check_return_ _CRTIMP int __cdecl _wcsicmp(_In_z_ const wchar_t *_Str1, _In_z_ const wchar_t *_Str2)
int major
Definition: precomp.h:28
DWORD flag
Definition: precomp.h:30
LPWSTR prefix
Definition: precomp.h:27
int minor
Definition: precomp.h:29
Definition: inflate.c:139
WCHAR * LPWSTR
Definition: xmlstorage.h:184

Referenced by ParseArguments().

Variable Documentation

◆ defaultReason

const DWORD defaultReason = SHTDN_REASON_MAJOR_OTHER | SHTDN_REASON_MINOR_OTHER

Definition at line 13 of file misc.c.

Referenced by ParseReasonCode().

◆ shutdownReason

REASON shutdownReason[]

Definition at line 15 of file misc.c.

Referenced by ParseReasonCode().