regedit: Rewrite processRegLinesA into an ANSI version of processRegLinesW.
Signed-off-by: Hugh McMaster <hugh.mcmaster@outlook.com> Signed-off-by: Alexandre Julliard <julliard@winehq.org>
This commit is contained in:
parent
3056608fb8
commit
3763c7a610
|
@ -596,144 +596,120 @@ static void processRegEntry(WCHAR* stdInput, BOOL isUnicode)
|
||||||
*/
|
*/
|
||||||
static void processRegLinesA(FILE *in, char* first_chars)
|
static void processRegLinesA(FILE *in, char* first_chars)
|
||||||
{
|
{
|
||||||
LPSTR line = NULL; /* line read from input stream */
|
char *buf = NULL; /* the line read from the input stream */
|
||||||
ULONG lineSize = REG_VAL_BUF_SIZE;
|
unsigned long line_size = REG_VAL_BUF_SIZE;
|
||||||
|
size_t chars_in_buf = -1;
|
||||||
|
char *s; /* A pointer to buf for fread */
|
||||||
|
char *line; /* The start of the current line */
|
||||||
|
WCHAR *lineW;
|
||||||
|
|
||||||
|
buf = HeapAlloc(GetProcessHeap(), 0, line_size);
|
||||||
|
CHECK_ENOUGH_MEMORY(buf);
|
||||||
|
s = buf;
|
||||||
|
line = buf;
|
||||||
|
|
||||||
line = HeapAlloc(GetProcessHeap(), 0, lineSize);
|
|
||||||
CHECK_ENOUGH_MEMORY(line);
|
|
||||||
memcpy(line, first_chars, 2);
|
memcpy(line, first_chars, 2);
|
||||||
|
|
||||||
while (!feof(in)) {
|
if (first_chars)
|
||||||
LPSTR s; /* The pointer into line for where the current fgets should read */
|
s += 2;
|
||||||
WCHAR* lineW;
|
|
||||||
s = line;
|
|
||||||
|
|
||||||
if(first_chars)
|
while (!feof(in)) {
|
||||||
|
size_t size_remaining;
|
||||||
|
int size_to_get;
|
||||||
|
char *s_eol = NULL; /* various local uses */
|
||||||
|
|
||||||
|
/* Do we need to expand the buffer? */
|
||||||
|
assert(s >= buf && s <= buf + line_size);
|
||||||
|
size_remaining = line_size - (s - buf);
|
||||||
|
if (size_remaining < 3) /* we need at least 3 bytes of room for \r\n\0 */
|
||||||
{
|
{
|
||||||
s += 2;
|
char *new_buffer;
|
||||||
first_chars = NULL;
|
size_t new_size = line_size + REG_VAL_BUF_SIZE;
|
||||||
|
if (new_size > line_size) /* no arithmetic overflow */
|
||||||
|
new_buffer = HeapReAlloc(GetProcessHeap(), 0, buf, new_size);
|
||||||
|
else
|
||||||
|
new_buffer = NULL;
|
||||||
|
CHECK_ENOUGH_MEMORY(new_buffer);
|
||||||
|
buf = new_buffer;
|
||||||
|
line = buf;
|
||||||
|
s = buf + line_size - size_remaining;
|
||||||
|
line_size = new_size;
|
||||||
|
size_remaining = line_size - (s - buf);
|
||||||
}
|
}
|
||||||
|
|
||||||
for (;;) {
|
/* Get as much as possible into the buffer, terminating on EOF,
|
||||||
size_t size_remaining;
|
* error or once we have read the maximum amount. Abort on error.
|
||||||
int size_to_get, i;
|
*/
|
||||||
char *s_eol; /* various local uses */
|
size_to_get = (size_remaining > INT_MAX ? INT_MAX : size_remaining);
|
||||||
|
|
||||||
/* Do we need to expand the buffer ? */
|
chars_in_buf = fread(s, 1, size_to_get - 1, in);
|
||||||
assert (s >= line && s <= line + lineSize);
|
s[chars_in_buf] = 0;
|
||||||
size_remaining = lineSize - (s-line);
|
|
||||||
if (size_remaining < 3) /* need at least 3 bytes of room for \r\n\0 */
|
if (chars_in_buf == 0) {
|
||||||
{
|
if (ferror(in)) {
|
||||||
char *new_buffer;
|
perror("While reading input");
|
||||||
size_t new_size = lineSize + REG_VAL_BUF_SIZE;
|
exit(IO_ERROR);
|
||||||
if (new_size > lineSize) /* no arithmetic overflow */
|
} else {
|
||||||
new_buffer = HeapReAlloc (GetProcessHeap(), 0, line, new_size);
|
assert(feof(in));
|
||||||
else
|
*s = '\0';
|
||||||
new_buffer = NULL;
|
}
|
||||||
CHECK_ENOUGH_MEMORY(new_buffer);
|
}
|
||||||
line = new_buffer;
|
|
||||||
s = line + lineSize - size_remaining;
|
/* If we didn't read the end-of-line sequence or EOF, go around again */
|
||||||
lineSize = new_size;
|
while (1)
|
||||||
size_remaining = lineSize - (s-line);
|
{
|
||||||
|
s_eol = strpbrk(line, "\r\n");
|
||||||
|
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, strlen(line) + 1);
|
||||||
|
line = buf;
|
||||||
|
s = strchr(line, '\0');
|
||||||
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Get as much as possible into the buffer, terminated either by
|
/* If we find a comment line, discard it and go around again */
|
||||||
* eof, error, eol or getting the maximum amount. Abort on error.
|
|
||||||
*/
|
|
||||||
size_to_get = (size_remaining > INT_MAX ? INT_MAX : size_remaining);
|
|
||||||
|
|
||||||
/* get a single line. note that `i' must be one past the last
|
|
||||||
* meaningful character in `s' when this loop exits */
|
|
||||||
for(i = 0; i < size_to_get-1; ++i){
|
|
||||||
int xchar;
|
|
||||||
|
|
||||||
xchar = fgetc(in);
|
|
||||||
s[i] = xchar;
|
|
||||||
if(xchar == EOF){
|
|
||||||
if(ferror(in)){
|
|
||||||
perror("While reading input");
|
|
||||||
exit(IO_ERROR);
|
|
||||||
}else
|
|
||||||
assert(feof(in));
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
if(s[i] == '\r'){
|
|
||||||
/* read the next character iff it's \n */
|
|
||||||
if(i+2 >= size_to_get){
|
|
||||||
/* buffer too short, so put back the EOL char to
|
|
||||||
* read next cycle */
|
|
||||||
ungetc('\r', in);
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
s[i+1] = fgetc(in);
|
|
||||||
if(s[i+1] != '\n'){
|
|
||||||
ungetc(s[i+1], in);
|
|
||||||
i = i+1;
|
|
||||||
}else
|
|
||||||
i = i+2;
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
if(s[i] == '\n'){
|
|
||||||
i = i+1;
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
s[i] = '\0';
|
|
||||||
|
|
||||||
/* If we didn't read the eol nor the eof go around for the rest */
|
|
||||||
s_eol = strpbrk (s, "\r\n");
|
|
||||||
if (!feof (in) && !s_eol) {
|
|
||||||
s = strchr (s, '\0');
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
|
|
||||||
/* If it is a comment line then discard it and go around again */
|
|
||||||
if (line [0] == '#' || line [0] == ';') {
|
if (line [0] == '#' || line [0] == ';') {
|
||||||
s = line;
|
if (*s_eol == '\r' && *(s_eol + 1) == '\n')
|
||||||
continue;
|
line = s_eol + 2;
|
||||||
}
|
|
||||||
|
|
||||||
/* Remove any line feed. Leave s_eol on the first \0 */
|
|
||||||
if (s_eol) {
|
|
||||||
if (*s_eol == '\r' && *(s_eol+1) == '\n')
|
|
||||||
*(s_eol+1) = '\0';
|
|
||||||
*s_eol = '\0';
|
|
||||||
} else
|
|
||||||
s_eol = strchr (s, '\0');
|
|
||||||
|
|
||||||
/* If there is a concatenating \\ then go around again */
|
|
||||||
if (s_eol > line && *(s_eol-1) == '\\') {
|
|
||||||
int c;
|
|
||||||
s = s_eol-1;
|
|
||||||
|
|
||||||
do
|
|
||||||
{
|
|
||||||
c = fgetc(in);
|
|
||||||
} while(c == ' ' || c == '\t');
|
|
||||||
|
|
||||||
if(c == EOF)
|
|
||||||
{
|
|
||||||
fprintf(stderr, "regedit: ERROR - invalid continuation.\n");
|
|
||||||
}
|
|
||||||
else
|
else
|
||||||
{
|
line = s_eol + 1;
|
||||||
*s = c;
|
|
||||||
s++;
|
|
||||||
}
|
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* If there is a concatenating '\\', go around again */
|
||||||
|
if (*(s_eol - 1) == '\\') {
|
||||||
|
char *next_line = s_eol + 1;
|
||||||
|
|
||||||
|
if (*s_eol == '\r' && *(s_eol + 1) == '\n')
|
||||||
|
next_line++;
|
||||||
|
|
||||||
|
while (*(next_line + 1) == ' ' || *(next_line + 1) == '\t')
|
||||||
|
next_line++;
|
||||||
|
|
||||||
|
MoveMemory(s_eol - 1, next_line, chars_in_buf - (next_line - s) + 1);
|
||||||
|
chars_in_buf -= next_line - s_eol + 1;
|
||||||
|
s_eol = 0;
|
||||||
|
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';
|
||||||
|
|
||||||
lineW = GetWideString(line);
|
lineW = GetWideString(line);
|
||||||
|
processRegEntry(lineW, FALSE);
|
||||||
break; /* That is the full virtual line */
|
HeapFree(GetProcessHeap(), 0, lineW);
|
||||||
|
line = s_eol + 1;
|
||||||
|
s_eol = 0;
|
||||||
|
continue; /* That is the full virtual line */
|
||||||
}
|
}
|
||||||
|
|
||||||
processRegEntry(lineW, FALSE);
|
|
||||||
HeapFree(GetProcessHeap(), 0, lineW);
|
|
||||||
}
|
}
|
||||||
processRegEntry(NULL, FALSE);
|
processRegEntry(NULL, FALSE);
|
||||||
|
|
||||||
HeapFree(GetProcessHeap(), 0, line);
|
HeapFree(GetProcessHeap(), 0, buf);
|
||||||
}
|
}
|
||||||
|
|
||||||
static void processRegLinesW(FILE *in)
|
static void processRegLinesW(FILE *in)
|
||||||
|
|
Loading…
Reference in New Issue