Add support for decimal, octal and binary based cell values.
New syntax d#, b#, o# and h# allow for an explicit prefix
on cell values to specify their base. Eg: <d# 123>
Signed-off-by: Jon Loeliger <jdl@freescale.com>
diff --git a/data.c b/data.c
index 1907a1a..c6c2350 100644
--- a/data.c
+++ b/data.c
@@ -19,6 +19,7 @@
*/
#include "dtc.h"
+#include "dtc-parser.tab.h"
void fixup_free(struct fixup *f)
{
@@ -224,6 +225,26 @@
return d;
}
+/*
+ * Convert a string representation of a numberic cell
+ * in the given base into a cell.
+ */
+cell_t data_convert_cell(char *s, unsigned int base)
+{
+ cell_t c;
+ extern YYLTYPE yylloc;
+
+ c = strtoul(s, NULL, base);
+ if (errno == EINVAL || errno == ERANGE) {
+ fprintf(stderr,
+ "Line %d: Invalid cell value '%s'; %d assumed\n",
+ yylloc.first_line, s, c);
+ }
+
+ return c;
+}
+
+
struct data data_append_cell(struct data d, cell_t word)
{
cell_t beword = cpu_to_be32(word);