ReactOS  0.4.15-dev-5463-g138eb58
regedit.c File Reference
#include <stdlib.h>
#include <windows.h>
#include <commctrl.h>
#include <shellapi.h>
#include "wine/debug.h"
#include "main.h"
Include dependency graph for regedit.c:

Go to the source code of this file.

Enumerations

enum  REGEDIT_ACTION {
  ACTION_ADD, ACTION_EXPORT, ACTION_DELETE, ACTION_UNDEF,
  ACTION_ADD, ACTION_EXPORT, ACTION_DELETE, ACTION_VIEW
}
 

Functions

 WINE_DEFAULT_DEBUG_CHANNEL (regedit)
 
static void output_writeconsole (const WCHAR *str, DWORD wlen)
 
static void output_formatstring (const WCHAR *fmt, va_list va_args)
 
void WINAPIV output_message (unsigned int id,...)
 
void WINAPIV error_exit (unsigned int id,...)
 
static void PerformRegAction (REGEDIT_ACTION action, WCHAR **argv, int *i)
 
BOOL ProcessCmdLine (WCHAR *cmdline)
 

Enumeration Type Documentation

◆ REGEDIT_ACTION

Enumerator
ACTION_ADD 
ACTION_EXPORT 
ACTION_DELETE 
ACTION_UNDEF 
ACTION_ADD 
ACTION_EXPORT 
ACTION_DELETE 
ACTION_VIEW 

Definition at line 122 of file regedit.c.

Function Documentation

◆ error_exit()

void WINAPIV error_exit ( unsigned int  id,
  ... 
)

Definition at line 103 of file regedit.c.

104 {
105  WCHAR fmt[1536];
106  va_list va_args;
107 
109  {
110 #ifndef __REACTOS__
111  WINE_FIXME("LoadString failed with %lu\n", GetLastError());
112 #endif
113  return;
114  }
115  va_start(va_args, id);
116  output_formatstring(fmt, va_args);
117  va_end(va_args);
118 
119  exit(0); /* regedit.exe always terminates with error code zero */
120 }
static void output_formatstring(const WCHAR *fmt, va_list va_args)
Definition: regedit.c:65
DWORD WINAPI GetLastError(VOID)
Definition: except.c:1040
int WINAPI LoadStringW(_In_opt_ HINSTANCE hInstance, _In_ UINT uID, _Out_writes_to_(cchBufferMax, return+1) LPWSTR lpBuffer, _In_ int cchBufferMax)
#define va_end(ap)
Definition: acmsvcex.h:90
char * va_list
Definition: acmsvcex.h:78
__wchar_t WCHAR
Definition: xmlstorage.h:180
va_start(ap, x)
#define ARRAY_SIZE(a)
Definition: main.h:24
#define NULL
Definition: types.h:112
HMODULE WINAPI GetModuleHandleW(LPCWSTR lpModuleName)
Definition: loader.c:838
void exit(int exitcode)
Definition: _exit.c:33
Definition: dsound.c:943
#define WINE_FIXME
Definition: debug.h:366

Referenced by delete_registry_key(), PerformRegAction(), ProcessCmdLine(), and REGPROC_open_export_file().

◆ output_formatstring()

static void output_formatstring ( const WCHAR fmt,
va_list  va_args 
)
static

Definition at line 65 of file regedit.c.

