[212] in bug-owl

home help back first fref pref prev next nref lref last post

filter attribute patch

daemon@ATHENA.MIT.EDU (Jeremy Daniel)
Sat Jun 28 12:58:45 2003

To: bug-owl@MIT.EDU
From: Jeremy Daniel <jdaniel@MIT.EDU>
Date: 28 Jun 2003 12:57:38 -0400
Message-ID: <skebrwicf7h.fsf@multics.mit.edu>
MIME-Version: 1.0
Content-Type: text/plain; charset=us-ascii

See the changelog additions below for a full description.	

--------
/mit/jdaniel/project/owl/patches/filter-attr.patch
--------
Index: ChangeLog
===================================================================
RCS file: /mit/ktools/src/owl/repository/owl/ChangeLog,v
retrieving revision 1.132
diff -u -r1.132 ChangeLog
--- ChangeLog	28 Jun 2003 12:23:02 -0000	1.132
+++ ChangeLog	28 Jun 2003 16:55:58 -0000
@@ -2,6 +2,14 @@
 
 2.0.6-pre-1
 	Initialze $owl::auth
+	Added an attribute field to filters alowing you to specify bold
+	  (-b), underline (-u) or reverse video (-rv) along with color.
+	  Attributes are xor'ed with ones already in the message so that
+	  bolding already bold text will become normal and still stand out
+	  among the already bolded text (think latex {\em foo {\em bar}}).
+	Changed show colors to show the available attributes as well.
+	Added owl_fmtext_normalize_margin() to make sure the text where the 
+	  message pointer is is default color with no attributes.
 	
 2.0.5
 	Fix in finding des for building zcrypt
Index: commands.c
===================================================================
RCS file: /mit/ktools/src/owl/repository/owl/commands.c,v
retrieving revision 1.43
diff -u -r1.43 commands.c
--- commands.c	28 Jun 2003 02:20:56 -0000	1.43
+++ commands.c	28 Jun 2003 04:26:05 -0000
@@ -447,7 +447,7 @@
   
   OWLCMD_ARGS("filter", owl_command_filter, OWL_CTX_ANY,
 	      "create a message filter",
-	      "filter <name> [ -c color ] [ <expression> ... ]",
+	      "filter <name> [ -c color ] [ -b ] [ -u ] [ -rv ] [ <expression> ... ]",
 	      "The filter command creates a filter with the specified name,\n"
 	      "or if one already exists it is replaced.  Example filter\n"
 	      "syntax would be:\n\n"
@@ -472,14 +472,17 @@
 	      "    false\n"
 	      "Spaces must be present before and after parenthesis.  If the\n"
 	      "optional color argument is used it specifies the color that\n"
-	      "messages matching this filter should be displayed in.\n\n"
+	      "messages matching this filter should be displayed in.\n"
+	      "Likewise the other optional arguments can be used to\n"
+	      "specify bold, underline, or reverse video.\n\n"
 	      "SEE ALSO: view, viewclass, viewuser\n"),
 
   OWLCMD_ARGS("colorview", owl_command_colorview, OWL_CTX_INTERACTIVE,
 	      "change the color on the current filter",
-	      "colorview <color>",
+	      "colorview [ <color> ] [ -b ] [ -u ] [ -rv ]",
 	      "The color of messages in the current filter will be changed\n"
-	      "to <color>.  Use the 'show colors' command for a list\n"
+	      "to <color>.  Bold, underline, or reverse video may also be\n"
+	      "specified.  Use the 'show colors' command for a list\n"
 	      "of valid colors.\n\n"
 	      "SEE ALSO: 'show colors'\n"),
 
@@ -1889,11 +1892,11 @@
 }
 
 char *owl_command_colorview(int argc, char **argv, char *buff) {
-  if (argc!=2) {
+  if (argc>5) {
     owl_function_makemsg("Wrong number of arguments to colorview command");
     return NULL;
   }
-  owl_function_color_current_filter(argv[1]);
+  owl_function_color_current_filter(argc, argv);
   return NULL;
 }
 
Index: filter.c
===================================================================
RCS file: /mit/ktools/src/owl/repository/owl/filter.c,v
retrieving revision 1.11
diff -u -r1.11 filter.c
--- filter.c	22 Jun 2003 17:40:49 -0000	1.11
+++ filter.c	28 Jun 2003 16:25:17 -0000
@@ -14,6 +14,9 @@
   return(out);
 }
 
