From 243e84706e625ccf6b992b010290759a5e08cbef Mon Sep 17 00:00:00 2001 From: Roland Illig Date: Sun, 29 Aug 2004 18:45:56 +0000 Subject: [PATCH] * Code cleanup: Added const qualifier for variables and function declarations where possible. No functional changes. --- edit/edit.c | 4 ++-- edit/edit.h | 6 +++--- edit/editcmd.c | 10 +++++----- edit/editlock.c | 15 ++++++++------- edit/editlock.h | 4 ++-- edit/editoptions.c | 10 +++++----- edit/syntax.c | 2 +- src/achown.c | 4 ++-- src/widget.h | 2 +- src/wtools.h | 8 ++++---- 10 files changed, 33 insertions(+), 32 deletions(-) diff --git a/edit/edit.c b/edit/edit.c index b39f79cae..32721d3d2 100644 --- a/edit/edit.c +++ b/edit/edit.c @@ -54,7 +54,7 @@ int option_edit_left_extreme = 0; int option_edit_top_extreme = 0; int option_edit_bottom_extreme = 0; -char *option_whole_chars_search = "0123456789abcdefghijklmnopqrstuvwxyz_"; +const char *option_whole_chars_search = "0123456789abcdefghijklmnopqrstuvwxyz_"; char *option_backup_ext = "~"; /* @@ -175,7 +175,7 @@ edit_load_file_fast (WEdit *edit, const char *filename) whether you read everything or not. */ /* FIXME: add proper `triple_pipe_open' to read, write and check errors. */ static const struct edit_filters { - char *read, *write, *extension; + const char *read, *write, *extension; } all_filters[] = { { diff --git a/edit/edit.h b/edit/edit.h index 895d0fe09..f4a67122d 100644 --- a/edit/edit.h +++ b/edit/edit.h @@ -130,7 +130,7 @@ void edit_init_menu_emacs (void); void edit_init_menu_normal (void); void edit_done_menu (void); void menu_save_mode_cmd (void); -int edit_raw_key_query (char *heading, char *query, int cancel); +int edit_raw_key_query (const char *heading, const char *query, int cancel); int edit (const char *_file, int line); int edit_translate_key (WEdit *edit, long x_key, int *cmd, int *ch); @@ -234,7 +234,7 @@ void edit_paste_from_history (WEdit *edit); void edit_set_filename (WEdit *edit, const char *name); -void edit_load_syntax (WEdit * edit, char **names, char *type); +void edit_load_syntax (WEdit * edit, char **names, const char *type); void edit_free_syntax_rules (WEdit * edit); void edit_get_syntax_color (WEdit * edit, long byte_index, int *color); @@ -318,7 +318,7 @@ extern int option_edit_left_extreme; extern int option_edit_top_extreme; extern int option_edit_bottom_extreme; -extern char *option_whole_chars_search; +extern const char *option_whole_chars_search; extern char *option_backup_ext; extern int edit_confirm_save; diff --git a/edit/editcmd.c b/edit/editcmd.c index 8ac0ccd34..8cbdbf51d 100644 --- a/edit/editcmd.c +++ b/edit/editcmd.c @@ -371,7 +371,7 @@ void menu_save_mode_cmd (void) #define DLG_Y 10 static char *str_result; static int save_mode_new; - static char *str[] = + static const char *str[] = { N_("Quick save "), N_("Safe save "), @@ -554,7 +554,7 @@ raw_callback (struct Dlg_head *h, dlg_msg_t msg, int parm) will return the next key pressed. ctrl-a (=B_CANCEL), ctrl-g, ctrl-c, and Esc are cannot returned */ int -edit_raw_key_query (char *heading, char *query, int cancel) +edit_raw_key_query (const char *heading, const char *query, int cancel) { int w = strlen (query) + 7; struct Dlg_head *raw_dlg = @@ -1617,7 +1617,7 @@ edit_find (long search_start, unsigned char *exp, int *len, long last_byte, int *p1++ = *p++; \ *p1 = '\0'; \ n = snprintf(s,e-s,q1,v); \ - if (n >= e - s) goto nospc; \ + if (n >= (size_t) (e - s)) goto nospc; \ s += n; \ } @@ -1643,7 +1643,7 @@ static int snprintf_p (char *str, size_t size, const char *fmt,...) while ((p = strchr (p, '%'))) { n = p - q; - if (n >= e - s) + if (n >= (size_t) (e - s)) goto nospc; memcpy (s, q, n); /* copy stuff between format specifiers */ s += n; @@ -1721,7 +1721,7 @@ static int snprintf_p (char *str, size_t size, const char *fmt,...) } va_end (ap); n = strlen (q); - if (n >= e - s) + if (n >= (size_t) (e - s)) return -1; memcpy (s, q, n + 1); return s + n - str; diff --git a/edit/editlock.c b/edit/editlock.c index b270796b8..e0749d570 100644 --- a/edit/editlock.c +++ b/edit/editlock.c @@ -50,9 +50,10 @@ struct lock_s { /* Build user@host.domain.pid string (need to be freed) */ static char * -lock_build_name (char *fname) +lock_build_name (const char *fname) { - char host[BUF_SIZE], *user; + char host[BUF_SIZE]; + const char *user; if (! ((user = getpwuid (getuid ())->pw_name) || (user = getenv ("USER")) @@ -68,10 +69,10 @@ lock_build_name (char *fname) /* Extract pid from user@host.domain.pid string */ static struct lock_s * -lock_extract_info (char *str) +lock_extract_info (const char *str) { int i; - char *p, *s; + const char *p, *s; static char pid[PID_BUF_SIZE], who[BUF_SIZE]; static struct lock_s lock; @@ -99,7 +100,7 @@ lock_extract_info (char *str) /* Extract user@host.domain.pid from lock file (static string) */ static char * -lock_get_info (char *lockfname) +lock_get_info (const char *lockfname) { int cnt; static char buf[BUF_SIZE]; @@ -116,7 +117,7 @@ lock_get_info (char *lockfname) Returns 1 on success, 0 on failure, -1 if abort Warning: Might do screen refresh and lose edit->force */ int -edit_lock_file (char *fname) +edit_lock_file (const char *fname) { char *lockfname, *newlock, *msg, *lock; struct stat statbuf; @@ -181,7 +182,7 @@ edit_lock_file (char *fname) /* Lowers file lock if possible Always returns 0 to make 'lock = edit_unlock_file (f)' possible */ int -edit_unlock_file (char *fname) +edit_unlock_file (const char *fname) { char *lockfname, *lock; struct stat statbuf; diff --git a/edit/editlock.h b/edit/editlock.h index 4a3cc9966..789477bae 100644 --- a/edit/editlock.h +++ b/edit/editlock.h @@ -1,7 +1,7 @@ #ifndef __EDIT_LOCK_H #define __EDIT_LOCK_H -int edit_lock_file (char *fname); -int edit_unlock_file (char *fname); +int edit_lock_file (const char *fname); +int edit_unlock_file (const char *fname); #endif /* !__EDIT_LOCK_H */ diff --git a/edit/editoptions.c b/edit/editoptions.c index 35aceb5a2..d7d980804 100644 --- a/edit/editoptions.c +++ b/edit/editoptions.c @@ -32,14 +32,14 @@ #define USE_INTERNAL_EDIT 1 #endif -static char *key_emu_str[] = +static const char *key_emu_str[] = {N_("Intuitive"), N_("Emacs"), NULL}; -static char *wrap_str[] = +static const char *wrap_str[] = {N_("None"), N_("Dynamic paragraphing"), N_("Type writer wrap"), NULL}; static void -i18n_translate_array (char *array[]) +i18n_translate_array (const char *array[]) { while (*array!=NULL) { *array = _(*array); @@ -106,14 +106,14 @@ edit_options_dialog (void) OPT_DLG_H, N_("&Fake half tabs"), 0, 0, 0, 0, NULL}, /* 13 */ {quick_radio, 5, OPT_DLG_W, OPT_DLG_H - 7, OPT_DLG_H, "", 3, 0, 0, - wrap_str, "wrapm"}, + const_cast(char **, wrap_str), "wrapm"}, /* 14 */ {quick_label, 4, OPT_DLG_W, OPT_DLG_H - 8, OPT_DLG_H, N_("Wrap mode"), 0, 0, 0, 0, NULL}, /* 15 */ {quick_radio, 5, OPT_DLG_W, OPT_DLG_H - 13, OPT_DLG_H, "", 2, 0, 0, - key_emu_str, "keyemu"}, + const_cast(char **, key_emu_str), "keyemu"}, /* 16 */ {quick_label, 4, OPT_DLG_W, OPT_DLG_H - 14, OPT_DLG_H, N_("Key emulation"), 0, 0, 0, 0, NULL}, diff --git a/edit/syntax.c b/edit/syntax.c index 12c6391f3..3b1c79c5e 100644 --- a/edit/syntax.c +++ b/edit/syntax.c @@ -1096,7 +1096,7 @@ static char *get_first_editor_line (WEdit * edit) * NULL, then the type will be selected according to the filename. */ void -edit_load_syntax (WEdit *edit, char **names, char *type) +edit_load_syntax (WEdit *edit, char **names, const char *type) { int r; char *f; diff --git a/src/achown.c b/src/achown.c index 307d4bc93..1806bec4f 100644 --- a/src/achown.c +++ b/src/achown.c @@ -63,7 +63,7 @@ static struct Dlg_head *ch_dlg; static struct { int ret_cmd, flags, y, x; - char *text; + const char *text; } chown_advanced_but [BUTTONS] = { { B_CANCEL, NORMAL_BUTTON, 4, 53, N_("&Cancel") }, { B_ENTER, DEFPUSH_BUTTON,4, 40, N_("&Set") }, @@ -94,7 +94,7 @@ static char *fname; static void get_ownership (void) { /* set buttons - ownership */ - char *name_t; + const char *name_t; name_t = name_trunc (get_owner (sf_stat->st_uid), 15); memset (b_user->text, ' ', 15); diff --git a/src/widget.h b/src/widget.h index 0c50021eb..4a23e7a8b 100644 --- a/src/widget.h +++ b/src/widget.h @@ -33,7 +33,7 @@ typedef struct WRadio { unsigned int state; /* radio button state */ int pos, sel; int count; /* number of members */ - char **texts; /* texts of labels */ + const char **texts; /* texts of labels */ int upper_letter_is_hotkey; /* If true, then the capital letter is a hk */ } WRadio; diff --git a/src/wtools.h b/src/wtools.h index a081da746..4b04b7437 100644 --- a/src/wtools.h +++ b/src/wtools.h @@ -35,20 +35,20 @@ typedef struct { int relative_y; int y_divisions; - char *text; /* Text */ + const char *text; /* Text */ int hotkey_pos; /* the hotkey position */ int value; /* Buttons only: value of button */ int *result; /* Checkbutton: where to store result */ char **str_result; /* Input lines: destination */ - char *histname; /* Name of the section for saving history */ + const char *histname; /* Name of the section for saving history */ } QuickWidget; #define NULL_QuickWidget { 0, 0, 0, 0, 0, NULL, 0, 0, NULL, NULL, NULL } typedef struct { int xlen, ylen; int xpos, ypos; /* if -1, then center the dialog */ - char *title; - char *help; + const char *title; + const char *help; QuickWidget *widgets; int i18n; /* If true, internationalization has happened */ } QuickDialog;