summaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
authorJose Antonio Ortega Ruiz <jao@gnu.org>2006-08-08 00:22:15 +0000
committerJose Antonio Ortega Ruiz <jao@gnu.org>2006-08-08 00:22:15 +0000
commit375187b866499e37817e2781e076b3460c2a3a1a (patch)
tree1efec15d9f2924acf739d114ff899758b7e9d6ec
parentcf35b1165b47dfb4c57cff1014476a3ddc886675 (diff)
downloadmdk-375187b866499e37817e2781e076b3460c2a3a1a.tar.gz
mdk-375187b866499e37817e2781e076b3460c2a3a1a.tar.bz2
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
-rw-r--r--mixgtk/Makefile.am1
-rw-r--r--mixgtk/mixgtk.glade101
-rw-r--r--mixgtk/mixgtk_cmd_dispatcher.c78
-rw-r--r--mixgtk/mixgtk_external.c204
-rw-r--r--mixgtk/mixgtk_external.h35
-rw-r--r--mixlib/xmix_vm_handlers.c32
-rw-r--r--samples/isains.mixal4
7 files changed, 347 insertions, 108 deletions
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</property>
</widget>
<widget class="GtkDialog" id="external_dialog">
+ <property name="border_width">1</property>
<property name="title" translatable="yes">External programs</property>
<property name="type">GTK_WINDOW_TOPLEVEL</property>
<property name="window_position">GTK_WIN_POS_NONE</property>
<property name="modal">True</property>
- <property name="resizable">True</property>
+ <property name="resizable">False</property>
<property name="destroy_with_parent">False</property>
<property name="decorated">True</property>
<property name="skip_taskbar_hint">False</property>
@@ -1906,6 +1907,7 @@ disk7</property>
<child>
<widget class="GtkFixed" id="fixed3">
+ <property name="border_width">9</property>
<property name="visible">True</property>
<child>
@@ -1913,18 +1915,19 @@ disk7</property>
<property name="width_request">0</property>
<property name="height_request">0</property>
<property name="visible">True</property>
+ <property name="tooltip" translatable="yes">Enter the arguments for the editor. %s will be substituted by the full path to the MIXAL file to edit. </property>
<property name="can_focus">True</property>
<property name="editable">True</property>
<property name="visibility">True</property>
<property name="max_length">0</property>
- <property name="text" translatable="yes">xterm -e vi %s</property>
+ <property name="text" translatable="yes">-e vi %s</property>
<property name="has_frame">True</property>
<property name="invisible_char">*</property>
<property name="activates_default">False</property>
</widget>
<packing>
- <property name="x">256</property>
- <property name="y">12</property>
+ <property name="x">168</property>
+ <property name="y">24</property>
</packing>
</child>
@@ -1933,7 +1936,7 @@ disk7</property>
<property name="width_request">0</property>
<property name="height_request">0</property>
<property name="visible">True</property>
- <property name="label" translatable="yes">Editor command (e.g xterm -e vi %s)</property>
+ <property name="label" translatable="yes">Editor command and arguments (e.g -e vi %s)</property>
<property name="use_underline">False</property>
<property name="use_markup">False</property>
<property name="justify">GTK_JUSTIFY_LEFT</property>
@@ -1950,7 +1953,25 @@ disk7</property>
</widget>
<packing>
<property name="x">8</property>
- <property name="y">15</property>
+ <property name="y">0</property>
+ </packing>
+ </child>
+
+ <child>
+ <widget class="GtkFileChooserButton" id="editor_chooser">
+ <property name="width_request">151</property>
+ <property name="height_request">31</property>
+ <property name="visible">True</property>
+ <property name="title" translatable="yes">Select A File</property>
+ <property name="action">GTK_FILE_CHOOSER_ACTION_OPEN</property>
+ <property name="local_only">True</property>
+ <property name="show_hidden">False</property>
+ <property name="do_overwrite_confirmation">False</property>
+ <property name="width_chars">-1</property>
+ </widget>
+ <packing>
+ <property name="x">8</property>
+ <property name="y">24</property>
</packing>
</child>
</widget>
@@ -1963,46 +1984,27 @@ disk7</property>
<child>
<widget class="GtkFixed" id="fixed4">
+ <property name="border_width">9</property>
<property name="visible">True</property>
<child>
- <widget class="GtkEntry" id="mixasm_entry">
- <property name="width_request">0</property>
- <property name="height_request">0</property>
- <property name="visible">True</property>
- <property name="can_focus">True</property>
- <property name="editable">True</property>
- <property name="visibility">True</property>
- <property name="max_length">0</property>
- <property name="text" translatable="yes">mixasm %s</property>
- <property name="has_frame">True</property>
- <property name="invisible_char">*</property>
- <property name="activates_default">False</property>
- </widget>
- <packing>
- <property name="x">255</property>
- <property name="y">4</property>
- </packing>
- </child>
-
- <child>
<widget class="GtkLabel" id="label235">
<property name="width_request">0</property>
<property name="height_request">0</property>
<property name="visible">True</property>
- <property name="label" translatable="yes">MIX sssembler command (e.g. mixasm %s)</property>
+ <property name="label" translatable="yes">MIX asssembler path</property>
<property name="use_underline">False</property>
<property name="use_markup">False</property>
<property name="justify">GTK_JUSTIFY_LEFT</property>
<property name="wrap">False</property>
<property name="selectable">False</property>
- <property name="xalign">0.5</property>
- <property name="yalign">0.5</property>
+ <property name="xalign">0.479999989271</property>
+ <property name="yalign">0.52999997139</property>
<property name="xpad">0</property>
<property name="ypad">0</property>
<property name="ellipsize">PANGO_ELLIPSIZE_NONE</property>
<property name="width_chars">-1</property>
- <property name="single_line_mode">False</property>
+ <property name="single_line_mode">True</property>
<property name="angle">0</property>
</widget>
<packing>
@@ -2010,6 +2012,45 @@ disk7</property>
<property name="y">8</property>
</packing>
</child>
+
+ <child>
+ <widget class="GtkFileChooserButton" id="mixasm_chooser">
+ <property name="width_request">151</property>
+ <property name="height_request">31</property>
+ <property name="visible">True</property>
+ <property name="title" translatable="yes">Select mixasm executable</property>
+ <property name="action">GTK_FILE_CHOOSER_ACTION_OPEN</property>
+ <property name="local_only">True</property>
+ <property name="show_hidden">False</property>
+ <property name="do_overwrite_confirmation">False</property>
+ <property name="width_chars">-1</property>
+ </widget>
+ <packing>
+ <property name="x">8</property>
+ <property name="y">32</property>
+ </packing>
+ </child>
+
+ <child>
+ <widget class="GtkCheckButton" id="mixasm_mls">
+ <property name="width_request">152</property>
+ <property name="height_request">24</property>
+ <property name="visible">True</property>
+ <property name="tooltip" translatable="yes">If checked, mixasm will be called with the --listing flag.</property>
+ <property name="can_focus">True</property>
+ <property name="label" translatable="yes">Generate listing file</property>
+ <property name="use_underline">True</property>
+ <property name="relief">GTK_RELIEF_NORMAL</property>
+ <property name="focus_on_click">False</property>
+ <property name="active">False</property>
+ <property name="inconsistent">False</property>
+ <property name="draw_indicator">True</property>
+ </widget>
+ <packing>
+ <property name="x">176</property>
+ <property name="y">32</property>
+ </packing>
+ </child>
</widget>
<packing>
<property name="padding">0</property>
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 <stdlib.h>
+
+#include <mixlib/mix.h>
+
+#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 <mixlib/mix_vm_command.h>
+
+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)