+/* Color arguments should no longer be passed in.  
+ * They get parsed separately first by owl_util_color_parse().
+ */
 int owl_filter_init(owl_filter *f, char *name, int argc, char **argv)
 {
   int i, error;
@@ -23,17 +26,10 @@
   f->name=owl_strdup(name);
   f->polarity=0;
   f->color=OWL_COLOR_DEFAULT;
+  f->attr=OWL_FMTEXT_ATTR_NONE;
   f->cachedmsgid=-1;
   owl_list_create(&(f->fes));
   
-  /* first take arguments that have to come first */
-  /* set the color */
-  if (argc>=2 && !strcmp(argv[0], "-c")) {
-    f->color=owl_util_string_to_color(argv[1]);
-    argc-=2;
-    argv+=2;
-  }
-  
   /* then deal with the expression */
   for (i=0; i<argc; i++) {
     error=0;
@@ -112,6 +108,16 @@
 int owl_filter_get_color(owl_filter *f)
 {
   return(f->color);
+}
+
+void owl_filter_set_attr(owl_filter *f, int attr) 
+{
+  f->attr=attr;
+}
+
+int owl_filter_get_attr(owl_filter *f) 
+{
+  return(f->attr);
 }
 
 void owl_filter_set_cachedmsgid(owl_filter *f, int cachedmsgid)
Index: fmtext.c
===================================================================
RCS file: /mit/ktools/src/owl/repository/owl/fmtext.c,v
retrieving revision 1.12
diff -u -r1.12 fmtext.c
--- fmtext.c	10 Jun 2003 19:14:59 -0000	1.12
+++ fmtext.c	28 Jun 2003 16:29:42 -0000
@@ -28,12 +28,13 @@
 
 /* Internal function.  Add the attribute 'attr' to the existing
  * attributes from index 'first' to index 'last'
+ * Use xor to make reversed reverse be normal, etc.
  */
 void _owl_fmtext_add_attr(owl_fmtext *f, int attr, int first, int last)
 {
   int i;
   for (i=first; i<=last; i++) {
-    f->fmbuff[i]|=(unsigned char) attr;
+    f->fmbuff[i]^=(unsigned char) attr;
   }
 }
 
@@ -122,6 +123,21 @@
   }
 }
 
+/* Anywhere the attributes are not set they will become 'attr'.
+ * If they are set, set them to the opposite. 
+ * i.e. bolding bold gets normal
+ */
+void owl_fmtext_attributize(owl_fmtext *f, int attr) 
+{
+  /* xor the given color attr in the text with `attr' */
+  int i, j;
+
+  j=f->textlen;
+  for(i=0; i<j; i++) {
+    f->fmbuff[i] ^= attr;
+  }
+}
+
 /* Append the text 'text' to 'f' and interpret the zephyr style
  * formatting syntax to set appropriate attributes.
  */
@@ -619,4 +635,27 @@
 
   if (stristr(f->textbuff, string)) return(1);
   return(0);
+}
+
+/* for the length of OWL_TAB at the beginning of each line 
+ * make the text default color with no attrs 
+ */
+void owl_fmtext_normalize_margin(owl_fmtext *f) 
+{
+  int i, j, ind;
+  char *ptr;
+
+  ptr=f->textbuff;
+  j=f->textlen;
+  while (1) {
+    for(i=0; i<OWL_TAB; i++) {
+      ind=ptr-f->textbuff+i;
+      if (ind>=j) break;
+      f->colorbuff[ind]=OWL_COLOR_DEFAULT;
+      f->fmbuff[ind]=OWL_FMTEXT_ATTR_NONE;
+    }
+    ptr+=i;
+    if ((ptr=strchr(ptr,'\n'))==NULL) break;
+    ptr++;
+  }
 }
