[426] in BarnOwl Developers

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

[D-O-H] r557 - trunk/owl

daemon@ATHENA.MIT.EDU (asedeno@MIT.EDU)
Thu Oct 29 18:06:01 2009

Resent-From: nelhage@mit.edu
Resent-To: barnowl-dev-mtg@charon.mit.edu
Date: Tue, 23 Jan 2007 23:49:15 -0500 (EST)
To: dirty-owl-hackers@mit.edu
From: asedeno@MIT.EDU
Reply-to: dirty-owl-hackers@MIT.EDU

Author: asedeno
Date: 2007-01-23 23:49:14 -0500 (Tue, 23 Jan 2007)
New Revision: 557

Modified:
   trunk/owl/configure
   trunk/owl/fmtext.c
   trunk/owl/global.c
   trunk/owl/owl.h
Log:
owl.h     - moved curses.h back up so building on Solaris would work.
configure - added test for resizeterm
global.c  - conditionally include resizeterm
fmtext.c  - remove tabs, rewrite parts of the colorpair manager



Modified: trunk/owl/configure
===================================================================
--- trunk/owl/configure	2007-01-24 02:56:58 UTC (rev 556)
+++ trunk/owl/configure	2007-01-24 04:49:14 UTC (rev 557)
@@ -2882,7 +2882,95 @@
 
 fi
 
+{ echo "$as_me:$LINENO: checking for resizeterm" >&5
+if test $ac_cv_lib_ncurses_initscr = yes; then
+echo $ECHO_N "checking for resizeterm in -lncurses... $ECHO_C" >&6; 
+else
+echo $ECHO_N "checking for resizeterm in -lcurses... $ECHO_C" >&6; 
+fi }
+if test "${ac_cv_lib_curses_resizeterm+set}" = set; then
+  echo $ECHO_N "(cached) $ECHO_C" >&6
+else
 
+cat >conftest.$ac_ext <<_ACEOF
+/* confdefs.h.  */
+_ACEOF
+cat confdefs.h >>conftest.$ac_ext
+cat >>conftest.$ac_ext <<_ACEOF
+/* end confdefs.h.  */
+
+/* Override any GCC internal prototype to avoid an error.
+   Use char because int might match the return type of a GCC
+   builtin and then its argument prototype would still apply.  */
+#ifdef __cplusplus
+extern "C"
+#endif
+char resizeterm ();
+int
+main ()
+{
+return resizeterm ();
+  ;
+  return 0;
+}
+_ACEOF
+rm -f conftest.$ac_objext conftest$ac_exeext
+if { (ac_try="$ac_link"
+case "(($ac_try" in
+  *\"* | *\`* | *\\*) ac_try_echo=\$ac_try;;
+  *) ac_try_echo=$ac_try;;
+esac
+eval "echo \"\$as_me:$LINENO: $ac_try_echo\"") >&5
+  (eval "$ac_link") 2>conftest.er1
+  ac_status=$?
+  grep -v '^ *+' conftest.er1 >conftest.err
+  rm -f conftest.er1
+  cat conftest.err >&5
+  echo "$as_me:$LINENO: \$? = $ac_status" >&5
+  (exit $ac_status); } &&
+	 { ac_try='test -z "$ac_c_werror_flag" || test ! -s conftest.err'
+  { (case "(($ac_try" in
+  *\"* | *\`* | *\\*) ac_try_echo=\$ac_try;;
+  *) ac_try_echo=$ac_try;;
+esac
+eval "echo \"\$as_me:$LINENO: $ac_try_echo\"") >&5
+  (eval "$ac_try") 2>&5
+  ac_status=$?
+  echo "$as_me:$LINENO: \$? = $ac_status" >&5
+  (exit $ac_status); }; } &&
+	 { ac_try='test -s conftest$ac_exeext'
+  { (case "(($ac_try" in
+  *\"* | *\`* | *\\*) ac_try_echo=\$ac_try;;
+  *) ac_try_echo=$ac_try;;
+esac
+eval "echo \"\$as_me:$LINENO: $ac_try_echo\"") >&5
+  (eval "$ac_try") 2>&5
+  ac_status=$?
+  echo "$as_me:$LINENO: \$? = $ac_status" >&5
+  (exit $ac_status); }; }; then
+  ac_cv_lib_curses_resizeterm=yes
+else
+  echo "$as_me: failed program was:" >&5
+sed 's/^/| /' conftest.$ac_ext >&5
+
+	ac_cv_lib_curses_resizeterm=no
+fi
+
+rm -f core conftest.err conftest.$ac_objext \
+      conftest$ac_exeext conftest.$ac_ext
+
+{ echo "$as_me:$LINENO: result: $ac_cv_lib_curses_resizeterm" >&5
+echo "${ECHO_T}$ac_cv_lib_curses_resizeterm" >&6; }
+
+if test $ac_cv_lib_curses_resizeterm = yes; then
+  cat >>confdefs.h <<_ACEOF
+#define HAVE_RESIZETERM 1
+_ACEOF
+
+fi
+
+fi
+
 { echo "$as_me:$LINENO: checking for com_err in -lcom_err" >&5
 echo $ECHO_N "checking for com_err in -lcom_err... $ECHO_C" >&6; }
 if test "${ac_cv_lib_com_err_com_err+set}" = set; then

