From 490ecb86b531aab803c175e6f70e150eacf6d24d Mon Sep 17 00:00:00 2001 From: Andrew Borodin Date: Sun, 10 Apr 2011 14:19:44 +0400 Subject: [PATCH] Get rid of some function forward declarations. Signed-off-by: Andrew Borodin --- lib/widget/dialog.c | 3 - src/filemanager/file.c | 374 +++++++++++++++++++++++------------------------- src/filemanager/panel.c | 7 - src/subshell.c | 135 ++++++++--------- 4 files changed, 243 insertions(+), 276 deletions(-) diff --git a/lib/widget/dialog.c b/lib/widget/dialog.c index 873077483..026c03654 100644 --- a/lib/widget/dialog.c +++ b/lib/widget/dialog.c @@ -79,9 +79,6 @@ typedef enum /*** file scope variables ************************************************************************/ /*** file scope functions ************************************************************************/ -/* --------------------------------------------------------------------------------------------- */ - -static void dlg_broadcast_msg_to (Dlg_head * h, widget_msg_t msg, gboolean reverse, int flags); /* --------------------------------------------------------------------------------------------- */ /** diff --git a/src/filemanager/file.c b/src/filemanager/file.c index 6d20ed0f2..613d09612 100644 --- a/src/filemanager/file.c +++ b/src/filemanager/file.c @@ -170,12 +170,12 @@ static struct link *linklist = NULL; static struct link *erase_list; /* - * In copy_dir_dir we use two additional single linked lists: The first - - * variable name `parent_dirs' - holds information about already copied - * directories and is used to detect cyclic symbolic links. - * The second (`dest_dirs' below) holds information about just created - * target directories and is used to detect when an directory is copied - * into itself (we don't want to copy infinitly). + * In copy_dir_dir we use two additional single linked lists: The first - + * variable name `parent_dirs' - holds information about already copied + * directories and is used to detect cyclic symbolic links. + * The second (`dest_dirs' below) holds information about just created + * target directories and is used to detect when an directory is copied + * into itself (we don't want to copy infinitly). * Both lists don't use the linkcount and name structure members of struct * link. */ @@ -186,17 +186,6 @@ static FileProgressStatus transform_error = FILE_CONT; /*** file scope functions ************************************************************************/ /* --------------------------------------------------------------------------------------------- */ -static FileProgressStatus query_replace (FileOpContext * ctx, const char *destname, - struct stat *_s_stat, struct stat *_d_stat); -static FileProgressStatus query_recursive (FileOpContext * ctx, const char *s); -static FileProgressStatus do_file_error (const char *str); -static FileProgressStatus erase_dir_iff_empty (FileOpContext * ctx, const char *s); -static FileProgressStatus erase_file (FileOpTotalContext * tctx, FileOpContext * ctx, - const char *s, gboolean is_toplevel_file); -static FileProgressStatus files_error (const char *format, const char *file1, const char *file2); - -/* --------------------------------------------------------------------------------------------- */ - static char * transform_source (FileOpContext * ctx, const char *source) { @@ -482,6 +471,180 @@ warn_same_file (const char *fmt, const char *a, const char *b) } /* --------------------------------------------------------------------------------------------- */ +/* {{{ Query/status report routines */ + +static FileProgressStatus +real_do_file_error (enum OperationMode mode, const char *error) +{ + int result; + const char *msg; + + msg = mode == Foreground ? MSG_ERROR : _("Background process error"); + result = query_dialog (msg, error, D_ERROR, 3, _("&Skip"), _("&Retry"), _("&Abort")); + + switch (result) + { + case 0: + do_refresh (); + return FILE_SKIP; + + case 1: + do_refresh (); + return FILE_RETRY; + + case 2: + default: + return FILE_ABORT; + } +} + +/* --------------------------------------------------------------------------------------------- */ + +static FileProgressStatus +real_query_recursive (FileOpContext * ctx, enum OperationMode mode, const char *s) +{ + gchar *text; + + if (ctx->recursive_result < RECURSIVE_ALWAYS) + { + const char *msg = mode == Foreground + ? _("\nDirectory not empty.\nDelete it recursively?") + : _("\nBackground process: Directory not empty.\nDelete it recursively?"); + text = g_strconcat (_("Delete:"), " ", path_trunc (s, 30), (char *) NULL); + + if (safe_delete) + query_set_sel (1); + + ctx->recursive_result = + (FileCopyMode) query_dialog (text, msg, D_ERROR, 5, + _("&Yes"), _("&No"), _("A&ll"), _("Non&e"), _("&Abort")); + + if (ctx->recursive_result != RECURSIVE_ABORT) + do_refresh (); + g_free (text); + } + + switch (ctx->recursive_result) + { + case RECURSIVE_YES: + case RECURSIVE_ALWAYS: + return FILE_CONT; + + case RECURSIVE_NO: + case RECURSIVE_NEVER: + return FILE_SKIP; + + case RECURSIVE_ABORT: + default: + return FILE_ABORT; + } +} + +/* --------------------------------------------------------------------------------------------- */ + +#ifdef WITH_BACKGROUND +static FileProgressStatus +do_file_error (const char *str) +{ + union + { + void *p; + FileProgressStatus (*f) (enum OperationMode, const char *); + } pntr; + pntr.f = real_do_file_error; + + if (we_are_background) + return parent_call (pntr.p, NULL, 1, strlen (str), str); + else + return real_do_file_error (Foreground, str); +} + +/* --------------------------------------------------------------------------------------------- */ + +static FileProgressStatus +query_recursive (FileOpContext * ctx, const char *s) +{ + union + { + void *p; + FileProgressStatus (*f) (FileOpContext *, enum OperationMode, const char *); + } pntr; + pntr.f = real_query_recursive; + + if (we_are_background) + return parent_call (pntr.p, ctx, 1, strlen (s), s); + else + return real_query_recursive (ctx, Foreground, s); +} + +/* --------------------------------------------------------------------------------------------- */ + +static FileProgressStatus +query_replace (FileOpContext * ctx, const char *destname, struct stat *_s_stat, + struct stat *_d_stat) +{ + union + { + void *p; + FileProgressStatus (*f) (FileOpContext *, enum OperationMode, const char *, + struct stat *, struct stat *); + } pntr; + pntr.f = file_progress_real_query_replace; + + if (we_are_background) + return parent_call (pntr.p, ctx, 3, strlen (destname), destname, + sizeof (struct stat), _s_stat, sizeof (struct stat), _d_stat); + else + return file_progress_real_query_replace (ctx, Foreground, destname, _s_stat, _d_stat); +} + +#else +/* --------------------------------------------------------------------------------------------- */ + +static FileProgressStatus +do_file_error (const char *str) +{ + return real_do_file_error (Foreground, str); +} + +/* --------------------------------------------------------------------------------------------- */ + +static FileProgressStatus +query_recursive (FileOpContext * ctx, const char *s) +{ + return real_query_recursive (ctx, Foreground, s); +} + +/* --------------------------------------------------------------------------------------------- */ + +static FileProgressStatus +query_replace (FileOpContext * ctx, const char *destname, struct stat *_s_stat, + struct stat *_d_stat) +{ + return file_progress_real_query_replace (ctx, Foreground, destname, _s_stat, _d_stat); +} + +#endif /* !WITH_BACKGROUND */ + +/* --------------------------------------------------------------------------------------------- */ +/** Report error with two files */ + +static FileProgressStatus +files_error (const char *format, const char *file1, const char *file2) +{ + char buf[BUF_MEDIUM]; + char *nfile1 = g_strdup (path_trunc (file1, 15)); + char *nfile2 = g_strdup (path_trunc (file2, 15)); + + g_snprintf (buf, sizeof (buf), format, nfile1, nfile2, unix_error_string (errno)); + + g_free (nfile1); + g_free (nfile2); + + return do_file_error (buf); +} + +/* --------------------------------------------------------------------------------------------- */ static void copy_file_file_display_progress (FileOpTotalContext * tctx, FileOpContext * ctx, @@ -537,7 +700,6 @@ copy_file_file_display_progress (FileOpTotalContext * tctx, FileOpContext * ctx, /* --------------------------------------------------------------------------------------------- */ - /* {{{ Move routines */ static FileProgressStatus move_file_file (FileOpTotalContext * tctx, FileOpContext * ctx, const char *s, const char *d) @@ -1057,182 +1219,6 @@ end_bg_process (FileOpContext * ctx, enum OperationMode mode) return 1; } #endif -/* }}} */ - -/* --------------------------------------------------------------------------------------------- */ -/* {{{ Query/status report routines */ - -static FileProgressStatus -real_do_file_error (enum OperationMode mode, const char *error) -{ - int result; - const char *msg; - - msg = mode == Foreground ? MSG_ERROR : _("Background process error"); - result = query_dialog (msg, error, D_ERROR, 3, _("&Skip"), _("&Retry"), _("&Abort")); - - switch (result) - { - case 0: - do_refresh (); - return FILE_SKIP; - - case 1: - do_refresh (); - return FILE_RETRY; - - case 2: - default: - return FILE_ABORT; - } -} - -/* --------------------------------------------------------------------------------------------- */ -/** Report error with two files */ - -static FileProgressStatus -files_error (const char *format, const char *file1, const char *file2) -{ - char buf[BUF_MEDIUM]; - char *nfile1 = g_strdup (path_trunc (file1, 15)); - char *nfile2 = g_strdup (path_trunc (file2, 15)); - - g_snprintf (buf, sizeof (buf), format, nfile1, nfile2, unix_error_string (errno)); - - g_free (nfile1); - g_free (nfile2); - - return do_file_error (buf); -} - -/* --------------------------------------------------------------------------------------------- */ - -static FileProgressStatus -real_query_recursive (FileOpContext * ctx, enum OperationMode mode, const char *s) -{ - gchar *text; - - if (ctx->recursive_result < RECURSIVE_ALWAYS) - { - const char *msg = mode == Foreground - ? _("\nDirectory not empty.\nDelete it recursively?") - : _("\nBackground process: Directory not empty.\nDelete it recursively?"); - text = g_strconcat (_("Delete:"), " ", path_trunc (s, 30), (char *) NULL); - - if (safe_delete) - query_set_sel (1); - - ctx->recursive_result = - (FileCopyMode) query_dialog (text, msg, D_ERROR, 5, - _("&Yes"), _("&No"), _("A&ll"), _("Non&e"), _("&Abort")); - - if (ctx->recursive_result != RECURSIVE_ABORT) - do_refresh (); - g_free (text); - } - - switch (ctx->recursive_result) - { - case RECURSIVE_YES: - case RECURSIVE_ALWAYS: - return FILE_CONT; - - case RECURSIVE_NO: - case RECURSIVE_NEVER: - return FILE_SKIP; - - case RECURSIVE_ABORT: - default: - return FILE_ABORT; - } -} - -/* --------------------------------------------------------------------------------------------- */ - -#ifdef WITH_BACKGROUND -static FileProgressStatus -do_file_error (const char *str) -{ - union - { - void *p; - FileProgressStatus (*f) (enum OperationMode, const char *); - } pntr; - pntr.f = real_do_file_error; - - if (we_are_background) - return parent_call (pntr.p, NULL, 1, strlen (str), str); - else - return real_do_file_error (Foreground, str); -} - -/* --------------------------------------------------------------------------------------------- */ - -static FileProgressStatus -query_recursive (FileOpContext * ctx, const char *s) -{ - union - { - void *p; - FileProgressStatus (*f) (FileOpContext *, enum OperationMode, const char *); - } pntr; - pntr.f = real_query_recursive; - - if (we_are_background) - return parent_call (pntr.p, ctx, 1, strlen (s), s); - else - return real_query_recursive (ctx, Foreground, s); -} - -/* --------------------------------------------------------------------------------------------- */ - -static FileProgressStatus -query_replace (FileOpContext * ctx, const char *destname, struct stat *_s_stat, - struct stat *_d_stat) -{ - union - { - void *p; - FileProgressStatus (*f) (FileOpContext *, enum OperationMode, const char *, - struct stat *, struct stat *); - } pntr; - pntr.f = file_progress_real_query_replace; - - if (we_are_background) - return parent_call (pntr.p, ctx, 3, strlen (destname), destname, - sizeof (struct stat), _s_stat, sizeof (struct stat), _d_stat); - else - return file_progress_real_query_replace (ctx, Foreground, destname, _s_stat, _d_stat); -} - -#else -/* --------------------------------------------------------------------------------------------- */ - -static FileProgressStatus -do_file_error (const char *str) -{ - return real_do_file_error (Foreground, str); -} - -/* --------------------------------------------------------------------------------------------- */ - -static FileProgressStatus -query_recursive (FileOpContext * ctx, const char *s) -{ - return real_query_recursive (ctx, Foreground, s); -} - -/* --------------------------------------------------------------------------------------------- */ - -static FileProgressStatus -query_replace (FileOpContext * ctx, const char *destname, struct stat *_s_stat, - struct stat *_d_stat) -{ - return file_progress_real_query_replace (ctx, Foreground, destname, _s_stat, _d_stat); -} - -#endif /* !WITH_BACKGROUND */ -/* }}} */ /* --------------------------------------------------------------------------------------------- */ /*** public functions ****************************************************************************/ diff --git a/src/filemanager/panel.c b/src/filemanager/panel.c index fa3cd99e3..d660b9729 100644 --- a/src/filemanager/panel.c +++ b/src/filemanager/panel.c @@ -342,12 +342,6 @@ typedef struct format_e /*** file scope variables ************************************************************************/ -static cb_ret_t panel_callback (Widget *, widget_msg_t msg, int parm); -static int panel_event (Gpm_Event * event, void *); -static void paint_frame (WPanel * panel); -static const char *panel_format (WPanel * panel); -static const char *mini_status_format (WPanel * panel); - static char *panel_sort_up_sign = NULL; static char *panel_sort_down_sign = NULL; @@ -1635,7 +1629,6 @@ panel_format (WPanel * panel) { switch (panel->list_type) { - case list_long: return "full perm space nlink space owner space group space size space mtime space name"; diff --git a/src/subshell.c b/src/subshell.c index 7efe891b4..3ab7f8b9e 100644 --- a/src/subshell.c +++ b/src/subshell.c @@ -185,14 +185,6 @@ static int prompt_pos; /*** file scope functions ************************************************************************/ -/* --------------------------------------------------------------------------------------------- */ - -static void init_raw_mode (void); -static gboolean feed_subshell (int how, int fail_on_error); -static void synchronize (void); -static int pty_open_master (char *pty_name); -static int pty_open_slave (const char *pty_name); -static int resize_tty (int fd); /* --------------------------------------------------------------------------------------------- */ /** @@ -225,6 +217,25 @@ write_all (int fd, const void *buf, size_t count) } /* --------------------------------------------------------------------------------------------- */ + +/** Resize given terminal using TIOCSWINSZ, return ioctl() result */ +static int +resize_tty (int fd) +{ +#if defined TIOCSWINSZ + struct winsize tty_size; + + tty_size.ws_row = LINES; + tty_size.ws_col = COLS; + tty_size.ws_xpixel = tty_size.ws_ypixel = 0; + + return ioctl (fd, TIOCSWINSZ, &tty_size); +#else + return 0; +#endif +} + +/* --------------------------------------------------------------------------------------------- */ /** * Prepare child process to running the shell and run it. * @@ -404,7 +415,7 @@ check_sid (void) /* --------------------------------------------------------------------------------------------- */ static void -init_raw_mode () +init_raw_mode (void) { static int initialized = 0; @@ -430,6 +441,44 @@ init_raw_mode () } /* --------------------------------------------------------------------------------------------- */ +/** + * Wait until the subshell dies or stops. If it stops, make it resume. + * Possibly modifies the globals `subshell_alive' and `subshell_stopped' + */ + +static void +synchronize (void) +{ + sigset_t sigchld_mask, old_mask; + + sigemptyset (&sigchld_mask); + sigaddset (&sigchld_mask, SIGCHLD); + sigprocmask (SIG_BLOCK, &sigchld_mask, &old_mask); + + /* + * SIGCHLD should not be blocked, but we unblock it just in case. + * This is known to be useful for cygwin 1.3.12 and older. + */ + sigdelset (&old_mask, SIGCHLD); + + /* Wait until the subshell has stopped */ + while (subshell_alive && !subshell_stopped) + sigsuspend (&old_mask); + + if (subshell_state != ACTIVE) + { + /* Discard all remaining data from stdin to the subshell */ + tcflush (subshell_pty_slave, TCIFLUSH); + } + + subshell_stopped = FALSE; + kill (subshell_pid, SIGCONT); + + sigprocmask (SIG_SETMASK, &old_mask, NULL); + /* We can't do any better without modifying the shell(s) */ +} + +/* --------------------------------------------------------------------------------------------- */ /** Feed the subshell our keyboard input until it says it's finished */ static gboolean @@ -558,49 +607,11 @@ feed_subshell (int how, int fail_on_error) } /* --------------------------------------------------------------------------------------------- */ -/** - * Wait until the subshell dies or stops. If it stops, make it resume. - * Possibly modifies the globals `subshell_alive' and `subshell_stopped' - */ - -static void -synchronize (void) -{ - sigset_t sigchld_mask, old_mask; - - sigemptyset (&sigchld_mask); - sigaddset (&sigchld_mask, SIGCHLD); - sigprocmask (SIG_BLOCK, &sigchld_mask, &old_mask); - - /* - * SIGCHLD should not be blocked, but we unblock it just in case. - * This is known to be useful for cygwin 1.3.12 and older. - */ - sigdelset (&old_mask, SIGCHLD); - - /* Wait until the subshell has stopped */ - while (subshell_alive && !subshell_stopped) - sigsuspend (&old_mask); - - if (subshell_state != ACTIVE) - { - /* Discard all remaining data from stdin to the subshell */ - tcflush (subshell_pty_slave, TCIFLUSH); - } - - subshell_stopped = FALSE; - kill (subshell_pid, SIGCONT); - - sigprocmask (SIG_SETMASK, &old_mask, NULL); - /* We can't do any better without modifying the shell(s) */ -} - /* pty opening functions */ #ifdef HAVE_GRANTPT /* System V version of pty_open_master */ - static int pty_open_master (char *pty_name) { @@ -635,8 +646,8 @@ pty_open_master (char *pty_name) } /* --------------------------------------------------------------------------------------------- */ -/** System V version of pty_open_slave */ +/** System V version of pty_open_slave */ static int pty_open_slave (const char *pty_name) { @@ -688,6 +699,7 @@ pty_open_slave (const char *pty_name) #else /* !HAVE_GRANTPT */ /* --------------------------------------------------------------------------------------------- */ + /** BSD version of pty_open_master */ static int pty_open_master (char *pty_name) @@ -725,8 +737,8 @@ pty_open_master (char *pty_name) } /* --------------------------------------------------------------------------------------------- */ -/** BSD version of pty_open_slave */ +/** BSD version of pty_open_slave */ static int pty_open_slave (const char *pty_name) { @@ -1043,34 +1055,13 @@ do_update_prompt (void) } /* --------------------------------------------------------------------------------------------- */ - -/** Resize given terminal using TIOCSWINSZ, return ioctl() result */ -static int -resize_tty (int fd) -{ -#if defined TIOCSWINSZ - struct winsize tty_size; - - tty_size.ws_row = LINES; - tty_size.ws_col = COLS; - tty_size.ws_xpixel = tty_size.ws_ypixel = 0; - - return ioctl (fd, TIOCSWINSZ, &tty_size); -#else - return 0; -#endif -} - -/* --------------------------------------------------------------------------------------------- */ /** Resize subshell_pty */ void resize_subshell (void) { - if (use_subshell == 0) - return; - - resize_tty (subshell_pty); + if (use_subshell != 0) + resize_tty (subshell_pty); } /* --------------------------------------------------------------------------------------------- */ -- 2.11.4.GIT