libpayload: fix wborder()
[coreboot.git] / payloads / libpayload / curses / tinycurses.c
index 6e83e670645356cacaf86813b4be39a211d869cd..fb492b6cea73889eed5004c3e7bc7dd74b1d3db9 100644 (file)
@@ -3,7 +3,7 @@
  *
  * Copyright (C) 2007 Uwe Hermann <uwe@hermann-uwe.de>
  * Copyright (C) 2008 Ulf Jordan <jordan@chalmers.se>
- * Copyright (C) 2008 coresystems GmbH
+ * Copyright (C) 2008-2009 coresystems GmbH
  *
  * Redistribution and use in source and binary forms, with or without
  * modification, are permitted provided that the following conditions
@@ -191,7 +191,9 @@ NCURSES_CH_T _nc_render(WINDOW *win, NCURSES_CH_T ch)
 int beep(void)
 {
        /* TODO: Flash the screen if beeping fails? */
+#ifdef CONFIG_SPEAKER
        speaker_tone(1760, 500);        /* 1760 == note A6 */
+#endif
        return OK;
 }
 // bool can_change_color(void) {}
@@ -232,6 +234,7 @@ int delwin(WINDOW *win)
 }
 WINDOW *derwin(WINDOW *orig, int num_lines, int num_columns, int begy, int begx)
 {
+#if 0
        WINDOW *win = NULL;
        int i;
        int flags = _SUBWIN;
@@ -255,9 +258,9 @@ WINDOW *derwin(WINDOW *orig, int num_lines, int num_columns, int begy, int begx)
                flags |= _ISPAD;
 
        // FIXME
-       //// if ((win = _nc_makenew(num_lines, num_columns, orig->_begy + begy,
-       ////                        orig->_begx + begx, flags)) == 0)
-       ////     return NULL;
+       if ((win = _nc_makenew(num_lines, num_columns, orig->_begy + begy,
+                               orig->_begx + begx, flags)) == 0)
+            return NULL;
 
        win->_pary = begy;
        win->_parx = begx;
@@ -270,6 +273,9 @@ WINDOW *derwin(WINDOW *orig, int num_lines, int num_columns, int begy, int begx)
        win->_parent = orig;
 
        return win;
+#else
+       return NULL;
+#endif
 }
 int doupdate(void) { /* TODO */ return(0); }
 // WINDOW * dupwin (WINDOW *) {}
@@ -323,7 +329,7 @@ WINDOW *initscr(void)
 
        // Speaker init?
 
-       stdscr = newwin(SCREEN_Y, SCREEN_X + 1, 0, 0);
+       stdscr = newwin(SCREEN_Y, SCREEN_X, 0, 0);
        // TODO: curscr, newscr?
 
        werase(stdscr);
@@ -495,7 +501,7 @@ int waddch(WINDOW *win, const chtype ch)
        // NCURSES_CH_T wch;
        // SetChar2(wch, ch);
 
