From f848ec0a1a2bf17063774badfd734e22b4f9864d Mon Sep 17 00:00:00 2001 From: girst Date: Sat, 19 May 2018 00:47:39 +0200 Subject: [PATCH] clean up append_movement to not add same direction twice --- viiper.c | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/viiper.c b/viiper.c index a7c9ae1..af6a418 100644 --- a/viiper.c +++ b/viiper.c @@ -356,16 +356,18 @@ int getctrlseq (void) { } void append_movement (int dir) { + struct directions* n; + for (n = g.n; n && n->next; n = n->next); /* advance to the end, if any */ + if (n && n->d == dir) return; /* don't add the same direction twice */ + struct directions* new_event = malloc (sizeof(struct directions)); new_event->d = dir; new_event->next = NULL; - if (g.n == NULL) { + + if (g.n == NULL) g.n = new_event; - } else { - struct directions* n; - for (n = g.n; n->next; n = n->next); + else n->next = new_event; - } } int get_movement (void) { -- 2.39.3