Skip to content

Commit

Permalink
Reduce visibility wherever possible
Browse files Browse the repository at this point in the history
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 <[email protected]>
  • Loading branch information
djpohly committed Feb 26, 2018
1 parent 30683c7 commit e0215d5
Show file tree
Hide file tree
Showing 4 changed files with 43 additions and 44 deletions.
31 changes: 30 additions & 1 deletion st.c
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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 */
Expand Down Expand Up @@ -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);

Expand Down
40 changes: 0 additions & 40 deletions st.h
Original file line number Diff line number Diff line change
@@ -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))
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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);
Expand Down
1 change: 0 additions & 1 deletion win.h
Original file line number Diff line number Diff line change
Expand Up @@ -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 *);
Expand Down
15 changes: 13 additions & 2 deletions x.c
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,15 @@ typedef XftColor Color;
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;
Expand Down Expand Up @@ -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 *);
Expand Down Expand Up @@ -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 */
Expand Down

0 comments on commit e0215d5

Please sign in to comment.