чување 5b7cdd2afe33f833eb8c16e36c6fb800367c51f2
родитељ 579d929fa5de671c615e549a19455970d8675c78
Аутор: Страхиња Радић <contact@strahinja.org>
Датум: Tue, 5 Oct 2021 14:58:32 +0200
Remove unnecessary checks
Signed-off-by: Страхиња Радић <contact@strahinja.org>
Diffstat:
| M | draw.c | | | 88 | ++++++++++++++++++++++++++++++++----------------------------------------------- |
| M | po.c | | | 25 | ++++++++++--------------- |
| M | poe.c | | | 46 | ++++++++++++++++++++-------------------------- |
измењених датотека: 3, додавања: 66(+), брисања: 93(-)
diff --git a/draw.c b/draw.c
@@ -12,7 +12,7 @@
#include "version.h"
static const char* help_title = "Main view help";
-static const char* help[] = {"",
+static const char* help[] = {
"Esc - Close dialog, clear error",
"Enter - Edit entry",
"H or F1 - Show this screen",
@@ -27,30 +27,30 @@ static const char* help[] = {"",
"k or \u2191 - Go to previous entry",
"j or \u2193 - Go to next entry",
"C-F or PgDn - Go to next page",
- "G or End - Go to last entry",
+ "G or End - Go to last entry",
"z or C-Z - Toggle fuzzy flag",
"q or C-Q - Quit",
"See the manual (man poe) for full help."};
static const char* editbox_title = "Edit translation";
-const char* errors[] = {
- [ERR_UNKNOWN_KEY] = "Unknown key (press H for help)",
- [ERR_EXIT_KEY] = "Press q or C-Q to quit",
- [ERR_DLG_OPEN] = "Press Esc to close dialog or q/C-Q to quit",
- [ERR_DLG_OPEN_QUIT] = "Press Esc to close dialog",
- [ERR_EMPTY_FILE] = "No msgids to edit",
- [ERR_CANT_ALLOC] = "Memory allocation failed",
- [ERR_CANT_SAVE] = "File is not writeable",
- [ERR_CANT_MOVE] = "Cannot move temporary file",
- [ERR_ILLEGAL_ON_FIRST] = "Not allowed on first entry"};
-const char* flag_strings[] = {
- [FL_C_FORMAT] = "c-format",
- [FL_NO_C_FORMAT] = "no-c-format",
- [FL_FUZZY] = "fuzzy"};
+const char* errors[] = {
+ [ERR_UNKNOWN_KEY] = "Unknown key (press H for help)",
+ [ERR_EXIT_KEY] = "Press q or C-Q to quit",
+ [ERR_DLG_OPEN] = "Press Esc to close dialog or q/C-Q to quit",
+ [ERR_DLG_OPEN_QUIT] = "Press Esc to close dialog",
+ [ERR_EMPTY_FILE] = "No msgids to edit",
+ [ERR_CANT_ALLOC] = "Memory allocation failed",
+ [ERR_CANT_SAVE] = "File is not writeable",
+ [ERR_CANT_MOVE] = "Cannot move temporary file",
+ [ERR_ILLEGAL_ON_FIRST] = "Not allowed on first entry"};
+const char* flag_strings[] = {
+ [FL_C_FORMAT] = "c-format",
+ [FL_NO_C_FORMAT] = "no-c-format",
+ [FL_FUZZY] = "fuzzy"};
const char* first_entry_msgid = "*** SPECIAL: file info ***";
const char* program_name = "poe";
const char* prompt_dirty = "File changed, save [y/n/ESC]?";
const char* prompt_cancel_dirty = "Entry changed, save [y/n/ESC]?";
-const char* prompt_overwrite = "Not empty, overwrite? [y/n/ESC]?";
+const char* prompt_overwrite = "Not empty, overwrite? [y/n/ESC]?";
void
init_bufferline(struct BufferLine* bl)
@@ -68,11 +68,8 @@ free_bufferline(struct BufferLine* bl)
{
if (!bl)
return;
- if (bl->text)
- {
- free(bl->text);
- bl->text = NULL;
- }
+ free(bl->text);
+ bl->text = NULL;
bl->length = 0;
bl->fg = 0;
bl->bg = 0;
@@ -130,45 +127,32 @@ free_drawstate(struct DrawState* state)
struct PoEntry* current_entry = NULL;
size_t i = 0;
- if (state->search)
- free(state->search);
+ free(state->search);
- if (state->input_buffer)
+ for (i = 0; i < state->input_rows_count; i++)
{
- for (i = 0; i < state->input_rows_count; i++)
- {
- current = state->input_buffer + i;
- free_bufferline(current);
- }
- free(state->input_buffer);
+ current = state->input_buffer + i;
+ free_bufferline(current);
}
- if (state->paste_buffer)
+ free(state->input_buffer);
+ for (i = 0; i < state->paste_rows_count; i++)
{
- for (i = 0; i < state->paste_rows_count; i++)
- {
- current = state->paste_buffer + i;
- free_bufferline(current);
- }
- free(state->paste_buffer);
+ current = state->paste_buffer + i;
+ free_bufferline(current);
}
- if (state->info_buffer)
+ free(state->paste_buffer);
+ for (i = 0; i < state->info_rows_count; i++)
{
- for (i = 0; i < state->info_rows_count; i++)
- {
- current = state->info_buffer + i;
- free_bufferline(current);
- }
- free(state->info_buffer);
+ current = state->info_buffer + i;
+ free_bufferline(current);
}
- if (state->entries)
+ free(state->info_buffer);
+ for (i = 0; i < state->real_msgid_count; i++)
{
- for (i = 0; i < state->real_msgid_count; i++)
- {
- current_entry = state->entries + i;
- free_po_entry(current_entry);
- }
- free(state->entries);
+ current_entry = state->entries + i;
+ free_po_entry(current_entry);
}
+ free(state->entries);
}
struct DrawState*
diff --git a/po.c b/po.c
@@ -49,8 +49,10 @@ init_po_entry(struct PoEntry* entry)
void
free_po_entry(struct PoEntry* entry)
{
- if (entry->msgid)
- free(entry->msgid);
+ if (!entry)
+ return;
+
+ free(entry->msgid);
if (entry->msgstr)
{
uint32_t** msgstr = entry->msgstr;
@@ -58,14 +60,10 @@ free_po_entry(struct PoEntry* entry)
free(*msgstr++);
free(entry->msgstr);
}
- if (entry->msgstr_size)
- free(entry->msgstr_size);
- if (entry->msgstr_len)
- free(entry->msgstr_len);
- if (entry->msgid_plural)
- free(entry->msgid_plural);
- if (entry->plural_forms)
- free(entry->plural_forms);
+ free(entry->msgstr_size);
+ free(entry->msgstr_len);
+ free(entry->msgid_plural);
+ free(entry->plural_forms);
if (entry->comments)
{
@@ -439,11 +437,8 @@ load_file(struct DrawState* dstate, long* lineno, long* col)
dstate->filename, *lineno, *col);
else
{
- if (dstate->entries)
- {
- free(dstate->entries);
- dstate->entries = NULL;
- }
+ free(dstate->entries);
+ dstate->entries = NULL;
return LOAD_PARSE_ERR(result);
}
(*lineno)++;
diff --git a/poe.c b/poe.c
@@ -220,12 +220,9 @@ load_info(struct DrawState* state)
struct BufferLine* newbuf = NULL;
struct BufferLine* pnewbuf = NULL;
- if (state->info_buffer)
- {
- for (size_t i = 0; i < state->info_rows_count; i++)
- free_bufferline(state->info_buffer + i);
- free(state->info_buffer);
- }
+ for (size_t i = 0; i < state->info_rows_count; i++)
+ free_bufferline(state->info_buffer + i);
+ free(state->info_buffer);
state->info_rows_maxlen = 0;
@@ -411,12 +408,9 @@ load_msgstr(struct DrawState* state)
struct BufferLine* newbuf = NULL;
struct BufferLine* pnewbuf = NULL;
- if (state->input_buffer)
- {
- for (size_t i = 0; i < state->input_rows_count; i++)
- free_bufferline(state->input_buffer + i);
- free(state->input_buffer);
- }
+ 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)
@@ -501,19 +495,18 @@ save_msgstr(struct DrawState* state)
}
free(state->input_buffer);
state->input_buffer = NULL;
- if (state->info_buffer)
- for (size_t i = 0; i < state->info_rows_count; i++)
- free_bufferline(state->info_buffer + i);
+ for (size_t i = 0; i < state->info_rows_count; i++)
+ free_bufferline(state->info_buffer + i);
free(state->info_buffer);
- state->info_buffer = NULL;
+ state->info_rows_count = 0;
+ state->info_buffer = NULL;
u32_encode_tabs(to_save, to_save_size * sizeof(uint32_t));
u32_set_msgstr(&state->entries[state->msgid_number - 1], to_save,
state->msgstr_index, 0, state);
state->input_changed_fuzzy = UNCHANGED;
tb_set_cursor(TB_HIDE_CURSOR, TB_HIDE_CURSOR);
- if (to_save)
- free(to_save);
+ free(to_save);
}
void
@@ -530,18 +523,19 @@ cancel_msgstr(struct DrawState* state)
state->show_edit = 0;
state->edit_info_focused = 0;
- if (state->input_buffer)
- for (size_t i = 0; i < state->input_rows_count; i++)
- free_bufferline(state->input_buffer + i);
+ for (size_t i = 0; i < state->input_rows_count; i++)
+ free_bufferline(state->input_buffer + i);
free(state->input_buffer);
- state->input_buffer = NULL;
+ state->input_buffer = NULL;
+ state->input_rows_count = 0;
if (state->info_buffer)
for (size_t i = 0; i < state->info_rows_count; i++)
free_bufferline(state->info_buffer + i);
free(state->info_buffer);
- state->info_buffer = NULL;
- state->dirty = state->dirty_before_edit;
- state->fuzzy_count = state->fuzzy_before_edit;
+ state->info_buffer = NULL;
+ state->info_rows_count = 0;
+ state->dirty = state->dirty_before_edit;
+ state->fuzzy_count = state->fuzzy_before_edit;
switch (state->input_changed_fuzzy)
{
case SET:
@@ -933,8 +927,8 @@ yank_msgstr_to_paste_buffer(struct DrawState* state)
for (size_t i = 0; i < state->paste_rows_count; i++)
free_bufferline(state->paste_buffer + i);
free(state->paste_buffer);
- state->paste_rows_count = 0;
state->paste_buffer = NULL;
+ state->paste_rows_count = 0;
return state;
}