ReactOS 0.4.16-dev-2534-gdcd45a5
label.c File Reference
#include <stdio.h>
#include <windef.h>
#include <winbase.h>
#include <wincon.h>
#include <winnls.h>
#include <conutils.h>
#include "resource.h"
Include dependency graph for label.c:

Go to the source code of this file.

Macros

#define MAX_LABEL_LENGTH   32
 
#define MAX_DRIVE_LENGTH   2
 

Functions

static VOID ConFormatMessage (PCON_STREAM Stream, DWORD MessageId,...)
 
static VOID ConInString (LPWSTR lpInput, DWORD dwLength)
 
static BOOL IsValidPathName (LPCWSTR pszPath)
 
static BOOL PromptYesNo (VOID)
 
int wmain (int argc, WCHAR *argv[])
 

Macro Definition Documentation

◆ MAX_DRIVE_LENGTH

#define MAX_DRIVE_LENGTH   2

Definition at line 32 of file label.c.

◆ MAX_LABEL_LENGTH

#define MAX_LABEL_LENGTH   32

Definition at line 31 of file label.c.

Function Documentation

◆ ConFormatMessage()

static VOID ConFormatMessage ( PCON_STREAM  Stream,
DWORD  MessageId,
  ... 
)
static

Definition at line 36 of file label.c.

37{
38 va_list arg_ptr;
39
40 va_start(arg_ptr, MessageId);
43 NULL,
44 MessageId,
46 &arg_ptr);
47 va_end(arg_ptr);
48}
#define NULL
Definition: types.h:112
#define va_end(v)
Definition: stdarg.h:28
#define va_start(v, l)
Definition: stdarg.h:26
char * va_list
Definition: vadefs.h:50
static IStream Stream
Definition: htmldoc.c:1115
INT ConMsgPrintfV(IN PCON_STREAM Stream, IN DWORD dwFlags, IN LPCVOID lpSource OPTIONAL, IN DWORD dwMessageId, IN DWORD dwLanguageId, IN va_list *Arguments OPTIONAL)
Definition: outstream.c:1028
#define LANG_USER_DEFAULT
Definition: tnerror.cpp:50
#define FORMAT_MESSAGE_FROM_SYSTEM
Definition: winbase.h:400

Referenced by wmain().

◆ ConInString()

static VOID ConInString ( LPWSTR  lpInput,
DWORD  dwLength 
)
static

Definition at line 52 of file label.c.

53{
54 DWORD dwOldMode;
55 DWORD dwRead = 0;
57 LPWSTR p;
58 PCHAR pBuf;
59
61
63 GetConsoleMode(hFile, &dwOldMode);
64
66
67 ReadFile(hFile, (PVOID)pBuf, dwLength - 1, &dwRead, NULL);
68
69 MultiByteToWideChar(GetConsoleCP(), 0, pBuf, dwRead, lpInput, dwLength - 1);
70 HeapFree(GetProcessHeap(), 0, pBuf);
71
72 for (p = lpInput; *p; p++)
73 {
74 if (*p == L'\x0d')
75 {
76 *p = UNICODE_NULL;
77 break;
78 }
79 }
80
81 SetConsoleMode(hFile, dwOldMode);
82}
HANDLE WINAPI GetStdHandle(IN DWORD nStdHandle)
Definition: console.c:203
#define GetProcessHeap()
Definition: compat.h:736
#define ReadFile(a, b, c, d, e)
Definition: compat.h:742
#define HeapAlloc
Definition: compat.h:733
#define HeapFree(x, y, z)
Definition: compat.h:735
#define MultiByteToWideChar
Definition: compat.h:110
#define HEAP_ZERO_MEMORY
Definition: compat.h:134
static DWORD DWORD * dwLength
Definition: fusion.c:86
BOOL WINAPI GetConsoleMode(HANDLE hConsoleHandle, LPDWORD lpMode)
Definition: console.c:1571
BOOL WINAPI DECLSPEC_HOTPATCH SetConsoleMode(HANDLE hConsoleHandle, DWORD dwMode)
Definition: console.c:1608
UINT WINAPI DECLSPEC_HOTPATCH GetConsoleCP(void)
Definition: console.c:821
#define L(x)
Definition: resources.c:13
unsigned long DWORD
Definition: ntddk_ex.h:95
GLfloat GLfloat p
Definition: glext.h:8902
#define PCHAR
Definition: match.c:90
_In_ HANDLE hFile
Definition: mswsock.h:90
#define UNICODE_NULL
char * PCHAR
Definition: typedefs.h:51
#define STD_INPUT_HANDLE
Definition: winbase.h:291
#define ENABLE_ECHO_INPUT
Definition: wincon.h:109
#define ENABLE_LINE_INPUT
Definition: wincon.h:108
WCHAR * LPWSTR
Definition: xmlstorage.h:184

