mirror of
https://github.com/neovim/neovim.git
synced 2025-09-29 14:38:32 +00:00
ex_cmds2.c: cleanup
This commit is contained in:
@@ -50,13 +50,6 @@
|
|||||||
#include "nvim/api/private/defs.h"
|
#include "nvim/api/private/defs.h"
|
||||||
|
|
||||||
|
|
||||||
#ifdef WIN32
|
|
||||||
#define os_strtok_r strtok_s
|
|
||||||
#else
|
|
||||||
#define os_strtok_r strtok_r
|
|
||||||
#endif
|
|
||||||
|
|
||||||
|
|
||||||
/// Growarray to store info about already sourced scripts.
|
/// Growarray to store info about already sourced scripts.
|
||||||
/// Also store the dev/ino, so that we don't have to stat() each
|
/// Also store the dev/ino, so that we don't have to stat() each
|
||||||
/// script when going through the list.
|
/// script when going through the list.
|
||||||
@@ -121,10 +114,8 @@ struct source_cookie {
|
|||||||
/// batch mode debugging: don't save and restore typeahead.
|
/// batch mode debugging: don't save and restore typeahead.
|
||||||
static bool debug_greedy = false;
|
static bool debug_greedy = false;
|
||||||
|
|
||||||
/// Repeatedly get Ex commands, until told to continue normal execution.
|
/// Debug mode. Repeatedly get Ex commands, until told to continue normal
|
||||||
/// Handles debug mode.
|
/// execution.
|
||||||
///
|
|
||||||
/// @param cmd
|
|
||||||
void do_debug(char_u *cmd)
|
void do_debug(char_u *cmd)
|
||||||
{
|
{
|
||||||
int save_msg_scroll = msg_scroll;
|
int save_msg_scroll = msg_scroll;
|
||||||
@@ -425,8 +416,6 @@ static void do_showbacktrace(char_u *cmd)
|
|||||||
|
|
||||||
|
|
||||||
/// ":debug".
|
/// ":debug".
|
||||||
///
|
|
||||||
/// @param eap
|
|
||||||
void ex_debug(exarg_T *eap)
|
void ex_debug(exarg_T *eap)
|
||||||
{
|
{
|
||||||
int debug_break_level_save = debug_break_level;
|
int debug_break_level_save = debug_break_level;
|
||||||
@@ -452,8 +441,6 @@ static char_u *debug_skipped_name;
|
|||||||
/// executed. Return true and set breakpoint_name for skipped commands that
|
/// executed. Return true and set breakpoint_name for skipped commands that
|
||||||
/// decide to execute something themselves.
|
/// decide to execute something themselves.
|
||||||
/// Called from do_one_cmd() before executing a command.
|
/// Called from do_one_cmd() before executing a command.
|
||||||
///
|
|
||||||
/// @param eap
|
|
||||||
void dbg_check_breakpoint(exarg_T *eap)
|
void dbg_check_breakpoint(exarg_T *eap)
|
||||||
{
|
{
|
||||||
char_u *p;
|
char_u *p;
|
||||||
@@ -493,12 +480,10 @@ void dbg_check_breakpoint(exarg_T *eap)
|
|||||||
/// Go to debug mode if skipped by dbg_check_breakpoint() because eap->skip was
|
/// Go to debug mode if skipped by dbg_check_breakpoint() because eap->skip was
|
||||||
/// set.
|
/// set.
|
||||||
///
|
///
|
||||||
/// @param eap
|
|
||||||
///
|
|
||||||
/// @return true when the debug mode is entered this time.
|
/// @return true when the debug mode is entered this time.
|
||||||
bool dbg_check_skipped(exarg_T *eap)
|
bool dbg_check_skipped(exarg_T *eap)
|
||||||
{
|
{
|
||||||
bool prev_got_int;
|
int prev_got_int;
|
||||||
|
|
||||||
if (debug_skipped) {
|
if (debug_skipped) {
|
||||||
// Save the value of got_int and reset it. We don't want a previous
|
// Save the value of got_int and reset it. We don't want a previous
|
||||||
@@ -545,8 +530,6 @@ static garray_T prof_ga = { 0, 0, sizeof(struct debuggy), 4, NULL };
|
|||||||
///
|
///
|
||||||
/// @param arg
|
/// @param arg
|
||||||
/// @param gap either &dbg_breakp or &prof_ga
|
/// @param gap either &dbg_breakp or &prof_ga
|
||||||
///
|
|
||||||
/// @return
|
|
||||||
static int dbg_parsearg(char_u *arg, garray_T *gap)
|
static int dbg_parsearg(char_u *arg, garray_T *gap)
|
||||||
{
|
{
|
||||||
char_u *p = arg;
|
char_u *p = arg;
|
||||||
@@ -771,17 +754,17 @@ void ex_breaklist(exarg_T *eap)
|
|||||||
/// Returns line number at which to break; zero when no matching breakpoint.
|
/// Returns line number at which to break; zero when no matching breakpoint.
|
||||||
linenr_T
|
linenr_T
|
||||||
dbg_find_breakpoint(
|
dbg_find_breakpoint(
|
||||||
bool file, // true for a file, false for a function
|
bool file, // true for a file, false for a function
|
||||||
char_u *fname, // file or function name
|
char_u *fname, // file or function name
|
||||||
linenr_T after // after this line number
|
linenr_T after // after this line number
|
||||||
)
|
)
|
||||||
{
|
{
|
||||||
return debuggy_find(file, fname, after, &dbg_breakp, NULL);
|
return debuggy_find(file, fname, after, &dbg_breakp, NULL);
|
||||||
}
|
}
|
||||||
|
|
||||||
/// @param file: true for a file, false for a function
|
/// @param file true for a file, false for a function
|
||||||
/// @param fname: file or function name
|
/// @param fname file or function name
|
||||||
/// @param[out] fp: forceit
|
/// @param fp[out] forceit
|
||||||
///
|
///
|
||||||
/// @returns true if profiling is on for a function or sourced file.
|
/// @returns true if profiling is on for a function or sourced file.
|
||||||
bool has_profiling(bool file, char_u *fname, bool *fp)
|
bool has_profiling(bool file, char_u *fname, bool *fp)
|
||||||
@@ -793,11 +776,11 @@ bool has_profiling(bool file, char_u *fname, bool *fp)
|
|||||||
/// Common code for dbg_find_breakpoint() and has_profiling().
|
/// Common code for dbg_find_breakpoint() and has_profiling().
|
||||||
static linenr_T
|
static linenr_T
|
||||||
debuggy_find(
|
debuggy_find(
|
||||||
bool file, // true for a file, false for a function
|
bool file, // true for a file, false for a function
|
||||||
char_u *fname, // file or function name
|
char_u *fname, // file or function name
|
||||||
linenr_T after, // after this line number
|
linenr_T after, // after this line number
|
||||||
garray_T *gap, // either &dbg_breakp or &prof_ga
|
garray_T *gap, // either &dbg_breakp or &prof_ga
|
||||||
bool *fp // if not NULL: return forceit
|
bool *fp // if not NULL: return forceit
|
||||||
)
|
)
|
||||||
{
|
{
|
||||||
struct debuggy *bp;
|
struct debuggy *bp;
|
||||||
@@ -980,7 +963,7 @@ void set_context_in_profile_cmd(expand_T *xp, char_u *arg)
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
// TODO(tarruda): expand function names after "func
|
// TODO(tarruda): expand function names after "func"
|
||||||
xp->xp_context = EXPAND_NOTHING;
|
xp->xp_context = EXPAND_NOTHING;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -1179,7 +1162,8 @@ bool prof_def_func(void)
|
|||||||
|
|
||||||
/// If 'autowrite' option set, try to write the file.
|
/// If 'autowrite' option set, try to write the file.
|
||||||
/// Careful: autocommands may make "buf" invalid!
|
/// Careful: autocommands may make "buf" invalid!
|
||||||
/// return FAIL for failure, OK otherwise
|
///
|
||||||
|
/// @return FAIL for failure, OK otherwise
|
||||||
int autowrite(buf_T *buf, int forceit)
|
int autowrite(buf_T *buf, int forceit)
|
||||||
{
|
{
|
||||||
int r;
|
int r;
|
||||||
@@ -1450,7 +1434,7 @@ bool check_changed_any(bool hidden, bool unload)
|
|||||||
FOR_ALL_TAB_WINDOWS(tp, wp) {
|
FOR_ALL_TAB_WINDOWS(tp, wp) {
|
||||||
if (wp->w_buffer == buf) {
|
if (wp->w_buffer == buf) {
|
||||||
goto_tabpage_win(tp, wp);
|
goto_tabpage_win(tp, wp);
|
||||||
// Paranoia: did autocms wipe out the buffer with changes?
|
// Paranoia: did autocmds wipe out the buffer with changes?
|
||||||
if (!buf_valid(buf)) {
|
if (!buf_valid(buf)) {
|
||||||
goto theend;
|
goto theend;
|
||||||
}
|
}
|
||||||
@@ -1470,8 +1454,8 @@ theend:
|
|||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
/// return FAIL if there is no file name, OK if there is one
|
/// Return FAIL if there is no file name, OK if there is one.
|
||||||
/// give error message for FAIL
|
/// Give error message for FAIL.
|
||||||
int check_fname(void)
|
int check_fname(void)
|
||||||
{
|
{
|
||||||
if (curbuf->b_ffname == NULL) {
|
if (curbuf->b_ffname == NULL) {
|
||||||
@@ -1481,8 +1465,9 @@ int check_fname(void)
|
|||||||
return OK;
|
return OK;
|
||||||
}
|
}
|
||||||
|
|
||||||
/// flush the contents of a buffer, unless it has no file name
|
/// Flush the contents of a buffer, unless it has no file name.
|
||||||
/// return FAIL for failure, OK otherwise
|
///
|
||||||
|
/// @return FAIL for failure, OK otherwise
|
||||||
int buf_write_all(buf_T *buf, int forceit)
|
int buf_write_all(buf_T *buf, int forceit)
|
||||||
{
|
{
|
||||||
int retval;
|
int retval;
|
||||||
@@ -1551,7 +1536,8 @@ void get_arglist(garray_T *gap, char_u *str)
|
|||||||
|
|
||||||
/// Parse a list of arguments (file names), expand them and return in
|
/// Parse a list of arguments (file names), expand them and return in
|
||||||
/// "fnames[fcountp]". When "wig" is true, removes files matching 'wildignore'.
|
/// "fnames[fcountp]". When "wig" is true, removes files matching 'wildignore'.
|
||||||
/// Return FAIL or OK.
|
///
|
||||||
|
/// @return FAIL or OK.
|
||||||
int get_arglist_exp(char_u *str, int *fcountp, char_u ***fnamesp, bool wig)
|
int get_arglist_exp(char_u *str, int *fcountp, char_u ***fnamesp, bool wig)
|
||||||
{
|
{
|
||||||
garray_T ga;
|
garray_T ga;
|
||||||
@@ -1897,7 +1883,6 @@ void ex_argedit(exarg_T *eap)
|
|||||||
int fnum;
|
int fnum;
|
||||||
int i;
|
int i;
|
||||||
char_u *s;
|
char_u *s;
|
||||||
int after;
|
|
||||||
|
|
||||||
// Add the argument to the buffer list and get the buffer number.
|
// Add the argument to the buffer list and get the buffer number.
|
||||||
fnum = buflist_add(eap->arg, BLN_LISTED);
|
fnum = buflist_add(eap->arg, BLN_LISTED);
|
||||||
@@ -1911,7 +1896,7 @@ void ex_argedit(exarg_T *eap)
|
|||||||
if (i == ARGCOUNT) {
|
if (i == ARGCOUNT) {
|
||||||
// Can't find it, add it to the argument list.
|
// Can't find it, add it to the argument list.
|
||||||
s = vim_strsave(eap->arg);
|
s = vim_strsave(eap->arg);
|
||||||
after = eap->addr_count > 0 ? (int)eap->line2 : curwin->w_arg_idx + 1;
|
int after = eap->addr_count > 0 ? (int)eap->line2 : curwin->w_arg_idx + 1;
|
||||||
i = alist_add_list(1, &s, after);
|
i = alist_add_list(1, &s, after);
|
||||||
curwin->w_arg_idx = i;
|
curwin->w_arg_idx = i;
|
||||||
}
|
}
|
||||||
@@ -2225,14 +2210,12 @@ void ex_compiler(exarg_T *eap)
|
|||||||
char_u *buf;
|
char_u *buf;
|
||||||
char_u *old_cur_comp = NULL;
|
char_u *old_cur_comp = NULL;
|
||||||
char_u *p;
|
char_u *p;
|
||||||
size_t bufsize;
|
|
||||||
|
|
||||||
if (*eap->arg == NUL) {
|
if (*eap->arg == NUL) {
|
||||||
// List all compiler scripts.
|
// List all compiler scripts.
|
||||||
do_cmdline_cmd("echo globpath(&rtp, 'compiler//.vim')");
|
do_cmdline_cmd("echo globpath(&rtp, 'compiler/*.vim')"); // NOLINT
|
||||||
// ) keep the indenter happy...
|
|
||||||
} else {
|
} else {
|
||||||
bufsize = STRLEN(eap->arg) + 14;
|
size_t bufsize = STRLEN(eap->arg) + 14;
|
||||||
buf = xmalloc(bufsize);
|
buf = xmalloc(bufsize);
|
||||||
if (eap->forceit) {
|
if (eap->forceit) {
|
||||||
// ":compiler! {name}" sets global options
|
// ":compiler! {name}" sets global options
|
||||||
@@ -2416,17 +2399,16 @@ static void cmd_source(char_u *fname, exarg_T *eap)
|
|||||||
// - inside a loop
|
// - inside a loop
|
||||||
openscript(fname, global_busy || listcmd_busy || eap->nextcmd != NULL
|
openscript(fname, global_busy || listcmd_busy || eap->nextcmd != NULL
|
||||||
|| eap->cstack->cs_idx >= 0);
|
|| eap->cstack->cs_idx >= 0);
|
||||||
} else if (do_source(fname, false, DOSO_NONE) == FAIL) {
|
|
||||||
// ":source" read ex commands
|
// ":source" read ex commands
|
||||||
|
} else if (do_source(fname, false, DOSO_NONE) == FAIL) {
|
||||||
EMSG2(_(e_notopen), fname);
|
EMSG2(_(e_notopen), fname);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/// ":source" and associated commands.
|
/// ":source" and associated commands.
|
||||||
///
|
///
|
||||||
/// @param cookie
|
/// @return address holding the next breakpoint line for a source cookie
|
||||||
///
|
|
||||||
/// @return the address holding the next breakpoint line for a source cookie.
|
|
||||||
linenr_T *source_breakpoint(void *cookie)
|
linenr_T *source_breakpoint(void *cookie)
|
||||||
{
|
{
|
||||||
return &((struct source_cookie *)cookie)->breakpoint;
|
return &((struct source_cookie *)cookie)->breakpoint;
|
||||||
@@ -2797,8 +2779,9 @@ void free_scriptnames(void)
|
|||||||
|
|
||||||
/// Get one full line from a sourced file.
|
/// Get one full line from a sourced file.
|
||||||
/// Called by do_cmdline() when it's called from do_source().
|
/// Called by do_cmdline() when it's called from do_source().
|
||||||
/// Return a pointer to the line in allocated memory.
|
///
|
||||||
/// Return NULL for end-of-file or some error.
|
/// @return pointer to the line in allocated memory, or NULL for end-of-file or
|
||||||
|
/// some error.
|
||||||
char_u *getsourceline(int c, void *cookie, int indent)
|
char_u *getsourceline(int c, void *cookie, int indent)
|
||||||
{
|
{
|
||||||
struct source_cookie *sp = (struct source_cookie *)cookie;
|
struct source_cookie *sp = (struct source_cookie *)cookie;
|
||||||
@@ -3388,12 +3371,12 @@ static char_u **find_locales(void)
|
|||||||
|
|
||||||
// Transform locale_a string where each locale is separated by "\n"
|
// Transform locale_a string where each locale is separated by "\n"
|
||||||
// into an array of locale strings.
|
// into an array of locale strings.
|
||||||
loc = (char_u *)os_strtok_r((char *)locale_a, "\n", &saveptr);
|
loc = (char_u *)os_strtok((char *)locale_a, "\n", &saveptr);
|
||||||
|
|
||||||
while (loc != NULL) {
|
while (loc != NULL) {
|
||||||
loc = vim_strsave(loc);
|
loc = vim_strsave(loc);
|
||||||
GA_APPEND(char_u *, &locales_ga, loc);
|
GA_APPEND(char_u *, &locales_ga, loc);
|
||||||
loc = (char_u *)os_strtok_r(NULL, "\n", &saveptr);
|
loc = (char_u *)os_strtok(NULL, "\n", &saveptr);
|
||||||
}
|
}
|
||||||
xfree(locale_a);
|
xfree(locale_a);
|
||||||
// Guarantee that .ga_data is NULL terminated
|
// Guarantee that .ga_data is NULL terminated
|
||||||
|
@@ -46,4 +46,10 @@
|
|||||||
/// negative libuv error codes are returned by a number of os functions.
|
/// negative libuv error codes are returned by a number of os functions.
|
||||||
#define os_strerror uv_strerror
|
#define os_strerror uv_strerror
|
||||||
|
|
||||||
|
#ifdef WIN32
|
||||||
|
# define os_strtok strtok_s
|
||||||
|
#else
|
||||||
|
# define os_strtok strtok_r
|
||||||
|
#endif
|
||||||
|
|
||||||
#endif // NVIM_OS_OS_DEFS_H
|
#endif // NVIM_OS_OS_DEFS_H
|
||||||
|
Reference in New Issue
Block a user