aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMarkus F.X.J. Oberhumer <markus@oberhumer.com>2021-03-28 21:16:59 +0200
committerHiltjo Posthuma <hiltjo@codemadness.org>2021-05-06 18:21:10 +0200
commit4536f46cfff50c66a115755def0155d8e246b02f (patch)
tree39339361538ab5ed96cceff78f02ea529a842dd8
parent9e68fdbcdb06dfa3d23fe3a7a7f7b59e40e1ea2f (diff)
downloadst-patched-4536f46cfff50c66a115755def0155d8e246b02f.tar.bz2
st-patched-4536f46cfff50c66a115755def0155d8e246b02f.tar.xz
st-patched-4536f46cfff50c66a115755def0155d8e246b02f.zip
Mild const-correctness improvements.
Only touch a few things, the main focus is to improve code readability.
-rw-r--r--st.c44
-rw-r--r--st.h4
-rw-r--r--x.c6
3 files changed, 28 insertions, 26 deletions
diff --git a/st.c b/st.c
index abbbe4b..ebdf360 100644
--- a/st.c
+++ b/st.c
@@ -186,18 +186,18 @@ static void tputc(Rune);
186static void treset(void); 186static void treset(void);
187static void tscrollup(int, int); 187static void tscrollup(int, int);
188static void tscrolldown(int, int); 188static void tscrolldown(int, int);
189static void tsetattr(int *, int); 189static void tsetattr(const int *, int);
190static void tsetchar(Rune, Glyph *, int, int); 190static void tsetchar(Rune, const Glyph *, int, int);
191static void tsetdirt(int, int); 191static void tsetdirt(int, int);
192static void tsetscroll(int, int); 192static void tsetscroll(int, int);
193static void tswapscreen(void); 193static void tswapscreen(void);
194static void tsetmode(int, int, int *, int); 194static void tsetmode(int, int, const int *, int);
195static int twrite(const char *, int, int); 195static int twrite(const char *, int, int);
196static void tfulldirt(void); 196static void tfulldirt(void);
197static void tcontrolcode(uchar ); 197static void tcontrolcode(uchar );
198static void tdectest(char ); 198static void tdectest(char );
199static void tdefutf8(char); 199static void tdefutf8(char);
200static int32_t tdefcolor(int *, int *, int); 200static int32_t tdefcolor(const int *, int *, int);
201static void tdeftran(char); 201static void tdeftran(char);
202static void tstrsequence(uchar); 202static void tstrsequence(uchar);
203 203
@@ -226,10 +226,10 @@ static int iofd = 1;
226static int cmdfd; 226static int cmdfd;
227static pid_t pid; 227static pid_t pid;
228 228
229static uchar utfbyte[UTF_SIZ + 1] = {0x80, 0, 0xC0, 0xE0, 0xF0}; 229static const uchar utfbyte[UTF_SIZ + 1] = {0x80, 0, 0xC0, 0xE0, 0xF0};
230static uchar utfmask[UTF_SIZ + 1] = {0xC0, 0x80, 0xE0, 0xF0, 0xF8}; 230static const uchar utfmask[UTF_SIZ + 1] = {0xC0, 0x80, 0xE0, 0xF0, 0xF8};
231static Rune utfmin[UTF_SIZ + 1] = { 0, 0, 0x80, 0x800, 0x10000}; 231static const Rune utfmin[UTF_SIZ + 1] = { 0, 0, 0x80, 0x800, 0x10000};
232static Rune utfmax[UTF_SIZ + 1] = {0x10FFFF, 0x7F, 0x7FF, 0xFFFF, 0x10FFFF}; 232static const Rune utfmax[UTF_SIZ + 1] = {0x10FFFF, 0x7F, 0x7FF, 0xFFFF, 0x10FFFF};
233 233
234ssize_t 234ssize_t
235xwrite(int fd, const char *s, size_t len) 235xwrite(int fd, const char *s, size_t len)
@@ -269,12 +269,14 @@ xrealloc(void *p, size_t len)
269} 269}
270 270
271char * 271char *
272xstrdup(char *s) 272xstrdup(const char *s)
273{ 273{
274 if ((s = strdup(s)) == NULL) 274 char *p;
275
276 if ((p = strdup(s)) == NULL)
275 die("strdup: %s\n", strerror(errno)); 277 die("strdup: %s\n", strerror(errno));
276 278
277 return s; 279 return p;
278} 280}
279 281
280size_t 282size_t
@@ -518,7 +520,7 @@ selsnap(int *x, int *y, int direction)
518{ 520{
519 int newx, newy, xt, yt; 521 int newx, newy, xt, yt;
520 int delim, prevdelim; 522 int delim, prevdelim;
521 Glyph *gp, *prevgp; 523 const Glyph *gp, *prevgp;
522 524
523 switch (sel.snap) { 525 switch (sel.snap) {
524 case SNAP_WORD: 526 case SNAP_WORD:
@@ -591,7 +593,7 @@ getsel(void)
591{ 593{
592 char *str, *ptr; 594 char *str, *ptr;
593 int y, bufsize, lastx, linelen; 595 int y, bufsize, lastx, linelen;
594 Glyph *gp, *last; 596 const Glyph *gp, *last;
595 597
596 if (sel.ob.x == -1) 598 if (sel.ob.x == -1)
597 return NULL; 599 return NULL;
@@ -758,7 +760,7 @@ stty(char **args)
758} 760}
759 761
760int 762int
761ttynew(char *line, char *cmd, char *out, char **args) 763ttynew(const char *line, char *cmd, const char *out, char **args)
762{ 764{
763 int m, s; 765 int m, s;
764 766
@@ -1186,9 +1188,9 @@ tmoveto(int x, int y)
1186} 1188}
1187 1189
1188void 1190void
1189tsetchar(Rune u, Glyph *attr, int x, int y) 1191tsetchar(Rune u, const Glyph *attr, int x, int y)
1190{ 1192{
1191 static char *vt100_0[62] = { /* 0x41 - 0x7e */ 1193 static const char *vt100_0[62] = { /* 0x41 - 0x7e */
1192 "↑", "↓", "→", "←", "█", "▚", "☃", /* A - G */ 1194 "↑", "↓", "→", "←", "█", "▚", "☃", /* A - G */
1193 0, 0, 0, 0, 0, 0, 0, 0, /* H - O */ 1195 0, 0, 0, 0, 0, 0, 0, 0, /* H - O */
1194 0, 0, 0, 0, 0, 0, 0, 0, /* P - W */ 1196 0, 0, 0, 0, 0, 0, 0, 0, /* P - W */
@@ -1300,7 +1302,7 @@ tdeleteline(int n)
1300} 1302}
1301 1303
1302int32_t 1304int32_t
1303tdefcolor(int *attr, int *npar, int l) 1305tdefcolor(const int *attr, int *npar, int l)
1304{ 1306{
1305 int32_t idx = -1; 1307 int32_t idx = -1;
1306 uint r, g, b; 1308 uint r, g, b;
@@ -1350,7 +1352,7 @@ tdefcolor(int *attr, int *npar, int l)
1350} 1352}
1351 1353
1352void 1354void
1353tsetattr(int *attr, int l) 1355tsetattr(const int *attr, int l)
1354{ 1356{
1355 int i; 1357 int i;
1356 int32_t idx; 1358 int32_t idx;
@@ -1468,9 +1470,9 @@ tsetscroll(int t, int b)
1468} 1470}
1469 1471
1470void 1472void
1471tsetmode(int priv, int set, int *args, int narg) 1473tsetmode(int priv, int set, const int *args, int narg)
1472{ 1474{
1473 int alt, *lim; 1475 int alt; const int *lim;
1474 1476
1475 for (lim = args + narg; args < lim; ++args) { 1477 for (lim = args + narg; args < lim; ++args) {
1476 if (priv) { 1478 if (priv) {
@@ -2020,7 +2022,7 @@ void
2020tdumpline(int n) 2022tdumpline(int n)
2021{ 2023{
2022 char buf[UTF_SIZ]; 2024 char buf[UTF_SIZ];
2023 Glyph *bp, *end; 2025 const Glyph *bp, *end;
2024 2026
2025 bp = &term.line[n][0]; 2027 bp = &term.line[n][0];
2026 end = &bp[MIN(tlinelen(n), term.col) - 1]; 2028 end = &bp[MIN(tlinelen(n), term.col) - 1];
diff --git a/st.h b/st.h
index 3d351b6..fa2eddf 100644
--- a/st.h
+++ b/st.h
@@ -91,7 +91,7 @@ void tnew(int, int);
91void tresize(int, int); 91void tresize(int, int);
92void tsetdirtattr(int); 92void tsetdirtattr(int);
93void ttyhangup(void); 93void ttyhangup(void);
94int ttynew(char *, char *, char *, char **); 94int ttynew(const char *, char *, const char *, char **);
95size_t ttyread(void); 95size_t ttyread(void);
96void ttyresize(int, int); 96void ttyresize(int, int);
97void ttywrite(const char *, size_t, int); 97void ttywrite(const char *, size_t, int);
@@ -109,7 +109,7 @@ size_t utf8encode(Rune, char *);
109 109
110void *xmalloc(size_t); 110void *xmalloc(size_t);
111void *xrealloc(void *, size_t); 111void *xrealloc(void *, size_t);
112char *xstrdup(char *); 112char *xstrdup(const char *);
113 113
114/* config.h globals */ 114/* config.h globals */
115extern char *utmp; 115extern char *utmp;
diff --git a/x.c b/x.c
index 8bf998e..7186040 100644
--- a/x.c
+++ b/x.c
@@ -156,7 +156,7 @@ static void xresize(int, int);
156static void xhints(void); 156static void xhints(void);
157static int xloadcolor(int, const char *, Color *); 157static int xloadcolor(int, const char *, Color *);
158static int xloadfont(Font *, FcPattern *); 158static int xloadfont(Font *, FcPattern *);
159static void xloadfonts(char *, double); 159static void xloadfonts(const char *, double);
160static void xunloadfont(Font *); 160static void xunloadfont(Font *);
161static void xunloadfonts(void); 161static void xunloadfonts(void);
162static void xsetenv(void); 162static void xsetenv(void);
@@ -952,7 +952,7 @@ xloadfont(Font *f, FcPattern *pattern)
952} 952}
953 953
954void 954void
955xloadfonts(char *fontstr, double fontsize) 955xloadfonts(const char *fontstr, double fontsize)
956{ 956{
957 FcPattern *pattern; 957 FcPattern *pattern;
958 double fontval; 958 double fontval;
@@ -960,7 +960,7 @@ xloadfonts(char *fontstr, double fontsize)
960 if (fontstr[0] == '-') 960 if (fontstr[0] == '-')
961 pattern = XftXlfdParse(fontstr, False, False); 961 pattern = XftXlfdParse(fontstr, False, False);
962 else 962 else
963 pattern = FcNameParse((FcChar8 *)fontstr); 963 pattern = FcNameParse((const FcChar8 *)fontstr);
964 964
965 if (!pattern) 965 if (!pattern)
966 die("can't open font %s\n", fontstr); 966 die("can't open font %s\n", fontstr);