ReactOS 0.4.16-dev-109-gf4cb10f
import.c File Reference
#include <errno.h>
#include <stdio.h>
#include "reg.h"
#include <wine/debug.h>
Include dependency graph for import.c:

Go to the source code of this file.

Classes

struct  parser
 

Macros

#define REG_VAL_BUF_SIZE   4096
 

Typedefs

typedef WCHAR *(* parser_state_func) (struct parser *parser, WCHAR *pos)
 

Enumerations

enum  parser_state {
  HEADER , PARSE_WIN31_LINE , LINE_START , KEY_NAME ,
  DELETE_KEY , DEFAULT_VALUE_NAME , QUOTED_VALUE_NAME , DATA_START ,
  DELETE_VALUE , DATA_TYPE , STRING_DATA , DWORD_DATA ,
  HEX_DATA , EOL_BACKSLASH , HEX_MULTILINE , UNKNOWN_DATA ,
  SET_VALUE , NB_PARSER_STATES , HEADER , PARSE_WIN31_LINE ,
  LINE_START , KEY_NAME , DELETE_KEY , DEFAULT_VALUE_NAME ,
  QUOTED_VALUE_NAME , DATA_START , DELETE_VALUE , DATA_TYPE ,
  STRING_DATA , DWORD_DATA , HEX_DATA , EOL_BACKSLASH ,
  HEX_MULTILINE , UNKNOWN_DATA , SET_VALUE , NB_PARSER_STATES ,
  LINE_START , SECTION_NAME , KEY_NAME , VALUE_NAME ,
  EOL_BACKSLASH , QUOTES , LEADING_SPACES , TRAILING_SPACES ,
  COMMENT , NB_PARSER_STATES , LINE_START , SECTION_NAME ,
  KEY_NAME , VALUE_NAME , EOL_BACKSLASH , QUOTES ,
  LEADING_SPACES , TRAILING_SPACES , COMMENT , NB_PARSER_STATES ,
  LINE_START , SECTION_NAME , KEY_NAME , VALUE_NAME ,
  EOL_BACKSLASH , QUOTES , LEADING_SPACES , TRAILING_SPACES ,
  COMMENT , NB_PARSER_STATES
}
 
enum  reg_versions {
  REG_VERSION_31 , REG_VERSION_40 , REG_VERSION_50 , REG_VERSION_FUZZY ,
  REG_VERSION_INVALID , REG_VERSION_31 , REG_VERSION_40 , REG_VERSION_50 ,
  REG_VERSION_FUZZY , REG_VERSION_INVALID
}
 

Functions

 WINE_DEFAULT_DEBUG_CHANNEL (reg)
 
static WCHARGetWideString (const char *strA)
 
static WCHARGetWideStringN (const char *strA, int size, DWORD *len)
 
static WCHARheader_state (struct parser *parser, WCHAR *pos)
 
static WCHARparse_win31_line_state (struct parser *parser, WCHAR *pos)
 
static WCHARline_start_state (struct parser *parser, WCHAR *pos)
 
static WCHARkey_name_state (struct parser *parser, WCHAR *pos)
 
static WCHARdelete_key_state (struct parser *parser, WCHAR *pos)
 
static WCHARdefault_value_name_state (struct parser *parser, WCHAR *pos)
 
static WCHARquoted_value_name_state (struct parser *parser, WCHAR *pos)
 
static WCHARdata_start_state (struct parser *parser, WCHAR *pos)
 
static WCHARdelete_value_state (struct parser *parser, WCHAR *pos)
 
static WCHARdata_type_state (struct parser *parser, WCHAR *pos)
 
static WCHARstring_data_state (struct parser *parser, WCHAR *pos)
 
static WCHARdword_data_state (struct parser *parser, WCHAR *pos)
 
static WCHARhex_data_state (struct parser *parser, WCHAR *pos)
 
static WCHAReol_backslash_state (struct parser *parser, WCHAR *pos)
 
static WCHARhex_multiline_state (struct parser *parser, WCHAR *pos)
 
static WCHARunknown_data_state (struct parser *parser, WCHAR *pos)
 
static WCHARset_value_state (struct parser *parser, WCHAR *pos)
 
static enum parser_state set_state (struct parser *parser, enum parser_state state)
 
static BOOL convert_hex_to_dword (WCHAR *str, DWORD *dw)
 
static BOOL convert_hex_csv_to_hex (struct parser *parser, WCHAR **str)
 
static BOOL parse_data_type (struct parser *parser, WCHAR **line)
 
static BOOL unescape_string (WCHAR *str, WCHAR **unparsed)
 
static HKEY parse_key_name (WCHAR *key_name, WCHAR **key_path)
 
static void close_key (struct parser *parser)
 
static LONG open_key (struct parser *parser, WCHAR *path)
 
static void free_parser_data (struct parser *parser)
 
static void prepare_hex_string_data (struct parser *parser)
 
static enum reg_versions parse_file_header (const WCHAR *s)
 
static WCHARget_lineA (FILE *fp)
 
static WCHARget_lineW (FILE *fp)
 
int reg_import (int argc, WCHAR *argvW[])
 

Variables

static WCHAR *(* get_line )(FILE *)
 
static const parser_state_func parser_funcs [NB_PARSER_STATES]
 

Macro Definition Documentation

◆ REG_VAL_BUF_SIZE

#define REG_VAL_BUF_SIZE   4096

Definition at line 868 of file import.c.

Typedef Documentation

◆ parser_state_func

typedef WCHAR *(* parser_state_func) (struct parser *parser, WCHAR *pos)

Definition at line 98 of file import.c.

