genius r738 - in trunk: . src



Author: jirka
Date: Thu Feb 26 06:54:30 2009
New Revision: 738
URL: http://svn.gnome.org/viewvc/genius?rev=738&view=rev

Log:

Thu Feb 26 00:54:16 2009  Jiri (George) Lebl <jirka 5z com>

	* src/gnome-genius.c: handle crashes of the readline-helper without
	  hanging.  Slight reorganization of startup to show window few
	  nanoseconds faster.  Also don't use gtk_show_uri yet.  This
	  causes backwards binary incompatibility which sucks as my other
	  laptop uses hardy.

	* src/calc.c: slight improvement in help handling.  Don't sort
	  the functions in the categories until we really need to.

	* src/dict.c: when checking for similar id's do the sum and a square
	  sum to check for reorderings.  This fixes the strange suggestions
	  sometimes

	* src/genius-readline-helper.c: avoid crashes on getting SIGINT, ignore



Modified:
   trunk/ChangeLog
   trunk/src/calc.c
   trunk/src/dict.c
   trunk/src/genius-readline-helper.c
   trunk/src/gnome-genius.c

Modified: trunk/src/calc.c
==============================================================================
--- trunk/src/calc.c	(original)
+++ trunk/src/calc.c	Thu Feb 26 06:54:30 2009
@@ -78,9 +78,10 @@
 	char *name;
 	gboolean internal;
 	GSList *funcs;
+	gboolean funcs_sorted;
 } HelpCategory;
-static GSList *categories = NULL;
-static GHashTable *helphash = NULL;
+static GSList *gel_categories = NULL;
+static GHashTable *gel_helphash = NULL;
 
 /*these two are used for test parses so that we know when we have a complete
   expression toevaluate*/
