summaryrefslogtreecommitdiffstats
path: root/src/help.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/help.c')
-rw-r--r--src/help.c52
1 files changed, 29 insertions, 23 deletions
diff --git a/src/help.c b/src/help.c
index a14744a..f36704c 100644
--- a/src/help.c
+++ b/src/help.c
@@ -1,7 +1,7 @@
/*
Hypertext file browser.
- Copyright (C) 1994-2023
+ Copyright (C) 1994-2024
Free Software Foundation, Inc.
This file is part of the Midnight Commander.
@@ -126,21 +126,20 @@ static const char *
search_string (const char *start, const char *text)
{
const char *result = NULL;
- char *local_text = g_strdup (text);
- char *d = local_text;
+ char *local_text;
+ char *d;
const char *e = start;
+ local_text = g_strdup (text);
+
/* fmt sometimes replaces a space with a newline in the help file */
/* Replace the newlines in the link name with spaces to correct the situation */
- while (*d != '\0')
- {
+ for (d = local_text; *d != '\0'; str_next_char (&d))
if (*d == '\n')
*d = ' ';
- str_next_char (&d);
- }
/* Do search */
- for (d = local_text; *e; e++)
+ for (d = local_text; *e != '\0'; e++)
{
if (*d == *e)
d++;
@@ -166,11 +165,12 @@ search_string (const char *start, const char *text)
static const char *
search_string_node (const char *start, const char *text)
{
- const char *d = text;
- const char *e = start;
-
if (start != NULL)
- for (; *e && *e != CHAR_NODE_END; e++)
+ {
+ const char *d = text;
+ const char *e;
+
+ for (e = start; *e != '\0' && *e != CHAR_NODE_END; e++)
{
if (*d == *e)
d++;
@@ -179,6 +179,7 @@ search_string_node (const char *start, const char *text)
if (*d == '\0')
return e + 1;
}
+ }
return NULL;
}
@@ -271,7 +272,7 @@ move_backward (int i)
static void
move_to_top (void)
{
- while (((int) (currentpoint > fdata) > 0) && (*currentpoint != CHAR_NODE_END))
+ while (((int) (currentpoint - fdata) > 0) && (*currentpoint != CHAR_NODE_END))
currentpoint--;
while (*currentpoint != ']')
@@ -301,7 +302,7 @@ help_follow_link (const char *start, const char *lc_selected_item)
if (lc_selected_item == NULL)
return start;
- for (p = lc_selected_item; *p && *p != CHAR_NODE_END && *p != CHAR_LINK_POINTER; p++)
+ for (p = lc_selected_item; *p != '\0' && *p != CHAR_NODE_END && *p != CHAR_LINK_POINTER; p++)
;
if (*p == CHAR_LINK_POINTER)
{
@@ -309,7 +310,8 @@ help_follow_link (const char *start, const char *lc_selected_item)
char link_name[MAXLINKNAME];
link_name[0] = '[';
- for (i = 1; *p != CHAR_LINK_END && *p && *p != CHAR_NODE_END && i < MAXLINKNAME - 3;)
+ for (i = 1;
+ *p != CHAR_LINK_END && *p != '\0' && *p != CHAR_NODE_END && i < MAXLINKNAME - 3;)
link_name[i++] = *++p;
link_name[i - 1] = ']';
link_name[i] = '\0';
@@ -447,10 +449,7 @@ help_print_word (WDialog * h, GString * word, int *col, int *line, gboolean add_
static void
help_show (WDialog * h, const char *paint_start)
{
- const char *p, *n;
- int col, line, c;
gboolean painting = TRUE;
- gboolean acs; /* Flag: Alternate character set active? */
gboolean repeat_paint;
int active_col, active_line; /* Active link position */
char buff[MB_LEN_MAX + 1];
@@ -461,9 +460,15 @@ help_show (WDialog * h, const char *paint_start)
tty_setcolor (HELP_NORMAL_COLOR);
do
{
- line = col = active_col = active_line = 0;
+ int line = 0;
+ int col = 0;
+ gboolean acs = FALSE; /* Flag: Is alternate character set active? */
+ const char *p, *n;
+
+ active_col = 0;
+ active_line = 0;
+
repeat_paint = FALSE;
- acs = FALSE;
clear_link_areas ();
if ((int) (selected_item - paint_start) < 0)
@@ -473,6 +478,8 @@ help_show (WDialog * h, const char *paint_start)
n = paint_start;
while ((n[0] != '\0') && (n[0] != CHAR_NODE_END) && (line < help_lines))
{
+ int c;
+
p = n;
n = str_cget_next_char (p);
memcpy (buff, p, n - p);
@@ -597,7 +604,7 @@ help_show (WDialog * h, const char *paint_start)
g_string_free (word, TRUE);
/* Position the cursor over a nice link */
- if (active_col)
+ if (active_col != 0)
widget_gotoyx (h, active_line, active_col);
}
@@ -1143,9 +1150,8 @@ help_interactive_display (const gchar * event_group_name, const gchar * event_na
selected_item = search_string_node (main_node, STRING_LINK_START) - 1;
currentpoint = main_node + 1; /* Skip the newline following the start of the node */
- for (history_ptr = HISTORY_SIZE; history_ptr;)
+ for (history_ptr = HISTORY_SIZE - 1; history_ptr >= 0; history_ptr--)
{
- history_ptr--;
history[history_ptr].page = currentpoint;
history[history_ptr].link = selected_item;
}