mirror of
https://github.com/netwide-assembler/nasm.git
synced 2025-01-24 16:35:40 +08:00
preproc: Extract reading line from predefined macros from read_line
It makes read_line less complex Signed-off-by: Cyrill Gorcunov <gorcunov@gmail.com>
This commit is contained in:
parent
924df0d498
commit
15bdc51187
51
preproc.c
51
preproc.c
@ -680,31 +680,29 @@ hash_findix(struct hash_table *hash, const char *str)
|
||||
return p ? *p : NULL;
|
||||
}
|
||||
|
||||
#define BUF_DELTA 512
|
||||
/*
|
||||
* Read a line from the top file in istk, handling multiple CR/LFs
|
||||
* at the end of the line read, and handling spurious ^Zs. Will
|
||||
* return lines from the standard macro set if this has not already
|
||||
* been done.
|
||||
* read line from standart macros set,
|
||||
* if there no more left -- return NULL
|
||||
*/
|
||||
static char *read_line(void)
|
||||
static char *line_from_stdmac(void)
|
||||
{
|
||||
char *buffer, *p, *q;
|
||||
int bufsize, continued_count;
|
||||
|
||||
if (stdmacpos) {
|
||||
unsigned char c;
|
||||
const unsigned char *p = stdmacpos;
|
||||
char *ret, *q;
|
||||
char *line, *q;
|
||||
size_t len = 0;
|
||||
|
||||
if (!stdmacpos)
|
||||
return NULL;
|
||||
|
||||
while ((c = *p++)) {
|
||||
if (c >= 0x80)
|
||||
len += pp_directives_len[c - 0x80] + 1;
|
||||
else
|
||||
len++;
|
||||
}
|
||||
ret = nasm_malloc(len+1);
|
||||
q = ret;
|
||||
|
||||
line = nasm_malloc(len + 1);
|
||||
q = line;
|
||||
while ((c = *stdmacpos++)) {
|
||||
if (c >= 0x80) {
|
||||
memcpy(q, pp_directives[c - 0x80], pp_directives_len[c - 0x80]);
|
||||
@ -741,18 +739,43 @@ static char *read_line(void)
|
||||
*tail = new_Token(NULL, t->type, t->text, 0);
|
||||
tail = &(*tail)->next;
|
||||
}
|
||||
|
||||
l = nasm_malloc(sizeof(Line));
|
||||
l->next = istk->expansion;
|
||||
l->first = head;
|
||||
l->finishes = NULL;
|
||||
|
||||
istk->expansion = l;
|
||||
}
|
||||
do_predef = false;
|
||||
}
|
||||
}
|
||||
return ret;
|
||||
|
||||
return line;
|
||||
}
|
||||
|
||||
#define BUF_DELTA 512
|
||||
/*
|
||||
* Read a line from the top file in istk, handling multiple CR/LFs
|
||||
* at the end of the line read, and handling spurious ^Zs. Will
|
||||
* return lines from the standard macro set if this has not already
|
||||
* been done.
|
||||
*/
|
||||
static char *read_line(void)
|
||||
{
|
||||
char *buffer, *p, *q;
|
||||
int bufsize, continued_count;
|
||||
|
||||
/*
|
||||
* standart macros set (predefined) goes first
|
||||
*/
|
||||
p = line_from_stdmac();
|
||||
if (p)
|
||||
return p;
|
||||
|
||||
/*
|
||||
* regular read from a file
|
||||
*/
|
||||
bufsize = BUF_DELTA;
|
||||
buffer = nasm_malloc(BUF_DELTA);
|
||||
p = buffer;
|
||||
|
Loading…
Reference in New Issue
Block a user