diff --git a/.github/FUNDING.yml b/.github/FUNDING.yml new file mode 100644 index 0000000..436ef8e --- /dev/null +++ b/.github/FUNDING.yml @@ -0,0 +1,4 @@ +# These are supported funding model platforms + +patreon: abishekvashok +open_collective: cmatrix diff --git a/.github/ISSUE_TEMPLATE/bug_report.md b/.github/ISSUE_TEMPLATE/bug_report.md new file mode 100644 index 0000000..9c9260c --- /dev/null +++ b/.github/ISSUE_TEMPLATE/bug_report.md @@ -0,0 +1,26 @@ +--- +name: Bug report +about: Create a report to help us improve +title: '' +labels: Bug +assignees: '' + +--- + +**Describe the bug** +A clear and concise description of what the bug is. + +**To Reproduce** +Steps to reproduce the behavior: + +**Expected behavior** +A clear and concise description of what you expected to happen. + +**Screenshots** +If applicable, add screenshots to help explain your problem. + + - OS: [e.g. iOS] + - Version [e.g. 22] + +**Additional context** +Add any other context about the problem here. diff --git a/.github/ISSUE_TEMPLATE/feature_request.md b/.github/ISSUE_TEMPLATE/feature_request.md new file mode 100644 index 0000000..e74cb57 --- /dev/null +++ b/.github/ISSUE_TEMPLATE/feature_request.md @@ -0,0 +1,20 @@ +--- +name: Feature request +about: Suggest an idea for this project +title: '' +labels: Feature +assignees: '' + +--- + +**Is your feature request related to a problem? Please describe.** +A clear and concise description of what the problem is. Ex. I'm always frustrated when [...] + +**Describe the solution you'd like** +A clear and concise description of what you want to happen. + +**Describe alternatives you've considered** +A clear and concise description of any alternative solutions or features you've considered. + +**Additional context** +Add any other context or screenshots about the feature request here. diff --git a/.gitignore b/.gitignore index bd16c7b..7816cdf 100644 --- a/.gitignore +++ b/.gitignore @@ -25,6 +25,7 @@ cscope.in.out cscope.po.out cscope.files cmatrix +cmatrix.exe *.o *.core CMakeCache.txt diff --git a/.travis.yml b/.travis.yml index dd1cc30..0abc5f0 100644 --- a/.travis.yml +++ b/.travis.yml @@ -1,3 +1,6 @@ +arch: + - amd64 + - ppc64le language: c os: @@ -24,4 +27,3 @@ script: mkdir build && cd build && cmake -DCMAKE_C_COMPILER="${CC}" .. fi - make - diff --git a/CMakeLists.txt b/CMakeLists.txt index c5548b3..fba6fed 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -5,6 +5,8 @@ cmake_minimum_required(VERSION 2.8) project(CMatrix LANGUAGES C) set(VERSION "2.0") +include(GNUInstallDirs) + # These are relative to CMAKE_INSTALL_PREFIX # which by default is "/usr/local" set(CONSOLE_FONTS_DIRS "share/consolefonts" "lib/kbd/consolefonts") @@ -12,9 +14,20 @@ set(X_FONTS_DIRS "lib/X11/fonts/misc" "X11R6/lib/X11/fonts/misc" "share/fonts/X1 set(MKFONTDIR "/usr/bin/mkfontdir") -add_definitions(-DEXCLUDE_CONFIG_H) +message(STATUS "Looking for include file config.h") +if(NOT EXISTS "${CMAKE_SOURCE_DIR}/config.h") + add_definitions(-DEXCLUDE_CONFIG_H) + message(STATUS "Looking for include file config.h - missing") +else() + message(STATUS "Looking for include file config.h - found") +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) @@ -33,17 +46,30 @@ 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) +Set(CURSES_NEED_WIDE TRUE) find_package(Curses) include_directories(${CURSES_INCLUDE_DIR}) add_definitions(-DHAVE_NCURSES_H) +include(CheckSymbolExists) +list(APPEND CMAKE_REQUIRED_LIBRARIES ncurses) +check_symbol_exists(use_default_colors "ncurses.h" HAVE_USE_DEFAULT_COLORS) +if (HAVE_USE_DEFAULT_COLORS) + add_definitions(-DHAVE_USE_DEFAULT_COLORS) +endif() + add_executable(cmatrix cmatrix.c) target_link_libraries(cmatrix ${CURSES_LIBRARIES}) -install(TARGETS cmatrix DESTINATION bin) +install(TARGETS cmatrix DESTINATION ${CMAKE_INSTALL_BINDIR}) +install(FILES cmatrix.1 DESTINATION ${CMAKE_INSTALL_MANDIR}/man1) if (UNIX) foreach (CONSOLE_FONTS_DIR ${CONSOLE_FONTS_DIRS}) @@ -70,4 +96,3 @@ if (UNIX) endif () endforeach () endif () - diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index 9d5c4cd..623bcba 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -1,19 +1,19 @@ # Contributing When contributing to this repository, please first discuss the change you wish to make via issue, -email, or any other method with the owners of this repository before making a change. +email, or any other method with the owners of this repository before making a change. Please note we have a code of conduct, please follow it in all your interactions with the project. ## Pull Request Process -1. Ensure any install or build dependencies are removed before the end of the layer when doing a +1. Ensure any install or build dependencies are removed before the end of the layer when doing a build. -2. Update the README.md with details of changes to the interface, this includes new environment +2. Update the README.md with details of changes to the interface, this includes new environment variables, exposed ports, useful file locations and container parameters. 3. Increase the version numbers in any examples files and the README.md to the new version that this Pull Request would represent. The versioning scheme we use is [SemVer](http://semver.org/). -4. You may merge the Pull Request in once you have the sign-off of two other developers, or if you +4. You may merge the Pull Request in once you have the sign-off of two other developers, or if you do not have permission to do that, you may request the second reviewer to merge it for you. ## Code of Conduct diff --git a/COPYING b/COPYING index 94a9ed0..f288702 100644 --- a/COPYING +++ b/COPYING @@ -1,7 +1,7 @@ GNU GENERAL PUBLIC LICENSE Version 3, 29 June 2007 - Copyright (C) 2007 Free Software Foundation, Inc. + Copyright (C) 2007 Free Software Foundation, Inc. Everyone is permitted to copy and distribute verbatim copies of this license document, but changing it is not allowed. @@ -645,7 +645,7 @@ the "copyright" line and a pointer to where the full notice is found. 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 . + along with this program. If not, see . Also add information on how to contact you by electronic and paper mail. @@ -664,11 +664,11 @@ might be different; for a GUI interface, you would use an "about box". You should also get your employer (if you work as a programmer) or school, if any, to sign a "copyright disclaimer" for the program, if necessary. For more information on this, and how to apply and follow the GNU GPL, see -. +. The GNU General Public License does not permit incorporating your program into proprietary programs. If your program is a subroutine library, you may consider it more useful to permit linking proprietary applications with the library. If this is what you want to do, use the GNU Lesser General Public License instead of this License. But first, please read -. +. diff --git a/ISSUE_TEMPLATE.md b/ISSUE_TEMPLATE.md index 3934370..27aeb8d 100644 --- a/ISSUE_TEMPLATE.md +++ b/ISSUE_TEMPLATE.md @@ -3,7 +3,7 @@ I am submitting a ### Problem or Feature in Brief -### +### ### Solution (if any) +

