diff options
| author | Devin J. Pohly <djpohly@gmail.com> | 2018-02-24 16:32:20 -0600 |
|---|---|---|
| committer | Devin J. Pohly <djpohly@gmail.com> | 2018-02-25 21:56:26 -0600 |
| commit | e0215d53770a9b6bc6e5d7b9a603ecd34dbd7100 (patch) | |
| tree | b696b3fa2c69270a198c3bcc1e0a289b12b3538c | |
| parent | 30683c70ab62fd37b5921cf72077b9aef2cb842e (diff) | |
| download | st-e0215d53770a9b6bc6e5d7b9a603ecd34dbd7100.tar.gz st-e0215d53770a9b6bc6e5d7b9a603ecd34dbd7100.zip | |
Reduce visibility wherever possible
When possible, declare functions/variables static and move struct
definitions out of headers. In order to allow utf8decode to become
internal, use codepoint for DECSCUSR extension directly.
Signed-off-by: Devin J. Pohly <djpohly@gmail.com>
| -rw-r--r-- | st.c | 31 | ||||
| -rw-r--r-- | st.h | 40 | ||||
| -rw-r--r-- | win.h | 1 | ||||
| -rw-r--r-- | x.c | 15 |
4 files changed, 43 insertions, 44 deletions
| @@ -36,6 +36,7 @@ | |||
| 36 | 36 | ||
| 37 | /* Arbitrary sizes */ | 37 | /* Arbitrary sizes */ |
| 38 | #define UTF_INVALID 0xFFFD | 38 | #define UTF_INVALID 0xFFFD |
| 39 | #define UTF_SIZ 4 | ||
| 39 | #define ESC_BUF_SIZ (128*UTF_SIZ) | 40 | #define ESC_BUF_SIZ (128*UTF_SIZ) |
| 40 | #define ESC_ARG_SIZ 16 | 41 | #define ESC_ARG_SIZ 16 |
| 41 | #define STR_BUF_SIZ ESC_BUF_SIZ | 42 | #define STR_BUF_SIZ ESC_BUF_SIZ |
| @@ -95,6 +96,31 @@ enum escape_state { | |||
| 95 | ESC_DCS =128, | 96 | ESC_DCS =128, |
| 96 | }; | 97 | }; |
| 97 | 98 | ||
| 99 | typedef struct { | ||
| 100 | Glyph attr; /* current char attributes */ | ||
| 101 | int x; | ||
| 102 | int y; | ||
| 103 | char state; | ||
| 104 | } TCursor; | ||
| 105 | |||
| 106 | typedef struct { | ||
| 107 | int mode; | ||
| 108 | int type; | ||
| 109 | int snap; | ||
| 110 | /* | ||
| 111 | * Selection variables: | ||
| 112 | * nb – normalized coordinates of the beginning of the selection | ||
| 113 | * ne – normalized coordinates of the end of the selection | ||
| 114 | * ob – original coordinates of the beginning of the selection | ||
| 115 | * oe – original coordinates of the end of the selection | ||
| 116 | */ | ||
| 117 | struct { | ||
| 118 | int x, y; | ||
| 119 | } nb, ne, ob, oe; | ||
| 120 | |||
| 121 | int alt; | ||
| 122 | } Selection; | ||
| 123 | |||
| 98 | /* Internal representation of the screen */ | 124 | /* Internal representation of the screen */ |
| 99 | typedef struct { | 125 | typedef struct { |
| 100 | int row; /* nb row */ | 126 | int row; /* nb row */ |
| @@ -187,15 +213,18 @@ static void tstrsequence(uchar); | |||
| 187 | 213 | ||
| 188 | static void drawregion(int, int, int, int); | 214 | static void drawregion(int, int, int, int); |
| 189 | 215 | ||
| 216 | static void selnormalize(void); | ||
| 190 | static void selscroll(int, int); | 217 | static void selscroll(int, int); |
| 191 | static void selsnap(int *, int *, int); | 218 | static void selsnap(int *, int *, int); |
| 192 | 219 | ||
| 220 | static size_t utf8decode(const char *, Rune *, size_t); | ||
| 193 | static Rune utf8decodebyte(char, size_t *); | 221 | static Rune utf8decodebyte(char, size_t *); |
| 194 | static char utf8encodebyte(Rune, size_t); | 222 | static char utf8encodebyte(Rune, size_t); |
| 195 | static char *utf8strchr(char *s, Rune u); | 223 | static char *utf8strchr(char *, Rune); |
| 196 | static size_t utf8validate(Rune *, size_t); | 224 | static size_t utf8validate(Rune *, size_t); |
| 197 | 225 | ||
| 198 | static char *base64dec(const char *); | 226 | static char *base64dec(const char *); |
| 227 | static char base64dec_getc(const char **); | ||
| 199 | 228 | ||
| 200 | static ssize_t xwrite(int, const char *, size_t); | 229 | static ssize_t xwrite(int, const char *, size_t); |
| 201 | 230 | ||
| @@ -1,8 +1,5 @@ | |||
| 1 | /* See LICENSE for license details. */ | 1 | /* See LICENSE for license details. */ |
| 2 | 2 | ||
| 3 | /* Arbitrary sizes */ | ||
| 4 | #define UTF_SIZ 4 | ||
| 5 | |||
| 6 | /* macros */ | 3 | /* macros */ |
| 7 | #define MIN(a, b) ((a) < (b) ? (a) : (b)) | 4 | #define MIN(a, b) ((a) < (b) ? (a) : (b)) |
| 8 | #define MAX(a, b) ((a) < (b) ? (b) : (a)) | 5 | #define MAX(a, b) ((a) < (b) ? (b) : (a)) |
| @@ -69,41 +66,6 @@ typedef struct { | |||
| 69 | 66 | ||
| 70 | typedef Glyph *Line; | 67 | typedef Glyph *Line; |
| 71 | 68 | ||
| 72 | typedef struct { | ||
| 73 | Glyph attr; /* current char attributes */ | ||
| 74 | int x; | ||
| 75 | int y; | ||
| 76 | char state; | ||
| 77 | } TCursor; | ||
| 78 | |||
| 79 | /* Purely graphic info */ | ||
| 80 | typedef struct { | ||
| 81 | int tw, th; /* tty width and height */ | ||
| 82 | int w, h; /* window width and height */ | ||
| 83 | int ch; /* char height */ | ||
| 84 | int cw; /* char width */ | ||
| 85 | int mode; /* window state/mode flags */ | ||
| 86 | int cursor; /* cursor style */ | ||
| 87 | } TermWindow; | ||
| 88 | |||
| 89 | typedef struct { | ||
| 90 | int mode; | ||
| 91 | int type; | ||
| 92 | int snap; | ||
| 93 | /* | ||
| 94 | * Selection variables: | ||
| 95 | * nb – normalized coordinates of the beginning of the selection | ||
| 96 | * ne – normalized coordinates of the end of the selection | ||
| 97 | * ob – original coordinates of the beginning of the selection | ||
| 98 | * oe – original coordinates of the end of the selection | ||
| 99 | */ | ||
| 100 | struct { | ||
| 101 | int x, y; | ||
| 102 | } nb, ne, ob, oe; | ||
| 103 | |||
| 104 | int alt; | ||
| 105 | } Selection; | ||
| 106 | |||
| 107 | typedef union { | 69 | typedef union { |
| 108 | int i; | 70 | int i; |
| 109 | uint ui; | 71 | uint ui; |
| @@ -137,11 +99,9 @@ void selclear(void); | |||
| 137 | void selinit(void); | 99 | void selinit(void); |
| 138 | void selstart(int, int, int); | 100 | void selstart(int, int, int); |
| 139 | void selextend(int, int, int, int); | 101 | void selextend(int, int, int, int); |
| 140 | void selnormalize(void); | ||
| 141 | int selected(int, int); | 102 | int selected(int, int); |
| 142 | char *getsel(void); | 103 | char *getsel(void); |
| 143 | 104 | ||
| 144 | size_t utf8decode(const char *, Rune *, size_t); | ||
| 145 | size_t utf8encode(Rune, char *); | 105 | size_t utf8encode(Rune, char *); |
| 146 | 106 | ||
| 147 | void *xmalloc(size_t); | 107 | void *xmalloc(size_t); |
| @@ -27,7 +27,6 @@ void xbell(void); | |||
| 27 | void xclipcopy(void); | 27 | void xclipcopy(void); |
| 28 | void xdrawcursor(int, int, Glyph, int, int, Glyph); | 28 | void xdrawcursor(int, int, Glyph, int, int, Glyph); |
| 29 | void xdrawline(Line, int, int, int); | 29 | void xdrawline(Line, int, int, int); |
| 30 | void xhints(void); | ||
| 31 | void xfinishdraw(void); | 30 | void xfinishdraw(void); |
| 32 | void xloadcols(void); | 31 | void xloadcols(void); |
| 33 | int xsetcolorname(int, const char *); | 32 | int xsetcolorname(int, const char *); |
| @@ -76,6 +76,15 @@ typedef XftGlyphFontSpec GlyphFontSpec; | |||
| 76 | 76 | ||
| 77 | /* Purely graphic info */ | 77 | /* Purely graphic info */ |
| 78 | typedef struct { | 78 | typedef struct { |
| 79 | int tw, th; /* tty width and height */ | ||
| 80 | int w, h; /* window width and height */ | ||
| 81 | int ch; /* char height */ | ||
| 82 | int cw; /* char width */ | ||
| 83 | int mode; /* window state/mode flags */ | ||
| 84 | int cursor; /* cursor style */ | ||
| 85 | } TermWindow; | ||
| 86 | |||
| 87 | typedef struct { | ||
| 79 | Display *dpy; | 88 | Display *dpy; |
| 80 | Colormap cmap; | 89 | Colormap cmap; |
| 81 | Window win; | 90 | Window win; |
| @@ -133,6 +142,8 @@ static int xgeommasktogravity(int); | |||
| 133 | static void xinit(int, int); | 142 | static void xinit(int, int); |
| 134 | static void cresize(int, int); | 143 | static void cresize(int, int); |
| 135 | static void xresize(int, int); | 144 | static void xresize(int, int); |
| 145 | static void xhints(void); | ||
| 146 | static int xloadcolor(int, const char *, Color *); | ||
| 136 | static int xloadfont(Font *, FcPattern *); | 147 | static int xloadfont(Font *, FcPattern *); |
| 137 | static void xloadfonts(char *, double); | 148 | static void xloadfonts(char *, double); |
| 138 | static void xunloadfont(Font *); | 149 | static void xunloadfont(Font *); |
| @@ -1430,8 +1441,8 @@ xdrawcursor(int cx, int cy, Glyph g, int ox, int oy, Glyph og) | |||
| 1430 | /* draw the new one */ | 1441 | /* draw the new one */ |
| 1431 | if (IS_SET(MODE_FOCUSED)) { | 1442 | if (IS_SET(MODE_FOCUSED)) { |
| 1432 | switch (win.cursor) { | 1443 | switch (win.cursor) { |
| 1433 | case 7: /* st extension: snowman */ | 1444 | case 7: /* st extension: snowman (U+2603) */ |
| 1434 | utf8decode("☃", &g.u, UTF_SIZ); | 1445 | g.u = 0x2603; |
| 1435 | case 0: /* Blinking Block */ | 1446 | case 0: /* Blinking Block */ |
| 1436 | case 1: /* Blinking Block (Default) */ | 1447 | case 1: /* Blinking Block (Default) */ |
| 1437 | case 2: /* Steady Block */ | 1448 | case 2: /* Steady Block */ |
