Remove use of FOREACH macros

This commit is contained in:
Sebastian Ramacher 2023-12-03 23:59:28 +01:00
parent a7f6b74b7d
commit fa210e8d89

View File

@ -139,12 +139,10 @@ cmd_marks_add(girara_session_t* session, girara_list_t* argument_list)
return false; return false;
} }
bool bool cmd_marks_delete(girara_session_t* session, girara_list_t* argument_list) {
cmd_marks_delete(girara_session_t* session, girara_list_t* argument_list)
{
g_return_val_if_fail(session != NULL, false); g_return_val_if_fail(session != NULL, false);
g_return_val_if_fail(session->global.data != NULL, false); g_return_val_if_fail(session->global.data != NULL, false);
zathura_t* zathura = (zathura_t*) session->global.data; zathura_t* zathura = (zathura_t*)session->global.data;
if (girara_list_size(argument_list) < 1) { if (girara_list_size(argument_list) < 1) {
return false; return false;
@ -154,23 +152,22 @@ cmd_marks_delete(girara_session_t* session, girara_list_t* argument_list)
return false; return false;
} }
GIRARA_LIST_FOREACH_BODY_WITH_ITER(argument_list, char*, iter, key_string, for (size_t idx = 0; idx != girara_list_size(argument_list); ++idx) {
char* key_string = girara_list_nth(argument_list, idx);
if (key_string == NULL) { if (key_string == NULL) {
girara_list_iterator_next(iter);
continue; continue;
} }
for (unsigned int i = 0; i < strlen(key_string); i++) { for (unsigned int i = 0; i < strlen(key_string); i++) {
char key = key_string[i]; char key = key_string[i];
if (((key >= 0x41 && key <= 0x5A) || (key >= if (((key >= 0x41 && key <= 0x5A) || (key >= 0x61 && key <= 0x7A)) == false) {
0x61 && key <= 0x7A)) == false) {
continue; continue;
} }
/* search for existing mark */ /* search for existing mark */
girara_list_iterator_t* mark_iter = girara_list_iterator(zathura->global.marks); girara_list_iterator_t* mark_iter = girara_list_iterator(zathura->global.marks);
do { do {
zathura_mark_t* mark = (zathura_mark_t*) girara_list_iterator_data(mark_iter); zathura_mark_t* mark = (zathura_mark_t*)girara_list_iterator_data(mark_iter);
if (mark == NULL) { if (mark == NULL) {
continue; continue;
} }
@ -182,14 +179,12 @@ cmd_marks_delete(girara_session_t* session, girara_list_t* argument_list)
} while (girara_list_iterator_next(mark_iter) != NULL); } while (girara_list_iterator_next(mark_iter) != NULL);
girara_list_iterator_free(mark_iter); girara_list_iterator_free(mark_iter);
} }
); }
return true; return true;
} }
static void static void mark_add(zathura_t* zathura, int key) {
mark_add(zathura_t* zathura, int key)
{
if (zathura == NULL || zathura->document == NULL || zathura->global.marks == NULL) { if (zathura == NULL || zathura->document == NULL || zathura->global.marks == NULL) {
return; return;
} }
@ -198,19 +193,19 @@ mark_add(zathura_t* zathura, int key)
double position_x = zathura_document_get_position_x(zathura->document); double position_x = zathura_document_get_position_x(zathura->document);
double position_y = zathura_document_get_position_y(zathura->document); double position_y = zathura_document_get_position_y(zathura->document);
double zoom = zathura_document_get_zoom(zathura->document); double zoom = zathura_document_get_zoom(zathura->document);
/* search for existing mark */ /* search for existing mark */
GIRARA_LIST_FOREACH_BODY_WITH_ITER(zathura->global.marks, zathura_mark_t*, iter, mark, for (size_t idx = 0; idx != girara_list_size(zathura->global.marks); ++idx) {
zathura_mark_t* mark = girara_list_nth(zathura->global.marks, idx);
if (mark->key == key) { if (mark->key == key) {
mark->page = page_id; mark->page = page_id;
mark->position_x = position_x; mark->position_x = position_x;
mark->position_y = position_y; mark->position_y = position_y;
mark->zoom = zoom; mark->zoom = zoom;
girara_list_iterator_free(iter);
return; return;
} }
); }
/* add new mark */ /* add new mark */
zathura_mark_t* mark = g_try_malloc0(sizeof(zathura_mark_t)); zathura_mark_t* mark = g_try_malloc0(sizeof(zathura_mark_t));
@ -227,18 +222,16 @@ mark_add(zathura_t* zathura, int key)
girara_list_append(zathura->global.marks, mark); girara_list_append(zathura->global.marks, mark);
} }
static void static void mark_evaluate(zathura_t* zathura, int key) {
mark_evaluate(zathura_t* zathura, int key)
{
if (zathura == NULL || zathura->global.marks == NULL) { if (zathura == NULL || zathura->global.marks == NULL) {
return; return;
} }
/* search for existing mark */ /* search for existing mark */
GIRARA_LIST_FOREACH_BODY(zathura->global.marks, zathura_mark_t*, mark, for (size_t idx = 0; idx != girara_list_size(zathura->global.marks); ++idx) {
zathura_mark_t* mark = girara_list_nth(zathura->global.marks, idx);
if (mark != NULL && mark->key == key) { if (mark != NULL && mark->key == key) {
zathura_document_set_zoom(zathura->document, zathura_document_set_zoom(zathura->document, zathura_correct_zoom_value(zathura->ui.session, mark->zoom));
zathura_correct_zoom_value(zathura->ui.session, mark->zoom));
render_all(zathura); render_all(zathura);
zathura_jumplist_add(zathura); zathura_jumplist_add(zathura);
@ -246,9 +239,9 @@ mark_evaluate(zathura_t* zathura, int key)
position_set(zathura, mark->position_x, mark->position_y); position_set(zathura, mark->position_x, mark->position_y);
zathura_jumplist_add(zathura); zathura_jumplist_add(zathura);
break; return;
} }
); }
} }
void void