mirror of
git://git.code.sf.net/p/zsh/code
synced 2024-05-31 20:36:03 +02:00
unposted: zstyle: Add a unit test and some comments.
This commit is contained in:
parent
4bb8c937d8
commit
2acbae3bad
|
@ -1,5 +1,8 @@
|
|||
2019-12-01 Daniel Shahaf <danielsh@apache.org>
|
||||
|
||||
* unposted: Src/Modules/zutil.c, Test/V05styles.ztst: zstyle:
|
||||
Add a unit test and some comments.
|
||||
|
||||
* unposted: Completion/Unix/Command/_sqlite: Fix syntax error
|
||||
|
||||
2019-11-30 Daniel Shahaf <d.s@daniel.shahaf.name>
|
||||
|
|
|
@ -88,7 +88,8 @@ typedef struct style *Style;
|
|||
|
||||
struct style {
|
||||
struct hashnode node;
|
||||
Stypat pats; /* patterns */
|
||||
Stypat pats; /* patterns, sorted by weight descending, then
|
||||
by order of definition, newest first. */
|
||||
};
|
||||
|
||||
struct stypat {
|
||||
|
@ -337,7 +338,19 @@ setstypat(Style s, char *pat, Patprog prog, char **vals, int eval)
|
|||
p->eval = eprog;
|
||||
p->next = NULL;
|
||||
|
||||
/* Calculate the weight. */
|
||||
/* Calculate the weight.
|
||||
*
|
||||
* The weight of a pattern is scored as follows:
|
||||
*
|
||||
* - The pattern is split to colon-separated components.
|
||||
* - A component equal to '*' (with nothing else) scores 0 points.
|
||||
* - A component that's a pattern, otherwise, scores 1 point.
|
||||
* - A component that's a literal string scores 2 points.
|
||||
* - The score of a pattern is the sum of the score of its components.
|
||||
*
|
||||
* This corresponds to the notion of 'more specific' in the zshmodules(1)
|
||||
* documentation of zstyle.
|
||||
*/
|
||||
|
||||
for (weight = 0, tmp = 2, first = 1, str = pat; *str; str++) {
|
||||
if (first && *str == '*' && (!str[1] || str[1] == ':')) {
|
||||
|
@ -362,9 +375,9 @@ setstypat(Style s, char *pat, Patprog prog, char **vals, int eval)
|
|||
}
|
||||
p->weight = (weight += tmp);
|
||||
|
||||
/* Insert 'q' to 's->pats', using 'qq' as a temporary. */
|
||||
for (qq = NULL, q = s->pats; q && q->weight >= weight;
|
||||
qq = q, q = q->next);
|
||||
|
||||
p->next = q;
|
||||
if (qq)
|
||||
qq->next = p;
|
||||
|
|
|
@ -141,3 +141,13 @@
|
|||
>scalar-style
|
||||
> :ztst:context:* second-scalar-value
|
||||
|
||||
(zstyle 'ctx?' foo one
|
||||
zstyle 'ctx*' foo two
|
||||
zstyle -s 'ctx1' foo bar && print $bar)
|
||||
(zstyle 'ctx*' foo two
|
||||
zstyle 'ctx?' foo one
|
||||
zstyle -s 'ctx1' foo bar && print $bar)
|
||||
0:patterns of equal weight are used in order of definition
|
||||
>one
|
||||
>two
|
||||
|
||||
|
|
Loading…
Reference in New Issue