Skip to content

Commit

Permalink
Code cleanup after runing splint on src/main.c file
Browse files Browse the repository at this point in the history
Signed-off-by: Slava Zanko <[email protected]>
  • Loading branch information
slavaz committed Oct 17, 2011
1 parent 1e9a3f5 commit a1e34b8
Show file tree
Hide file tree
Showing 17 changed files with 95 additions and 88 deletions.
4 changes: 2 additions & 2 deletions lib/charsets.h
Original file line number Diff line number Diff line change
Expand Up @@ -93,15 +93,15 @@ convert_to_display_c (int c)
{
if (c < 0 || c >= 256)
return c;
return conv_displ[c];
return (int) conv_displ[c];
}

static inline int
convert_from_input_c (int c)
{
if (c < 0 || c >= 256)
return c;
return conv_input[c];
return (int) conv_input[c];
}

#endif /* HAVE_CHARSET */
Expand Down
1 change: 1 addition & 0 deletions lib/fs.h
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,7 @@ static inline void
compute_namelen (struct dirent *dent __attribute__ ((unused)))
{
#ifdef DIRENT_LENGTH_COMPUTED
(void) dent;
return;
#else
dent->d_namlen = strlen (dent);
Expand Down
1 change: 1 addition & 0 deletions lib/global.c
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,7 @@ mc_global_t mc_global = {
.disable_colors = FALSE,
.ugly_line_drawing = FALSE,
.old_mouse = FALSE,
.alternate_plus_minus = FALSE,
},

.vfs =
Expand Down
5 changes: 5 additions & 0 deletions lib/global.h
Original file line number Diff line number Diff line change
Expand Up @@ -258,6 +258,11 @@ typedef struct

/* Tries to use old highlight mouse tracking */
gboolean old_mouse;

/* If true, use + and \ keys normally and select/unselect do if M-+ / M-\.
and M-- and keypad + / - */
gboolean alternate_plus_minus;

} tty;

struct
Expand Down
10 changes: 3 additions & 7 deletions lib/tty/key.c
Original file line number Diff line number Diff line change
Expand Up @@ -75,10 +75,6 @@

/*** global variables ****************************************************************************/

/* If true, use + and \ keys normally and select/unselect do if M-+ / M-\.
and M-- and keypad + / - */
int alternate_plus_minus = 0;

int mou_auto_repeat = 100;
int double_click_speed = 250;
int old_esc_mode = 0;
Expand Down Expand Up @@ -1058,7 +1054,7 @@ correct_key_code (int code)
mod &= ~KEY_M_SHIFT;
}

