summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorKevin Lange <k@dakko.us>2011-12-04 01:12:11 -0600
committerKevin Lange <k@dakko.us>2011-12-04 01:12:11 -0600
commit8653b2f53860ef5ba4375a24ddc2108725b8ce0d (patch)
treeb86a8890774042b2d2ecb0d1dbeb4b1ede7987c8
parentaffb94d97a13ee48496706b746a26b4d1dcb1d3d (diff)
downloadnyancat-8653b2f53860ef5ba4375a24ddc2108725b8ce0d.tar.gz
You have nyaned for (way too long)
-rw-r--r--src/nyancat.c29
1 files changed, 25 insertions, 4 deletions
diff --git a/src/nyancat.c b/src/nyancat.c
index f02eebe..932c572 100644
--- a/src/nyancat.c
+++ b/src/nyancat.c
@@ -45,6 +45,7 @@
#include <stdlib.h>
#include <unistd.h>
#include <signal.h>
+#include <time.h>
#include "telnet.h"
/* The animation frames are stored separately. */
@@ -61,12 +62,21 @@ char * output = " ";
/* Telnet mode? */
int telnet = 0;
+/* I refuse to include libm */
+double log10(double x) {
+ int val = (int)x;
+ int d = 1, c;
+ if (val >= 0) for (c = 10; c <= val; c *= 10) d++;
+ else for (c = -10 ; c >= val; c *= 10) d++;
+ return (c < 0) ? (double)++d : (double)d;
+}
+
/*
* These values crop the animation, as we have a full 64x64 stored,
* but we only want to display 80x24.
*/
#define MIN_ROW 20
-#define MAX_ROW 44
+#define MAX_ROW 43
#define MIN_COL 10
#define MAX_COL 50
@@ -406,7 +416,6 @@ ready:
/* Clear the screen */
printf("\033[H\033[2J\033[?25l");
-
/* Display the MOTD */
int countdown_clock = 5;
for (k = 0; k < countdown_clock; ++k) {
@@ -437,6 +446,10 @@ ready:
/* Clear the screen again */
printf("\033[H\033[2J\033[?25l");
+ /* Store the start time */
+ time_t start, current;
+ time(&start);
+
int playing = 1;
size_t i = 0;
char last = 0;
@@ -460,9 +473,17 @@ ready:
}
}
/* End of row, send newline */
- if (y != MAX_ROW - 1)
- newline(1);
+ newline(1);
+ }
+ time(&current);
+ double diff = difftime(current, start);
+ double nLen = log10(diff);
+ int width = (80 - 29 - (int)nLen) / 2;
+ while (width) {
+ printf(" ");
+ width--;
}
+ printf("You have nyaned for %0.0f seconds!\033[J", diff);
/* Update frame crount */
++i;
if (!frames[i]) {
011-07-27Autoconf 2.68michael3-1455/+2751 git-svn-id: https://ssl.bulix.org/svn/lcd4linux/trunk@1152 3ae390bd-cb1e-0410-b409-cd5a39f66f1f 2011-07-27run smoketest on all of my 8 coresmichael1-2/+2 git-svn-id: https://ssl.bulix.org/svn/lcd4linux/trunk@1151 3ae390bd-cb1e-0410-b409-cd5a39f66f1f 2011-07-27indentationmichael4-330/+320 git-svn-id: https://ssl.bulix.org/svn/lcd4linux/trunk@1150 3ae390bd-cb1e-0410-b409-cd5a39f66f1f 2011-07-27patch to replace outdate library libmpd with recent library libmpdclient ↵michael2-240/+427 from Andreas Brachold git-svn-id: https://ssl.bulix.org/svn/lcd4linux/trunk@1149 3ae390bd-cb1e-0410-b409-cd5a39f66f1f 2011-07-27lcd4linux-wireless.patch from Hans de Goedemichael1-1/+1 git-svn-id: https://ssl.bulix.org/svn/lcd4linux/trunk@1148 3ae390bd-cb1e-0410-b409-cd5a39f66f1f 2011-07-27st2205-width-height-swap.patch from Hans de Goedemichael1-2/+2 git-svn-id: https://ssl.bulix.org/svn/lcd4linux/trunk@1147 3ae390bd-cb1e-0410-b409-cd5a39f66f1f 2011-07-27hwmon patch from Hans de Goedemichael1-0/+14 git-svn-id: https://ssl.bulix.org/svn/lcd4linux/trunk@1146 3ae390bd-cb1e-0410-b409-cd5a39f66f1f 2011-07-27patch to support SureElectronicsDE-LD023 from Matt Joicemichael1-3/+16 git-svn-id: https://ssl.bulix.org/svn/lcd4linux/trunk@1145 3ae390bd-cb1e-0410-b409-cd5a39f66f1f 2011-05-06Fixed keypad widget in GLCD2USBharbaum1-0/+7 git-svn-id: https://ssl.bulix.org/svn/lcd4linux/trunk@1144 3ae390bd-cb1e-0410-b409-cd5a39f66f1f 2011-02-12timer.c: fixed detection of positive clock skew (and some typos)mzuther4-10/+10 git-svn-id: https://ssl.bulix.org/svn/lcd4linux/trunk@1143 3ae390bd-cb1e-0410-b409-cd5a39f66f1f 2011-01-23timer.c: fixed clock skew detectionmzuther1-26/+46 git-svn-id: https://ssl.bulix.org/svn/lcd4linux/trunk@1142 3ae390bd-cb1e-0410-b409-cd5a39f66f1f 2011-01-23timer.c: skip intermediate timer intervalsmzuther2-16/+46 "timer_inc()" now checks how many trigger intervals have passed since a given timer has been updated. This might be due to "negative clock skew" (think of summer time) or the fact that some processing took too long (i.e. fetching of a web site). These missed trigger intervals are then skipped and the user is notified so that he may adapt his timer settings. This handling is essential, otherwise unprocessed timers might stack up and would trigger continuously while at the same time becoming notoriously late and unreliable. git-svn-id: https://ssl.bulix.org/svn/lcd4linux/trunk@1141 3ae390bd-cb1e-0410-b409-cd5a39f66f1f 2011-01-05fix for a bug introduced in the DE-LD021 drivermichael1-3/+3 git-svn-id: https://ssl.bulix.org/svn/lcd4linux/trunk@1140 3ae390bd-cb1e-0410-b409-cd5a39f66f1f 2011-01-04indentationmichael2-3/+3 git-svn-id: https://ssl.bulix.org/svn/lcd4linux/trunk@1139 3ae390bd-cb1e-0410-b409-cd5a39f66f1f 2011-01-04support for Sure Electronics DE-LD021 by Natanael Olaizmichael1-10/+8 git-svn-id: https://ssl.bulix.org/svn/lcd4linux/trunk@1138 3ae390bd-cb1e-0410-b409-cd5a39f66f1f 2011-01-02driver for EFN LED modules by Tilman Glötznermichael9-21/+469 git-svn-id: https://ssl.bulix.org/svn/lcd4linux/trunk@1137 3ae390bd-cb1e-0410-b409-cd5a39f66f1f 2010-11-28commented, corrected and beautified both timer and timer group codemzuther11-197/+511 git-svn-id: https://ssl.bulix.org/svn/lcd4linux/trunk@1136 3ae390bd-cb1e-0410-b409-cd5a39f66f1f 2010-11-27finished commenting the timer codemzuther2-46/+138 git-svn-id: https://ssl.bulix.org/svn/lcd4linux/trunk@1135 3ae390bd-cb1e-0410-b409-cd5a39f66f1f 2010-11-20started commenting the timer codemzuther5-52/+170 I'm not done yet, but my system is currently very unstable, and I don't want the changes to get lost... :( git-svn-id: https://ssl.bulix.org/svn/lcd4linux/trunk@1134 3ae390bd-cb1e-0410-b409-cd5a39f66f1f 2010-11-19Added brightness support for GLCD2USBharbaum5-28/+8014 git-svn-id: https://ssl.bulix.org/svn/lcd4linux/trunk@1133 3ae390bd-cb1e-0410-b409-cd5a39f66f1f