From 0f418c937cdc84818e0f0b3d6e82d91b25f149a1 Mon Sep 17 00:00:00 2001 From: David Griffith Date: Sat, 21 Sep 2019 16:02:57 -0700 Subject: [PATCH] Convert hotkey.c to K&R style. --- src/common/hotkey.c | 240 +++++++++++++++++++------------------------- 1 file changed, 103 insertions(+), 137 deletions(-) diff --git a/src/common/hotkey.c b/src/common/hotkey.c index ac8f568..7d2691b 100644 --- a/src/common/hotkey.c +++ b/src/common/hotkey.c @@ -39,20 +39,15 @@ extern void seed_random (int); * ...allows user to toggle cheating options on/off. * */ -static bool hot_key_debugging (void) +static bool hot_key_debugging(void) { - - print_string ("Debugging options\n"); - - f_setup.attribute_assignment = read_yes_or_no ("Watch attribute assignment"); - f_setup.attribute_testing = read_yes_or_no ("Watch attribute testing"); - - f_setup.object_movement = read_yes_or_no ("Watch object movement"); - f_setup.object_locating = read_yes_or_no ("Watch object locating"); - - return FALSE; - -}/* hot_key_debugging */ + print_string ("Debugging options\n"); + f_setup.attribute_assignment = read_yes_or_no("Watch attribute assignment"); + f_setup.attribute_testing = read_yes_or_no("Watch attribute testing"); + f_setup.object_movement = read_yes_or_no("Watch object movement"); + f_setup.object_locating = read_yes_or_no("Watch object locating"); + return FALSE; +} /* hot_key_debugging */ /* @@ -61,24 +56,21 @@ static bool hot_key_debugging (void) * ...displays a list of all hot keys. * */ -static bool hot_key_help (void) { - - print_string ("Help\n"); - - print_string ( - "\n" - "Alt-D debugging options\n" - "Alt-H help\n" - "Alt-N new game\n" - "Alt-P playback on\n" - "Alt-R recording on/off\n" - "Alt-S seed random numbers\n" - "Alt-U undo one turn\n" - "Alt-X exit game\n"); - - return FALSE; - -}/* hot_key_help */ +static bool hot_key_help(void) +{ + print_string ("Help\n"); + print_string ( + "\n" + "Alt-D debugging options\n" + "Alt-H help\n" + "Alt-N new game\n" + "Alt-P playback on\n" + "Alt-R recording on/off\n" + "Alt-S seed random numbers\n" + "Alt-U undo one turn\n" + "Alt-X exit game\n"); + return FALSE; +} /* hot_key_help */ /* @@ -87,16 +79,13 @@ static bool hot_key_help (void) { * ...allows user to turn playback on. * */ -static bool hot_key_playback (void) +static bool hot_key_playback(void) { - print_string ("Playback on\n"); - - if (!istream_replay) - replay_open (); - - return FALSE; - -}/* hot_key_playback */ + print_string ("Playback on\n"); + if (!istream_replay) + replay_open (); + return FALSE; +} /* hot_key_playback */ /* @@ -105,23 +94,20 @@ static bool hot_key_playback (void) * ...allows user to turn recording on/off. * */ -static bool hot_key_recording (void) +static bool hot_key_recording(void) { - - if (istream_replay) { - print_string ("Playback off\n"); - replay_close (); - } else if (ostream_record) { - print_string ("Recording off\n"); - record_close (); - } else { - print_string ("Recording on\n"); - record_open (); - } - - return FALSE; - -}/* hot_key_recording */ + if (istream_replay) { + print_string("Playback off\n"); + replay_close(); + } else if (ostream_record) { + print_string("Recording off\n"); + record_close(); + } else { + print_string("Recording on\n"); + record_open(); + } + return FALSE; +} /* hot_key_recording */ /* @@ -130,17 +116,13 @@ static bool hot_key_recording (void) * ...allows user to seed the random number seed. * */ -static bool hot_key_seed (void) +static bool hot_key_seed(void) { - - print_string ("Seed random numbers\n"); - - print_string ("Enter seed value (or return to randomize): "); - seed_random (read_number ()); - - return FALSE; - -}/* hot_key_seed */ + print_string("Seed random numbers\n"); + print_string("Enter seed value (or return to randomize): "); + seed_random(read_number ()); + return FALSE; +} /* hot_key_seed */ /* @@ -149,28 +131,24 @@ static bool hot_key_seed (void) * ...allows user to undo the previous turn. * */ -static bool hot_key_undo (void) +static bool hot_key_undo(void) { + print_string("Undo one turn\n"); + if (restore_undo()) { + if (h_version >= V5) { /* for V5+ games we must */ + store(2); /* store 2 (for success) */ + return TRUE; /* and abort the input */ + } - print_string ("Undo one turn\n"); - - if (restore_undo ()) { - - if (h_version >= V5) { /* for V5+ games we must */ - store (2); /* store 2 (for success) */ - return TRUE; /* and abort the input */ - } - - if (h_version <= V3) { /* for V3- games we must */ - z_show_status (); /* draw the status line */ - return FALSE; /* and continue input */ - } + if (h_version <= V3) { /* for V3- games we must */ + z_show_status(); /* draw the status line */ + return FALSE; /* and continue input */ + } + } else + print_string("No more undo information available.\n"); - } else print_string ("No more undo information available.\n"); - - return FALSE; - -}/* hot_key_undo */ + return FALSE; +} /* hot_key_undo */ /* @@ -179,18 +157,15 @@ static bool hot_key_undo (void) * ...allows user to start a new game. * */ -static bool hot_key_restart (void) +static bool hot_key_restart(void) { - print_string ("New game\n"); - - if (read_yes_or_no ("Do you wish to restart")) { - - z_restart (); - return TRUE; - - } else return FALSE; - -}/* hot_key_restart */ + print_string("New game\n"); + if (read_yes_or_no("Do you wish to restart")) { + z_restart(); + return TRUE; + } else + return FALSE; +} /* hot_key_restart */ /* @@ -199,19 +174,15 @@ static bool hot_key_restart (void) * ...allows user to exit the game. * */ -static bool hot_key_quit (void) +static bool hot_key_quit(void) { - - print_string ("Exit game\n"); - - if (read_yes_or_no ("Do you wish to quit")) { - - z_quit (); - return TRUE; - - } else return FALSE; - -}/* hot_key_quit */ + print_string("Exit game\n"); + if (read_yes_or_no("Do you wish to quit")) { + z_quit(); + return TRUE; + } else + return FALSE; +} /* hot_key_quit */ /* @@ -221,34 +192,29 @@ static bool hot_key_quit (void) * true to abort the current input action. * */ -bool handle_hot_key (zchar key) +bool handle_hot_key(zchar key) { - if (cwin == 0) { - - bool aborting; - - aborting = FALSE; - - print_string ("\nHot key -- "); - - switch (key) { - case ZC_HKEY_RECORD: aborting = hot_key_recording (); break; - case ZC_HKEY_PLAYBACK: aborting = hot_key_playback (); break; - case ZC_HKEY_SEED: aborting = hot_key_seed (); break; - case ZC_HKEY_UNDO: aborting = hot_key_undo (); break; - case ZC_HKEY_RESTART: aborting = hot_key_restart (); break; - case ZC_HKEY_QUIT: aborting = hot_key_quit (); break; - case ZC_HKEY_DEBUG: aborting = hot_key_debugging (); break; - case ZC_HKEY_HELP: aborting = hot_key_help (); break; + if (cwin == 0) { + bool aborting; + aborting = FALSE; + + print_string ("\nHot key -- "); + + switch (key) { + case ZC_HKEY_RECORD: aborting = hot_key_recording(); break; + case ZC_HKEY_PLAYBACK: aborting = hot_key_playback(); break; + case ZC_HKEY_SEED: aborting = hot_key_seed(); break; + case ZC_HKEY_UNDO: aborting = hot_key_undo(); break; + case ZC_HKEY_RESTART: aborting = hot_key_restart(); break; + case ZC_HKEY_QUIT: aborting = hot_key_quit(); break; + case ZC_HKEY_DEBUG: aborting = hot_key_debugging(); break; + case ZC_HKEY_HELP: aborting = hot_key_help(); break; + } + + if (aborting) + return TRUE; + + print_string ("\nContinue input...\n"); } - - if (aborting) - return TRUE; - - print_string ("\nContinue input...\n"); - - } - - return FALSE; - -}/* handle_hot_key */ + return FALSE; +} /* handle_hot_key */ -- 2.34.1