[397] in BarnOwl Developers
[D-O-H] r534 - in trunk: . owl
daemon@ATHENA.MIT.EDU (nelhage@MIT.EDU)
Thu Oct 29 18:05:42 2009
Resent-From: nelhage@mit.edu
Resent-To: barnowl-dev-mtg@charon.mit.edu
Date: Tue, 16 Jan 2007 17:43:27 -0500
To: dirty-owl-hackers@mit.edu
From: nelhage@MIT.EDU
Reply-To: dirty-owl-hackers@MIT.EDU
Author: nelhage
Date: 2007-01-16 17:43:26 -0500 (Tue, 16 Jan 2007)
New Revision: 534
Modified:
trunk/
trunk/owl/owl.c
trunk/owl/stylefunc.c
Log:
r18012@phanatique: nelhage | 2007-01-16 17:43:23 -0500
Adding filter-based word wrapping. Still need a heuristic for when not
to wordwrap.
Property changes on: trunk
___________________________________________________________________
Name: svk:merge
- bb873fd7-8e23-0410-944a-99ec44c633eb:/branches/owl/filter-rewrite:15925
bb873fd7-8e23-0410-944a-99ec44c633eb:/local/d-o-h/trunk:18010
+ bb873fd7-8e23-0410-944a-99ec44c633eb:/branches/owl/filter-rewrite:15925
bb873fd7-8e23-0410-944a-99ec44c633eb:/local/d-o-h/trunk:18012
Modified: trunk/owl/owl.c
===================================================================
--- trunk/owl/owl.c 2007-01-16 20:57:51 UTC (rev 533)
+++ trunk/owl/owl.c 2007-01-16 22:43:26 UTC (rev 534)
@@ -249,6 +249,10 @@
owl_list_append_element(owl_global_get_filterlist(&g), f);
f=owl_malloc(sizeof(owl_filter));
+ owl_filter_init_fromstring(f, "wordwrap", "not ( type ^admin$ or type ^zephyr$ ) ");
+ owl_list_append_element(owl_global_get_filterlist(&g), f);
+
+ f=owl_malloc(sizeof(owl_filter));
owl_filter_init_fromstring(f, "trash", "class ^mail$ or opcode ^ping$ or type ^admin$ or ( not login ^none$ )");
owl_list_append_element(owl_global_get_filterlist(&g), f);
Modified: trunk/owl/stylefunc.c
===================================================================
--- trunk/owl/stylefunc.c 2007-01-16 20:57:51 UTC (rev 533)
+++ trunk/owl/stylefunc.c 2007-01-16 22:43:26 UTC (rev 534)
@@ -8,22 +8,60 @@
void owl_style_basic_format_body(owl_fmtext *fm, owl_message *m) {
char *indent, *body;
+ owl_filter *f;
+ int wrap = 0;
/* get the body */
body=owl_strdup(owl_message_get_body(m));
- body=realloc(body, strlen(body)+30);
- /* add a newline if we need to */
- if (body[0]!='\0' && body[strlen(body)-1]!='\n') {
- strcat(body, "\n");
+ f = owl_global_get_filter(&g, "wordwrap");
+ if(f && owl_filter_message_match(f, m))
+ wrap = 1;
+
+ if(wrap) {
+ int cols, i, width, word;
+ char *tab, *tok, *ws = " \t\n\r";
+ cols = owl_global_get_cols(&g) - OWL_MSGTAB - 1;
+
+ tab = owl_malloc(OWL_MSGTAB+1);
+ for(i = 0; i < OWL_MSGTAB; i++) {
+ tab[i] = ' ';
+ }
+ tab[OWL_MSGTAB] = 0;
+
+ tok = strtok(body, ws);
+ tab[OWL_MSGTAB-1] = 0;
+ owl_fmtext_append_normal(fm, tab);
+ tab[OWL_MSGTAB-1] = ' ';
+ width = 0;
+
+ while(tok) {
+ word = strlen(tok);
+ if(word + width + 1 < cols) {
+ owl_fmtext_append_normal(fm, " ");
+ owl_fmtext_append_normal(fm, tok);
+ width += word + 1;
+ } else {
+ owl_fmtext_append_normal(fm, "\n");
+ owl_fmtext_append_normal(fm, tab);
+ owl_fmtext_append_normal(fm, tok);
+ width = word;
+ }
+ tok = strtok(NULL, ws);
+ }
+ owl_fmtext_append_normal(fm, "\n");
+
+ owl_free(tab);
+ } else {
+ /* do the indenting into indent */
+ indent=owl_malloc(strlen(body)+owl_text_num_lines(body)*OWL_MSGTAB+10);
+ owl_text_indent(indent, body, OWL_MSGTAB);
+ owl_fmtext_append_ztext(fm, indent);
+ if(body[strlen(body)-1] != '\n')
+ owl_fmtext_append_ztext(fm, "\n");
+ owl_free(indent);
}
- /* do the indenting into indent */
- indent=owl_malloc(strlen(body)+owl_text_num_lines(body)*OWL_MSGTAB+10);
- owl_text_indent(indent, body, OWL_MSGTAB);
- owl_fmtext_append_ztext(fm, indent);
-
- owl_free(indent);
owl_free(body);
}