projects
/
wumpus.git
/ blobdiff
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
shortlog
|
log
|
commit
|
commitdiff
|
tree
raw
|
inline
| side by side
Prepare superhack.c for 1TBS reflow.
[wumpus.git]
/
superhack.c
diff --git
a/superhack.c
b/superhack.c
index c5461a1ff7f3fae5ff1c84a46be6073c55fc1c46..8ddd148cfec9e9095ad0b9ad88974a0db3b51c12 100644
(file)
--- a/
superhack.c
+++ b/
superhack.c
@@
-8,6
+8,8
@@
*
* Any resemblance to persons living or dead is strictly coincidental. And
* if you believe *that*...
*
* Any resemblance to persons living or dead is strictly coincidental. And
* if you believe *that*...
+ *
+ * SPDX-License-Identifier: BSD-2-Clause
*/
#include <stdio.h>
*/
#include <stdio.h>
@@
-22,6
+24,7
@@
static int path[5];
static int j, k, scratchloc, pies;
static char inp[BUFSIZ]; /* common input buffer */
static int j, k, scratchloc, pies;
static char inp[BUFSIZ]; /* common input buffer */
+#define NUMBERS "0123456789"
#define YOU 0
#define RMS 1
#define STARLET1 2
#define YOU 0
#define RMS 1
#define STARLET1 2
@@
-74,8
+77,9
@@
int getlet(prompt)
char *prompt;
{
(void) printf("%s? ", prompt);
char *prompt;
{
(void) printf("%s? ", prompt);
- if (fgets(inp, sizeof(inp), stdin))
+ if (fgets(inp, sizeof(inp), stdin))
{
return(tolower(inp[0]));
return(tolower(inp[0]));
+ }
else {
fputs("\n",stdout);
exit(1);
else {
fputs("\n",stdout);
exit(1);
@@
-162,9
+166,11
@@
int where;
retry:
newloc = FNA();
retry:
newloc = FNA();
- for (j = 0; j < LOCS; j++)
- if (loc[j] == newloc)
+ for (j = 0; j < LOCS; j++)
{
+ if (loc[j] == newloc) {
goto retry;
goto retry;
+ }
+ }
loc[where] = newloc;
}
loc[where] = newloc;
}
@@
-210,14
+216,18
@@
void check_hazards()
{
int room = cave[loc[YOU]][k];
{
int room = cave[loc[YOU]][k];
- if (room == loc[RMS])
+ if (room == loc[RMS])
{
(void) puts("I smell a superhack!");
(void) puts("I smell a superhack!");
- else if (room == loc[STARLET1] || room == loc[STARLET2])
+ }
+ else if (room == loc[STARLET1] || room == loc[STARLET2]) {
(void) puts("I smell perfume!");
(void) puts("I smell perfume!");
- else if (room == loc[DROID1] || room == loc[DROID2])
+ }
+ else if (room == loc[DROID1] || room == loc[DROID2]) {
(void) puts("Droids nearby!");
(void) puts("Droids nearby!");
- else if (room == loc[LUSER1] || room == loc[LUSER2])
+ }
+ else if (room == loc[LUSER1] || room == loc[LUSER2]) {
(void) puts("Lusers nearby!");
(void) puts("Lusers nearby!");
+ }
}
}
}
}
@@
-226,20
+236,22
@@
void throw()
extern void check_shot(), move_superhack();
int j9;
extern void check_shot(), move_superhack();
int j9;
- j9 = sscanf(inp +
isalpha(inp[0]
), "%d %d %d %d %d",
+ j9 = sscanf(inp +
strcspn(inp, NUMBERS
), "%d %d %d %d %d",
&path[0], &path[1], &path[2], &path[3], &path[4]);
&path[0], &path[1], &path[2], &path[3], &path[4]);
+
if (j9 < 1)
{
PM("Sorry, I didn't see any room numbers after your throw command.");
return;
}
if (j9 < 1)
{
PM("Sorry, I didn't see any room numbers after your throw command.");
return;
}
- for (k = 0; k < j9; k++)
+ for (k = 0; k < j9; k++)
{
if (k >= 2 && path[k] == path[k - 2])
{
(void) puts("Pies can't fly that crookedly --- try again.");
return;
}
if (k >= 2 && path[k] == path[k - 2])
{
(void) puts("Pies can't fly that crookedly --- try again.");
return;
}
+ }
scratchloc = loc[YOU];
scratchloc = loc[YOU];
@@
-253,8
+265,9
@@
void throw()
{
scratchloc = path[k];
check_shot();
{
scratchloc = path[k];
check_shot();
- if (finished != NOT)
+ if (finished != NOT)
{
return;
return;
+ }
}
}
}
}
@@
-273,8
+286,9
@@
void throw()
move_superhack();
move_superhack();
- if (--pies <= 0)
+ if (--pies <= 0)
{
finished = LOSE;
finished = LOSE;
+ }
}
}
}
}
@@
-298,11
+312,13
@@
void move_superhack()
{
k = FNC();
{
k = FNC();
- if (k < 3)
+ if (k < 3)
{
loc[RMS] = cave[loc[RMS]][k];
loc[RMS] = cave[loc[RMS]][k];
+ }
- if (loc[RMS] != loc[YOU])
+ if (loc[RMS] != loc[YOU])
{
return;
return;
+ }
(void) puts("The superhack flames you to a crisp. You lose!");
(void) puts("The superhack flames you to a crisp. You lose!");
@@
-312,7
+328,7
@@
void move_superhack()
void move()
{
void move()
{
- if (sscanf(inp +
isalpha(inp[0]
), "%d", &scratchloc) < 1)
+ if (sscanf(inp +
strcspn(inp, NUMBERS
), "%d", &scratchloc) < 1)
{
PM("Sorry, I didn't see a room number after your `m' command.");
return;
{
PM("Sorry, I didn't see a room number after your `m' command.");
return;
@@
-320,9
+336,11
@@
void move()
scratchloc--;
scratchloc--;
- for (k = 0; k < 3; k++)
- if (cave[loc[YOU]][k] == scratchloc)
- goto goodmove;
+ for (k = 0; k < 3; k++) {
+ if (cave[loc[YOU]][k] == scratchloc) {
+ goto goodmove;
+ }
+ }
PM("You can't get there from here!");
return;
PM("You can't get there from here!");
return;
@@
-355,23
+373,30
@@
goodmove:
int main(int argc, char *argv[])
{
int main(int argc, char *argv[])
{
- if (argc >= 2 && strcmp(argv[1], "-s") == 0)
- srand(atoi(argv[2]));
- else
- srand((int)time((long *) 0));
+ if (argc >= 2 && strcmp(argv[1], "-s") == 0) {
+ srand(atoi(argv[2]));
+ }
+ else {
+ srand((int)time((long *) 0));
+ }
for (;;)
{
badlocs:
for (;;)
{
badlocs:
- for (j = 0; j < LOCS; j++)
- loc[j] = FNA();
+ for (j = 0; j < LOCS; j++) {
+ loc[j] = FNA();
+ }
- for (j = 0; j < LOCS; j++)
- for (k = 0; k < LOCS; k++)
- if (j == k)
- continue;
- else if (loc[j] == loc[k])
- goto badlocs;
+ for (j = 0; j < LOCS; j++) {
+ for (k = 0; k < LOCS; k++) {
+ if (j == k) {
+ continue;
+ }
+ else if (loc[j] == loc[k]) {
+ goto badlocs;
+ }
+ }
+ }
(void) puts("Hunt the Superhack");
(void) puts("Hunt the Superhack");
@@
-387,12
+412,15
@@
int main(int argc, char *argv[])
c = getlet("Throw, move or help [t,m,?]");
c = getlet("Throw, move or help [t,m,?]");
- if (c == 't')
+ if (c == 't')
{
throw();
throw();
- else if (c == 'm')
+ }
+ else if (c == 'm') {
move();
move();
- else if (c == '?')
+ }
+ else if (c == '?') {
print_instructions();
print_instructions();
+ }
#ifdef DEBUG
else if (c == 'd')
{
#ifdef DEBUG
else if (c == 'd')
{