From f050f5e68686ff3cadafddf4166f061298be1c0b Mon Sep 17 00:00:00 2001 From: Sergei Trofimovich Date: Wed, 15 Jul 2009 21:53:13 +0300 Subject: [PATCH] fixed compiler hints: -Wwrite-strings option helped a lot Some crufty ugly APIs (slang stuff, putenv) now have explicit (char*) casts. Signed-off-by: Sergei Trofimovich --- src/cmd.c | 2 +- src/color.c | 4 ++-- src/command.c | 12 +++++++----- src/cons.saver.c | 3 ++- src/execute.c | 2 +- src/file.c | 2 +- src/search/regex.c | 4 ++-- src/search/search.h | 2 +- src/slint.c | 10 +++++----- src/subshell.c | 4 ++-- 10 files changed, 24 insertions(+), 21 deletions(-) diff --git a/src/cmd.c b/src/cmd.c index 3aee491f4..d2cfc3a79 100644 --- a/src/cmd.c +++ b/src/cmd.c @@ -376,7 +376,7 @@ void mkdir_cmd (void) { char *dir, *absdir; - char *name = ""; + const char *name = ""; /* If 'on' then automatically fills name with current selected item name */ if (auto_fill_mkdir_name) diff --git a/src/color.c b/src/color.c index 99811d882..a4c9f1de1 100644 --- a/src/color.c +++ b/src/color.c @@ -332,7 +332,7 @@ void init_colors (void) * Hopefully, future versions of S-Lang will * document this feature. */ - SLtt_set_color (DEFAULT_COLOR_INDEX, NULL, "default", "default"); + SLtt_set_color (DEFAULT_COLOR_INDEX, NULL, (char*)"default", (char*)"default"); #else /* Use default terminal colors */ mc_init_pair (DEFAULT_COLOR_INDEX, -1, -1); @@ -384,7 +384,7 @@ mc_init_pair (int index, CTYPE foreground, CTYPE background) if (!foreground) foreground = "default"; - SLtt_set_color (index, "", (char *) foreground, (char *) background); + SLtt_set_color (index, (char*)"", (char *) foreground, (char *) background); if (index > max_index) max_index = index; } diff --git a/src/command.c b/src/command.c index 8b0f27422..c24a92c16 100644 --- a/src/command.c +++ b/src/command.c @@ -146,9 +146,10 @@ examine_cd (const char *_path) } /* Execute the cd command on the command line */ -void do_cd_command (char *cmd) +void do_cd_command (char * orig_cmd) { int len; + const char * cmd; /* Any final whitespace should be removed here (to see why, try "cd fred "). */ @@ -156,13 +157,14 @@ void do_cd_command (char *cmd) that way, we can cd into hidden directories */ /* FIXME: what about interpreting quoted strings like the shell. so one could type "cd M-a " and it would work. */ - len = strlen (cmd) - 1; + len = strlen (orig_cmd) - 1; while (len >= 0 && - (cmd [len] == ' ' || cmd [len] == '\t' || cmd [len] == '\n')){ - cmd [len] = 0; + (orig_cmd [len] == ' ' || orig_cmd [len] == '\t' || orig_cmd [len] == '\n')){ + orig_cmd [len] = 0; len --; } - + + cmd = orig_cmd; if (cmd [2] == 0) cmd = "cd "; diff --git a/src/cons.saver.c b/src/cons.saver.c index 0ca0b4ab3..cda7219a8 100644 --- a/src/cons.saver.c +++ b/src/cons.saver.c @@ -133,7 +133,8 @@ main (int argc, char **argv) int console_fd, vcsa_fd, console_minor, buffer_size; struct stat st; uid_t uid, euid; - char *buffer, *tty_name, console_name [16], vcsa_name [16], *p, *q; + char *buffer, *tty_name, console_name [16], vcsa_name [16]; + const char *p, *q; struct winsize winsz; close (2); diff --git a/src/execute.c b/src/execute.c index bb7d5dc7e..2c8bc71c5 100644 --- a/src/execute.c +++ b/src/execute.c @@ -123,7 +123,7 @@ do_execute (const char *shell, const char *command, int flags) /* We don't care if it died, higher level takes care of this */ #ifdef USE_VFS - invoke_subshell (command, VISIBLY, old_vfs_dir ? 0 : &new_dir); + invoke_subshell (command, VISIBLY, old_vfs_dir ? NULL : &new_dir); #else invoke_subshell (command, VISIBLY, &new_dir); #endif /* !USE_VFS */ diff --git a/src/file.c b/src/file.c index 267acced3..6db61e6ca 100644 --- a/src/file.c +++ b/src/file.c @@ -1431,7 +1431,7 @@ compute_dir_size_create_ui (void) { ComputeDirSizeUI *ui; - char *b_name = N_("&Abort"); + const char *b_name = N_("&Abort"); #ifdef ENABLE_NLS b_name = _(b_name); diff --git a/src/search/regex.c b/src/search/regex.c index b2c8cedde..b149a3ebb 100644 --- a/src/search/regex.c +++ b/src/search/regex.c @@ -59,8 +59,8 @@ mc_search__regex_str_append_if_special (GString * copy_to, GString * regex_str, { char *tmp_regex_str; gsize spec_chr_len; - char **spec_chr; - char *special_chars[] = { + const char **spec_chr; + const char *special_chars[] = { "\\s", "\\S", "\\d", "\\D", "\\B", "\\B", diff --git a/src/search/search.h b/src/search/search.h index c61fef249..faf7efc0e 100644 --- a/src/search/search.h +++ b/src/search/search.h @@ -103,7 +103,7 @@ typedef struct mc_search_struct { } mc_search_t; typedef struct mc_search_type_str_struct { - char *str; + const char *str; mc_search_type_t type; } mc_search_type_str_t; diff --git a/src/slint.c b/src/slint.c index 1ab463168..773199777 100644 --- a/src/slint.c +++ b/src/slint.c @@ -222,9 +222,9 @@ slang_shutdown (void) /* Load the op capability to reset the colors to those that were * active when the program was started up */ - op_cap = SLtt_tgetstr ("op"); + op_cap = SLtt_tgetstr ((char*)"op"); if (op_cap){ - fprintf (stdout, "%s", op_cap); + fputs (op_cap, stdout); fflush (stdout); } } @@ -268,12 +268,12 @@ slang_reset_softkeys (void) void slang_keypad (int set) { - char *keypad_string; + const char *keypad_string; extern int reset_hp_softkeys; - keypad_string = (char *) SLtt_tgetstr (set ? "ks" : "ke"); + keypad_string = SLtt_tgetstr ((char*)(set ? "ks" : "ke")); if (keypad_string) - SLtt_write_string (keypad_string); + SLtt_write_string ((char*)keypad_string); if (set && reset_hp_softkeys) slang_reset_softkeys (); } diff --git a/src/subshell.c b/src/subshell.c index a1315d658..e04b736d6 100644 --- a/src/subshell.c +++ b/src/subshell.c @@ -252,11 +252,11 @@ init_subshell_child (const char *pty_name) init_file = ".bashrc"; /* Make MC's special commands not show up in bash's history */ - putenv ("HISTCONTROL=ignorespace"); + putenv ((char*)"HISTCONTROL=ignorespace"); /* Allow alternative readline settings for MC */ if (access (".mc/inputrc", R_OK) == 0) - putenv ("INPUTRC=.mc/inputrc"); + putenv ((char*)"INPUTRC=.mc/inputrc"); break; -- 2.11.4.GIT