1
0
mirror of git://projects.qi-hardware.com/eda-tools.git synced 2024-06-28 21:45:27 +03:00
eda-tools/b2/dump.c
2012-06-02 05:18:14 -03:00

66 lines
1.4 KiB
C

/*
* dump.c - Dump a value (for debugging)
*
* Copyright 2012 by Werner Almesberger
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*/
#include <stdio.h>
#include "bitset.h"
#include "param.h"
void dump_name(FILE *file, const struct format *fmt, const struct value *v)
{
(void) fmt;
fprintf(file, "%s", v->u.s);
}
void dump_set(FILE *file, const struct format *fmt, const struct value *v)
{
const struct names *name;
int first = 1;
int i;
i = 0;
for (name = fmt->u.set; name; name = name->next) {
if (bitset_get(&v->u.set, i)) {
fprintf(file, "%s%s", first ? "" : "|",
name->equiv->name);
first = 0;
}
i++;
}
}
void dump_abs(FILE *file, const struct format *fmt, const struct value *v)
{
fprintf(file, "%g%s", v->u.abs, fmt->u.abs ? fmt->u.abs : "");
}
void dump_rel(FILE *file, const struct format *fmt, const struct value *v)
{
if (v->u.rel.fract)
fprintf(file, "-%g/+%g%%",
v->u.rel.minus*100, v->u.rel.plus*100);
else
fprintf(file, "-%g/+%g%s",
v->u.rel.minus, v->u.rel.plus,
fmt->u.rel->u.abs ? fmt->u.rel->u.abs : "");
}
void dump_param(FILE *file, const struct format *fmt, const struct value *v)
{
fmt->ops->dump(file, fmt, v);
}