From 785efc208784aaa0235203136aa8b445ae44c896 Mon Sep 17 00:00:00 2001 From: Benno Schulenberg Date: Wed, 9 Oct 2019 18:58:30 +0200 Subject: [PATCH] tweaks: make a function do a check so its calls don't need to --- src/files.c | 4 +--- src/nano.c | 16 +++++++++------- src/proto.h | 2 +- src/text.c | 8 ++------ 4 files changed, 13 insertions(+), 17 deletions(-) diff --git a/src/files.c b/src/files.c index df8193a7..567299a7 100644 --- a/src/files.c +++ b/src/files.c @@ -1212,9 +1212,7 @@ void do_insertfile(void) /* If the current mode of operation allows it, go insert a file. */ void do_insertfile_void(void) { - if (ISSET(RESTRICTED)) - show_restricted_warning(); - else + if (!in_restricted_mode()) do_insertfile(); } diff --git a/src/nano.c b/src/nano.c index 56177d20..4228a8ca 100644 --- a/src/nano.c +++ b/src/nano.c @@ -463,11 +463,15 @@ void print_view_warning(void) statusbar(_("Key is invalid in view mode")); } -/* Indicate that something is disabled in restricted mode. */ -void show_restricted_warning(void) +/* When in restricted mode, show a warning and return TRUE. */ +bool in_restricted_mode(void) { - statusbar(_("This function is disabled in restricted mode")); - beep(); + if (ISSET(RESTRICTED)) { + statusbar(_("This function is disabled in restricted mode")); + beep(); + return TRUE; + } else + return FALSE; } #ifndef ENABLE_HELP @@ -1340,10 +1344,8 @@ void do_toggle(int flag) { bool enabled; - if (flag == SUSPEND && ISSET(RESTRICTED)) { - show_restricted_warning(); + if (flag == SUSPEND && in_restricted_mode()) return; - } TOGGLE(flag); focusing = FALSE; diff --git a/src/proto.h b/src/proto.h index 02f729b2..e2676a9d 100644 --- a/src/proto.h +++ b/src/proto.h @@ -408,7 +408,7 @@ void extract(linestruct *top, size_t top_x, linestruct *bot, size_t bot_x); void ingraft_buffer(linestruct *somebuffer); void copy_from_buffer(linestruct *somebuffer); void print_view_warning(void); -void show_restricted_warning(void); +bool in_restricted_mode(void); #ifndef ENABLE_HELP void say_there_is_no_help(void); #endif diff --git a/src/text.c b/src/text.c index 939e7677..c23b29fd 100644 --- a/src/text.c +++ b/src/text.c @@ -2640,10 +2640,8 @@ void do_spell(void) /* A storage place for the current flag settings. */ const char *result_msg; - if (ISSET(RESTRICTED)) { - show_restricted_warning(); + if (in_restricted_mode()) return; - } temp = safe_tempfile(&temp_file); @@ -2712,10 +2710,8 @@ void do_linter(void) lintstruct *lints = NULL, *tmplint = NULL, *curlint = NULL; time_t last_wait = 0; - if (ISSET(RESTRICTED)) { - show_restricted_warning(); + if (in_restricted_mode()) return; - } if (!openfile->syntax || !openfile->syntax->linter) { statusbar(_("No linter defined for this type of file!"));