66 {
67  WCHAR *str;
68  DWORD len;
69 
70 #ifdef __REACTOS__
72 #endif
74  fmt, 0, 0, (WCHAR *)&str, 0, &va_args);
75 #ifdef __REACTOS__
76  if (len == 0 && GetLastError() != NO_ERROR)
77 #else
78  if (len == 0 && GetLastError() != ERROR_NO_WORK_DONE)
79 #endif
80  {
81  WINE_FIXME("Could not format string: le=%lu, fmt=%s\n", GetLastError(), wine_dbgstr_w(fmt));
82  return;
83  }
85  LocalFree(str);
86 }
char * wine_dbgstr_w(const wchar_t *wstr)
Definition: atltest.h:87
#define FORMAT_MESSAGE_FROM_STRING
Definition: winbase.h:421
DWORD WINAPI GetLastError(VOID)
Definition: except.c:1040
DWORD WINAPI FormatMessageW(DWORD dwFlags, LPCVOID lpSource, DWORD dwMessageId, DWORD dwLanguageId, LPWSTR lpBuffer, DWORD nSize, __ms_va_list *args)
Definition: format_msg.c:583
#define NO_ERROR
Definition: dderror.h:5
#define FORMAT_MESSAGE_ALLOCATE_BUFFER
Definition: winbase.h:419
const WCHAR * str
__wchar_t WCHAR
Definition: xmlstorage.h:180
unsigned long DWORD
Definition: ntddk_ex.h:95
#define SetLastError(x)
Definition: compat.h:752
GLenum GLsizei len
Definition: glext.h:6722
HLOCAL NTAPI LocalFree(HLOCAL hMem)
Definition: heapmem.c:1577
Definition: dsound.c:943
static void output_writeconsole(const WCHAR *str, DWORD wlen)
Definition: regedit.c:35
#define WINE_FIXME
Definition: debug.h:366

Referenced by error_exit(), and output_message().

◆ output_message()

void WINAPIV output_message ( unsigned int  id,
  ... 
)

Definition at line 88 of file regedit.c.

89 {
90  WCHAR fmt[1536];
91  va_list va_args;
92 
94  {
95  WINE_FIXME("LoadString failed with %ld\n", GetLastError());
96  return;
97  }
98  va_start(va_args, id);
99  output_formatstring(fmt, va_args);
100  va_end(va_args);
101 }
static void output_formatstring(const WCHAR *fmt, va_list va_args)
Definition: regedit.c:65
DWORD WINAPI GetLastError(VOID)
Definition: except.c:1040
int WINAPI LoadStringW(_In_opt_ HINSTANCE hInstance, _In_ UINT uID, _Out_writes_to_(cchBufferMax, return+1) LPWSTR lpBuffer, _In_ int cchBufferMax)
#define va_end(ap)
Definition: acmsvcex.h:90
char * va_list
Definition: acmsvcex.h:78
__wchar_t WCHAR
Definition: xmlstorage.h:180
va_start(ap, x)
#define ARRAY_SIZE(a)
Definition: main.h:24
#define NULL
Definition: types.h:112
HMODULE WINAPI GetModuleHandleW(LPCWSTR lpModuleName)
Definition: loader.c:838
Definition: dsound.c:943
#define WINE_FIXME
Definition: debug.h:366

Referenced by PerformRegAction(), and ProcessCmdLine().

◆ output_writeconsole()

static void output_writeconsole ( const WCHAR str,
DWORD  wlen 
)
static

Definition at line 35 of file regedit.c.

