aboutsummaryrefslogtreecommitdiffstats
path: root/src/nyancat.c
diff options
context:
space:
mode:
authorJonathan McCrohan <jmccrohan@gmail.com>2013-03-10 00:05:39 +0000
committerJonathan McCrohan <jmccrohan@gmail.com>2013-03-14 22:17:37 +0000
commit30ea534e61594cbe41651e8110aa5ead2e947ed6 (patch)
tree1105e1b25aecdd072e8fb9b02a4291a86ba713e6 /src/nyancat.c
parentaf6bfbc44713ed2c19a81aac88bb0e3eb9d8aa20 (diff)
parent43097ebfc2bc9bc0f721f5f80dc1aede1f7e10d7 (diff)
downloadnyancat-30ea534e61594cbe41651e8110aa5ead2e947ed6.tar.gz
Merge branch 'master' of git://github.com/klange/nyancat
Conflicts: Makefile
Diffstat (limited to 'src/nyancat.c')
-rw-r--r--src/nyancat.c59
1 files changed, 44 insertions, 15 deletions
diff --git a/src/nyancat.c b/src/nyancat.c
index 234ff10..44bdf06 100644
--- a/src/nyancat.c
+++ b/src/nyancat.c
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 2011 Kevin Lange. All rights reserved.
+ * Copyright (c) 2011-2013 Kevin Lange. All rights reserved.
*
* Developed by: Kevin Lange
* http://github.com/klange/nyancat
@@ -58,9 +58,22 @@
#include <signal.h>
#include <time.h>
#include <setjmp.h>
-#include <sys/ioctl.h>
#include <getopt.h>
+#ifdef __toaru__
+
+#include <syscall.h>
+
+DEFN_SYSCALL2(nanosleep, 46, unsigned long, unsigned long);
+
+int usleep(useconds_t time) {
+ syscall_nanosleep(0, time / 10000);
+}
+
+#else
+#include <sys/ioctl.h>
+#endif
+
#ifndef TIOCGWINSZ
#include <termios.h>
#ifdef ECHO
@@ -304,8 +317,8 @@ int main(int argc, char ** argv) {
int k, ttype;
uint32_t option = 0, done = 0, sb_mode = 0, do_echo = 0;
/* Various pieces for the telnet communication */
- char sb[1024] = {0};
- char sb_len = 0;
+ char sb[1024] = {0};
+ short sb_len = 0;
/* Whether or not to show the MOTD intro */
char show_intro = 0;
@@ -430,14 +443,14 @@ int main(int argc, char ** argv) {
if (sb[0] == TTYPE) {
/* This was a response to the TTYPE command, meaning
* that this should be a terminal type */
- alarm(0);
+ alarm(2);
strcpy(term, &sb[2]);
done++;
}
else if (sb[0] == NAWS) {
/* This was a response to the NAWS command, meaning
* that this should be a window size */
- alarm(0);
+ alarm(2);
terminal_width = sb[2];
done++;
}
@@ -483,7 +496,7 @@ int main(int argc, char ** argv) {
/* Begin Extended Option Mode */
sb_mode = 1;
sb_len = 0;
- memset(sb, 0, 1024);
+ memset(sb, 0, sizeof(sb));
break;
case IAC:
/* IAC IAC? That's probably not right. */
@@ -494,7 +507,7 @@ int main(int argc, char ** argv) {
}
} else if (sb_mode) {
/* Extended Option Mode -> Accept character */
- if (sb_len < 1023) {
+ if (sb_len < sizeof(sb) - 1) {
/* Append this character to the SB string,
* but only if it doesn't put us over
* our limit; honestly, we shouldn't hit
@@ -508,6 +521,7 @@ int main(int argc, char ** argv) {
}
}
}
+ alarm(0);
} else {
/* We are running standalone, retrieve the
* terminal type from the environment. */
@@ -517,9 +531,20 @@ int main(int argc, char ** argv) {
}
/* Also get the number of columns */
+#ifdef __toaru__
+ if (strstr(term, "toaru")) {
+ printf("\033[1003z");
+ fflush(stdout);
+ int height;
+ scanf("%d,%d", &terminal_width, &height);
+ } else {
+ terminal_width = 80; /* better safe than sorry */
+ }
+#else
struct winsize w;
ioctl(0, TIOCGWINSZ, &w);
terminal_width = w.ws_col;
+#endif
}
/* Convert the entire terminal string to lower case */
@@ -535,6 +560,8 @@ int main(int argc, char ** argv) {
/* Do our terminal detection */
if (strstr(term, "xterm")) {
ttype = 1; /* 256-color, spaces */
+ } else if (strstr(term, "toaru")) {
+ ttype = 1; /* emulates xterm */
} else if (strstr(term, "linux")) {
ttype = 3; /* Spaces and blink attribute */
} else if (strstr(term, "vtnt")) {
@@ -549,6 +576,8 @@ int main(int argc, char ** argv) {
ttype = 3; /* Accepts LINUX mode */
} else if (strstr(term, "vt100") && terminal_width == 40) {
ttype = 7; /* No color support, only 40 columns */
+ } else if (!strncmp(term, "st", 2)) {
+ ttype = 1; /* suckless simple terminal is xterm-256color-compatible */
} else {
ttype = 2; /* Everything else */
}
@@ -559,18 +588,18 @@ int main(int argc, char ** argv) {
switch (ttype) {
case 1:
colors[','] = "\033[48;5;17m"; /* Blue background */
- colors['.'] = "\033[48;5;15m"; /* White stars */
- colors['\''] = "\033[48;5;0m"; /* Black border */
+ colors['.'] = "\033[48;5;231m"; /* White stars */
+ colors['\''] = "\033[48;5;16m"; /* Black border */
colors['@'] = "\033[48;5;230m"; /* Tan poptart */
colors['$'] = "\033[48;5;175m"; /* Pink poptart */
colors['-'] = "\033[48;5;162m"; /* Red poptart */
- colors['>'] = "\033[48;5;9m"; /* Red rainbow */
- colors['&'] = "\033[48;5;202m"; /* Orange rainbow */
- colors['+'] = "\033[48;5;11m"; /* Yellow Rainbow */
- colors['#'] = "\033[48;5;10m"; /* Green rainbow */
+ colors['>'] = "\033[48;5;196m"; /* Red rainbow */
+ colors['&'] = "\033[48;5;214m"; /* Orange rainbow */
+ colors['+'] = "\033[48;5;226m"; /* Yellow Rainbow */
+ colors['#'] = "\033[48;5;118m"; /* Green rainbow */
colors['='] = "\033[48;5;33m"; /* Light blue rainbow */
colors[';'] = "\033[48;5;19m"; /* Dark blue rainbow */
- colors['*'] = "\033[48;5;8m"; /* Gray cat face */
+ colors['*'] = "\033[48;5;240m"; /* Gray cat face */
colors['%'] = "\033[48;5;175m"; /* Pink cheeks */
break;
case 2: