diff options
author | Jon Loeliger <jdl@freescale.com> | 2007-02-16 09:33:54 -0600 |
---|---|---|
committer | Jon Loeliger <jdl@freescale.com> | 2007-02-16 09:33:54 -0600 |
commit | 3948849fd0cdcaf0b91c7cc4774e86c05ba097ef (patch) | |
tree | 5c0580f8d9a196f7370b2e5c0ed574913aad3371 /dtc-parser.y | |
parent | fd84d97deecc23b8519f8bc1f384a418bb69181b (diff) | |
download | dtc-3948849fd0cdcaf0b91c7cc4774e86c05ba097ef.zip dtc-3948849fd0cdcaf0b91c7cc4774e86c05ba097ef.tar.gz dtc-3948849fd0cdcaf0b91c7cc4774e86c05ba097ef.tar.bz2 |
Moved data_convert_cell() out of data.c to the parser.
It constructs a cell_t, not data objects.
Renamed it to cell_from_string() as well.
Signed-off-by: Jon Loeliger <jdl@freescale.com>
Diffstat (limited to 'dtc-parser.y')
-rw-r--r-- | dtc-parser.y | 30 |
1 files changed, 27 insertions, 3 deletions
diff --git a/dtc-parser.y b/dtc-parser.y index 992fdb1..a8902fc 100644 --- a/dtc-parser.y +++ b/dtc-parser.y @@ -24,8 +24,9 @@ %{ #include "dtc.h" -int yylex (void); -void yyerror (char const *); +int yylex(void); +void yyerror(char const *); +cell_t cell_from_string(char *s, unsigned int base); extern struct boot_info *the_boot_info; @@ -144,7 +145,7 @@ opt_cell_base: celllist: celllist opt_cell_base DT_CELL { $$ = data_append_cell($1, - data_convert_cell($3, $2)); + cell_from_string($3, $2)); } | celllist DT_REF { $$ = data_append_cell(data_add_fixup($1, $2), -1); @@ -179,3 +180,26 @@ void yyerror (char const *s) { fprintf (stderr, "%s at line %d\n", s, yylloc.first_line); } + + +/* + * Convert a string representation of a numeric cell + * in the given base into a cell. + * + * FIXME: The string "abc123", base 10, should be flagged + * as an error due to the leading "a", but isn't yet. + */ + +cell_t cell_from_string(char *s, unsigned int base) +{ + cell_t c; + + 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; +} |