Tous les collages #49752 Brut Modifier

Anonymous

public text v1 · immuable
#49752 ·publié 2006-04-18 19:35 UTC
corps du collage affiché
Hi,

I saw an IRC log where it was mentioned that bzadmin wasn't building with PDCurses 2.8. Although I haven't tried building it myself yet, I took a look at curses_wrapper.h, and I think I see the problem. Ironically, it's due to kludges for older versions of PDCurses that are no longer needed with 2.8.

 #ifndef HAVE_PROTO
 #  define HAVE_PROTO
 #endif

HAVE_PROTO is no longer needed (though harmless).

 // stop ugly macros from polluting our namespace (pdcurses doesn't use
 // the NOMACROS preprocessor variable)

It does, now. More importantly, it declares all of the following as functions, with or without NOMACROS:

 #undef erase
 inline int erase() {
   return werase(stdscr);
 }

 #undef clear
 inline int clear() {
   return wclear(stdscr);
 }

 #undef move
 inline int move(int y, int x) {
   return wmove(stdscr, y, x);
 }

 #undef nonl
 inline int nonl() {
   return OK;
 }

so those should go. I assume this is the source of the errors.

 // wrap some functions to make it compatible with ncurses
 inline int pd_waddstr(WINDOW* w, const char* str) {
   char* newStr = new char[strlen(str) + 1];
   strcpy(newStr, str);
   return waddstr(w, newStr);
 }
 #define waddstr(W, C) pd_waddstr(W, C)

I'm not sure the purpose of this. If it's just about the lack of "const" in PDCurses' prototype for waddstr(), that's been corrected.

 #ifdef XCURSES
 inline int pd_endwin() {
   int i = endwin();
   XCursesExit();
   return i;
 }
 #define endwin pd_endwin
 #endif // XCURSES

Explicit calls to XCursesExit() are no longer needed in 2.8 (although harmless).

 inline int wresize(WINDOW* w, int lines, int cols) {
   return (resize_window(w, lines, cols) != NULL);
 }

This isn't correct for either old or new PDCurses. resize_window() creates a new window with the new size, and destroys the old one. It does _not_ copy the new window to the old pointer, as ncurses' wresize() does. Your function destroys the old window and discards the new one. In PDCurses 2.8, wresize() is defined as a macro (only) that doesn't get undefined by NOMACROS. This is the only way to do it without rewriting resize_window().

You can compile conditionally on the value of PDC_BUILD. In my own code, I just did this:

 #if defined(__PDCURSES__) && (PDC_BUILD < 2801)
 # error Please upgrade to PDCurses 2.8 or later
 #endif


-- 
William McBrine <wmcbrine@gmail.com>