[674] in BarnOwl Developers

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

[D-O-H] r755 - in branches/barnowl_sqlite: . owl owl/perl/lib/BarnOwl

daemon@ATHENA.MIT.EDU (nelhage@MIT.EDU)
Thu Oct 29 18:08:32 2009

Resent-From: nelhage@mit.edu
Resent-To: barnowl-dev-mtg@charon.mit.edu
To: dirty-owl-hackers@mit.edu
From: nelhage@MIT.EDU
Reply-to: dirty-owl-hackers@MIT.EDU
Date: Tue, 14 Aug 2007 23:08:50 -0400 (EDT)

Author: nelhage
Date: 2007-08-14 23:08:49 -0400 (Tue, 14 Aug 2007)
New Revision: 755

Added:
   branches/barnowl_sqlite/owl/t/
Modified:
   branches/barnowl_sqlite/
   branches/barnowl_sqlite/owl/
   branches/barnowl_sqlite/owl/Makefile.in
   branches/barnowl_sqlite/owl/commands.c
   branches/barnowl_sqlite/owl/dict.c
   branches/barnowl_sqlite/owl/filter.c
   branches/barnowl_sqlite/owl/functions.c
   branches/barnowl_sqlite/owl/global.c
   branches/barnowl_sqlite/owl/message.c
   branches/barnowl_sqlite/owl/obarray.c
   branches/barnowl_sqlite/owl/owl.c
   branches/barnowl_sqlite/owl/owl.h
   branches/barnowl_sqlite/owl/perl/lib/BarnOwl/ModuleLoader.pm
   branches/barnowl_sqlite/owl/perlconfig.c
   branches/barnowl_sqlite/owl/perlglue.xs
   branches/barnowl_sqlite/owl/perlwrap.pm
   branches/barnowl_sqlite/owl/test.h
   branches/barnowl_sqlite/owl/tester.c
   branches/barnowl_sqlite/owl/util.c
   branches/barnowl_sqlite/owl/variable.c
   branches/barnowl_sqlite/owl/zephyr.c
   branches/barnowl_sqlite/owl/zwrite.c
Log:
Mergedown from trunk into sqlite branch.




Property changes on: branches/barnowl_sqlite
___________________________________________________________________
Name: svnmerge-integrated
   - /trunk:1-735
   + /trunk:1-754


Property changes on: branches/barnowl_sqlite/owl
___________________________________________________________________
Name: svk:merge
   - 06e3988a-d725-0410-af47-c5dd11e74598:/local/barnowl:1614
8baf6839-b125-0410-9df9-922793c80423:/local/barnowl:17717
8baf6839-b125-0410-9df9-922793c80423:/local/owl:15641
bb873fd7-8e23-0410-944a-99ec44c633eb:/local/d-o-h/branches/par:19594
fe09232e-8620-0410-8e36-e6b4839e121d:/branches/par:688
   + 06e3988a-d725-0410-af47-c5dd11e74598:/local/barnowl:1614
8baf6839-b125-0410-9df9-922793c80423:/local/barnowl:20981
8baf6839-b125-0410-9df9-922793c80423:/local/owl:15641
bb873fd7-8e23-0410-944a-99ec44c633eb:/local/d-o-h/branches/par:19594
fe09232e-8620-0410-8e36-e6b4839e121d:/branches/par:688

Modified: branches/barnowl_sqlite/owl/Makefile.in
===================================================================
--- branches/barnowl_sqlite/owl/Makefile.in	2007-08-11 05:18:37 UTC (rev 754)
+++ branches/barnowl_sqlite/owl/Makefile.in	2007-08-15 03:08:49 UTC (rev 755)
@@ -44,7 +44,7 @@
 AUTOGEN=$(GEN_C) $(GEN_H)
 #AUTOGEN=$(GEN_C)
 
-HEADERS=$(GEN_H) owl.h config.h
+HEADERS=$(GEN_H) owl.h config.h test.h
 
 %.o: %.c $(HEADERS)
 	$(CC) -c $(CFLAGS) $< -o $@

Modified: branches/barnowl_sqlite/owl/commands.c
===================================================================
--- branches/barnowl_sqlite/owl/commands.c	2007-08-11 05:18:37 UTC (rev 754)
+++ branches/barnowl_sqlite/owl/commands.c	2007-08-15 03:08:49 UTC (rev 755)
@@ -280,6 +280,25 @@
 	      "suppressed to be received again.\n\n"
 	      "SEE ALSO:  zpunt, show zpunts\n"),
 
+  OWLCMD_ARGS("punt", owl_command_punt, OWL_CTX_ANY,
+	      "suppress an arbitrary filter",
+	      "punt <filter-name>",
+	      "punt <filter-text (multiple words)>\n"
+	      "The punt command will supress message to the specified\n"
+	      "filter\n\n"
+	      "SEE ALSO:  unpunt, zpunt, show zpunts\n"),
+
+  OWLCMD_ARGS("unpunt", owl_command_unpunt, OWL_CTX_ANY,
+	      "remove an entry from the punt list",
+	      "zpunt <filter-name>\n"
+	      "zpunt <filter-text>\n"
+	      "zpunt <number>\n",
+	      "The unpunt command will remove an entry from the puntlist.\n"
+	      "The first two forms correspond to the first two forms of the :punt\n"
+	      "command. The latter allows you to remove a specific entry from the\n"
+	      "the list (see :show zpunts)\n\n"
+	      "SEE ALSO:  punt, zpunt, zunpunt, show zpunts\n"),
+
   OWLCMD_VOID("info", owl_command_info, OWL_CTX_INTERACTIVE,
 	      "display detailed information about the current message",
 	      "", ""),
