push a2e7360632735b5a2be8f61a9725e4e6969c5533
[wine/hacks.git] / programs / reg / reg.c
blob043872c8d42a8bd9d518ee49e52adada4f81cdbe
1 /*
2 * Copyright 2008 Andrew Riedi
4 * This library is free software; you can redistribute it and/or
5 * modify it under the terms of the GNU Lesser General Public
6 * License as published by the Free Software Foundation; either
7 * version 2.1 of the License, or (at your option) any later version.
9 * This library is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 * Lesser General Public License for more details.
14 * You should have received a copy of the GNU Lesser General Public
15 * License along with this library; if not, write to the Free Software
16 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
19 #include <windows.h>
20 #include "reg.h"
22 static int reg_printfW(const WCHAR *msg, ...)
24 va_list va_args;
25 int wlen;
26 DWORD count, ret;
27 WCHAR msg_buffer[8192];
29 va_start(va_args, msg);
30 wvsprintfW(msg_buffer, msg, va_args);
31 va_end(va_args);
33 wlen = lstrlenW(msg_buffer);
34 ret = WriteConsoleW(GetStdHandle(STD_OUTPUT_HANDLE), msg_buffer, wlen, &count, NULL);
35 if (!ret)
37 DWORD len;
38 char *msgA;
40 len = WideCharToMultiByte(GetConsoleOutputCP(), 0, msg_buffer, wlen,
41 NULL, 0, NULL, NULL);
42 msgA = HeapAlloc(GetProcessHeap(), 0, len * sizeof(char));
43 if (!msgA)
44 return 0;
46 WideCharToMultiByte(GetConsoleOutputCP(), 0, msg_buffer, wlen, msgA, len,
47 NULL, NULL);
48 WriteFile(GetStdHandle(STD_OUTPUT_HANDLE), msgA, len, &count, FALSE);
49 HeapFree(GetProcessHeap(), 0, msgA);
52 return count;
55 static int reg_message(int msg, ...)
57 va_list va_args;
58 WCHAR msg_buffer[8192];
60 LoadStringW(GetModuleHandleW(NULL), msg, msg_buffer,
61 sizeof(msg_buffer)/sizeof(WCHAR));
62 va_start(va_args, msg);
63 reg_printfW(msg_buffer, va_args);
64 va_end(va_args);
66 return 0;
69 static int reg_add(WCHAR *key_name, WCHAR *value_name, BOOL value_empty,
70 WCHAR *type, WCHAR separator, WCHAR *data, BOOL force)
72 const WCHAR stubW[] = {'S','T','U','B',' ','A','D','D',' ','-',' ','%','s',
73 ' ','%','s',' ','%','d',' ','%','s',' ','%','s',' ','%','d','\n',0};
74 reg_printfW(stubW, key_name, value_name, value_empty, type, data, force);
76 return 1;
79 static int reg_delete(WCHAR *key_name, WCHAR *value_name, BOOL value_empty,
80 BOOL value_all, BOOL force)
82 const WCHAR stubW[] = {'S','T','U','B',' ','D','E','L','E','T','E',' ','-',
83 ' ','%','s',' ','%','s',' ','%','d',' ','%','d',' ','%','d','\n',0};
84 reg_printfW(stubW, key_name, value_name, value_empty, value_all, force);
86 return 1;
89 static int reg_query(WCHAR *key_name, WCHAR *value_name, BOOL value_empty,
90 BOOL subkey)
92 const WCHAR stubW[] = {'S','T','U','B',' ','Q','U','E','R','Y',' ','-',' ',
93 '%','s',' ','%','s',' ','%','d',' ','%','d','\n',0};
94 reg_printfW(stubW, key_name, value_name, value_empty, subkey);
96 return 1;
99 int wmain(int argc, WCHAR *argvW[])
101 int i;
103 const WCHAR addW[] = {'a','d','d',0};
104 const WCHAR deleteW[] = {'d','e','l','e','t','e',0};
105 const WCHAR queryW[] = {'q','u','e','r','y',0};
106 const WCHAR slashDW[] = {'/','d',0};
107 const WCHAR slashFW[] = {'/','f',0};
108 const WCHAR slashSW[] = {'/','s',0};
109 const WCHAR slashTW[] = {'/','t',0};
110 const WCHAR slashVW[] = {'/','v',0};
111 const WCHAR slashVAW[] = {'/','v','a',0};
112 const WCHAR slashVEW[] = {'/','v','e',0};
114 if (argc < 2)
116 reg_message(STRING_USAGE);
117 return 1;
120 if (!lstrcmpiW(argvW[1], addW))
122 WCHAR *key_name, *value_name = NULL, *type = NULL, separator = '\0', *data = NULL;
123 BOOL value_empty = FALSE, force = FALSE;
125 if (argc < 3)
127 reg_message(STRING_ADD_USAGE);
128 return 1;
131 key_name = argvW[2];
132 for (i = 1; i < argc; i++)
134 if (!lstrcmpiW(argvW[i], slashVW))
135 value_name = argvW[++i];
136 else if (!lstrcmpiW(argvW[i], slashVEW))
137 value_empty = TRUE;
138 else if (!lstrcmpiW(argvW[i], slashTW))
139 type = argvW[++i];
140 else if (!lstrcmpiW(argvW[i], slashSW))
141 separator = argvW[++i][0];
142 else if (!lstrcmpiW(argvW[i], slashDW))
143 data = argvW[++i];
144 else if (!lstrcmpiW(argvW[i], slashFW))
145 force = TRUE;
147 return reg_add(key_name, value_name, value_empty, type, separator,
148 data, force);
150 else if (!lstrcmpiW(argvW[1], deleteW))
152 WCHAR *key_name, *value_name = NULL;
153 BOOL value_empty = FALSE, value_all = FALSE, force = FALSE;
155 if (argc < 3)
157 reg_message(STRING_DELETE_USAGE);
158 return 1;
161 key_name = argvW[2];
162 for (i = 1; i < argc; i++)
164 if (!lstrcmpiW(argvW[i], slashVW))
165 value_name = argvW[++i];
166 else if (!lstrcmpiW(argvW[i], slashVEW))
167 value_empty = TRUE;
168 else if (!lstrcmpiW(argvW[i], slashVAW))
169 value_all = TRUE;
170 else if (!lstrcmpiW(argvW[i], slashFW))
171 force = TRUE;
173 return reg_delete(key_name, value_name, value_empty, value_all, force);
175 else if (!lstrcmpiW(argvW[1], queryW))
177 WCHAR *key_name, *value_name = NULL;
178 BOOL value_empty = FALSE, subkey = FALSE;
180 if (argc < 3)
182 reg_message(STRING_QUERY_USAGE);
183 return 1;
186 key_name = argvW[2];
187 for (i = 1; i < argc; i++)
189 if (!lstrcmpiW(argvW[i], slashVW))
190 value_name = argvW[++i];
191 else if (!lstrcmpiW(argvW[i], slashVEW))
192 value_empty = TRUE;
193 else if (!lstrcmpiW(argvW[i], slashSW))
194 subkey = TRUE;
196 return reg_query(key_name, value_name, value_empty, subkey);
199 return 0;