From: Cyrill Gorcunov Date: Sat, 10 Apr 2010 21:03:20 +0000 (+0400) Subject: nasmlib.c: Introduce nasm_get_word helper X-Git-Tag: nasm-2.11.05~677 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=6702d93c10c003cf9472d33a67185db0a5a8c593;p=platform%2Fupstream%2Fnasm.git nasmlib.c: Introduce nasm_get_word helper For easier space separated words extraction from a text stream. Signed-off-by: Cyrill Gorcunov --- diff --git a/nasmlib.c b/nasmlib.c index 2351101..812f640 100644 --- a/nasmlib.c +++ b/nasmlib.c @@ -705,6 +705,27 @@ char *nasm_trim_spaces(char *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 * passed or if nothing left for handling diff --git a/nasmlib.h b/nasmlib.h index f103e62..5efb0b4 100644 --- a/nasmlib.h +++ b/nasmlib.h @@ -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);