summaryrefslogtreecommitdiffhomepage
path: root/mixlib
diff options
context:
space:
mode:
Diffstat (limited to 'mixlib')
-rw-r--r--mixlib/mix_config.c70
-rw-r--r--mixlib/mix_config.h19
-rw-r--r--mixlib/mix_vm_command.c23
3 files changed, 111 insertions, 1 deletions
diff --git a/mixlib/mix_config.c b/mixlib/mix_config.c
index 871af91..ba9ad19 100644
--- a/mixlib/mix_config.c
+++ b/mixlib/mix_config.c
@@ -34,7 +34,9 @@ static const gchar *DEF_DIR_ = ".mdk";
static const gchar *AUTOSAVE_KEY_ = "Autosave";
static const gchar *AUTOSAVE_YES_ = "True";
static const gchar *AUTOSAVE_NO_ = "False";
-static const gchar *DEVICES_KEY_ = "DevicesDir";
+static const gchar *DEVICES_KEY_ = "Devices.dir";
+static const gchar *HISTORY_KEY_ = "History.file";
+static const gchar *HISTORY_SIZE_KEY_ = "History.size";
/* the config type */
struct mix_config_t
@@ -126,6 +128,17 @@ mix_config_get (const mix_config_t *config, const gchar *key)
}
+gint
+mix_config_get_integer (const mix_config_t *config, const gchar *key)
+{
+ const gchar *val;
+ g_return_val_if_fail (config != NULL, 0);
+ g_return_val_if_fail (key != NULL, 0);
+ val = mix_config_get (config, key);
+ if (!val) return 0;
+ return atoi (val);
+}
+
/* update (or create if it does not exist) a new config item */
void
mix_config_update (mix_config_t *config, const gchar *key, const gchar *value)
@@ -150,6 +163,20 @@ mix_config_update (mix_config_t *config, const gchar *key, const gchar *value)
g_hash_table_insert (config->items, tmp, g_strdup (value));
}
+void
+mix_config_update_integer (mix_config_t *config, const gchar *key, gint value)
+{
+ gchar *val;
+
+ g_return_if_fail (config != NULL);
+ g_return_if_fail (key != NULL);
+ g_return_if_fail (value != NULL);
+
+ val = g_strdup_printf ("%d", value);
+ mix_config_update (config, key, val);
+ g_free (val);
+}
+
/* save the current configuration */
static void
save_ (gpointer key, gpointer value, gpointer file)
@@ -209,3 +236,44 @@ mix_config_get_devices_dir (const mix_config_t *config)
return mix_config_get (config, DEVICES_KEY_);
}
+/* history file. if relative path, config dir taken as root */
+void
+mix_config_set_history_file (mix_config_t *config, const gchar *path)
+{
+ g_return_if_fail (config != NULL);
+ g_return_if_fail (path != NULL);
+ if (g_path_is_absolute (path))
+ {
+ mix_config_update (config, HISTORY_KEY_, path);
+ }
+ else
+ {
+ gchar *base = g_dirname (config->filename);
+ gchar *hf = g_strconcat (base, G_DIR_SEPARATOR_S, path, NULL);
+ mix_config_update (config, HISTORY_KEY_, hf);
+ g_free (hf);
+ g_free (base);
+ }
+}
+
+const gchar *
+mix_config_get_history_file (const mix_config_t *config)
+{
+ g_return_val_if_fail (config != NULL, NULL);
+ return mix_config_get (config, HISTORY_KEY_);
+}
+
+void
+mix_config_set_history_size (mix_config_t *config, gint s)
+{
+ g_return_if_fail (config != NULL);
+ g_return_if_fail (s >= 0);
+ mix_config_update_integer (config, HISTORY_SIZE_KEY_, s);
+}
+
+gint
+mix_config_get_history_size (const mix_config_t *config)
+{
+ g_return_val_if_fail (config != NULL, 0);
+ return mix_config_get_integer (config, HISTORY_SIZE_KEY_);
+}
diff --git a/mixlib/mix_config.h b/mixlib/mix_config.h
index e6e00b8..47932e1 100644
--- a/mixlib/mix_config.h
+++ b/mixlib/mix_config.h
@@ -46,10 +46,16 @@ mix_config_get_filename (const mix_config_t *config);
extern const gchar *
mix_config_get (const mix_config_t *config, const gchar *key);
+extern gint
+mix_config_get_integer (const mix_config_t *config, const gchar *key);
+
/* update (or create if it does not exist) a new config item */
extern void
mix_config_update (mix_config_t *config, const gchar *key, const gchar *value);
+extern void
+mix_config_update_integer (mix_config_t *config, const gchar *key, gint value);
+
/* save the current configuration */
extern void
mix_config_save (const mix_config_t *config);
@@ -70,6 +76,19 @@ mix_config_set_devices_dir (mix_config_t *config, const gchar *dirname);
extern const gchar *
mix_config_get_devices_dir (const mix_config_t *config);
+/* history file. if relative path, config dir taken as root */
+extern void
+mix_config_set_history_file (mix_config_t *config, const gchar *path);
+
+extern const gchar *
+mix_config_get_history_file (const mix_config_t *config);
+
+extern void
+mix_config_set_history_size (mix_config_t *config, gint s);
+
+extern gint
+mix_config_get_history_size (const mix_config_t *config);
+
#endif /* MIX_CONFIG_H */
diff --git a/mixlib/mix_vm_command.c b/mixlib/mix_vm_command.c
index afabc55..bb4b67f 100644
--- a/mixlib/mix_vm_command.c
+++ b/mixlib/mix_vm_command.c
@@ -33,6 +33,11 @@
#include "mix_eval.h"
#include "mix_vm_command.h"
+#ifdef HAVE_LIBHISTORY
+# include <readline/history.h>
+#endif
+
+
/* hooks */
typedef struct
{
@@ -253,6 +258,7 @@ mix_vm_cmd_dispatcher_new_with_config (FILE *out, FILE *err,
mix_vm_cmd_dispatcher_t *result = mix_vm_cmd_dispatcher_new (out, err);
if (result != NULL && (result->config = config) != NULL)
{
+ gint hsize = 0;
const gchar *val = mix_config_get (result->config, TRACING_KEY_);
if (val) cmd_tracing_ (result, val);
val = mix_config_get (result->config, EDITOR_KEY_);
@@ -270,6 +276,17 @@ mix_vm_cmd_dispatcher_new_with_config (FILE *out, FILE *err,
}
else
cmd_devdir_ (result, val);
+#ifdef HAVE_LIBHISTORY
+ val = mix_config_get_history_file (result->config);
+ hsize = mix_config_get_history_size (result->config);
+ using_history ();
+ stifle_history (hsize);
+ if (val)
+ {
+ read_history ((char *)val);
+ history_set_pos (history_base + history_length - 1);
+ }
+#endif
}
return result;
}
@@ -279,12 +296,18 @@ mix_vm_cmd_dispatcher_new_with_config (FILE *out, FILE *err,
void
mix_vm_cmd_dispatcher_delete (mix_vm_cmd_dispatcher_t *dis)
{
+ const gchar *hfile = NULL;
g_return_if_fail (dis != NULL);
mix_eval_delete (dis->eval);
mix_dump_context_delete (dis->dump);
mix_vm_delete (dis->vm);
if (dis->editor) g_free (dis->editor);
if (dis->editor) g_free (dis->assembler);
+#ifdef HAVE_LIBHISTORY
+ if (dis->config && (hfile = mix_config_get_history_file
+ (dis->config)))
+ write_history ((char *)hfile);
+#endif
g_free (dis);
}