From db2f3e7394d6f95435579bd9acad9cd9a727ed4d Mon Sep 17 00:00:00 2001 From: Michael Jennings Date: Mon, 3 Jul 2000 19:08:41 +0000 Subject: [PATCH] Mon Jul 3 12:17:53 PDT 2000 Michael Jennings Marius Gedminas reported a couple of issues back when he was on his bug-spotting binge that I didn't have time to fix just then. Well, now I've fixed them. ~/.Eterm/user.cfg will now be found if there isn't a theme-specific one; this allows you to have a single user.cfg which specifies some options you want all your Eterms to have. Along those same lines, the action code now searches for duplicate bindings and changes the existing one rather than adding a new one to the end of the list. This allows bindings in user.cfg to override those in theme.cfg (as they should). Also, bindings are added in reverse order, so newer ones (like in user.cfg) take precedence over older ones (like in theme.cfg) if there is a conflict (e.g., if your theme.cfg binds "anymod button2" and user.cfg binds "ctrl button2," user.cfg wins). SVN revision: 2901 --- ChangeLog | 19 +++++++++++++++++++ libmej/mem.h | 2 +- src/actions.c | 47 ++++++++++++++++++++++++++++++++++++++++------- src/actions.h | 3 +++ src/debug.h | 13 +++++++------ src/options.c | 25 ++++++++++++++++--------- src/options.h | 7 ++++++- src/startup.c | 5 +++-- src/system.c | 2 +- 9 files changed, 96 insertions(+), 27 deletions(-) diff --git a/ChangeLog b/ChangeLog index 142b78f..9182b2c 100644 --- a/ChangeLog +++ b/ChangeLog @@ -3724,3 +3724,22 @@ Wed Jun 28 14:14:53 PDT 2000 Michael Jennings screwed. Fixed now. ------------------------------------------------------------------------------- +Mon Jul 3 12:17:53 PDT 2000 Michael Jennings + + Marius Gedminas reported a couple of issues back + when he was on his bug-spotting binge that I didn't have time to fix + just then. Well, now I've fixed them. ~/.Eterm/user.cfg will now + be found if there isn't a theme-specific one; this allows you to have + a single user.cfg which specifies some options you want all your + Eterms to have. + + Along those same lines, the action code now searches for duplicate + bindings and changes the existing one rather than adding a new one + to the end of the list. This allows bindings in user.cfg to override + those in theme.cfg (as they should). Also, bindings are added in + reverse order, so newer ones (like in user.cfg) take precedence over + older ones (like in theme.cfg) if there is a conflict (e.g., if your + theme.cfg binds "anymod button2" and user.cfg binds "ctrl button2," + user.cfg wins). + +------------------------------------------------------------------------------- diff --git a/libmej/mem.h b/libmej/mem.h index 5b6ca7d..01318d5 100644 --- a/libmej/mem.h +++ b/libmej/mem.h @@ -52,7 +52,7 @@ typedef struct memrec_struct { #else # define MALLOC(sz) malloc(sz) # define CALLOC(type,n) calloc((n),(sizeof(type))) -# define REALLOC(mem,sz) ((sz) ? ((mem) ? (realloc((mem), (sz))) : (malloc(sz))) : ((mem) ? (free(mem)) : (NULL))) +# define REALLOC(mem,sz) ((sz) ? ((mem) ? (realloc((mem), (sz))) : (malloc(sz))) : ((mem) ? (free(mem), NULL) : (NULL))) # define FREE(ptr) do { free(ptr); (ptr) = NULL; } while (0) #endif diff --git a/src/actions.c b/src/actions.c index a404360..525010e 100644 --- a/src/actions.c +++ b/src/actions.c @@ -69,6 +69,14 @@ action_handle_echo(event_t *ev, action_t *action) { ev = NULL; } +unsigned char +action_handle_function(event_t *ev, action_t *action) { + REQUIRE_RVAL(action->param.string != NULL, 0); + /* To be continued.... :-) */ + return 1; + ev = NULL; +} + unsigned char action_handle_menu(event_t *ev, action_t *action) { REQUIRE_RVAL(action->param.menu != NULL, 0); @@ -76,6 +84,22 @@ action_handle_menu(event_t *ev, action_t *action) { return 1; } +action_t * +action_find_match(unsigned short mod, unsigned char button, KeySym keysym) { + + action_t *action; + + D_ACTIONS(("mod == 0x%08x, button == %d, keysym == 0x%08x\n", mod, button, keysym)); + for (action = action_list; action; action = action->next) { + D_ACTIONS(("Checking action. mod == 0x%08x, button == %d, keysym == 0x%08x\n", action->mod, action->button, action->keysym)); + if ((action->mod == mod) && (action->button == button) && (action->keysym == keysym)) { + D_ACTIONS(("Match found at %8p\n", action)); + return action; + } + } + return NULL; +} + unsigned char action_dispatch(event_t *ev, KeySym keysym) { @@ -141,14 +165,18 @@ action_dispatch(event_t *ev, KeySym keysym) { void action_add(unsigned short mod, unsigned char button, KeySym keysym, action_type_t type, void *param) { - static action_t *action; + action_t *action; - if (!action_list) { - action_list = (action_t *) MALLOC(sizeof(action_t)); - action = action_list; + if (!action_list || (action = action_find_match(mod, button, keysym)) == NULL) { + action = (action_t *) MALLOC(sizeof(action_t)); + action->next = action_list; + action_list = action; } else { - action->next = (action_t *) MALLOC(sizeof(action_t)); - action = action->next; + if (action->type == ACTION_STRING || action->type == ACTION_ECHO || action->type == ACTION_FUNCTION) { + if (action->param.string) { + FREE(action->param.string); + } + } } action->mod = mod; action->button = button; @@ -167,6 +195,12 @@ action_add(unsigned short mod, unsigned char button, KeySym keysym, action_type_ strcpy(action->param.string, (char *) param); parse_escaped_string(action->param.string); break; + case ACTION_FUNCTION: + action->handler = (action_handler_t) action_handle_function; + action->param.string = (char *) MALLOC(strlen((char *) param) + 2); + strcpy(action->param.string, (char *) param); + parse_escaped_string(action->param.string); + break; case ACTION_MENU: action->handler = (action_handler_t) action_handle_menu; action->param.menu = (menu_t *) param; @@ -174,7 +208,6 @@ action_add(unsigned short mod, unsigned char button, KeySym keysym, action_type_ default: break; } - action->next = NULL; D_ACTIONS(("Added action. mod == 0x%08x, button == %d, keysym == 0x%08x\n", action->mod, action->button, action->keysym)); } diff --git a/src/actions.h b/src/actions.h index 891946d..cfc387f 100644 --- a/src/actions.h +++ b/src/actions.h @@ -35,6 +35,7 @@ typedef enum { ACTION_NONE = 0, ACTION_STRING, ACTION_ECHO, + ACTION_FUNCTION, ACTION_MENU } action_type_t; @@ -82,7 +83,9 @@ _XFUNCPROTOBEGIN extern unsigned char action_handle_string(event_t *ev, action_t *action); extern unsigned char action_handle_echo(event_t *ev, action_t *action); +extern unsigned char action_handle_function(event_t *ev, action_t *action); extern unsigned char action_handle_menu(event_t *ev, action_t *action); +extern action_t *action_find_match(unsigned short mod, unsigned char button, KeySym keysym); extern unsigned char action_dispatch(event_t *ev, KeySym keysym); extern void action_add(unsigned short mod, unsigned char button, KeySym keysym, action_type_t type, void *param); diff --git a/src/debug.h b/src/debug.h index 46b8983..4d26c2c 100644 --- a/src/debug.h +++ b/src/debug.h @@ -172,15 +172,16 @@ extern unsigned int debug_level; # define DEBUG_COLORS 3 # define D_COLORS(x) DPRINTF3(x) -# define DEBUG_MALLOC 4 -# define D_MALLOC(x) DPRINTF4(x) # define DEBUG_ACTIONS 4 # define D_ACTIONS(x) DPRINTF4(x) -# define DEBUG_PROFILE 4 -# define D_PROFILE(x) DPRINTF4(x) -# define DEBUG_VT 5 -# define D_VT(x) DPRINTF5(x) +# define DEBUG_MALLOC 5 +# define D_MALLOC(x) DPRINTF5(x) +# define DEBUG_PROFILE 5 +# define D_PROFILE(x) DPRINTF5(x) + +# define DEBUG_VT 6 +# define D_VT(x) DPRINTF6(x) # define DEBUG_X 9 diff --git a/src/options.c b/src/options.c index b5dfedc..9797fe2 100644 --- a/src/options.c +++ b/src/options.c @@ -3365,6 +3365,7 @@ open_config_file(char *name) if (fp != NULL) { fgets(buff, 256, fp); if (BEG_STRCASECMP(buff, "<" PACKAGE "-")) { + print_warning("%s exists but does not contain the proper magic string (<" PACKAGE "-" VERSION ">)\n", name); fclose(fp); fp = NULL; } else { @@ -3524,7 +3525,7 @@ conf_parse(char *conf_name, const char *dir, const char *path) { } char * -conf_parse_theme(char *theme, char *conf_name, unsigned char fallback) +conf_parse_theme(char **theme, char *conf_name, unsigned char fallback) { static char path[CONFIG_BUFF]; char *ret = NULL; @@ -3541,16 +3542,22 @@ conf_parse_theme(char *theme, char *conf_name, unsigned char fallback) } shell_expand(path); } - if (!theme || (ret = conf_parse(conf_name, rs_theme, path)) == NULL) { - if (fallback) { - RESET_AND_ASSIGN(rs_theme, StrDup(PACKAGE)); - if ((ret = conf_parse(conf_name, rs_theme, path)) == NULL) { - RESET_AND_ASSIGN(rs_theme, NULL); - ret = conf_parse(conf_name, rs_theme, path); - } + if (fallback & PARSE_TRY_USER_THEME) { + if (theme && *theme && (ret = conf_parse(conf_name, *theme, path)) != NULL) { + return ret; } } - return ret; + if (fallback & PARSE_TRY_DEFAULT_THEME) { + RESET_AND_ASSIGN(*theme, StrDup(PACKAGE)); + if ((ret = conf_parse(conf_name, *theme, path)) != NULL) { + return ret; + } + } + if (fallback & PARSE_TRY_NO_THEME) { + RESET_AND_ASSIGN(*theme, NULL); + return (conf_parse(conf_name, *theme, path)); + } + return NULL; } static void * diff --git a/src/options.h b/src/options.h index c9652c4..6f14350 100644 --- a/src/options.h +++ b/src/options.h @@ -38,6 +38,11 @@ #define CONF_BEGIN_CHAR ((char) 1) #define CONF_END_CHAR ((char) 2) +#define PARSE_TRY_USER_THEME ((unsigned char) 0x01) +#define PARSE_TRY_DEFAULT_THEME ((unsigned char) 0x02) +#define PARSE_TRY_NO_THEME ((unsigned char) 0x04) +#define PARSE_TRY_ALL ((unsigned char) 0x07) + #define OPT_BOOLEAN 0x0001 #define OPT_INTEGER 0x0002 #define OPT_STRING 0x0004 @@ -257,7 +262,7 @@ extern char *shell_expand(char *); extern char *conf_find_file(const char *file, const char *dir, const char *pathlist); extern FILE *open_config_file(char *name); extern char *conf_parse(char *conf_name, const char *dir, const char *path); -extern char *conf_parse_theme(char *theme, char *conf_name, unsigned char fallback); +extern char *conf_parse_theme(char **theme, char *conf_name, unsigned char fallback); extern void init_defaults(void); extern void post_parse(void); unsigned char save_config(char *, unsigned char); diff --git a/src/startup.c b/src/startup.c index 1bf17e2..ab6bfa5 100644 --- a/src/startup.c +++ b/src/startup.c @@ -141,7 +141,7 @@ eterm_bootstrap(int argc, char *argv[]) /* Initialize the parser */ conf_init_subsystem(); - if ((theme_dir = conf_parse_theme(rs_theme, THEME_CFG, 1)) != NULL) { + if ((theme_dir = conf_parse_theme(&rs_theme, THEME_CFG, PARSE_TRY_ALL)) != NULL) { char *tmp; D_OPTIONS(("conf_parse_theme() returned \"%s\"\n", theme_dir)); @@ -149,7 +149,8 @@ eterm_bootstrap(int argc, char *argv[]) sprintf(tmp, "ETERM_THEME_ROOT=%s", theme_dir); putenv(tmp); } - if ((user_dir = conf_parse_theme(rs_theme, (rs_config_file ? rs_config_file : USER_CFG), 0)) != NULL) { + if ((user_dir = conf_parse_theme(&rs_theme, (rs_config_file ? rs_config_file : USER_CFG), + (PARSE_TRY_USER_THEME | PARSE_TRY_NO_THEME))) != NULL) { char *tmp; D_OPTIONS(("conf_parse_theme() returned \"%s\"\n", user_dir)); diff --git a/src/system.c b/src/system.c index 8383d92..c3eedc6 100644 --- a/src/system.c +++ b/src/system.c @@ -42,7 +42,7 @@ static const char cvs_ident[] = "$Id$"; #include "misc.h" #include "system.h" -static sighandler_t old_handler = (sighandler_t) NULL; +/*static sighandler_t old_handler = (sighandler_t) NULL;*/ int wait_for_chld(int system_pid)