[REGEDIT]
[reactos.git] / reactos / base / applications / regedit / regproc.c
index 2f675d0..facf2df 100644 (file)
  */
 #define REG_FILE_HEX_LINE_LEN   (2 + 25 * 3)
 
-static const CHAR *reg_class_names[] = {
-                                     "HKEY_LOCAL_MACHINE", "HKEY_USERS", "HKEY_CLASSES_ROOT",
-                                     "HKEY_CURRENT_CONFIG", "HKEY_CURRENT_USER", "HKEY_DYN_DATA"
-                                 };
+static const CHAR *reg_class_names[] =
+{
+    "HKEY_LOCAL_MACHINE", "HKEY_USERS", "HKEY_CLASSES_ROOT",
+    "HKEY_CURRENT_CONFIG", "HKEY_CURRENT_USER", "HKEY_DYN_DATA"
+};
 
 #define REG_CLASS_NUMBER (sizeof(reg_class_names) / sizeof(reg_class_names[0]))
 
-const WCHAR* reg_class_namesW[REG_CLASS_NUMBER] = {
+const WCHAR* reg_class_namesW[REG_CLASS_NUMBER] =
+{
     L"HKEY_LOCAL_MACHINE", L"HKEY_USERS", L"HKEY_CLASSES_ROOT",
     L"HKEY_CURRENT_CONFIG", L"HKEY_CURRENT_USER", L"HKEY_DYN_DATA"
 };
 
-static HKEY reg_class_keys[REG_CLASS_NUMBER] = {
-            HKEY_LOCAL_MACHINE, HKEY_USERS, HKEY_CLASSES_ROOT,
-            HKEY_CURRENT_CONFIG, HKEY_CURRENT_USER, HKEY_DYN_DATA
-        };
+static HKEY reg_class_keys[REG_CLASS_NUMBER] =
+{
+    HKEY_LOCAL_MACHINE, HKEY_USERS, HKEY_CLASSES_ROOT,
+    HKEY_CURRENT_CONFIG, HKEY_CURRENT_USER, HKEY_DYN_DATA
+};
 
 /* return values */
 #define NOT_ENOUGH_MEMORY     1
@@ -149,7 +152,8 @@ static BOOL convertHexToDWord(WCHAR* str, DWORD *dw)
     char dummy;
 
     WideCharToMultiByte(CP_ACP, 0, str, -1, buf, 9, NULL, NULL);
-    if (lstrlenW(str) > 8 || sscanf(buf, "%lx%c", dw, &dummy) != 1) {
+    if (lstrlenW(str) > 8 || sscanf(buf, "%lx%c", dw, &dummy) != 1)
+    {
         fprintf(stderr,"%s: ERROR, invalid hex value\n", getAppName());
         return FALSE;
     }
@@ -172,12 +176,14 @@ static BYTE* convertHexCSVToHex(WCHAR *str, DWORD *size)
     s = str;
     d = data;
     *size=0;
-    while (*s != '\0') {
+    while (*s != '\0')
+    {
         UINT wc;
         WCHAR *end;
 
         wc = wcstoul(s,&end, 16);
-        if (end == s || wc > 0xff || (*end && *end != L',')) {
+        if (end == s || wc > 0xff || (*end && *end != L','))
+        {
             char* strA = GetMultiByteString(s);
             fprintf(stderr,"%s: ERROR converting CSV hex stream. Invalid value at '%s'\n",
                     getAppName(), strA);
@@ -203,7 +209,13 @@ static BYTE* convertHexCSVToHex(WCHAR *str, DWORD *size)
  */
 static DWORD getDataType(LPWSTR *lpValue, DWORD* parse_type)
 {
-    struct data_type { const WCHAR *tag; int len; int type; int parse_type; };
+    struct data_type
+    {
+        const WCHAR *tag;
+        int len;
+        int type;
+        int parse_type;
+    };
 
     static const WCHAR quote[] = {'"'};
     static const WCHAR str[] = {'s','t','r',':','"'};
@@ -213,19 +225,20 @@ static DWORD getDataType(LPWSTR *lpValue, DWORD* parse_type)
     static const WCHAR hexp[] = {'h','e','x','('};
 
     static const struct data_type data_types[] = {                   /* actual type */  /* type to assume for parsing */
-                { quote,       1,   REG_SZ,              REG_SZ },
-                { str,         5,   REG_SZ,              REG_SZ },
-                { str2,        8,   REG_EXPAND_SZ,       REG_SZ },
-                { hex,         4,   REG_BINARY,          REG_BINARY },
-                { dword,       6,   REG_DWORD,           REG_DWORD },
-                { hexp,        4,   -1,                  REG_BINARY },
-                { NULL,        0,    0,                  0 }
-            };
+        { quote,       1,   REG_SZ,              REG_SZ },
+        { str,         5,   REG_SZ,              REG_SZ },
+        { str2,        8,   REG_EXPAND_SZ,       REG_SZ },
+        { hex,         4,   REG_BINARY,          REG_BINARY },
+        { dword,       6,   REG_DWORD,           REG_DWORD },
+        { hexp,        4,   -1,                  REG_BINARY },
+        { NULL,        0,    0,                  0 }
+    };
 
     const struct data_type *ptr;
     int type;
 
-    for (ptr = data_types; ptr->tag; ptr++) {
+    for (ptr = data_types; ptr->tag; ptr++)
+    {
         if (wcsncmp(ptr->tag, *lpValue, ptr->len))
             continue;
 
@@ -233,14 +246,18 @@ static DWORD getDataType(LPWSTR *lpValue, DWORD* parse_type)
         *parse_type = ptr->parse_type;
         type=ptr->type;
         *lpValue+=ptr->len;
-        if (type == -1) {
+        if (type == -1)
+        {
             WCHAR* end;
 
             /* "hex(xx):" is special */
             type = (int)wcstoul( *lpValue , &end, 16 );
-            if (**lpValue=='\0' || *end!=')' || *(end+1)!=':') {
+            if (**lpValue=='\0' || *end!=')' || *(end+1)!=':')
+            {
                 type=REG_NONE;
-            } else {
+            }
+            else
+            {
                 *lpValue = end + 2;
             }
         }
@@ -258,10 +275,13 @@ static void REGPROC_unescape_string(WCHAR* str)
     int str_idx = 0;            /* current character under analysis */
     int val_idx = 0;            /* the last character of the unescaped string */
     int len = lstrlenW(str);
-    for (str_idx = 0; str_idx < len; str_idx++, val_idx++) {
-        if (str[str_idx] == '\\') {
+    for (str_idx = 0; str_idx < len; str_idx++, val_idx++)
+    {
+        if (str[str_idx] == '\\')
+        {
             str_idx++;
-            switch (str[str_idx]) {
+            switch (str[str_idx])
+            {
             case 'n':
                 str[val_idx] = '\n';
                 break;
@@ -271,11 +291,13 @@ static void REGPROC_unescape_string(WCHAR* str)
                 break;
             default:
                 fprintf(stderr,"Warning! Unrecognized escape sequence: \\%c'\n",
-                        str[str_idx]);
+                str[str_idx]);
                 str[val_idx] = str[str_idx];
                 break;
             }
-        } else {
+        }
+        else
+        {
             str[val_idx] = str[str_idx];
         }
     }
@@ -310,9 +332,11 @@ static BOOL parseKeyName(LPWSTR lpKeyName, HKEY *hKey, LPWSTR *lpKeyPath)
     }
     *hKey = NULL;
 
-    for (i = 0; i < REG_CLASS_NUMBER; i++) {
+    for (i = 0; i < REG_CLASS_NUMBER; i++)
+    {
         if (CompareStringW(LOCALE_USER_DEFAULT, 0, lpKeyName, len, reg_class_namesW[i], len) == CSTR_EQUAL &&
-            len == lstrlenW(reg_class_namesW[i])) {
+        len == lstrlenW(reg_class_namesW[i]))
+        {
             *hKey = reg_class_keys[i];
             break;
         }
@@ -404,12 +428,12 @@ static LONG setValue(WCHAR* val_name, WCHAR* val_data, BOOL is_unicode)
     }
 
     res = RegSetValueExW(
-               currentKeyHandle,
-               val_name,
-               0,                  /* Reserved */
-               dwDataType,
-               lpbData,
-               dwLen);
+        currentKeyHandle,
+        val_name,
+        0,                  /* Reserved */
+        dwDataType,
+        lpbData,
+        dwLen);
     if (dwParseType == REG_BINARY)
         HeapFree(GetProcessHeap(), 0, lpbData);
     return res;
@@ -435,15 +459,15 @@ static LONG openKeyW(WCHAR* stdInput)
         return ERROR_INVALID_PARAMETER;
 
     res = RegCreateKeyExW(
-               keyClass,                 /* Class     */
-               keyPath,                  /* Sub Key   */
-               0,                        /* MUST BE 0 */
-               NULL,                     /* object type */
-               REG_OPTION_NON_VOLATILE,  /* option, REG_OPTION_NON_VOLATILE ... */
-               KEY_ALL_ACCESS,           /* access mask, KEY_ALL_ACCESS */
-               NULL,                     /* security attribute */
-               &currentKeyHandle,        /* result */
-               &dwDisp);                 /* disposition, REG_CREATED_NEW_KEY or
+        keyClass,                 /* Class     */
+        keyPath,                  /* Sub Key   */
+        0,                        /* MUST BE 0 */
+        NULL,                     /* object type */
+        REG_OPTION_NON_VOLATILE,  /* option, REG_OPTION_NON_VOLATILE ... */
+        KEY_ALL_ACCESS,           /* access mask, KEY_ALL_ACCESS */
+        NULL,                     /* security attribute */
+        &currentKeyHandle,        /* result */
+        &dwDisp);                 /* disposition, REG_CREATED_NEW_KEY or
                                                         REG_OPENED_EXISTING_KEY */
 
     if (res == ERROR_SUCCESS)
@@ -485,29 +509,39 @@ static void processSetValue(WCHAR* line, BOOL is_unicode)
 
     /* get value name */
     while ( iswspace(line[line_idx]) ) line_idx++;
-    if (line[line_idx] == '@' && line[line_idx + 1] == '=') {
+    if (line[line_idx] == '@' && line[line_idx + 1] == '=')
+    {
         line[line_idx] = '\0';
         val_name = line;
         line_idx++;
-    } else if (line[line_idx] == '\"') {
+    }
+    else if (line[line_idx] == '\"')
+    {
         line_idx++;
         val_name = line + line_idx;
-        while (TRUE) {
+        while (TRUE)
+        {
             if (line[line_idx] == '\\')   /* skip escaped character */
             {
                 line_idx += 2;
-            } else {
-                if (line[line_idx] == '\"') {
+            }
+            else
+            {
+                if (line[line_idx] == '\"')
+                {
                     line[line_idx] = '\0';
                     line_idx++;
                     break;
-                } else {
+                }
+                else
+                {
                     line_idx++;
                 }
             }
         }
         while ( iswspace(line[line_idx]) ) line_idx++;
-        if (line[line_idx] != '=') {
+        if (line[line_idx] != '=')
+        {
             char* lineA;
             line[line_idx] = '\"';
             lineA = GetMultiByteString(line);
@@ -516,7 +550,9 @@ static void processSetValue(WCHAR* line, BOOL is_unicode)
             return;
         }
 
-    } else {
+    }
+    else
+    {
         char* lineA = GetMultiByteString(line);
         fprintf(stderr,"Warning! unrecognized line:\n%s\n", lineA);
         HeapFree(GetProcessHeap(), 0, lineA);
@@ -538,10 +574,10 @@ static void processSetValue(WCHAR* line, BOOL is_unicode)
         char* val_nameA = GetMultiByteString(val_name);
         char* val_dataA = GetMultiByteString(val_data);
         fprintf(stderr,"%s: ERROR Key %s not created. Value: %s, Data: %s\n",
-                getAppName(),
-                currentKeyName,
-                val_nameA,
-                val_dataA);
+        getAppName(),
+        currentKeyName,
+        val_nameA,
+        val_dataA);
         HeapFree(GetProcessHeap(), 0, val_nameA);
         HeapFree(GetProcessHeap(), 0, val_dataA);
     }
@@ -558,7 +594,8 @@ static void processRegEntry(WCHAR* stdInput, BOOL isUnicode)
      * We encountered the end of the file, make sure we
      * close the opened key and exit
      */
-    if (stdInput == NULL) {
+    if (stdInput == NULL)
+    {
         closeKey();
         return;
     }
@@ -578,19 +615,22 @@ static void processRegEntry(WCHAR* stdInput, BOOL isUnicode)
         if ( stdInput[0] == '-')
         {
             delete_registry_key(stdInput + 1);
-        } else if ( openKeyW(stdInput) != ERROR_SUCCESS )
+        }
+        else if ( openKeyW(stdInput) != ERROR_SUCCESS )
         {
             char* stdInputA = GetMultiByteString(stdInput);
             fprintf(stderr,"%s: setValue failed to open key %s\n",
-                    getAppName(), stdInputA);
+            getAppName(), stdInputA);
             HeapFree(GetProcessHeap(), 0, stdInputA);
         }
-    } else if( currentKeyHandle &&
-               (( stdInput[0] == '@') || /* reading a default @=data pair */
-                ( stdInput[0] == '\"'))) /* reading a new value=data pair */
+    }
+    else if( currentKeyHandle &&
+    (( stdInput[0] == '@') || /* reading a default @=data pair */
+    ( stdInput[0] == '\"'))) /* reading a new value=data pair */
     {
         processSetValue(stdInput, isUnicode);
-    } else
+    }
+    else
     {
         /* Since we are assuming that the file format is valid we must be
          * reading a blank line which indicates the end of this key processing
@@ -614,13 +654,15 @@ static void processRegLinesA(FILE *in)
     line = HeapAlloc(GetProcessHeap(), 0, lineSize);
     CHECK_ENOUGH_MEMORY(line);
 
-    while (!feof(in)) {
+    while (!feof(in))
+    {
         LPSTR s; /* The pointer into line for where the current fgets should read */
         LPSTR check;
         WCHAR* lineW;
         s = line;
 
-        for (;;) {
+        for (;;)
+        {
             size_t size_remaining;
             int size_to_get;
             char *s_eol; /* various local uses */
@@ -650,11 +692,15 @@ static void processRegLinesA(FILE *in)
 
             check = fgets (s, size_to_get, in);
 
-            if (check == NULL) {
-                if (ferror(in)) {
+            if (check == NULL)
+            {
+                if (ferror(in))
+                {
                     perror ("While reading input");
                     exit (IO_ERROR);
-                } else {
+                }
+                else
+                {
                     assert (feof(in));
                     *s = '\0';
                     /* It is not clear to me from the definition that the
@@ -666,40 +712,46 @@ static void processRegLinesA(FILE *in)
 
             /* If we didn't read the eol nor the eof go around for the rest */
             s_eol = strchr (s, '\n');
-            if (!feof (in) && !s_eol) {
+            if (!feof (in) && !s_eol)
+            {
                 s = strchr (s, '\0');
                 /* It should be s + size_to_get - 1 but this is safer */
                 continue;
             }
 
             /* If it is a comment line then discard it and go around again */
-            if (line [0] == '#') {
+            if (line [0] == '#')
+            {
                 s = line;
                 continue;
             }
 
             /* Remove any line feed.  Leave s_eol on the \0 */
-            if (s_eol) {
+            if (s_eol)
+            {
                 *s_eol = '\0';
                 if (s_eol > line && *(s_eol-1) == '\r')
                     *--s_eol = '\0';
-            } else
+            }
+            else
                 s_eol = strchr (s, '\0');
 
             /* If there is a concatenating \\ then go around again */
-            if (s_eol > line && *(s_eol-1) == '\\') {
+            if (s_eol > line && *(s_eol-1) == '\\')
+            {
                 int c;
                 s = s_eol-1;
 
                 do
                 {
                     c = fgetc(in);
-                } while(c == ' ' || c == '\t');
+                }
+                while(c == ' ' || c == '\t');
 
                 if(c == EOF)
                 {
                     fprintf(stderr,"%s: ERROR - invalid continuation.\n",
-                            getAppName());
+                    getAppName());
                 }
                 else
                 {
@@ -737,7 +789,8 @@ static void processRegLinesW(FILE *in)
     s = buf;
     line = buf;
 
-    while(!feof(in)) {
+    while(!feof(in))
+    {
         size_t size_remaining;
         int size_to_get;
         WCHAR *s_eol = NULL; /* various local uses */
@@ -769,11 +822,15 @@ static void processRegLinesW(FILE *in)
         CharsInBuf = fread(s, sizeof(WCHAR), size_to_get - 1, in);
         s[CharsInBuf] = 0;
 
-        if (CharsInBuf == 0) {
-            if (ferror(in)) {
+        if (CharsInBuf == 0)
+        {
+            if (ferror(in))
+            {
                 perror ("While reading input");
                 exit (IO_ERROR);
-            } else {
+            }
+            else
+            {
                 assert (feof(in));
                 *s = '\0';
                 /* It is not clear to me from the definition that the
@@ -788,7 +845,8 @@ static void processRegLinesW(FILE *in)
         {
             s_eol = wcschr(line, '\n');
 
-            if(!s_eol) {
+            if(!s_eol)
+            {
                 /* Move the stub of the line to the start of the buffer so
                  * we get the maximum space to read into, and so we don't
                  * have to recalculate 'line' if the buffer expands */
@@ -799,14 +857,16 @@ static void processRegLinesW(FILE *in)
             }
 
             /* If it is a comment line then discard it and go around again */
-            if (*line == '#') {
+            if (*line == '#')
+            {
                 line = s_eol + 1;
                 continue;
             }
 
             /* If there is a concatenating \\ then go around again */
             if ((*(s_eol-1) == '\\') ||
-                (*(s_eol-1) == '\r' && *(s_eol-2) == '\\')) {
+            (*(s_eol-1) == '\r' && *(s_eol-2) == '\\'))
+            {
                 WCHAR* NextLine = s_eol;
 
                 while(*(NextLine+1) == ' ' || *(NextLine+1) == '\t')
@@ -824,7 +884,8 @@ static void processRegLinesW(FILE *in)
             }
 
             /* Remove any line feed.  Leave s_eol on the \0 */
-            if (s_eol) {
+            if (s_eol)
+            {
                 *s_eol = '\0';
                 if (s_eol > buf && *(s_eol-1) == '\r')
                     *(s_eol-1) = '\0';
@@ -859,10 +920,11 @@ static void REGPROC_print_error(void)
 
     error_code = GetLastError ();
     status = FormatMessage(FORMAT_MESSAGE_ALLOCATE_BUFFER | FORMAT_MESSAGE_FROM_SYSTEM,
-                           NULL, error_code, 0, (LPTSTR) &lpMsgBuf, 0, NULL);
-    if (!status) {
+    NULL, error_code, 0, (LPTSTR) &lpMsgBuf, 0, NULL);
+    if (!status)
+    {
         fprintf(stderr,"%s: Cannot display message for error %ld, status %ld\n",
-                getAppName(), error_code, GetLastError());
+        getAppName(), error_code, GetLastError());
         exit(1);
     }
     puts(lpMsgBuf);
@@ -883,7 +945,8 @@ static void REGPROC_print_error(void)
 static void REGPROC_resize_char_buffer(WCHAR **buffer, DWORD *len, DWORD required_len)
 {
     required_len++;
-    if (required_len > *len) {
+    if (required_len > *len)
+    {
         *len = required_len;
         if (!*buffer)
             *buffer = HeapAlloc(GetProcessHeap(), 0, *len * sizeof(**buffer));
@@ -903,7 +966,8 @@ static void REGPROC_resize_char_buffer(WCHAR **buffer, DWORD *len, DWORD require
  */
 static void REGPROC_resize_binary_buffer(BYTE **buffer, DWORD *size, DWORD required_size)
 {
-    if (required_size > *size) {
+    if (required_size > *size)
+    {
         *size = required_size;
         if (!*buffer)
             *buffer = HeapAlloc(GetProcessHeap(), 0, *size);
@@ -925,9 +989,11 @@ static void REGPROC_export_string(WCHAR **line_buf, DWORD *line_buf_size, DWORD
 
     /* escaping characters */
     pos = *line_len;
-    for (i = 0; i < str_len; i++) {
+    for (i = 0; i < str_len; i++)
+    {
         WCHAR c = str[i];
-        switch (c) {
+        switch (c)
+        {
         case '\n':
             extra++;
             REGPROC_resize_char_buffer(line_buf, line_buf_size, *line_len + str_len + extra);
@@ -962,9 +1028,12 @@ static void REGPROC_export_binary(WCHAR **line_buf, DWORD *line_buf_size, DWORD
     const WCHAR newline[] = {'\n',0};
     CHAR* value_multibyte = NULL;
 
-    if (type == REG_BINARY) {
+    if (type == REG_BINARY)
+    {
         hex_prefix = hex;
-    } else {
+    }
+    else
+    {
         const WCHAR hex_format[] = {'h','e','x','(','%','u',')',':',0};
         hex_prefix = hex_buf;
         wsprintfW(hex_buf, hex_format, type);
@@ -1011,7 +1080,8 @@ static void REGPROC_export_binary(WCHAR **line_buf, DWORD *line_buf_size, DWORD
             column += 3;
 
             /* wrap the line */
-            if (column >= REG_FILE_HEX_LINE_LEN) {
+            if (column >= REG_FILE_HEX_LINE_LEN)
+            {
                 lstrcpyW(*line_buf + data_pos, concat);
                 data_pos += concat_len;
                 column = concat_prefix;
@@ -1062,11 +1132,11 @@ static void REGPROC_write_line(FILE *file, const WCHAR* str, BOOL unicode)
  * val_size - size of the buffer for storing values in bytes.
  */
 static void export_hkey(FILE *file, HKEY key,
-                 WCHAR **reg_key_name_buf, DWORD *reg_key_name_size,
-                 WCHAR **val_name_buf, DWORD *val_name_size,
-                 BYTE **val_buf, DWORD *val_size,
-                 WCHAR **line_buf, DWORD *line_buf_size,
-                 BOOL unicode)
+WCHAR **reg_key_name_buf, DWORD *reg_key_name_size,
+WCHAR **val_name_buf, DWORD *val_name_size,
+BYTE **val_buf, DWORD *val_size,
+WCHAR **line_buf, DWORD *line_buf_size,
+BOOL unicode)
 {
     DWORD max_sub_key_len;
     DWORD max_val_name_len;
@@ -1079,16 +1149,17 @@ static void export_hkey(FILE *file, HKEY key,
 
     /* get size information and resize the buffers if necessary */
     if (RegQueryInfoKeyW(key, NULL, NULL, NULL, NULL,
-                        &max_sub_key_len, NULL,
-                        NULL, &max_val_name_len, &max_val_size, NULL, NULL
-                       ) != ERROR_SUCCESS) {
+    &max_sub_key_len, NULL,
+    NULL, &max_val_name_len, &max_val_size, NULL, NULL
+                        ) != ERROR_SUCCESS)
+    {
         REGPROC_print_error();
     }
     curr_len = lstrlenW(*reg_key_name_buf);
     REGPROC_resize_char_buffer(reg_key_name_buf, reg_key_name_size,
-                               max_sub_key_len + curr_len + 1);
+    max_sub_key_len + curr_len + 1);
     REGPROC_resize_char_buffer(val_name_buf, val_name_size,
-                               max_val_name_len);
+    max_val_name_len);
     REGPROC_resize_binary_buffer(val_buf, val_size, max_val_size);
     REGPROC_resize_char_buffer(line_buf, line_buf_size, lstrlenW(*reg_key_name_buf) + 4);
     /* output data for the current key */
@@ -1098,26 +1169,34 @@ static void export_hkey(FILE *file, HKEY key,
     /* print all the values */
     i = 0;
     more_data = TRUE;
-    while(more_data) {
+    while(more_data)
+    {
         DWORD value_type;
         DWORD val_name_size1 = *val_name_size;
         DWORD val_size1 = *val_size;
         ret = RegEnumValueW(key, i, *val_name_buf, &val_name_size1, NULL,
-                           &value_type, *val_buf, &val_size1);
-        if (ret == ERROR_MORE_DATA) {
+        &value_type, *val_buf, &val_size1);
+        if (ret == ERROR_MORE_DATA)
+        {
             /* Increase the size of the buffers and retry */
             REGPROC_resize_char_buffer(val_name_buf, val_name_size, val_name_size1);
             REGPROC_resize_binary_buffer(val_buf, val_size, val_size1);
-        } else if (ret != ERROR_SUCCESS) {
+        }
+        else if (ret != ERROR_SUCCESS)
+        {
             more_data = FALSE;
-            if (ret != ERROR_NO_MORE_ITEMS) {
+            if (ret != ERROR_NO_MORE_ITEMS)
+            {
                 REGPROC_print_error();
             }
-        } else {
+        }
+        else
+        {
             DWORD line_len;
             i++;
 
-            if ((*val_name_buf)[0]) {
+            if ((*val_name_buf)[0])
+            {
                 const WCHAR val_start[] = {'"','%','s','"','=',0};
 
                 line_len = 0;
@@ -1128,22 +1207,28 @@ static void export_hkey(FILE *file, HKEY key,
                 line_len = 3 + lstrlenW(*val_name_buf);
                 REGPROC_resize_char_buffer(line_buf, line_buf_size, line_len);
                 wsprintfW(*line_buf, val_start, *val_name_buf);
-            } else {
+            }
+            else
+            {
                 const WCHAR std_val[] = {'@','=',0};
                 line_len = 2;
                 REGPROC_resize_char_buffer(line_buf, line_buf_size, line_len);
                 lstrcpyW(*line_buf, std_val);
             }
 
-            switch (value_type) {
+            switch (value_type)
+            {
             case REG_SZ:
             {
                 WCHAR* wstr = (WCHAR*)*val_buf;
 
                 if (val_size1 < sizeof(WCHAR) || val_size1 % sizeof(WCHAR) ||
-                    wstr[val_size1 / sizeof(WCHAR) - 1]) {
+                wstr[val_size1 / sizeof(WCHAR) - 1])
+                {
                     REGPROC_export_binary(line_buf, line_buf_size, &line_len, value_type, *val_buf, val_size1, unicode);
-                } else {
+                }
+                else
+                {
                     const WCHAR start[] = {'"',0};
                     const WCHAR end[] = {'"','\n',0};
                     DWORD len;
@@ -1178,14 +1263,14 @@ static void export_hkey(FILE *file, HKEY key,
                 char* key_nameA = GetMultiByteString(*reg_key_name_buf);
                 char* value_nameA = GetMultiByteString(*val_name_buf);
                 fprintf(stderr,"%s: warning - unsupported registry format '%ld', "
-                        "treat as binary\n",
-                        getAppName(), value_type);
+                "treat as binary\n",
+                getAppName(), value_type);
                 fprintf(stderr,"key name: \"%s\"\n", key_nameA);
                 fprintf(stderr,"value name:\"%s\"\n\n", value_nameA);
                 HeapFree(GetProcessHeap(), 0, key_nameA);
                 HeapFree(GetProcessHeap(), 0, value_nameA);
             }
-                /* falls through */
+            /* falls through */
             case REG_EXPAND_SZ:
             case REG_MULTI_SZ:
                 /* falls through */
@@ -1199,30 +1284,40 @@ static void export_hkey(FILE *file, HKEY key,
     i = 0;
     more_data = TRUE;
     (*reg_key_name_buf)[curr_len] = '\\';
-    while(more_data) {
+    while(more_data)
+    {
         DWORD buf_size = *reg_key_name_size - curr_len - 1;
 
         ret = RegEnumKeyExW(key, i, *reg_key_name_buf + curr_len + 1, &buf_size,
-                           NULL, NULL, NULL, NULL);
-        if (ret == ERROR_MORE_DATA) {
+        NULL, NULL, NULL, NULL);
+        if (ret == ERROR_MORE_DATA)
+        {
             /* Increase the size of the buffer and retry */
             REGPROC_resize_char_buffer(reg_key_name_buf, reg_key_name_size, curr_len + 1 + buf_size);
-        } else if (ret != ERROR_SUCCESS) {
+        }
+        else if (ret != ERROR_SUCCESS)
+        {
             more_data = FALSE;
-            if (ret != ERROR_NO_MORE_ITEMS) {
+            if (ret != ERROR_NO_MORE_ITEMS)
+            {
                 REGPROC_print_error();
             }
-        } else {
+        }
+        else
+        {
             HKEY subkey;
 
             i++;
             if (RegOpenKeyW(key, *reg_key_name_buf + curr_len + 1,
-                           &subkey) == ERROR_SUCCESS) {
+            &subkey) == ERROR_SUCCESS)
+            {
                 export_hkey(file, subkey, reg_key_name_buf, reg_key_name_size,
-                            val_name_buf, val_name_size, val_buf, val_size,
-                            line_buf, line_buf_size, unicode);
+                val_name_buf, val_name_size, val_buf, val_size,
+                line_buf, line_buf_size, unicode);
                 RegCloseKey(subkey);
-            } else {
+            }
+            else
+            {
                 REGPROC_print_error();
             }
         }
@@ -1246,7 +1341,8 @@ static FILE *REGPROC_open_export_file(WCHAR *file_name, BOOL unicode)
             file = _wfopen(file_name, L"wb");
         else
             file = _wfopen(file_name, L"w");
-        if (!file) {
+        if (!file)
+        {
             CHAR* file_nameA = GetMultiByteString(file_name);
             perror("");
             fprintf(stderr,"%s: Can't open file \"%s\"\n", getAppName(), file_nameA);
@@ -1291,75 +1387,87 @@ BOOL export_registry_key(WCHAR *file_name, WCHAR *reg_key_name, DWORD format)
     BOOL unicode = (format == REG_FORMAT_5);
 
     reg_key_name_buf = HeapAlloc(GetProcessHeap(), 0,
-                                 reg_key_name_size  * sizeof(*reg_key_name_buf));
+    reg_key_name_size  * sizeof(*reg_key_name_buf));
     val_name_buf = HeapAlloc(GetProcessHeap(), 0,
-                             val_name_size * sizeof(*val_name_buf));
+    val_name_size * sizeof(*val_name_buf));
     val_buf = HeapAlloc(GetProcessHeap(), 0, val_size);
     line_buf = HeapAlloc(GetProcessHeap(), 0, line_buf_size * sizeof(*line_buf));
     CHECK_ENOUGH_MEMORY(reg_key_name_buf && val_name_buf && val_buf && line_buf);
 
-    if (reg_key_name && reg_key_name[0]) {
+    if (reg_key_name && reg_key_name[0])
+    {
         HKEY reg_key_class;
         WCHAR *branch_name = NULL;
         HKEY key;
 
         REGPROC_resize_char_buffer(&reg_key_name_buf, &reg_key_name_size,
-                                   lstrlenW(reg_key_name));
+        lstrlenW(reg_key_name));
         lstrcpyW(reg_key_name_buf, reg_key_name);
 
         /* open the specified key */
-        if (!parseKeyName(reg_key_name, &reg_key_class, &branch_name)) {
+        if (!parseKeyName(reg_key_name, &reg_key_class, &branch_name))
+        {
             CHAR* key_nameA = GetMultiByteString(reg_key_name);
             fprintf(stderr,"%s: Incorrect registry class specification in '%s'\n",
-                    getAppName(), key_nameA);
+            getAppName(), key_nameA);
             HeapFree(GetProcessHeap(), 0, key_nameA);
             exit(1);
         }
-        if (!branch_name[0]) {
+        if (!branch_name[0])
+        {
             /* no branch - registry class is specified */
             file = REGPROC_open_export_file(file_name, unicode);
             export_hkey(file, reg_key_class,
-                        &reg_key_name_buf, &reg_key_name_size,
-                        &val_name_buf, &val_name_size,
-                        &val_buf, &val_size, &line_buf,
-                        &line_buf_size, unicode);
-        } else if (RegOpenKeyW(reg_key_class, branch_name, &key) == ERROR_SUCCESS) {
+            &reg_key_name_buf, &reg_key_name_size,
+            &val_name_buf, &val_name_size,
+            &val_buf, &val_size, &line_buf,
+            &line_buf_size, unicode);
+        }
+        else if (RegOpenKeyW(reg_key_class, branch_name, &key) == ERROR_SUCCESS)
+        {
             file = REGPROC_open_export_file(file_name, unicode);
             export_hkey(file, key,
-                        &reg_key_name_buf, &reg_key_name_size,
-                        &val_name_buf, &val_name_size,
-                        &val_buf, &val_size, &line_buf,
-                        &line_buf_size, unicode);
+            &reg_key_name_buf, &reg_key_name_size,
+            &val_name_buf, &val_name_size,
+            &val_buf, &val_size, &line_buf,
+            &line_buf_size, unicode);
             RegCloseKey(key);
-        } else {
+        }
+        else
+        {
             CHAR* key_nameA = GetMultiByteString(reg_key_name);
             fprintf(stderr,"%s: Can't export. Registry key '%s' does not exist!\n",
-                    getAppName(), key_nameA);
+            getAppName(), key_nameA);
             HeapFree(GetProcessHeap(), 0, key_nameA);
             REGPROC_print_error();
         }
-    } else {
+    }
+    else
+    {
         unsigned int i;
 
         /* export all registry classes */
         file = REGPROC_open_export_file(file_name, unicode);
-        for (i = 0; i < REG_CLASS_NUMBER; i++) {
+        for (i = 0; i < REG_CLASS_NUMBER; i++)
+        {
             /* do not export HKEY_CLASSES_ROOT */
             if (reg_class_keys[i] != HKEY_CLASSES_ROOT &&
-                    reg_class_keys[i] != HKEY_CURRENT_USER &&
-                    reg_class_keys[i] != HKEY_CURRENT_CONFIG &&
-                    reg_class_keys[i] != HKEY_DYN_DATA) {
+            reg_class_keys[i] != HKEY_CURRENT_USER &&
+            reg_class_keys[i] != HKEY_CURRENT_CONFIG &&
+            reg_class_keys[i] != HKEY_DYN_DATA)
+            {
                 lstrcpyW(reg_key_name_buf, reg_class_namesW[i]);
                 export_hkey(file, reg_class_keys[i],
-                            &reg_key_name_buf, &reg_key_name_size,
-                            &val_name_buf, &val_name_size,
-                            &val_buf, &val_size, &line_buf,
-                            &line_buf_size, unicode);
+                &reg_key_name_buf, &reg_key_name_size,
+                &val_name_buf, &val_name_size,
+                &val_buf, &val_size, &line_buf,
+                &line_buf_size, unicode);
             }
         }
     }
 
-    if (file) {
+    if (file)
+    {
         fclose(file);
     }
     HeapFree(GetProcessHeap(), 0, reg_key_name);
@@ -1382,7 +1490,8 @@ BOOL import_registry_file(FILE* reg_file)
             if (s[0] == 0xff && s[1] == 0xfe)
             {
                 processRegLinesW(reg_file);
-            } else
+            }
+            else
             {
                 fseek(reg_file, 0, SEEK_SET);
                 processRegLinesA(reg_file);
@@ -1408,17 +1517,19 @@ void delete_registry_key(WCHAR *reg_key_name)
     if (!reg_key_name || !reg_key_name[0])
         return;
 
-    if (!parseKeyName(reg_key_name, &key_class, &key_name)) {
+    if (!parseKeyName(reg_key_name, &key_class, &key_name))
+    {
         char* reg_key_nameA = GetMultiByteString(reg_key_name);
         fprintf(stderr,"%s: Incorrect registry class specification in '%s'\n",
-                getAppName(), reg_key_nameA);
+        getAppName(), reg_key_nameA);
         HeapFree(GetProcessHeap(), 0, reg_key_nameA);
         exit(1);
     }
-    if (!*key_name) {
+    if (!*key_name)
+    {
         char* reg_key_nameA = GetMultiByteString(reg_key_name);
         fprintf(stderr,"%s: Can't delete registry class '%s'\n",
-                getAppName(), reg_key_nameA);
+        getAppName(), reg_key_nameA);
         HeapFree(GetProcessHeap(), 0, reg_key_nameA);
         exit(1);
     }