diff --git a/edit.c b/edit.c index 9550924f..0c503285 100644 --- a/edit.c +++ b/edit.c @@ -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[] = { @@ -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) @@ -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); @@ -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) @@ -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; diff --git a/evar.c b/evar.c index 9b369e72..27c9edb5 100644 --- a/evar.c +++ b/evar.c @@ -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) { diff --git a/line.c b/line.c index b3408373..e9f7dff1 100644 --- a/line.c +++ b/line.c @@ -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; @@ -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); @@ -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; @@ -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) { @@ -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)) { @@ -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); @@ -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; @@ -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) @@ -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) diff --git a/main.c b/main.c index 87e98260..ec4b680d 100644 --- a/main.c +++ b/main.c @@ -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 diff --git a/screen.c b/screen.c index 3d73dbd5..17401ac5 100644 --- a/screen.c +++ b/screen.c @@ -2455,7 +2455,7 @@ 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 == '-') { @@ -2463,10 +2463,12 @@ static int parse_color6(char **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; } } @@ -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; @@ -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; @@ -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);