Modified: trunk/owl/fmtext.c
===================================================================
--- trunk/owl/fmtext.c	2007-01-24 02:56:58 UTC (rev 556)
+++ trunk/owl/fmtext.c	2007-01-24 04:49:14 UTC (rev 557)
@@ -234,14 +234,15 @@
     /* set the color */
     /* warning, this is sort of a hack */
     if (owl_global_get_hascolors(&g)) {
-      int pair, fg, bg;
+      int fg, bg;
+      short pair;
       fg = f->fgcolorbuff[position];
       bg = f->bgcolorbuff[position];
       owl_function_debugmsg("waddstr: fg(%i) bg(%i).", fg, bg);
 
       pair = owl_fmtext_get_colorpair(fg, bg);
       if (pair != -1) {
-	wattron(w, COLOR_PAIR(pair));
+        wattron(w, COLOR_PAIR(pair));
       }
     }
 
@@ -410,8 +411,8 @@
 
     found++;
     _owl_fmtext_add_attr(f, OWL_FMTEXT_ATTR_REVERSE,
-			 ptr2 - f->textbuff,
-			 ptr2 - f->textbuff + len - 1);
+                         ptr2 - f->textbuff,
+                         ptr2 - f->textbuff + len - 1);
 
     ptr1=ptr2+len;
   }
@@ -463,101 +464,101 @@
 
       /* if we've hit our max stack depth, print the @ and move on */
       if (stacksize==32) {
-	owl_fmtext_append_attr(f, "@", curattrs, curcolor, OWL_COLOR_DEFAULT);
-	txtptr++;
-	continue;
+        owl_fmtext_append_attr(f, "@", curattrs, curcolor, OWL_COLOR_DEFAULT);
+        txtptr++;
+        continue;
       }
 
       /* if it's an @@, print an @ and continue */
       if (txtptr[1]=='@') {
-	owl_fmtext_append_attr(f, "@", curattrs, curcolor, OWL_COLOR_DEFAULT);
-	txtptr+=2;
-	continue;
+        owl_fmtext_append_attr(f, "@", curattrs, curcolor, OWL_COLOR_DEFAULT);
+        txtptr+=2;
+        continue;
       }
