[hackers] [st] Reduce visibility wherever possible || Devin J. Pohly

From: <git_AT_suckless.org>
Date: Fri, 9 Mar 2018 15:37:40 +0100 (CET)

commit e0215d53770a9b6bc6e5d7b9a603ecd34dbd7100
Author: Devin J. Pohly <djpohly_AT_gmail.com>
AuthorDate: Sat Feb 24 16:32:20 2018 -0600
Commit: Devin J. Pohly <djpohly_AT_gmail.com>
CommitDate: Sun Feb 25 21:56:26 2018 -0600

    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_AT_gmail.com>

diff --git a/st.c b/st.c
index ce32cc0..f46aab6 100644
--- a/st.c
+++ b/st.c
_AT_@ -36,6 +36,7 @@
 
 /* Arbitrary sizes */
 #define UTF_INVALID 0xFFFD
+#define UTF_SIZ 4
 #define ESC_BUF_SIZ (128*UTF_SIZ)
 #define ESC_ARG_SIZ 16
 #define STR_BUF_SIZ ESC_BUF_SIZ
_AT_@ -95,6 +96,31 @@ enum escape_state {
         ESC_DCS =128,
 };
 
+typedef struct {
+ Glyph attr; /* current char attributes */
+ int x;
+ int y;
+ char state;
+} TCursor;
+
+typedef struct {
+ int mode;
+ int type;
+ int snap;
+ /*
+ * Selection variables:
+ * nb – normalized coordinates of the beginning of the selection
+ * ne – normalized coordinates of the end of the selection
+ * ob – original coordinates of the beginning of the selection
+ * oe – original coordinates of the end of the selection
+ */
+ struct {
+ int x, y;
+ } nb, ne, ob, oe;
+
+ int alt;
+} Selection;
+
 /* Internal representation of the screen */
 typedef struct {
         int row; /* nb row */
_AT_@ -187,15 +213,18 @@ static void tstrsequence(uchar);
 
 static void drawregion(int, int, int, int);
 
+static void selnormalize(void);
 static void selscroll(int, int);
 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 *s, Rune u);
+static char *utf8strchr(char *, Rune);
 static size_t utf8validate(Rune *, size_t);
 
 static char *base64dec(const char *);
+static char base64dec_getc(const char **);
 
 static ssize_t xwrite(int, const char *, size_t);
 
diff --git a/st.h b/st.h
index 0a7472b..1015fc6 100644
--- a/st.h
+++ b/st.h
_AT_@ -1,8 +1,5 @@
 /* See LICENSE for license details. */
 
-/* Arbitrary sizes */
-#define UTF_SIZ 4
-
 /* macros */
 #define MIN(a, b) ((a) < (b) ? (a) : (b))
 #define MAX(a, b) ((a) < (b) ? (b) : (a))
_AT_@ -69,41 +66,6 @@ typedef struct {
 
 typedef Glyph *Line;
 
-typedef struct {
- Glyph attr; /* current char attributes */
- int x;
- int y;
- char state;
-} TCursor;
-
-/* Purely graphic info */
-typedef struct {
- int tw, th; /* tty width and height */
- int w, h; /* window width and height */
- int ch; /* char height */
- int cw; /* char width */
- int mode; /* window state/mode flags */
- int cursor; /* cursor style */
-} TermWindow;
-
-typedef struct {
- int mode;
- int type;
- int snap;
- /*
- * Selection variables:
- * nb – normalized coordinates of the beginning of the selection
- * ne – normalized coordinates of the end of the selection
- * ob – original coordinates of the beginning of the selection
- * oe – original coordinates of the end of the selection
- */
- struct {
- int x, y;
- } nb, ne, ob, oe;
-
- int alt;
-} Selection;
-
 typedef union {
         int i;
         uint ui;
_AT_@ -137,11 +99,9 @@ void selclear(void);
 void selinit(void);
 void selstart(int, int, int);
 void selextend(int, int, int, int);
-void selnormalize(void);
 int selected(int, int);
 char *getsel(void);
 
-size_t utf8decode(const char *, Rune *, size_t);
 size_t utf8encode(Rune, char *);
 
 void *xmalloc(size_t);
diff --git a/win.h b/win.h
index 7a866fd..31f327d 100644
--- a/win.h
+++ b/win.h
_AT_@ -27,7 +27,6 @@ void xbell(void);
 void xclipcopy(void);
 void xdrawcursor(int, int, Glyph, int, int, Glyph);
 void xdrawline(Line, int, int, int);
-void xhints(void);
 void xfinishdraw(void);
 void xloadcols(void);
 int xsetcolorname(int, const char *);
diff --git a/x.c b/x.c
index 970d6dd..f7b0528 100644
--- a/x.c
+++ b/x.c
_AT_@ -76,6 +76,15 @@ typedef XftGlyphFontSpec GlyphFontSpec;
 
 /* Purely graphic info */
 typedef struct {
+ int tw, th; /* tty width and height */
+ int w, h; /* window width and height */
+ int ch; /* char height */
+ int cw; /* char width */
+ int mode; /* window state/mode flags */
+ int cursor; /* cursor style */
+} TermWindow;
+
+typedef struct {
         Display *dpy;
         Colormap cmap;
         Window win;
_AT_@ -133,6 +142,8 @@ static int xgeommasktogravity(int);
 static void xinit(int, int);
 static void cresize(int, int);
 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 xunloadfont(Font *);
_AT_@ -1430,8 +1441,8 @@ xdrawcursor(int cx, int cy, Glyph g, int ox, int oy, Glyph og)
         /* draw the new one */
         if (IS_SET(MODE_FOCUSED)) {
                 switch (win.cursor) {
- case 7: /* st extension: snowman */
- utf8decode("☃", &g.u, UTF_SIZ);
+ case 7: /* st extension: snowman (U+2603) */
+ g.u = 0x2603;
                 case 0: /* Blinking Block */
                 case 1: /* Blinking Block (Default) */
                 case 2: /* Steady Block */
Received on Fri Mar 09 2018 - 15:37:40 CET

This archive was generated by hypermail 2.3.0 : Fri Mar 09 2018 - 15:51:12 CET