Skip to content

Commit

Permalink
More more more constify.
Browse files Browse the repository at this point in the history
  • Loading branch information
gwsw committed Nov 7, 2023
1 parent 656ebf1 commit 42e1b42
Show file tree
Hide file tree
Showing 5 changed files with 39 additions and 28 deletions.
24 changes: 12 additions & 12 deletions edit.c
Original file line number Diff line number Diff line change
Expand Up @@ -147,7 +147,7 @@ public char * back_textlist(struct textlist *tlist, char *prev)
/*
* Parse a single option setting in a modeline.
*/
static void modeline_option(char *str, int opt_len)
static void modeline_option(constant char *str, int opt_len)
{
struct mloption { constant char *opt_name; void (*opt_func)(constant char*,int); };
struct mloption options[] = {
Expand All @@ -171,10 +171,10 @@ static void modeline_option(char *str, int opt_len)
* String length, terminated by option separator (space or colon).
* Space/colon can be escaped with backspace.
*/
static int modeline_option_len(char *str)
static int modeline_option_len(constant char *str)
{
int esc = FALSE;
char *s;
constant char *s;
for (s = str; *s != '\0'; s++)
{
if (esc)
Expand All @@ -190,12 +190,12 @@ static int modeline_option_len(char *str)
/*
* Parse colon- or space-separated option settings in a modeline.
*/
static void modeline_options(char *str, char end_char)
static void modeline_options(constant char *str, char end_char)
{
for (;;)
{
int opt_len;
str = skipsp(str);
str = skipspc(str);
if (*str == '\0' || *str == end_char)
break;
opt_len = modeline_option_len(str);
Expand All @@ -209,21 +209,21 @@ static void modeline_options(char *str, char end_char)
/*
* See if there is a modeline string in a line.
*/
static void check_modeline(char *line)
static void check_modeline(constant char *line)
{
#if HAVE_STRSTR
static char *pgms[] = { "less:", "vim:", "vi:", "ex:", NULL };
char **pgm;
static constant char *pgms[] = { "less:", "vim:", "vi:", "ex:", NULL };
constant char **pgm;
for (pgm = pgms; *pgm != NULL; ++pgm)
{
char *pline = line;
constant char *pline = line;
for (;;)
{
char *str;
constant char *str;
pline = strstr(pline, *pgm);
if (pline == NULL) /* pgm is not in this line */
break;
str = skipsp(pline + strlen(*pgm));
str = skipspc(pline + strlen(*pgm));
if (pline == line || pline[-1] == ' ')
{
if (strncmp(str, "set ", 4) == 0)
Expand Down Expand Up @@ -924,7 +924,7 @@ public void cat_file(void)
* is standard input, create the log file.
* We take care not to blindly overwrite an existing file.
*/
public void use_logfile(char *filename)
public void use_logfile(constant char *filename)
{
int exists;
int answer;
Expand Down
1 change: 1 addition & 0 deletions evar.c
Original file line number Diff line number Diff line change
Expand Up @@ -161,6 +161,7 @@ static int add_evar(struct xbuffer *xbuf, char *buf, int len, int e, constant ch

/*
* Expand env variables in a string.
* Writes expanded output to xbuf. Corrupts buf.
*/
public void expand_evars(char *buf, int len, struct xbuffer *xbuf)
{
Expand Down
18 changes: 9 additions & 9 deletions line.c
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ static int in_hilite;

static int attr_swidth(int a);
static int attr_ewidth(int a);
static int do_append(LWCHAR ch, char *rep, POSITION pos);
static int do_append(LWCHAR ch, constant char *rep, POSITION pos);

extern int sigs;
extern int bs_mode;
Expand Down Expand Up @@ -288,7 +288,7 @@ static void add_linebuf(char ch, int attr, int w)
/*
* Append a string to the line buffer.
*/
static void addstr_linebuf(char *s, int attr, int cw)
static void addstr_linebuf(constant char *s, int attr, int cw)
{
for ( ; *s != '\0'; s++)
add_linebuf(*s, attr, cw);
Expand Down Expand Up @@ -677,7 +677,7 @@ static int fits_on_screen(int w, int a)
if (store_char((ch),(a),(rep),(pos))) return (1); \
} while (0)

static int store_char(LWCHAR ch, int a, char *rep, POSITION pos)
static int store_char(LWCHAR ch, int a, constant char *rep, POSITION pos)
{
int w;
int i;
Expand Down Expand Up @@ -968,7 +968,7 @@ public int pappend(int c, POSITION pos)
return (r);
}

static int store_control_char(LWCHAR ch, char *rep, POSITION pos)
static int store_control_char(LWCHAR ch, constant char *rep, POSITION pos)
{
if (ctldisp == OPT_ON)
{
Expand All @@ -982,7 +982,7 @@ static int store_control_char(LWCHAR ch, char *rep, POSITION pos)
return (0);
}

static int store_ansi(LWCHAR ch, char *rep, POSITION pos)
static int store_ansi(LWCHAR ch, constant char *rep, POSITION pos)
{
switch (ansi_step(line_ansi, ch))
{
Expand Down Expand Up @@ -1021,7 +1021,7 @@ static int store_ansi(LWCHAR ch, char *rep, POSITION pos)
return (0);
}

static int store_bs(LWCHAR ch, char *rep, POSITION pos)
static int store_bs(LWCHAR ch, constant char *rep, POSITION pos)
{
if (proc_backspace == OPT_ONPLUS || (bs_mode == BS_CONTROL && proc_backspace == OPT_OFF))
return store_control_char(ch, rep, pos);
Expand All @@ -1036,7 +1036,7 @@ static int store_bs(LWCHAR ch, char *rep, POSITION pos)
return 0;
}

static int do_append(LWCHAR ch, char *rep, POSITION pos)
static int do_append(LWCHAR ch, constant char *rep, POSITION pos)
{
int a = AT_NORMAL;
int in_overstrike = overstrike;
Expand Down Expand Up @@ -1579,7 +1579,7 @@ static int color_index(int attr)
/*
* Set the color string to use for a given attribute.
*/
public int set_color_map(int attr, char *colorstr)
public int set_color_map(int attr, constant char *colorstr)
{
int cx = color_index(attr);
if (cx < 0)
Expand All @@ -1595,7 +1595,7 @@ public int set_color_map(int attr, char *colorstr)
/*
* Get the color string to use for a given attribute.
*/
public char * get_color_map(int attr)
public constant char * get_color_map(int attr)
{
int cx = color_index(attr);
if (cx < 0)
Expand Down
8 changes: 8 additions & 0 deletions main.c
Original file line number Diff line number Diff line change
Expand Up @@ -508,6 +508,14 @@ public char * skipsp(char *s)
return (s);
}

/* {{ There must be a better way. }} */
public constant char * skipspc(constant char *s)
{
while (*s == ' ' || *s == '\t')
s++;
return (s);
}

/*
* See how many characters of two strings are identical.
* If uppercase is true, the first string must begin with an uppercase
Expand Down
16 changes: 9 additions & 7 deletions screen.c
Original file line number Diff line number Diff line change
Expand Up @@ -2455,18 +2455,20 @@ static int parse_color4(char ch)
/*
* Parse a color as a decimal integer.
*/
static int parse_color6(char **ps)
static int parse_color6(constant char **ps)
{
if (**ps == '-')
{
(*ps)++;
return CV_NOCHANGE;
} else
{
char *ops = *ps;
int color = lstrtoi(ops, ps, 10);
if (color < 0 || *ps == ops)
char *wps = (char *) *ps; /*{{const-issue}}*/
char *ops = wps;
int color = lstrtoi(wps, &wps, 10);
if (color < 0 || wps == ops)
return CV_ERROR;
*ps = (constant char *) wps; /*{{const-issue}}*/
return color;
}
}
Expand All @@ -2477,7 +2479,7 @@ static int parse_color6(char **ps)
* CV_4BIT: fg/bg values are OR of CV_{RGB} bits.
* CV_6BIT: fg/bg values are integers entered by user.
*/
public COLOR_TYPE parse_color(char *str, int *p_fg, int *p_bg)
public COLOR_TYPE parse_color(constant char *str, int *p_fg, int *p_bg)
{
int fg;
int bg;
Expand Down Expand Up @@ -2542,7 +2544,7 @@ static void tput_fmt(char *fmt, int color, int (*f_putc)(int))
attrcolor = color;
}

static void tput_color(char *str, int (*f_putc)(int))
static void tput_color(constant char *str, int (*f_putc)(int))
{
int fg;
int bg;
Expand Down Expand Up @@ -2574,7 +2576,7 @@ static void tput_color(char *str, int (*f_putc)(int))

static void tput_inmode(char *mode_str, int attr, int attr_bit, int (*f_putc)(int))
{
char *color_str;
constant char *color_str;
if ((attr & attr_bit) == 0)
return;
color_str = get_color_map(attr_bit);
Expand Down

0 comments on commit 42e1b42

Please sign in to comment.