poe

Уређивач .po фајлова
Дневник | Датотеке | Референце | ПРОЧИТАЈМЕ | ЛИЦЕНЦА

чување d30b66b093ef7248f6653076dbdd982f876fe41e
родитељ 24d181a8a18567c7f775bcea9e11b6467cbec779
Аутор: Страхиња Радић <contact@strahinja.org>
Датум:   Mon,  7 Jun 2021 23:48:09 +0200

Rewrite to conform to C99

Signed-off-by: Страхиња Радић <contact@strahinja.org>

Diffstat:
Mconfig.def.h | 15+++++++++------
Mconfig.h | 15+++++++++------
Mdefault.o.do | 2+-
Mdraw.c | 16++++++++--------
Mdraw.h | 36++++++++++++++++++------------------
Mpo.h | 4++--
Mpoe.c | 27+++++++++++++++------------
Mpoe.do | 2+-
Mtermbox.c | 3+++
измењених датотека: 9, додавања: 66(+), брисања: 54(-)

diff --git a/config.def.h b/config.def.h @@ -1,12 +1,15 @@ /* See the file LICENSE for copyright and license details. */ void format_filename(char* result, size_t result_size, const char* format, - const DrawState* state); + const struct DrawState* state); void format_msgs(char* result, size_t result_size, const char* format, - const DrawState* state); + const struct DrawState* state); -static const StatusSegment status_segments[] = { - { "%s", format_filename, TB_BLACK, TB_WHITE, LEFT }, - { "msg:%ld/%ld", format_msgs, TB_WHITE | TB_BOLD, TB_BLUE, CENTER }, - { "H=HELP, q=QUIT", NULL, TB_BLACK, TB_WHITE, RIGHT }, +static const struct StatusSegment status_segments[] = { + { .format = "%s", .callback = format_filename, + .fg = TB_BLACK, .bg = TB_WHITE, .alignment = LEFT }, + { .format = "msg:%ld/%ld", .callback = format_msgs, + .fg = TB_WHITE | TB_BOLD, .bg = TB_BLUE, .alignment = CENTER }, + { .format = "H=HELP, q=QUIT", .callback = NULL, + .fg = TB_BLACK, .bg = TB_WHITE, .alignment = RIGHT }, }; diff --git a/config.h b/config.h @@ -1,12 +1,15 @@ /* See the file LICENSE for copyright and license details. */ void format_filename(char* result, size_t result_size, const char* format, - const DrawState* state); + const struct DrawState* state); void format_msgs(char* result, size_t result_size, const char* format, - const DrawState* state); + const struct DrawState* state); -static const StatusSegment status_segments[] = { - { "%s", format_filename, TB_BLACK, TB_WHITE, LEFT }, - { "msg:%ld/%ld", format_msgs, TB_WHITE | TB_BOLD, TB_BLUE, CENTER }, - { "H=HELP, q=QUIT", NULL, TB_BLACK, TB_WHITE, RIGHT }, +static const struct StatusSegment status_segments[] = { + { .format = "%s", .callback = format_filename, + .fg = TB_BLACK, .bg = TB_WHITE, .alignment = LEFT }, + { .format = "msg:%ld/%ld", .callback = format_msgs, + .fg = TB_WHITE | TB_BOLD, .bg = TB_BLUE, .alignment = CENTER }, + { .format = "H=HELP, q=QUIT", .callback = NULL, + .fg = TB_BLACK, .bg = TB_WHITE, .alignment = RIGHT }, }; diff --git a/default.o.do b/default.o.do @@ -1,3 +1,3 @@ redo-ifchange $2.c -gcc -g -Wall -c $2.c -o $3 +gcc -g -Wall -std=c99 -c $2.c -o $3 diff --git a/draw.c b/draw.c @@ -128,7 +128,7 @@ draw_string(const int x, const int y, const uint16_t fg, const uint16_t bg, } void -draw_help(const DrawState* state) +draw_help(const struct DrawState* state) { if (!state) return; @@ -158,7 +158,7 @@ draw_help(const DrawState* state) } void -draw_editbox(const DrawState* state) +draw_editbox(const struct DrawState* state) { if (!state) return; @@ -192,15 +192,15 @@ draw_editbox(const DrawState* state) } void -draw_status(const DrawState* state) +draw_status(const struct DrawState* state) { if (!state) return; char buf[MAXBUF]; - int seg_size = state->maxx/3; - int current_start = 0; - const StatusSegment* pseg = status_segments; + int seg_size = state->maxx/3; + int current_start = 0; + const struct StatusSegment* pseg = status_segments; if (state->error && state->error[0]) draw_string(0, state->maxy-1, ERROR_FG, ERROR_BG, state->error, @@ -224,7 +224,7 @@ draw_status(const DrawState* state) } void -draw_entry(const PoEntry* entry, const DrawState* state) +draw_entry(const struct PoEntry* entry, const struct DrawState* state) { if (!state) return; @@ -267,7 +267,7 @@ draw_entry(const PoEntry* entry, const DrawState* state) } void -draw(const DrawState* state) +draw(const struct DrawState* state) { if (!state) return; diff --git a/draw.h b/draw.h @@ -1,10 +1,10 @@ /* See the file LICENSE for copyright and license details. */ -#define BORDER_NW u'\u250c' -#define BORDER_NE u'\u2510' -#define BORDER_SW u'\u2514' -#define BORDER_SE u'\u2518' -#define BORDER_VER u'\u2502' -#define BORDER_HOR u'\u2500' +#define BORDER_NW ((uint32_t)L'\u250c') +#define BORDER_NE ((uint32_t)L'\u2510') +#define BORDER_SW ((uint32_t)L'\u2514') +#define BORDER_SE ((uint32_t)L'\u2518') +#define BORDER_VER ((uint32_t)L'\u2502') +#define BORDER_HOR ((uint32_t)L'\u2500') #define ERROR_FG TB_WHITE | TB_BOLD #define ERROR_BG TB_RED @@ -23,10 +23,10 @@ typedef enum { RIGHT } Alignment; -typedef struct { +struct DrawState { char* error; char* filename; - PoEntry* entries; + struct PoEntry* entries; int running; int show_help; int show_edit; @@ -34,17 +34,17 @@ typedef struct { int maxy; long msgid_number; long msgid_count; -} DrawState; +}; -typedef struct { +struct StatusSegment { const char* format; - void (*callback)(char*, size_t, const char*, const DrawState*); + void (*callback)(char*, size_t, const char*, const struct DrawState*); uint16_t fg; uint16_t bg; Alignment alignment; -} StatusSegment; +}; -extern PoEntry entries[]; +extern struct PoEntry entries[]; void draw_rect(const int startx, const int endx, const int starty, const int endy, const uint16_t fg, const uint16_t bg); @@ -53,9 +53,9 @@ void draw_box(const int startx, const int endx, const int starty, void draw_string(const int x, const int y, const uint16_t fg, const uint16_t bg, const char* s, const int max_cols, const int fill_cols, const int padding, const Alignment align); -void draw_help(const DrawState* st); -void draw_editbox(const DrawState* state); -void draw_status(const DrawState* st); -void draw_entry(const PoEntry* entry, const DrawState* st); -void draw(const DrawState* st); +void draw_help(const struct DrawState* st); +void draw_editbox(const struct DrawState* state); +void draw_status(const struct DrawState* st); +void draw_entry(const struct PoEntry* entry, const struct DrawState* st); +void draw(const struct DrawState* st); diff --git a/po.h b/po.h @@ -6,9 +6,9 @@ typedef enum { FL_FUZZY = 1 << 1, } Flags; -typedef struct { +struct PoEntry { Flags flags; char* msgid; char* msgstr; -} PoEntry; +}; diff --git a/poe.c b/poe.c @@ -1,4 +1,7 @@ /* See the file LICENSE for copyright and license details. */ + +#define _POSIX_C_SOURCE 200809L + #include <bits/stdint-uintn.h> #include <errno.h> #include <stdarg.h> @@ -32,7 +35,7 @@ print_error(const int code, const char* msg, ...) void format_filename(char* result, size_t result_size, const char* format, - const DrawState* state) + const struct DrawState* state) { if (!result) return; @@ -42,7 +45,7 @@ format_filename(char* result, size_t result_size, const char* format, void format_msgs(char* result, size_t result_size, const char* format, - const DrawState* state) + const struct DrawState* state) { if (!result) return; @@ -53,7 +56,7 @@ format_msgs(char* result, size_t result_size, const char* format, } void -handle_key_event(const struct tb_event* ev, DrawState* state) +handle_key_event(const struct tb_event* ev, struct DrawState* state) { if (!state) return; @@ -128,17 +131,17 @@ main(int argc, char** argv) struct tb_event ev; struct timespec sleep_spec; char error[MAXBUF]; - DrawState state; + struct DrawState state; FILE* input = NULL; char filename[MAXPATH]; /* Test */ - PoEntry entries[] = { - { flags: FL_C_FORMAT | FL_FUZZY, - msgid: "First msgid: %s", msgstr: "Први msgid: %s" }, - { flags: FL_NONE, - msgid: "Test msgid", msgstr: "Пробни msgstr" }, - { flags: FL_FUZZY, - msgid: "Final text", msgstr: "Последњи текст" }, + struct PoEntry entries[] = { + { .flags = FL_C_FORMAT | FL_FUZZY, + .msgid = "First msgid: %s", .msgstr = "Први msgid: %s" }, + { .flags = FL_NONE, + .msgid = "Test msgid", .msgstr = "Пробни msgstr" }, + { .flags = FL_FUZZY, + .msgid = "Final text", .msgstr = "Последњи текст" }, }; filename[0] = 0; @@ -162,7 +165,7 @@ main(int argc, char** argv) state.error = error; state.filename = filename; - state.entries = entries; + state.entries = &entries[0]; state.running = 1; state.show_edit = 0; state.show_help = 0; diff --git a/poe.do b/poe.do @@ -1,5 +1,5 @@ for f in *.c; do echo $f done | xargs redo-ifchange -gcc -g -Wall -o $3 poe.o draw.o termbox.o utf8.o util.o +gcc -g -Wall -std=c99 -o $3 poe.o draw.o termbox.o utf8.o util.o diff --git a/termbox.c b/termbox.c @@ -1,3 +1,6 @@ +#define _POSIX_C_SOURCE 200809L +#define _XOPEN_SOURCE + #include <assert.h> #include <stdlib.h> #include <string.h>