Referenced by cmd_date(), cmd_set(), cmd_time(), CommandHistory(), FilePromptYN(), FilePromptYNA(), PromptYesNo(), and wmain().

◆ IsValidPathName()

static BOOL IsValidPathName ( LPCWSTR  pszPath)
static

Definition at line 86 of file label.c.

87{
88 WCHAR szOldPath[MAX_PATH];
89 BOOL bResult;
90
92 bResult = SetCurrentDirectoryW(pszPath);
93
94 SetCurrentDirectoryW(szOldPath);
95
96 return bResult;
97}
#define GetCurrentDirectoryW(x, y)
Definition: compat.h:756
#define MAX_PATH
Definition: compat.h:34
BOOL WINAPI SetCurrentDirectoryW(IN LPCWSTR lpPathName)
Definition: path.c:2168
unsigned int BOOL
Definition: ntddk_ex.h:94
__wchar_t WCHAR
Definition: xmlstorage.h:180

Referenced by cmd_vol(), and wmain().

◆ PromptYesNo()

static BOOL PromptYesNo ( VOID  )
static

Definition at line 101 of file label.c.

102{
103 WCHAR szOptions[4];
104 WCHAR szInput[16];
105 BOOL bResult = FALSE;
106
107 LoadStringW(NULL, STRING_LABEL_OPTIONS, szOptions, ARRAYSIZE(szOptions));
108
109 for (;;)
110 {
111 ConPuts(StdOut, L"\n");
113
114 ConInString(szInput, ARRAYSIZE(szInput));
115
116 if (towupper(szInput[0]) == szOptions[0])
117 {
118 bResult = TRUE;
119 break;
120 }
121 else if (towupper(szInput[0]) == szOptions[1])
122 {
123 bResult = FALSE;
124 break;
125 }
126
127 ConPuts(StdOut, L"\n");
128 }
129
130 ConPuts(StdOut, L"\n");
131
132 return bResult;
133}
#define STRING_LABEL_PROMPT
Definition: resource.h:10
#define STRING_LABEL_OPTIONS
Definition: resource.h:11
void ConPuts(FILE *fp, LPCWSTR psz)
Definition: conutils_noros.h:8
#define StdOut
Definition: conutils_noros.h:6
void ConResPuts(FILE *fp, UINT nID)
#define TRUE
Definition: types.h:120
#define FALSE
Definition: types.h:117
#define ARRAYSIZE(array)
Definition: filtermapper.c:47
static VOID ConInString(LPWSTR lpInput, DWORD dwLength)
Definition: label.c:52
#define LoadStringW
Definition: utils.h:64
#define towupper(c)
Definition: wctype.h:99

Referenced by wmain().

◆ wmain()

int wmain ( int  argc,
WCHAR argv[] 
)

Definition at line 135 of file label.c.

