1
0
mirror of git://projects.qi-hardware.com/eda-tools.git synced 2024-07-03 00:32:00 +03:00
eda-tools/b2/subst.h

82 lines
1.5 KiB
C
Raw Normal View History

/*
* 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>
#include "relop.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;
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;
char units[10];
} match;
struct {
const char *dst;
enum relop op;
struct chunk *pat;
} assign;
const struct subst *jump;
const char *tmp; /* jump target name; for subst_finalize */
} u;
struct subst *next;
};
#define MULT_CHARS "GMkmunpf"
struct subst *subst_match(const char *src, const char *re);
struct subst *subst_assign(const char *dst, enum relop op, 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 */