summaryrefslogtreecommitdiff
path: root/ext
diff options
context:
space:
mode:
authorakr <akr@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2012-02-22 11:44:26 +0000
committerakr <akr@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2012-02-22 11:44:26 +0000
commitc01d52e8d9e3f1596d3bbbebaa8ea35c330f8763 (patch)
tree7566e6c15846290b7476774bd8f92dfb4dc6b497 /ext
parentfa65fc9aeb5e73b84ce80c4c2c3edaa888362e03 (diff)
* ext/curses/extconf.rb: try to distinguish curses_version is a
function or variable. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@34745 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'ext')
-rw-r--r--ext/curses/curses.c8
-rw-r--r--ext/curses/extconf.rb39
2 files changed, 46 insertions, 1 deletions
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