Introduce EditorFlags type, cleanup.
authorLaurent Monin <geeqie@norz.org>
Sun, 8 Mar 2009 23:12:49 +0000 (23:12 +0000)
committerLaurent Monin <geeqie@norz.org>
Sun, 8 Mar 2009 23:12:49 +0000 (23:12 +0000)
src/editors.c
src/editors.h
src/typedefs.h
src/utilops.c

index 22d50bc..89d7e45 100644 (file)
@@ -42,7 +42,7 @@ struct _EditorVerboseData {
 
 typedef struct _EditorData EditorData;
 struct _EditorData {
-       gint flags;
+       EditorFlags flags;
        GPid pid;
        GList *list;
        gint count;
@@ -56,9 +56,9 @@ struct _EditorData {
 
 
 static void editor_verbose_window_progress(EditorData *ed, const gchar *text);
-static gint editor_command_next_start(EditorData *ed);
-static gint editor_command_next_finish(EditorData *ed, gint status);
-static gint editor_command_done(EditorData *ed);
+static EditorFlags editor_command_next_start(EditorData *ed);
+static EditorFlags editor_command_next_finish(EditorData *ed, gint status);
+static EditorFlags editor_command_done(EditorData *ed);
 
 /*
  *-----------------------------------------------------------------------------
@@ -648,9 +648,9 @@ static gchar *editor_command_path_parse(const FileData *fd, PathType type, const
 }
 
 
-gint editor_command_parse(const EditorDescription *editor, GList *list, gchar **output)
+EditorFlags editor_command_parse(const EditorDescription *editor, GList *list, gchar **output)
 {
-       gint flags = 0;
+       EditorFlags flags = 0;
        const gchar *p;
        GString *result = NULL;
 
@@ -821,7 +821,7 @@ static void editor_child_exit_cb(GPid pid, gint status, gpointer data)
 }
 
 
-static gint editor_command_one(const EditorDescription *editor, GList *list, EditorData *ed)
+static EditorFlags editor_command_one(const EditorDescription *editor, GList *list, EditorData *ed)
 {
        gchar *command;
        FileData *fd = list->data;
@@ -831,7 +831,8 @@ static gint editor_command_one(const EditorDescription *editor, GList *list, Edi
        gboolean ok;
 
        ed->pid = -1;
-       ed->flags = editor->flags | editor_command_parse(editor, list, &command);
+       ed->flags = editor->flags;
+       ed->flags |= editor_command_parse(editor, list, &command);
 
        ok = !EDITOR_ERRORS(ed->flags);
 
@@ -930,14 +931,14 @@ static gint editor_command_one(const EditorDescription *editor, GList *list, Edi
        return EDITOR_ERRORS(ed->flags);
 }
 
-static gint editor_command_next_start(EditorData *ed)
+static EditorFlags editor_command_next_start(EditorData *ed)
 {
        if (ed->vd) editor_verbose_window_fill(ed->vd, "\n", 1);
 
        if (ed->list && ed->count < ed->total)
                {
                FileData *fd;
-               gint error;
+               EditorFlags error;
 
                fd = ed->list->data;
 
@@ -972,7 +973,7 @@ static gint editor_command_next_start(EditorData *ed)
        return editor_command_done(ed);
 }
 
-static gint editor_command_next_finish(EditorData *ed, gint status)
+static EditorFlags editor_command_next_finish(EditorData *ed, gint status)
 {
        gint cont = ed->stopping ? EDITOR_CB_SKIP : EDITOR_CB_CONTINUE;
 
@@ -1012,9 +1013,9 @@ static gint editor_command_next_finish(EditorData *ed, gint status)
        return editor_command_next_start(ed);
 }
 
-static gint editor_command_done(EditorData *ed)
+static EditorFlags editor_command_done(EditorData *ed)
 {
-       gint flags;
+       EditorFlags flags;
 
        if (ed->vd)
                {
@@ -1057,10 +1058,10 @@ void editor_skip(gpointer ed)
        editor_command_done(ed);
 }
 
-static gint editor_command_start(const EditorDescription *editor, const gchar *text, GList *list, EditorCallback cb, gpointer data)
+static EditorFlags editor_command_start(const EditorDescription *editor, const gchar *text, GList *list, EditorCallback cb, gpointer data)
 {
        EditorData *ed;
-       gint flags = editor->flags;
+       EditorFlags flags = editor->flags;
 
        if (EDITOR_ERRORS(flags)) return EDITOR_ERRORS(flags);
 
@@ -1089,9 +1090,9 @@ gboolean is_valid_editor_command(const gchar *key)
        return g_hash_table_lookup(editors, key) != NULL;
 }
 
-gint start_editor_from_filelist_full(const gchar *key, GList *list, EditorCallback cb, gpointer data)
+EditorFlags start_editor_from_filelist_full(const gchar *key, GList *list, EditorCallback cb, gpointer data)
 {
-       gint error;
+       EditorFlags error;
        EditorDescription *editor;
        if (!key) return FALSE;
        
@@ -1113,15 +1114,15 @@ gint start_editor_from_filelist_full(const gchar *key, GList *list, EditorCallba
        return error;
 }
 
-gint start_editor_from_filelist(const gchar *key, GList *list)
+EditorFlags start_editor_from_filelist(const gchar *key, GList *list)
 {
        return start_editor_from_filelist_full(key, list,  NULL, NULL);
 }
 
-gint start_editor_from_file_full(const gchar *key, FileData *fd, EditorCallback cb, gpointer data)
+EditorFlags start_editor_from_file_full(const gchar *key, FileData *fd, EditorCallback cb, gpointer data)
 {
        GList *list;
-       gint error;
+       EditorFlags error;
 
        if (!fd) return FALSE;
 
@@ -1131,12 +1132,12 @@ gint start_editor_from_file_full(const gchar *key, FileData *fd, EditorCallback
        return error;
 }
 
-gint start_editor_from_file(const gchar *key, FileData *fd)
+EditorFlags start_editor_from_file(const gchar *key, FileData *fd)
 {
        return start_editor_from_file_full(key, fd, NULL, NULL);
 }
 
-gint editor_window_flag_set(const gchar *key)
+gboolean editor_window_flag_set(const gchar *key)
 {
        EditorDescription *editor;
        if (!key) return TRUE;
@@ -1144,10 +1145,10 @@ gint editor_window_flag_set(const gchar *key)
        editor = g_hash_table_lookup(editors, key);
        if (!editor) return TRUE;
 
-       return (editor->flags & EDITOR_KEEP_FS);
+       return !!(editor->flags & EDITOR_KEEP_FS);
 }
 
-gint editor_is_filter(const gchar *key)
+gboolean editor_is_filter(const gchar *key)
 {
        EditorDescription *editor;
        if (!key) return TRUE;
@@ -1155,10 +1156,10 @@ gint editor_is_filter(const gchar *key)
        editor = g_hash_table_lookup(editors, key);
        if (!editor) return TRUE;
 
-       return (editor->flags & EDITOR_DEST);
+       return !!(editor->flags & EDITOR_DEST);
 }
 
-const gchar *editor_get_error_str(gint flags)
+const gchar *editor_get_error_str(EditorFlags flags)
 {
        if (flags & EDITOR_ERROR_EMPTY) return _("Editor template is empty.");
        if (flags & EDITOR_ERROR_SYNTAX) return _("Editor template has incorrect syntax.");
index 8f104bb..c253131 100644 (file)
 #define EDITORS_H
 
 
-#define        EDITOR_KEEP_FS            0x00000001
-#define        EDITOR_VERBOSE            0x00000002
-#define        EDITOR_VERBOSE_MULTI      0x00000004
-#define EDITOR_TERMINAL                  0x00000008
-
-#define        EDITOR_DEST               0x00000100
-#define        EDITOR_FOR_EACH           0x00000200
-#define        EDITOR_SINGLE_COMMAND     0x00000400
-
-#define        EDITOR_ERROR_EMPTY        0x00020000
-#define        EDITOR_ERROR_SYNTAX       0x00040000
-#define        EDITOR_ERROR_INCOMPATIBLE 0x00080000
-#define        EDITOR_ERROR_NO_FILE      0x00100000
-#define        EDITOR_ERROR_CANT_EXEC    0x00200000
-#define        EDITOR_ERROR_STATUS       0x00400000
-#define        EDITOR_ERROR_SKIPPED      0x00800000
-
-#define        EDITOR_ERROR_MASK         0xffff0000
+typedef enum {
+       EDITOR_KEEP_FS            = 0x00000001,
+       EDITOR_VERBOSE            = 0x00000002,
+       EDITOR_VERBOSE_MULTI      = 0x00000004,
+       EDITOR_TERMINAL           = 0x00000008,
+
+       EDITOR_DEST               = 0x00000100,
+       EDITOR_FOR_EACH           = 0x00000200,
+       EDITOR_SINGLE_COMMAND     = 0x00000400,
+       /* below are errors */
+       EDITOR_ERROR_EMPTY        = 0x00020000,
+       EDITOR_ERROR_SYNTAX       = 0x00040000,
+       EDITOR_ERROR_INCOMPATIBLE = 0x00080000,
+       EDITOR_ERROR_NO_FILE      = 0x00100000,
+       EDITOR_ERROR_CANT_EXEC    = 0x00200000,
+       EDITOR_ERROR_STATUS       = 0x00400000,
+       EDITOR_ERROR_SKIPPED      = 0x00800000,
+       /* mask to match errors only */
+       EDITOR_ERROR_MASK         = 0xffff0000,
+} EditorFlags;
+
+struct _EditorDescription {
+       gchar *key;             /* desktop file name, not including path, including extension */
+       gchar *name;            /* Name, localized name presented to user */
+       gchar *icon;            /* Icon */
+       gchar *exec;            /* Exec */
+       gchar *menu_path;       
+       gchar *hotkey;
+       GList *ext_list;
+       gchar *file;
+       EditorFlags flags;
+       gboolean hidden;
+};
 
 #define EDITOR_ERRORS(flags) ((flags) & EDITOR_ERROR_MASK)
-#define EDITOR_ERRORS_BUT_SKIPPED(flags) (((flags) & EDITOR_ERROR_MASK) && !((flags) & EDITOR_ERROR_SKIPPED))
+#define EDITOR_ERRORS_BUT_SKIPPED(flags) (!!(((flags) & EDITOR_ERROR_MASK) && !((flags) & EDITOR_ERROR_SKIPPED)))
+
 
 /* return values from callback function */
 enum {
@@ -60,7 +76,7 @@ flags - flags above
 list - list of procesed FileData structures, typically single file or whole list passed to start_editor_*
 data - generic pointer
 */
-typedef gint (*EditorCallback) (gpointer ed, gint flags, GList *list, gpointer data);
+typedef gint (*EditorCallback) (gpointer ed, EditorFlags flags, GList *list, gpointer data);
 
 
 void editor_resume(gpointer ed);
@@ -68,18 +84,18 @@ void editor_skip(gpointer ed);
 
 
 
-gint start_editor_from_file(const gchar *key, FileData *fd);
-gint start_editor_from_filelist(const gchar *key, GList *list);
-gint start_editor_from_file_full(const gchar *key, FileData *fd, EditorCallback cb, gpointer data);
-gint start_editor_from_filelist_full(const gchar *key, GList *list, EditorCallback cb, gpointer data);
-gint editor_window_flag_set(const gchar *key);
-gint editor_is_filter(const gchar *key);
-const gchar *editor_get_error_str(gint flags);
+EditorFlags start_editor_from_file(const gchar *key, FileData *fd);
+EditorFlags start_editor_from_filelist(const gchar *key, GList *list);
+EditorFlags start_editor_from_file_full(const gchar *key, FileData *fd, EditorCallback cb, gpointer data);
+EditorFlags start_editor_from_filelist_full(const gchar *key, GList *list, EditorCallback cb, gpointer data);
+gboolean editor_window_flag_set(const gchar *key);
+gboolean editor_is_filter(const gchar *key);
+const gchar *editor_get_error_str(EditorFlags flags);
 
 const gchar *editor_get_name(const gchar *key);
 
 gboolean is_valid_editor_command(const gchar *key);
-gint editor_command_parse(const EditorDescription *editor, GList *list, gchar **output);
+EditorFlags editor_command_parse(const EditorDescription *editor, GList *list, gchar **output);
 
 #endif
 /* vim: set shiftwidth=8 softtabstop=0 cindent cinoptions={1s: */
index 8dbe3b7..7c2cf2c 100644 (file)
@@ -226,19 +226,6 @@ struct _Histogram {
 };
 
 
-struct _EditorDescription {
-       gchar *key;             /* desktop file name, not including path, including extension */
-       gchar *name;            /* Name, localized name presented to user */
-       gchar *icon;            /* Icon */
-       gchar *exec;            /* Exec */
-       gchar *menu_path;       
-       gchar *hotkey;
-       GList *ext_list;
-       gchar *file;
-       guint flags;
-       gboolean hidden;
-};
-
 
 struct _ImageLoader;
 
index c93a547..e9366d8 100644 (file)
@@ -475,7 +475,7 @@ static GtkWidget *file_util_dialog_add_list(GtkWidget *box, GList *list, gint fu
 
 static gboolean file_util_perform_ci_internal(gpointer data);
 void file_util_dialog_run(UtilityData *ud);
-static gint file_util_perform_ci_cb(gpointer resume_data, gint flags, GList *list, gpointer data);
+static gint file_util_perform_ci_cb(gpointer resume_data, EditorFlags flags, GList *list, gpointer data);
 
 /* call file_util_perform_ci_internal or start_editor_from_filelist_full */
 
@@ -500,7 +500,7 @@ 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)
+static gint file_util_perform_ci_cb(gpointer resume_data, EditorFlags flags, GList *list, gpointer data)
 {
        UtilityData *ud = data;
        gint ret = EDITOR_CB_CONTINUE;
@@ -612,7 +612,7 @@ static gboolean file_util_perform_ci_internal(gpointer data)
                /* take a single entry each time, this allows better control over the operation */
                GList *single_entry = g_list_append(NULL, ud->flist->data);
                gboolean last = !ud->flist->next;
-               gint status = EDITOR_ERROR_STATUS;
+               EditorFlags status = EDITOR_ERROR_STATUS;
        
                if (ud->with_sidecars ? file_data_sc_perform_ci(single_entry->data) 
                                      : file_data_perform_ci(single_entry->data))
@@ -790,7 +790,7 @@ static void file_util_perform_ci_dir(UtilityData *ud, gboolean internal, gboolea
        file_util_dialog_run(ud);
 }
 
-static gint file_util_perform_ci_dir_cb(gpointer resume_data, gint flags, GList *list, gpointer data)
+static gint file_util_perform_ci_dir_cb(gpointer resume_data, EditorFlags flags, GList *list, gpointer data)
 {
        UtilityData *ud = data;
        file_util_perform_ci_dir(ud, FALSE, !EDITOR_ERRORS_BUT_SKIPPED(flags));
@@ -829,7 +829,7 @@ void file_util_perform_ci(UtilityData *ud)
 
        if (is_valid_editor_command(ud->external_command))
                {
-               gint flags;
+               EditorFlags flags;
                
                ud->external = TRUE;