diff options
| -rw-r--r-- | src/nvim/ex_cmds2.c | 2244 | 
1 files changed, 1084 insertions, 1160 deletions
| diff --git a/src/nvim/ex_cmds2.c b/src/nvim/ex_cmds2.c index 247f86679f..b06d0c1883 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,22 @@  #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. */ +#ifdef WIN32 +#define os_strtok_r strtok_s +#else +#define os_strtok_r strtok_r +#endif + + +/// 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 +83,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 +118,13 @@ 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. - */ +/// Repeatedly get Ex commands, until told to continue normal execution. +/// Handles debug mode. +/// +/// @param cmd  void do_debug(char_u *cmd)  {    int save_msg_scroll = msg_scroll; @@ -130,7 +135,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 +155,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 +207,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 +261,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 +274,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 +289,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 +323,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 +347,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 +423,10 @@ static void do_showbacktrace(char_u *cmd)    }  } -/* - * ":debug". - */ + +/// ":debug". +/// +/// @param eap  void ex_debug(exarg_T *eap)  {    int debug_break_level_save = debug_break_level; @@ -434,88 +439,85 @@ 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. +/// +/// @param eap  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. +/// +/// @param eap +/// +/// @return true when the debug mode is entered this time. +bool dbg_check_skipped(exarg_T *eap)  { -  int prev_got_int; +  bool 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 +527,32 @@ 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 +/// +/// @return +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 +569,7 @@ dbg_parsearg (        return FAIL;      }      bp->dbg_type = DBG_FILE; -    here = TRUE; +    here = true;    } else {      EMSG2(_(e_invarg2), p);      return FAIL; @@ -585,7 +586,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 +594,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 +633,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 +689,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 +697,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 +719,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[out] fp: 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 +805,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 +881,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 +894,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 +929,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 +946,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 +980,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 +1009,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 +1069,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 +1104,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 +1167,40 @@ static void script_dump_profile(FILE *fd)    }  } -/* - * Return TRUE when a function defined in the current script should be - * profiled. - */ -int prof_def_func(void) +/// Return true when a function defined in the current script should be +/// profiled. +bool prof_def_func(void)  { -  if (current_SID > 0) +  if (current_SID > 0) {      return SCRIPT_ITEM(current_SID).sn_pr_force; -  return FALSE; +  } +  return false;  } -/* - * If 'autowrite' option set, try to write the file. - * Careful: autocommands may make "buf" invalid! - * - * return FAIL for failure, OK otherwise - */ +/// If 'autowrite' option set, try to write the file. +/// Careful: autocommands may make "buf" invalid! +/// return FAIL for failure, OK otherwise  int autowrite(buf_T *buf, int forceit)  {    int r;    if (!(p_aw || p_awa) || !p_write -      /* never autowrite a "nofile" or "nowrite" buffer */ +      // never autowrite a "nofile" or "nowrite" buffer        || bt_dontwrite(buf) -      || (!forceit && buf->b_p_ro) || buf->b_ffname == NULL) +      || (!forceit && buf->b_p_ro) || buf->b_ffname == NULL) {      return FAIL; +  }    r = buf_write_all(buf, forceit); -  /* Writing may succeed but the buffer still changed, e.g., when there is a -   * conversion error.  We do want to return FAIL then. */ -  if (buf_valid(buf) && bufIsChanged(buf)) +  // Writing may succeed but the buffer still changed, e.g., when there is a +  // conversion error.  We do want to return FAIL then. +  if (buf_valid(buf) && bufIsChanged(buf)) {      r = FAIL; +  }    return r;  } -/* - * flush all buffers, except the ones that are readonly - */ +/// flush all buffers, except the ones that are readonly  void autowrite_all(void)  {    if (!(p_aw || p_awa) || !p_write) { @@ -1226,123 +1209,125 @@ void autowrite_all(void)    FOR_ALL_BUFFERS(buf) {      if (bufIsChanged(buf) && !buf->b_p_ro) { -      (void)buf_write_all(buf, FALSE); -      /* an autocommand may have deleted the buffer */ -      if (!buf_valid(buf)) +      (void)buf_write_all(buf, false); +      // an autocommand may have deleted the buffer +      if (!buf_valid(buf)) {          buf = firstbuf; +      }      }    }  } -/* - * Return TRUE if buffer was changed and cannot be abandoned. - * For flags use the CCGD_ values. - */ -int check_changed(buf_T *buf, int flags) +/// Return true if buffer was changed and cannot be abandoned. +/// For flags use the CCGD_ values. +bool check_changed(buf_T *buf, int flags)  {    int forceit = (flags & CCGD_FORCEIT); -  if (       !forceit -             && bufIsChanged(buf) -             && ((flags & CCGD_MULTWIN) || buf->b_nwindows <= 1) -             && (!(flags & CCGD_AW) || autowrite(buf, forceit) == FAIL)) { +  if (!forceit +      && bufIsChanged(buf) +      && ((flags & CCGD_MULTWIN) || buf->b_nwindows <= 1) +      && (!(flags & CCGD_AW) || autowrite(buf, forceit) == FAIL)) {      if ((p_confirm || cmdmod.confirm) && p_write) {        int count = 0; -      if (flags & CCGD_ALLBUF) +      if (flags & CCGD_ALLBUF) {          FOR_ALL_BUFFERS(buf2) {            if (bufIsChanged(buf2) && (buf2->b_ffname != NULL)) { -            ++count; +            count++;            }          } -      if (!buf_valid(buf)) -        /* Autocommand deleted buffer, oops!  It's not changed now. */ -        return FALSE; +      } +      if (!buf_valid(buf)) { +        // Autocommand deleted buffer, oops!  It's not changed now. +        return false; +      }        dialog_changed(buf, count > 1); -      if (!buf_valid(buf)) -        /* Autocommand deleted buffer, oops!  It's not changed now. */ -        return FALSE; +      if (!buf_valid(buf)) { +        // Autocommand deleted buffer, oops!  It's not changed now. +        return false; +      }        return bufIsChanged(buf);      } -    if (flags & CCGD_EXCMD) +    if (flags & CCGD_EXCMD) {        EMSG(_(e_nowrtmsg)); -    else +    } else {        EMSG(_(e_nowrtmsg_nobang)); -    return TRUE; +    } +    return true;    } -  return FALSE; +  return false;  } -/* - * Ask the user what to do when abandoning a changed buffer. - * Must check 'write' option first! - */ -void  -dialog_changed ( -    buf_T *buf, -    int checkall                   /* may abandon all changed buffers */ -) +/// Ask the user what to do when abandoning a changed buffer. +/// Must check 'write' option first! +/// +/// @param buf +/// @param checkall may abandon all changed buffers +void dialog_changed(buf_T *buf, int checkall)  {    char_u buff[DIALOG_MSG_SIZE];    int ret;    exarg_T ea;    dialog_msg(buff, _("Save changes to \"%s\"?"), -      (buf->b_fname != NULL) ? -      buf->b_fname : (char_u *)_("Untitled")); -  if (checkall) +             (buf->b_fname != NULL) ? +             buf->b_fname : (char_u *)_("Untitled")); +  if (checkall) {      ret = vim_dialog_yesnoallcancel(VIM_QUESTION, NULL, buff, 1); -  else +  } else {      ret = vim_dialog_yesnocancel(VIM_QUESTION, NULL, buff, 1); +  } -  /* Init ea pseudo-structure, this is needed for the check_overwrite() -   * function. */ -  ea.append = ea.forceit = FALSE; +  // Init ea pseudo-structure, this is needed for the check_overwrite() +  // function. +  ea.append = ea.forceit = false;    if (ret == VIM_YES) { -    if (buf->b_fname != NULL && check_overwrite(&ea, buf, -            buf->b_fname, buf->b_ffname, FALSE) == OK) -      /* didn't hit Cancel */ -      (void)buf_write_all(buf, FALSE); +    if (buf->b_fname != NULL +        && check_overwrite(&ea, +                           buf, +                           buf->b_fname, +                           buf->b_ffname, +                           false) == OK) { +      // didn't hit Cancel +      (void)buf_write_all(buf, false); +    }    } else if (ret == VIM_NO) { -    unchanged(buf, TRUE); +    unchanged(buf, true);    } else if (ret == VIM_ALL) { -    /* -     * Write all modified files that can be written. -     * Skip readonly buffers, these need to be confirmed -     * individually. -     */ +    // Write all modified files that can be written. +    // Skip readonly buffers, these need to be confirmed +    // individually.      FOR_ALL_BUFFERS(buf2) {        if (bufIsChanged(buf2) -          && (buf2->b_ffname != NULL -              ) +          && (buf2->b_ffname != NULL)            && !buf2->b_p_ro) { -        if (buf2->b_fname != NULL && check_overwrite(&ea, buf2, -                buf2->b_fname, buf2->b_ffname, FALSE) == OK) -          /* didn't hit Cancel */ -          (void)buf_write_all(buf2, FALSE); -        /* an autocommand may have deleted the buffer */ -        if (!buf_valid(buf2)) +        if (buf2->b_fname != NULL +            && check_overwrite(&ea, buf2, buf2->b_fname, +                               buf2->b_ffname, false) == OK) { +          // didn't hit Cancel +          (void)buf_write_all(buf2, false); +        } +        // an autocommand may have deleted the buffer +        if (!buf_valid(buf2)) {            buf2 = firstbuf; +        }        }      }    } else if (ret == VIM_DISCARDALL) { -    /* -     * mark all buffers as unchanged -     */ +    // mark all buffers as unchanged      FOR_ALL_BUFFERS(buf2) { -      unchanged(buf2, TRUE); +      unchanged(buf2, true);      }    }  } -/* - * Return TRUE if the buffer "buf" can be abandoned, either by making it - * hidden, autowriting it or unloading it. - */ -int can_abandon(buf_T *buf, int forceit) +/// Return true if the buffer "buf" can be abandoned, either by making it +/// hidden, autowriting it or unloading it. +bool can_abandon(buf_T *buf, int forceit)  {    return P_HID(buf)           || !bufIsChanged(buf) @@ -1352,16 +1337,16 @@ int can_abandon(buf_T *buf, int forceit)  } -/* - * Add a buffer number to "bufnrs", unless it's already there. - */ +/// Add a buffer number to "bufnrs", unless it's already there.  static void add_bufnum(int *bufnrs, int *bufnump, int nr)  {    int i; -  for (i = 0; i < *bufnump; ++i) -    if (bufnrs[i] == nr) +  for (i = 0; i < *bufnump; i++) { +    if (bufnrs[i] == nr) {        return; +    } +  }    bufnrs[*bufnump] = nr;    *bufnump = *bufnump + 1;  } @@ -1375,7 +1360,7 @@ static void add_bufnum(int *bufnrs, int *bufnump, int nr)  /// @param[in] unload specifies whether to unload, instead of hide, the buffer.  ///  /// @returns          true if any buffer is changed and cannot be abandoned -int check_changed_any(bool hidden, bool unload) +bool check_changed_any(bool hidden, bool unload)  {    bool ret = false;    int save; @@ -1385,7 +1370,7 @@ int check_changed_any(bool hidden, bool unload)    int         *bufnrs;    FOR_ALL_BUFFERS(buf) { -    ++bufcount; +    bufcount++;    }    if (bufcount == 0) { @@ -1394,16 +1379,16 @@ int check_changed_any(bool hidden, bool unload)    bufnrs = xmalloc(sizeof(*bufnrs) * bufcount); -  /* curbuf */ +  // curbuf    bufnrs[bufnum++] = curbuf->b_fnum; -  /* buf in curtab */ +  // buf in curtab    FOR_ALL_WINDOWS_IN_TAB(wp, curtab) {      if (wp->w_buffer != curbuf) {        add_bufnum(bufnrs, &bufnum, wp->w_buffer->b_fnum);      }    } -  /* buf in other tab */ +  // buf in other tab    FOR_ALL_TABS(tp) {      if (tp != curtab) {        FOR_ALL_WINDOWS_IN_TAB(wp, tp) { @@ -1412,59 +1397,60 @@ int check_changed_any(bool hidden, bool unload)      }    } -  /* any other buf */ +  // any other buf    FOR_ALL_BUFFERS(buf) {      add_bufnum(bufnrs, &bufnum, buf->b_fnum);    }    buf_T *buf = NULL; -  for (i = 0; i < bufnum; ++i) { +  for (i = 0; i < bufnum; i++) {      buf = buflist_findnr(bufnrs[i]); -    if (buf == NULL) +    if (buf == NULL) {        continue; +    }      if ((!hidden || buf->b_nwindows == 0) && bufIsChanged(buf)) { -      /* Try auto-writing the buffer.  If this fails but the buffer no -       * longer exists it's not changed, that's OK. */ +      // Try auto-writing the buffer.  If this fails but the buffer no +      // longer exists it's not changed, that's OK.        if (check_changed(buf, (p_awa ? CCGD_AW : 0) -              | CCGD_MULTWIN -              | CCGD_ALLBUF) && buf_valid(buf)) -        break;              /* didn't save - still changes */ +                        | CCGD_MULTWIN +                        | CCGD_ALLBUF) && buf_valid(buf)) { +        break;    // didn't save - still changes +      }      }    } -  if (i >= bufnum) +  if (i >= bufnum) {      goto theend; +  } -  ret = TRUE; -  exiting = FALSE; -  /* -   * When ":confirm" used, don't give an error message. -   */ +  ret = true; +  exiting = false; +  // When ":confirm" used, don't give an error message.    if (!(p_confirm || cmdmod.confirm)) { -    /* There must be a wait_return for this message, do_buffer() -     * may cause a redraw.  But wait_return() is a no-op when vgetc() -     * is busy (Quit used from window menu), then make sure we don't -     * cause a scroll up. */ +    // There must be a wait_return for this message, do_buffer() +    // may cause a redraw.  But wait_return() is a no-op when vgetc() +    // is busy (Quit used from window menu), then make sure we don't +    // cause a scroll up.      if (vgetc_busy > 0) {        msg_row = cmdline_row;        msg_col = 0; -      msg_didout = FALSE; +      msg_didout = false;      }      if (EMSG2(_("E162: No write since last change for buffer \"%s\""), -            buf_spname(buf) != NULL ? buf_spname(buf) : buf->b_fname)) { +              buf_spname(buf) != NULL ? buf_spname(buf) : buf->b_fname)) {        save = no_wait_return; -      no_wait_return = FALSE; -      wait_return(FALSE); +      no_wait_return = false; +      wait_return(false);        no_wait_return = save;      }    } -  /* Try to find a window that contains the buffer. */ +  // Try to find a window that contains the buffer.    if (buf != curbuf) {      FOR_ALL_TAB_WINDOWS(tp, wp) {        if (wp->w_buffer == buf) {          goto_tabpage_win(tp, wp); -        /* Paranoia: did autocms wipe out the buffer with changes? */ +        // Paranoia: did autocms wipe out the buffer with changes?          if (!buf_valid(buf)) {            goto theend;          } @@ -1484,10 +1470,8 @@ theend:    return ret;  } -/* - * return FAIL if there is no file name, OK if there is one - * give error message for FAIL - */ +/// return FAIL if there is no file name, OK if there is one +/// give error message for FAIL  int check_fname(void)  {    if (curbuf->b_ffname == NULL) { @@ -1497,19 +1481,16 @@ int check_fname(void)    return OK;  } -/* - * flush the contents of a buffer, unless it has no file name - * - * return FAIL for failure, OK otherwise - */ +/// flush the contents of a buffer, unless it has no file name +/// return FAIL for failure, OK otherwise  int buf_write_all(buf_T *buf, int forceit)  {    int retval;    buf_T       *old_curbuf = curbuf;    retval = (buf_write(buf, buf->b_ffname, buf->b_fname, -                (linenr_T)1, buf->b_ml.ml_line_count, NULL, -                FALSE, forceit, TRUE, FALSE)); +                      (linenr_T)1, buf->b_ml.ml_line_count, NULL, +                      false, forceit, true, false));    if (curbuf != old_curbuf) {      msg_source(hl_attr(HLF_W));      MSG(_("Warning: Entered other buffer unexpectedly (check autocommands)")); @@ -1517,37 +1498,35 @@ int buf_write_all(buf_T *buf, int forceit)    return retval;  } -/* - * Code to handle the argument list. - */ +/// Code to handle the argument list.  #define AL_SET  1  #define AL_ADD  2  #define AL_DEL  3 -/* - * Isolate one argument, taking backticks. - * Changes the argument in-place, puts a NUL after it.  Backticks remain. - * Return a pointer to the start of the next argument. - */ +/// Isolate one argument, taking backticks. +/// Changes the argument in-place, puts a NUL after it.  Backticks remain. +/// Return a pointer to the start of the next argument.  static char_u *do_one_arg(char_u *str)  {    char_u      *p; -  int inbacktick; +  bool inbacktick; -  inbacktick = FALSE; -  for (p = str; *str; ++str) { -    /* When the backslash is used for escaping the special meaning of a -     * character we need to keep it until wildcard expansion. */ +  inbacktick = false; +  for (p = str; *str; str++) { +    // When the backslash is used for escaping the special meaning of a +    // character we need to keep it until wildcard expansion.      if (rem_backslash(str)) {        *p++ = *str++;        *p++ = *str;      } else { -      /* An item ends at a space not in backticks */ -      if (!inbacktick && ascii_isspace(*str)) +      // An item ends at a space not in backticks +      if (!inbacktick && ascii_isspace(*str)) {          break; -      if (*str == '`') -        inbacktick ^= TRUE; +      } +      if (*str == '`') { +        inbacktick ^= true; +      }        *p++ = *str;      }    } @@ -1557,26 +1536,22 @@ static char_u *do_one_arg(char_u *str)    return str;  } -/* - * Separate the arguments in "str" and return a list of pointers in the - * growarray "gap". - */ +/// Separate the arguments in "str" and return a list of pointers in the +/// growarray "gap".  void get_arglist(garray_T *gap, char_u *str)  {    ga_init(gap, (int)sizeof(char_u *), 20);    while (*str != NUL) {      GA_APPEND(char_u *, gap, str); -    /* Isolate one argument, change it in-place, put a NUL after it. */ +    // Isolate one argument, change it in-place, put a NUL after it.      str = do_one_arg(str);    }  } -/* - * Parse a list of arguments (file names), expand them and return in - * "fnames[fcountp]".  When "wig" is true, removes files matching 'wildignore'. - * Return FAIL or OK. - */ +/// Parse a list of arguments (file names), expand them and return in +/// "fnames[fcountp]".  When "wig" is true, removes files matching 'wildignore'. +/// Return FAIL or OK.  int get_arglist_exp(char_u *str, int *fcountp, char_u ***fnamesp, bool wig)  {    garray_T ga; @@ -1584,31 +1559,29 @@ int get_arglist_exp(char_u *str, int *fcountp, char_u ***fnamesp, bool wig)    get_arglist(&ga, str); -  if (wig) +  if (wig) {      i = expand_wildcards(ga.ga_len, (char_u **)ga.ga_data, -        fcountp, fnamesp, EW_FILE|EW_NOTFOUND); -  else +                         fcountp, fnamesp, EW_FILE|EW_NOTFOUND); +  } else {      i = gen_expand_wildcards(ga.ga_len, (char_u **)ga.ga_data, -        fcountp, fnamesp, EW_FILE|EW_NOTFOUND); +                             fcountp, fnamesp, EW_FILE|EW_NOTFOUND); +  }    ga_clear(&ga);    return i;  } -/* - * "what" == AL_SET: Redefine the argument list to 'str'. - * "what" == AL_ADD: add files in 'str' to the argument list after "after". - * "what" == AL_DEL: remove files in 'str' from the argument list. - * - * Return FAIL for failure, OK otherwise. - */ -static int  -do_arglist ( -    char_u *str, -    int what, -    int after                       /* 0 means before first one */ -) +/// @param str +/// @param what +///         AL_SET: Redefine the argument list to 'str'. +///         AL_ADD: add files in 'str' to the argument list after "after". +///         AL_DEL: remove files in 'str' from the argument list. +/// @param after +///         0 means before first one +/// +/// @return FAIL for failure, OK otherwise. +static int do_arglist(char_u *str, int what, int after)  {    garray_T new_ga;    int exp_count; @@ -1629,47 +1602,50 @@ do_arglist (    if (what == AL_DEL) {      regmatch_T regmatch; -    int didone; - -    /* -     * Delete the items: use each item as a regexp and find a match in the -     * argument list. -     */ -    regmatch.rm_ic = p_fic;     /* ignore case when 'fileignorecase' is set */ -    for (int i = 0; i < new_ga.ga_len && !got_int; ++i) { +    bool didone; + +    // Delete the items: use each item as a regexp and find a match in the +    // argument list. +    regmatch.rm_ic = p_fic;     // ignore case when 'fileignorecase' is set +    for (int i = 0; i < new_ga.ga_len && !got_int; i++) {        p = ((char_u **)new_ga.ga_data)[i]; -      p = file_pat_to_reg_pat(p, NULL, NULL, FALSE); -      if (p == NULL) +      p = file_pat_to_reg_pat(p, NULL, NULL, false); +      if (p == NULL) {          break; +      }        regmatch.regprog = vim_regcomp(p, p_magic ? RE_MAGIC : 0);        if (regmatch.regprog == NULL) {          xfree(p);          break;        } -      didone = FALSE; -      for (match = 0; match < ARGCOUNT; ++match) +      didone = false; +      for (match = 0; match < ARGCOUNT; match++) {          if (vim_regexec(®match, alist_name(&ARGLIST[match]), -                (colnr_T)0)) { -          didone = TRUE; +                        (colnr_T)0)) { +          didone = true;            xfree(ARGLIST[match].ae_fname);            memmove(ARGLIST + match, ARGLIST + match + 1,                    (size_t)(ARGCOUNT - match - 1) * sizeof(aentry_T)); -          --ALIST(curwin)->al_ga.ga_len; -          if (curwin->w_arg_idx > match) -            --curwin->w_arg_idx; -          --match; +          ALIST(curwin)->al_ga.ga_len--; +          if (curwin->w_arg_idx > match) { +            curwin->w_arg_idx--; +          } +          match--;          } +      }        vim_regfree(regmatch.regprog);        xfree(p); -      if (!didone) +      if (!didone) {          EMSG2(_(e_nomatch2), ((char_u **)new_ga.ga_data)[i]); +      }      }      ga_clear(&new_ga);    } else {      int i = expand_wildcards(new_ga.ga_len, (char_u **)new_ga.ga_data, -        &exp_count, &exp_files, EW_DIR|EW_FILE|EW_ADDSLASH|EW_NOTFOUND); +                             &exp_count, &exp_files, +                             EW_DIR|EW_FILE|EW_ADDSLASH|EW_NOTFOUND);      ga_clear(&new_ga);      if (i == FAIL || exp_count == 0) {        EMSG(_(e_nomatch)); @@ -1679,8 +1655,9 @@ do_arglist (      if (what == AL_ADD) {        (void)alist_add_list(exp_count, exp_files, after);        xfree(exp_files); -    } else   /* what == AL_SET */ -      alist_set(ALIST(curwin), exp_count, exp_files, FALSE, NULL, 0); +    } else {  // what == AL_SET +      alist_set(ALIST(curwin), exp_count, exp_files, false, NULL, 0); +    }    }    alist_check_arg_idx(); @@ -1688,9 +1665,7 @@ do_arglist (    return OK;  } -/* - * Check the validity of the arg_idx for each other window. - */ +/// Check the validity of the arg_idx for each other window.  static void alist_check_arg_idx(void)  {    FOR_ALL_TAB_WINDOWS(tp, win) { @@ -1700,136 +1675,123 @@ static void alist_check_arg_idx(void)    }  } -/* - * Return TRUE if window "win" is editing the file at the current argument - * index. - */ -static int editing_arg_idx(win_T *win) +/// Return true if window "win" is editing the file at the current argument +/// index. +static bool editing_arg_idx(win_T *win)  {    return !(win->w_arg_idx >= WARGCOUNT(win)             || (win->w_buffer->b_fnum                 != WARGLIST(win)[win->w_arg_idx].ae_fnum                 && (win->w_buffer->b_ffname == NULL                     || !(path_full_compare( -                            alist_name(&WARGLIST(win)[win->w_arg_idx]), -                            win->w_buffer->b_ffname, TRUE) & kEqualFiles)))); +                       alist_name(&WARGLIST(win)[win->w_arg_idx]), +                       win->w_buffer->b_ffname, true) & kEqualFiles))));  } -/* - * Check if window "win" is editing the w_arg_idx file in its argument list. - */ +/// Check if window "win" is editing the w_arg_idx file in its argument list.  void check_arg_idx(win_T *win)  {    if (WARGCOUNT(win) > 1 && !editing_arg_idx(win)) { -    /* We are not editing the current entry in the argument list. -     * Set "arg_had_last" if we are editing the last one. */ -    win->w_arg_idx_invalid = TRUE; +    // We are not editing the current entry in the argument list. +    // Set "arg_had_last" if we are editing the last one. +    win->w_arg_idx_invalid = true;      if (win->w_arg_idx != WARGCOUNT(win) - 1 -        && arg_had_last == FALSE +        && arg_had_last == false          && ALIST(win) == &global_alist          && GARGCOUNT > 0          && win->w_arg_idx < GARGCOUNT          && (win->w_buffer->b_fnum == GARGLIST[GARGCOUNT - 1].ae_fnum              || (win->w_buffer->b_ffname != NULL                  && (path_full_compare(alist_name(&GARGLIST[GARGCOUNT - 1]), -                        win->w_buffer->b_ffname, TRUE) & kEqualFiles)))) -      arg_had_last = TRUE; +                                      win->w_buffer->b_ffname, true) +                    & kEqualFiles)))) { +      arg_had_last = true; +    }    } else { -    /* We are editing the current entry in the argument list. -     * Set "arg_had_last" if it's also the last one */ -    win->w_arg_idx_invalid = FALSE; +    // We are editing the current entry in the argument list. +    // Set "arg_had_last" if it's also the last one +    win->w_arg_idx_invalid = false;      if (win->w_arg_idx == WARGCOUNT(win) - 1 -        && win->w_alist == &global_alist -        ) -      arg_had_last = TRUE; +        && win->w_alist == &global_alist) { +      arg_had_last = true; +    }    }  } -/* - * ":args", ":argslocal" and ":argsglobal". - */ +/// ":args", ":argslocal" and ":argsglobal".  void ex_args(exarg_T *eap)  {    if (eap->cmdidx != CMD_args) {      alist_unlink(ALIST(curwin)); -    if (eap->cmdidx == CMD_argglobal) +    if (eap->cmdidx == CMD_argglobal) {        ALIST(curwin) = &global_alist; -    else     /* eap->cmdidx == CMD_arglocal */ +    } else {     // eap->cmdidx == CMD_arglocal        alist_new(); +    }    }    if (!ends_excmd(*eap->arg)) { -    /* -     * ":args file ..": define new argument list, handle like ":next" -     * Also for ":argslocal file .." and ":argsglobal file ..". -     */ +    // ":args file ..": define new argument list, handle like ":next" +    // Also for ":argslocal file .." and ":argsglobal file ..".      ex_next(eap); -  } else if (eap->cmdidx == CMD_args)  { -    /* -     * ":args": list arguments. -     */ +  } else if (eap->cmdidx == CMD_args) { +    // ":args": list arguments.      if (ARGCOUNT > 0) { -      /* Overwrite the command, for a short list there is no scrolling -       * required and no wait_return(). */ -      gotocmdline(TRUE); -      for (int i = 0; i < ARGCOUNT; ++i) { -        if (i == curwin->w_arg_idx) +      // Overwrite the command, for a short list there is no scrolling +      // required and no wait_return(). +      gotocmdline(true); +      for (int i = 0; i < ARGCOUNT; i++) { +        if (i == curwin->w_arg_idx) {            msg_putchar('['); +        }          msg_outtrans(alist_name(&ARGLIST[i])); -        if (i == curwin->w_arg_idx) +        if (i == curwin->w_arg_idx) {            msg_putchar(']'); +        }          msg_putchar(' ');        }      }    } else if (eap->cmdidx == CMD_arglocal) {      garray_T        *gap = &curwin->w_alist->al_ga; -    /* -     * ":argslocal": make a local copy of the global argument list. -     */ +    // ":argslocal": make a local copy of the global argument list.      ga_grow(gap, GARGCOUNT); -    for (int i = 0; i < GARGCOUNT; ++i) +    for (int i = 0; i < GARGCOUNT; i++) {        if (GARGLIST[i].ae_fname != NULL) {          AARGLIST(curwin->w_alist)[gap->ga_len].ae_fname =            vim_strsave(GARGLIST[i].ae_fname);          AARGLIST(curwin->w_alist)[gap->ga_len].ae_fnum =            GARGLIST[i].ae_fnum; -        ++gap->ga_len; +        gap->ga_len++;        } +    }    }  } -/* - * ":previous", ":sprevious", ":Next" and ":sNext". - */ +/// ":previous", ":sprevious", ":Next" and ":sNext".  void ex_previous(exarg_T *eap)  { -  /* If past the last one already, go to the last one. */ -  if (curwin->w_arg_idx - (int)eap->line2 >= ARGCOUNT) +  // If past the last one already, go to the last one. +  if (curwin->w_arg_idx - (int)eap->line2 >= ARGCOUNT) {      do_argfile(eap, ARGCOUNT - 1); -  else +  } else {      do_argfile(eap, curwin->w_arg_idx - (int)eap->line2); +  }  } -/* - * ":rewind", ":first", ":sfirst" and ":srewind". - */ +/// ":rewind", ":first", ":sfirst" and ":srewind".  void ex_rewind(exarg_T *eap)  {    do_argfile(eap, 0);  } -/* - * ":last" and ":slast". - */ +/// ":last" and ":slast".  void ex_last(exarg_T *eap)  {    do_argfile(eap, ARGCOUNT - 1);  } -/* - * ":argument" and ":sargument". - */ +/// ":argument" and ":sargument".  void ex_argument(exarg_T *eap)  {    int i; @@ -1842,9 +1804,7 @@ void ex_argument(exarg_T *eap)    do_argfile(eap, i);  } -/* - * Edit file "argn" of the argument lists. - */ +/// Edit file "argn" of the argument lists.  void do_argfile(exarg_T *eap, int argn)  {    int other; @@ -1852,26 +1812,26 @@ void do_argfile(exarg_T *eap, int argn)    int old_arg_idx = curwin->w_arg_idx;    if (argn < 0 || argn >= ARGCOUNT) { -    if (ARGCOUNT <= 1) +    if (ARGCOUNT <= 1) {        EMSG(_("E163: There is only one file to edit")); -    else if (argn < 0) +    } else if (argn < 0) {        EMSG(_("E164: Cannot go before first file")); -    else +    } else {        EMSG(_("E165: Cannot go beyond last file")); +    }    } else {      setpcmark(); -    /* split window or create new tab page first */ +    // split window or create new tab page first      if (*eap->cmd == 's' || cmdmod.tab != 0) { -      if (win_split(0, 0) == FAIL) +      if (win_split(0, 0) == FAIL) {          return; +      }        RESET_BINDING(curwin);      } else { -      /* -       * if 'hidden' set, only check for changed file when re-editing -       * the same buffer -       */ -      other = TRUE; +      // if 'hidden' set, only check for changed file when re-editing +      // the same buffer +      other = true;        if (P_HID(curbuf)) {          p = (char_u *)fix_fname((char *)alist_name(&ARGLIST[argn]));          other = otherfile(p); @@ -1879,101 +1839,98 @@ void do_argfile(exarg_T *eap, int argn)        }        if ((!P_HID(curbuf) || !other)            && check_changed(curbuf, CCGD_AW -              | (other ? 0 : CCGD_MULTWIN) -              | (eap->forceit ? CCGD_FORCEIT : 0) -              | CCGD_EXCMD)) +                           | (other ? 0 : CCGD_MULTWIN) +                           | (eap->forceit ? CCGD_FORCEIT : 0) +                           | CCGD_EXCMD)) {          return; +      }      }      curwin->w_arg_idx = argn;      if (argn == ARGCOUNT - 1 -        && curwin->w_alist == &global_alist -        ) -      arg_had_last = TRUE; +        && curwin->w_alist == &global_alist) { +      arg_had_last = true; +    } -    /* Edit the file; always use the last known line number. -     * When it fails (e.g. Abort for already edited file) restore the -     * argument index. */ +    // Edit the file; always use the last known line number. +    // When it fails (e.g. Abort for already edited file) restore the +    // argument index.      if (do_ecmd(0, alist_name(&ARGLIST[curwin->w_arg_idx]), NULL, -            eap, ECMD_LAST, -            (P_HID(curwin->w_buffer) ? ECMD_HIDE : 0) -            + (eap->forceit ? ECMD_FORCEIT : 0), curwin) == FAIL) +                eap, ECMD_LAST, +                (P_HID(curwin->w_buffer) ? ECMD_HIDE : 0) +                + (eap->forceit ? ECMD_FORCEIT : 0), curwin) == FAIL) {        curwin->w_arg_idx = old_arg_idx; -    /* like Vi: set the mark where the cursor is in the file. */ -    else if (eap->cmdidx != CMD_argdo) +    } else if (eap->cmdidx != CMD_argdo) { +      // like Vi: set the mark where the cursor is in the file.        setmark('\''); +    }    }  } -/* - * ":next", and commands that behave like it. - */ +/// ":next", and commands that behave like it.  void ex_next(exarg_T *eap)  {    int i; -  /* -   * check for changed buffer now, if this fails the argument list is not -   * redefined. -   */ -  if (       P_HID(curbuf) -             || eap->cmdidx == CMD_snext -             || !check_changed(curbuf, CCGD_AW -                 | (eap->forceit ? CCGD_FORCEIT : 0) -                 | CCGD_EXCMD)) { -    if (*eap->arg != NUL) {                 /* redefine file list */ -      if (do_arglist(eap->arg, AL_SET, 0) == FAIL) +  // check for changed buffer now, if this fails the argument list is not +  // redefined. +  if (P_HID(curbuf) +      || eap->cmdidx == CMD_snext +      || !check_changed(curbuf, CCGD_AW +                        | (eap->forceit ? CCGD_FORCEIT : 0) +                        | CCGD_EXCMD)) { +    if (*eap->arg != NUL) {                 // redefine file list +      if (do_arglist(eap->arg, AL_SET, 0) == FAIL) {          return; +      }        i = 0; -    } else +    } else {        i = curwin->w_arg_idx + (int)eap->line2; +    }      do_argfile(eap, i);    }  } -/* - * ":argedit" - */ +/// ":argedit"  void ex_argedit(exarg_T *eap)  {    int fnum;    int i;    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); -  /* Check if this argument is already in the argument list. */ -  for (i = 0; i < ARGCOUNT; ++i) -    if (ARGLIST[i].ae_fnum == fnum) +  // Check if this argument is already in the argument list. +  for (i = 0; i < ARGCOUNT; i++) { +    if (ARGLIST[i].ae_fnum == fnum) {        break; +    } +  }    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); -    i = alist_add_list(1, &s, -        eap->addr_count > 0 ? (int)eap->line2 : curwin->w_arg_idx + 1); +    after = eap->addr_count > 0 ? (int)eap->line2 : curwin->w_arg_idx + 1; +    i = alist_add_list(1, &s, after);      curwin->w_arg_idx = i;    }    alist_check_arg_idx(); -  /* Edit the argument. */ +  // Edit the argument.    do_argfile(eap, i);  } -/* - * ":argadd" - */ +/// ":argadd"  void ex_argadd(exarg_T *eap)  {    do_arglist(eap->arg, AL_ADD, -      eap->addr_count > 0 ? (int)eap->line2 : curwin->w_arg_idx + 1); +             eap->addr_count > 0 ? (int)eap->line2 : curwin->w_arg_idx + 1);    maketitle();  } -/* - * ":argdelete" - */ +/// ":argdelete"  void ex_argdelete(exarg_T *eap)  {    if (eap->addr_count > 0) { @@ -1985,7 +1942,7 @@ void ex_argdelete(exarg_T *eap)      if (*eap->arg != NUL || n <= 0) {        EMSG(_(e_invarg));      } else { -      for (linenr_T i = eap->line1; i <= eap->line2; ++i) { +      for (linenr_T i = eap->line1; i <= eap->line2; i++) {          xfree(ARGLIST[i - 1].ae_fname);        }        memmove(ARGLIST + eap->line1 - 1, ARGLIST + eap->line2, @@ -2020,10 +1977,11 @@ void ex_listdo(exarg_T *eap)    char_u      *save_ei = NULL;    char_u      *p_shm_save; -  if (eap->cmdidx != CMD_windo && eap->cmdidx != CMD_tabdo) -    /* Don't do syntax HL autocommands.  Skipping the syntax file is a -     * great speed improvement. */ +  if (eap->cmdidx != CMD_windo && eap->cmdidx != CMD_tabdo) { +    // Don't do syntax HL autocommands.  Skipping the syntax file is a +    // great speed improvement.      save_ei = au_event_disable(",Syntax"); +  }    start_global_changes(); @@ -2031,28 +1989,28 @@ void ex_listdo(exarg_T *eap)        || eap->cmdidx == CMD_tabdo        || P_HID(curbuf)        || !check_changed(curbuf, CCGD_AW -          | (eap->forceit ? CCGD_FORCEIT : 0) -          | CCGD_EXCMD)) { +                        | (eap->forceit ? CCGD_FORCEIT : 0) +                        | CCGD_EXCMD)) {      i = 0; -    /* start at the eap->line1 argument/window/buffer */ +    // start at the eap->line1 argument/window/buffer      wp = firstwin;      tp = first_tabpage;      switch (eap->cmdidx) { -      case CMD_windo: -        for (; wp != NULL && i + 1 < eap->line1; wp = wp->w_next) { -          i++; -        } -        break; -      case CMD_tabdo: -        for (; tp != NULL && i + 1 < eap->line1; tp = tp->tp_next) { -          i++; -        } -        break; -      case CMD_argdo: -        i = (int)eap->line1 - 1; -        break; -      default: -        break; +    case CMD_windo: +      for (; wp != NULL && i + 1 < eap->line1; wp = wp->w_next) { +        i++; +      } +      break; +    case CMD_tabdo: +      for (; tp != NULL && i + 1 < eap->line1; tp = tp->tp_next) { +        i++; +      } +      break; +    case CMD_argdo: +      i = (int)eap->line1 - 1; +      break; +    default: +      break;      }      buf_T *buf = curbuf; @@ -2092,64 +2050,71 @@ void ex_listdo(exarg_T *eap)      } else {        setpcmark();      } -    listcmd_busy = TRUE;            /* avoids setting pcmark below */ +    listcmd_busy = true;            // avoids setting pcmark below      while (!got_int && buf != NULL) {        if (eap->cmdidx == CMD_argdo) { -        /* go to argument "i" */ -        if (i == ARGCOUNT) +        // go to argument "i" +        if (i == ARGCOUNT) {            break; -        /* Don't call do_argfile() when already there, it will try -         * reloading the file. */ +        } +        // Don't call do_argfile() when already there, it will try +        // reloading the file.          if (curwin->w_arg_idx != i || !editing_arg_idx(curwin)) { -          /* Clear 'shm' to avoid that the file message overwrites -           * any output from the command. */ +          // Clear 'shm' to avoid that the file message overwrites +          // any output from the command.            p_shm_save = vim_strsave(p_shm);            set_option_value((char_u *)"shm", 0L, (char_u *)"", 0);            do_argfile(eap, i);            set_option_value((char_u *)"shm", 0L, p_shm_save, 0);            xfree(p_shm_save);          } -        if (curwin->w_arg_idx != i) +        if (curwin->w_arg_idx != i) {            break; +        }        } else if (eap->cmdidx == CMD_windo) { -        /* go to window "wp" */ -        if (!win_valid(wp)) +        // go to window "wp" +        if (!win_valid(wp)) {            break; +        }          assert(wp);          win_goto(wp); -        if (curwin != wp) -          break;            /* something must be wrong */ +        if (curwin != wp) { +          break;    // something must be wrong +        }          wp = curwin->w_next;        } else if (eap->cmdidx == CMD_tabdo) { -        /* go to window "tp" */ -        if (!valid_tabpage(tp)) +        // go to window "tp" +        if (!valid_tabpage(tp)) {            break; +        }          assert(tp); -        goto_tabpage_tp(tp, TRUE, TRUE); +        goto_tabpage_tp(tp, true, true);          tp = tp->tp_next;        } else if (eap->cmdidx == CMD_bufdo) { -        /* Remember the number of the next listed buffer, in case -         * ":bwipe" is used or autocommands do something strange. */ +        // Remember the number of the next listed buffer, in case +        // ":bwipe" is used or autocommands do something strange.          next_fnum = -1; -        for (buf_T *buf = curbuf->b_next; buf != NULL; buf = buf->b_next) +        for (buf_T *buf = curbuf->b_next; buf != NULL; buf = buf->b_next) {            if (buf->b_p_bl) {              next_fnum = buf->b_fnum;              break;            } +        }        } -      ++i; -      /* execute the command */ +      i++; +      // execute the command        do_cmdline(eap->arg, eap->getline, eap->cookie, -          DOCMD_VERBOSE + DOCMD_NOWAIT); +                 DOCMD_VERBOSE + DOCMD_NOWAIT);        if (eap->cmdidx == CMD_bufdo) { -        /* Done? */ -        if (next_fnum < 0 || next_fnum > eap->line2) +        // Done? +        if (next_fnum < 0 || next_fnum > eap->line2) {            break; +        } -        /* Check if the buffer still exists. */ +        // Check if the buffer still exists.          bool buf_still_exists = false;          FOR_ALL_BUFFERS(bp) {            if (bp->b_fnum == next_fnum) { @@ -2161,8 +2126,8 @@ void ex_listdo(exarg_T *eap)            break;          } -        /* Go to the next buffer.  Clear 'shm' to avoid that the file -         * message overwrites any output from the command. */ +        // Go to the next buffer.  Clear 'shm' to avoid that the file +        // message overwrites any output from the command.          p_shm_save = vim_strsave(p_shm);          set_option_value((char_u *)"shm", 0L, (char_u *)"", 0);          goto_buffer(eap, DOBUF_FIRST, FORWARD, next_fnum); @@ -2188,15 +2153,16 @@ void ex_listdo(exarg_T *eap)          // If jumping to the next quickfix entry fails, quit here.          if (qf_get_cur_idx(eap) == qf_idx) { -            break; +          break;          }        }        if (eap->cmdidx == CMD_windo) { -        validate_cursor();              /* cursor may have moved */ -        /* required when 'scrollbind' has been set */ -        if (curwin->w_p_scb) -          do_check_scrollbind(TRUE); +        validate_cursor();              // cursor may have moved +        // required when 'scrollbind' has been set +        if (curwin->w_p_scb) { +          do_check_scrollbind(true); +        }        }        if (eap->cmdidx == CMD_windo || eap->cmdidx == CMD_tabdo) {          if (i + 1 > eap->line2) { @@ -2207,41 +2173,40 @@ void ex_listdo(exarg_T *eap)          break;        }      } -    listcmd_busy = FALSE; +    listcmd_busy = false;    }    if (save_ei != NULL) {      au_event_restore(save_ei);      apply_autocmds(EVENT_SYNTAX, curbuf->b_p_syn, -        curbuf->b_fname, TRUE, curbuf); +                   curbuf->b_fname, true, curbuf);    }    end_global_changes();  } -/* - * Add files[count] to the arglist of the current window after arg "after". - * The file names in files[count] must have been allocated and are taken over. - * Files[] itself is not taken over. - * Returns index of first added argument. - */ -static int  -alist_add_list ( -    int count, -    char_u **files, -    int after                  /* where to add: 0 = before first one */ -) +/// Add files[count] to the arglist of the current window after arg "after". +/// The file names in files[count] must have been allocated and are taken over. +/// Files[] itself is not taken over. +/// +/// @param after: where to add: 0 = before first one +/// +/// @return index of first added argument +static int alist_add_list(int count, char_u **files, int after)  {    int old_argcount = ARGCOUNT;    ga_grow(&ALIST(curwin)->al_ga, count);    { -    if (after < 0) +    if (after < 0) {        after = 0; -    if (after > ARGCOUNT) +    } +    if (after > ARGCOUNT) {        after = ARGCOUNT; -    if (after < ARGCOUNT) +    } +    if (after < ARGCOUNT) {        memmove(&(ARGLIST[after + count]), &(ARGLIST[after]),                (size_t)(ARGCOUNT - after) * sizeof(aentry_T)); -    for (int i = 0; i < count; ++i) { +    } +    for (int i = 0; i < count; i++) {        ARGLIST[after + i].ae_fname = files[i];        ARGLIST[after + i].ae_fnum = buflist_add(files[i], BLN_LISTED);      } @@ -2254,66 +2219,68 @@ alist_add_list (  } -/* - * ":compiler[!] {name}" - */ +/// ":compiler[!] {name}"  void ex_compiler(exarg_T *eap)  {    char_u      *buf;    char_u      *old_cur_comp = NULL;    char_u      *p; +  size_t bufsize;    if (*eap->arg == NUL) { -    /* List all compiler scripts. */ -    do_cmdline_cmd("echo globpath(&rtp, 'compiler/*.vim')"); -    /* ) keep the indenter happy... */ +    // List all compiler scripts. +    do_cmdline_cmd("echo globpath(&rtp, 'compiler//.vim')"); +    // ) keep the indenter happy...    } else { -    buf = xmalloc(STRLEN(eap->arg) + 14); +    bufsize = STRLEN(eap->arg) + 14; +    buf = xmalloc(bufsize);      if (eap->forceit) { -      /* ":compiler! {name}" sets global options */ +      // ":compiler! {name}" sets global options        do_cmdline_cmd("command -nargs=* CompilerSet set <args>");      } else { -      /* ":compiler! {name}" sets local options. -       * To remain backwards compatible "current_compiler" is always -       * used.  A user's compiler plugin may set it, the distributed -       * plugin will then skip the settings.  Afterwards set -       * "b:current_compiler" and restore "current_compiler". -       * Explicitly prepend "g:" to make it work in a function. */ +      // ":compiler! {name}" sets local options. +      // To remain backwards compatible "current_compiler" is always +      // used.  A user's compiler plugin may set it, the distributed +      // plugin will then skip the settings.  Afterwards set +      // "b:current_compiler" and restore "current_compiler". +      // Explicitly prepend "g:" to make it work in a function.        old_cur_comp = get_var_value((char_u *)"g:current_compiler"); -      if (old_cur_comp != NULL) +      if (old_cur_comp != NULL) {          old_cur_comp = vim_strsave(old_cur_comp); +      }        do_cmdline_cmd("command -nargs=* CompilerSet setlocal <args>");      } -    do_unlet((char_u *)"g:current_compiler", TRUE); -    do_unlet((char_u *)"b:current_compiler", TRUE); +    do_unlet((char_u *)"g:current_compiler", true); +    do_unlet((char_u *)"b:current_compiler", true); -    sprintf((char *)buf, "compiler/%s.vim", eap->arg); -    if (source_runtime(buf, TRUE) == FAIL) +    snprintf((char *)buf, bufsize, "compiler/%s.vim", eap->arg); +    if (source_runtime(buf, true) == FAIL) {        EMSG2(_("E666: compiler not supported: %s"), eap->arg); +    }      xfree(buf);      do_cmdline_cmd(":delcommand CompilerSet"); -    /* Set "b:current_compiler" from "current_compiler". */ +    // Set "b:current_compiler" from "current_compiler".      p = get_var_value((char_u *)"g:current_compiler"); -    if (p != NULL) +    if (p != NULL) {        set_internal_string_var((char_u *)"b:current_compiler", p); +    } -    /* Restore "current_compiler" for ":compiler {name}". */ +    // Restore "current_compiler" for ":compiler {name}".      if (!eap->forceit) {        if (old_cur_comp != NULL) {          set_internal_string_var((char_u *)"g:current_compiler", -            old_cur_comp); +                                old_cur_comp);          xfree(old_cur_comp); -      } else -        do_unlet((char_u *)"g:current_compiler", TRUE); +      } else { +        do_unlet((char_u *)"g:current_compiler", true); +      }      }    }  } -/* - * ":runtime {name}" - */ +/// ":runtime {name}"  void ex_runtime(exarg_T *eap)  {    source_runtime(eap->arg, eap->forceit); @@ -2322,31 +2289,26 @@ void ex_runtime(exarg_T *eap)  static void source_callback(char_u *fname, void *cookie)  { -  (void)do_source(fname, FALSE, DOSO_NONE); +  (void)do_source(fname, false, DOSO_NONE);  } -/* - * Source the file "name" from all directories in 'runtimepath'. - * "name" can contain wildcards. - * When "all" is TRUE, source all files, otherwise only the first one. - * return FAIL when no file could be sourced, OK otherwise. - */ +/// Source the file "name" from all directories in 'runtimepath'. +/// "name" can contain wildcards. +/// When "all" is true, source all files, otherwise only the first one. +/// return FAIL when no file could be sourced, OK otherwise.  int source_runtime(char_u *name, int all)  {    return do_in_runtimepath(name, all, source_callback, NULL);  } -/* - * Find "name" in 'runtimepath'.  When found, invoke the callback function for - * it: callback(fname, "cookie") - * When "all" is TRUE repeat for all matches, otherwise only the first one is - * used. - * Returns OK when at least one match found, FAIL otherwise. - * - * If "name" is NULL calls callback for each entry in runtimepath. Cookie is - * passed by reference in this case, setting it to NULL indicates that callback - * has done its job. - */ +/// Find "name" in 'runtimepath'.  When found, invoke the callback function for +/// it: callback(fname, "cookie") +/// When "all" is true repeat for all matches, otherwise only the first one is +/// used. +/// Returns OK when at least one match found, FAIL otherwise. +/// If "name" is NULL calls callback for each entry in runtimepath. Cookie is +/// passed by reference in this case, setting it to NULL indicates that callback +/// has done its job.  int do_in_runtimepath(char_u *name, int all, DoInRuntimepathCB callback,                        void *cookie)  { @@ -2358,40 +2320,41 @@ int do_in_runtimepath(char_u *name, int all, DoInRuntimepathCB callback,    int num_files;    char_u      **files;    int i; -  int did_one = FALSE; +  bool did_one = false; -  /* Make a copy of 'runtimepath'.  Invoking the callback may change the -   * value. */ +  // Make a copy of 'runtimepath'.  Invoking the callback may change the +  // value.    rtp_copy = vim_strsave(p_rtp);    buf = xmallocz(MAXPATHL);    {      if (p_verbose > 1 && name != NULL) {        verbose_enter();        smsg(_("Searching for \"%s\" in \"%s\""), -          (char *)name, (char *)p_rtp); +           (char *)name, (char *)p_rtp);        verbose_leave();      } -    /* Loop over all entries in 'runtimepath'. */ +    // Loop over all entries in 'runtimepath'.      rtp = rtp_copy;      while (*rtp != NUL && (all || !did_one)) { -      /* Copy the path from 'runtimepath' to buf[]. */ +      // Copy the path from 'runtimepath' to buf[].        copy_option_part(&rtp, buf, MAXPATHL, ",");        if (name == NULL) { -        (*callback)(buf, (void *) &cookie); -        if (!did_one) +        (*callback)(buf, (void *)&cookie); +        if (!did_one) {            did_one = (cookie == NULL); +        }        } else if (STRLEN(buf) + STRLEN(name) + 2 < MAXPATHL) {          add_pathsep((char *)buf);          tail = buf + STRLEN(buf); -        /* Loop over all patterns in "name" */ +        // Loop over all patterns in "name"          np = name;          while (*np != NUL && (all || !did_one)) { -          /* Append the pattern from "name" to buf[]. */ +          // Append the pattern from "name" to buf[].            assert(MAXPATHL >= (tail - buf));            copy_option_part(&np, tail, (size_t)(MAXPATHL - (tail - buf)), -              "\t "); +                           "\t ");            if (p_verbose > 2) {              verbose_enter(); @@ -2399,14 +2362,15 @@ int do_in_runtimepath(char_u *name, int all, DoInRuntimepathCB callback,              verbose_leave();            } -          /* Expand wildcards, invoke the callback for each match. */ +          // Expand wildcards, invoke the callback for each match.            if (gen_expand_wildcards(1, &buf, &num_files, &files, -                  EW_FILE) == OK) { -            for (i = 0; i < num_files; ++i) { +                                   EW_FILE) == OK) { +            for (i = 0; i < num_files; i++) {                (*callback)(files[i], cookie); -              did_one = TRUE; -              if (!all) +              did_one = true; +              if (!all) {                  break; +              }              }              FreeWild(num_files, files);            } @@ -2426,17 +2390,13 @@ int do_in_runtimepath(char_u *name, int all, DoInRuntimepathCB callback,    return did_one ? OK : FAIL;  } -/* - * ":options" - */ +/// ":options"  void ex_options(exarg_T *eap)  {    cmd_source((char_u *)SYS_OPTWIN_FILE, NULL);  } -/* - * ":source {fname}" - */ +/// ":source {fname}"  void ex_source(exarg_T *eap)  {    cmd_source(eap->arg, eap); @@ -2444,50 +2404,41 @@ void ex_source(exarg_T *eap)  static void cmd_source(char_u *fname, exarg_T *eap)  { -  if (*fname == NUL) +  if (*fname == NUL) {      EMSG(_(e_argreq)); - -  else if (eap != NULL && eap->forceit) -    /* ":source!": read Normal mode commands -     * Need to execute the commands directly.  This is required at least -     * for: -     * - ":g" command busy -     * - after ":argdo", ":windo" or ":bufdo" -     * - another command follows -     * - inside a loop -     */ +  } else if (eap != NULL && eap->forceit) { +    // ":source!": read Normal mode commands +    // Need to execute the commands directly.  This is required at least +    // for: +    // - ":g" command busy +    // - after ":argdo", ":windo" or ":bufdo" +    // - another command follows +    // - inside a loop      openscript(fname, global_busy || listcmd_busy || eap->nextcmd != NULL -        || eap->cstack->cs_idx >= 0 -        ); - -  /* ":source" read ex commands */ -  else if (do_source(fname, FALSE, DOSO_NONE) == FAIL) +               || eap->cstack->cs_idx >= 0); +  } else if (do_source(fname, false, DOSO_NONE) == FAIL) { +    // ":source" read ex commands      EMSG2(_(e_notopen), fname); +  }  } -/* - * ":source" and associated commands. - */ - -/* - * Return the address holding the next breakpoint line for a source cookie. - */ +/// ":source" and associated commands. +/// +/// @param cookie +/// +/// @return the address holding the next breakpoint line for a source cookie.  linenr_T *source_breakpoint(void *cookie)  {    return &((struct source_cookie *)cookie)->breakpoint;  } -/* - * Return the address holding the debug tick for a source cookie. - */ +/// Return the address holding the debug tick for a source cookie.  int *source_dbg_tick(void *cookie)  {    return &((struct source_cookie *)cookie)->dbg_tick;  } -/* - * Return the nesting level for a source cookie. - */ +/// Return the nesting level for a source cookie.  int source_level(void *cookie)  {    return ((struct source_cookie *)cookie)->level; @@ -2520,19 +2471,16 @@ static FILE *fopen_noinh_readbin(char *filename)  } -/* - * do_source: Read the file "fname" and execute its lines as EX commands. - * - * This function may be called recursively! - * - * return FAIL if file could not be opened, OK otherwise - */ -int  -do_source ( -    char_u *fname, -    int check_other,                    /* check for .vimrc and _vimrc */ -    int is_vimrc                       /* DOSO_ value */ -) +/// Read the file "fname" and execute its lines as EX commands. +/// +/// This function may be called recursively! +/// +/// @param fname +/// @param check_other  check for .vimrc and _vimrc +/// @param is_vimrc     DOSO_ value +/// +/// @return FAIL if file could not be opened, OK otherwise +int do_source(char_u *fname, int check_other, int is_vimrc)  {    struct source_cookie cookie;    char_u                  *save_sourcing_name; @@ -2549,34 +2497,34 @@ do_source (    proftime_T wait_start;    p = expand_env_save(fname); -  if (p == NULL) +  if (p == NULL) {      return retval; +  }    fname_exp = (char_u *)fix_fname((char *)p);    xfree(p); -  if (fname_exp == NULL) +  if (fname_exp == NULL) {      return retval; +  }    if (os_isdir(fname_exp)) {      smsg(_("Cannot source a directory: \"%s\""), fname);      goto theend;    } -  /* Apply SourceCmd autocommands, they should get the file and source it. */ +  // Apply SourceCmd autocommands, they should get the file and source it.    if (has_autocmd(EVENT_SOURCECMD, fname_exp, NULL)        && apply_autocmds(EVENT_SOURCECMD, fname_exp, fname_exp, -          FALSE, curbuf)) { +                        false, curbuf)) {      retval = aborting() ? FAIL : OK;      goto theend;    } -  /* Apply SourcePre autocommands, they may get the file. */ -  apply_autocmds(EVENT_SOURCEPRE, fname_exp, fname_exp, FALSE, curbuf); +  // Apply SourcePre autocommands, they may get the file. +  apply_autocmds(EVENT_SOURCEPRE, fname_exp, fname_exp, false, curbuf);    cookie.fp = fopen_noinh_readbin((char *)fname_exp);    if (cookie.fp == NULL && check_other) { -    /* -     * Try again, replacing file name ".vimrc" by "_vimrc" or vice versa, -     * and ".exrc" by "_exrc" or vice versa. -     */ +    // Try again, replacing file name ".vimrc" by "_vimrc" or vice versa, +    // and ".exrc" by "_exrc" or vice versa.      p = path_tail(fname_exp);      if ((*p == '.' || *p == '_')          && (STRICMP(p + 1, "nvimrc") == 0 || STRICMP(p + 1, "exrc") == 0)) { @@ -2588,75 +2536,74 @@ do_source (    if (cookie.fp == NULL) {      if (p_verbose > 0) {        verbose_enter(); -      if (sourcing_name == NULL) +      if (sourcing_name == NULL) {          smsg(_("could not source \"%s\""), fname); -      else +      } else {          smsg(_("line %" PRId64 ": could not source \"%s\""), -            (int64_t)sourcing_lnum, fname); +             (int64_t)sourcing_lnum, fname); +      }        verbose_leave();      }      goto theend;    } -  /* -   * The file exists. -   * - In verbose mode, give a message. -   * - For a vimrc file, may want to call vimrc_found(). -   */ +  // The file exists. +  // - In verbose mode, give a message. +  // - For a vimrc file, may want to call vimrc_found().    if (p_verbose > 1) {      verbose_enter(); -    if (sourcing_name == NULL) +    if (sourcing_name == NULL) {        smsg(_("sourcing \"%s\""), fname); -    else +    } else {        smsg(_("line %" PRId64 ": sourcing \"%s\""), -          (int64_t)sourcing_lnum, fname); +           (int64_t)sourcing_lnum, fname); +    }      verbose_leave();    } -  if (is_vimrc == DOSO_VIMRC) +  if (is_vimrc == DOSO_VIMRC) {      vimrc_found(fname_exp, (char_u *)"MYVIMRC"); -  else if (is_vimrc == DOSO_GVIMRC) +  } else if (is_vimrc == DOSO_GVIMRC) {      vimrc_found(fname_exp, (char_u *)"MYGVIMRC"); +  }  #ifdef USE_CRNL -  /* If no automatic file format: Set default to CR-NL. */ -  if (*p_ffs == NUL) +  // If no automatic file format: Set default to CR-NL. +  if (*p_ffs == NUL) {      cookie.fileformat = EOL_DOS; -  else +  } else {      cookie.fileformat = EOL_UNKNOWN; -  cookie.error = FALSE; +  } +  cookie.error = false;  #endif    cookie.nextline = NULL; -  cookie.finished = FALSE; +  cookie.finished = false; -  /* -   * Check if this script has a breakpoint. -   */ -  cookie.breakpoint = dbg_find_breakpoint(TRUE, fname_exp, (linenr_T)0); +  // Check if this script has a breakpoint. +  cookie.breakpoint = dbg_find_breakpoint(true, fname_exp, (linenr_T)0);    cookie.fname = fname_exp;    cookie.dbg_tick = debug_tick;    cookie.level = ex_nesting_level; -  /* -   * Keep the sourcing name/lnum, for recursive calls. -   */ +  // Keep the sourcing name/lnum, for recursive calls.    save_sourcing_name = sourcing_name;    sourcing_name = fname_exp;    save_sourcing_lnum = sourcing_lnum;    sourcing_lnum = 0; -  cookie.conv.vc_type = CONV_NONE;              /* no conversion */ +  cookie.conv.vc_type = CONV_NONE;              // no conversion -  /* Read the first line so we can check for a UTF-8 BOM. */ +  // Read the first line so we can check for a UTF-8 BOM.    firstline = getsourceline(0, (void *)&cookie, 0);    if (firstline != NULL && STRLEN(firstline) >= 3 && firstline[0] == 0xef        && firstline[1] == 0xbb && firstline[2] == 0xbf) { -    /* Found BOM; setup conversion, skip over BOM and recode the line. */ +    // Found BOM; setup conversion, skip over BOM and recode the line.      convert_setup(&cookie.conv, (char_u *)"utf-8", p_enc);      p = string_convert(&cookie.conv, firstline + 3, NULL); -    if (p == NULL) +    if (p == NULL) {        p = vim_strsave(firstline + 3); +    }      xfree(firstline);      firstline = p;    } @@ -2671,22 +2618,21 @@ do_source (    }    const int l_do_profiling = do_profiling; -  if (l_do_profiling == PROF_YES) -    prof_child_enter(&wait_start);              /* entering a child now */ +  if (l_do_profiling == PROF_YES) { +    prof_child_enter(&wait_start);    // entering a child now +  } -  /* Don't use local function variables, if called from a function. -   * Also starts profiling timer for nested script. */ +  // Don't use local function variables, if called from a function. +  // Also starts profiling timer for nested script.    save_funccalp = save_funccal(); -  /* -   * Check if this script was sourced before to finds its SID. -   * If it's new, generate a new SID. -   */ +  // Check if this script was sourced before to finds its SID. +  // If it's new, generate a new SID.    save_current_SID = current_SID;    FileID file_id;    bool file_id_ok = os_fileid((char *)fname_exp, &file_id);    assert(script_items.ga_len >= 0); -  for (current_SID = script_items.ga_len; current_SID > 0; --current_SID) { +  for (current_SID = script_items.ga_len; current_SID > 0; current_SID--) {      si = &SCRIPT_ITEM(current_SID);      // Compare dev/ino when possible, it catches symbolic links.      // Also compare file names, the inode may change when the file was edited. @@ -2701,7 +2647,7 @@ do_source (      current_SID = ++last_current_SID;      ga_grow(&script_items, (int)(current_SID - script_items.ga_len));      while (script_items.ga_len < current_SID) { -      ++script_items.ga_len; +      script_items.ga_len++;        SCRIPT_ITEM(script_items.ga_len).sn_name = NULL;        SCRIPT_ITEM(script_items.ga_len).sn_prof_on = false;      } @@ -2715,53 +2661,53 @@ do_source (        si->file_id_valid = false;      } -    /* Allocate the local script variables to use for this script. */ +    // Allocate the local script variables to use for this script.      new_script_vars(current_SID);    }    if (l_do_profiling == PROF_YES) { -    int forceit; +    bool forceit; -    /* Check if we do profiling for this script. */ +    // Check if we do profiling for this script.      if (!si->sn_prof_on && has_profiling(true, si->sn_name, &forceit)) {        profile_init(si);        si->sn_pr_force = forceit;      }      if (si->sn_prof_on) { -      ++si->sn_pr_count; +      si->sn_pr_count++;        si->sn_pr_start = profile_start();        si->sn_pr_children = profile_zero();      }    } -  /* -   * Call do_cmdline, which will call getsourceline() to get the lines. -   */ +  // Call do_cmdline, which will call getsourceline() to get the lines.    do_cmdline(firstline, getsourceline, (void *)&cookie, -      DOCMD_VERBOSE|DOCMD_NOWAIT|DOCMD_REPEAT); +             DOCMD_VERBOSE|DOCMD_NOWAIT|DOCMD_REPEAT);    retval = OK;    if (l_do_profiling == PROF_YES) { -    /* Get "si" again, "script_items" may have been reallocated. */ +    // Get "si" again, "script_items" may have been reallocated.      si = &SCRIPT_ITEM(current_SID);      if (si->sn_prof_on) {        si->sn_pr_start = profile_end(si->sn_pr_start);        si->sn_pr_start = profile_sub_wait(wait_start, si->sn_pr_start);        si->sn_pr_total = profile_add(si->sn_pr_total, si->sn_pr_start);        si->sn_pr_self = profile_self(si->sn_pr_self, si->sn_pr_start, -          si->sn_pr_children); +                                    si->sn_pr_children);      }    } -  if (got_int) +  if (got_int) {      EMSG(_(e_interr)); +  }    sourcing_name = save_sourcing_name;    sourcing_lnum = save_sourcing_lnum;    if (p_verbose > 1) {      verbose_enter();      smsg(_("finished sourcing %s"), fname); -    if (sourcing_name != NULL) +    if (sourcing_name != NULL) {        smsg(_("continuing in %s"), sourcing_name); +    }      verbose_leave();    } @@ -2771,18 +2717,18 @@ do_source (      time_pop(rel_time);    } -  /* -   * After a "finish" in debug mode, need to break at first command of next -   * sourced file. -   */ +  // After a "finish" in debug mode, need to break at first command of next +  // sourced file.    if (save_debug_break_level > ex_nesting_level -      && debug_break_level == ex_nesting_level) -    ++debug_break_level; +      && debug_break_level == ex_nesting_level) { +    debug_break_level++; +  }    current_SID = save_current_SID;    restore_funccal(save_funccalp); -  if (l_do_profiling == PROF_YES) -    prof_child_exit(&wait_start);               /* leaving a child now */ +  if (l_do_profiling == PROF_YES) { +    prof_child_exit(&wait_start);    // leaving a child now +  }    fclose(cookie.fp);    xfree(cookie.nextline);    xfree(firstline); @@ -2794,26 +2740,23 @@ theend:  } -/* - * ":scriptnames" - */ +/// ":scriptnames"  void ex_scriptnames(exarg_T *eap)  { -  for (int i = 1; i <= script_items.ga_len && !got_int; ++i) +  for (int i = 1; i <= script_items.ga_len && !got_int; i++) {      if (SCRIPT_ITEM(i).sn_name != NULL) {        home_replace(NULL, SCRIPT_ITEM(i).sn_name, -          NameBuff, MAXPATHL, TRUE); +                   NameBuff, MAXPATHL, true);        smsg("%3d: %s", i, NameBuff);      } +  }  }  # if defined(BACKSLASH_IN_FILENAME) -/* - * Fix slashes in the list of script names for 'shellslash'. - */ +/// Fix slashes in the list of script names for 'shellslash'.  void scriptnames_slash_adjust(void)  { -  for (int i = 1; i <= script_items.ga_len; ++i) { +  for (int i = 1; i <= script_items.ga_len; i++) {      if (SCRIPT_ITEM(i).sn_name != NULL) {        slash_adjust(SCRIPT_ITEM(i).sn_name);      } @@ -2822,21 +2765,24 @@ void scriptnames_slash_adjust(void)  # endif -/* - * Get a pointer to a script name.  Used for ":verbose set". - */ +/// Get a pointer to a script name.  Used for ":verbose set".  char_u *get_scriptname(scid_T id)  { -  if (id == SID_MODELINE) +  if (id == SID_MODELINE) {      return (char_u *)_("modeline"); -  if (id == SID_CMDARG) +  } +  if (id == SID_CMDARG) {      return (char_u *)_("--cmd argument"); -  if (id == SID_CARG) +  } +  if (id == SID_CARG) {      return (char_u *)_("-c argument"); -  if (id == SID_ENV) +  } +  if (id == SID_ENV) {      return (char_u *)_("environment variable"); -  if (id == SID_ERROR) +  } +  if (id == SID_ERROR) {      return (char_u *)_("error handler"); +  }    return SCRIPT_ITEM(id).sn_name;  } @@ -2849,51 +2795,48 @@ void free_scriptnames(void)  # endif -/* - * Get one full line from a sourced file. - * 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. - */ +/// Get one full line from a sourced file. +/// 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.  char_u *getsourceline(int c, void *cookie, int indent)  {    struct source_cookie *sp = (struct source_cookie *)cookie; -  char_u              *line; -  char_u              *p; +  char_u *line; +  char_u *p; -  /* If breakpoints have been added/deleted need to check for it. */ +  // If breakpoints have been added/deleted need to check for it.    if (sp->dbg_tick < debug_tick) { -    sp->breakpoint = dbg_find_breakpoint(TRUE, sp->fname, sourcing_lnum); +    sp->breakpoint = dbg_find_breakpoint(true, sp->fname, sourcing_lnum);      sp->dbg_tick = debug_tick;    } -  if (do_profiling == PROF_YES) +  if (do_profiling == PROF_YES) {      script_line_end(); -  /* -   * Get current line.  If there is a read-ahead line, use it, otherwise get -   * one now. -   */ -  if (sp->finished) +  } +  // Get current line.  If there is a read-ahead line, use it, otherwise get +  // one now. +  if (sp->finished) {      line = NULL; -  else if (sp->nextline == NULL) +  } else if (sp->nextline == NULL) {      line = get_one_sourceline(sp); -  else { +  } else {      line = sp->nextline;      sp->nextline = NULL; -    ++sourcing_lnum; +    sourcing_lnum++;    } -  if (line != NULL && do_profiling == PROF_YES) +  if (line != NULL && do_profiling == PROF_YES) {      script_line_start(); +  } -  /* Only concatenate lines starting with a \ when 'cpoptions' doesn't -   * contain the 'C' flag. */ +  // Only concatenate lines starting with a \ when 'cpoptions' doesn't +  // contain the 'C' flag.    if (line != NULL && (vim_strchr(p_cpo, CPO_CONCAT) == NULL)) { -    /* compensate for the one line read-ahead */ -    --sourcing_lnum; +    // compensate for the one line read-ahead +    sourcing_lnum--; -    /* Get the next line and concatenate it when it starts with a -     * backslash. We always need to read the next line, keep it in -     * sp->nextline. */ +    // Get the next line and concatenate it when it starts with a +    // backslash. We always need to read the next line, keep it in +    // sp->nextline.      sp->nextline = get_one_sourceline(sp);      if (sp->nextline != NULL && *(p = skipwhite(sp->nextline)) == '\\') {        garray_T ga; @@ -2904,13 +2847,15 @@ char_u *getsourceline(int c, void *cookie, int indent)        for (;; ) {          xfree(sp->nextline);          sp->nextline = get_one_sourceline(sp); -        if (sp->nextline == NULL) +        if (sp->nextline == NULL) {            break; +        }          p = skipwhite(sp->nextline); -        if (*p != '\\') +        if (*p != '\\') {            break; -        /* Adjust the growsize to the current length to speed up -         * concatenating many lines. */ +        } +        // Adjust the growsize to the current length to speed up +        // concatenating many lines.          if (ga.ga_len > 400) {            ga_set_growsize(&ga, (ga.ga_len > 8000) ? 8000 : ga.ga_len);          } @@ -2925,7 +2870,7 @@ char_u *getsourceline(int c, void *cookie, int indent)    if (line != NULL && sp->conv.vc_type != CONV_NONE) {      char_u  *s; -    /* Convert the encoding of the script line. */ +    // Convert the encoding of the script line.      s = string_convert(&sp->conv, line, NULL);      if (s != NULL) {        xfree(line); @@ -2933,11 +2878,11 @@ char_u *getsourceline(int c, void *cookie, int indent)      }    } -  /* Did we encounter a breakpoint? */ +  // Did we encounter a breakpoint?    if (sp->breakpoint != 0 && sp->breakpoint <= sourcing_lnum) {      dbg_breakpoint(sp->fname, sourcing_lnum); -    /* Find next breakpoint. */ -    sp->breakpoint = dbg_find_breakpoint(TRUE, sp->fname, sourcing_lnum); +    // Find next breakpoint. +    sp->breakpoint = dbg_find_breakpoint(true, sp->fname, sourcing_lnum);      sp->dbg_tick = debug_tick;    } @@ -2951,175 +2896,170 @@ static char_u *get_one_sourceline(struct source_cookie *sp)    int c;    char_u              *buf;  #ifdef USE_CRNL -  int has_cr;                           /* CR-LF found */ +  int has_cr;                           // CR-LF found  #endif -  int have_read = FALSE; +  bool have_read = false; -  /* use a growarray to store the sourced line */ +  // use a growarray to store the sourced line    ga_init(&ga, 1, 250); -  /* -   * Loop until there is a finished line (or end-of-file). -   */ +  // Loop until there is a finished line (or end-of-file).    sourcing_lnum++;    for (;; ) { -    /* make room to read at least 120 (more) characters */ +    // make room to read at least 120 (more) characters      ga_grow(&ga, 120);      buf = (char_u *)ga.ga_data;      if (fgets((char *)buf + ga.ga_len, ga.ga_maxlen - ga.ga_len, -            sp->fp) == NULL) +              sp->fp) == NULL) {        break; +    }      len = ga.ga_len + (int)STRLEN(buf + ga.ga_len);  #ifdef USE_CRNL -    /* Ignore a trailing CTRL-Z, when in Dos mode.	Only recognize the -     * CTRL-Z by its own, or after a NL. */ -    if (       (len == 1 || (len >= 2 && buf[len - 2] == '\n')) -               && sp->fileformat == EOL_DOS -               && buf[len - 1] == Ctrl_Z) { +    // Ignore a trailing CTRL-Z, when in Dos mode. Only recognize the +    // CTRL-Z by its own, or after a NL. +    if ((len == 1 || (len >= 2 && buf[len - 2] == '\n')) +        && sp->fileformat == EOL_DOS +        && buf[len - 1] == Ctrl_Z) {        buf[len - 1] = NUL;        break;      }  #endif -    have_read = TRUE; +    have_read = true;      ga.ga_len = len; -    /* If the line was longer than the buffer, read more. */ -    if (ga.ga_maxlen - ga.ga_len == 1 && buf[len - 1] != '\n') +    // If the line was longer than the buffer, read more. +    if (ga.ga_maxlen - ga.ga_len == 1 && buf[len - 1] != '\n') {        continue; +    } -    if (len >= 1 && buf[len - 1] == '\n') {     /* remove trailing NL */ +    if (len >= 1 && buf[len - 1] == '\n') {     // remove trailing NL  #ifdef USE_CRNL        has_cr = (len >= 2 && buf[len - 2] == '\r');        if (sp->fileformat == EOL_UNKNOWN) { -        if (has_cr) +        if (has_cr) {            sp->fileformat = EOL_DOS; -        else +        } else {            sp->fileformat = EOL_UNIX; +        }        }        if (sp->fileformat == EOL_DOS) { -        if (has_cr) {               /* replace trailing CR */ +        if (has_cr) {               // replace trailing CR            buf[len - 2] = '\n'; -          --len; -          --ga.ga_len; -        } else {          /* lines like ":map xx yy^M" will have failed */ +          len--; +          ga.ga_len--; +        } else {          // lines like ":map xx yy^M" will have failed            if (!sp->error) {              msg_source(hl_attr(HLF_W));              EMSG(_("W15: Warning: Wrong line separator, ^M may be missing"));            } -          sp->error = TRUE; +          sp->error = true;            sp->fileformat = EOL_UNIX;          }        }  #endif -      /* The '\n' is escaped if there is an odd number of ^V's just -       * before it, first set "c" just before the 'V's and then check -       * len&c parities (is faster than ((len-c)%2 == 0)) -- Acevedo */ -      for (c = len - 2; c >= 0 && buf[c] == Ctrl_V; c--) -        ; -      if ((len & 1) != (c & 1)) {       /* escaped NL, read more */ +      // The '\n' is escaped if there is an odd number of ^V's just +      // before it, first set "c" just before the 'V's and then check +      // len&c parities (is faster than ((len-c)%2 == 0)) -- Acevedo +      for (c = len - 2; c >= 0 && buf[c] == Ctrl_V; c--) {} +      if ((len & 1) != (c & 1)) {       // escaped NL, read more          sourcing_lnum++;          continue;        } -      buf[len - 1] = NUL;               /* remove the NL */ +      buf[len - 1] = NUL;               // remove the NL      } -    /* -     * Check for ^C here now and then, so recursive :so can be broken. -     */ +    // Check for ^C here now and then, so recursive :so can be broken.      line_breakcheck();      break;    } -  if (have_read) +  if (have_read) {      return (char_u *)ga.ga_data; +  }    xfree(ga.ga_data);    return NULL;  } -/* - * Called when starting to read a script line. - * "sourcing_lnum" must be correct! - * When skipping lines it may not actually be executed, but we won't find out - * until later and we need to store the time now. - */ +/// Called when starting to read a script line. +/// "sourcing_lnum" must be correct! +/// When skipping lines it may not actually be executed, but we won't find out +/// until later and we need to store the time now.  void script_line_start(void)  {    scriptitem_T    *si;    sn_prl_T        *pp; -  if (current_SID <= 0 || current_SID > script_items.ga_len) +  if (current_SID <= 0 || current_SID > script_items.ga_len) {      return; +  }    si = &SCRIPT_ITEM(current_SID);    if (si->sn_prof_on && sourcing_lnum >= 1) { -    /* Grow the array before starting the timer, so that the time spent -     * here isn't counted. */ +    // Grow the array before starting the timer, so that the time spent +    // here isn't counted.      ga_grow(&si->sn_prl_ga, (int)(sourcing_lnum - si->sn_prl_ga.ga_len));      si->sn_prl_idx = sourcing_lnum - 1;      while (si->sn_prl_ga.ga_len <= si->sn_prl_idx             && si->sn_prl_ga.ga_len < si->sn_prl_ga.ga_maxlen) { -      /* Zero counters for a line that was not used before. */ +      // Zero counters for a line that was not used before.        pp = &PRL_ITEM(si, si->sn_prl_ga.ga_len);        pp->snp_count = 0;        pp->sn_prl_total = profile_zero();        pp->sn_prl_self = profile_zero(); -      ++si->sn_prl_ga.ga_len; +      si->sn_prl_ga.ga_len++;      } -    si->sn_prl_execed = FALSE; +    si->sn_prl_execed = false;      si->sn_prl_start = profile_start();      si->sn_prl_children = profile_zero();      si->sn_prl_wait = profile_get_wait();    }  } -/* - * Called when actually executing a function line. - */ +/// Called when actually executing a function line.  void script_line_exec(void)  {    scriptitem_T    *si; -  if (current_SID <= 0 || current_SID > script_items.ga_len) +  if (current_SID <= 0 || current_SID > script_items.ga_len) {      return; +  }    si = &SCRIPT_ITEM(current_SID); -  if (si->sn_prof_on && si->sn_prl_idx >= 0) -    si->sn_prl_execed = TRUE; +  if (si->sn_prof_on && si->sn_prl_idx >= 0) { +    si->sn_prl_execed = true; +  }  } -/* - * Called when done with a function line. - */ +/// Called when done with a function line.  void script_line_end(void)  {    scriptitem_T    *si;    sn_prl_T        *pp; -  if (current_SID <= 0 || current_SID > script_items.ga_len) +  if (current_SID <= 0 || current_SID > script_items.ga_len) {      return; +  }    si = &SCRIPT_ITEM(current_SID);    if (si->sn_prof_on && si->sn_prl_idx >= 0        && si->sn_prl_idx < si->sn_prl_ga.ga_len) {      if (si->sn_prl_execed) {        pp = &PRL_ITEM(si, si->sn_prl_idx); -      ++pp->snp_count; +      pp->snp_count++;        si->sn_prl_start = profile_end(si->sn_prl_start);        si->sn_prl_start = profile_sub_wait(si->sn_prl_wait, si->sn_prl_start);        pp->sn_prl_total = profile_add(pp->sn_prl_total, si->sn_prl_start);        pp->sn_prl_self = profile_self(pp->sn_prl_self, si->sn_prl_start, -          si->sn_prl_children); +                                     si->sn_prl_children);      }      si->sn_prl_idx = -1;    }  } -/* - * ":scriptencoding": Set encoding conversion for a sourced script. - * Without the multi-byte feature it's simply ignored. - */ +/// ":scriptencoding": Set encoding conversion for a sourced script. +/// Without the multi-byte feature it's simply ignored.  void ex_scriptencoding(exarg_T *eap)  {    struct source_cookie        *sp; @@ -3132,84 +3072,80 @@ void ex_scriptencoding(exarg_T *eap)    if (*eap->arg != NUL) {      name = enc_canonize(eap->arg); -  } else +  } else {      name = eap->arg; +  } -  /* Setup for conversion from the specified encoding to 'encoding'. */ +  // Setup for conversion from the specified encoding to 'encoding'.    sp = (struct source_cookie *)getline_cookie(eap->getline, eap->cookie);    convert_setup(&sp->conv, name, p_enc); -  if (name != eap->arg) +  if (name != eap->arg) {      xfree(name); +  }  } -/* - * ":finish": Mark a sourced file as finished. - */ +/// ":finish": Mark a sourced file as finished.  void ex_finish(exarg_T *eap)  { -  if (getline_equal(eap->getline, eap->cookie, getsourceline)) -    do_finish(eap, FALSE); -  else +  if (getline_equal(eap->getline, eap->cookie, getsourceline)) { +    do_finish(eap, false); +  } else {      EMSG(_("E168: :finish used outside of a sourced file")); +  }  } -/* - * Mark a sourced file as finished.  Possibly makes the ":finish" pending. - * Also called for a pending finish at the ":endtry" or after returning from - * an extra do_cmdline().  "reanimate" is used in the latter case. - */ +/// Mark a sourced file as finished.  Possibly makes the ":finish" pending. +/// Also called for a pending finish at the ":endtry" or after returning from +/// an extra do_cmdline().  "reanimate" is used in the latter case.  void do_finish(exarg_T *eap, int reanimate)  {    int idx; -  if (reanimate) +  if (reanimate) {      ((struct source_cookie *)getline_cookie(eap->getline, -         eap->cookie))->finished = FALSE; - -  /* -   * Cleanup (and inactivate) conditionals, but stop when a try conditional -   * not in its finally clause (which then is to be executed next) is found. -   * In this case, make the ":finish" pending for execution at the ":endtry". -   * Otherwise, finish normally. -   */ -  idx = cleanup_conditionals(eap->cstack, 0, TRUE); +                                            eap->cookie))->finished = false; +  } + +  // Cleanup (and inactivate) conditionals, but stop when a try conditional +  // not in its finally clause (which then is to be executed next) is found. +  // In this case, make the ":finish" pending for execution at the ":endtry". +  // Otherwise, finish normally. +  idx = cleanup_conditionals(eap->cstack, 0, true);    if (idx >= 0) {      eap->cstack->cs_pending[idx] = CSTP_FINISH;      report_make_pending(CSTP_FINISH, NULL); -  } else +  } else {      ((struct source_cookie *)getline_cookie(eap->getline, -         eap->cookie))->finished = TRUE; +                                            eap->cookie))->finished = true; +  }  } -/* - * Return TRUE when a sourced file had the ":finish" command: Don't give error - * message for missing ":endif". - * Return FALSE when not sourcing a file. - */ -int source_finished(LineGetter fgetline, void *cookie) +/// Return true when a sourced file had the ":finish" command: Don't give error +/// message for missing ":endif". +/// Return false when not sourcing a file. +bool source_finished(LineGetter fgetline, void *cookie)  {    return getline_equal(fgetline, cookie, getsourceline)           && ((struct source_cookie *)getline_cookie( -                 fgetline, cookie))->finished; +             fgetline, cookie))->finished;  } -/* - * ":checktime [buffer]" - */ +/// ":checktime [buffer]"  void ex_checktime(exarg_T *eap)  {    buf_T       *buf;    int save_no_check_timestamps = no_check_timestamps;    no_check_timestamps = 0; -  if (eap->addr_count == 0)     /* default is all buffers */ -    check_timestamps(FALSE); -  else { +  if (eap->addr_count == 0) {    // default is all buffers +    check_timestamps(false); +  } else {      buf = buflist_findnr((int)eap->line2); -    if (buf != NULL)            /* cannot happen? */ -      (void)buf_check_timestamp(buf, FALSE); +    if (buf != NULL) {           // cannot happen? +      (void)buf_check_timestamp(buf, false); +    }    }    no_check_timestamps = save_no_check_timestamps;  } @@ -3228,10 +3164,8 @@ static char *get_locale_val(int what) -/* - * Obtain the current messages language.  Used to set the default for - * 'helplang'.  May return NULL or an empty string. - */ +/// Obtain the current messages language.  Used to set the default for +/// 'helplang'.  May return NULL or an empty string.  char *get_mess_lang(void)  {    char *p; @@ -3240,10 +3174,10 @@ char *get_mess_lang(void)  #  if defined(LC_MESSAGES)    p = get_locale_val(LC_MESSAGES);  #  else -  /* This is necessary for Win32, where LC_MESSAGES is not defined and $LANG -   * may be set to the LCID number.  LC_COLLATE is the best guess, LC_TIME -   * and LC_MONETARY may be set differently for a Japanese working in the -   * US. */ +  // This is necessary for Win32, where LC_MESSAGES is not defined and $LANG +  // may be set to the LCID number.  LC_COLLATE is the best guess, LC_TIME +  // and LC_MONETARY may be set differently for a Japanese working in the +  // US.    p = get_locale_val(LC_COLLATE);  #  endif  # else @@ -3258,11 +3192,9 @@ char *get_mess_lang(void)    return p;  } -/* Complicated #if; matches with where get_mess_env() is used below. */ +// Complicated #if; matches with where get_mess_env() is used below.  #ifdef HAVE_WORKING_LIBINTL -/* - * Get the language used for messages from the environment. - */ +/// Get the language used for messages from the environment.  static char_u *get_mess_env(void)  {    char_u      *p; @@ -3273,7 +3205,7 @@ static char_u *get_mess_env(void)      if (p == NULL) {        p = (char_u *)os_getenv("LANG");        if (p != NULL && ascii_isdigit(*p)) { -        p = NULL;                       /* ignore something like "1043" */ +        p = NULL;                       // ignore something like "1043"        }  # ifdef HAVE_GET_LOCALE_VAL        if (p == NULL) { @@ -3288,10 +3220,8 @@ static char_u *get_mess_env(void)  #endif -/* - * Set the "v:lang" variable according to the current locale setting. - * Also do "v:lc_time"and "v:ctype". - */ +/// Set the "v:lang" variable according to the current locale setting. +/// Also do "v:lc_time"and "v:ctype".  void set_lang_var(void)  {    const char *loc; @@ -3304,10 +3234,10 @@ void set_lang_var(void)  # endif    set_vim_var_string(VV_CTYPE, loc, -1); -  /* When LC_MESSAGES isn't defined use the value from $LC_MESSAGES, fall -   * back to LC_CTYPE if it's empty. */ +  // When LC_MESSAGES isn't defined use the value from $LC_MESSAGES, fall +  // back to LC_CTYPE if it's empty.  # ifdef HAVE_WORKING_LIBINTL -  loc = (char *) get_mess_env(); +  loc = (char *)get_mess_env();  # elif defined(LC_MESSAGES)    loc = get_locale_val(LC_MESSAGES);  # else @@ -3323,9 +3253,11 @@ void set_lang_var(void)  }  #ifdef HAVE_WORKING_LIBINTL -/* - * ":language":  Set the language (locale). - */ +/// +/// ":language":  Set the language (locale). +/// +/// @param eap +///  void ex_language(exarg_T *eap)  {    char        *loc; @@ -3341,9 +3273,9 @@ void ex_language(exarg_T *eap)    name = eap->arg; -  /* Check for "messages {name}", "ctype {name}" or "time {name}" argument. -   * Allow abbreviation, but require at least 3 characters to avoid -   * confusion with a two letter language name "me" or "ct". */ +  // Check for "messages {name}", "ctype {name}" or "time {name}" argument. +  // Allow abbreviation, but require at least 3 characters to avoid +  // confusion with a two letter language name "me" or "ct".    p = skiptowhite(eap->arg);    if ((*p == NUL || ascii_iswhite(*p)) && p - eap->arg >= 3) {      if (STRNICMP(eap->arg, "messages", p - eap->arg) == 0) { @@ -3363,47 +3295,52 @@ void ex_language(exarg_T *eap)    if (*name == NUL) {  #ifdef HAVE_WORKING_LIBINTL -    if (what == VIM_LC_MESSAGES) +    if (what == VIM_LC_MESSAGES) {        p = get_mess_env(); -    else +    } else {  #endif -    p = (char_u *)setlocale(what, NULL); -    if (p == NULL || *p == NUL) +      p = (char_u *)setlocale(what, NULL); +#ifdef HAVE_WORKING_LIBINTL +    } +#endif +    if (p == NULL || *p == NUL) {        p = (char_u *)"Unknown"; +    }      smsg(_("Current %slanguage: \"%s\""), whatstr, p);    } else {  #ifndef LC_MESSAGES -    if (what == VIM_LC_MESSAGES) +    if (what == VIM_LC_MESSAGES) {        loc = ""; -    else +    } else {  #endif -    {        loc = setlocale(what, (char *)name);  #ifdef LC_NUMERIC -      /* Make sure strtod() uses a decimal point, not a comma. */ +      // Make sure strtod() uses a decimal point, not a comma.        setlocale(LC_NUMERIC, "C");  #endif +#ifndef LC_MESSAGES      } -    if (loc == NULL) +#endif +    if (loc == NULL) {        EMSG2(_("E197: Cannot set language to \"%s\""), name); -    else { +    } else {  #ifdef HAVE_NL_MSG_CAT_CNTR -      /* Need to do this for GNU gettext, otherwise cached translations -       * will be used again. */ +      // Need to do this for GNU gettext, otherwise cached translations +      // will be used again.        extern int _nl_msg_cat_cntr; -      ++_nl_msg_cat_cntr; +      _nl_msg_cat_cntr++;  #endif -      /* Reset $LC_ALL, otherwise it would overrule everything. */ +      // Reset $LC_ALL, otherwise it would overrule everything.        vim_setenv("LC_ALL", "");        if (what != LC_TIME) { -        /* Tell gettext() what to translate to.  It apparently doesn't -         * use the currently effective locale. */ +        // Tell gettext() what to translate to.  It apparently doesn't +        // use the currently effective locale.          if (what == LC_ALL) {            vim_setenv("LANG", (char *)name); -          /* Clear $LANGUAGE because GNU gettext uses it. */ +          // Clear $LANGUAGE because GNU gettext uses it.            vim_setenv("LANGUAGE", "");          }          if (what != LC_CTYPE) { @@ -3412,7 +3349,7 @@ void ex_language(exarg_T *eap)          }        } -      /* Set v:lang, v:lc_time and v:ctype to the final result. */ +      // Set v:lang, v:lc_time and v:ctype to the final result.        set_lang_var();        maketitle();      } @@ -3420,43 +3357,43 @@ void ex_language(exarg_T *eap)  } -static char_u   **locales = NULL;       /* Array of all available locales */ -static int did_init_locales = FALSE; +static char_u **locales = NULL;       // Array of all available locales +static bool did_init_locales = false; -/* - * Lazy initialization of all available locales. - */ +/// Lazy initialization of all available locales.  static void init_locales(void)  {    if (!did_init_locales) { -    did_init_locales = TRUE; +    did_init_locales = true;      locales = find_locales();    }  } -/* Return an array of strings for all available locales + NULL for the - * last element.  Return NULL in case of error. */ +// Return an array of strings for all available locales + NULL for the +/// last element.  Return NULL in case of error.  static char_u **find_locales(void)  {    garray_T locales_ga;    char_u      *loc; +  char *saveptr = NULL; -  /* Find all available locales by running command "locale -a".  If this -   * doesn't work we won't have completion. */ +  // Find all available locales by running command "locale -a".  If this +  // doesn't work we won't have completion.    char_u *locale_a = get_cmd_output((char_u *)"locale -a", NULL,                                      kShellOptSilent, NULL); -  if (locale_a == NULL) +  if (locale_a == NULL) {      return NULL; +  }    ga_init(&locales_ga, sizeof(char_u *), 20); -  /* Transform locale_a string where each locale is separated by "\n" -   * into an array of locale strings. */ -  loc = (char_u *)strtok((char *)locale_a, "\n"); +  // Transform locale_a string where each locale is separated by "\n" +  // into an array of locale strings. +  loc = (char_u *)os_strtok_r((char *)locale_a, "\n", &saveptr);    while (loc != NULL) {      loc = vim_strsave(loc);      GA_APPEND(char_u *, &locales_ga, loc); -    loc = (char_u *)strtok(NULL, "\n"); +    loc = (char_u *)os_strtok_r(NULL, "\n", &saveptr);    }    xfree(locale_a);    // Guarantee that .ga_data is NULL terminated @@ -3470,8 +3407,9 @@ void free_locales(void)  {    int i;    if (locales != NULL) { -    for (i = 0; locales[i] != NULL; i++) +    for (i = 0; locales[i] != NULL; i++) {        xfree(locales[i]); +    }      xfree(locales);      locales = NULL;    } @@ -3479,33 +3417,34 @@ void free_locales(void)  #  endif -/* - * Function given to ExpandGeneric() to obtain the possible arguments of the - * ":language" command. - */ +/// Function given to ExpandGeneric() to obtain the possible arguments of the +/// ":language" command.  char_u *get_lang_arg(expand_T *xp, int idx)  { -  if (idx == 0) +  if (idx == 0) {      return (char_u *)"messages"; -  if (idx == 1) +  } +  if (idx == 1) {      return (char_u *)"ctype"; -  if (idx == 2) +  } +  if (idx == 2) {      return (char_u *)"time"; +  }    init_locales(); -  if (locales == NULL) +  if (locales == NULL) {      return NULL; +  }    return locales[idx - 3];  } -/* - * Function given to ExpandGeneric() to obtain the available locales. - */ +/// Function given to ExpandGeneric() to obtain the available locales.  char_u *get_locales(expand_T *xp, int idx)  {    init_locales(); -  if (locales == NULL) +  if (locales == NULL) {      return NULL; +  }    return locales[idx];  } @@ -3552,79 +3491,64 @@ static void script_host_do_range(char *name, exarg_T *eap)    (void)eval_call_provider(name, "do_range", args);  } -/* - * ":drop" - * Opens the first argument in a window.  When there are two or more arguments - * the argument list is redefined. - */ +/// ":drop" +/// Opens the first argument in a window.  When there are two or more arguments +/// the argument list is redefined.  void ex_drop(exarg_T   *eap)  { -    int                split = FALSE; -    buf_T      *buf; - -    /* -     * Check if the first argument is already being edited in a window.  If -     * so, jump to that window. -     * We would actually need to check all arguments, but that's complicated -     * and mostly only one file is dropped. -     * This also ignores wildcards, since it is very unlikely the user is -     * editing a file name with a wildcard character. -     */ -    do_arglist(eap->arg, AL_SET, 0); - -    /* -     * Expanding wildcards may result in an empty argument list.  E.g. when -     * editing "foo.pyc" and ".pyc" is in 'wildignore'.  Assume that we -     * already did an error message for this. -     */ -    if (ARGCOUNT == 0) -       return; - -    if (cmdmod.tab) -    { -       /* ":tab drop file ...": open a tab for each argument that isn't -        * edited in a window yet.  It's like ":tab all" but without closing -        * windows or tabs. */ -       ex_all(eap); -    } -    else -    { -       /* ":drop file ...": Edit the first argument.  Jump to an existing -        * window if possible, edit in current window if the current buffer -        * can be abandoned, otherwise open a new window. */ -       buf = buflist_findnr(ARGLIST[0].ae_fnum); - -       FOR_ALL_TAB_WINDOWS(tp, wp) -       { -           if (wp->w_buffer == buf) -           { -               goto_tabpage_win(tp, wp); -               curwin->w_arg_idx = 0; -               return; -           } -       } - -       /* -        * Check whether the current buffer is changed. If so, we will need -        * to split the current window or data could be lost. -        * Skip the check if the 'hidden' option is set, as in this case the -        * buffer won't be lost. -        */ -       if (!P_HID(curbuf)) -       { -           ++emsg_off; -           split = check_changed(curbuf, CCGD_AW | CCGD_EXCMD); -           --emsg_off; -       } - -       /* Fake a ":sfirst" or ":first" command edit the first argument. */ -       if (split) -       { -           eap->cmdidx = CMD_sfirst; -           eap->cmd[0] = 's'; -       } -       else -           eap->cmdidx = CMD_first; -       ex_rewind(eap); +  bool split = false; +  buf_T *buf; + +  // Check if the first argument is already being edited in a window.  If +  // so, jump to that window. +  // We would actually need to check all arguments, but that's complicated +  // and mostly only one file is dropped. +  // This also ignores wildcards, since it is very unlikely the user is +  // editing a file name with a wildcard character. +  do_arglist(eap->arg, AL_SET, 0); + +  // Expanding wildcards may result in an empty argument list.  E.g. when +  // editing "foo.pyc" and ".pyc" is in 'wildignore'.  Assume that we +  // already did an error message for this. +  if (ARGCOUNT == 0) { +    return; +  } + +  if (cmdmod.tab) { +    // ":tab drop file ...": open a tab for each argument that isn't +    // edited in a window yet.  It's like ":tab all" but without closing +    // windows or tabs. +    ex_all(eap); +  } else { +    // ":drop file ...": Edit the first argument.  Jump to an existing +    // window if possible, edit in current window if the current buffer +    // can be abandoned, otherwise open a new window. +    buf = buflist_findnr(ARGLIST[0].ae_fnum); + +    FOR_ALL_TAB_WINDOWS(tp, wp) { +      if (wp->w_buffer == buf) { +        goto_tabpage_win(tp, wp); +        curwin->w_arg_idx = 0; +        return; +      } +    } + +    // Check whether the current buffer is changed. If so, we will need +    // to split the current window or data could be lost. +    // Skip the check if the 'hidden' option is set, as in this case the +    // buffer won't be lost. +    if (!P_HID(curbuf)) { +      emsg_off++; +      split = check_changed(curbuf, CCGD_AW | CCGD_EXCMD); +      emsg_off--;      } + +    // Fake a ":sfirst" or ":first" command edit the first argument. +    if (split) { +      eap->cmdidx = CMD_sfirst; +      eap->cmd[0] = 's'; +    } else { +      eap->cmdidx = CMD_first; +    } +  }  } | 
