From: Cyrill Gorcunov Date: Fri, 18 Sep 2009 15:23:53 +0000 (+0400) Subject: nasm.c: getkw -- use string helpers X-Git-Tag: nasm-2.11.05~809 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=bd416c6860cd48e9df78278923c43d3b03b761ad;p=platform%2Fupstream%2Fnasm.git nasm.c: getkw -- use string helpers This allow us to shrink code a bit and make it easy to read. Signed-off-by: Cyrill Gorcunov --- diff --git a/nasm.c b/nasm.c index 7bf7c57..2004965 100644 --- a/nasm.c +++ b/nasm.c @@ -1772,47 +1772,38 @@ static enum directives getkw(char **directive, char **value) { char *p, *q, *buf; - buf = *directive; - - /* allow leading spaces or tabs */ - while (*buf == ' ' || *buf == '\t') - buf++; + buf = nasm_skip_spaces(*directive); + /* it should be enclosed in [ ] */ if (*buf != '[') - return 0; - - p = buf; - - while (*p && *p != ']') - p++; + return D_NONE; + q = strchr(buf, ']'); + if (!q) + return D_NONE; + + /* stip off the comments */ + p = strchr(buf, ';'); + if (p) { + if (p < q) /* ouch! somwhere inside */ + return D_NONE; + *p = '\0'; + } - if (!*p) - return 0; + /* no brace, no trailing spaces */ + *q = '\0'; + nasm_zap_spaces_rev(--q); - q = p++; + /* directive */ + p = nasm_skip_spaces(++buf); + q = nasm_skip_word(p); + if (!q) + return D_NONE; /* sigh... no value there */ + *q = '\0'; + *directive = p; - while (*p && *p != ';') { - if (!nasm_isspace(*p)) - return 0; - p++; - } - q[1] = '\0'; - - *directive = p = buf + 1; - while (*buf && *buf != ' ' && *buf != ']' && *buf != '\t') - buf++; - if (*buf == ']') { - *buf = '\0'; - *value = buf; - } else { - *buf++ = '\0'; - while (nasm_isspace(*buf)) - buf++; /* beppu - skip leading whitespace */ - *value = buf; - while (*buf != ']') - buf++; - *buf++ = '\0'; - } + /* and value finally */ + p = nasm_skip_spaces(++q); + *value = p; return find_directive(*directive); }