From 4b1237e6d4fc6ca2e5ffe10946c92fe2e5484be0 Mon Sep 17 00:00:00 2001 From: crunchy Date: Mon, 4 Nov 2002 16:25:17 +0000 Subject: saving command history --- mpiosh/callback.c | 7 ++++++- mpiosh/config.c | 36 ++++++++++++++++++++++++++++++++---- mpiosh/global.c | 4 ++-- mpiosh/mpiosh.c | 7 ++----- 4 files changed, 42 insertions(+), 12 deletions(-) (limited to 'mpiosh') diff --git a/mpiosh/callback.c b/mpiosh/callback.c index dfd8474..b43d0c4 100644 --- a/mpiosh/callback.c +++ b/mpiosh/callback.c @@ -2,7 +2,7 @@ * * Author: Andreas Büsching * - * $Id: callback.c,v 1.30 2002/10/29 20:03:34 crunchy Exp $ + * $Id: callback.c,v 1.31 2002/11/04 16:25:17 crunchy Exp $ * * Copyright (C) 2001 Andreas Büsching * @@ -237,6 +237,11 @@ mpiosh_cmd_quit(char *args[]) UNUSED(args); + if (mpiosh.config) { + mpiosh_config_write(mpiosh.config); + mpiosh_config_free(mpiosh.config); + } + exit(0); } diff --git a/mpiosh/config.c b/mpiosh/config.c index 330bfea..dfe0e29 100644 --- a/mpiosh/config.c +++ b/mpiosh/config.c @@ -2,7 +2,7 @@ * * Author: Andreas Buesching * - * $Id: config.c,v 1.1 2002/10/29 20:03:35 crunchy Exp $ + * $Id: config.c,v 1.2 2002/11/04 16:25:17 crunchy Exp $ * * Copyright (C) 2001 Andreas Büsching * @@ -32,8 +32,7 @@ struct mpiosh_config_t * mpiosh_config_new(void) { struct mpiosh_config_t * cfg = malloc(sizeof(struct mpiosh_config_t)); - char *filename; - char *tmp; + char *filename, *tmp; struct stat st; cfg->prompt_int = cfg->prompt_ext = NULL; @@ -48,6 +47,8 @@ mpiosh_config_new(void) if (stat(tmp, &st) != -1) cfg->handle_global = cfg_handle_new_with_filename(tmp, 1); + else + cfg->handle_global = 0; free(tmp), free(filename); filename = malloc(strlen(CONFIG_USER) + strlen(CONFIG_FILE) + 1); @@ -65,6 +66,18 @@ mpiosh_config_new(void) free(tmp), free(filename); + /* initialise history */ + using_history(); + + filename = malloc(strlen(CONFIG_USER) + strlen(CONFIG_HISTORY) + 1); + filename[0] = '\0'; + strcat(filename, CONFIG_USER); + strcat(filename, CONFIG_HISTORY); + tmp = cfg_resolve_path(filename); + + read_history(tmp); + free(tmp), free(filename); + return cfg; } @@ -87,7 +100,9 @@ mpiosh_config_read_key(struct mpiosh_config_t *config, const char *group, void mpiosh_config_free(struct mpiosh_config_t *config) { - cfg_close(config->handle_global); + if (config->handle_global) + cfg_close(config->handle_global); + cfg_close(config->handle_user); free(config->prompt_int); free(config->prompt_ext); @@ -141,6 +156,8 @@ mpiosh_config_write(struct mpiosh_config_t *config) free(path); if (config->handle_user) { + char *tmp, *filename; + cfg_key_set_value(config->handle_user, "mpiosh", "prompt_int", config->prompt_int); cfg_key_set_value(config->handle_user, @@ -153,6 +170,17 @@ mpiosh_config_write(struct mpiosh_config_t *config) "mpiosh", "default_mem", "internal"); cfg_save(config->handle_user, 0); + + /* save history */ + filename = malloc(strlen(CONFIG_USER) + strlen(CONFIG_HISTORY) + 1); + filename[0] = '\0'; + strcat(filename, CONFIG_USER); + strcat(filename, CONFIG_HISTORY); + tmp = cfg_resolve_path(filename); + + printf("writing history to file %s\n", filename); + write_history(tmp); + free(tmp), free(filename); } return 1; diff --git a/mpiosh/global.c b/mpiosh/global.c index 554652e..a6459bd 100644 --- a/mpiosh/global.c +++ b/mpiosh/global.c @@ -2,7 +2,7 @@ * * Author: Andreas Buesching * - * $Id: global.c,v 1.5 2002/10/29 20:03:35 crunchy Exp $ + * $Id: global.c,v 1.6 2002/11/04 16:25:17 crunchy Exp $ * * Copyright (C) 2001 Andreas Büsching * @@ -37,7 +37,7 @@ int mpiosh_cancel_ack = 0; const char *CONFIG_GLOBAL = SYSCONFDIR "/mpio/"; const char *CONFIG_USER = "~/.mpio/"; const char *CONFIG_FILE = "mpioshrc"; -const char *CONFIG_HISTORY = "~/.mpio/mpiosh_history"; +const char *CONFIG_HISTORY = "history"; /* prompt strings */ const char *PROMPT_INT = "\033[;1mmpio \033[m "; diff --git a/mpiosh/mpiosh.c b/mpiosh/mpiosh.c index 5ed1faa..5d76f42 100644 --- a/mpiosh/mpiosh.c +++ b/mpiosh/mpiosh.c @@ -2,7 +2,7 @@ /* * - * $Id: mpiosh.c,v 1.21 2002/10/29 20:03:35 crunchy Exp $ + * $Id: mpiosh.c,v 1.22 2002/11/04 16:25:17 crunchy Exp $ * * Author: Andreas Büsching * @@ -94,10 +94,7 @@ main(int argc, char *argv[]) { /* init readline and history */ mpiosh_readline_init(); - using_history(); - - debug_init(); - + debug_init(); mpiosh_init(); if (!isatty(fileno(stdin))) { -- cgit v1.2.3