mirror of
https://github.com/MidnightCommander/mc
synced 2024-12-22 12:32:40 +03:00
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 <slavazanko@gmail.com>
This commit is contained in:
parent
6d4c3828af
commit
80011ad7cb
@ -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 ****************************************************************/
|
||||
|
15
src/args.h
15
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);
|
||||
|
@ -36,7 +36,7 @@
|
||||
|
||||
#include "lib/vfs/vfs.h"
|
||||
|
||||
#include "main.h"
|
||||
#include "setup.h"
|
||||
#include "src/execute.h"
|
||||
|
||||
#include "clipboard.h"
|
||||
|
@ -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"
|
||||
|
@ -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"
|
||||
|
||||
|
@ -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
|
||||
|
@ -36,7 +36,6 @@
|
||||
#include "lib/charsets.h"
|
||||
#endif
|
||||
|
||||
#include "src/main.h"
|
||||
#include "src/history.h"
|
||||
|
||||
#include "src/editor/editwidget.h"
|
||||
|
@ -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"
|
||||
|
@ -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 */
|
||||
|
@ -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 */
|
||||
|
||||
|
@ -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 */
|
||||
|
@ -31,6 +31,7 @@
|
||||
|
||||
#include <config.h>
|
||||
|
||||
#include <pwd.h> /* for username in xterm title */
|
||||
#include <stdlib.h>
|
||||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
@ -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);
|
||||
}
|
||||
}
|
||||
|
||||
/* --------------------------------------------------------------------------------------------- */
|
||||
|
@ -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 */
|
||||
|
@ -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;
|
||||
|
@ -69,7 +69,6 @@
|
||||
#include "keybind-defaults.h"
|
||||
#include "keybind-defaults.h"
|
||||
#include "help.h"
|
||||
#include "main.h"
|
||||
|
||||
/*** global variables ****************************************************************************/
|
||||
|
||||
|
102
src/main.c
102
src/main.c
@ -35,11 +35,11 @@
|
||||
#include <ctype.h>
|
||||
#include <errno.h>
|
||||
#include <locale.h>
|
||||
#include <pwd.h> /* for username in xterm title */
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include <sys/wait.h>
|
||||
#include <pwd.h> /* for username in xterm title */
|
||||
#include <signal.h>
|
||||
|
||||
#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[])
|
||||
{
|
||||
|
71
src/main.h
71
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 */
|
||||
|
@ -38,7 +38,7 @@
|
||||
#include "lib/widget.h"
|
||||
#include "lib/charsets.h"
|
||||
|
||||
#include "main.h"
|
||||
#include "setup.h"
|
||||
|
||||
#include "selcodepage.h"
|
||||
|
||||
|
38
src/setup.c
38
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 */
|
||||
|
44
src/setup.h
44
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 ************************************************************/
|
||||
|
||||
|
@ -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 ****************************************************************************/
|
||||
|
@ -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"
|
||||
|
@ -49,7 +49,6 @@
|
||||
#endif
|
||||
|
||||
#include "src/setup.h" /* panels_options */
|
||||
#include "src/main.h"
|
||||
#include "src/keybind-defaults.h"
|
||||
|
||||
#include "internal.h"
|
||||
|
@ -48,7 +48,6 @@
|
||||
#include "lib/charsets.h"
|
||||
#endif
|
||||
|
||||
#include "src/main.h"
|
||||
#ifdef HAVE_CHARSET
|
||||
#include "src/selcodepage.h"
|
||||
#endif
|
||||
|
@ -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 */
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user