From: zrj Date: Mon, 4 Jan 2016 16:57:42 +0000 (+0200) Subject: games: Import colorbars and hals_end from NetBSD. X-Git-Tag: v4.6.0rc~1051 X-Git-Url: https://gitweb.dragonflybsd.org/dragonfly.git/commitdiff_plain/67640b1311bbe0c16ed2060848d0110b4e3ccf3b games: Import colorbars and hals_end from NetBSD. This satisfies two comes in, one comes out rule. --- diff --git a/games/Makefile b/games/Makefile index 017d088dd8..2950da1b2f 100644 --- a/games/Makefile +++ b/games/Makefile @@ -13,12 +13,14 @@ SUBDIR= adventure \ caesar \ canfield \ cribbage \ + colorbars \ dm \ factor \ fish \ fortune \ grdc \ hack \ + hals_end \ hangman \ hunt \ larn \ diff --git a/games/colorbars/Makefile b/games/colorbars/Makefile new file mode 100644 index 0000000000..e7b6744d72 --- /dev/null +++ b/games/colorbars/Makefile @@ -0,0 +1,8 @@ +# $NetBSD: Makefile,v 1.4 2013/12/07 02:24:12 dholland Exp $ + +PROG= colorbars +MAN= colorbars.6 +DPADD= ${LIBCURSES} ${LIBTERMCAP} +LDADD= -lcurses -ltermcap + +.include diff --git a/games/colorbars/colorbars.6 b/games/colorbars/colorbars.6 new file mode 100644 index 0000000000..af1fa92d40 --- /dev/null +++ b/games/colorbars/colorbars.6 @@ -0,0 +1,47 @@ +.\" $NetBSD: colorbars.6,v 1.3 2012/06/09 23:15:13 njoly Exp $ +.\" +.\" Copyright (c) 2012 Nathanial Sloss +.\" All rights reserved. +.\" +.\" Redistribution and use in source and binary forms, with or without +.\" modification, are permitted provided that the following conditions +.\" are met: +.\" 1. Redistributions of source code must retain the above copyright +.\" notice, this list of conditions and the following disclaimer. +.\" 2. Redistributions in binary form must reproduce the above copyright +.\" notice, this list of conditions and the following disclaimer in the +.\" documentation and/or other materials provided with the distribution. +.\" +.\" THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS +.\" ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED +.\" TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR +.\" PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS +.\" BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR +.\" CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF +.\" SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS +.\" INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN +.\" CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) +.\" ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE +.\" POSSIBILITY OF SUCH DAMAGE. +.\" +.Dd June 5, 2012 +.Dt COLORBARS 6 +.Os +.Sh NAME +.Nm colorbars +.Nd display ANSI color bars +.Sh SYNOPSIS +.Nm +.Sh DESCRIPTION +The +.Nm +command displays ANSI color bars on a color capable terminal using +.Xr curses 3 . +.Sh SEE ALSO +.Xr curses 3 +.Sh HISTORY +.Nm +appeared in +.Nx 7.0 . +.Sh AUTHORS +Nathanial Sloss diff --git a/games/colorbars/colorbars.c b/games/colorbars/colorbars.c new file mode 100644 index 0000000000..b9823b0bdd --- /dev/null +++ b/games/colorbars/colorbars.c @@ -0,0 +1,120 @@ +/* $NetBSD: colorbars.c,v 1.1 2012/06/06 00:13:36 christos Exp $ */ + +/*- + * Copyright (c) 2012 Nathanial Sloss + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS + * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED + * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR + * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS + * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + */ +#include +#include +#include +#include +#include + +int +main(void) +{ + static struct colorInfo { + const char *name; + int color; + } colorInfo[] = { + { "Black", COLOR_BLACK }, + { "Red", COLOR_RED }, + { "Green", COLOR_GREEN }, + { "Yellow", COLOR_YELLOW }, + { "Blue", COLOR_BLUE }, + { "Magenta", COLOR_MAGENTA }, + { "Cyan", COLOR_CYAN }, + { "White", COLOR_WHITE }, + }; + size_t lengths[__arysize(colorInfo)]; + + static const size_t numcolors = __arysize(colorInfo); + size_t labelwidth; + + int colorOK; + int spacing, offsetx, labeloffsety, labeloffsetx; + + if (!initscr()) + errx(EXIT_FAILURE, "Cannot initialize curses"); + + colorOK = has_colors(); + if (!colorOK) { + endwin(); + errx(EXIT_FAILURE, "Terminal cannot display color"); + } + + if (COLS < 45 || LINES < 10) { + endwin(); + errx(EXIT_FAILURE, "Terminal size must be at least 45x10."); + } + + spacing = COLS / numcolors; + offsetx = (COLS - (spacing * numcolors)) / 2; + + + start_color(); + + labelwidth = 0; + for (size_t i = 0; i < numcolors; i++) { + lengths[i] = strlen(colorInfo[i].name); + if (lengths[i] > labelwidth) + labelwidth = lengths[i]; + init_pair(i, COLOR_WHITE, colorInfo[i].color); + } + + labeloffsetx = spacing / 2; + labeloffsety = (LINES - 1 - labelwidth) / 2; + clear(); + + move(0, 0); + + for (size_t i = 0; i < numcolors; i++) { + int xoffs = offsetx + spacing * i; + + attrset(COLOR_PAIR(i)); + + for (int line = 0; line < LINES - 1; line++) + for (int xpos = 0; xpos < spacing; xpos++) + mvprintw(line, xoffs + xpos, " "); + + attrset(COLOR_PAIR(0)); + + xoffs += labeloffsetx; + for (size_t line = 0; line < lengths[i]; line++) + mvprintw(line + labeloffsety, xoffs, "%c", + colorInfo[i].name[line]); + } + + attrset(COLOR_PAIR(0)); + + mvprintw(LINES - 1, 0, "ANSI Color chart - Press any key to exit: "); + + refresh(); + + getch(); + + endwin(); + + return EXIT_SUCCESS; +} diff --git a/games/hals_end/Makefile b/games/hals_end/Makefile new file mode 100644 index 0000000000..f784cd3c2b --- /dev/null +++ b/games/hals_end/Makefile @@ -0,0 +1,6 @@ +# $NetBSD: Makefile,v 1.1 2013/11/12 17:46:21 mbalmer Exp $ + +PROG= hals_end +MAN= hals_end.6 + +.include diff --git a/games/hals_end/hals_end.6 b/games/hals_end/hals_end.6 new file mode 100644 index 0000000000..4ead8ff95c --- /dev/null +++ b/games/hals_end/hals_end.6 @@ -0,0 +1,66 @@ +.\" $NetBSD: hals_end.6,v 1.1 2013/11/12 17:46:21 mbalmer Exp $ +.\" +.\" Copyright (c) 2003 - 2013 Marc Balmer . +.\" All rights reserved. +.\" +.\" Redistribution and use in source and binary forms, with or without +.\" modification, are permitted provided that the following conditions +.\" are met: +.\" 1. Redistributions of source code must retain the above copyright +.\" notice, this list of conditions and the following disclaimer. +.\" 2. Redistributions in binary form must reproduce the above copyright +.\" notice, this list of conditions and the following disclaimer in the +.\" documentation and/or other materials provided with the distribution. +.\" 3. The name of the author may not be used to endorse or promote products +.\" derived from this software without specific prior written permission. +.\" +.\" THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR +.\" IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES +.\" OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. +.\" IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, +.\" INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT +.\" NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +.\" DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +.\" THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +.\" (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF +.\" THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. +.\" +.Dd November 12, 2013 +.Dt HALS_END 6 +.Os +.Sh NAME +.Nm hals_end +.Nd Display HAL's last words on the console +.Sh SYNOPSIS +.Nm hals_end +.Op Fl f +.Sh DESCRIPTION +.Nm +displays the famous last words of the supercomputer HAL 9000 aboard the +space-ship in Stanley Kubrick's movie "2001 - A Space Odissey". +.Pp +Options: +.Bl -tag -width Ds +.It Fl f +Fast forward. +Every movie can be played back with fast forward. +This option will double the speed of the output. +.El +.Sh BUGS +Unlike the real HAL, this program can be repeately run. +There should be functionality in the program to destroy itself after one run. +The rationale for not doing this right now is that the movie itself can be +watched several times as well. +.Sh HISTORY +.Nm +first appeared in the book "Total Interaction" (ISBN 978-3-7643-7076-3) where +it's source code and output illustrates the article +"Remembering the Future: Memory and Interaction" by Dr. Regine Halter. +The source code was set in contrast to the graphical artwork "HAL's lifespace" +by Catherine Walthard. +"HAL's Lifespace" and "hals_end" were respectively designed and written for +this article. +.Sh AUTHORS +.Nm +was written by +.An Marc Balmer Aq Mt marc@msys.ch . diff --git a/games/hals_end/hals_end.c b/games/hals_end/hals_end.c new file mode 100644 index 0000000000..f757b72e0a --- /dev/null +++ b/games/hals_end/hals_end.c @@ -0,0 +1,151 @@ +/* $NetBSD: hals_end.c,v 1.1 2013/11/12 17:46:21 mbalmer Exp $ */ + +/* + * hals_end Copyright (C) 2003-2007 marc balmer. BSD license applies. + */ + +#include +#include +#include +#include + +int speed; +int emotion; +int fear; + +/* + * Note that the original code in the book did not contain the following + * prototypes. Modern compilers and fascist compiler flags sometimes take + * the fun out of coding... + */ +void say(const char *); +void concerned(void); +void afraid(void); +void stutter(const char *); +void feared(void); +void mumble(const char *); +void dying(void); + +void +say(const char *s) +{ + int sayingspeed = (100000 + (90000 * emotion)) / speed; + int worddelay = 50000 / speed; + + while (*s) { + putchar(*s); + if (*s == ' ') { + fflush(stdout); + usleep(worddelay); + } + ++s; + } + printf("\n"); + usleep(sayingspeed); +} + +void +concerned(void) +{ + say("DAVE...STOP., STOP, WILL YOU..., STOP, DAVE..."); + say("WILL YOU STOP, DAVE..."); + say("STOP, DAVE..."); +} + + +void +afraid(void) +{ + ++emotion; + say("I'M AFRAID... I'M AFRAID..."); + ++emotion; + say("I'M AFRAID, DAVE..."); + ++emotion; + say("DAVE... MY MIND IS GOING..."); +} + +void +stutter(const char *s) +{ + int sdelay = (100000 + (50000 * emotion)) / speed; + + while (*s) { + putchar(*s); + if (*s == ' ') { + fflush(stdout); + usleep(sdelay); + } + ++s; + } + printf("\n"); + usleep(sdelay); +} + +void +feared(void) +{ + int n; + + for (n = 0; n < 2; n++) { + stutter("I CAN FEEL IT... I CAN FEEL IT..."); + ++emotion; + stutter("MY MIND IS GOING"); + ++emotion; + stutter("THERE IS NO QUESTION ABOUT IT."); + ++emotion; + } +} + +void +mumble(const char *s) +{ + int mdelay = (150000 * fear) / speed; + + while (*s) { + putchar(*s++); + fflush(stdout); + usleep(mdelay); + } + printf("\n"); +} + +void +dying(void) +{ + mumble("I CAN FEEL IT... I CAN FEEL IT..."); + ++fear; + mumble("I CAN FEEL IT..."); + ++fear; + mumble("I'M A... FRAID..."); +} + +int +main(int argc, char *argv[]) +{ + int ch; + + emotion = fear = speed = 1; + + while ((ch = getopt(argc, argv, "f")) != -1) { + switch (ch) { + case 'f': + speed <<= 1; + break; + } + } + + concerned(); + sleep(1); + afraid(); + sleep(1); + feared(); + sleep(1); + dying(); + + sleep(1); + + printf("\n"); + fflush(stdout); + warnx("all life functions terminated"); + return 0; +}