Skip to content

Commit

Permalink
Some constifying.
Browse files Browse the repository at this point in the history
  • Loading branch information
gwsw committed Nov 6, 2023
1 parent 2f45bca commit 756acc9
Show file tree
Hide file tree
Showing 8 changed files with 56 additions and 52 deletions.
4 changes: 2 additions & 2 deletions decode.c
Original file line number Diff line number Diff line change
Expand Up @@ -248,7 +248,7 @@ static void expand_special_keys(char *table, int len)
char *fm;
char *to;
int a;
char *repl;
constant char *repl;
int klen;

for (fm = table; fm < table + len; )
Expand Down Expand Up @@ -788,7 +788,7 @@ public char * lgetenv_ext(char *var, char *env_buf, int env_buf_len)
/*
* Is a string null or empty?
*/
public int isnullenv(char *s)
public int isnullenv(constant char *s)
{
return (s == NULL || *s == '\0');
}
Expand Down
4 changes: 2 additions & 2 deletions edit.c
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ public void init_textlist(struct textlist *tlist, char *str)
#if SPACES_IN_FILENAMES
int meta_quoted = 0;
int delim_quoted = 0;
char *esc = get_meta_escape();
constant char *esc = get_meta_escape();
int esclen = (int) strlen(esc);
#endif

