From 1a21982ebc2747a694558c6e82cea54bd5dbead9 Mon Sep 17 00:00:00 2001 From: Mattias Andrée Date: Mon, 12 Apr 2021 00:07:26 +0200 Subject: Deduplicate code and make some minor improvements MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Mattias Andrée --- set-contact-groups.c | 11 +++++------ 1 file changed, 5 insertions(+), 6 deletions(-) (limited to 'set-contact-groups.c') diff --git a/set-contact-groups.c b/set-contact-groups.c index 2b8e3c1..f0408c5 100644 --- a/set-contact-groups.c +++ b/set-contact-groups.c @@ -39,7 +39,8 @@ main(int argc, char *argv[]) for (; *argv; argv++) { if (libcontacts_load_contact(*argv, &contact, user)) { - weprintf("libcontacts_load_contact %s: %s\n", *argv, errno ? strerror(errno) : "contact file is malformatted"); + weprintf("libcontacts_load_contact %s: %s\n", *argv, + errno ? strerror(errno) : "contact file is malformatted"); ret = 1; continue; } @@ -48,17 +49,15 @@ main(int argc, char *argv[]) if (!strcmp(contact.groups[i], group)) break; r = &contact.groups[i]; + if (!remove && !*r) + goto add_group; if (remove && *r) { free(*r); - for (w = r++; *r;) - *w++ = *r++; - *w = NULL; + for (w = r++; (*w++ = *r++);); if (libcontacts_save_contact(&contact, user)) { weprintf("libcontacts_save_contact %s:", *argv); ret = 1; } - } else if (!remove && !*r) { - goto add_group; } } else if (!remove) { i = 0; -- cgit v1.2.3-70-g09d2