#ifndef _BUF_H #define _BUF_H #include #include #define PATHSIZE 512 #define MINIB_SIZE 100 #define MAX_SAVED_MOTION 10 #define TABSTOP 8 struct line { TAILQ_ENTRY(line) list; int len; char *line; }; struct buf { TAILQ_HEAD(lines_head, line) lines; int num_lines; int dirty; }; struct pos { int x; int y; }; struct file { char path[PATHSIZE]; char dir[PATHSIZE]; mode_t mode; }; struct cmd { char key; int count; int flags; struct pos new_pos; /* Used for motion commands */ struct pos mstart; /* Start of the motion */ struct pos mend; /* End of the motion */ }; struct commands { int flags; int (*func)(struct cmd *cmd, struct buf *b); }; #define CMD_COUNT 0x1 /* Can take a count */ #define CMD_ISMOTION 0x2 /* Can be used as a motion */ #define CMD_MOTION 0x4 /* Takes a motion */ #define CMD_MLINE 0x8 /* Operates on whole lines when motion */ #define CMD_MODE 0x10 /* Changes mode and possibly curr_line XXX temp */ #define CMD_COUNT0 0x20 /* Non-specified count has a special meaning */ #define CMD_EFFECT 0x40 /* Modifies the buffer */ /* Used for struct cmd */ #define CMD_DOT 0x00010000 /* This command was invoked from '.' */ #define CMD_SUCCESS 0x00020000 /* Command succeeded */ #define NUM_COMMANDS 512 #define SHOWMATCH_MS 1000 typedef enum { UND_ADD, UND_MOD, UND_DEL } undo_type_t; extern struct commands cmds[NUM_COMMANDS]; #define CTRL_G 7 #define ESC 27 #define BKSPC 127 struct line *line_next(struct line *l); struct line *line_prev(struct line *l); struct line *line_alloc(char *line, int len); void line_add(struct buf *b, struct line *l, int pos); void line_add_undo(struct buf *b, struct line *l, int y); void line_add_partial(struct buf *b, struct line *l, int start, int end, int pos); void line_remove(struct buf *b, struct line *l); void line_remove_undo(struct buf *b, struct line *l, int y); void line_replace(struct line *l, char *text, int len); void line_replace_undo(struct line *l, char *text, int len, int y); struct line *line_dup(struct line *l); void line_free(struct line *l); void buf_init(struct buf *b); struct line *buf_get_line(struct buf *b, int num); int buf_find_line(struct buf *b, struct line *line); void buf_dump(struct buf *b); void buf_clear(struct buf *b); void buf_union(struct buf *b1, struct buf *b2, int pos); int file_load(struct file *f, struct buf *b); int file_store(struct file *f, struct buf *b); #define printd(...) printy(maxy - 1, A_NORMAL, __VA_ARGS__) #define printerr(...) printy(maxy - 1, A_REVERSE, __VA_ARGS__) void printy(int y, int attr, const char *fmt, ...); void clear_mini(void); int draw_line(struct line *l, int y); void place_cursor(struct line *l, int x, int y, int insert); void place_char(struct line *l, int x, int y, int c); void y_inc(struct pos *pos); void y_dec(struct pos *pos); void cur_fixup(void); int nextchar(struct buf *b, struct pos *p); int prevchar(struct buf *b, struct pos *p); void skipblank(struct line *l, struct pos *p); int findmatch(struct buf *b, char o, struct pos *p, int _depth); int delete(struct buf *b, struct buf *yank, struct pos start, struct pos end, int del); int cmd_insert(struct cmd *c, struct buf *b); int cmd_replace(struct cmd *c, struct buf *b); int cmd_change(struct cmd *c, struct buf *b); void undo_init(void); void undo_start(struct cmd *c); void undo_finish(struct cmd *c); void undo_add_line(struct line *l, int y, undo_type_t type); int cmd_undo(struct cmd *c, struct buf *b); int cmd_search(struct cmd *c, struct buf *b); int cmd_search_next(struct cmd *c, struct buf *b); int cmd_ex(struct cmd *c, struct buf *b); /* Globals */ extern struct file file; extern struct buf buf; extern struct buf yank_buf; extern struct line *curr_line; extern int tmp_count; extern char *minib; extern int minipos; extern struct pos cur; extern int disp_y; extern int maxx, maxy; extern int cur_y; extern int debug; extern int opt_ai; extern int opt_sm; #endif