aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authordundargoc <33953936+dundargoc@users.noreply.github.com>2021-10-02 16:59:41 +0200
committerGitHub <noreply@github.com>2021-10-02 07:59:41 -0700
commit9c268263b1792d00b3ffdfd7495af2575862656e (patch)
tree39153ef6da8b4f464c1a14602d04d99579bbd33f /src
parent898f91f0f3cedb224cde1c5b6840abea3e767892 (diff)
downloadrneovim-9c268263b1792d00b3ffdfd7495af2575862656e.tar.gz
rneovim-9c268263b1792d00b3ffdfd7495af2575862656e.tar.bz2
rneovim-9c268263b1792d00b3ffdfd7495af2575862656e.zip
refactor: format with uncrustify #15842
* refactor: format with uncrustify * refactor: convert function comments to doxygen
Diffstat (limited to 'src')
-rw-r--r--src/nvim/decoration.c10
-rw-r--r--src/nvim/if_cscope.c445
-rw-r--r--src/nvim/lua/executor.c2
-rw-r--r--src/nvim/runtime.c16
-rw-r--r--src/nvim/screen.c4
-rw-r--r--src/nvim/strings.c916
-rw-r--r--src/nvim/terminal.c666
-rw-r--r--src/uncrustify.cfg2
8 files changed, 1121 insertions, 940 deletions
diff --git a/src/nvim/decoration.c b/src/nvim/decoration.c
index 561be9968a..4e80528c74 100644
--- a/src/nvim/decoration.c
+++ b/src/nvim/decoration.c
@@ -421,11 +421,11 @@ int decor_virtual_lines(win_T *wp, linenr_T lnum)
return 0;
}
if (buf->b_virt_line_pos < 0) {
- mtpos_t pos = marktree_lookup(buf->b_marktree, buf->b_virt_line_mark, NULL);
- if (pos.row < 0) {
- buf->b_virt_line_mark = 0;
- }
- buf->b_virt_line_pos = pos.row + (buf->b_virt_line_above ? 0 : 1);
+ mtpos_t pos = marktree_lookup(buf->b_marktree, buf->b_virt_line_mark, NULL);
+ if (pos.row < 0) {
+ buf->b_virt_line_mark = 0;
+ }
+ buf->b_virt_line_pos = pos.row + (buf->b_virt_line_above ? 0 : 1);
}
return (lnum-1 == buf->b_virt_line_pos) ? (int)kv_size(buf->b_virt_lines) : 0;
diff --git a/src/nvim/if_cscope.c b/src/nvim/if_cscope.c
index 31615e744a..0bccaf1a35 100644
--- a/src/nvim/if_cscope.c
+++ b/src/nvim/if_cscope.c
@@ -9,31 +9,29 @@
* might be a few lines of code that look similar to what Nvi has.
*/
-#include <stdbool.h>
-
#include <assert.h>
#include <errno.h>
-#include <inttypes.h>
#include <fcntl.h>
+#include <inttypes.h>
+#include <stdbool.h>
+#include <sys/stat.h>
+#include <sys/types.h>
-#include "nvim/buffer.h"
#include "nvim/ascii.h"
-#include "nvim/if_cscope.h"
+#include "nvim/buffer.h"
#include "nvim/charset.h"
+#include "nvim/event/stream.h"
#include "nvim/fileio.h"
-#include "nvim/message.h"
+#include "nvim/if_cscope.h"
#include "nvim/memory.h"
+#include "nvim/message.h"
+#include "nvim/os/input.h"
+#include "nvim/os/os.h"
#include "nvim/os/time.h"
#include "nvim/path.h"
#include "nvim/quickfix.h"
#include "nvim/strings.h"
#include "nvim/tag.h"
-#include "nvim/os/os.h"
-#include "nvim/os/input.h"
-#include "nvim/event/stream.h"
-
-#include <sys/types.h>
-#include <sys/stat.h>
#if defined(UNIX)
# include <sys/wait.h>
#endif
@@ -90,19 +88,20 @@ char_u *get_cscope_name(expand_T *xp, int idx)
// Complete with sub-commands of ":cscope":
// add, find, help, kill, reset, show
return (char_u *)cs_cmds[idx].name;
- case EXP_SCSCOPE_SUBCMD:
- {
+ case EXP_SCSCOPE_SUBCMD: {
// Complete with sub-commands of ":scscope": same sub-commands as
// ":cscope" but skip commands which don't support split windows
int i;
- for (i = 0, current_idx = 0; cs_cmds[i].name != NULL; i++)
- if (cs_cmds[i].cansplit)
- if (current_idx++ == idx)
+ for (i = 0, current_idx = 0; cs_cmds[i].name != NULL; i++) {
+ if (cs_cmds[i].cansplit) {
+ if (current_idx++ == idx) {
break;
+ }
+ }
+ }
return (char_u *)cs_cmds[i].name;
}
- case EXP_CSCOPE_FIND:
- {
+ case EXP_CSCOPE_FIND: {
const char *query_type[] =
{
"a", "c", "d", "e", "f", "g", "i", "s", "t", NULL
@@ -114,8 +113,7 @@ char_u *get_cscope_name(expand_T *xp, int idx)
// redundant.
return (char_u *)query_type[idx];
}
- case EXP_CSCOPE_KILL:
- {
+ case EXP_CSCOPE_KILL: {
static char connection[5];
// ":cscope kill" accepts connection numbers or partial names of
@@ -124,8 +122,9 @@ char_u *get_cscope_name(expand_T *xp, int idx)
// connections.
size_t i;
for (i = 0, current_idx = 0; i < csinfo_size; i++) {
- if (csinfo[i].fname == NULL)
+ if (csinfo[i].fname == NULL) {
continue;
+ }
if (current_idx++ == idx) {
vim_snprintf(connection, sizeof(connection), "%zu", i);
return (char_u *)connection;
@@ -172,11 +171,9 @@ void set_context_in_cscope_cmd(expand_T *xp, const char *arg, cmdidx_T cmdidx)
/// Find the command, print help if invalid, and then call the corresponding
/// command function.
-static void
-do_cscope_general(
- exarg_T *eap,
- int make_split // whether to split window
-)
+///
+/// @param make_split whether to split window
+static void do_cscope_general(exarg_T *eap, int make_split)
{
cscmd_T *cmdp;
@@ -187,8 +184,7 @@ do_cscope_general(
if (make_split) {
if (!cmdp->cansplit) {
- (void)MSG_PUTS(_(
- "This cscope command does not support splitting the window.\n"));
+ (void)MSG_PUTS(_("This cscope command does not support splitting the window.\n"));
return;
}
postponed_split = -1;
@@ -228,14 +224,16 @@ void ex_cstag(exarg_T *eap)
case 0:
if (cs_check_for_connections()) {
ret = cs_find_common("g", (char *)(eap->arg), eap->forceit, FALSE,
- FALSE, *eap->cmdlinep);
+ FALSE, *eap->cmdlinep);
if (ret == FALSE) {
cs_free_tags();
- if (msg_col)
+ if (msg_col) {
msg_putchar('\n');
+ }
- if (cs_check_for_tags())
+ if (cs_check_for_tags()) {
ret = do_tag(eap->arg, DT_JUMP, 0, eap->forceit, FALSE);
+ }
}
} else if (cs_check_for_tags()) {
ret = do_tag(eap->arg, DT_JUMP, 0, eap->forceit, FALSE);
@@ -245,21 +243,24 @@ void ex_cstag(exarg_T *eap)
if (cs_check_for_tags()) {
ret = do_tag(eap->arg, DT_JUMP, 0, eap->forceit, FALSE);
if (ret == FALSE) {
- if (msg_col)
+ if (msg_col) {
msg_putchar('\n');
+ }
if (cs_check_for_connections()) {
ret = cs_find_common("g", (char *)(eap->arg), eap->forceit,
- FALSE, FALSE, *eap->cmdlinep);
- if (ret == FALSE)
+ FALSE, FALSE, *eap->cmdlinep);
+ if (ret == FALSE) {
cs_free_tags();
+ }
}
}
} else if (cs_check_for_connections()) {
ret = cs_find_common("g", (char *)(eap->arg), eap->forceit, FALSE,
- FALSE, *eap->cmdlinep);
- if (ret == FALSE)
+ FALSE, *eap->cmdlinep);
+ if (ret == FALSE) {
cs_free_tags();
+ }
}
break;
default:
@@ -306,29 +307,29 @@ void cs_print_tags(void)
/*
* "cscope_connection([{num} , {dbpath} [, {prepend}]])" function
*
- * Checks for the existence of a |cscope| connection. If no
- * parameters are specified, then the function returns:
+ * Checks for the existence of a |cscope| connection. If no
+ * parameters are specified, then the function returns:
*
- * 0, if cscope was not available (not compiled in), or if there
- * are no cscope connections; or
- * 1, if there is at least one cscope connection.
+ * 0, if cscope was not available (not compiled in), or if there
+ * are no cscope connections; or
+ * 1, if there is at least one cscope connection.
*
- * If parameters are specified, then the value of {num}
- * determines how existence of a cscope connection is checked:
+ * If parameters are specified, then the value of {num}
+ * determines how existence of a cscope connection is checked:
*
- * {num} Description of existence check
- * ----- ------------------------------
- * 0 Same as no parameters (e.g., "cscope_connection()").
- * 1 Ignore {prepend}, and use partial string matches for
- * {dbpath}.
- * 2 Ignore {prepend}, and use exact string matches for
- * {dbpath}.
- * 3 Use {prepend}, use partial string matches for both
- * {dbpath} and {prepend}.
- * 4 Use {prepend}, use exact string matches for both
- * {dbpath} and {prepend}.
+ * {num} Description of existence check
+ * ----- ------------------------------
+ * 0 Same as no parameters (e.g., "cscope_connection()").
+ * 1 Ignore {prepend}, and use partial string matches for
+ * {dbpath}.
+ * 2 Ignore {prepend}, and use exact string matches for
+ * {dbpath}.
+ * 3 Use {prepend}, use partial string matches for both
+ * {dbpath} and {prepend}.
+ * 4 Use {prepend}, use exact string matches for both
+ * {dbpath} and {prepend}.
*
- * Note: All string comparisons are case sensitive!
+ * Note: All string comparisons are case sensitive!
*/
bool cs_connection(int num, char_u *dbpath, char_u *ppath)
{
@@ -393,8 +394,9 @@ static int cs_add(exarg_T *eap)
cs_usage_msg(Add);
return CSCOPE_FAILURE;
}
- if ((ppath = strtok((char *)NULL, (const char *)" ")) != NULL)
+ if ((ppath = strtok((char *)NULL, (const char *)" ")) != NULL) {
flags = strtok((char *)NULL, (const char *)" ");
+ }
return cs_add_common(fname, ppath, flags);
}
@@ -413,18 +415,16 @@ static void cs_stat_emsg(char *fname)
/// The common routine to add a new cscope connection. Called by
/// cs_add() and cs_reset(). I really don't like to do this, but this
/// routine uses a number of goto statements.
-static int
-cs_add_common(
- char *arg1, // filename - may contain environment variables
- char *arg2, // prepend path - may contain environment variables
- char *flags
-)
+///
+/// @param arg1 filename - may contain environment variables
+/// @param arg2 prepend path - may contain environment variables
+static int cs_add_common(char *arg1, char *arg2, char *flags)
{
- char *fname = NULL;
- char *fname2 = NULL;
- char *ppath = NULL;
+ char *fname = NULL;
+ char *fname2 = NULL;
+ char *ppath = NULL;
size_t usedlen = 0;
- char_u *fbuf = NULL;
+ char_u *fbuf = NULL;
// get the filename (arg1), expand it, and try to stat it
fname = xmalloc(MAXPATHL + 1);
@@ -443,8 +443,9 @@ cs_add_common(
bool file_info_ok = os_fileinfo(fname, &file_info);
if (!file_info_ok) {
staterr:
- if (p_csverbose)
+ if (p_csverbose) {
cs_stat_emsg(fname);
+ }
goto add_err;
}
@@ -465,31 +466,32 @@ staterr:
while (fname[strlen(fname)-1] == '/'
) {
fname[strlen(fname)-1] = '\0';
- if (fname[0] == '\0')
+ if (fname[0] == '\0') {
break;
+ }
}
- if (fname[0] == '\0')
+ if (fname[0] == '\0') {
(void)sprintf(fname2, "/%s", CSCOPE_DBFILE);
- else
+ } else {
(void)sprintf(fname2, "%s/%s", fname, CSCOPE_DBFILE);
+ }
file_info_ok = os_fileinfo(fname2, &file_info);
if (!file_info_ok) {
- if (p_csverbose)
+ if (p_csverbose) {
cs_stat_emsg(fname2);
+ }
goto add_err;
}
i = cs_insert_filelist(fname2, ppath, flags, &file_info);
- }
- else if (S_ISREG(file_info.stat.st_mode) || S_ISLNK(file_info.stat.st_mode))
- {
+ } else if (S_ISREG(file_info.stat.st_mode) || S_ISLNK(file_info.stat.st_mode)) {
i = cs_insert_filelist(fname, ppath, flags, &file_info);
} else {
- if (p_csverbose)
- (void)EMSG2(
- _("E564: %s is not a directory or a valid cscope database"),
- fname);
+ if (p_csverbose) {
+ (void)EMSG2(_("E564: %s is not a directory or a valid cscope database"),
+ fname);
+ }
goto add_err;
}
@@ -538,15 +540,15 @@ static size_t cs_cnt_connections(void)
size_t cnt = 0;
for (size_t i = 0; i < csinfo_size; i++) {
- if (csinfo[i].fname != NULL)
+ if (csinfo[i].fname != NULL) {
cnt++;
+ }
}
return cnt;
}
-static void cs_reading_emsg(
- size_t idx // connection index
-)
+/// @param idx connection index
+static void cs_reading_emsg(size_t idx)
{
EMSGU(_("E262: error reading cscope connection %" PRIu64), idx);
}
@@ -582,7 +584,7 @@ static int cs_cnt_matches(size_t idx)
// Accept "\S*cscope: X lines", also matches "mlcscope".
// Bail out for the "Unable to search" error.
if (strstr((const char *)buf, "Unable to search database") != NULL) {
- break;
+ break;
}
if ((stok = strtok(buf, (const char *)" ")) == NULL) {
continue;
@@ -591,18 +593,21 @@ static int cs_cnt_matches(size_t idx)
continue;
}
- if ((stok = strtok(NULL, (const char *)" ")) == NULL)
+ if ((stok = strtok(NULL, (const char *)" ")) == NULL) {
continue;
+ }
nlines = atoi(stok);
if (nlines < 0) {
nlines = 0;
break;
}
- if ((stok = strtok(NULL, (const char *)" ")) == NULL)
+ if ((stok = strtok(NULL, (const char *)" ")) == NULL) {
continue;
- if (strncmp((const char *)stok, "lines", 5))
+ }
+ if (strncmp((const char *)stok, "lines", 5)) {
continue;
+ }
break;
}
@@ -620,31 +625,40 @@ static char *cs_create_cmd(char *csoption, char *pattern)
char *pat;
switch (csoption[0]) {
- case '0': case 's':
+ case '0':
+ case 's':
search = 0;
break;
- case '1': case 'g':
+ case '1':
+ case 'g':
search = 1;
break;
- case '2': case 'd':
+ case '2':
+ case 'd':
search = 2;
break;
- case '3': case 'c':
+ case '3':
+ case 'c':
search = 3;
break;
- case '4': case 't':
+ case '4':
+ case 't':
search = 4;
break;
- case '6': case 'e':
+ case '6':
+ case 'e':
search = 6;
break;
- case '7': case 'f':
+ case '7':
+ case 'f':
search = 7;
break;
- case '8': case 'i':
+ case '8':
+ case 'i':
search = 8;
break;
- case '9': case 'a':
+ case '9':
+ case 'a':
search = 9;
break;
default:
@@ -656,9 +670,11 @@ static char *cs_create_cmd(char *csoption, char *pattern)
// Skip white space before the patter, except for text and pattern search,
// they may want to use the leading white space.
pat = pattern;
- if (search != 4 && search != 6)
- while (ascii_iswhite(*pat))
+ if (search != 4 && search != 6) {
+ while (ascii_iswhite(*pat)) {
++pat;
+ }
+ }
cmd = xmalloc(strlen(pat) + 2);
@@ -675,7 +691,7 @@ static int cs_create_connection(size_t i)
#ifdef UNIX
int to_cs[2], from_cs[2];
#endif
- char *prog, *cmd, *ppath = NULL;
+ char *prog, *cmd, *ppath = NULL;
#if defined(UNIX)
/*
@@ -686,14 +702,18 @@ static int cs_create_connection(size_t i)
if (pipe(to_cs) < 0 || pipe(from_cs) < 0) {
(void)EMSG(_("E566: Could not create cscope pipes"));
err_closing:
- if (to_cs[0] != -1)
+ if (to_cs[0] != -1) {
(void)close(to_cs[0]);
- if (to_cs[1] != -1)
+ }
+ if (to_cs[1] != -1) {
(void)close(to_cs[1]);
- if (from_cs[0] != -1)
+ }
+ if (from_cs[0] != -1) {
(void)close(from_cs[0]);
- if (from_cs[1] != -1)
+ }
+ if (from_cs[1] != -1) {
(void)close(from_cs[1]);
+ }
return CSCOPE_FAILURE;
}
@@ -759,8 +779,9 @@ err_closing:
len += strlen(ppath);
}
- if (csinfo[i].flags)
+ if (csinfo[i].flags) {
len += strlen(csinfo[i].flags);
+ }
cmd = xmalloc(len);
@@ -779,10 +800,10 @@ err_closing:
(void)strcat(cmd, " ");
(void)strcat(cmd, csinfo[i].flags);
}
-# ifdef UNIX
+#ifdef UNIX
// on Win32 we still need prog
xfree(prog);
-# endif
+#endif
xfree(ppath);
#if defined(UNIX)
@@ -791,12 +812,14 @@ err_closing:
# if defined(HAVE_SETSID)
(void)setsid();
# else
- if (setpgid(0, 0) == -1)
+ if (setpgid(0, 0) == -1) {
PERROR(_("cs_create_connection setpgid failed"));
+ }
# endif
# endif
- if (execl("/bin/sh", "sh", "-c", cmd, (char *)NULL) == -1)
+ if (execl("/bin/sh", "sh", "-c", cmd, (char *)NULL) == -1) {
PERROR(_("cs_create_connection exec failed"));
+ }
exit(127);
// NOTREACHED
@@ -827,7 +850,7 @@ err_closing:
si.hStdError = stdout_wr;
si.hStdInput = stdin_rd;
created = CreateProcess(NULL, cmd, NULL, NULL, TRUE, CREATE_NEW_CONSOLE,
- NULL, NULL, &si, &pi);
+ NULL, NULL, &si, &pi);
xfree(prog);
xfree(cmd);
@@ -888,9 +911,11 @@ static int cs_find(exarg_T *eap)
* Let's replace the NULs written by strtok() with spaces - we need the
* spaces to correctly display the quickfix/location list window's title.
*/
- for (int i = 0; i < eap_arg_len; ++i)
- if (NUL == eap->arg[i])
+ for (int i = 0; i < eap_arg_len; ++i) {
+ if (NUL == eap->arg[i]) {
eap->arg[i] = ' ';
+ }
+ }
return cs_find_common(opt, pat, eap->forceit, true,
eap->cmdidx == CMD_lcscope, *eap->cmdlinep);
@@ -898,8 +923,8 @@ static int cs_find(exarg_T *eap)
/// Common code for cscope find, shared by cs_find() and ex_cstag().
-static int cs_find_common(char *opt, char *pat, int forceit, int verbose,
- int use_ll, char_u *cmdline)
+static int cs_find_common(char *opt, char *pat, int forceit, int verbose, int use_ll,
+ char_u *cmdline)
{
char *cmd;
int *nummatches;
@@ -966,8 +991,9 @@ static int cs_find_common(char *opt, char *pat, int forceit, int verbose,
// create the actual command to send to cscope
cmd = cs_create_cmd(opt, pat);
- if (cmd == NULL)
+ if (cmd == NULL) {
return FALSE;
+ }
nummatches = xmalloc(sizeof(int) * csinfo_size);
@@ -978,8 +1004,9 @@ static int cs_find_common(char *opt, char *pat, int forceit, int verbose,
}
totmatches = 0;
for (size_t i = 0; i < csinfo_size; i++) {
- if (csinfo[i].fname == NULL || csinfo[i].to_fp == NULL)
+ if (csinfo[i].fname == NULL || csinfo[i].to_fp == NULL) {
continue;
+ }
// send cmd to cscope
(void)fprintf(csinfo[i].to_fp, "%s\n", cmd);
@@ -987,11 +1014,13 @@ static int cs_find_common(char *opt, char *pat, int forceit, int verbose,
nummatches[i] = cs_cnt_matches(i);
- if (nummatches[i] > -1)
+ if (nummatches[i] > -1) {
totmatches += (size_t)nummatches[i];
+ }
- if (nummatches[i] == 0)
+ if (nummatches[i] == 0) {
(void)cs_read_prompt(i);
+ }
}
xfree(cmd);
@@ -1014,10 +1043,10 @@ static int cs_find_common(char *opt, char *pat, int forceit, int verbose,
if (qfpos != NULL && *qfpos != '0') {
// Fill error list.
- FILE *f;
- char_u *tmp = vim_tempname();
- qf_info_T *qi = NULL;
- win_T *wp = NULL;
+ FILE *f;
+ char_u *tmp = vim_tempname();
+ qf_info_T *qi = NULL;
+ win_T *wp = NULL;
f = os_fopen((char *)tmp, "w");
if (f == NULL) {
@@ -1039,14 +1068,15 @@ static int cs_find_common(char *opt, char *pat, int forceit, int verbose,
}
apply_autocmds(EVENT_QUICKFIXCMDPOST, (char_u *)"cscope",
- curbuf->b_fname, TRUE, curbuf);
- if (use_ll)
+ curbuf->b_fname, TRUE, curbuf);
+ if (use_ll) {
/*
* In the location list window, use the displayed location
* list. Otherwise, use the location list for the window.
*/
qi = (bt_quickfix(wp->w_buffer) && wp->w_llist_ref != NULL)
? wp->w_llist_ref : wp->w_llist;
+ }
qf_jump(qi, 0, 0, forceit);
}
}
@@ -1060,10 +1090,11 @@ static int cs_find_common(char *opt, char *pat, int forceit, int verbose,
// read output
cs_fill_results((char *)pat, totmatches, nummatches, &matches,
- &contexts, &matched);
+ &contexts, &matched);
xfree(nummatches);
- if (matches == NULL)
+ if (matches == NULL) {
return FALSE;
+ }
(void)cs_manage_matches(matches, contexts, matched, Store);
@@ -1086,10 +1117,10 @@ static int cs_help(exarg_T *eap)
space_cnt = 0;
}
(void)smsg(_("%-5s: %s%*s (Usage: %s)"),
- cmdp->name,
- help, space_cnt, " ",
- cmdp->usage);
- if (strcmp(cmdp->name, "find") == 0)
+ cmdp->name,
+ help, space_cnt, " ",
+ cmdp->usage);
+ if (strcmp(cmdp->name, "find") == 0) {
MSG_PUTS(_("\n"
" a: Find assignments to this symbol\n"
" c: Find functions calling this function\n"
@@ -1100,6 +1131,7 @@ static int cs_help(exarg_T *eap)
" i: Find files #including this file\n"
" s: Find this C symbol\n"
" t: Find this text string\n"));
+ }
cmdp++;
}
@@ -1121,8 +1153,7 @@ static void clear_csinfo(size_t i)
}
/// Insert a new cscope database filename into the filelist.
-static int cs_insert_filelist(char *fname, char *ppath, char *flags,
- FileInfo *file_info)
+static int cs_insert_filelist(char *fname, char *ppath, char *flags, FileInfo *file_info)
{
size_t i = 0;
bool empty_found = false;
@@ -1130,8 +1161,9 @@ static int cs_insert_filelist(char *fname, char *ppath, char *flags,
for (size_t j = 0; j < csinfo_size; j++) {
if (csinfo[j].fname != NULL
&& os_fileid_equal_fileinfo(&(csinfo[j].file_id), file_info)) {
- if (p_csverbose)
+ if (p_csverbose) {
(void)EMSG(_("E568: duplicate cscope database not added"));
+ }
return CSCOPE_FAILURE;
}
@@ -1154,8 +1186,9 @@ static int cs_insert_filelist(char *fname, char *ppath, char *flags,
csinfo_size *= 2;
csinfo = xrealloc(csinfo, sizeof(csinfo_T)*csinfo_size);
}
- for (size_t j = csinfo_size/2; j < csinfo_size; j++)
+ for (size_t j = csinfo_size/2; j < csinfo_size; j++) {
clear_csinfo(j);
+ }
}
csinfo[i].fname = xmalloc(strlen(fname) + 1);
@@ -1165,14 +1198,16 @@ static int cs_insert_filelist(char *fname, char *ppath, char *flags,
if (ppath != NULL) {
csinfo[i].ppath = xmalloc(strlen(ppath) + 1);
(void)strcpy(csinfo[i].ppath, (const char *)ppath);
- } else
+ } else {
csinfo[i].ppath = NULL;
+ }
if (flags != NULL) {
csinfo[i].flags = xmalloc(strlen(flags) + 1);
(void)strcpy(csinfo[i].flags, (const char *)flags);
- } else
+ } else {
csinfo[i].flags = NULL;
+ }
os_fileinfo_id(file_info, &(csinfo[i].file_id));
assert(i <= INT_MAX);
@@ -1181,25 +1216,28 @@ static int cs_insert_filelist(char *fname, char *ppath, char *flags,
/// Find cscope command in command table.
-static cscmd_T * cs_lookup_cmd(exarg_T *eap)
+static cscmd_T *cs_lookup_cmd(exarg_T *eap)
{
cscmd_T *cmdp;
char *stok;
size_t len;
- if (eap->arg == NULL)
+ if (eap->arg == NULL) {
return NULL;
+ }
// Store length of eap->arg before it gets modified by strtok().
eap_arg_len = (int)STRLEN(eap->arg);
- if ((stok = strtok((char *)(eap->arg), (const char *)" ")) == NULL)
+ if ((stok = strtok((char *)(eap->arg), (const char *)" ")) == NULL) {
return NULL;
+ }
len = strlen(stok);
for (cmdp = cs_cmds; cmdp->name != NULL; ++cmdp) {
- if (strncmp((const char *)(stok), cmdp->name, len) == 0)
+ if (strncmp((const char *)(stok), cmdp->name, len) == 0) {
return cmdp;
+ }
}
return NULL;
}
@@ -1224,21 +1262,23 @@ static int cs_kill(exarg_T *eap)
|| (strlen(stok) < 3 && stok[0] == '-'
&& ascii_isdigit((int)(stok[1])))) {
num = atoi(stok);
- if (num == -1)
+ if (num == -1) {
killall = true;
- else if (num >= 0) {
+ } else if (num >= 0) {
i = (size_t)num;
} else { // All negative values besides -1 are invalid.
- if (p_csverbose)
+ if (p_csverbose) {
(void)EMSG2(_("E261: cscope connection %s not found"), stok);
+ }
return CSCOPE_FAILURE;
}
} else {
// Else it must be part of a name. We will try to find a match
// within all the names in the csinfo data structure
for (i = 0; i < csinfo_size; i++) {
- if (csinfo[i].fname != NULL && strstr(csinfo[i].fname, stok))
+ if (csinfo[i].fname != NULL && strstr(csinfo[i].fname, stok)) {
break;
+ }
}
}
@@ -1250,8 +1290,9 @@ static int cs_kill(exarg_T *eap)
} else {
if (killall) {
for (i = 0; i < csinfo_size; i++) {
- if (csinfo[i].fname)
+ if (csinfo[i].fname) {
cs_kill_execute(i, csinfo[i].fname);
+ }
}
} else {
cs_kill_execute((size_t)i, stok);
@@ -1263,10 +1304,10 @@ static int cs_kill(exarg_T *eap)
/// Actually kills a specific cscope connection.
-static void cs_kill_execute(
- size_t i, // cscope table index
- char *cname // cscope database name
-)
+///
+/// @param i cscope table index
+/// @param cname cscope database name
+static void cs_kill_execute(size_t i, char *cname)
{
if (p_csverbose) {
msg_clr_eos();
@@ -1293,8 +1334,7 @@ static void cs_kill_execute(
/// Besides, even if this particular case didn't happen, the search pattern
/// would still have to be modified to escape all the special regular expression
/// characters to comply with ctags formatting.
-static char *cs_make_vim_style_matches(char *fname, char *slno, char *search,
- char *tagstr)
+static char *cs_make_vim_style_matches(char *fname, char *slno, char *search, char *tagstr)
{
// vim style is ctags:
//
@@ -1339,8 +1379,7 @@ static char *cs_make_vim_style_matches(char *fname, char *slno, char *search,
/// Free: frees up everything and resets
///
/// Print: prints the tags
-static char *cs_manage_matches(char **matches, char **contexts,
- size_t totmatches, mcmd_e cmd)
+static char *cs_manage_matches(char **matches, char **contexts, size_t totmatches, mcmd_e cmd)
{
static char **mp = NULL;
static char **cp = NULL;
@@ -1352,16 +1391,18 @@ static char *cs_manage_matches(char **matches, char **contexts,
case Store:
assert(matches != NULL);
assert(totmatches > 0);
- if (mp != NULL || cp != NULL)
+ if (mp != NULL || cp != NULL) {
(void)cs_manage_matches(NULL, NULL, 0, Free);
+ }
mp = matches;
cp = contexts;
cnt = totmatches;
next = 0;
break;
case Get:
- if (next >= cnt)
+ if (next >= cnt) {
return NULL;
+ }
p = mp[next];
next++;
@@ -1370,8 +1411,9 @@ static char *cs_manage_matches(char **matches, char **contexts,
if (mp != NULL) {
while (cnt--) {
xfree(mp[cnt]);
- if (cp != NULL)
+ if (cp != NULL) {
xfree(cp[cnt]);
+ }
}
xfree(mp);
xfree(cp);
@@ -1396,8 +1438,8 @@ static char *cs_manage_matches(char **matches, char **contexts,
/// Parse cscope output.
-static char *cs_parse_results(size_t cnumber, char *buf, int bufsize,
- char **context, char **linenumber, char **search)
+static char *cs_parse_results(size_t cnumber, char *buf, int bufsize, char **context,
+ char **linenumber, char **search)
{
int ch;
char *p;
@@ -1421,8 +1463,9 @@ retry:
// If the line's too long for the buffer, discard it.
if ((p = strchr(buf, '\n')) == NULL) {
- while ((ch = getc(csinfo[cnumber].fr_fp)) != EOF && ch != '\n')
+ while ((ch = getc(csinfo[cnumber].fr_fp)) != EOF && ch != '\n') {
;
+ }
return NULL;
}
*p = '\0';
@@ -1430,14 +1473,17 @@ retry:
/*
* cscope output is in the following format:
*
- * <filename> <context> <line number> <pattern>
+ * <filename> <context> <line number> <pattern>
*/
- if ((name = strtok((char *)buf, (const char *)" ")) == NULL)
+ if ((name = strtok((char *)buf, (const char *)" ")) == NULL) {
return NULL;
- if ((*context = strtok(NULL, (const char *)" ")) == NULL)
+ }
+ if ((*context = strtok(NULL, (const char *)" ")) == NULL) {
return NULL;
- if ((*linenumber = strtok(NULL, (const char *)" ")) == NULL)
+ }
+ if ((*linenumber = strtok(NULL, (const char *)" ")) == NULL) {
return NULL;
+ }
*search = *linenumber + strlen(*linenumber) + 1; // +1 to skip \0
// --- nvi ---
@@ -1463,25 +1509,29 @@ static void cs_file_results(FILE *f, int *nummatches_a)
char *buf = xmalloc(CSREAD_BUFSIZE);
for (size_t i = 0; i < csinfo_size; i++) {
- if (nummatches_a[i] < 1)
+ if (nummatches_a[i] < 1) {
continue;
+ }
for (int j = 0; j < nummatches_a[i]; j++) {
if ((fullname = cs_parse_results(i, buf, CSREAD_BUFSIZE, &cntx,
- &slno, &search)) == NULL)
+ &slno, &search)) == NULL) {
continue;
+ }
context = xmalloc(strlen(cntx) + 5);
- if (strcmp(cntx, "<global>")==0)
+ if (strcmp(cntx, "<global>")==0) {
strcpy(context, "<<global>>");
- else
+ } else {
sprintf(context, "<<%s>>", cntx);
+ }
- if (search == NULL)
+ if (search == NULL) {
fprintf(f, "%s\t%s\t%s\n", fullname, slno, context);
- else
+ } else {
fprintf(f, "%s\t%s\t%s %s\n", fullname, slno, context, search);
+ }
xfree(context);
xfree(fullname);
@@ -1495,9 +1545,8 @@ static void cs_file_results(FILE *f, int *nummatches_a)
/// Get parsed cscope output and calls cs_make_vim_style_matches to convert
/// into ctags format.
/// When there are no matches sets "*matches_p" to NULL.
-static void cs_fill_results(char *tagstr, size_t totmatches, int *nummatches_a,
- char ***matches_p, char ***cntxts_p,
- size_t *matched)
+static void cs_fill_results(char *tagstr, size_t totmatches, int *nummatches_a, char ***matches_p,
+ char ***cntxts_p, size_t *matched)
{
char *buf;
char *search, *slno;
@@ -1514,22 +1563,24 @@ static void cs_fill_results(char *tagstr, size_t totmatches, int *nummatches_a,
cntxts = xmalloc(sizeof(char *) * (size_t)totmatches);
for (size_t i = 0; i < csinfo_size; i++) {
- if (nummatches_a[i] < 1)
+ if (nummatches_a[i] < 1) {
continue;
+ }
for (int j = 0; j < nummatches_a[i]; j++) {
if ((fullname = cs_parse_results(i, buf, CSREAD_BUFSIZE, &cntx,
- &slno, &search)) == NULL)
+ &slno, &search)) == NULL) {
continue;
+ }
matches[totsofar] = cs_make_vim_style_matches(fullname, slno, search,
tagstr);
xfree(fullname);
- if (strcmp(cntx, "<global>") == 0)
+ if (strcmp(cntx, "<global>") == 0) {
cntxts[totsofar] = NULL;
- else {
+ } else {
cntxts[totsofar] = xstrdup(cntx);
}
@@ -1691,9 +1742,9 @@ static void cs_print_tags_priv(char **matches, char **cntxts,
static int cs_read_prompt(size_t i)
{
int ch;
- char *buf = NULL; // buffer for possible error message from cscope
+ char *buf = NULL; // buffer for possible error message from cscope
size_t bufpos = 0;
- char *cs_emsg = _("E609: Cscope error: %s");
+ char *cs_emsg = _("E609: Cscope error: %s");
size_t cs_emsg_len = strlen(cs_emsg);
static char *eprompt = "Press the RETURN key to continue:";
size_t epromptlen = strlen(eprompt);
@@ -1886,10 +1937,12 @@ static void cs_release_csp(size_t i, bool freefnpp)
}
#endif
- if (csinfo[i].fr_fp != NULL)
+ if (csinfo[i].fr_fp != NULL) {
(void)fclose(csinfo[i].fr_fp);
- if (csinfo[i].to_fp != NULL)
+ }
+ if (csinfo[i].to_fp != NULL) {
(void)fclose(csinfo[i].to_fp);
+ }
if (freefnpp) {
xfree(csinfo[i].fname);
@@ -1904,11 +1957,12 @@ static void cs_release_csp(size_t i, bool freefnpp)
/// Calls cs_kill on all cscope connections then reinits.
static int cs_reset(exarg_T *eap)
{
- char **dblist = NULL, **pplist = NULL, **fllist = NULL;
+ char **dblist = NULL, **pplist = NULL, **fllist = NULL;
char buf[25]; // for snprintf " (#%zu)"
- if (csinfo_size == 0)
+ if (csinfo_size == 0) {
return CSCOPE_SUCCESS;
+ }
// malloc our db and ppath list
dblist = xmalloc(csinfo_size * sizeof(char *));
@@ -1919,8 +1973,9 @@ static int cs_reset(exarg_T *eap)
dblist[i] = csinfo[i].fname;
pplist[i] = csinfo[i].ppath;
fllist[i] = csinfo[i].flags;
- if (csinfo[i].fname != NULL)
+ if (csinfo[i].fname != NULL) {
cs_release_csp(i, FALSE);
+ }
}
// rebuild the cscope connection list
@@ -1959,8 +2014,8 @@ static int cs_reset(exarg_T *eap)
/// Contrast this with my development system (Digital Unix), which does.
static char *cs_resolve_file(size_t i, char *name)
{
- char *fullname;
- char_u *csdir = NULL;
+ char *fullname;
+ char_u *csdir = NULL;
/*
* Ppath is freed when we destroy the cscope connection.
@@ -1975,8 +2030,8 @@ static char *cs_resolve_file(size_t i, char *name)
// path in path resolution.
csdir = xmalloc(MAXPATHL);
STRLCPY(csdir, csinfo[i].fname,
- path_tail((char_u *)csinfo[i].fname)
- - (char_u *)csinfo[i].fname + 1);
+ path_tail((char_u *)csinfo[i].fname)
+ - (char_u *)csinfo[i].fname + 1);
len += STRLEN(csdir);
}
@@ -1985,8 +2040,7 @@ static char *cs_resolve_file(size_t i, char *name)
// happens, you are screwed up and need to fix how you're using cscope.
if (csinfo[i].ppath != NULL
&& (strncmp(name, csinfo[i].ppath, strlen(csinfo[i].ppath)) != 0)
- && (name[0] != '/')
- ) {
+ && (name[0] != '/')) {
fullname = xmalloc(len);
(void)sprintf(fullname, "%s/%s", csinfo[i].ppath, name);
} else if (csdir != NULL && csinfo[i].fname != NULL && *csdir != NUL) {
@@ -2005,15 +2059,15 @@ static char *cs_resolve_file(size_t i, char *name)
/// Show all cscope connections.
static int cs_show(exarg_T *eap)
{
- if (cs_cnt_connections() == 0)
+ if (cs_cnt_connections() == 0) {
MSG_PUTS(_("no cscope connections\n"));
- else {
- MSG_PUTS_ATTR(
- _(" # pid database name prepend path\n"),
- HL_ATTR(HLF_T));
+ } else {
+ MSG_PUTS_ATTR(_(" # pid database name prepend path\n"),
+ HL_ATTR(HLF_T));
for (size_t i = 0; i < csinfo_size; i++) {
- if (csinfo[i].fname == NULL)
+ if (csinfo[i].fname == NULL) {
continue;
+ }
if (csinfo[i].ppath != NULL) {
(void)smsg("%2zu %-5" PRId64 " %-34s %-32s", i,
@@ -2033,8 +2087,9 @@ static int cs_show(exarg_T *eap)
/// Only called when VIM exits to quit any cscope sessions.
void cs_end(void)
{
- for (size_t i = 0; i < csinfo_size; i++)
+ for (size_t i = 0; i < csinfo_size; i++) {
cs_release_csp(i, true);
+ }
xfree(csinfo);
csinfo_size = 0;
}
diff --git a/src/nvim/lua/executor.c b/src/nvim/lua/executor.c
index 9333d781cd..3f93bb9a09 100644
--- a/src/nvim/lua/executor.c
+++ b/src/nvim/lua/executor.c
@@ -5,6 +5,7 @@
#include <lua.h>
#include <lualib.h>
+#include "cjson/lua_cjson.h"
#include "luv/luv.h"
#include "mpack/lmpack.h"
#include "nvim/api/private/defs.h"
@@ -40,7 +41,6 @@
#include "nvim/undo.h"
#include "nvim/version.h"
#include "nvim/vim.h"
-#include "cjson/lua_cjson.h"
static int in_fast_callback = 0;
diff --git a/src/nvim/runtime.c b/src/nvim/runtime.c
index 7b72efce23..f0b54a254f 100644
--- a/src/nvim/runtime.c
+++ b/src/nvim/runtime.c
@@ -5,8 +5,8 @@
///
/// Management of runtime files (including packages)
-#include "nvim/ascii.h"
#include "nvim/api/private/helpers.h"
+#include "nvim/ascii.h"
#include "nvim/charset.h"
#include "nvim/eval.h"
#include "nvim/ex_cmds.h"
@@ -169,9 +169,9 @@ int do_in_path(char_u *path, char_u *name, int flags, DoInRuntimepathCB callback
int do_in_cached_path(char_u *name, int flags, DoInRuntimepathCB callback, void *cookie)
{
runtime_search_path_validate();
- char_u *tail;
+ char_u *tail;
int num_files;
- char_u **files;
+ char_u **files;
int i;
bool did_one = false;
@@ -452,11 +452,11 @@ void runtime_search_path_invalidate(void)
void runtime_search_path_free(RuntimeSearchPath path)
{
- for (size_t j = 0; j < kv_size(path); j++) {
- SearchPathItem item = kv_A(path, j);
- xfree(item.path);
- }
- kv_destroy(path);
+ for (size_t j = 0; j < kv_size(path); j++) {
+ SearchPathItem item = kv_A(path, j);
+ xfree(item.path);
+ }
+ kv_destroy(path);
}
void runtime_search_path_validate(void)
diff --git a/src/nvim/screen.c b/src/nvim/screen.c
index 98d8722ec8..fcd8fb1118 100644
--- a/src/nvim/screen.c
+++ b/src/nvim/screen.c
@@ -4545,8 +4545,8 @@ void draw_virt_text(buf_T *buf, int col_off, int *end_col, int max_col)
}
}
-static int draw_virt_text_item(buf_T *buf, int col, VirtText vt, HlMode hl_mode,
- int max_col, int vcol)
+static int draw_virt_text_item(buf_T *buf, int col, VirtText vt, HlMode hl_mode, int max_col,
+ int vcol)
{
LineState s = LINE_STATE("");
int virt_attr = 0;
diff --git a/src/nvim/strings.c b/src/nvim/strings.c
index 79a3db4843..11c1aa1760 100644
--- a/src/nvim/strings.c
+++ b/src/nvim/strings.c
@@ -1,28 +1,26 @@
// This is an open source non-commercial project. Dear PVS-Studio, please check
// it. PVS-Studio Static Code Analyzer for C, C++ and C#: http://www.viva64.com
+#include <assert.h>
#include <inttypes.h>
+#include <math.h>
#include <stdarg.h>
#include <stdbool.h>
#include <string.h>
-#include <math.h>
-#include <assert.h>
-#include "nvim/assert.h"
-#include "nvim/vim.h"
#include "nvim/ascii.h"
-#include "nvim/strings.h"
-#include "nvim/file_search.h"
+#include "nvim/assert.h"
#include "nvim/buffer.h"
#include "nvim/charset.h"
#include "nvim/diff.h"
#include "nvim/edit.h"
#include "nvim/eval.h"
+#include "nvim/eval/encode.h"
#include "nvim/ex_cmds.h"
#include "nvim/ex_docmd.h"
#include "nvim/ex_getln.h"
+#include "nvim/file_search.h"
#include "nvim/fileio.h"
-#include "nvim/func_attr.h"
#include "nvim/fold.h"
#include "nvim/func_attr.h"
#include "nvim/getchar.h"
@@ -35,8 +33,10 @@
#include "nvim/message.h"
#include "nvim/misc1.h"
#include "nvim/move.h"
-#include "nvim/option.h"
#include "nvim/ops.h"
+#include "nvim/option.h"
+#include "nvim/os/os.h"
+#include "nvim/os/shell.h"
#include "nvim/os_unix.h"
#include "nvim/path.h"
#include "nvim/quickfix.h"
@@ -44,12 +44,11 @@
#include "nvim/screen.h"
#include "nvim/search.h"
#include "nvim/spell.h"
+#include "nvim/strings.h"
#include "nvim/syntax.h"
#include "nvim/tag.h"
+#include "nvim/vim.h"
#include "nvim/window.h"
-#include "nvim/os/os.h"
-#include "nvim/os/shell.h"
-#include "nvim/eval/encode.h"
/// Copy "string" into newly allocated memory.
char_u *vim_strsave(const char_u *string)
@@ -84,8 +83,7 @@ char_u *vim_strsave_escaped(const char_u *string, const char_u *esc_chars)
* characters where rem_backslash() would remove the backslash.
* Escape the characters with "cc".
*/
-char_u *vim_strsave_escaped_ext(const char_u *string, const char_u *esc_chars,
- char_u cc, bool bsl)
+char_u *vim_strsave_escaped_ext(const char_u *string, const char_u *esc_chars, char_u cc, bool bsl)
FUNC_ATTR_NONNULL_RET FUNC_ATTR_MALLOC FUNC_ATTR_NONNULL_ALL
{
/*
@@ -100,9 +98,10 @@ char_u *vim_strsave_escaped_ext(const char_u *string, const char_u *esc_chars,
p += l - 1;
continue;
}
- if (vim_strchr(esc_chars, *p) != NULL || (bsl && rem_backslash(p)))
- ++length; /* count a backslash */
- ++length; /* count an ordinary char */
+ if (vim_strchr(esc_chars, *p) != NULL || (bsl && rem_backslash(p))) {
+ ++length; // count a backslash
+ }
+ ++length; // count an ordinary char
}
char_u *escaped_string = xmalloc(length);
@@ -112,11 +111,12 @@ char_u *vim_strsave_escaped_ext(const char_u *string, const char_u *esc_chars,
if (l > 1) {
memcpy(p2, p, l);
p2 += l;
- p += l - 1; /* skip multibyte char */
+ p += l - 1; // skip multibyte char
continue;
}
- if (vim_strchr(esc_chars, *p) != NULL || (bsl && rem_backslash(p)))
+ if (vim_strchr(esc_chars, *p) != NULL || (bsl && rem_backslash(p))) {
*p2++ = cc;
+ }
*p2++ = *p;
}
*p2 = NUL;
@@ -182,12 +182,11 @@ char *vim_strnsave_unquoted(const char *const string, const size_t length)
* When "do_newline" is false do not escape newline unless it is csh shell.
* Returns the result in allocated memory.
*/
-char_u *vim_strsave_shellescape(const char_u *string,
- bool do_special, bool do_newline)
+char_u *vim_strsave_shellescape(const char_u *string, bool do_special, bool do_newline)
FUNC_ATTR_NONNULL_RET FUNC_ATTR_MALLOC FUNC_ATTR_NONNULL_ALL
{
- char_u *d;
- char_u *escaped_string;
+ char_u *d;
+ char_u *escaped_string;
size_t l;
int csh_like;
bool fish_like;
@@ -202,7 +201,7 @@ char_u *vim_strsave_shellescape(const char_u *string,
// itself must be escaped to get a literal '\'.
fish_like = fish_like_shell();
- /* First count the number of extra bytes required. */
+ // First count the number of extra bytes required.
size_t length = STRLEN(string) + 3; // two quotes and a trailing NUL
for (const char_u *p = string; *p != NUL; MB_PTR_ADV(p)) {
#ifdef WIN32
@@ -217,12 +216,13 @@ char_u *vim_strsave_shellescape(const char_u *string,
}
if ((*p == '\n' && (csh_like || do_newline))
|| (*p == '!' && (csh_like || do_special))) {
- ++length; /* insert backslash */
- if (csh_like && do_special)
- ++length; /* insert backslash */
+ ++length; // insert backslash
+ if (csh_like && do_special) {
+ ++length; // insert backslash
+ }
}
if (do_special && find_cmdline_var(p, &l) >= 0) {
- ++length; /* insert backslash */
+ ++length; // insert backslash
p += l - 1;
}
if (*p == '\\' && fish_like) {
@@ -230,7 +230,7 @@ char_u *vim_strsave_shellescape(const char_u *string,
}
}
- /* Allocate memory for the result and fill it. */
+ // Allocate memory for the result and fill it.
escaped_string = xmalloc(length);
d = escaped_string;
@@ -264,15 +264,17 @@ char_u *vim_strsave_shellescape(const char_u *string,
if ((*p == '\n' && (csh_like || do_newline))
|| (*p == '!' && (csh_like || do_special))) {
*d++ = '\\';
- if (csh_like && do_special)
+ if (csh_like && do_special) {
*d++ = '\\';
+ }
*d++ = *p++;
continue;
}
if (do_special && find_cmdline_var(p, &l) >= 0) {
- *d++ = '\\'; /* insert backslash */
- while (--l != SIZE_MAX) /* copy the var */
+ *d++ = '\\'; // insert backslash
+ while (--l != SIZE_MAX) { // copy the var
*d++ = *p++;
+ }
continue;
}
if (*p == '\\' && fish_like) {
@@ -285,11 +287,11 @@ char_u *vim_strsave_shellescape(const char_u *string,
}
// add terminating quote and finish with a NUL
-# ifdef WIN32
+#ifdef WIN32
if (!p_ssl) {
*d++ = '"';
} else
-# endif
+#endif
*d++ = '\'';
*d = NUL;
@@ -384,11 +386,12 @@ char *strcase_save(const char *const orig, bool upper)
void del_trailing_spaces(char_u *ptr)
FUNC_ATTR_NONNULL_ALL
{
- char_u *q;
+ char_u *q;
q = ptr + STRLEN(ptr);
- while (--q > ptr && ascii_iswhite(q[0]) && q[-1] != '\\' && q[-1] != Ctrl_V)
+ while (--q > ptr && ascii_iswhite(q[0]) && q[-1] != '\\' && q[-1] != Ctrl_V) {
*q = NUL;
+ }
}
#if (!defined(HAVE_STRCASECMP) && !defined(HAVE_STRICMP))
@@ -404,14 +407,16 @@ int vim_stricmp(const char *s1, const char *s2)
for (;; ) {
i = (int)TOLOWER_LOC(*s1) - (int)TOLOWER_LOC(*s2);
- if (i != 0)
- return i; /* this character different */
- if (*s1 == NUL)
- break; /* strings match until NUL */
+ if (i != 0) {
+ return i; // this character different
+ }
+ if (*s1 == NUL) {
+ break; // strings match until NUL
+ }
++s1;
++s2;
}
- return 0; /* strings match */
+ return 0; // strings match
}
#endif
@@ -428,15 +433,17 @@ int vim_strnicmp(const char *s1, const char *s2, size_t len)
while (len > 0) {
i = (int)TOLOWER_LOC(*s1) - (int)TOLOWER_LOC(*s2);
- if (i != 0)
- return i; /* this character different */
- if (*s1 == NUL)
- break; /* strings match until NUL */
+ if (i != 0) {
+ return i; // this character different
+ }
+ if (*s1 == NUL) {
+ break; // strings match until NUL
+ }
++s1;
++s2;
--len;
}
- return 0; /* strings match */
+ return 0; // strings match
}
#endif
@@ -490,10 +497,13 @@ bool has_non_ascii(const char_u *s)
{
const char_u *p;
- if (s != NULL)
- for (p = s; *p != NUL; ++p)
- if (*p >= 128)
+ if (s != NULL) {
+ for (p = s; *p != NUL; ++p) {
+ if (*p >= 128) {
return true;
+ }
+ }
+ }
return false;
}
@@ -504,7 +514,7 @@ bool has_non_ascii_len(const char *const s, const size_t len)
{
if (s != NULL) {
for (size_t i = 0; i < len; i++) {
- if ((uint8_t) s[i] >= 128) {
+ if ((uint8_t)s[i] >= 128) {
return true;
}
}
@@ -527,7 +537,7 @@ char_u *concat_str(const char_u *restrict str1, const char_u *restrict str2)
static const char *const e_printf =
- N_("E766: Insufficient arguments for printf()");
+ N_("E766: Insufficient arguments for printf()");
/// Get number argument from idxp entry in tvs
///
@@ -606,15 +616,14 @@ static const void *tv_ptr(const typval_T *const tvs, int *const idxp)
FUNC_ATTR_NONNULL_ALL FUNC_ATTR_WARN_UNUSED_RESULT
{
#define OFF(attr) offsetof(union typval_vval_union, attr)
- STATIC_ASSERT(
- OFF(v_string) == OFF(v_list)
- && OFF(v_string) == OFF(v_dict)
- && OFF(v_string) == OFF(v_partial)
- && sizeof(tvs[0].vval.v_string) == sizeof(tvs[0].vval.v_list)
- && sizeof(tvs[0].vval.v_string) == sizeof(tvs[0].vval.v_dict)
- && sizeof(tvs[0].vval.v_string) == sizeof(tvs[0].vval.v_partial),
- "Strings, dictionaries, lists and partials are expected to be pointers, "
- "so that all three of them can be accessed via v_string");
+ STATIC_ASSERT(OFF(v_string) == OFF(v_list)
+ && OFF(v_string) == OFF(v_dict)
+ && OFF(v_string) == OFF(v_partial)
+ && sizeof(tvs[0].vval.v_string) == sizeof(tvs[0].vval.v_list)
+ && sizeof(tvs[0].vval.v_string) == sizeof(tvs[0].vval.v_dict)
+ && sizeof(tvs[0].vval.v_string) == sizeof(tvs[0].vval.v_partial),
+ "Strings, dictionaries, lists and partials are expected to be pointers, "
+ "so that all three of them can be accessed via v_string");
#undef OFF
const int idx = *idxp - 1;
if (tvs[idx].v_type == VAR_UNKNOWN) {
@@ -735,8 +744,8 @@ int vim_snprintf(char *str, size_t str_m, const char *fmt, ...)
// Return the representation of infinity for printf() function:
// "-inf", "inf", "+inf", " inf", "-INF", "INF", "+INF" or " INF".
-static const char *infinity_str(bool positive, char fmt_spec,
- int force_sign, int space_for_positive)
+static const char *infinity_str(bool positive, char fmt_spec, int force_sign,
+ int space_for_positive)
{
static const char *table[] = {
"-inf", "inf", "+inf", " inf",
@@ -765,8 +774,7 @@ int vim_vsnprintf(char *str, size_t str_m, const char *fmt, va_list ap)
///
/// @return Number of bytes excluding NUL byte that would be written to the
/// string if str_m was greater or equal to the return value.
-int vim_vsnprintf_typval(
- char *str, size_t str_m, const char *fmt, va_list ap, typval_T *const tvs)
+int vim_vsnprintf_typval(char *str, size_t str_m, const char *fmt, va_list ap, typval_T *const tvs)
{
size_t str_l = 0;
bool str_avail = str_l < str_m;
@@ -800,7 +808,7 @@ int vim_vsnprintf_typval(
char length_modifier = '\0';
// temporary buffer for simple numeric->string conversion
-# define TMP_LEN 350 // 1e308 seems reasonable as the maximum printable
+#define TMP_LEN 350 // 1e308 seems reasonable as the maximum printable
char tmp[TMP_LEN];
// string address in case of string argument
@@ -832,15 +840,22 @@ int vim_vsnprintf_typval(
// parse flags
while (true) {
switch (*p) {
- case '0': zero_padding = 1; p++; continue;
- case '-': justify_left = 1; p++; continue;
- // if both '0' and '-' flags appear, '0' should be ignored
- case '+': force_sign = 1; space_for_positive = 0; p++; continue;
- case ' ': force_sign = 1; p++; continue;
- // if both ' ' and '+' flags appear, ' ' should be ignored
- case '#': alternate_form = 1; p++; continue;
- case '\'': p++; continue;
- default: break;
+ case '0':
+ zero_padding = 1; p++; continue;
+ case '-':
+ justify_left = 1; p++; continue;
+ // if both '0' and '-' flags appear, '0' should be ignored
+ case '+':
+ force_sign = 1; space_for_positive = 0; p++; continue;
+ case ' ':
+ force_sign = 1; p++; continue;
+ // if both ' ' and '+' flags appear, ' ' should be ignored
+ case '#':
+ alternate_form = 1; p++; continue;
+ case '\'':
+ p++; continue;
+ default:
+ break;
}
break;
}
@@ -905,444 +920,447 @@ int vim_vsnprintf_typval(
// common synonyms
switch (fmt_spec) {
- case 'i': fmt_spec = 'd'; break;
- case 'D': fmt_spec = 'd'; length_modifier = 'l'; break;
- case 'U': fmt_spec = 'u'; length_modifier = 'l'; break;
- case 'O': fmt_spec = 'o'; length_modifier = 'l'; break;
- default: break;
+ case 'i':
+ fmt_spec = 'd'; break;
+ case 'D':
+ fmt_spec = 'd'; length_modifier = 'l'; break;
+ case 'U':
+ fmt_spec = 'u'; length_modifier = 'l'; break;
+ case 'O':
+ fmt_spec = 'o'; length_modifier = 'l'; break;
+ default:
+ break;
}
switch (fmt_spec) {
- case 'b': case 'B':
- case 'd': case 'u': case 'o': case 'x': case 'X':
- if (tvs && length_modifier == '\0') {
- length_modifier = '2';
- }
+ case 'b':
+ case 'B':
+ case 'd':
+ case 'u':
+ case 'o':
+ case 'x':
+ case 'X':
+ if (tvs && length_modifier == '\0') {
+ length_modifier = '2';
+ }
}
// get parameter value, do initial processing
switch (fmt_spec) {
- // '%' and 'c' behave similar to 's' regarding flags and field widths
- case '%': case 'c': case 's': case 'S':
- str_arg_l = 1;
- switch (fmt_spec) {
- case '%':
- str_arg = p;
- break;
-
- case 'c': {
- const int j = tvs ? (int)tv_nr(tvs, &arg_idx) : va_arg(ap, int);
- // standard demands unsigned char
- uchar_arg = (unsigned char)j;
- str_arg = (char *)&uchar_arg;
- break;
- }
+ // '%' and 'c' behave similar to 's' regarding flags and field widths
+ case '%':
+ case 'c':
+ case 's':
+ case 'S':
+ str_arg_l = 1;
+ switch (fmt_spec) {
+ case '%':
+ str_arg = p;
+ break;
- case 's':
- case 'S':
- str_arg = tvs ? tv_str(tvs, &arg_idx, &tofree)
- : va_arg(ap, const char *);
- if (!str_arg) {
- str_arg = "[NULL]";
- str_arg_l = 6;
- } else if (!precision_specified) {
- // make sure not to address string beyond the specified
- // precision
- str_arg_l = strlen(str_arg);
- } else if (precision == 0) {
- // truncate string if necessary as requested by precision
- str_arg_l = 0;
- } else {
- // memchr on HP does not like n > 2^31
- // TODO(elmart): check if this still holds / is relevant
- str_arg_l = (size_t)((char *)xmemscan(str_arg,
- NUL,
- MIN(precision,
- 0x7fffffff))
- - str_arg);
- }
- if (fmt_spec == 'S') {
- if (min_field_width != 0) {
- min_field_width += (strlen(str_arg)
- - mb_string2cells((char_u *)str_arg));
- }
- if (precision) {
- char_u *p1;
- size_t i = 0;
-
- for (p1 = (char_u *)str_arg; *p1;
- p1 += mb_ptr2len(p1)) {
- i += (size_t)utf_ptr2cells(p1);
- if (i > precision) {
- break;
- }
- }
- str_arg_l = (size_t)(p1 - (char_u *)str_arg);
+ case 'c': {
+ const int j = tvs ? (int)tv_nr(tvs, &arg_idx) : va_arg(ap, int);
+ // standard demands unsigned char
+ uchar_arg = (unsigned char)j;
+ str_arg = (char *)&uchar_arg;
+ break;
+ }
+
+ case 's':
+ case 'S':
+ str_arg = tvs ? tv_str(tvs, &arg_idx, &tofree)
+ : va_arg(ap, const char *);
+ if (!str_arg) {
+ str_arg = "[NULL]";
+ str_arg_l = 6;
+ } else if (!precision_specified) {
+ // make sure not to address string beyond the specified
+ // precision
+ str_arg_l = strlen(str_arg);
+ } else if (precision == 0) {
+ // truncate string if necessary as requested by precision
+ str_arg_l = 0;
+ } else {
+ // memchr on HP does not like n > 2^31
+ // TODO(elmart): check if this still holds / is relevant
+ str_arg_l = (size_t)((char *)xmemscan(str_arg,
+ NUL,
+ MIN(precision,
+ 0x7fffffff))
+ - str_arg);
+ }
+ if (fmt_spec == 'S') {
+ if (min_field_width != 0) {
+ min_field_width += (strlen(str_arg)
+ - mb_string2cells((char_u *)str_arg));
+ }
+ if (precision) {
+ char_u *p1;
+ size_t i = 0;
+
+ for (p1 = (char_u *)str_arg; *p1;
+ p1 += mb_ptr2len(p1)) {
+ i += (size_t)utf_ptr2cells(p1);
+ if (i > precision) {
+ break;
}
}
- break;
-
- default:
- break;
+ str_arg_l = (size_t)(p1 - (char_u *)str_arg);
+ }
}
break;
- case 'd':
- case 'u':
- case 'b': case 'B':
- case 'o':
- case 'x': case 'X':
- case 'p': {
- // u, b, B, o, x, X and p conversion specifiers imply
- // the value is unsigned; d implies a signed value
-
- // 0 if numeric argument is zero (or if pointer is NULL for 'p'),
- // +1 if greater than zero (or non NULL for 'p'),
- // -1 if negative (unsigned argument is never negative)
- int arg_sign = 0;
-
- intmax_t arg = 0;
- uintmax_t uarg = 0;
-
- // only defined for p conversion
- const void *ptr_arg = NULL;
-
- if (fmt_spec == 'p') {
- ptr_arg = tvs ? tv_ptr(tvs, &arg_idx) : va_arg(ap, void *);
- if (ptr_arg) {
- arg_sign = 1;
- }
- } else if (fmt_spec == 'd') {
- // signed
- switch (length_modifier) {
- case '\0': {
- arg = (int)(tvs ? tv_nr(tvs, &arg_idx) : va_arg(ap, int));
- break;
- }
- case 'h': {
- // char and short arguments are passed as int16_t
- arg = (int16_t)(tvs ? tv_nr(tvs, &arg_idx) : va_arg(ap, int));
- break;
- }
- case 'l': {
- arg = (tvs ? (long)tv_nr(tvs, &arg_idx) : va_arg(ap, long));
- break;
- }
- case '2': {
- arg = (
- tvs
+ default:
+ break;
+ }
+ break;
+
+ case 'd':
+ case 'u':
+ case 'b':
+ case 'B':
+ case 'o':
+ case 'x':
+ case 'X':
+ case 'p': {
+ // u, b, B, o, x, X and p conversion specifiers imply
+ // the value is unsigned; d implies a signed value
+
+ // 0 if numeric argument is zero (or if pointer is NULL for 'p'),
+ // +1 if greater than zero (or non NULL for 'p'),
+ // -1 if negative (unsigned argument is never negative)
+ int arg_sign = 0;
+
+ intmax_t arg = 0;
+ uintmax_t uarg = 0;
+
+ // only defined for p conversion
+ const void *ptr_arg = NULL;
+
+ if (fmt_spec == 'p') {
+ ptr_arg = tvs ? tv_ptr(tvs, &arg_idx) : va_arg(ap, void *);
+ if (ptr_arg) {
+ arg_sign = 1;
+ }
+ } else if (fmt_spec == 'd') {
+ // signed
+ switch (length_modifier) {
+ case '\0':
+ arg = (int)(tvs ? tv_nr(tvs, &arg_idx) : va_arg(ap, int));
+ break;
+ case 'h':
+ // char and short arguments are passed as int16_t
+ arg = (int16_t)(tvs ? tv_nr(tvs, &arg_idx) : va_arg(ap, int));
+ break;
+ case 'l':
+ arg = (tvs ? (long)tv_nr(tvs, &arg_idx) : va_arg(ap, long));
+ break;
+ case '2':
+ arg = (
+ tvs
? (long long)tv_nr(tvs, &arg_idx) // NOLINT (runtime/int)
: va_arg(ap, long long)); // NOLINT (runtime/int)
- break;
- }
- case 'z': {
- arg = (tvs
+ break;
+ case 'z':
+ arg = (tvs
? (ptrdiff_t)tv_nr(tvs, &arg_idx)
: va_arg(ap, ptrdiff_t));
- break;
- }
- }
- if (arg > 0) {
- arg_sign = 1;
- } else if (arg < 0) {
- arg_sign = -1;
- }
- } else {
- // unsigned
- switch (length_modifier) {
- case '\0': {
- uarg = (unsigned int)(tvs
+ break;
+ }
+ if (arg > 0) {
+ arg_sign = 1;
+ } else if (arg < 0) {
+ arg_sign = -1;
+ }
+ } else {
+ // unsigned
+ switch (length_modifier) {
+ case '\0':
+ uarg = (unsigned int)(tvs
? tv_nr(tvs, &arg_idx)
: va_arg(ap, unsigned int));
- break;
- }
- case 'h': {
- uarg = (uint16_t)(tvs
+ break;
+ case 'h':
+ uarg = (uint16_t)(tvs
? tv_nr(tvs, &arg_idx)
: va_arg(ap, unsigned int));
- break;
- }
- case 'l': {
- uarg = (tvs
+ break;
+ case 'l':
+ uarg = (tvs
? (unsigned long)tv_nr(tvs, &arg_idx)
: va_arg(ap, unsigned long));
- break;
- }
- case '2': {
- uarg = (uintmax_t)(unsigned long long)( // NOLINT (runtime/int)
- tvs
+ break;
+ case '2':
+ uarg = (uintmax_t)(unsigned long long)( // NOLINT (runtime/int)
+ tvs
? ((unsigned long long) // NOLINT (runtime/int)
tv_nr(tvs, &arg_idx))
: va_arg(ap, unsigned long long)); // NOLINT (runtime/int)
- break;
- }
- case 'z': {
- uarg = (tvs
+ break;
+ case 'z':
+ uarg = (tvs
? (size_t)tv_nr(tvs, &arg_idx)
: va_arg(ap, size_t));
- break;
- }
- }
- arg_sign = (uarg != 0);
+ break;
}
+ arg_sign = (uarg != 0);
+ }
- str_arg = tmp;
- str_arg_l = 0;
+ str_arg = tmp;
+ str_arg_l = 0;
- // For d, i, u, o, x, and X conversions, if precision is specified,
- // '0' flag should be ignored. This is so with Solaris 2.6, Digital
- // UNIX 4.0, HPUX 10, Linux, FreeBSD, NetBSD; but not with Perl.
- if (precision_specified) {
- zero_padding = 0;
- }
+ // For d, i, u, o, x, and X conversions, if precision is specified,
+ // '0' flag should be ignored. This is so with Solaris 2.6, Digital
+ // UNIX 4.0, HPUX 10, Linux, FreeBSD, NetBSD; but not with Perl.
+ if (precision_specified) {
+ zero_padding = 0;
+ }
- if (fmt_spec == 'd') {
- if (force_sign && arg_sign >= 0) {
- tmp[str_arg_l++] = space_for_positive ? ' ' : '+';
- }
- // leave negative numbers for snprintf to handle, to
- // avoid handling tricky cases like (short int)-32768
- } else if (alternate_form) {
- if (arg_sign != 0 && (fmt_spec == 'x' || fmt_spec == 'X'
- || fmt_spec == 'b' || fmt_spec == 'B')) {
- tmp[str_arg_l++] = '0';
- tmp[str_arg_l++] = fmt_spec;
- }
- // alternate form should have no effect for p * conversion, but ...
+ if (fmt_spec == 'd') {
+ if (force_sign && arg_sign >= 0) {
+ tmp[str_arg_l++] = space_for_positive ? ' ' : '+';
}
-
- zero_padding_insertion_ind = str_arg_l;
- if (!precision_specified) {
- precision = 1; // default precision is 1
+ // leave negative numbers for snprintf to handle, to
+ // avoid handling tricky cases like (short int)-32768
+ } else if (alternate_form) {
+ if (arg_sign != 0 && (fmt_spec == 'x' || fmt_spec == 'X'
+ || fmt_spec == 'b' || fmt_spec == 'B')) {
+ tmp[str_arg_l++] = '0';
+ tmp[str_arg_l++] = fmt_spec;
}
- if (precision == 0 && arg_sign == 0) {
- // when zero value is formatted with an explicit precision 0,
- // resulting formatted string is empty (d, i, u, b, B, o, x, X, p)
- } else {
- switch (fmt_spec) {
- case 'p': { // pointer
- str_arg_l += (size_t)snprintf(tmp + str_arg_l,
- sizeof(tmp) - str_arg_l,
- "%p", ptr_arg);
- break;
- }
- case 'd': { // signed
- str_arg_l += (size_t)snprintf(tmp + str_arg_l,
- sizeof(tmp) - str_arg_l,
- "%" PRIdMAX, arg);
- break;
- }
- case 'b': case 'B': { // binary
- size_t bits = 0;
- for (bits = sizeof(uintmax_t) * 8; bits > 0; bits--) {
- if ((uarg >> (bits - 1)) & 0x1) {
- break;
- }
- }
+ // alternate form should have no effect for p * conversion, but ...
+ }
- while (bits > 0) {
- tmp[str_arg_l++] = ((uarg >> --bits) & 0x1) ? '1' : '0';
- }
- break;
- }
- default: { // unsigned
- // construct a simple format string for snprintf
- char f[] = "%" PRIuMAX;
- f[sizeof("%" PRIuMAX) - 1 - 1] = fmt_spec;
- assert(PRIuMAX[sizeof(PRIuMAX) - 1 - 1] == 'u');
- str_arg_l += (size_t)snprintf(tmp + str_arg_l,
- sizeof(tmp) - str_arg_l,
- f, uarg);
+ zero_padding_insertion_ind = str_arg_l;
+ if (!precision_specified) {
+ precision = 1; // default precision is 1
+ }
+ if (precision == 0 && arg_sign == 0) {
+ // when zero value is formatted with an explicit precision 0,
+ // resulting formatted string is empty (d, i, u, b, B, o, x, X, p)
+ } else {
+ switch (fmt_spec) {
+ case 'p': // pointer
+ str_arg_l += (size_t)snprintf(tmp + str_arg_l,
+ sizeof(tmp) - str_arg_l,
+ "%p", ptr_arg);
+ break;
+ case 'd': // signed
+ str_arg_l += (size_t)snprintf(tmp + str_arg_l,
+ sizeof(tmp) - str_arg_l,
+ "%" PRIdMAX, arg);
+ break;
+ case 'b':
+ case 'B': { // binary
+ size_t bits = 0;
+ for (bits = sizeof(uintmax_t) * 8; bits > 0; bits--) {
+ if ((uarg >> (bits - 1)) & 0x1) {
break;
}
}
- assert(str_arg_l < sizeof(tmp));
- // include the optional minus sign and possible "0x" in the region
- // before the zero padding insertion point
- if (zero_padding_insertion_ind < str_arg_l
- && tmp[zero_padding_insertion_ind] == '-') {
- zero_padding_insertion_ind++;
- }
- if (zero_padding_insertion_ind + 1 < str_arg_l
- && tmp[zero_padding_insertion_ind] == '0'
- && (tmp[zero_padding_insertion_ind + 1] == 'x'
- || tmp[zero_padding_insertion_ind + 1] == 'X'
- || tmp[zero_padding_insertion_ind + 1] == 'b'
- || tmp[zero_padding_insertion_ind + 1] == 'B')) {
- zero_padding_insertion_ind += 2;
+ while (bits > 0) {
+ tmp[str_arg_l++] = ((uarg >> --bits) & 0x1) ? '1' : '0';
}
+ break;
+ }
+ default: { // unsigned
+ // construct a simple format string for snprintf
+ char f[] = "%" PRIuMAX;
+ f[sizeof("%" PRIuMAX) - 1 - 1] = fmt_spec;
+ assert(PRIuMAX[sizeof(PRIuMAX) - 1 - 1] == 'u');
+ str_arg_l += (size_t)snprintf(tmp + str_arg_l,
+ sizeof(tmp) - str_arg_l,
+ f, uarg);
+ break;
+ }
}
+ assert(str_arg_l < sizeof(tmp));
- {
- size_t num_of_digits = str_arg_l - zero_padding_insertion_ind;
-
- if (alternate_form && fmt_spec == 'o'
- // unless zero is already the first character
- && !(zero_padding_insertion_ind < str_arg_l
- && tmp[zero_padding_insertion_ind] == '0')) {
- // assure leading zero for alternate-form octal numbers
- if (!precision_specified
- || precision < num_of_digits + 1) {
- // precision is increased to force the first character to be
- // zero, except if a zero value is formatted with an explicit
- // precision of zero
- precision = num_of_digits + 1;
- }
- }
- // zero padding to specified precision?
- if (num_of_digits < precision) {
- number_of_zeros_to_pad = precision - num_of_digits;
- }
+ // include the optional minus sign and possible "0x" in the region
+ // before the zero padding insertion point
+ if (zero_padding_insertion_ind < str_arg_l
+ && tmp[zero_padding_insertion_ind] == '-') {
+ zero_padding_insertion_ind++;
}
- // zero padding to specified minimal field width?
- if (!justify_left && zero_padding) {
- const int n = (int)(min_field_width - (str_arg_l
- + number_of_zeros_to_pad));
- if (n > 0) {
- number_of_zeros_to_pad += (size_t)n;
- }
+ if (zero_padding_insertion_ind + 1 < str_arg_l
+ && tmp[zero_padding_insertion_ind] == '0'
+ && (tmp[zero_padding_insertion_ind + 1] == 'x'
+ || tmp[zero_padding_insertion_ind + 1] == 'X'
+ || tmp[zero_padding_insertion_ind + 1] == 'b'
+ || tmp[zero_padding_insertion_ind + 1] == 'B')) {
+ zero_padding_insertion_ind += 2;
}
- break;
}
- case 'f':
- case 'F':
- case 'e':
- case 'E':
- case 'g':
- case 'G':
- {
- // floating point
- char format[40];
- int remove_trailing_zeroes = false;
-
- double f = tvs ? tv_float(tvs, &arg_idx) : va_arg(ap, double);
- double abs_f = f < 0 ? -f : f;
-
- if (fmt_spec == 'g' || fmt_spec == 'G') {
- // can't use %g directly, cause it prints "1.0" as "1"
- if ((abs_f >= 0.001 && abs_f < 10000000.0) || abs_f == 0.0) {
- fmt_spec = ASCII_ISUPPER(fmt_spec) ? 'F' : 'f';
- } else {
- fmt_spec = fmt_spec == 'g' ? 'e' : 'E';
- }
- remove_trailing_zeroes = true;
+ {
+ size_t num_of_digits = str_arg_l - zero_padding_insertion_ind;
+
+ if (alternate_form && fmt_spec == 'o'
+ // unless zero is already the first character
+ && !(zero_padding_insertion_ind < str_arg_l
+ && tmp[zero_padding_insertion_ind] == '0')) {
+ // assure leading zero for alternate-form octal numbers
+ if (!precision_specified
+ || precision < num_of_digits + 1) {
+ // precision is increased to force the first character to be
+ // zero, except if a zero value is formatted with an explicit
+ // precision of zero
+ precision = num_of_digits + 1;
}
+ }
+ // zero padding to specified precision?
+ if (num_of_digits < precision) {
+ number_of_zeros_to_pad = precision - num_of_digits;
+ }
+ }
+ // zero padding to specified minimal field width?
+ if (!justify_left && zero_padding) {
+ const int n = (int)(min_field_width - (str_arg_l
+ + number_of_zeros_to_pad));
+ if (n > 0) {
+ number_of_zeros_to_pad += (size_t)n;
+ }
+ }
+ break;
+ }
- if (xisinf(f)
- || (strchr("fF", fmt_spec) != NULL && abs_f > 1.0e307)) {
- xstrlcpy(tmp, infinity_str(f > 0.0, fmt_spec,
- force_sign, space_for_positive),
- sizeof(tmp));
- str_arg_l = strlen(tmp);
- zero_padding = 0;
- } else if (xisnan(f)) {
- // Not a number: nan or NAN
- memmove(tmp, ASCII_ISUPPER(fmt_spec) ? "NAN" : "nan", 4);
- str_arg_l = 3;
- zero_padding = 0;
- } else {
- // Regular float number
- format[0] = '%';
- size_t l = 1;
- if (force_sign) {
- format[l++] = space_for_positive ? ' ' : '+';
- }
- if (precision_specified) {
- size_t max_prec = TMP_LEN - 10;
+ case 'f':
+ case 'F':
+ case 'e':
+ case 'E':
+ case 'g':
+ case 'G': {
+ // floating point
+ char format[40];
+ int remove_trailing_zeroes = false;
+
+ double f = tvs ? tv_float(tvs, &arg_idx) : va_arg(ap, double);
+ double abs_f = f < 0 ? -f : f;
+
+ if (fmt_spec == 'g' || fmt_spec == 'G') {
+ // can't use %g directly, cause it prints "1.0" as "1"
+ if ((abs_f >= 0.001 && abs_f < 10000000.0) || abs_f == 0.0) {
+ fmt_spec = ASCII_ISUPPER(fmt_spec) ? 'F' : 'f';
+ } else {
+ fmt_spec = fmt_spec == 'g' ? 'e' : 'E';
+ }
+ remove_trailing_zeroes = true;
+ }
- // make sure we don't get more digits than we have room for
- if ((fmt_spec == 'f' || fmt_spec == 'F') && abs_f > 1.0) {
- max_prec -= (size_t)log10(abs_f);
- }
- if (precision > max_prec) {
- precision = max_prec;
- }
- l += (size_t)snprintf(format + l, sizeof(format) - l, ".%d",
- (int)precision);
- }
+ if (xisinf(f)
+ || (strchr("fF", fmt_spec) != NULL && abs_f > 1.0e307)) {
+ xstrlcpy(tmp, infinity_str(f > 0.0, fmt_spec,
+ force_sign, space_for_positive),
+ sizeof(tmp));
+ str_arg_l = strlen(tmp);
+ zero_padding = 0;
+ } else if (xisnan(f)) {
+ // Not a number: nan or NAN
+ memmove(tmp, ASCII_ISUPPER(fmt_spec) ? "NAN" : "nan", 4);
+ str_arg_l = 3;
+ zero_padding = 0;
+ } else {
+ // Regular float number
+ format[0] = '%';
+ size_t l = 1;
+ if (force_sign) {
+ format[l++] = space_for_positive ? ' ' : '+';
+ }
+ if (precision_specified) {
+ size_t max_prec = TMP_LEN - 10;
- // Cast to char to avoid a conversion warning on Ubuntu 12.04.
- assert(l + 1 < sizeof(format));
- format[l] = (char)(fmt_spec == 'F' ? 'f' : fmt_spec);
- format[l + 1] = NUL;
+ // make sure we don't get more digits than we have room for
+ if ((fmt_spec == 'f' || fmt_spec == 'F') && abs_f > 1.0) {
+ max_prec -= (size_t)log10(abs_f);
+ }
+ if (precision > max_prec) {
+ precision = max_prec;
+ }
+ l += (size_t)snprintf(format + l, sizeof(format) - l, ".%d",
+ (int)precision);
+ }
- str_arg_l = (size_t)snprintf(tmp, sizeof(tmp), format, f);
- assert(str_arg_l < sizeof(tmp));
+ // Cast to char to avoid a conversion warning on Ubuntu 12.04.
+ assert(l + 1 < sizeof(format));
+ format[l] = (char)(fmt_spec == 'F' ? 'f' : fmt_spec);
+ format[l + 1] = NUL;
- if (remove_trailing_zeroes) {
- int i;
- char *tp;
+ str_arg_l = (size_t)snprintf(tmp, sizeof(tmp), format, f);
+ assert(str_arg_l < sizeof(tmp));
- // using %g or %G: remove superfluous zeroes
- if (fmt_spec == 'f' || fmt_spec == 'F') {
- tp = tmp + str_arg_l - 1;
- } else {
- tp = (char *)vim_strchr((char_u *)tmp,
- fmt_spec == 'e' ? 'e' : 'E');
- if (tp) {
- // remove superfluous '+' and leading zeroes from exponent
- if (tp[1] == '+') {
- // change "1.0e+07" to "1.0e07"
- STRMOVE(tp + 1, tp + 2);
- str_arg_l--;
- }
- i = (tp[1] == '-') ? 2 : 1;
- while (tp[i] == '0') {
- // change "1.0e07" to "1.0e7"
- STRMOVE(tp + i, tp + i + 1);
- str_arg_l--;
- }
- tp--;
- }
- }
+ if (remove_trailing_zeroes) {
+ int i;
+ char *tp;
- if (tp != NULL && !precision_specified) {
- // remove trailing zeroes, but keep the one just after a dot
- while (tp > tmp + 2 && *tp == '0' && tp[-1] != '.') {
- STRMOVE(tp, tp + 1);
- tp--;
- str_arg_l--;
- }
+ // using %g or %G: remove superfluous zeroes
+ if (fmt_spec == 'f' || fmt_spec == 'F') {
+ tp = tmp + str_arg_l - 1;
+ } else {
+ tp = (char *)vim_strchr((char_u *)tmp,
+ fmt_spec == 'e' ? 'e' : 'E');
+ if (tp) {
+ // remove superfluous '+' and leading zeroes from exponent
+ if (tp[1] == '+') {
+ // change "1.0e+07" to "1.0e07"
+ STRMOVE(tp + 1, tp + 2);
+ str_arg_l--;
}
- } else {
- // Be consistent: some printf("%e") use 1.0e+12 and some
- // 1.0e+012; remove one zero in the last case.
- char *tp = (char *)vim_strchr((char_u *)tmp,
- fmt_spec == 'e' ? 'e' : 'E');
- if (tp && (tp[1] == '+' || tp[1] == '-') && tp[2] == '0'
- && ascii_isdigit(tp[3]) && ascii_isdigit(tp[4])) {
- STRMOVE(tp + 2, tp + 3);
+ i = (tp[1] == '-') ? 2 : 1;
+ while (tp[i] == '0') {
+ // change "1.0e07" to "1.0e7"
+ STRMOVE(tp + i, tp + i + 1);
str_arg_l--;
}
+ tp--;
}
}
- if (zero_padding && min_field_width > str_arg_l
- && (tmp[0] == '-' || force_sign)) {
- // Padding 0's should be inserted after the sign.
- number_of_zeros_to_pad = min_field_width - str_arg_l;
- zero_padding_insertion_ind = 1;
+
+ if (tp != NULL && !precision_specified) {
+ // remove trailing zeroes, but keep the one just after a dot
+ while (tp > tmp + 2 && *tp == '0' && tp[-1] != '.') {
+ STRMOVE(tp, tp + 1);
+ tp--;
+ str_arg_l--;
+ }
+ }
+ } else {
+ // Be consistent: some printf("%e") use 1.0e+12 and some
+ // 1.0e+012; remove one zero in the last case.
+ char *tp = (char *)vim_strchr((char_u *)tmp,
+ fmt_spec == 'e' ? 'e' : 'E');
+ if (tp && (tp[1] == '+' || tp[1] == '-') && tp[2] == '0'
+ && ascii_isdigit(tp[3]) && ascii_isdigit(tp[4])) {
+ STRMOVE(tp + 2, tp + 3);
+ str_arg_l--;
}
- str_arg = tmp;
- break;
}
+ }
+ if (zero_padding && min_field_width > str_arg_l
+ && (tmp[0] == '-' || force_sign)) {
+ // Padding 0's should be inserted after the sign.
+ number_of_zeros_to_pad = min_field_width - str_arg_l;
+ zero_padding_insertion_ind = 1;
+ }
+ str_arg = tmp;
+ break;
+ }
- default:
- // unrecognized conversion specifier, keep format string as-is
- zero_padding = 0; // turn zero padding off for non-numeric conversion
- justify_left = 1;
- min_field_width = 0; // reset flags
-
- // discard the unrecognized conversion, just keep
- // the unrecognized conversion character
- str_arg = p;
- str_arg_l = 0;
- if (*p) {
- str_arg_l++; // include invalid conversion specifier
- }
- // unchanged if not at end-of-string
- break;
+ default:
+ // unrecognized conversion specifier, keep format string as-is
+ zero_padding = 0; // turn zero padding off for non-numeric conversion
+ justify_left = 1;
+ min_field_width = 0; // reset flags
+
+ // discard the unrecognized conversion, just keep
+ // the unrecognized conversion character
+ str_arg = p;
+ str_arg_l = 0;
+ if (*p) {
+ str_arg_l++; // include invalid conversion specifier
+ }
+ // unchanged if not at end-of-string
+ break;
}
if (*p) {
diff --git a/src/nvim/terminal.c b/src/nvim/terminal.c
index 3335fa500a..6f19a9209e 100644
--- a/src/nvim/terminal.c
+++ b/src/nvim/terminal.c
@@ -37,45 +37,44 @@
// Some code from pangoterm http://www.leonerd.org.uk/code/pangoterm
#include <assert.h>
-#include <stdio.h>
-#include <stdint.h>
#include <stdbool.h>
-
+#include <stdint.h>
+#include <stdio.h>
#include <vterm.h>
-#include "nvim/log.h"
-#include "nvim/vim.h"
-#include "nvim/terminal.h"
-#include "nvim/message.h"
-#include "nvim/memory.h"
-#include "nvim/option.h"
-#include "nvim/highlight.h"
-#include "nvim/macros.h"
-#include "nvim/mbyte.h"
+#include "nvim/api/private/helpers.h"
+#include "nvim/ascii.h"
#include "nvim/buffer.h"
#include "nvim/change.h"
-#include "nvim/ascii.h"
+#include "nvim/edit.h"
+#include "nvim/event/loop.h"
+#include "nvim/event/time.h"
+#include "nvim/ex_cmds.h"
+#include "nvim/ex_docmd.h"
+#include "nvim/fileio.h"
#include "nvim/getchar.h"
-#include "nvim/ui.h"
-#include "nvim/syntax.h"
-#include "nvim/screen.h"
+#include "nvim/highlight.h"
#include "nvim/keymap.h"
-#include "nvim/edit.h"
-#include "nvim/mouse.h"
-#include "nvim/memline.h"
+#include "nvim/log.h"
+#include "nvim/macros.h"
+#include "nvim/main.h"
#include "nvim/map.h"
+#include "nvim/mbyte.h"
+#include "nvim/memline.h"
+#include "nvim/memory.h"
+#include "nvim/message.h"
#include "nvim/misc1.h"
+#include "nvim/mouse.h"
#include "nvim/move.h"
-#include "nvim/main.h"
+#include "nvim/option.h"
+#include "nvim/os/input.h"
+#include "nvim/screen.h"
#include "nvim/state.h"
-#include "nvim/ex_docmd.h"
-#include "nvim/ex_cmds.h"
+#include "nvim/syntax.h"
+#include "nvim/terminal.h"
+#include "nvim/ui.h"
+#include "nvim/vim.h"
#include "nvim/window.h"
-#include "nvim/fileio.h"
-#include "nvim/event/loop.h"
-#include "nvim/event/time.h"
-#include "nvim/os/input.h"
-#include "nvim/api/private/helpers.h"
typedef struct terminal_state {
VimState state;
@@ -210,7 +209,7 @@ Terminal *terminal_open(buf_T *buf, TerminalOptions opts)
buf->b_p_ma = false; // 'nomodifiable'
buf->b_p_ul = -1; // 'undolevels'
buf->b_p_scbk = // 'scrollback' (initialize local from global)
- (p_scbk < 0) ? 10000 : MAX(1, p_scbk);
+ (p_scbk < 0) ? 10000 : MAX(1, p_scbk);
buf->b_p_tw = 0; // 'textwidth'
set_option_value("wrap", false, NULL, OPT_LOCAL);
set_option_value("list", false, NULL, OPT_LOCAL);
@@ -452,56 +451,56 @@ static int terminal_execute(VimState *state, int key)
TerminalState *s = (TerminalState *)state;
switch (key) {
- case K_LEFTMOUSE:
- case K_LEFTDRAG:
- case K_LEFTRELEASE:
- case K_MOUSEMOVE:
- case K_MIDDLEMOUSE:
- case K_MIDDLEDRAG:
- case K_MIDDLERELEASE:
- case K_RIGHTMOUSE:
- case K_RIGHTDRAG:
- case K_RIGHTRELEASE:
- case K_MOUSEDOWN:
- case K_MOUSEUP:
- if (send_mouse_event(s->term, key)) {
- return 0;
- }
- break;
-
- case K_EVENT:
- // We cannot let an event free the terminal yet. It is still needed.
- s->term->refcount++;
- state_handle_k_event();
- s->term->refcount--;
- if (s->term->buf_handle == 0) {
- s->close = true;
- return 0;
- }
- break;
+ case K_LEFTMOUSE:
+ case K_LEFTDRAG:
+ case K_LEFTRELEASE:
+ case K_MOUSEMOVE:
+ case K_MIDDLEMOUSE:
+ case K_MIDDLEDRAG:
+ case K_MIDDLERELEASE:
+ case K_RIGHTMOUSE:
+ case K_RIGHTDRAG:
+ case K_RIGHTRELEASE:
+ case K_MOUSEDOWN:
+ case K_MOUSEUP:
+ if (send_mouse_event(s->term, key)) {
+ return 0;
+ }
+ break;
+
+ case K_EVENT:
+ // We cannot let an event free the terminal yet. It is still needed.
+ s->term->refcount++;
+ state_handle_k_event();
+ s->term->refcount--;
+ if (s->term->buf_handle == 0) {
+ s->close = true;
+ return 0;
+ }
+ break;
- case K_COMMAND:
- do_cmdline(NULL, getcmdkeycmd, NULL, 0);
- break;
+ case K_COMMAND:
+ do_cmdline(NULL, getcmdkeycmd, NULL, 0);
+ break;
- case Ctrl_N:
- if (s->got_bsl) {
- return 0;
- }
- FALLTHROUGH;
+ case Ctrl_N:
+ if (s->got_bsl) {
+ return 0;
+ }
+ FALLTHROUGH;
- default:
- if (key == Ctrl_BSL && !s->got_bsl) {
- s->got_bsl = true;
- break;
- }
- if (s->term->closed) {
- s->close = true;
- return 0;
- }
+ default:
+ if (key == Ctrl_BSL && !s->got_bsl) {
+ s->got_bsl = true;
+ break;
+ }
+ if (s->term->closed) {
+ s->close = true;
+ return 0;
+ }
- s->got_bsl = false;
- terminal_send_key(s->term, key);
+ s->got_bsl = false;
+ terminal_send_key(s->term, key);
}
if (curbuf->terminal == NULL) {
@@ -554,30 +553,30 @@ static bool is_filter_char(int c)
{
unsigned int flag = 0;
switch (c) {
- case 0x08:
- flag = TPF_BS;
- break;
- case 0x09:
- flag = TPF_HT;
- break;
- case 0x0A:
- case 0x0D:
- break;
- case 0x0C:
- flag = TPF_FF;
- break;
- case 0x1b:
- flag = TPF_ESC;
- break;
- case 0x7F:
- flag = TPF_DEL;
- break;
- default:
- if (c < ' ') {
- flag = TPF_C0;
- } else if (c >= 0x80 && c <= 0x9F) {
- flag = TPF_C1;
- }
+ case 0x08:
+ flag = TPF_BS;
+ break;
+ case 0x09:
+ flag = TPF_HT;
+ break;
+ case 0x0A:
+ case 0x0D:
+ break;
+ case 0x0C:
+ flag = TPF_FF;
+ break;
+ case 0x1b:
+ flag = TPF_ESC;
+ break;
+ case 0x7F:
+ flag = TPF_DEL;
+ break;
+ default:
+ if (c < ' ') {
+ flag = TPF_C0;
+ } else if (c >= 0x80 && c <= 0x9F) {
+ flag = TPF_C1;
+ }
}
return !!(tpf_flags & flag);
}
@@ -666,8 +665,7 @@ static int get_rgb(VTermState *state, VTermColor color)
}
-void terminal_get_line_attributes(Terminal *term, win_T *wp, int linenr,
- int *term_attrs)
+void terminal_get_line_attributes(Terminal *term, win_T *wp, int linenr, int *term_attrs)
{
int height, width;
vterm_get_size(term->vt, &height, &width);
@@ -701,12 +699,12 @@ void terminal_get_line_attributes(Terminal *term, win_T *wp, int linenr,
bool bg_set = vt_bg_idx && vt_bg_idx <= 16 && term->color_set[vt_bg_idx-1];
int hl_attrs = (cell.attrs.bold ? HL_BOLD : 0)
- | (cell.attrs.italic ? HL_ITALIC : 0)
- | (cell.attrs.reverse ? HL_INVERSE : 0)
- | (cell.attrs.underline ? HL_UNDERLINE : 0)
- | (cell.attrs.strike ? HL_STRIKETHROUGH: 0)
- | ((fg_indexed && !fg_set) ? HL_FG_INDEXED : 0)
- | ((bg_indexed && !bg_set) ? HL_BG_INDEXED : 0);
+ | (cell.attrs.italic ? HL_ITALIC : 0)
+ | (cell.attrs.reverse ? HL_INVERSE : 0)
+ | (cell.attrs.underline ? HL_UNDERLINE : 0)
+ | (cell.attrs.strike ? HL_STRIKETHROUGH: 0)
+ | ((fg_indexed && !fg_set) ? HL_FG_INDEXED : 0)
+ | ((bg_indexed && !bg_set) ? HL_BG_INDEXED : 0);
int attr_id = 0;
@@ -757,12 +755,11 @@ static int term_damage(VTermRect rect, void *data)
static int term_moverect(VTermRect dest, VTermRect src, void *data)
{
invalidate_terminal(data, MIN(dest.start_row, src.start_row),
- MAX(dest.end_row, src.end_row));
+ MAX(dest.end_row, src.end_row));
return 1;
}
-static int term_movecursor(VTermPos new, VTermPos old, int visible,
- void *data)
+static int term_movecursor(VTermPos new, VTermPos old, int visible, void *data)
{
Terminal *term = data;
term->cursor.row = new.row;
@@ -791,26 +788,26 @@ static int term_settermprop(VTermProp prop, VTermValue *val, void *data)
Terminal *term = data;
switch (prop) {
- case VTERM_PROP_ALTSCREEN:
- break;
-
- case VTERM_PROP_CURSORVISIBLE:
- term->cursor.visible = val->boolean;
- invalidate_terminal(term, term->cursor.row, term->cursor.row + 1);
- break;
+ case VTERM_PROP_ALTSCREEN:
+ break;
+
+ case VTERM_PROP_CURSORVISIBLE:
+ term->cursor.visible = val->boolean;
+ invalidate_terminal(term, term->cursor.row, term->cursor.row + 1);
+ break;
+
+ case VTERM_PROP_TITLE: {
+ buf_T *buf = handle_get_buffer(term->buf_handle);
+ buf_set_term_title(buf, val->string);
+ break;
+ }
- case VTERM_PROP_TITLE: {
- buf_T *buf = handle_get_buffer(term->buf_handle);
- buf_set_term_title(buf, val->string);
- break;
- }
+ case VTERM_PROP_MOUSE:
+ term->forward_mouse = (bool)val->number;
+ break;
- case VTERM_PROP_MOUSE:
- term->forward_mouse = (bool)val->number;
- break;
-
- default:
- return 0;
+ default:
+ return 0;
}
return 1;
@@ -844,12 +841,11 @@ static int term_sb_push(int cols, const VTermScreenCell *cells, void *data)
// Make room at the start by shifting to the right.
memmove(term->sb_buffer + 1, term->sb_buffer,
- sizeof(term->sb_buffer[0]) * (term->sb_current - 1));
-
+ sizeof(term->sb_buffer[0]) * (term->sb_current - 1));
} else if (term->sb_current > 0) {
// Make room at the start by shifting to the right.
memmove(term->sb_buffer + 1, term->sb_buffer,
- sizeof(term->sb_buffer[0]) * term->sb_current);
+ sizeof(term->sb_buffer[0]) * term->sb_current);
}
if (!sbrow) {
@@ -894,7 +890,7 @@ static int term_sb_pop(int cols, VTermScreenCell *cells, void *data)
term->sb_current--;
// Forget the "popped" row by shifting the rest onto it.
memmove(term->sb_buffer, term->sb_buffer + 1,
- sizeof(term->sb_buffer[0]) * (term->sb_current));
+ sizeof(term->sb_buffer[0]) * (term->sb_current));
size_t cols_to_copy = (size_t)cols;
if (cols_to_copy > sbrow->cols) {
@@ -919,35 +915,41 @@ static int term_sb_pop(int cols, VTermScreenCell *cells, void *data)
static void convert_modifiers(int key, VTermModifier *statep)
{
- if (mod_mask & MOD_MASK_SHIFT) { *statep |= VTERM_MOD_SHIFT; }
- if (mod_mask & MOD_MASK_CTRL) { *statep |= VTERM_MOD_CTRL; }
- if (mod_mask & MOD_MASK_ALT) { *statep |= VTERM_MOD_ALT; }
+ if (mod_mask & MOD_MASK_SHIFT) {
+ *statep |= VTERM_MOD_SHIFT;
+ }
+ if (mod_mask & MOD_MASK_CTRL) {
+ *statep |= VTERM_MOD_CTRL;
+ }
+ if (mod_mask & MOD_MASK_ALT) {
+ *statep |= VTERM_MOD_ALT;
+ }
switch (key) {
- case K_S_TAB:
- case K_S_UP:
- case K_S_DOWN:
- case K_S_LEFT:
- case K_S_RIGHT:
- case K_S_F1:
- case K_S_F2:
- case K_S_F3:
- case K_S_F4:
- case K_S_F5:
- case K_S_F6:
- case K_S_F7:
- case K_S_F8:
- case K_S_F9:
- case K_S_F10:
- case K_S_F11:
- case K_S_F12:
- *statep |= VTERM_MOD_SHIFT;
- break;
-
- case K_C_LEFT:
- case K_C_RIGHT:
- *statep |= VTERM_MOD_CTRL;
- break;
+ case K_S_TAB:
+ case K_S_UP:
+ case K_S_DOWN:
+ case K_S_LEFT:
+ case K_S_RIGHT:
+ case K_S_F1:
+ case K_S_F2:
+ case K_S_F3:
+ case K_S_F4:
+ case K_S_F5:
+ case K_S_F6:
+ case K_S_F7:
+ case K_S_F8:
+ case K_S_F9:
+ case K_S_F10:
+ case K_S_F11:
+ case K_S_F12:
+ *statep |= VTERM_MOD_SHIFT;
+ break;
+
+ case K_C_LEFT:
+ case K_C_RIGHT:
+ *statep |= VTERM_MOD_CTRL;
+ break;
}
}
@@ -956,115 +958,212 @@ static VTermKey convert_key(int key, VTermModifier *statep)
convert_modifiers(key, statep);
switch (key) {
- case K_BS: return VTERM_KEY_BACKSPACE;
- case K_S_TAB: FALLTHROUGH;
- case TAB: return VTERM_KEY_TAB;
- case Ctrl_M: return VTERM_KEY_ENTER;
- case ESC: return VTERM_KEY_ESCAPE;
-
- case K_S_UP: FALLTHROUGH;
- case K_UP: return VTERM_KEY_UP;
- case K_S_DOWN: FALLTHROUGH;
- case K_DOWN: return VTERM_KEY_DOWN;
- case K_S_LEFT: FALLTHROUGH;
- case K_C_LEFT: FALLTHROUGH;
- case K_LEFT: return VTERM_KEY_LEFT;
- case K_S_RIGHT: FALLTHROUGH;
- case K_C_RIGHT: FALLTHROUGH;
- case K_RIGHT: return VTERM_KEY_RIGHT;
-
- case K_INS: return VTERM_KEY_INS;
- case K_DEL: return VTERM_KEY_DEL;
- case K_HOME: return VTERM_KEY_HOME;
- case K_END: return VTERM_KEY_END;
- case K_PAGEUP: return VTERM_KEY_PAGEUP;
- case K_PAGEDOWN: return VTERM_KEY_PAGEDOWN;
-
- case K_K0: FALLTHROUGH;
- case K_KINS: return VTERM_KEY_KP_0;
- case K_K1: FALLTHROUGH;
- case K_KEND: return VTERM_KEY_KP_1;
- case K_K2: FALLTHROUGH;
- case K_KDOWN: return VTERM_KEY_KP_2;
- case K_K3: FALLTHROUGH;
- case K_KPAGEDOWN: return VTERM_KEY_KP_3;
- case K_K4: FALLTHROUGH;
- case K_KLEFT: return VTERM_KEY_KP_4;
- case K_K5: FALLTHROUGH;
- case K_KORIGIN: return VTERM_KEY_KP_5;
- case K_K6: FALLTHROUGH;
- case K_KRIGHT: return VTERM_KEY_KP_6;
- case K_K7: FALLTHROUGH;
- case K_KHOME: return VTERM_KEY_KP_7;
- case K_K8: FALLTHROUGH;
- case K_KUP: return VTERM_KEY_KP_8;
- case K_K9: FALLTHROUGH;
- case K_KPAGEUP: return VTERM_KEY_KP_9;
- case K_KDEL: FALLTHROUGH;
- case K_KPOINT: return VTERM_KEY_KP_PERIOD;
- case K_KENTER: return VTERM_KEY_KP_ENTER;
- case K_KPLUS: return VTERM_KEY_KP_PLUS;
- case K_KMINUS: return VTERM_KEY_KP_MINUS;
- case K_KMULTIPLY: return VTERM_KEY_KP_MULT;
- case K_KDIVIDE: return VTERM_KEY_KP_DIVIDE;
-
- case K_S_F1: FALLTHROUGH;
- case K_F1: return VTERM_KEY_FUNCTION(1);
- case K_S_F2: FALLTHROUGH;
- case K_F2: return VTERM_KEY_FUNCTION(2);
- case K_S_F3: FALLTHROUGH;
- case K_F3: return VTERM_KEY_FUNCTION(3);
- case K_S_F4: FALLTHROUGH;
- case K_F4: return VTERM_KEY_FUNCTION(4);
- case K_S_F5: FALLTHROUGH;
- case K_F5: return VTERM_KEY_FUNCTION(5);
- case K_S_F6: FALLTHROUGH;
- case K_F6: return VTERM_KEY_FUNCTION(6);
- case K_S_F7: FALLTHROUGH;
- case K_F7: return VTERM_KEY_FUNCTION(7);
- case K_S_F8: FALLTHROUGH;
- case K_F8: return VTERM_KEY_FUNCTION(8);
- case K_S_F9: FALLTHROUGH;
- case K_F9: return VTERM_KEY_FUNCTION(9);
- case K_S_F10: FALLTHROUGH;
- case K_F10: return VTERM_KEY_FUNCTION(10);
- case K_S_F11: FALLTHROUGH;
- case K_F11: return VTERM_KEY_FUNCTION(11);
- case K_S_F12: FALLTHROUGH;
- case K_F12: return VTERM_KEY_FUNCTION(12);
-
- case K_F13: return VTERM_KEY_FUNCTION(13);
- case K_F14: return VTERM_KEY_FUNCTION(14);
- case K_F15: return VTERM_KEY_FUNCTION(15);
- case K_F16: return VTERM_KEY_FUNCTION(16);
- case K_F17: return VTERM_KEY_FUNCTION(17);
- case K_F18: return VTERM_KEY_FUNCTION(18);
- case K_F19: return VTERM_KEY_FUNCTION(19);
- case K_F20: return VTERM_KEY_FUNCTION(20);
- case K_F21: return VTERM_KEY_FUNCTION(21);
- case K_F22: return VTERM_KEY_FUNCTION(22);
- case K_F23: return VTERM_KEY_FUNCTION(23);
- case K_F24: return VTERM_KEY_FUNCTION(24);
- case K_F25: return VTERM_KEY_FUNCTION(25);
- case K_F26: return VTERM_KEY_FUNCTION(26);
- case K_F27: return VTERM_KEY_FUNCTION(27);
- case K_F28: return VTERM_KEY_FUNCTION(28);
- case K_F29: return VTERM_KEY_FUNCTION(29);
- case K_F30: return VTERM_KEY_FUNCTION(30);
- case K_F31: return VTERM_KEY_FUNCTION(31);
- case K_F32: return VTERM_KEY_FUNCTION(32);
- case K_F33: return VTERM_KEY_FUNCTION(33);
- case K_F34: return VTERM_KEY_FUNCTION(34);
- case K_F35: return VTERM_KEY_FUNCTION(35);
- case K_F36: return VTERM_KEY_FUNCTION(36);
- case K_F37: return VTERM_KEY_FUNCTION(37);
-
- default: return VTERM_KEY_NONE;
+ case K_BS:
+ return VTERM_KEY_BACKSPACE;
+ case K_S_TAB:
+ FALLTHROUGH;
+ case TAB:
+ return VTERM_KEY_TAB;
+ case Ctrl_M:
+ return VTERM_KEY_ENTER;
+ case ESC:
+ return VTERM_KEY_ESCAPE;
+
+ case K_S_UP:
+ FALLTHROUGH;
+ case K_UP:
+ return VTERM_KEY_UP;
+ case K_S_DOWN:
+ FALLTHROUGH;
+ case K_DOWN:
+ return VTERM_KEY_DOWN;
+ case K_S_LEFT:
+ FALLTHROUGH;
+ case K_C_LEFT:
+ FALLTHROUGH;
+ case K_LEFT:
+ return VTERM_KEY_LEFT;
+ case K_S_RIGHT:
+ FALLTHROUGH;
+ case K_C_RIGHT:
+ FALLTHROUGH;
+ case K_RIGHT:
+ return VTERM_KEY_RIGHT;
+
+ case K_INS:
+ return VTERM_KEY_INS;
+ case K_DEL:
+ return VTERM_KEY_DEL;
+ case K_HOME:
+ return VTERM_KEY_HOME;
+ case K_END:
+ return VTERM_KEY_END;
+ case K_PAGEUP:
+ return VTERM_KEY_PAGEUP;
+ case K_PAGEDOWN:
+ return VTERM_KEY_PAGEDOWN;
+
+ case K_K0:
+ FALLTHROUGH;
+ case K_KINS:
+ return VTERM_KEY_KP_0;
+ case K_K1:
+ FALLTHROUGH;
+ case K_KEND:
+ return VTERM_KEY_KP_1;
+ case K_K2:
+ FALLTHROUGH;
+ case K_KDOWN:
+ return VTERM_KEY_KP_2;
+ case K_K3:
+ FALLTHROUGH;
+ case K_KPAGEDOWN:
+ return VTERM_KEY_KP_3;
+ case K_K4:
+ FALLTHROUGH;
+ case K_KLEFT:
+ return VTERM_KEY_KP_4;
+ case K_K5:
+ FALLTHROUGH;
+ case K_KORIGIN:
+ return VTERM_KEY_KP_5;
+ case K_K6:
+ FALLTHROUGH;
+ case K_KRIGHT:
+ return VTERM_KEY_KP_6;
+ case K_K7:
+ FALLTHROUGH;
+ case K_KHOME:
+ return VTERM_KEY_KP_7;
+ case K_K8:
+ FALLTHROUGH;
+ case K_KUP:
+ return VTERM_KEY_KP_8;
+ case K_K9:
+ FALLTHROUGH;
+ case K_KPAGEUP:
+ return VTERM_KEY_KP_9;
+ case K_KDEL:
+ FALLTHROUGH;
+ case K_KPOINT:
+ return VTERM_KEY_KP_PERIOD;
+ case K_KENTER:
+ return VTERM_KEY_KP_ENTER;
+ case K_KPLUS:
+ return VTERM_KEY_KP_PLUS;
+ case K_KMINUS:
+ return VTERM_KEY_KP_MINUS;
+ case K_KMULTIPLY:
+ return VTERM_KEY_KP_MULT;
+ case K_KDIVIDE:
+ return VTERM_KEY_KP_DIVIDE;
+
+ case K_S_F1:
+ FALLTHROUGH;
+ case K_F1:
+ return VTERM_KEY_FUNCTION(1);
+ case K_S_F2:
+ FALLTHROUGH;
+ case K_F2:
+ return VTERM_KEY_FUNCTION(2);
+ case K_S_F3:
+ FALLTHROUGH;
+ case K_F3:
+ return VTERM_KEY_FUNCTION(3);
+ case K_S_F4:
+ FALLTHROUGH;
+ case K_F4:
+ return VTERM_KEY_FUNCTION(4);
+ case K_S_F5:
+ FALLTHROUGH;
+ case K_F5:
+ return VTERM_KEY_FUNCTION(5);
+ case K_S_F6:
+ FALLTHROUGH;
+ case K_F6:
+ return VTERM_KEY_FUNCTION(6);
+ case K_S_F7:
+ FALLTHROUGH;
+ case K_F7:
+ return VTERM_KEY_FUNCTION(7);
+ case K_S_F8:
+ FALLTHROUGH;
+ case K_F8:
+ return VTERM_KEY_FUNCTION(8);
+ case K_S_F9:
+ FALLTHROUGH;
+ case K_F9:
+ return VTERM_KEY_FUNCTION(9);
+ case K_S_F10:
+ FALLTHROUGH;
+ case K_F10:
+ return VTERM_KEY_FUNCTION(10);
+ case K_S_F11:
+ FALLTHROUGH;
+ case K_F11:
+ return VTERM_KEY_FUNCTION(11);
+ case K_S_F12:
+ FALLTHROUGH;
+ case K_F12:
+ return VTERM_KEY_FUNCTION(12);
+
+ case K_F13:
+ return VTERM_KEY_FUNCTION(13);
+ case K_F14:
+ return VTERM_KEY_FUNCTION(14);
+ case K_F15:
+ return VTERM_KEY_FUNCTION(15);
+ case K_F16:
+ return VTERM_KEY_FUNCTION(16);
+ case K_F17:
+ return VTERM_KEY_FUNCTION(17);
+ case K_F18:
+ return VTERM_KEY_FUNCTION(18);
+ case K_F19:
+ return VTERM_KEY_FUNCTION(19);
+ case K_F20:
+ return VTERM_KEY_FUNCTION(20);
+ case K_F21:
+ return VTERM_KEY_FUNCTION(21);
+ case K_F22:
+ return VTERM_KEY_FUNCTION(22);
+ case K_F23:
+ return VTERM_KEY_FUNCTION(23);
+ case K_F24:
+ return VTERM_KEY_FUNCTION(24);
+ case K_F25:
+ return VTERM_KEY_FUNCTION(25);
+ case K_F26:
+ return VTERM_KEY_FUNCTION(26);
+ case K_F27:
+ return VTERM_KEY_FUNCTION(27);
+ case K_F28:
+ return VTERM_KEY_FUNCTION(28);
+ case K_F29:
+ return VTERM_KEY_FUNCTION(29);
+ case K_F30:
+ return VTERM_KEY_FUNCTION(30);
+ case K_F31:
+ return VTERM_KEY_FUNCTION(31);
+ case K_F32:
+ return VTERM_KEY_FUNCTION(32);
+ case K_F33:
+ return VTERM_KEY_FUNCTION(33);
+ case K_F34:
+ return VTERM_KEY_FUNCTION(34);
+ case K_F35:
+ return VTERM_KEY_FUNCTION(35);
+ case K_F36:
+ return VTERM_KEY_FUNCTION(36);
+ case K_F37:
+ return VTERM_KEY_FUNCTION(37);
+
+ default:
+ return VTERM_KEY_NONE;
}
}
-static void mouse_action(Terminal *term, int button, int row, int col,
- bool drag, VTermModifier mod)
+static void mouse_action(Terminal *term, int button, int row, int col, bool drag, VTermModifier mod)
{
if (term->pressed_button && (term->pressed_button != button || !drag)) {
// release the previous button
@@ -1100,16 +1199,26 @@ static bool send_mouse_event(Terminal *term, int c)
bool drag = false;
switch (c) {
- case K_LEFTDRAG: drag = true; FALLTHROUGH;
- case K_LEFTMOUSE: button = 1; break;
- case K_MOUSEMOVE: drag = true; button = 0; break;
- case K_MIDDLEDRAG: drag = true; FALLTHROUGH;
- case K_MIDDLEMOUSE: button = 2; break;
- case K_RIGHTDRAG: drag = true; FALLTHROUGH;
- case K_RIGHTMOUSE: button = 3; break;
- case K_MOUSEDOWN: button = 4; break;
- case K_MOUSEUP: button = 5; break;
- default: return false;
+ case K_LEFTDRAG:
+ drag = true; FALLTHROUGH;
+ case K_LEFTMOUSE:
+ button = 1; break;
+ case K_MOUSEMOVE:
+ drag = true; button = 0; break;
+ case K_MIDDLEDRAG:
+ drag = true; FALLTHROUGH;
+ case K_MIDDLEMOUSE:
+ button = 2; break;
+ case K_RIGHTDRAG:
+ drag = true; FALLTHROUGH;
+ case K_RIGHTMOUSE:
+ button = 3; break;
+ case K_MOUSEDOWN:
+ button = 4; break;
+ case K_MOUSEUP:
+ button = 5; break;
+ default:
+ return false;
}
mouse_action(term, button, row, col - offset, drag, 0);
@@ -1162,7 +1271,7 @@ static void fetch_row(Terminal *term, int row, int end_col)
if (cell.chars[0]) {
for (int i = 0; cell.chars[i]; i++) {
cell_len += utf_char2bytes((int)cell.chars[i],
- (uint8_t *)ptr + cell_len);
+ (uint8_t *)ptr + cell_len);
}
} else {
*ptr = ' ';
@@ -1181,8 +1290,7 @@ static void fetch_row(Terminal *term, int row, int end_col)
term->textbuf[line_len] = 0;
}
-static bool fetch_cell(Terminal *term, int row, int col,
- VTermScreenCell *cell)
+static bool fetch_cell(Terminal *term, int row, int col, VTermScreenCell *cell)
{
if (row < 0) {
ScrollbackLine *sbrow = term->sb_buffer[-row - 1];
@@ -1197,8 +1305,8 @@ static bool fetch_cell(Terminal *term, int row, int col,
return false;
}
} else {
- vterm_screen_get_cell(term->vts, (VTermPos){.row = row, .col = col},
- cell);
+ vterm_screen_get_cell(term->vts, (VTermPos){ .row = row, .col = col },
+ cell);
}
return true;
}
diff --git a/src/uncrustify.cfg b/src/uncrustify.cfg
index 5d73e70ed0..05f133fa49 100644
--- a/src/uncrustify.cfg
+++ b/src/uncrustify.cfg
@@ -1,4 +1,4 @@
-# Uncrustify-0.73.0-186-03faf73c
+# Uncrustify-0.73.0-186-03faf73c5
#
# General options