Enumeration Type Documentation

◆ parser_state

Enumerator
HEADER 
PARSE_WIN31_LINE 
LINE_START 
KEY_NAME 
DELETE_KEY 
DEFAULT_VALUE_NAME 
QUOTED_VALUE_NAME 
DATA_START 
DELETE_VALUE 
DATA_TYPE 
STRING_DATA 
DWORD_DATA 
HEX_DATA 
EOL_BACKSLASH 
HEX_MULTILINE 
UNKNOWN_DATA 
SET_VALUE 
NB_PARSER_STATES 
HEADER 
PARSE_WIN31_LINE 
LINE_START 
KEY_NAME 
DELETE_KEY 
DEFAULT_VALUE_NAME 
QUOTED_VALUE_NAME 
DATA_START 
DELETE_VALUE 
DATA_TYPE 
STRING_DATA 
DWORD_DATA 
HEX_DATA 
EOL_BACKSLASH 
HEX_MULTILINE 
UNKNOWN_DATA 
SET_VALUE 
NB_PARSER_STATES 
LINE_START 
SECTION_NAME 
KEY_NAME 
VALUE_NAME 
EOL_BACKSLASH 
QUOTES 
LEADING_SPACES 
TRAILING_SPACES 
COMMENT 
NB_PARSER_STATES 
LINE_START 
SECTION_NAME 
KEY_NAME 
VALUE_NAME 
EOL_BACKSLASH 
QUOTES 
LEADING_SPACES 
TRAILING_SPACES 
COMMENT 
NB_PARSER_STATES 
LINE_START 
SECTION_NAME 
KEY_NAME 
VALUE_NAME 
EOL_BACKSLASH 
QUOTES 
LEADING_SPACES 
TRAILING_SPACES 
COMMENT 
NB_PARSER_STATES 

Definition at line 58 of file import.c.

59{
60 HEADER, /* parsing the registry file version header */
61 PARSE_WIN31_LINE, /* parsing a Windows 3.1 registry line */
62 LINE_START, /* at the beginning of a registry line */
63 KEY_NAME, /* parsing a key name */
64 DELETE_KEY, /* deleting a registry key */
65 DEFAULT_VALUE_NAME, /* parsing a default value name */
66 QUOTED_VALUE_NAME, /* parsing a double-quoted value name */
67 DATA_START, /* preparing for data parsing operations */
68 DELETE_VALUE, /* deleting a registry value */
69 DATA_TYPE, /* parsing the registry data type */
70 STRING_DATA, /* parsing REG_SZ data */
71 DWORD_DATA, /* parsing DWORD data */
72 HEX_DATA, /* parsing REG_BINARY, REG_NONE, REG_EXPAND_SZ or REG_MULTI_SZ data */
73 EOL_BACKSLASH, /* preparing to parse multiple lines of hex data */
74 HEX_MULTILINE, /* parsing multiple lines of hex data */
75 UNKNOWN_DATA, /* parsing an unhandled or invalid data type */
76 SET_VALUE, /* adding a value to the registry */
78};
@ PARSE_WIN31_LINE
Definition: import.c:61
@ HEX_DATA
Definition: import.c:72
@ DEFAULT_VALUE_NAME
Definition: import.c:65
@ HEADER
Definition: import.c:60
@ NB_PARSER_STATES
Definition: import.c:77
@ STRING_DATA
Definition: import.c:70
@ QUOTED_VALUE_NAME
Definition: import.c:66
@ DATA_TYPE
Definition: import.c:69
@ HEX_MULTILINE
Definition: import.c:74
@ UNKNOWN_DATA
Definition: import.c:75
@ LINE_START
Definition: import.c:62
@ EOL_BACKSLASH
Definition: import.c:73
@ SET_VALUE
Definition: import.c:76
@ DELETE_VALUE
Definition: import.c:68
@ DWORD_DATA
Definition: import.c:71
@ KEY_NAME
Definition: import.c:63
@ DATA_START
Definition: import.c:67
@ DELETE_KEY
Definition: import.c:64

◆ reg_versions

Enumerator
REG_VERSION_31 
REG_VERSION_40 
REG_VERSION_50 
REG_VERSION_FUZZY 
REG_VERSION_INVALID 
REG_VERSION_31 
REG_VERSION_40 
REG_VERSION_50 
REG_VERSION_FUZZY 
REG_VERSION_INVALID 

Definition at line 437 of file import.c.

437 {
443};
@ REG_VERSION_50
Definition: import.c:440
@ REG_VERSION_INVALID
Definition: import.c:442
@ REG_VERSION_40
Definition: import.c:439
@ REG_VERSION_FUZZY
Definition: import.c:441
@ REG_VERSION_31
Definition: import.c:438

Function Documentation

◆ close_key()

static void close_key ( struct parser parser)
static

Definition at line 357 of file import.c.

358{
359 if (parser->hkey)
360 {
363
365 parser->hkey = NULL;
366 }
367}
#define RegCloseKey(hKey)
Definition: registry.h:49
#define free
Definition: debug_ros.c:5
#define NULL
Definition: types.h:112
Definition: import.c:81
HKEY hkey
Definition: import.c:87
WCHAR * key_name
Definition: import.c:88

◆ convert_hex_csv_to_hex()

static BOOL convert_hex_csv_to_hex ( struct parser parser,
WCHAR **  str 
)
static

Definition at line 185 of file import.c.