-       if (win->_line[win->_cury].firstchar == _NOCHANGE || 
+       if (win->_line[win->_cury].firstchar == _NOCHANGE ||
                        win->_line[win->_cury].firstchar > win->_curx)
                win->_line[win->_cury].firstchar = win->_curx;
 
@@ -506,7 +512,7 @@ int waddch(WINDOW *win, const chtype ch)
        win->_line[win->_cury].text[win->_curx].attr |=
                ((ch) & (chtype)A_ATTRIBUTES);
 
-       if (win->_line[win->_cury].lastchar == _NOCHANGE || 
+       if (win->_line[win->_cury].lastchar == _NOCHANGE ||
                        win->_line[win->_cury].lastchar < win->_curx)
                win->_line[win->_cury].lastchar = win->_curx;
 
@@ -531,7 +537,7 @@ int waddnstr(WINDOW *win, const char *astr, int n)
        if (n < 0)
                n = strlen(astr);
 
-       if (win->_line[win->_cury].firstchar == _NOCHANGE || 
+       if (win->_line[win->_cury].firstchar == _NOCHANGE ||
                        win->_line[win->_cury].firstchar > win->_curx)
                win->_line[win->_cury].firstchar = win->_curx;
 
@@ -550,7 +556,7 @@ int waddnstr(WINDOW *win, const char *astr, int n)
                // }
        }
 
-       if (win->_line[win->_cury].lastchar == _NOCHANGE || 
+       if (win->_line[win->_cury].lastchar == _NOCHANGE ||
                        win->_line[win->_cury].lastchar < win->_curx)
                win->_line[win->_cury].lastchar = win->_curx;
 
@@ -578,6 +584,15 @@ int wborder(WINDOW *win, chtype ls, chtype rs, chtype ts, chtype bs,
 {
        int x, y;
 
+       if (ls == 0) ls = ACS_VLINE;
+       if (rs == 0) rs = ACS_VLINE;
+       if (ts == 0) ts = ACS_HLINE;
+       if (bs == 0) bs = ACS_HLINE;
+       if (tl == 0) tl = ACS_ULCORNER;
+       if (tr == 0) tr = ACS_URCORNER;
+       if (bl == 0) bl = ACS_LLCORNER;
+       if (br == 0) br = ACS_LRCORNER;
+
        for(y = 0; y <= win->_maxy; y++) {
 
                if (y == 0) {
@@ -614,7 +629,7 @@ int wborder(WINDOW *win, chtype ls, chtype rs, chtype ts, chtype bs,
        return OK;
 }
 // int wclrtobot (WINDOW *) {}
-int wclrtoeol(WINDOW *win) { /* TODO */ return(*(int *)0); }
+int wclrtoeol(WINDOW *win) { /* TODO */ return ERR; }
 int wcolor_set(WINDOW *win, short color_pair_number, void *opts)
 {
        if (!opts && (color_pair_number >= 0)
@@ -736,9 +751,6 @@ int wnoutrefresh(WINDOW *win)
                for (x = win->_line[y].firstchar; x <= win->_line[y].lastchar; x++) {
                        attr_t attr = win->_line[y].text[x].attr;
 
-                       unsigned int c =
-                               ((int)color_pairs[PAIR_NUMBER(attr)]) << 8;
-
 #ifdef CONFIG_SERIAL_CONSOLE
                        if (curses_flags & F_ENABLE_SERIAL) {
                                ch = win->_line[y].text[x].chars[0];
@@ -806,6 +818,9 @@ int wnoutrefresh(WINDOW *win)
                        }
 #endif
 #ifdef CONFIG_VIDEO_CONSOLE
+                       unsigned int c =
+                               ((int)color_pairs[PAIR_NUMBER(attr)]) << 8;
+
                        c = SWAP_RED_BLUE(c);
 
                        if (curses_flags & F_ENABLE_CONSOLE) {
@@ -920,7 +935,7 @@ int wscrl(WINDOW *win, int n)
                win->_line[y].firstchar = win->_line[y + n].firstchar;
                win->_line[y].lastchar = win->_line[y + n].lastchar;
                for (x = 0; x <= win->_maxx; x++) {
-                       if ((win->_line[y].text[x].chars[0] != win->_line[y + n].text[x].chars[0]) || 
+                       if ((win->_line[y].text[x].chars[0] != win->_line[y + n].text[x].chars[0]) ||
                                        (win->_line[y].text[x].attr != win->_line[y + n].text[x].attr)) {
                                if (win->_line[y].firstchar == _NOCHANGE)
                                        win->_line[y].firstchar = x;
@@ -935,7 +950,7 @@ int wscrl(WINDOW *win, int n)
 
        for (y = (win->_maxy+1 - n); y <= win->_maxy; y++) {
                for (x = 0; x <= win->_maxx; x++) {
-                       if ((win->_line[y].text[x].chars[0] != ' ') || 
+                       if ((win->_line[y].text[x].chars[0] != ' ') ||
                                        (win->_line[y].text[x].attr != A_NORMAL)) {
                                if (win->_line[y].firstchar == _NOCHANGE)
                                        win->_line[y].firstchar = x;
@@ -965,7 +980,7 @@ int wsetscrreg(WINDOW *win, int top, int bottom)
 }
 // void wsyncdown (WINDOW *) {}
 // void wsyncup (WINDOW *) {}
-/* D */ void wtimeout(WINDOW *win, int delay) { win->_delay = delay; }
+/* D */ void wtimeout(WINDOW *win, int _delay) { win->_delay = _delay; }
 /* D */ int wtouchln(WINDOW *win, int y, int n, int changed)
 {
        int i;