чување 2e873ebffee0fdcaf367f20ebfed9ff6a39a94d5
родитељ f91aa7860c8e97ff54b4336b382e331de53ff1e0
Аутор: Страхиња Радић <contact@strahinja.org>
Датум: Tue, 15 Feb 2022 17:07:41 +0100
Remove unneeded code; update TODO
Signed-off-by: Страхиња Радић <contact@strahinja.org>
Diffstat:
| M | TODO | | | 7 | +++++-- |
| M | draw.c | | | 9 | --------- |
| M | draw.h | | | 2 | -- |
| M | sled.c | | | 164 | ------------------------------------------------------------------------------- |
| M | util.c | | | 286 | ------------------------------------------------------------------------------- |
| M | util.h | | | 15 | +-------------- |
измењених датотека: 6, додавања: 6(+), брисања: 477(-)
diff --git a/TODO b/TODO
@@ -2,8 +2,11 @@
====
[~] Create a working base by migration from poe
-
- [x] Implement "inverse vi mode"
+ [x] Implement "inverse vi mode"
+ [ ] Selections!
+ [ ] Selections modify behavior of eg. Delete key ->
+ DrawState.in_selection is needed
+ [ ] Copy/paste?
Legend
diff --git a/draw.c b/draw.c
@@ -169,15 +169,6 @@ calculate_help_width(const struct DrawState* state)
}
void
-draw_rect(const int startx, const int endx, const int starty, const int endy,
- const uint16_t fg, const uint16_t bg)
-{
- for (int y = starty; y < endy; y++)
- for (int x = startx; x < endx; x++)
- tb_change_cell(x, y, ' ', fg, bg);
-}
-
-void
draw_box(const int startx, const int endx, const int starty, const int endy,
const uint16_t fg, const uint16_t bg)
{
diff --git a/draw.h b/draw.h
@@ -72,8 +72,6 @@ size_t display_length(const struct DrawState* state, uint32_t* buffer,
size_t buffer_length(const struct DrawState* state, uint32_t* buffer,
const size_t max_index);
int calculate_help_width(const struct DrawState* state);
-void draw_rect(const int startx, const int endx, const int starty,
- const int endy, const uint16_t fg, const uint16_t bg);
void draw_box(const int startx, const int endx, const int starty,
const int endy, const uint16_t fg, const uint16_t bg);
const char* draw_string(const int x, const int y, const uint16_t fg,
diff --git a/sled.c b/sled.c
@@ -16,12 +16,9 @@
#include "version.h"
#include "termbox.h"
#include "util.h"
-//#include "po.h"
#include "draw.h"
#include "config.h"
-#define ALLOC_DELTA 10
-
enum {
LOAD_ERR_NONE = 0,
LOAD_ERR_CANT_ALLOC = 1,
@@ -135,52 +132,6 @@ format_position(char* result, size_t result_size, const char* format,
}
void
-format_msgs(char* result, size_t result_size, const char* format,
- const struct DrawState* state)
-{
- if (!result)
- return;
-}
-
-void
-overwrite_copy_msgid_callback(struct DrawState* state, struct tb_event* ev)
-{
- if (!state)
- return;
- /*
- if (ev->ch == 'y')
- copy_msgid_to_input(state);
- */
- state->prompt_callback = NULL;
-}
-
-void
-overwrite_paste_callback(struct DrawState* state, struct tb_event* ev)
-{
- if (!state)
- return;
- /*
- if (ev->ch == 'y')
- paste_paste_buffer_to_input(state);
- */
- state->prompt_callback = NULL;
-}
-
-void
-cancel_callback(struct DrawState* state, struct tb_event* ev)
-{
- if (!state)
- return;
-
- /*if (ev->ch == 'y')
- save_msgstr(state);
- else
- cancel_msgstr(state);
- */
- state->prompt_callback = NULL;
-}
-
-void
quit_callback(struct DrawState* state, struct tb_event* ev)
{
if (!state)
@@ -206,65 +157,6 @@ quit_callback(struct DrawState* state, struct tb_event* ev)
state->running = 0;
}
-struct DrawState*
-load_msgstr(struct DrawState* state)
-{
- /*
- int msgstr_index = state->msgstr_index;
- struct PoEntry* current = &state->entries[state->msgid_number
- - 1]; size_t num_lines = current->msgstr_count == 0 ? 1 :
- u32_lines_in_string(*(current->msgstr + msgstr_index), 0, 0); struct
- BufferLine* newbuf = NULL; struct BufferLine* pnewbuf = NULL;
-
- for (size_t i = 0; i < state->input_rows_count; i++)
- free_bufferline(state->input_buffer + i);
- free(state->input_buffer);
-
- newbuf = calloc(num_lines, sizeof(struct BufferLine));
- if (!newbuf)
- return NULL;
-
- pnewbuf = newbuf;
- for (size_t i = 0; i < num_lines; i++)
- {
- init_bufferline(pnewbuf);
- uint32_t* newtext = calloc(MAXBUFLINE,
- sizeof(uint32_t)); if (!newtext) return NULL; pnewbuf->text =
- newtext; pnewbuf++;
- }
-
- state->input_rows_count = num_lines;
-
- if (current->msgstr_count > 0)
- {
- const uint32_t* pumsgstr = *(current->msgstr +
- msgstr_index); if (pumsgstr)
- {
- pnewbuf = newbuf;
- while (*pumsgstr)
- {
- size_t len = 0;
- size_t newlen = 0;
- const uint32_t* old_pumsgstr = pumsgstr;
- len = u32_next_line(*(current->msgstr
- +
- msgstr_index), &pumsgstr, 0, 0); u32_strncpy(pnewbuf->text,
- old_pumsgstr, MIN(len + 1, MAXBUFLINE)); newlen =
- u32_decode_tabs(pnewbuf->text, MAXBUFLINE); pnewbuf->length = newlen;
- pnewbuf++;
- }
- }
- else
- newbuf[0].length = 0;
- }
- else
- newbuf[0].length = 0;
-
- state->input_buffer = newbuf;
- */
- return state;
-}
-
int
load_file(struct DrawState* dstate, long* lineno, long* col)
{
@@ -326,62 +218,6 @@ save_file(struct DrawState* state)
return SAVE_ERR_NONE;
}
-void
-save_msgstr(struct DrawState* state)
-{
- /*
- uint32_t* to_save = NULL;
- size_t to_save_size = 0;
- struct PoEntry* current = NULL;
-
- if (state->buffer)
- {
- to_save_size = state->input_rows_count * MAXMSGLINE;
- to_save = calloc(to_save_size, sizeof(uint32_t));
- if (!to_save)
- {
- strcpy(state->error, errors[ERR_CANT_ALLOC]);
- return;
- }
- struct BufferLine* pinput_buffer = NULL;
- for (size_t i = 0; i < state->input_rows_count; i++)
- {
- pinput_buffer = state->input_buffer + i;
- if (i == 0)
- u32_strncpy(to_save, pinput_buffer->text,
- to_save_size * sizeof(uint32_t));
- else
- {
- u32_strncat(to_save, (uint32_t*)L"\\n",
- to_save_size * sizeof(uint32_t));
- u32_strncat(to_save, pinput_buffer->text,
- to_save_size * sizeof(uint32_t));
- }
- free_bufferline(pinput_buffer);
- }
- }
- free(state->input_buffer);
- state->input_buffer = NULL;
- state->input_rows_count = 0;
- for (size_t i = 0; i < state->info_rows_count; i++)
- free_bufferline(state->info_buffer + i);
- free(state->info_buffer);
- state->dirty = (state->dirty_before_edit || state->dirty);
- state->info_rows_count = 0;
- state->info_buffer = NULL;
- u32_encode_tabs(to_save, to_save_size * sizeof(uint32_t));
- current = &state->entries[state->msgid_number - 1];
- u32_match_msgid_ending(current->msgid, to_save,
- to_save_size * sizeof(uint32_t));
- u32_set_msgstr(current, to_save, state->msgstr_index, 0, state);
- update_warning(current->msgid, to_save, ¤t->warning);
- state->input_changed_fuzzy = UNCHANGED;
-
- tb_set_cursor(TB_HIDE_CURSOR, TB_HIDE_CURSOR);
- free(to_save);
- */
-}
-
struct DrawState*
paste_paste_buffer_to_input(struct DrawState* state)
{
diff --git a/util.c b/util.c
@@ -7,7 +7,6 @@
#include <string.h>
#include "termbox.h"
-//#include "po.h"
#include "util.h"
size_t
@@ -58,157 +57,6 @@ unicode_string_to_u8(char* s, const uint32_t* us, const size_t max)
}
size_t
-u32_match_msgid_ending(const uint32_t* msgid, uint32_t* msgstr, size_t max)
-{
- uint32_t* buf = calloc(max + 1, sizeof(uint32_t));
- if (!buf)
- return 0;
- size_t buf_len = 0;
- size_t msgid_len = 0;
-
- buf_len = u32_strcpy(buf, msgstr);
- msgid_len = u32_strlen(msgid);
-
- if (msgid_len > 1
- && u32_starts_with(msgid + msgid_len - 2, (uint32_t*)L"\\n"))
- {
- if (!(buf_len > 1
- && u32_starts_with(buf + buf_len - 2,
- (uint32_t*)L"\\n")))
- {
- buf_len += 2;
- buf[buf_len - 2] = '\\';
- buf[buf_len - 1] = 'n';
- buf[buf_len] = 0;
- }
- }
- else if (msgid_len > 0
- && u32_strstr((uint32_t*)L" .", msgid + msgid_len - 1))
- {
- if (!(buf_len > 0
- && u32_strstr((uint32_t*)L" .", buf + buf_len - 1)))
- {
- buf_len++;
- buf[buf_len - 1] = msgid[msgid_len - 1];
- buf[buf_len] = 0;
- }
- }
- else if (buf_len > 1
- && u32_starts_with(buf + buf_len - 2, (uint32_t*)L"\\n"))
- {
- buf_len -= 2;
- buf[buf_len] = 0;
- }
- else if (buf_len > 0 && u32_strstr((uint32_t*)L" .", buf + buf_len - 1))
- {
- buf_len--;
- buf[buf_len] = 0;
- }
-
- u32_strncpy(msgstr, buf, max);
-
- return buf_len;
-}
-
-size_t
-u32_count_chars(const uint32_t* s, const uint32_t ch)
-{
- size_t result = 0;
- const uint32_t* ps = s;
- while (*ps)
- {
- if (*ps == ch)
- result++;
- ps++;
- }
- return result;
-}
-
-size_t
-u32_count_strings(const uint32_t* haystack, const uint32_t* needle)
-{
- size_t result = 0;
- const uint32_t* phaystack = haystack;
- size_t needle_len = 0;
-
- if (!haystack || !needle)
- return 0;
-
- needle_len = u32_strlen(needle);
- if (!needle_len)
- return 0;
-
- while (*phaystack)
- {
- if (u32_starts_with(phaystack, needle))
- result++;
- phaystack++;
- }
- return result;
-}
-
-size_t
-u32_encode_tabs(uint32_t* s, size_t max)
-{
- uint32_t* buf = calloc(max + 1, sizeof(uint32_t));
- if (!buf)
- return 0;
- uint32_t* pbuf = buf;
- uint32_t* ps = s;
- size_t newlen = 0;
-
- while (*ps)
- {
- if (*ps == '\t')
- {
- *pbuf++ = '\\';
- *pbuf++ = 't';
- ps++;
- newlen += 2;
- }
- else
- {
- *pbuf++ = *ps++;
- newlen++;
- }
- }
- *pbuf = 0;
- u32_strncpy(s, buf, max);
- free(buf);
- return newlen;
-}
-
-size_t
-u32_decode_tabs(uint32_t* s, size_t max)
-{
- uint32_t* buf = calloc(max + 1, sizeof(uint32_t));
- if (!buf)
- return 0;
- uint32_t* pbuf = buf;
- uint32_t* ps = s;
- size_t newlen = 0;
-
- while (*ps)
- {
- if (*ps == '\\' && *(ps + 1) == 't')
- {
- *pbuf++ = '\t';
- ps += 2;
- newlen++;
- }
- else
- {
- *pbuf++ = *ps++;
- newlen++;
- }
- }
- *pbuf = 0;
- u32_strncpy(s, buf, max);
- free(buf);
- return newlen;
-}
-
-size_t
u32_strlen(const uint32_t* s)
{
const uint32_t* ps = s;
@@ -221,19 +69,6 @@ u32_strlen(const uint32_t* s)
}
uint32_t*
-u32_strstr(uint32_t* haystack, const uint32_t* needle)
-{
- uint32_t* ph = haystack;
- while (*ph)
- {
- if (u32_starts_with(ph, needle))
- return ph;
- ph++;
- }
- return NULL;
-}
-
-uint32_t*
u32_strchr(uint32_t* haystack, const uint32_t needle)
{
uint32_t* ph = haystack;
@@ -309,116 +144,6 @@ u32_u8_strcpy(uint32_t* to, const char* from)
return len;
}
-size_t
-u32_u8_strncpy(uint32_t* to, const char* from, size_t max)
-{
- uint32_t* ufrom = calloc(strlen(from) + 1, sizeof(uint32_t));
- if (!ufrom)
- return 0;
- u8_string_to_unicode(ufrom, from, max);
- size_t len = u32_strncpy(to, ufrom, max);
- free(ufrom);
- return len;
-}
-
-size_t
-u8_u32_strncpy(char* to, const uint32_t* from, size_t max)
-{
- char* cfrom = calloc(u32_strlen(from) * UTF8REPMAX + 1, 1);
- if (!cfrom)
- return 0;
- unicode_string_to_u8(cfrom, from, max);
- strncpy(to, cfrom, max);
- to[max - 1] = 0;
- free(cfrom);
- return strlen(to);
-}
-
-/* wrap - if >0, also wrap lines
- * */
-size_t
-u32_lines_in_string(const uint32_t* s, const int include_eol, const size_t wrap)
-{
- size_t result = 1;
- const uint32_t* ps = NULL;
- int last_empty = 0;
-
- if (!s)
- return result;
-
- ps = s;
- while (*ps)
- {
- u32_next_line(s, &ps, include_eol, wrap);
- if (*ps)
- result++;
- }
- if (ps > s + 1 && *(ps - 2) == '\\' && *(ps - 1) == 'n')
- last_empty = 1;
- return result + last_empty;
-}
-
-/*
- * returns line length
- * s - entire string (multiple lines)
- * next_line - pointer to the next line; if NULL, only line length is returned
- * wrap - wrap lines to this many characters (runes); if 0, don't wrap
- */
-size_t
-u32_next_line(const uint32_t* s, const uint32_t** next_line,
- const int include_eol, const size_t wrap)
-{
- size_t result = 0;
- const uint32_t* ps = NULL;
- const uint32_t* start = NULL;
- size_t last_nonblank = 0;
- int have_last_nonblank = 0;
-
- if (!s)
- return result;
-
- start = s;
- if (next_line)
- start = *next_line;
- ps = start;
- while (*ps)
- {
- if (wrap > 0 && result > wrap)
- {
- size_t cutoff = wrap;
-
- if (have_last_nonblank)
- cutoff = last_nonblank + 1;
- if (next_line)
- *next_line = start + cutoff;
-
- return cutoff;
- }
-
- if (*ps == '\\' && *(ps + 1) == 'n')
- {
- if (next_line)
- *next_line = ps + 2;
- return result + (include_eol ? 2 : 0);
- }
-
- if (!u32_is_word_boundary(*ps, 1)
- && u32_is_word_boundary(*(ps + 1), 1))
- {
- last_nonblank = ps - start;
- have_last_nonblank = 1;
- }
-
- ps++;
- result++;
- }
-
- if (next_line)
- *next_line = ps;
-
- return result;
-}
-
int
u32_is_word_boundary(const uint32_t ch, const int strictly_whitespace)
{
@@ -465,14 +190,3 @@ u8_basename(const char* path)
ppath++;
return ppath;
}
-
-void
-poe_log(const char* msg, ...)
-{
- va_list args;
- va_start(args, msg);
- FILE* log = fopen("/tmp/poe.log", "at");
- vfprintf(log, msg, args);
- va_end(args);
- fclose(log);
-}
diff --git a/util.h b/util.h
@@ -26,6 +26,7 @@ enum {
ERR_NO_PLURAL_FORMS
};
+#define ALLOC_DELTA 50
#define MAXBUFLINE 4096
#define MAXDATEBUF 80
#define MAXFLAGSBUF (4 + 1)
@@ -37,27 +38,13 @@ enum {
size_t u8_string_to_unicode(uint32_t* us, const char* s, const size_t max);
size_t unicode_string_to_u8(char* s, const uint32_t* us, const size_t max);
-size_t u32_match_msgid_ending(const uint32_t* msgid, uint32_t* msgstr,
- size_t max);
-size_t u32_count_chars(const uint32_t* s, const uint32_t ch);
-size_t u32_count_strings(const uint32_t* haystack, const uint32_t* needle);
-size_t u32_encode_tabs(uint32_t* s, size_t max);
-size_t u32_decode_tabs(uint32_t* s, size_t max);
size_t u32_strlen(const uint32_t* s);
-uint32_t* u32_strstr(uint32_t* haystack, const uint32_t* needle);
uint32_t* u32_strchr(uint32_t* haystack, const uint32_t needle);
size_t u32_strcpy(uint32_t* to, const uint32_t* from);
size_t u32_strncpy(uint32_t* to, const uint32_t* from, size_t max);
size_t u32_strncat(uint32_t* to, const uint32_t* from, size_t max);
size_t u32_u8_strcpy(uint32_t* to, const char* from);
-size_t u32_u8_strncpy(uint32_t* to, const char* from, size_t max);
-size_t u8_u32_strncpy(char* to, const uint32_t* from, size_t max);
-size_t u32_lines_in_string(const uint32_t* s, const int include_eol,
- const size_t wrap);
-size_t u32_next_line(const uint32_t* s, const uint32_t** sptr,
- const int include_eol, const size_t wrap);
int u32_is_word_boundary(const uint32_t ch, const int strictly_whitespace);
int starts_with(const char* s, const char* with);
int u32_starts_with(const uint32_t* s, const uint32_t* with);
const char* u8_basename(const char* path);
-void poe_log(const char* msg, ...);