source: style.c @ 6dc2d6b

release-1.10release-1.4release-1.5release-1.6release-1.7release-1.8release-1.9
Last change on this file since 6dc2d6b 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
RevLine 
[864ed35]1#define OWL_PERL
[bd3f232]2#include "owl.h"
3
[864ed35]4void owl_style_create_perl(owl_style *s, char *name, SV *obj)
[bd3f232]5{
6  s->name=owl_strdup(name);
[864ed35]7  s->perlobj = SvREFCNT_inc(obj);
[bd3f232]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
[ef56a67]16char *owl_style_get_name(owl_style *s)
17{
18  return(s->name);
19}
20
[f1e629d]21char *owl_style_get_description(owl_style *s)
22{
[864ed35]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  }
[f1e629d]36}
37
[5639bf2]38/* Use style 's' to format message 'm' into fmtext 'fm'.
39 * 'fm' should already be be initialzed
40 */
[bd3f232]41void owl_style_get_formattext(owl_style *s, owl_fmtext *fm, owl_message *m)
42{
[864ed35]43  char *body, *indent;
44  int curlen;
[bd3f232]45
[864ed35]46  SV *sv = NULL;
47 
48  /* Call the perl object */
49  OWL_PERL_CALL_METHOD(s->perlobj,
50                       "format_message",
[1639ff7]51                       XPUSHs(sv_2mortal(owl_perlconfig_message2hashref(m)));,
[864ed35]52                       "Error in format_message: %s",
53                       0,
54                       sv = SvREFCNT_inc(POPs);
55                       );
[282ec9b]56
[864ed35]57  if(sv) {
58    body = SvPV_nolen(sv);
59  } else {
60    body = "<unformatted message>";
[bd3f232]61  }
[864ed35]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)
[e574a00]77    SvREFCNT_dec(sv);
[bd3f232]78}
79
[f1e629d]80int owl_style_validate(owl_style *s) {
[864ed35]81  if (!s || !s->perlobj || !SvOK(s->perlobj)) {
[f1e629d]82    return -1;
83  }
[864ed35]84  return 0;
[f1e629d]85}
86
[bd3f232]87void owl_style_free(owl_style *s)
88{
89  if (s->name) owl_free(s->name);
[864ed35]90  SvREFCNT_dec(s->perlobj);
[bd3f232]91}
Note: See TracBrowser for help on using the repository browser.