mirror of
git://projects.qi-hardware.com/eda-tools.git
synced 2024-12-23 21:21:12 +02:00
96 lines
2.0 KiB
C
96 lines
2.0 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>
|
|
|
|
#include "relop.h"
|
|
|
|
|
|
#define NMATCH 10 /* $0 (not used), $1...$9 */
|
|
|
|
|
|
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, /* try to match a variable */
|
|
st_assign, /* assign to a variable */
|
|
st_end, /* end the substitutions, accepting the part */
|
|
st_ignore, /* ignore the part */
|
|
st_break, /* jump to an outer block */
|
|
st_continue, /* repeat an outer block */
|
|
st_print, /* print a variable, for debugging */
|
|
};
|
|
|
|
struct subst {
|
|
enum subst_type type;
|
|
union {
|
|
struct {
|
|
const char *src;
|
|
regex_t re;
|
|
struct subst *block;
|
|
char units[NMATCH-1];
|
|
} match;
|
|
struct {
|
|
const char *dst;
|
|
enum relop op;
|
|
struct chunk *pat;
|
|
} assign;
|
|
const char *print;
|
|
const struct subst *jump;
|
|
const char *tmp; /* jump target name; for subst_finalize */
|
|
} u;
|
|
const struct subst *prev; /* for tracking availability of variables */
|
|
struct subst *next;
|
|
};
|
|
|
|
|
|
#define MULT_CHARS "GMkmunpf"
|
|
|
|
|
|
extern const char *fn;
|
|
|
|
|
|
struct subst *subst_match(const char *src, const char *re, char **res);
|
|
struct subst *subst_assign(const char *dst, enum relop op, const char *pat);
|
|
struct subst *subst_print(const char *var);
|
|
struct subst *subst_end(void);
|
|
struct subst *subst_ignore(void);
|
|
struct subst *subst_break(const char *block);
|
|
struct subst *subst_continue(const char *block);
|
|
|
|
void subst_finalize(struct subst *sub);
|
|
|
|
void subst_dump(FILE *file, const struct subst *sub);
|
|
|
|
void subst_init(void);
|
|
|
|
#endif /* !SUBST_H */
|