refactor: format with uncrustify #15842

* refactor: format with uncrustify
* refactor: convert function comments to doxygen
This commit is contained in:
dundargoc
2021-10-02 16:59:41 +02:00
committed by GitHub
parent 898f91f0f3
commit 9c268263b1
8 changed files with 1163 additions and 982 deletions

View File

@@ -9,31 +9,29 @@
* might be a few lines of code that look similar to what Nvi has. * might be a few lines of code that look similar to what Nvi has.
*/ */
#include <stdbool.h>
#include <assert.h> #include <assert.h>
#include <errno.h> #include <errno.h>
#include <inttypes.h>
#include <fcntl.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/ascii.h"
#include "nvim/if_cscope.h" #include "nvim/buffer.h"
#include "nvim/charset.h" #include "nvim/charset.h"
#include "nvim/event/stream.h"
#include "nvim/fileio.h" #include "nvim/fileio.h"
#include "nvim/message.h" #include "nvim/if_cscope.h"
#include "nvim/memory.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/os/time.h"
#include "nvim/path.h" #include "nvim/path.h"
#include "nvim/quickfix.h" #include "nvim/quickfix.h"
#include "nvim/strings.h" #include "nvim/strings.h"
#include "nvim/tag.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) #if defined(UNIX)
# include <sys/wait.h> # include <sys/wait.h>
#endif #endif
@@ -90,19 +88,20 @@ char_u *get_cscope_name(expand_T *xp, int idx)
// Complete with sub-commands of ":cscope": // Complete with sub-commands of ":cscope":
// add, find, help, kill, reset, show // add, find, help, kill, reset, show
return (char_u *)cs_cmds[idx].name; 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 // Complete with sub-commands of ":scscope": same sub-commands as
// ":cscope" but skip commands which don't support split windows // ":cscope" but skip commands which don't support split windows
int i; int i;
for (i = 0, current_idx = 0; cs_cmds[i].name != NULL; i++) for (i = 0, current_idx = 0; cs_cmds[i].name != NULL; i++) {
if (cs_cmds[i].cansplit) if (cs_cmds[i].cansplit) {
if (current_idx++ == idx) if (current_idx++ == idx) {
break; break;
}
}
}
return (char_u *)cs_cmds[i].name; return (char_u *)cs_cmds[i].name;
} }
case EXP_CSCOPE_FIND: case EXP_CSCOPE_FIND: {
{
const char *query_type[] = const char *query_type[] =
{ {
"a", "c", "d", "e", "f", "g", "i", "s", "t", NULL "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. // redundant.
return (char_u *)query_type[idx]; return (char_u *)query_type[idx];
} }
case EXP_CSCOPE_KILL: case EXP_CSCOPE_KILL: {
{
static char connection[5]; static char connection[5];
// ":cscope kill" accepts connection numbers or partial names of // ":cscope kill" accepts connection numbers or partial names of
@@ -124,8 +122,9 @@ char_u *get_cscope_name(expand_T *xp, int idx)
// connections. // connections.
size_t i; size_t i;
for (i = 0, current_idx = 0; i < csinfo_size; i++) { for (i = 0, current_idx = 0; i < csinfo_size; i++) {
if (csinfo[i].fname == NULL) if (csinfo[i].fname == NULL) {
continue; continue;
}
if (current_idx++ == idx) { if (current_idx++ == idx) {
vim_snprintf(connection, sizeof(connection), "%zu", i); vim_snprintf(connection, sizeof(connection), "%zu", i);
return (char_u *)connection; 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 /// Find the command, print help if invalid, and then call the corresponding
/// command function. /// command function.
static void ///
do_cscope_general( /// @param make_split whether to split window
exarg_T *eap, static void do_cscope_general(exarg_T *eap, int make_split)
int make_split // whether to split window
)
{ {
cscmd_T *cmdp; cscmd_T *cmdp;
@@ -187,8 +184,7 @@ do_cscope_general(
if (make_split) { if (make_split) {
if (!cmdp->cansplit) { if (!cmdp->cansplit) {
(void)MSG_PUTS(_( (void)MSG_PUTS(_("This cscope command does not support splitting the window.\n"));
"This cscope command does not support splitting the window.\n"));
return; return;
} }
postponed_split = -1; postponed_split = -1;
@@ -231,12 +227,14 @@ void ex_cstag(exarg_T *eap)
FALSE, *eap->cmdlinep); FALSE, *eap->cmdlinep);
if (ret == FALSE) { if (ret == FALSE) {
cs_free_tags(); cs_free_tags();
if (msg_col) if (msg_col) {
msg_putchar('\n'); msg_putchar('\n');
}
if (cs_check_for_tags()) if (cs_check_for_tags()) {
ret = do_tag(eap->arg, DT_JUMP, 0, eap->forceit, FALSE); ret = do_tag(eap->arg, DT_JUMP, 0, eap->forceit, FALSE);
} }
}
} else if (cs_check_for_tags()) { } else if (cs_check_for_tags()) {
ret = do_tag(eap->arg, DT_JUMP, 0, eap->forceit, FALSE); ret = do_tag(eap->arg, DT_JUMP, 0, eap->forceit, FALSE);
} }
@@ -245,22 +243,25 @@ void ex_cstag(exarg_T *eap)
if (cs_check_for_tags()) { if (cs_check_for_tags()) {
ret = do_tag(eap->arg, DT_JUMP, 0, eap->forceit, FALSE); ret = do_tag(eap->arg, DT_JUMP, 0, eap->forceit, FALSE);
if (ret == FALSE) { if (ret == FALSE) {
if (msg_col) if (msg_col) {
msg_putchar('\n'); msg_putchar('\n');
}
if (cs_check_for_connections()) { if (cs_check_for_connections()) {
ret = cs_find_common("g", (char *)(eap->arg), eap->forceit, ret = cs_find_common("g", (char *)(eap->arg), eap->forceit,
FALSE, FALSE, *eap->cmdlinep); FALSE, FALSE, *eap->cmdlinep);
if (ret == FALSE) if (ret == FALSE) {
cs_free_tags(); cs_free_tags();
} }
} }
}
} else if (cs_check_for_connections()) { } else if (cs_check_for_connections()) {
ret = cs_find_common("g", (char *)(eap->arg), eap->forceit, FALSE, ret = cs_find_common("g", (char *)(eap->arg), eap->forceit, FALSE,
FALSE, *eap->cmdlinep); FALSE, *eap->cmdlinep);
if (ret == FALSE) if (ret == FALSE) {
cs_free_tags(); cs_free_tags();
} }
}
break; break;
default: default:
break; break;
@@ -393,8 +394,9 @@ static int cs_add(exarg_T *eap)
cs_usage_msg(Add); cs_usage_msg(Add);
return CSCOPE_FAILURE; 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 *)" "); flags = strtok((char *)NULL, (const char *)" ");
}
return cs_add_common(fname, ppath, flags); return cs_add_common(fname, ppath, flags);
} }
@@ -413,12 +415,10 @@ static void cs_stat_emsg(char *fname)
/// The common routine to add a new cscope connection. Called by /// 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 /// cs_add() and cs_reset(). I really don't like to do this, but this
/// routine uses a number of goto statements. /// routine uses a number of goto statements.
static int ///
cs_add_common( /// @param arg1 filename - may contain environment variables
char *arg1, // filename - may contain environment variables /// @param arg2 prepend path - may contain environment variables
char *arg2, // prepend path - may contain environment variables static int cs_add_common(char *arg1, char *arg2, char *flags)
char *flags
)
{ {
char *fname = NULL; char *fname = NULL;
char *fname2 = NULL; char *fname2 = NULL;
@@ -443,8 +443,9 @@ cs_add_common(
bool file_info_ok = os_fileinfo(fname, &file_info); bool file_info_ok = os_fileinfo(fname, &file_info);
if (!file_info_ok) { if (!file_info_ok) {
staterr: staterr:
if (p_csverbose) if (p_csverbose) {
cs_stat_emsg(fname); cs_stat_emsg(fname);
}
goto add_err; goto add_err;
} }
@@ -465,31 +466,32 @@ staterr:
while (fname[strlen(fname)-1] == '/' while (fname[strlen(fname)-1] == '/'
) { ) {
fname[strlen(fname)-1] = '\0'; fname[strlen(fname)-1] = '\0';
if (fname[0] == '\0') if (fname[0] == '\0') {
break; break;
} }
if (fname[0] == '\0') }
if (fname[0] == '\0') {
(void)sprintf(fname2, "/%s", CSCOPE_DBFILE); (void)sprintf(fname2, "/%s", CSCOPE_DBFILE);
else } else {
(void)sprintf(fname2, "%s/%s", fname, CSCOPE_DBFILE); (void)sprintf(fname2, "%s/%s", fname, CSCOPE_DBFILE);
}
file_info_ok = os_fileinfo(fname2, &file_info); file_info_ok = os_fileinfo(fname2, &file_info);
if (!file_info_ok) { if (!file_info_ok) {
if (p_csverbose) if (p_csverbose) {
cs_stat_emsg(fname2); cs_stat_emsg(fname2);
}
goto add_err; goto add_err;
} }
i = cs_insert_filelist(fname2, ppath, flags, &file_info); 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); i = cs_insert_filelist(fname, ppath, flags, &file_info);
} else { } else {
if (p_csverbose) if (p_csverbose) {
(void)EMSG2( (void)EMSG2(_("E564: %s is not a directory or a valid cscope database"),
_("E564: %s is not a directory or a valid cscope database"),
fname); fname);
}
goto add_err; goto add_err;
} }
@@ -538,15 +540,15 @@ static size_t cs_cnt_connections(void)
size_t cnt = 0; size_t cnt = 0;
for (size_t i = 0; i < csinfo_size; i++) { for (size_t i = 0; i < csinfo_size; i++) {
if (csinfo[i].fname != NULL) if (csinfo[i].fname != NULL) {
cnt++; cnt++;
} }
}
return cnt; return cnt;
} }
static void cs_reading_emsg( /// @param idx connection index
size_t idx // connection index static void cs_reading_emsg(size_t idx)
)
{ {
EMSGU(_("E262: error reading cscope connection %" PRIu64), idx); EMSGU(_("E262: error reading cscope connection %" PRIu64), idx);
} }
@@ -591,18 +593,21 @@ static int cs_cnt_matches(size_t idx)
continue; continue;
} }
if ((stok = strtok(NULL, (const char *)" ")) == NULL) if ((stok = strtok(NULL, (const char *)" ")) == NULL) {
continue; continue;
}
nlines = atoi(stok); nlines = atoi(stok);
if (nlines < 0) { if (nlines < 0) {
nlines = 0; nlines = 0;
break; break;
} }
if ((stok = strtok(NULL, (const char *)" ")) == NULL) if ((stok = strtok(NULL, (const char *)" ")) == NULL) {
continue; continue;
if (strncmp((const char *)stok, "lines", 5)) }
if (strncmp((const char *)stok, "lines", 5)) {
continue; continue;
}
break; break;
} }
@@ -620,31 +625,40 @@ static char *cs_create_cmd(char *csoption, char *pattern)
char *pat; char *pat;
switch (csoption[0]) { switch (csoption[0]) {
case '0': case 's': case '0':
case 's':
search = 0; search = 0;
break; break;
case '1': case 'g': case '1':
case 'g':
search = 1; search = 1;
break; break;
case '2': case 'd': case '2':
case 'd':
search = 2; search = 2;
break; break;
case '3': case 'c': case '3':
case 'c':
search = 3; search = 3;
break; break;
case '4': case 't': case '4':
case 't':
search = 4; search = 4;
break; break;
case '6': case 'e': case '6':
case 'e':
search = 6; search = 6;
break; break;
case '7': case 'f': case '7':
case 'f':
search = 7; search = 7;
break; break;
case '8': case 'i': case '8':
case 'i':
search = 8; search = 8;
break; break;
case '9': case 'a': case '9':
case 'a':
search = 9; search = 9;
break; break;
default: 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, // Skip white space before the patter, except for text and pattern search,
// they may want to use the leading white space. // they may want to use the leading white space.
pat = pattern; pat = pattern;
if (search != 4 && search != 6) if (search != 4 && search != 6) {
while (ascii_iswhite(*pat)) while (ascii_iswhite(*pat)) {
++pat; ++pat;
}
}
cmd = xmalloc(strlen(pat) + 2); cmd = xmalloc(strlen(pat) + 2);
@@ -686,14 +702,18 @@ static int cs_create_connection(size_t i)
if (pipe(to_cs) < 0 || pipe(from_cs) < 0) { if (pipe(to_cs) < 0 || pipe(from_cs) < 0) {
(void)EMSG(_("E566: Could not create cscope pipes")); (void)EMSG(_("E566: Could not create cscope pipes"));
err_closing: err_closing:
if (to_cs[0] != -1) if (to_cs[0] != -1) {
(void)close(to_cs[0]); (void)close(to_cs[0]);
if (to_cs[1] != -1) }
if (to_cs[1] != -1) {
(void)close(to_cs[1]); (void)close(to_cs[1]);
if (from_cs[0] != -1) }
if (from_cs[0] != -1) {
(void)close(from_cs[0]); (void)close(from_cs[0]);
if (from_cs[1] != -1) }
if (from_cs[1] != -1) {
(void)close(from_cs[1]); (void)close(from_cs[1]);
}
return CSCOPE_FAILURE; return CSCOPE_FAILURE;
} }
@@ -759,8 +779,9 @@ err_closing:
len += strlen(ppath); len += strlen(ppath);
} }
if (csinfo[i].flags) if (csinfo[i].flags) {
len += strlen(csinfo[i].flags); len += strlen(csinfo[i].flags);
}
cmd = xmalloc(len); cmd = xmalloc(len);
@@ -779,10 +800,10 @@ err_closing:
(void)strcat(cmd, " "); (void)strcat(cmd, " ");
(void)strcat(cmd, csinfo[i].flags); (void)strcat(cmd, csinfo[i].flags);
} }
# ifdef UNIX #ifdef UNIX
// on Win32 we still need prog // on Win32 we still need prog
xfree(prog); xfree(prog);
# endif #endif
xfree(ppath); xfree(ppath);
#if defined(UNIX) #if defined(UNIX)
@@ -791,12 +812,14 @@ err_closing:
# if defined(HAVE_SETSID) # if defined(HAVE_SETSID)
(void)setsid(); (void)setsid();
# else # else
if (setpgid(0, 0) == -1) if (setpgid(0, 0) == -1) {
PERROR(_("cs_create_connection setpgid failed")); PERROR(_("cs_create_connection setpgid failed"));
}
# endif # endif
# 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")); PERROR(_("cs_create_connection exec failed"));
}
exit(127); exit(127);
// NOTREACHED // NOTREACHED
@@ -888,9 +911,11 @@ static int cs_find(exarg_T *eap)
* Let's replace the NULs written by strtok() with spaces - we need the * Let's replace the NULs written by strtok() with spaces - we need the
* spaces to correctly display the quickfix/location list window's title. * spaces to correctly display the quickfix/location list window's title.
*/ */
for (int i = 0; i < eap_arg_len; ++i) for (int i = 0; i < eap_arg_len; ++i) {
if (NUL == eap->arg[i]) if (NUL == eap->arg[i]) {
eap->arg[i] = ' '; eap->arg[i] = ' ';
}
}
return cs_find_common(opt, pat, eap->forceit, true, return cs_find_common(opt, pat, eap->forceit, true,
eap->cmdidx == CMD_lcscope, *eap->cmdlinep); 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(). /// 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, static int cs_find_common(char *opt, char *pat, int forceit, int verbose, int use_ll,
int use_ll, char_u *cmdline) char_u *cmdline)
{ {
char *cmd; char *cmd;
int *nummatches; 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 // create the actual command to send to cscope
cmd = cs_create_cmd(opt, pat); cmd = cs_create_cmd(opt, pat);
if (cmd == NULL) if (cmd == NULL) {
return FALSE; return FALSE;
}
nummatches = xmalloc(sizeof(int) * csinfo_size); 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; totmatches = 0;
for (size_t i = 0; i < csinfo_size; i++) { 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; continue;
}
// send cmd to cscope // send cmd to cscope
(void)fprintf(csinfo[i].to_fp, "%s\n", cmd); (void)fprintf(csinfo[i].to_fp, "%s\n", cmd);
@@ -987,12 +1014,14 @@ static int cs_find_common(char *opt, char *pat, int forceit, int verbose,
nummatches[i] = cs_cnt_matches(i); nummatches[i] = cs_cnt_matches(i);
if (nummatches[i] > -1) if (nummatches[i] > -1) {
totmatches += (size_t)nummatches[i]; totmatches += (size_t)nummatches[i];
}
if (nummatches[i] == 0) if (nummatches[i] == 0) {
(void)cs_read_prompt(i); (void)cs_read_prompt(i);
} }
}
xfree(cmd); xfree(cmd);
if (totmatches == 0) { if (totmatches == 0) {
@@ -1040,13 +1069,14 @@ static int cs_find_common(char *opt, char *pat, int forceit, int verbose,
apply_autocmds(EVENT_QUICKFIXCMDPOST, (char_u *)"cscope", apply_autocmds(EVENT_QUICKFIXCMDPOST, (char_u *)"cscope",
curbuf->b_fname, TRUE, curbuf); curbuf->b_fname, TRUE, curbuf);
if (use_ll) if (use_ll) {
/* /*
* In the location list window, use the displayed location * In the location list window, use the displayed location
* list. Otherwise, use the location list for the window. * list. Otherwise, use the location list for the window.
*/ */
qi = (bt_quickfix(wp->w_buffer) && wp->w_llist_ref != NULL) qi = (bt_quickfix(wp->w_buffer) && wp->w_llist_ref != NULL)
? wp->w_llist_ref : wp->w_llist; ? wp->w_llist_ref : wp->w_llist;
}
qf_jump(qi, 0, 0, forceit); qf_jump(qi, 0, 0, forceit);
} }
} }
@@ -1062,8 +1092,9 @@ static int cs_find_common(char *opt, char *pat, int forceit, int verbose,
cs_fill_results((char *)pat, totmatches, nummatches, &matches, cs_fill_results((char *)pat, totmatches, nummatches, &matches,
&contexts, &matched); &contexts, &matched);
xfree(nummatches); xfree(nummatches);
if (matches == NULL) if (matches == NULL) {
return FALSE; return FALSE;
}
(void)cs_manage_matches(matches, contexts, matched, Store); (void)cs_manage_matches(matches, contexts, matched, Store);
@@ -1089,7 +1120,7 @@ static int cs_help(exarg_T *eap)
cmdp->name, cmdp->name,
help, space_cnt, " ", help, space_cnt, " ",
cmdp->usage); cmdp->usage);
if (strcmp(cmdp->name, "find") == 0) if (strcmp(cmdp->name, "find") == 0) {
MSG_PUTS(_("\n" MSG_PUTS(_("\n"
" a: Find assignments to this symbol\n" " a: Find assignments to this symbol\n"
" c: Find functions calling this function\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" " i: Find files #including this file\n"
" s: Find this C symbol\n" " s: Find this C symbol\n"
" t: Find this text string\n")); " t: Find this text string\n"));
}
cmdp++; cmdp++;
} }
@@ -1121,8 +1153,7 @@ static void clear_csinfo(size_t i)
} }
/// Insert a new cscope database filename into the filelist. /// Insert a new cscope database filename into the filelist.
static int cs_insert_filelist(char *fname, char *ppath, char *flags, static int cs_insert_filelist(char *fname, char *ppath, char *flags, FileInfo *file_info)
FileInfo *file_info)
{ {
size_t i = 0; size_t i = 0;
bool empty_found = false; 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++) { for (size_t j = 0; j < csinfo_size; j++) {
if (csinfo[j].fname != NULL if (csinfo[j].fname != NULL
&& os_fileid_equal_fileinfo(&(csinfo[j].file_id), file_info)) { && os_fileid_equal_fileinfo(&(csinfo[j].file_id), file_info)) {
if (p_csverbose) if (p_csverbose) {
(void)EMSG(_("E568: duplicate cscope database not added")); (void)EMSG(_("E568: duplicate cscope database not added"));
}
return CSCOPE_FAILURE; return CSCOPE_FAILURE;
} }
@@ -1154,9 +1186,10 @@ static int cs_insert_filelist(char *fname, char *ppath, char *flags,
csinfo_size *= 2; csinfo_size *= 2;
csinfo = xrealloc(csinfo, sizeof(csinfo_T)*csinfo_size); 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); clear_csinfo(j);
} }
}
csinfo[i].fname = xmalloc(strlen(fname) + 1); 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) { if (ppath != NULL) {
csinfo[i].ppath = xmalloc(strlen(ppath) + 1); csinfo[i].ppath = xmalloc(strlen(ppath) + 1);
(void)strcpy(csinfo[i].ppath, (const char *)ppath); (void)strcpy(csinfo[i].ppath, (const char *)ppath);
} else } else {
csinfo[i].ppath = NULL; csinfo[i].ppath = NULL;
}
if (flags != NULL) { if (flags != NULL) {
csinfo[i].flags = xmalloc(strlen(flags) + 1); csinfo[i].flags = xmalloc(strlen(flags) + 1);
(void)strcpy(csinfo[i].flags, (const char *)flags); (void)strcpy(csinfo[i].flags, (const char *)flags);
} else } else {
csinfo[i].flags = NULL; csinfo[i].flags = NULL;
}
os_fileinfo_id(file_info, &(csinfo[i].file_id)); os_fileinfo_id(file_info, &(csinfo[i].file_id));
assert(i <= INT_MAX); assert(i <= INT_MAX);
@@ -1181,26 +1216,29 @@ static int cs_insert_filelist(char *fname, char *ppath, char *flags,
/// Find cscope command in command table. /// 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; cscmd_T *cmdp;
char *stok; char *stok;
size_t len; size_t len;
if (eap->arg == NULL) if (eap->arg == NULL) {
return NULL; return NULL;
}
// Store length of eap->arg before it gets modified by strtok(). // Store length of eap->arg before it gets modified by strtok().
eap_arg_len = (int)STRLEN(eap->arg); 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; return NULL;
}
len = strlen(stok); len = strlen(stok);
for (cmdp = cs_cmds; cmdp->name != NULL; ++cmdp) { 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 cmdp;
} }
}
return NULL; return NULL;
} }
@@ -1224,23 +1262,25 @@ static int cs_kill(exarg_T *eap)
|| (strlen(stok) < 3 && stok[0] == '-' || (strlen(stok) < 3 && stok[0] == '-'
&& ascii_isdigit((int)(stok[1])))) { && ascii_isdigit((int)(stok[1])))) {
num = atoi(stok); num = atoi(stok);
if (num == -1) if (num == -1) {
killall = true; killall = true;
else if (num >= 0) { } else if (num >= 0) {
i = (size_t)num; i = (size_t)num;
} else { // All negative values besides -1 are invalid. } else { // All negative values besides -1 are invalid.
if (p_csverbose) if (p_csverbose) {
(void)EMSG2(_("E261: cscope connection %s not found"), stok); (void)EMSG2(_("E261: cscope connection %s not found"), stok);
}
return CSCOPE_FAILURE; return CSCOPE_FAILURE;
} }
} else { } else {
// Else it must be part of a name. We will try to find a match // Else it must be part of a name. We will try to find a match
// within all the names in the csinfo data structure // within all the names in the csinfo data structure
for (i = 0; i < csinfo_size; i++) { 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; break;
} }
} }
}
if (!killall && (i >= csinfo_size || csinfo[i].fname == NULL)) { if (!killall && (i >= csinfo_size || csinfo[i].fname == NULL)) {
if (p_csverbose) { if (p_csverbose) {
@@ -1250,9 +1290,10 @@ static int cs_kill(exarg_T *eap)
} else { } else {
if (killall) { if (killall) {
for (i = 0; i < csinfo_size; i++) { for (i = 0; i < csinfo_size; i++) {
if (csinfo[i].fname) if (csinfo[i].fname) {
cs_kill_execute(i, csinfo[i].fname); cs_kill_execute(i, csinfo[i].fname);
} }
}
} else { } else {
cs_kill_execute((size_t)i, stok); cs_kill_execute((size_t)i, stok);
} }
@@ -1263,10 +1304,10 @@ static int cs_kill(exarg_T *eap)
/// Actually kills a specific cscope connection. /// Actually kills a specific cscope connection.
static void cs_kill_execute( ///
size_t i, // cscope table index /// @param i cscope table index
char *cname // cscope database name /// @param cname cscope database name
) static void cs_kill_execute(size_t i, char *cname)
{ {
if (p_csverbose) { if (p_csverbose) {
msg_clr_eos(); msg_clr_eos();
@@ -1293,8 +1334,7 @@ static void cs_kill_execute(
/// Besides, even if this particular case didn't happen, the search pattern /// 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 /// would still have to be modified to escape all the special regular expression
/// characters to comply with ctags formatting. /// characters to comply with ctags formatting.
static char *cs_make_vim_style_matches(char *fname, char *slno, char *search, static char *cs_make_vim_style_matches(char *fname, char *slno, char *search, char *tagstr)
char *tagstr)
{ {
// vim style is ctags: // 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 /// Free: frees up everything and resets
/// ///
/// Print: prints the tags /// Print: prints the tags
static char *cs_manage_matches(char **matches, char **contexts, static char *cs_manage_matches(char **matches, char **contexts, size_t totmatches, mcmd_e cmd)
size_t totmatches, mcmd_e cmd)
{ {
static char **mp = NULL; static char **mp = NULL;
static char **cp = NULL; static char **cp = NULL;
@@ -1352,16 +1391,18 @@ static char *cs_manage_matches(char **matches, char **contexts,
case Store: case Store:
assert(matches != NULL); assert(matches != NULL);
assert(totmatches > 0); assert(totmatches > 0);
if (mp != NULL || cp != NULL) if (mp != NULL || cp != NULL) {
(void)cs_manage_matches(NULL, NULL, 0, Free); (void)cs_manage_matches(NULL, NULL, 0, Free);
}
mp = matches; mp = matches;
cp = contexts; cp = contexts;
cnt = totmatches; cnt = totmatches;
next = 0; next = 0;
break; break;
case Get: case Get:
if (next >= cnt) if (next >= cnt) {
return NULL; return NULL;
}
p = mp[next]; p = mp[next];
next++; next++;
@@ -1370,9 +1411,10 @@ static char *cs_manage_matches(char **matches, char **contexts,
if (mp != NULL) { if (mp != NULL) {
while (cnt--) { while (cnt--) {
xfree(mp[cnt]); xfree(mp[cnt]);
if (cp != NULL) if (cp != NULL) {
xfree(cp[cnt]); xfree(cp[cnt]);
} }
}
xfree(mp); xfree(mp);
xfree(cp); xfree(cp);
} }
@@ -1396,8 +1438,8 @@ static char *cs_manage_matches(char **matches, char **contexts,
/// Parse cscope output. /// Parse cscope output.
static char *cs_parse_results(size_t cnumber, char *buf, int bufsize, static char *cs_parse_results(size_t cnumber, char *buf, int bufsize, char **context,
char **context, char **linenumber, char **search) char **linenumber, char **search)
{ {
int ch; int ch;
char *p; char *p;
@@ -1421,8 +1463,9 @@ retry:
// If the line's too long for the buffer, discard it. // If the line's too long for the buffer, discard it.
if ((p = strchr(buf, '\n')) == NULL) { 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; return NULL;
} }
*p = '\0'; *p = '\0';
@@ -1432,12 +1475,15 @@ retry:
* *
* <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; return NULL;
if ((*context = strtok(NULL, (const char *)" ")) == NULL) }
if ((*context = strtok(NULL, (const char *)" ")) == NULL) {
return NULL; return NULL;
if ((*linenumber = strtok(NULL, (const char *)" ")) == NULL) }
if ((*linenumber = strtok(NULL, (const char *)" ")) == NULL) {
return NULL; return NULL;
}
*search = *linenumber + strlen(*linenumber) + 1; // +1 to skip \0 *search = *linenumber + strlen(*linenumber) + 1; // +1 to skip \0
// --- nvi --- // --- nvi ---
@@ -1463,25 +1509,29 @@ static void cs_file_results(FILE *f, int *nummatches_a)
char *buf = xmalloc(CSREAD_BUFSIZE); char *buf = xmalloc(CSREAD_BUFSIZE);
for (size_t i = 0; i < csinfo_size; i++) { for (size_t i = 0; i < csinfo_size; i++) {
if (nummatches_a[i] < 1) if (nummatches_a[i] < 1) {
continue; continue;
}
for (int j = 0; j < nummatches_a[i]; j++) { for (int j = 0; j < nummatches_a[i]; j++) {
if ((fullname = cs_parse_results(i, buf, CSREAD_BUFSIZE, &cntx, if ((fullname = cs_parse_results(i, buf, CSREAD_BUFSIZE, &cntx,
&slno, &search)) == NULL) &slno, &search)) == NULL) {
continue; continue;
}
context = xmalloc(strlen(cntx) + 5); context = xmalloc(strlen(cntx) + 5);
if (strcmp(cntx, "<global>")==0) if (strcmp(cntx, "<global>")==0) {
strcpy(context, "<<global>>"); strcpy(context, "<<global>>");
else } else {
sprintf(context, "<<%s>>", cntx); sprintf(context, "<<%s>>", cntx);
}
if (search == NULL) if (search == NULL) {
fprintf(f, "%s\t%s\t%s\n", fullname, slno, context); 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); fprintf(f, "%s\t%s\t%s %s\n", fullname, slno, context, search);
}
xfree(context); xfree(context);
xfree(fullname); 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 /// Get parsed cscope output and calls cs_make_vim_style_matches to convert
/// into ctags format. /// into ctags format.
/// When there are no matches sets "*matches_p" to NULL. /// When there are no matches sets "*matches_p" to NULL.
static void cs_fill_results(char *tagstr, size_t totmatches, int *nummatches_a, static void cs_fill_results(char *tagstr, size_t totmatches, int *nummatches_a, char ***matches_p,
char ***matches_p, char ***cntxts_p, char ***cntxts_p, size_t *matched)
size_t *matched)
{ {
char *buf; char *buf;
char *search, *slno; 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); cntxts = xmalloc(sizeof(char *) * (size_t)totmatches);
for (size_t i = 0; i < csinfo_size; i++) { for (size_t i = 0; i < csinfo_size; i++) {
if (nummatches_a[i] < 1) if (nummatches_a[i] < 1) {
continue; continue;
}
for (int j = 0; j < nummatches_a[i]; j++) { for (int j = 0; j < nummatches_a[i]; j++) {
if ((fullname = cs_parse_results(i, buf, CSREAD_BUFSIZE, &cntx, if ((fullname = cs_parse_results(i, buf, CSREAD_BUFSIZE, &cntx,
&slno, &search)) == NULL) &slno, &search)) == NULL) {
continue; continue;
}
matches[totsofar] = cs_make_vim_style_matches(fullname, slno, search, matches[totsofar] = cs_make_vim_style_matches(fullname, slno, search,
tagstr); tagstr);
xfree(fullname); xfree(fullname);
if (strcmp(cntx, "<global>") == 0) if (strcmp(cntx, "<global>") == 0) {
cntxts[totsofar] = NULL; cntxts[totsofar] = NULL;
else { } else {
cntxts[totsofar] = xstrdup(cntx); cntxts[totsofar] = xstrdup(cntx);
} }
@@ -1886,10 +1937,12 @@ static void cs_release_csp(size_t i, bool freefnpp)
} }
#endif #endif
if (csinfo[i].fr_fp != NULL) if (csinfo[i].fr_fp != NULL) {
(void)fclose(csinfo[i].fr_fp); (void)fclose(csinfo[i].fr_fp);
if (csinfo[i].to_fp != NULL) }
if (csinfo[i].to_fp != NULL) {
(void)fclose(csinfo[i].to_fp); (void)fclose(csinfo[i].to_fp);
}
if (freefnpp) { if (freefnpp) {
xfree(csinfo[i].fname); xfree(csinfo[i].fname);
@@ -1907,8 +1960,9 @@ 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)" char buf[25]; // for snprintf " (#%zu)"
if (csinfo_size == 0) if (csinfo_size == 0) {
return CSCOPE_SUCCESS; return CSCOPE_SUCCESS;
}
// malloc our db and ppath list // malloc our db and ppath list
dblist = xmalloc(csinfo_size * sizeof(char *)); dblist = xmalloc(csinfo_size * sizeof(char *));
@@ -1919,9 +1973,10 @@ static int cs_reset(exarg_T *eap)
dblist[i] = csinfo[i].fname; dblist[i] = csinfo[i].fname;
pplist[i] = csinfo[i].ppath; pplist[i] = csinfo[i].ppath;
fllist[i] = csinfo[i].flags; fllist[i] = csinfo[i].flags;
if (csinfo[i].fname != NULL) if (csinfo[i].fname != NULL) {
cs_release_csp(i, FALSE); cs_release_csp(i, FALSE);
} }
}
// rebuild the cscope connection list // rebuild the cscope connection list
for (size_t i = 0; i < csinfo_size; i++) { for (size_t i = 0; i < csinfo_size; i++) {
@@ -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. // happens, you are screwed up and need to fix how you're using cscope.
if (csinfo[i].ppath != NULL if (csinfo[i].ppath != NULL
&& (strncmp(name, csinfo[i].ppath, strlen(csinfo[i].ppath)) != 0) && (strncmp(name, csinfo[i].ppath, strlen(csinfo[i].ppath)) != 0)
&& (name[0] != '/') && (name[0] != '/')) {
) {
fullname = xmalloc(len); fullname = xmalloc(len);
(void)sprintf(fullname, "%s/%s", csinfo[i].ppath, name); (void)sprintf(fullname, "%s/%s", csinfo[i].ppath, name);
} else if (csdir != NULL && csinfo[i].fname != NULL && *csdir != NUL) { } 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. /// Show all cscope connections.
static int cs_show(exarg_T *eap) static int cs_show(exarg_T *eap)
{ {
if (cs_cnt_connections() == 0) if (cs_cnt_connections() == 0) {
MSG_PUTS(_("no cscope connections\n")); MSG_PUTS(_("no cscope connections\n"));
else { } else {
MSG_PUTS_ATTR( MSG_PUTS_ATTR(_(" # pid database name prepend path\n"),
_(" # pid database name prepend path\n"),
HL_ATTR(HLF_T)); HL_ATTR(HLF_T));
for (size_t i = 0; i < csinfo_size; i++) { for (size_t i = 0; i < csinfo_size; i++) {
if (csinfo[i].fname == NULL) if (csinfo[i].fname == NULL) {
continue; continue;
}
if (csinfo[i].ppath != NULL) { if (csinfo[i].ppath != NULL) {
(void)smsg("%2zu %-5" PRId64 " %-34s %-32s", i, (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. /// Only called when VIM exits to quit any cscope sessions.
void cs_end(void) 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); cs_release_csp(i, true);
}
xfree(csinfo); xfree(csinfo);
csinfo_size = 0; csinfo_size = 0;
} }

View File

@@ -5,6 +5,7 @@
#include <lua.h> #include <lua.h>
#include <lualib.h> #include <lualib.h>
#include "cjson/lua_cjson.h"
#include "luv/luv.h" #include "luv/luv.h"
#include "mpack/lmpack.h" #include "mpack/lmpack.h"
#include "nvim/api/private/defs.h" #include "nvim/api/private/defs.h"
@@ -40,7 +41,6 @@
#include "nvim/undo.h" #include "nvim/undo.h"
#include "nvim/version.h" #include "nvim/version.h"
#include "nvim/vim.h" #include "nvim/vim.h"
#include "cjson/lua_cjson.h"
static int in_fast_callback = 0; static int in_fast_callback = 0;

View File

@@ -5,8 +5,8 @@
/// ///
/// Management of runtime files (including packages) /// Management of runtime files (including packages)
#include "nvim/ascii.h"
#include "nvim/api/private/helpers.h" #include "nvim/api/private/helpers.h"
#include "nvim/ascii.h"
#include "nvim/charset.h" #include "nvim/charset.h"
#include "nvim/eval.h" #include "nvim/eval.h"
#include "nvim/ex_cmds.h" #include "nvim/ex_cmds.h"

View File

@@ -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, static int draw_virt_text_item(buf_T *buf, int col, VirtText vt, HlMode hl_mode, int max_col,
int max_col, int vcol) int vcol)
{ {
LineState s = LINE_STATE(""); LineState s = LINE_STATE("");
int virt_attr = 0; int virt_attr = 0;

View File

@@ -1,28 +1,26 @@
// This is an open source non-commercial project. Dear PVS-Studio, please check // 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 // it. PVS-Studio Static Code Analyzer for C, C++ and C#: http://www.viva64.com
#include <assert.h>
#include <inttypes.h> #include <inttypes.h>
#include <math.h>
#include <stdarg.h> #include <stdarg.h>
#include <stdbool.h> #include <stdbool.h>
#include <string.h> #include <string.h>
#include <math.h>
#include <assert.h>
#include "nvim/assert.h"
#include "nvim/vim.h"
#include "nvim/ascii.h" #include "nvim/ascii.h"
#include "nvim/strings.h" #include "nvim/assert.h"
#include "nvim/file_search.h"
#include "nvim/buffer.h" #include "nvim/buffer.h"
#include "nvim/charset.h" #include "nvim/charset.h"
#include "nvim/diff.h" #include "nvim/diff.h"
#include "nvim/edit.h" #include "nvim/edit.h"
#include "nvim/eval.h" #include "nvim/eval.h"
#include "nvim/eval/encode.h"
#include "nvim/ex_cmds.h" #include "nvim/ex_cmds.h"
#include "nvim/ex_docmd.h" #include "nvim/ex_docmd.h"
#include "nvim/ex_getln.h" #include "nvim/ex_getln.h"
#include "nvim/file_search.h"
#include "nvim/fileio.h" #include "nvim/fileio.h"
#include "nvim/func_attr.h"
#include "nvim/fold.h" #include "nvim/fold.h"
#include "nvim/func_attr.h" #include "nvim/func_attr.h"
#include "nvim/getchar.h" #include "nvim/getchar.h"
@@ -35,8 +33,10 @@
#include "nvim/message.h" #include "nvim/message.h"
#include "nvim/misc1.h" #include "nvim/misc1.h"
#include "nvim/move.h" #include "nvim/move.h"
#include "nvim/option.h"
#include "nvim/ops.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/os_unix.h"
#include "nvim/path.h" #include "nvim/path.h"
#include "nvim/quickfix.h" #include "nvim/quickfix.h"
@@ -44,12 +44,11 @@
#include "nvim/screen.h" #include "nvim/screen.h"
#include "nvim/search.h" #include "nvim/search.h"
#include "nvim/spell.h" #include "nvim/spell.h"
#include "nvim/strings.h"
#include "nvim/syntax.h" #include "nvim/syntax.h"
#include "nvim/tag.h" #include "nvim/tag.h"
#include "nvim/vim.h"
#include "nvim/window.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. /// Copy "string" into newly allocated memory.
char_u *vim_strsave(const char_u *string) 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. * characters where rem_backslash() would remove the backslash.
* Escape the characters with "cc". * Escape the characters with "cc".
*/ */
char_u *vim_strsave_escaped_ext(const char_u *string, const char_u *esc_chars, char_u *vim_strsave_escaped_ext(const char_u *string, const char_u *esc_chars, char_u cc, bool bsl)
char_u cc, bool bsl)
FUNC_ATTR_NONNULL_RET FUNC_ATTR_MALLOC FUNC_ATTR_NONNULL_ALL 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; p += l - 1;
continue; continue;
} }
if (vim_strchr(esc_chars, *p) != NULL || (bsl && rem_backslash(p))) if (vim_strchr(esc_chars, *p) != NULL || (bsl && rem_backslash(p))) {
++length; /* count a backslash */ ++length; // count a backslash
++length; /* count an ordinary char */ }
++length; // count an ordinary char
} }
char_u *escaped_string = xmalloc(length); 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) { if (l > 1) {
memcpy(p2, p, l); memcpy(p2, p, l);
p2 += l; p2 += l;
p += l - 1; /* skip multibyte char */ p += l - 1; // skip multibyte char
continue; 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++ = cc;
}
*p2++ = *p; *p2++ = *p;
} }
*p2 = NUL; *p2 = NUL;
@@ -182,8 +182,7 @@ 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. * When "do_newline" is false do not escape newline unless it is csh shell.
* Returns the result in allocated memory. * Returns the result in allocated memory.
*/ */
char_u *vim_strsave_shellescape(const char_u *string, char_u *vim_strsave_shellescape(const char_u *string, bool do_special, bool do_newline)
bool do_special, bool do_newline)
FUNC_ATTR_NONNULL_RET FUNC_ATTR_MALLOC FUNC_ATTR_NONNULL_ALL FUNC_ATTR_NONNULL_RET FUNC_ATTR_MALLOC FUNC_ATTR_NONNULL_ALL
{ {
char_u *d; char_u *d;
@@ -202,7 +201,7 @@ char_u *vim_strsave_shellescape(const char_u *string,
// itself must be escaped to get a literal '\'. // itself must be escaped to get a literal '\'.
fish_like = fish_like_shell(); 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 size_t length = STRLEN(string) + 3; // two quotes and a trailing NUL
for (const char_u *p = string; *p != NUL; MB_PTR_ADV(p)) { for (const char_u *p = string; *p != NUL; MB_PTR_ADV(p)) {
#ifdef WIN32 #ifdef WIN32
@@ -217,12 +216,13 @@ char_u *vim_strsave_shellescape(const char_u *string,
} }
if ((*p == '\n' && (csh_like || do_newline)) if ((*p == '\n' && (csh_like || do_newline))
|| (*p == '!' && (csh_like || do_special))) { || (*p == '!' && (csh_like || do_special))) {
++length; /* insert backslash */ ++length; // insert backslash
if (csh_like && do_special) if (csh_like && do_special) {
++length; /* insert backslash */ ++length; // insert backslash
}
} }
if (do_special && find_cmdline_var(p, &l) >= 0) { if (do_special && find_cmdline_var(p, &l) >= 0) {
++length; /* insert backslash */ ++length; // insert backslash
p += l - 1; p += l - 1;
} }
if (*p == '\\' && fish_like) { 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); escaped_string = xmalloc(length);
d = escaped_string; d = escaped_string;
@@ -264,15 +264,17 @@ char_u *vim_strsave_shellescape(const char_u *string,
if ((*p == '\n' && (csh_like || do_newline)) if ((*p == '\n' && (csh_like || do_newline))
|| (*p == '!' && (csh_like || do_special))) { || (*p == '!' && (csh_like || do_special))) {
*d++ = '\\'; *d++ = '\\';
if (csh_like && do_special) if (csh_like && do_special) {
*d++ = '\\'; *d++ = '\\';
}
*d++ = *p++; *d++ = *p++;
continue; continue;
} }
if (do_special && find_cmdline_var(p, &l) >= 0) { if (do_special && find_cmdline_var(p, &l) >= 0) {
*d++ = '\\'; /* insert backslash */ *d++ = '\\'; // insert backslash
while (--l != SIZE_MAX) /* copy the var */ while (--l != SIZE_MAX) { // copy the var
*d++ = *p++; *d++ = *p++;
}
continue; continue;
} }
if (*p == '\\' && fish_like) { 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 // add terminating quote and finish with a NUL
# ifdef WIN32 #ifdef WIN32
if (!p_ssl) { if (!p_ssl) {
*d++ = '"'; *d++ = '"';
} else } else
# endif #endif
*d++ = '\''; *d++ = '\'';
*d = NUL; *d = NUL;
@@ -387,8 +389,9 @@ void del_trailing_spaces(char_u *ptr)
char_u *q; char_u *q;
q = ptr + STRLEN(ptr); 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; *q = NUL;
}
} }
#if (!defined(HAVE_STRCASECMP) && !defined(HAVE_STRICMP)) #if (!defined(HAVE_STRCASECMP) && !defined(HAVE_STRICMP))
@@ -404,14 +407,16 @@ int vim_stricmp(const char *s1, const char *s2)
for (;; ) { for (;; ) {
i = (int)TOLOWER_LOC(*s1) - (int)TOLOWER_LOC(*s2); i = (int)TOLOWER_LOC(*s1) - (int)TOLOWER_LOC(*s2);
if (i != 0) if (i != 0) {
return i; /* this character different */ return i; // this character different
if (*s1 == NUL) }
break; /* strings match until NUL */ if (*s1 == NUL) {
break; // strings match until NUL
}
++s1; ++s1;
++s2; ++s2;
} }
return 0; /* strings match */ return 0; // strings match
} }
#endif #endif
@@ -428,15 +433,17 @@ int vim_strnicmp(const char *s1, const char *s2, size_t len)
while (len > 0) { while (len > 0) {
i = (int)TOLOWER_LOC(*s1) - (int)TOLOWER_LOC(*s2); i = (int)TOLOWER_LOC(*s1) - (int)TOLOWER_LOC(*s2);
if (i != 0) if (i != 0) {
return i; /* this character different */ return i; // this character different
if (*s1 == NUL) }
break; /* strings match until NUL */ if (*s1 == NUL) {
break; // strings match until NUL
}
++s1; ++s1;
++s2; ++s2;
--len; --len;
} }
return 0; /* strings match */ return 0; // strings match
} }
#endif #endif
@@ -490,10 +497,13 @@ bool has_non_ascii(const char_u *s)
{ {
const char_u *p; const char_u *p;
if (s != NULL) if (s != NULL) {
for (p = s; *p != NUL; ++p) for (p = s; *p != NUL; ++p) {
if (*p >= 128) if (*p >= 128) {
return true; return true;
}
}
}
return false; return false;
} }
@@ -504,7 +514,7 @@ bool has_non_ascii_len(const char *const s, const size_t len)
{ {
if (s != NULL) { if (s != NULL) {
for (size_t i = 0; i < len; i++) { for (size_t i = 0; i < len; i++) {
if ((uint8_t) s[i] >= 128) { if ((uint8_t)s[i] >= 128) {
return true; return true;
} }
} }
@@ -606,8 +616,7 @@ static const void *tv_ptr(const typval_T *const tvs, int *const idxp)
FUNC_ATTR_NONNULL_ALL FUNC_ATTR_WARN_UNUSED_RESULT FUNC_ATTR_NONNULL_ALL FUNC_ATTR_WARN_UNUSED_RESULT
{ {
#define OFF(attr) offsetof(union typval_vval_union, attr) #define OFF(attr) offsetof(union typval_vval_union, attr)
STATIC_ASSERT( STATIC_ASSERT(OFF(v_string) == OFF(v_list)
OFF(v_string) == OFF(v_list)
&& OFF(v_string) == OFF(v_dict) && OFF(v_string) == OFF(v_dict)
&& OFF(v_string) == OFF(v_partial) && 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_list)
@@ -735,8 +744,8 @@ int vim_snprintf(char *str, size_t str_m, const char *fmt, ...)
// Return the representation of infinity for printf() function: // Return the representation of infinity for printf() function:
// "-inf", "inf", "+inf", " inf", "-INF", "INF", "+INF" or " INF". // "-inf", "inf", "+inf", " inf", "-INF", "INF", "+INF" or " INF".
static const char *infinity_str(bool positive, char fmt_spec, static const char *infinity_str(bool positive, char fmt_spec, int force_sign,
int force_sign, int space_for_positive) int space_for_positive)
{ {
static const char *table[] = { static const char *table[] = {
"-inf", "inf", "+inf", " inf", "-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 /// @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. /// string if str_m was greater or equal to the return value.
int vim_vsnprintf_typval( int vim_vsnprintf_typval(char *str, size_t str_m, const char *fmt, va_list ap, typval_T *const tvs)
char *str, size_t str_m, const char *fmt, va_list ap, typval_T *const tvs)
{ {
size_t str_l = 0; size_t str_l = 0;
bool str_avail = str_l < str_m; bool str_avail = str_l < str_m;
@@ -800,7 +808,7 @@ int vim_vsnprintf_typval(
char length_modifier = '\0'; char length_modifier = '\0';
// temporary buffer for simple numeric->string conversion // 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]; char tmp[TMP_LEN];
// string address in case of string argument // string address in case of string argument
@@ -832,15 +840,22 @@ int vim_vsnprintf_typval(
// parse flags // parse flags
while (true) { while (true) {
switch (*p) { switch (*p) {
case '0': zero_padding = 1; p++; continue; case '0':
case '-': justify_left = 1; p++; continue; zero_padding = 1; p++; continue;
case '-':
justify_left = 1; p++; continue;
// if both '0' and '-' flags appear, '0' should be ignored // if both '0' and '-' flags appear, '0' should be ignored
case '+': force_sign = 1; space_for_positive = 0; p++; continue; case '+':
case ' ': force_sign = 1; p++; continue; force_sign = 1; space_for_positive = 0; p++; continue;
case ' ':
force_sign = 1; p++; continue;
// if both ' ' and '+' flags appear, ' ' should be ignored // if both ' ' and '+' flags appear, ' ' should be ignored
case '#': alternate_form = 1; p++; continue; case '#':
case '\'': p++; continue; alternate_form = 1; p++; continue;
default: break; case '\'':
p++; continue;
default:
break;
} }
break; break;
} }
@@ -905,16 +920,26 @@ int vim_vsnprintf_typval(
// common synonyms // common synonyms
switch (fmt_spec) { switch (fmt_spec) {
case 'i': fmt_spec = 'd'; break; case 'i':
case 'D': fmt_spec = 'd'; length_modifier = 'l'; break; fmt_spec = 'd'; break;
case 'U': fmt_spec = 'u'; length_modifier = 'l'; break; case 'D':
case 'O': fmt_spec = 'o'; length_modifier = 'l'; break; fmt_spec = 'd'; length_modifier = 'l'; break;
default: break; case 'U':
fmt_spec = 'u'; length_modifier = 'l'; break;
case 'O':
fmt_spec = 'o'; length_modifier = 'l'; break;
default:
break;
} }
switch (fmt_spec) { switch (fmt_spec) {
case 'b': case 'B': case 'b':
case 'd': case 'u': case 'o': case 'x': case 'X': case 'B':
case 'd':
case 'u':
case 'o':
case 'x':
case 'X':
if (tvs && length_modifier == '\0') { if (tvs && length_modifier == '\0') {
length_modifier = '2'; length_modifier = '2';
} }
@@ -923,7 +948,10 @@ int vim_vsnprintf_typval(
// get parameter value, do initial processing // get parameter value, do initial processing
switch (fmt_spec) { switch (fmt_spec) {
// '%' and 'c' behave similar to 's' regarding flags and field widths // '%' and 'c' behave similar to 's' regarding flags and field widths
case '%': case 'c': case 's': case 'S': case '%':
case 'c':
case 's':
case 'S':
str_arg_l = 1; str_arg_l = 1;
switch (fmt_spec) { switch (fmt_spec) {
case '%': case '%':
@@ -989,9 +1017,11 @@ int vim_vsnprintf_typval(
case 'd': case 'd':
case 'u': case 'u':
case 'b': case 'B': case 'b':
case 'B':
case 'o': case 'o':
case 'x': case 'X': case 'x':
case 'X':
case 'p': { case 'p': {
// u, b, B, o, x, X and p conversion specifiers imply // u, b, B, o, x, X and p conversion specifiers imply
// the value is unsigned; d implies a signed value // the value is unsigned; d implies a signed value
@@ -1015,33 +1045,28 @@ int vim_vsnprintf_typval(
} else if (fmt_spec == 'd') { } else if (fmt_spec == 'd') {
// signed // signed
switch (length_modifier) { switch (length_modifier) {
case '\0': { case '\0':
arg = (int)(tvs ? tv_nr(tvs, &arg_idx) : va_arg(ap, int)); arg = (int)(tvs ? tv_nr(tvs, &arg_idx) : va_arg(ap, int));
break; break;
} case 'h':
case 'h': {
// char and short arguments are passed as int16_t // char and short arguments are passed as int16_t
arg = (int16_t)(tvs ? tv_nr(tvs, &arg_idx) : va_arg(ap, int)); arg = (int16_t)(tvs ? tv_nr(tvs, &arg_idx) : va_arg(ap, int));
break; break;
} case 'l':
case 'l': {
arg = (tvs ? (long)tv_nr(tvs, &arg_idx) : va_arg(ap, long)); arg = (tvs ? (long)tv_nr(tvs, &arg_idx) : va_arg(ap, long));
break; break;
} case '2':
case '2': {
arg = ( arg = (
tvs tvs
? (long long)tv_nr(tvs, &arg_idx) // NOLINT (runtime/int) ? (long long)tv_nr(tvs, &arg_idx) // NOLINT (runtime/int)
: va_arg(ap, long long)); // NOLINT (runtime/int) : va_arg(ap, long long)); // NOLINT (runtime/int)
break; break;
} case 'z':
case 'z': {
arg = (tvs arg = (tvs
? (ptrdiff_t)tv_nr(tvs, &arg_idx) ? (ptrdiff_t)tv_nr(tvs, &arg_idx)
: va_arg(ap, ptrdiff_t)); : va_arg(ap, ptrdiff_t));
break; break;
} }
}
if (arg > 0) { if (arg > 0) {
arg_sign = 1; arg_sign = 1;
} else if (arg < 0) { } else if (arg < 0) {
@@ -1050,39 +1075,34 @@ int vim_vsnprintf_typval(
} else { } else {
// unsigned // unsigned
switch (length_modifier) { switch (length_modifier) {
case '\0': { case '\0':
uarg = (unsigned int)(tvs uarg = (unsigned int)(tvs
? tv_nr(tvs, &arg_idx) ? tv_nr(tvs, &arg_idx)
: va_arg(ap, unsigned int)); : va_arg(ap, unsigned int));
break; break;
} case 'h':
case 'h': {
uarg = (uint16_t)(tvs uarg = (uint16_t)(tvs
? tv_nr(tvs, &arg_idx) ? tv_nr(tvs, &arg_idx)
: va_arg(ap, unsigned int)); : va_arg(ap, unsigned int));
break; break;
} case 'l':
case 'l': {
uarg = (tvs uarg = (tvs
? (unsigned long)tv_nr(tvs, &arg_idx) ? (unsigned long)tv_nr(tvs, &arg_idx)
: va_arg(ap, unsigned long)); : va_arg(ap, unsigned long));
break; break;
} case '2':
case '2': {
uarg = (uintmax_t)(unsigned long long)( // NOLINT (runtime/int) uarg = (uintmax_t)(unsigned long long)( // NOLINT (runtime/int)
tvs tvs
? ((unsigned long long) // NOLINT (runtime/int) ? ((unsigned long long) // NOLINT (runtime/int)
tv_nr(tvs, &arg_idx)) tv_nr(tvs, &arg_idx))
: va_arg(ap, unsigned long long)); // NOLINT (runtime/int) : va_arg(ap, unsigned long long)); // NOLINT (runtime/int)
break; break;
} case 'z':
case 'z': {
uarg = (tvs uarg = (tvs
? (size_t)tv_nr(tvs, &arg_idx) ? (size_t)tv_nr(tvs, &arg_idx)
: va_arg(ap, size_t)); : va_arg(ap, size_t));
break; break;
} }
}
arg_sign = (uarg != 0); arg_sign = (uarg != 0);
} }
@@ -1120,19 +1140,18 @@ int vim_vsnprintf_typval(
// resulting formatted string is empty (d, i, u, b, B, o, x, X, p) // resulting formatted string is empty (d, i, u, b, B, o, x, X, p)
} else { } else {
switch (fmt_spec) { switch (fmt_spec) {
case 'p': { // pointer case 'p': // pointer
str_arg_l += (size_t)snprintf(tmp + str_arg_l, str_arg_l += (size_t)snprintf(tmp + str_arg_l,
sizeof(tmp) - str_arg_l, sizeof(tmp) - str_arg_l,
"%p", ptr_arg); "%p", ptr_arg);
break; break;
} case 'd': // signed
case 'd': { // signed
str_arg_l += (size_t)snprintf(tmp + str_arg_l, str_arg_l += (size_t)snprintf(tmp + str_arg_l,
sizeof(tmp) - str_arg_l, sizeof(tmp) - str_arg_l,
"%" PRIdMAX, arg); "%" PRIdMAX, arg);
break; break;
} case 'b':
case 'b': case 'B': { // binary case 'B': { // binary
size_t bits = 0; size_t bits = 0;
for (bits = sizeof(uintmax_t) * 8; bits > 0; bits--) { for (bits = sizeof(uintmax_t) * 8; bits > 0; bits--) {
if ((uarg >> (bits - 1)) & 0x1) { if ((uarg >> (bits - 1)) & 0x1) {
@@ -1211,8 +1230,7 @@ int vim_vsnprintf_typval(
case 'e': case 'e':
case 'E': case 'E':
case 'g': case 'g':
case 'G': case 'G': {
{
// floating point // floating point
char format[40]; char format[40];
int remove_trailing_zeroes = false; int remove_trailing_zeroes = false;

View File

@@ -37,45 +37,44 @@
// Some code from pangoterm http://www.leonerd.org.uk/code/pangoterm // Some code from pangoterm http://www.leonerd.org.uk/code/pangoterm
#include <assert.h> #include <assert.h>
#include <stdio.h>
#include <stdint.h>
#include <stdbool.h> #include <stdbool.h>
#include <stdint.h>
#include <stdio.h>
#include <vterm.h> #include <vterm.h>
#include "nvim/log.h" #include "nvim/api/private/helpers.h"
#include "nvim/vim.h" #include "nvim/ascii.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/buffer.h" #include "nvim/buffer.h"
#include "nvim/change.h" #include "nvim/change.h"
#include "nvim/ascii.h"
#include "nvim/getchar.h"
#include "nvim/ui.h"
#include "nvim/syntax.h"
#include "nvim/screen.h"
#include "nvim/keymap.h"
#include "nvim/edit.h" #include "nvim/edit.h"
#include "nvim/mouse.h"
#include "nvim/memline.h"
#include "nvim/map.h"
#include "nvim/misc1.h"
#include "nvim/move.h"
#include "nvim/main.h"
#include "nvim/state.h"
#include "nvim/ex_docmd.h"
#include "nvim/ex_cmds.h"
#include "nvim/window.h"
#include "nvim/fileio.h"
#include "nvim/event/loop.h" #include "nvim/event/loop.h"
#include "nvim/event/time.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/highlight.h"
#include "nvim/keymap.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/option.h"
#include "nvim/os/input.h" #include "nvim/os/input.h"
#include "nvim/api/private/helpers.h" #include "nvim/screen.h"
#include "nvim/state.h"
#include "nvim/syntax.h"
#include "nvim/terminal.h"
#include "nvim/ui.h"
#include "nvim/vim.h"
#include "nvim/window.h"
typedef struct terminal_state { typedef struct terminal_state {
VimState state; VimState state;
@@ -666,8 +665,7 @@ static int get_rgb(VTermState *state, VTermColor color)
} }
void terminal_get_line_attributes(Terminal *term, win_T *wp, int linenr, void terminal_get_line_attributes(Terminal *term, win_T *wp, int linenr, int *term_attrs)
int *term_attrs)
{ {
int height, width; int height, width;
vterm_get_size(term->vt, &height, &width); vterm_get_size(term->vt, &height, &width);
@@ -761,8 +759,7 @@ static int term_moverect(VTermRect dest, VTermRect src, void *data)
return 1; return 1;
} }
static int term_movecursor(VTermPos new, VTermPos old, int visible, static int term_movecursor(VTermPos new, VTermPos old, int visible, void *data)
void *data)
{ {
Terminal *term = data; Terminal *term = data;
term->cursor.row = new.row; term->cursor.row = new.row;
@@ -845,7 +842,6 @@ static int term_sb_push(int cols, const VTermScreenCell *cells, void *data)
// Make room at the start by shifting to the right. // Make room at the start by shifting to the right.
memmove(term->sb_buffer + 1, term->sb_buffer, 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) { } else if (term->sb_current > 0) {
// Make room at the start by shifting to the right. // Make room at the start by shifting to the right.
memmove(term->sb_buffer + 1, term->sb_buffer, memmove(term->sb_buffer + 1, term->sb_buffer,
@@ -919,9 +915,15 @@ static int term_sb_pop(int cols, VTermScreenCell *cells, void *data)
static void convert_modifiers(int key, VTermModifier *statep) static void convert_modifiers(int key, VTermModifier *statep)
{ {
if (mod_mask & MOD_MASK_SHIFT) { *statep |= VTERM_MOD_SHIFT; } if (mod_mask & MOD_MASK_SHIFT) {
if (mod_mask & MOD_MASK_CTRL) { *statep |= VTERM_MOD_CTRL; } *statep |= VTERM_MOD_SHIFT;
if (mod_mask & MOD_MASK_ALT) { *statep |= VTERM_MOD_ALT; } }
if (mod_mask & MOD_MASK_CTRL) {
*statep |= VTERM_MOD_CTRL;
}
if (mod_mask & MOD_MASK_ALT) {
*statep |= VTERM_MOD_ALT;
}
switch (key) { switch (key) {
case K_S_TAB: case K_S_TAB:
@@ -956,115 +958,212 @@ static VTermKey convert_key(int key, VTermModifier *statep)
convert_modifiers(key, statep); convert_modifiers(key, statep);
switch (key) { switch (key) {
case K_BS: return VTERM_KEY_BACKSPACE; case K_BS:
case K_S_TAB: FALLTHROUGH; return VTERM_KEY_BACKSPACE;
case TAB: return VTERM_KEY_TAB; case K_S_TAB:
case Ctrl_M: return VTERM_KEY_ENTER; FALLTHROUGH;
case ESC: return VTERM_KEY_ESCAPE; 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_S_UP:
case K_UP: return VTERM_KEY_UP; FALLTHROUGH;
case K_S_DOWN: FALLTHROUGH; case K_UP:
case K_DOWN: return VTERM_KEY_DOWN; return VTERM_KEY_UP;
case K_S_LEFT: FALLTHROUGH; case K_S_DOWN:
case K_C_LEFT: FALLTHROUGH; FALLTHROUGH;
case K_LEFT: return VTERM_KEY_LEFT; case K_DOWN:
case K_S_RIGHT: FALLTHROUGH; return VTERM_KEY_DOWN;
case K_C_RIGHT: FALLTHROUGH; case K_S_LEFT:
case K_RIGHT: return VTERM_KEY_RIGHT; 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_INS:
case K_DEL: return VTERM_KEY_DEL; return VTERM_KEY_INS;
case K_HOME: return VTERM_KEY_HOME; case K_DEL:
case K_END: return VTERM_KEY_END; return VTERM_KEY_DEL;
case K_PAGEUP: return VTERM_KEY_PAGEUP; case K_HOME:
case K_PAGEDOWN: return VTERM_KEY_PAGEDOWN; 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_K0:
case K_KINS: return VTERM_KEY_KP_0; FALLTHROUGH;
case K_K1: FALLTHROUGH; case K_KINS:
case K_KEND: return VTERM_KEY_KP_1; return VTERM_KEY_KP_0;
case K_K2: FALLTHROUGH; case K_K1:
case K_KDOWN: return VTERM_KEY_KP_2; FALLTHROUGH;
case K_K3: FALLTHROUGH; case K_KEND:
case K_KPAGEDOWN: return VTERM_KEY_KP_3; return VTERM_KEY_KP_1;
case K_K4: FALLTHROUGH; case K_K2:
case K_KLEFT: return VTERM_KEY_KP_4; FALLTHROUGH;
case K_K5: FALLTHROUGH; case K_KDOWN:
case K_KORIGIN: return VTERM_KEY_KP_5; return VTERM_KEY_KP_2;
case K_K6: FALLTHROUGH; case K_K3:
case K_KRIGHT: return VTERM_KEY_KP_6; FALLTHROUGH;
case K_K7: FALLTHROUGH; case K_KPAGEDOWN:
case K_KHOME: return VTERM_KEY_KP_7; return VTERM_KEY_KP_3;
case K_K8: FALLTHROUGH; case K_K4:
case K_KUP: return VTERM_KEY_KP_8; FALLTHROUGH;
case K_K9: FALLTHROUGH; case K_KLEFT:
case K_KPAGEUP: return VTERM_KEY_KP_9; return VTERM_KEY_KP_4;
case K_KDEL: FALLTHROUGH; case K_K5:
case K_KPOINT: return VTERM_KEY_KP_PERIOD; FALLTHROUGH;
case K_KENTER: return VTERM_KEY_KP_ENTER; case K_KORIGIN:
case K_KPLUS: return VTERM_KEY_KP_PLUS; return VTERM_KEY_KP_5;
case K_KMINUS: return VTERM_KEY_KP_MINUS; case K_K6:
case K_KMULTIPLY: return VTERM_KEY_KP_MULT; FALLTHROUGH;
case K_KDIVIDE: return VTERM_KEY_KP_DIVIDE; 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_S_F1:
case K_F1: return VTERM_KEY_FUNCTION(1); FALLTHROUGH;
case K_S_F2: FALLTHROUGH; case K_F1:
case K_F2: return VTERM_KEY_FUNCTION(2); return VTERM_KEY_FUNCTION(1);
case K_S_F3: FALLTHROUGH; case K_S_F2:
case K_F3: return VTERM_KEY_FUNCTION(3); FALLTHROUGH;
case K_S_F4: FALLTHROUGH; case K_F2:
case K_F4: return VTERM_KEY_FUNCTION(4); return VTERM_KEY_FUNCTION(2);
case K_S_F5: FALLTHROUGH; case K_S_F3:
case K_F5: return VTERM_KEY_FUNCTION(5); FALLTHROUGH;
case K_S_F6: FALLTHROUGH; case K_F3:
case K_F6: return VTERM_KEY_FUNCTION(6); return VTERM_KEY_FUNCTION(3);
case K_S_F7: FALLTHROUGH; case K_S_F4:
case K_F7: return VTERM_KEY_FUNCTION(7); FALLTHROUGH;
case K_S_F8: FALLTHROUGH; case K_F4:
case K_F8: return VTERM_KEY_FUNCTION(8); return VTERM_KEY_FUNCTION(4);
case K_S_F9: FALLTHROUGH; case K_S_F5:
case K_F9: return VTERM_KEY_FUNCTION(9); FALLTHROUGH;
case K_S_F10: FALLTHROUGH; case K_F5:
case K_F10: return VTERM_KEY_FUNCTION(10); return VTERM_KEY_FUNCTION(5);
case K_S_F11: FALLTHROUGH; case K_S_F6:
case K_F11: return VTERM_KEY_FUNCTION(11); FALLTHROUGH;
case K_S_F12: FALLTHROUGH; case K_F6:
case K_F12: return VTERM_KEY_FUNCTION(12); 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_F13:
case K_F14: return VTERM_KEY_FUNCTION(14); return VTERM_KEY_FUNCTION(13);
case K_F15: return VTERM_KEY_FUNCTION(15); case K_F14:
case K_F16: return VTERM_KEY_FUNCTION(16); return VTERM_KEY_FUNCTION(14);
case K_F17: return VTERM_KEY_FUNCTION(17); case K_F15:
case K_F18: return VTERM_KEY_FUNCTION(18); return VTERM_KEY_FUNCTION(15);
case K_F19: return VTERM_KEY_FUNCTION(19); case K_F16:
case K_F20: return VTERM_KEY_FUNCTION(20); return VTERM_KEY_FUNCTION(16);
case K_F21: return VTERM_KEY_FUNCTION(21); case K_F17:
case K_F22: return VTERM_KEY_FUNCTION(22); return VTERM_KEY_FUNCTION(17);
case K_F23: return VTERM_KEY_FUNCTION(23); case K_F18:
case K_F24: return VTERM_KEY_FUNCTION(24); return VTERM_KEY_FUNCTION(18);
case K_F25: return VTERM_KEY_FUNCTION(25); case K_F19:
case K_F26: return VTERM_KEY_FUNCTION(26); return VTERM_KEY_FUNCTION(19);
case K_F27: return VTERM_KEY_FUNCTION(27); case K_F20:
case K_F28: return VTERM_KEY_FUNCTION(28); return VTERM_KEY_FUNCTION(20);
case K_F29: return VTERM_KEY_FUNCTION(29); case K_F21:
case K_F30: return VTERM_KEY_FUNCTION(30); return VTERM_KEY_FUNCTION(21);
case K_F31: return VTERM_KEY_FUNCTION(31); case K_F22:
case K_F32: return VTERM_KEY_FUNCTION(32); return VTERM_KEY_FUNCTION(22);
case K_F33: return VTERM_KEY_FUNCTION(33); case K_F23:
case K_F34: return VTERM_KEY_FUNCTION(34); return VTERM_KEY_FUNCTION(23);
case K_F35: return VTERM_KEY_FUNCTION(35); case K_F24:
case K_F36: return VTERM_KEY_FUNCTION(36); return VTERM_KEY_FUNCTION(24);
case K_F37: return VTERM_KEY_FUNCTION(37); 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; default:
return VTERM_KEY_NONE;
} }
} }
static void mouse_action(Terminal *term, int button, int row, int col, static void mouse_action(Terminal *term, int button, int row, int col, bool drag, VTermModifier mod)
bool drag, VTermModifier mod)
{ {
if (term->pressed_button && (term->pressed_button != button || !drag)) { if (term->pressed_button && (term->pressed_button != button || !drag)) {
// release the previous button // release the previous button
@@ -1100,16 +1199,26 @@ static bool send_mouse_event(Terminal *term, int c)
bool drag = false; bool drag = false;
switch (c) { switch (c) {
case K_LEFTDRAG: drag = true; FALLTHROUGH; case K_LEFTDRAG:
case K_LEFTMOUSE: button = 1; break; drag = true; FALLTHROUGH;
case K_MOUSEMOVE: drag = true; button = 0; break; case K_LEFTMOUSE:
case K_MIDDLEDRAG: drag = true; FALLTHROUGH; button = 1; break;
case K_MIDDLEMOUSE: button = 2; break; case K_MOUSEMOVE:
case K_RIGHTDRAG: drag = true; FALLTHROUGH; drag = true; button = 0; break;
case K_RIGHTMOUSE: button = 3; break; case K_MIDDLEDRAG:
case K_MOUSEDOWN: button = 4; break; drag = true; FALLTHROUGH;
case K_MOUSEUP: button = 5; break; case K_MIDDLEMOUSE:
default: return false; 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); mouse_action(term, button, row, col - offset, drag, 0);
@@ -1181,8 +1290,7 @@ static void fetch_row(Terminal *term, int row, int end_col)
term->textbuf[line_len] = 0; term->textbuf[line_len] = 0;
} }
static bool fetch_cell(Terminal *term, int row, int col, static bool fetch_cell(Terminal *term, int row, int col, VTermScreenCell *cell)
VTermScreenCell *cell)
{ {
if (row < 0) { if (row < 0) {
ScrollbackLine *sbrow = term->sb_buffer[-row - 1]; ScrollbackLine *sbrow = term->sb_buffer[-row - 1];
@@ -1197,7 +1305,7 @@ static bool fetch_cell(Terminal *term, int row, int col,
return false; return false;
} }
} else { } else {
vterm_screen_get_cell(term->vts, (VTermPos){.row = row, .col = col}, vterm_screen_get_cell(term->vts, (VTermPos){ .row = row, .col = col },
cell); cell);
} }
return true; return true;

View File

@@ -1,4 +1,4 @@
# Uncrustify-0.73.0-186-03faf73c # Uncrustify-0.73.0-186-03faf73c5
# #
# General options # General options