lexor handles arbitrary length defines in the precompiled_defiles file.
This commit is contained in:
parent
006aef93d0
commit
3e9c14060f
|
|
@ -2066,51 +2066,66 @@ void dump_precompiled_defines(FILE* out)
|
||||||
|
|
||||||
void load_precompiled_defines(FILE* src)
|
void load_precompiled_defines(FILE* src)
|
||||||
{
|
{
|
||||||
char buf[4096];
|
char*buf = malloc(4096);
|
||||||
|
size_t buf_len = 4096;
|
||||||
int ch;
|
int ch;
|
||||||
|
|
||||||
while ((ch = fgetc(src)) != EOF)
|
while ((ch = fgetc(src)) != EOF)
|
||||||
{
|
{
|
||||||
char* cp = buf;
|
char* cp = buf;
|
||||||
char* name = 0;
|
char* name = 0;
|
||||||
char* value = 0;
|
|
||||||
|
|
||||||
int argc = 0;
|
int argc = 0;
|
||||||
size_t len = 0;
|
size_t len = 0;
|
||||||
|
|
||||||
name = cp;
|
|
||||||
|
|
||||||
*cp++ = ch;
|
*cp++ = ch;
|
||||||
|
|
||||||
while ((ch = fgetc(src)) != EOF && ch != ':')
|
while ((ch = fgetc(src)) != EOF && ch != ':') {
|
||||||
*cp++ = ch;
|
*cp++ = ch;
|
||||||
|
assert( (size_t)(cp-buf) < buf_len );
|
||||||
|
}
|
||||||
|
|
||||||
if (ch != ':')
|
if (ch != ':')
|
||||||
return;
|
return;
|
||||||
|
|
||||||
/* Terminate the name string. */
|
/* Terminate the name string. */
|
||||||
*cp++ = 0;
|
*cp++ = 0;
|
||||||
|
assert( (size_t)(cp-buf) < buf_len );
|
||||||
|
|
||||||
/* Read the argc number */
|
/* Read the argc number. (this doesn't need buffer space) */
|
||||||
while (isdigit(ch = fgetc(src)))
|
while (isdigit(ch = fgetc(src)))
|
||||||
argc = 10*argc + ch-'0';
|
argc = 10*argc + ch-'0';
|
||||||
|
|
||||||
if (ch != ':')
|
if (ch != ':')
|
||||||
return;
|
return;
|
||||||
|
|
||||||
|
/* Read the value len (this doesn't need buffer space) */
|
||||||
while (isdigit(ch = fgetc(src)))
|
while (isdigit(ch = fgetc(src)))
|
||||||
len = 10*len + ch-'0';
|
len = 10*len + ch-'0';
|
||||||
|
|
||||||
if (ch != ':')
|
if (ch != ':')
|
||||||
return;
|
return;
|
||||||
|
|
||||||
value = cp;
|
/* Save the name, and start the buffer over. */
|
||||||
|
name = strdup(buf);
|
||||||
|
|
||||||
|
/* We now know how big the value should be, so if necessary,
|
||||||
|
reallocate the buffer to be sure we can hold it. */
|
||||||
|
if ((len+4) >= buf_len) {
|
||||||
|
buf = realloc(buf, len+8);
|
||||||
|
assert(buf);
|
||||||
|
}
|
||||||
|
|
||||||
|
cp = buf;
|
||||||
|
|
||||||
while (len > 0)
|
while (len > 0)
|
||||||
{
|
{
|
||||||
ch = fgetc(src);
|
ch = fgetc(src);
|
||||||
if (ch == EOF)
|
if (ch == EOF) {
|
||||||
|
free(name);
|
||||||
return;
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
*cp++ = ch;
|
*cp++ = ch;
|
||||||
len -= 1;
|
len -= 1;
|
||||||
|
|
@ -2119,10 +2134,14 @@ void load_precompiled_defines(FILE* src)
|
||||||
*cp++ = 0;
|
*cp++ = 0;
|
||||||
|
|
||||||
ch = fgetc(src);
|
ch = fgetc(src);
|
||||||
if (ch != '\n')
|
if (ch != '\n') {
|
||||||
|
free(name);
|
||||||
|
free(buf);
|
||||||
return;
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
define_macro(name, value, 0, argc);
|
define_macro(name, buf, 0, argc);
|
||||||
|
free(name);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue