1
0
mirror of https://git.zap.org.au/git/trader.git synced 2024-06-09 19:20:43 +00:00

Add the SysV-compatible curses library

The AX_WITH_CURSES macro is taken from the autoconf-archive project,
available at http://www.gnu.org/software/autoconf-archive/.
This commit is contained in:
John Zaitseff 2011-06-30 20:31:19 +10:00
parent d6050858d9
commit 3a4c95f927
5 changed files with 175 additions and 4 deletions

View File

@ -40,6 +40,11 @@ AC_PROG_CC_STDC
AX_CFLAGS_WARN_ALL
AX_C___ATTRIBUTE__
AX_WITH_CURSES
AS_IF([test "x$ax_cv_curses" != "xyes"],
AC_MSG_ERROR([requires a SysV-compatible curses library.]),
AC_SUBST([CURSES_LIB]))
AC_CONFIG_HEADERS([config.h])
AC_CONFIG_FILES([
Makefile

122
m4/ax_with_curses.m4 Normal file
View File

@ -0,0 +1,122 @@
# ===========================================================================
# http://www.gnu.org/software/autoconf-archive/ax_with_curses.html
# ===========================================================================
#
# SYNOPSIS
#
# AX_WITH_CURSES
#
# DESCRIPTION
#
# Detect SysV compatible curses, such as ncurses.
#
# Defines HAVE_CURSES_H or HAVE_NCURSES_H if curses is found. CURSES_LIB
# is also set with the required library, but is not appended to LIBS
# automatically. If no working curses library is found CURSES_LIB will be
# left blank. If CURSES_LIB is set in the environment, the supplied value
# will be used.
#
# There are two options: --with-ncurses forces the use of ncurses, and
# --with-ncursesw forces the use of ncursesw (wide character ncurses). The
# corresponding options --without-ncurses and --without-ncursesw force
# those libraries not to be used. By default, ncursesw is preferred to
# ncurses, which is preferred to plain curses.
#
# ax_cv_curses is set to "yes" if any curses is found (including
# ncurses!); ax_cv_ncurses is set to "yes" if any ncurses is found, and
# ax_cv_ncursesw is set to "yes" if ncursesw is found.
#
# LICENSE
#
# Copyright (c) 2009 Mark Pulford <mark@kyne.com.au>
# Copyright (c) 2009 Damian Pietras <daper@daper.net>
# Copyright (c) 2011 Reuben Thomas <rrt@sc3d.org>
#
# This program is free software: you can redistribute it and/or modify it
# under the terms of the GNU General Public License as published by the
# Free Software Foundation, either version 3 of the License, or (at your
# option) any later version.
#
# This program is distributed in the hope that it will be useful, but
# WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General
# Public License for more details.
#
# You should have received a copy of the GNU General Public License along
# with this program. If not, see <http://www.gnu.org/licenses/>.
#
# As a special exception, the respective Autoconf Macro's copyright owner
# gives unlimited permission to copy, distribute and modify the configure
# scripts that are the output of Autoconf when processing the Macro. You
# need not follow the terms of the GNU General Public License when using
# or distributing such scripts, even though portions of the text of the
# Macro appear in them. The GNU General Public License (GPL) does govern
# all other use of the material that constitutes the Autoconf Macro.
#
# This special exception to the GPL applies to versions of the Autoconf
# Macro released by the Autoconf Archive. When you make and distribute a
# modified version of the Autoconf Macro, you may extend this special
# exception to the GPL to apply to your modified version as well.
#serial 10
AU_ALIAS([MP_WITH_CURSES], [AX_WITH_CURSES])
AC_DEFUN([AX_WITH_CURSES],
[AC_ARG_WITH(ncurses, [AS_HELP_STRING([--with-ncurses],
[Force the use of ncurses over curses])],,)
ax_save_LIBS="$LIBS"
AC_ARG_WITH(ncursesw, [AS_HELP_STRING([--without-ncursesw],
[Don't use ncursesw (wide character support)])],,)
if test ! "$CURSES_LIB" && test "$with_ncurses" != no && test "$with_ncursesw" != "no"
then
AC_CACHE_CHECK([for working ncursesw], ax_cv_ncursesw,
[LIBS="$ax_save_LIBS -lncursesw"
AC_TRY_LINK(
[#include <ncurses.h>],
[chtype a; int b=A_STANDOUT, c=KEY_LEFT; initscr(); ],
ax_cv_ncursesw=yes, ax_cv_ncursesw=no)])
if test "$ax_cv_ncursesw" = yes
then
AC_CHECK_HEADER([ncursesw/curses.h], AC_DEFINE([HAVE_NCURSESW_H], 1,
[Define if you have ncursesw.h]))
AC_DEFINE([HAVE_NCURSES_H], 1, [Define if you have ncursesw/curses.h])
AC_DEFINE([HAVE_NCURSESW], 1, [Define if you have libncursesw])
CURSES_LIB="-lncursesw"
ax_cv_ncurses=yes
ax_cv_curses=yes
fi
fi
if test ! "$CURSES_LIB" && test "$with_ncurses" != no && test "$with_ncursesw" != yes
then
AC_CACHE_CHECK([for working ncurses], ax_cv_ncurses,
[LIBS="$ax_save_LIBS -lncurses"
AC_TRY_LINK(
[#include <ncurses.h>],
[chtype a; int b=A_STANDOUT, c=KEY_LEFT; initscr(); ],
ax_cv_ncurses=yes, ax_cv_ncurses=no)])
if test "$ax_cv_ncurses" = yes
then
AC_DEFINE([HAVE_NCURSES_H],[1],[Define if you have ncurses.h])
CURSES_LIB="-lncurses"
ax_cv_curses=yes
fi
fi
if test "$ax_cv_curses" != yes && test "$with_ncurses" != yes && test "$with_ncursesw" != yes
then
if test ! "$CURSES_LIB"
then
CURSES_LIB="-lcurses"
fi
AC_CACHE_CHECK([for working curses], ax_cv_curses,
[LIBS="$ax_save_LIBS $CURSES_LIB"
AC_TRY_LINK(
[#include <curses.h>],
[chtype a; int b=A_STANDOUT, c=KEY_LEFT; initscr(); ],
ax_cv_curses=yes, ax_cv_curses=no)])
if test "$ax_cv_curses" = yes
then
AC_DEFINE([HAVE_CURSES_H],[1],[Define if you have curses.h])
fi
fi
LIBS="$ax_save_LIBS"
])dnl

View File

@ -34,3 +34,5 @@ trader_SOURCES = \
globals.c globals.h \
utils.c utils.h \
system.h
trader_LDADD = @CURSES_LIB@

View File

@ -45,11 +45,25 @@
* System header files *
************************************************************************/
#define _GNU_SOURCE 1
#include <stdlib.h>
#include <stdio.h>
#include <string.h>
#include <locale.h>
#include <getopt.h>
#if defined(HAVE_NCURSESW) && defined(HAVE_NCURSESW_H)
# include <ncursesw/curses.h>
#elif defined(HAVE_NCURSES_H)
# include <ncurses.h>
#elif defined(HAVE_CURSES_H)
# include <curses.h>
#else
# error SysV-compatible curses library required
#endif
/************************************************************************
* Miscellaneous definitions *

View File

@ -52,15 +52,43 @@ int main (int argc, char *argv[])
{
init_program_name(argv);
// Initialise the locale (and ignore any errors)
setlocale(LC_ALL, "");
// Process command line arguments
process_cmdline(argc, argv);
// Testing...
printf(_("Program name: %s\n"), program_name());
printf(_("Home directory: %s\n"), home_directory());
printf(_("Data directory: %s\n"), data_directory());
printf(_("Game filename: %s\n"), game_filename);
initscr();
noecho();
timeout(-1);
keypad(stdscr, TRUE);
raw();
printw(_("Program name: %s\n"), program_name());
printw(_("Home directory: %s\n"), home_directory());
printw(_("Data directory: %s\n"), data_directory());
printw(_("Game filename: %s\n"), game_filename);
printw(_("Cols x Lines: %d x %d\n"), COLS, LINES);
printw(_("Colours, pairs: %d, %d\n"), COLORS, COLOR_PAIRS);
printw(_("Type some keys (^C to exit):\n\n"));
int c = 0;
while ((c = getch()) != 3) {
if ((c >= 0) && (c < 32)) {
printw("0%03o ^%c ", c, c + '@');
} else if ((c >= 32) && (c <= 127)) {
printw("0%03o %c ", c, c);
} else {
printw("0%05o ", c);
}
refresh();
}
endwin();
return EXIT_SUCCESS;
}