---
config.def.h | 4 ++--
st.c | 37 ++++++++++++++++---------------------
st.h | 6 +++---
x.c | 24 +++++++++++-------------
4 files changed, 32 insertions(+), 39 deletions(-)
diff --git a/config.def.h b/config.def.h
index 6fb91b3..b5a4450 100644
--- a/config.def.h
+++ b/config.def.h
@@ -16,7 +16,7 @@ static int borderpx = 2;
* 4: value of shell in /etc/passwd
* 5: value of shell in config.h
*/
-static const char *shell = "/bin/sh";
+static char shell[] = "/bin/sh";
char *utmp = NULL;
const char *stty_args = "stty raw pass8 nl -echo -iexten -cstopb 38400";
@@ -69,7 +69,7 @@ static unsigned int cursorthickness = 2;
static int bellvolume = 0;
/* default TERM value */
-const char *termname = "st-256color";
+char termname[] = "st-256color";
/*
* spaces per tab
diff --git a/st.c b/st.c
index 236c92b..5a8cdcc 100644
--- a/st.c
+++ b/st.c
@@ -151,7 +151,7 @@ typedef struct {
int narg; /* nb of args */
} STREscape;
-static void execsh(const char *, char *const *);
+static void execsh(char *, char *const *);
static void stty(char *const *);
static void sigchld(int);
static void ttywriteraw(const char *, size_t);
@@ -273,14 +273,12 @@ xrealloc(void *p, size_t len)
}
char *
-xstrdup(char *s)
+xstrdup(const char *s)
{
char *tmp = strdup(s);
- if (tmp == NULL) {
- free(s);
+ if (tmp == NULL)
die("strdup: %s\n", strerror(errno));
- }
return tmp;
}
@@ -608,7 +606,8 @@ char *
getsel(void)
{
char *str, *ptr;
- int y, bufsize;
+ int y;
+ size_t bufsize;
if (sel.ob.x == -1)
return NULL;
@@ -682,9 +681,9 @@ die(const char *errstr, ...)
}
void
-execsh(const char *cmd, char *const *args)
+execsh(char *cmd, char *const *args)
{
- const char *prog, *sh;
+ char *sh;
const struct passwd *pw;
errno = 0;
@@ -695,23 +694,19 @@ execsh(const char *cmd, char *const *args)
die("who are you?\n");
}
- if ((sh = getenv("SHELL")) == NULL)
+ if ((sh = getenv("SHELL")) == NULL) {
sh = (pw->pw_shell[0]) ? pw->pw_shell : cmd;
+ setenv("SHELL", sh, 1);
+ }
- if (args)
- prog = args[0];
- else if (utmp)
- prog = utmp;
- else
- prog = sh;
- DEFAULT(args, ((char *const []){(char *)prog, NULL}));
+ char *const prog = args ? *args : utmp ? utmp : sh;
+ DEFAULT(args, ((char *const []){prog, NULL}));
unsetenv("COLUMNS");
unsetenv("LINES");
unsetenv("TERMCAP");
setenv("LOGNAME", pw->pw_name, 1);
setenv("USER", pw->pw_name, 1);
- setenv("SHELL", sh, 1);
setenv("HOME", pw->pw_dir, 1);
setenv("TERM", termname, 1);
@@ -769,7 +764,7 @@ stty(char *const *args)
}
int
-ttynew(const char *line, const char *cmd, const char *out, char *const *args)
+ttynew(const char *line, char *cmd, const char *out, char *const *args)
{
int m, s;
@@ -835,12 +830,12 @@ ttyread(void)
static char buf[BUFSIZ];
static size_t buflen = 0;
size_t written;
- int ret;
+ ssize_t ret;
/* append read bytes to unprocessed bytes */
if ((ret = read(cmdfd, buf+buflen, LEN(buf)-buflen)) < 0)
die("couldn't read from shell: %s\n", strerror(errno));
- buflen += ret;
+ buflen += (size_t)ret;
written = twrite(buf, buflen, 0);
buflen -= written;
@@ -848,7 +843,7 @@ ttyread(void)
if (buflen > 0)
memmove(buf, buf + written, buflen);
- return ret;
+ return (size_t)ret;
}
void
diff --git a/st.h b/st.h
index 506926f..0aa01d8 100644
--- a/st.h
+++ b/st.h
@@ -104,7 +104,7 @@ void tnew(int, int);
void tresize(int, int);
void tsetdirtattr(int);
void ttyhangup(void);
-int ttynew(const char *, const char *, const char *, char *const *);
+int ttynew(const char *, char *, const char *, char *const *);
size_t ttyread(void);
void ttyresize(int, int);
void ttywrite(const char *, size_t, int);
@@ -122,7 +122,7 @@ size_t utf8encode(Rune, char *);
void *xmalloc(size_t);
void *xrealloc(void *, size_t);
-char *xstrdup(char *);
+char *xstrdup(const char *);
/* config.h globals */
extern char *utmp;
@@ -130,7 +130,7 @@ extern const char *stty_args;
extern const char *vtiden;
extern const char *worddelimiters;
extern int allowaltscreen;
-extern const char *termname;
+extern char termname[];
extern unsigned int tabspaces;
extern unsigned int defaultfg;
extern unsigned int defaultbg;
diff --git a/x.c b/x.c
index f886109..9e9bd3e 100644
--- a/x.c
+++ b/x.c
@@ -232,14 +232,14 @@ static const char *usedfont = NULL;
static double usedfontsize = 0;
static double defaultfontsize = 0;
-static const char *opt_class = NULL;
+static char *opt_class = NULL;
static char *const *opt_cmd = NULL;
static const char *opt_embed = NULL;
static const char *opt_font = NULL;
static const char *opt_io = NULL;
static const char *opt_line = NULL;
-static const char *opt_name = NULL;
-static const char *opt_title = NULL;
+static char *opt_name = NULL;
+static char *opt_title = NULL;
static int oldbutton = 3; /* button event on startup: 3 = release */
@@ -789,8 +789,8 @@ xclear(int x1, int y1, int x2, int y2)
void
xhints(void)
{
- XClassHint class = {opt_name ? (char *)opt_name : (char *)termname,
- opt_class ? (char *)opt_class : (char *)termname};
+ XClassHint class = {opt_name ? opt_name : (char *)termname,
+ opt_class ? opt_class : (char *)termname};
XWMHints wm = {.flags = InputHint, .input = 1};
XSizeHints *sizeh;
@@ -919,7 +919,7 @@ xloadfonts(const char *fontstr, double fontsize)
if (fontstr[0] == '-')
pattern = XftXlfdParse(fontstr, False, False);
else
- pattern = FcNameParse((FcChar8 *)fontstr);
+ pattern = FcNameParse((const FcChar8 *)fontstr);
if (!pattern)
die("can't open font %s\n", fontstr);
@@ -1504,10 +1504,8 @@ void
xsettitle(char *p)
{
XTextProperty prop;
- DEFAULT(p, (char *)opt_title);
-
- Xutf8TextListToTextProperty(xw.dpy, &p, 1, XUTF8StringStyle,
- &prop);
+ DEFAULT(p, opt_title);
+ Xutf8TextListToTextProperty(xw.dpy, &p, 1, XUTF8StringStyle, &prop);
XSetWMName(xw.dpy, xw.win, &prop);
XSetTextProperty(xw.dpy, xw.win, &prop, xw.netwmname);
XFree(prop.value);
@@ -1699,14 +1697,14 @@ kpress(XEvent *ev)
const char *customkey;
int len;
Status status;
- Shortcut *bp;
+ const Shortcut *bp;
if (IS_SET(MODE_KBDLOCK))
return;
len = XmbLookupString(xw.xic, e, buf, sizeof buf, &ksym, &status);
/* 1. shortcuts */
- for (bp = (Shortcut *)shortcuts; bp < shortcuts + LEN(shortcuts); bp++)
{
+ for (bp = shortcuts; bp < shortcuts + LEN(shortcuts); bp++) {
if (ksym == bp->keysym && match(bp->mod, e->state)) {
bp->func(&(bp->arg));
return;
@@ -1944,7 +1942,7 @@ run:
opt_cmd = argv;
if (!opt_title)
- opt_title = (opt_line || !opt_cmd) ? "st" : opt_cmd[0];
+ opt_title = (opt_line || !opt_cmd) ? argv0 : opt_cmd[0];
setlocale(LC_CTYPE, "");
XSetLocaleModifiers("");
--
2.20.1