aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJustin M. Keyes <justinkz@gmail.com>2016-06-25 18:24:09 -0400
committerGitHub <noreply@github.com>2016-06-25 18:24:09 -0400
commitc69ccca56d5e5e916a2aef6eedbcea2b5962a505 (patch)
tree1c5912d1d0d4b921091fd209f818b2ef20eabcfe
parent26d8ab51daf8ff524d7f6edb843fe1c61f943425 (diff)
parent2b7d13fb19471b9031fa5b64eb03f5053d8e1a02 (diff)
downloadrneovim-c69ccca56d5e5e916a2aef6eedbcea2b5962a505.tar.gz
rneovim-c69ccca56d5e5e916a2aef6eedbcea2b5962a505.tar.bz2
rneovim-c69ccca56d5e5e916a2aef6eedbcea2b5962a505.zip
Merge #4965 from justinmk/fixup4453
ex_cmds2.c: lint
-rw-r--r--src/nvim/ex_cmds2.c2223
-rw-r--r--src/nvim/os/os_defs.h6
2 files changed, 1071 insertions, 1158 deletions
diff --git a/src/nvim/ex_cmds2.c b/src/nvim/ex_cmds2.c
index 247f86679f..e7f51326c4 100644
--- a/src/nvim/ex_cmds2.c
+++ b/src/nvim/ex_cmds2.c
@@ -1,6 +1,6 @@
-/*
- * ex_cmds2.c: some more functions for command line commands
- */
+/// @file ex_cmds2.c
+///
+/// Some more functions for command line commands
#include <assert.h>
#include <inttypes.h>
@@ -50,15 +50,15 @@
#include "nvim/api/private/defs.h"
-/* Growarray to store info about already sourced scripts.
- * Also store the dev/ino, so that we don't have to stat() each
- * script when going through the list. */
+/// Growarray to store info about already sourced scripts.
+/// Also store the dev/ino, so that we don't have to stat() each
+/// script when going through the list.
typedef struct scriptitem_S {
char_u *sn_name;
bool file_id_valid;
FileID file_id;
bool sn_prof_on; ///< true when script is/was profiled
- int sn_pr_force; ///< forceit: profile functions in this script
+ bool sn_pr_force; ///< forceit: profile functions in this script
proftime_T sn_pr_child; ///< time set when going into first child
int sn_pr_nest; ///< nesting for sn_pr_child
// profiling the script as a whole
@@ -76,29 +76,27 @@ typedef struct scriptitem_S {
int sn_prl_execed; ///< line being timed was executed
} scriptitem_T;
-static garray_T script_items = {0, 0, sizeof(scriptitem_T), 4, NULL};
+static garray_T script_items = { 0, 0, sizeof(scriptitem_T), 4, NULL };
#define SCRIPT_ITEM(id) (((scriptitem_T *)script_items.ga_data)[(id) - 1])
-/* Struct used in sn_prl_ga for every line of a script. */
+// Struct used in sn_prl_ga for every line of a script.
typedef struct sn_prl_S {
int snp_count; ///< nr of times line was executed
proftime_T sn_prl_total; ///< time spent in a line + children
proftime_T sn_prl_self; ///< time spent in a line itself
} sn_prl_T;
-/*
- * Structure used to store info for each sourced file.
- * It is shared between do_source() and getsourceline().
- * This is required, because it needs to be handed to do_cmdline() and
- * sourcing can be done recursively.
- */
+/// Structure used to store info for each sourced file.
+/// It is shared between do_source() and getsourceline().
+/// This is required, because it needs to be handed to do_cmdline() and
+/// sourcing can be done recursively.
struct source_cookie {
FILE *fp; ///< opened file for sourcing
char_u *nextline; ///< if not NULL: line that was read ahead
int finished; ///< ":finish" used
#if defined(USE_CRNL)
int fileformat; ///< EOL_UNKNOWN, EOL_UNIX or EOL_DOS
- int error; ///< TRUE if LF found after CR-LF
+ bool error; ///< true if LF found after CR-LF
#endif
linenr_T breakpoint; ///< next line with breakpoint or zero
char_u *fname; ///< name of sourced file
@@ -113,13 +111,11 @@ struct source_cookie {
# include "ex_cmds2.c.generated.h"
#endif
-static int debug_greedy = FALSE; /* batch mode debugging: don't save
- and restore typeahead. */
+/// batch mode debugging: don't save and restore typeahead.
+static bool debug_greedy = false;
-/*
- * do_debug(): Debug mode.
- * Repeatedly get Ex commands, until told to continue normal execution.
- */
+/// Debug mode. Repeatedly get Ex commands, until told to continue normal
+/// execution.
void do_debug(char_u *cmd)
{
int save_msg_scroll = msg_scroll;
@@ -130,7 +126,7 @@ void do_debug(char_u *cmd)
int save_emsg_silent = emsg_silent;
int save_redir_off = redir_off;
tasave_T typeaheadbuf;
- int typeahead_saved = FALSE;
+ bool typeahead_saved = false;
int save_ignore_script = 0;
int save_ex_normal_busy;
int n;
@@ -150,43 +146,44 @@ void do_debug(char_u *cmd)
#define CMD_DOWN 10
- ++RedrawingDisabled; /* don't redisplay the window */
- ++no_wait_return; /* don't wait for return */
- did_emsg = FALSE; /* don't use error from debugged stuff */
- cmd_silent = FALSE; /* display commands */
- msg_silent = FALSE; /* display messages */
- emsg_silent = FALSE; /* display error messages */
- redir_off = TRUE; /* don't redirect debug commands */
+ RedrawingDisabled++; // don't redisplay the window
+ no_wait_return++; // don't wait for return
+ did_emsg = false; // don't use error from debugged stuff
+ cmd_silent = false; // display commands
+ msg_silent = false; // display messages
+ emsg_silent = false; // display error messages
+ redir_off = true; // don't redirect debug commands
State = NORMAL;
- if (!debug_did_msg)
+ if (!debug_did_msg) {
MSG(_("Entering Debug mode. Type \"cont\" to continue."));
- if (sourcing_name != NULL)
+ }
+ if (sourcing_name != NULL) {
msg(sourcing_name);
- if (sourcing_lnum != 0)
+ }
+ if (sourcing_lnum != 0) {
smsg(_("line %" PRId64 ": %s"), (int64_t)sourcing_lnum, cmd);
- else
+ } else {
smsg(_("cmd: %s"), cmd);
+ }
- /*
- * Repeat getting a command and executing it.
- */
+ // Repeat getting a command and executing it.
for (;; ) {
- msg_scroll = TRUE;
- need_wait_return = FALSE;
- /* Save the current typeahead buffer and replace it with an empty one.
- * This makes sure we get input from the user here and don't interfere
- * with the commands being executed. Reset "ex_normal_busy" to avoid
- * the side effects of using ":normal". Save the stuff buffer and make
- * it empty. Set ignore_script to avoid reading from script input. */
+ msg_scroll = true;
+ need_wait_return = false;
+ // Save the current typeahead buffer and replace it with an empty one.
+ // This makes sure we get input from the user here and don't interfere
+ // with the commands being executed. Reset "ex_normal_busy" to avoid
+ // the side effects of using ":normal". Save the stuff buffer and make
+ // it empty. Set ignore_script to avoid reading from script input.
save_ex_normal_busy = ex_normal_busy;
ex_normal_busy = 0;
if (!debug_greedy) {
save_typeahead(&typeaheadbuf);
- typeahead_saved = TRUE;
+ typeahead_saved = true;
save_ignore_script = ignore_script;
- ignore_script = TRUE;
+ ignore_script = true;
}
xfree(cmdline);
@@ -201,9 +198,9 @@ void do_debug(char_u *cmd)
cmdline_row = msg_row;
msg_starthere();
if (cmdline != NULL) {
- /* If this is a debug command, set "last_cmd".
- * If not, reset "last_cmd".
- * For a blank line use previous command. */
+ // If this is a debug command, set "last_cmd".
+ // If not, reset "last_cmd".
+ // For a blank line use previous command.
p = skipwhite(cmdline);
if (*p != NUL) {
switch (*p) {
@@ -255,11 +252,11 @@ void do_debug(char_u *cmd)
default: last_cmd = 0;
}
if (last_cmd != 0) {
- /* Check that the tail matches. */
- ++p;
+ // Check that the tail matches.
+ p++;
while (*p != NUL && *p == *tail) {
- ++p;
- ++tail;
+ p++;
+ tail++;
}
if (ASCII_ISALPHA(*p) && last_cmd != CMD_FRAME) {
last_cmd = 0;
@@ -268,8 +265,7 @@ void do_debug(char_u *cmd)
}
if (last_cmd != 0) {
- /* Execute debug command: decided where to break next and
- * return. */
+ // Execute debug command: decided where to break next and return.
switch (last_cmd) {
case CMD_CONT:
debug_break_level = -1;
@@ -284,13 +280,13 @@ void do_debug(char_u *cmd)
debug_break_level = ex_nesting_level - 1;
break;
case CMD_QUIT:
- got_int = TRUE;
+ got_int = true;
debug_break_level = -1;
break;
case CMD_INTERRUPT:
- got_int = TRUE;
+ got_int = true;
debug_break_level = 9999;
- /* Do not repeat ">interrupt" cmd, continue stepping. */
+ // Do not repeat ">interrupt" cmd, continue stepping.
last_cmd = CMD_STEP;
break;
case CMD_BACKTRACE:
@@ -318,21 +314,21 @@ void do_debug(char_u *cmd)
break;
}
- /* don't debug this command */
+ // don't debug this command
n = debug_break_level;
debug_break_level = -1;
(void)do_cmdline(cmdline, getexline, NULL,
- DOCMD_VERBOSE|DOCMD_EXCRESET);
+ DOCMD_VERBOSE|DOCMD_EXCRESET);
debug_break_level = n;
}
lines_left = (int)(Rows - 1);
}
xfree(cmdline);
- --RedrawingDisabled;
- --no_wait_return;
+ RedrawingDisabled--;
+ no_wait_return--;
redraw_all_later(NOT_VALID);
- need_wait_return = FALSE;
+ need_wait_return = false;
msg_scroll = save_msg_scroll;
lines_left = (int)(Rows - 1);
State = save_State;
@@ -342,9 +338,8 @@ void do_debug(char_u *cmd)
emsg_silent = save_emsg_silent;
redir_off = save_redir_off;
- /* Only print the message again when typing a command before coming back
- * here. */
- debug_did_msg = TRUE;
+ // Only print the message again when typing a command before coming back here.
+ debug_did_msg = true;
}
static int get_maxbacktrace_level(void)
@@ -419,9 +414,8 @@ static void do_showbacktrace(char_u *cmd)
}
}
-/*
- * ":debug".
- */
+
+/// ":debug".
void ex_debug(exarg_T *eap)
{
int debug_break_level_save = debug_break_level;
@@ -434,88 +428,81 @@ void ex_debug(exarg_T *eap)
static char_u *debug_breakpoint_name = NULL;
static linenr_T debug_breakpoint_lnum;
-/*
- * When debugging or a breakpoint is set on a skipped command, no debug prompt
- * is shown by do_one_cmd(). This situation is indicated by debug_skipped, and
- * debug_skipped_name is then set to the source name in the breakpoint case. If
- * a skipped command decides itself that a debug prompt should be displayed, it
- * can do so by calling dbg_check_skipped().
- */
+/// When debugging or a breakpoint is set on a skipped command, no debug prompt
+/// is shown by do_one_cmd(). This situation is indicated by debug_skipped, and
+/// debug_skipped_name is then set to the source name in the breakpoint case. If
+/// a skipped command decides itself that a debug prompt should be displayed, it
+/// can do so by calling dbg_check_skipped().
static int debug_skipped;
static char_u *debug_skipped_name;
-/*
- * Go to debug mode when a breakpoint was encountered or "ex_nesting_level" is
- * at or below the break level. But only when the line is actually
- * executed. Return TRUE and set breakpoint_name for skipped commands that
- * decide to execute something themselves.
- * Called from do_one_cmd() before executing a command.
- */
+/// Go to debug mode when a breakpoint was encountered or "ex_nesting_level" is
+/// at or below the break level. But only when the line is actually
+/// executed. Return true and set breakpoint_name for skipped commands that
+/// decide to execute something themselves.
+/// Called from do_one_cmd() before executing a command.
void dbg_check_breakpoint(exarg_T *eap)
{
char_u *p;
- debug_skipped = FALSE;
+ debug_skipped = false;
if (debug_breakpoint_name != NULL) {
if (!eap->skip) {
- /* replace K_SNR with "<SNR>" */
+ // replace K_SNR with "<SNR>"
if (debug_breakpoint_name[0] == K_SPECIAL
&& debug_breakpoint_name[1] == KS_EXTRA
- && debug_breakpoint_name[2] == (int)KE_SNR)
+ && debug_breakpoint_name[2] == (int)KE_SNR) {
p = (char_u *)"<SNR>";
- else
+ } else {
p = (char_u *)"";
+ }
smsg(_("Breakpoint in \"%s%s\" line %" PRId64),
- p,
- debug_breakpoint_name + (*p == NUL ? 0 : 3),
- (int64_t)debug_breakpoint_lnum);
+ p,
+ debug_breakpoint_name + (*p == NUL ? 0 : 3),
+ (int64_t)debug_breakpoint_lnum);
debug_breakpoint_name = NULL;
do_debug(eap->cmd);
} else {
- debug_skipped = TRUE;
+ debug_skipped = true;
debug_skipped_name = debug_breakpoint_name;
debug_breakpoint_name = NULL;
}
} else if (ex_nesting_level <= debug_break_level) {
- if (!eap->skip)
+ if (!eap->skip) {
do_debug(eap->cmd);
- else {
- debug_skipped = TRUE;
+ } else {
+ debug_skipped = true;
debug_skipped_name = NULL;
}
}
}
-/*
- * Go to debug mode if skipped by dbg_check_breakpoint() because eap->skip was
- * set. Return TRUE when the debug mode is entered this time.
- */
-int dbg_check_skipped(exarg_T *eap)
+/// Go to debug mode if skipped by dbg_check_breakpoint() because eap->skip was
+/// set.
+///
+/// @return true when the debug mode is entered this time.
+bool dbg_check_skipped(exarg_T *eap)
{
int prev_got_int;
if (debug_skipped) {
- /*
- * Save the value of got_int and reset it. We don't want a previous
- * interruption cause flushing the input buffer.
- */
+ // Save the value of got_int and reset it. We don't want a previous
+ // interruption cause flushing the input buffer.
prev_got_int = got_int;
- got_int = FALSE;
+ got_int = false;
debug_breakpoint_name = debug_skipped_name;
- /* eap->skip is TRUE */
- eap->skip = FALSE;
+ // eap->skip is true
+ eap->skip = false;
dbg_check_breakpoint(eap);
- eap->skip = TRUE;
+ eap->skip = true;
got_int |= prev_got_int;
- return TRUE;
+ return true;
}
- return FALSE;
+ return false;
}
-/*
- * The list of breakpoints: dbg_breakp.
- * This is a grow-array of structs.
- */
+/// The list of breakpoints: dbg_breakp.
+/// This is a grow-array of structs.
struct debuggy {
int dbg_nr; ///< breakpoint number
int dbg_type; ///< DBG_FUNC or DBG_FILE
@@ -525,33 +512,30 @@ struct debuggy {
int dbg_forceit; ///< ! used
};
-static garray_T dbg_breakp = {0, 0, sizeof(struct debuggy), 4, NULL};
+static garray_T dbg_breakp = { 0, 0, sizeof(struct debuggy), 4, NULL };
#define BREAKP(idx) (((struct debuggy *)dbg_breakp.ga_data)[idx])
#define DEBUGGY(gap, idx) (((struct debuggy *)gap->ga_data)[idx])
-static int last_breakp = 0; /* nr of last defined breakpoint */
+static int last_breakp = 0; // nr of last defined breakpoint
-/* Profiling uses file and func names similar to breakpoints. */
-static garray_T prof_ga = {0, 0, sizeof(struct debuggy), 4, NULL};
+// Profiling uses file and func names similar to breakpoints.
+static garray_T prof_ga = { 0, 0, sizeof(struct debuggy), 4, NULL };
#define DBG_FUNC 1
#define DBG_FILE 2
-/*
- * Parse the arguments of ":profile", ":breakadd" or ":breakdel" and put them
- * in the entry just after the last one in dbg_breakp. Note that "dbg_name"
- * is allocated.
- * Returns FAIL for failure.
- */
-static int
-dbg_parsearg (
- char_u *arg,
- garray_T *gap /* either &dbg_breakp or &prof_ga */
-)
+/// Parse the arguments of ":profile", ":breakadd" or ":breakdel" and put them
+/// in the entry just after the last one in dbg_breakp. Note that "dbg_name"
+/// is allocated.
+/// Returns FAIL for failure.
+///
+/// @param arg
+/// @param gap either &dbg_breakp or &prof_ga
+static int dbg_parsearg(char_u *arg, garray_T *gap)
{
char_u *p = arg;
char_u *q;
struct debuggy *bp;
- int here = FALSE;
+ bool here = false;
ga_grow(gap, 1);
@@ -568,7 +552,7 @@ dbg_parsearg (
return FAIL;
}
bp->dbg_type = DBG_FILE;
- here = TRUE;
+ here = true;
} else {
EMSG2(_(e_invarg2), p);
return FAIL;
@@ -585,7 +569,7 @@ dbg_parsearg (
bp->dbg_lnum = 0;
}
- /* Find the function or file name. Don't accept a function name with (). */
+ // Find the function or file name. Don't accept a function name with ().
if ((!here && *p == NUL)
|| (here && *p != NUL)
|| (bp->dbg_type == DBG_FUNC && strstr((char *)p, "()") != NULL)) {
@@ -593,36 +577,38 @@ dbg_parsearg (
return FAIL;
}
- if (bp->dbg_type == DBG_FUNC)
+ if (bp->dbg_type == DBG_FUNC) {
bp->dbg_name = vim_strsave(p);
- else if (here)
+ } else if (here) {
bp->dbg_name = vim_strsave(curbuf->b_ffname);
- else {
- /* Expand the file name in the same way as do_source(). This means
- * doing it twice, so that $DIR/file gets expanded when $DIR is
- * "~/dir". */
+ } else {
+ // Expand the file name in the same way as do_source(). This means
+ // doing it twice, so that $DIR/file gets expanded when $DIR is
+ // "~/dir".
q = expand_env_save(p);
- if (q == NULL)
+ if (q == NULL) {
return FAIL;
+ }
p = expand_env_save(q);
xfree(q);
- if (p == NULL)
+ if (p == NULL) {
return FAIL;
+ }
if (*p != '*') {
bp->dbg_name = (char_u *)fix_fname((char *)p);
xfree(p);
- } else
+ } else {
bp->dbg_name = p;
+ }
}
- if (bp->dbg_name == NULL)
+ if (bp->dbg_name == NULL) {
return FAIL;
+ }
return OK;
}
-/*
- * ":breakadd".
- */
+/// ":breakadd".
void ex_breakadd(exarg_T *eap)
{
struct debuggy *bp;
@@ -630,52 +616,51 @@ void ex_breakadd(exarg_T *eap)
garray_T *gap;
gap = &dbg_breakp;
- if (eap->cmdidx == CMD_profile)
+ if (eap->cmdidx == CMD_profile) {
gap = &prof_ga;
+ }
if (dbg_parsearg(eap->arg, gap) == OK) {
bp = &DEBUGGY(gap, gap->ga_len);
bp->dbg_forceit = eap->forceit;
- pat = file_pat_to_reg_pat(bp->dbg_name, NULL, NULL, FALSE);
+ pat = file_pat_to_reg_pat(bp->dbg_name, NULL, NULL, false);
if (pat != NULL) {
bp->dbg_prog = vim_regcomp(pat, RE_MAGIC + RE_STRING);
xfree(pat);
}
- if (pat == NULL || bp->dbg_prog == NULL)
+ if (pat == NULL || bp->dbg_prog == NULL) {
xfree(bp->dbg_name);
- else {
- if (bp->dbg_lnum == 0) /* default line number is 1 */
+ } else {
+ if (bp->dbg_lnum == 0) { // default line number is 1
bp->dbg_lnum = 1;
+ }
if (eap->cmdidx != CMD_profile) {
DEBUGGY(gap, gap->ga_len).dbg_nr = ++last_breakp;
- ++debug_tick;
+ debug_tick++;
}
- ++gap->ga_len;
+ gap->ga_len++;
}
}
}
-/*
- * ":debuggreedy".
- */
+/// ":debuggreedy".
void ex_debuggreedy(exarg_T *eap)
{
- if (eap->addr_count == 0 || eap->line2 != 0)
- debug_greedy = TRUE;
- else
- debug_greedy = FALSE;
+ if (eap->addr_count == 0 || eap->line2 != 0) {
+ debug_greedy = true;
+ } else {
+ debug_greedy = false;
+ }
}
-/*
- * ":breakdel" and ":profdel".
- */
+/// ":breakdel" and ":profdel".
void ex_breakdel(exarg_T *eap)
{
struct debuggy *bp, *bpi;
int nr;
int todel = -1;
- int del_all = FALSE;
+ bool del_all = false;
linenr_T best_lnum = 0;
garray_T *gap;
@@ -687,7 +672,7 @@ void ex_breakdel(exarg_T *eap)
if (ascii_isdigit(*eap->arg)) {
// ":breakdel {nr}"
nr = atoi((char *)eap->arg);
- for (int i = 0; i < gap->ga_len; ++i) {
+ for (int i = 0; i < gap->ga_len; i++) {
if (DEBUGGY(gap, i).dbg_nr == nr) {
todel = i;
break;
@@ -695,13 +680,14 @@ void ex_breakdel(exarg_T *eap)
}
} else if (*eap->arg == '*') {
todel = 0;
- del_all = TRUE;
+ del_all = true;
} else {
- /* ":breakdel {func|file} [lnum] {name}" */
- if (dbg_parsearg(eap->arg, gap) == FAIL)
+ // ":breakdel {func|file} [lnum] {name}"
+ if (dbg_parsearg(eap->arg, gap) == FAIL) {
return;
+ }
bp = &DEBUGGY(gap, gap->ga_len);
- for (int i = 0; i < gap->ga_len; ++i) {
+ for (int i = 0; i < gap->ga_len; i++) {
bpi = &DEBUGGY(gap, i);
if (bp->dbg_type == bpi->dbg_type
&& STRCMP(bp->dbg_name, bpi->dbg_name) == 0
@@ -716,90 +702,85 @@ void ex_breakdel(exarg_T *eap)
xfree(bp->dbg_name);
}
- if (todel < 0)
+ if (todel < 0) {
EMSG2(_("E161: Breakpoint not found: %s"), eap->arg);
- else {
+ } else {
while (!GA_EMPTY(gap)) {
xfree(DEBUGGY(gap, todel).dbg_name);
vim_regfree(DEBUGGY(gap, todel).dbg_prog);
- --gap->ga_len;
- if (todel < gap->ga_len)
+ gap->ga_len--;
+ if (todel < gap->ga_len) {
memmove(&DEBUGGY(gap, todel), &DEBUGGY(gap, todel + 1),
(size_t)(gap->ga_len - todel) * sizeof(struct debuggy));
+ }
if (eap->cmdidx == CMD_breakdel) {
- ++debug_tick;
+ debug_tick++;
}
if (!del_all) {
break;
}
}
- /* If all breakpoints were removed clear the array. */
- if (GA_EMPTY(gap))
+ // If all breakpoints were removed clear the array.
+ if (GA_EMPTY(gap)) {
ga_clear(gap);
+ }
}
}
-/*
- * ":breaklist".
- */
+/// ":breaklist".
void ex_breaklist(exarg_T *eap)
{
struct debuggy *bp;
- if (GA_EMPTY(&dbg_breakp))
+ if (GA_EMPTY(&dbg_breakp)) {
MSG(_("No breakpoints defined"));
- else
- for (int i = 0; i < dbg_breakp.ga_len; ++i) {
+ } else {
+ for (int i = 0; i < dbg_breakp.ga_len; i++) {
bp = &BREAKP(i);
- if (bp->dbg_type == DBG_FILE)
- home_replace(NULL, bp->dbg_name, NameBuff, MAXPATHL, TRUE);
+ if (bp->dbg_type == DBG_FILE) {
+ home_replace(NULL, bp->dbg_name, NameBuff, MAXPATHL, true);
+ }
smsg(_("%3d %s %s line %" PRId64),
- bp->dbg_nr,
- bp->dbg_type == DBG_FUNC ? "func" : "file",
- bp->dbg_type == DBG_FUNC ? bp->dbg_name : NameBuff,
- (int64_t)bp->dbg_lnum);
- }
-}
-
-/*
- * Find a breakpoint for a function or sourced file.
- * Returns line number at which to break; zero when no matching breakpoint.
- */
-linenr_T
-dbg_find_breakpoint (
- int file, /* TRUE for a file, FALSE for a function */
- char_u *fname, /* file or function name */
- linenr_T after /* after this line number */
+ bp->dbg_nr,
+ bp->dbg_type == DBG_FUNC ? "func" : "file",
+ bp->dbg_type == DBG_FUNC ? bp->dbg_name : NameBuff,
+ (int64_t)bp->dbg_lnum);
+ }
+ }
+}
+
+/// Find a breakpoint for a function or sourced file.
+/// Returns line number at which to break; zero when no matching breakpoint.
+linenr_T
+dbg_find_breakpoint(
+ bool file, // true for a file, false for a function
+ char_u *fname, // file or function name
+ linenr_T after // after this line number
)
{
return debuggy_find(file, fname, after, &dbg_breakp, NULL);
}
-/*
- * Return TRUE if profiling is on for a function or sourced file.
- */
-int
-has_profiling (
- int file, /* TRUE for a file, FALSE for a function */
- char_u *fname, /* file or function name */
- int *fp /* return: forceit */
-)
+/// @param file true for a file, false for a function
+/// @param fname file or function name
+/// @param fp[out] forceit
+///
+/// @returns true if profiling is on for a function or sourced file.
+bool has_profiling(bool file, char_u *fname, bool *fp)
{
return debuggy_find(file, fname, (linenr_T)0, &prof_ga, fp)
!= (linenr_T)0;
}
-/*
- * Common code for dbg_find_breakpoint() and has_profiling().
- */
-static linenr_T
-debuggy_find (
- int file, /* TRUE for a file, FALSE for a function */
- char_u *fname, /* file or function name */
- linenr_T after, /* after this line number */
- garray_T *gap, /* either &dbg_breakp or &prof_ga */
- int *fp /* if not NULL: return forceit */
+/// Common code for dbg_find_breakpoint() and has_profiling().
+static linenr_T
+debuggy_find(
+ bool file, // true for a file, false for a function
+ char_u *fname, // file or function name
+ linenr_T after, // after this line number
+ garray_T *gap, // either &dbg_breakp or &prof_ga
+ bool *fp // if not NULL: return forceit
)
{
struct debuggy *bp;
@@ -807,59 +788,57 @@ debuggy_find (
char_u *name = fname;
int prev_got_int;
- /* Return quickly when there are no breakpoints. */
- if (GA_EMPTY(gap))
+ // Return quickly when there are no breakpoints.
+ if (GA_EMPTY(gap)) {
return (linenr_T)0;
+ }
- /* Replace K_SNR in function name with "<SNR>". */
+ // Replace K_SNR in function name with "<SNR>".
if (!file && fname[0] == K_SPECIAL) {
name = xmalloc(STRLEN(fname) + 3);
STRCPY(name, "<SNR>");
STRCPY(name + 5, fname + 3);
}
- for (int i = 0; i < gap->ga_len; ++i) {
- /* Skip entries that are not useful or are for a line that is beyond
- * an already found breakpoint. */
+ for (int i = 0; i < gap->ga_len; i++) {
+ // Skip entries that are not useful or are for a line that is beyond
+ // an already found breakpoint.
bp = &DEBUGGY(gap, i);
- if (((bp->dbg_type == DBG_FILE) == file
- && (gap == &prof_ga
- || (bp->dbg_lnum > after
- && (lnum == 0 || bp->dbg_lnum < lnum))))) {
+ if ((bp->dbg_type == DBG_FILE) == file
+ && (gap == &prof_ga
+ || (bp->dbg_lnum > after && (lnum == 0 || bp->dbg_lnum < lnum)))) {
// Save the value of got_int and reset it. We don't want a
// previous interruption cancel matching, only hitting CTRL-C
// while matching should abort it.
prev_got_int = got_int;
- got_int = FALSE;
+ got_int = false;
if (vim_regexec_prog(&bp->dbg_prog, false, name, (colnr_T)0)) {
lnum = bp->dbg_lnum;
- if (fp != NULL)
+ if (fp != NULL) {
*fp = bp->dbg_forceit;
+ }
}
got_int |= prev_got_int;
}
}
- if (name != fname)
+ if (name != fname) {
xfree(name);
+ }
return lnum;
}
-/*
- * Called when a breakpoint was encountered.
- */
+/// Called when a breakpoint was encountered.
void dbg_breakpoint(char_u *name, linenr_T lnum)
{
- /* We need to check if this line is actually executed in do_one_cmd() */
+ // We need to check if this line is actually executed in do_one_cmd()
debug_breakpoint_name = name;
debug_breakpoint_lnum = lnum;
}
static char_u *profile_fname = NULL;
-/*
- * ":profile cmd args"
- */
+/// ":profile cmd args"
void ex_profile(exarg_T *eap)
{
static proftime_T pause_time;
@@ -885,8 +864,9 @@ void ex_profile(exarg_T *eap)
set_vim_var_nr(VV_PROFILING, 0L);
profile_reset();
} else if (STRCMP(eap->arg, "pause") == 0) {
- if (do_profiling == PROF_YES)
+ if (do_profiling == PROF_YES) {
pause_time = profile_start();
+ }
do_profiling = PROF_PAUSED;
} else if (STRCMP(eap->arg, "continue") == 0) {
if (do_profiling == PROF_PAUSED) {
@@ -897,7 +877,7 @@ void ex_profile(exarg_T *eap)
} else if (STRCMP(eap->arg, "dump") == 0) {
profile_dump();
} else {
- /* The rest is similar to ":breakadd". */
+ // The rest is similar to ":breakadd".
ex_breakadd(eap);
}
}
@@ -932,7 +912,7 @@ void ex_pydo3(exarg_T *eap)
script_host_do_range("python3", eap);
}
-/* Command line expansion for :profile. */
+// Command line expansion for :profile.
static enum {
PEXP_SUBCMD, ///< expand :profile sub-commands
PEXP_FUNC ///< expand :profile func {funcname}
@@ -949,36 +929,33 @@ static char *pexpand_cmds[] = {
NULL
};
-/*
- * Function given to ExpandGeneric() to obtain the profile command
- * specific expansion.
- */
+/// Function given to ExpandGeneric() to obtain the profile command
+/// specific expansion.
char_u *get_profile_name(expand_T *xp, int idx)
{
switch (pexpand_what) {
case PEXP_SUBCMD:
return (char_u *)pexpand_cmds[idx];
- /* case PEXP_FUNC: TODO */
+ // case PEXP_FUNC: TODO
default:
return NULL;
}
}
-/*
- * Handle command line completion for :profile command.
- */
+/// Handle command line completion for :profile command.
void set_context_in_profile_cmd(expand_T *xp, char_u *arg)
{
char_u *end_subcmd;
- /* Default: expand subcommands. */
+ // Default: expand subcommands.
xp->xp_context = EXPAND_PROFILE;
pexpand_what = PEXP_SUBCMD;
xp->xp_pattern = arg;
end_subcmd = skiptowhite(arg);
- if (*end_subcmd == NUL)
+ if (*end_subcmd == NUL) {
return;
+ }
if (end_subcmd - arg == 5 && STRNCMP(arg, "start", 5) == 0) {
xp->xp_context = EXPAND_FILES;
@@ -986,22 +963,20 @@ void set_context_in_profile_cmd(expand_T *xp, char_u *arg)
return;
}
- /* TODO: expand function names after "func" */
+ // TODO(tarruda): expand function names after "func"
xp->xp_context = EXPAND_NOTHING;
}
-/*
- * Dump the profiling info.
- */
+/// Dump the profiling info.
void profile_dump(void)
{
FILE *fd;
if (profile_fname != NULL) {
fd = mch_fopen((char *)profile_fname, "w");
- if (fd == NULL)
+ if (fd == NULL) {
EMSG2(_(e_notopen), profile_fname);
- else {
+ } else {
script_dump_profile(fd);
func_dump_profile(fd);
fclose(fd);
@@ -1017,7 +992,7 @@ static void profile_reset(void)
scriptitem_T *si = &SCRIPT_ITEM(id);
if (si->sn_prof_on) {
si->sn_prof_on = false;
- si->sn_pr_force = 0;
+ si->sn_pr_force = false;
si->sn_pr_child = profile_zero();
si->sn_pr_nest = 0;
si->sn_pr_count = 0;
@@ -1077,26 +1052,23 @@ static void profile_init(scriptitem_T *si)
si->sn_pr_nest = 0;
}
-/*
- * save time when starting to invoke another script or function.
- */
+/// save time when starting to invoke another script or function.
void script_prof_save(
- proftime_T *tm /* place to store wait time */
- )
+ proftime_T *tm // place to store wait time
+)
{
scriptitem_T *si;
if (current_SID > 0 && current_SID <= script_items.ga_len) {
si = &SCRIPT_ITEM(current_SID);
- if (si->sn_prof_on && si->sn_pr_nest++ == 0)
+ if (si->sn_prof_on && si->sn_pr_nest++ == 0) {
si->sn_pr_child = profile_start();
+ }
}
*tm = profile_get_wait();
}
-/*
- * Count time spent in children after invoking another script or function.
- */
+/// Count time spent in children after invoking another script or function.
void script_prof_restore(proftime_T *tm)
{
scriptitem_T *si;
@@ -1115,62 +1087,60 @@ void script_prof_restore(proftime_T *tm)
static proftime_T inchar_time;
-/*
- * Called when starting to wait for the user to type a character.
- */
+/// Called when starting to wait for the user to type a character.
void prof_inchar_enter(void)
{
inchar_time = profile_start();
}
-/*
- * Called when finished waiting for the user to type a character.
- */
+/// Called when finished waiting for the user to type a character.
void prof_inchar_exit(void)
{
inchar_time = profile_end(inchar_time);
profile_set_wait(profile_add(profile_get_wait(), inchar_time));
}
-/*
- * Dump the profiling results for all scripts in file "fd".
- */
+/// Dump the profiling results for all scripts in file "fd".
static void script_dump_profile(FILE *fd)
{
scriptitem_T *si;
FILE *sfd;
sn_prl_T *pp;
- for (int id = 1; id <= script_items.ga_len; ++id) {
+ for (int id = 1; id <= script_items.ga_len; id++) {
si = &SCRIPT_ITEM(id);
if (si->sn_prof_on) {
fprintf(fd, "SCRIPT %s\n", si->sn_name);
- if (si->sn_pr_count == 1)
+ if (si->sn_pr_count == 1) {
fprintf(fd, "Sourced 1 time\n");
- else
+ } else {
fprintf(fd, "Sourced %d times\n", si->sn_pr_count);
+ }
fprintf(fd, "Total time: %s\n", profile_msg(si->sn_pr_total));
fprintf(fd, " Self time: %s\n", profile_msg(si->sn_pr_self));
fprintf(fd, "\n");
fprintf(fd, "count total (s) self (s)\n");
sfd = mch_fopen((char *)si->sn_name, "r");
- if (sfd == NULL)
+ if (sfd == NULL) {
fprintf(fd, "Cannot open file!\n");
- else {
- for (int i = 0; i < si->sn_prl_ga.ga_len; ++i) {
- if (vim_fgets(IObuff, IOSIZE, sfd))
+ } else {
+ for (int i = 0; i < si->sn_prl_ga.ga_len; i++) {
+ if (vim_fgets(IObuff, IOSIZE, sfd)) {
break;
+ }
pp = &PRL_ITEM(si, i);
if (pp->snp_count > 0) {
fprintf(fd, "%5d ", pp->snp_count);
- if (profile_equal(pp->sn_prl_total, pp->sn_prl_self))
+ if (profile_equal(pp->sn_prl_total, pp->sn_prl_self)) {
fprintf(fd, " ");
- else
+ } else {
fprintf(fd, "%s ", profile_msg(pp->sn_prl_total));
+ }
fprintf(fd, "%s ", profile_msg(pp->sn_prl_self));
- } else
+ } else {
fprintf(fd, " ");
+ }
fprintf(fd, "%s", IObuff);
}
fclose(sfd);
@@ -1180,44 +1150,41 @@ static void script_dump_profile(FILE *fd)
}
}
-/*
- * Return TRUE when a function defined in the current script should be