source: style.c @ 747d6a5

release-1.10release-1.4release-1.5release-1.6release-1.7release-1.8release-1.9
Last change on this file since 747d6a5 was d43edd2, checked in by Anders Kaseorg <andersk@mit.edu>, 15 years ago
Death to RCS keywords. Signed-off-by: Anders Kaseorg <andersk@mit.edu>
  • Property mode set to 100644
File size: 2.1 KB
Line 
1#define OWL_PERL
2#include "owl.h"
3
4void owl_style_create_perl(owl_style *s, char *name, SV *obj)
5{
6  s->name=owl_strdup(name);
7  s->perlobj = SvREFCNT_inc(obj);
8}
9
10int owl_style_matches_name(owl_style *s, char *name)
11{
12  if (!strcmp(s->name, name)) return(1);
13  return(0);
14}
15
16char *owl_style_get_name(owl_style *s)
17{
18  return(s->name);
19}
20
21char *owl_style_get_description(owl_style *s)
22{
23  SV *sv = NULL;
24  OWL_PERL_CALL_METHOD(s->perlobj,
25                       "description",
26                       /* no args */,
27                       "Error in style_get_description: %s",
28                       0,
29                       sv = SvREFCNT_inc(POPs);
30                       );
31  if(sv) {
32    return SvPV_nolen(sv_2mortal(sv));
33  } else {
34    return "[error getting description]";
35  }
36}
37
38/* Use style 's' to format message 'm' into fmtext 'fm'.
39 * 'fm' should already be be initialzed
40 */
41void owl_style_get_formattext(owl_style *s, owl_fmtext *fm, owl_message *m)
42{
43  char *body, *indent;
44  int curlen;
45
46  SV *sv = NULL;
47 
48  /* Call the perl object */
49  OWL_PERL_CALL_METHOD(s->perlobj,
50                       "format_message",
51                       XPUSHs(sv_2mortal(owl_perlconfig_message2hashref(m)));,
52                       "Error in format_message: %s",
53                       0,
54                       sv = SvREFCNT_inc(POPs);
55                       );
56
57  if(sv) {
58    body = SvPV_nolen(sv);
59  } else {
60    body = "<unformatted message>";
61  }
62
63  /* indent and ensure ends with a newline */
64  indent=owl_malloc(strlen(body)+(owl_text_num_lines(body))*OWL_TAB+10);
65  owl_text_indent(indent, body, OWL_TAB);
66  curlen = strlen(indent);
67  if (curlen==0 || indent[curlen-1] != '\n') {
68    indent[curlen] = '\n';
69    indent[curlen+1] = '\0';
70  }
71
72  /* fmtext_append.  This needs to change */
73  owl_fmtext_append_ztext(fm, indent);
74
75  owl_free(indent);
76  if(sv)
77    SvREFCNT_dec(sv);
78}
79
80int owl_style_validate(owl_style *s) {
81  if (!s || !s->perlobj || !SvOK(s->perlobj)) {
82    return -1;
83  }
84  return 0;
85}
86
87void owl_style_free(owl_style *s)
88{
89  if (s->name) owl_free(s->name);
90  SvREFCNT_dec(s->perlobj);
91}
Note: See TracBrowser for help on using the repository browser.