1 | #include "owl.h" |
---|
2 | |
---|
3 | static const char fileIdent[] = "$Id$"; |
---|
4 | |
---|
5 | void owl_style_create_internal(owl_style *s, char *name, void (*formatfunc) (owl_fmtext *fm, owl_message *m)) |
---|
6 | { |
---|
7 | s->type=OWL_STYLE_TYPE_INTERNAL; |
---|
8 | s->name=owl_strdup(name); |
---|
9 | s->perlfuncname=NULL; |
---|
10 | s->formatfunc=formatfunc; |
---|
11 | } |
---|
12 | |
---|
13 | void owl_style_create_perl(owl_style *s, char *name, char *perlfuncname) |
---|
14 | { |
---|
15 | s->type=OWL_STYLE_TYPE_PERL; |
---|
16 | s->name=owl_strdup(name); |
---|
17 | s->perlfuncname=owl_strdup(perlfuncname); |
---|
18 | s->formatfunc=NULL; |
---|
19 | } |
---|
20 | |
---|
21 | int owl_style_matches_name(owl_style *s, char *name) |
---|
22 | { |
---|
23 | if (!strcmp(s->name, name)) return(1); |
---|
24 | return(0); |
---|
25 | } |
---|
26 | |
---|
27 | char *owl_style_get_name(owl_style *s) |
---|
28 | { |
---|
29 | return(s->name); |
---|
30 | } |
---|
31 | |
---|
32 | /* Use style 's' to format message 'm' into fmtext 'fm'. |
---|
33 | * 'fm' should already be be initialzed |
---|
34 | */ |
---|
35 | void owl_style_get_formattext(owl_style *s, owl_fmtext *fm, owl_message *m) |
---|
36 | { |
---|
37 | if (s->type==OWL_STYLE_TYPE_INTERNAL) { |
---|
38 | (* s->formatfunc)(fm, m); |
---|
39 | } else if (s->type==OWL_STYLE_TYPE_PERL) { |
---|
40 | char *body, *indent; |
---|
41 | |
---|
42 | /* run the perl function */ |
---|
43 | body=owl_config_getmsg(m, s->perlfuncname); |
---|
44 | |
---|
45 | /* indent */ |
---|
46 | indent=owl_malloc(strlen(body)+owl_text_num_lines(body)*OWL_TAB+10); |
---|
47 | owl_text_indent(indent, body, OWL_TAB); |
---|
48 | |
---|
49 | /* fmtext_append. This needs to change */ |
---|
50 | owl_fmtext_append_ztext(fm, indent); |
---|
51 | |
---|
52 | owl_free(indent); |
---|
53 | owl_free(body); |
---|
54 | } |
---|
55 | } |
---|
56 | |
---|
57 | void owl_style_free(owl_style *s) |
---|
58 | { |
---|
59 | if (s->name) owl_free(s->name); |
---|
60 | if (s->type==OWL_STYLE_TYPE_PERL && s->perlfuncname) { |
---|
61 | owl_free(s->perlfuncname); |
---|
62 | } |
---|
63 | } |
---|