mirror of
https://github.com/netwide-assembler/nasm.git
synced 2024-11-21 03:14:19 +08:00
nasmlib.c: Introduce nasm_get_word helper
For easier space separated words extraction from a text stream. Signed-off-by: Cyrill Gorcunov <gorcunov@gmail.com>
This commit is contained in:
parent
c084467eba
commit
6702d93c10
21
nasmlib.c
21
nasmlib.c
@ -704,6 +704,27 @@ char *nasm_trim_spaces(char *p)
|
||||
return p;
|
||||
}
|
||||
|
||||
/*
|
||||
* return the word extracted from a stream
|
||||
* or NULL if nothing left
|
||||
*/
|
||||
char *nasm_get_word(char *p, char **tail)
|
||||
{
|
||||
char *word = nasm_skip_spaces(p);
|
||||
char *next = nasm_skip_word(word);
|
||||
|
||||
if (word && *word) {
|
||||
if (*next)
|
||||
*next++ = '\0';
|
||||
} else
|
||||
word = next = NULL;
|
||||
|
||||
/* NOTE: the tail may start with spaces */
|
||||
*tail = next;
|
||||
|
||||
return word;
|
||||
}
|
||||
|
||||
/*
|
||||
* extract option and value from a string formatted as "opt = val"
|
||||
* and return pointer to the next string or NULL on empty string
|
||||
|
@ -394,6 +394,7 @@ char *nasm_skip_word(const char *p);
|
||||
char *nasm_zap_spaces_fwd(char *p);
|
||||
char *nasm_zap_spaces_rev(char *p);
|
||||
char *nasm_trim_spaces(char *p);
|
||||
char *nasm_get_word(char *p, char **tail);
|
||||
char *nasm_opt_val(char *p, char **opt, char **val);
|
||||
|
||||
const char *prefix_name(int);
|
||||
|
Loading…
Reference in New Issue
Block a user