amatrix

AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA
git clone git://git.kocotian.pl/amatrix.git
Log | Files | Refs | README | LICENSE

commit a5ae646c15f1f89ae8fb9481334cbe226a1e8bb3
parent 1faae5182f7282551d364714200d14dbc8c22d2b
Author: Abishek V Ashok <abishekvashok@gmail.com>
Date:   Sun, 31 May 2020 14:32:51 +0530

Merge pull request #102 from Prince213/master

Add basic support for Windows and PDCurses.
Diffstat:
MCMakeLists.txt | 8+++++++-
MREADME.md | 3++-
Mcmatrix.c | 48++++++++++++++++++++++++++++++++++++++++++++++--
Mconfigure.ac | 22+++++++++++++++++++---
4 files changed, 74 insertions(+), 7 deletions(-)

diff --git a/CMakeLists.txt b/CMakeLists.txt @@ -23,7 +23,9 @@ endif() # configure_file(config.h.in config.h) add_definitions(-DVERSION="${VERSION}") -add_definitions(-DUSE_TIOCSTI) +if (NOT WIN32) + add_definitions(-DUSE_TIOCSTI) +endif () include(CheckIncludeFiles) check_include_files("sys/ioctl.h" HAVE_SYS_IOCTL_H) @@ -42,6 +44,10 @@ check_include_files("termio.h" HAVE_TERMIO_H) if (HAVE_TERMIO_H) add_definitions(-DHAVE_TERMIO_H) endif () +check_include_files("getopt.h" HAVE_GETOPT_H) +if (HAVE_GETOPT_H) + add_definitions(-DHAVE_GETOPT_H) +endif () Set(CURSES_NEED_NCURSES TRUE) find_package(Curses) diff --git a/README.md b/README.md @@ -12,7 +12,7 @@ effect, you must specify `-s` on the command line. For usage info, use `cmatrix [![Build Status](https://travis-ci.org/abishekvashok/cmatrix.svg?branch=master)](https://travis-ci.org/abishekvashok/cmatrix) ### Dependencies -You'll probably need a decent ncurses library to get this to work. +You'll probably need a decent ncurses library (or PDCurses on native Windows) to get this to work. ### Building and installing cmatrix To install cmatrix, use either of the following methods from within the cmatrix directory. @@ -27,6 +27,7 @@ make install #### Using CMake Here we also show an out-of-source build in the sub directory "build". +Don't use CMake if you want to use PDCurses, it won't work (for now). ``` mkdir -p build cd build diff --git a/cmatrix.c b/cmatrix.c @@ -17,7 +17,7 @@ GNU General Public License for more details. You should have received a copy of the GNU General Public License - along with Foobar. If not, see <http://www.gnu.org/licenses/>. + along with cmatrix. If not, see <http://www.gnu.org/licenses/>. */ @@ -30,14 +30,21 @@ #include <sys/types.h> #include <sys/stat.h> #include <fcntl.h> -#include <termios.h> #include <signal.h> #include <locale.h> +#ifdef _WIN32 +#define WIN32_LEAN_AND_MEAN +#include <windows.h> +#endif #ifndef EXCLUDE_CONFIG_H #include "config.h" #endif +#ifdef HAVE_GETOPT_H +#include <getopt.h> +#endif + #ifdef HAVE_NCURSES_H #include <ncurses.h> #else @@ -72,7 +79,9 @@ cmatrix **matrix = (cmatrix **) NULL; int *length = NULL; /* Length of cols in each line */ int *spaces = NULL; /* Spaces left to fill */ int *updates = NULL; /* What does this do again? */ +#ifndef _WIN32 volatile sig_atomic_t signal_status = 0; /* Indicates a caught signal */ +#endif int va_system(char *str, ...) { @@ -222,11 +231,22 @@ void var_init() { } +#ifndef _WIN32 void sighandler(int s) { signal_status = s; } +#endif void resize_screen(void) { +#ifdef _WIN32 + BOOL result; + HANDLE hStdHandle; + CONSOLE_SCREEN_BUFFER_INFO csbiInfo; + + hStdHandle = GetStdHandle(STD_OUTPUT_HANDLE); + if(hStdHandle == INVALID_HANDLE_VALUE) + return; +#else char *tty; int fd = 0; int result = 0; @@ -235,6 +255,14 @@ void resize_screen(void) { tty = ttyname(0); if (!tty) { return; +#endif +#ifdef _WIN32 + result = GetConsoleScreenBufferInfo(hStdHandle, &csbiInfo); + if(!result) + return; + LINES = csbiInfo.dwSize.Y; + COLS = csbiInfo.dwSize.X; +#else } fd = open(tty, O_RDWR); if (fd == -1) { @@ -247,6 +275,7 @@ void resize_screen(void) { COLS = win.ws_col; LINES = win.ws_row; +#endif if(LINES <10){ LINES = 10; @@ -384,8 +413,12 @@ int main(int argc, char *argv[]) { } if (force && strcmp("linux", getenv("TERM"))) { +#ifdef _WIN32 + SetEnvironmentVariableW(L"TERM", L"linux"); +#else /* setenv is much more safe to use than putenv */ setenv("TERM", "linux", 1); +#endif } if (tty) { FILE *ftty = fopen(tty, "r+"); @@ -403,15 +436,21 @@ int main(int argc, char *argv[]) { initscr(); savetty(); nonl(); +#ifdef _WIN32 + raw(); +#else cbreak(); +#endif noecho(); timeout(0); leaveok(stdscr, TRUE); curs_set(0); +#ifndef _WIN32 signal(SIGINT, sighandler); signal(SIGQUIT, sighandler); signal(SIGWINCH, sighandler); signal(SIGTSTP, sighandler); +#endif if (console) { #ifdef HAVE_CONSOLECHARS @@ -475,6 +514,7 @@ if (console) { var_init(); while (1) { +#ifndef _WIN32 /* Check for signals */ if (signal_status == SIGINT || signal_status == SIGQUIT) { if(lock != 1) @@ -490,6 +530,7 @@ if (console) { if(lock != 1) finish(); } +#endif count++; if (count > 4) { @@ -513,6 +554,9 @@ if (console) { finish(); } else { switch (keypress) { +#ifdef _WIN32 + case 3: /* Ctrl-C. Fall through */ +#endif case 'q': if(lock != 1) finish(); diff --git a/configure.ac b/configure.ac @@ -5,6 +5,15 @@ AC_CONFIG_SRCDIR([cmatrix.c]) AM_CONFIG_HEADER(config.h) AM_INIT_AUTOMAKE +AC_CANONICAL_HOST +case $host in + *mingw*) + ;; + *) + native_windows=no + ;; +esac + dnl Checks for programs. AC_PROG_CC AC_PROG_INSTALL @@ -16,7 +25,7 @@ AC_CHECK_LIB(ncurses, main) dnl Checks for header files. AC_HEADER_STDC -AC_CHECK_HEADERS(fcntl.h sys/ioctl.h unistd.h termios.h termio.h) +AC_CHECK_HEADERS(fcntl.h sys/ioctl.h unistd.h termios.h termio.h getopt.h) dnl Checks for library functions. AC_TYPE_SIGNAL @@ -35,6 +44,11 @@ fi if eval "test x$CURSES_LIB_NAME = x" then + AC_CHECK_LIB(pdcurses, initscr, CURSES_LIB="-lpdcurses" CURSES_LIB_NAME=pdcurses) +fi + +if eval "test x$CURSES_LIB_NAME = x" +then AC_CHECK_LIB(termcap, tgetent, CURSES_LIB="-ltermcap" CURSES_LIB_NAME=termcap) fi @@ -48,7 +62,7 @@ then AC_MSG_WARN([ *** No termcap lib available, consider getting the official ncurses *** distribution from ftp://ftp.gnu.org/pub/gnu/ncurses if you get -*** errors compiling nano.]) +*** errors compiling cmatrix.]) else AC_MSG_RESULT("Using $CURSES_LIB_NAME as the termcap library") fi @@ -136,7 +150,9 @@ AM_CONDITIONAL([MATRIX_FONTS], [test x$enable_fonts = xtrue]) AC_SUBST(CURSES_LIB) -AC_DEFINE(USE_TIOCSTI) +if test x$native_windows = xno; then + AC_DEFINE(USE_TIOCSTI) +fi AH_TEMPLATE([HAVE_USE_DEFAULT_COLORS], [Define this if your curses library has use_default_colors, for cool transparency =-)]) AH_TEMPLATE([HAVE_CONSOLECHARS], [Define this if you have the linux consolechars program])