Skip to content

Commit 7ee4f57

Browse files
committed
Mild const-correctness improvements.
Only touch a few things, the main focus is to improve code readability. Reference: https://git.suckless.org/st/commit/4536f46cfff50c66a115755def0155d8e246b02f.html
1 parent a145f91 commit 7ee4f57

File tree

3 files changed

+27
-24
lines changed

3 files changed

+27
-24
lines changed

st.c

Lines changed: 22 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -198,18 +198,18 @@ static void tputc(Rune);
198198
static void treset(void);
199199
static void tscrollup(int, int);
200200
static void tscrolldown(int, int);
201-
static void tsetattr(int *, int);
202-
static void tsetchar(Rune, Glyph *, int, int);
201+
static void tsetattr(const int *, int);
202+
static void tsetchar(Rune, const Glyph *, int, int);
203203
static void tsetdirt(int, int);
204204
static void tsetscroll(int, int);
205205
static void tswapscreen(void);
206-
static void tsetmode(int, int, int *, int);
206+
static void tsetmode(int, int, const int *, int);
207207
static int twrite(const char *, int, int);
208208
static void tfulldirt(void);
209209
static void tcontrolcode(uchar );
210210
static void tdectest(char );
211211
static void tdefutf8(char);
212-
static int32_t tdefcolor(int *, int *, int);
212+
static int32_t tdefcolor(const int *, int *, int);
213213
static void tdeftran(char);
214214
static void tstrsequence(uchar);
215215
static void tsetcolor(int, int, int, uint32_t, uint32_t);
@@ -241,10 +241,10 @@ static int iofd = 1;
241241
static int cmdfd;
242242
static pid_t pid;
243243

244-
static uchar utfbyte[UTF_SIZ + 1] = { 0x80, 0, 0xC0, 0xE0, 0xF0};
245-
static uchar utfmask[UTF_SIZ + 1] = { 0xC0, 0x80, 0xE0, 0xF0, 0xF8};
246-
static Rune utfmin[UTF_SIZ + 1] = { 0, 0, 0x80, 0x800, 0x10000};
247-
static Rune utfmax[UTF_SIZ + 1] = {0x10FFFF, 0x7F, 0x7FF, 0xFFFF, 0x10FFFF};
244+
static const uchar utfbyte[UTF_SIZ + 1] = { 0x80, 0, 0xC0, 0xE0, 0xF0};
245+
static const uchar utfmask[UTF_SIZ + 1] = { 0xC0, 0x80, 0xE0, 0xF0, 0xF8};
246+
static const Rune utfmin[UTF_SIZ + 1] = { 0, 0, 0x80, 0x800, 0x10000};
247+
static const Rune utfmax[UTF_SIZ + 1] = {0x10FFFF, 0x7F, 0x7FF, 0xFFFF, 0x10FFFF};
248248

249249
int buffCols;
250250

@@ -301,12 +301,14 @@ xrealloc(void *p, size_t len)
301301
}
302302

303303
char *
304-
xstrdup(char *s)
304+
xstrdup(const char *s)
305305
{
306-
if ((s = strdup(s)) == NULL)
306+
char *p;
307+
308+
if ((p = strdup(s)) == NULL)
307309
die("strdup: %s\n", strerror(errno));
308310

309-
return s;
311+
return p;
310312
}
311313

312314
size_t
@@ -823,7 +825,7 @@ stty(char **args)
823825
}
824826

825827
int
826-
ttynew(char *line, char *cmd, char *out, char **args)
828+
ttynew(const char *line, char *cmd, const char *out, char **args)
827829
{
828830
int m, s;
829831

@@ -1273,9 +1275,9 @@ tmoveto(int x, int y)
12731275
}
12741276

12751277
void
1276-
tsetchar(Rune u, Glyph *attr, int x, int y)
1278+
tsetchar(Rune u, const Glyph *attr, int x, int y)
12771279
{
1278-
static char *vt100_0[62] = { /* 0x41 - 0x7e */
1280+
static const char *vt100_0[62] = { /* 0x41 - 0x7e */
12791281
"↑", "↓", "→", "←", "█", "▚", "☃", /* A - G */
12801282
0, 0, 0, 0, 0, 0, 0, 0, /* H - O */
12811283
0, 0, 0, 0, 0, 0, 0, 0, /* P - W */
@@ -1387,7 +1389,7 @@ tdeleteline(int n)
13871389
}
13881390

13891391
int32_t
1390-
tdefcolor(int *attr, int *npar, int l)
1392+
tdefcolor(const int *attr, int *npar, int l)
13911393
{
13921394
int32_t idx = -1;
13931395
uint r, g, b;
@@ -1439,7 +1441,7 @@ tdefcolor(int *attr, int *npar, int l)
14391441
}
14401442

14411443
void
1442-
tsetattr(int *attr, int l)
1444+
tsetattr(const int *attr, int l)
14431445
{
14441446
int i;
14451447
int32_t idx;
@@ -1557,9 +1559,10 @@ tsetscroll(int t, int b)
15571559
}
15581560

15591561
void
1560-
tsetmode(int priv, int set, int *args, int narg)
1562+
tsetmode(int priv, int set, const int *args, int narg)
15611563
{
1562-
int alt, *lim;
1564+
int alt;
1565+
const int *lim;
15631566

15641567
for (lim = args + narg; args < lim; ++args) {
15651568
if (priv) {
@@ -2109,7 +2112,7 @@ void
21092112
tdumpline(int n)
21102113
{
21112114
char buf[UTF_SIZ];
2112-
Glyph *bp, *end;
2115+
const Glyph *bp, *end;
21132116

21142117
bp = &term.line[n][0];
21152118
end = &bp[MIN(tlinelen(n), term.col) - 1];

st.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -103,7 +103,7 @@ void tresize(int, int);
103103
void tmoveto(int x, int y);
104104
void tsetdirtattr(int);
105105
void ttyhangup(void);
106-
int ttynew(char *, char *, char *, char **);
106+
int ttynew(const char *, char *, const char *, char **);
107107
size_t ttyread(void);
108108
void ttyresize(int, int);
109109
void ttywrite(const char *, size_t, int);
@@ -121,7 +121,7 @@ size_t utf8encode(Rune, char *);
121121

122122
void *xmalloc(size_t);
123123
void *xrealloc(void *, size_t);
124-
char *xstrdup(char *);
124+
char *xstrdup(const char *);
125125

126126
/*
127127
* config.h globals

x.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -176,7 +176,7 @@ static void xresize(int, int);
176176
static void xhints(void);
177177
static int xloadcolor(int, const char *, Color *);
178178
static int xloadfont(Font *, FcPattern *);
179-
static void xloadfonts(char *, double);
179+
static void xloadfonts(const char *, double);
180180
static void xunloadfont(Font *);
181181
static void xunloadfonts(void);
182182
static void xsetenv(void);
@@ -988,15 +988,15 @@ xloadfont(Font *f, FcPattern *pattern)
988988
}
989989

990990
void
991-
xloadfonts(char *fontstr, double fontsize)
991+
xloadfonts(const char *fontstr, double fontsize)
992992
{
993993
FcPattern *pattern;
994994
double fontval;
995995

996996
if (fontstr[0] == '-')
997997
pattern = XftXlfdParse(fontstr, False, False);
998998
else
999-
pattern = FcNameParse((FcChar8 *)fontstr);
999+
pattern = FcNameParse((const FcChar8 *)fontstr);
10001000

10011001
if (!pattern)
10021002
die("can't open font %s\n", fontstr);

0 commit comments

Comments
 (0)