ReactOS  0.4.15-dev-425-gc40b086
label.c File Reference
#include <stdio.h>
#include <stdlib.h>
#include <windef.h>
#include <winbase.h>
#include <wincon.h>
#include <winnls.h>
#include <winuser.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 34 of file label.c.

◆ MAX_LABEL_LENGTH

#define MAX_LABEL_LENGTH   32

Definition at line 33 of file label.c.

Function Documentation

◆ ConFormatMessage()

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

Definition at line 39 of file label.c.

40 {
41  va_list arg_ptr;
42 
43  va_start(arg_ptr, MessageId);
46  NULL,
47  MessageId,
49  &arg_ptr);
50  va_end(arg_ptr);
51 }
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:1030
#define va_end(ap)
Definition: acmsvcex.h:90
smooth NULL
Definition: ftsmooth.c:416
char * va_list
Definition: acmsvcex.h:78
#define FORMAT_MESSAGE_FROM_SYSTEM
Definition: winbase.h:404
#define va_start(ap, A)
Definition: acmsvcex.h:91
_Inout_opt_ PUNICODE_STRING _Inout_opt_ PUNICODE_STRING Stream
Definition: fltkernel.h:1092
#define LANG_USER_DEFAULT
Definition: tnerror.cpp:50

Referenced by wmain().

◆ ConInString()

static VOID ConInString ( LPWSTR  lpInput,
DWORD  dwLength 
)
static

Definition at line 56 of file label.c.

57 {
58  DWORD dwOldMode;
59  DWORD dwRead = 0;
60  HANDLE hFile;
61  LPWSTR p;
62  PCHAR pBuf;
63 
65 
67  GetConsoleMode(hFile, &dwOldMode);
68 
70 
71  ReadFile(hFile, (PVOID)pBuf, dwLength - 1, &dwRead, NULL);
72 
73  MultiByteToWideChar(GetConsoleCP(), 0, pBuf, dwRead, lpInput, dwLength - 1);
74  HeapFree(GetProcessHeap(), 0, pBuf);
75 
76  for (p = lpInput; *p; p++)
77  {
78  if (*p == L'\x0d')
79  {
80  *p = UNICODE_NULL;
81  break;
82  }
83  }
84 
85  SetConsoleMode(hFile, dwOldMode);
86 }
signed char * PCHAR
Definition: retypes.h:7
BOOL WINAPI GetConsoleMode(HANDLE hConsoleHandle, LPDWORD lpMode)
Definition: console.c:1571
HANDLE WINAPI GetStdHandle(IN DWORD nStdHandle)
Definition: console.c:200
#define ENABLE_ECHO_INPUT
Definition: wincon.h:80
#define UNICODE_NULL
BOOL WINAPI DECLSPEC_HOTPATCH SetConsoleMode(HANDLE hConsoleHandle, DWORD dwMode)
Definition: console.c:1608
smooth NULL
Definition: ftsmooth.c:416
UINT WINAPI DECLSPEC_HOTPATCH GetConsoleCP(VOID)
Definition: console.c:2393
#define STD_INPUT_HANDLE
Definition: winbase.h:264
#define PCHAR
Definition: match.c:90
#define GetProcessHeap()
Definition: compat.h:404
PVOID WINAPI HeapAlloc(HANDLE, DWORD, SIZE_T)
static DWORD DWORD * dwLength
Definition: fusion.c:85
unsigned long DWORD
Definition: ntddk_ex.h:95
#define ENABLE_LINE_INPUT
Definition: wincon.h:79
static const WCHAR L[]
Definition: oid.c:1250
_In_ HANDLE hFile
Definition: mswsock.h:90
#define HEAP_ZERO_MEMORY
Definition: compat.h:123
#define MultiByteToWideChar
Definition: compat.h:100
GLfloat GLfloat p
Definition: glext.h:8902
WCHAR * LPWSTR
Definition: xmlstorage.h:184
BOOL WINAPI ReadFile(IN HANDLE hFile, IN LPVOID lpBuffer, IN DWORD nNumberOfBytesToRead, OUT LPDWORD lpNumberOfBytesRead OPTIONAL, IN LPOVERLAPPED lpOverlapped OPTIONAL)
Definition: rw.c:123
#define HeapFree(x, y, z)
Definition: compat.h:403

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

◆ IsValidPathName()

static BOOL IsValidPathName ( LPCWSTR  pszPath)
static

Definition at line 91 of file label.c.

