changeset 444:452b7ffeb7ad

Minor cleanup and code redundancy reduction.
author zas_
date Sun, 20 Apr 2008 13:42:22 +0000
parents e7361d06d83a
children 89f8bffbce21
files src/editors.c
diffstat 1 files changed, 22 insertions(+), 16 deletions(-) [+]
line wrap: on
line diff
--- a/src/editors.c	Sun Apr 20 13:30:36 2008 +0000
+++ b/src/editors.c	Sun Apr 20 13:42:22 2008 +0000
@@ -236,6 +236,7 @@
 			if (!g_utf8_validate(buf, count, NULL))
 				{
 				gchar *utf8;
+
 				utf8 = g_locale_to_utf8(buf, count, NULL, NULL, NULL);
 				if (utf8)
 					{
@@ -288,6 +289,7 @@
 			{
 			while(work)
 				{
+				GList *work2;
 				gchar *ext = work->data;
 				work = work->next;
 
@@ -298,8 +300,7 @@
 					break;
 					}
 
-				GList *work2 = fd->sidecar_files;
-
+				work2 = fd->sidecar_files;
 				while(work2)
 					{
 					FileData *sfd = work2->data;
@@ -324,6 +325,7 @@
 		else
 			p = "";
 		}
+
 	while (*p != '\0')
 		{
 		/* must escape \, ", `, and $ to avoid problems,
@@ -428,8 +430,10 @@
 			/* for example "%f" or "%{.crw;.raw;.cr2}f" */
 			if (*p == '{')
 				{
+				gchar *end;
+				
 				p++;
-				gchar *end = strchr(p, '}');
+				end = strchr(p, '}');
 				if (!end)
 					{
 					flags |= EDITOR_ERROR_SYNTAX;
@@ -485,6 +489,7 @@
 						/* use whole list */
 						GList *work = list;
 						gboolean ok = FALSE;
+
 						while (work)
 							{
 							FileData *fd = work->data;
@@ -589,7 +594,6 @@
 
 	if (ed->vd)
 		{
-
 		if (!ok)
 			{
 			gchar *buf;
@@ -601,9 +605,9 @@
 			}
 		else
 			{
-
 			GIOChannel *channel_output;
 			GIOChannel *channel_error;
+
 			channel_output = g_io_channel_unix_new(standard_output);
 			g_io_channel_set_flags(channel_output, G_IO_FLAG_NONBLOCK, NULL);
 
@@ -627,7 +631,6 @@
 
 static gint editor_command_next_start(EditorData *ed)
 {
-
 	if (ed->vd) editor_verbose_window_fill(ed->vd, "\n", 1);
 
 	if (ed->list && ed->count < ed->total)
@@ -676,6 +679,7 @@
 		{
 		/* handle the first element from the list */
 		GList *fd_element = ed->list;
+
 		ed->list = g_list_remove_link(ed->list, fd_element);
 		if (ed->callback)
 			cont = ed->callback(ed->list ? ed : NULL, ed->flags, fd_element, ed->data);
@@ -696,16 +700,16 @@
 		return editor_command_done(ed);
 	else
 		return editor_command_next_start(ed);
-
 }
 
 static gint editor_command_done(EditorData *ed)
 {
 	gint flags;
-	const gchar *text;
 
 	if (ed->vd)
 		{
+		const gchar *text;
+
 		if (ed->count == ed->total)
 			{
 			text = _("done");
@@ -774,14 +778,20 @@
 	return flags & EDITOR_ERROR_MASK;
 }
 
+static gint is_valid_editor_command(gint n)
+{
+	return (n >= 0 && n < GQ_EDITOR_SLOTS
+		&& options->editor_command[n]
+		&& strlen(options->editor_command[n]) > 0); 
+}
+
 gint start_editor_from_filelist_full(gint n, GList *list, EditorCallback cb, gpointer data)
 {
 	gchar *command;
 	gint error;
 
-	if (n < 0 || n >= GQ_EDITOR_SLOTS || !list ||
-	    !options->editor_command[n] ||
-	    strlen(options->editor_command[n]) == 0) return FALSE;
+	if (!list) return FALSE;
+	if (!is_valid_editor_command(n)) return FALSE;
 
 	command = g_locale_from_utf8(options->editor_command[n], -1, NULL, NULL, NULL);
 	error = editor_command_start(command, options->editor_name[n], list, cb, data);
@@ -794,7 +804,6 @@
 	return start_editor_from_filelist_full(n, list,  NULL, NULL);
 }
 
-
 gint start_editor_from_file_full(gint n, FileData *fd, EditorCallback cb, gpointer data)
 {
 	GList *list;
@@ -815,14 +824,11 @@
 
 gint editor_window_flag_set(gint n)
 {
-	if (n < 0 || n >= GQ_EDITOR_SLOTS ||
-	    !options->editor_command[n] ||
-	    strlen(options->editor_command[n]) == 0) return TRUE;
+	if (!is_valid_editor_command(n)) return TRUE;
 
 	return (editor_command_parse(options->editor_command[n], NULL, NULL) & EDITOR_KEEP_FS);
 }
 
-
 const gchar *editor_get_error_str(gint flags)
 {
 	if (flags & EDITOR_ERROR_EMPTY) return _("Editor template is empty.");