186{
187 size_t size;
188 BYTE *d;
189 WCHAR *s;
190
192
193 /* The worst case is 1 digit + 1 comma per byte */
194 size = ((lstrlenW(*str) + 1) / 2) + parser->data_size;
196
197 s = *str;
198 d = (BYTE *)parser->data + parser->data_size;
199
200 while (*s)
201 {
202 WCHAR *end;
203 unsigned long wc;
204
205 wc = wcstoul(s, &end, 16);
206 if (wc > 0xff) return FALSE;
207
208 if (s == end && wc == 0)
209 {
210 while (*end == ' ' || *end == '\t') end++;
211 if (*end == '\\')
212 {
214 *str = end + 1;
215 return TRUE;
216 }
217 else if (*end == ';')
218 return TRUE;
219 return FALSE;
220 }
221
222 *d++ = wc;
223 parser->data_size++;
224
225 if (*end && *end != ',')
226 {
227 while (*end == ' ' || *end == '\t') end++;
228 if (*end && *end != ';') return FALSE;
229 return TRUE;
230 }
231
232 if (*end) end++;
233 s = end;
234 }
235
236 return TRUE;
237}
while(CdLookupNextInitialFileDirent(IrpContext, Fcb, FileContext))
#define realloc
Definition: debug_ros.c:6
#define TRUE
Definition: types.h:120
#define FALSE
Definition: types.h:117
#define lstrlenW
Definition: compat.h:750
GLdouble s
Definition: gl.h:2039
GLuint GLuint end
Definition: gl.h:1545
GLsizeiptr size
Definition: glext.h:5919
_Check_return_ unsigned long __cdecl wcstoul(_In_z_ const wchar_t *_Str, _Out_opt_ _Deref_post_z_ wchar_t **_EndPtr, _In_ int _Radix)
#define d
Definition: ke_i.h:81
const WCHAR * str
BOOL backslash
Definition: import.c:94
DWORD data_size
Definition: import.c:93
void * data
Definition: import.c:92
__wchar_t WCHAR
Definition: xmlstorage.h:180
unsigned char BYTE
Definition: xxhash.c:193

Referenced by hex_data_state().

◆ convert_hex_to_dword()

static BOOL convert_hex_to_dword ( WCHAR str,
DWORD dw 
)
static

Definition at line 151 of file import.c.

152{
153 WCHAR *p, *end;
154 int count = 0;
155
156 while (*str == ' ' || *str == '\t') str++;
157 if (!*str) goto error;
158
159 p = str;
160 while (iswxdigit(*p))
161 {
162 count++;
163 p++;
164 }
165 if (count > 8) goto error;
166
167 end = p;
168 while (*p == ' ' || *p == '\t') p++;
169 if (*p && *p != ';') goto error;
170
171 *end = 0;
172 *dw = wcstoul(str, &end, 16);
173 return TRUE;
174
175error:
176 return FALSE;
177}
GLuint GLuint GLsizei count
Definition: gl.h:1545
GLfloat GLfloat p
Definition: glext.h:8902
#define iswxdigit(_c)
Definition: ctype.h:668
REFIID LPVOID DWORD_PTR dw
Definition: atlbase.h:40
#define error(str)
Definition: mkdosfs.c:1605

Referenced by dword_data_state().

◆ data_start_state()

static WCHAR * data_start_state ( struct parser parser,
WCHAR pos 
)
static

Definition at line 656 of file import.c.

657{
658 WCHAR *p = pos;
659 unsigned int len;
660
661 while (*p == ' ' || *p == '\t') p++;
662 if (*p != '=') goto invalid;
663 p++;
664 while (*p == ' ' || *p == '\t') p++;
665
666 /* trim trailing whitespace */
667 len = lstrlenW(p);
668 while (len > 0 && (p[len - 1] == ' ' || p[len - 1] == '\t')) len--;
669 p[len] = 0;
670
671 if (*p == '-')
673 else
675 return p;
676
677invalid:
679 return p;
680}
static enum parser_state set_state(struct parser *parser, enum parser_state state)
Definition: import.c:141
GLenum GLsizei len
Definition: glext.h:6722
static const WCHAR invalid[]
Definition: assoc.c:39

◆ data_type_state()

static WCHAR * data_type_state ( struct parser parser,
WCHAR pos 
)
static

Definition at line 698 of file import.c.

699{
700 WCHAR *line = pos;
701
703 {
705 return line;
706 }
707
708 switch (parser->parse_type)
709 {
710 case REG_SZ:
712 break;
713 case REG_DWORD:
715 break;
716 case REG_BINARY: /* all hex data types, including undefined */
718 break;
719 default:
721 }
722
723 return line;
724}
static BOOL parse_data_type(struct parser *parser, WCHAR **line)
Definition: import.c:245
#define REG_SZ
Definition: layer.c:22
#define REG_BINARY
Definition: nt_native.h:1496
#define REG_DWORD
Definition: sdbapi.c:596
Definition: parser.c:49
DWORD parse_type
Definition: import.c:90

◆ default_value_name_state()

static WCHAR * default_value_name_state ( struct parser parser,
WCHAR pos 
)
static

Definition at line 623 of file import.c.

624{
627
629 return pos + 1;
630}
WCHAR * value_name
Definition: import.c:89

◆ delete_key_state()

static WCHAR * delete_key_state ( struct parser parser,
WCHAR pos 
)
static

Definition at line 601 of file import.c.

602{
603 WCHAR *p = pos;
604
606
607 if (*p == 'H' || *p == 'h')
608 {
609 HKEY root;
610 WCHAR *path;
611
613
614 if (root && path && *path)
616 }
617
619 return p;
620}
static HKEY parse_key_name(WCHAR *key_name, WCHAR **key_path)
Definition: import.c:347
struct _root root
LSTATUS WINAPI RegDeleteTreeW(_In_ HKEY, _In_opt_ LPCWSTR)
#define close_key(k)
Definition: reg_test.h:52

