summaryrefslogtreecommitdiff
path: root/treesource.c
diff options
context:
space:
mode:
authorDavid Gibson <david@gibson.dropbear.id.au>2007-11-07 10:22:25 +1100
committerJon Loeliger <jdl@freescale.com>2007-11-08 09:02:49 -0600
commitd3ea6e5f96e8b6fb74607b9061836f2bdd57b0af (patch)
treed0def954173fb6cee26cbdc1eb3e88957dfeddd0 /treesource.c
parented01ae41e2cbbbd26c9efd495b833ba9eb1e062a (diff)
downloaddtc-d3ea6e5f96e8b6fb74607b9061836f2bdd57b0af.tar.gz
dtc: Make -Idts -Odts preserve property-internal labels
This patch changes -Odts mode output so that labels within property values in the input are preserved in the output. Applied on top of the earlier patch to preserve node and property labels in -Odts mode, this means that dtc in -Idts -Odts mode will transfer all labels in the input to the output. Signed-off-by: David Gibson <david@gibson.dropbear.id.au>
Diffstat (limited to 'treesource.c')
-rw-r--r--treesource.c66
1 files changed, 61 insertions, 5 deletions
diff --git a/treesource.c b/treesource.c
index 0a4367a..0752280 100644
--- a/treesource.c
+++ b/treesource.c
@@ -60,13 +60,24 @@ static void write_propval_string(FILE *f, struct data val)
{
char *str = val.val;
int i;
+ int newchunk = 1;
+ struct fixup *l = val.labels;
assert(str[val.len-1] == '\0');
- fprintf(f, "\"");
for (i = 0; i < (val.len-1); i++) {
char c = str[i];
+ if (newchunk) {
+ while (l && (l->offset <= i)) {
+ assert(l->offset == i);
+ fprintf(f, "%s: ", l->ref);
+ l = l->next;
+ }
+ fprintf(f, "\"");
+ newchunk = 0;
+ }
+
switch (c) {
case '\a':
fprintf(f, "\\a");
@@ -96,7 +107,8 @@ static void write_propval_string(FILE *f, struct data val)
fprintf(f, "\\\"");
break;
case '\0':
- fprintf(f, "\", \"");
+ fprintf(f, "\", ");
+ newchunk = 1;
break;
default:
if (isprint(c))
@@ -106,20 +118,41 @@ static void write_propval_string(FILE *f, struct data val)
}
}
fprintf(f, "\"");
+
+ /* Wrap up any labels at the end of the value */
+ while (l) {
+ assert (l->offset == val.len);
+ fprintf(f, " %s:", l->ref);
+ l = l->next;
+ }
}
static void write_propval_cells(FILE *f, struct data val)
{
void *propend = val.val + val.len;
cell_t *cp = (cell_t *)val.val;
+ struct fixup *l = val.labels;
fprintf(f, "<");
for (;;) {
+ while (l && (l->offset <= ((char *)cp - val.val))) {
+ assert(l->offset == ((char *)cp - val.val));
+ fprintf(f, "%s: ", l->ref);
+ l = l->next;
+ }
+
fprintf(f, "%x", be32_to_cpu(*cp++));
if ((void *)cp >= propend)
break;
fprintf(f, " ");
}
+
+ /* Wrap up any labels at the end of the value */
+ while (l) {
+ assert (l->offset == val.len);
+ fprintf(f, " %s:", l->ref);
+ l = l->next;
+ }
fprintf(f, ">");
}
@@ -127,14 +160,27 @@ static void write_propval_bytes(FILE *f, struct data val)
{
void *propend = val.val + val.len;
char *bp = val.val;
+ struct fixup *l = val.labels;
fprintf(f, "[");
for (;;) {
+ while (l && (l->offset == (bp-val.val))) {
+ fprintf(f, "%s: ", l->ref);
+ l = l->next;
+ }
+
fprintf(f, "%02hhx", *bp++);
if ((void *)bp >= propend)
break;
fprintf(f, " ");
}
+
+ /* Wrap up any labels at the end of the value */
+ while (l) {
+ assert (l->offset == val.len);
+ fprintf(f, " %s:", l->ref);
+ l = l->next;
+ }
fprintf(f, "]");
}
@@ -142,7 +188,9 @@ static void write_propval(FILE *f, struct property *prop)
{
int len = prop->val.len;
char *p = prop->val.val;
+ struct fixup *l;
int nnotstring = 0, nnul = 0;
+ int nnotstringlbl = 0, nnotcelllbl = 0;
int i;
if (len == 0) {
@@ -157,15 +205,23 @@ static void write_propval(FILE *f, struct property *prop)
nnul++;
}
- fprintf(f, " = ");
+ for (l = prop->val.labels; l; l = l->next) {
+ if ((l->offset > 0) && (prop->val.val[l->offset - 1] != '\0'))
+ nnotstringlbl++;
+ if ((l->offset % sizeof(cell_t)) != 0)
+ nnotcelllbl++;
+ }
- if ((p[len-1] == '\0') && (nnotstring == 0) && (nnul < (len-nnul))) {
+ fprintf(f, " = ");
+ if ((p[len-1] == '\0') && (nnotstring == 0) && (nnul < (len-nnul))
+ && (nnotstringlbl == 0)) {
write_propval_string(f, prop->val);
- } else if (((len % sizeof(cell_t)) == 0)) {
+ } else if (((len % sizeof(cell_t)) == 0) && (nnotcelllbl == 0)) {
write_propval_cells(f, prop->val);
} else {
write_propval_bytes(f, prop->val);
}
+
fprintf(f, ";\n");
}