Index: functions.c
===================================================================
RCS file: /mit/ktools/src/owl/repository/owl/functions.c,v
retrieving revision 1.73
diff -u -r1.73 functions.c
--- functions.c	28 Jun 2003 01:16:45 -0000	1.73
+++ functions.c	28 Jun 2003 16:36:59 -0000
@@ -2102,7 +2102,10 @@
 {
   owl_filter *f;
   owl_view *v;
-  int ret, inuse=0;
+  int ret, inuse=0, colorargs;
+  char *filtername;
+  char color=OWL_COLOR_DEFAULT;
+  char attr=OWL_FMTEXT_ATTR_NONE;
 
   if (argc < 2) {
     owl_function_makemsg("Wrong number of arguments to filter command");
@@ -2110,43 +2113,57 @@
   }
 
   v=owl_global_get_current_view(&g);
+  filtername=argv[1];
+  /* skip the command name and filter name */
+  argv+=2;
+  argc-=2;
 
   /* don't touch the all filter */
-  if (!strcmp(argv[1], "all")) {
+  if (!strcmp(filtername, "all")) {
     owl_function_makemsg("You may not change the 'all' filter.");
     return;
   }
 
-  /* deal with the case of trying change the filter color */
-  if (argc==4 && !strcmp(argv[2], "-c")) {
-    f=owl_global_get_filter(&g, argv[1]);
-    if (!f) {
-      owl_function_makemsg("The filter '%s' does not exist.", argv[1]);
+  /* try and parse as if only setting color */
+  if ((colorargs=owl_util_color_parse(argc, argv, &color, &attr, 0))) {
+    f=owl_global_get_filter(&g, filtername);
+    /* if there are no more arguments after coloring */
+    if (argc==colorargs) {
+      if (f) {
+	owl_filter_set_color(f, color);
+	owl_filter_set_attr(f, attr);
+	owl_global_set_needrefresh(&g);
+	owl_mainwin_redisplay(owl_global_get_mainwin(&g));
+      } else {
+	owl_function_makemsg("The filter '%s' does not exist.", filtername);
+      }
       return;
+    } else {
+      argc-=colorargs;
+      argv+=colorargs;
     }
-    owl_filter_set_color(f, owl_util_string_to_color(argv[3]));
-    owl_global_set_needrefresh(&g);
-    owl_mainwin_redisplay(owl_global_get_mainwin(&g));
-    return;
   }
 
   /* create the filter and check for errors */
   f=owl_malloc(sizeof(owl_filter));
-  ret=owl_filter_init(f, argv[1], argc-2, argv+2);
+  ret=owl_filter_init(f, filtername, argc, argv);
   if (ret==-1) {
     owl_free(f);
     owl_function_makemsg("Invalid filter syntax");
     return;
   }
 
+  f->color=color;
+  f->attr=attr;
+
   /* if the named filter is in use by the current view, remember it */
-  if (!strcmp(owl_view_get_filtname(v), argv[1])) {
+  if (!strcmp(owl_view_get_filtname(v), filtername)) {
     inuse=1;
   }
 
   /* if the named filter already exists, nuke it */
-  if (owl_global_get_filter(&g, argv[1])) {
-    owl_global_remove_filter(&g, argv[1]);
+  if (owl_global_get_filter(&g, filtername)) {
+    owl_global_remove_filter(&g, filtername);
   }
 
   /* add the filter */
@@ -2154,7 +2171,7 @@
 
   /* if it was in use by the current view then update */
   if (inuse) {
-    owl_function_change_view(argv[1]);
+    owl_function_change_view(filtername);
   }
   owl_global_set_needrefresh(&g);
   owl_mainwin_redisplay(owl_global_get_mainwin(&g));
@@ -2178,9 +2195,9 @@
     f=owl_list_get_element(l, i);
     owl_fmtext_append_normal(&fm, "   ");
     if (owl_global_get_hascolors(&g)) {
-      owl_fmtext_append_normal_color(&fm, owl_filter_get_name(f), owl_filter_get_color(f));
+      owl_fmtext_append_attr(&fm, owl_filter_get_name(f), owl_filter_get_attr(f), owl_filter_get_color(f));
     } else {
-      owl_fmtext_append_normal(&fm, owl_filter_get_name(f));
+      owl_fmtext_append_attr(&fm, owl_filter_get_name(f), owl_filter_get_attr(f), OWL_FMTEXT_ATTR_NONE);
     }
     owl_fmtext_append_normal(&fm, "\n");
   }
@@ -2541,10 +2558,12 @@
 
 
 
-void owl_function_color_current_filter(char *color)
+void owl_function_color_current_filter(int argc, char **argv)
 {
   owl_filter *f;
   char *name;
+  char color=OWL_COLOR_DEFAULT;
+  char attr=OWL_FMTEXT_ATTR_NONE;
 
   name=owl_view_get_filtname(owl_global_get_current_view(&g));
   f=owl_global_get_filter(&g, name);
@@ -2559,8 +2578,19 @@
     return;
   }
 
+  /* skip the command name */
+  argv++;
+  argc--;
+
   /* deal with the case of trying change the filter color */
-  owl_filter_set_color(f, owl_util_string_to_color(color));
+  if (argc==owl_util_color_parse(argc, argv, &color, &attr, 1)) {
+    owl_filter_set_color(f, color);
+    owl_filter_set_attr(f, attr);
+  } else {
+    /* if all the args weren't used return an error */
+    owl_function_makemsg("Invalid colorview syntax");
+  }
+
   owl_global_set_needrefresh(&g);
   owl_mainwin_redisplay(owl_global_get_mainwin(&g));
 }
@@ -2568,16 +2598,31 @@
 void owl_function_show_colors()
 {
   owl_fmtext fm;
+  char *name;
+  int i, color, num_colors;
+  int colors[8] = { OWL_COLOR_RED,
+		    OWL_COLOR_GREEN,
+		    OWL_COLOR_YELLOW,
+		    OWL_COLOR_BLUE,
+		    OWL_COLOR_MAGENTA,
+		    OWL_COLOR_CYAN,
+		    OWL_COLOR_WHITE,
+		    OWL_COLOR_DEFAULT };
 
   owl_fmtext_init_null(&fm);
-  owl_fmtext_append_normal_color(&fm, "default\n", OWL_COLOR_DEFAULT);
-  owl_fmtext_append_normal_color(&fm, "red\n", OWL_COLOR_RED);
-  owl_fmtext_append_normal_color(&fm, "green\n", OWL_COLOR_GREEN);
-  owl_fmtext_append_normal_color(&fm, "yellow\n", OWL_COLOR_YELLOW);
-  owl_fmtext_append_normal_color(&fm, "blue\n", OWL_COLOR_BLUE);
-  owl_fmtext_append_normal_color(&fm, "magenta\n", OWL_COLOR_MAGENTA);
-  owl_fmtext_append_normal_color(&fm, "cyan\n", OWL_COLOR_CYAN);
-  owl_fmtext_append_normal_color(&fm, "white\n", OWL_COLOR_WHITE);
+  num_colors=sizeof(colors)/sizeof(colors[0]);
+  for (i=0; i<num_colors; i++) {
+    color=colors[i];
+    name=owl_util_color_to_string(color);
+    owl_fmtext_append_attr(&fm, name, OWL_FMTEXT_ATTR_NONE, color);
+    owl_fmtext_append_normal(&fm, "\t\t");
+    owl_fmtext_append_attr(&fm, "-b", OWL_FMTEXT_ATTR_BOLD, color);
+    owl_fmtext_append_normal(&fm, "\t");
+    owl_fmtext_append_attr(&fm, "-rv", OWL_FMTEXT_ATTR_REVERSE, color);
+    owl_fmtext_append_normal(&fm, "\t");
+    owl_fmtext_append_attr(&fm, "-u", OWL_FMTEXT_ATTR_UNDERLINE, color);
+    owl_fmtext_append_normal(&fm, "\n");
+  }
 
   owl_function_popless_fmtext(&fm);
   owl_fmtext_free(&fm);
Index: mainwin.c
===================================================================
RCS file: /mit/ktools/src/owl/repository/owl/mainwin.c,v
retrieving revision 1.5
diff -u -r1.5 mainwin.c
--- mainwin.c	17 Feb 2003 21:29:08 -0000	1.5
+++ mainwin.c	17 Jun 2003 20:22:24 -0000
@@ -11,7 +11,7 @@
   owl_message *m;
   int i, p, q, lines, isfull, viewsize;
   int x, y, savey, recwinlines, start;
-  int topmsg, curmsg, color;
+  int topmsg, curmsg, color, attr;
   WINDOW *recwin;
   owl_view *v;
   owl_list *filtlist;
@@ -70,12 +70,18 @@
 
     /* if we match filters set the color */
     color=OWL_COLOR_DEFAULT;
+    attr=OWL_FMTEXT_ATTR_NONE;
     filtlist=owl_global_get_filterlist(&g);
     q=owl_list_get_size(filtlist);
     for (p=0; p<q; p++) {
       f=owl_list_get_element(filtlist, p);
       if (owl_filter_message_match(f, m)) {
-	if (owl_filter_get_color(f)!=OWL_COLOR_DEFAULT) color=owl_filter_get_color(f);
+	if (owl_filter_get_color(f)!=OWL_COLOR_DEFAULT || 
+	    owl_filter_get_attr(f)!=OWL_FMTEXT_ATTR_NONE)
+	  {
+	    color=owl_filter_get_color(f);
+	    attr=owl_filter_get_attr(f);
+	  }
       }
     }
 
@@ -89,7 +95,7 @@
 			       start+recwinlines-y,
 			       owl_global_get_rightshift(&g),
 			       owl_global_get_cols(&g)+owl_global_get_rightshift(&g)-1,
-			       color);
+			       color, attr);
     } else {
       /* otherwise print the whole thing */
       owl_message_curs_waddstr(m, owl_global_get_curs_recwin(&g),
@@ -97,7 +103,7 @@
 			       start+lines,
 			       owl_global_get_rightshift(&g),
 			       owl_global_get_cols(&g)+owl_global_get_rightshift(&g)-1,
-			       color);
+			       color, attr);
     }
 
 
Index: message.c
===================================================================
RCS file: /mit/ktools/src/owl/repository/owl/message.c,v
retrieving revision 1.37
diff -u -r1.37 message.c
--- message.c	27 Jun 2003 21:22:40 -0000	1.37
+++ message.c	28 Jun 2003 15:55:38 -0000
@@ -441,7 +441,7 @@
 }
 
 
