ReactOS  0.4.12-dev-57-g7050ac4
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 }
INT __cdecl ConPrintf(IN PCON_STREAM Stream, IN LPWSTR szStr,...)
Definition: outstream.c:520
smooth NULL
Definition: ftsmooth.c:416
#define FORMAT_MESSAGE_FROM_SYSTEM
Definition: winbase.h:404
INT ConMsgPuts(IN PCON_STREAM Stream, IN DWORD dwFlags, IN LPCVOID lpSource OPTIONAL, IN DWORD dwMessageId, IN DWORD dwLanguageId)
Definition: outstream.c:837
#define StdErr
Definition: stream.h:77
static const WCHAR L[]
Definition: oid.c:1087
#define LANG_USER_DEFAULT
Definition: tnerror.cpp:50

◆ ParseReasonCode()

DWORD ParseReasonCode ( LPCWSTR  code)

Definition at line 55 of file misc.c.

Referenced by ParseArguments().

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 }
int minor
Definition: precomp.h:29
smooth NULL
Definition: ftsmooth.c:416
__kernel_size_t size_t
Definition: linux.h:237
REASON shutdownReason[]
Definition: misc.c:15
static const WCHAR L[]
Definition: oid.c:1087
LPWSTR prefix
Definition: precomp.h:27
int major
Definition: precomp.h:28
DWORD flag
Definition: precomp.h:30
WCHAR * LPWSTR
Definition: xmlstorage.h:184
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)
const DWORD defaultReason
Definition: misc.c:13

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.