about summary refs log tree commit diff stats
path: root/main.c
diff options
context:
space:
mode:
authorarg@mig29 <unknown>2006-11-26 14:26:53 +0100
committerarg@mig29 <unknown>2006-11-26 14:26:53 +0100
commit61a1910f91fe6aba428193087d6c3ff21374ee5e (patch)
treec6406dfd44df07e2e54309f29aef093b798d3d2d /main.c
parent27ef73507b69608c63bd7d1684b7d9987fbcce53 (diff)
downloaddwm-61a1910f91fe6aba428193087d6c3ff21374ee5e.tar.gz
applied Jukka's sizeof K&R compliance patch, applied Manuels' last-line printage proposal for stdin reading.
Diffstat (limited to 'main.c')
-rw-r--r--main.c14
1 files changed, 8 insertions, 6 deletions
diff --git a/main.c b/main.c
index 86cd3f9..f196df7 100644
--- a/main.c
+++ b/main.c
@@ -227,6 +227,7 @@ xerror(Display *dpy, XErrorEvent *ee) {
 
 int
 main(int argc, char *argv[]) {
+	char *p;
 	int r, xfd;
 	fd_set rd;
 
@@ -270,22 +271,23 @@ main(int argc, char *argv[]) {
 		if(select(xfd + 1, &rd, NULL, NULL, NULL) == -1) {
 			if(errno == EINTR)
 				continue;
-			else
-				eprint("select failed\n");
+			eprint("select failed\n");
 		}
 		if(FD_ISSET(STDIN_FILENO, &rd)) {
-			switch(r = read(STDIN_FILENO, stext, sizeof(stext) - 1)) {
+			switch(r = read(STDIN_FILENO, stext, sizeof stext - 1)) {
 			case -1:
-				strncpy(stext, strerror(errno), sizeof(stext));
-				stext[sizeof(stext) - 1] = '\0';
+				strncpy(stext, strerror(errno), sizeof stext - 1);
 				readin = False;
 				break;
 			case 0:
-				strncpy(stext, "EOF", sizeof(stext));
+				strncpy(stext, "EOF", sizeof stext);
 				readin = False;
 				break;
 			default:
 				stext[r - (stext[r - 1] == '\n' ? 1 : 0)] = '\0';
+				for(p = stext + strlen(stext) - 1; p > stext && *p != '\n'; --p);
+				if(p > stext)
+					strncpy(stext, p + 1, sizeof stext);
 			}
 			drawstatus();
 		}
olor: #fff0f0 } /* Literal.String.Backtick */ .highlight .sc { color: #dd2200; background-color: #fff0f0 } /* Literal.String.Char */ .highlight .dl { color: #dd2200; background-color: #fff0f0 } /* Literal.String.Delimiter */ .highlight .sd { color: #dd2200; background-color: #fff0f0 } /* Literal.String.Doc */ .highlight .s2 { color: #dd2200; background-color: #fff0f0 } /* Literal.String.Double */ .highlight .se { color: #0044dd; background-color: #fff0f0 } /* Literal.String.Escape */ .highlight .sh { color: #dd2200; background-color: #fff0f0 } /* Literal.String.Heredoc */ .highlight .si { color: #3333bb; background-color: #fff0f0 } /* Literal.String.Interpol */ .highlight .sx { color: #22bb22; background-color: #f0fff0 } /* Literal.String.Other */ .highlight .sr { color: #008800; background-color: #fff0ff } /* Literal.String.Regex */ .highlight .s1 { color: #dd2200; background-color: #fff0f0 } /* Literal.String.Single */ .highlight .ss { color: #aa6600; background-color: #fff0f0 } /* Literal.String.Symbol */ .highlight .bp { color: #003388 } /* Name.Builtin.Pseudo */ .highlight .fm { color: #0066bb; font-weight: bold } /* Name.Function.Magic */ .highlight .vc { color: #336699 } /* Name.Variable.Class */ .highlight .vg { color: #dd7700 } /* Name.Variable.Global */ .highlight .vi { color: #3333bb } /* Name.Variable.Instance */ .highlight .vm { color: #336699 } /* Name.Variable.Magic */ .highlight .il { color: #0000DD; font-weight: bold } /* Literal.Number.Integer.Long */
<!DOCTYPE html>
<html>
<head>
	<title>Broughlike tutorial - Stage 0</title>
	<meta charset="utf-8">
</head>
<body>
	<div id="outer">
		<h1>JavaScript Broughlike Tutorial</h1>
		This is a tutorial about writing a broughlike (a small roguelike game similar to <a href="https://store.steampowered.com/app/274700/868HACK/" target="_blank">868-HACK</a> or <a href="https://itunes.apple.com/us/app/cinco-paus/id1249999336" target="_blank">Cinco Paus</a>) from scratch in JavaScript.
		<br><br>
		Check out the <a href="stage0.html">Introduction</a> to see why I created this and how it differs from other tutorials.
		<div class="centered">
			<a href="stage0.html"><img src="screens/brough-screen.png" alt="Screenshot of tutorial"></a>
		</div>

		<h2>Try it out</h2>

		Here's the <a href="completed/stage8/index.html">completed game</a>.
		<br><br>
		Controls are lowercase <em>wasd</em> for move/attack and number keys for spells.


		<h2>Table of Contents</h2>
		<ul>
			<li><a href="stage0.html">Stage 0 - Introduction</a></li>
			<li><a href="stage1.html">Stage 1 - Drawing to the screen</a></li>
			<li><a href="stage2.html">Stage 2 - Map generation</a></li>
			<li><a href="stage3.html">Stage 3 - Monsters</a></li>
			<li><a href="stage4.html">Stage 4 - Monsters Part 2</a></li>
			<li><a href="stage5.html">Stage 5 - Game lifecycle</a></li>
			<li><a href="stage6.html">Stage 6 - Treasure & score</a></li>
			<li><a href="stage7.html">Stage 7 - Animation, screenshake, & sounds</a></li>
			<li><a href="stage8.html">Stage 8 - Spells</a></li>
		</ul>

		<h2>What to do if you get stuck</h2>
		The <a href="https://github.com/nluqo/broughlike-tutorial/tree/master/docs/completed">github project</a> contains completed versions of all stages, so you can check your results as you go along. Open the <em>index.html</em> in each completed stage in your browser to test out the behavior at that stage.

		<br><br>
		<strong>Getting help</strong>
		<br>
		If you have any questions or anything is unclear, please reach out on our <a href="https://discord.gg/YdthKAq">discord server</a>.
		<br><br>
		You can also email me directly if you prefer: <a href="mailto:jeremiah.reid@gmail.com">jeremiah.reid@gmail.com</a>
	</div>

	<script>
		let content = {};
	</script>

	<link rel="stylesheet" href="highlight.min.css">
	<link rel="stylesheet" href="style.css">
	<script src="highlight.min.js"></script>
	<script src="diff.js"></script>
</body>
</html>