From 454110e1b17214b220317704f092bd3587b88a9d Mon Sep 17 00:00:00 2001 From: Lars-Dominik Braun Date: Sat, 9 May 2009 13:08:34 +0200 Subject: Switch to cmake "Works for now..." --- mpiosh/.gitignore | 2 + mpiosh/CMakeLists.txt | 15 ++++ mpiosh/Makefile.am | 23 ----- mpiosh/callback.c | 1 + mpiosh/cfg.c | 238 ++++++++++++++++++++++++++++++++++++++++++++++++++ mpiosh/cfg.h | 56 ++++++++++++ mpiosh/config.c | 238 -------------------------------------------------- mpiosh/config.h | 55 ------------ mpiosh/config.h.in | 9 ++ mpiosh/global.c | 1 + mpiosh/mpiosh.c | 2 +- 11 files changed, 323 insertions(+), 317 deletions(-) create mode 100644 mpiosh/.gitignore create mode 100644 mpiosh/CMakeLists.txt delete mode 100644 mpiosh/Makefile.am create mode 100644 mpiosh/cfg.c create mode 100644 mpiosh/cfg.h delete mode 100644 mpiosh/config.c delete mode 100644 mpiosh/config.h create mode 100644 mpiosh/config.h.in (limited to 'mpiosh') diff --git a/mpiosh/.gitignore b/mpiosh/.gitignore new file mode 100644 index 0000000..2e3941e --- /dev/null +++ b/mpiosh/.gitignore @@ -0,0 +1,2 @@ +mpiosh +config.h diff --git a/mpiosh/CMakeLists.txt b/mpiosh/CMakeLists.txt new file mode 100644 index 0000000..efff2c7 --- /dev/null +++ b/mpiosh/CMakeLists.txt @@ -0,0 +1,15 @@ +cmake_minimum_required (VERSION 2.4) + +set (PACKAGE mpiosh) +project (${PACKAGE} C) + +set (CMAKE_C_FLAGS -Wall) + +configure_file (${CMAKE_CURRENT_SOURCE_DIR}/config.h.in + ${CMAKE_CURRENT_BINARY_DIR}/config.h) + +include_directories (${CMAKE_CURRENT_SOURCE_DIR}/..) + +add_executable (mpiosh mpiosh.c callback.c readline.c command.c global.c + cfgio.c cfg.c) +target_link_libraries (mpiosh mpio -lreadline -lncurses) diff --git a/mpiosh/Makefile.am b/mpiosh/Makefile.am deleted file mode 100644 index ed5843e..0000000 --- a/mpiosh/Makefile.am +++ /dev/null @@ -1,23 +0,0 @@ -INCLUDES=-I.. - -bin_PROGRAMS=mpiosh - -mpiosh_SOURCES = mpiosh.c \ - callback.c \ - readline.c \ - command.c \ - global.c \ - cfgio.c \ - config.c - -AM_CFLAGS=-DSYSCONFDIR=\"@sysconfdir@\" - -mpiosh_LDADD=../libmpio/libmpio.la -lreadline -lncurses - -noinst_HEADERS = mpiosh.h \ - callback.h \ - readline.h \ - command.h \ - global.h \ - cfgio.h \ - config.h \ No newline at end of file diff --git a/mpiosh/callback.c b/mpiosh/callback.c index ad4a133..10e5a0a 100644 --- a/mpiosh/callback.c +++ b/mpiosh/callback.c @@ -34,6 +34,7 @@ #include "mpiosh.h" #include "command.h" +#include "cfg.h" #include "libmpio/debug.h" diff --git a/mpiosh/cfg.c b/mpiosh/cfg.c new file mode 100644 index 0000000..f8c672f --- /dev/null +++ b/mpiosh/cfg.c @@ -0,0 +1,238 @@ +/* config.c + * + * Author: Andreas Buesching + * + * $Id: config.c,v 1.7 2003/06/27 13:40:23 crunchy Exp $ + * + * Copyright (C) 2001 Andreas Büsching + * + * 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, 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., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. + */ + +#include "cfg.h" +#include "global.h" + +#include +#include +#include + +struct mpiosh_config_t * +mpiosh_config_new(void) +{ + struct mpiosh_config_t * cfg = malloc(sizeof(struct mpiosh_config_t)); + char *filename, *tmp; + struct stat st; + + cfg->prompt_int = cfg->prompt_ext = NULL; + cfg->default_mem = MPIO_INTERNAL_MEM; + + filename = malloc(strlen(CONFIG_GLOBAL) + strlen(CONFIG_FILE) + 1); + filename[0] = '\0'; + strcat(filename, CONFIG_GLOBAL); + strcat(filename, CONFIG_FILE); + tmp = cfg_resolve_path(filename); + + 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); + filename[0] = '\0'; + strcat(filename, CONFIG_USER); + strcat(filename, CONFIG_FILE); + tmp = cfg_resolve_path(filename); + + if (stat(tmp, &st) != -1) + cfg->handle_user = + cfg_handle_new_with_filename(tmp, 1); + else + cfg->handle_user = + cfg_handle_new_with_filename(tmp, 0); + + 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; +} + +const char * +mpiosh_config_read_key(struct mpiosh_config_t *config, const char *group, + const char *key) +{ + char *value = NULL; + + if (config->handle_user) + value = (char *)cfg_key_get_value(config->handle_user, + group, key); + else if (config->handle_global) + value = (char *)cfg_key_get_value(config->handle_global, + group, key); + + return value; +} + +void +mpiosh_config_free(struct mpiosh_config_t *config) +{ + if (config->handle_global) + cfg_close(config->handle_global); + + cfg_close(config->handle_user); + free(config->prompt_int); + free(config->prompt_ext); + free(config); +} + +int +mpiosh_config_read(struct mpiosh_config_t *config) +{ + if (config) { + const char *value; + + value = mpiosh_config_read_key(config, "mpiosh", "prompt_int"); + if (value) { + config->prompt_int = strdup(value); + } else { + config->prompt_int = strdup(PROMPT_INT); + } + + value = mpiosh_config_read_key(config, "mpiosh", "prompt_ext"); + if (value) { + config->prompt_ext = strdup(value); + } else { + config->prompt_ext = strdup(PROMPT_EXT); + } + + value = mpiosh_config_read_key(config, "mpiosh", "default_mem"); + if (value) { + if (!strcmp("internal", value)) { + config->default_mem = MPIO_INTERNAL_MEM; + } else if (!strcmp("external", value)) { + config->default_mem = MPIO_EXTERNAL_MEM; + } + } + + value = mpiosh_config_read_key(config, "mpiosh", "charset"); + if (value) { + config->charset = strdup(value); + } else { + config->charset = NULL; + } + + value = mpiosh_config_read_key(config, "mpiosh", "id3_rewriting"); + if (value) { + if (!strcmp("on", value)) { + config->id3_rewriting = 1; + } else { + config->id3_rewriting = 0; + } + } + + value = mpiosh_config_read_key(config, "mpiosh", "id3_format"); + if (value) { + config->id3_format = strdup(value); + } else { + config->id3_format = strdup(MPIO_ID3_FORMAT); + } + + } + + return 1; +} + +char * +mpiosh_config_check_backup_dir( struct mpiosh_config_t *config, int create ) +{ + DIR *dir; + char *path = cfg_resolve_path( CONFIG_BACKUP ); + char *ret = path; + + if ( ( dir = opendir( path ) ) == NULL ) + if ( create ) { + if ( mkdir(path, 0777 ) ) + ret = NULL; + } else + ret = NULL; + else + closedir(dir); + + return ret; +} + +int +mpiosh_config_write( struct mpiosh_config_t *config ) +{ + DIR *dir; + char *path = cfg_resolve_path(CONFIG_USER); + + if ((dir = opendir(path)) == NULL) + mkdir(path, 0777); + else + closedir(dir); + + 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, + "mpiosh", "prompt_ext", config->prompt_ext); + if (config->default_mem == MPIO_EXTERNAL_MEM) + cfg_key_set_value(config->handle_user, + "mpiosh", "default_mem", "external"); + else + cfg_key_set_value(config->handle_user, + "mpiosh", "default_mem", "internal"); + cfg_key_set_value(config->handle_user, + "mpiosh", "id3_rewriting", + (config->id3_rewriting?"on":"off")); + cfg_key_set_value(config->handle_user, + "mpiosh", "id3_format", config->id3_format); + + 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; +} + + +/* end of config.c */ diff --git a/mpiosh/cfg.h b/mpiosh/cfg.h new file mode 100644 index 0000000..4157bd6 --- /dev/null +++ b/mpiosh/cfg.h @@ -0,0 +1,56 @@ +/* config.h + * + * Author: Andreas Buesching + * + * $Id: config.h,v 1.5 2003/06/27 13:40:23 crunchy Exp $ + * + * Copyright (C) 2001 Andreas Büsching + * + * 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, 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., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. + */ + +#ifndef MPIOSH_CONFIG_HH +#define MPIOSH_CONFIG_HH + +#include "cfgio.h" + +struct mpiosh_config_t { + CfgHandle *handle_global; + CfgHandle *handle_user; + + char *prompt_int; + char *prompt_ext; + char *charset; + unsigned default_mem; + + unsigned id3_rewriting; + char *id3_format; +}; + +struct mpiosh_config_t *mpiosh_config_new(void); +void mpiosh_config_free(struct mpiosh_config_t *config); + +const char *mpiosh_config_read_key(struct mpiosh_config_t *config, + const char *group, const char *key); +int mpiosh_config_read(struct mpiosh_config_t *config); +int mpiosh_config_write(struct mpiosh_config_t *config); + +char * mpiosh_config_check_backup_dir( struct mpiosh_config_t *config, + int create ); + +#endif + +/* end of config.h */ + diff --git a/mpiosh/config.c b/mpiosh/config.c deleted file mode 100644 index 931f785..0000000 --- a/mpiosh/config.c +++ /dev/null @@ -1,238 +0,0 @@ -/* config.c - * - * Author: Andreas Buesching - * - * $Id: config.c,v 1.7 2003/06/27 13:40:23 crunchy Exp $ - * - * Copyright (C) 2001 Andreas Büsching - * - * 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, 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., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. - */ - -#include "config.h" -#include "global.h" - -#include -#include -#include - -struct mpiosh_config_t * -mpiosh_config_new(void) -{ - struct mpiosh_config_t * cfg = malloc(sizeof(struct mpiosh_config_t)); - char *filename, *tmp; - struct stat st; - - cfg->prompt_int = cfg->prompt_ext = NULL; - cfg->default_mem = MPIO_INTERNAL_MEM; - - filename = malloc(strlen(CONFIG_GLOBAL) + strlen(CONFIG_FILE) + 1); - filename[0] = '\0'; - strcat(filename, CONFIG_GLOBAL); - strcat(filename, CONFIG_FILE); - tmp = cfg_resolve_path(filename); - - 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); - filename[0] = '\0'; - strcat(filename, CONFIG_USER); - strcat(filename, CONFIG_FILE); - tmp = cfg_resolve_path(filename); - - if (stat(tmp, &st) != -1) - cfg->handle_user = - cfg_handle_new_with_filename(tmp, 1); - else - cfg->handle_user = - cfg_handle_new_with_filename(tmp, 0); - - 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; -} - -const char * -mpiosh_config_read_key(struct mpiosh_config_t *config, const char *group, - const char *key) -{ - char *value = NULL; - - if (config->handle_user) - value = (char *)cfg_key_get_value(config->handle_user, - group, key); - else if (config->handle_global) - value = (char *)cfg_key_get_value(config->handle_global, - group, key); - - return value; -} - -void -mpiosh_config_free(struct mpiosh_config_t *config) -{ - if (config->handle_global) - cfg_close(config->handle_global); - - cfg_close(config->handle_user); - free(config->prompt_int); - free(config->prompt_ext); - free(config); -} - -int -mpiosh_config_read(struct mpiosh_config_t *config) -{ - if (config) { - const char *value; - - value = mpiosh_config_read_key(config, "mpiosh", "prompt_int"); - if (value) { - config->prompt_int = strdup(value); - } else { - config->prompt_int = strdup(PROMPT_INT); - } - - value = mpiosh_config_read_key(config, "mpiosh", "prompt_ext"); - if (value) { - config->prompt_ext = strdup(value); - } else { - config->prompt_ext = strdup(PROMPT_EXT); - } - - value = mpiosh_config_read_key(config, "mpiosh", "default_mem"); - if (value) { - if (!strcmp("internal", value)) { - config->default_mem = MPIO_INTERNAL_MEM; - } else if (!strcmp("external", value)) { - config->default_mem = MPIO_EXTERNAL_MEM; - } - } - - value = mpiosh_config_read_key(config, "mpiosh", "charset"); - if (value) { - config->charset = strdup(value); - } else { - config->charset = NULL; - } - - value = mpiosh_config_read_key(config, "mpiosh", "id3_rewriting"); - if (value) { - if (!strcmp("on", value)) { - config->id3_rewriting = 1; - } else { - config->id3_rewriting = 0; - } - } - - value = mpiosh_config_read_key(config, "mpiosh", "id3_format"); - if (value) { - config->id3_format = strdup(value); - } else { - config->id3_format = strdup(MPIO_ID3_FORMAT); - } - - } - - return 1; -} - -char * -mpiosh_config_check_backup_dir( struct mpiosh_config_t *config, int create ) -{ - DIR *dir; - char *path = cfg_resolve_path( CONFIG_BACKUP ); - char *ret = path; - - if ( ( dir = opendir( path ) ) == NULL ) - if ( create ) { - if ( mkdir(path, 0777 ) ) - ret = NULL; - } else - ret = NULL; - else - closedir(dir); - - return ret; -} - -int -mpiosh_config_write( struct mpiosh_config_t *config ) -{ - DIR *dir; - char *path = cfg_resolve_path(CONFIG_USER); - - if ((dir = opendir(path)) == NULL) - mkdir(path, 0777); - else - closedir(dir); - - 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, - "mpiosh", "prompt_ext", config->prompt_ext); - if (config->default_mem == MPIO_EXTERNAL_MEM) - cfg_key_set_value(config->handle_user, - "mpiosh", "default_mem", "external"); - else - cfg_key_set_value(config->handle_user, - "mpiosh", "default_mem", "internal"); - cfg_key_set_value(config->handle_user, - "mpiosh", "id3_rewriting", - (config->id3_rewriting?"on":"off")); - cfg_key_set_value(config->handle_user, - "mpiosh", "id3_format", config->id3_format); - - 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; -} - - -/* end of config.c */ diff --git a/mpiosh/config.h b/mpiosh/config.h deleted file mode 100644 index 091e61a..0000000 --- a/mpiosh/config.h +++ /dev/null @@ -1,55 +0,0 @@ -/* config.h - * - * Author: Andreas Buesching - * - * $Id: config.h,v 1.5 2003/06/27 13:40:23 crunchy Exp $ - * - * Copyright (C) 2001 Andreas Büsching - * - * 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, 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., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. - */ - -#ifndef MPIOSH_CONFIG_HH -#define MPIOSH_CONFIG_HH - -#include "cfgio.h" - -struct mpiosh_config_t { - CfgHandle *handle_global; - CfgHandle *handle_user; - - char *prompt_int; - char *prompt_ext; - char *charset; - unsigned default_mem; - - unsigned id3_rewriting; - char *id3_format; -}; - -struct mpiosh_config_t *mpiosh_config_new(void); -void mpiosh_config_free(struct mpiosh_config_t *config); - -const char *mpiosh_config_read_key(struct mpiosh_config_t *config, - const char *group, const char *key); -int mpiosh_config_read(struct mpiosh_config_t *config); -int mpiosh_config_write(struct mpiosh_config_t *config); - -char * mpiosh_config_check_backup_dir( struct mpiosh_config_t *config, - int create ); - -#endif - -/* end of config.h */ diff --git a/mpiosh/config.h.in b/mpiosh/config.h.in new file mode 100644 index 0000000..bb60f14 --- /dev/null +++ b/mpiosh/config.h.in @@ -0,0 +1,9 @@ +#ifndef _CONFIG_H +#define _CONFIG_H + +/* package name */ +#define PACKAGE "${PACKAGE}" +#define VERSION "0.7.1-pre3" +#define SYSCONFDIR "/etc" + +#endif /* _CONFIG_H */ diff --git a/mpiosh/global.c b/mpiosh/global.c index f589114..09a63f3 100644 --- a/mpiosh/global.c +++ b/mpiosh/global.c @@ -24,6 +24,7 @@ #include "callback.h" #include "global.h" #include "readline.h" +#include "cfg.h" /* structure containing current state */ struct mpiosh_t mpiosh; diff --git a/mpiosh/mpiosh.c b/mpiosh/mpiosh.c index eb20845..7a5370a 100644 --- a/mpiosh/mpiosh.c +++ b/mpiosh/mpiosh.c @@ -35,7 +35,7 @@ #include "callback.h" #include "command.h" -#include "config.h" +#include "cfg.h" #include "readline.h" #include "mpiosh.h" -- cgit v1.2.3