Skip to content

Commit

Permalink
Constify.
Browse files Browse the repository at this point in the history
  • Loading branch information
gwsw committed Nov 7, 2023
1 parent a7b3b89 commit efae1e9
Show file tree
Hide file tree
Showing 11 changed files with 67 additions and 64 deletions.
12 changes: 6 additions & 6 deletions charset.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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;
Expand All @@ -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);
Expand Down
19 changes: 10 additions & 9 deletions cmdbuf.c
Original file line number Diff line number Diff line change
Expand Up @@ -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)
{
Expand Down Expand Up @@ -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. */
Expand All @@ -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");
Expand All @@ -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);
}

/*
Expand Down Expand Up @@ -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;

Expand Down
2 changes: 1 addition & 1 deletion command.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
21 changes: 11 additions & 10 deletions decode.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down Expand Up @@ -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);
Expand Down
10 changes: 5 additions & 5 deletions filename.c
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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)
{
Expand Down Expand Up @@ -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))
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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;
Expand Down
4 changes: 2 additions & 2 deletions line.c
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
6 changes: 3 additions & 3 deletions main.c
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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 */
Expand Down
2 changes: 1 addition & 1 deletion opttbl.c
Original file line number Diff line number Diff line change
Expand Up @@ -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))
Expand Down
4 changes: 2 additions & 2 deletions prompt.c
Original file line number Diff line number Diff line change
Expand Up @@ -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

/*
Expand Down

0 comments on commit efae1e9

Please sign in to comment.