typedef struct abuf -> abuf
This commit is contained in:
48
main.c
48
main.c
@@ -75,11 +75,11 @@
|
|||||||
|
|
||||||
|
|
||||||
/* append buffer */
|
/* append buffer */
|
||||||
struct abuf {
|
typedef struct abuf {
|
||||||
char *b;
|
char *b;
|
||||||
size_t len;
|
size_t len;
|
||||||
size_t cap;
|
size_t cap;
|
||||||
};
|
} abuf;
|
||||||
|
|
||||||
#define ABUF_INIT {NULL, 0, 0}
|
#define ABUF_INIT {NULL, 0, 0}
|
||||||
|
|
||||||
@@ -152,12 +152,12 @@ void reset_editor(void);
|
|||||||
int next_power_of_2(int n);
|
int next_power_of_2(int n);
|
||||||
int cap_growth(int cap, int sz);
|
int cap_growth(int cap, int sz);
|
||||||
size_t kstrnlen(const char *buf, const size_t max);
|
size_t kstrnlen(const char *buf, const size_t max);
|
||||||
void ab_init(struct abuf *buf);
|
void ab_init(abuf *buf);
|
||||||
void ab_appendch(struct abuf *buf, char c);
|
void ab_appendch(abuf *buf, char c);
|
||||||
void ab_append(struct abuf *buf, const char *s, size_t len);
|
void ab_append(abuf *buf, const char *s, size_t len);
|
||||||
void ab_prependch(struct abuf *buf, char c);
|
void ab_prependch(abuf *buf, char c);
|
||||||
void ab_prepend(struct abuf *buf, const char *s, size_t len);
|
void ab_prepend(abuf *buf, const char *s, size_t len);
|
||||||
void ab_free(struct abuf *buf);
|
void ab_free(abuf *buf);
|
||||||
char nibble_to_hex(char c);
|
char nibble_to_hex(char c);
|
||||||
void swap_int(int *a, int *b);
|
void swap_int(int *a, int *b);
|
||||||
|
|
||||||
@@ -225,13 +225,13 @@ int process_keypress(void);
|
|||||||
char *get_cloc_code_lines(const char *filename);
|
char *get_cloc_code_lines(const char *filename);
|
||||||
int dump_pidfile(void);
|
int dump_pidfile(void);
|
||||||
void enable_termraw(void);
|
void enable_termraw(void);
|
||||||
void display_clear(struct abuf *ab);
|
void display_clear(abuf *ab);
|
||||||
void disable_termraw(void);
|
void disable_termraw(void);
|
||||||
void setup_terminal(void);
|
void setup_terminal(void);
|
||||||
void draw_rows(struct abuf *ab);
|
void draw_rows(abuf *ab);
|
||||||
char status_mode_char(void);
|
char status_mode_char(void);
|
||||||
void draw_status_bar(struct abuf *ab);
|
void draw_status_bar(abuf *ab);
|
||||||
void draw_message_line(struct abuf *ab);
|
void draw_message_line(abuf *ab);
|
||||||
void scroll(void);
|
void scroll(void);
|
||||||
void display_refresh(void);
|
void display_refresh(void);
|
||||||
void editor_set_status(const char *fmt, ...);
|
void editor_set_status(const char *fmt, ...);
|
||||||
@@ -391,7 +391,7 @@ reset_editor(void)
|
|||||||
|
|
||||||
|
|
||||||
void
|
void
|
||||||
ab_init(struct abuf *buf)
|
ab_init(abuf *buf)
|
||||||
{
|
{
|
||||||
buf->b = NULL;
|
buf->b = NULL;
|
||||||
buf->len = 0;
|
buf->len = 0;
|
||||||
@@ -400,14 +400,14 @@ ab_init(struct abuf *buf)
|
|||||||
|
|
||||||
|
|
||||||
void
|
void
|
||||||
ab_appendch(struct abuf *buf, char c)
|
ab_appendch(abuf *buf, char c)
|
||||||
{
|
{
|
||||||
ab_append(buf, &c, 1);
|
ab_append(buf, &c, 1);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
void
|
void
|
||||||
ab_append(struct abuf *buf, const char *s, size_t len)
|
ab_append(abuf *buf, const char *s, size_t len)
|
||||||
{
|
{
|
||||||
char *nc = buf->b;
|
char *nc = buf->b;
|
||||||
size_t sz = buf->len + len;
|
size_t sz = buf->len + len;
|
||||||
@@ -431,14 +431,14 @@ ab_append(struct abuf *buf, const char *s, size_t len)
|
|||||||
|
|
||||||
|
|
||||||
void
|
void
|
||||||
ab_prependch(struct abuf *buf, const char c)
|
ab_prependch(abuf *buf, const char c)
|
||||||
{
|
{
|
||||||
ab_prepend(buf, &c, 1);
|
ab_prepend(buf, &c, 1);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
void
|
void
|
||||||
ab_prepend(struct abuf *buf, const char *s, const size_t len)
|
ab_prepend(abuf *buf, const char *s, const size_t len)
|
||||||
{
|
{
|
||||||
char *nc = realloc(buf->b, buf->len + len);
|
char *nc = realloc(buf->b, buf->len + len);
|
||||||
assert(nc != NULL);
|
assert(nc != NULL);
|
||||||
@@ -452,7 +452,7 @@ ab_prepend(struct abuf *buf, const char *s, const size_t len)
|
|||||||
|
|
||||||
|
|
||||||
void
|
void
|
||||||
ab_free(struct abuf *buf)
|
ab_free(abuf *buf)
|
||||||
{
|
{
|
||||||
free(buf->b);
|
free(buf->b);
|
||||||
buf->b = NULL;
|
buf->b = NULL;
|
||||||
@@ -2668,7 +2668,7 @@ enable_termraw(void)
|
|||||||
|
|
||||||
|
|
||||||
void
|
void
|
||||||
display_clear(struct abuf *ab)
|
display_clear(abuf *ab)
|
||||||
{
|
{
|
||||||
if (ab == NULL) {
|
if (ab == NULL) {
|
||||||
kwrite(STDOUT_FILENO, ESCSEQ "2J", 4);
|
kwrite(STDOUT_FILENO, ESCSEQ "2J", 4);
|
||||||
@@ -2703,7 +2703,7 @@ setup_terminal(void)
|
|||||||
|
|
||||||
|
|
||||||
void
|
void
|
||||||
draw_rows(struct abuf *ab)
|
draw_rows(abuf *ab)
|
||||||
{
|
{
|
||||||
assert(editor.cols >= 0);
|
assert(editor.cols >= 0);
|
||||||
|
|
||||||
@@ -2775,7 +2775,7 @@ status_mode_char(void)
|
|||||||
|
|
||||||
|
|
||||||
void
|
void
|
||||||
draw_status_bar(struct abuf *ab)
|
draw_status_bar(abuf *ab)
|
||||||
{
|
{
|
||||||
char status[editor.cols];
|
char status[editor.cols];
|
||||||
char rstatus[editor.cols];
|
char rstatus[editor.cols];
|
||||||
@@ -2825,7 +2825,7 @@ draw_status_bar(struct abuf *ab)
|
|||||||
|
|
||||||
|
|
||||||
void
|
void
|
||||||
draw_message_line(struct abuf *ab)
|
draw_message_line(abuf *ab)
|
||||||
{
|
{
|
||||||
int len = strlen(editor.msg);
|
int len = strlen(editor.msg);
|
||||||
|
|
||||||
@@ -2876,8 +2876,8 @@ scroll(void)
|
|||||||
void
|
void
|
||||||
display_refresh(void)
|
display_refresh(void)
|
||||||
{
|
{
|
||||||
char buf[32];
|
char buf[32];
|
||||||
struct abuf ab = ABUF_INIT;
|
abuf ab = ABUF_INIT;
|
||||||
|
|
||||||
scroll();
|
scroll();
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user