-void owl_message_curs_waddstr(owl_message *m, WINDOW *win, int aline, int bline, int acol, int bcol, int color)
+void owl_message_curs_waddstr(owl_message *m, WINDOW *win, int aline, int bline, int acol, int bcol, int color, int attr)
 {
   owl_fmtext a, b;
 
@@ -452,10 +452,15 @@
   owl_fmtext_init_null(&b);
   
   owl_fmtext_truncate_lines(&(m->fmtext), aline, bline-aline+1, &a);
-  owl_fmtext_truncate_cols(&a, acol, bcol, &b);
   if (color!=OWL_COLOR_DEFAULT) {
-    owl_fmtext_colorize(&b, color);
+    owl_fmtext_colorize(&a, color);
+  }
+  if (attr!=OWL_FMTEXT_ATTR_NONE) {
+    owl_fmtext_attributize(&a, attr);
   }
+
+  owl_fmtext_normalize_margin(&a);
+  owl_fmtext_truncate_cols(&a, acol, bcol, &b);
 
   if (owl_global_is_search_active(&g)) {
     owl_fmtext_search_and_highlight(&b, owl_global_get_search_string(&g));
Index: owl.h
===================================================================
RCS file: /mit/ktools/src/owl/repository/owl/owl.h,v
retrieving revision 1.51
diff -u -r1.51 owl.h
--- owl.h	28 Jun 2003 12:23:02 -0000	1.51
+++ owl.h	28 Jun 2003 15:51:16 -0000
@@ -319,6 +319,7 @@
   int polarity;
   owl_list fes; /* filterelements */
   int color;
+  int attr;
   int cachedmsgid;  /* cached msgid: should move into view eventually */
 } owl_filter;
 
Index: util.c
===================================================================
RCS file: /mit/ktools/src/owl/repository/owl/util.c,v
retrieving revision 1.27
diff -u -r1.27 util.c
--- util.c	27 Jun 2003 17:03:17 -0000	1.27
+++ util.c	28 Jun 2003 16:03:51 -0000
@@ -589,6 +589,59 @@
   return("Unknown color");
 }
 
