comparison src/editors.c @ 1405:03384485676d

Introduce EditorFlags type, cleanup.
author zas_
date Sun, 08 Mar 2009 23:12:49 +0000
parents 611c25ef73f4
children c0afd5cbaa23
comparison
equal deleted inserted replaced
1404:de06d83e1adc 1405:03384485676d
40 GtkWidget *spinner; 40 GtkWidget *spinner;
41 }; 41 };
42 42
43 typedef struct _EditorData EditorData; 43 typedef struct _EditorData EditorData;
44 struct _EditorData { 44 struct _EditorData {
45 gint flags; 45 EditorFlags flags;
46 GPid pid; 46 GPid pid;
47 GList *list; 47 GList *list;
48 gint count; 48 gint count;
49 gint total; 49 gint total;
50 gboolean stopping; 50 gboolean stopping;
54 const EditorDescription *editor; 54 const EditorDescription *editor;
55 }; 55 };
56 56
57 57
58 static void editor_verbose_window_progress(EditorData *ed, const gchar *text); 58 static void editor_verbose_window_progress(EditorData *ed, const gchar *text);
59 static gint editor_command_next_start(EditorData *ed); 59 static EditorFlags editor_command_next_start(EditorData *ed);
60 static gint editor_command_next_finish(EditorData *ed, gint status); 60 static EditorFlags editor_command_next_finish(EditorData *ed, gint status);
61 static gint editor_command_done(EditorData *ed); 61 static EditorFlags editor_command_done(EditorData *ed);
62 62
63 /* 63 /*
64 *----------------------------------------------------------------------------- 64 *-----------------------------------------------------------------------------
65 * external editor routines 65 * external editor routines
66 *----------------------------------------------------------------------------- 66 *-----------------------------------------------------------------------------
646 646
647 return pathl; 647 return pathl;
648 } 648 }
649 649
650 650
651 gint editor_command_parse(const EditorDescription *editor, GList *list, gchar **output) 651 EditorFlags editor_command_parse(const EditorDescription *editor, GList *list, gchar **output)
652 { 652 {
653 gint flags = 0; 653 EditorFlags flags = 0;
654 const gchar *p; 654 const gchar *p;
655 GString *result = NULL; 655 GString *result = NULL;
656 656
657 if (output) 657 if (output)
658 result = g_string_new(""); 658 result = g_string_new("");
819 819
820 editor_command_next_finish(ed, status); 820 editor_command_next_finish(ed, status);
821 } 821 }
822 822
823 823
824 static gint editor_command_one(const EditorDescription *editor, GList *list, EditorData *ed) 824 static EditorFlags editor_command_one(const EditorDescription *editor, GList *list, EditorData *ed)
825 { 825 {
826 gchar *command; 826 gchar *command;
827 FileData *fd = list->data; 827 FileData *fd = list->data;
828 GPid pid; 828 GPid pid;
829 gint standard_output; 829 gint standard_output;
830 gint standard_error; 830 gint standard_error;
831 gboolean ok; 831 gboolean ok;
832 832
833 ed->pid = -1; 833 ed->pid = -1;
834 ed->flags = editor->flags | editor_command_parse(editor, list, &command); 834 ed->flags = editor->flags;
835 ed->flags |= editor_command_parse(editor, list, &command);
835 836
836 ok = !EDITOR_ERRORS(ed->flags); 837 ok = !EDITOR_ERRORS(ed->flags);
837 838
838 if (ok) 839 if (ok)
839 { 840 {
928 g_free(command); 929 g_free(command);
929 930
930 return EDITOR_ERRORS(ed->flags); 931 return EDITOR_ERRORS(ed->flags);
931 } 932 }
932 933
933 static gint editor_command_next_start(EditorData *ed) 934 static EditorFlags editor_command_next_start(EditorData *ed)
934 { 935 {
935 if (ed->vd) editor_verbose_window_fill(ed->vd, "\n", 1); 936 if (ed->vd) editor_verbose_window_fill(ed->vd, "\n", 1);
936 937
937 if (ed->list && ed->count < ed->total) 938 if (ed->list && ed->count < ed->total)
938 { 939 {
939 FileData *fd; 940 FileData *fd;
940 gint error; 941 EditorFlags error;
941 942
942 fd = ed->list->data; 943 fd = ed->list->data;
943 944
944 if (ed->vd) 945 if (ed->vd)
945 { 946 {
970 971
971 /* everything is done */ 972 /* everything is done */
972 return editor_command_done(ed); 973 return editor_command_done(ed);
973 } 974 }
974 975
975 static gint editor_command_next_finish(EditorData *ed, gint status) 976 static EditorFlags editor_command_next_finish(EditorData *ed, gint status)
976 { 977 {
977 gint cont = ed->stopping ? EDITOR_CB_SKIP : EDITOR_CB_CONTINUE; 978 gint cont = ed->stopping ? EDITOR_CB_SKIP : EDITOR_CB_CONTINUE;
978 979
979 if (status) 980 if (status)
980 ed->flags |= EDITOR_ERROR_STATUS; 981 ed->flags |= EDITOR_ERROR_STATUS;
1010 } 1011 }
1011 1012
1012 return editor_command_next_start(ed); 1013 return editor_command_next_start(ed);
1013 } 1014 }
1014 1015
1015 static gint editor_command_done(EditorData *ed) 1016 static EditorFlags editor_command_done(EditorData *ed)
1016 { 1017 {
1017 gint flags; 1018 EditorFlags flags;
1018 1019
1019 if (ed->vd) 1020 if (ed->vd)
1020 { 1021 {
1021 if (ed->count == ed->total) 1022 if (ed->count == ed->total)
1022 { 1023 {
1055 void editor_skip(gpointer ed) 1056 void editor_skip(gpointer ed)
1056 { 1057 {
1057 editor_command_done(ed); 1058 editor_command_done(ed);
1058 } 1059 }
1059 1060
1060 static gint editor_command_start(const EditorDescription *editor, const gchar *text, GList *list, EditorCallback cb, gpointer data) 1061 static EditorFlags editor_command_start(const EditorDescription *editor, const gchar *text, GList *list, EditorCallback cb, gpointer data)
1061 { 1062 {
1062 EditorData *ed; 1063 EditorData *ed;
1063 gint flags = editor->flags; 1064 EditorFlags flags = editor->flags;
1064 1065
1065 if (EDITOR_ERRORS(flags)) return EDITOR_ERRORS(flags); 1066 if (EDITOR_ERRORS(flags)) return EDITOR_ERRORS(flags);
1066 1067
1067 ed = g_new0(EditorData, 1); 1068 ed = g_new0(EditorData, 1);
1068 ed->list = filelist_copy(list); 1069 ed->list = filelist_copy(list);
1087 { 1088 {
1088 if (!key) return FALSE; 1089 if (!key) return FALSE;
1089 return g_hash_table_lookup(editors, key) != NULL; 1090 return g_hash_table_lookup(editors, key) != NULL;
1090 } 1091 }
1091 1092
1092 gint start_editor_from_filelist_full(const gchar *key, GList *list, EditorCallback cb, gpointer data) 1093 EditorFlags start_editor_from_filelist_full(const gchar *key, GList *list, EditorCallback cb, gpointer data)
1093 { 1094 {
1094 gint error; 1095 EditorFlags error;
1095 EditorDescription *editor; 1096 EditorDescription *editor;
1096 if (!key) return FALSE; 1097 if (!key) return FALSE;
1097 1098
1098 editor = g_hash_table_lookup(editors, key); 1099 editor = g_hash_table_lookup(editors, key);
1099 1100
1111 } 1112 }
1112 1113
1113 return error; 1114 return error;
1114 } 1115 }
1115 1116
1116 gint start_editor_from_filelist(const gchar *key, GList *list) 1117 EditorFlags start_editor_from_filelist(const gchar *key, GList *list)
1117 { 1118 {
1118 return start_editor_from_filelist_full(key, list, NULL, NULL); 1119 return start_editor_from_filelist_full(key, list, NULL, NULL);
1119 } 1120 }
1120 1121
1121 gint start_editor_from_file_full(const gchar *key, FileData *fd, EditorCallback cb, gpointer data) 1122 EditorFlags start_editor_from_file_full(const gchar *key, FileData *fd, EditorCallback cb, gpointer data)
1122 { 1123 {
1123 GList *list; 1124 GList *list;
1124 gint error; 1125 EditorFlags error;
1125 1126
1126 if (!fd) return FALSE; 1127 if (!fd) return FALSE;
1127 1128
1128 list = g_list_append(NULL, fd); 1129 list = g_list_append(NULL, fd);
1129 error = start_editor_from_filelist_full(key, list, cb, data); 1130 error = start_editor_from_filelist_full(key, list, cb, data);
1130 g_list_free(list); 1131 g_list_free(list);
1131 return error; 1132 return error;
1132 } 1133 }
1133 1134
1134 gint start_editor_from_file(const gchar *key, FileData *fd) 1135 EditorFlags start_editor_from_file(const gchar *key, FileData *fd)
1135 { 1136 {
1136 return start_editor_from_file_full(key, fd, NULL, NULL); 1137 return start_editor_from_file_full(key, fd, NULL, NULL);
1137 } 1138 }
1138 1139
1139 gint editor_window_flag_set(const gchar *key) 1140 gboolean editor_window_flag_set(const gchar *key)
1140 { 1141 {
1141 EditorDescription *editor; 1142 EditorDescription *editor;
1142 if (!key) return TRUE; 1143 if (!key) return TRUE;
1143 1144
1144 editor = g_hash_table_lookup(editors, key); 1145 editor = g_hash_table_lookup(editors, key);
1145 if (!editor) return TRUE; 1146 if (!editor) return TRUE;
1146 1147
1147 return (editor->flags & EDITOR_KEEP_FS); 1148 return !!(editor->flags & EDITOR_KEEP_FS);
1148 } 1149 }
1149 1150
1150 gint editor_is_filter(const gchar *key) 1151 gboolean editor_is_filter(const gchar *key)
1151 { 1152 {
1152 EditorDescription *editor; 1153 EditorDescription *editor;
1153 if (!key) return TRUE; 1154 if (!key) return TRUE;
1154 1155
1155 editor = g_hash_table_lookup(editors, key); 1156 editor = g_hash_table_lookup(editors, key);
1156 if (!editor) return TRUE; 1157 if (!editor) return TRUE;
1157 1158
1158 return (editor->flags & EDITOR_DEST); 1159 return !!(editor->flags & EDITOR_DEST);
1159 } 1160 }
1160 1161
1161 const gchar *editor_get_error_str(gint flags) 1162 const gchar *editor_get_error_str(EditorFlags flags)
1162 { 1163 {
1163 if (flags & EDITOR_ERROR_EMPTY) return _("Editor template is empty."); 1164 if (flags & EDITOR_ERROR_EMPTY) return _("Editor template is empty.");
1164 if (flags & EDITOR_ERROR_SYNTAX) return _("Editor template has incorrect syntax."); 1165 if (flags & EDITOR_ERROR_SYNTAX) return _("Editor template has incorrect syntax.");
1165 if (flags & EDITOR_ERROR_INCOMPATIBLE) return _("Editor template uses incompatible macros."); 1166 if (flags & EDITOR_ERROR_INCOMPATIBLE) return _("Editor template uses incompatible macros.");
1166 if (flags & EDITOR_ERROR_NO_FILE) return _("Can't find matching file type."); 1167 if (flags & EDITOR_ERROR_NO_FILE) return _("Can't find matching file type.");