@@ -2141,9 +2160,8 @@
   } else if (!strcmp(argv[1], "startup")) {
     char *filename;
     
-    filename=owl_sprintf("%s/%s", owl_global_get_homedir(&g), OWL_STARTUP_FILE);
+    filename=owl_global_get_startupfile(&g);
     owl_function_popless_file(filename);
-    owl_free(filename);
   } else if (!strcmp(argv[1], "errors")) {
     owl_function_showerrs();
   } else {
@@ -2294,7 +2312,6 @@
   return NULL;
 }
 
-
 void owl_command_zpunt_and_zunpunt(int argc, char **argv, int type)
 {
   /* if type==0 then zpunt
@@ -2344,6 +2361,52 @@
   return NULL;
 }
 
+char *owl_command_punt(int argc, char **argv, char *buff)
+{
+  owl_command_punt_unpunt(argc, argv, buff, 0);
+  return NULL;
+}
+
+char *owl_command_unpunt(int argc, char **argv, char *buff)
+{
+  owl_command_punt_unpunt(argc, argv, buff, 1);
+  return NULL;
+}
+
+void owl_command_punt_unpunt(int argc, char ** argv, char *buff, int unpunt)
+{
+  owl_list * fl;
+  owl_filter * f;
+  char * text;
+  int i;
+
+  fl = owl_global_get_puntlist(&g);
+  if(argc == 1) {
+    owl_function_show_zpunts();
+  }
+
+  if(argc == 2) {
+    /* Handle :unpunt <number> */
+    if(unpunt && (i=atoi(argv[1])) !=0) {
+      i--;      /* Accept 1-based indexing */
+      if(i < owl_list_get_size(fl)) {
+        f = (owl_filter*)owl_list_get_element(fl, i);
+        owl_list_remove_element(fl, i);
+        owl_filter_free(f);
+        return;
+      } else {
+        owl_function_error("No such filter number: %d", i+1);
+      }
+    }
+    text = owl_sprintf("filter %s", argv[1]);
+  } else {
+    text = skiptokens(buff, 1);
+  }
+
+  owl_function_punt(text, unpunt);
+}
+
+
 char *owl_command_getview(int argc, char **argv, char *buff)
 {
   char *filtname;
@@ -2468,6 +2531,7 @@
 {
   owl_message *m;
   owl_view *v;
+  char *cmd;
 
   v = owl_global_get_current_view(&g);
 
@@ -2486,7 +2550,7 @@
     owl_function_error("You already answered that question.");
     return;
   }
-  char * cmd = owl_message_get_attribute_value(m, "yescommand");
+  cmd = owl_message_get_attribute_value(m, "yescommand");
   if(!cmd) {
     owl_function_error("No yes command!");
     return;
@@ -2501,6 +2565,7 @@
 {
   owl_message *m;
   owl_view *v;
+  char *cmd;
 
   v = owl_global_get_current_view(&g);
 
@@ -2519,7 +2584,7 @@
     owl_function_error("You already answered that question.");
     return;
   }
-  char * cmd = owl_message_get_attribute_value(m, "nocommand");
+  cmd = owl_message_get_attribute_value(m, "nocommand");
   if(!cmd) {
     owl_function_error("No no command!");
     return;

Modified: branches/barnowl_sqlite/owl/dict.c
===================================================================
--- branches/barnowl_sqlite/owl/dict.c	2007-08-11 05:18:37 UTC (rev 754)
+++ branches/barnowl_sqlite/owl/dict.c	2007-08-15 03:08:49 UTC (rev 755)
@@ -151,7 +151,7 @@
   int numfailed=0;
   char *av="aval", *bv="bval", *cv="cval", *dv="dval";
 
-  printf("BEGIN testing owl_dict\n");
+  printf("# BEGIN testing owl_dict\n");
   FAIL_UNLESS("create", 0==owl_dict_create(&d));
   FAIL_UNLESS("insert b", 0==owl_dict_insert_element(&d, "b", (void*)bv, owl_dict_noop_free));
   FAIL_UNLESS("insert d", 0==owl_dict_insert_element(&d, "d", (void*)dv, owl_dict_noop_free));
@@ -178,8 +178,8 @@
   owl_list_free_all(&l, owl_free);
   owl_dict_free_all(&d, NULL);
 
-  if (numfailed) printf("*** WARNING: failures encountered with owl_dict\n");
-  printf("END testing owl_dict (%d failures)\n", numfailed);
+  //  if (numfailed) printf("*** WARNING: failures encountered with owl_dict\n");
+  printf("# END testing owl_dict (%d failures)\n", numfailed);
   return(numfailed);
 }
 

Modified: branches/barnowl_sqlite/owl/filter.c
===================================================================
--- branches/barnowl_sqlite/owl/filter.c	2007-08-11 05:18:37 UTC (rev 754)
+++ branches/barnowl_sqlite/owl/filter.c	2007-08-15 03:08:49 UTC (rev 755)
@@ -62,13 +62,13 @@
 
 static owl_filterelement * owl_filter_parse_primitive_expression(int argc, char **argv, int *next)
 {
+  owl_filterelement *fe, *op;
+  int i = 0, skip;
+
   if(!argc) return NULL;
 
-  owl_filterelement * fe = owl_malloc(sizeof(owl_filterelement));
-  owl_filterelement *op;
-
+  fe = owl_malloc(sizeof(owl_filterelement));
   owl_filterelement_create(fe);
-  int i = 0, skip;
 
   if(!strcasecmp(argv[i], "(")) {
     i++;
@@ -117,7 +117,7 @@
 owl_filterelement * owl_filter_parse_expression(int argc, char **argv, int *next)
 {
   int i = 0, skip;
-  owl_filterelement * op1 = NULL, * op2 = NULL;
+  owl_filterelement * op1 = NULL, * op2 = NULL, *tmp;
 
   op1 = owl_filter_parse_primitive_expression(argc-i, argv+i, &skip);
   i += skip;
@@ -128,7 +128,7 @@
        strcasecmp(argv[i], "or")) break;
     op2 = owl_filter_parse_primitive_expression(argc-i-1, argv+i+1, &skip);
     if(!op2) goto err;
-    owl_filterelement * tmp = owl_malloc(sizeof(owl_filterelement));
+    tmp = owl_malloc(sizeof(owl_filterelement));
     if(!strcasecmp(argv[i], "and")) {
       owl_filterelement_create_and(tmp, op1, op2);
     } else {
@@ -203,8 +203,9 @@
  */
 int owl_filter_message_match(owl_filter *f, owl_message *m)
 {
+  int ret;
   if(!f->root) return 0;
-  int ret = owl_filterelement_match(f->root, m);
+  ret = owl_filterelement_match(f->root, m);
   if(f->polarity) ret = !ret;
   return ret;
 }
@@ -282,19 +283,19 @@
   int ok;
   int failed = 0;
   if(owl_filter_init_fromstring(&f, "test-filter", filt)) {
-    printf("\tFAIL: parse %s\n", filt);
+    printf("not ok can't parse %s\n", filt);
     failed = 1;
     goto out;
   }
   ok = owl_filter_message_match(&f, m);
   if((shouldmatch && !ok) || (!shouldmatch && ok)) {
-    printf("\tFAIL: match %s (got %d, expected %d)\n", filt, ok, shouldmatch);
+    printf("not ok match %s (got %d, expected %d)\n", filt, ok, shouldmatch);
     failed = 1;
   }
  out:
   owl_filter_free(&f);
   if(!failed) {
-    printf("\tok  : %s %s\n", shouldmatch ? "matches" : "doesn't match", filt);
+    printf("ok %s %s\n", shouldmatch ? "matches" : "doesn't match", filt);
   }
   return failed;
 }
@@ -304,9 +305,11 @@
 
 
 int owl_filter_regtest(void) {
-  owl_list_create(&(g.filterlist));
   int numfailed=0;
   owl_message m;
+  owl_filter f1, f2, f3, f4;
+
+  owl_list_create(&(g.filterlist));
   owl_message_init(&m);
   owl_message_set_type_zephyr(&m);
   owl_message_set_direction_in(&m);
@@ -344,8 +347,6 @@
   TEST_FILTER("false and false or true", 1);
   TEST_FILTER("true and false or false", 0);
 
-  owl_filter f1, f2, f3, f4;
-
   owl_filter_init_fromstring(&f1, "f1", "class owl");
   owl_global_add_filter(&g, &f1);
   TEST_FILTER("filter f1", 1);

Modified: branches/barnowl_sqlite/owl/functions.c
===================================================================
--- branches/barnowl_sqlite/owl/functions.c	2007-08-11 05:18:37 UTC (rev 754)
+++ branches/barnowl_sqlite/owl/functions.c	2007-08-15 03:08:49 UTC (rev 755)
@@ -579,6 +579,7 @@
   }
 
   if (i>owl_view_get_size(v)-1) i=owl_view_get_size(v)-1;
+  if (i<0) i=0;
 
   if (!found) {
     owl_function_makemsg("already at last%s message%s%s",
@@ -2556,6 +2557,8 @@
 
   for (i=0; i<j; i++) {
     f=owl_list_get_element(fl, i);
+    snprintf(buff, sizeof(buff), "[% 2d] ", i+1);
+    owl_fmtext_append_normal(&fm, buff);
     owl_filter_print(f, buff);
     owl_fmtext_append_normal(&fm, buff);
   }
@@ -2669,9 +2672,9 @@
   f=owl_malloc(sizeof(owl_filter));
 
   argbuff=owl_malloc(strlen(longuser)+1000);
-  sprintf(argbuff, "( type ^zephyr$ and ( class ^message$ and instance ^personal$ and ");
+  sprintf(argbuff, "( type ^zephyr$ and filter personal and ");
   sprintf(argbuff, "%s ( ( direction ^in$ and sender ^%s$ ) or ( direction ^out$ and recipient ^%s$ ) ) )", argbuff, longuser, longuser);
-  sprintf(argbuff, "%s or ( ( class ^login$ ) and ( sender ^%s$ ) ) )", argbuff, longuser);
+  sprintf(argbuff, "%s or ( ( class ^login$ ) and ( sender ^%s$ ) )", argbuff, longuser);
 
   owl_filter_init_fromstring(f, filtname, argbuff);
 
@@ -2799,6 +2802,7 @@
   owl_view *v;
   owl_message *m;
   char *zperson, *filtname=NULL;
+  char *argv[1];
   
   v=owl_global_get_current_view(&g);
   m=owl_view_get_element(v, owl_global_get_curmsg(&g));
@@ -2830,7 +2834,7 @@
 
   /* narrow personal and login messages to the sender or recip as appropriate */
   if (owl_message_is_type_zephyr(m)) {
-    if (owl_message_is_private(m) || owl_message_is_loginout(m)) {
+    if (owl_message_is_personal(m) || owl_message_is_loginout(m)) {
       if (owl_message_is_direction_in(m)) {
         zperson=short_zuser(owl_message_get_sender(m));
       } else {
@@ -2857,7 +2861,6 @@
   }
 
   /* pass it off to perl */
-  char *argv[1];
   if(type) {
     argv[0] = "-i";
   };
@@ -3015,16 +3018,9 @@
  */
 void owl_function_zpunt(char *class, char *inst, char *recip, int direction)
 {
-  owl_filter *f;
-  owl_list *fl;
   char *buff;
   char *quoted;
-  int ret, i, j;
 
-  fl=owl_global_get_puntlist(&g);
-
-  /* first, create the filter */
-  f=malloc(sizeof(owl_filter));
   buff=malloc(strlen(class)+strlen(inst)+strlen(recip)+100);
   strcpy(buff, "class");
   if (!strcmp(class, "*")) {
@@ -3055,10 +3051,23 @@
     sprintf(buff, "%s and recipient ^%s$", buff, quoted);
     owl_free(quoted);
   }
-  
-  owl_function_debugmsg("About to filter %s", buff);
-  ret=owl_filter_init_fromstring(f, "punt-filter", buff);
+
+  owl_function_punt(buff, direction);
   owl_free(buff);
+}
+
+void owl_function_punt(char *filter, int direction)
+{
+  owl_filter *f;
+  owl_list *fl;
+  int ret, i, j;
+  fl=owl_global_get_puntlist(&g);
+
+  /* first, create the filter */
+  f=malloc(sizeof(owl_filter));
+
+  owl_function_debugmsg("About to filter %s", filter);
+  ret=owl_filter_init_fromstring(f, "punt-filter", filter);
   if (ret) {
     owl_function_error("Error creating filter for zpunt");
     owl_filter_free(f);
@@ -3069,6 +3078,7 @@
   j=owl_list_get_size(fl);
   for (i=0; i<j; i++) {
     if (owl_filter_equiv(f, owl_list_get_element(fl, i))) {
+      owl_function_debugmsg("found an equivalent punt filter");
       /* if we're punting, then just silently bow out on this duplicate */
       if (direction==0) {
 	owl_filter_free(f);
@@ -3079,11 +3089,13 @@
       if (direction==1) {
 	owl_filter_free(owl_list_get_element(fl, i));
 	owl_list_remove_element(fl, i);
+        owl_filter_free(f);
 	return;
       }
     }
   }
 
+  owl_function_debugmsg("punting");
   /* If we're punting, add the filter to the global punt list */
   if (direction==0) {
     owl_list_append_element(fl, f);
@@ -3460,17 +3472,15 @@
   FILE *file;
   char *filename;
 
-  filename=owl_sprintf("%s/%s", owl_global_get_homedir(&g), OWL_STARTUP_FILE);
+  filename=owl_global_get_startupfile(&g);
   file=fopen(filename, "a");
   if (!file) {
     owl_function_error("Error opening startupfile for new command");
-    owl_free(filename);
     return;
   }
 
   /* delete earlier copies */
   owl_util_file_deleteline(filename, buff, 1);
-  owl_free(filename);
 
   /* add this line */
   fprintf(file, "%s\n", buff);
@@ -3482,9 +3492,8 @@
 void owl_function_delstartup(char *buff)
 {
   char *filename;
-  filename=owl_sprintf("%s/%s", owl_global_get_homedir(&g), OWL_STARTUP_FILE);
+  filename=owl_global_get_startupfile(&g);
   owl_util_file_deleteline(filename, buff, 1);
-  owl_free(filename);
 }
 
 /* Execute owl commands from the given filename.  If the filename
@@ -3496,9 +3505,8 @@
   char buff[LINE];
 
   if (!filename) {
-    filename=owl_sprintf("%s/%s", owl_global_get_homedir(&g), OWL_STARTUP_FILE);
+    filename=owl_global_get_startupfile(&g);
     file=fopen(filename, "r");
-    owl_free(filename);
   } else {
     file=fopen(filename, "r");
   }

Modified: branches/barnowl_sqlite/owl/global.c
===================================================================
--- branches/barnowl_sqlite/owl/global.c	2007-08-11 05:18:37 UTC (rev 754)
+++ branches/barnowl_sqlite/owl/global.c	2007-08-15 03:08:49 UTC (rev 755)
@@ -17,6 +17,7 @@
 void owl_global_init(owl_global *g) {
   struct hostent *hent;
   char hostname[MAXHOSTNAMELEN];
+  char *cd;
 
   g->malloced=0;
   g->freed=0;
@@ -85,6 +86,12 @@
   /* TODO: come back later and check passwd file first */
   g->homedir=owl_strdup(getenv("HOME"));
 
+  g->confdir = NULL;
+  g->startupfile = NULL;
+  cd = owl_sprintf("%s/%s", g->homedir, OWL_CONFIG_DIR);
+  owl_global_set_confdir(g, cd);
+  owl_free(cd);
+
   owl_messagelist_create(&(g->msglist));
   owl_mainwin_init(&(g->mw));
   owl_popwin_init(&(g->pw));
@@ -318,6 +325,26 @@
   return("/");
 }
 
+char *owl_global_get_confdir(owl_global *g) {
+  if (g->confdir) return(g->confdir);
+  return("/");
+}
+
+/*
+ * Setting this also sets startupfile to confdir/startup
+ */
+void owl_global_set_confdir(owl_global *g, char *cd) {
+  free(g->confdir);
+  g->confdir = owl_strdup(cd);
+  free(g->startupfile);
+  g->startupfile = owl_sprintf("%s/startup", cd);
+}
+
+char *owl_global_get_startupfile(owl_global *g) {
+  if(g->startupfile) return(g->startupfile);
+  return("/");
+}
+
 int owl_global_get_direction(owl_global *g) {
   return(g->direction);
 }

Modified: branches/barnowl_sqlite/owl/message.c
===================================================================
--- branches/barnowl_sqlite/owl/message.c	2007-08-11 05:18:37 UTC (rev 754)
+++ branches/barnowl_sqlite/owl/message.c	2007-08-15 03:08:49 UTC (rev 755)
@@ -26,10 +26,10 @@
 
 owl_fmtext_cache * owl_message_next_fmtext() /*noproto*/
 {
+    owl_fmtext_cache * f = fmtext_cache_next;
     if(fmtext_cache_next->message != NULL) {
         owl_message_invalidate_format(fmtext_cache_next->message);
     }
-    owl_fmtext_cache * f = fmtext_cache_next;
     fmtext_cache_next++;
     if(fmtext_cache_next - fmtext_cache == OWL_FMTEXT_CACHE_SIZE)
         fmtext_cache_next = fmtext_cache;
@@ -416,6 +416,7 @@
 
 char *owl_message_get_text(owl_message *m)
 {
+  owl_message_format(m);
   return(owl_fmtext_get_text(&(m->fmtext->fmtext)));
 }
 
@@ -565,8 +566,9 @@
 }
 
 int owl_message_is_answered(owl_message *m) {
+  char *q;
   if(!owl_message_is_question(m)) return 0;
-  char * q = owl_message_get_attribute_value(m, "question");
+  q = owl_message_get_attribute_value(m, "question");
   if(!q) return 0;
   return !strcmp(q, "answered");
 }
@@ -812,6 +814,7 @@
 {
   struct hostent *hent;
   char *ptr, *tmp, *tmp2;
+  int len;
 
   owl_message_init(m);
   
@@ -840,7 +843,7 @@
   } else {
     owl_message_set_opcode(m, "");
   }
-  owl_message_set_zsig(m, n->z_message);
+  owl_message_set_zsig(m, owl_zephyr_get_zsig(n, &len));
 
   if ((ptr=strchr(n->z_recipient, '@'))!=NULL) {
     owl_message_set_realm(m, ptr+1);

Modified: branches/barnowl_sqlite/owl/obarray.c
===================================================================
--- branches/barnowl_sqlite/owl/obarray.c	2007-08-11 05:18:37 UTC (rev 754)
+++ branches/barnowl_sqlite/owl/obarray.c	2007-08-15 03:08:49 UTC (rev 755)
@@ -79,7 +79,7 @@
   owl_obarray oa;
   owl_obarray_init(&oa);
 
-  printf("BEGIN testing owl_obarray\n");
+  printf("# BEGIN testing owl_obarray\n");
 
   p = owl_obarray_insert(&oa, "test");
   FAIL_UNLESS("returned string is equal", p && !strcmp(p, "test"));
@@ -95,7 +95,7 @@
   p = owl_obarray_find(&oa, "nothere");
   FAIL_UNLESS("Didn't find a string that isn't there", p == NULL);
 
-  printf("END testing owl_obarray (%d failures)\n", numfailed);
+  printf("# END testing owl_obarray (%d failures)\n", numfailed);
 
   return numfailed;
 }

Modified: branches/barnowl_sqlite/owl/owl.c
===================================================================
--- branches/barnowl_sqlite/owl/owl.c	2007-08-11 05:18:37 UTC (rev 754)
+++ branches/barnowl_sqlite/owl/owl.c	2007-08-15 03:08:49 UTC (rev 755)
@@ -63,6 +63,13 @@
 
 owl_global g;
 
+char * owl_get_datadir() {
+    char * datadir = getenv("BARNOWL_DATA_DIR");
+    if(datadir != NULL)
+        return strchr(datadir, '=') + 1;
+    return DATADIR;
+}
+
 int main(int argc, char **argv, char **env)
 {
   WINDOW *recwin, *sepwin, *typwin, *msgwin;
@@ -72,6 +79,7 @@
   int newmsgs, nexttimediff;
   struct sigaction sigact;
   char *configfile, *tty, *perlout, *perlerr, **argvsave, buff[LINE], startupmsg[LINE];
+  char *confdir;
   owl_filter *f;
   owl_style *s;
   time_t nexttime, now;
@@ -86,6 +94,7 @@
   argcsave=argc;
   argvsave=argv;
   configfile=NULL;
+  confdir = NULL;
   tty=NULL;
   debug=0;
   initialsubs=1;
@@ -100,22 +109,31 @@
       argc--;
     } else if (!strcmp(argv[0], "-c")) {
       if (argc<2) {
-	fprintf(stderr, "Too few arguments to -c\n");
-	usage();
-	exit(1);
+        fprintf(stderr, "Too few arguments to -c\n");
+        usage();
+        exit(1);
       }
       configfile=argv[1];
       argv+=2;
       argc-=2;
     } else if (!strcmp(argv[0], "-t")) {
       if (argc<2) {
-	fprintf(stderr, "Too few arguments to -t\n");
-	usage();
-	exit(1);
+        fprintf(stderr, "Too few arguments to -t\n");
+        usage();
+        exit(1);
       }
       tty=argv[1];
       argv+=2;
       argc-=2;
+    } else if (!strcmp(argv[0], "-s")){
+      if (argc<2) {
+        fprintf(stderr, "Too few arguments to -s\n");
+        usage();
+        exit(1);
+      }
+      confdir = argv[1];
+      argv+=2;
+      argc-=2;
     } else if (!strcmp(argv[0], "-d")) {
       debug=1;
       argv++;
@@ -190,7 +208,8 @@
 
   /* owl global init */
   owl_global_init(&g);
-    if (debug) owl_global_set_debug_on(&g);
+  if (debug) owl_global_set_debug_on(&g);
+  if (confdir) owl_global_set_confdir(&g, confdir);
   owl_function_debugmsg("startup: first available debugging message");
   owl_global_set_startupargs(&g, argcsave, argvsave);
   owl_global_set_haveaim(&g);
@@ -212,9 +231,8 @@
 
   /* create the owl directory, in case it does not exist */
   owl_function_debugmsg("startup: creating owl directory, if not present");
-  dir=owl_sprintf("%s/%s", owl_global_get_homedir(&g), OWL_CONFIG_DIR);
+  dir=owl_global_get_confdir(&g);
   mkdir(dir, S_IRWXU);
-  owl_free(dir);
 
   /* set the tty, either from the command line, or by figuring it out */
   owl_function_debugmsg("startup: setting tty name");
@@ -258,7 +276,9 @@
    *  included.  Also, there should be an %aimme% */
   owl_function_debugmsg("startup: creating default filters");
   f=owl_malloc(sizeof(owl_filter));
-  owl_filter_init_fromstring(f, "personal", "isprivate ^true$");
+  owl_filter_init_fromstring(f, "personal", "isprivate ^true$ and ( not type ^zephyr$"
+                             " or ( class ^message and"
+                             " ( instance ^personal$ or instance ^urgent$ ) ) )");
   owl_list_append_element(owl_global_get_filterlist(&g), f);
 
   f=owl_malloc(sizeof(owl_filter));
@@ -696,13 +716,14 @@
 void usage()
 {
   fprintf(stderr, "Owl version %s\n", OWL_VERSION_STRING);
-  fprintf(stderr, "Usage: owl [-n] [-d] [-D] [-v] [-h] [-c <configfile>] [-t <ttyname>]\n");
+  fprintf(stderr, "Usage: owl [-n] [-d] [-D] [-v] [-h] [-c <configfile>] [-s <confdir>] [-t <ttyname>]\n");
   fprintf(stderr, "  -n      don't load zephyr subscriptions\n");
   fprintf(stderr, "  -d      enable debugging\n");
   fprintf(stderr, "  -D      enable debugging and delete previous debug file\n");
   fprintf(stderr, "  -v      print the Owl version number and exit\n");
   fprintf(stderr, "  -h      print this help message\n");
   fprintf(stderr, "  -c      specify an alternate config file\n");
+  fprintf(stderr, "  -s      specify an alternate config dir (default ~/.owl)\n");
   fprintf(stderr, "  -t      set the tty name\n");
 }
 

Modified: branches/barnowl_sqlite/owl/owl.h
===================================================================
--- branches/barnowl_sqlite/owl/owl.h	2007-08-11 05:18:37 UTC (rev 754)
+++ branches/barnowl_sqlite/owl/owl.h	2007-08-15 03:08:49 UTC (rev 755)
@@ -558,6 +558,8 @@
   int typwinactive;
   char *thishost;
   char *homedir;
+  char *confdir;
+  char *startupfile;
   int direction;
   int zaway;
   char *cur_zaway_msg;

Modified: branches/barnowl_sqlite/owl/perl/lib/BarnOwl/ModuleLoader.pm
===================================================================
--- branches/barnowl_sqlite/owl/perl/lib/BarnOwl/ModuleLoader.pm	2007-08-11 05:18:37 UTC (rev 754)
+++ branches/barnowl_sqlite/owl/perl/lib/BarnOwl/ModuleLoader.pm	2007-08-15 03:08:49 UTC (rev 755)
@@ -5,14 +5,17 @@
 
 use lib (BarnOwl::get_data_dir() . "/modules/");
 use PAR (BarnOwl::get_data_dir() . "/modules/*.par");
-use PAR ($ENV{HOME} . "/.owl/modules/*.par");
+use PAR (BarnOwl::get_config_dir() . "/modules/*.par");
 
 sub load_all {
     my %modules;
     my @modules;
+
+    my @moddirs = ();
+    push @moddirs, BarnOwl::get_data_dir() . "/modules";
+    push @moddirs, BarnOwl::get_config_dir() . "/modules";
     
-    for my $dir ( BarnOwl::get_data_dir() . "/modules",
-                  $ENV{HOME} . "/.owl/modules" ) {
+    for my $dir (@moddirs) {
         opendir(my $dh, $dir) or next;
         while(defined(my $f = readdir($dh))) {
             next if $f =~ /^\./;

Modified: branches/barnowl_sqlite/owl/perlconfig.c
===================================================================
--- branches/barnowl_sqlite/owl/perlconfig.c	2007-08-11 05:18:37 UTC (rev 754)
+++ branches/barnowl_sqlite/owl/perlconfig.c	2007-08-15 03:08:49 UTC (rev 755)
@@ -136,6 +136,7 @@
   I32 count, len;
   char *key,*val;
   HV * hash;
+  struct tm tm;
 
   hash = (HV*)SvRV(msg);
 
@@ -161,7 +162,6 @@
       owl_message_set_zwriteline(m, val);
     } else if (!strcmp(key, "time")) {
       m->timestr = owl_strdup(val);
-      struct tm tm;
       strptime(val, "%a %b %d %T %Y", &tm);
       m->time = mktime(&tm);
     } else {
@@ -444,6 +444,7 @@
 {
   int i, count;
   char * ret = NULL;
+  SV *rv;
   STRLEN n_a;
   dSP;
 
@@ -466,7 +467,7 @@
   } else {
     if(count != 1)
       croak("Perl command %s returned more than one value!", cmd->name);
-    SV * rv = POPs;
+    rv = POPs;
     if(SvTRUE(rv)) {
       ret = owl_strdup(SvPV(rv, n_a));
     }
@@ -487,12 +488,12 @@
 {
   SV *cb = (SV*)(e->cbdata);
   unsigned int n_a;
+  dSP;
+
   if(cb == NULL) {
     owl_function_error("Perl callback is NULL!");
   }
 
-  dSP;
-
   ENTER;
   SAVETMPS;
 
@@ -515,9 +516,9 @@
 
 void owl_perlconfig_mainloop()
 {
+  dSP;
   if (!owl_perlconfig_is_function("BarnOwl::Hooks::_mainloop_hook"))
     return;
-  dSP ;
   PUSHMARK(SP) ;
   call_pv("BarnOwl::Hooks::_mainloop_hook", G_DISCARD|G_EVAL);
   if(SvTRUE(ERRSV)) {

Modified: branches/barnowl_sqlite/owl/perlglue.xs
===================================================================
--- branches/barnowl_sqlite/owl/perlglue.xs	2007-08-11 05:18:37 UTC (rev 754)
+++ branches/barnowl_sqlite/owl/perlglue.xs	2007-08-15 03:08:49 UTC (rev 755)
@@ -198,10 +198,17 @@
 char * 
 get_data_dir ()
 	CODE:
-		RETVAL = (char *) DATADIR;
+		RETVAL = (char *) owl_get_datadir();
 	OUTPUT:
 	RETVAL
 
+char * 
+get_config_dir ()
+	CODE:
+		RETVAL = (char *) owl_global_get_confdir(&g);
+	OUTPUT:
+	RETVAL	
+
 void
 popless_text(text) 
 	char *text

Modified: branches/barnowl_sqlite/owl/perlwrap.pm
===================================================================
--- branches/barnowl_sqlite/owl/perlwrap.pm	2007-08-11 05:18:37 UTC (rev 754)
+++ branches/barnowl_sqlite/owl/perlwrap.pm	2007-08-15 03:08:49 UTC (rev 755)
@@ -20,9 +20,11 @@
     bootstrap BarnOwl 1.2;
 };
 
-use lib(get_data_dir()."/lib");
-use lib($ENV{HOME}."/.owl/lib");
+use lib(get_data_dir() . "/lib");
+use lib(get_config_dir() . "/lib");
 
+# perlconfig.c will set this to the value of the -c command-line
+# switch, if present.
 our $configfile;
 
 if(!$configfile && -f $ENV{HOME} . "/.barnowlconf") {
@@ -519,7 +521,7 @@
 
     if ( $m->is_loginout) {
         return format_login($m);
-    } elsif($m->is_ping) {
+    } elsif($m->is_ping && $m->is_personal) {
         return ( "\@b(PING) from \@b(" . $m->pretty_sender . ")\n" );
     } elsif($m->is_admin) {
         return "\@bold(OWL ADMIN)\n" . indentBody($m);
@@ -567,6 +569,9 @@
         $header .= ' / @b{' . $m->pretty_sender . '}';
     }
 
+    if($m->opcode) {
+        $header .= " [" . $m->opcode . "]";
+    }
     $header .= "  " . time_hhmm($m);
     my $sender = $m->long_sender;
     $sender =~ s/\n.*$//s;

Copied: branches/barnowl_sqlite/owl/t (from rev 754, trunk/owl/t)

Modified: branches/barnowl_sqlite/owl/test.h
===================================================================
--- branches/barnowl_sqlite/owl/test.h	2007-08-11 05:18:37 UTC (rev 754)
+++ branches/barnowl_sqlite/owl/test.h	2007-08-15 03:08:49 UTC (rev 755)
@@ -2,7 +2,7 @@
 #define __OWL_TEST_H__
 
 #define FAIL_UNLESS(desc,pred) do { int __pred = (pred);                \
-    printf("\t%-4s: %s", (__pred)?"ok":(numfailed++,"FAIL"), desc);     \
+    printf("%s %s", (__pred)?"ok":(numfailed++,"not ok"), desc);     \
     if(!(__pred)) printf("\t(%s:%d)", __FILE__, __LINE__); printf("%c", '\n'); } while(0)
 
 #endif

Modified: branches/barnowl_sqlite/owl/tester.c
===================================================================
--- branches/barnowl_sqlite/owl/tester.c	2007-08-11 05:18:37 UTC (rev 754)
+++ branches/barnowl_sqlite/owl/tester.c	2007-08-15 03:08:49 UTC (rev 755)
@@ -142,20 +142,28 @@
 }
 
 
+#define OWL_DICT_NTESTS  20
+#define OWL_UTIL_NTESTS  9
+#define OWL_OBARRAY_NTESTS  5
+#define OWL_VARIABLE_NTESTS  52
+#define OWL_FILTER_NTESTS  23
+
 int main(int argc, char **argv, char **env)
 {
   owl_errqueue_init(owl_global_get_errqueue(&g));
   owl_obarray_init(&(g.obarray));
 
   int numfailures=0;
-  if (argc==2 && 0==strcmp(argv[1],"reg")) {
+  if (argc==1 || (argc==2 && 0==strcmp(argv[1],"reg"))) {
+    printf("1..%d\n", OWL_UTIL_NTESTS+OWL_DICT_NTESTS+OWL_VARIABLE_NTESTS
+           +OWL_FILTER_NTESTS+OWL_OBARRAY_NTESTS);
     numfailures += owl_util_regtest();
     numfailures += owl_dict_regtest();
     numfailures += owl_variable_regtest();
     numfailures += owl_filter_regtest();
     numfailures += owl_obarray_regtest();
     if (numfailures) {
-      fprintf(stderr, "*** WARNING: %d failures total\n", numfailures);
+      fprintf(stderr, "# *** WARNING: %d failures total\n", numfailures);
     }
     return(numfailures);
   } else if (argc==2 && 0==strcmp(argv[1],"test1")) {

Modified: branches/barnowl_sqlite/owl/util.c
===================================================================
--- branches/barnowl_sqlite/owl/util.c	2007-08-11 05:18:37 UTC (rev 754)
+++ branches/barnowl_sqlite/owl/util.c	2007-08-15 03:08:49 UTC (rev 755)
@@ -758,7 +758,6 @@
 */
 char * owl_util_baseclass(char * class)
 {
-  char *ret;
   char *start, *end;
 
   start = class;
@@ -788,7 +787,7 @@
 {
   int numfailed=0;
 
-  printf("BEGIN testing owl_util\n");
+  printf("# BEGIN testing owl_util\n");
 
   FAIL_UNLESS("owl_util_substitute 1",
 	      !strcmp("foo", owl_text_substitute("foo", "", "Y")));
@@ -811,8 +810,8 @@
   FAIL_UNLESS("owl_util_uniq 3", 
 	      !strcmp("meep foo bar", owl_util_uniq("meep foo", "bar foo meep", "-")));
 
-  if (numfailed) printf("*** WARNING: failures encountered with owl_util\n");
-  printf("END testing owl_util (%d failures)\n", numfailed);
+  // if (numfailed) printf("*** WARNING: failures encountered with owl_util\n");
+  printf("# END testing owl_util (%d failures)\n", numfailed);
   return(numfailed);
 }
 

Modified: branches/barnowl_sqlite/owl/variable.c
===================================================================
--- branches/barnowl_sqlite/owl/variable.c	2007-08-11 05:18:37 UTC (rev 754)
+++ branches/barnowl_sqlite/owl/variable.c	2007-08-15 03:08:49 UTC (rev 755)
@@ -973,10 +973,11 @@
   owl_vardict vd;
   int numfailed=0;
   char buf[1024];
+  owl_variable * v;
 
   in_regtest = 1;
 
-  printf("BEGIN testing owl_variable\n");
+  printf("# BEGIN testing owl_variable\n");
   FAIL_UNLESS("setup", 0==owl_variable_dict_setup(&vd));
 
   FAIL_UNLESS("get bool", 0==owl_variable_get_bool(&vd,"rxping"));
@@ -1026,8 +1027,6 @@
   FAIL_UNLESS("set enum 9", -1==owl_variable_set_fromstring(&vd,"webbrowser","netscapey",0,0));
   FAIL_UNLESS("get enum 10", OWL_WEBBROWSER_NETSCAPE==owl_variable_get_int(&vd,"webbrowser"));
 
-  owl_variable * v;
-  
   owl_variable_dict_newvar_string(&vd, "stringvar", "", "", "testval");
   FAIL_UNLESS("get new string var", NULL != (v = owl_variable_get(&vd, "stringvar", OWL_VARIABLE_STRING)));
   FAIL_UNLESS("get new string val", !strcmp("testval", owl_variable_get_string(&vd, "stringvar")));
@@ -1048,8 +1047,8 @@
 
   owl_variable_dict_free(&vd);
 
-  if (numfailed) printf("*** WARNING: failures encountered with owl_variable\n");
-  printf("END testing owl_variable (%d failures)\n", numfailed);
+  // if (numfailed) printf("*** WARNING: failures encountered with owl_variable\n");
+  printf("# END testing owl_variable (%d failures)\n", numfailed);
   return(numfailed);
 }
 

Modified: branches/barnowl_sqlite/owl/zephyr.c
===================================================================
--- branches/barnowl_sqlite/owl/zephyr.c	2007-08-11 05:18:37 UTC (rev 754)
+++ branches/barnowl_sqlite/owl/zephyr.c	2007-08-15 03:08:49 UTC (rev 755)
@@ -327,6 +327,10 @@
   int i, count, save;
   char *out;
 
+  /* If there's no message here, just run along now */
+  if (n->z_message_len == 0)
+    return(owl_strdup(""));
+
   count=save=0;
   for (i=0; i<n->z_message_len; i++) {
     if (n->z_message[i]=='\0') {
@@ -362,6 +366,9 @@
 {
   int i, fields;
 
+  if(n->z_message_len == 0)
+    return 0;
+
   fields=1;
   for (i=0; i<n->z_message_len; i++) {
     if (n->z_message[i]=='\0') fields++;

Modified: branches/barnowl_sqlite/owl/zwrite.c
===================================================================
--- branches/barnowl_sqlite/owl/zwrite.c	2007-08-11 05:18:37 UTC (rev 754)
+++ branches/barnowl_sqlite/owl/zwrite.c	2007-08-15 03:08:49 UTC (rev 755)
@@ -124,6 +124,13 @@
     return(-1);
   }
 
+  if (z->class == NULL &&
+      z->inst == NULL &&
+      owl_list_get_size(&(z->recips))==0) {
+    owl_function_error("You must specify a recipient for zwrite");
+    return(-1);
+  }
+
   /* now deal with defaults */
   if (z->class==NULL) z->class=owl_strdup("message");
   if (z->inst==NULL) z->inst=owl_strdup("personal");
@@ -131,13 +138,6 @@
   if (z->opcode==NULL) z->opcode=owl_strdup("");
   /* z->message is allowed to stay NULL */
   
-  if (!strcasecmp(z->class, "message") &&
-      !strcasecmp(z->inst, "personal") &&
-      owl_list_get_size(&(z->recips))==0) {
-    owl_function_error("You must specify a recipient for zwrite");
-    return(-1);
-  }
-
   /* get a zsig, if not given */
   if (z->zsig==NULL) {
     zsigproc = owl_global_get_zsigproc(&g);


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