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 int syn_merge(int old
, int new)
28 int fg
= SYN_FGSET(new) ? SYN_FG(new) : SYN_FG(old
);
29 int bg
= SYN_BGSET(new) ? SYN_BG(new) : SYN_BG(old
);
30 return ((old
| new) & SYN_FLG
) | (bg
<< 8) | fg
;
33 void syn_context(int att
)
38 int *syn_highlight(char *ft
, char *s
)
42 int *att
= malloc(n
* sizeof(att
[0]));
44 struct rset
*rs
= syn_find(ft
);
47 memset(att
, 0, n
* sizeof(att
[0]));
50 for (i
= 0; i
< n
; i
++)
52 while ((hl
= rset_find(rs
, s
+ sidx
, LEN(subs
) / 2, subs
, flg
)) >= 0) {
56 conf_highlight(hl
, NULL
, &catt
, NULL
, &grp
);
57 for (i
= 0; i
< LEN(subs
) / 2; i
++) {
58 if (subs
[i
* 2] >= 0) {
59 int beg
= uc_off(s
, sidx
+ subs
[i
* 2 + 0]);
60 int end
= uc_off(s
, sidx
+ subs
[i
* 2 + 1]);
61 for (j
= beg
; j
< end
; j
++)
62 att
[j
] = syn_merge(att
[j
], catt
[i
]);
64 cend
= MAX(cend
, subs
[i
* 2 + 1]);
73 static void syn_initft(char *name
)
75 char *pats
[128] = {NULL
};
78 for (i
= 0; !conf_highlight(i
, &ft
, NULL
, &pat
, NULL
) && i
< LEN(pats
); i
++)
79 if (!strcmp(ft
, name
))
82 for (i
= 0; i
< LEN(ftmap
); i
++) {
83 if (!ftmap
[i
].ft
[0]) {
84 strcpy(ftmap
[i
].ft
, name
);
85 ftmap
[i
].rs
= rset_make(n
, pats
, 0);
91 char *syn_filetype(char *path
)
93 int hl
= rset_find(syn_ftrs
, path
, 0, NULL
, 0);
95 if (!conf_filetype(hl
, &ft
, NULL
))
102 char *pats
[128] = {NULL
};
105 for (i
= 0; !conf_highlight(i
, &ft
, NULL
, NULL
, NULL
); i
++)
108 for (i
= 0; !conf_filetype(i
, NULL
, &pat
) && i
< LEN(pats
); i
++)
110 syn_ftrs
= rset_make(i
, pats
, 0);
116 for (i
= 0; i
< LEN(ftmap
); i
++)
118 rset_free(ftmap
[i
].rs
);