vim-patch:8.1.2387: using old C style comments

Problem:    Using old C style comments.
Solution:   Use // comments where appropriate.
2ab2e8608f
This commit is contained in:
Jan Edmund Lazo
2020-03-23 01:21:51 -04:00
parent 73dc9e943c
commit b3e249db7c
2 changed files with 490 additions and 454 deletions

File diff suppressed because it is too large Load Diff

View File

@@ -71,10 +71,10 @@ static void cs_usage_msg(csid_e x)
static enum { static enum {
EXP_CSCOPE_SUBCMD, /* expand ":cscope" sub-commands */ EXP_CSCOPE_SUBCMD, // expand ":cscope" sub-commands
EXP_SCSCOPE_SUBCMD, /* expand ":scscope" sub-commands */ EXP_SCSCOPE_SUBCMD, // expand ":scscope" sub-commands
EXP_CSCOPE_FIND, /* expand ":cscope find" arguments */ EXP_CSCOPE_FIND, // expand ":cscope find" arguments
EXP_CSCOPE_KILL /* expand ":cscope kill" arguments */ EXP_CSCOPE_KILL // expand ":cscope kill" arguments
} expand_what; } expand_what;
/* /*
@@ -87,13 +87,13 @@ char_u *get_cscope_name(expand_T *xp, int idx)
switch (expand_what) { switch (expand_what) {
case EXP_CSCOPE_SUBCMD: case EXP_CSCOPE_SUBCMD:
/* 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)
@@ -118,10 +118,10 @@ char_u *get_cscope_name(expand_T *xp, int idx)
{ {
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
* the pathname of the cscope database as argument. Only complete // the pathname of the cscope database as argument. Only complete
* with connection numbers. -1 can also be used to kill all // with connection numbers. -1 can also be used to kill all
* 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)
@@ -149,7 +149,7 @@ void set_context_in_cscope_cmd(expand_T *xp, const char *arg, cmdidx_T cmdidx)
expand_what = ((cmdidx == CMD_scscope) expand_what = ((cmdidx == CMD_scscope)
? EXP_SCSCOPE_SUBCMD : EXP_CSCOPE_SUBCMD); ? EXP_SCSCOPE_SUBCMD : EXP_CSCOPE_SUBCMD);
/* (part of) subcommand already typed */ // (part of) subcommand already typed
if (*arg != NUL) { if (*arg != NUL) {
const char *p = (const char *)skiptowhite((const char_u *)arg); const char *p = (const char *)skiptowhite((const char_u *)arg);
if (*p != NUL) { // Past first word. if (*p != NUL) { // Past first word.
@@ -175,7 +175,7 @@ void set_context_in_cscope_cmd(expand_T *xp, const char *arg, cmdidx_T cmdidx)
static void static void
do_cscope_general( do_cscope_general(
exarg_T *eap, exarg_T *eap,
int make_split /* whether to split window */ int make_split // whether to split window
) )
{ {
cscmd_T *cmdp; cscmd_T *cmdp;
@@ -276,17 +276,19 @@ void ex_cstag(exarg_T *eap)
/// This simulates a vim_fgets(), but for cscope, returns the next line /// This simulates a vim_fgets(), but for cscope, returns the next line
/// from the cscope output. should only be called from find_tags() /// from the cscope output. should only be called from find_tags()
/// ///
/// @return TRUE if eof, FALSE otherwise /// @return true if eof, FALSE otherwise
int cs_fgets(char_u *buf, int size) bool cs_fgets(char_u *buf, int size)
FUNC_ATTR_NONNULL_ALL
{ {
char *p; char *p;
if ((p = cs_manage_matches(NULL, NULL, 0, Get)) == NULL) if ((p = cs_manage_matches(NULL, NULL, 0, Get)) == NULL) {
return true; return true;
}
STRLCPY(buf, p, size); STRLCPY(buf, p, size);
return FALSE; return false;
} /* cs_fgets */ }
/// Called only from do_tag(), when popping the tag stack. /// Called only from do_tag(), when popping the tag stack.
@@ -328,48 +330,53 @@ void cs_print_tags(void)
* *
* Note: All string comparisons are case sensitive! * Note: All string comparisons are case sensitive!
*/ */
int cs_connection(int num, char_u *dbpath, char_u *ppath) bool cs_connection(int num, char_u *dbpath, char_u *ppath)
{ {
if (num < 0 || num > 4 || (num > 0 && !dbpath)) if (num < 0 || num > 4 || (num > 0 && !dbpath)) {
return false; return false;
}
for (size_t i = 0; i < csinfo_size; i++) { for (size_t i = 0; i < csinfo_size; i++) {
if (!csinfo[i].fname) if (!csinfo[i].fname) {
continue; continue;
}
if (num == 0) if (num == 0) {
return TRUE; return true;
}
switch (num) { switch (num) {
case 1: case 1:
if (strstr(csinfo[i].fname, (char *)dbpath)) if (strstr(csinfo[i].fname, (char *)dbpath)) {
return TRUE; return true;
}
break; break;
case 2: case 2:
if (strcmp(csinfo[i].fname, (char *)dbpath) == 0) if (strcmp(csinfo[i].fname, (char *)dbpath) == 0) {
return TRUE; return true;
}
break; break;
case 3: case 3:
if (strstr(csinfo[i].fname, (char *)dbpath) if (strstr(csinfo[i].fname, (char *)dbpath)
&& ((!ppath && !csinfo[i].ppath) && ((!ppath && !csinfo[i].ppath)
|| (ppath || (ppath
&& csinfo[i].ppath && csinfo[i].ppath
&& strstr(csinfo[i].ppath, (char *)ppath)))) && strstr(csinfo[i].ppath, (char *)ppath)))) {
return TRUE; return true;
}
break; break;
case 4: case 4:
if ((strcmp(csinfo[i].fname, (char *)dbpath) == 0) if ((strcmp(csinfo[i].fname, (char *)dbpath) == 0)
&& ((!ppath && !csinfo[i].ppath) && ((!ppath && !csinfo[i].ppath)
|| (ppath || (ppath
&& csinfo[i].ppath && csinfo[i].ppath
&& (strcmp(csinfo[i].ppath, (char *)ppath) == 0)))) && (strcmp(csinfo[i].ppath, (char *)ppath) == 0)))) {
return TRUE; return true;
}
break; break;
} }
} }
return FALSE; return false;
} /* cs_connection */ } // cs_connection
/* /*
@@ -419,7 +426,7 @@ cs_add_common(
size_t usedlen = 0; size_t usedlen = 0;
char_u *fbuf = NULL; char_u *fbuf = NULL;
/* get the filename (arg1), expand it, and try to stat it */ // get the filename (arg1), expand it, and try to stat it
fname = xmalloc(MAXPATHL + 1); fname = xmalloc(MAXPATHL + 1);
expand_env((char_u *)arg1, (char_u *)fname, MAXPATHL); expand_env((char_u *)arg1, (char_u *)fname, MAXPATHL);
@@ -451,7 +458,7 @@ staterr:
} }
int i; int i;
/* if filename is a directory, append the cscope database name to it */ // if filename is a directory, append the cscope database name to it
if ((file_info.stat.st_mode & S_IFMT) == S_IFDIR) { if ((file_info.stat.st_mode & S_IFMT) == S_IFDIR) {
fname2 = (char *)xmalloc(strlen(CSCOPE_DBFILE) + strlen(fname) + 2); fname2 = (char *)xmalloc(strlen(CSCOPE_DBFILE) + strlen(fname) + 2);
@@ -512,18 +519,18 @@ add_err:
xfree(fname); xfree(fname);
xfree(ppath); xfree(ppath);
return CSCOPE_FAILURE; return CSCOPE_FAILURE;
} /* cs_add_common */ }
static int cs_check_for_connections(void) static int cs_check_for_connections(void)
{ {
return cs_cnt_connections() > 0; return cs_cnt_connections() > 0;
} /* cs_check_for_connections */ }
static int cs_check_for_tags(void) static int cs_check_for_tags(void)
{ {
return p_tags[0] != NUL && curbuf->b_p_tags != NULL; return p_tags[0] != NUL && curbuf->b_p_tags != NULL;
} /* cs_check_for_tags */ }
/// Count the number of cscope connections. /// Count the number of cscope connections.
static size_t cs_cnt_connections(void) static size_t cs_cnt_connections(void)
@@ -535,10 +542,10 @@ static size_t cs_cnt_connections(void)
cnt++; cnt++;
} }
return cnt; return cnt;
} /* cs_cnt_connections */ }
static void cs_reading_emsg( static void cs_reading_emsg(
size_t idx /* connection index */ size_t idx // connection index
) )
{ {
EMSGU(_("E262: error reading cscope connection %" PRIu64), idx); EMSGU(_("E262: error reading cscope connection %" PRIu64), idx);
@@ -602,7 +609,7 @@ static int cs_cnt_matches(size_t idx)
xfree(buf); xfree(buf);
return nlines; return nlines;
} /* cs_cnt_matches */ }
/// Creates the actual cscope command query from what the user entered. /// Creates the actual cscope command query from what the user entered.
@@ -646,8 +653,8 @@ static char *cs_create_cmd(char *csoption, char *pattern)
return NULL; return NULL;
} }
/* 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))
@@ -658,7 +665,7 @@ static char *cs_create_cmd(char *csoption, char *pattern)
(void)sprintf(cmd, "%d%s", search, pat); (void)sprintf(cmd, "%d%s", search, pat);
return cmd; return cmd;
} /* cs_create_cmd */ }
/// This piece of code was taken/adapted from nvi. do we need to add /// This piece of code was taken/adapted from nvi. do we need to add
@@ -694,15 +701,18 @@ err_closing:
case -1: case -1:
(void)EMSG(_("E622: Could not fork for cscope")); (void)EMSG(_("E622: Could not fork for cscope"));
goto err_closing; goto err_closing;
case 0: /* child: run cscope. */ case 0: // child: run cscope.
if (dup2(to_cs[0], STDIN_FILENO) == -1) if (dup2(to_cs[0], STDIN_FILENO) == -1) {
PERROR("cs_create_connection 1"); PERROR("cs_create_connection 1");
if (dup2(from_cs[1], STDOUT_FILENO) == -1) }
if (dup2(from_cs[1], STDOUT_FILENO) == -1) {
PERROR("cs_create_connection 2"); PERROR("cs_create_connection 2");
if (dup2(from_cs[1], STDERR_FILENO) == -1) }
if (dup2(from_cs[1], STDERR_FILENO) == -1) {
PERROR("cs_create_connection 3"); PERROR("cs_create_connection 3");
}
/* close unused */ // close unused
(void)close(to_cs[1]); (void)close(to_cs[1]);
(void)close(from_cs[0]); (void)close(from_cs[0]);
#else #else
@@ -735,14 +745,14 @@ err_closing:
return CSCOPE_FAILURE; return CSCOPE_FAILURE;
} }
#endif #endif
/* expand the cscope exec for env var's */ // expand the cscope exec for env var's
prog = xmalloc(MAXPATHL + 1); prog = xmalloc(MAXPATHL + 1);
expand_env(p_csprg, (char_u *)prog, MAXPATHL); expand_env(p_csprg, (char_u *)prog, MAXPATHL);
/* alloc space to hold the cscope command */ // alloc space to hold the cscope command
size_t len = strlen(prog) + strlen(csinfo[i].fname) + 32; size_t len = strlen(prog) + strlen(csinfo[i].fname) + 32;
if (csinfo[i].ppath) { if (csinfo[i].ppath) {
/* expand the prepend path for env var's */ // expand the prepend path for env var's
ppath = xmalloc(MAXPATHL + 1); ppath = xmalloc(MAXPATHL + 1);
expand_env((char_u *)csinfo[i].ppath, (char_u *)ppath, MAXPATHL); expand_env((char_u *)csinfo[i].ppath, (char_u *)ppath, MAXPATHL);
@@ -754,12 +764,12 @@ err_closing:
cmd = xmalloc(len); cmd = xmalloc(len);
/* run the cscope command; is there execl for non-unix systems? */ // run the cscope command; is there execl for non-unix systems?
#if defined(UNIX) #if defined(UNIX)
(void)sprintf(cmd, "exec %s -dl -f %s", prog, csinfo[i].fname); (void)snprintf(cmd, len, "exec %s -dl -f %s", prog, csinfo[i].fname);
#else #else
/* WIN32 */ // WIN32
(void)sprintf(cmd, "%s -dl -f %s", prog, csinfo[i].fname); (void)snprintf(cmd, len, "%s -dl -f %s", prog, csinfo[i].fname);
#endif #endif
if (csinfo[i].ppath != NULL) { if (csinfo[i].ppath != NULL) {
(void)strcat(cmd, " -P"); (void)strcat(cmd, " -P");
@@ -770,14 +780,14 @@ err_closing:
(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)
# if defined(HAVE_SETSID) || defined(HAVE_SETPGID) # if defined(HAVE_SETSID) || defined(HAVE_SETPGID)
/* Change our process group to avoid cscope receiving SIGWINCH. */ // Change our process group to avoid cscope receiving SIGWINCH.
# if defined(HAVE_SETSID) # if defined(HAVE_SETSID)
(void)setsid(); (void)setsid();
# else # else
@@ -789,18 +799,18 @@ err_closing:
PERROR(_("cs_create_connection exec failed")); PERROR(_("cs_create_connection exec failed"));
exit(127); exit(127);
/* NOTREACHED */ // NOTREACHED
default: /* parent. */ default: // parent.
/* // Save the file descriptors for later duplication, and
* Save the file descriptors for later duplication, and // reopen as streams.
* reopen as streams. if ((csinfo[i].to_fp = fdopen(to_cs[1], "w")) == NULL) {
*/
if ((csinfo[i].to_fp = fdopen(to_cs[1], "w")) == NULL)
PERROR(_("cs_create_connection: fdopen for to_fp failed")); PERROR(_("cs_create_connection: fdopen for to_fp failed"));
if ((csinfo[i].fr_fp = fdopen(from_cs[0], "r")) == NULL) }
if ((csinfo[i].fr_fp = fdopen(from_cs[0], "r")) == NULL) {
PERROR(_("cs_create_connection: fdopen for fr_fp failed")); PERROR(_("cs_create_connection: fdopen for fr_fp failed"));
}
/* close unused */ // close unused
(void)close(to_cs[0]); (void)close(to_cs[0]);
(void)close(from_cs[1]); (void)close(from_cs[1]);
@@ -808,11 +818,11 @@ err_closing:
} }
#else #else
/* WIN32 */ // WIN32
/* Create a new process to run cscope and use pipes to talk with it */ // Create a new process to run cscope and use pipes to talk with it
GetStartupInfo(&si); GetStartupInfo(&si);
si.dwFlags = STARTF_USESTDHANDLES | STARTF_USESHOWWINDOW; si.dwFlags = STARTF_USESTDHANDLES | STARTF_USESHOWWINDOW;
si.wShowWindow = SW_HIDE; /* Hide child application window */ si.wShowWindow = SW_HIDE; // Hide child application window
si.hStdOutput = stdout_wr; si.hStdOutput = stdout_wr;
si.hStdError = stdout_wr; si.hStdError = stdout_wr;
si.hStdInput = stdin_rd; si.hStdInput = stdin_rd;
@@ -826,7 +836,7 @@ err_closing:
(void)EMSG(_("E623: Could not spawn cscope process")); (void)EMSG(_("E623: Could not spawn cscope process"));
goto err_closing; goto err_closing;
} }
/* else */ // else
csinfo[i].pid = pi.dwProcessId; csinfo[i].pid = pi.dwProcessId;
csinfo[i].hProc = pi.hProcess; csinfo[i].hProc = pi.hProcess;
CloseHandle(pi.hThread); CloseHandle(pi.hThread);
@@ -844,10 +854,10 @@ err_closing:
CloseHandle(stdin_rd); CloseHandle(stdin_rd);
CloseHandle(stdout_wr); CloseHandle(stdout_wr);
#endif /* !UNIX */ #endif // !UNIX
return CSCOPE_SUCCESS; return CSCOPE_SUCCESS;
} /* cs_create_connection */ }
/// Query cscope using command line interface. Parse the output and use tselect /// Query cscope using command line interface. Parse the output and use tselect
@@ -882,9 +892,9 @@ static int cs_find(exarg_T *eap)
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);
} /* cs_find */ }
/// Common code for cscope find, shared by cs_find() and ex_cstag(). /// Common code for cscope find, shared by cs_find() and ex_cstag().
@@ -897,7 +907,7 @@ static int cs_find_common(char *opt, char *pat, int forceit, int verbose,
char cmdletter; char cmdletter;
char *qfpos; char *qfpos;
/* get cmd letter */ // get cmd letter
switch (opt[0]) { switch (opt[0]) {
case '0': case '0':
cmdletter = 's'; cmdletter = 's';
@@ -933,10 +943,10 @@ static int cs_find_common(char *opt, char *pat, int forceit, int verbose,
qfpos = (char *)vim_strchr(p_csqf, cmdletter); qfpos = (char *)vim_strchr(p_csqf, cmdletter);
if (qfpos != NULL) { if (qfpos != NULL) {
qfpos++; qfpos++;
/* next symbol must be + or - */ // next symbol must be + or -
if (strchr(CSQF_FLAGS, *qfpos) == NULL) { if (strchr(CSQF_FLAGS, *qfpos) == NULL) {
char *nf = _("E469: invalid cscopequickfix flag %c for %c"); char *nf = _("E469: invalid cscopequickfix flag %c for %c");
/* strlen will be enough because we use chars */ // strlen will be enough because we use chars
char *buf = xmalloc(strlen(nf)); char *buf = xmalloc(strlen(nf));
sprintf(buf, nf, *qfpos, *(qfpos-1)); sprintf(buf, nf, *qfpos, *(qfpos-1));
@@ -954,23 +964,24 @@ 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);
/* Send query to all open connections, then count the total number // Send query to all open connections, then count the total number
* of matches so we can alloc all in one swell foop. */ // of matches so we can alloc all in one swell foop.
for (size_t i = 0; i < csinfo_size; i++) for (size_t i = 0; i < csinfo_size; i++) {
nummatches[i] = 0; nummatches[i] = 0;
}
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);
(void)fflush(csinfo[i].to_fp); (void)fflush(csinfo[i].to_fp);
@@ -1014,8 +1025,9 @@ static int cs_find_common(char *opt, char *pat, int forceit, int verbose,
} else { } else {
cs_file_results(f, nummatches); cs_file_results(f, nummatches);
fclose(f); fclose(f);
if (use_ll) /* Use location list */ if (use_ll) { // Use location list
wp = curwin; wp = curwin;
}
// '-' starts a new error list // '-' starts a new error list
if (qf_init(wp, tmp, (char_u *)"%f%*\\t%l%*\\t%m", if (qf_init(wp, tmp, (char_u *)"%f%*\\t%l%*\\t%m",
*qfpos == '-', cmdline, NULL) > 0) { *qfpos == '-', cmdline, NULL) > 0) {
@@ -1046,7 +1058,7 @@ static int cs_find_common(char *opt, char *pat, int forceit, int verbose,
char **matches = NULL, **contexts = NULL; char **matches = NULL, **contexts = NULL;
size_t matched = 0; size_t matched = 0;
/* read output */ // read output
cs_fill_results((char *)pat, totmatches, nummatches, &matches, cs_fill_results((char *)pat, totmatches, nummatches, &matches,
&contexts, &matched); &contexts, &matched);
xfree(nummatches); xfree(nummatches);
@@ -1057,8 +1069,7 @@ static int cs_find_common(char *opt, char *pat, int forceit, int verbose,
return do_tag((char_u *)pat, DT_CSCOPE, 0, forceit, verbose); return do_tag((char_u *)pat, DT_CSCOPE, 0, forceit, verbose);
} }
}
} /* cs_find_common */
/// Print help. /// Print help.
static int cs_help(exarg_T *eap) static int cs_help(exarg_T *eap)
@@ -1070,9 +1081,10 @@ static int cs_help(exarg_T *eap)
char *help = _(cmdp->help); char *help = _(cmdp->help);
int space_cnt = 30 - vim_strsize((char_u *)help); int space_cnt = 30 - vim_strsize((char_u *)help);
/* Use %*s rather than %30s to ensure proper alignment in utf-8 */ // Use %*s rather than %30s to ensure proper alignment in utf-8
if (space_cnt < 0) if (space_cnt < 0) {
space_cnt = 0; space_cnt = 0;
}
(void)smsg(_("%-5s: %s%*s (Usage: %s)"), (void)smsg(_("%-5s: %s%*s (Usage: %s)"),
cmdp->name, cmdp->name,
help, space_cnt, " ", help, space_cnt, " ",
@@ -1094,7 +1106,7 @@ static int cs_help(exarg_T *eap)
wait_return(TRUE); wait_return(TRUE);
return CSCOPE_SUCCESS; return CSCOPE_SUCCESS;
} /* cs_help */ }
static void clear_csinfo(size_t i) static void clear_csinfo(size_t i)
@@ -1124,7 +1136,7 @@ static int cs_insert_filelist(char *fname, char *ppath, char *flags,
} }
if (csinfo[j].fname == NULL && !empty_found) { if (csinfo[j].fname == NULL && !empty_found) {
i = j; /* remember first empty entry */ i = j; // remember first empty entry
empty_found = true; empty_found = true;
} }
} }
@@ -1132,13 +1144,13 @@ static int cs_insert_filelist(char *fname, char *ppath, char *flags,
if (!empty_found) { if (!empty_found) {
i = csinfo_size; i = csinfo_size;
if (csinfo_size == 0) { if (csinfo_size == 0) {
/* First time allocation: allocate only 1 connection. It should // First time allocation: allocate only 1 connection. It should
* be enough for most users. If more is needed, csinfo will be // be enough for most users. If more is needed, csinfo will be
* reallocated. */ // reallocated.
csinfo_size = 1; csinfo_size = 1;
csinfo = xcalloc(1, sizeof(csinfo_T)); csinfo = xcalloc(1, sizeof(csinfo_T));
} else { } else {
/* Reallocate space for more connections. */ // Reallocate space for more connections.
csinfo_size *= 2; csinfo_size *= 2;
csinfo = xrealloc(csinfo, sizeof(csinfo_T)*csinfo_size); csinfo = xrealloc(csinfo, sizeof(csinfo_T)*csinfo_size);
} }
@@ -1165,7 +1177,7 @@ static int cs_insert_filelist(char *fname, char *ppath, char *flags,
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);
return (int)i; return (int)i;
} /* cs_insert_filelist */ }
/// Find cscope command in command table. /// Find cscope command in command table.
@@ -1178,7 +1190,7 @@ static cscmd_T * cs_lookup_cmd(exarg_T *eap)
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)
@@ -1190,7 +1202,7 @@ static cscmd_T * cs_lookup_cmd(exarg_T *eap)
return cmdp; return cmdp;
} }
return NULL; return NULL;
} /* cs_lookup_cmd */ }
/// Nuke em. /// Nuke em.
@@ -1247,13 +1259,13 @@ static int cs_kill(exarg_T *eap)
} }
return CSCOPE_SUCCESS; return CSCOPE_SUCCESS;
} /* cs_kill */ }
/// Actually kills a specific cscope connection. /// Actually kills a specific cscope connection.
static void cs_kill_execute( static void cs_kill_execute(
size_t i, /* cscope table index */ size_t i, // cscope table index
char *cname /* cscope database name */ char *cname // cscope database name
) )
{ {
if (p_csverbose) { if (p_csverbose) {
@@ -1284,17 +1296,16 @@ static void cs_kill_execute(
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:
* //
* <tagstr>\t<filename>\t<linenum_or_search>"\t<extra> // <tagstr>\t<filename>\t<linenum_or_search>"\t<extra>
* //
* but as mentioned above, we'll always use the line number and // but as mentioned above, we'll always use the line number and
* put the search pattern (if one exists) as "extra" // put the search pattern (if one exists) as "extra"
* //
* buf is used as part of vim's method of handling tags, and // buf is used as part of vim's method of handling tags, and
* (i think) vim frees it when you pop your tags and get replaced // (i think) vim frees it when you pop your tags and get replaced
* by new ones on the tag stack. // by new ones on the tag stack.
*/
char *buf; char *buf;
size_t amt; size_t amt;
@@ -1311,7 +1322,7 @@ static char *cs_make_vim_style_matches(char *fname, char *slno, char *search,
} }
return buf; return buf;
} /* cs_make_vim_style_matches */ }
/// This is kind of hokey, but i don't see an easy way round this. /// This is kind of hokey, but i don't see an easy way round this.
@@ -1381,7 +1392,7 @@ static char *cs_manage_matches(char **matches, char **contexts,
} }
return p; return p;
} /* cs_manage_matches */ }
/// Parse cscope output. /// Parse cscope output.
@@ -1408,7 +1419,7 @@ retry:
return NULL; return NULL;
} }
/* 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')
; ;
@@ -1427,15 +1438,15 @@ retry:
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 ---
* If the file is older than the cscope database, that is, // If the file is older than the cscope database, that is,
* the database was built since the file was last modified, // the database was built since the file was last modified,
* or there wasn't a search string, use the line number. // or there wasn't a search string, use the line number.
*/ if (strcmp(*search, "<unknown>") == 0) {
if (strcmp(*search, "<unknown>") == 0)
*search = NULL; *search = NULL;
}
name = cs_resolve_file(cnumber, name); name = cs_resolve_file(cnumber, name);
return name; return name;
@@ -1474,11 +1485,10 @@ static void cs_file_results(FILE *f, int *nummatches_a)
xfree(context); xfree(context);
xfree(fullname); xfree(fullname);
} /* for all matches */ } // for all matches
(void)cs_read_prompt(i); (void)cs_read_prompt(i);
} // for all cscope connections
} /* for all cscope connections */
xfree(buf); xfree(buf);
} }
@@ -1539,10 +1549,10 @@ static void cs_fill_results(char *tagstr, size_t totmatches, int *nummatches_a,
*cntxts_p = cntxts; *cntxts_p = cntxts;
xfree(buf); xfree(buf);
} // cs_fill_results }
/* get the requested path components */ // get the requested path components
static char *cs_pathcomponents(char *path) static char *cs_pathcomponents(char *path)
{ {
if (p_cspc == 0) { if (p_cspc == 0) {
@@ -1688,7 +1698,7 @@ static int cs_read_prompt(size_t i)
static char *eprompt = "Press the RETURN key to continue:"; static char *eprompt = "Press the RETURN key to continue:";
size_t epromptlen = strlen(eprompt); size_t epromptlen = strlen(eprompt);
/* compute maximum allowed len for Cscope error message */ // compute maximum allowed len for Cscope error message
assert(IOSIZE >= cs_emsg_len); assert(IOSIZE >= cs_emsg_len);
size_t maxlen = IOSIZE - cs_emsg_len; size_t maxlen = IOSIZE - cs_emsg_len;
@@ -1738,11 +1748,12 @@ static int cs_read_prompt(size_t i)
} }
if (ch == EOF) { if (ch == EOF) {
PERROR("cs_read_prompt EOF"); PERROR("cs_read_prompt EOF");
if (buf != NULL && buf[0] != NUL) if (buf != NULL && buf[0] != NUL) {
(void)EMSG2(cs_emsg, buf); (void)EMSG2(cs_emsg, buf);
else if (p_csverbose) } else if (p_csverbose) {
cs_reading_emsg(i); /* don't have additional information */ cs_reading_emsg(i); // don't have additional information
cs_release_csp(i, TRUE); }
cs_release_csp(i, true);
xfree(buf); xfree(buf);
return CSCOPE_FAILURE; return CSCOPE_FAILURE;
} }
@@ -1753,9 +1764,10 @@ static int cs_read_prompt(size_t i)
} }
} }
if (ch == EOF) if (ch == EOF) {
continue; /* didn't find the prompt */ continue; // didn't find the prompt
break; /* did find the prompt */ }
break; // did find the prompt
} }
xfree(buf); xfree(buf);
@@ -1766,8 +1778,9 @@ static int cs_read_prompt(size_t i)
/* /*
* Used to catch and ignore SIGALRM below. * Used to catch and ignore SIGALRM below.
*/ */
static void sig_handler(int s) { static void sig_handler(int s)
/* do nothing */ {
// do nothing
return; return;
} }
@@ -1775,7 +1788,7 @@ static void sig_handler(int s) {
/// Does the actual free'ing for the cs ptr with an optional flag of whether /// Does the actual free'ing for the cs ptr with an optional flag of whether
/// or not to free the filename. Called by cs_kill and cs_reset. /// or not to free the filename. Called by cs_kill and cs_reset.
static void cs_release_csp(size_t i, int freefnpp) static void cs_release_csp(size_t i, bool freefnpp)
{ {
// Trying to exit normally (not sure whether it is fit to Unix cscope) // Trying to exit normally (not sure whether it is fit to Unix cscope)
if (csinfo[i].to_fp != NULL) { if (csinfo[i].to_fp != NULL) {
@@ -1791,7 +1804,7 @@ static void cs_release_csp(size_t i, int freefnpp)
# if defined(HAVE_SIGACTION) # if defined(HAVE_SIGACTION)
struct sigaction sa, old; struct sigaction sa, old;
/* Use sigaction() to limit the waiting time to two seconds. */ // Use sigaction() to limit the waiting time to two seconds.
sigemptyset(&sa.sa_mask); sigemptyset(&sa.sa_mask);
sa.sa_handler = sig_handler; sa.sa_handler = sig_handler;
# ifdef SA_NODEFER # ifdef SA_NODEFER
@@ -1800,27 +1813,28 @@ static void cs_release_csp(size_t i, int freefnpp)
sa.sa_flags = 0; sa.sa_flags = 0;
# endif # endif
sigaction(SIGALRM, &sa, &old); sigaction(SIGALRM, &sa, &old);
alarm(2); /* 2 sec timeout */ alarm(2); // 2 sec timeout
/* Block until cscope exits or until timer expires */ // Block until cscope exits or until timer expires
pid = waitpid(csinfo[i].pid, &pstat, 0); pid = waitpid(csinfo[i].pid, &pstat, 0);
waitpid_errno = errno; waitpid_errno = errno;
/* cancel pending alarm if still there and restore signal */ // cancel pending alarm if still there and restore signal
alarm(0); alarm(0);
sigaction(SIGALRM, &old, NULL); sigaction(SIGALRM, &old, NULL);
# else # else
int waited; int waited;
/* Can't use sigaction(), loop for two seconds. First yield the CPU // Can't use sigaction(), loop for two seconds. First yield the CPU
* to give cscope a chance to exit quickly. */ // to give cscope a chance to exit quickly.
sleep(0); sleep(0);
for (waited = 0; waited < 40; ++waited) { for (waited = 0; waited < 40; ++waited) {
pid = waitpid(csinfo[i].pid, &pstat, WNOHANG); pid = waitpid(csinfo[i].pid, &pstat, WNOHANG);
waitpid_errno = errno; waitpid_errno = errno;
if (pid != 0) if (pid != 0) {
break; /* break unless the process is still running */ break; // break unless the process is still running
os_delay(50L, false); /* sleep 50 ms */ }
os_delay(50L, false); // sleep 50 ms
} }
# endif # endif
/* /*
@@ -1830,7 +1844,7 @@ static void cs_release_csp(size_t i, int freefnpp)
*/ */
if (pid < 0 && csinfo[i].pid > 1) { if (pid < 0 && csinfo[i].pid > 1) {
# ifdef ECHILD # ifdef ECHILD
int alive = TRUE; bool alive = true;
if (waitpid_errno == ECHILD) { if (waitpid_errno == ECHILD) {
/* /*
@@ -1845,13 +1859,13 @@ static void cs_release_csp(size_t i, int freefnpp)
int waited; int waited;
sleep(0); sleep(0);
for (waited = 0; waited < 40; ++waited) { for (waited = 0; waited < 40; waited++) {
/* Check whether cscope process is still alive */ // Check whether cscope process is still alive
if (kill(csinfo[i].pid, 0) != 0) { if (kill(csinfo[i].pid, 0) != 0) {
alive = FALSE; /* cscope process no longer exists */ alive = false; // cscope process no longer exists
break; break;
} }
os_delay(50L, false); /* sleep 50ms */ os_delay(50L, false); // sleep 50ms
} }
} }
if (alive) if (alive)
@@ -1862,11 +1876,12 @@ static void cs_release_csp(size_t i, int freefnpp)
} }
} }
} }
#else /* !UNIX */ #else // !UNIX
if (csinfo[i].hProc != NULL) { if (csinfo[i].hProc != NULL) {
/* Give cscope a chance to exit normally */ // Give cscope a chance to exit normally
if (WaitForSingleObject(csinfo[i].hProc, 1000) == WAIT_TIMEOUT) if (WaitForSingleObject(csinfo[i].hProc, 1000) == WAIT_TIMEOUT) {
TerminateProcess(csinfo[i].hProc, 0); TerminateProcess(csinfo[i].hProc, 0);
}
CloseHandle(csinfo[i].hProc); CloseHandle(csinfo[i].hProc);
} }
#endif #endif
@@ -1883,7 +1898,7 @@ static void cs_release_csp(size_t i, int freefnpp)
} }
clear_csinfo(i); clear_csinfo(i);
} /* cs_release_csp */ }
/// Calls cs_kill on all cscope connections then reinits. /// Calls cs_kill on all cscope connections then reinits.
@@ -1895,7 +1910,7 @@ static int cs_reset(exarg_T *eap)
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 *));
pplist = xmalloc(csinfo_size * sizeof(char *)); pplist = xmalloc(csinfo_size * sizeof(char *));
fllist = xmalloc(csinfo_size * sizeof(char *)); fllist = xmalloc(csinfo_size * sizeof(char *));
@@ -1908,15 +1923,14 @@ static int cs_reset(exarg_T *eap)
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++) {
if (dblist[i] != NULL) { if (dblist[i] != NULL) {
cs_add_common(dblist[i], pplist[i], fllist[i]); cs_add_common(dblist[i], pplist[i], fllist[i]);
if (p_csverbose) { if (p_csverbose) {
/* don't use smsg_attr() because we want to display the // don't use smsg_attr() because we want to display the
* connection number in the same line as // connection number in the same line as
* "Added cscope database..." // "Added cscope database..."
*/
snprintf(buf, ARRAY_SIZE(buf), " (#%zu)", i); snprintf(buf, ARRAY_SIZE(buf), " (#%zu)", i);
MSG_PUTS_ATTR(buf, HL_ATTR(HLF_R)); MSG_PUTS_ATTR(buf, HL_ATTR(HLF_R));
} }
@@ -1933,7 +1947,7 @@ static int cs_reset(exarg_T *eap)
msg_attr(_("All cscope databases reset"), HL_ATTR(HLF_R) | MSG_HIST); msg_attr(_("All cscope databases reset"), HL_ATTR(HLF_R) | MSG_HIST);
} }
return CSCOPE_SUCCESS; return CSCOPE_SUCCESS;
} /* cs_reset */ }
/// Construct the full pathname to a file found in the cscope database. /// Construct the full pathname to a file found in the cscope database.
@@ -1954,11 +1968,11 @@ static char *cs_resolve_file(size_t i, char *name)
* copied into the tag buffer used by Vim. * copied into the tag buffer used by Vim.
*/ */
size_t len = strlen(name) + 2; size_t len = strlen(name) + 2;
if (csinfo[i].ppath != NULL) if (csinfo[i].ppath != NULL) {
len += strlen(csinfo[i].ppath); len += strlen(csinfo[i].ppath);
else if (p_csre && csinfo[i].fname != NULL) { } else if (p_csre && csinfo[i].fname != NULL) {
/* If 'cscoperelative' is set and ppath is not set, use cscope.out // If 'cscoperelative' is set and ppath is not set, use cscope.out
* path in path resolution. */ // path in path resolution.
csdir = xmalloc(MAXPATHL); csdir = xmalloc(MAXPATHL);
STRLCPY(csdir, csinfo[i].fname, STRLCPY(csdir, csinfo[i].fname,
path_tail((char_u *)csinfo[i].fname) path_tail((char_u *)csinfo[i].fname)
@@ -1966,9 +1980,9 @@ static char *cs_resolve_file(size_t i, char *name)
len += STRLEN(csdir); len += STRLEN(csdir);
} }
/* Note/example: this won't work if the cscope output already starts // Note/example: this won't work if the cscope output already starts
* "../.." and the prefix path is also "../..". if something like this // "../.." and the prefix path is also "../..". if something like this
* 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] != '/')
@@ -1976,9 +1990,9 @@ static char *cs_resolve_file(size_t i, char *name)
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) {
/* Check for csdir to be non empty to avoid empty path concatenated to // Check for csdir to be non empty to avoid empty path concatenated to
* cscope output. */ // cscope output.
fullname = concat_fnames((char *)csdir, name, TRUE); fullname = concat_fnames((char *)csdir, name, true);
} else { } else {
fullname = xstrdup(name); fullname = xstrdup(name);
} }
@@ -2013,7 +2027,7 @@ static int cs_show(exarg_T *eap)
wait_return(TRUE); wait_return(TRUE);
return CSCOPE_SUCCESS; return CSCOPE_SUCCESS;
} /* cs_show */ }
/// Only called when VIM exits to quit any cscope sessions. /// Only called when VIM exits to quit any cscope sessions.
@@ -2025,4 +2039,4 @@ void cs_end(void)
csinfo_size = 0; csinfo_size = 0;
} }
/* the end */ // the end