36 {
37 #ifdef __REACTOS__
38  /* This is win32gui application, don't ever try writing to console.
39  * For the console version we have a separate reg.exe application. */
40  WCHAR AppStr[255];
41  LoadStringW(hInst, IDS_APP_TITLE, AppStr, ARRAY_SIZE(AppStr));
43 #else
44  DWORD count;
45 
47  {
48  DWORD len;
49  char *msgA;
50 
51  /* WriteConsole() fails on Windows if its output is redirected. If this occurs,
52  * we should call WriteFile() with OEM code page.
53  */
54  len = WideCharToMultiByte(GetOEMCP(), 0, str, wlen, NULL, 0, NULL, NULL);
55  msgA = malloc(len);
56  if (!msgA) return;
57 
58  WideCharToMultiByte(GetOEMCP(), 0, str, wlen, msgA, len, NULL, NULL);
60  free(msgA);
61  }
62 #endif
63 }
BOOL WINAPI WriteFile(IN HANDLE hFile, IN LPCVOID lpBuffer, IN DWORD nNumberOfBytesToWrite OPTIONAL, OUT LPDWORD lpNumberOfBytesWritten, IN LPOVERLAPPED lpOverlapped OPTIONAL)
Definition: rw.c:24
#define WideCharToMultiByte
Definition: compat.h:111
BOOL WINAPI DECLSPEC_HOTPATCH WriteConsoleW(IN HANDLE hConsoleOutput, IN CONST VOID *lpBuffer, IN DWORD nNumberOfCharsToWrite, OUT LPDWORD lpNumberOfCharsWritten, LPVOID lpReserved)
Definition: readwrite.c:1447
GLuint GLuint GLsizei count
Definition: gl.h:1545
#define free
Definition: debug_ros.c:5
HANDLE WINAPI GetStdHandle(IN DWORD nStdHandle)
Definition: console.c:203
int WINAPI MessageBoxW(_In_opt_ HWND hWnd, _In_opt_ LPCWSTR lpText, _In_opt_ LPCWSTR lpCaption, _In_ UINT uType)
int WINAPI LoadStringW(_In_opt_ HINSTANCE hInstance, _In_ UINT uID, _Out_writes_to_(cchBufferMax, return+1) LPWSTR lpBuffer, _In_ int cchBufferMax)
#define FALSE
Definition: types.h:117
const WCHAR * str
__wchar_t WCHAR
Definition: xmlstorage.h:180
unsigned long DWORD
Definition: ntddk_ex.h:95
#define MB_ICONINFORMATION
Definition: winuser.h:796
GLenum GLsizei len
Definition: glext.h:6722
#define STD_OUTPUT_HANDLE
Definition: winbase.h:268
HINSTANCE hInst
Definition: dxdiag.c:13
#define ARRAY_SIZE(a)
Definition: main.h:24
#define NULL
Definition: types.h:112
#define MB_OK
Definition: winuser.h:784
#define IDS_APP_TITLE
Definition: resource.h:10
#define malloc
Definition: debug_ros.c:4
UINT WINAPI GetOEMCP(VOID)
Definition: nls.c:2322

Referenced by output_formatstring().

◆ PerformRegAction()

static void PerformRegAction ( REGEDIT_ACTION  action,
WCHAR **  argv,
int i 
)
static

Definition at line 126 of file regedit.c.

127 {
128  switch (action) {
129  case ACTION_ADD: {
130  WCHAR *filename = argv[*i];
131  WCHAR *realname = NULL;
132  FILE *reg_file;
133 
134  if (!lstrcmpW(filename, L"-"))
135  reg_file = stdin;
136  else
137  {
138  int size;
139 
141  if (size > 0)
142  {
143  realname = malloc(size * sizeof(WCHAR));
144  size = SearchPathW(NULL, filename, NULL, size, realname, NULL);
145  }
146  if (size == 0)
147  {
149  free(realname);
150  return;
151  }
152  reg_file = _wfopen(realname, L"rb");
153  if (reg_file == NULL)
154  {
155  _wperror(L"regedit");
157  free(realname);
158  return;
159  }
160  }
161  import_registry_file(reg_file);
162  if (realname)
163  {
164  free(realname);
165  fclose(reg_file);
166  }
167  break;
168  }
169  case ACTION_DELETE:
171  break;
172  case ACTION_EXPORT: {
173  WCHAR *filename = argv[*i];
174  WCHAR *key_name = argv[++(*i)];
175 
176  if (key_name && *key_name)
178  else
180  break;
181  }
182  default:
184  break;
185  }
186 }
_Check_return_ _CRTIMP FILE *__cdecl _wfopen(_In_z_ const wchar_t *_Filename, _In_z_ const wchar_t *_Mode)
int WINAPI lstrcmpW(LPCWSTR lpString1, LPCWSTR lpString2)
Definition: lstring.c:170
#define free
Definition: debug_ros.c:5
FILE * stdin
#define STRING_UNHANDLED_ACTION
Definition: resource.h:309
#define argv
Definition: mplay32.c:18
const char * filename
Definition: ioapi.h:137
#define L(x)
Definition: ntvdm.h:50
void delete_registry_key(WCHAR *reg_key_name)
Definition: regproc.c:1097
GLsizeiptr size
Definition: glext.h:5919
__wchar_t WCHAR
Definition: xmlstorage.h:180
BOOL export_registry_key(WCHAR *file_name, WCHAR *path, DWORD format)
Definition: regproc.c:1548
BOOL import_registry_file(FILE *reg_file)
Definition: regproc.c:1049
void WINAPIV error_exit(unsigned int id,...)
Definition: regedit.c:103
#define STRING_FILE_NOT_FOUND
Definition: resource.h:8
_Check_return_opt_ _CRTIMP int __cdecl fclose(_Inout_ FILE *_File)
_CRTIMP void __cdecl _wperror(_In_opt_z_ const wchar_t *_ErrMsg)
#define STRING_CANNOT_OPEN_FILE
Definition: resource.h:308
DWORD WINAPI SearchPathW(IN LPCWSTR lpPath OPTIONAL, IN LPCWSTR lpFileName, IN LPCWSTR lpExtension OPTIONAL, IN DWORD nBufferLength, OUT LPWSTR lpBuffer, OUT LPWSTR *lpFilePart OPTIONAL)
Definition: path.c:1298
const WCHAR * action
Definition: action.c:7479
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
void WINAPIV output_message(unsigned int id,...)
Definition: regedit.c:88
#define NULL
Definition: types.h:112
#define malloc
Definition: debug_ros.c:4
#define REG_FORMAT_5
Definition: main.h:44

