[PATCH] Help Viewer - incorrect behaviour of up arrrow key

2006-11-29 Thread Grigory Trenin

Hello all,

While browsing MC's help, I've noticed a strange behaviour of up arrow
key. After I visit some topic and return back (using right arrow key),
the behaviour of up arrow key weirdly changes: instead of selecting
the previous link, it jumps to the top of the window!

Here is a detailed description how to reproduce it:

1) Open the Help Contents (press F1, Tab, Enter)
2) Navigate some lines forward (press End or PageDown several times)
3) Enter the selected topic (press Enter)
4) Return back (press right arrow)
5) Move to the top of Contents (press Home)
6) Now try navigating the Contents using the up and down arrow keys.
 (for example, press down arrow for 5 times, then press up arrow).
You will notice that when you press up arrow key the selection
jumps to the top of window.


The problem is in the help_handle_key() function:
 case KEY_UP:
 case ALT ('\t'):
 /* select previous link */
 new_item = select_prev_link (startpoint, selected_item);

The 'startpoint' variable should be a pointer to the first byte
displayed in the Help window. But here it has a wrong value - that's
the problem. That's why select_prev_link() cannot find the link and
returns NULL, and the selection moves to the first link in the window.

I tried to find out what's wrong with the 'startpoint' variable.
I came to the conclusion that 'startpoint' is used here erroneously
instead of 'currentpoint' variable.
'currentpoint' always contains a pointer to the first byte displayed,
and it should be used here. And by the way, 'startpoint' variable
seems to be totally useless.

So in my patch I replaced 'startpoint' with 'currentpoint' and
removed the 'startpoint' variable completely.


Regards,
 Grigory Trenin
--- help.c.orig 2006-11-29 18:06:27.0 +0300
+++ help.c  2006-11-29 18:09:20.0 +0300
@@ -72,7 +72,7 @@
 static const char *main_node;  /* The main node */
 static const char *last_shown = NULL;  /* Last byte shown in a screen */
 static int end_of_node = 0;/* Flag: the last character of the node shown? 
*/
-static const char *currentpoint, *startpoint;
+static const char *currentpoint;
 static const char *selected_item;
 
 /* The widget variables */
@@ -489,7 +489,7 @@
 event-y -= 2;
 
 if (event-buttons  GPM_B_RIGHT){
-   currentpoint = startpoint = history [history_ptr].page;
+   currentpoint = history [history_ptr].page;
selected_item = history [history_ptr].link;
history_ptr--;
if (history_ptr  0)
@@ -527,7 +527,7 @@
history_ptr = (history_ptr+1) % HISTORY_SIZE;
history [history_ptr].page = currentpoint;
history [history_ptr].link = current_area-link_name;
-   currentpoint = startpoint = help_follow_link (currentpoint, 
current_area-link_name);
+   currentpoint = help_follow_link (currentpoint, current_area-link_name);
selected_item = NULL;
 } else{
if (event-y  0)
@@ -561,7 +561,7 @@
 if (p == NULL)
return;
 
-currentpoint = startpoint = p + 1;
+currentpoint = p + 1;
 selected_item = NULL;
 help_callback (h, DLG_DRAW, 0);
 }
@@ -582,7 +582,7 @@
 history[history_ptr].page = currentpoint;
 history[history_ptr].link = selected_item;
 
-currentpoint = startpoint = new_item + 1;
+currentpoint = new_item + 1;
 selected_item = NULL;
 help_callback (h, DLG_DRAW, 0);
 }
@@ -595,7 +595,7 @@
 static void prev_node_cmd (void *vp)
 {
 Dlg_head *h = vp;
-currentpoint = startpoint = history [history_ptr].page;
+currentpoint = history [history_ptr].page;
 selected_item = history [history_ptr].link;
 history_ptr--;
 if (history_ptr  0)
@@ -672,14 +672,14 @@
if (history_ptr  0)
history_ptr = HISTORY_SIZE-1;

-   currentpoint = startpoint = history [history_ptr].page;
+   currentpoint = history [history_ptr].page;
selected_item   = history [history_ptr].link;
 #endif
} else {
history_ptr = (history_ptr+1) % HISTORY_SIZE;
history [history_ptr].page = currentpoint;
history [history_ptr].link = selected_item;
-   currentpoint = startpoint = help_follow_link (currentpoint, 
selected_item) + 1;
+   currentpoint = help_follow_link (currentpoint, selected_item) + 1;
}
selected_item = NULL;
break;
@@ -704,7 +704,7 @@
 case KEY_UP:
 case ALT ('\t'):
/* select previous link */
-   new_item = select_prev_link (startpoint, selected_item);
+   new_item = select_prev_link (currentpoint, selected_item);
selected_item = new_item;
if (selected_item  currentpoint || selected_item = last_shown){
if (c == KEY_UP)
@@ -835,7 +835,7 @@
DLG_TRYUP | DLG_CENTER | DLG_WANT_TAB);
 
 selected_item = search_string_node (main_node, STRING_LINK_START) - 1;
-currentpoint = startpoint = main_node + 1;
+currentpoint = main_node + 1;
 
 for 

Re: [PATCH] mc crashes when temporary directory cannot be created

2006-11-29 Thread Leonard den Ottolander
Hello Jindrich,

On Tue, 2006-11-28 at 13:21 +0100, Jindrich Novy wrote:
 IMO only removal of the fallback will prevent
 the infinite loop in any case as it shouldn't call mc_mkstemps() at all.

That cure seems worse than the disease. Isn't the real problem the fact
that mc_mkstemps() blindly concats tmpdir to the prefix instead of
testing if mc_tmpdir() succeeded? Why not abort mc_mkstemps() if
mc_tmpdir() returns /dev/null/?

What about the attached (untested) patch?

By the way, could you please add the -p option to your diffs?

Bye,
Leonard.

-- 
mount -t life -o ro /dev/dna /genetic/research

--- util.c.000	2005-11-10 21:50:22.0 +0100
+++ util.c	2006-11-29 20:56:21.0 +0100
@@ -1301,14 +1301,18 @@ mc_mkstemps (char **pname, const char *p
 	= abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789;
 static unsigned long value;
 struct timeval tv;
+char *tmpdir;
 char *tmpbase;
 char *tmpname;
 char *XX;
 int count;
 
 if (strchr (prefix, PATH_SEP) == NULL) {
+	tmpdir = mc_tmpdir ();
+	if (strcmp (tmpdir, /dev/null/) == 0)
+	return -1;
 	/* Add prefix first to find the position of XX */
-	tmpbase = concat_dir_and_file (mc_tmpdir (), prefix);
+	tmpbase = concat_dir_and_file (tmpdir, prefix);
 } else {
 	tmpbase = g_strdup (prefix);
 }
___
Mc-devel mailing list
http://mail.gnome.org/mailman/listinfo/mc-devel


Re: [PATCH] Help Viewer - incorrect behaviour of up arrrow key

2006-11-29 Thread Grigory Trenin
s/right arrow/left arrow/g

Of course I meant left arrow key when I was talking about going back
to the previous topic.
Sorry for that.

--
Grigory.
___
Mc-devel mailing list
http://mail.gnome.org/mailman/listinfo/mc-devel