Root/
| 1 | /* |
| 2 | * dump.c - Dump a value (for debugging) |
| 3 | * |
| 4 | * Copyright 2012 by Werner Almesberger |
| 5 | * |
| 6 | * This program is free software; you can redistribute it and/or modify |
| 7 | * it under the terms of the GNU General Public License as published by |
| 8 | * the Free Software Foundation; either version 2 of the License, or |
| 9 | * (at your option) any later version. |
| 10 | */ |
| 11 | |
| 12 | |
| 13 | #include <stdio.h> |
| 14 | |
| 15 | #include "bitset.h" |
| 16 | #include "param.h" |
| 17 | |
| 18 | |
| 19 | void dump_name(FILE *file, const struct format *fmt, const struct value *v) |
| 20 | { |
| 21 | (void) fmt; |
| 22 | fprintf(file, "%s", v->u.s); |
| 23 | } |
| 24 | |
| 25 | |
| 26 | void dump_set(FILE *file, const struct format *fmt, const struct value *v) |
| 27 | { |
| 28 | const struct names *name; |
| 29 | int first = 1; |
| 30 | int i; |
| 31 | |
| 32 | i = 0; |
| 33 | for (name = fmt->u.set; name; name = name->next) { |
| 34 | if (bitset_get(&v->u.set, i)) { |
| 35 | fprintf(file, "%s%s", first ? "" : "|", |
| 36 | name->equiv->name); |
| 37 | first = 0; |
| 38 | } |
| 39 | i++; |
| 40 | } |
| 41 | } |
| 42 | |
| 43 | |
| 44 | void dump_abs(FILE *file, const struct format *fmt, const struct value *v) |
| 45 | { |
| 46 | fprintf(file, "%g%s", v->u.abs, fmt->u.abs ? fmt->u.abs : ""); |
| 47 | } |
| 48 | |
| 49 | |
| 50 | void dump_rel(FILE *file, const struct format *fmt, const struct value *v) |
| 51 | { |
| 52 | if (v->u.rel.fract) |
| 53 | fprintf(file, "-%g/+%g%%", |
| 54 | v->u.rel.minus*100, v->u.rel.plus*100); |
| 55 | else |
| 56 | fprintf(file, "-%g/+%g%s", |
| 57 | v->u.rel.minus, v->u.rel.plus, |
| 58 | fmt->u.rel->u.abs ? fmt->u.rel->u.abs : ""); |
| 59 | } |
| 60 | |
| 61 | |
| 62 | void dump_param(FILE *file, const struct format *fmt, const struct value *v) |
| 63 | { |
| 64 | fmt->ops->dump(file, fmt, v); |
| 65 | } |
| 66 |
Branches:
master
