From 80011ad7cba187f8895e5bda478c1934b712ba00 Mon Sep 17 00:00:00 2001 From: Slava Zanko Date: Fri, 19 Oct 2012 12:08:54 +0300 Subject: [PATCH] Move global variables to an appropriate place ...and move update_xterm_title_path() and title_path_prepare() from src/main.c to src/filemanager/layout.c Signed-off-by: Slava Zanko --- src/args.c | 4 +- src/args.h | 15 ++++++ src/clipboard.c | 2 +- src/diffviewer/ydiff.c | 1 + src/editor/edit.c | 1 - src/editor/editcmd.c | 1 - src/editor/editcmd_dialogs.c | 1 - src/editor/editdraw.c | 1 - src/editor/editwidget.c | 2 +- src/filemanager/command.c | 2 +- src/filemanager/find.c | 1 - src/filemanager/layout.c | 54 ++++++++++++++++++- src/filemanager/layout.h | 4 ++ src/filemanager/panel.h | 10 +++- src/help.c | 1 - src/main.c | 102 +---------------------------------- src/main.h | 71 ------------------------ src/selcodepage.c | 2 +- src/setup.c | 38 +++++++++++++ src/setup.h | 44 +++++++++++++++ src/subshell.c | 1 + src/vfs/extfs/extfs.c | 2 +- src/viewer/display.c | 1 - src/viewer/lib.c | 1 - src/viewer/mcviewer.c | 2 - 25 files changed, 173 insertions(+), 191 deletions(-) diff --git a/src/args.c b/src/args.c index 811ddc7fa..87892e5f0 100644 --- a/src/args.c +++ b/src/args.c @@ -38,7 +38,6 @@ #include "src/vfs/smbfs/smbfs.h" /* smbfs_set_debugf() */ #endif -#include "src/main.h" #include "src/textconf.h" #include "src/args.h" @@ -72,6 +71,9 @@ char *mc_args__keymap_file = NULL; /* Debug level */ int mc_args__debug_level = 0; +void *mc_run_param0 = NULL; +char *mc_run_param1 = NULL; + /*** file scope macro definitions ****************************************************************/ /*** file scope type declarations ****************************************************************/ diff --git a/src/args.h b/src/args.h index bfca15aa9..4fe1dea58 100644 --- a/src/args.h +++ b/src/args.h @@ -27,6 +27,21 @@ extern char *mc_args__netfs_logfile; extern char *mc_args__keymap_file; extern int mc_args__debug_level; +/* + * MC_RUN_FULL: dir for left panel + * MC_RUN_EDITOR: list of files to edit + * MC_RUN_VIEWER: file to view + * MC_RUN_DIFFVIEWER: first file to compare + */ +extern void *mc_run_param0; +/* + * MC_RUN_FULL: dir for right panel + * MC_RUN_EDITOR: unused + * MC_RUN_VIEWER: unused + * MC_RUN_DIFFVIEWER: second file to compare + */ +extern char *mc_run_param1; + /*** declarations of public functions ************************************************************/ gboolean mc_args_parse (int *argc, char ***argv, const char *translation_domain, GError ** error); diff --git a/src/clipboard.c b/src/clipboard.c index 5b04600e8..9ceb1fb2e 100644 --- a/src/clipboard.c +++ b/src/clipboard.c @@ -36,7 +36,7 @@ #include "lib/vfs/vfs.h" -#include "main.h" +#include "setup.h" #include "src/execute.h" #include "clipboard.h" diff --git a/src/diffviewer/ydiff.c b/src/diffviewer/ydiff.c index e44c23aac..68add475f 100644 --- a/src/diffviewer/ydiff.c +++ b/src/diffviewer/ydiff.c @@ -54,6 +54,7 @@ #include "src/filemanager/layout.h" /* Needed for get_current_index and get_other_panel */ #include "src/keybind-defaults.h" +#include "src/setup.h" #include "src/history.h" #ifdef HAVE_CHARSET #include "src/selcodepage.h" diff --git a/src/editor/edit.c b/src/editor/edit.c index d41c0dac7..23041bd2e 100644 --- a/src/editor/edit.c +++ b/src/editor/edit.c @@ -64,7 +64,6 @@ #include "src/filemanager/usermenu.h" /* user_menu_cmd() */ #include "src/setup.h" /* option_tab_spacing */ -#include "src/main.h" /* macro_index */ #include "src/learn.h" /* learn_keys */ #include "src/keybind-defaults.h" diff --git a/src/editor/editcmd.c b/src/editor/editcmd.c index 7c59bf608..2daa21f55 100644 --- a/src/editor/editcmd.c +++ b/src/editor/editcmd.c @@ -68,7 +68,6 @@ #include "src/history.h" #include "src/setup.h" /* option_tab_spacing */ -#include "src/main.h" /* mactos_t */ #ifdef HAVE_CHARSET #include "src/selcodepage.h" #endif diff --git a/src/editor/editcmd_dialogs.c b/src/editor/editcmd_dialogs.c index 742eb6940..0c0b5c75e 100644 --- a/src/editor/editcmd_dialogs.c +++ b/src/editor/editcmd_dialogs.c @@ -36,7 +36,6 @@ #include "lib/charsets.h" #endif -#include "src/main.h" #include "src/history.h" #include "src/editor/editwidget.h" diff --git a/src/editor/editdraw.c b/src/editor/editdraw.c index 9cce8120d..788a8dd7e 100644 --- a/src/editor/editdraw.c +++ b/src/editor/editdraw.c @@ -54,7 +54,6 @@ #endif #include "src/setup.h" /* edit_tab_spacing */ -#include "src/main.h" /* macro_index */ #include "edit-impl.h" #include "editwidget.h" diff --git a/src/editor/editwidget.c b/src/editor/editwidget.c index b6096247c..f0bb4b9a6 100644 --- a/src/editor/editwidget.c +++ b/src/editor/editwidget.c @@ -56,7 +56,7 @@ #include "lib/event.h" /* mc_event_raise() */ #include "src/keybind-defaults.h" -#include "src/main.h" /* home_dir */ +#include "src/setup.h" /* home_dir */ #include "src/filemanager/cmd.h" /* view_other_cmd(), save_setup_cmd() */ #include "src/learn.h" /* learn_keys() */ #include "src/args.h" /* mcedit_arg_t */ diff --git a/src/filemanager/command.c b/src/filemanager/command.c index dc7385290..1e27a8c1e 100644 --- a/src/filemanager/command.c +++ b/src/filemanager/command.c @@ -42,7 +42,7 @@ #include "lib/util.h" #include "lib/widget.h" -#include "src/main.h" /* do_cd */ +#include "src/setup.h" /* quit */ #include "src/subshell.h" /* SUBSHELL_EXIT */ #include "src/execute.h" /* shell_execute */ diff --git a/src/filemanager/find.c b/src/filemanager/find.c index 07ee2adc5..23d982fae 100644 --- a/src/filemanager/find.c +++ b/src/filemanager/find.c @@ -51,7 +51,6 @@ #include "src/setup.h" /* verbose */ #include "src/history.h" /* MC_HISTORY_SHARED_SEARCH */ -#include "src/main.h" /* do_cd */ #include "dir.h" #include "cmd.h" /* view_file_at_line */ diff --git a/src/filemanager/layout.c b/src/filemanager/layout.c index 7cb1b463d..4a26ea422 100644 --- a/src/filemanager/layout.c +++ b/src/filemanager/layout.c @@ -31,6 +31,7 @@ #include +#include /* for username in xterm title */ #include #include #include @@ -52,7 +53,6 @@ #include "src/viewer/mcviewer.h" /* The view widget */ #include "src/setup.h" #ifdef HAVE_SUBSHELL_SUPPORT -#include "src/main.h" /* do_load_prompt() */ #include "src/subshell.h" #endif @@ -1328,3 +1328,55 @@ load_prompt (int fd, void *unused) #endif /* HAVE_SUBSHELL_SUPPORT */ /* --------------------------------------------------------------------------------------------- */ + +void +title_path_prepare (char **path, char **login) +{ + char host[BUF_TINY]; + struct passwd *pw = NULL; + int res = 0; + + *path = + vfs_path_to_str_flags (current_panel->cwd_vpath, 0, VPF_STRIP_HOME | VPF_STRIP_PASSWORD); + + res = gethostname (host, sizeof (host)); + if (res != 0) + host[0] = '\0'; + else + host[sizeof (host) - 1] = '\0'; + + pw = getpwuid (getuid ()); + if (pw != NULL) + *login = g_strdup_printf ("%s@%s", pw->pw_name, host); + else + *login = g_strdup (host); +} + +/* --------------------------------------------------------------------------------------------- */ + +/** Show current directory in the xterm title */ +void +update_xterm_title_path (void) +{ + if (mc_global.tty.xterm_flag && xterm_title) + { + char *p; + char *path; + char *login; + + title_path_prepare (&path, &login); + + p = g_strdup_printf ("mc [%s]:%s", login, path); + g_free (login); + g_free (path); + + fprintf (stdout, "\33]0;%s\7", str_term_form (p)); + g_free (p); + + if (!mc_global.tty.alternate_plus_minus) + numeric_keypad_mode (); + (void) fflush (stdout); + } +} + +/* --------------------------------------------------------------------------------------------- */ diff --git a/src/filemanager/layout.h b/src/filemanager/layout.h index aea7483a6..0ddbb2ebb 100644 --- a/src/filemanager/layout.h +++ b/src/filemanager/layout.h @@ -86,6 +86,10 @@ gboolean do_load_prompt (void); int load_prompt (int fd, void *unused); #endif +void update_xterm_title_path (void); + +void title_path_prepare (char **path, char **login); + /*** inline functions ****************************************************************************/ #endif /* MC__LAYOUT_H */ diff --git a/src/filemanager/panel.h b/src/filemanager/panel.h index 6b2436df5..62b929824 100644 --- a/src/filemanager/panel.h +++ b/src/filemanager/panel.h @@ -12,8 +12,6 @@ #include "lib/strutil.h" #include "lib/widget.h" /* Widget */ -#include "src/main.h" /* cd_enum */ - #include "dir.h" /* dir_list */ /*** typedefs(not structures) and defined constants **********************************************/ @@ -48,6 +46,14 @@ typedef enum UP_ONLY_CURRENT = 2 } panel_update_flags_t; +/* run mode and params */ + +enum cd_enum +{ + cd_parse_command, + cd_exact +}; + /*** structures declarations (and typedefs of structures)*****************************************/ struct format_e; diff --git a/src/help.c b/src/help.c index 09835791c..508466d34 100644 --- a/src/help.c +++ b/src/help.c @@ -69,7 +69,6 @@ #include "keybind-defaults.h" #include "keybind-defaults.h" #include "help.h" -#include "main.h" /*** global variables ****************************************************************************/ diff --git a/src/main.c b/src/main.c index a09ade142..34366b06b 100644 --- a/src/main.c +++ b/src/main.c @@ -35,11 +35,11 @@ #include #include #include +#include /* for username in xterm title */ #include #include #include #include -#include /* for username in xterm title */ #include #include "lib/global.h" @@ -79,46 +79,6 @@ /*** global variables ****************************************************************************/ -mc_fhl_t *mc_filehighlight; - -/* Set when main loop should be terminated */ -int quit = 0; - -#ifdef HAVE_CHARSET -/* Numbers of (file I/O) and (input/display) codepages. -1 if not selected */ -int default_source_codepage = -1; -char *autodetect_codeset = NULL; -gboolean is_autodetect_codeset_enabled = FALSE; -#endif /* !HAVE_CHARSET */ - -/* If true use the internal viewer */ -int use_internal_view = 1; -/* If set, use the builtin editor */ -int use_internal_edit = 1; - -void *mc_run_param0 = NULL; -char *mc_run_param1 = NULL; - -/* The user's shell */ -char *shell = NULL; - -/* The prompt */ -const char *mc_prompt = NULL; - -/* Set to TRUE to suppress printing the last directory */ -int print_last_revert = FALSE; - -/* If set, then print to the given file the last directory we were at */ -char *last_wd_string = NULL; - -/* index to record_macro_buf[], -1 if not recording a macro */ -int macro_index = -1; - -/* macro stuff */ -struct macro_action_t record_macro_buf[MAX_MACRO_LENGTH]; - -GArray *macros_list; - /*** file scope macro definitions ****************************************************************/ /*** file scope type declarations ****************************************************************/ @@ -274,66 +234,6 @@ init_sigchld (void) /*** public functions ****************************************************************************/ /* --------------------------------------------------------------------------------------------- */ -void -title_path_prepare (char **path, char **login) -{ - - char host[BUF_TINY]; - struct passwd *pw = NULL; - int res = 0; - - *login = NULL; - - - *path = - vfs_path_to_str_flags (current_panel->cwd_vpath, 0, VPF_STRIP_HOME | VPF_STRIP_PASSWORD); - res = gethostname (host, sizeof (host)); - if (res) - { /* On success, res = 0 */ - host[0] = '\0'; - } - else - { - host[sizeof (host) - 1] = '\0'; - } - pw = getpwuid (getuid ()); - if (pw) - { - *login = g_strdup_printf ("%s@%s", pw->pw_name, host); - } - else - { - *login = g_strdup (host); - } -} - -/* --------------------------------------------------------------------------------------------- */ - -/** Show current directory in the xterm title */ -void -update_xterm_title_path (void) -{ - char *p; - char *path; - char *login; - - if (!(mc_global.tty.xterm_flag && xterm_title)) - return; - - title_path_prepare (&path, &login); - - p = g_strdup_printf ("mc [%s]:%s", login, path); - fprintf (stdout, "\33]0;%s\7", str_term_form (p)); - g_free (login); - g_free (p); - if (!mc_global.tty.alternate_plus_minus) - numeric_keypad_mode (); - (void) fflush (stdout); - g_free (path); -} - -/* --------------------------------------------------------------------------------------------- */ - int main (int argc, char *argv[]) { diff --git a/src/main.h b/src/main.h index b5f6df017..37a88ebb2 100644 --- a/src/main.h +++ b/src/main.h @@ -10,85 +10,14 @@ /*** typedefs(not structures) and defined constants **********************************************/ -#define MAX_MACRO_LENGTH 1024 - /*** enums ***************************************************************************************/ -/* run mode and params */ - -enum cd_enum -{ - cd_parse_command, - cd_exact -}; - /*** structures declarations (and typedefs of structures)*****************************************/ -typedef struct macro_action_t -{ - unsigned long action; - int ch; -} macro_action_t; - -typedef struct macros_t -{ - int hotkey; - GArray *macro; -} macros_t; - -struct mc_fhl_struct; - /*** global variables defined in .c file *********************************************************/ -/* - * MC_RUN_FULL: dir for left panel - * MC_RUN_EDITOR: list of files to edit - * MC_RUN_VIEWER: file to view - * MC_RUN_DIFFVIEWER: first file to compare - */ -extern void *mc_run_param0; -/* - * MC_RUN_FULL: dir for right panel - * MC_RUN_EDITOR: unused - * MC_RUN_VIEWER: unused - * MC_RUN_DIFFVIEWER: second file to compare - */ -extern char *mc_run_param1; - -extern int quit; -/* Set to TRUE to suppress printing the last directory */ -extern gboolean print_last_revert; -/* If set, then print to the given file the last directory we were at */ -extern char *last_wd_string; - -extern struct mc_fhl_struct *mc_filehighlight; - -extern int use_internal_view; -extern int use_internal_edit; - -#ifdef HAVE_CHARSET -extern int default_source_codepage; -extern char *autodetect_codeset; -extern gboolean is_autodetect_codeset_enabled; -#endif /* !HAVE_CHARSET */ - -extern char *shell; -extern const char *mc_prompt; - -/* index to record_macro_buf[], -1 if not recording a macro */ -extern int macro_index; - -/* macro stuff */ -extern struct macro_action_t record_macro_buf[MAX_MACRO_LENGTH]; - -extern GArray *macros_list; - /*** declarations of public functions ************************************************************/ -void update_xterm_title_path (void); - -void title_path_prepare (char **path, char **login); - /*** inline functions ****************************************************************************/ #endif /* MC__MAIN_H */ diff --git a/src/selcodepage.c b/src/selcodepage.c index f26bb4800..f8834943f 100644 --- a/src/selcodepage.c +++ b/src/selcodepage.c @@ -38,7 +38,7 @@ #include "lib/widget.h" #include "lib/charsets.h" -#include "main.h" +#include "setup.h" #include "selcodepage.h" diff --git a/src/setup.c b/src/setup.c index 2ef45e32e..ecaa66dec 100644 --- a/src/setup.c +++ b/src/setup.c @@ -35,6 +35,7 @@ #include "lib/global.h" +#include "lib/filehighlight.h" #include "lib/tty/tty.h" #include "lib/tty/key.h" #include "lib/mcconfig.h" @@ -175,6 +176,43 @@ int verbose = 1; */ int file_op_compute_totals = 1; +/* If true use the internal viewer */ +int use_internal_view = 1; +/* If set, use the builtin editor */ +int use_internal_edit = 1; + +#ifdef HAVE_CHARSET +/* Numbers of (file I/O) and (input/display) codepages. -1 if not selected */ +int default_source_codepage = -1; +char *autodetect_codeset = NULL; +gboolean is_autodetect_codeset_enabled = FALSE; +#endif /* !HAVE_CHARSET */ + +/* If set, then print to the given file the last directory we were at */ +char *last_wd_string = NULL; + +mc_fhl_t *mc_filehighlight; + +/* Set when main loop should be terminated */ +int quit = 0; + +/* The user's shell */ +char *shell = NULL; + +/* The prompt */ +const char *mc_prompt = NULL; + +/* Set to TRUE to suppress printing the last directory */ +int print_last_revert = FALSE; + +/* index to record_macro_buf[], -1 if not recording a macro */ +int macro_index = -1; + +/* macro stuff */ +struct macro_action_t record_macro_buf[MAX_MACRO_LENGTH]; + +GArray *macros_list; + /*** file scope macro definitions ****************************************************************/ /* In order to use everywhere the same setup for the locale we use defines */ diff --git a/src/setup.h b/src/setup.h index ec4f6948b..f40be383f 100644 --- a/src/setup.h +++ b/src/setup.h @@ -16,6 +16,8 @@ /* TAB length for editor and viewer */ #define DEFAULT_TAB_SPACING 8 +#define MAX_MACRO_LENGTH 1024 + /*** enums ***************************************************************************************/ typedef enum @@ -54,6 +56,20 @@ typedef struct struct WPanel; +typedef struct macro_action_t +{ + unsigned long action; + int ch; +} macro_action_t; + +typedef struct macros_t +{ + int hotkey; + GArray *macro; +} macros_t; + +struct mc_fhl_struct; + /*** global variables defined in .c file *********************************************************/ /* global paremeters */ @@ -88,6 +104,34 @@ extern panels_options_t panels_options; extern panel_view_mode_t startup_left_mode; extern panel_view_mode_t startup_right_mode; extern gboolean boot_current_is_left; +extern int use_internal_view; +extern int use_internal_edit; + +#ifdef HAVE_CHARSET +extern int default_source_codepage; +extern char *autodetect_codeset; +extern gboolean is_autodetect_codeset_enabled; +#endif /* !HAVE_CHARSET */ + +/* If set, then print to the given file the last directory we were at */ +extern char *last_wd_string; + +extern int quit; +/* Set to TRUE to suppress printing the last directory */ +extern gboolean print_last_revert; + +extern struct mc_fhl_struct *mc_filehighlight; + +extern char *shell; +extern const char *mc_prompt; + +/* index to record_macro_buf[], -1 if not recording a macro */ +extern int macro_index; + +/* macro stuff */ +extern struct macro_action_t record_macro_buf[MAX_MACRO_LENGTH]; + +extern GArray *macros_list; /*** declarations of public functions ************************************************************/ diff --git a/src/subshell.c b/src/subshell.c index 7eefab554..077e7b586 100644 --- a/src/subshell.c +++ b/src/subshell.c @@ -65,6 +65,7 @@ #include "filemanager/midnight.h" /* current_panel */ #include "consaver/cons.saver.h" /* handle_console() */ +#include "setup.h" #include "subshell.h" /*** global variables ****************************************************************************/ diff --git a/src/vfs/extfs/extfs.c b/src/vfs/extfs/extfs.c index d3e356d85..f1a4bdf0d 100644 --- a/src/vfs/extfs/extfs.c +++ b/src/vfs/extfs/extfs.c @@ -58,7 +58,7 @@ #include "lib/util.h" #include "lib/widget.h" /* message() */ -#include "src/main.h" /* shell */ +#include "src/setup.h" /* shell */ #include "src/execute.h" /* For shell_execute */ #include "lib/vfs/vfs.h" diff --git a/src/viewer/display.c b/src/viewer/display.c index 92336c399..45381022d 100644 --- a/src/viewer/display.c +++ b/src/viewer/display.c @@ -49,7 +49,6 @@ #endif #include "src/setup.h" /* panels_options */ -#include "src/main.h" #include "src/keybind-defaults.h" #include "internal.h" diff --git a/src/viewer/lib.c b/src/viewer/lib.c index 8a029e7ca..7f20ce68b 100644 --- a/src/viewer/lib.c +++ b/src/viewer/lib.c @@ -48,7 +48,6 @@ #include "lib/charsets.h" #endif -#include "src/main.h" #ifdef HAVE_CHARSET #include "src/selcodepage.h" #endif diff --git a/src/viewer/mcviewer.c b/src/viewer/mcviewer.c index a9c7c25f1..b132ba858 100644 --- a/src/viewer/mcviewer.c +++ b/src/viewer/mcviewer.c @@ -46,8 +46,6 @@ #include "lib/util.h" /* load_file_position() */ #include "lib/widget.h" -#include "src/main.h" - #include "src/filemanager/layout.h" /* menubar_visible */ #include "src/filemanager/midnight.h" /* the_menubar */