Author: cwittich
Date: Sat Dec 8 17:29:51 2007
New Revision: 31081
URL:
http://svn.reactos.org/svn/reactos?rev=31081&view=rev
Log:
Francois Gouget : Add missing '\n' to an error message. <fgouget at
codeweavers.com>
Francois Gouget : Modify getRegClass() to avoid dubious comparisons and casts between
HKEYs and error codes.
Francois Gouget : Having garbage after the dash in '"foo"=-' is not
valid.
Francois Gouget : The registry functions return standard error codes, not HRESULTs.
Francois Gouget : If the data for a given value is in an unknown format, then print an
error and don't modify the value.
Modified:
trunk/reactos/base/applications/regedit/regproc.c
trunk/reactos/base/applications/regedit/regproc.h
Modified: trunk/reactos/base/applications/regedit/regproc.c
URL:
http://svn.reactos.org/svn/reactos/trunk/reactos/base/applications/regedit/…
==============================================================================
--- trunk/reactos/base/applications/regedit/regproc.c (original)
+++ trunk/reactos/base/applications/regedit/regproc.c Sat Dec 8 17:29:51 2007
@@ -61,7 +61,7 @@
#define CHECK_ENOUGH_MEMORY(p) \
if (!(p)) \
{ \
- fprintf(stderr,"%s: file %s, line %d: Not enough memory", \
+ fprintf(stderr,"%s: file %s, line %d: Not enough memory\n", \
getAppName(), __FILE__, __LINE__); \
exit(NOT_ENOUGH_MEMORY); \
}
@@ -305,7 +305,8 @@
}
return type;
}
- return (**lpValue=='\0'?REG_SZ:REG_NONE);
+ *parse_type=REG_NONE;
+ return REG_NONE;
}
/******************************************************************************
@@ -413,9 +414,9 @@
* val_name - name of the registry value
* val_data - registry value data
*/
-HRESULT setValue(LPSTR val_name, LPSTR val_data)
-{
- HRESULT hRes;
+LONG setValue(LPSTR val_name, LPSTR val_data)
+{
+ LONG res;
DWORD dwDataType, dwParseType = REG_BINARY;
LPBYTE lpbData;
BYTE convert[KEY_MAX_LEN];
@@ -425,10 +426,16 @@
if ( (val_name == NULL) || (val_data == NULL) )
return ERROR_INVALID_PARAMETER;
+ if (strcmp(val_data, "-") == 0)
+ {
+ res=RegDeleteValueA(currentKeyHandle,val_name);
+ return (res == ERROR_FILE_NOT_FOUND ? ERROR_SUCCESS : res);
+ }
+
/* Get the data type stored into the value field */
dwDataType = getDataType(&val_data, &dwParseType);
- if ( dwParseType == REG_SZ) /* no conversion for string */
+ if (dwParseType == REG_SZ) /* no conversion for string */
{
dwLen = (DWORD) strlen(val_data);
if (dwLen>0 && val_data[dwLen-1]=='"')
@@ -439,11 +446,13 @@
dwLen++;
REGPROC_unescape_string(val_data);
lpbData = (LPBYTE)val_data;
- } else if (dwParseType == REG_DWORD) /* Convert the dword types */
+ }
+ else if (dwParseType == REG_DWORD) /* Convert the dword types */
{
dwLen = convertHexToDWord(val_data, convert);
lpbData = convert;
- } else /* Convert the hexadecimal types */
+ }
+ else if (dwParseType == REG_BINARY) /* Convert the binary data */
{
size_t b_len = strlen (val_data)+2/3;
if (b_len > KEY_MAX_LEN) {
@@ -456,8 +465,13 @@
lpbData = convert;
}
}
-
- hRes = RegSetValueExA(
+ else /* unknown format */
+ {
+ fprintf(stderr,"%s: ERROR, unknown data format\n", getAppName());
+ return ERROR_INVALID_DATA;
+ }
+
+ res = RegSetValueExA(
currentKeyHandle,
val_name,
0, /* Reserved */
@@ -467,33 +481,32 @@
if (bBigBuffer)
HeapFree (GetProcessHeap(), 0, bBigBuffer);
- return hRes;
+ return res;
}
/******************************************************************************
* Open the key
*/
-HRESULT openKey( LPSTR stdInput)
-{
- DWORD dwDisp;
- HRESULT hRes;
+LONG openKey( LPSTR stdInput)
+{
+ DWORD dwDisp;
+ LONG res;
/* Sanity checks */
if (stdInput == NULL)
return ERROR_INVALID_PARAMETER;
/* Get the registry class */
- currentKeyClass = getRegClass(stdInput); /* Sets global variable */
- if (currentKeyClass == (HKEY)ERROR_INVALID_PARAMETER)
- return (HRESULT)ERROR_INVALID_PARAMETER;
+ if (!getRegClass(stdInput, ¤tKeyClass)) /* Sets global variable */
+ return ERROR_INVALID_PARAMETER;
/* Get the key name */
currentKeyName = getRegKeyName(stdInput); /* Sets global variable */
if (currentKeyName == NULL)
return ERROR_INVALID_PARAMETER;
- hRes = RegCreateKeyExA(
+ res = RegCreateKeyExA(
currentKeyClass, /* Class */
currentKeyName, /* Sub Key */
0, /* MUST BE 0 */
@@ -505,10 +518,10 @@
&dwDisp); /* disposition, REG_CREATED_NEW_KEY or
REG_OPENED_EXISTING_KEY */
- if (hRes == ERROR_SUCCESS)
+ if (res == ERROR_SUCCESS)
bTheKeyIsOpen = TRUE;
- return hRes;
+ return res;
}
@@ -548,7 +561,7 @@
* Extracts from [HKEY\some\key\path] or HKEY\some\key\path types of line
* the key class (what ends before the first '\')
*/
-HKEY getRegClass(LPSTR lpClass)
+BOOL getRegClass(LPSTR lpClass, HKEY* hkey)
{
LPSTR classNameEnd;
LPSTR classNameBeg;
@@ -557,7 +570,7 @@
char lpClassCopy[KEY_MAX_LEN];
if (lpClass == NULL)
- return (HKEY)ERROR_INVALID_PARAMETER;
+ return FALSE;
lstrcpynA(lpClassCopy, lpClass, KEY_MAX_LEN);
@@ -579,10 +592,11 @@
for (i = 0; i < REG_CLASS_NUMBER; i++) {
if (!strcmp(classNameBeg, reg_class_names[i])) {
- return reg_class_keys[i];
- }
- }
- return (HKEY)ERROR_INVALID_PARAMETER;
+ *hkey = reg_class_keys[i];
+ return TRUE;
+ }
+ }
+ return FALSE;
}
/******************************************************************************
@@ -724,7 +738,7 @@
LPSTR val_data; /* registry value data */
int line_idx = 0; /* current character under analysis */
- HRESULT hRes = 0;
+ LONG res;
/* get value name */
if (line[line_idx] == '@' && line[line_idx + 1] == '=') {
@@ -767,8 +781,8 @@
val_data = line + line_idx;
REGPROC_unescape_string(val_name);
- hRes = setValue(val_name, val_data);
- if ( hRes != ERROR_SUCCESS )
+ res = setValue(val_name, val_data);
+ if ( res != ERROR_SUCCESS )
fprintf(stderr,"%s: ERROR Key %s not created. Value: %s, Data: %s\n",
getAppName(),
currentKeyName,
@@ -1372,8 +1386,7 @@
strcpy(reg_key_name_buf, reg_key_name);
/* open the specified key */
- reg_key_class = getRegClass(reg_key_name);
- if (reg_key_class == (HKEY)ERROR_INVALID_PARAMETER) {
+ if (!getRegClass(reg_key_name, ®_key_class)) {
fprintf(stderr,"%s: Incorrect registry class specification in
'%s'\n",
getAppName(), reg_key_name);
exit(1);
Modified: trunk/reactos/base/applications/regedit/regproc.h
URL:
http://svn.reactos.org/svn/reactos/trunk/reactos/base/applications/regedit/…
==============================================================================
--- trunk/reactos/base/applications/regedit/regproc.h (original)
+++ trunk/reactos/base/applications/regedit/regproc.h Sat Dec 8 17:29:51 2007
@@ -57,7 +57,7 @@
LPSTR convertHexToHexCSV( BYTE *buf, ULONG len);
LPSTR convertHexToDWORDStr( BYTE *buf, ULONG len);
LPSTR getRegKeyName(LPSTR lpLine);
-HKEY getRegClass(LPSTR lpLine);
+BOOL getRegClass(LPSTR lpLine, HKEY* hkey);
DWORD getDataType(LPSTR *lpValue, DWORD* parse_type);
LPSTR getArg(LPSTR arg);
HRESULT openKey(LPSTR stdInput);