aboutsummaryrefslogtreecommitdiff
path: root/src/nvim/if_cscope.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/nvim/if_cscope.c')
-rw-r--r--src/nvim/if_cscope.c207
1 files changed, 91 insertions, 116 deletions
diff --git a/src/nvim/if_cscope.c b/src/nvim/if_cscope.c
index 689d1fce0d..bc31d702f4 100644
--- a/src/nvim/if_cscope.c
+++ b/src/nvim/if_cscope.c
@@ -1,13 +1,11 @@
// 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
-/*
- * CSCOPE support for Vim added by Andy Kahn <kahn@zk3.dec.com>
- * Ported to Win32 by Sergey Khorev <sergey.khorev@gmail.com>
- *
- * The basic idea/structure of cscope for Vim was borrowed from Nvi. There
- * might be a few lines of code that look similar to what Nvi has.
- */
+// CSCOPE support for Vim added by Andy Kahn <kahn@zk3.dec.com>
+// Ported to Win32 by Sergey Khorev <sergey.khorev@gmail.com>
+//
+// The basic idea/structure of cscope for Vim was borrowed from Nvi. There
+// might be a few lines of code that look similar to what Nvi has.
#include <assert.h>
#include <errno.h>
@@ -78,10 +76,8 @@ static enum {
EXP_CSCOPE_KILL, // expand ":cscope kill" arguments
} expand_what;
-/*
- * Function given to ExpandGeneric() to obtain the cscope command
- * expansion.
- */
+// Function given to ExpandGeneric() to obtain the cscope command
+// expansion.
char *get_cscope_name(expand_T *xp, int idx)
{
int current_idx;
@@ -140,9 +136,7 @@ char *get_cscope_name(expand_T *xp, int idx)
}
}
-/*
- * Handle command line completion for :cscope command.
- */
+// Handle command line completion for :cscope command.
void set_context_in_cscope_cmd(expand_T *xp, const char *arg, cmdidx_T cmdidx)
{
// Default: expand subcommands.
@@ -153,10 +147,10 @@ void set_context_in_cscope_cmd(expand_T *xp, const char *arg, cmdidx_T cmdidx)
// (part of) subcommand already typed
if (*arg != NUL) {
- const char *p = (const char *)skiptowhite((const char_u *)arg);
+ const char *p = (const char *)skiptowhite(arg);
if (*p != NUL) { // Past first word.
xp->xp_pattern = skipwhite(p);
- if (*skiptowhite((char_u *)xp->xp_pattern) != NUL) {
+ if (*skiptowhite(xp->xp_pattern) != NUL) {
xp->xp_context = EXPAND_NOTHING;
} else if (STRNICMP(arg, "add", p - arg) == 0) {
xp->xp_context = EXPAND_FILES;
@@ -203,19 +197,19 @@ static void do_cscope_general(exarg_T *eap, int make_split)
/// Implementation of ":cscope" and ":lcscope"
void ex_cscope(exarg_T *eap)
{
- do_cscope_general(eap, FALSE);
+ do_cscope_general(eap, false);
}
/// Implementation of ":scscope". Same as ex_cscope(), but splits window, too.
void ex_scscope(exarg_T *eap)
{
- do_cscope_general(eap, TRUE);
+ do_cscope_general(eap, true);
}
/// Implementation of ":cstag"
void ex_cstag(exarg_T *eap)
{
- int ret = FALSE;
+ int ret = false;
if (*eap->arg == NUL) {
(void)emsg(_("E562: Usage: cstag <ident>"));
@@ -234,16 +228,16 @@ void ex_cstag(exarg_T *eap)
}
if (cs_check_for_tags()) {
- ret = do_tag((char_u *)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()) {
- ret = do_tag((char_u *)eap->arg, DT_JUMP, 0, eap->forceit, false);
+ ret = do_tag(eap->arg, DT_JUMP, 0, eap->forceit, false);
}
break;
case 1:
if (cs_check_for_tags()) {
- ret = do_tag((char_u *)eap->arg, DT_JUMP, 0, eap->forceit, false);
+ ret = do_tag(eap->arg, DT_JUMP, 0, eap->forceit, false);
if (ret == false) {
if (msg_col) {
msg_putchar('\n');
@@ -278,7 +272,7 @@ void ex_cstag(exarg_T *eap)
/// This simulates a vim_fgets(), but for cscope, returns the next line
/// from the cscope output. should only be called from find_tags()
///
-/// @return true if eof, FALSE otherwise
+/// @return true if eof, false otherwise
bool cs_fgets(char_u *buf, int size)
FUNC_ATTR_NONNULL_ALL
{
@@ -304,33 +298,31 @@ void cs_print_tags(void)
cs_manage_matches(NULL, NULL, 0, Print);
}
-/*
- * "cscope_connection([{num} , {dbpath} [, {prepend}]])" function
- *
- * Checks for the existence of a |cscope| connection. If no
- * parameters are specified, then the function returns:
- *
- * 0, if cscope was not available (not compiled in), or if there
- * are no cscope connections; or
- * 1, if there is at least one cscope connection.
- *
- * If parameters are specified, then the value of {num}
- * determines how existence of a cscope connection is checked:
- *
- * {num} Description of existence check
- * ----- ------------------------------
- * 0 Same as no parameters (e.g., "cscope_connection()").
- * 1 Ignore {prepend}, and use partial string matches for
- * {dbpath}.
- * 2 Ignore {prepend}, and use exact string matches for
- * {dbpath}.
- * 3 Use {prepend}, use partial string matches for both
- * {dbpath} and {prepend}.
- * 4 Use {prepend}, use exact string matches for both
- * {dbpath} and {prepend}.
- *
- * Note: All string comparisons are case sensitive!
- */
+// "cscope_connection([{num} , {dbpath} [, {prepend}]])" function
+//
+// Checks for the existence of a |cscope| connection. If no
+// parameters are specified, then the function returns:
+//
+// 0, if cscope was not available (not compiled in), or if there
+// are no cscope connections; or
+// 1, if there is at least one cscope connection.
+//
+// If parameters are specified, then the value of {num}
+// determines how existence of a cscope connection is checked:
+//
+// {num} Description of existence check
+// ----- ------------------------------
+// 0 Same as no parameters (e.g., "cscope_connection()").
+// 1 Ignore {prepend}, and use partial string matches for
+// {dbpath}.
+// 2 Ignore {prepend}, and use exact string matches for
+// {dbpath}.
+// 3 Use {prepend}, use partial string matches for both
+// {dbpath} and {prepend}.
+// 4 Use {prepend}, use exact string matches for both
+// {dbpath} and {prepend}.
+//
+// Note: All string comparisons are case sensitive!
bool cs_connection(int num, char_u *dbpath, char_u *ppath)
{
if (num < 0 || num > 4 || (num > 0 && !dbpath)) {
@@ -379,9 +371,8 @@ bool cs_connection(int num, char_u *dbpath, char_u *ppath)
return false;
} // cs_connection
-/*
- * PRIVATE functions
- ****************************************************************************/
+// PRIVATE functions
+// **************************************************************************
/// Add cscope database or a directory name (to look for cscope.out)
/// to the cscope connection list.
@@ -423,8 +414,8 @@ static int cs_add_common(char *arg1, char *arg2, char *flags)
// get the filename (arg1), expand it, and try to stat it
fname = xmalloc(MAXPATHL + 1);
- expand_env((char_u *)arg1, (char_u *)fname, MAXPATHL);
- size_t len = STRLEN(fname);
+ expand_env(arg1, fname, MAXPATHL);
+ size_t len = strlen(fname);
fbuf = fname;
(void)modify_fname(":p", false, &usedlen, &fname, &fbuf, &len);
if (fname == NULL) {
@@ -445,8 +436,8 @@ staterr:
// get the prepend path (arg2), expand it, and see if it exists
if (arg2 != NULL) {
ppath = xmalloc(MAXPATHL + 1);
- expand_env((char_u *)arg2, (char_u *)ppath, MAXPATHL);
- if (!os_path_exists((char_u *)ppath)) {
+ expand_env(arg2, ppath, MAXPATHL);
+ if (!os_path_exists(ppath)) {
goto staterr;
}
}
@@ -658,7 +649,7 @@ static char *cs_create_cmd(char *csoption, char *pattern)
return NULL;
}
- // Skip white space before the patter, except for text and pattern search,
+ // Skip white space before the pattern, except for text and pattern search,
// they may want to use the leading white space.
pat = pattern;
if (search != 4 && search != 6) {
@@ -684,10 +675,8 @@ static int cs_create_connection(size_t i)
char *prog, *cmd, *ppath = NULL;
#if defined(UNIX)
- /*
- * Cscope reads from to_cs[0] and writes to from_cs[1]; vi reads from
- * from_cs[0] and writes to to_cs[1].
- */
+ // Cscope reads from to_cs[0] and writes to from_cs[1]; vi reads from
+ // from_cs[0] and writes to to_cs[1].
to_cs[0] = to_cs[1] = from_cs[0] = from_cs[1] = -1;
if (pipe(to_cs) < 0 || pipe(from_cs) < 0) {
(void)emsg(_("E566: Could not create cscope pipes"));
@@ -757,14 +746,14 @@ err_closing:
#endif
// expand the cscope exec for env var's
prog = xmalloc(MAXPATHL + 1);
- expand_env(p_csprg, (char_u *)prog, MAXPATHL);
+ expand_env(p_csprg, prog, MAXPATHL);
// alloc space to hold the cscope command
size_t len = strlen(prog) + strlen(csinfo[i].fname) + 32;
if (csinfo[i].ppath) {
// expand the prepend path for env var's
ppath = xmalloc(MAXPATHL + 1);
- expand_env((char_u *)csinfo[i].ppath, (char_u *)ppath, MAXPATHL);
+ expand_env(csinfo[i].ppath, ppath, MAXPATHL);
len += strlen(ppath);
}
@@ -779,7 +768,7 @@ err_closing:
#if defined(UNIX)
(void)snprintf(cmd, len, "exec %s -dl -f %s", prog, csinfo[i].fname);
#else
- // WIN32
+ // MS-Windows
(void)snprintf(cmd, len, "%s -dl -f %s", prog, csinfo[i].fname);
#endif
if (csinfo[i].ppath != NULL) {
@@ -831,7 +820,7 @@ err_closing:
}
#else
- // WIN32
+ // MS-Windows
// Create a new process to run cscope and use pipes to talk with it
GetStartupInfo(&si);
si.dwFlags = STARTF_USESTDHANDLES | STARTF_USESHOWWINDOW;
@@ -839,7 +828,7 @@ err_closing:
si.hStdOutput = stdout_wr;
si.hStdError = stdout_wr;
si.hStdInput = stdin_rd;
- created = CreateProcess(NULL, cmd, NULL, NULL, TRUE, CREATE_NEW_CONSOLE,
+ created = CreateProcess(NULL, cmd, NULL, NULL, true, CREATE_NEW_CONSOLE,
NULL, NULL, &si, &pi);
xfree(prog);
xfree(cmd);
@@ -875,7 +864,7 @@ err_closing:
/// Query cscope using command line interface. Parse the output and use tselect
/// to allow choices. Like Nvi, creates a pipe to send to/from query/cscope.
///
-/// @return TRUE if we jump to a tag or abort, FALSE if not.
+/// @return true if we jump to a tag or abort, false if not.
static int cs_find(exarg_T *eap)
{
char *opt, *pat;
@@ -896,11 +885,9 @@ static int cs_find(exarg_T *eap)
return false;
}
- /*
- * 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) {
+ // 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]) {
eap->arg[i] = ' ';
}
@@ -953,7 +940,7 @@ static bool cs_find_common(char *opt, char *pat, int forceit, int verbose, bool
cmdletter = opt[0];
}
- qfpos = vim_strchr((char *)p_csqf, cmdletter);
+ qfpos = vim_strchr(p_csqf, cmdletter);
if (qfpos != NULL) {
qfpos++;
// next symbol must be + or -
@@ -1016,7 +1003,7 @@ static bool cs_find_common(char *opt, char *pat, int forceit, int verbose, bool
if (qfpos != NULL && *qfpos != '0') {
// Fill error list.
FILE *f;
- char_u *tmp = vim_tempname();
+ char_u *tmp = (char_u *)vim_tempname();
qf_info_T *qi = NULL;
win_T *wp = NULL;
@@ -1041,10 +1028,8 @@ static bool cs_find_common(char *opt, char *pat, int forceit, int verbose, bool
apply_autocmds(EVENT_QUICKFIXCMDPOST, "cscope", curbuf->b_fname, true, curbuf);
if (use_ll) {
- /*
- * In the location list window, use the displayed location
- * list. Otherwise, use the location list for the window.
- */
+ // 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;
}
@@ -1068,7 +1053,7 @@ static bool cs_find_common(char *opt, char *pat, int forceit, int verbose, bool
(void)cs_manage_matches(matches, contexts, matched, Store);
- return do_tag((char_u *)pat, DT_CSCOPE, 0, forceit, verbose);
+ return do_tag(pat, DT_CSCOPE, 0, forceit, verbose);
}
}
@@ -1106,7 +1091,7 @@ static int cs_help(exarg_T *eap)
cmdp++;
}
- wait_return(TRUE);
+ wait_return(true);
return CSCOPE_SUCCESS;
}
@@ -1195,7 +1180,7 @@ static cscmd_T *cs_lookup_cmd(exarg_T *eap)
}
// 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(eap->arg, (const char *)" ")) == NULL) { // NOLINT(runtime/threadsafe_fn)
return NULL;
@@ -1280,7 +1265,7 @@ static void cs_kill_execute(size_t i, char *cname)
(void)smsg_attr(HL_ATTR(HLF_R) | MSG_HIST,
_("cscope connection %s closed"), cname);
}
- cs_release_csp(i, TRUE);
+ cs_release_csp(i, true);
}
/// Convert the cscope output into a ctags style entry (as might be found
@@ -1431,11 +1416,9 @@ retry:
}
*p = '\0';
- /*
- * cscope output is in the following format:
- *
- * <filename> <context> <line number> <pattern>
- */
+ // cscope output is in the following format:
+ //
+ // <filename> <context> <line number> <pattern>
char *saveptr = NULL;
if ((name = os_strtok(buf, (const char *)" ", &saveptr)) == NULL) {
return NULL;
@@ -1651,7 +1634,7 @@ static void cs_print_tags_priv(char **matches, char **cntxts,
}
(void)snprintf(buf, bufsize, csfmt_str, i + 1, lno);
msg_puts_attr(buf, HL_ATTR(HLF_CM));
- msg_outtrans_long_attr((char_u *)cs_pathcomponents(fname), HL_ATTR(HLF_CM));
+ msg_outtrans_long_attr(cs_pathcomponents(fname), HL_ATTR(HLF_CM));
// compute the required space for the context
char *context = cntxts[i] ? cntxts[i] : globalcntx;
@@ -1673,11 +1656,11 @@ static void cs_print_tags_priv(char **matches, char **cntxts,
msg_putchar('\n');
}
msg_advance(12);
- msg_outtrans_long_attr((char_u *)buf, 0);
+ msg_outtrans_long_attr(buf, 0);
msg_putchar('\n');
if (extra != NULL) {
msg_advance(13);
- msg_outtrans_long_attr((char_u *)extra, 0);
+ msg_outtrans_long_attr(extra, 0);
}
// restore matches[i]
@@ -1786,9 +1769,7 @@ static int cs_read_prompt(size_t i)
}
#if defined(UNIX) && defined(SIGALRM)
-/*
- * Used to catch and ignore SIGALRM below.
- */
+// Used to catch and ignore SIGALRM below.
static void sig_handler(int s)
{
// do nothing
@@ -1838,7 +1819,7 @@ static void cs_release_csp(size_t i, bool freefnpp)
// Can't use sigaction(), loop for two seconds. First yield the CPU
// to give cscope a chance to exit quickly.
sleep(0);
- for (waited = 0; waited < 40; ++waited) {
+ for (waited = 0; waited < 40; waited++) {
pid = waitpid(csinfo[i].pid, &pstat, WNOHANG);
waitpid_errno = errno;
if (pid != 0) {
@@ -1847,25 +1828,21 @@ static void cs_release_csp(size_t i, bool freefnpp)
os_delay(50L, false); // sleep 50 ms
}
# endif
- /*
- * If the cscope process is still running: kill it.
- * Safety check: If the PID would be zero here, the entire X session
- * would be killed. -1 and 1 are dangerous as well.
- */
+ // If the cscope process is still running: kill it.
+ // Safety check: If the PID would be zero here, the entire X session
+ // would be killed. -1 and 1 are dangerous as well.
if (pid < 0 && csinfo[i].pid > 1) {
# ifdef ECHILD
bool alive = true;
if (waitpid_errno == ECHILD) {
- /*
- * When using 'vim -g', vim is forked and cscope process is
- * no longer a child process but a sibling. So waitpid()
- * fails with errno being ECHILD (No child processes).
- * Don't send SIGKILL to cscope immediately but wait
- * (polling) for it to exit normally as result of sending
- * the "q" command, hence giving it a chance to clean up
- * its temporary files.
- */
+ // When using 'vim -g', vim is forked and cscope process is
+ // no longer a child process but a sibling. So waitpid()
+ // fails with errno being ECHILD (No child processes).
+ // Don't send SIGKILL to cscope immediately but wait
+ // (polling) for it to exit normally as result of sending
+ // the "q" command, hence giving it a chance to clean up
+ // its temporary files.
int waited;
sleep(0);
@@ -1932,7 +1909,7 @@ static int cs_reset(exarg_T *eap)
pplist[i] = csinfo[i].ppath;
fllist[i] = csinfo[i].flags;
if (csinfo[i].fname != NULL) {
- cs_release_csp(i, FALSE);
+ cs_release_csp(i, false);
}
}
@@ -1974,11 +1951,9 @@ static char *cs_resolve_file(size_t i, char *name)
char *fullname;
char_u *csdir = NULL;
- /*
- * Ppath is freed when we destroy the cscope connection.
- * Fullname is freed after cs_make_vim_style_matches, after it's been
- * copied into the tag buffer used by Vim.
- */
+ // Ppath is freed when we destroy the cscope connection.
+ // Fullname is freed after cs_make_vim_style_matches, after it's been
+ // copied into the tag buffer used by Vim.
size_t len = strlen(name) + 2;
if (csinfo[i].ppath != NULL) {
len += strlen(csinfo[i].ppath);
@@ -2035,7 +2010,7 @@ static int cs_show(exarg_T *eap)
}
}
- wait_return(TRUE);
+ wait_return(false);
return CSCOPE_SUCCESS;
}