Skip to content

Commit

Permalink
Add helper macros EDITOR_ERRORS() and EDITOR_ERRORS_BUT_SKIPPED() to …
Browse files Browse the repository at this point in the history
…clean up the code a bit. Minor tidy up.
  • Loading branch information
Laurent Monin committed Mar 8, 2009
1 parent 91b011a commit 411a041
Show file tree
Hide file tree
Showing 5 changed files with 25 additions and 23 deletions.
27 changes: 15 additions & 12 deletions src/editors.c
Original file line number Diff line number Diff line change
Expand Up @@ -830,7 +830,7 @@ static gint editor_command_one(const EditorDescription *editor, GList *list, Edi
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)
{
Expand Down Expand Up @@ -924,7 +924,7 @@ static gint editor_command_one(const EditorDescription *editor, GList *list, Edi

g_free(command);

return ed->flags & EDITOR_ERROR_MASK;
return EDITOR_ERRORS(ed->flags);
}

static gint editor_command_next_start(EditorData *ed)
Expand Down Expand Up @@ -995,12 +995,15 @@ static gint editor_command_next_finish(EditorData *ed, gint status)
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)
Expand Down Expand Up @@ -1034,7 +1037,7 @@ static gint editor_command_done(EditorData *ed)

ed->count = 0;

flags = ed->flags & EDITOR_ERROR_MASK;
flags = EDITOR_ERRORS(ed->flags);

if (!ed->vd) editor_data_free(ed);

Expand All @@ -1056,7 +1059,7 @@ static gint editor_command_start(const EditorDescription *editor, const gchar *t
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);
Expand All @@ -1074,7 +1077,7 @@ static gint editor_command_start(const EditorDescription *editor, const gchar *t

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)
Expand All @@ -1096,7 +1099,7 @@ gint start_editor_from_filelist_full(const gchar *key, GList *list, EditorCallba

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);

Expand Down
2 changes: 2 additions & 0 deletions src/editors.h
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
8 changes: 2 additions & 6 deletions src/menu.c
Original file line number Diff line number Diff line change
Expand Up @@ -76,12 +76,8 @@ static void add_edit_items(GtkWidget *menu, GCallback func, GList *fd_list)
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)
{
Expand Down
2 changes: 1 addition & 1 deletion src/preferences.c
Original file line number Diff line number Diff line change
Expand Up @@ -201,7 +201,7 @@ static void config_parse_editor_entries(GtkWidget **editor_name_entry, GtkWidget
{
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),
Expand Down
9 changes: 5 additions & 4 deletions src/utilops.c
Original file line number Diff line number Diff line change
Expand Up @@ -503,10 +503,11 @@ static void file_util_abort_cb(GenericDialog *gd, gpointer data)
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;
Expand Down Expand Up @@ -548,7 +549,7 @@ static gint file_util_perform_ci_cb(gpointer resume_data, gint flags, GList *lis
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);
Expand Down Expand Up @@ -792,7 +793,7 @@ static void file_util_perform_ci_dir(UtilityData *ud, gboolean internal, gboolea
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 */
}

Expand Down

0 comments on commit 411a041

Please sign in to comment.