+int owl_util_color_parse(int argc, char **argv, char *color, char *attr, int type) 
+{
+  /* parse colors and attrs from argv
+     return the number of args consumed 
+     -b, -rv, and -u are always accepted
+     type==0 called from filter and requires -c before a color name
+     type==1 called from colorview allows bare color names */
+
+  int argc_orig=argc;
+  char newcolor=OWL_COLOR_DEFAULT;
+  char newattr=OWL_FMTEXT_ATTR_NONE;
+  int type_filter=0, type_colorview=1;
+
+  if (argc>=1) {
+    while (argc) {
+      if (!strcmp(argv[0], "-b")) {
+	newattr |= OWL_FMTEXT_ATTR_BOLD;
+      } else if (!strcmp(argv[0], "-u")) {
+	newattr |= OWL_FMTEXT_ATTR_UNDERLINE;
+      } else if (!strcmp(argv[0], "-rv")) {
+	newattr |= OWL_FMTEXT_ATTR_REVERSE;
+      } else if (type==type_filter) {
+	if (!strcmp(argv[0], "-c")) {
+	  if (argc<2) {
+	    break;
+	  }
+	  newcolor=owl_util_string_to_color(argv[1]);
+	  argv++; 
+	  argc--;
+	} else { 
+	  break;
+	}
+      } else if (type==type_colorview) {
+	newcolor=owl_util_string_to_color(argv[0]);
+	if (newcolor != OWL_COLOR_DEFAULT) {
+	  /* the argument is a color */
+	} else if (!strcmp(argv[0], "default")) {
+	  /* the argument is the default color */
+	} else {
+	  break;
+	}
+      }
+      argv++;
+      argc--;
+    }
+    if (argc != argc_orig) {
+      *color=newcolor;
+      *attr=newattr;
+    }
+  }
+  return (argc_orig-argc);
+}
+
 /* Get the default tty name.  Caller must free the return */
 char *owl_util_get_default_tty()
 {

home help back first fref pref prev next nref lref last post