summaryrefslogtreecommitdiff
path: root/nasm.c
diff options
context:
space:
mode:
authorCyrill Gorcunov <gorcunov@gmail.com>2009-09-18 19:23:53 +0400
committerCyrill Gorcunov <gorcunov@gmail.com>2009-10-13 19:42:05 +0400
commitbd416c6860cd48e9df78278923c43d3b03b761ad (patch)
tree698ec9ae2cd2070d432128648a494999cec2cb09 /nasm.c
parentc7e8f1bf6faff60c16dbbc920c3a36c2251ab3ab (diff)
downloadnasm-bd416c6860cd48e9df78278923c43d3b03b761ad.tar.gz
nasm-bd416c6860cd48e9df78278923c43d3b03b761ad.tar.bz2
nasm-bd416c6860cd48e9df78278923c43d3b03b761ad.zip
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 <gorcunov@gmail.com>
Diffstat (limited to 'nasm.c')
-rw-r--r--nasm.c63
1 files changed, 27 insertions, 36 deletions
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);
}