8 /* mapping filetypes to regular expression sets */
14 static struct rset
*syn_ftrs
;
16 static struct rset
*syn_find(char *ft
)
19 for (i
= 0; i
< LEN(ftmap
); i
++)
20 if (!strcmp(ft
, ftmap
[i
].ft
))
25 int syn_merge(int old
, int new)
27 int fg
= SYN_FGSET(new) ? SYN_FG(new) : SYN_FG(old
);
28 int bg
= SYN_BGSET(new) ? SYN_BG(new) : SYN_BG(old
);
29 return ((old
| new) & SYN_FLG
) | (bg
<< 8) | fg
;
32 int *syn_highlight(char *ft
, char *s
)
36 int *att
= malloc(n
* sizeof(att
[0]));
38 struct rset
*rs
= syn_find(ft
);
41 memset(att
, 0, n
* sizeof(att
[0]));
44 while ((hl
= rset_find(rs
, s
+ sidx
, LEN(subs
) / 2, subs
, flg
)) >= 0) {
48 conf_highlight(hl
, NULL
, &catt
, NULL
, &grp
);
49 for (i
= 0; i
< LEN(subs
) / 2; i
++) {
50 if (subs
[i
* 2] >= 0) {
51 int beg
= uc_off(s
, sidx
+ subs
[i
* 2 + 0]);
52 int end
= uc_off(s
, sidx
+ subs
[i
* 2 + 1]);
53 for (j
= beg
; j
< end
; j
++)
54 att
[j
] = syn_merge(att
[j
], catt
[i
]);
56 cend
= MAX(cend
, subs
[i
* 2 + 1]);
65 static void syn_initft(char *name
)
67 char *pats
[128] = {NULL
};
70 for (i
= 0; !conf_highlight(i
, &ft
, NULL
, &pat
, NULL
) && i
< LEN(pats
); i
++)
71 if (!strcmp(ft
, name
))
74 for (i
= 0; i
< LEN(ftmap
); i
++) {
75 if (!ftmap
[i
].ft
[0]) {
76 strcpy(ftmap
[i
].ft
, name
);
77 ftmap
[i
].rs
= rset_make(n
, pats
, 0);
83 char *syn_filetype(char *path
)
85 int hl
= rset_find(syn_ftrs
, path
, 0, NULL
, 0);
87 if (!conf_filetype(hl
, &ft
, NULL
))
94 char *pats
[128] = {NULL
};
97 for (i
= 0; !conf_highlight(i
, &ft
, NULL
, NULL
, NULL
); i
++)
100 for (i
= 0; !conf_filetype(i
, NULL
, &pat
) && i
< LEN(pats
); i
++)
102 syn_ftrs
= rset_make(i
, pats
, 0);
108 for (i
= 0; i
< LEN(ftmap
); i
++)
110 rset_free(ftmap
[i
].rs
);