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
22 static int reg_printfW(const WCHAR
*msg
, ...)
27 WCHAR msg_buffer
[8192];
29 va_start(va_args
, msg
);
30 wvsprintfW(msg_buffer
, msg
, va_args
);
33 wlen
= lstrlenW(msg_buffer
);
34 ret
= WriteConsoleW(GetStdHandle(STD_OUTPUT_HANDLE
), msg_buffer
, wlen
, &count
, NULL
);
40 len
= WideCharToMultiByte(GetConsoleOutputCP(), 0, msg_buffer
, wlen
,
42 msgA
= HeapAlloc(GetProcessHeap(), 0, len
* sizeof(char));
46 WideCharToMultiByte(GetConsoleOutputCP(), 0, msg_buffer
, wlen
, msgA
, len
,
48 WriteFile(GetStdHandle(STD_OUTPUT_HANDLE
), msgA
, len
, &count
, FALSE
);
49 HeapFree(GetProcessHeap(), 0, msgA
);
55 static int reg_message(int msg
, ...)
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
);
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
);
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
);
89 static int reg_query(WCHAR
*key_name
, WCHAR
*value_name
, BOOL value_empty
,
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
);
99 int wmain(int argc
, WCHAR
*argvW
[])
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};
116 reg_message(STRING_USAGE
);
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
;
127 reg_message(STRING_ADD_USAGE
);
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
))
138 else if (!lstrcmpiW(argvW
[i
], slashTW
))
140 else if (!lstrcmpiW(argvW
[i
], slashSW
))
141 separator
= argvW
[++i
][0];
142 else if (!lstrcmpiW(argvW
[i
], slashDW
))
144 else if (!lstrcmpiW(argvW
[i
], slashFW
))
147 return reg_add(key_name
, value_name
, value_empty
, type
, separator
,
150 else if (!lstrcmpiW(argvW
[1], deleteW
))
152 WCHAR
*key_name
, *value_name
= NULL
;
153 BOOL value_empty
= FALSE
, value_all
= FALSE
, force
= FALSE
;
157 reg_message(STRING_DELETE_USAGE
);
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
))
168 else if (!lstrcmpiW(argvW
[i
], slashVAW
))
170 else if (!lstrcmpiW(argvW
[i
], slashFW
))
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
;
182 reg_message(STRING_QUERY_USAGE
);
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
))
193 else if (!lstrcmpiW(argvW
[i
], slashSW
))
196 return reg_query(key_name
, value_name
, value_empty
, subkey
);