diff options
| author | Markus F.X.J. Oberhumer <markus@oberhumer.com> | 2021-03-28 21:16:59 +0200 |
|---|---|---|
| committer | Hiltjo Posthuma <hiltjo@codemadness.org> | 2021-05-06 18:21:10 +0200 |
| commit | 4536f46cfff50c66a115755def0155d8e246b02f (patch) | |
| tree | 39339361538ab5ed96cceff78f02ea529a842dd8 /st.c | |
| parent | fix: correctly encode mouse buttons >= 8 in X10 and SGR mode (diff) | |
| download | st-4536f46cfff50c66a115755def0155d8e246b02f.tar.gz st-4536f46cfff50c66a115755def0155d8e246b02f.zip | |
Mild const-correctness improvements.
Only touch a few things, the main focus is to
improve code readability.
Diffstat (limited to '')
| -rw-r--r-- | st.c | 44 |
1 files changed, 23 insertions, 21 deletions
| @@ -186,18 +186,18 @@ static void tputc(Rune); | |||
| 186 | static void treset(void); | 186 | static void treset(void); |
| 187 | static void tscrollup(int, int); | 187 | static void tscrollup(int, int); |
| 188 | static void tscrolldown(int, int); | 188 | static void tscrolldown(int, int); |
| 189 | static void tsetattr(int *, int); | 189 | static void tsetattr(const int *, int); |
| 190 | static void tsetchar(Rune, Glyph *, int, int); | 190 | static void tsetchar(Rune, const Glyph *, int, int); |
| 191 | static void tsetdirt(int, int); | 191 | static void tsetdirt(int, int); |
| 192 | static void tsetscroll(int, int); | 192 | static void tsetscroll(int, int); |
| 193 | static void tswapscreen(void); | 193 | static void tswapscreen(void); |
| 194 | static void tsetmode(int, int, int *, int); | 194 | static void tsetmode(int, int, const int *, int); |
| 195 | static int twrite(const char *, int, int); | 195 | static int twrite(const char *, int, int); |
| 196 | static void tfulldirt(void); | 196 | static void tfulldirt(void); |
| 197 | static void tcontrolcode(uchar ); | 197 | static void tcontrolcode(uchar ); |
| 198 | static void tdectest(char ); | 198 | static void tdectest(char ); |
| 199 | static void tdefutf8(char); | 199 | static void tdefutf8(char); |
| 200 | static int32_t tdefcolor(int *, int *, int); | 200 | static int32_t tdefcolor(const int *, int *, int); |
| 201 | static void tdeftran(char); | 201 | static void tdeftran(char); |
| 202 | static void tstrsequence(uchar); | 202 | static void tstrsequence(uchar); |
| 203 | 203 | ||
| @@ -226,10 +226,10 @@ static int iofd = 1; | |||
| 226 | static int cmdfd; | 226 | static int cmdfd; |
| 227 | static pid_t pid; | 227 | static pid_t pid; |
| 228 | 228 | ||
| 229 | static uchar utfbyte[UTF_SIZ + 1] = {0x80, 0, 0xC0, 0xE0, 0xF0}; | 229 | static const uchar utfbyte[UTF_SIZ + 1] = {0x80, 0, 0xC0, 0xE0, 0xF0}; |
| 230 | static uchar utfmask[UTF_SIZ + 1] = {0xC0, 0x80, 0xE0, 0xF0, 0xF8}; | 230 | static const uchar utfmask[UTF_SIZ + 1] = {0xC0, 0x80, 0xE0, 0xF0, 0xF8}; |
| 231 | static Rune utfmin[UTF_SIZ + 1] = { 0, 0, 0x80, 0x800, 0x10000}; | 231 | static const Rune utfmin[UTF_SIZ + 1] = { 0, 0, 0x80, 0x800, 0x10000}; |
| 232 | static Rune utfmax[UTF_SIZ + 1] = {0x10FFFF, 0x7F, 0x7FF, 0xFFFF, 0x10FFFF}; | 232 | static const Rune utfmax[UTF_SIZ + 1] = {0x10FFFF, 0x7F, 0x7FF, 0xFFFF, 0x10FFFF}; |
| 233 | 233 | ||
| 234 | ssize_t | 234 | ssize_t |
| 235 | xwrite(int fd, const char *s, size_t len) | 235 | xwrite(int fd, const char *s, size_t len) |
| @@ -269,12 +269,14 @@ xrealloc(void *p, size_t len) | |||
| 269 | } | 269 | } |
| 270 | 270 | ||
| 271 | char * | 271 | char * |
| 272 | xstrdup(char *s) | 272 | xstrdup(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 | ||
| 280 | size_t | 282 | size_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 | ||
| 760 | int | 762 | int |
| 761 | ttynew(char *line, char *cmd, char *out, char **args) | 763 | ttynew(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 | ||
| 1188 | void | 1190 | void |
| 1189 | tsetchar(Rune u, Glyph *attr, int x, int y) | 1191 | tsetchar(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 | ||
| 1302 | int32_t | 1304 | int32_t |
| 1303 | tdefcolor(int *attr, int *npar, int l) | 1305 | tdefcolor(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 | ||
| 1352 | void | 1354 | void |
| 1353 | tsetattr(int *attr, int l) | 1355 | tsetattr(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 | ||
| 1470 | void | 1472 | void |
| 1471 | tsetmode(int priv, int set, int *args, int narg) | 1473 | tsetmode(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 | |||
| 2020 | tdumpline(int n) | 2022 | tdumpline(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]; |