◆ delete_value_state()

static WCHAR * delete_value_state ( struct parser parser,
WCHAR pos 
)
static

Definition at line 683 of file import.c.

684{
685 WCHAR *p = pos + 1;
686
687 while (*p == ' ' || *p == '\t') p++;
688 if (*p && *p != ';') goto done;
689
691
692done:
694 return p;
695}
LONG WINAPI RegDeleteValueW(HKEY hKey, LPCWSTR lpValueName)
Definition: reg.c:2330

◆ dword_data_state()

static WCHAR * dword_data_state ( struct parser parser,
WCHAR pos 
)
static

Definition at line 751 of file import.c.

752{
753 WCHAR *line = pos;
754
755 parser->data = malloc(sizeof(DWORD));
756
758 goto invalid;
759
760 parser->data_size = sizeof(DWORD);
761
763 return line;
764
765invalid:
768 return line;
769}
static BOOL convert_hex_to_dword(WCHAR *str, DWORD *dw)
Definition: import.c:151
static void free_parser_data(struct parser *parser)
Definition: import.c:395
#define malloc
Definition: debug_ros.c:4
unsigned long DWORD
Definition: ntddk_ex.h:95
#define DWORD
Definition: nt_native.h:44

◆ eol_backslash_state()

static WCHAR * eol_backslash_state ( struct parser parser,
WCHAR pos 
)
static

Definition at line 801 of file import.c.

802{
803 WCHAR *p = pos;
804
805 while (*p == ' ' || *p == '\t') p++;
806 if (*p && *p != ';') goto invalid;
807
809 return pos;
810
811invalid:
814 return p;
815}

◆ free_parser_data()

static void free_parser_data ( struct parser parser)
static

◆ get_lineA()

static WCHAR * get_lineA ( FILE fp)
static

Definition at line 870 of file import.c.

871{
872 static WCHAR *lineW;
873 static size_t size;
874 static char *buf, *next;
875 char *line;
876
877 free(lineW);
878
879 if (!fp) goto cleanup;
880
881 if (!size)
882 {
884 buf = malloc(size);
885 *buf = 0;
886 next = buf;
887 }
888 line = next;
889
890 while (next)
891 {
892 char *p = strpbrk(line, "\r\n");
893 if (!p)
894 {
895 size_t len, count;
896 len = strlen(next);
897 memmove(buf, next, len + 1);
898 if (size - len < 3)
899 {
900 size *= 2;
901 buf = realloc(buf, size);
902 }
903 if (!(count = fread(buf + len, 1, size - len - 1, fp)))
904 {
905 next = NULL;
906 lineW = GetWideString(buf);
907 return lineW;
908 }
909 buf[len + count] = 0;
910 next = buf;
911 line = buf;
912 continue;
913 }
914 next = p + 1;
915 if (*p == '\r' && *(p + 1) == '\n') next++;
916 *p = 0;
917 lineW = GetWideString(line);
918 return lineW;
919 }
920
921cleanup:
922 lineW = NULL;
923 free(buf);
924 size = 0;
925 return NULL;
926}
ACPI_SIZE strlen(const char *String)
Definition: utclib.c:269
char * strpbrk(const char *String, const char *Delimiters)
Definition: utclib.c:302
#define REG_VAL_BUF_SIZE
Definition: import.c:868
static WCHAR * GetWideString(const char *strA)
Definition: import.c:26
static void cleanup(void)
Definition: main.c:1335
GLenum GLuint GLenum GLsizei const GLchar * buf
Definition: glext.h:7751
_Check_return_opt_ _CRTIMP size_t __cdecl fread(_Out_writes_bytes_(_ElementSize *_Count) void *_DstBuf, _In_ size_t _ElementSize, _In_ size_t _Count, _Inout_ FILE *_File)
#define memmove(s1, s2, n)
Definition: mkisofs.h:881
static unsigned __int64 next
Definition: rand_nt.c:6

Referenced by reg_import().

◆ get_lineW()

static WCHAR * get_lineW ( FILE fp)
static

Definition at line 928 of file import.c.

929{
930 static size_t size;
931 static WCHAR *buf, *next;
932 WCHAR *line;
933
934 if (!fp) goto cleanup;
935
936 if (!size)
937 {
939 buf = malloc(size * sizeof(WCHAR));
940 *buf = 0;
941 next = buf;
942 }
943 line = next;
944
945 while (next)
946 {
947 WCHAR *p = wcspbrk(line, L"\r\n");
948 if (!p)
949 {
950 size_t len, count;
951 len = lstrlenW(next);
952 memmove(buf, next, (len + 1) * sizeof(WCHAR));
953 if (size - len < 3)
954 {
955 size *= 2;
956 buf = realloc(buf, size * sizeof(WCHAR));
957 }
958 if (!(count = fread(buf + len, sizeof(WCHAR), size - len - 1, fp)))
959 {
960 next = NULL;
961 return buf;
962 }
963 buf[len + count] = 0;
964 next = buf;
965 line = buf;
966 continue;
967 }
968 next = p + 1;
969 if (*p == '\r' && *(p + 1) == '\n') next++;
970 *p = 0;
971 return line;
972 }
973
974cleanup:
975 free(buf);
976 size = 0;
977 return NULL;
978}
#define L(x)
Definition: ntvdm.h:50
_Check_return_ _CRTIMP _CONST_RETURN wchar_t *__cdecl wcspbrk(_In_z_ const wchar_t *_Str, _In_z_ const wchar_t *_Control)

