minor code-style, initialize var at the top of function
[st.git] / st.h
bloba3b19dea2f58072518fcbc7052d370e9f4829448
1 /* See LICENSE for license details. */
3 #include <stdint.h>
4 #include <sys/types.h>
6 /* macros */
7 #define MIN(a, b) ((a) < (b) ? (a) : (b))
8 #define MAX(a, b) ((a) < (b) ? (b) : (a))
9 #define LEN(a) (sizeof(a) / sizeof(a)[0])
10 #define BETWEEN(x, a, b) ((a) <= (x) && (x) <= (b))
11 #define DIVCEIL(n, d) (((n) + ((d) - 1)) / (d))
12 #define DEFAULT(a, b) (a) = (a) ? (a) : (b)
13 #define LIMIT(x, a, b) (x) = (x) < (a) ? (a) : (x) > (b) ? (b) : (x)
14 #define ATTRCMP(a, b) ((a).mode != (b).mode || (a).fg != (b).fg || \
15 (a).bg != (b).bg)
16 #define TIMEDIFF(t1, t2) ((t1.tv_sec-t2.tv_sec)*1000 + \
17 (t1.tv_nsec-t2.tv_nsec)/1E6)
18 #define MODBIT(x, set, bit) ((set) ? ((x) |= (bit)) : ((x) &= ~(bit)))
20 #define TRUECOLOR(r,g,b) (1 << 24 | (r) << 16 | (g) << 8 | (b))
21 #define IS_TRUECOL(x) (1 << 24 & (x))
23 enum glyph_attribute {
24 ATTR_NULL = 0,
25 ATTR_BOLD = 1 << 0,
26 ATTR_FAINT = 1 << 1,
27 ATTR_ITALIC = 1 << 2,
28 ATTR_UNDERLINE = 1 << 3,
29 ATTR_BLINK = 1 << 4,
30 ATTR_REVERSE = 1 << 5,
31 ATTR_INVISIBLE = 1 << 6,
32 ATTR_STRUCK = 1 << 7,
33 ATTR_WRAP = 1 << 8,
34 ATTR_WIDE = 1 << 9,
35 ATTR_WDUMMY = 1 << 10,
36 ATTR_BOLD_FAINT = ATTR_BOLD | ATTR_FAINT,
39 enum selection_mode {
40 SEL_IDLE = 0,
41 SEL_EMPTY = 1,
42 SEL_READY = 2
45 enum selection_type {
46 SEL_REGULAR = 1,
47 SEL_RECTANGULAR = 2
50 enum selection_snap {
51 SNAP_WORD = 1,
52 SNAP_LINE = 2
55 typedef unsigned char uchar;
56 typedef unsigned int uint;
57 typedef unsigned long ulong;
58 typedef unsigned short ushort;
60 typedef uint_least32_t Rune;
62 #define Glyph Glyph_
63 typedef struct {
64 Rune u; /* character code */
65 ushort mode; /* attribute flags */
66 uint32_t fg; /* foreground */
67 uint32_t bg; /* background */
68 } Glyph;
70 typedef Glyph *Line;
72 typedef union {
73 int i;
74 uint ui;
75 float f;
76 const void *v;
77 } Arg;
79 void die(const char *, ...);
80 void redraw(void);
81 void draw(void);
83 void printscreen(const Arg *);
84 void printsel(const Arg *);
85 void sendbreak(const Arg *);
86 void toggleprinter(const Arg *);
88 int tattrset(int);
89 void tnew(int, int);
90 void tresize(int, int);
91 void tsetdirtattr(int);
92 void ttyhangup(void);
93 int ttynew(char *, char *, char *, char **);
94 size_t ttyread(void);
95 void ttyresize(int, int);
96 void ttywrite(const char *, size_t, int);
98 void resettitle(void);
100 void selclear(void);
101 void selinit(void);
102 void selstart(int, int, int);
103 void selextend(int, int, int, int);
104 int selected(int, int);
105 char *getsel(void);
107 size_t utf8encode(Rune, char *);
109 void *xmalloc(size_t);
110 void *xrealloc(void *, size_t);
111 char *xstrdup(char *);
113 /* config.h globals */
114 extern char *utmp;
115 extern char *stty_args;
116 extern char *vtiden;
117 extern wchar_t *extrawordchars;
118 extern int allowaltscreen;
119 extern char *termname;
120 extern unsigned int tabspaces;
121 extern unsigned int defaultfg;
122 extern unsigned int defaultbg;