From 375187b866499e37817e2781e076b3460c2a3a1a Mon Sep 17 00:00:00 2001 From: Jose Antonio Ortega Ruiz Date: Tue, 8 Aug 2006 00:22:15 +0000 Subject: External programs management improvement - External programs (editor and mixasm) execution is more robustly controlled both in mixvm and gmixvm. - In gmixvm the external programs dialog has been revamped: - Only proper paths can be introduced for the executables (via a graphical file chooser). - Flags for mixasm are no longer free text, but a check button. - Internally, the code has been refactored. git-archimport-id: mdk@sv.gnu.org/mdk--devel--1--patch-28 --- mixgtk/Makefile.am | 1 + mixgtk/mixgtk.glade | 101 ++++++++++++++------ mixgtk/mixgtk_cmd_dispatcher.c | 78 +--------------- mixgtk/mixgtk_external.c | 204 +++++++++++++++++++++++++++++++++++++++++ mixgtk/mixgtk_external.h | 35 +++++++ mixlib/xmix_vm_handlers.c | 32 ++++++- samples/isains.mixal | 4 +- 7 files changed, 347 insertions(+), 108 deletions(-) create mode 100644 mixgtk/mixgtk_external.c create mode 100644 mixgtk/mixgtk_external.h diff --git a/mixgtk/Makefile.am b/mixgtk/Makefile.am index 4bd8af6..9fc5b49 100644 --- a/mixgtk/Makefile.am +++ b/mixgtk/Makefile.am @@ -34,6 +34,7 @@ bin_PROGRAMS = gmixvm gmixvm_SOURCES = gmixvm.c mixgtk.h mixgtk.c \ mixgtk_config.h mixgtk_config.c \ mixgtk_gen_handlers.h mixgtk_gen_handlers.c \ + mixgtk_external.h mixgtk_external.c \ mixgtk_cmd_dispatcher.h mixgtk_cmd_dispatcher.c \ mixgtk_widgets.h mixgtk_widgets.c \ mixgtk_device.h mixgtk_device.c \ diff --git a/mixgtk/mixgtk.glade b/mixgtk/mixgtk.glade index 005bb75..3b92bca 100644 --- a/mixgtk/mixgtk.glade +++ b/mixgtk/mixgtk.glade @@ -1835,11 +1835,12 @@ disk7 + 1 External programs GTK_WINDOW_TOPLEVEL GTK_WIN_POS_NONE True - True + False False True False @@ -1906,6 +1907,7 @@ disk7 + 9 True @@ -1913,18 +1915,19 @@ disk7 0 0 True + Enter the arguments for the editor. %s will be substituted by the full path to the MIXAL file to edit. True True True 0 - xterm -e vi %s + -e vi %s True * False - 256 - 12 + 168 + 24 @@ -1933,7 +1936,7 @@ disk7 0 0 True - Editor command (e.g xterm -e vi %s) + Editor command and arguments (e.g -e vi %s) False False GTK_JUSTIFY_LEFT @@ -1950,7 +1953,25 @@ disk7 8 - 15 + 0 + + + + + + 151 + 31 + True + Select A File + GTK_FILE_CHOOSER_ACTION_OPEN + True + False + False + -1 + + + 8 + 24 @@ -1963,46 +1984,27 @@ disk7 + 9 True - - - 0 - 0 - True - True - True - True - 0 - mixasm %s - True - * - False - - - 255 - 4 - - - 0 0 True - MIX sssembler command (e.g. mixasm %s) + MIX asssembler path False False GTK_JUSTIFY_LEFT False False - 0.5 - 0.5 + 0.479999989271 + 0.52999997139 0 0 PANGO_ELLIPSIZE_NONE -1 - False + True 0 @@ -2010,6 +2012,45 @@ disk7 8 + + + + 151 + 31 + True + Select mixasm executable + GTK_FILE_CHOOSER_ACTION_OPEN + True + False + False + -1 + + + 8 + 32 + + + + + + 152 + 24 + True + If checked, mixasm will be called with the --listing flag. + True + Generate listing file + True + GTK_RELIEF_NORMAL + False + False + False + True + + + 176 + 32 + + 0 diff --git a/mixgtk/mixgtk_cmd_dispatcher.c b/mixgtk/mixgtk_cmd_dispatcher.c index 1fc6b10..12d11d9 100644 --- a/mixgtk/mixgtk_cmd_dispatcher.c +++ b/mixgtk/mixgtk_cmd_dispatcher.c @@ -43,6 +43,7 @@ #include "mixgtk_mixal.h" #include "mixgtk_fontsel.h" #include "mixgtk_config.h" +#include "mixgtk_external.h" #include "mixgtk_cmd_dispatcher.h" @@ -61,13 +62,6 @@ typedef struct mixgtk_dispatch_ static struct mixgtk_dispatch_ dis_data_ = {NULL}; -static GtkWidget *ext_dlg_ = NULL; -static GtkWidget *ed_entry_ = NULL; -static GtkWidget *asm_entry_ = NULL; - -static const gchar *ED_NAME_ = "editor_entry"; -static const gchar *ASM_NAME_ = "mixasm_entry"; - static const gchar *TITLE_FORMAT_ = "gmixvm - %s"; static void @@ -221,68 +215,6 @@ install_hooks_ (void) NULL); } -/* configuration stuff */ -static const gchar *EDITOR_KEY_ = "Editor"; -static const gchar *MIXASM_KEY_ = "Mixasm"; - -static void -read_config_ (void) -{ - const gchar *editor = mixgtk_config_get (EDITOR_KEY_); - const gchar *assem = mixgtk_config_get (MIXASM_KEY_); - - if (!editor) - { - static const gchar *ENV[] = {"MDK_EDITOR", "X_EDITOR", NULL}; - gchar *edit = NULL; - int k = 0; - while (!edit && ENV[k]) edit = getenv (ENV[k++]); - if (edit) edit = g_strconcat (edit, " %s", NULL); - else edit = g_strdup ("xterm -e vi %s"); - mix_vm_cmd_dispatcher_set_editor (dis_data_.dispatcher, edit); - g_free (edit); - } - else - { - mix_vm_cmd_dispatcher_set_editor (dis_data_.dispatcher, editor); - } - if (!assem) assem = "mixasm %s"; - mix_vm_cmd_dispatcher_set_assembler (dis_data_.dispatcher, assem); - -} - -void -on_external_programs_activate () -{ - if (!ext_dlg_) - { - ext_dlg_ = mixgtk_widget_factory_get_dialog (MIXGTK_EXTERNPROG_DIALOG); - g_return_if_fail (ext_dlg_ != NULL); - ed_entry_ = mixgtk_widget_factory_get_child_by_name - (MIXGTK_EXTERNPROG_DIALOG, ED_NAME_); - g_assert (ed_entry_); - asm_entry_ = mixgtk_widget_factory_get_child_by_name - (MIXGTK_EXTERNPROG_DIALOG, ASM_NAME_); - g_assert (asm_entry_); - } - gtk_entry_set_text (GTK_ENTRY (ed_entry_), - mix_vm_cmd_dispatcher_get_editor (dis_data_.dispatcher)); - gtk_entry_set_text (GTK_ENTRY (asm_entry_), - mix_vm_cmd_dispatcher_get_assembler - (dis_data_.dispatcher)); - gtk_widget_show (ext_dlg_); - if (gtk_dialog_run (GTK_DIALOG (ext_dlg_)) == GTK_RESPONSE_OK) - { - const gchar *value = gtk_entry_get_text (GTK_ENTRY (ed_entry_)); - mix_vm_cmd_dispatcher_set_editor (dis_data_.dispatcher, value); - mixgtk_config_update (EDITOR_KEY_, value); - value = gtk_entry_get_text (GTK_ENTRY (asm_entry_)); - mix_vm_cmd_dispatcher_set_assembler (dis_data_.dispatcher, value); - mixgtk_config_update (MIXASM_KEY_, value); - } - - gtk_widget_hide (ext_dlg_); -} /* initialise the command dispatcher */ gboolean @@ -291,10 +223,6 @@ mixgtk_cmd_dispatcher_init (mixgtk_dialog_id_t top) static gboolean restart = FALSE; gchar *text = NULL; - ext_dlg_ = NULL; - ed_entry_ = NULL; - asm_entry_ = NULL; - dis_data_.prompt = mixgtk_widget_factory_get (top, MIXGTK_WIDGET_PROMPT); g_return_val_if_fail (dis_data_.prompt != NULL, FALSE); @@ -354,7 +282,9 @@ mixgtk_cmd_dispatcher_init (mixgtk_dialog_id_t top) dis_data_.context = gtk_statusbar_get_context_id (GTK_STATUSBAR (dis_data_.status), "cmd_dis_context"); - if (!restart) read_config_ (); + + if (!restart) mixgtk_external_init (dis_data_.dispatcher); + if (dis_data_.last_file) gtk_window_set_title (GTK_WINDOW (mixgtk_widget_factory_get_dialog (MIXGTK_MAIN)), diff --git a/mixgtk/mixgtk_external.c b/mixgtk/mixgtk_external.c new file mode 100644 index 0000000..182bad6 --- /dev/null +++ b/mixgtk/mixgtk_external.c @@ -0,0 +1,204 @@ +/* -*-c-*- -------------- mixgtk_cmd_dispatcher.c : + * Implementation of the functions declared in mixgtk_external.h + * ------------------------------------------------------------------ + * Copyright (C) 2006 Free Software Foundation, Inc. + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA + * 02110-1301, USA. + * + */ + +#include + +#include + +#include "mixgtk_config.h" +#include "mixgtk_cmd_dispatcher.h" +#include "mixgtk_external.h" + +enum { + ext_wdg_ed_chooser, + ext_wdg_ed_entry, + ext_wdg_asm_chooser, + ext_wdg_asm_ls, + ext_wdg_no +}; + +static GtkWidget *ext_dlg_ = NULL; +static GtkWidget *ext_wdg_[ext_wdg_no] = {NULL, NULL, NULL, NULL}; +static const gchar *ext_wdg_names_[] = { + "editor_chooser", "editor_entry", "mixasm_chooser", "mixasm_mls" +}; + +static const gchar *EDITOR_KEY_ = "Editor"; +static const gchar *MIXASM_KEY_ = "Mixasm"; +static const gchar *DEFAULT_EDITOR_CMD_ = "/usr/bin/xterm -e vi %s"; +static const gchar *DEFAULT_ASM_CMD_ = "/usr/bin/mixasm"; + +static mix_vm_cmd_dispatcher_t *dispatcher_; + +static void init_widgets_ (void); +static void update_dialog_ (void); +static void read_config_ (void); +static void update_config_ (void); +static void update_editor_ (const gchar *cmd); +static void update_asm_ (const gchar *cmd); + + +void +mixgtk_external_init (mix_vm_cmd_dispatcher_t *dispatcher) +{ + g_assert (dispatcher); + dispatcher_ = dispatcher; + init_widgets_ (); + read_config_ (); + update_dialog_ (); +} + +void +on_external_programs_activate () +{ + if (ext_dlg_) + { + update_dialog_ (); + + gtk_widget_show (ext_dlg_); + + if (gtk_dialog_run (GTK_DIALOG (ext_dlg_)) == GTK_RESPONSE_OK) + { + update_config_ (); + } + gtk_widget_hide (ext_dlg_); + } +} + + +void +init_widgets_ (void) +{ + gint k; + + ext_dlg_ = mixgtk_widget_factory_get_dialog (MIXGTK_EXTERNPROG_DIALOG); + g_assert (ext_dlg_ != NULL); + + for (k = 0; k < ext_wdg_no; ++k) + { + ext_wdg_[k] = mixgtk_widget_factory_get_child_by_name + (MIXGTK_EXTERNPROG_DIALOG, ext_wdg_names_[k]); + g_assert (ext_wdg_[k]); + } +} + +void +update_editor_ (const gchar *cmd) +{ + mix_vm_cmd_dispatcher_set_editor (dispatcher_, cmd); + mixgtk_config_update (EDITOR_KEY_, cmd); +} + +void +update_asm_ (const gchar *cmd) +{ + mix_vm_cmd_dispatcher_set_assembler (dispatcher_, cmd); + mixgtk_config_update (MIXASM_KEY_, cmd); +} + +void +read_config_ (void) +{ + const gchar *editor = mixgtk_config_get (EDITOR_KEY_); + const gchar *assem = mixgtk_config_get (MIXASM_KEY_); + + if (!editor) + { + static const gchar *ENV[] = {"MDK_EDITOR", "X_EDITOR", NULL}; + gchar *edit = NULL; + + int k = 0; + while (!edit && ENV[k]) edit = getenv (ENV[k++]); + + if (edit) edit = g_strconcat (edit, " %s", NULL); + else edit = g_strdup (DEFAULT_EDITOR_CMD_); + + update_editor_ (edit); + + g_free (edit); + } + else + { + update_editor_ (editor); + } + + update_asm_ (assem? assem : DEFAULT_ASM_CMD_); +} + +void +update_dialog_ (void) +{ + const gchar *editor = mixgtk_config_get (EDITOR_KEY_); + const gchar *assem = mixgtk_config_get (MIXASM_KEY_); + + if (editor && assem && ext_dlg_) + { + gchar **parts = g_strsplit_set (editor, " \t", 2); + gboolean is_active; + + gtk_file_chooser_select_filename + (GTK_FILE_CHOOSER (ext_wdg_[ext_wdg_ed_chooser]), parts[0]); + gtk_entry_set_text + (GTK_ENTRY (ext_wdg_[ext_wdg_ed_entry]), parts[1]); + + g_strfreev (parts); + + parts = g_strsplit_set (assem, " \t", 3); + gtk_file_chooser_select_filename + (GTK_FILE_CHOOSER (ext_wdg_[ext_wdg_asm_chooser]), parts[0]); + + is_active = + parts[1] && g_ascii_strcasecmp (g_strstrip (parts[1]), "-l") == 0; + + gtk_toggle_button_set_active + (GTK_TOGGLE_BUTTON (ext_wdg_[ext_wdg_asm_ls]), is_active); + + g_strfreev (parts); + } +} + +void +update_config_ (void) +{ + gchar *prog = gtk_file_chooser_get_filename + (GTK_FILE_CHOOSER (ext_wdg_[ext_wdg_ed_chooser])); + const gchar *args = gtk_entry_get_text (GTK_ENTRY (ext_wdg_[ext_wdg_ed_entry])); + gchar *cmd = g_strdup_printf ("%s %s", prog, args); + + update_editor_ (cmd); + + g_free (cmd); + g_free (prog); + + prog = gtk_file_chooser_get_filename + (GTK_FILE_CHOOSER (ext_wdg_[ext_wdg_asm_chooser])); + args = + gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (ext_wdg_[ext_wdg_asm_ls])) + ? " -l " + : " "; + cmd = g_strdup_printf ("%s%s%%s", prog, args); + + update_asm_ (cmd); + + g_free (cmd); + g_free (prog); +} diff --git a/mixgtk/mixgtk_external.h b/mixgtk/mixgtk_external.h new file mode 100644 index 0000000..88f1965 --- /dev/null +++ b/mixgtk/mixgtk_external.h @@ -0,0 +1,35 @@ +/* -*-c-*- -------------- mixgtk_external.h : + * Managing the external programs dialog. + * ------------------------------------------------------------------ + * Copyright (C) 2006 Free Software Foundation, Inc. + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. + * + */ + +#ifndef MIXGTK_EXTERNAL_H_0608072329 +#define MIXGTK_EXTERNAL_H_0608072329 + +#include + +extern void +mixgtk_external_init (mix_vm_cmd_dispatcher_t *dispatcher); + +extern void +on_external_programs_activate (); + + + +#endif // MIXGTK_EXTERNAL_H_0608072329 diff --git a/mixlib/xmix_vm_handlers.c b/mixlib/xmix_vm_handlers.c index 4ebfc77..689a3a6 100644 --- a/mixlib/xmix_vm_handlers.c +++ b/mixlib/xmix_vm_handlers.c @@ -286,10 +286,38 @@ cmd_compile_ (mix_vm_cmd_dispatcher_t *dis, const gchar *arg) else { gchar *cmd = g_strdup_printf (dis->assembler, arg); + gchar *errors = NULL; + gchar *output = NULL; + gint exit_status; + gboolean result; + GError *gerr = NULL; + if (wants_logs_ (dis)) log_message_ (dis, cmd); - if (system (cmd) == EXIT_SUCCESS && wants_logs_ (dis)) - log_message_ (dis, _("Successful compilation")); + + result = + g_spawn_command_line_sync (cmd, &output, &errors, &exit_status, &gerr); + + if (output) + { + log_message_ (dis, output); + } + + if (errors != NULL) + { + log_message_ (dis, errors); + } + else if ((exit_status != 0) || !result) + { + log_error_ (dis, _("Compilation failed")); + if (gerr && gerr->message) log_error_ (dis, gerr->message); + } + + if (gerr) g_free (gerr); + if (output) g_free (output); + if (errors) g_free (errors); + g_free (cmd); + return TRUE; } } diff --git a/samples/isains.mixal b/samples/isains.mixal index b1d7f2d..0815fab 100644 --- a/samples/isains.mixal +++ b/samples/isains.mixal @@ -1,5 +1,5 @@ -BB EQU 1(4:4) -BMAX EQU BB-1 +B EQU 1(4:4) +BMAX EQU B-1 UMAX EQU 20 TABLE NOP GOOD(BMAX) ADD FLOAT(5:5) -- cgit v1.2.3