changeset 1400:67573155210c

Add helper macros EDITOR_ERRORS() and EDITOR_ERRORS_BUT_SKIPPED() to clean up the code a bit. Minor tidy up.
author zas_
date Sun, 08 Mar 2009 15:30:15 +0000
parents 7dfa34e4de15
children e18871df295f
files src/editors.c src/editors.h src/menu.c src/preferences.c src/utilops.c
diffstat 5 files changed, 25 insertions(+), 23 deletions(-) [+]
line wrap: on
line diff
--- a/src/editors.c	Sun Mar 08 15:02:18 2009 +0000
+++ b/src/editors.c	Sun Mar 08 15:30:15 2009 +0000
@@ -830,7 +830,7 @@
 	ed->pid = -1;
 	ed->flags = editor->flags | editor_command_parse(editor, list, &command);
 
-	ok = !(ed->flags & EDITOR_ERROR_MASK);
+	ok = !EDITOR_ERRORS(ed->flags);
 
 	if (ok)
 		{
@@ -924,7 +924,7 @@
 
 	g_free(command);
 
-	return ed->flags & EDITOR_ERROR_MASK;
+	return EDITOR_ERRORS(ed->flags);
 }
 
 static gint editor_command_next_start(EditorData *ed)
@@ -995,12 +995,15 @@
 		ed->list = NULL;
 		}
 
-	if (cont == EDITOR_CB_SUSPEND)
-		return ed->flags & EDITOR_ERROR_MASK;
-	else if (cont == EDITOR_CB_SKIP)
-		return editor_command_done(ed);
-	else
-		return editor_command_next_start(ed);
+	switch (cont)
+		{
+		case EDITOR_CB_SUSPEND:
+			return EDITOR_ERRORS(ed->flags);
+		case EDITOR_CB_SKIP:
+			return editor_command_done(ed);
+		}
+	
+	return editor_command_next_start(ed);
 }
 
 static gint editor_command_done(EditorData *ed)
@@ -1034,7 +1037,7 @@
 
 	ed->count = 0;
 
-	flags = ed->flags & EDITOR_ERROR_MASK;
+	flags = EDITOR_ERRORS(ed->flags);
 
 	if (!ed->vd) editor_data_free(ed);
 
@@ -1056,7 +1059,7 @@
 	EditorData *ed;
 	gint flags = editor->flags;
 
-	if (flags & EDITOR_ERROR_MASK) return flags & EDITOR_ERROR_MASK;
+	if (EDITOR_ERRORS(flags)) return EDITOR_ERRORS(flags);
 
 	ed = g_new0(EditorData, 1);
 	ed->list = filelist_copy(list);
@@ -1074,7 +1077,7 @@
 
 	editor_command_next_start(ed);
 	/* errors from editor_command_next_start will be handled via callback */
-	return flags & EDITOR_ERROR_MASK;
+	return EDITOR_ERRORS(flags);
 }
 
 gboolean is_valid_editor_command(const gchar *key)
@@ -1096,7 +1099,7 @@
 
 	error = editor_command_start(editor, editor->name, list, cb, data);
 
-	if (error & EDITOR_ERROR_MASK)
+	if (EDITOR_ERRORS(error))
 		{
 		gchar *text = g_strdup_printf(_("%s\n\"%s\""), editor_get_error_str(error), editor->file);
 		
--- a/src/editors.h	Sun Mar 08 15:02:18 2009 +0000
+++ b/src/editors.h	Sun Mar 08 15:30:15 2009 +0000
@@ -34,6 +34,8 @@
 
 #define	EDITOR_ERROR_MASK         0xffff0000
 
+#define EDITOR_ERRORS(flags) ((flags) & EDITOR_ERROR_MASK)
+#define EDITOR_ERRORS_BUT_SKIPPED(flags) (((flags) & EDITOR_ERROR_MASK) && !((flags) & EDITOR_ERROR_SKIPPED))
 
 /* return values from callback function */
 enum {
--- a/src/menu.c	Sun Mar 08 15:02:18 2009 +0000
+++ b/src/menu.c	Sun Mar 08 15:30:15 2009 +0000
@@ -76,12 +76,8 @@
 		work = work->next;
 		gboolean active = TRUE;
 
-		if (fd_list)
-			{
-			gint flags = editor_command_parse(editor, fd_list, NULL);
-			if ((flags & EDITOR_ERROR_MASK) != 0)
-				active = FALSE;
-			}
+		if (fd_list && EDITOR_ERRORS(editor_command_parse(editor, fd_list, NULL)))
+			active = FALSE;
 
 		if (active)
 			{
--- a/src/preferences.c	Sun Mar 08 15:02:18 2009 +0000
+++ b/src/preferences.c	Sun Mar 08 15:30:15 2009 +0000
@@ -201,7 +201,7 @@
 			{
 			gint flags = editor_command_parse(buf, NULL, NULL);
 		
-			if (flags & EDITOR_ERROR_MASK)
+			if (EDITOR_ERRORS(flags))
 				{
 				if (errmsg->str[0]) g_string_append(errmsg, "\n\n");
 				g_string_append_printf(errmsg, _("%s\n#%d \"%s\":\n%s"), editor_get_error_str(flags),
--- a/src/utilops.c	Sun Mar 08 15:02:18 2009 +0000
+++ b/src/utilops.c	Sun Mar 08 15:30:15 2009 +0000
@@ -503,10 +503,11 @@
 static gint file_util_perform_ci_cb(gpointer resume_data, gint flags, GList *list, gpointer data)
 {
 	UtilityData *ud = data;
+	gint ret = EDITOR_CB_CONTINUE;
+
 	ud->resume_data = resume_data;
 	
-	gint ret = EDITOR_CB_CONTINUE;
-	if ((flags & EDITOR_ERROR_MASK) && !(flags & EDITOR_ERROR_SKIPPED))
+	if (EDITOR_ERRORS_BUT_SKIPPED(flags))
 		{
 		GString *msg = g_string_new(editor_get_error_str(flags));
 		GenericDialog *d;
@@ -548,7 +549,7 @@
 		FileData *fd = list->data;
 		list = list->next;
 
-		if (!(flags & EDITOR_ERROR_MASK)) /* files were successfully deleted, call the maint functions */
+		if (!EDITOR_ERRORS(flags)) /* files were successfully deleted, call the maint functions */
 			{
 			if (ud->with_sidecars) 
 				file_data_sc_apply_ci(fd);
@@ -792,7 +793,7 @@
 static gint file_util_perform_ci_dir_cb(gpointer resume_data, gint flags, GList *list, gpointer data)
 {
 	UtilityData *ud = data;
-	file_util_perform_ci_dir(ud, FALSE, !((flags & EDITOR_ERROR_MASK) && !(flags & EDITOR_ERROR_SKIPPED)));
+	file_util_perform_ci_dir(ud, FALSE, !EDITOR_ERRORS_BUT_SKIPPED(flags));
 	return EDITOR_CB_CONTINUE; /* does not matter, there was just single directory */
 }