From efae1e913ddd8b81376454dea12803905ee84f6a Mon Sep 17 00:00:00 2001 From: Mark Nudelman Date: Mon, 6 Nov 2023 23:26:30 -0800 Subject: [PATCH] Constify. --- charset.c | 12 ++++++------ cmdbuf.c | 19 ++++++++++--------- command.c | 2 +- decode.c | 21 +++++++++++---------- filename.c | 10 +++++----- line.c | 4 ++-- main.c | 6 +++--- opttbl.c | 2 +- prompt.c | 4 ++-- screen.c | 49 +++++++++++++++++++++++++------------------------ tags.c | 2 +- 11 files changed, 67 insertions(+), 64 deletions(-) diff --git a/charset.c b/charset.c index b9f984e4..2825a68f 100644 --- a/charset.c +++ b/charset.c @@ -145,7 +145,7 @@ static void wchar_range_table_set(struct wchar_range_table *tbl, struct xbuffer /* * Skip over a "U" or "U+" prefix before a hex codepoint. */ -static char * skip_uprefix(char *s) +static constant char * skip_uprefix(constant char *s) { if (*s == 'U' || *s == 'u') if (*++s == '+') ++s; @@ -155,14 +155,14 @@ static char * skip_uprefix(char *s) /* * Parse a dash-separated range of hex values. */ -static void wchar_range_get(char **ss, struct wchar_range *range) +static void wchar_range_get(constant char **ss, struct wchar_range *range) { - char *s = skip_uprefix(*ss); - range->first = lstrtoul(s, &s, 16); + constant char *s = skip_uprefix(*ss); + range->first = lstrtoulc(s, &s, 16); if (s[0] == '-') { s = skip_uprefix(&s[1]); - range->last = lstrtoul(s, &s, 16); + range->last = lstrtoulc(s, &s, 16); } else { range->last = range->first; @@ -173,7 +173,7 @@ static void wchar_range_get(char **ss, struct wchar_range *range) /* * Parse the LESSUTFCHARDEF variable. */ -static void ichardef_utf(char *s) +static void ichardef_utf(constant char *s) { xbuf_init(&user_wide_array); xbuf_init(&user_ubin_array); diff --git a/cmdbuf.c b/cmdbuf.c index 45787b8b..3e8961ce 100644 --- a/cmdbuf.c +++ b/cmdbuf.c @@ -1093,7 +1093,7 @@ static char * next_compl(int action, char *prev) */ static int cmd_complete(int action) { - char *s; + constant char *s; if (!in_completion || action == EC_EXPAND) { @@ -1344,7 +1344,7 @@ static int mlist_size(struct mlist *ml) */ static char * histfile_find(int must_exist) { - char *home = lgetenv("HOME"); + constant char *home = lgetenv("HOME"); char *name = NULL; /* Try in $XDG_STATE_HOME, then in $HOME/.local/state, then in $XDG_DATA_HOME, then in $HOME. */ @@ -1371,7 +1371,8 @@ static char * histfile_find(int must_exist) static char * histfile_name(int must_exist) { - char *name; + constant char *name; + char *wname; /* See if filename is explicitly specified by $LESSHISTFILE. */ name = lgetenv("LESSHISTFILE"); @@ -1387,15 +1388,15 @@ static char * histfile_name(int must_exist) if (strcmp(LESSHISTFILE, "") == 0 || strcmp(LESSHISTFILE, "-") == 0) return (NULL); - name = NULL; + wname = NULL; if (!must_exist) { /* If we're writing the file and the file already exists, use it. */ - name = histfile_find(1); + wname = histfile_find(1); } - if (name == NULL) - name = histfile_find(must_exist); - return (name); + if (wname == NULL) + wname = histfile_find(must_exist); + return (wname); } /* @@ -1632,7 +1633,7 @@ public void save_cmdhist(void) int skip_search; int skip_shell; struct save_ctx ctx; - char *s; + constant char *s; FILE *fout = NULL; int histsize = 0; diff --git a/command.c b/command.c index 6091666e..57a9fa55 100644 --- a/command.c +++ b/command.c @@ -51,7 +51,7 @@ extern int updown_match; extern void *ml_shell; #endif #if EDITOR -extern char *editproto; +extern constant char *editproto; #endif extern int shift_count; extern int forw_prompt; diff --git a/decode.c b/decode.c index 95e87640..ef86a6e8 100644 --- a/decode.c +++ b/decode.c @@ -738,29 +738,29 @@ public int ecmd_decode(constant char *cmd, constant char **sp) * Get the value of an environment variable. * Looks first in the lesskey file, then in the real environment. */ -public char * lgetenv(constant char *var) /*{{const-issue}}*/ +public constant char * lgetenv(constant char *var) { int a; constant char *s; a = cmd_decode(list_var_tables, var, &s); if (a == EV_OK) - return ((char *) s); /*{{const-issue}}*/ + return (s); /*{{const-issue}}*/ s = getenv(var); if (s != NULL && *s != '\0') - return ((char *) s); /*{{const-issue}}*/ + return (s); /*{{const-issue}}*/ a = cmd_decode(list_sysvar_tables, var, &s); if (a == EV_OK) - return ((char *) s); /*{{const-issue}}*/ + return (s); /*{{const-issue}}*/ return (NULL); } /* * Like lgetenv, but also uses a buffer partially filled with an env table. */ -public char * lgetenv_ext(constant char *var, unsigned char *env_buf, int env_buf_len) +public constant char * lgetenv_ext(constant char *var, unsigned char *env_buf, int env_buf_len) { - char *r; + constant char *r; int e; int env_end = 0; @@ -992,21 +992,22 @@ void lesskey_parse_error(char *s) public int add_hometable(int (*call_lesskey)(constant char *, int), char *envname, char *def_filename, int sysvar) { char *filename; + constant char *efilename; int r; - if (envname != NULL && (filename = lgetenv(envname)) != NULL) - filename = save(filename); + if (envname != NULL && (efilename = lgetenv(envname)) != NULL) + filename = save(efilename); else if (sysvar) /* def_filename is full path */ filename = save(def_filename); else /* def_filename is just basename */ { /* Remove first char (normally a dot) unless stored in $HOME. */ - char *xdg = lgetenv("XDG_CONFIG_HOME"); + constant char *xdg = lgetenv("XDG_CONFIG_HOME"); if (!isnullenv(xdg)) filename = dirfile(xdg, &def_filename[1], 1); if (filename == NULL) { - char *home = lgetenv("HOME"); + constant char *home = lgetenv("HOME"); if (!isnullenv(home)) { char *cfg_dir = dirfile(home, ".config", 0); diff --git a/filename.c b/filename.c index 8c55c568..8ac67b09 100644 --- a/filename.c +++ b/filename.c @@ -100,7 +100,7 @@ public char * shell_unquote(constant char *str) */ public constant char * get_meta_escape(void) { - char *s; + constant char *s; s = lgetenv("LESSMETAESCAPE"); if (s == NULL) @@ -113,7 +113,7 @@ public constant char * get_meta_escape(void) */ static constant char * metachars(void) { - static char *mchars = NULL; + static constant char *mchars = NULL; if (mchars == NULL) { @@ -551,7 +551,7 @@ static FILE * shellcmd(constant char *cmd) FILE *fd; #if HAVE_SHELL - char *shell; + constant char *shell; shell = lgetenv("SHELL"); if (!isnullenv(shell)) @@ -833,7 +833,7 @@ public char * open_altfile(constant char *filename, int *pf, void **pfd) #if !HAVE_POPEN return (NULL); #else - char *lessopen; + constant char *lessopen; char *qfilename; char *cmd; int len; @@ -954,7 +954,7 @@ public char * open_altfile(constant char *filename, int *pf, void **pfd) public void close_altfile(constant char *altfilename, constant char *filename) { #if HAVE_POPEN - char *lessclose; + constant char *lessclose; char *qfilename; char *qaltfilename; FILE *fd; diff --git a/line.c b/line.c index e9f7dff1..00db5fdd 100644 --- a/line.c +++ b/line.c @@ -71,8 +71,8 @@ static int last_overstrike = AT_NORMAL; static int is_null_line; /* There is no current line */ static LWCHAR pendc; static POSITION pendpos; -static char *end_ansi_chars; -static char *mid_ansi_chars; +static constant char *end_ansi_chars; +static constant char *mid_ansi_chars; static int in_hilite; static int attr_swidth(int a); diff --git a/main.c b/main.c index ec4b680d..9091ce07 100644 --- a/main.c +++ b/main.c @@ -46,8 +46,8 @@ public char * namelogfile = NULL; #endif #if EDITOR -public char * editor; -public char * editproto; +public constant char * editor; +public constant char * editproto; #endif #if TAGS @@ -233,7 +233,7 @@ static void init_secure(void) int main(int argc, char *argv[]) { IFILE ifile; - char *s; + constant char *s; #if MSDOS_COMPILER==WIN32C && (defined(MINGW) || defined(_MSC_VER)) if (GetACP() != CP_UTF8) /* not using a UTF-8 manifest */ diff --git a/opttbl.c b/opttbl.c index b21f1549..e1c9bf1f 100644 --- a/opttbl.c +++ b/opttbl.c @@ -744,7 +744,7 @@ static struct loption option[] = public void init_option(void) { struct loption *o; - char *p; + constant char *p; p = lgetenv("LESS_IS_MORE"); if (!isnullenv(p)) diff --git a/prompt.c b/prompt.c index a827ba72..5835fca2 100644 --- a/prompt.c +++ b/prompt.c @@ -30,8 +30,8 @@ extern int less_is_more; extern int header_lines; extern IFILE curr_ifile; #if EDITOR -extern char *editor; -extern char *editproto; +extern constant char *editor; +extern constant char *editproto; #endif /* diff --git a/screen.c b/screen.c index 17401ac5..a8276b9b 100644 --- a/screen.c +++ b/screen.c @@ -190,7 +190,7 @@ public int vt_enabled = -1; /* Is virtual terminal processing available? */ /* * Strings passed to tputs() to do various terminal functions. */ -static char +static constant char *sc_pad, /* Pad string */ *sc_home, /* Cursor home */ *sc_addline, /* Add line, scroll down following lines */ @@ -237,7 +237,7 @@ public int above_mem, below_mem; /* Memory retained above/below screen */ public int can_goto_line; /* Can move cursor to any line */ public int clear_bg; /* Clear fills with background color */ public int missing_cap = 0; /* Some capability is missing */ -public char *kent = NULL; /* Keypad ENTER sequence */ +public constant char *kent = NULL; /* Keypad ENTER sequence */ public int term_init_done = FALSE; public int full_screen = TRUE; @@ -251,9 +251,9 @@ extern char *ttyin_name; #endif /*LESSTEST*/ #if !MSDOS_COMPILER -static char *cheaper(char *t1, char *t2, char *def); -static void tmodes(char *incap, char *outcap, char **instr, - char **outstr, char *def_instr, char *def_outstr, char **spp); +static constant char *cheaper(constant char *t1, constant char *t2, constant char *def); +static void tmodes(constant char *incap, constant char *outcap, constant char **instr, + constant char **outstr, constant char *def_instr, constant char *def_outstr, char **spp); #endif /* @@ -706,7 +706,7 @@ public void raw_mode(int on) */ static int hardcopy; -static char * ltget_env(char *capname) +static constant char * ltget_env(constant char *capname) { char name[64]; @@ -732,7 +732,7 @@ static char * ltget_env(char *capname) static int ltgetflag(char *capname) { - char *s; + constant char *s; if ((s = ltget_env(capname)) != NULL) return (*s != '\0' && *s != '0'); @@ -743,7 +743,7 @@ static int ltgetflag(char *capname) static int ltgetnum(char *capname) { - char *s; + constant char *s; if ((s = ltget_env(capname)) != NULL) return (atoi(s)); @@ -752,9 +752,9 @@ static int ltgetnum(char *capname) return (tgetnum(capname)); } -static char * ltgetstr(char *capname, char **pp) +static constant char * ltgetstr(constant char *capname, char **pp) { - char *s; + constant char *s; if ((s = ltget_env(capname)) != NULL) return (s); @@ -769,7 +769,7 @@ static char * ltgetstr(char *capname, char **pp) */ static void scrsize(void) { - char *s; + constant char *s; int sys_height; int sys_width; #if !MSDOS_COMPILER @@ -958,7 +958,7 @@ static void delay(int msec) public constant char * special_key_str(int key) { static char tbuf[40]; - char *s; + constant char *s; #if MSDOS_COMPILER || OS2 static char k_right[] = { '\340', PCK_RIGHT, 0 }; static char k_left[] = { '\340', PCK_LEFT, 0 }; @@ -1201,8 +1201,9 @@ public void get_term(void) #else /* !MSDOS_COMPILER */ { char *sp; - char *t1, *t2; - char *term; + constant char *t1; + constant char *t2; + constant char *term; /* * Some termcap libraries assume termbuf is static * (accessible after tgetent returns). @@ -1214,8 +1215,8 @@ public void get_term(void) /* * Make sure the termcap database is available. */ - sp = lgetenv("TERMCAP"); - if (isnullenv(sp)) + constant char *cp = lgetenv("TERMCAP"); + if (isnullenv(cp)) { char *termcap; if ((sp = homefile("termcap.dat")) != NULL) @@ -1452,7 +1453,7 @@ static int inc_costcount(int c) return (c); } -static int cost(char *t) +static int cost(constant char *t) { costcount = 0; tputs(t, sc_height, inc_costcount); @@ -1464,7 +1465,7 @@ static int cost(char *t) * The best, if both exist, is the one with the lower * cost (see cost() function). */ -static char * cheaper(char *t1, char *t2, char *def) +static constant char * cheaper(constant char *t1, constant char *t2, constant char *def) { if (*t1 == '\0' && *t2 == '\0') { @@ -1480,7 +1481,7 @@ static char * cheaper(char *t1, char *t2, char *def) return (t2); } -static void tmodes(char *incap, char *outcap, char **instr, char **outstr, char *def_instr, char *def_outstr, char **spp) +static void tmodes(constant char *incap, constant char *outcap, constant char **instr, constant char **outstr, constant char *def_instr, constant char *def_outstr, char **spp) { *instr = ltgetstr(incap, spp); if (*instr == NULL) @@ -1634,7 +1635,7 @@ static void win32_deinit_term(void) #endif #if !MSDOS_COMPILER -static void do_tputs(char *str, int affcnt, int (*f_putc)(int)) +static void do_tputs(constant char *str, int affcnt, int (*f_putc)(int)) { #if LESSTEST if (ttyin_name != NULL && f_putc == putchr) @@ -1648,7 +1649,7 @@ static void do_tputs(char *str, int affcnt, int (*f_putc)(int)) * Like tputs but we handle $<...> delay strings here because * some implementations of tputs don't perform delays correctly. */ -static void ltputs(char *str, int affcnt, int (*f_putc)(int)) +static void ltputs(constant char *str, int affcnt, int (*f_putc)(int)) { while (str != NULL && *str != '\0') { @@ -1667,7 +1668,7 @@ static void ltputs(char *str, int affcnt, int (*f_putc)(int)) do_tputs(str2, affcnt, f_putc); str += slen + 2; /* Perform the delay. */ - delay = lstrtoi(str, &str, 10); + delay = lstrtoic(str, &str, 10); if (*str == '*') if (ckd_mul(&delay, delay, affcnt)) delay = INT_MAX; @@ -2574,7 +2575,7 @@ static void tput_color(constant char *str, int (*f_putc)(int)) } } -static void tput_inmode(char *mode_str, int attr, int attr_bit, int (*f_putc)(int)) +static void tput_inmode(constant char *mode_str, int attr, int attr_bit, int (*f_putc)(int)) { constant char *color_str; if ((attr & attr_bit) == 0) @@ -2590,7 +2591,7 @@ static void tput_inmode(char *mode_str, int attr, int attr_bit, int (*f_putc)(in tput_color(color_str, f_putc); } -static void tput_outmode(char *mode_str, int attr_bit, int (*f_putc)(int)) +static void tput_outmode(constant char *mode_str, int attr_bit, int (*f_putc)(int)) { if ((attrmode & attr_bit) == 0) return; diff --git a/tags.c b/tags.c index 41f6f220..e7dead46 100644 --- a/tags.c +++ b/tags.c @@ -510,7 +510,7 @@ static enum tag_result findgtag(char *tag, int type) char *command; char *flag; char *qtag; - char *cmd = lgetenv("LESSGLOBALTAGS"); + constant char *cmd = lgetenv("LESSGLOBALTAGS"); if (isnullenv(cmd)) return TAG_NOFILE;