refactor(misc1): move line_breakcheck family of functions to os/input.c

This commit is contained in:
Björn Linse
2021-12-09 21:00:04 +01:00
parent 2fe60905f6
commit 2ec0e0a868
12 changed files with 44 additions and 41 deletions

View File

@@ -17,6 +17,7 @@
#include "nvim/getchar.h" #include "nvim/getchar.h"
#include "nvim/misc1.h" #include "nvim/misc1.h"
#include "nvim/option.h" #include "nvim/option.h"
#include "nvim/os/input.h"
#include "nvim/regexp.h" #include "nvim/regexp.h"
#include "nvim/search.h" #include "nvim/search.h"
#include "nvim/state.h" #include "nvim/state.h"

View File

@@ -28,6 +28,7 @@
#include "nvim/mbyte.h" #include "nvim/mbyte.h"
#include "nvim/memory.h" #include "nvim/memory.h"
#include "nvim/message.h" #include "nvim/message.h"
#include "nvim/os/input.h"
#include "nvim/pos.h" #include "nvim/pos.h"
#include "nvim/types.h" #include "nvim/types.h"
#include "nvim/vim.h" #include "nvim/vim.h"

View File

@@ -41,6 +41,7 @@
#include "nvim/ops.h" #include "nvim/ops.h"
#include "nvim/option.h" #include "nvim/option.h"
#include "nvim/os/fs_defs.h" #include "nvim/os/fs_defs.h"
#include "nvim/os/input.h"
#include "nvim/os/shell.h" #include "nvim/os/shell.h"
#include "nvim/os_unix.h" #include "nvim/os_unix.h"
#include "nvim/path.h" #include "nvim/path.h"

View File

@@ -32,6 +32,7 @@
#include "nvim/move.h" #include "nvim/move.h"
#include "nvim/ops.h" #include "nvim/ops.h"
#include "nvim/option.h" #include "nvim/option.h"
#include "nvim/os/input.h"
#include "nvim/plines.h" #include "nvim/plines.h"
#include "nvim/screen.h" #include "nvim/screen.h"
#include "nvim/strings.h" #include "nvim/strings.h"

View File

@@ -858,47 +858,6 @@ void preserve_exit(void)
getout(1); getout(1);
} }
/*
* Check for CTRL-C pressed, but only once in a while.
* Should be used instead of os_breakcheck() for functions that check for
* each line in the file. Calling os_breakcheck() each time takes too much
* time, because it can be a system call.
*/
#ifndef BREAKCHECK_SKIP
# define BREAKCHECK_SKIP 1000
#endif
static int breakcheck_count = 0;
void line_breakcheck(void)
{
if (++breakcheck_count >= BREAKCHECK_SKIP) {
breakcheck_count = 0;
os_breakcheck();
}
}
/*
* Like line_breakcheck() but check 10 times less often.
*/
void fast_breakcheck(void)
{
if (++breakcheck_count >= BREAKCHECK_SKIP * 10) {
breakcheck_count = 0;
os_breakcheck();
}
}
// Like line_breakcheck() but check 100 times less often.
void veryfast_breakcheck(void)
{
if (++breakcheck_count >= BREAKCHECK_SKIP * 100) {
breakcheck_count = 0;
os_breakcheck();
}
}
/// os_call_shell() wrapper. Handles 'verbose', :profile, and v:shell_error. /// os_call_shell() wrapper. Handles 'verbose', :profile, and v:shell_error.
/// Invalidates cached tags. /// Invalidates cached tags.
/// ///

View File

@@ -183,6 +183,40 @@ void os_breakcheck(void)
updating_screen = save_us; updating_screen = save_us;
} }
#define BREAKCHECK_SKIP 1000
static int breakcheck_count = 0;
/// Check for CTRL-C pressed, but only once in a while.
///
/// Should be used instead of os_breakcheck() for functions that check for
/// each line in the file. Calling os_breakcheck() each time takes too much
/// time, because it will use system calls to check for input.
void line_breakcheck(void)
{
if (++breakcheck_count >= BREAKCHECK_SKIP) {
breakcheck_count = 0;
os_breakcheck();
}
}
/// Like line_breakcheck() but check 10 times less often.
void fast_breakcheck(void)
{
if (++breakcheck_count >= BREAKCHECK_SKIP * 10) {
breakcheck_count = 0;
os_breakcheck();
}
}
/// Like line_breakcheck() but check 100 times less often.
void veryfast_breakcheck(void)
{
if (++breakcheck_count >= BREAKCHECK_SKIP * 100) {
breakcheck_count = 0;
os_breakcheck();
}
}
/// Test whether a file descriptor refers to a terminal. /// Test whether a file descriptor refers to a terminal.
/// ///

View File

@@ -65,6 +65,7 @@
#include "nvim/memory.h" #include "nvim/memory.h"
#include "nvim/message.h" #include "nvim/message.h"
#include "nvim/misc1.h" #include "nvim/misc1.h"
#include "nvim/os/input.h"
#include "nvim/plines.h" #include "nvim/plines.h"
#include "nvim/garray.h" #include "nvim/garray.h"
#include "nvim/strings.h" #include "nvim/strings.h"

View File

@@ -16,6 +16,7 @@
#include "nvim/ascii.h" #include "nvim/ascii.h"
#include "nvim/garray.h" #include "nvim/garray.h"
#include "nvim/os/input.h"
/* /*
* Logging of NFA engine. * Logging of NFA engine.

View File

@@ -36,6 +36,7 @@
#include "nvim/move.h" #include "nvim/move.h"
#include "nvim/normal.h" #include "nvim/normal.h"
#include "nvim/option.h" #include "nvim/option.h"
#include "nvim/os/input.h"
#include "nvim/os/time.h" #include "nvim/os/time.h"
#include "nvim/path.h" #include "nvim/path.h"
#include "nvim/regexp.h" #include "nvim/regexp.h"

View File

@@ -239,6 +239,7 @@
#include "nvim/memory.h" #include "nvim/memory.h"
#include "nvim/misc1.h" #include "nvim/misc1.h"
#include "nvim/option.h" #include "nvim/option.h"
#include "nvim/os/input.h"
#include "nvim/os/os.h" #include "nvim/os/os.h"
#include "nvim/path.h" #include "nvim/path.h"
#include "nvim/regexp.h" #include "nvim/regexp.h"

View File

@@ -34,6 +34,7 @@
#include "nvim/message.h" #include "nvim/message.h"
#include "nvim/misc1.h" #include "nvim/misc1.h"
#include "nvim/option.h" #include "nvim/option.h"
#include "nvim/os/input.h"
#include "nvim/os/os.h" #include "nvim/os/os.h"
#include "nvim/os/time.h" #include "nvim/os/time.h"
#include "nvim/os_unix.h" #include "nvim/os_unix.h"

View File

@@ -100,6 +100,7 @@
#include "nvim/message.h" #include "nvim/message.h"
#include "nvim/misc1.h" #include "nvim/misc1.h"
#include "nvim/option.h" #include "nvim/option.h"
#include "nvim/os/input.h"
#include "nvim/os/os.h" #include "nvim/os/os.h"
#include "nvim/os/time.h" #include "nvim/os/time.h"
#include "nvim/os_unix.h" #include "nvim/os_unix.h"