8 /* mapping filetypes to regular expression sets */
14 static struct rset
*syn_ftrs
;
17 static struct rset
*syn_find(char *ft
)
20 for (i
= 0; i
< LEN(ftmap
); i
++)
21 if (!strcmp(ft
, ftmap
[i
].ft
))
26 static struct rset
*syn_make(char *name
)
28 char *pats
[256] = {NULL
};
32 if (name
== NULL
|| !name
[0])
34 for (i
= 0; !conf_highlight(i
, &ft
, NULL
, &pat
, NULL
) && i
< LEN(pats
); i
++)
35 if (!strcmp(ft
, name
))
38 for (i
= 0; i
< LEN(ftmap
); i
++) {
39 if (!ftmap
[i
].ft
[0]) {
40 strcpy(ftmap
[i
].ft
, name
);
41 ftmap
[i
].rs
= rset_make(n
, pats
, 0);
48 int syn_merge(int old
, int new)
50 int fg
= SYN_FGSET(new) ? SYN_FG(new) : SYN_FG(old
);
51 int bg
= SYN_BGSET(new) ? SYN_BG(new) : SYN_BG(old
);
52 return ((old
| new) & SYN_FLG
) | (bg
<< 8) | fg
;
55 void syn_context(int att
)
60 int *syn_highlight(char *ft
, char *s
)
64 int *att
= malloc(n
* sizeof(att
[0]));
66 struct rset
*rs
= syn_find(ft
);
69 memset(att
, 0, n
* sizeof(att
[0]));
70 if (!strcmp(ft
, "___")) {
71 for (i
= 0; i
< n
; i
++)
79 while ((hl
= rset_find(rs
, s
+ sidx
, LEN(subs
) / 2, subs
, flg
)) >= 0) {
83 conf_highlight(hl
, NULL
, &catt
, NULL
, &grp
);
84 for (i
= 0; i
< LEN(subs
) / 2; i
++) {
85 if (subs
[i
* 2] >= 0) {
86 int beg
= uc_off(s
, sidx
+ subs
[i
* 2 + 0]);
87 int end
= uc_off(s
, sidx
+ subs
[i
* 2 + 1]);
88 for (j
= beg
; j
< end
; j
++)
89 att
[j
] = syn_merge(att
[j
], catt
[i
]);
91 cend
= MAX(cend
, subs
[i
* 2 + 1]);
97 for (i
= 0; i
< n
; i
++)
98 att
[i
] = syn_merge(att
[i
], syn_ctx
);
102 char *syn_filetype(char *path
)
104 int hl
= rset_find(syn_ftrs
, path
, 0, NULL
, 0);
106 if (!conf_filetype(hl
, &ft
, NULL
))
113 char *pats
[128] = {NULL
};
116 for (i
= 0; !conf_filetype(i
, NULL
, &pat
) && i
< LEN(pats
); i
++)
118 syn_ftrs
= rset_make(i
, pats
, 0);
124 for (i
= 0; i
< LEN(ftmap
); i
++)
126 rset_free(ftmap
[i
].rs
);