2012-03-18 18:24:12 +02:00
|
|
|
/*
|
|
|
|
* param.h - Parameters and values
|
|
|
|
*
|
|
|
|
* 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.
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
|
|
#ifndef PARAM_H
|
|
|
|
#define PARAM_H
|
|
|
|
|
2012-04-25 23:14:39 +03:00
|
|
|
#include <stdio.h>
|
|
|
|
|
2012-03-18 18:24:12 +02:00
|
|
|
#include "bitset.h"
|
2012-05-21 05:04:41 +03:00
|
|
|
#include "relop.h"
|
2012-03-18 18:24:12 +02:00
|
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Parameter types:
|
|
|
|
*
|
|
|
|
* "name" arbitrary name
|
|
|
|
* "set" names from an ordered list
|
|
|
|
* "abs" absolute numeric value
|
|
|
|
* "rel" numeric value relative to another parameter
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
|
|
struct equiv {
|
|
|
|
const char *name;
|
|
|
|
struct equiv *next;
|
|
|
|
};
|
|
|
|
|
|
|
|
struct names {
|
|
|
|
struct equiv *equiv; /* equivalent value(s) */
|
|
|
|
struct names *next; /* next/greater value */
|
|
|
|
};
|
|
|
|
|
|
|
|
struct param_ops;
|
|
|
|
|
|
|
|
struct format {
|
|
|
|
const struct param_ops *ops;
|
|
|
|
union {
|
|
|
|
const struct names *set;
|
2012-06-01 06:20:31 +03:00
|
|
|
const char *abs; /* unit name; NULL if dimensionless */
|
2012-03-18 18:24:12 +02:00
|
|
|
const struct format *rel;
|
|
|
|
} u;
|
|
|
|
};
|
|
|
|
|
|
|
|
struct value {
|
|
|
|
union {
|
2012-05-21 20:44:33 +03:00
|
|
|
const char *s;
|
2012-03-18 18:24:12 +02:00
|
|
|
struct bitset set;
|
|
|
|
double abs;
|
|
|
|
struct rel_value {
|
2012-04-29 05:24:25 +03:00
|
|
|
double plus, minus; /* rel: 100% = 1 */
|
2012-03-18 18:24:12 +02:00
|
|
|
int fract; /* 0: abs. offset; 1: fract. offs. */
|
|
|
|
} rel;
|
|
|
|
} u;
|
|
|
|
};
|
|
|
|
|
2012-05-22 01:19:04 +03:00
|
|
|
/*
|
|
|
|
* When using "struct param" to store (string) variables not associated to a
|
|
|
|
* field, then u.name contains the variable name, "op" contains the relational
|
|
|
|
* operator (default rel_eq), and value.u.s contains the variable's value.
|
2012-05-22 19:01:39 +03:00
|
|
|
*
|
|
|
|
* If the variable is "$", then u.name is set to NULL.
|
2012-05-22 01:19:04 +03:00
|
|
|
*/
|
|
|
|
|
2012-04-28 17:46:42 +03:00
|
|
|
struct param {
|
|
|
|
union {
|
|
|
|
const char *name;
|
|
|
|
const struct field *field;
|
|
|
|
} u;
|
2012-05-22 01:19:04 +03:00
|
|
|
enum relop op;
|
2012-04-28 17:46:42 +03:00
|
|
|
struct value value;
|
|
|
|
struct param *next;
|
|
|
|
};
|
|
|
|
|
2012-03-18 18:24:12 +02:00
|
|
|
struct param_ops {
|
|
|
|
int (*eval)(const struct format *fmt, const char *s,
|
|
|
|
struct value *res);
|
|
|
|
int (*comp)(const struct value *a, enum relop relop,
|
|
|
|
const struct value *b);
|
2012-04-25 23:14:39 +03:00
|
|
|
void (*dump)(FILE *file, const struct format *fmt,
|
|
|
|
const struct value *v);
|
2012-03-18 18:24:12 +02:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
void register_nameset(const char *name, const struct names *set);
|
|
|
|
const struct names *find_nameset(const char *name);
|
2012-04-25 23:14:39 +03:00
|
|
|
const char *nameset_rev_lookup(const struct names *first_name);
|
2012-03-18 18:24:12 +02:00
|
|
|
|
|
|
|
int eval_name(const struct format *fmt, const char *s, struct value *res);
|
|
|
|
int eval_set(const struct format *fmt, const char *s, struct value *res);
|
|
|
|
int eval_abs(const struct format *fmt, const char *s, struct value *res);
|
|
|
|
int eval_rel(const struct format *fmt, const char *s, struct value *res);
|
|
|
|
int evaluate(const struct format *fmt, const char *s, struct value *res);
|
|
|
|
|
|
|
|
int comp_name(const struct value *a, enum relop relop, const struct value *b);
|
|
|
|
int comp_set(const struct value *a, enum relop relop, const struct value *b);
|
|
|
|
int comp_abs(const struct value *a, enum relop relop, const struct value *b);
|
|
|
|
int comp_rel(const struct value *a, enum relop relop, const struct value *b);
|
|
|
|
int compare(const struct format *fmt,
|
|
|
|
const struct value *a, enum relop relop, const struct value *b);
|
|
|
|
|
2012-04-25 23:14:39 +03:00
|
|
|
void dump_name(FILE *file, const struct format *fmt, const struct value *v);
|
|
|
|
void dump_set(FILE *file, const struct format *fmt, const struct value *v);
|
|
|
|
void dump_abs(FILE *file, const struct format *fmt, const struct value *v);
|
|
|
|
void dump_rel(FILE *file, const struct format *fmt, const struct value *v);
|
2012-06-02 11:18:14 +03:00
|
|
|
void dump_param(FILE *file, const struct format *fmt, const struct value *v);
|
2012-04-25 23:14:39 +03:00
|
|
|
|
2012-03-18 18:24:12 +02:00
|
|
|
extern const struct param_ops param_ops_name;
|
|
|
|
extern const struct param_ops param_ops_set;
|
|
|
|
extern const struct param_ops param_ops_abs;
|
|
|
|
extern const struct param_ops param_ops_rel;
|
|
|
|
|
2012-05-22 01:46:42 +03:00
|
|
|
struct param *make_var(const char *name, enum relop op, const char *val);
|
|
|
|
const char *var_lookup(const struct param *vars, const char *name);
|
2012-05-24 06:05:21 +03:00
|
|
|
struct param *merge_vars(const struct param *a, const struct param *b);
|
2012-05-22 01:46:42 +03:00
|
|
|
void free_vars(struct param *vars);
|
|
|
|
|
2012-03-18 18:24:12 +02:00
|
|
|
#endif /* !PARAM_H */
|