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 d945730 commit 656ebf1
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 18 deletions.
10 changes: 5 additions & 5 deletions cmdbuf.c
Original file line number Diff line number Diff line change
Expand Up @@ -1401,7 +1401,7 @@ static char * histfile_name(int must_exist)
/*
* Read a .lesshst file and call a callback for each line in the file.
*/
static void read_cmdhist2(void (*action)(void*,struct mlist*,char*), void *uparam, int skip_search, int skip_shell)
static void read_cmdhist2(void (*action)(void*,struct mlist*,constant char*), void *uparam, int skip_search, int skip_shell)
{
struct mlist *ml = NULL;
char line[CMDBUF_SIZE];
Expand Down Expand Up @@ -1466,20 +1466,20 @@ static void read_cmdhist2(void (*action)(void*,struct mlist*,char*), void *upara
fclose(f);
}

static void read_cmdhist(void (*action)(void*,struct mlist*,char*), void *uparam, int skip_search, int skip_shell)
static void read_cmdhist(void (*action)(void*,struct mlist*,constant char*), void *uparam, int skip_search, int skip_shell)
{
if (!secure_allow(SF_HISTORY))
return;
read_cmdhist2(action, uparam, skip_search, skip_shell);
(*action)(uparam, NULL, NULL); /* signal end of file */
}

static void addhist_init(void *uparam, struct mlist *ml, char *string)
static void addhist_init(void *uparam, struct mlist *ml, constant char *string)
{
if (ml != NULL)
cmd_addhist(ml, string, 0);
else if (string != NULL)
restore_mark((char*)string); /* stupid const cast */
restore_mark((char*)string); /*{{const-issue}}*/
}
#endif /* CMD_HISTORY */

Expand Down Expand Up @@ -1546,7 +1546,7 @@ struct save_ctx
* At the end of each mlist, append any new entries
* created during this session.
*/
static void copy_hist(void *uparam, struct mlist *ml, char *string)
static void copy_hist(void *uparam, struct mlist *ml, constant char *string)
{
struct save_ctx *ctx = (struct save_ctx *) uparam;

Expand Down
26 changes: 13 additions & 13 deletions option.c
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
static struct loption *pendopt;
public int plusoption = FALSE;

static char *optstring(char *s, char **p_str, char *printopt, char *validchars);
static char *optstring(char *s, char **p_str, constant char *printopt, char *validchars);
static int flip_triple(int val, int lc);

extern int less_is_more;
Expand All @@ -34,7 +34,7 @@ extern int opt_use_backslash;
/*
* Return a printable description of an option.
*/
static char * opt_desc(struct loption *o)
static constant char * opt_desc(struct loption *o)
{
static char buf[OPTNAME_MAX + 10];
if (o->oletter == OLETTER_NONE)
Expand All @@ -48,7 +48,7 @@ static char * opt_desc(struct loption *o)
* Return a string suitable for printing as the "name" of an option.
* For example, if the option letter is 'x', just return "-x".
*/
public char * propt(int c)
public constant char * propt(int c)
{
static char buf[MAX_PRCHAR_LEN+2];

Expand All @@ -65,7 +65,7 @@ public void scan_option(char *s)
struct loption *o;
int optc;
char *optname;
char *printopt;
constant char *printopt;
char *str;
int set_default;
int lc;
Expand Down Expand Up @@ -546,7 +546,7 @@ public int isoptpending(void)
/*
* Print error message about missing string.
*/
static void nostring(char *printopt)
static void nostring(constant char *printopt)
{
PARG parg;
parg.p_string = printopt;
Expand All @@ -571,7 +571,7 @@ public void nopendopt(void)
* "d" indicates a string of one or more digits (0-9)
* "," indicates a comma-separated list of digit strings is allowed
*/
static char * optstring(char *s, char **p_str, char *printopt, char *validchars)
static char * optstring(char *s, char **p_str, constant char *printopt, char *validchars)
{
char *p;
char *out;
Expand Down Expand Up @@ -632,7 +632,7 @@ static char * optstring(char *s, char **p_str, char *printopt, char *validchars)

/*
*/
static int num_error(char *printopt, int *errp, int overflow)
static int num_error(constant char *printopt, int *errp, int overflow)
{
PARG parg;

Expand All @@ -657,9 +657,9 @@ static int num_error(char *printopt, int *errp, int overflow)
* Like atoi(), but takes a pointer to a char *, and updates
* the char * to point after the translated number.
*/
public int getnum(char **sp, char *printopt, int *errp)
public int getnum(char **sp, constant char *printopt, int *errp)
{
char *s;
constant char *s;
int n;
int neg;

Expand All @@ -673,7 +673,7 @@ public int getnum(char **sp, char *printopt, int *errp)
if (*s < '0' || *s > '9')
return (num_error(printopt, errp, FALSE));

n = lstrtoi(s, sp, 10);
n = lstrtoi((char*)s, sp, 10); /*{{const-issue}}*/
if (n < 0)
return (num_error(printopt, errp, TRUE));
if (errp != NULL)
Expand All @@ -689,9 +689,9 @@ public int getnum(char **sp, char *printopt, int *errp)
* The value of the fraction is returned as parts per NUM_FRAC_DENOM.
* That is, if "n" is returned, the fraction intended is n/NUM_FRAC_DENOM.
*/
public long getfraction(char **sp, char *printopt, int *errp)
public long getfraction(char **sp, constant char *printopt, int *errp)
{
char *s;
constant char *s;
long frac = 0;
int fraclen = 0;

Expand All @@ -708,7 +708,7 @@ public long getfraction(char **sp, char *printopt, int *errp)
}
while (fraclen++ < NUM_LOG_FRAC_DENOM)
frac *= 10;
*sp = s;
*sp = (char*) s; /*{{const-issue}}*/
if (errp != NULL)
*errp = FALSE;
return (frac);
Expand Down

0 comments on commit 656ebf1

Please sign in to comment.