-	
+        
       /* if there's no opener, print the @ and continue */
       tmpptr=strpbrk(txtptr, "(<[{ ");
       if (!tmpptr || tmpptr[0]==' ') {
-	owl_fmtext_append_attr(f, "@", curattrs, curcolor, OWL_COLOR_DEFAULT);
-	txtptr++;
-	continue;
+        owl_fmtext_append_attr(f, "@", curattrs, curcolor, OWL_COLOR_DEFAULT);
+        txtptr++;
+        continue;
       }
 
       /* check what command we've got, push it on the stack, start
-	 using it, and continue ... unless it's a color command */
+         using it, and continue ... unless it's a color command */
       buff=owl_malloc(tmpptr-ptr+20);
       strncpy(buff, ptr, tmpptr-ptr);
       buff[tmpptr-ptr]='\0';
       if (!strcasecmp(buff, "@bold")) {
-	attrstack[stacksize]=OWL_FMTEXT_ATTR_BOLD;
-	chrstack[stacksize]=tmpptr[0];
-	stacksize++;
-	curattrs|=OWL_FMTEXT_ATTR_BOLD;
-	txtptr+=6;
-	owl_free(buff);
-	continue;
+        attrstack[stacksize]=OWL_FMTEXT_ATTR_BOLD;
+        chrstack[stacksize]=tmpptr[0];
+        stacksize++;
+        curattrs|=OWL_FMTEXT_ATTR_BOLD;
+        txtptr+=6;
+        owl_free(buff);
+        continue;
       } else if (!strcasecmp(buff, "@b")) {
-	attrstack[stacksize]=OWL_FMTEXT_ATTR_BOLD;
-	chrstack[stacksize]=tmpptr[0];
-	stacksize++;
-	curattrs|=OWL_FMTEXT_ATTR_BOLD;
-	txtptr+=3;
-	owl_free(buff);
-	continue;
+        attrstack[stacksize]=OWL_FMTEXT_ATTR_BOLD;
+        chrstack[stacksize]=tmpptr[0];
+        stacksize++;
+        curattrs|=OWL_FMTEXT_ATTR_BOLD;
+        txtptr+=3;
+        owl_free(buff);
+        continue;
       } else if (!strcasecmp(buff, "@i")) {
-	attrstack[stacksize]=OWL_FMTEXT_ATTR_UNDERLINE;
-	chrstack[stacksize]=tmpptr[0];
-	stacksize++;
-	curattrs|=OWL_FMTEXT_ATTR_UNDERLINE;
-	txtptr+=3;
-	owl_free(buff);
-	continue;
+        attrstack[stacksize]=OWL_FMTEXT_ATTR_UNDERLINE;
+        chrstack[stacksize]=tmpptr[0];
+        stacksize++;
+        curattrs|=OWL_FMTEXT_ATTR_UNDERLINE;
+        txtptr+=3;
+        owl_free(buff);
+        continue;
       } else if (!strcasecmp(buff, "@italic")) {
-	attrstack[stacksize]=OWL_FMTEXT_ATTR_UNDERLINE;
-	chrstack[stacksize]=tmpptr[0];
-	stacksize++;
-	curattrs|=OWL_FMTEXT_ATTR_UNDERLINE;
-	txtptr+=8;
-	owl_free(buff);
-	continue;
+        attrstack[stacksize]=OWL_FMTEXT_ATTR_UNDERLINE;
+        chrstack[stacksize]=tmpptr[0];
+        stacksize++;
+        curattrs|=OWL_FMTEXT_ATTR_UNDERLINE;
+        txtptr+=8;
+        owl_free(buff);
+        continue;
 
-	/* if it's a color read the color, set the current color and
+        /* if it's a color read the color, set the current color and
            continue */
       } else if (!strcasecmp(buff, "@color") 
-		 && owl_global_get_hascolors(&g)
-		 && owl_global_is_colorztext(&g)) {
-	owl_free(buff);
-	txtptr+=7;
-	tmpptr=strpbrk(txtptr, "@{[<()>]}");
-	if (tmpptr &&
-	    ((txtptr[-1]=='(' && tmpptr[0]==')') ||
-	     (txtptr[-1]=='<' && tmpptr[0]=='>') ||
-	     (txtptr[-1]=='[' && tmpptr[0]==']') ||
-	     (txtptr[-1]=='{' && tmpptr[0]=='}'))) {
+                 && owl_global_get_hascolors(&g)
+                 && owl_global_is_colorztext(&g)) {
+        owl_free(buff);
+        txtptr+=7;
+        tmpptr=strpbrk(txtptr, "@{[<()>]}");
+        if (tmpptr &&
+            ((txtptr[-1]=='(' && tmpptr[0]==')') ||
+             (txtptr[-1]=='<' && tmpptr[0]=='>') ||
+             (txtptr[-1]=='[' && tmpptr[0]==']') ||
+             (txtptr[-1]=='{' && tmpptr[0]=='}'))) {
 
-	  /* grab the color name */
-	  buff=owl_malloc(tmpptr-txtptr+20);
-	  strncpy(buff, txtptr, tmpptr-txtptr);
-	  buff[tmpptr-txtptr]='\0';
+          /* grab the color name */
+          buff=owl_malloc(tmpptr-txtptr+20);
+          strncpy(buff, txtptr, tmpptr-txtptr);
+          buff[tmpptr-txtptr]='\0';
 
-	  /* set it as the current color */
-	  curcolor=owl_util_string_to_color(buff);
-	  if (curcolor==-1) curcolor=OWL_COLOR_DEFAULT;
-	  owl_free(buff);
-	  txtptr=tmpptr+1;
-	  continue;
+          /* set it as the current color */
+          curcolor=owl_util_string_to_color(buff);
+          if (curcolor==-1) curcolor=OWL_COLOR_DEFAULT;
+          owl_free(buff);
+          txtptr=tmpptr+1;
+          continue;
 
-	} else {
+        } else {
 
-	}
+        }
 
       } else {
-	/* if we didn't understand it, we'll print it.  This is different from zwgc
-	 * but zwgc seems to be smarter about some screw cases than I am
-	 */
-	owl_fmtext_append_attr(f, "@", curattrs, curcolor, OWL_COLOR_DEFAULT);
-	txtptr++;
-	continue;
+        /* if we didn't understand it, we'll print it.  This is different from zwgc
+         * but zwgc seems to be smarter about some screw cases than I am
+         */
+        owl_fmtext_append_attr(f, "@", curattrs, curcolor, OWL_COLOR_DEFAULT);
+        txtptr++;
+        continue;
       }
 
     } else if (ptr[0]=='}' || ptr[0]==']' || ptr[0]==')' || ptr[0]=='>') {
@@ -573,38 +574,38 @@
 
       /* first, if the stack is empty we must bail (just print and go) */
       if (stacksize==0) {
-	buff=owl_malloc(5);
-	buff[0]=ptr[0];
-	buff[1]='\0';
-	owl_fmtext_append_attr(f, buff, curattrs, curcolor, OWL_COLOR_DEFAULT);
-	owl_free(buff);
-	txtptr++;
-	continue;
+        buff=owl_malloc(5);
+        buff[0]=ptr[0];
+        buff[1]='\0';
+        owl_fmtext_append_attr(f, buff, curattrs, curcolor, OWL_COLOR_DEFAULT);
+        owl_free(buff);
+        txtptr++;
+        continue;
       }
 
       /* if the closing char is what's on the stack, turn off the
          attribue and pop the stack */
       if ((ptr[0]==')' && chrstack[stacksize-1]=='(') ||
-	  (ptr[0]=='>' && chrstack[stacksize-1]=='<') ||
-	  (ptr[0]==']' && chrstack[stacksize-1]=='[') ||
-	  (ptr[0]=='}' && chrstack[stacksize-1]=='{')) {
-	int i;
-	stacksize--;
-	curattrs=OWL_FMTEXT_ATTR_NONE;
-	for (i=0; i<stacksize; i++) {
-	  curattrs|=attrstack[i];
-	}
-	txtptr+=1;
-	continue;
+          (ptr[0]=='>' && chrstack[stacksize-1]=='<') ||
+          (ptr[0]==']' && chrstack[stacksize-1]=='[') ||
+          (ptr[0]=='}' && chrstack[stacksize-1]=='{')) {
+        int i;
+        stacksize--;
+        curattrs=OWL_FMTEXT_ATTR_NONE;
+        for (i=0; i<stacksize; i++) {
+          curattrs|=attrstack[i];
+        }
+        txtptr+=1;
+        continue;
       } else {
-	/* otherwise print and continue */
-	buff=owl_malloc(5);
-	buff[0]=ptr[0];
-	buff[1]='\0';
-	owl_fmtext_append_attr(f, buff, curattrs, curcolor, OWL_COLOR_DEFAULT);
-	owl_free(buff);
-	txtptr++;
-	continue;
+        /* otherwise print and continue */
+        buff=owl_malloc(5);
+        buff[0]=ptr[0];
+        buff[1]='\0';
+        owl_fmtext_append_attr(f, buff, curattrs, curcolor, OWL_COLOR_DEFAULT);
+        owl_free(buff);
+        txtptr++;
+        continue;
       }
     } else {
       /* we've found an unattached opener, print everything and move on */
@@ -635,8 +636,8 @@
     if (elem && format_fn) {
       text = format_fn(elem);
       if (text) {
-	owl_fmtext_append_normal(f, text);
-	owl_free(text);
+        owl_fmtext_append_normal(f, text);
+        owl_free(text);
       }
     } else if (elem) {
       owl_fmtext_append_normal(f, elem);
@@ -683,44 +684,45 @@
 }
 
 /* Assign pairs by request */
-int owl_fmtext_get_colorpair(int fg, int bg)
+short owl_fmtext_get_colorpair(int fg, int bg)
 {
   owl_colorpair_mgr *cpmgr;
-  short pair, i;
+  short pair, i, default_bg;
+
+#ifdef HAVE_USE_DEFAULT_COLORS
   if (fg == OWL_COLOR_DEFAULT) fg = -1;
-  if (bg == OWL_COLOR_DEFAULT) {
+  default_bg = OWL_COLOR_DEFAULT;
+#else
+  if (fg == OWL_COLOR_DEFAULT) fg = 0;
+  if (bg == OWL_COLOR_DEFAULT) bg = 0;
+  default_bg = COLOR_BLACK;
+#endif
+
+  if (bg == default_bg) {
+    // default bg -> use color pairs initialized by owl.c
     pair = fg;
   } else {
+    // looking for a pair we already set up for this draw.
     cpmgr = owl_global_get_colorpair_mgr(&g);
     pair = cpmgr->pairs[fg+1][bg];
-    if (pair != -1) {
-      short oldfg, oldbg;
-      pair_content(pair, &oldfg, &oldbg);
-      if (cpmgr->pairs[oldfg+1][oldbg] == pair) {
-        cpmgr->pairs[oldfg+1][oldbg] = -1;
-      }
-      init_pair(pair, fg, bg);
-      cpmgr->pairs[fg+1][bg] = pair;
-      cpmgr->used[pair] = 1;
-    } else {
+    if (!(pair != -1 && cpmgr->used[pair])) {
+      // If we didn't find a pair, search for a free one to assign.
       // Skip the first COLORS, since they're static.
+      // If we ever get 256 color curses, this will need more thought.
       for(i = COLORS; i < COLOR_PAIRS; i++) {
-        if (0 == cpmgr->used[i]) {
+        if (!cpmgr->used[i]) {
+          // Found a free pair
           pair = i;
           break;
         }
       }
       if (pair != -1) {
-        short oldfg, oldbg;
-        pair_content(pair, &oldfg, &oldbg);
-        if (cpmgr->pairs[oldfg+1][oldbg] == pair) {
-          cpmgr->pairs[oldfg+1][oldbg] = -1;
-        }
+        // We found a free pair, initialize it.
         init_pair(pair, fg, bg);
         cpmgr->pairs[fg+1][bg] = pair;
         cpmgr->used[pair] = 1;
       } else {
-        // Fail to skipping background.
+        // We still don't have a pair, drop the background color. Too bad.
         pair = fg;
       }
     }

Modified: trunk/owl/global.c
===================================================================
--- trunk/owl/global.c	2007-01-24 02:56:58 UTC (rev 556)
+++ trunk/owl/global.c	2007-01-24 04:49:14 UTC (rev 557)
@@ -393,7 +393,9 @@
     g->cols=y;
   }
 
+#ifdef HAVE_RESIZETERM
   resizeterm(size.ws_row, size.ws_col);
+#endif
 
   /* re-initialize the windows */
   _owl_global_setup_windows(g);

Modified: trunk/owl/owl.h
===================================================================
--- trunk/owl/owl.h	2007-01-24 02:56:58 UTC (rev 556)
+++ trunk/owl/owl.h	2007-01-24 04:49:14 UTC (rev 557)
@@ -40,6 +40,9 @@
 #ifndef INC_OWL_H
 #define INC_OWL_H
 
+#ifndef OWL_PERL
+#include <curses.h>
+#endif
 #include <sys/param.h>
 #include <EXTERN.h>
 #include <netdb.h>
@@ -62,7 +65,6 @@
 #include <perl.h>
 #include "XSUB.h"
 #else
-#include <curses.h>
 typedef void SV;
 #endif
 


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