From 70a8bfa98907f6e41745a81c6eea3a67872059fb Mon Sep 17 00:00:00 2001 From: Petr Baudis Date: Sat, 7 Jan 2012 20:40:52 +0100 Subject: [PATCH] str2pattern(): Introduce --- pattern.c | 18 ++++++++++++++++++ pattern.h | 2 ++ 2 files changed, 20 insertions(+) diff --git a/pattern.c b/pattern.c index 0b0d328..2e06d9d 100644 --- a/pattern.c +++ b/pattern.c @@ -495,3 +495,21 @@ pattern2str(char *str, struct pattern *p) str = stpcpy(str, ")"); return str; } + +char * +str2pattern(char *str, struct pattern *p) +{ + p->n = 0; + while (isspace(*str)) str++; + if (*str++ != '(') { + fprintf(stderr, "invalid patternspec: %s\n", str); + exit(EXIT_FAILURE); + } + + while (*str != ')') { + str = str2feature(str, &p->f[p->n++]); + } + + str++; + return str; +} diff --git a/pattern.h b/pattern.h index 2a585af..ee3cf49 100644 --- a/pattern.h +++ b/pattern.h @@ -138,6 +138,8 @@ int feature_payloads(struct pattern_config *pc, enum feature_id f); /* Append pattern as feature spec string. */ char *pattern2str(char *str, struct pattern *p); +/* Convert string to pattern, return pointer after the patternspec. */ +char *str2pattern(char *str, struct pattern *p); /* Initialize p and fill it with features matched by the * given board move. */ -- 2.11.4.GIT