From 9c83a8376f7db19421fb42d311fba81b398c67b0 Mon Sep 17 00:00:00 2001 From: Behdad Esfahbod Date: Wed, 11 Feb 2009 23:44:36 -0500 Subject: [PATCH] [fcformat] Support indexing simple tags The format '%{family[0]}' will only output the first value for element family. --- src/fcformat.c | 43 +++++++++++++++++++++++++++++++++++++++---- src/fcint.h | 5 +++++ src/fcname.c | 2 +- 3 files changed, 45 insertions(+), 5 deletions(-) diff --git a/src/fcformat.c b/src/fcformat.c index 334eee6..898ee32 100644 --- a/src/fcformat.c +++ b/src/fcformat.c @@ -39,9 +39,8 @@ */ -/* fc-match needs '', etc handling, as well as printing - * printing first value only. */ -#define FCMATCH_FORMAT "%{file|basename}: \"%{family}\" \"%{style}\"" +/* fc-match needs '', etc handling. */ +#define FCMATCH_FORMAT "%{file|basename}: \"%{family[0]}\" \"%{style[0]}\"" #define FCLIST_FORMAT "%{?file{%{file}: }}%{=unparse}" @@ -543,6 +542,7 @@ interpret_simple (FcFormatContext *c, FcPatternElt *e; FcBool add_colon = FcFalse; FcBool add_elt_name = FcFalse; + int idx; if (consume_char (c, ':')) add_colon = FcTrue; @@ -550,6 +550,19 @@ interpret_simple (FcFormatContext *c, if (!read_word (c)) return FcFalse; + idx = -1; + if (consume_char (c, '[')) + { + idx = strtol ((const char *) c->format, (char **) &c->format, 10); + if (idx < 0) + { + message ("expected non-negative number at %d", + c->format-1 - c->format_orig + 1); + return FcFalse; + } + expect_char (c, ']'); + } + if (consume_char (c, '=')) add_elt_name = FcTrue; @@ -568,7 +581,29 @@ interpret_simple (FcFormatContext *c, } l = FcPatternEltValues(e); - FcNameUnparseValueList (buf, l, '\0'); + + if (idx != -1) + { + while (l && idx > 0) + { + l = FcValueListNext(l); + idx--; + } + if (l && idx == 0) + { + if (!FcNameUnparseValue (buf, &l->value, '\0')) + return FcFalse; + } + else goto notfound; + } + else + { + FcNameUnparseValueList (buf, l, '\0'); + } + } + else +notfound: + { } return FcTrue; diff --git a/src/fcint.h b/src/fcint.h index 0b41d59..b667e54 100644 --- a/src/fcint.h +++ b/src/fcint.h @@ -645,6 +645,11 @@ FcNameUnparseCharSet (FcStrBuf *buf, const FcCharSet *c); FcPrivate FcCharSet * FcNameParseCharSet (FcChar8 *string); +FcPrivate FcBool +FcNameUnparseValue (FcStrBuf *buf, + FcValue *v0, + FcChar8 *escape); + FcPrivate FcBool FcNameUnparseValueList (FcStrBuf *buf, FcValueListPtr v, diff --git a/src/fcname.c b/src/fcname.c index 02a2b82..dd05bc3 100644 --- a/src/fcname.c +++ b/src/fcname.c @@ -783,7 +783,7 @@ FcNameUnparseString (FcStrBuf *buf, return FcTrue; } -static FcBool +FcBool FcNameUnparseValue (FcStrBuf *buf, FcValue *v0, FcChar8 *escape) -- 2.39.2