Referenced by reg_import().

◆ GetWideString()

static WCHAR * GetWideString ( const char strA)
static

Definition at line 26 of file import.c.

27{
28 if (strA)
29 {
30 WCHAR *strW;
31 int len = MultiByteToWideChar(CP_ACP, 0, strA, -1, NULL, 0);
32
33 strW = malloc(len * sizeof(WCHAR));
35 return strW;
36 }
37 return NULL;
38}
#define CP_ACP
Definition: compat.h:109
#define MultiByteToWideChar
Definition: compat.h:110
WCHAR strW[12]
Definition: clipboard.c:2029
char strA[12]
Definition: clipboard.c:2028

Referenced by get_lineA().

◆ GetWideStringN()

static WCHAR * GetWideStringN ( const char strA,
int  size,
DWORD len 
)
static

Definition at line 40 of file import.c.

41{
42 if (strA)
43 {
44 WCHAR *strW;
46
47 strW = malloc(*len * sizeof(WCHAR));
49 return strW;
50 }
51 *len = 0;
52 return NULL;
53}

Referenced by prepare_hex_string_data().

◆ header_state()

static WCHAR * header_state ( struct parser parser,
WCHAR pos 
)
static

Definition at line 472 of file import.c.

473{
474 WCHAR *line, *header;
475
476 if (!(line = get_line(parser->file)))
477 return NULL;
478
479 if (!parser->is_unicode)
480 {
481 header = malloc((lstrlenW(line) + 3) * sizeof(WCHAR));
482 header[0] = parser->two_wchars[0];
483 header[1] = parser->two_wchars[1];
484 lstrcpyW(header + 2, line);
486 free(header);
487 }
489
490 switch (parser->reg_version)
491 {
492 case REG_VERSION_31:
494 break;
495 case REG_VERSION_40:
496 case REG_VERSION_50:
498 break;
499 default:
500 get_line(NULL); /* Reset static variables */
501 return NULL;
502 }
503
504 return line;
505}
static enum reg_versions parse_file_header(const WCHAR *s)
Definition: import.c:445
static WCHAR *(* get_line)(FILE *)
Definition: import.c:55
#define lstrcpyW
Definition: compat.h:749
BOOL is_unicode
Definition: import.c:84
WCHAR two_wchars[2]
Definition: import.c:83
short int reg_version
Definition: import.c:85
FILE * file
Definition: import.c:82

◆ hex_data_state()

static WCHAR * hex_data_state ( struct parser parser,
WCHAR pos 
)
static

Definition at line 772 of file import.c.

773{
774 WCHAR *line = pos;
775
776 if (!*line)
777 goto set_value;
778
780 goto invalid;
781
782 if (parser->backslash)
783 {
785 return line;
786 }
787
789
792 return line;
793
794invalid:
797 return line;
798}
static void prepare_hex_string_data(struct parser *parser)
Definition: import.c:404
static BOOL convert_hex_csv_to_hex(struct parser *parser, WCHAR **str)
Definition: import.c:185
static HRESULT set_value(struct d3dx_parameter *param, const void *data, unsigned int bytes, void *dst_data)
Definition: effect.c:889

◆ hex_multiline_state()

static WCHAR * hex_multiline_state ( struct parser parser,
WCHAR pos 
)
static

Definition at line 818 of file import.c.

819{
820 WCHAR *line;
821
822 if (!(line = get_line(parser->file)))
823 {
826 return pos;
827 }
828
829 while (*line == ' ' || *line == '\t') line++;
830 if (!*line || *line == ';') return line;
831
832 if (!iswxdigit(*line)) goto invalid;
833
835 return line;
836
837invalid:
840 return line;
841}

◆ key_name_state()

static WCHAR * key_name_state ( struct parser parser,
WCHAR pos 
)
static

Definition at line 578 of file import.c.

579{
580 WCHAR *p = pos, *key_end;
581
582 if (*p == ' ' || *p == '\t' || !(key_end = wcsrchr(p, ']')))
583 goto done;
584
585 *key_end = 0;
586
587 if (*p == '-')
588 {
590 return p + 1;
591 }
592 else if (open_key(parser, p) != ERROR_SUCCESS)
594
595done:
597 return p;
598}
void WINAPIV output_message(unsigned int id,...)
Definition: reg.c:92
#define STRING_KEY_IMPORT_FAILED
Definition: resource.h:81
#define ERROR_SUCCESS
Definition: deptool.c:10
#define wcsrchr
Definition: compat.h:16
#define open_key(r, p, s, k)
Definition: reg_test.h:49

◆ line_start_state()

static WCHAR * line_start_state ( struct parser parser,
WCHAR pos 
)
static

Definition at line 546 of file import.c.

547{
548 WCHAR *line, *p;
549
550 if (!(line = get_line(parser->file)))
551 return NULL;
552
553 for (p = line; *p; p++)
554 {
555 switch (*p)
556 {
557 case '[':
559 return p + 1;
560 case '@':
562 return p;
563 case '"':
565 return p + 1;
566 case ' ':
567 case '\t':
568 break;
569 default:
570 return p;
571 }
572 }
573
574 return p;
575}

◆ open_key()

static LONG open_key ( struct parser parser,
WCHAR path 
)
static

Definition at line 369 of file import.c.

