source: style.c @ fb2f9ab

release-1.10release-1.4release-1.5release-1.6release-1.7release-1.8release-1.9
Last change on this file since fb2f9ab was 1fdab04, checked in by Anders Kaseorg <andersk@mit.edu>, 15 years ago
Add const qualifiers for owl_style *. 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, const char *name, SV *obj)
5{
6  s->name=owl_strdup(name);
7  s->perlobj = SvREFCNT_inc(obj);
8}
9
10int owl_style_matches_name(const owl_style *s, const char *name)
11{
12  if (!strcmp(s->name, name)) return(1);
13  return(0);
14}
15
16const char *owl_style_get_name(const owl_style *s)
17{
18  return(s->name);
19}
20
21const char *owl_style_get_description(const 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(const owl_style *s, owl_fmtext *fm, const owl_message *m)
42{
43  const char *body;
44  char *indent;
45  int curlen;
46
47  SV *sv = NULL;
48 
49  /* Call the perl object */
50  OWL_PERL_CALL_METHOD(s->perlobj,
51                       "format_message",
52                       XPUSHs(sv_2mortal(owl_perlconfig_message2hashref(m)));,
53                       "Error in format_message: %s",
54                       0,
55                       sv = SvREFCNT_inc(POPs);
56                       );
57
58  if(sv) {
59    body = SvPV_nolen(sv);
60  } else {
61    body = "<unformatted message>";
62  }
63
64  /* indent and ensure ends with a newline */
65  indent=owl_malloc(strlen(body)+(owl_text_num_lines(body))*OWL_TAB+10);
66  owl_text_indent(indent, body, OWL_TAB);
67  curlen = strlen(indent);
68  if (curlen==0 || indent[curlen-1] != '\n') {
69    indent[curlen] = '\n';
70    indent[curlen+1] = '\0';
71  }
72
73  /* fmtext_append.  This needs to change */
74  owl_fmtext_append_ztext(fm, indent);
75
76  owl_free(indent);
77  if(sv)
78    SvREFCNT_dec(sv);
79}
80
81int owl_style_validate(const owl_style *s) {
82  if (!s || !s->perlobj || !SvOK(s->perlobj)) {
83    return -1;
84  }
85  return 0;
86}
87
88void owl_style_free(owl_style *s)
89{
90  if (s->name) owl_free(s->name);
91  SvREFCNT_dec(s->perlobj);
92}
Note: See TracBrowser for help on using the repository browser.