92 {
93  WCHAR szOldPath[MAX_PATH];
94  BOOL bResult;
95 
96  GetCurrentDirectoryW(MAX_PATH, szOldPath);
97  bResult = SetCurrentDirectoryW(pszPath);
98 
99  SetCurrentDirectoryW(szOldPath);
100 
101  return bResult;
102 }
#define GetCurrentDirectoryW(x, y)
Definition: compat.h:422
unsigned int BOOL
Definition: ntddk_ex.h:94
__wchar_t WCHAR
Definition: xmlstorage.h:180
#define MAX_PATH
Definition: compat.h:26
BOOL WINAPI SetCurrentDirectoryW(IN LPCWSTR lpPathName)
Definition: path.c:2248

Referenced by cmd_vol(), and wmain().

◆ PromptYesNo()

static BOOL PromptYesNo ( VOID  )
static

Definition at line 107 of file label.c.

108 {
109  WCHAR szOptions[4];
110  WCHAR szInput[16];
111  BOOL bResult = FALSE;
112 
114 
115  for (;;)
116  {
117  ConPuts(StdOut, L"\n");
119 
120  ConInString(szInput, ARRAYSIZE(szInput));
121 
122  if (towupper(szInput[0]) == szOptions[0])
123  {
124  bResult = TRUE;
125  break;
126  }
127  else if (towupper(szInput[0]) == szOptions[1])
128  {
129  bResult = FALSE;
130  break;
131  }
132 
133  ConPuts(StdOut, L"\n");
134  }
135 
136  ConPuts(StdOut, L"\n");
137 
138  return bResult;
139 }
#define TRUE
Definition: types.h:120
static VOID ConInString(LPWSTR lpInput, DWORD dwLength)
Definition: label.c:56
#define ARRAYSIZE(array)
Definition: filtermapper.c:47
#define STRING_LABEL_PROMPT
Definition: resource.h:10
unsigned int BOOL
Definition: ntddk_ex.h:94
smooth NULL
Definition: ftsmooth.c:416
__wchar_t WCHAR
Definition: xmlstorage.h:180
INT ConResPuts(IN PCON_STREAM Stream, IN UINT uID)
Definition: outstream.c:610
static const WCHAR L[]
Definition: oid.c:1250
#define STRING_LABEL_OPTIONS
Definition: resource.h:11
#define GetModuleHandle
Definition: winbase.h:3667
INT ConPuts(IN PCON_STREAM Stream, IN LPWSTR szStr)
Definition: outstream.c:427
#define StdOut
Definition: stream.h:76
#define towupper(c)
Definition: wctype.h:99
#define LoadString
Definition: winuser.h:5794

Referenced by wmain().

◆ wmain()

int wmain ( int  argc,
WCHAR argv[] 
)

Definition at line 142 of file label.c.

