sled

Једноставни уређивач текста
git clone https://git.sr.ht/~strahinja/sled
Дневник | Датотеке | Референце | ПРОЧИТАЈМЕ | ЛИЦЕНЦА

чување 8b00c7c489861fc29aadb0c754220fc9866f35e1
родитељ 9c8786f11b3d0fdcb6bffa39cf460d01136baa47
Аутор: Страхиња Радић <contact@strahinja.org>
Датум:   Mon, 17 Jun 2024 21:01:16 +0200

Make functions local to compilation unit static

Diffstat:
Msled.c | 164++++++++++++++++++++++++++++++++++++++++----------------------------------------
Msled.h | 169++++++++++++++++++++++++++++++++++++++++---------------------------------------
измењених датотека: 2, додавања: 167(+), брисања: 166(-)

diff --git a/sled.c b/sled.c @@ -108,7 +108,7 @@ clear_selection(struct DrawState* state) #define MAXCOPYBUF 8192 -int +static int cp(const char* from, const char* to) { int fromfd, tofd; @@ -167,7 +167,7 @@ cp_cleanup: return result; } -int +static int create_file(struct DrawState* state) { struct BufferLine* newchunk = NULL; @@ -200,7 +200,7 @@ create_file(struct DrawState* state) return LOAD_ERR_NONE; } -int +static int cut_to_paste(struct DrawState* state) { simple_yank(state); @@ -210,7 +210,7 @@ cut_to_paste(struct DrawState* state) return 0; } -char* +static char* dirname(char* dir, char* path, const size_t dir_size) { char* p = NULL; @@ -241,7 +241,7 @@ dirname(char* dir, char* path, const size_t dir_size) return dir; } -int +static int do_search_replace(struct DrawState* state) { uint32_t* buf = NULL; @@ -326,7 +326,7 @@ do_search_replace_error: return 1; } -int +static int enter_command_mode(struct DrawState* state) { if (!state) @@ -335,7 +335,7 @@ enter_command_mode(struct DrawState* state) return 0; } -int +static int enter_insert_mode(struct DrawState* state) { if (!state) @@ -344,7 +344,7 @@ enter_insert_mode(struct DrawState* state) return 0; } -int +static int erase_backwards(struct DrawState* state) { struct BufferLine* buffer_line = &state->buffer[state->coord.row]; @@ -379,7 +379,7 @@ erase_backwards(struct DrawState* state) return 0; } -int +static int erase_forward(struct DrawState* state) { struct BufferLine* buffer_line = &state->buffer[state->coord.row]; @@ -409,7 +409,7 @@ erase_forward(struct DrawState* state) return 0; } -int +static int erase_line(struct DrawState* state) { struct BufferLine* current = NULL; @@ -436,7 +436,7 @@ erase_line(struct DrawState* state) return 0; } -int +static int erase_prev_word(struct DrawState* state) { int i = state->coord.col; @@ -466,7 +466,7 @@ erase_prev_word(struct DrawState* state) return 0; } -int +static int erase_selection(struct DrawState* state) { if (SEL_NOT_EMPTY(state)) @@ -519,7 +519,7 @@ erase_selection(struct DrawState* state) return 0; } -int +static int erase_to_end(struct DrawState* state) { struct BufferLine* buffer_line = &state->buffer[state->coord.row]; @@ -539,7 +539,7 @@ erase_to_end(struct DrawState* state) return 0; } -int +static int erase_to_start(struct DrawState* state) { size_t i = state->coord.col; @@ -566,7 +566,7 @@ erase_to_start(struct DrawState* state) return 0; } -int +static int exit_program(struct DrawState* state) { char* temp = NULL; @@ -633,7 +633,7 @@ get_selection(int* ssr, int* ssc, int* ser, int* sec, } } -int +static int go_to_line_callback(struct DrawState* state) { size_t lineno = 0; @@ -677,7 +677,7 @@ go_to_line_callback(struct DrawState* state) return 0; } -void +static void handle_key_event(struct tb_event* ev, struct DrawState* state) { const struct Key* current = NULL; @@ -799,7 +799,7 @@ handle_key_event(struct tb_event* ev, struct DrawState* state) MEMCCPY(state->error, errors[ERR_UNKNOWN_KEY], LINE_DEFAULT, temp); } -int +static int input_cancel(struct DrawState* state) { if (*state->error) @@ -817,7 +817,7 @@ input_cancel(struct DrawState* state) return 0; } -int +static int input_enter(struct DrawState* state) { int hide_dialog = 1; @@ -841,7 +841,7 @@ input_enter(struct DrawState* state) return 0; } -int +static int input_erase_backwards(struct DrawState* state) { if (state->input_column > 0) @@ -860,7 +860,7 @@ input_erase_backwards(struct DrawState* state) return 0; } -int +static int input_erase_forward(struct DrawState* state) { if (state->input) @@ -878,7 +878,7 @@ input_erase_forward(struct DrawState* state) return 0; } -int +static int input_erase_to_end(struct DrawState* state) { uint32_t* temp = NULL; @@ -890,7 +890,7 @@ input_erase_to_end(struct DrawState* state) return 0; } -int +static int input_erase_to_start(struct DrawState* state) { size_t i = state->input_column; @@ -908,7 +908,7 @@ input_erase_to_start(struct DrawState* state) return 0; } -int +static int input_insert_char(struct DrawState* state, uint32_t ch) { size_t len = u32_strlen(state->input); @@ -931,26 +931,26 @@ input_insert_char(struct DrawState* state, uint32_t ch) return 0; } -int +static int input_insert_space(struct DrawState* state) { return input_insert_char(state, ' '); } -int +static int input_insert_tab(struct DrawState* state) { return input_insert_char(state, '\t'); } -int +static int input_move_end(struct DrawState* state) { input_position_to(state, u32_strlen(state->input)); return 0; } -int +static int input_move_left(struct DrawState* state) { if (state->input_column == 0) @@ -959,7 +959,7 @@ input_move_left(struct DrawState* state) return 0; } -int +static int input_move_next_word(struct DrawState* state) { int i = state->input_column; @@ -974,7 +974,7 @@ input_move_next_word(struct DrawState* state) return 0; } -int +static int input_move_prev_word(struct DrawState* state) { int i = state->input_column; @@ -991,21 +991,21 @@ input_move_prev_word(struct DrawState* state) return 0; } -int +static int input_move_right(struct DrawState* state) { input_position_to(state, state->input_column + 1); return 0; } -int +static int input_move_start(struct DrawState* state) { input_position_to(state, 0); return 0; } -void +static void input_position_to(struct DrawState* state, const int column) { size_t len = u32_strlen(state->input); @@ -1023,7 +1023,7 @@ input_position_to(struct DrawState* state, const int column) - (state->input_dialog_width - 4); } -int +static int insert_char(struct DrawState* state, uint32_t ch) { struct BufferLine* buffer_line = NULL; @@ -1097,7 +1097,7 @@ insert_char_error: return 1; } -int +static int insert_line(struct DrawState* state) { struct BufferLine* buffer_line = NULL; @@ -1138,19 +1138,19 @@ insert_line(struct DrawState* state) return 0; } -int +static int insert_space(struct DrawState* state) { return insert_char(state, ' '); } -int +static int insert_tab(struct DrawState* state) { return insert_char(state, '\t'); } -int +static int join_lines(struct DrawState* state) { /* Selection start row/col */ @@ -1217,7 +1217,7 @@ join_lines_error: return -1; } -int +static int load_file(struct DrawState* state) { struct BufferLine* newchunk = NULL; @@ -1325,7 +1325,7 @@ load_file_alloc_error: return LOAD_ERR_CANT_ALLOC; } -int +static int move_bottom(struct DrawState* state) { position_to(state, state->rows_count > 1 ? state->rows_count - 1 : 0, @@ -1333,14 +1333,14 @@ move_bottom(struct DrawState* state) return 0; } -int +static int move_down(struct DrawState* state) { position_to(state, state->coord.row + 1, state->coord.col); return 0; } -int +static int move_end(struct DrawState* state) { position_to(state, state->coord.row, @@ -1348,14 +1348,14 @@ move_end(struct DrawState* state) return 0; } -int +static int move_left(struct DrawState* state) { position_to(state, state->coord.row, state->coord.col - 1); return 0; } -int +static int move_next_word(struct DrawState* state) { int i = state->coord.col; @@ -1370,7 +1370,7 @@ move_next_word(struct DrawState* state) return 0; } -int +static int move_page_down(struct DrawState* state) { if ((size_t)(state->coord.row + state->maxy) < state->rows_count + 2) @@ -1381,7 +1381,7 @@ move_page_down(struct DrawState* state) return 0; } -int +static int move_page_up(struct DrawState* state) { if (state->coord.row > state->maxy - 2) @@ -1392,7 +1392,7 @@ move_page_up(struct DrawState* state) return 0; } -int +static int move_prev_word(struct DrawState* state) { int i = state->coord.col; @@ -1409,14 +1409,14 @@ move_prev_word(struct DrawState* state) return 0; } -int +static int move_right(struct DrawState* state) { position_to(state, state->coord.row, state->coord.col + 1); return 0; } -int +static int move_screen_bottom(struct DrawState* state) { if (state->rows_count + 2 < (size_t)state->maxy) @@ -1432,7 +1432,7 @@ move_screen_bottom(struct DrawState* state) return 0; } -int +static int move_screen_middle(struct DrawState* state) { if (state->rows_count + 2 < (size_t)state->maxy) @@ -1447,28 +1447,28 @@ move_screen_middle(struct DrawState* state) return 0; } -int +static int move_screen_top(struct DrawState* state) { position_to(state, state->first_shown.row, state->coord.col); return 0; } -int +static int move_start(struct DrawState* state) { position_to(state, state->coord.row, 0); return 0; } -int +static int move_top(struct DrawState* state) { position_to(state, 0, state->coord.col); return 0; } -int +static int move_up(struct DrawState* state) { position_to(state, state->coord.row > 1 ? state->coord.row - 1 : 0, @@ -1476,7 +1476,7 @@ move_up(struct DrawState* state) return 0; } -int +static int next_match(struct DrawState* state) { struct BufferLine* current = NULL; @@ -1509,7 +1509,7 @@ next_match(struct DrawState* state) return 0; } -int +static int paste_from_paste(struct DrawState* state) { uint32_t* newtext = NULL; @@ -1659,7 +1659,7 @@ paste_from_paste_cleanup: * state->saved_column - display coordinate * row, column - buffer coordinates (not display) */ -void +static void position_to(struct DrawState* state, const int row, const int column) { size_t dlen; @@ -1739,7 +1739,7 @@ position_to(struct DrawState* state, const int row, const int column) assign_coord(&state->sel_end, state->coord); } -int +static int position_to_selection_start(struct DrawState* state) { if (SEL_NOT_EMPTY(state)) @@ -1757,7 +1757,7 @@ position_to_selection_start(struct DrawState* state) return 0; } -int +static int prev_match(struct DrawState* state) { struct BufferLine* current = NULL; @@ -1809,7 +1809,7 @@ prev_match(struct DrawState* state) return 0; } -int +static int print_error(const int code, const char* msg, ...) { char buf[LINE_DEFAULT]; @@ -1821,7 +1821,7 @@ print_error(const int code, const char* msg, ...) return code; } -int +static int quit_callback(struct DrawState* state, struct tb_event* ev) { if (!state) @@ -1835,7 +1835,7 @@ quit_callback(struct DrawState* state, struct tb_event* ev) return 0; } -int +static int reread_callback(struct DrawState* state, struct tb_event* ev) { if (!state) @@ -1848,7 +1848,7 @@ reread_callback(struct DrawState* state, struct tb_event* ev) return 0; } -int +static int reread_file(struct DrawState* state) { int result; @@ -1875,7 +1875,7 @@ reread_file(struct DrawState* state) return result; } -int +static int reread_or_callback(struct DrawState* state) { char* temp = NULL; @@ -1893,7 +1893,7 @@ reread_or_callback(struct DrawState* state) return 0; } -int +static int save_file(struct DrawState* state) { FILE* output = NULL; @@ -2034,7 +2034,7 @@ save_file_cleanup: return result; } -int +static int search_dialog_callback(struct DrawState* state) { next_match(state); @@ -2043,7 +2043,7 @@ search_dialog_callback(struct DrawState* state) return 0; } -int +static int search_replace_replace_dialog_callback(struct DrawState* state) { do_search_replace(state); @@ -2056,7 +2056,7 @@ search_replace_replace_dialog_callback(struct DrawState* state) return 0; } -int +static int search_replace_search_dialog_callback(struct DrawState* state) { /*next_match(state);*/ @@ -2067,7 +2067,7 @@ search_replace_search_dialog_callback(struct DrawState* state) return 0; } -int +static int search_update_callback(struct DrawState* state) { uint32_t* temp = NULL; @@ -2075,7 +2075,7 @@ search_update_callback(struct DrawState* state) return 0; } -int +static int show_go_to_line(struct DrawState* state) { char* temp = NULL; @@ -2099,7 +2099,7 @@ show_go_to_line(struct DrawState* state) return 0; } -int +static int show_help(struct DrawState* state) { SET(state->mode, M_HELP); @@ -2107,7 +2107,7 @@ show_help(struct DrawState* state) return 0; } -int +static int show_replace(struct DrawState* state) { char* temp = NULL; @@ -2133,7 +2133,7 @@ show_replace(struct DrawState* state) return 0; } -int +static int show_search(struct DrawState* state) { char* temp = NULL; @@ -2170,7 +2170,7 @@ show_search(struct DrawState* state) return 0; } -int +static int show_search_replace(struct DrawState* state) { char* temp = NULL; @@ -2208,7 +2208,7 @@ show_search_replace(struct DrawState* state) return 0; } -void +static void simple_insert_line(struct DrawState* state) { struct BufferLine* newchunk = NULL; @@ -2263,7 +2263,7 @@ simple_insert_line_error: return; } -void +static void simple_join_lines(struct DrawState* state) { size_t first_line = state->coord.row; @@ -2304,7 +2304,7 @@ simple_join_lines_error: return; } -void +static void simple_yank(struct DrawState* state) { /* Selection start row/col */ @@ -2395,7 +2395,7 @@ simple_yank_alloc_error: return; } -int +static int suspend_program(struct DrawState* state) { tb_set_clear_attrs(TB_WHITE, TB_DEFAULT); @@ -2422,7 +2422,7 @@ suspend_program(struct DrawState* state) return 0; } -int +static int toggle_overwrite(struct DrawState* state) { TOGGLE(state->mode, M_OVERWRITE); @@ -2430,7 +2430,7 @@ toggle_overwrite(struct DrawState* state) return 0; } -int +static int toggle_selection(struct DrawState* state) { TOGGLE(state->mode, M_SELECTION); @@ -2440,7 +2440,7 @@ toggle_selection(struct DrawState* state) return 0; } -int +static int write_file(struct DrawState* state) { int result; @@ -2482,7 +2482,7 @@ write_file(struct DrawState* state) return result; } -int +static int yank_to_paste(struct DrawState* state) { simple_yank(state); diff --git a/sled.h b/sled.h @@ -2,89 +2,90 @@ * any later version. Copyright (C) 2022-2024 Страхиња Радић. * See the file LICENSE for exact copyright and license details. */ -int cancel_close(struct DrawState* state); -int clear_selection(struct DrawState* state); -int cp(const char* from, const char* to); -int create_file(struct DrawState* dstate); -int cut_to_paste(struct DrawState* state); -char* dirname(char* dir, char* path, const size_t path_size); -int do_search_replace(struct DrawState* state); -int enter_command_mode(struct DrawState* state); -int enter_insert_mode(struct DrawState* state); -int erase_backwards(struct DrawState* state); -int erase_forward(struct DrawState* state); -int erase_line(struct DrawState* state); -int erase_prev_word(struct DrawState* state); -int erase_selection(struct DrawState* state); -int erase_to_end(struct DrawState* state); -int erase_to_start(struct DrawState* state); -int exit_program(struct DrawState* state); +static int cancel_close(struct DrawState* state); +static int clear_selection(struct DrawState* state); +static int cp(const char* from, const char* to); +static int create_file(struct DrawState* dstate); +static int cut_to_paste(struct DrawState* state); +static char* dirname(char* dir, char* path, const size_t path_size); +static int do_search_replace(struct DrawState* state); +static int enter_command_mode(struct DrawState* state); +static int enter_insert_mode(struct DrawState* state); +static int erase_backwards(struct DrawState* state); +static int erase_forward(struct DrawState* state); +static int erase_line(struct DrawState* state); +static int erase_prev_word(struct DrawState* state); +static int erase_selection(struct DrawState* state); +static int erase_to_end(struct DrawState* state); +static int erase_to_start(struct DrawState* state); +static int exit_program(struct DrawState* state); void get_selection(int* ssr, int* ssc, int* ser, int* sec, const struct DrawState* state); -int go_to_line_callback(struct DrawState* state); -void handle_key_event(struct tb_event* ev, struct DrawState* state); -int input_cancel(struct DrawState* state); -int input_enter(struct DrawState* state); -int input_erase_backwards(struct DrawState* state); -int input_erase_forward(struct DrawState* state); -int input_erase_to_end(struct DrawState* state); -int input_erase_to_start(struct DrawState* state); -int input_insert_char(struct DrawState* state, uint32_t ch); -int input_insert_space(struct DrawState* state); -int input_insert_tab(struct DrawState* state); -int input_move_end(struct DrawState* state); -int input_move_left(struct DrawState* state); -int input_move_next_word(struct DrawState* state); -int input_move_prev_word(struct DrawState* state); -int input_move_right(struct DrawState* state); -int input_move_start(struct DrawState* state); -void input_position_to(struct DrawState* state, const int column); -int insert_char(struct DrawState* state, uint32_t ch); -int insert_line(struct DrawState* state); -int insert_space(struct DrawState* state); -int insert_tab(struct DrawState* state); -int join_lines(struct DrawState* state); -int load_file(struct DrawState* dstate); -int move_bottom(struct DrawState* state); -int move_down(struct DrawState* state); -int move_end(struct DrawState* state); -int move_left(struct DrawState* state); -int move_next_word(struct DrawState* state); -int move_page_down(struct DrawState* state); -int move_page_up(struct DrawState* state); -int move_prev_word(struct DrawState* state); -int move_right(struct DrawState* state); -int move_screen_bottom(struct DrawState* state); -int move_screen_middle(struct DrawState* state); -int move_screen_top(struct DrawState* state); -int move_start(struct DrawState* state); -int move_top(struct DrawState* state); -int move_up(struct DrawState* state); -int next_match(struct DrawState* state); -int paste_from_paste(struct DrawState* state); -void position_to(struct DrawState* state, const int row, const int column); -int position_to_selection_start(struct DrawState* state); -int prev_match(struct DrawState* state); -int print_error(const int code, const char* msg, ...); -int quit_callback(struct DrawState* state, struct tb_event* ev); -int reread_callback(struct DrawState* state, struct tb_event* ev); -int reread_file(struct DrawState* state); -int reread_or_callback(struct DrawState* state); -int save_file(struct DrawState* state); -int search_dialog_callback(struct DrawState* state); -int search_replace_replace_dialog_callback(struct DrawState* state); -int search_replace_search_dialog_callback(struct DrawState* state); -int search_update_callback(struct DrawState* state); -int show_go_to_line(struct DrawState* state); -int show_help(struct DrawState* state); -int show_replace(struct DrawState* state); -int show_search(struct DrawState* state); -int show_search_replace(struct DrawState* state); -void simple_insert_line(struct DrawState* state); -void simple_join_lines(struct DrawState* state); -void simple_yank(struct DrawState* state); -int suspend_program(struct DrawState* state); -int toggle_overwrite(struct DrawState* state); -int toggle_selection(struct DrawState* state); -int write_file(struct DrawState* state); -int yank_to_paste(struct DrawState* state); +static int go_to_line_callback(struct DrawState* state); +static void handle_key_event(struct tb_event* ev, struct DrawState* state); +static int input_cancel(struct DrawState* state); +static int input_enter(struct DrawState* state); +static int input_erase_backwards(struct DrawState* state); +static int input_erase_forward(struct DrawState* state); +static int input_erase_to_end(struct DrawState* state); +static int input_erase_to_start(struct DrawState* state); +static int input_insert_char(struct DrawState* state, uint32_t ch); +static int input_insert_space(struct DrawState* state); +static int input_insert_tab(struct DrawState* state); +static int input_move_end(struct DrawState* state); +static int input_move_left(struct DrawState* state); +static int input_move_next_word(struct DrawState* state); +static int input_move_prev_word(struct DrawState* state); +static int input_move_right(struct DrawState* state); +static int input_move_start(struct DrawState* state); +static void input_position_to(struct DrawState* state, const int column); +static int insert_char(struct DrawState* state, uint32_t ch); +static int insert_line(struct DrawState* state); +static int insert_space(struct DrawState* state); +static int insert_tab(struct DrawState* state); +static int join_lines(struct DrawState* state); +static int load_file(struct DrawState* dstate); +static int move_bottom(struct DrawState* state); +static int move_down(struct DrawState* state); +static int move_end(struct DrawState* state); +static int move_left(struct DrawState* state); +static int move_next_word(struct DrawState* state); +static int move_page_down(struct DrawState* state); +static int move_page_up(struct DrawState* state); +static int move_prev_word(struct DrawState* state); +static int move_right(struct DrawState* state); +static int move_screen_bottom(struct DrawState* state); +static int move_screen_middle(struct DrawState* state); +static int move_screen_top(struct DrawState* state); +static int move_start(struct DrawState* state); +static int move_top(struct DrawState* state); +static int move_up(struct DrawState* state); +static int next_match(struct DrawState* state); +static int paste_from_paste(struct DrawState* state); +static void position_to(struct DrawState* state, const int row, + const int column); +static int position_to_selection_start(struct DrawState* state); +static int prev_match(struct DrawState* state); +static int print_error(const int code, const char* msg, ...); +static int quit_callback(struct DrawState* state, struct tb_event* ev); +static int reread_callback(struct DrawState* state, struct tb_event* ev); +static int reread_file(struct DrawState* state); +static int reread_or_callback(struct DrawState* state); +static int save_file(struct DrawState* state); +static int search_dialog_callback(struct DrawState* state); +static int search_replace_replace_dialog_callback(struct DrawState* state); +static int search_replace_search_dialog_callback(struct DrawState* state); +static int search_update_callback(struct DrawState* state); +static int show_go_to_line(struct DrawState* state); +static int show_help(struct DrawState* state); +static int show_replace(struct DrawState* state); +static int show_search(struct DrawState* state); +static int show_search_replace(struct DrawState* state); +static void simple_insert_line(struct DrawState* state); +static void simple_join_lines(struct DrawState* state); +static void simple_yank(struct DrawState* state); +static int suspend_program(struct DrawState* state); +static int toggle_overwrite(struct DrawState* state); +static int toggle_selection(struct DrawState* state); +static int write_file(struct DrawState* state); +static int yank_to_paste(struct DrawState* state);