source: style.c @ c08a725

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