---
st.c | 29 +++++++++++++++--------------
st.h | 10 +++++-----
x.c | 43 ++++++++++++++++++++++---------------------
3 files changed, 42 insertions(+), 40 deletions(-)
diff --git a/st.c b/st.c
index e0e8e65..4cdab8a 100644
--- a/st.c
+++ b/st.c
@@ -151,8 +151,8 @@ typedef struct {
int narg; /* nb of args */
} STREscape;
-static void execsh(char *, char **);
-static void stty(char **);
+static void execsh(const char *, char *const *);
+static void stty(char *const *);
static void sigchld(int);
static void ttywriteraw(const char *, size_t);
@@ -166,7 +166,7 @@ static void strhandle(void);
static void strparse(void);
static void strreset(void);
-static void tprinter(char *, size_t);
+static void tprinter(const char *, size_t);
static void tdumpsel(void);
static void tdumpline(int);
static void tdump(void);
@@ -209,7 +209,7 @@ static void selsnap(int *, int *, int);
static size_t utf8decode(const char *, Rune *, size_t);
static Rune utf8decodebyte(char, size_t *);
static char utf8encodebyte(Rune, size_t);
-static char *utf8strchr(char *, Rune);
+static const char *utf8strchr(const char *, Rune);
static size_t utf8validate(Rune *, size_t);
static char *base64dec(const char *);
@@ -335,8 +335,8 @@ utf8encodebyte(Rune u, size_t i)
return utfbyte[i] | (u & ~utfmask[i]);
}
-char *
-utf8strchr(char *s, Rune u)
+const char *
+utf8strchr(const char *s, Rune u)
{
Rune r;
size_t i, j, len;
@@ -673,9 +673,9 @@ die(const char *errstr, ...)
}
void
-execsh(char *cmd, char **args)
+execsh(const char *cmd, char *const *args)
{
- char *sh, *prog;
+ const char *prog, *sh;
const struct passwd *pw;
errno = 0;
@@ -695,7 +695,7 @@ execsh(char *cmd, char **args)
prog = utmp;
else
prog = sh;
- DEFAULT(args, ((char *[]) {prog, NULL}));
+ DEFAULT(args, ((char *const []){(char *)prog, NULL}));
unsetenv("COLUMNS");
unsetenv("LINES");
@@ -735,9 +735,10 @@ sigchld(int a)
}
void
-stty(char **args)
+stty(char *const *args)
{
- char cmd[_POSIX_ARG_MAX], **p, *q, *s;
+ char cmd[_POSIX_ARG_MAX], *q, *s;
+ char *const *p;
size_t n, siz;
if ((n = strlen(stty_args)) > sizeof(cmd)-1)
@@ -759,7 +760,7 @@ stty(char **args)
}
int
-ttynew(char *line, char *cmd, char *out, char **args)
+ttynew(const char *line, const char *cmd, const char *out, char *const *args)
{
int m, s;
@@ -1194,7 +1195,7 @@ tmoveto(int x, int y)
void
tsetchar(Rune u, Glyph *attr, int x, int y)
{
- static char *vt100_0[62] = { /* 0x41 - 0x7e */
+ static const char *vt100_0[62] = { /* 0x41 - 0x7e */
"↑", "↓", "→", "←", "█", "▚", "☃", /* A - G */
0, 0, 0, 0, 0, 0, 0, 0, /* H - O */
0, 0, 0, 0, 0, 0, 0, 0, /* P - W */
@@ -1958,7 +1959,7 @@ sendbreak(const Arg *arg)
}
void
-tprinter(char *s, size_t len)
+tprinter(const char *s, size_t len)
{
if (iofd != -1 && xwrite(iofd, s, len) < 0) {
perror("Error writing to output file");
diff --git a/st.h b/st.h
index 38c61c4..bc1c717 100644
--- a/st.h
+++ b/st.h
@@ -90,7 +90,7 @@ void tnew(int, int);
void tresize(int, int);
void tsetdirtattr(int);
void ttyhangup(void);
-int ttynew(char *, char *, char *, char **);
+int ttynew(const char *, const char *, const char *, char *const *);
size_t ttyread(void);
void ttyresize(int, int);
void ttywrite(const char *, size_t, int);
@@ -112,11 +112,11 @@ char *xstrdup(char *);
/* config.h globals */
extern char *utmp;
-extern char *stty_args;
-extern char *vtiden;
-extern char *worddelimiters;
+extern const char *stty_args;
+extern const char *vtiden;
+extern const char *worddelimiters;
extern int allowaltscreen;
-extern char *termname;
+extern const char *termname;
extern unsigned int tabspaces;
extern unsigned int defaultfg;
extern unsigned int defaultbg;
diff --git a/x.c b/x.c
index 00cb6b1..af569e5 100644
--- a/x.c
+++ b/x.c
@@ -31,13 +31,13 @@ typedef struct {
typedef struct {
uint b;
uint mask;
- char *s;
+ const char *s;
} MouseShortcut;
typedef struct {
KeySym k;
uint mask;
- char *s;
+ const char *s;
/* three-valued logic variables: 0 indifferent, 1 on, -1 off */
signed char appkey; /* application keypad */
signed char appcursor; /* application cursor */
@@ -145,7 +145,7 @@ static void xresize(int, int);
static void xhints(void);
static int xloadcolor(int, const char *, Color *);
static int xloadfont(Font *, FcPattern *);
-static void xloadfonts(char *, double);
+static void xloadfonts(const char *, double);
static void xunloadfont(Font *);
static void xunloadfonts(void);
static void xsetenv(void);
@@ -170,7 +170,7 @@ static void selrequest(XEvent *);
static void setsel(char *, Time);
static void mousesel(XEvent *, int);
static void mousereport(XEvent *);
-static char *kmap(KeySym, uint);
+static const char *kmap(KeySym, uint);
static int match(uint, uint);
static void run(void);
@@ -225,18 +225,18 @@ typedef struct {
/* Fontcache is an array now. A new font will be appended to the array. */
static Fontcache frc[16];
static int frclen = 0;
-static char *usedfont = NULL;
+static const char *usedfont = NULL;
static double usedfontsize = 0;
static double defaultfontsize = 0;
-static char *opt_class = NULL;
-static char **opt_cmd = NULL;
-static char *opt_embed = NULL;
-static char *opt_font = NULL;
-static char *opt_io = NULL;
-static char *opt_line = NULL;
-static char *opt_name = NULL;
-static char *opt_title = NULL;
+static const 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 int oldbutton = 3; /* button event on startup: 3 = release */
@@ -783,8 +783,8 @@ xclear(int x1, int y1, int x2, int y2)
void
xhints(void)
{
- XClassHint class = {opt_name ? opt_name : termname,
- opt_class ? opt_class : termname};
+ XClassHint class = {opt_name ? (char *)opt_name : (char *)termname,
+ opt_class ? (char *)opt_class : (char *)termname};
XWMHints wm = {.flags = InputHint, .input = 1};
XSizeHints *sizeh;
@@ -905,7 +905,7 @@ xloadfont(Font *f, FcPattern *pattern)
}
void
-xloadfonts(char *fontstr, double fontsize)
+xloadfonts(const char *fontstr, double fontsize)
{
FcPattern *pattern;
double fontval;
@@ -1498,7 +1498,7 @@ void
xsettitle(char *p)
{
XTextProperty prop;
- DEFAULT(p, opt_title);
+ DEFAULT(p, (char *)opt_title);
Xutf8TextListToTextProperty(xw.dpy, &p, 1, XUTF8StringStyle,
&prop);
@@ -1647,7 +1647,7 @@ match(uint mask, uint state)
return mask == XK_ANY_MOD || mask == (state & ~ignoremod);
}
-char*
+const char*
kmap(KeySym k, uint state)
{
Key *kp;
@@ -1663,7 +1663,7 @@ kmap(KeySym k, uint state)
return NULL;
}
- for (kp = key; kp < key + LEN(key); kp++) {
+ for (kp = (Key *)key; kp < key + LEN(key); kp++) {
if (kp->k != k)
continue;
@@ -1689,7 +1689,8 @@ kpress(XEvent *ev)
{
XKeyEvent *e = &ev->xkey;
KeySym ksym;
- char buf[32], *customkey;
+ char buf[32];
+ const char *customkey;
int len;
Rune c;
Status status;
@@ -1700,7 +1701,7 @@ kpress(XEvent *ev)
len = XmbLookupString(xw.xic, e, buf, sizeof buf, &ksym, &status);
/* 1. shortcuts */
- for (bp = shortcuts; bp < shortcuts + LEN(shortcuts); bp++) {
+ for (bp = (Shortcut *)shortcuts; bp < shortcuts + LEN(shortcuts); bp++)
{
if (ksym == bp->keysym && match(bp->mod, e->state)) {
bp->func(&(bp->arg));
return;
--
2.20.1