From fd6b3c6de21724f8dff524d602ef88c8b3128da7 Mon Sep 17 00:00:00 2001 From: Sven Herzberg Date: Tue, 3 Jul 2012 18:10:32 +0200 Subject: do not hardcode sizes MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit This patch will fix the following warning I received from gcc: > nyancat.c: In function ‘main’: > nyancat.c:497: warning: comparison is always true due to limited range of data type * src/nyancat.c: adjust the size of the array and update the references to its size --- src/nyancat.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'src') diff --git a/src/nyancat.c b/src/nyancat.c index 234ff10..fbb3c6e 100644 --- a/src/nyancat.c +++ b/src/nyancat.c @@ -483,7 +483,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 +494,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 -- cgit v1.2.3 From c035cf7f9ba1fdc07f77d6fa2e37e1e48c6ee3dd Mon Sep 17 00:00:00 2001 From: Kevin Lange Date: Tue, 3 Jul 2012 15:24:58 -0700 Subject: Fix type for sb_len --- src/nyancat.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'src') diff --git a/src/nyancat.c b/src/nyancat.c index fbb3c6e..67820ef 100644 --- a/src/nyancat.c +++ b/src/nyancat.c @@ -304,8 +304,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; -- cgit v1.2.3 From 01f6c5ec53c2e545a089fc3c885bd5584c5e6821 Mon Sep 17 00:00:00 2001 From: Kevin Lange Date: Wed, 12 Sep 2012 17:40:49 -0700 Subject: Support the Suckless simple terminal `st` supports xterm-256color escapes, so just treat it the same as we treat xterm. --- src/nyancat.c | 2 ++ 1 file changed, 2 insertions(+) (limited to 'src') diff --git a/src/nyancat.c b/src/nyancat.c index 67820ef..d6eb4e4 100644 --- a/src/nyancat.c +++ b/src/nyancat.c @@ -549,6 +549,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 */ } -- cgit v1.2.3 From e948abcb64adf60faa0c9ae095fdd85d0dfab7ce Mon Sep 17 00:00:00 2001 From: Kevin Lange Date: Thu, 13 Dec 2012 19:58:37 -0800 Subject: =?UTF-8?q?Support=20building=20and=20running=20on=20=E3=81=A8?= =?UTF-8?q?=E3=81=82=E3=82=8BOS?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/nyancat.c | 28 +++++++++++++++++++++++++++- 1 file changed, 27 insertions(+), 1 deletion(-) (limited to 'src') diff --git a/src/nyancat.c b/src/nyancat.c index d6eb4e4..6ab0403 100644 --- a/src/nyancat.c +++ b/src/nyancat.c @@ -58,9 +58,22 @@ #include #include #include -#include #include +#ifdef __toaru__ + +#include + +DEFN_SYSCALL2(nanosleep, 46, unsigned long, unsigned long); + +int usleep(useconds_t time) { + syscall_nanosleep(0, time / 10000); +} + +#else +#include +#endif + #ifndef TIOCGWINSZ #include #ifdef ECHO @@ -517,9 +530,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 +559,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")) { -- cgit v1.2.3 From 1652cd3bd12088296c27efba909bdc1b4123ae3c Mon Sep 17 00:00:00 2001 From: Kevin Lange Date: Fri, 21 Dec 2012 03:50:38 -0800 Subject: For the morons using solarized --- src/nyancat.c | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) (limited to 'src') diff --git a/src/nyancat.c b/src/nyancat.c index 6ab0403..02965a5 100644 --- a/src/nyancat.c +++ b/src/nyancat.c @@ -587,18 +587,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;255m"; /* White stars */ + colors['\''] = "\033[48;5;232m"; /* 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: -- cgit v1.2.3 From 3e1afbd2a68e0634c073bc37f7d493421b39f7a2 Mon Sep 17 00:00:00 2001 From: Kevin Lange Date: Fri, 21 Dec 2012 03:59:38 -0800 Subject: Better white and black --- src/nyancat.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'src') diff --git a/src/nyancat.c b/src/nyancat.c index 02965a5..759b9bf 100644 --- a/src/nyancat.c +++ b/src/nyancat.c @@ -587,8 +587,8 @@ int main(int argc, char ** argv) { switch (ttype) { case 1: colors[','] = "\033[48;5;17m"; /* Blue background */ - colors['.'] = "\033[48;5;255m"; /* White stars */ - colors['\''] = "\033[48;5;232m"; /* 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 */ -- cgit v1.2.3 From 3b70f513774d2e7098db93bcc9e51497a2037d44 Mon Sep 17 00:00:00 2001 From: Kevin Lange Date: Fri, 11 Jan 2013 15:52:05 -0800 Subject: Update src/nyancat.c update copyright date, happy new year --- src/nyancat.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'src') diff --git a/src/nyancat.c b/src/nyancat.c index 759b9bf..e7d3f38 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 -- cgit v1.2.3 From 634c7d3e97c5bda9635815a55eb7294c3eb0ac62 Mon Sep 17 00:00:00 2001 From: Kevin Lange Date: Thu, 7 Mar 2013 19:43:48 -0800 Subject: Set alarm for extended options. Instead of clearing the alarm, set it to two seconds; Previously, this could, potentially, not finish at all on some telnet clients, which is definitely bad. This is a reasonable workaround. --- src/nyancat.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'src') diff --git a/src/nyancat.c b/src/nyancat.c index e7d3f38..2137849 100644 --- a/src/nyancat.c +++ b/src/nyancat.c @@ -443,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++; } -- cgit v1.2.3 From 4f4d5d418a0e060b8c6418995088eeec39b54c35 Mon Sep 17 00:00:00 2001 From: Kevin Lange Date: Thu, 7 Mar 2013 19:47:03 -0800 Subject: Reset alarm before setting to 2secs --- src/nyancat.c | 2 ++ 1 file changed, 2 insertions(+) (limited to 'src') diff --git a/src/nyancat.c b/src/nyancat.c index 2137849..cef7034 100644 --- a/src/nyancat.c +++ b/src/nyancat.c @@ -443,6 +443,7 @@ 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++; @@ -450,6 +451,7 @@ int main(int argc, char ** argv) { 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++; -- cgit v1.2.3 From 4960f3ff2fc7c4313df1980d5c4f0a3c5fec48aa Mon Sep 17 00:00:00 2001 From: Kevin Lange Date: Thu, 7 Mar 2013 19:48:47 -0800 Subject: Hm, or not. --- src/nyancat.c | 2 -- 1 file changed, 2 deletions(-) (limited to 'src') diff --git a/src/nyancat.c b/src/nyancat.c index cef7034..e7d3f38 100644 --- a/src/nyancat.c +++ b/src/nyancat.c @@ -444,7 +444,6 @@ int main(int argc, char ** argv) { /* 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++; } @@ -452,7 +451,6 @@ int main(int argc, char ** argv) { /* 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++; } -- cgit v1.2.3 From 43097ebfc2bc9bc0f721f5f80dc1aede1f7e10d7 Mon Sep 17 00:00:00 2001 From: Kevin Lange Date: Thu, 7 Mar 2013 19:54:32 -0800 Subject: Ah, right, yes. --- src/nyancat.c | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) (limited to 'src') diff --git a/src/nyancat.c b/src/nyancat.c index e7d3f38..44bdf06 100644 --- a/src/nyancat.c +++ b/src/nyancat.c @@ -443,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++; } @@ -521,6 +521,7 @@ int main(int argc, char ** argv) { } } } + alarm(0); } else { /* We are running standalone, retrieve the * terminal type from the environment. */ -- cgit v1.2.3