st.h - st - personal variant of st
 (HTM) git clone https://git.drkhsh.at/st.git
 (DIR) Log
 (DIR) Files
 (DIR) Refs
 (DIR) README
 (DIR) LICENSE
       ---
       st.h (3117B)
       ---
            1 /* See LICENSE for license details. */
            2 
            3 #include <stdint.h>
            4 #include <sys/types.h>
            5 
            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)))
           19 
           20 #define TRUECOLOR(r,g,b)        (1 << 24 | (r) << 16 | (g) << 8 | (b))
           21 #define IS_TRUECOL(x)                (1 << 24 & (x))
           22 
           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,
           37 };
           38 
           39 enum drawing_mode {
           40     DRAW_NONE = 0,
           41     DRAW_BG = 1 << 0,
           42     DRAW_FG = 1 << 1,
           43 };
           44 
           45 enum selection_mode {
           46         SEL_IDLE = 0,
           47         SEL_EMPTY = 1,
           48         SEL_READY = 2
           49 };
           50 
           51 enum selection_type {
           52         SEL_REGULAR = 1,
           53         SEL_RECTANGULAR = 2
           54 };
           55 
           56 enum selection_snap {
           57         SNAP_WORD = 1,
           58         SNAP_LINE = 2
           59 };
           60 
           61 typedef unsigned char uchar;
           62 typedef unsigned int uint;
           63 typedef unsigned long ulong;
           64 typedef unsigned short ushort;
           65 
           66 typedef uint_least32_t Rune;
           67 
           68 #define Glyph Glyph_
           69 typedef struct {
           70         Rune u;           /* character code */
           71         ushort mode;      /* attribute flags */
           72         uint32_t fg;      /* foreground  */
           73         uint32_t bg;      /* background  */
           74 } Glyph;
           75 
           76 typedef Glyph *Line;
           77 
           78 typedef union {
           79         int i;
           80         uint ui;
           81         float f;
           82         const void *v;
           83         const char *s;
           84 } Arg;
           85 
           86 void die(const char *, ...);
           87 void redraw(void);
           88 void draw(void);
           89 
           90 void kscrolldown(const Arg *);
           91 void kscrollup(const Arg *);
           92 void newterm(const Arg *);
           93 void printscreen(const Arg *);
           94 void printsel(const Arg *);
           95 void sendbreak(const Arg *);
           96 void toggleprinter(const Arg *);
           97 
           98 int tattrset(int);
           99 void tnew(int, int);
          100 void tresize(int, int);
          101 void tsetdirtattr(int);
          102 void ttyhangup(void);
          103 int ttynew(const char *, char *, const char *, char **);
          104 size_t ttyread(void);
          105 void ttyresize(int, int);
          106 void ttywrite(const char *, size_t, int);
          107 
          108 void resettitle(void);
          109 
          110 void selclear(void);
          111 void selinit(void);
          112 void selstart(int, int, int);
          113 void selextend(int, int, int, int);
          114 int selected(int, int);
          115 char *getsel(void);
          116 
          117 size_t utf8encode(Rune, char *);
          118 
          119 void *xmalloc(size_t);
          120 void *xrealloc(void *, size_t);
          121 char *xstrdup(const char *);
          122 
          123 /* config.h globals */
          124 extern char *utmp;
          125 extern char *scroll;
          126 extern char *stty_args;
          127 extern char *vtiden;
          128 extern wchar_t *worddelimiters;
          129 extern int allowaltscreen;
          130 extern int allowwindowops;
          131 extern char *termname;
          132 extern unsigned int tabspaces;
          133 extern unsigned int defaultfg;
          134 extern unsigned int defaultbg;
          135 extern unsigned int defaultcs;
          136 extern float alpha;