aboutsummaryrefslogtreecommitdiff
path: root/src/nvim/help.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/nvim/help.c')
-rw-r--r--src/nvim/help.c50
1 files changed, 18 insertions, 32 deletions
diff --git a/src/nvim/help.c b/src/nvim/help.c
index bbc552fa4c..5fa48e0cee 100644
--- a/src/nvim/help.c
+++ b/src/nvim/help.c
@@ -47,19 +47,14 @@
void ex_help(exarg_T *eap)
{
char *arg;
- char *tag;
FILE *helpfd; // file descriptor of help file
- int n;
- int i;
win_T *wp;
int num_matches;
char **matches;
- char *p;
int empty_fnum = 0;
int alt_fnum = 0;
buf_T *buf;
int len;
- char *lang;
const bool old_KeyTyped = KeyTyped;
if (eap != NULL) {
@@ -88,13 +83,13 @@ void ex_help(exarg_T *eap)
}
// remove trailing blanks
- p = arg + strlen(arg) - 1;
+ char *p = arg + strlen(arg) - 1;
while (p > arg && ascii_iswhite(*p) && p[-1] != '\\') {
*p-- = NUL;
}
// Check for a specified language
- lang = check_help_lang(arg);
+ char *lang = check_help_lang(arg);
// When no argument given go to the index.
if (*arg == NUL) {
@@ -102,9 +97,9 @@ void ex_help(exarg_T *eap)
}
// Check if there is a match for the argument.
- n = find_help_tags(arg, &num_matches, &matches, eap != NULL && eap->forceit);
+ int n = find_help_tags(arg, &num_matches, &matches, eap != NULL && eap->forceit);
- i = 0;
+ int i = 0;
if (n != FAIL && lang != NULL) {
// Find first item with the requested language.
for (i = 0; i < num_matches; i++) {
@@ -128,7 +123,7 @@ void ex_help(exarg_T *eap)
}
// The first match (in the requested language) is the best match.
- tag = xstrdup(matches[i]);
+ char *tag = xstrdup(matches[i]);
FreeWild(num_matches, matches);
// Re-use an existing help window or open a new one.
@@ -259,11 +254,8 @@ char *check_help_lang(char *arg)
int help_heuristic(char *matched_string, int offset, int wrong_case)
FUNC_ATTR_PURE
{
- int num_letters;
- char *p;
-
- num_letters = 0;
- for (p = matched_string; *p; p++) {
+ int num_letters = 0;
+ for (char *p = matched_string; *p; p++) {
if (ASCII_ISALNUM(*p)) {
num_letters++;
}
@@ -298,11 +290,8 @@ int help_heuristic(char *matched_string, int offset, int wrong_case)
/// that has been put after the tagname by find_tags().
static int help_compare(const void *s1, const void *s2)
{
- char *p1;
- char *p2;
-
- p1 = *(char **)s1 + strlen(*(char **)s1) + 1;
- p2 = *(char **)s2 + strlen(*(char **)s2) + 1;
+ char *p1 = *(char **)s1 + strlen(*(char **)s1) + 1;
+ char *p2 = *(char **)s2 + strlen(*(char **)s2) + 1;
// Compare by help heuristic number first.
int cmp = strcmp(p1, p2);
@@ -320,8 +309,6 @@ static int help_compare(const void *s1, const void *s2)
/// When "keep_lang" is true try keeping the language of the current buffer.
int find_help_tags(const char *arg, int *num_matches, char ***matches, bool keep_lang)
{
- int i;
-
// Specific tags that either have a specific replacement or won't go
// through the generic rules.
static char *(except_tbl[][2]) = {
@@ -379,7 +366,7 @@ int find_help_tags(const char *arg, int *num_matches, char ***matches, bool keep
// When the string starting with "expr-" and containing '?' and matches
// the table, it is taken literally (but ~ is escaped). Otherwise '?'
// is recognized as a wildcard.
- for (i = (int)ARRAY_SIZE(expr_table); --i >= 0;) {
+ for (int i = (int)ARRAY_SIZE(expr_table); --i >= 0;) {
if (strcmp(arg + 5, expr_table[i]) == 0) {
for (int si = 0, di = 0;; si++) {
if (arg[si] == '~') {
@@ -396,7 +383,7 @@ int find_help_tags(const char *arg, int *num_matches, char ***matches, bool keep
} else {
// Recognize a few exceptions to the rule. Some strings that contain
// '*'are changed to "star", otherwise '*' is recognized as a wildcard.
- for (i = 0; except_tbl[i][0] != NULL; i++) {
+ for (int i = 0; except_tbl[i][0] != NULL; i++) {
if (strcmp(arg, except_tbl[i][0]) == 0) {
STRCPY(d, except_tbl[i][1]);
break;
@@ -660,7 +647,6 @@ void fix_help_buffer(void)
{
linenr_T lnum;
char *line;
- bool in_example = false;
// Set filetype to "help".
if (strcmp(curbuf->b_p_ft, "help") != 0) {
@@ -670,6 +656,7 @@ void fix_help_buffer(void)
}
if (!syntax_present(curwin)) {
+ bool in_example = false;
for (lnum = 1; lnum <= curbuf->b_ml.ml_line_count; lnum++) {
line = ml_get_buf(curbuf, lnum, false);
const size_t len = strlen(line);
@@ -722,9 +709,7 @@ void fix_help_buffer(void)
&& path_full_compare(rt, NameBuff, false, true) != kEqualFiles) {
int fcount;
char **fnames;
- char *s;
vimconv_T vc;
- char *cp;
// Find all "doc/ *.txt" files in this directory.
if (!add_pathsep(NameBuff)
@@ -740,6 +725,8 @@ void fix_help_buffer(void)
if (gen_expand_wildcards(1, buff_list, &fcount,
&fnames, EW_FILE|EW_SILENT) == OK
&& fcount > 0) {
+ char *s;
+ char *cp;
// If foo.abx is found use it instead of foo.txt in
// the same directory.
for (int i1 = 0; i1 < fcount; i1++) {
@@ -1080,7 +1067,6 @@ static void helptags_one(char *dir, const char *ext, const char *tagfname, bool
static void do_helptags(char *dirname, bool add_help_tags, bool ignore_writeerr)
FUNC_ATTR_NONNULL_ALL
{
- int len;
garray_T ga;
char lang[2];
char ext[5];
@@ -1090,7 +1076,7 @@ static void do_helptags(char *dirname, bool add_help_tags, bool ignore_writeerr)
// Get a list of all files in the help directory and in subdirectories.
xstrlcpy(NameBuff, dirname, sizeof(NameBuff));
- if (!add_pathsep((char *)NameBuff)
+ if (!add_pathsep(NameBuff)
|| xstrlcat(NameBuff, "**", sizeof(NameBuff)) >= MAXPATHL) {
emsg(_(e_fnametoolong));
return;
@@ -1111,7 +1097,7 @@ static void do_helptags(char *dirname, bool add_help_tags, bool ignore_writeerr)
int j;
ga_init(&ga, 1, 10);
for (int i = 0; i < filecount; i++) {
- len = (int)strlen(files[i]);
+ int len = (int)strlen(files[i]);
if (len <= 4) {
continue;
}
@@ -1177,7 +1163,6 @@ static void helptags_cb(char *fname, void *cookie)
void ex_helptags(exarg_T *eap)
{
expand_T xpc;
- char *dirname;
bool add_help_tags = false;
// Check for ":helptags ++t {dir}".
@@ -1191,7 +1176,8 @@ void ex_helptags(exarg_T *eap)
} else {
ExpandInit(&xpc);
xpc.xp_context = EXPAND_DIRECTORIES;
- dirname = ExpandOne(&xpc, eap->arg, NULL, WILD_LIST_NOTFOUND|WILD_SILENT, WILD_EXPAND_FREE);
+ char *dirname =
+ ExpandOne(&xpc, eap->arg, NULL, WILD_LIST_NOTFOUND|WILD_SILENT, WILD_EXPAND_FREE);
if (dirname == NULL || !os_isdir(dirname)) {
semsg(_("E150: Not a directory: %s"), eap->arg);
} else {