if (!alternate_plus_minus)
if (!mc_global.tty.alternate_plus_minus)
switch (c)
{
case KEY_KP_ADD:
Expand Down Expand Up @@ -2102,7 +2098,7 @@ learn_key (void)
void
numeric_keypad_mode (void)
{
if (mc_global.tty.console_flag || mc_global.tty.xterm_flag)
if (mc_global.tty.console_flag != '\0' || mc_global.tty.xterm_flag)
{
fputs (ESC_STR ">", stdout);
fflush (stdout);
Expand All @@ -2114,7 +2110,7 @@ numeric_keypad_mode (void)
void
application_keypad_mode (void)
{
if (mc_global.tty.console_flag || mc_global.tty.xterm_flag)
if (mc_global.tty.console_flag != '\0' || mc_global.tty.xterm_flag)
{
fputs (ESC_STR "=", stdout);
fflush (stdout);
Expand Down
3 changes: 1 addition & 2 deletions lib/tty/key.h
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,6 @@ extern const key_code_name_t key_name_conv_tab[];

extern int old_esc_mode_timeout;

extern int alternate_plus_minus;
extern int double_click_speed;
extern int old_esc_mode;
extern int use_8th_bit_as_meta;
Expand Down Expand Up @@ -104,7 +103,7 @@ void application_keypad_mode (void);
static inline gboolean
is_abort_char (int c)
{
return ((c == ESC_CHAR) || (c == KEY_F (10)));
return ((c == (int) ESC_CHAR) || (c == (int) KEY_F (10)));
}

#endif /* MC_KEY_H */
32 changes: 18 additions & 14 deletions src/cons.handler.c
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ show_console_contents_linux (int starty, unsigned char begin_line, unsigned char
ssize_t ret;

/* Is tty console? */
if (!mc_global.tty.console_flag)
if (mc_global.tty.console_flag == '\0')
return;
/* Paranoid: Is the cons.saver still running? */
if (cons_saver_pid < 1 || kill (cons_saver_pid, SIGCONT))
Expand Down Expand Up @@ -128,7 +128,7 @@ show_console_contents_linux (int starty, unsigned char begin_line, unsigned char
/* --------------------------------------------------------------------------------------------- */

static void
handle_console_linux (unsigned char action)
handle_console_linux (console_action_t action)
{
char *tty_name;
char *mc_conssaver;
Expand Down Expand Up @@ -166,7 +166,7 @@ handle_console_linux (unsigned char action)
status = close (pipefd2[1]);
/* Was the child successful? */
status = read (pipefd2[0], &mc_global.tty.console_flag, 1);
if (!mc_global.tty.console_flag)
if (mc_global.tty.console_flag == '\0')
{
pid_t ret;
status = close (pipefd1[1]);
Expand Down Expand Up @@ -216,7 +216,7 @@ handle_console_linux (unsigned char action)
case CONSOLE_SAVE:
case CONSOLE_RESTORE:
/* Is tty console? */
if (!mc_global.tty.console_flag)
if (mc_global.tty.console_flag == '\0')
return;
/* Paranoid: Is the cons.saver still running? */
if (cons_saver_pid < 1 || kill (cons_saver_pid, SIGCONT))
Expand All @@ -232,7 +232,7 @@ handle_console_linux (unsigned char action)
/* Wait the console handler to do its job */
status = read (pipefd2[0], &mc_global.tty.console_flag, 1);
}
if (action == CONSOLE_DONE || !mc_global.tty.console_flag)
if (action == CONSOLE_DONE || mc_global.tty.console_flag == '\0')
{
/* We are done -> Let's clean up */
pid_t ret;
Expand All @@ -242,6 +242,8 @@ handle_console_linux (unsigned char action)
mc_global.tty.console_flag = '\0';
}
break;
default:
break;
}
}

Expand All @@ -256,7 +258,7 @@ handle_console_linux (unsigned char action)
static void
console_init (void)
{
if (mc_global.tty.console_flag)
if (mc_global.tty.console_flag != '\0')
return;

screen_info.size = sizeof (screen_info);
Expand Down Expand Up @@ -297,7 +299,7 @@ console_restore (void)
{
int i, last;

if (!mc_global.tty.console_flag)
if (mc_global.tty.console_flag == '\0')
return;

cursor_to (0, 0);
Expand All @@ -321,7 +323,7 @@ console_restore (void)
static void
console_shutdown (void)
{
if (!mc_global.tty.console_flag)
if (mc_global.tty.console_flag == '\0')
return;

g_free (screen_shot.buf);
Expand All @@ -338,7 +340,7 @@ console_save (void)
scrmap_t map;
scrmap_t revmap;

if (!mc_global.tty.console_flag)
if (mc_global.tty.console_flag == '\0')
return;

/* screen_info.size is already set in console_init() */
Expand Down Expand Up @@ -376,8 +378,8 @@ console_save (void)
for (i = 0; i < screen_shot.xsize * screen_shot.ysize; i++)
{
screen_shot.buf[i] =
(screen_shot.buf[i] & 0xff00) | (unsigned char) revmap.
scrmap[screen_shot.buf[i] & 0xff];
(screen_shot.buf[i] & 0xff00) | (unsigned char) revmap.scrmap[screen_shot.
buf[i] & 0xff];
}
}

Expand All @@ -389,7 +391,7 @@ show_console_contents_freebsd (int starty, unsigned char begin_line, unsigned ch
int col, line;
char c;

if (!mc_global.tty.console_flag)
if (mc_global.tty.console_flag == '\0')
return;

for (line = begin_line; line <= end_line; line++)
Expand All @@ -406,7 +408,7 @@ show_console_contents_freebsd (int starty, unsigned char begin_line, unsigned ch
/* --------------------------------------------------------------------------------------------- */

static void
handle_console_freebsd (unsigned char action)
handle_console_freebsd (console_action_t action)
{
switch (action)
{
Expand All @@ -425,6 +427,8 @@ handle_console_freebsd (unsigned char action)
case CONSOLE_RESTORE:
console_restore ();
break;
default:
break;
}
}
#endif /* __FreeBSD__ */
Expand Down Expand Up @@ -455,7 +459,7 @@ show_console_contents (int starty, unsigned char begin_line, unsigned char end_l
/* --------------------------------------------------------------------------------------------- */

void
handle_console (unsigned char action)
handle_console (console_action_t action)
{
(void) action;

Expand Down
6 changes: 3 additions & 3 deletions src/consaver/cons.saver.h
Original file line number Diff line number Diff line change
Expand Up @@ -16,14 +16,14 @@

/*** enums ***************************************************************************************/

enum
typedef enum
{
CONSOLE_INIT = '1',
CONSOLE_DONE,
CONSOLE_SAVE,
CONSOLE_RESTORE,
CONSOLE_CONTENTS
};
} console_action_t;

/*** structures declarations (and typedefs of structures)*****************************************/

Expand All @@ -39,7 +39,7 @@ extern int cons_saver_pid;
#ifndef LINUX_CONS_SAVER_C
/* Used only in mc, not in cons.saver */
void show_console_contents (int starty, unsigned char begin_line, unsigned char end_line);
void handle_console (unsigned char action);
void handle_console (console_action_t action);
#endif /* !LINUX_CONS_SAVER_C */

/*** inline functions ****************************************************************************/
Expand Down
26 changes: 13 additions & 13 deletions src/execute.c
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ edition_post_exec (void)
tty_raw_mode ();
channels_up ();
enable_mouse ();
if (alternate_plus_minus)
if (mc_global.tty.alternate_plus_minus)
application_keypad_mode ();
}

Expand All @@ -81,7 +81,7 @@ edition_pre_exec (void)
clr_scr ();
else
{
if (!(mc_global.tty.console_flag || mc_global.tty.xterm_flag))
if (!(mc_global.tty.console_flag != '\0' || mc_global.tty.xterm_flag))
printf ("\n\n");
}

Expand Down Expand Up @@ -135,7 +135,7 @@ do_execute (const char *lc_shell, const char *command, int flags)
if (mc_global.mc_run_mode == MC_RUN_FULL)
save_cwds_stat ();
pre_exec ();
if (mc_global.tty.console_flag)
if (mc_global.tty.console_flag != '\0')
handle_console (CONSOLE_RESTORE);

if (!mc_global.tty.use_subshell && command && !(flags & EXECUTE_INTERNAL))
Expand All @@ -159,7 +159,7 @@ do_execute (const char *lc_shell, const char *command, int flags)
{
if ((pause_after_run == pause_always
|| (pause_after_run == pause_on_dumb_terminals && !mc_global.tty.xterm_flag
&& !mc_global.tty.console_flag)) && quit == 0
&& mc_global.tty.console_flag == '\0')) && quit == 0
#ifdef HAVE_SUBSHELL_SUPPORT
&& subshell_state != RUNNING_COMMAND
#endif /* HAVE_SUBSHELL_SUPPORT */
Expand All @@ -172,7 +172,7 @@ do_execute (const char *lc_shell, const char *command, int flags)
printf ("\r\n");
fflush (stdout);
}
if (mc_global.tty.console_flag)
if (mc_global.tty.console_flag != '\0')
{
if (output_lines && mc_global.keybar_visible)
{
Expand All @@ -182,7 +182,7 @@ do_execute (const char *lc_shell, const char *command, int flags)
}
}

if (mc_global.tty.console_flag)
if (mc_global.tty.console_flag != '\0')
handle_console (CONSOLE_SAVE);
edition_post_exec ();

Expand Down Expand Up @@ -215,7 +215,7 @@ do_suspend_cmd (void)
{
pre_exec ();

if (mc_global.tty.console_flag && !mc_global.tty.use_subshell)
if (mc_global.tty.console_flag != '\0' && !mc_global.tty.use_subshell)
handle_console (CONSOLE_RESTORE);

#ifdef SIGTSTP
Expand All @@ -234,7 +234,7 @@ do_suspend_cmd (void)
}
#endif /* SIGTSTP */

if (mc_global.tty.console_flag && !mc_global.tty.use_subshell)
if (mc_global.tty.console_flag != '\0' && !mc_global.tty.use_subshell)
handle_console (CONSOLE_SAVE);

edition_post_exec ();
Expand Down Expand Up @@ -312,7 +312,7 @@ toggle_panels (void)
disable_mouse ();
if (clear_before_exec)
clr_scr ();
if (alternate_plus_minus)
if (mc_global.tty.alternate_plus_minus)
numeric_keypad_mode ();
#ifndef HAVE_SLANG
/* With slang we don't want any of this, since there
Expand All @@ -325,7 +325,7 @@ toggle_panels (void)
tty_reset_screen ();
do_exit_ca_mode ();
tty_raw_mode ();
if (mc_global.tty.console_flag)
if (mc_global.tty.console_flag != '\0')
handle_console (CONSOLE_RESTORE);

#ifdef HAVE_SUBSHELL_SUPPORT
Expand All @@ -348,7 +348,7 @@ toggle_panels (void)
get_key_code (0);
}

if (mc_global.tty.console_flag)
if (mc_global.tty.console_flag != '\0')
handle_console (CONSOLE_SAVE);

do_enter_ca_mode ();
Expand All @@ -374,7 +374,7 @@ toggle_panels (void)

enable_mouse ();
channels_up ();
if (alternate_plus_minus)
if (mc_global.tty.alternate_plus_minus)
application_keypad_mode ();

#ifdef HAVE_SUBSHELL_SUPPORT
Expand All @@ -383,7 +383,7 @@ toggle_panels (void)
load_prompt (0, NULL);
if (new_dir)
do_possible_cd (new_dir);
if (mc_global.tty.console_flag && output_lines)
if (mc_global.tty.console_flag != '\0' && output_lines)
show_console_contents (output_start_y,
LINES - mc_global.keybar_visible - output_lines -
1, LINES - mc_global.keybar_visible - 1);
Expand Down
4 changes: 2 additions & 2 deletions src/filemanager/cmd.c
Original file line number Diff line number Diff line change
Expand Up @@ -1268,8 +1268,8 @@ view_other_cmd (void)
{
static int message_flag = TRUE;

if (!mc_global.tty.xterm_flag && !mc_global.tty.console_flag && !mc_global.tty.use_subshell
&& !output_starts_shell)
if (!mc_global.tty.xterm_flag && mc_global.tty.console_flag == '\0'
&& !mc_global.tty.use_subshell && !output_starts_shell)
{
if (message_flag)
message (D_ERROR, MSG_ERROR,
Expand Down
Loading

0 comments on commit a1e34b8

Please sign in to comment.