@@ -132,7 +133,7 @@
 get_category (const char *category, gboolean insert)
 {
 	GSList *li;
-	for (li = categories; li != NULL; li = li->next) {
+	for (li = gel_categories; li != NULL; li = li->next) {
 		HelpCategory *cat = li->data;
 		if (strcmp (cat->category, category) == 0)
 			return cat;
@@ -141,7 +142,7 @@
 	if (insert) {
 		HelpCategory *cat = g_new0 (HelpCategory, 1);
 		cat->category = g_strdup (category);
-		categories = g_slist_append (categories, cat);
+		gel_categories = g_slist_append (gel_categories, cat);
 		return cat;
 	} else {
 		return NULL;
@@ -153,15 +154,15 @@
 {
 	GelHelp *help;
 
-	if (helphash == NULL)
-		helphash = g_hash_table_new (g_str_hash, g_str_equal);
+	if (gel_helphash == NULL)
+		gel_helphash = g_hash_table_new (g_str_hash, g_str_equal);
 
-	help = g_hash_table_lookup (helphash, func);
+	help = g_hash_table_lookup (gel_helphash, func);
 
 	if (help == NULL && insert) {
 		help = g_new0 (GelHelp, 1);
 		help->func = g_strdup (func);
-		g_hash_table_insert (helphash, help->func, help);
+		g_hash_table_insert (gel_helphash, help->func, help);
 	}
 
 	return help;
@@ -172,7 +173,7 @@
 get_categories (void)
 {
 	GSList *li, *list = NULL;
-	for (li = categories; li != NULL; li = li->next) {
+	for (li = gel_categories; li != NULL; li = li->next) {
 		HelpCategory *cat = li->data;
 		list = g_slist_prepend (list, g_strdup (cat->category));
 	}
@@ -240,6 +241,11 @@
 		return NULL;
 	} else {
 		GSList *li, *list = NULL;
+		if ( ! cat->funcs_sorted) {
+			cat->funcs = g_slist_sort (cat->funcs,
+						   function_sort);
+			cat->funcs_sorted = TRUE;
+		}
 		for (li = cat->funcs; li != NULL; li = li->next) {
 			const char *func = li->data;
 			GelHelp *help = get_help (func, FALSE /* insert */);
@@ -321,9 +327,9 @@
 	}
 	help->category = g_strdup (category);
 
-	cat->funcs = g_slist_insert_sorted (cat->funcs,
-					    g_strdup (func),
-					    function_sort);
+	cat->funcs = g_slist_prepend (cat->funcs,
+				      g_strdup (func));
+	cat->funcs_sorted = FALSE;
 }
 
 static void
@@ -411,10 +417,10 @@
 {
 	GelHelp *help;
 
-	if (helphash == NULL)
+	if (gel_helphash == NULL)
 		return;
 
-	help = g_hash_table_lookup (helphash, func);
+	help = g_hash_table_lookup (gel_helphash, func);
 	if (help != NULL) {
 		GSList *li, *list;
 
@@ -430,7 +436,7 @@
 		if (help->category != NULL)
 			remove_from_category (func, help->category);
 
-		g_hash_table_remove (helphash, func);
+		g_hash_table_remove (gel_helphash, func);
 
 		g_slist_free (help->aliases);
 		g_free (help->aliasfor);
@@ -2404,7 +2410,6 @@
 static void
 full_help (void)
 {
-	GSList *categories = get_categories ();
 	GSList *functions;
 	GSList *cli, *fli;
 	int i;
@@ -2429,14 +2434,14 @@
 	for (i = 0; genius_toplevels[i] != NULL; i++)
 		print_command_help (genius_toplevels[i]);
 
-	for (cli = categories; cli != NULL; cli = cli->next) {
-		char *cat = cli->data;
-		functions = get_helps (cat);
+	for (cli = gel_categories; cli != NULL; cli = cli->next) {
+		HelpCategory *cat = cli->data;
+		functions = get_helps (cat->category);
 
 		if (functions != NULL) {
 			do_black ();
 			gel_output_printf_full (main_out, FALSE, "\n%s:\n",
-						get_category_name (cat));
+						get_category_name (cat->category));
 
 			for (fli = functions; fli != NULL; fli = fli->next) {
 				GelHelp *help = fli->data;
@@ -2445,10 +2450,7 @@
 
 			g_slist_free (functions);
 		}
-
-		g_free (cat);
 	}
-	g_slist_free (categories);
 
 	functions = get_helps (NULL);
 	if (functions != NULL) {
@@ -2655,26 +2657,21 @@
 void
 gel_dump_strings_from_help (FILE *outfile)
 {
-	GSList *categories = get_categories ();
 	GSList *cli;
 
-	for (cli = categories; cli != NULL; cli = cli->next) {
-		char *cat = cli->data;
-		HelpCategory *cats;
+	for (cli = gel_categories; cli != NULL; cli = cli->next) {
+		HelpCategory *cats = cli->data;
 
-		cats = get_category (cat, FALSE /* insert */);
 		if (cats != NULL &&
 		    cats->name != NULL &&
 		    ! cats->internal) {
 			dump_a_string (outfile, cats->name);
 		}
 
-		dump_cat (outfile, cat);
+		dump_cat (outfile, cats->category);
 
 		cli->data = NULL;
-		g_free (cat);
 	}
-	g_slist_free (categories);
 
 	dump_cat (outfile, NULL);
 }

Modified: trunk/src/dict.c
==============================================================================
--- trunk/src/dict.c	(original)
+++ trunk/src/dict.c	Thu Feb 26 06:54:30 2009
@@ -819,6 +819,18 @@
 }
 
 static int
+lowercase_ascii_sum_square (const char *id)
+{
+	int sum = 0;
+	int i;
+	for (i = 0; id[i] != '\0'; i++) {
+		int n = g_ascii_tolower (id[i]) - 'a';
+		sum += n*n;
+	}
+	return sum;
+}
+
+static int
 lowercase_ascii_sum (const char *id)
 {
 	int sum = 0;
@@ -891,13 +903,16 @@
 
 	if (len1 > 6 && len1 == len2) {
 		int sum1, sum2;
+		int sum1s, sum2s;
 
 		sum1 = lowercase_ascii_sum (id1);
 		sum2 = lowercase_ascii_sum (id2);
 
-		/* just a reordering (possibly)
-		   (won't work right on small words) */
-		if (sum1 == sum2) {
+		sum1s = lowercase_ascii_sum_square (id1);
+		sum2s = lowercase_ascii_sum_square (id2);
+
+		/* just a reordering (possibly) */
+		if (sum1 == sum2 && sum1s == sum2s) {
 			return TRUE;
 		}
 	}

Modified: trunk/src/genius-readline-helper.c
==============================================================================
--- trunk/src/genius-readline-helper.c	(original)
+++ trunk/src/genius-readline-helper.c	Thu Feb 26 06:54:30 2009
@@ -156,6 +156,9 @@
 		exit(1);
 	}
 
+	/* for some reasons we get SIGINT sometimes because of vte? */
+	signal (SIGINT, SIG_IGN);
+
 	rl_catch_signals = 1;
 	rl_catch_sigwinch = 1;
 	rl_terminal_name = "xterm";

Modified: trunk/src/gnome-genius.c
==============================================================================
--- trunk/src/gnome-genius.c	(original)
+++ trunk/src/gnome-genius.c	Thu Feb 26 06:54:30 2009
@@ -243,6 +243,8 @@
 
 static void actually_open_help (const char *id);
 
+static void fork_helper_setup_comm (void);
+
 static GtkActionEntry entries[] = {
   { "FileMenu", NULL, N_("_File") },		/* name, stock id, label */
   { "EditMenu", NULL, N_("_Edit") },		/* name, stock id, label */
@@ -1615,7 +1617,9 @@
 static void
 actually_open_help (const char *id)
 {
-#if GTK_CHECK_VERSION(2,14,0)
+/* breaks binary back compatibility */
+#if 0
+/*#if GTK_CHECK_VERSION(2,14,0) */
 	GError *error = NULL;
 	char *str;
 
@@ -1636,7 +1640,8 @@
 		g_free (str);
 		g_error_free (error);
 	}
-#else
+/*#else*/
+#endif
 	char *xdgopen;
 	char *uri;
 	char *file = NULL;
@@ -1695,7 +1700,7 @@
 
 	g_free (xdgopen);
 	g_free (uri);
-#endif
+/*#endif*/
 }
 
 void
@@ -2121,9 +2126,18 @@
 			   default_console_font :
 			   genius_setup.font);
 		setup_term_color ();
+		/* breaks binary back compatibility */
+/*#if VTE_CHECK_VERSION(0,17,1)
+		vte_terminal_set_cursor_blink_mode
+			(VTE_TERMINAL (term),
+			 genius_setup.blinking_cursor ?
+			 VTE_CURSOR_BLINK_SYSTEM :
+			 VTE_CURSOR_BLINK_OFF);
+#else*/
 		vte_terminal_set_cursor_blinks
 			(VTE_TERMINAL (term),
 			genius_setup.blinking_cursor);
+/*#endif */
 
 
 		if (resp == GTK_RESPONSE_OK ||
@@ -4387,12 +4401,48 @@
 	g_free (foo);
 }
 
+static void
+genius_got_etree (GelETree *e)
+{
+	if (e != NULL) {
+		calc_running ++;
+		gel_evalexp_parsed (e, main_out, "= \e[1;36m", TRUE);
+		gel_test_max_nodes_again ();
+		calc_running --;
+		gel_output_full_string (main_out, "\e[0m");
+		gel_output_flush (main_out);
+	}
+
+	gel_printout_infos ();
+
+	if (gel_got_eof) {
+		gel_output_full_string (main_out, "\n");
+		gel_output_flush (main_out);
+		gel_got_eof = FALSE;
+		gtk_main_quit();
+	}
+}
+
+
 static gboolean
 get_new_line (GIOChannel *source, GIOCondition condition, gpointer data)
 {
 	int fd = g_io_channel_unix_get_fd (source);
 	int r;
 	char buf[5] = "EOF!";
+	
+	if (condition & G_IO_HUP) {
+		char *str;
+		str = g_strdup_printf ("\r\n\e[01;31m%s\e[0m\r\n", 
+				       _("Readline helper died, weird.  Trying to recover, things may be odd."));
+		vte_terminal_feed (VTE_TERMINAL (term), str, -1);
+		g_free (str);
+		close (fromrl);
+		fclose (torlfp);
+		fork_helper_setup_comm ();
+		start_cb_p_expression (genius_got_etree, torlfp);
+		return FALSE;
+	}
 
 	if ( ! (condition & G_IO_IN))
 		return TRUE;
@@ -4431,27 +4481,24 @@
 }
 
 static void
-genius_got_etree (GelETree *e)
+fork_helper_setup_comm (void)
 {
-	if (e != NULL) {
-		calc_running ++;
-		gel_evalexp_parsed (e, main_out, "= \e[1;36m", TRUE);
-		gel_test_max_nodes_again ();
-		calc_running --;
-		gel_output_full_string (main_out, "\e[0m");
-		gel_output_flush (main_out);
-	}
+	GIOChannel *channel;
 
-	gel_printout_infos ();
+	fork_a_helper ();
 
-	if (gel_got_eof) {
-		gel_output_full_string (main_out, "\n");
-		gel_output_flush (main_out);
-		gel_got_eof = FALSE;
-		gtk_main_quit();
-	}
+	torlfp = fopen (torlfifo, "w");
+
+	fromrl = open (fromrlfifo, O_RDONLY);
+	g_assert (fromrl >= 0);
+
+	channel = g_io_channel_unix_new (fromrl);
+	g_io_add_watch_full (channel, G_PRIORITY_DEFAULT, G_IO_IN | G_IO_HUP | G_IO_ERR, 
+			     get_new_line, NULL, NULL);
+	g_io_channel_unref (channel);
 }
 
+
 static char *
 make_a_fifo (const char *postfix)
 {
@@ -4709,7 +4756,6 @@
 	GtkWidget *w;
 	char *file;
 	int plugin_count = 0;
-	GIOChannel *channel;
 	gboolean give_no_lib_error_after_init = FALSE;
 
 	genius_is_gui = TRUE;
@@ -4771,7 +4817,8 @@
 				      _("Cannot find the library file, genius installation may be incorrect"));
 	}
 
-	setup_rl_fifos ();
+	/*read parameters */
+	get_properties ();
 
 	main_out = gel_output_new();
 	gel_output_setup_string (main_out, 80, get_term_width);
@@ -4781,11 +4828,6 @@
 	statechange_hook = set_state;
 	_gel_tree_limit_hook = tree_limit_hit;
 
-	gel_read_plugin_list ();
-
-	/*read parameters */
-	get_properties ();
-
 	file = g_build_filename (genius_datadir,
 				 "icons",
 				 "hicolor",
@@ -4832,7 +4874,6 @@
 	term = vte_terminal_new ();
 	vte_terminal_set_scrollback_lines (VTE_TERMINAL (term),
 					   genius_setup.scrollback);
-	vte_terminal_set_cursor_blinks (VTE_TERMINAL (term), TRUE);
 	vte_terminal_set_audible_bell (VTE_TERMINAL (term), TRUE);
 	vte_terminal_set_scroll_on_keystroke (VTE_TERMINAL (term), TRUE);
 	vte_terminal_set_scroll_on_output (VTE_TERMINAL (term), FALSE);
@@ -4856,42 +4897,6 @@
 		(vte_terminal_get_adjustment (VTE_TERMINAL (term)));
 	gtk_box_pack_start (GTK_BOX (hbox), w, FALSE, FALSE, 0);
 	
-	if (gel_plugin_list != NULL) {
-		GSList *li;
-		int i;
-		GtkWidget *menu = GTK_MENU_ITEM (gtk_ui_manager_get_widget (genius_ui, "/MenuBar/PluginsMenu"))->submenu;
-
-		for (i = 0, li = gel_plugin_list;
-		     li != NULL;
-		     li = li->next, i++) {
-			GtkWidget *item;
-			GelPlugin *plug = li->data;
-			if (plug->hide)
-				continue;
-
-			item = gtk_menu_item_new_with_label (plug->name);
-			g_signal_connect (item, "select",
-					  G_CALLBACK (simple_menu_item_select_cb), 
-					  plug->description);
-			g_signal_connect (item, "deselect",
-					  G_CALLBACK (simple_menu_item_deselect_cb), 
-					  plug->description);
-			gtk_widget_show (item);
-			g_signal_connect (G_OBJECT (item), "activate",
-					  G_CALLBACK (open_plugin_cb), plug);
-			gtk_menu_shell_append (GTK_MENU_SHELL (menu), item);
-			plugin_count ++;
-		}
-	}
-
-	/* if no plugins, hide the menu */
-	if (plugin_count == 0) {
-		gtk_widget_hide (gtk_ui_manager_get_widget (genius_ui, "/MenuBar/PluginsMenu"));
-	} else {
-		gtk_widget_show (gtk_ui_manager_get_widget (genius_ui, "/MenuBar/PluginsMenu"));
-		gtk_widget_hide (gtk_ui_manager_get_widget (genius_ui, "/MenuBar/PluginsMenu/NoPlugin"));
-	}
-
 	/*set up the main window*/
 	gtk_notebook_append_page (GTK_NOTEBOOK (notebook),
 				  hbox,
@@ -4921,16 +4926,69 @@
 					     default_console_font :
 					     genius_setup.font);
 	setup_term_color ();
+	/* breaks binary back compatibility */
+/* #if VTE_CHECK_VERSION(0,17,1)
+	vte_terminal_set_cursor_blink_mode
+		(VTE_TERMINAL (term),
+		 genius_setup.blinking_cursor ?
+		 VTE_CURSOR_BLINK_SYSTEM :
+		 VTE_CURSOR_BLINK_OFF);
+#else*/
 	vte_terminal_set_cursor_blinks
 		(VTE_TERMINAL (term),
 		 genius_setup.blinking_cursor);
+/*#endif*/
 	vte_terminal_set_encoding (VTE_TERMINAL (term), "UTF-8");
 
 	update_term_geometry ();
 	g_signal_connect (G_OBJECT (term), "char-size-changed",
 			  G_CALLBACK (update_term_geometry), NULL);
 
+	gtk_widget_hide (gtk_ui_manager_get_widget (genius_ui, "/MenuBar/PluginsMenu"));
+
+	/* Show the window now before going on with the
+	 * setup */
 	gtk_widget_show_now (genius_window);
+	check_events ();
+
+	gel_read_plugin_list ();
+
+	if (gel_plugin_list != NULL) {
+		GSList *li;
+		int i;
+		GtkWidget *menu = GTK_MENU_ITEM (gtk_ui_manager_get_widget (genius_ui, "/MenuBar/PluginsMenu"))->submenu;
+
+		for (i = 0, li = gel_plugin_list;
+		     li != NULL;
+		     li = li->next, i++) {
+			GtkWidget *item;
+			GelPlugin *plug = li->data;
+			if (plug->hide)
+				continue;
+
+			item = gtk_menu_item_new_with_label (plug->name);
+			g_signal_connect (item, "select",
+					  G_CALLBACK (simple_menu_item_select_cb), 
+					  plug->description);
+			g_signal_connect (item, "deselect",
+					  G_CALLBACK (simple_menu_item_deselect_cb), 
+					  plug->description);
+			gtk_widget_show (item);
+			g_signal_connect (G_OBJECT (item), "activate",
+					  G_CALLBACK (open_plugin_cb), plug);
+			gtk_menu_shell_append (GTK_MENU_SHELL (menu), item);
+			plugin_count ++;
+		}
+	}
+
+	/* if no plugins, hide the menu */
+	if (plugin_count == 0) {
+		gtk_widget_hide (gtk_ui_manager_get_widget (genius_ui, "/MenuBar/PluginsMenu"));
+	} else {
+		gtk_widget_show (gtk_ui_manager_get_widget (genius_ui, "/MenuBar/PluginsMenu"));
+		gtk_widget_hide (gtk_ui_manager_get_widget (genius_ui, "/MenuBar/PluginsMenu/NoPlugin"));
+	}
+
 
 	gel_output_printf (main_out,
 			   _("%sGenius %s%s\n"
@@ -4956,17 +5014,9 @@
 	set_new_errorout (geniuserror);
 	set_new_infoout (geniusinfo);
 
-	fork_a_helper ();
-
-	torlfp = fopen (torlfifo, "w");
-
-	fromrl = open (fromrlfifo, O_RDONLY);
-	g_assert (fromrl >= 0);
+	setup_rl_fifos ();
 
-	channel = g_io_channel_unix_new (fromrl);
-	g_io_add_watch_full (channel, G_PRIORITY_DEFAULT, G_IO_IN | G_IO_HUP | G_IO_ERR, 
-			     get_new_line, NULL, NULL);
-	g_io_channel_unref (channel);
+	fork_helper_setup_comm ();
 
 	/*init the context stack and clear out any stale dictionaries
 	  except the global one, if this is the first time called it



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]