Changes to make Tweak compile on Mac OS X (still as a Unix/curses
authorsimon <simon@cda61777-01e9-0310-a592-d414129be87e>
Tue, 25 Jan 2005 23:53:57 +0000 (23:53 +0000)
committersimon <simon@cda61777-01e9-0310-a592-d414129be87e>
Tue, 25 Jan 2005 23:53:57 +0000 (23:53 +0000)
application, of course). A couple of declarations and prototypes had
to be moved higher up main.c (Apple's gcc installation is pleasingly
pedantic, and I'm not quite sure how I got away with the previous
code for so long!), and I've also had to arrange that Tweak can cope
with curses being unwilling to allocate colour pairs.

git-svn-id: svn://svn.tartarus.org/sgt/tweak@5211 cda61777-01e9-0310-a592-d414129be87e

curses.c
main.c
slang.c
tweak.h

index ea8b5ac..9b4a37e 100644 (file)
--- a/curses.c
+++ b/curses.c
@@ -62,7 +62,7 @@ void display_write_chars(char *str, int len)
 #define MAXCOLOURS 32
 int attrs[MAXCOLOURS];
 
-void display_define_colour(int colour, int fg, int bg)
+void display_define_colour(int colour, int fg, int bg, int reverse)
 {
     static int colours[8] = {
         COLOR_BLACK,
@@ -78,10 +78,15 @@ void display_define_colour(int colour, int fg, int bg)
     if (fg < 0 && bg < 0) {
         attrs[colour] = 0;
     } else {
-        assert(colour >= 0 && colour < MAXCOLOURS && colour < COLOR_PAIRS-2);
+        assert(colour >= 0 && colour < MAXCOLOURS);
         assert(!(bg & ~7));            /* bold backgrounds are nonportable */
-        init_pair(colour+1, colours[fg & 7], colours[bg]);
-        attrs[colour] = (fg & 8 ? A_BOLD : 0) | COLOR_PAIR(colour+1);
+       if (colour < COLOR_PAIRS-2) {
+           init_pair(colour+1, colours[fg & 7], colours[bg]);
+           attrs[colour] = (fg & 8 ? A_BOLD : 0) | COLOR_PAIR(colour+1);
+       } else {
+           /* can't allocate a colour pair, so we just use b&w attrs */
+           attrs[colour] = (fg & 8 ? A_BOLD : 0) | (reverse ? A_REVERSE : 0);
+       }
     }
 }
 
diff --git a/main.c b/main.c
index adb3254..9875d5a 100644 (file)
--- a/main.c
+++ b/main.c
@@ -251,11 +251,11 @@ static void init(void) {
 
     display_setup();
 
-    display_define_colour(COL_BUFFER, -1, -1);
-    display_define_colour(COL_SELECT, 0, 7);
-    display_define_colour(COL_STATUS, 11, 4);
-    display_define_colour(COL_ESCAPE, 9, 0);
-    display_define_colour(COL_INVALID, 11, 0);
+    display_define_colour(COL_BUFFER, -1, -1, FALSE);
+    display_define_colour(COL_SELECT, 0, 7, TRUE);
+    display_define_colour(COL_STATUS, 11, 4, TRUE);
+    display_define_colour(COL_ESCAPE, 9, 0, FALSE);
+    display_define_colour(COL_INVALID, 11, 0, FALSE);
 
     for (i=0; i<256; i++) {
        sprintf(hex[i], "%02X", i);
@@ -546,6 +546,9 @@ void draw_scr (void) {
     display_refresh ();
 }
 
+volatile int safe_update, update_required;
+void update (void);
+
 /*
  * Get a string, in the "minibuffer". Return TRUE on success, FALSE
  * on break. Possibly syntax-highlight the entered string for
@@ -669,8 +672,6 @@ void suspend(void) {
 #endif
 }
 
-volatile int safe_update, update_required;
-
 void update (void) {
     display_recheck_size();
     fix_offset ();
diff --git a/slang.c b/slang.c
index a6e0b37..3a0d24b 100644 (file)
--- a/slang.c
+++ b/slang.c
@@ -109,7 +109,7 @@ void display_write_chars(char *str, int len)
     SLsmg_write_nchars(str, len);
 }
 
-void display_define_colour(int colour, int fg, int bg)
+void display_define_colour(int colour, int fg, int bg, int reverse)
 {
     static char *colours[16] = {
        "black", "red", "green", "brown",
diff --git a/tweak.h b/tweak.h
index f9ea9eb..956dccf 100644 (file)
--- a/tweak.h
+++ b/tweak.h
@@ -101,7 +101,7 @@ extern void display_moveto(int y, int x);
 extern void display_refresh(void);
 extern void display_write_str(char *str);
 extern void display_write_chars(char *str, int len);
-extern void display_define_colour(int colour, int fg, int bg);
+extern void display_define_colour(int colour, int fg, int bg, int reverse);
 extern void display_set_colour(int colour);
 extern void display_clear_to_eol(void);
 extern int display_getkey(void);