mirror of
https://github.com/neovim/neovim.git
synced 2025-09-22 11:18:19 +00:00
refactor: format with uncrustify #15842
* refactor: format with uncrustify * refactor: convert function comments to doxygen
This commit is contained in:
@@ -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;
|
||||
@@ -231,12 +227,14 @@ void ex_cstag(exarg_T *eap)
|
||||
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,22 +243,25 @@ 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)
|
||||
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)
|
||||
if (ret == FALSE) {
|
||||
cs_free_tags();
|
||||
}
|
||||
}
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
@@ -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,12 +415,10 @@ 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;
|
||||
@@ -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"),
|
||||
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);
|
||||
}
|
||||
@@ -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);
|
||||
|
||||
@@ -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
|
||||
@@ -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,12 +1014,14 @@ 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);
|
||||
|
||||
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",
|
||||
curbuf->b_fname, TRUE, curbuf);
|
||||
if (use_ll)
|
||||
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);
|
||||
}
|
||||
}
|
||||
@@ -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,
|
||||
&contexts, &matched);
|
||||
xfree(nummatches);
|
||||
if (matches == NULL)
|
||||
if (matches == NULL) {
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
(void)cs_manage_matches(matches, contexts, matched, Store);
|
||||
|
||||
@@ -1089,7 +1120,7 @@ static int cs_help(exarg_T *eap)
|
||||
cmdp->name,
|
||||
help, space_cnt, " ",
|
||||
cmdp->usage);
|
||||
if (strcmp(cmdp->name, "find") == 0)
|
||||
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,9 +1186,10 @@ 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,26 +1216,29 @@ 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,23 +1262,25 @@ 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;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (!killall && (i >= csinfo_size || csinfo[i].fname == NULL)) {
|
||||
if (p_csverbose) {
|
||||
@@ -1250,9 +1290,10 @@ 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,9 +1411,10 @@ 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';
|
||||
@@ -1432,12 +1475,15 @@ retry:
|
||||
*
|
||||
* <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);
|
||||
}
|
||||
|
||||
@@ -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);
|
||||
@@ -1907,8 +1960,9 @@ static int cs_reset(exarg_T *eap)
|
||||
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,9 +1973,10 @@ 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
|
||||
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.
|
||||
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"),
|
||||
} 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;
|
||||
}
|
||||
|
@@ -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;
|
||||
|
||||
|
@@ -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"
|
||||
|
@@ -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;
|
||||
|
@@ -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,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.
|
||||
* 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;
|
||||
@@ -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;
|
||||
|
||||
@@ -387,8 +389,9 @@ void del_trailing_spaces(char_u *ptr)
|
||||
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;
|
||||
}
|
||||
}
|
||||
@@ -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
|
||||
{
|
||||
#define OFF(attr) offsetof(union typval_vval_union, attr)
|
||||
STATIC_ASSERT(
|
||||
OFF(v_string) == OFF(v_list)
|
||||
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)
|
||||
@@ -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;
|
||||
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;
|
||||
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 '#':
|
||||
alternate_form = 1; p++; continue;
|
||||
case '\'':
|
||||
p++; continue;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
break;
|
||||
}
|
||||
@@ -905,16 +920,26 @@ 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':
|
||||
case 'b':
|
||||
case 'B':
|
||||
case 'd':
|
||||
case 'u':
|
||||
case 'o':
|
||||
case 'x':
|
||||
case 'X':
|
||||
if (tvs && length_modifier == '\0') {
|
||||
length_modifier = '2';
|
||||
}
|
||||
@@ -923,7 +948,10 @@ int vim_vsnprintf_typval(
|
||||
// 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':
|
||||
case '%':
|
||||
case 'c':
|
||||
case 's':
|
||||
case 'S':
|
||||
str_arg_l = 1;
|
||||
switch (fmt_spec) {
|
||||
case '%':
|
||||
@@ -989,9 +1017,11 @@ int vim_vsnprintf_typval(
|
||||
|
||||
case 'd':
|
||||
case 'u':
|
||||
case 'b': case 'B':
|
||||
case 'b':
|
||||
case 'B':
|
||||
case 'o':
|
||||
case 'x': case 'X':
|
||||
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
|
||||
@@ -1015,33 +1045,28 @@ int vim_vsnprintf_typval(
|
||||
} else if (fmt_spec == 'd') {
|
||||
// signed
|
||||
switch (length_modifier) {
|
||||
case '\0': {
|
||||
case '\0':
|
||||
arg = (int)(tvs ? tv_nr(tvs, &arg_idx) : va_arg(ap, int));
|
||||
break;
|
||||
}
|
||||
case 'h': {
|
||||
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': {
|
||||
case 'l':
|
||||
arg = (tvs ? (long)tv_nr(tvs, &arg_idx) : va_arg(ap, long));
|
||||
break;
|
||||
}
|
||||
case '2': {
|
||||
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': {
|
||||
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) {
|
||||
@@ -1050,39 +1075,34 @@ int vim_vsnprintf_typval(
|
||||
} else {
|
||||
// unsigned
|
||||
switch (length_modifier) {
|
||||
case '\0': {
|
||||
case '\0':
|
||||
uarg = (unsigned int)(tvs
|
||||
? tv_nr(tvs, &arg_idx)
|
||||
: va_arg(ap, unsigned int));
|
||||
break;
|
||||
}
|
||||
case 'h': {
|
||||
case 'h':
|
||||
uarg = (uint16_t)(tvs
|
||||
? tv_nr(tvs, &arg_idx)
|
||||
: va_arg(ap, unsigned int));
|
||||
break;
|
||||
}
|
||||
case 'l': {
|
||||
case 'l':
|
||||
uarg = (tvs
|
||||
? (unsigned long)tv_nr(tvs, &arg_idx)
|
||||
: va_arg(ap, unsigned long));
|
||||
break;
|
||||
}
|
||||
case '2': {
|
||||
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': {
|
||||
case 'z':
|
||||
uarg = (tvs
|
||||
? (size_t)tv_nr(tvs, &arg_idx)
|
||||
: va_arg(ap, size_t));
|
||||
break;
|
||||
}
|
||||
}
|
||||
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)
|
||||
} else {
|
||||
switch (fmt_spec) {
|
||||
case 'p': { // pointer
|
||||
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
|
||||
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
|
||||
case 'b':
|
||||
case 'B': { // binary
|
||||
size_t bits = 0;
|
||||
for (bits = sizeof(uintmax_t) * 8; bits > 0; bits--) {
|
||||
if ((uarg >> (bits - 1)) & 0x1) {
|
||||
@@ -1211,8 +1230,7 @@ int vim_vsnprintf_typval(
|
||||
case 'e':
|
||||
case 'E':
|
||||
case 'g':
|
||||
case 'G':
|
||||
{
|
||||
case 'G': {
|
||||
// floating point
|
||||
char format[40];
|
||||
int remove_trailing_zeroes = false;
|
||||
|
@@ -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/getchar.h"
|
||||
#include "nvim/ui.h"
|
||||
#include "nvim/syntax.h"
|
||||
#include "nvim/screen.h"
|
||||
#include "nvim/keymap.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/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/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 {
|
||||
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,
|
||||
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);
|
||||
@@ -761,8 +759,7 @@ static int term_moverect(VTermRect dest, VTermRect src, void *data)
|
||||
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;
|
||||
@@ -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.
|
||||
memmove(term->sb_buffer + 1, term->sb_buffer,
|
||||
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,
|
||||
@@ -919,9 +915,15 @@ 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:
|
||||
@@ -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_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_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_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_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_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);
|
||||
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;
|
||||
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);
|
||||
@@ -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,7 +1305,7 @@ static bool fetch_cell(Terminal *term, int row, int col,
|
||||
return false;
|
||||
}
|
||||
} else {
|
||||
vterm_screen_get_cell(term->vts, (VTermPos){.row = row, .col = col},
|
||||
vterm_screen_get_cell(term->vts, (VTermPos){ .row = row, .col = col },
|
||||
cell);
|
||||
}
|
||||
return true;
|
||||
|
@@ -1,4 +1,4 @@
|
||||
# Uncrustify-0.73.0-186-03faf73c
|
||||
# Uncrustify-0.73.0-186-03faf73c5
|
||||
|
||||
#
|
||||
# General options
|
||||
|
Reference in New Issue
Block a user