source: style.c @ 5ea6fea

barnowl_perlaimdebianowlrelease-1.10release-1.4release-1.5release-1.6release-1.7release-1.8release-1.9
Last change on this file since 5ea6fea was bd3f232, checked in by James M. Kretchmar <kretch@mit.edu>, 21 years ago
Styles implemented It's still a little buggy ... if a format_msg(); is used in perl admin messages (or maybe just the first admin message) are not formatted.
  • Property mode set to 100644
File size: 1.4 KB
Line 
1#include "owl.h"
2
3static const char fileIdent[] = "$Id$";
4
5void 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
13void 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
21int owl_style_matches_name(owl_style *s, char *name)
22{
23  if (!strcmp(s->name, name)) return(1);
24  return(0);
25}
26
27void owl_style_get_formattext(owl_style *s, owl_fmtext *fm, owl_message *m)
28{
29  if (s->type==OWL_STYLE_TYPE_INTERNAL) {
30    (* s->formatfunc)(fm, m);
31  } else if (s->type==OWL_STYLE_TYPE_PERL) {
32    char *body, *indent;
33
34    /* run the perl function */
35    body=owl_config_getmsg(m, s->perlfuncname);
36   
37    /* indent */
38    indent=owl_malloc(strlen(body)+owl_text_num_lines(body)*OWL_TAB+10);
39    owl_text_indent(indent, body, OWL_TAB);
40   
41    /* fmtext_append.  This needs to change */
42    owl_fmtext_append_ztext(fm, indent);
43   
44    owl_free(indent);
45    owl_free(body);
46  }
47}
48
49char *owl_style_get_name(owl_style *s)
50{
51  return(s->name);
52}
53
54void owl_style_free(owl_style *s)
55{
56  if (s->name) owl_free(s->name);
57  if (s->type==OWL_STYLE_TYPE_PERL && s->perlfuncname) {
58    owl_free(s->perlfuncname);
59  }
60}
Note: See TracBrowser for help on using the repository browser.