aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--ChangeLog7
-rw-r--r--ext/curses/curses.c8
-rw-r--r--ext/curses/extconf.rb39
3 files changed, 53 insertions, 1 deletions
diff --git a/ChangeLog b/ChangeLog
index f179026f00..31f3c0839c 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,10 @@
+Wed Feb 22 20:42:28 2012 Tanaka Akira <akr@fsij.org>
+
+ * ext/curses/extconf.rb: try to distinguish curses_version is a
+ function or variable.
+
+ * ext/curses/curses.c (Init_curses): refine Curses::VERSION.
+
Wed Feb 22 19:47:03 2012 Tanaka Akira <akr@fsij.org>
* ext/curses/extconf.rb: show the chosen header and library.
diff --git a/ext/curses/curses.c b/ext/curses/curses.c
index eec364ba15..60ba65b15b 100644
--- a/ext/curses/curses.c
+++ b/ext/curses/curses.c
@@ -2768,8 +2768,14 @@ Init_curses(void)
rb_define_module_function(mCurses, "def_prog_mode", curses_def_prog_mode, 0);
rb_define_module_function(mCurses, "reset_prog_mode", curses_reset_prog_mode, 0);
-#ifdef NCURSES_VERSION
+#ifdef HAVE_FUNC_CURSES_VERSION
rb_define_const(mCurses, "VERSION", rb_str_new2(curses_version()));
+#elif HAVE_VAR_CURSES_VERSION
+ {
+ /* SVR4 curses has an undocumented and undeclared variable, curses_version. */
+ RUBY_EXTERN char *curses_version;
+ rb_define_const(mCurses, "VERSION", rb_sprintf("curses (%s)", curses_version));
+ }
#else
rb_define_const(mCurses, "VERSION", rb_str_new2("unknown"));
#endif
diff --git a/ext/curses/extconf.rb b/ext/curses/extconf.rb
index e1499437d0..14dfa7d5cb 100644
--- a/ext/curses/extconf.rb
+++ b/ext/curses/extconf.rb
@@ -72,5 +72,44 @@ if header_library
have_var("TABSIZE", curses)
have_var("COLORS", curses)
have_var("COLOR_PAIRS", curses)
+
+ # SVR4 curses has a (undocumented) variable char *curses_version.
+ # ncurses and PDcurses has a function char *curses_version().
+ # Note that the original BSD curses doesn't provide version information.
+
+ prolog = cpp_include(curses)
+ if checking_for(checking_message('function curses_version', curses)) {
+ try_run(<<-"End")
+ #{prolog}
+ int main(int argc, char *argv[])
+ {
+ curses_version();
+ return EXIT_SUCCESS;
+ }
+ End
+ }
+ $defs << '-DHAVE_FUNC_CURSES_VERSION'
+ end
+
+ if checking_for(checking_message('variable curses_version', curses)) {
+ try_run(<<-"End")
+ #{prolog}
+ extern char *curses_version;
+ int main(int argc, char *argv[])
+ {
+ int i = 0;
+ for (i = 0; i < 100; i++) {
+ if (curses_version[i] == 0)
+ return 0 < i ? EXIT_SUCCESS : EXIT_FAILURE;
+ if (curses_version[i] & 0x80)
+ return EXIT_FAILURE;
+ }
+ return EXIT_FAILURE;
+ }
+ End
+ }
+ $defs << '-DHAVE_VAR_CURSES_VERSION'
+ end
+
create_makefile("curses")
end