370{
371 HKEY key_class;
372 WCHAR *key_path;
373 LONG res;
374
376
377 /* Get the registry class */
378 if (!path || !(key_class = parse_key_name(path, &key_path)))
380
381 res = RegCreateKeyExW(key_class, key_path, 0, NULL, REG_OPTION_NON_VOLATILE,
383
384 if (res == ERROR_SUCCESS)
385 {
386 parser->key_name = malloc((lstrlenW(path) + 1) * sizeof(WCHAR));
388 }
389 else
390 parser->hkey = NULL;
391
392 return res;
393}
LONG WINAPI RegCreateKeyExW(_In_ HKEY hKey, _In_ LPCWSTR lpSubKey, _In_ DWORD Reserved, _In_opt_ LPWSTR lpClass, _In_ DWORD dwOptions, _In_ REGSAM samDesired, _In_opt_ LPSECURITY_ATTRIBUTES lpSecurityAttributes, _Out_ PHKEY phkResult, _Out_opt_ LPDWORD lpdwDisposition)
Definition: reg.c:1096
#define ERROR_INVALID_PARAMETER
Definition: compat.h:101
GLuint res
Definition: glext.h:9613
#define KEY_ALL_ACCESS
Definition: nt_native.h:1041
#define REG_OPTION_NON_VOLATILE
Definition: nt_native.h:1057
long LONG
Definition: pedump.c:60
REGSAM sam
Definition: import.c:86

◆ parse_data_type()

static BOOL parse_data_type ( struct parser parser,
WCHAR **  line 
)
static

Definition at line 245 of file import.c.

246{
247 struct data_type { const WCHAR *tag; int len; int type; int parse_type; };
248
249 static const struct data_type data_types[] = {
250 /* tag len type parse type */
251 { L"\"", 1, REG_SZ, REG_SZ },
252 { L"hex:", 4, REG_BINARY, REG_BINARY },
253 { L"dword:", 6, REG_DWORD, REG_DWORD },
254 { L"hex(", 4, -1, REG_BINARY }, /* REG_NONE, REG_EXPAND_SZ, REG_MULTI_SZ */
255 { NULL, 0, 0, 0 }
256 };
257
258 const struct data_type *ptr;
259
260 for (ptr = data_types; ptr->tag; ptr++)
261 {
262 if (wcsncmp(ptr->tag, *line, ptr->len))
263 continue;
264
265 parser->parse_type = ptr->parse_type;
266 parser->data_type = ptr->parse_type;
267 *line += ptr->len;
268
269 if (ptr->type == -1)
270 {
271 WCHAR *end;
272 DWORD val;
273
274 if (!**line || towlower((*line)[1]) == 'x')
275 return FALSE;
276
277 /* "hex(xx):" is special */
278 val = wcstoul(*line, &end, 16);
279#ifdef __REACTOS__
280 /* Up to 8 hex digits, "hex(000000002)" is invalid */
281 if (*end != ')' || *(end + 1) != ':' || (val == ~0u && errno == ERANGE) || end - *line > 8)
282#else
283 if (*end != ')' || *(end + 1) != ':' || (val == ~0u && errno == ERANGE))
284#endif
285 return FALSE;
286
288 *line = end + 2;
289 }
290 return TRUE;
291 }
292 return FALSE;
293}
#define ERANGE
Definition: acclib.h:92
GLuint GLuint GLsizei GLenum type
Definition: gl.h:1545
GLuint GLfloat * val
Definition: glext.h:7180
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 * u
Definition: glfuncs.h:240
static PVOID ptr
Definition: dispmode.c:27
#define errno
Definition: errno.h:18
_Check_return_ _CRTIMP int __cdecl wcsncmp(_In_reads_or_z_(_MaxCount) const wchar_t *_Str1, _In_reads_or_z_(_MaxCount) const wchar_t *_Str2, _In_ size_t _MaxCount)
int parse_type(Type t, const vector< string > &tokens, int off, vector< string > &names, vector< string > &dependencies)
Definition: sdkparse.cpp:653
DWORD data_type
Definition: import.c:91
Definition: ecma_167.h:138
#define towlower(c)
Definition: wctype.h:97

Referenced by data_type_state().

◆ parse_file_header()

static enum reg_versions parse_file_header ( const WCHAR s)
static

Definition at line 445 of file import.c.

446{
447 static const WCHAR *header_31 = L"REGEDIT";
448
449 while (*s == ' ' || *s == '\t') s++;
450
451 if (!lstrcmpW(s, header_31))
452 return REG_VERSION_31;
453
454 if (!lstrcmpW(s, L"REGEDIT4"))
455 return REG_VERSION_40;
456
457 if (!lstrcmpW(s, L"Windows Registry Editor Version 5.00"))
458 return REG_VERSION_50;
459
460 /* The Windows version accepts registry file headers beginning with "REGEDIT" and ending
461 * with other characters, as long as "REGEDIT" appears at the start of the line. For example,
462 * "REGEDIT 4", "REGEDIT9" and "REGEDIT4FOO" are all treated as valid file headers.
463 * In all such cases, however, the contents of the registry file are not imported.
464 */
465 if (!wcsncmp(s, header_31, 7)) /* "REGEDIT" without NUL */
466 return REG_VERSION_FUZZY;
467
468 return REG_VERSION_INVALID;
469}
int WINAPI lstrcmpW(LPCWSTR str1, LPCWSTR str2)
Definition: locale.c:4242

Referenced by header_state().

◆ parse_key_name()

static HKEY parse_key_name ( WCHAR key_name,
WCHAR **  key_path 
)
static

Definition at line 347 of file import.c.

348{
349 if (!key_name) return 0;
350
351 *key_path = wcschr(key_name, '\\');
352 if (*key_path) (*key_path)++;
353
355}
HKEY path_get_rootkey(const WCHAR *path)
Definition: reg.c:165
#define wcschr
Definition: compat.h:17

Referenced by delete_key_state(), and open_key().

◆ parse_win31_line_state()

static WCHAR * parse_win31_line_state ( struct parser parser,
WCHAR pos 
)
static

Definition at line 508 of file import.c.

509{
510 WCHAR *line, *value;
511 unsigned int key_end = 0;
512
513 if (!(line = get_line(parser->file)))
514 return NULL;
515
516 if (wcsncmp(line, L"HKEY_CLASSES_ROOT", 17)) /* "HKEY_CLASSES_ROOT" without NUL */
517 return line;
518
519 /* get key name */
520 while (line[key_end] && !iswspace(line[key_end])) key_end++;
521
522 value = line + key_end;
523 while (*value == ' ' || *value == '\t') value++;
524
525 if (*value == '=') value++;
526 if (*value == ' ') value++; /* at most one space is skipped */
527
528 line[key_end] = 0;
529
531 {
533 return line;
534 }
535
538 parser->data = value;
539 parser->data_size = (lstrlenW(value) + 1) * sizeof(WCHAR);
540
542 return value;
543}
#define iswspace(_c)
Definition: ctype.h:669
Definition: pdh_main.c:94

◆ prepare_hex_string_data()

static void prepare_hex_string_data ( struct parser parser)
static

Definition at line 404 of file import.c.

405{
408 {
409 if (parser->is_unicode)
410 {
411 WCHAR *data = parser->data;
412 DWORD len = parser->data_size / sizeof(WCHAR);
413
414 if (data[len - 1] != 0)
415 {
416 data[len] = 0;
417 parser->data_size += sizeof(WCHAR);
418 }
419 }
420 else
421 {
422 BYTE *data = parser->data;
423
424 if (data[parser->data_size - 1] != 0)
425 {
426 data[parser->data_size] = 0;
427 parser->data_size++;
428 }
429
431 parser->data_size *= sizeof(WCHAR);
432 free(data);
433 }
434 }
435}
static WCHAR * GetWideStringN(const char *strA, int size, DWORD *len)
Definition: import.c:40
GLint GLenum GLsizei GLsizei GLsizei GLint GLsizei const GLvoid * data
Definition: gl.h:1950
#define REG_MULTI_SZ
Definition: nt_native.h:1501
#define REG_EXPAND_SZ
Definition: nt_native.h:1494

Referenced by hex_data_state(), and hex_multiline_state().

◆ quoted_value_name_state()

static WCHAR * quoted_value_name_state ( struct parser parser,
WCHAR pos 
)
static

Definition at line 633 of file import.c.

634{
635 WCHAR *val_name = pos, *p;
636
639
640 if (!unescape_string(val_name, &p))
641 goto invalid;
642
643 /* copy the value name in case we need to parse multiple lines and the buffer is overwritten */
644 parser->value_name = malloc((lstrlenW(val_name) + 1) * sizeof(WCHAR));
645 lstrcpyW(parser->value_name, val_name);
646
648 return p;
649
650invalid:
652 return val_name;
653}
static BOOL unescape_string(WCHAR *str, WCHAR **unparsed)
Definition: import.c:302

◆ reg_import()

int reg_import ( int  argc,
WCHAR argvW[] 
)

Definition at line 980 of file import.c.

981{
982 WCHAR *filename, *pos;
983 FILE *fp;
984 BYTE s[2];
985 struct parser parser;
986
987 if (argc > 4) goto invalid;
988
989 parser.sam = 0;
990
991 if (argc == 4)
992 {
993 WCHAR *str = argvW[3];
994
995 if (*str != '/' && *str != '-')
996 goto invalid;
997
998 str++;
999
1000 if (!lstrcmpiW(str, L"reg:32"))
1002 else if (!lstrcmpiW(str, L"reg:64"))
1004 else
1005 goto invalid;
1006 }
1007
1008 filename = argvW[2];
1009
1010 fp = _wfopen(filename, L"rb");
1011 if (!fp)
1012 {
1014 return 1;
1015 }
1016
1017 if (fread(s, sizeof(WCHAR), 1, fp) != 1)
1018 goto error;
1019
1020 parser.is_unicode = (s[0] == 0xff && s[1] == 0xfe);
1022
1023 parser.file = fp;
1024 parser.two_wchars[0] = s[0];
1025 parser.two_wchars[1] = s[1];
1026 parser.reg_version = -1;
1027 parser.hkey = NULL;
1030 parser.parse_type = 0;
1031 parser.data_type = 0;
1032 parser.data = NULL;
1033 parser.data_size = 0;
1036
1038
1039 /* parser main loop */
1040 while (pos)
1042
1044 goto error;
1045
1047 close_key(&parser);
1048
1049 fclose(fp);
1050 return 0;
1051
1052error:
1053 fclose(fp);
1054 return 1;
1055
1056invalid:
1059 return 1;
1060}
static int argc
Definition: ServiceArgs.c:12
#define STRING_FILE_NOT_FOUND
Definition: resource.h:8
static WCHAR * get_lineA(FILE *fp)
Definition: import.c:870
static WCHAR * get_lineW(FILE *fp)
Definition: import.c:928
static const parser_state_func parser_funcs[NB_PARSER_STATES]
Definition: import.c:119
#define STRING_INVALID_SYNTAX
Definition: resource.h:33
#define STRING_FUNC_HELP
Definition: resource.h:34
int WINAPI lstrcmpiW(LPCWSTR str1, LPCWSTR str2)
Definition: locale.c:4261
_Check_return_ _CRTIMP FILE *__cdecl _wfopen(_In_z_ const wchar_t *_Filename, _In_z_ const wchar_t *_Mode)
_Check_return_opt_ _CRTIMP int __cdecl fclose(_Inout_ FILE *_File)
const char * filename
Definition: ioapi.h:137
_CRTIMP wchar_t *__cdecl _wcsupr(_Inout_z_ wchar_t *_String)
enum parser_state state
Definition: import.c:95
#define KEY_WOW64_32KEY
Definition: cmtypes.h:45
#define KEY_WOW64_64KEY
Definition: cmtypes.h:46

Referenced by wmain().

◆ set_state()

◆ set_value_state()

static WCHAR * set_value_state ( struct parser parser,
WCHAR pos 
)
static

Definition at line 853 of file import.c.

854{
857
859
862 else
864
865 return pos;
866}
LONG WINAPI RegSetValueExW(_In_ HKEY hKey, _In_ LPCWSTR lpValueName, _In_ DWORD Reserved, _In_ DWORD dwType, _In_ CONST BYTE *lpData, _In_ DWORD cbData)
Definition: reg.c:4882

◆ string_data_state()

static WCHAR * string_data_state ( struct parser parser,
WCHAR pos 
)
static

Definition at line 727 of file import.c.

728{
729 WCHAR *line;
730
731 parser->data = pos;
732
734 goto invalid;
735
736 while (*line == ' ' || *line == '\t') line++;
737 if (*line && *line != ';') goto invalid;
738
739 parser->data_size = (lstrlenW(parser->data) + 1) * sizeof(WCHAR);
740
742 return line;
743
744invalid:
747 return line;
748}

◆ unescape_string()

static BOOL unescape_string ( WCHAR str,
WCHAR **  unparsed 
)
static

Definition at line 302 of file import.c.

303{
304 int str_idx = 0; /* current character under analysis */
305 int val_idx = 0; /* the last character of the unescaped string */
306 int len = lstrlenW(str);
307 BOOL ret;
308
309 for (str_idx = 0; str_idx < len; str_idx++, val_idx++)
310 {
311 if (str[str_idx] == '\\')
312 {
313 str_idx++;
314 switch (str[str_idx])
315 {
316 case 'n':
317 str[val_idx] = '\n';
318 break;
319 case 'r':
320 str[val_idx] = '\r';
321 break;
322 case '0':
323 return FALSE;
324 case '\\':
325 case '"':
326 str[val_idx] = str[str_idx];
327 break;
328 default:
329 if (!str[str_idx]) return FALSE;
331 str[val_idx] = str[str_idx];
332 break;
333 }
334 }
335 else if (str[str_idx] == '"')
336 break;
337 else
338 str[val_idx] = str[str_idx];
339 }
340
341 ret = (str[str_idx] == '"');
342 *unparsed = str + str_idx + 1;
343 str[val_idx] = '\0';
344 return ret;
345}
#define STRING_ESCAPE_SEQUENCE
Definition: resource.h:80
unsigned int BOOL
Definition: ntddk_ex.h:94

Referenced by quoted_value_name_state(), and string_data_state().

◆ unknown_data_state()

static WCHAR * unknown_data_state ( struct parser parser,
WCHAR pos 
)
static

Definition at line 844 of file import.c.

845{
846 FIXME("Unknown registry data type [0x%x]\n", parser->data_type);
847
849 return pos;
850}
#define FIXME(fmt,...)
Definition: precomp.h:53

◆ WINE_DEFAULT_DEBUG_CHANNEL()

WINE_DEFAULT_DEBUG_CHANNEL ( reg  )

Variable Documentation

◆ get_line

◆ parser_funcs

Initial value:
=
{
}
static WCHAR * default_value_name_state(struct parser *parser, WCHAR *pos)
Definition: import.c:623
static WCHAR * hex_data_state(struct parser *parser, WCHAR *pos)
Definition: import.c:772
static WCHAR * dword_data_state(struct parser *parser, WCHAR *pos)
Definition: import.c:751
static WCHAR * string_data_state(struct parser *parser, WCHAR *pos)
Definition: import.c:727
static WCHAR * key_name_state(struct parser *parser, WCHAR *pos)
Definition: import.c:578
static WCHAR * delete_value_state(struct parser *parser, WCHAR *pos)
Definition: import.c:683
static WCHAR * eol_backslash_state(struct parser *parser, WCHAR *pos)
Definition: import.c:801
static WCHAR * data_type_state(struct parser *parser, WCHAR *pos)
Definition: import.c:698
static WCHAR * set_value_state(struct parser *parser, WCHAR *pos)
Definition: import.c:853
static WCHAR * data_start_state(struct parser *parser, WCHAR *pos)
Definition: import.c:656
static WCHAR * unknown_data_state(struct parser *parser, WCHAR *pos)
Definition: import.c:844
static WCHAR * quoted_value_name_state(struct parser *parser, WCHAR *pos)
Definition: import.c:633
static WCHAR * parse_win31_line_state(struct parser *parser, WCHAR *pos)
Definition: import.c:508
static WCHAR * delete_key_state(struct parser *parser, WCHAR *pos)
Definition: import.c:601
static WCHAR * hex_multiline_state(struct parser *parser, WCHAR *pos)
Definition: import.c:818
static WCHAR * header_state(struct parser *parser, WCHAR *pos)
Definition: import.c:472
static WCHAR * line_start_state(struct parser *parser, WCHAR *pos)
Definition: import.c:546

Definition at line 119 of file import.c.

Referenced by reg_import().