+cmatrix screenshot +

-![Special Font & bold](data/img/capture_bold_font.png?raw=true "cmatrix -bx") +#### :small_blue_diamond: Screencasts -#### Screencasts + +

+cmatrix screencast +

-![Movie-Like Cast](data/img/capture_orig.gif?raw=true "cmatrix -xba") +![-----------------------------------------------------](https://raw.githubusercontent.com/andreasbm/readme/master/assets/lines/rainbow.png) -### Maintainers -- Abishek V Ashok (@abishekvashok) [Core] +## :zap: Maintainers +- ➤ **Abishek V Ashok** [Core] -
+

+ + + + + + +

-### Thanks to: -- Chris Allegretta for writing cmatrix up in a fornight and giving us + +## :busts_in_silhouette: Our Contributors +#### :small_orange_diamond: Thanks to +- ➤ **Chris Allegretta** for writing cmatrix up in a fortnight and giving us the responsibility to further improve it. -- Krisjon Hanson and Bjoern Ganslandt for helping with bold support and +- ➤ **Krisjon Hanson** and **Bjoern Ganslandt** for helping with bold support and Bjoern again for the cursor removal code, helping with the `-u` and `-l` modes/flags, and Makefile improvements. -- Adam Gurno for multi-color support. -- Garrick West for debian consolefont dir support. -- Nemo for design thoughts and continuous help and support. -- John Donahue for helping with transparent term support -- Ben Esacove for Redhat 6 compatibility w/matrix.psf.gz -- jwz for the xmatrix module to xscreensaver at http://www.jwz.org/xscreensaver. -- Chris Allegretta's girlfriend Amy for not killing him when he stayed up till 3 AM +- ➤ **Adam Gurno** for multi-color support. +- ➤ **Garrick West** for debian consolefont dir support. +- ➤ **Nemo** for design thoughts and continuous help and support. +- ➤ **John Donahue** for helping with transparent term support +- ➤ **Ben Esacove** for Redhat 6 compatibility w/matrix.psf.gz +- ➤ **jwz** for the xmatrix module to xscreensaver at http://www.jwz.org/xscreensaver. +- Chris Allegretta's girlfriend **Amy** for not killing him when he stayed up till 3 AM writing code. +- ➤ **Sumit Kumar Soni** for beautifying the README. - The makers of the Matrix for one kickass movie! -- Everyone who has sent (and who will send) us and Chris mails regarding - bugs, comments, patches or just a hello. -- Everyone who has opened issues and PRs on the github repository. +- ➤ Everyone who has sent (and who will send) us and Chris mails regarding + bugs, comments, patches or just a simple hello. +- ➤ Everyone who has contributed to the project by opening issues and PRs on the github repository. -### License -This software is provided under the GNU GPL v3. +![-----------------------------------------------------](https://raw.githubusercontent.com/andreasbm/readme/master/assets/lines/rainbow.png) -### Disclaimer -We are in no way affiliated in any way with the movie "The Matrix", "Warner Bros" nor -any of its affiliates in any way, just fans. +## :book: Contribution Guide +If you have any suggestions/flames/patches to send, please feel free to: +- Open issues and if possible label them, so that it is easy to categorise features, bugs etc. +- If you solved some problems or made some valuable changes, Please open a Pull Request on Github. +- See [contributing.md](./CONTRIBUTING.md) for more details. + +![-----------------------------------------------------](https://raw.githubusercontent.com/andreasbm/readme/master/assets/lines/rainbow.png) + +## :page_facing_up: License +This software is provided under the GNU GPL v3. [View License](./COPYING) diff --git a/cmatrix.1 b/cmatrix.1 index 2dbf23e..59c6654 100644 --- a/cmatrix.1 +++ b/cmatrix.1 @@ -26,9 +26,21 @@ Linux mode (sets "matrix.fnt" font in console) .I "\-o" Use old-style scrolling .TP +.I "\-c" +Only print the shadows of letters +.TP +.I "\-L" +Locks cmatrix, Unable to quit +.TP .I "\-h, \-?" Print usage and exit .TP +.I "\-r" +"Rainbow" mode, rainbow colored character +.TP +.I "\-k" +Every characters change +.TP .I "\-n" No bold characters (overrides \-b and \-B) .TP @@ -48,8 +60,14 @@ Print version information and exit Screen update delay 0 - 9, default 4 .TP .I "\-C color" -Use this color for matrix (default green). +Use this color for matrix (default green). Valid colors are green, red, blue, white, yellow, cyan, magenta and black. +.TP +.I "\-M message" +Add a message in the center of cmatrix +.TP +.I "\-t tty" +Set tty to use .SS KEYSTROKES The following keystrokes are available during execution (unavailable in \-s mode) diff --git a/cmatrix.c b/cmatrix.c index 90284cb..7e24a0a 100644 --- a/cmatrix.c +++ b/cmatrix.c @@ -17,10 +17,13 @@ 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 . + along with cmatrix. If not, see . */ +#define NCURSES_WIDECHAR 1 + +#include #include #include #include @@ -29,19 +32,30 @@ #include #include #include -#include #include #include +#ifdef _WIN32 +#define WIN32_LEAN_AND_MEAN +#include +#endif #ifndef EXCLUDE_CONFIG_H #include "config.h" #endif +#ifdef HAVE_GETOPT_H +#include +#endif + #ifdef HAVE_NCURSES_H #include #else +#ifdef _WIN32 +#include +#else #include #endif +#endif #ifdef HAVE_SYS_IOCTL_H #include @@ -57,6 +71,10 @@ #include #endif +#ifdef __CYGWIN__ +#define TIOCSTI 0x5412 +#endif + /* Matrix typedef */ typedef struct cmatrix { int val; @@ -71,7 +89,14 @@ 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? */ +//<<<<<<< wordwiz +int counter = 0; + +//======= +//>>>>>>> stable +#ifndef _WIN32 volatile sig_atomic_t signal_status = 0; /* Indicates a caught signal */ +#endif int va_system(char *str, ...) { @@ -127,7 +152,7 @@ void c_die(char *msg, ...) { } void usage(void) { - printf(" Usage: cmatrix -[abBcfhlsmVx] [-u delay] [-C color]\n"); + printf(" Usage: cmatrix -[abBcfhlsmVxk] [-u delay] [-C color] [-t tty] [-M message]\n"); printf(" -a: Asynchronous scroll\n"); printf(" -b: Bold characters on\n"); printf(" -B: All bold characters (overrides -b)\n"); @@ -141,10 +166,18 @@ void usage(void) { printf(" -s: \"Screensaver\" mode, exits on first keystroke\n"); printf(" -x: X window mode, use if your xterm is using mtx.pcf\n"); printf(" -V: Print version information and exit\n"); + printf(" -M [message]: Prints your message in the center of the screen. Overrides -L's default message.\n"); printf(" -u delay (0 - 10, default 4): Screen update delay\n"); printf(" -C [color]: Use this color for matrix (default green)\n"); printf(" -r: rainbow mode\n"); printf(" -m: lambda mode\n"); + printf(" -k: Characters change while scrolling. (Works without -o opt.)\n"); + printf(" -t [tty]: Set tty to use\n"); +//<<<<<<< wordwiz + printf(" -w wordify"); + +//======= +//>>>>>>> stable } void version(void) { @@ -219,11 +252,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; @@ -232,6 +276,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) { @@ -244,11 +296,12 @@ void resize_screen(void) { COLS = win.ws_col; LINES = win.ws_row; +#endif - if(LINES <10){ + if (LINES < 10) { LINES = 10; } - if(COLS <10){ + if (COLS < 10) { COLS = 10; } @@ -287,13 +340,20 @@ int main(int argc, char *argv[]) { int randmin = 0; int pause = 0; int classic = 0; + int changes = 0; + char *msg = ""; + char *tty = NULL; srand((unsigned) time(NULL)); setlocale(LC_ALL, ""); /* Many thanks to morph- (morph@jmss.com) for this getopt patch */ opterr = 0; - while ((optchr = getopt(argc, argv, "abBcfhlLnrosmxVu:C:")) != EOF) { +//<<<<<<< wordwiz + while ((optchr = getopt(argc, argv, "abBcfhlLnrosmxkVM:u:C:t:w:")) != EOF) { +//======= +// while ((optchr = getopt(argc, argv, "abBcfhlLnrosmxkVM:u:C:t:")) != EOF) { +//>>>>>>> stable switch (optchr) { case 's': screensaver = 1; @@ -343,6 +403,13 @@ int main(int argc, char *argv[]) { break; case 'L': lock = 1; + //if -M was used earlier, don't override it + if (0 == strncmp(msg, "", 1)) { + msg = "Computer locked."; + } + break; + case 'M': + msg = strdup(optarg); break; case 'n': bold = -1; @@ -364,30 +431,70 @@ int main(int argc, char *argv[]) { version(); exit(0); case 'r': - rainbow = 1; - break; + rainbow = 1; + break; case 'm': - lambda = 1; - break; + lambda = 1; + break; + case 'k': + changes = 1; + break; + case 't': + tty = optarg; + break; +//<<<<<<< wordwiz + case 'w': + msg = strdup(optarg); + break; +//======= +//>>>>>>> stable } } + /* Clear TERM variable on Windows */ +#ifdef _WIN32 + _putenv_s("TERM", ""); +#endif + 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 } - initscr(); + if (tty) { + FILE *ftty = fopen(tty, "r+"); + if (!ftty) { + fprintf(stderr, "cmatrix: error: '%s' couldn't be opened: %s.\n", + tty, strerror(errno)); + exit(EXIT_FAILURE); + } + SCREEN *ttyscr; + ttyscr = newterm(NULL, ftty, ftty); + if (ttyscr == NULL) + exit(EXIT_FAILURE); + set_term(ttyscr); + } else + 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 @@ -421,7 +528,7 @@ if (console) { init_pair(COLOR_YELLOW, COLOR_YELLOW, -1); } else { #else - { /* Hack to deal the after effects of else in HAVE_USE_DEFAULT_COLOURS*/ + { /* Hack to deal the after effects of else in HAVE_USE_DEFAULT_COLOURS */ #endif init_pair(COLOR_BLACK, COLOR_BLACK, COLOR_BLACK); init_pair(COLOR_GREEN, COLOR_GREEN, COLOR_BLACK); @@ -435,10 +542,13 @@ if (console) { } /* Set up values for random number generation */ - if(classic) { - /* Japanese character unicode range [they are seen in the original cmatrix] */ - randmin = 12288; - highnum = 12351; + if (classic) { + /* Half-width kana characters. In the movie they are y-axis flipped, and + * they appear alongside latin characters and numerals, but this is the + * closest we can do with a standard unicode set and a single number + * range */ + randmin = 0xff66; + highnum = 0xff9d; } else if (console || xwindow) { randmin = 166; highnum = 217; @@ -451,9 +561,10 @@ if (console) { var_init(); while (1) { +#ifndef _WIN32 /* Check for signals */ if (signal_status == SIGINT || signal_status == SIGQUIT) { - if(lock != 1) + if (lock != 1) finish(); /* exits */ } @@ -462,10 +573,11 @@ if (console) { signal_status = 0; } - if(signal_status == SIGTSTP){ - if(lock != 1) + if (signal_status == SIGTSTP) { + if (lock != 1) finish(); } +#endif count++; if (count > 4) { @@ -489,8 +601,11 @@ if (console) { finish(); } else { switch (keypress) { +#ifdef _WIN32 + case 3: /* Ctrl-C. Fall through */ +#endif case 'q': - if(lock != 1) + if (lock != 1) finish(); break; case 'a': @@ -565,7 +680,7 @@ if (console) { for (j = 0; j <= COLS - 1; j += 2) { if ((count > updates[j] || asynch == 0) && pause == 0) { - /* I dont like old-style scrolling, yuck */ + /* I don't like old-style scrolling, yuck */ if (oldstyle) { for (i = LINES - 1; i >= 1; i--) { matrix[i][j].val = matrix[i - 1][j].val; @@ -581,7 +696,7 @@ if (console) { spaces[j]--; } else { - /* Random number to determine whether head of next collumn + /* Random number to determine whether head of next column of chars has a white 'head' on it. */ if (((int) rand() % 3) == 1) { @@ -600,13 +715,15 @@ if (console) { } else { /* New style scrolling (default) */ if (matrix[0][j].val == -1 && matrix[1][j].val == ' ' && spaces[j] > 0) { - matrix[0][j].val = -1; spaces[j]--; } else if (matrix[0][j].val == -1 && matrix[1][j].val == ' ') { length[j] = (int) rand() % (LINES - 3) + 3; + if (msg) { + matrix[0][j].val = msg[j]; + } else { matrix[0][j].val = (int) rand() % randnum + randmin; - + } spaces[j] = (int) rand() % LINES + 1; } i = 0; @@ -624,12 +741,25 @@ if (console) { break; } - /* Go to the head of this collumn */ + /* Go to the head of this column */ z = i; y = 0; while (i <= LINES && (matrix[i][j].val != ' ' && matrix[i][j].val != -1)) { matrix[i][j].is_head = false; + if (changes) { +//<<<<<<< wordwiz + + if (msg){ + matrix[i][j].val = msg[j]; + } else { if (rand() % 8 == 0) + matrix[i][j].val = (int) rand() % randnum + randmin; + } +//======= + // if (rand() % 8 == 0) + // matrix[i][j].val = (int) rand() % randnum + randmin; +//>>>>>>> stable + } i++; y++; } @@ -638,19 +768,44 @@ if (console) { matrix[z][j].val = ' '; continue; } - + // This is the area to edit after getting getopt better + if (counter <= strlen(msg)){ + matrix[i][j].val = msg[counter]; + + // break; + //counter = counter + 1; + } +// if (counter == strlen(msg){ +// counter = 0; +// } + + else + { matrix[i][j].val = (int) rand() % randnum + randmin; + } + //matrix[i][j].val = msg[i]; matrix[i][j].is_head = true; - - /* If we're at the top of the collumn and it's reached its +//<<<<<<< wordwiz + //counter = counter + 1; + if (counter > strlen(msg)) + { + counter = 0; + } + +//======= +// +//>>>>>>> stable + /* If we're at the top of the column and it's reached its full length (about to start moving down), we do this to get it moving. This is also how we keep segments not already growing from growing accidentally => */ + if (y > length[j] || firstcoldone) { matrix[z][j].val = ' '; matrix[0][j].val = -1; } + counter = counter + 1; firstcoldone = 1; i++; } @@ -667,7 +822,7 @@ if (console) { for (i = y; i <= z; i++) { move(i - y, j); - if (matrix[i][j].is_head && !rainbow) { + if (matrix[i][j].val == 0 || (matrix[i][j].is_head && !rainbow)) { if (console || xwindow) { attron(A_ALTCHARSET); } @@ -681,6 +836,8 @@ if (console) { } else { addch('&'); } + } else if (matrix[i][j].val == -1) { + addch(' '); } else { addch(matrix[i][j].val); } @@ -693,10 +850,10 @@ if (console) { attroff(A_ALTCHARSET); } } else { - if(rainbow) { + if (rainbow) { int randomColor = rand() % 6; - switch(randomColor){ + switch (randomColor) { case 0: mcolor = COLOR_GREEN; break; @@ -739,7 +896,15 @@ if (console) { } else if (lambda && matrix[i][j].val != ' ') { addstr("λ"); } else { - addch(matrix[i][j].val); + /* addch doesn't seem to work with unicode + * characters and there was no direct equivalent. + * So, construct a c-style string with the character + * and print that. + */ + wchar_t char_array[2]; + char_array[0] = matrix[i][j].val; + char_array[1] = 0; + addwstr(char_array); } if (bold == 2 || (bold == 1 && matrix[i][j].val % 2 == 0)) { @@ -754,31 +919,30 @@ if (console) { } } - //Check if computer is locked - if(lock == 1){ - + //check if -M and/or -L was used + if (msg[0] != '\0') { //Add our message to the screen - char *msg = "Computer locked."; int msg_x = LINES/2; int msg_y = COLS/2 - strlen(msg)/2; int i = 0; //Add space before message move(msg_x-1, msg_y-2); - for(i = 0; i < strlen(msg)+4; i++) + for (i = 0; i < strlen(msg)+4; i++) addch(' '); - + + //temporarily turning this off //Write message - move(msg_x, msg_y-2); - addch(' '); - addch(' '); - addstr(msg); - addch(' '); - addch(' '); + //move(msg_x, msg_y-2); + //addch(' '); + //addch(' '); + //addstr(msg); + //addch(' '); + //addch(' '); //Add space after message move(msg_x+1, msg_y-2); - for(i = 0; i < strlen(msg)+4; i++) + for (i = 0; i < strlen(msg)+4; i++) addch(' '); } @@ -786,4 +950,3 @@ if (console) { } finish(); } - diff --git a/configure.ac b/configure.ac index 8a8066a..0565a52 100644 --- 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 @@ -33,6 +42,11 @@ then AC_CHECK_LIB(curses, tgetent, CURSES_LIB="-lcurses" CURSES_LIB_NAME=curses) 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) @@ -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 @@ -59,13 +73,21 @@ AC_CHECK_LIB($CURSES_LIB_NAME, resizeterm, [AC_DEFINE(HAVE_RESIZETERM)]) AC_CHECK_LIB([$CURSES_LIB_NAME], wresize, [AC_DEFINE(HAVE_WRESIZE)]) -dnl Only change gcc options if we are using gcc. +dnl Only change gcc options if we are using gcc. if test "$ac_cv_prog_CC" = gcc -o "$ac_cv_prog_CC" = g++; then CFLAGS="$CFLAGS -Wall -Wno-comment" fi +dnl Build static executable on native Windows +if test x$native_windows != xno; then + CFLAGS="$CFLAGS -static" +fi + dnl cmatrix terminal font disable option (default enabled) -AC_ARG_WITH([fonts], AS_HELP_STRING([--without-fonts], [Install cmatrix without cmatrix font]), [enable_fonts=false], [enable_fonts=true]) +AC_ARG_WITH([fonts], + AS_HELP_STRING([--without-fonts], [Install cmatrix without cmatrix font]), + AS_IF([test "x$with_fonts" == "xno"], [enable_fonts=false], [enable_fonts=true]), + [enable_fonts=true]) if test "x$enable_fonts" != xfalse; then dnl Check for consolechars and setfonts @@ -81,7 +103,7 @@ if test "x$enable_fonts" != xfalse; then *** console without this program (it may still work in xterms). If you are *** using Linux, the package containing this program is usually called *** kbd, kbd-utils, or console-utils -]) +]) else AC_DEFINE_UNQUOTED(HAVE_SETFONT, $SETFONT) fi @@ -97,7 +119,7 @@ if test "x$enable_fonts" != xfalse; then if test "x$ac_cv_file__usr_lib_kbd_consolefonts" = "xno"; then if test "x$ac_cv_file__usr_share_consolefonts" = "xno"; then - AC_MSG_WARN([ + AC_MSG_WARN([ *** You do not appear to have a consolefonts directory in a standard location *** (/usr/lib/kbd or /usr/share), even though you appear to have the @@ -112,14 +134,14 @@ if test "x$enable_fonts" != xfalse; then fi AC_PATH_PROG(MKFONTDIR, mkfontdir, "", $PATH:/usr/bin:/usr/bin/X11:/usr/local/bin/X11:/usr/X11R6/bin:/usr/local/bin:/sbin:/usr/sbin) - AC_CHECK_FILES([/usr/lib/X11/fonts/misc /usr/X11R6/lib/X11/fonts/misc]) + AC_CHECK_FILES([/usr/share/fonts/misc /usr/share/X11/fonts/misc /usr/X11R6/lib/X11/fonts/misc]) if test "x$ac_cv_file__usr_lib_X11_fonts_misc" = "xno"; then if test "x$ac_cv_file__usr_X11R6_lib_X11_fonts_misc" = "xno"; then - AC_MSG_WARN([ + AC_MSG_WARN([ *** You do not appear to have an X window fonts directory in the standard -*** locations (/usr/lib/X11/fonts/misc or /usr/X11R6/lib/X11/fonts/misc). The +*** locations (/usr/share/fonts/misc or /usr/X11R6/lib/X11/fonts/misc). The *** mtx.pcf font will not be installed. This means you will probably not *** be able to use the mtx fonts in your x terminals, and hence be unable *** to use the -x command line switch. Sorry about that... @@ -136,7 +158,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]) diff --git a/takeScreenshots b/takeScreenshots index 5816607..c209090 100755 --- a/takeScreenshots +++ b/takeScreenshots @@ -1,4 +1,4 @@ -#!/bin/bash +#!/usr/bin/env bash # Produces a bunch of `cmatrix` screenshots and screencasts. # This script requires X and the following: #apt-get install rxvt byzanz @@ -11,18 +11,17 @@ TERM_EMULATOR_BASE="rxvt +sb" CAPTURES_DIR="data/img" # Function to take a single cmatrix screenshot (takes about 3.5s to execute) -# or optionally, a screncast of choosable length. -function captureCMatrix() -{ +# or optionally, a screencast of choosable length. +captureCMatrix() { CAPTURE_FILE="$1" CMATRIX_OPTIONS="$2" # If 0 (default if no 3rd param is given), # we make a screenshot instead of a screencast. SCREENCAST_DURATION="${3:-0}" - if [ ${SCREENCAST_DURATION} -gt 0 ] + if [ "${SCREENCAST_DURATION}" -gt 0 ] then - let KILL_DELAY="${SCREENCAST_DURATION} + 1" + KILL_DELAY="$((SCREENCAST_DURATION + 1))" CAPTURE_FILE="${CAPTURE_FILE}.gif" else KILL_DELAY=3 @@ -31,7 +30,7 @@ function captureCMatrix() WINDOW_TITLE="CMatrix capture ${CAPTURE_FILE}" # NOTE the "-PIPE" prevents output of the "Terminated: ..." message - ( cmdpid=$BASHPID; ( sleep ${KILL_DELAY}; kill -PIPE $cmdpid ) & exec ${TERM_EMULATOR_BASE} -name "${WINDOW_TITLE}" -title "${WINDOW_TITLE}" -e bash -c " + ( cmdpid=$BASHPID; ( sleep "${KILL_DELAY}"; kill -PIPE "$cmdpid" ) & exec ${TERM_EMULATOR_BASE} -name "${WINDOW_TITLE}" -title "${WINDOW_TITLE}" -e bash -c " if [ ${SCREENCAST_DURATION} -gt 0 ] then # Take screencast (animated GIF) @@ -74,4 +73,3 @@ do ${CMD_CS} "${CAPTURE_FILE_BASE}bold_C_${color}" "-b -C ${color}" done ${CMD_CS} "${CAPTURE_FILE_BASE}bold_rainbow" "-b -r" -