Referenced by ProcessCmdLine().

◆ ProcessCmdLine()

BOOL ProcessCmdLine ( WCHAR cmdline)

Definition at line 188 of file regedit.c.

189 {
190  WCHAR **argv;
191  int argc, i;
193 
195 
196  if (!argv)
197  return FALSE;
198 
199  if (argc == 1)
200  {
201  LocalFree(argv);
202  return FALSE;
203  }
204 
205  for (i = 1; i < argc; i++)
206  {
207  if (argv[i][0] != '/' && argv[i][0] != '-')
208  break; /* No flags specified. */
209 
210  if (!argv[i][1] && argv[i][0] == '-')
211  break; /* '-' is a filename. It indicates we should use stdin. */
212 
213  if (argv[i][1] && argv[i][2] && argv[i][2] != ':')
214  break; /* This is a file path beginning with '/'. */
215 
216  switch (towupper(argv[i][1]))
217  {
218  case '?':
220  break;
221  case 'D':
223  break;
224  case 'E':
226  break;
227  case 'C':
228  case 'L':
229  case 'M':
230  case 'R':
231  /* unhandled */;
232  break;
233  case 'S':
234  case 'V':
235  /* ignored */;
236  break;
237  default:
240  }
241  }
242 
243  if (i == argc)
244  {
245  switch (action)
246  {
247  case ACTION_ADD:
248  case ACTION_EXPORT:
250  break;
251  case ACTION_DELETE:
253  break;
254  }
256  }
257 
258  for (; i < argc; i++)
260 
261  LocalFree(argv);
262 
263  return TRUE;
264 }
#define STRING_INVALID_SWITCH
Definition: resource.h:303
static int argc
Definition: ServiceArgs.c:12
#define STRING_USAGE
Definition: resource.h:44
#define TRUE
Definition: types.h:120
TCHAR * cmdline
Definition: stretchblt.cpp:32
#define argv
Definition: mplay32.c:18
#define STRING_NO_FILENAME
Definition: resource.h:305
#define FALSE
Definition: types.h:117
LPWSTR *WINAPI CommandLineToArgvW(LPCWSTR lpCmdline, int *numargs)
Definition: shell32_main.c:80
__wchar_t WCHAR
Definition: xmlstorage.h:180
#define STRING_NO_REG_KEY
Definition: resource.h:306
void WINAPIV error_exit(unsigned int id,...)
Definition: regedit.c:103
REGEDIT_ACTION
Definition: regedit.c:122
static void PerformRegAction(REGEDIT_ACTION action, WCHAR **argv, int *i)
Definition: regedit.c:126
const WCHAR * action
Definition: action.c:7479
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
HLOCAL NTAPI LocalFree(HLOCAL hMem)
Definition: heapmem.c:1577
void WINAPIV output_message(unsigned int id,...)
Definition: regedit.c:88
#define STRING_HELP
Definition: xcopy.h:74
#define towupper(c)
Definition: wctype.h:99

Referenced by wWinMain().

◆ WINE_DEFAULT_DEBUG_CHANNEL()

WINE_DEFAULT_DEBUG_CHANNEL ( regedit  )