[868] in BarnOwl Developers

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

[D-O-H] r857 - branches/barnowl_sqlite/owl

daemon@ATHENA.MIT.EDU (nelhage@MIT.EDU)
Thu Oct 29 18:10:34 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: Sat, 12 Jan 2008 20:12:01 -0500 (EST)

Author: nelhage
Date: 2008-01-12 20:12:01 -0500 (Sat, 12 Jan 2008)
New Revision: 857

Modified:
   branches/barnowl_sqlite/owl/commands.c
   branches/barnowl_sqlite/owl/functions.c
   branches/barnowl_sqlite/owl/global.c
   branches/barnowl_sqlite/owl/perlconfig.c
Log:
Abstract around getting the current message in C

Modified: branches/barnowl_sqlite/owl/commands.c
===================================================================
--- branches/barnowl_sqlite/owl/commands.c	2008-01-13 00:06:34 UTC (rev 856)
+++ branches/barnowl_sqlite/owl/commands.c	2008-01-13 01:12:01 UTC (rev 857)
@@ -2015,9 +2015,7 @@
     owl_function_reply(1, !edit);
   } else if (argc==2 && !strcmp(argv[1], "zaway")) {
     owl_message *m;
-    owl_view    *v;
-    v = owl_global_get_current_view(&g);    
-    m = owl_view_get_element(v, owl_global_get_curmsg(&g));
+    m = owl_global_get_current_message(&g);
     if (m) owl_zephyr_zaway(m);
   } else {
     owl_function_makemsg("Invalid arguments to the reply command.");
@@ -2584,18 +2582,16 @@
 void owl_command_yes(void)
 {
   owl_message *m;
-  owl_view *v;
   char *cmd;
 
-  v = owl_global_get_current_view(&g);
+  m = owl_global_get_current_message(&g);
 
   /* bail if there's no current message */
-  if (owl_view_get_size(v) < 1) {
+  if (m == NULL) {
     owl_function_error("No current message.");
     return;
   }
 
-  m = owl_view_get_element(v, owl_global_get_curmsg(&g));
   if(!owl_message_is_question(m)) {
     owl_function_error("That message isn't a question.");
     return;
@@ -2618,18 +2614,16 @@
 void owl_command_no(void)
 {
   owl_message *m;
-  owl_view *v;
   char *cmd;
 
-  v = owl_global_get_current_view(&g);
+  m = owl_global_get_current_message(&g);
 
   /* bail if there's no current message */
-  if (owl_view_get_size(v) < 1) {
+  if (m == NULL) {
     owl_function_error("No current message.");
     return;
   }
 
-  m = owl_view_get_element(v, owl_global_get_curmsg(&g));
   if(!owl_message_is_question(m)) {
     owl_function_error("That message isn't a question.");
     return;

Modified: branches/barnowl_sqlite/owl/functions.c
===================================================================
--- branches/barnowl_sqlite/owl/functions.c	2008-01-13 00:06:34 UTC (rev 856)
+++ branches/barnowl_sqlite/owl/functions.c	2008-01-13 01:12:01 UTC (rev 857)
@@ -1005,7 +1005,6 @@
 {
   /* visit the first url in the current message */
   owl_message *m;
-  owl_view *v;
   char *ptr1, *ptr2, *text, url[LINE], tmpbuff[LINE];
   int webbrowser;
 
@@ -1016,11 +1015,9 @@
     return;
   }
 
-  v=owl_global_get_current_view(&g);
-  
-  m=owl_view_get_element(v, owl_global_get_curmsg(&g));
+  m = owl_global_get_current_message(&g);
 
-  if (!m || owl_view_get_size(v)==0) {
+  if (!m) {
     owl_function_error("No current message selected");
     return;
   }
@@ -1484,16 +1481,14 @@
   owl_message *m;
   owl_fmtext fm, attrfm;
   char buff[10000];
-  owl_view *v;
 #ifdef HAVE_LIBZEPHYR
   ZNotice_t *n;
 #endif
 
   owl_fmtext_init_null(&fm);
   
-  v=owl_global_get_current_view(&g);
-  m=owl_view_get_element(v, owl_global_get_curmsg(&g));
-  if (!m || owl_view_get_size(v)==0) {
+  m=owl_global_get_current_message(&g);
+  if (!m) {
     owl_function_error("No message selected\n");
     return;
   }
@@ -1656,18 +1651,16 @@
 void owl_function_curmsg_to_popwin()
 {
   owl_popwin *pw;
-  owl_view *v;
   owl_message *m;
   owl_style *s;
   owl_fmtext fm;
 
-  v=owl_global_get_current_view(&g);
   s=owl_global_get_style_by_name(&g, "default");
   pw=owl_global_get_popwin(&g);
 
-  m=owl_view_get_element(v, owl_global_get_curmsg(&g));
+  m = owl_global_get_current_message(&g);
 
-  if (!m || owl_view_get_size(v)==0) {
+  if (!m) {
     owl_function_error("No current message");
     return;
   }
@@ -2037,7 +2030,7 @@
   } else {
     char *class, *inst, *to, *cc=NULL;
     
-    m=owl_view_get_element(owl_global_get_current_view(&g), owl_global_get_curmsg(&g));
+    m = owl_global_get_current_message(&g);
     if (!m) {
       owl_function_error("No message selected");
       return;
@@ -2803,15 +2796,13 @@
  */
 char *owl_function_smartfilter(int type)
 {
-  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));
+  m = owl_global_get_current_message(&g);
 
-  if (!m || owl_view_get_size(v)==0) {
+  if (!m) {
     owl_function_error("No message selected\n");
     return(NULL);
   }
@@ -2875,14 +2866,12 @@
 {
   /* Starts a zpunt command based on the current class,instance pair. 
    * If type=0, uses just class.  If type=1, uses instance as well. */
-  owl_view *v;
   owl_message *m;
   char *cmd, *cmdprefix, *mclass, *minst;
   
-  v=owl_global_get_current_view(&g);
-  m=owl_view_get_element(v, owl_global_get_curmsg(&g));
+  m = owl_global_get_current_message(&g);
 
-  if (!m || owl_view_get_size(v)==0) {
+  if (!m) {
     owl_function_error("No message selected\n");
     return;
   }

Modified: branches/barnowl_sqlite/owl/global.c
===================================================================
--- branches/barnowl_sqlite/owl/global.c	2008-01-13 00:06:34 UTC (rev 856)
+++ branches/barnowl_sqlite/owl/global.c	2008-01-13 01:12:01 UTC (rev 857)
@@ -629,6 +629,12 @@
   return(&(g->current_view));
 }
 
+owl_message *owl_global_get_current_message(owl_global *g) {
+  owl_view *cur = owl_global_get_current_view(g);
+  if(owl_view_get_size(cur) < 1) return NULL;
+  return owl_view_get_element(cur, owl_global_get_curmsg(g));
+}
+
 /* has colors */
 
 int owl_global_get_hascolors(owl_global *g) {

Modified: branches/barnowl_sqlite/owl/perlconfig.c
===================================================================
--- branches/barnowl_sqlite/owl/perlconfig.c	2008-01-13 00:06:34 UTC (rev 856)
+++ branches/barnowl_sqlite/owl/perlconfig.c	2008-01-13 01:12:01 UTC (rev 857)
@@ -32,14 +32,11 @@
 
 SV *owl_perlconfig_curmessage2hashref(void) /*noproto*/
 {
-  int curmsg;
-  owl_view *v;
-  v=owl_global_get_current_view(&g);
-  if (owl_view_get_size(v) < 1) {
+  owl_message *m = owl_global_get_current_message(&g);
+  if(m == NULL) {
     return &PL_sv_undef;
   }
-  curmsg=owl_global_get_curmsg(&g);
-  return owl_perlconfig_message2hashref(owl_view_get_element(v, curmsg));
+  return owl_perlconfig_message2hashref(m);
 }
 
 owl_message * owl_perlconfig_hashref2message(SV *msg)
@@ -52,7 +49,8 @@
 char *owl_perlconfig_call_with_message(char *subname, owl_message *m)
 {
   dSP ;
-  int count, len;
+  int count;
+  unsigned int len;
   SV *msgref, *srv;
   char *out, *preout;
   
@@ -335,7 +333,7 @@
 
   if(SvTRUE(ERRSV)) {
     owl_function_error("%s", SvPV(ERRSV, n_a));
-    POPs;
+    (void)POPs;
   } else {
     if(count != 1)
       croak("Perl command %s returned more than one value!", cmd->name);


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