From 534e3e36786bd08665285fa3a7bf4dd3cc174e7b Mon Sep 17 00:00:00 2001 From: "Eric S. Raymond" Date: Mon, 29 Jan 2024 04:27:20 -0500 Subject: [PATCH] Prepare superhack.c for 1TBS reflow. --- superhack.c | 84 ++++++++++++++++++++++++++++++++++------------------- 1 file changed, 54 insertions(+), 30 deletions(-) diff --git a/superhack.c b/superhack.c index 2a245bd..8ddd148 100644 --- a/superhack.c +++ b/superhack.c @@ -77,8 +77,9 @@ int getlet(prompt) char *prompt; { (void) printf("%s? ", prompt); - if (fgets(inp, sizeof(inp), stdin)) + if (fgets(inp, sizeof(inp), stdin)) { return(tolower(inp[0])); + } else { fputs("\n",stdout); exit(1); @@ -165,9 +166,11 @@ int where; 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; + } + } loc[where] = newloc; } @@ -213,14 +216,18 @@ void check_hazards() { int room = cave[loc[YOU]][k]; - if (room == loc[RMS]) + if (room == loc[RMS]) { (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!"); - else if (room == loc[DROID1] || room == loc[DROID2]) + } + else if (room == loc[DROID1] || room == loc[DROID2]) { (void) puts("Droids nearby!"); - else if (room == loc[LUSER1] || room == loc[LUSER2]) + } + else if (room == loc[LUSER1] || room == loc[LUSER2]) { (void) puts("Lusers nearby!"); + } } } @@ -238,12 +245,13 @@ void throw() 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; } + } scratchloc = loc[YOU]; @@ -257,8 +265,9 @@ void throw() { scratchloc = path[k]; check_shot(); - if (finished != NOT) + if (finished != NOT) { return; + } } } @@ -277,8 +286,9 @@ void throw() move_superhack(); - if (--pies <= 0) + if (--pies <= 0) { finished = LOSE; + } } } @@ -302,11 +312,13 @@ void move_superhack() { k = FNC(); - if (k < 3) + if (k < 3) { loc[RMS] = cave[loc[RMS]][k]; + } - if (loc[RMS] != loc[YOU]) + if (loc[RMS] != loc[YOU]) { return; + } (void) puts("The superhack flames you to a crisp. You lose!"); @@ -324,9 +336,11 @@ void move() 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; @@ -359,23 +373,30 @@ goodmove: 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 (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"); @@ -391,12 +412,15 @@ int main(int argc, char *argv[]) c = getlet("Throw, move or help [t,m,?]"); - if (c == 't') + if (c == 't') { throw(); - else if (c == 'm') + } + else if (c == 'm') { move(); - else if (c == '?') + } + else if (c == '?') { print_instructions(); + } #ifdef DEBUG else if (c == 'd') { -- 2.31.1