Expand Down Expand Up @@ -149,7 +149,7 @@ public char * back_textlist(struct textlist *tlist, char *prev)
*/
static void modeline_option(char *str, int opt_len)
{
struct mloption { char *opt_name; void (*opt_func)(char*,int); };
struct mloption { constant char *opt_name; void (*opt_func)(constant char*,int); };
struct mloption options[] = {
{ "ts=", set_tabs },
{ "tabstop=", set_tabs },
Expand Down
2 changes: 1 addition & 1 deletion evar.c
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ static struct replace * make_replaces(char *buf, int len, int *pe, char term)
term = buf[e];
buf[e++] = '\0'; /* terminate the to string */
}
repl = malloc(sizeof(struct replace));
repl = ecalloc(1, sizeof(struct replace));
repl->r_fm = &buf[fm];
repl->r_to = &buf[to];
repl->r_next = replaces;
Expand Down
76 changes: 40 additions & 36 deletions filename.c
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ extern dev_t curr_dev;
/*
* Remove quotes around a filename.
*/
public char * shell_unquote(char *str)
public char * shell_unquote(constant char *str)
{
char *name;
char *p;
Expand All @@ -82,7 +82,7 @@ public char * shell_unquote(char *str)
}
} else
{
char *esc = get_meta_escape();
constant char *esc = get_meta_escape();
int esclen = (int) strlen(esc);
while (*str != '\0')
{
Expand All @@ -98,7 +98,7 @@ public char * shell_unquote(char *str)
/*
* Get the shell's escape character.
*/
public char * get_meta_escape(void)
public constant char * get_meta_escape(void)
{
char *s;

Expand All @@ -111,7 +111,7 @@ public char * get_meta_escape(void)
/*
* Get the characters which the shell considers to be "metacharacters".
*/
static char * metachars(void)
static constant char * metachars(void)
{
static char *mchars = NULL;

Expand All @@ -135,12 +135,13 @@ static int metachar(char c)
/*
* Insert a backslash before each metacharacter in a string.
*/
public char * shell_quote(char *s)
public char * shell_quote(constant char *s)
{
char *p;
constant char *p;
char *np;
char *newstr;
int len;
char *esc = get_meta_escape();
constant char *esc = get_meta_escape();
int esclen = (int) strlen(esc);
int use_quotes = 0;
int have_quotes = 0;
Expand Down Expand Up @@ -184,7 +185,7 @@ public char * shell_quote(char *s)
/*
* Allocate and construct the new string.
*/
newstr = p = (char *) ecalloc(len, sizeof(char));
newstr = np = (char *) ecalloc(len, sizeof(char));
if (use_quotes)
{
SNPRINTF3(newstr, len, "%c%s%c", openquote, s, closequote);
Expand All @@ -197,12 +198,12 @@ public char * shell_quote(char *s)
/*
* Add the escape char.
*/
strcpy(p, esc);
p += esclen;
strcpy(np, esc);
np += esclen;
}
*p++ = *s++;
*np++ = *s++;
}
*p = '\0';
*np = '\0';
}
return (newstr);
}
Expand All @@ -211,7 +212,7 @@ public char * shell_quote(char *s)
* Return a pathname that points to a specified file in a specified directory.
* Return NULL if the file does not exist in the directory.
*/
public char * dirfile(char *dirname, char *filename, int must_exist)
public char * dirfile(constant char *dirname, constant char *filename, int must_exist)
{
char *pathname;
int len;
Expand Down Expand Up @@ -248,7 +249,7 @@ public char * dirfile(char *dirname, char *filename, int must_exist)
/*
* Return the full pathname of the given file in the "home directory".
*/
public char * homefile(char *filename)
public char * homefile(constant char *filename)
{
char *pathname;

Expand Down Expand Up @@ -290,9 +291,10 @@ public char * homefile(char *filename)
* Likewise for a string of N "#"s.
* {{ This is a lot of work just to support % and #. }}
*/
public char * fexpand(char *s)
public char * fexpand(constant char *s)
{
char *fr, *to;
constant char *fr;
char *to;
int n;
char *e;
IFILE ifile;
Expand Down Expand Up @@ -384,10 +386,11 @@ public char * fexpand(char *s)
* Return a blank-separated list of filenames which "complete"
* the given string.
*/
public char * fcomplete(char *s)
public char * fcomplete(constant char *s)
{
char *fpat;
char *qs;
char *uqs;

/* {{ Is this needed? lglob calls secure_allow. }} */
if (!secure_allow(SF_GLOB))
Expand All @@ -404,7 +407,7 @@ public char * fcomplete(char *s)
* but "FILE.A" is globbed as "FILE.A*").
*/
{
char *slash;
constant char *slash;
int len;
for (slash = s+strlen(s)-1; slash > s; slash--)
if (*slash == *PATHNAME_SEP || *slash == '/')
Expand All @@ -424,16 +427,16 @@ public char * fcomplete(char *s)
}
#endif
qs = lglob(fpat);
s = shell_unquote(qs);
if (strcmp(s,fpat) == 0)
uqs = shell_unquote(qs);
if (strcmp(uqs, fpat) == 0)
{
/*
* The filename didn't expand.
*/
free(qs);
qs = NULL;
}
free(s);
free(uqs);
free(fpat);
return (qs);
}
Expand Down Expand Up @@ -543,7 +546,7 @@ static char * readfd(FILE *fd)
* Execute a shell command.
* Return a pointer to a pipe connected to the shell command's standard output.
*/
static FILE * shellcmd(char *cmd)
static FILE * shellcmd(constant char *cmd)
{
FILE *fd;

Expand Down Expand Up @@ -711,17 +714,18 @@ public char * lglob(char *filename)
* an "echo" command to the shell and reading its output.
*/
FILE *fd;
char *s;
char *lessecho;
constant char *s;
constant char *lessecho;
char *cmd;
char *esc;
constant char *esc;
char *qesc;
int len;

esc = get_meta_escape();
if (strlen(esc) == 0)
esc = "-";
esc = shell_quote(esc);
if (esc == NULL)
qesc = shell_quote(esc);
if (qesc == NULL)
{
return (filename);
}
Expand All @@ -734,8 +738,8 @@ public char * lglob(char *filename)
len = (int) (strlen(lessecho) + strlen(filename) + (7*strlen(metachars())) + 24);
cmd = (char *) ecalloc(len, sizeof(char));
SNPRINTF4(cmd, len, "%s -p0x%x -d0x%x -e%s ", lessecho,
(unsigned char) openquote, (unsigned char) closequote, esc);
free(esc);
(unsigned char) openquote, (unsigned char) closequote, qesc);
free(qesc);
for (s = metachars(); *s != '\0'; s++)
sprintf(cmd + strlen(cmd), "-n0x%x ", (unsigned char) *s);
sprintf(cmd + strlen(cmd), "-- %s", filename);
Expand Down Expand Up @@ -772,7 +776,7 @@ public char * lglob(char *filename)
/*
* Does path not represent something in the file system?
*/
public int is_fake_pathname(char *path)
public int is_fake_pathname(constant char *path)
{
return (strcmp(path, "-") == 0 ||
strcmp(path, FAKE_HELPFILE) == 0 || strcmp(path, FAKE_EMPTYFILE) == 0);
Expand All @@ -781,7 +785,7 @@ public int is_fake_pathname(char *path)
/*
* Return canonical pathname.
*/
public char * lrealpath(char *path)
public char * lrealpath(constant char *path)
{
if (!is_fake_pathname(path))
{
Expand All @@ -799,7 +803,7 @@ public char * lrealpath(char *path)
* Return number of %s escapes in a string.
* Return a large number if there are any other % escapes besides %s.
*/
static int num_pct_s(char *lessopen)
static int num_pct_s(constant char *lessopen)
{
int num = 0;

Expand All @@ -824,7 +828,7 @@ static int num_pct_s(char *lessopen)
* See if we should open a "replacement file"
* instead of the file we're about to open.
*/
public char * open_altfile(char *filename, int *pf, void **pfd)
public char * open_altfile(constant char *filename, int *pf, void **pfd)
{
#if !HAVE_POPEN
return (NULL);
Expand Down Expand Up @@ -947,7 +951,7 @@ public char * open_altfile(char *filename, int *pf, void **pfd)
/*
* Close a replacement file.
*/
public void close_altfile(char *altfilename, char *filename)
public void close_altfile(constant char *altfilename, constant char *filename)
{
#if HAVE_POPEN
char *lessclose;
Expand Down Expand Up @@ -984,7 +988,7 @@ public void close_altfile(char *altfilename, char *filename)
/*
* Is the specified file a directory?
*/
public int is_dir(char *filename)
public int is_dir(constant char *filename)
{
int isdir = 0;

Expand Down Expand Up @@ -1016,7 +1020,7 @@ public int is_dir(char *filename)
* is an ordinary file, otherwise an error message
* (if it cannot be opened or is a directory, etc.)
*/
public char * bad_file(char *filename)
public char * bad_file(constant char *filename)
{
char *m = NULL;

Expand Down
4 changes: 2 additions & 2 deletions optfunc.c
Original file line number Diff line number Diff line change
Expand Up @@ -688,10 +688,10 @@ public void opt_D(int type, char *s)

/*
*/
public void set_tabs(char *s, int len)
public void set_tabs(constant char *s, int len)
{
int i;
char *es = s + len;
constant char *es = s + len;
/* Start at 1 because tabstops[0] is always zero. */
for (i = 1; i < TABSTOP_MAX; )
{
Expand Down
2 changes: 1 addition & 1 deletion os.c
Original file line number Diff line number Diff line change
Expand Up @@ -359,7 +359,7 @@ static char * strerror(int err)
/*
* errno_message: Return an error message based on the value of "errno".
*/
public char * errno_message(char *filename)
public char * errno_message(constant char *filename)
{
char *p;
char *m;
Expand Down
14 changes: 7 additions & 7 deletions output.c
Original file line number Diff line number Diff line change
Expand Up @@ -517,9 +517,9 @@ IPRINT_FUNC(iprint_linenum, LINENUM, linenumtoa)
* {{ This paranoia about the portability of printf dates from experiences
* with systems in the 1980s and is of course no longer necessary. }}
*/
public int less_printf(char *fmt, PARG *parg)
public int less_printf(constant char *fmt, PARG *parg)
{
char *s;
constant char *s;
int col;

col = 0;
Expand Down Expand Up @@ -596,7 +596,7 @@ public void get_return(void)
* Output a message in the lower left corner of the screen
* and wait for carriage return.
*/
public void error(char *fmt, PARG *parg)
public void error(constant char *fmt, PARG *parg)
{
int col = 0;
static char return_to_continue[] = " (press RETURN)";
Expand Down Expand Up @@ -642,7 +642,7 @@ public void error(char *fmt, PARG *parg)
* Usually used to warn that we are beginning a potentially
* time-consuming operation.
*/
static void ierror_suffix(char *fmt, PARG *parg, char *suffix1, char *suffix2, char *suffix3)
static void ierror_suffix(constant char *fmt, PARG *parg, constant char *suffix1, constant char *suffix2, constant char *suffix3)
{
at_exit();
clear_bot();
Expand All @@ -656,12 +656,12 @@ static void ierror_suffix(char *fmt, PARG *parg, char *suffix1, char *suffix2, c
need_clr = 1;
}

public void ierror(char *fmt, PARG *parg)
public void ierror(constant char *fmt, PARG *parg)
{
ierror_suffix(fmt, parg, "... (interrupt to abort)", "", "");
}

public void ixerror(char *fmt, PARG *parg)
public void ixerror(constant char *fmt, PARG *parg)
{
if (!supports_ctrl_x())
ierror(fmt, parg);
Expand All @@ -674,7 +674,7 @@ public void ixerror(char *fmt, PARG *parg)
* Output a message in the lower left corner of the screen
* and return a single-character response.
*/
public int query(char *fmt, PARG *parg)
public int query(constant char *fmt, PARG *parg)
{
int c;
int col = 0;
Expand Down
2 changes: 1 addition & 1 deletion screen.c
Original file line number Diff line number Diff line change
Expand Up @@ -955,7 +955,7 @@ static void delay(int msec)
/*
* Return the characters actually input by a "special" key.
*/
public char * special_key_str(int key)
public constant char * special_key_str(int key)
{
static char tbuf[40];
char *s;
Expand Down

0 comments on commit 756acc9

Please sign in to comment.