Commit 6b6e2cb9 authored by Hugh McMaster's avatar Hugh McMaster Committed by Alexandre Julliard

regedit: Re-implement processRegLinesW().

parent ae568447
...@@ -793,120 +793,79 @@ static void processRegLinesA(FILE *in, char* first_chars) ...@@ -793,120 +793,79 @@ static void processRegLinesA(FILE *in, char* first_chars)
HeapFree(GetProcessHeap(), 0, buf); HeapFree(GetProcessHeap(), 0, buf);
} }
static void processRegLinesW(FILE *in) static WCHAR *get_lineW(FILE *fp)
{ {
WCHAR* buf = NULL; /* line read from input stream */ static size_t size;
ULONG lineSize = REG_VAL_BUF_SIZE; static WCHAR *buf, *next;
size_t CharsInBuf = -1; WCHAR *line;
WCHAR* s; /* The pointer into buf for where the current fgets should read */ if (!size)
WCHAR* line; /* The start of the current line */ {
size = REG_VAL_BUF_SIZE;
buf = HeapAlloc(GetProcessHeap(), 0, lineSize * sizeof(WCHAR)); buf = HeapAlloc(GetProcessHeap(), 0, size * sizeof(WCHAR));
CHECK_ENOUGH_MEMORY(buf); CHECK_ENOUGH_MEMORY(buf);
*buf = 0;
s = buf; next = buf;
line = buf; }
line = next;
while(!feof(in)) {
size_t size_remaining;
int size_to_get;
WCHAR *s_eol = NULL; /* various local uses */
/* Do we need to expand the buffer ? */ while (next)
assert (s >= buf && s <= buf + lineSize); {
size_remaining = lineSize - (s-buf); static const WCHAR line_endings[] = {'\r','\n',0};
if (size_remaining < 2) /* room for 1 character and the \0 */ WCHAR *p = strpbrkW(line, line_endings);
if (!p)
{ {
WCHAR *new_buffer; size_t len, count;
size_t new_size = lineSize + (REG_VAL_BUF_SIZE / sizeof(WCHAR)); len = strlenW(next);
if (new_size > lineSize) /* no arithmetic overflow */ memmove(buf, next, (len + 1) * sizeof(WCHAR));
new_buffer = HeapReAlloc (GetProcessHeap(), 0, buf, new_size * sizeof(WCHAR)); if (size - len < 3)
else {
new_buffer = NULL; WCHAR *new_buf = HeapReAlloc(GetProcessHeap(), 0, buf, (size * 2) * sizeof(WCHAR));
CHECK_ENOUGH_MEMORY(new_buffer); CHECK_ENOUGH_MEMORY(new_buf);
buf = new_buffer; buf = new_buf;
size *= 2;
}
if (!(count = fread(buf + len, sizeof(WCHAR), size - len - 1, fp)))
{
next = NULL;
return buf;
}
buf[len + count] = 0;
next = buf;
line = buf; line = buf;
s = buf + lineSize - size_remaining; continue;
lineSize = new_size;
size_remaining = lineSize - (s-buf);
} }
next = p + 1;
/* Get as much as possible into the buffer, terminated either by if (*p == '\r' && *(p + 1) == '\n') next++;
* eof, error or getting the maximum amount. Abort on error. *p = 0;
*/ if (*(p - 1) == '\\')
size_to_get = (size_remaining > INT_MAX ? INT_MAX : size_remaining); {
*(--p) = 0;
CharsInBuf = fread(s, sizeof(WCHAR), size_to_get - 1, in); while (*next && (*next == ' ' || *next == '\t')) next++;
s[CharsInBuf] = 0; memmove(p, next, (strlenW(next) + 1) * sizeof(WCHAR));
next = line;
if (CharsInBuf == 0) { continue;
if (ferror(in)) {
perror ("While reading input");
exit (IO_ERROR);
} else {
assert (feof(in));
*s = '\0';
/* It is not clear to me from the definition that the
* contents of the buffer are well defined on detecting
* an eof without managing to read anything.
*/
}
} }
if (*line == ';' || *line == '#')
/* If we didn't read the eol nor the eof go around for the rest */
while(1)
{ {
const WCHAR line_endings[] = {'\r','\n',0}; line = next;
s_eol = strpbrkW(line, line_endings); continue;
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 */
MoveMemory(buf, line, (strlenW(line)+1) * sizeof(WCHAR));
line = buf;
s = strchrW(line, '\0');
break;
}
/* If it is a comment line then discard it and go around again */
if (*line == '#' || *line == ';') {
if (*s_eol == '\r' && *(s_eol+1) == '\n')
line = s_eol + 2;
else
line = s_eol + 1;
continue;
}
/* If there is a concatenating \\ then go around again */
if (*(s_eol-1) == '\\') {
WCHAR* NextLine = s_eol + 1;
if(*s_eol == '\r' && *(s_eol+1) == '\n')
NextLine++;
while(*(NextLine+1) == ' ' || *(NextLine+1) == '\t')
NextLine++;
MoveMemory(s_eol - 1, NextLine, (CharsInBuf - (NextLine - s) + 1)*sizeof(WCHAR));
CharsInBuf -= NextLine - s_eol + 1;
continue;
}
/* Remove any line feed. Leave s_eol on the last \0 */
if (*s_eol == '\r' && *(s_eol + 1) == '\n')
*s_eol++ = '\0';
*s_eol = '\0';
processRegEntry(line, TRUE);
line = s_eol + 1;
} }
return line;
} }
HeapFree( GetProcessHeap(), 0, buf );
size = 0;
return NULL;
}
closeKey(); static void processRegLinesW(FILE *fp)
{
WCHAR *line;
HeapFree(GetProcessHeap(), 0, buf); while ((line = get_lineW(fp)))
processRegEntry(line, TRUE);
closeKey();
} }
/****************************************************************************** /******************************************************************************
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment