source: style.c @ 3ba3af0

barnowl_perlaimdebianowlrelease-1.10release-1.4release-1.5release-1.6release-1.7release-1.8release-1.9
Last change on this file since 3ba3af0 was ef56a67, checked in by James M. Kretchmar <kretch@mit.edu>, 21 years ago
added the 'show view' command. removed the style variable A style is now part of a view, the view command has been revamped
  • Property mode set to 100644
File size: 1.5 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
27char *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 */
35void 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
57void 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}
Note: See TracBrowser for help on using the repository browser.