143 {
144  WCHAR szRootPath[] = L" :\\";
145  WCHAR szBuffer[80] = L"";
146  WCHAR szLabel[80] = L"";
147  WCHAR szOldLabel[80];
148  DWORD dwSerialNr;
149  INT len, i;
150 
151  /* Initialize the Console Standard Streams */
153 
154  /* print help */
155  if (argc > 1 && wcscmp(argv[1], L"/?") == 0)
156  {
158  return 0;
159  }
160 
161  if (argc > 1)
162  {
163  len = 0;
164  for (i = 1; i < argc; i++)
165  {
166  if (i > 1)
167  len++;
168  len += wcslen(argv[i]);
169  }
170 
172  {
174  return 1;
175  }
176 
177  for (i = 1; i < argc; i++)
178  {
179  if (i > 1)
180  wcscat(szBuffer, L" ");
181  wcscat(szBuffer, argv[i]);
182  }
183  }
184 
185  if (wcslen(szBuffer) > 0)
186  {
187  if (szBuffer[1] == L':')
188  {
189  szRootPath[0] = towupper(szBuffer[0]);
190  wcscpy(szLabel, &szBuffer[2]);
191  }
192  else
193  {
194  wcscpy(szLabel, szBuffer);
195  }
196  }
197 
198  if (wcslen(szLabel) > MAX_LABEL_LENGTH)
199  {
201  return 1;
202  }
203 
204  if (szRootPath[0] == L' ')
205  {
206  /* get label of current drive */
207  WCHAR szCurPath[MAX_PATH];
208  GetCurrentDirectoryW(MAX_PATH, szCurPath);
209  szRootPath[0] = szCurPath[0];
210  }
211 
212  /* check root path */
213  if (!IsValidPathName(szRootPath))
214  {
216  return 1;
217  }
218 
219  if (wcslen(szLabel) == 0)
220  {
221  GetVolumeInformationW(szRootPath, szOldLabel, ARRAYSIZE(szOldLabel), &dwSerialNr,
222  NULL, NULL, NULL, 0);
223 
224  /* print drive info */
225  if (szOldLabel[0] != UNICODE_NULL)
226  {
227  ConResPrintf(StdOut, STRING_LABEL_TEXT1, towupper(szRootPath[0]), szOldLabel);
228  }
229  else
230  {
232  }
233 
234  /* print the volume serial number */
235  ConResPrintf(StdOut, STRING_LABEL_TEXT3, HIWORD(dwSerialNr), LOWORD(dwSerialNr));
236 
238 
239  ConInString(szLabel, ARRAYSIZE(szLabel));
240  ConPuts(StdOut, L"\n");
241 
242  if (wcslen(szLabel) == 0)
243  {
244  if (PromptYesNo() == FALSE)
245  return 0;
246  }
247  }
248 
249  if (!SetVolumeLabelW(szRootPath, szLabel))
250  {
252  return 1;
253  }
254 
255  return 0;
256 }
static int argc
Definition: ServiceArgs.c:12
#define GetCurrentDirectoryW(x, y)
Definition: compat.h:422
static VOID ConInString(LPWSTR lpInput, DWORD dwLength)
Definition: label.c:56
#define ARRAYSIZE(array)
Definition: filtermapper.c:47
DWORD WINAPI GetLastError(VOID)
Definition: except.c:1059
#define argv
Definition: mplay32.c:18
int32_t INT
Definition: typedefs.h:57
#define STRING_ERROR_INVALID_DRIVE
Definition: resource.h:13
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 ConInitStdStreams()
Definition: stream.h:122
#define STRING_ERROR_INVALID_LABEL
Definition: resource.h:14
#define UNICODE_NULL
#define STRING_LABEL_TEXT4
Definition: resource.h:9
#define STRING_LABEL_TEXT1
Definition: resource.h:6
smooth NULL
Definition: ftsmooth.c:416
#define MAX_DRIVE_LENGTH
Definition: label.c:34
#define STRING_LABEL_TEXT2
Definition: resource.h:7
INT __cdecl ConResPrintf(IN PCON_STREAM Stream, IN UINT uID,...)
Definition: outstream.c:781
__wchar_t WCHAR
Definition: xmlstorage.h:180
BOOL WINAPI SetVolumeLabelW(IN LPCWSTR lpRootPathName, IN LPCWSTR lpVolumeName OPTIONAL)
Definition: volume.c:503
#define MAX_PATH
Definition: compat.h:26
unsigned long DWORD
Definition: ntddk_ex.h:95
#define StdErr
Definition: stream.h:77
#define MAX_LABEL_LENGTH
Definition: label.c:33
INT ConResPuts(IN PCON_STREAM Stream, IN UINT uID)
Definition: outstream.c:610
#define STRING_LABEL_HELP
Definition: resource.h:5
_CRTIMP wchar_t *__cdecl wcscpy(_Out_writes_z_(_String_length_(_Source)+1) wchar_t *_Dest, _In_z_ const wchar_t *_Source)
static const WCHAR L[]
Definition: oid.c:1250
GLenum GLsizei len
Definition: glext.h:6722
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
_Check_return_ _CRTIMP int __cdecl wcscmp(_In_z_ const wchar_t *_Str1, _In_z_ const wchar_t *_Str2)
_CRTIMP wchar_t *__cdecl wcscat(_Inout_updates_z_(_String_length_(_Dest)+_String_length_(_Source)+1) wchar_t *_Dest, _In_z_ const wchar_t *_Source)
INT ConPuts(IN PCON_STREAM Stream, IN LPWSTR szStr)
Definition: outstream.c:427
#define STRING_LABEL_TEXT3
Definition: resource.h:8
static VOID ConFormatMessage(PCON_STREAM Stream, DWORD MessageId,...)
Definition: label.c:39
#define StdOut
Definition: stream.h:76
#define HIWORD(l)
Definition: typedefs.h:246
static BOOL IsValidPathName(LPCWSTR pszPath)
Definition: label.c:91
#define towupper(c)
Definition: wctype.h:99
#define LOWORD(l)
Definition: pedump.c:82
size_t __cdecl wcslen(_In_z_ const wchar_t *_Str)
static BOOL PromptYesNo(VOID)
Definition: label.c:107