summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorCyrill Gorcunov <gorcunov@gmail.com>2010-04-09 13:17:23 +0400
committerCyrill Gorcunov <gorcunov@gmail.com>2010-04-10 00:02:32 +0400
commitbb0745f432fcbebd7866f55ea246bae7a484504b (patch)
tree8060346911a34d21e17e9d8f1e9d13bcd220144f
parent28711d949aa1ca3afbb780d645a5beef4b5d9b9c (diff)
downloadnasm-bb0745f432fcbebd7866f55ea246bae7a484504b.tar.gz
nasm-bb0745f432fcbebd7866f55ea246bae7a484504b.tar.bz2
nasm-bb0745f432fcbebd7866f55ea246bae7a484504b.zip
nasmlib: Introduce nasm_trim_spaces and nasm_opt_val helpers
Signed-off-by: Cyrill Gorcunov <gorcunov@gmail.com>
-rw-r--r--nasmlib.c35
-rw-r--r--nasmlib.h2
2 files changed, 37 insertions, 0 deletions
diff --git a/nasmlib.c b/nasmlib.c
index 22d3b62..550c42d 100644
--- a/nasmlib.c
+++ b/nasmlib.c
@@ -690,6 +690,41 @@ char *nasm_zap_spaces_rev(char *p)
return p;
}
+/* zap leading and trailing spaces */
+char *nasm_trim_spaces(char *p)
+{
+ p = nasm_zap_spaces_fwd(p);
+ nasm_zap_spaces_fwd(nasm_skip_word(p));
+
+ return p;
+}
+
+/*
+ * 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
+ */
+char *nasm_opt_val(char *p, char **opt, char **val)
+{
+ char *q, *next;
+
+ p = nasm_skip_spaces(p);
+ if (!p || (p && !*p))
+ return NULL;
+
+ q = strchr(p, '=');
+ if (q) {
+ *q++ = '\0';
+ next = nasm_skip_spaces(nasm_skip_word(nasm_skip_spaces(q)));
+ } else
+ next = nasm_skip_spaces(nasm_skip_word(nasm_skip_spaces(p)));
+
+ *opt = nasm_trim_spaces(p);
+ *val = nasm_trim_spaces(q);
+
+ return next;
+}
+
/*
* initialized data bytes length from opcode
*/
diff --git a/nasmlib.h b/nasmlib.h
index b034947..f103e62 100644
--- a/nasmlib.h
+++ b/nasmlib.h
@@ -393,6 +393,8 @@ char *nasm_skip_spaces(const char *p);
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_opt_val(char *p, char **opt, char **val);
const char *prefix_name(int);