tvi.h - neatvi - [fork] simple vi-type editor with UTF-8 support
 (HTM) git clone git://src.adamsgaard.dk/neatvi
 (DIR) Log
 (DIR) Files
 (DIR) Refs
 (DIR) README
       ---
       tvi.h (6644B)
       ---
            1 /* neatvi main header */
            2 
            3 /* helper macros */
            4 #define LEN(a)                (sizeof(a) / sizeof((a)[0]))
            5 #define MIN(a, b)        ((a) < (b) ? (a) : (b))
            6 #define MAX(a, b)        ((a) < (b) ? (b) : (a))
            7 
            8 /* line buffer, managing a number of lines */
            9 struct lbuf *lbuf_make(void);
           10 void lbuf_free(struct lbuf *lbuf);
           11 int lbuf_rd(struct lbuf *lbuf, int fd, int beg, int end);
           12 int lbuf_wr(struct lbuf *lbuf, int fd, int beg, int end);
           13 void lbuf_edit(struct lbuf *lbuf, char *s, int beg, int end);
           14 char *lbuf_cp(struct lbuf *lbuf, int beg, int end);
           15 char *lbuf_get(struct lbuf *lbuf, int pos);
           16 int lbuf_len(struct lbuf *lbuf);
           17 void lbuf_mark(struct lbuf *lbuf, int mark, int pos, int off);
           18 int lbuf_jump(struct lbuf *lbuf, int mark, int *pos, int *off);
           19 int lbuf_undo(struct lbuf *lbuf);
           20 int lbuf_redo(struct lbuf *lbuf);
           21 int lbuf_modified(struct lbuf *lb);
           22 void lbuf_saved(struct lbuf *lb, int clear);
           23 int lbuf_indents(struct lbuf *lb, int r);
           24 int lbuf_eol(struct lbuf *lb, int r);
           25 void lbuf_globset(struct lbuf *lb, int pos, int dep);
           26 int lbuf_globget(struct lbuf *lb, int pos, int dep);
           27 /* motions */
           28 int lbuf_findchar(struct lbuf *lb, char *cs, int cmd, int n, int *r, int *o);
           29 int lbuf_search(struct lbuf *lb, char *kw, int dir, int *r, int *o, int *len);
           30 int lbuf_paragraphbeg(struct lbuf *lb, int dir, int *row, int *off);
           31 int lbuf_sectionbeg(struct lbuf *lb, int dir, int *row, int *off);
           32 int lbuf_wordbeg(struct lbuf *lb, int big, int dir, int *row, int *off);
           33 int lbuf_wordend(struct lbuf *lb, int big, int dir, int *row, int *off);
           34 int lbuf_pair(struct lbuf *lb, int *row, int *off);
           35 
           36 /* string buffer, variable-sized string */
           37 struct sbuf *sbuf_make(void);
           38 void sbuf_free(struct sbuf *sb);
           39 char *sbuf_done(struct sbuf *sb);
           40 char *sbuf_buf(struct sbuf *sb);
           41 void sbuf_chr(struct sbuf *sb, int c);
           42 void sbuf_str(struct sbuf *sb, char *s);
           43 void sbuf_mem(struct sbuf *sb, char *s, int len);
           44 void sbuf_printf(struct sbuf *sbuf, char *s, ...);
           45 int sbuf_len(struct sbuf *sb);
           46 void sbuf_cut(struct sbuf *s, int len);
           47 
           48 /* regular expressions */
           49 #define RE_ICASE                1
           50 #define RE_NOTBOL                2
           51 #define RE_NOTEOL                4
           52 /* regular expression sets: searching for multiple regular expressions */
           53 struct rset *rset_make(int n, char **pat, int flg);
           54 int rset_find(struct rset *re, char *s, int n, int *grps, int flg);
           55 void rset_free(struct rset *re);
           56 char *re_read(char **src);
           57 /* searching for a single pattern regular expression */
           58 struct rstr *rstr_make(char *re, int flg);
           59 int rstr_find(struct rstr *rs, char *s, int n, int *grps, int flg);
           60 void rstr_free(struct rstr *rs);
           61 
           62 /* rendering lines */
           63 int *ren_position(char *s);
           64 int ren_next(char *s, int p, int dir);
           65 int ren_eol(char *s, int dir);
           66 int ren_pos(char *s, int off);
           67 int ren_cursor(char *s, int pos);
           68 int ren_noeol(char *s, int p);
           69 int ren_off(char *s, int pos);
           70 int ren_wid(char *s);
           71 int ren_region(char *s, int c1, int c2, int *l1, int *l2, int closed);
           72 char *ren_translate(char *s, char *ln);
           73 int ren_cwid(char *s, int pos);
           74 
           75 /* text direction */
           76 int dir_context(char *s);
           77 void dir_reorder(char *s, int *ord);
           78 void dir_init(void);
           79 void dir_done(void);
           80 
           81 /* string registers */
           82 char *reg_get(int c, int *lnmode);
           83 void reg_put(int c, char *s, int lnmode);
           84 void reg_done(void);
           85 
           86 /* utf-8 helper functions */
           87 int uc_len(char *s);
           88 int uc_wid(char *s);
           89 int uc_slen(char *s);
           90 int uc_code(char *s);
           91 char *uc_chr(char *s, int off);
           92 int uc_off(char *s, int off);
           93 char *uc_sub(char *s, int beg, int end);
           94 char *uc_dup(char *s);
           95 int uc_isspace(char *s);
           96 int uc_isprint(char *s);
           97 int uc_isdigit(char *s);
           98 int uc_isalpha(char *s);
           99 int uc_kind(char *c);
          100 int uc_isbell(char *c);
          101 int uc_iscomb(char *c);
          102 char **uc_chop(char *s, int *n);
          103 char *uc_next(char *s);
          104 char *uc_prev(char *beg, char *s);
          105 char *uc_beg(char *beg, char *s);
          106 char *uc_end(char *s);
          107 char *uc_shape(char *beg, char *s);
          108 char *uc_lastline(char *s);
          109 
          110 /* managing the terminal */
          111 #define xrows                (term_rows() - 1)
          112 #define xcols                (term_cols())
          113 
          114 void term_init(void);
          115 void term_done(void);
          116 void term_suspend(void);
          117 void term_str(char *s);
          118 void term_chr(int ch);
          119 void term_pos(int r, int c);
          120 void term_clear(void);
          121 void term_kill(void);
          122 void term_room(int n);
          123 int term_rows(void);
          124 int term_cols(void);
          125 int term_read(void);
          126 void term_record(void);
          127 void term_commit(void);
          128 char *term_att(int att, int old);
          129 void term_push(char *s, int n);
          130 char *term_cmd(int *n);
          131 
          132 #define TK_CTL(x)        ((x) & 037)
          133 #define TK_INT(c)        ((c) < 0 || (c) == TK_ESC || (c) == TK_CTL('c'))
          134 #define TK_ESC                (TK_CTL('['))
          135 
          136 /* line-oriented input and output */
          137 char *led_prompt(char *pref, char *post, int *kmap, char *syn);
          138 char *led_input(char *pref, char *post, int *kmap, char *syn);
          139 void led_print(char *msg, int row, char *syn);
          140 void led_printmsg(char *s, int row, char *syn);
          141 char *led_read(int *kmap);
          142 int led_pos(char *s, int pos);
          143 
          144 /* ex commands */
          145 void ex(void);
          146 void ex_command(char *cmd);
          147 char *ex_read(char *msg);
          148 void ex_print(char *line);
          149 void ex_show(char *msg);
          150 int ex_init(char **files);
          151 void ex_done(void);
          152 char *ex_path(void);
          153 char *ex_filetype(void);
          154 struct lbuf *ex_lbuf(void);
          155 int ex_kwd(char **kwd, int *dir);
          156 void ex_kwdset(char *kwd, int dir);
          157 
          158 #define EXLEN        512                /* ex line length */
          159 #define xb         ex_lbuf()
          160 
          161 /* process management */
          162 char *cmd_pipe(char *cmd, char *s, int iproc, int oproc);
          163 int cmd_exec(char *cmd);
          164 
          165 /* syntax highlighting */
          166 #define SYN_BD                0x010000
          167 #define SYN_IT                0x020000
          168 #define SYN_RV                0x040000
          169 #define SYN_FGMK(f)        (0x100000 | (f))
          170 #define SYN_BGMK(b)        (0x200000 | ((b) << 8))
          171 
          172 #define SYN_FLG                0xff0000
          173 #define SYN_FGSET(a)        ((a) & 0x1000ff)
          174 #define SYN_BGSET(a)        ((a) & 0x20ff00)
          175 #define SYN_FG(a)        ((a) & 0xff)
          176 #define SYN_BG(a)        (((a) >> 8) & 0xff)
          177 
          178 int *syn_highlight(char *ft, char *s);
          179 char *syn_filetype(char *path);
          180 void syn_context(int att);
          181 int syn_merge(int old, int new);
          182 void syn_init(void);
          183 void syn_done(void);
          184 
          185 /* configuration variables */
          186 int conf_dirmark(int idx, char **pat, int *ctx, int *dir, int *grp);
          187 int conf_dircontext(int idx, char **pat, int *ctx);
          188 int conf_placeholder(int idx, char **s, char **d, int *wid);
          189 int conf_highlight(int idx, char **ft, int **att, char **pat, int *end);
          190 int conf_filetype(int idx, char **ft, char **pat);
          191 int conf_hlrev(void);
          192 int conf_hlline(void);
          193 int conf_mode(void);
          194 char **conf_kmap(int id);
          195 int conf_kmapfind(char *name);
          196 char *conf_digraph(int c1, int c2);
          197 char *conf_lnpref(void);
          198 
          199 /* global variables */
          200 extern int xrow;
          201 extern int xoff;
          202 extern int xtop;
          203 extern int xleft;
          204 extern int xvis;
          205 extern int xled;
          206 extern int xquit;
          207 extern int xic;
          208 extern int xai;
          209 extern int xtd;
          210 extern int xshape;
          211 extern int xorder;
          212 extern int xhl;
          213 extern int xhll;
          214 extern int xkmap;
          215 extern int xkmap_alt;
          216 extern int xlim;