|
@@ -5,237 +5,202 @@
|
|
|
|
|
|
|
|
#include "app.h"
|
|
#include "app.h"
|
|
|
|
|
|
|
|
-enum direction {
|
|
|
|
|
- DIR_FORWARD,
|
|
|
|
|
- DIR_BACKWARD,
|
|
|
|
|
-};
|
|
|
|
|
|
|
+void keybind_save_buffer(struct app *app, enum keybind_dir dir);
|
|
|
|
|
|
|
|
-union keybind_args {
|
|
|
|
|
- enum direction dir;
|
|
|
|
|
- void *ptr;
|
|
|
|
|
-};
|
|
|
|
|
|
|
+void keybind_mv_cur_char(struct app *app, enum keybind_dir dir);
|
|
|
|
|
+void keybind_forward_char(struct app *app, enum keybind_dir dir);
|
|
|
|
|
+void keybind_delete_char(struct app *app, enum keybind_dir dir);
|
|
|
|
|
|
|
|
-typedef struct app (*keybind_func)(struct app, union keybind_args);
|
|
|
|
|
|
|
+void keybind_mv_cur_word(struct app *app, enum keybind_dir dir);
|
|
|
|
|
+void keybind_delete_word(struct app *app, enum keybind_dir dir);
|
|
|
|
|
|
|
|
-struct bind {
|
|
|
|
|
- const SDL_Keymod mod;
|
|
|
|
|
- keybind_func func;
|
|
|
|
|
- union keybind_args args;
|
|
|
|
|
-};
|
|
|
|
|
|
|
+void keybind_mv_cur_line(struct app *app, enum keybind_dir dir);
|
|
|
|
|
+void keybind_mv_cur_beg_line(struct app *app, enum keybind_dir dir);
|
|
|
|
|
+void keybind_mv_cur_end_line(struct app *app, enum keybind_dir dir);
|
|
|
|
|
|
|
|
-#define BINDS_SIZE 10
|
|
|
|
|
-struct keybinds {
|
|
|
|
|
- uint8_t size;
|
|
|
|
|
- const struct bind binds[BINDS_SIZE];
|
|
|
|
|
-};
|
|
|
|
|
|
|
+void keybind_insert_newline(struct app *app, enum keybind_dir dir);
|
|
|
|
|
|
|
|
-struct app keybind_save_buffer(struct app app, union keybind_args args);
|
|
|
|
|
|
|
+void keybind_toggle_fps(struct app *app, enum keybind_dir dir);
|
|
|
|
|
|
|
|
-struct app keybind_mv_cur_char(struct app app, union keybind_args args);
|
|
|
|
|
-struct app keybind_forward_char(struct app app, union keybind_args args);
|
|
|
|
|
-struct app keybind_delete_char(struct app app, union keybind_args args);
|
|
|
|
|
-
|
|
|
|
|
-struct app keybind_mv_cur_word(struct app app, union keybind_args args);
|
|
|
|
|
-struct app keybind_delete_word(struct app app, union keybind_args args);
|
|
|
|
|
-
|
|
|
|
|
-struct app keybind_mv_cur_line(struct app app, union keybind_args args);
|
|
|
|
|
-struct app keybind_mv_cur_beg_line(struct app app, union keybind_args args);
|
|
|
|
|
-struct app keybind_mv_cur_end_line(struct app app, union keybind_args args);
|
|
|
|
|
-
|
|
|
|
|
-struct app keybind_insert_newline(struct app app, union keybind_args args);
|
|
|
|
|
-
|
|
|
|
|
-struct app keybind_toggle_fps(struct app app, union keybind_args args);
|
|
|
|
|
-
|
|
|
|
|
-struct app keybind_mv_cur_end_buffer(struct app app, union keybind_args args);
|
|
|
|
|
|
|
+void keybind_mv_cur_end_buffer(struct app *app, enum keybind_dir dir);
|
|
|
|
|
|
|
|
#if defined(KEYBIND_IMP) || defined(IMP)
|
|
#if defined(KEYBIND_IMP) || defined(IMP)
|
|
|
|
|
|
|
|
-struct app
|
|
|
|
|
-keybind_save_buffer(struct app app, union keybind_args args)
|
|
|
|
|
|
|
+void
|
|
|
|
|
+keybind_save_buffer(struct app *app, enum keybind_dir dir)
|
|
|
{
|
|
{
|
|
|
- (void) args;
|
|
|
|
|
|
|
+ (void) dir; (void) app;
|
|
|
/* buffer_save(app.buf); */
|
|
/* buffer_save(app.buf); */
|
|
|
- return app;
|
|
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
-struct app
|
|
|
|
|
-keybind_mv_cur_char(struct app app, union keybind_args args)
|
|
|
|
|
|
|
+void
|
|
|
|
|
+keybind_mv_cur_char(struct app *app, enum keybind_dir dir)
|
|
|
{
|
|
{
|
|
|
- if ( args.dir == DIR_FORWARD ) {
|
|
|
|
|
- buffer_mv_cur_right(&app.buf);
|
|
|
|
|
|
|
+ if ( dir == DIR_FORWARD ) {
|
|
|
|
|
+ buffer_mv_cur_right(app->cbuf);
|
|
|
}
|
|
}
|
|
|
- if ( args.dir == DIR_BACKWARD ) {
|
|
|
|
|
- buffer_mv_cur_left(&app.buf);
|
|
|
|
|
|
|
+ if ( dir == DIR_BACKWARD ) {
|
|
|
|
|
+ buffer_mv_cur_left(app->cbuf);
|
|
|
}
|
|
}
|
|
|
- app.buf.high_col = buffer_calc_cur_col(&app.buf);
|
|
|
|
|
- return app;
|
|
|
|
|
|
|
+ app->cbuf->high_col = buffer_calc_cur_col(app->cbuf);
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
-struct app
|
|
|
|
|
-keybind_delete_char(struct app app, union keybind_args args)
|
|
|
|
|
|
|
+void
|
|
|
|
|
+keybind_delete_char(struct app *app, enum keybind_dir dir)
|
|
|
{
|
|
{
|
|
|
- if ( args.dir == DIR_FORWARD ) {
|
|
|
|
|
- buffer_remove_char(&app.buf, app.buf.cur);
|
|
|
|
|
|
|
+ if ( dir == DIR_FORWARD ) {
|
|
|
|
|
+ buffer_remove_char(app->cbuf, app->cbuf->cur);
|
|
|
}
|
|
}
|
|
|
- if ( args.dir == DIR_BACKWARD ) {
|
|
|
|
|
- if ( app.buf.cur == 0 ) {
|
|
|
|
|
- return app;
|
|
|
|
|
|
|
+ if ( dir == DIR_BACKWARD ) {
|
|
|
|
|
+ if ( app->cbuf->cur == 0 ) {
|
|
|
|
|
+ return;
|
|
|
}
|
|
}
|
|
|
- buffer_remove_char(&app.buf, --app.buf.cur);
|
|
|
|
|
|
|
+ buffer_remove_char(app->cbuf, --app->cbuf->cur);
|
|
|
}
|
|
}
|
|
|
- app.buf.high_col = buffer_calc_cur_col(&app.buf);
|
|
|
|
|
- return app;
|
|
|
|
|
|
|
+ app->cbuf->high_col = buffer_calc_cur_col(app->cbuf);
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
-struct app
|
|
|
|
|
-keybind_mv_cur_word(struct app app, union keybind_args args)
|
|
|
|
|
|
|
+void
|
|
|
|
|
+keybind_mv_cur_word(struct app *app, enum keybind_dir dir)
|
|
|
{
|
|
{
|
|
|
size_t index;
|
|
size_t index;
|
|
|
enum buffer_err err;
|
|
enum buffer_err err;
|
|
|
- if ( args.dir == DIR_FORWARD ) {
|
|
|
|
|
- index = buffer_index_fw_word(&app.buf, &err);
|
|
|
|
|
|
|
+ if ( dir == DIR_FORWARD ) {
|
|
|
|
|
+ index = buffer_index_fw_word(app->cbuf, &err);
|
|
|
if ( err != BUFFER_ERR_OK ) {
|
|
if ( err != BUFFER_ERR_OK ) {
|
|
|
if ( err == BUFFER_ERR_INVALID_CUR_POS ) {
|
|
if ( err == BUFFER_ERR_INVALID_CUR_POS ) {
|
|
|
- app.buf.cur = app.buf.data.size;
|
|
|
|
|
|
|
+ app->cbuf->cur = app->cbuf->data.size;
|
|
|
}
|
|
}
|
|
|
- return app;
|
|
|
|
|
|
|
+ return;
|
|
|
}
|
|
}
|
|
|
- app.buf.cur = index;
|
|
|
|
|
|
|
+ app->cbuf->cur = index;
|
|
|
}
|
|
}
|
|
|
- if ( args.dir == DIR_BACKWARD ) {
|
|
|
|
|
- index = buffer_index_bw_word(&app.buf, &err);
|
|
|
|
|
|
|
+ if ( dir == DIR_BACKWARD ) {
|
|
|
|
|
+ index = buffer_index_bw_word(app->cbuf, &err);
|
|
|
if ( err != BUFFER_ERR_OK ) {
|
|
if ( err != BUFFER_ERR_OK ) {
|
|
|
if ( err == BUFFER_ERR_INVALID_CUR_POS ) {
|
|
if ( err == BUFFER_ERR_INVALID_CUR_POS ) {
|
|
|
- app.buf.cur = app.buf.data.size;
|
|
|
|
|
|
|
+ app->cbuf->cur = app->cbuf->data.size;
|
|
|
}
|
|
}
|
|
|
- return app;
|
|
|
|
|
|
|
+ return;
|
|
|
}
|
|
}
|
|
|
- app.buf.cur = index;
|
|
|
|
|
|
|
+ app->cbuf->cur = index;
|
|
|
}
|
|
}
|
|
|
- app.buf.high_col = buffer_calc_cur_col(&app.buf);
|
|
|
|
|
- return app;
|
|
|
|
|
|
|
+ app->cbuf->high_col = buffer_calc_cur_col(app->cbuf);
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
-struct app
|
|
|
|
|
-keybind_delete_word(struct app app, union keybind_args args)
|
|
|
|
|
|
|
+void
|
|
|
|
|
+keybind_delete_word(struct app *app, enum keybind_dir dir)
|
|
|
{
|
|
{
|
|
|
size_t index, n_rm;
|
|
size_t index, n_rm;
|
|
|
size_t start, end ;
|
|
size_t start, end ;
|
|
|
enum buffer_err err;
|
|
enum buffer_err err;
|
|
|
- switch ( args.dir ) {
|
|
|
|
|
|
|
+ switch ( dir ) {
|
|
|
case DIR_BACKWARD: {
|
|
case DIR_BACKWARD: {
|
|
|
- index = buffer_index_bw_word(&app.buf, &err);
|
|
|
|
|
|
|
+ index = buffer_index_bw_word(app->cbuf, &err);
|
|
|
if ( err != BUFFER_ERR_OK ) {
|
|
if ( err != BUFFER_ERR_OK ) {
|
|
|
if ( err == BUFFER_ERR_INVALID_CUR_POS ) {
|
|
if ( err == BUFFER_ERR_INVALID_CUR_POS ) {
|
|
|
- app.buf.cur = app.buf.data.size;
|
|
|
|
|
|
|
+ app->cbuf->cur = app->cbuf->data.size;
|
|
|
}
|
|
}
|
|
|
- return app;
|
|
|
|
|
|
|
+ return;
|
|
|
}
|
|
}
|
|
|
start = index;
|
|
start = index;
|
|
|
- end = app.buf.cur;
|
|
|
|
|
|
|
+ end = app->cbuf->cur;
|
|
|
} break;
|
|
} break;
|
|
|
case DIR_FORWARD: {
|
|
case DIR_FORWARD: {
|
|
|
- index = buffer_index_fw_word(&app.buf, &err);
|
|
|
|
|
|
|
+ index = buffer_index_fw_word(app->cbuf, &err);
|
|
|
if ( err != BUFFER_ERR_OK ) {
|
|
if ( err != BUFFER_ERR_OK ) {
|
|
|
if ( err == BUFFER_ERR_INVALID_CUR_POS ) {
|
|
if ( err == BUFFER_ERR_INVALID_CUR_POS ) {
|
|
|
- app.buf.cur = app.buf.data.size;
|
|
|
|
|
|
|
+ app->cbuf->cur = app->cbuf->data.size;
|
|
|
}
|
|
}
|
|
|
- return app;
|
|
|
|
|
|
|
+ return;
|
|
|
}
|
|
}
|
|
|
- start = app.buf.cur;
|
|
|
|
|
|
|
+ start = app->cbuf->cur;
|
|
|
end = index;
|
|
end = index;
|
|
|
} break;
|
|
} break;
|
|
|
default: {
|
|
default: {
|
|
|
fprintf(stderr, "Got invalid direction in %s: %d",
|
|
fprintf(stderr, "Got invalid direction in %s: %d",
|
|
|
- __func__, args.dir);
|
|
|
|
|
|
|
+ __func__, dir);
|
|
|
exit(EXIT_FAILURE);
|
|
exit(EXIT_FAILURE);
|
|
|
} break;
|
|
} break;
|
|
|
}
|
|
}
|
|
|
- n_rm = buffer_remove_between(&app.buf, start, end, &err);
|
|
|
|
|
|
|
+ n_rm = buffer_remove_between(app->cbuf, start, end, &err);
|
|
|
if ( err != BUFFER_ERR_OK ) {
|
|
if ( err != BUFFER_ERR_OK ) {
|
|
|
- return app;
|
|
|
|
|
|
|
+ return;
|
|
|
}
|
|
}
|
|
|
- app.buf.cur -= ( args.dir == DIR_BACKWARD ) * n_rm;
|
|
|
|
|
- app.buf.high_col = buffer_calc_cur_col(&app.buf);
|
|
|
|
|
- return app;
|
|
|
|
|
|
|
+ app->cbuf->cur -= ( dir == DIR_BACKWARD ) * n_rm;
|
|
|
|
|
+ app->cbuf->high_col = buffer_calc_cur_col(app->cbuf);
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
-struct app
|
|
|
|
|
-keybind_mv_cur_line(struct app app, union keybind_args args)
|
|
|
|
|
|
|
+void
|
|
|
|
|
+keybind_mv_cur_line(struct app *app, enum keybind_dir dir)
|
|
|
{
|
|
{
|
|
|
- (void) args;
|
|
|
|
|
- switch ( args.dir ) {
|
|
|
|
|
|
|
+ (void) dir;
|
|
|
|
|
+ switch ( dir ) {
|
|
|
case DIR_FORWARD: {
|
|
case DIR_FORWARD: {
|
|
|
- buffer_mv_cur_down(&app.buf);
|
|
|
|
|
|
|
+ buffer_mv_cur_down(app->cbuf);
|
|
|
} break;
|
|
} break;
|
|
|
case DIR_BACKWARD: {
|
|
case DIR_BACKWARD: {
|
|
|
- buffer_mv_cur_up(&app.buf);
|
|
|
|
|
|
|
+ buffer_mv_cur_up(app->cbuf);
|
|
|
} break;
|
|
} break;
|
|
|
default: {
|
|
default: {
|
|
|
fprintf(stderr, "Got invalid direction in %s: %d",
|
|
fprintf(stderr, "Got invalid direction in %s: %d",
|
|
|
- __func__, args.dir);
|
|
|
|
|
|
|
+ __func__, dir);
|
|
|
exit(EXIT_FAILURE);
|
|
exit(EXIT_FAILURE);
|
|
|
} break;
|
|
} break;
|
|
|
}
|
|
}
|
|
|
- return app;
|
|
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
-struct app
|
|
|
|
|
-keybind_mv_cur_beg_line(struct app app, union keybind_args args)
|
|
|
|
|
|
|
+void
|
|
|
|
|
+keybind_mv_cur_beg_line(struct app *app, enum keybind_dir dir)
|
|
|
{
|
|
{
|
|
|
- (void) args;
|
|
|
|
|
- struct buffer_line l = buffer_find_line(&app.buf, app.buf.cur-1);
|
|
|
|
|
- app.buf.cur = l.start;
|
|
|
|
|
- app.buf.high_col = buffer_calc_cur_col(&app.buf);
|
|
|
|
|
- return app;
|
|
|
|
|
|
|
+ (void) dir;
|
|
|
|
|
+ struct buffer_line l = buffer_find_line(app->cbuf, app->cbuf->cur-1);
|
|
|
|
|
+ app->cbuf->cur = l.start;
|
|
|
|
|
+ app->cbuf->high_col = buffer_calc_cur_col(app->cbuf);
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
-struct app
|
|
|
|
|
-keybind_mv_cur_end_line(struct app app, union keybind_args args)
|
|
|
|
|
|
|
+void
|
|
|
|
|
+keybind_mv_cur_end_line(struct app *app, enum keybind_dir dir)
|
|
|
{
|
|
{
|
|
|
- (void) args;
|
|
|
|
|
- struct buffer_line l = buffer_find_line(&app.buf, app.buf.cur+1);
|
|
|
|
|
- app.buf.cur = l.end;
|
|
|
|
|
- app.buf.high_col = buffer_calc_cur_col(&app.buf);
|
|
|
|
|
- return app;
|
|
|
|
|
|
|
+ (void) dir;
|
|
|
|
|
+ struct buffer_line l = buffer_find_line(app->cbuf, app->cbuf->cur+1);
|
|
|
|
|
+ app->cbuf->cur = l.end;
|
|
|
|
|
+ app->cbuf->high_col = buffer_calc_cur_col(app->cbuf);
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
-struct app
|
|
|
|
|
-keybind_insert_newline(struct app app, union keybind_args args)
|
|
|
|
|
|
|
+void
|
|
|
|
|
+keybind_insert_newline(struct app *app, enum keybind_dir dir)
|
|
|
{
|
|
{
|
|
|
- (void) args;
|
|
|
|
|
- buffer_insert_char(&app.buf, '\n', app.buf.cur);
|
|
|
|
|
- app.buf.high_col = buffer_calc_cur_col(&app.buf);
|
|
|
|
|
- return app;
|
|
|
|
|
|
|
+ (void) dir;
|
|
|
|
|
+ buffer_insert_char(app->cbuf, '\n', app->cbuf->cur);
|
|
|
|
|
+ app->cbuf->high_col = buffer_calc_cur_col(app->cbuf);
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
-struct app
|
|
|
|
|
-keybind_toggle_fps(struct app app, union keybind_args args)
|
|
|
|
|
|
|
+void
|
|
|
|
|
+keybind_toggle_fps(struct app *app, enum keybind_dir dir)
|
|
|
{
|
|
{
|
|
|
- (void) args;
|
|
|
|
|
- app.show_fps = ! app.show_fps;
|
|
|
|
|
- return app;
|
|
|
|
|
|
|
+ (void) dir;
|
|
|
|
|
+ app->show_fps = ! app->show_fps;
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
-struct app
|
|
|
|
|
-keybind_mv_cur_end_buffer(struct app app, union keybind_args args)
|
|
|
|
|
|
|
+void
|
|
|
|
|
+keybind_mv_cur_end_buffer(struct app *app, enum keybind_dir dir)
|
|
|
{
|
|
{
|
|
|
- switch ( args.dir ) {
|
|
|
|
|
|
|
+ switch ( dir ) {
|
|
|
case DIR_FORWARD: {
|
|
case DIR_FORWARD: {
|
|
|
- app.buf.cur = app.buf.data.size;
|
|
|
|
|
|
|
+ app->cbuf->cur = app->cbuf->data.size;
|
|
|
} break;
|
|
} break;
|
|
|
case DIR_BACKWARD: {
|
|
case DIR_BACKWARD: {
|
|
|
- app.buf.cur = 0;
|
|
|
|
|
|
|
+ app->cbuf->cur = 0;
|
|
|
} break;
|
|
} break;
|
|
|
default: {
|
|
default: {
|
|
|
fprintf(stderr, "Got invalid direction in %s: %d",
|
|
fprintf(stderr, "Got invalid direction in %s: %d",
|
|
|
- __func__, args.dir);
|
|
|
|
|
|
|
+ __func__, dir);
|
|
|
exit(EXIT_FAILURE);
|
|
exit(EXIT_FAILURE);
|
|
|
} break;
|
|
} break;
|
|
|
}
|
|
}
|
|
|
- app.buf.high_col = buffer_calc_cur_col(&app.buf);
|
|
|
|
|
- return app;
|
|
|
|
|
|
|
+ app->cbuf->high_col = buffer_calc_cur_col(app->cbuf);
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
#endif /* defined(KEYBIND_IMP) || defined(IMP) */
|
|
#endif /* defined(KEYBIND_IMP) || defined(IMP) */
|