summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authormrb0nk500 <b0nk@b0nk.xyz>2021-05-08 12:55:21 -0400
committermrb0nk500 <b0nk@b0nk.xyz>2021-05-08 12:55:21 -0400
commit11ec62df93c86bda4100bcdd712c4406a68dd149 (patch)
treec75bee104963ab2b3872a7c9c08c3ee05d34b2b8
parent5db9af7b0d1d027b9325b45917ab46beaa52d5a0 (diff)
Add support for saving to a string buffer in
parse_quote(). This allows for replacing the string parsing code in handle_directive() with a call to parse_quote().
-rw-r--r--asmmon.h1
-rw-r--r--lexer.c25
2 files changed, 17 insertions, 9 deletions
diff --git a/asmmon.h b/asmmon.h
index 1be290d..fd52770 100644
--- a/asmmon.h
+++ b/asmmon.h
@@ -852,6 +852,7 @@ extern uint8_t defined;
extern uint8_t isfixup;
extern line *find_line(uint32_t ln, uint8_t dbg);
+extern uint64_t parse_quote(char **s, char delm, int get_value, uint8_t *buf, uint8_t dbg);
extern uint64_t lex(char *str, uint64_t address, uint16_t bline, uint8_t dbg);
extern uint64_t get_val(expr *tree, uint64_t addr, uint8_t size, int depth, uint8_t dbg);
extern token *skip_expr(token *t, uint8_t end_expr, uint8_t stop_comma, uint8_t dbg);
diff --git a/lexer.c b/lexer.c
index 099204e..d27a7f0 100644
--- a/lexer.c
+++ b/lexer.c
@@ -588,19 +588,21 @@ char *parse_escape(char *s, char *code) {
}
}
-uint64_t parse_quote(char **s, char delm, int get_value, uint8_t dbg) {
+uint64_t parse_quote(char **s, char delm, int get_value, uint8_t *buf, uint8_t dbg) {
uint64_t value = 0;
- uint8_t *tmp_val = (uint8_t *)&value;
- char *str = *s+1;
+ uint8_t *tmp_val = (buf != NULL) ? buf : (uint8_t *)&value;
+ const uint8_t has_delm = (delm && **s == delm);
+ char *str = *s+has_delm;
+ int i;
- for (int i = 0; *str; i++) {
+ for (i = 0; *str; i++) {
char c;
/* Are we at the start of an escape character? */
if (*str == '\\') {
str = parse_escape(str, &c);
} else {
c = *str++;
- if (c == delm) {
+ if (delm && c == delm) {
if (*str == delm) {
/* Allow for multiple repeated
* instances of delm to be treated
@@ -612,14 +614,19 @@ uint64_t parse_quote(char **s, char delm, int get_value, uint8_t dbg) {
}
}
}
- if (get_value && i < sizeof(uint64_t)) {
+ if (get_value && (buf != NULL || i < sizeof(uint64_t))) {
tmp_val[i] = c;
}
}
+ if (get_value && buf != NULL) {
+ tmp_val[i] = '\0';
+ }
+ //i = (get_value && buf != NULL && i > len) ? len : i;
+
*s = str;
- return value;
+ return (buf != NULL) ? ++i : value;
}
expr *make_expr(int type, uint64_t value, symbol *sym, uint8_t dbg) {
@@ -732,7 +739,7 @@ int get_expr_type(char **p, uint64_t address, void *val, int *found_reg, char st
break;
case PTOK_SQUOTE:
type = EXPR_CHAR;
- value = parse_quote(&str, *str, 1, dbg);
+ value = parse_quote(&str, *str, 1, NULL, dbg);
*(uint64_t *)val = value;
break;
case PTOK_AT:
@@ -1004,7 +1011,7 @@ uint64_t lex(char *str, uint64_t address, uint16_t bline, uint8_t dbg) {
do {
char *tmp = (str + i);
int get_value = (ptok == PTOK_SQUOTE);
- value = parse_quote(&tmp, str[i], get_value, dbg);
+ value = parse_quote(&tmp, str[i], get_value, NULL, dbg);
tmp--;
i++;
j = tmp - (str + i);