136{
137 WCHAR szRootPath[] = L" :\\";
138 WCHAR szBuffer[80] = L"";
139 WCHAR szLabel[80] = L"";
140 WCHAR szOldLabel[80];
141 DWORD dwSerialNr;
142 INT i;
143
144 /* Initialize the Console Standard Streams */
146
147 /* print help */
148 if (argc > 1 && wcscmp(argv[1], L"/?") == 0)
149 {
151 return 0;
152 }
153
154 if (argc > 1)
155 {
156 size_t len = 0;
157 for (i = 1; i < argc; i++)
158 {
159 if (i > 1)
160 len++;
161 len += wcslen(argv[i]);
162 }
163
165 {
167 return 1;
168 }
169
170 for (i = 1; i < argc; i++)
171 {
172 if (i > 1)
173 wcscat(szBuffer, L" ");
174 wcscat(szBuffer, argv[i]);
175 }
176 }
177
178 if (wcslen(szBuffer) > 0)
179 {
180 if (szBuffer[1] == L':')
181 {
182 szRootPath[0] = towupper(szBuffer[0]);
183 wcscpy(szLabel, &szBuffer[2]);
184 }
185 else
186 {
187 wcscpy(szLabel, szBuffer);
188 }
189 }
190
191 if (wcslen(szLabel) > MAX_LABEL_LENGTH)
192 {
194 return 1;
195 }
196
197 if (szRootPath[0] == L' ')
198 {
199 /* get label of current drive */
200 WCHAR szCurPath[MAX_PATH];
201 GetCurrentDirectoryW(MAX_PATH, szCurPath);
202 szRootPath[0] = szCurPath[0];
203 }
204
205 /* check root path */
206 if (!IsValidPathName(szRootPath))
207 {
209 return 1;
210 }
211
212 if (wcslen(szLabel) == 0)
213 {
214 GetVolumeInformationW(szRootPath, szOldLabel, ARRAYSIZE(szOldLabel), &dwSerialNr,
215 NULL, NULL, NULL, 0);
216
217 /* print drive info */
218 if (szOldLabel[0] != UNICODE_NULL)
219 {
220 ConResPrintf(StdOut, STRING_LABEL_TEXT1, towupper(szRootPath[0]), szOldLabel);
221 }
222 else
223 {
225 }
226
227 /* print the volume serial number */
228 ConResPrintf(StdOut, STRING_LABEL_TEXT3, HIWORD(dwSerialNr), LOWORD(dwSerialNr));
229
231
232 ConInString(szLabel, ARRAYSIZE(szLabel));
233 ConPuts(StdOut, L"\n");
234
235 if (wcslen(szLabel) == 0)
236 {
237 if (PromptYesNo() == FALSE)
238 return 0;
239 }
240 }
241
242 if (!SetVolumeLabelW(szRootPath, szLabel))
243 {
245 return 1;
246 }
247
248 return 0;
249}
#define STRING_LABEL_TEXT4
Definition: resource.h:9
#define STRING_LABEL_HELP
Definition: resource.h:5
#define STRING_ERROR_INVALID_LABEL
Definition: resource.h:14
#define STRING_ERROR_INVALID_DRIVE
Definition: resource.h:13
#define STRING_LABEL_TEXT3
Definition: resource.h:8
#define STRING_LABEL_TEXT1
Definition: resource.h:6
#define STRING_LABEL_TEXT2
Definition: resource.h:7
#define ConInitStdStreams()
Definition: conutils_noros.h:5
void ConResPrintf(FILE *fp, UINT nID,...)
#define StdErr
Definition: conutils_noros.h:7
BOOL WINAPI GetVolumeInformationW(IN LPCWSTR lpRootPathName, IN LPWSTR lpVolumeNameBuffer, IN DWORD nVolumeNameSize, OUT LPDWORD lpVolumeSerialNumber OPTIONAL, OUT LPDWORD lpMaximumComponentLength OPTIONAL, OUT LPDWORD lpFileSystemFlags OPTIONAL, OUT LPWSTR lpFileSystemNameBuffer OPTIONAL, IN DWORD nFileSystemNameSize)
Definition: volume.c:226
BOOL WINAPI SetVolumeLabelW(IN LPCWSTR lpRootPathName, IN LPCWSTR lpVolumeName OPTIONAL)
Definition: volume.c:503
MonoAssembly int argc
Definition: metahost.c:107
_ACRTIMP size_t __cdecl wcslen(const wchar_t *)
Definition: wcs.c:2983
_ACRTIMP int __cdecl wcscmp(const wchar_t *, const wchar_t *)
Definition: wcs.c:1972
GLenum GLsizei len
Definition: glext.h:6722
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
static VOID ConFormatMessage(PCON_STREAM Stream, DWORD MessageId,...)
Definition: label.c:36
#define MAX_LABEL_LENGTH
Definition: label.c:31
static BOOL IsValidPathName(LPCWSTR pszPath)
Definition: label.c:86
static BOOL PromptYesNo(VOID)
Definition: label.c:101
#define MAX_DRIVE_LENGTH
Definition: label.c:32
#define argv
Definition: mplay32.c:18
#define LOWORD(l)
Definition: pedump.c:82
wcscat
wcscpy
int32_t INT
Definition: typedefs.h:58
#define HIWORD(l)
Definition: typedefs.h:247
DWORD WINAPI GetLastError(void)
Definition: except.c:1042