1
0
mirror of git://projects.qi-hardware.com/eda-tools.git synced 2024-11-26 15:12:28 +02:00
eda-tools/b2/subst.h
2012-05-20 20:33:14 -03:00

76 lines
1.4 KiB
C

/*
* subst.h - Substitution rules
*
* 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 SUBST_H
#define SUBST_H
#include <stdio.h>
#include <sys/types.h>
#include <regex.h>
enum chunk_type {
ct_string,
ct_var,
ct_sub,
};
struct chunk {
enum chunk_type type;
union {
const char *s;
const char *var;
int sub; /* 0 if $$ */
} u;
const char *unit; /* NULL if no conversion specified */
struct chunk *next;
};
enum subst_type {
st_match,
st_assign,
st_end,
st_break,
st_again,
};
struct subst {
enum subst_type type;
union {
struct {
const char *src;
regex_t re;
struct subst *block;
} match;
struct {
const char *dst;
struct chunk *pat;
} assign;
const struct subst *jump;
const char *tmp; /* jump target name; for subst_finalize */
} u;
struct subst *next;
};
struct subst *subst_match(const char *src, const char *re);
struct subst *subst_assign(const char *dst, const char *pat);
struct subst *subst_end(void);
struct subst *subst_break(const char *block);
struct subst *subst_again(const char *block);
void subst_finalize(struct subst *sub);
void subst_dump(FILE *file, const struct subst *sub);
#endif /* !SUBST_H */