From fd895e3759973a2c8a84c1f88fe2850f21606de2 Mon Sep 17 00:00:00 2001 From: Pavel Roskin Date: Mon, 23 Jul 2001 22:50:54 +0000 Subject: [PATCH] * user.c: Eliminate static variable s_editwidget. Pass edit_widget as argument. All callers changed. (expand_format): Fix expansion of %n and %b for the editor. * util.c: Remove dead code. --- src/ChangeLog | 5 +++++ src/command.c | 2 +- src/ext.c | 2 +- src/user.c | 59 ++++++++++++++++++++++++++++----------------------- src/user.h | 2 +- src/util.c | 25 ---------------------- 6 files changed, 41 insertions(+), 54 deletions(-) diff --git a/src/ChangeLog b/src/ChangeLog index 6abbde12b..57e15e138 100644 --- a/src/ChangeLog +++ b/src/ChangeLog @@ -1,5 +1,10 @@ 2001-07-23 Pavel Roskin + * user.c: Eliminate static variable s_editwidget. Pass + edit_widget as argument. All callers changed. + (expand_format): Fix expansion of %n and %b for the editor. + * util.c: Remove dead code. + * setup.c (load_keys_from_section): Give terminal-specific settings preference over settings from [terminal:general]. diff --git a/src/command.c b/src/command.c index 687792fad..58f8f7fc3 100644 --- a/src/command.c +++ b/src/command.c @@ -205,7 +205,7 @@ static int enter (WCommand *cmdline) for (i = j = 0; i < strlen (cmd); i ++){ if (cmd [i] == '%'){ i ++; - s = expand_format (cmd [i], 1); + s = expand_format (NULL, cmd [i], 1); command = g_realloc (command, strlen (command) + strlen (s) + strlen (cmd) - i + 1); strcat (command, s); diff --git a/src/ext.c b/src/ext.c index 176045859..f77e7f17f 100644 --- a/src/ext.c +++ b/src/ext.c @@ -225,7 +225,7 @@ exec_extension (const char *filename, const char *data, char **drops, int *move_ } else if (*data == 'q') { text = quote_block (quote_func, drops); } else - text = expand_format (*data, !is_cd); + text = expand_format (NULL, *data, !is_cd); if (!is_cd) fputs (text, cmd_file); else { diff --git a/src/user.c b/src/user.c index d345e2d22..1c6774483 100644 --- a/src/user.c +++ b/src/user.c @@ -54,7 +54,6 @@ static int debug_flag = 0; static int debug_error = 0; #endif /* !HAVE_X */ -static WEdit *s_editwidget; static char *menu = NULL; /* Formats defined: @@ -178,7 +177,7 @@ strip_ext(char *ss) return ss; } -char *expand_format (char c, int quote) +char *expand_format (WEdit *edit_widget, char c, int quote) { WPanel *panel; char *(*quote_func)(const char *, int); @@ -208,24 +207,33 @@ char *expand_format (char c, int quote) switch (c){ case 'f': case 'p': return (*quote_func) (fname, 0); - case 'b': return strip_ext((*quote_func) (fname, 0)); case 'x': return (*quote_func) (extension(fname), 0); case 'd': return (*quote_func) (panel->cwd, 0); case 'i': /* indent equal number cursor position in line */ - if (s_editwidget) - return g_strnfill (s_editwidget->curs_col, ' '); + if (edit_widget) + return g_strnfill (edit_widget->curs_col, ' '); break; case 'y': /* syntax type */ - if (s_editwidget && s_editwidget->syntax_type) - return g_strdup (s_editwidget->syntax_type); + if (edit_widget && edit_widget->syntax_type) + return g_strdup (edit_widget->syntax_type); break; case 'e': /* error file name */ - case 'k': /* block file name */ { - char *file = g_strconcat (home_dir, (c == 'e') ? ERROR_FILE : BLOCK_FILE, NULL); - fname = (*quote_func) (file, 0); - g_free (file); - return fname; + case 'b': /* block file name / strip extension */ { + if (edit_widget) { + char *file = g_strconcat (home_dir, + (c == 'e') ? ERROR_FILE : BLOCK_FILE, + NULL); + fname = (*quote_func) (file, 0); + g_free (file); + return fname; + } else if (c == 'e') { + return strip_ext((*quote_func) (fname, 0)); + } } + case 'n': /* strip extension in editor */ + if (edit_widget) + return strip_ext((*quote_func) (fname, 0)); + break; case 'm': /* menu file name */ if (menu) return (*quote_func) (menu, 0); @@ -344,7 +352,7 @@ static int test_type (WPanel *panel, char *arg) /* Calculates the truth value of the next condition starting from p. Returns the point after condition. */ -static char *test_condition (char *p, int *condition) +static char *test_condition (WEdit *edit_widget, char *p, int *condition) { WPanel *panel; char arg [256]; @@ -366,7 +374,7 @@ static char *test_condition (char *p, int *condition) switch (*p++){ case '!': - p = test_condition (p, condition); + p = test_condition (edit_widget, p, condition); *condition = ! *condition; p--; break; @@ -375,10 +383,10 @@ static char *test_condition (char *p, int *condition) *condition = panel && regexp_match (arg, panel->dir.list [panel->selected].fname, match_file); break; case 'y': /* syntax pattern */ - if (s_editwidget && s_editwidget->syntax_type) { + if (edit_widget && edit_widget->syntax_type) { p = extract_arg (p, arg); *condition = panel && - regexp_match (arg, s_editwidget->syntax_type, match_normal); + regexp_match (arg, edit_widget->syntax_type, match_normal); } break; case 'd': @@ -462,7 +470,7 @@ debug_out (char *start, char *end, int cond) /* Calculates the truth value of one lineful of conditions. Returns the point just before the end of line. */ -static char *test_line (char *p, int *result) +static char *test_line (WEdit *edit_widget, char *p, int *result) { int condition; char operator; @@ -490,7 +498,7 @@ static char *test_line (char *p, int *result) condition = 1; /* True by default */ debug_start = p; - p = test_condition (p, &condition); + p = test_condition (edit_widget, p, &condition); debug_end = p; /* Add one debug statement */ debug_out (debug_start, debug_end, condition); @@ -525,7 +533,7 @@ static char *test_line (char *p, int *result) /* FIXME: recode this routine on version 3.0, it could be cleaner */ static void -execute_menu_command (char *commands) +execute_menu_command (WEdit *edit_widget, char *commands) { FILE *cmd_file; int cmd_file_fd; @@ -598,7 +606,7 @@ execute_menu_command (char *commands) if (*commands == '{') parameter = prompt; else{ - char *text = expand_format (*commands, do_quote); + char *text = expand_format (edit_widget, *commands, do_quote); fputs (text, cmd_file); g_free (text); } @@ -658,7 +666,6 @@ void user_menu_cmd (WEdit *edit_widget) int col, i, accept_entry = 1; int selected, old_patterns; Listbox *listbox; - s_editwidget = edit_widget; if (!vfs_current_is_local ()){ message (1, _(" Oops... "), @@ -716,23 +723,23 @@ void user_menu_cmd (WEdit *edit_widget) } else if (*p == '+'){ if (*(p+1) == '='){ /* Combined adding and default */ - p = test_line (p, &accept_entry); + p = test_line (edit_widget, p, &accept_entry); if (selected == 0 && accept_entry) selected = menu_lines; } else { /* A condition for adding the entry */ - p = test_line (p, &accept_entry); + p = test_line (edit_widget, p, &accept_entry); } } else if (*p == '='){ if (*(p+1) == '+'){ /* Combined adding and default */ - p = test_line (p, &accept_entry); + p = test_line (edit_widget, p, &accept_entry); if (selected == 0 && accept_entry) selected = menu_lines; } else { /* A condition for making the entry default */ i = 1; - p = test_line (p, &i); + p = test_line (edit_widget, p, &i); if (selected == 0 && i) selected = menu_lines; } @@ -780,7 +787,7 @@ void user_menu_cmd (WEdit *edit_widget) selected = run_listbox (listbox); if (selected >= 0) - execute_menu_command (entries [selected]); + execute_menu_command (edit_widget, entries [selected]); do_refresh (); } diff --git a/src/user.h b/src/user.h index 771fe2b02..ed2e15901 100644 --- a/src/user.h +++ b/src/user.h @@ -9,7 +9,7 @@ #endif void user_menu_cmd (WEdit *edit_widget); -char *expand_format (char, int); +char *expand_format (WEdit *edit_widget, char c, int quote); int check_format_view (const char *); int check_format_var (const char *, char **); int check_format_cd (const char *); diff --git a/src/util.c b/src/util.c index c9ff66c49..f48f622da 100644 --- a/src/util.c +++ b/src/util.c @@ -74,7 +74,6 @@ #include "global.h" #include "x.h" #include "profile.h" -#include "user.h" /* expand_format */ #include "main.h" /* mc_home */ #include "cmd.h" /* guess_message_value */ #include "../vfs/vfs.h" @@ -798,30 +797,6 @@ void my_putenv (char *name, char *data) /* WARNING: NEVER FREE THE full VARIABLE!!!!!!!!!!!!!!!!!!!!!!!! */ /* It is used by putenv. Freeing it will corrupt the environment */ } - -#if 0 -static void my_putenv_expand (char *name, char macro_code) -{ - char *data; - - data = expand_format (macro_code); - my_putenv (name, data); - g_free (data); -} - -/* Puts some status information in to the environment so that - processes to be executed can access it. */ -static void prepare_environment (void) -{ - my_putenv_expand ("MC_CURRENT_DIR", 'd'); - my_putenv_expand ("MC_OTHER_DIR", 'D'); - my_putenv_expand ("MC_CURRENT_FILE", 'f'); - my_putenv_expand ("MC_OTHER_FILE", 'F'); - my_putenv_expand ("MC_CURRENT_TAGGED", 't'); - my_putenv_expand ("MC_OTHER_TAGGED", 'T'); - /* MC_CONTROL_FILE has been added to environment on startup */ -} -#endif #endif /* VFS_STANDALONE */ char *unix_error_string (int error_num)