mirror of
https://github.com/reactos/reactos.git
synced 2025-06-20 07:36:05 +00:00
[SETUPAPI] Partially sync parser.c with Wine Staging 1.7.37. Started off by Victor's work in CORE-9397 and completed by me. CORE-9246
svn path=/trunk/; revision=66832
This commit is contained in:
parent
5fadd826c9
commit
dfeca474ec
2 changed files with 42 additions and 37 deletions
|
@ -19,6 +19,8 @@
|
||||||
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
|
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
/* Partially synced with Wine Staging 1.7.37 */
|
||||||
|
|
||||||
#include "setupapi_private.h"
|
#include "setupapi_private.h"
|
||||||
|
|
||||||
#include <ndk/obfuncs.h>
|
#include <ndk/obfuncs.h>
|
||||||
|
@ -186,7 +188,7 @@ static struct line *find_line( struct inf_file *file, int section_index, const W
|
||||||
{
|
{
|
||||||
struct section *section;
|
struct section *section;
|
||||||
struct line *line;
|
struct line *line;
|
||||||
int i;
|
unsigned int i;
|
||||||
|
|
||||||
if (section_index < 0 || section_index >= file->nb_sections) return NULL;
|
if (section_index < 0 || section_index >= file->nb_sections) return NULL;
|
||||||
section = file->sections[section_index];
|
section = file->sections[section_index];
|
||||||
|
@ -311,7 +313,7 @@ static const WCHAR *get_string_subst( const struct inf_file *file, const WCHAR *
|
||||||
struct section *strings_section;
|
struct section *strings_section;
|
||||||
struct line *line;
|
struct line *line;
|
||||||
struct field *field;
|
struct field *field;
|
||||||
unsigned int i,j;
|
unsigned int i, j;
|
||||||
int dirid;
|
int dirid;
|
||||||
WCHAR *dirid_str, *end;
|
WCHAR *dirid_str, *end;
|
||||||
const WCHAR *ret = NULL;
|
const WCHAR *ret = NULL;
|
||||||
|
@ -397,12 +399,12 @@ static const WCHAR *get_string_subst( const struct inf_file *file, const WCHAR *
|
||||||
/* do string substitutions on the specified text */
|
/* do string substitutions on the specified text */
|
||||||
/* the buffer is assumed to be large enough */
|
/* the buffer is assumed to be large enough */
|
||||||
/* returns necessary length not including terminating null */
|
/* returns necessary length not including terminating null */
|
||||||
unsigned int PARSER_string_substW( const struct inf_file *file, const WCHAR *text, WCHAR *buffer,
|
static unsigned int PARSER_string_substW( const struct inf_file *file, const WCHAR *text,
|
||||||
unsigned int size )
|
WCHAR *buffer, unsigned int size )
|
||||||
{
|
{
|
||||||
const WCHAR *start, *subst, *p;
|
const WCHAR *start, *subst, *p;
|
||||||
unsigned int len, total = 0;
|
unsigned int len, total = 0;
|
||||||
int inside = 0;
|
BOOL inside = FALSE;
|
||||||
|
|
||||||
if (!buffer) size = MAX_STRING_LEN + 1;
|
if (!buffer) size = MAX_STRING_LEN + 1;
|
||||||
for (p = start = text; *p; p++)
|
for (p = start = text; *p; p++)
|
||||||
|
@ -450,8 +452,8 @@ unsigned int PARSER_string_substW( const struct inf_file *file, const WCHAR *tex
|
||||||
/* do string substitutions on the specified text */
|
/* do string substitutions on the specified text */
|
||||||
/* the buffer is assumed to be large enough */
|
/* the buffer is assumed to be large enough */
|
||||||
/* returns necessary length not including terminating null */
|
/* returns necessary length not including terminating null */
|
||||||
unsigned int PARSER_string_substA( const struct inf_file *file, const WCHAR *text, char *buffer,
|
static unsigned int PARSER_string_substA( const struct inf_file *file, const WCHAR *text,
|
||||||
unsigned int size )
|
char *buffer, unsigned int size )
|
||||||
{
|
{
|
||||||
WCHAR buffW[MAX_STRING_LEN+1];
|
WCHAR buffW[MAX_STRING_LEN+1];
|
||||||
DWORD ret;
|
DWORD ret;
|
||||||
|
@ -503,14 +505,14 @@ static inline enum parser_state set_state( struct parser *parser, enum parser_st
|
||||||
|
|
||||||
|
|
||||||
/* check if the pointer points to an end of file */
|
/* check if the pointer points to an end of file */
|
||||||
static inline int is_eof( const struct parser *parser, const WCHAR *ptr )
|
static inline BOOL is_eof( const struct parser *parser, const WCHAR *ptr )
|
||||||
{
|
{
|
||||||
return (ptr >= parser->end || *ptr == CONTROL_Z);
|
return (ptr >= parser->end || *ptr == CONTROL_Z);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/* check if the pointer points to an end of line */
|
/* check if the pointer points to an end of line */
|
||||||
static inline int is_eol( const struct parser *parser, const WCHAR *ptr )
|
static inline BOOL is_eol( const struct parser *parser, const WCHAR *ptr )
|
||||||
{
|
{
|
||||||
return (ptr >= parser->end || *ptr == CONTROL_Z || *ptr == '\n');
|
return (ptr >= parser->end || *ptr == CONTROL_Z || *ptr == '\n');
|
||||||
}
|
}
|
||||||
|
@ -560,7 +562,7 @@ static int add_section_from_token( struct parser *parser )
|
||||||
|
|
||||||
|
|
||||||
/* add a field containing the current token to the current line */
|
/* add a field containing the current token to the current line */
|
||||||
static struct field *add_field_from_token( struct parser *parser, int is_key )
|
static struct field *add_field_from_token( struct parser *parser, BOOL is_key )
|
||||||
{
|
{
|
||||||
struct field *field;
|
struct field *field;
|
||||||
WCHAR *text;
|
WCHAR *text;
|
||||||
|
@ -680,14 +682,14 @@ static const WCHAR *key_name_state( struct parser *parser, const WCHAR *pos )
|
||||||
|
|
||||||
case '=':
|
case '=':
|
||||||
push_token( parser, token_end );
|
push_token( parser, token_end );
|
||||||
if (!add_field_from_token( parser, 1 )) return NULL;
|
if (!add_field_from_token( parser, TRUE )) return NULL;
|
||||||
parser->start = p + 1;
|
parser->start = p + 1;
|
||||||
push_state( parser, VALUE_NAME );
|
push_state( parser, VALUE_NAME );
|
||||||
set_state( parser, LEADING_SPACES );
|
set_state( parser, LEADING_SPACES );
|
||||||
return p + 1;
|
return p + 1;
|
||||||
case ';':
|
case ';':
|
||||||
push_token( parser, token_end );
|
push_token( parser, token_end );
|
||||||
if (!add_field_from_token( parser, 0 )) return NULL;
|
if (!add_field_from_token( parser, FALSE )) return NULL;
|
||||||
push_state( parser, LINE_START );
|
push_state( parser, LINE_START );
|
||||||
set_state( parser, COMMENT );
|
set_state( parser, COMMENT );
|
||||||
return p + 1;
|
return p + 1;
|
||||||
|
@ -732,13 +734,13 @@ static const WCHAR *value_name_state( struct parser *parser, const WCHAR *pos )
|
||||||
{
|
{
|
||||||
case ';':
|
case ';':
|
||||||
push_token( parser, token_end );
|
push_token( parser, token_end );
|
||||||
if (!add_field_from_token( parser, 0 )) return NULL;
|
if (!add_field_from_token( parser, FALSE )) return NULL;
|
||||||
push_state( parser, LINE_START );
|
push_state( parser, LINE_START );
|
||||||
set_state( parser, COMMENT );
|
set_state( parser, COMMENT );
|
||||||
return p + 1;
|
return p + 1;
|
||||||
case ',':
|
case ',':
|
||||||
push_token( parser, token_end );
|
push_token( parser, token_end );
|
||||||
if (!add_field_from_token( parser, 0 )) return NULL;
|
if (!add_field_from_token( parser, FALSE )) return NULL;
|
||||||
parser->start = p + 1;
|
parser->start = p + 1;
|
||||||
push_state( parser, VALUE_NAME );
|
push_state( parser, VALUE_NAME );
|
||||||
set_state( parser, LEADING_SPACES );
|
set_state( parser, LEADING_SPACES );
|
||||||
|
@ -768,7 +770,7 @@ static const WCHAR *value_name_state( struct parser *parser, const WCHAR *pos )
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
push_token( parser, token_end );
|
push_token( parser, token_end );
|
||||||
if (!add_field_from_token( parser, 0 )) return NULL;
|
if (!add_field_from_token( parser, FALSE )) return NULL;
|
||||||
set_state( parser, LINE_START );
|
set_state( parser, LINE_START );
|
||||||
return p;
|
return p;
|
||||||
}
|
}
|
||||||
|
@ -810,7 +812,7 @@ static const WCHAR *eol_backslash_state( struct parser *parser, const WCHAR *pos
|
||||||
/* handler for parser QUOTES state */
|
/* handler for parser QUOTES state */
|
||||||
static const WCHAR *quotes_state( struct parser *parser, const WCHAR *pos )
|
static const WCHAR *quotes_state( struct parser *parser, const WCHAR *pos )
|
||||||
{
|
{
|
||||||
const WCHAR *p, *token_end = parser->start;
|
const WCHAR *p;
|
||||||
|
|
||||||
for (p = pos; !is_eol( parser, p ); p++)
|
for (p = pos; !is_eol( parser, p ); p++)
|
||||||
{
|
{
|
||||||
|
@ -819,7 +821,7 @@ static const WCHAR *quotes_state( struct parser *parser, const WCHAR *pos )
|
||||||
if (p+1 < parser->end && p[1] == '"') /* double quotes */
|
if (p+1 < parser->end && p[1] == '"') /* double quotes */
|
||||||
{
|
{
|
||||||
push_token( parser, p + 1 );
|
push_token( parser, p + 1 );
|
||||||
parser->start = token_end = p + 2;
|
parser->start = p + 2;
|
||||||
p++;
|
p++;
|
||||||
}
|
}
|
||||||
else /* end of quotes */
|
else /* end of quotes */
|
||||||
|
@ -888,6 +890,19 @@ static const WCHAR *comment_state( struct parser *parser, const WCHAR *pos )
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
static void free_inf_file( struct inf_file *file )
|
||||||
|
{
|
||||||
|
unsigned int i;
|
||||||
|
|
||||||
|
for (i = 0; i < file->nb_sections; i++) HeapFree( GetProcessHeap(), 0, file->sections[i] );
|
||||||
|
HeapFree( GetProcessHeap(), 0, file->filename );
|
||||||
|
HeapFree( GetProcessHeap(), 0, file->sections );
|
||||||
|
HeapFree( GetProcessHeap(), 0, file->fields );
|
||||||
|
HeapFree( GetProcessHeap(), 0, file->strings );
|
||||||
|
HeapFree( GetProcessHeap(), 0, file );
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
/* parse a complete buffer */
|
/* parse a complete buffer */
|
||||||
static DWORD parse_buffer( struct inf_file *file, const WCHAR *buffer, const WCHAR *end,
|
static DWORD parse_buffer( struct inf_file *file, const WCHAR *buffer, const WCHAR *end,
|
||||||
UINT *error_line )
|
UINT *error_line )
|
||||||
|
@ -1012,7 +1027,7 @@ static struct inf_file *parse_file( HANDLE handle, UINT *error_line, DWORD style
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
WCHAR *new_buff = (WCHAR *)buffer;
|
WCHAR *new_buff = buffer;
|
||||||
/* UCS-16 files should start with the Unicode BOM; we should skip it */
|
/* UCS-16 files should start with the Unicode BOM; we should skip it */
|
||||||
if (*new_buff == 0xfeff)
|
if (*new_buff == 0xfeff)
|
||||||
new_buff++;
|
new_buff++;
|
||||||
|
@ -1041,7 +1056,7 @@ static struct inf_file *parse_file( HANDLE handle, UINT *error_line, DWORD style
|
||||||
UnmapViewOfFile( buffer );
|
UnmapViewOfFile( buffer );
|
||||||
if (err)
|
if (err)
|
||||||
{
|
{
|
||||||
HeapFree( GetProcessHeap(), 0, file );
|
if (file) free_inf_file( file );
|
||||||
SetLastError( err );
|
SetLastError( err );
|
||||||
file = NULL;
|
file = NULL;
|
||||||
}
|
}
|
||||||
|
@ -1251,7 +1266,7 @@ HINF WINAPI SetupOpenInfFileW( PCWSTR name, PCWSTR class, DWORD style, UINT *err
|
||||||
|
|
||||||
if (handle != INVALID_HANDLE_VALUE)
|
if (handle != INVALID_HANDLE_VALUE)
|
||||||
{
|
{
|
||||||
file = parse_file( handle, error, style );
|
file = parse_file( handle, error, style);
|
||||||
CloseHandle( handle );
|
CloseHandle( handle );
|
||||||
}
|
}
|
||||||
if (!file)
|
if (!file)
|
||||||
|
@ -1293,7 +1308,7 @@ HINF WINAPI SetupOpenInfFileW( PCWSTR name, PCWSTR class, DWORD style, UINT *err
|
||||||
}
|
}
|
||||||
|
|
||||||
SetLastError( 0 );
|
SetLastError( 0 );
|
||||||
return (HINF)file;
|
return file;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -1366,16 +1381,10 @@ HINF WINAPI SetupOpenMasterInf( VOID )
|
||||||
void WINAPI SetupCloseInfFile( HINF hinf )
|
void WINAPI SetupCloseInfFile( HINF hinf )
|
||||||
{
|
{
|
||||||
struct inf_file *file = hinf;
|
struct inf_file *file = hinf;
|
||||||
unsigned int i;
|
|
||||||
|
|
||||||
if (!hinf || (hinf == INVALID_HANDLE_VALUE)) return;
|
if (!hinf || (hinf == INVALID_HANDLE_VALUE)) return;
|
||||||
|
|
||||||
for (i = 0; i < file->nb_sections; i++) HeapFree( GetProcessHeap(), 0, file->sections[i] );
|
free_inf_file( file );
|
||||||
HeapFree( GetProcessHeap(), 0, file->filename );
|
|
||||||
HeapFree( GetProcessHeap(), 0, file->sections );
|
|
||||||
HeapFree( GetProcessHeap(), 0, file->fields );
|
|
||||||
HeapFree( GetProcessHeap(), 0, file->strings );
|
|
||||||
HeapFree( GetProcessHeap(), 0, file );
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -261,13 +261,9 @@ inline static WCHAR *strdupAtoW( const char *str )
|
||||||
|
|
||||||
struct inf_file;
|
struct inf_file;
|
||||||
extern const WCHAR *DIRID_get_string( int dirid );
|
extern const WCHAR *DIRID_get_string( int dirid );
|
||||||
extern unsigned int PARSER_string_substA( const struct inf_file *file, const WCHAR *text,
|
extern const WCHAR *PARSER_get_inf_filename( HINF hinf ) DECLSPEC_HIDDEN;
|
||||||
char *buffer, unsigned int size );
|
extern WCHAR *PARSER_get_src_root( HINF hinf ) DECLSPEC_HIDDEN;
|
||||||
extern unsigned int PARSER_string_substW( const struct inf_file *file, const WCHAR *text,
|
extern WCHAR *PARSER_get_dest_dir( INFCONTEXT *context ) DECLSPEC_HIDDEN;
|
||||||
WCHAR *buffer, unsigned int size );
|
|
||||||
extern const WCHAR *PARSER_get_inf_filename( HINF hinf );
|
|
||||||
extern WCHAR *PARSER_get_src_root( HINF hinf );
|
|
||||||
extern WCHAR *PARSER_get_dest_dir( INFCONTEXT *context );
|
|
||||||
|
|
||||||
/* support for Ascii queue callback functions */
|
/* support for Ascii queue callback functions */
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue