2012-05-20 17:18:18 +03:00
|
|
|
/*
|
|
|
|
* 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>
|
|
|
|
|
2012-05-21 05:16:51 +03:00
|
|
|
#include "relop.h"
|
|
|
|
|
2012-05-20 17:18:18 +03:00
|
|
|
|
|
|
|
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;
|
2012-05-21 03:55:54 +03:00
|
|
|
char units[10];
|
2012-05-21 06:20:07 +03:00
|
|
|
int parens; /* number of parentheses */
|
2012-05-20 17:18:18 +03:00
|
|
|
} match;
|
|
|
|
struct {
|
|
|
|
const char *dst;
|
2012-05-21 05:16:51 +03:00
|
|
|
enum relop op;
|
2012-05-20 17:18:18 +03:00
|
|
|
struct chunk *pat;
|
|
|
|
} assign;
|
|
|
|
const struct subst *jump;
|
|
|
|
const char *tmp; /* jump target name; for subst_finalize */
|
|
|
|
} u;
|
2012-05-21 06:20:07 +03:00
|
|
|
const struct subst *prev; /* for tracking availability of variables */
|
2012-05-20 17:18:18 +03:00
|
|
|
struct subst *next;
|
|
|
|
};
|
|
|
|
|
|
|
|
|
2012-05-21 03:55:54 +03:00
|
|
|
#define MULT_CHARS "GMkmunpf"
|
|
|
|
|
|
|
|
|
2012-05-20 17:18:18 +03:00
|
|
|
struct subst *subst_match(const char *src, const char *re);
|
2012-05-21 05:16:51 +03:00
|
|
|
struct subst *subst_assign(const char *dst, enum relop op, const char *pat);
|
2012-05-20 17:18:18 +03:00
|
|
|
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 */
|