aboutsummaryrefslogtreecommitdiffstats
path: root/set-contact-groups.c
diff options
context:
space:
mode:
authorMattias Andrée <maandree@kth.se>2021-04-12 00:07:26 +0200
committerMattias Andrée <maandree@kth.se>2021-04-12 00:07:26 +0200
commit1a21982ebc2747a694558c6e82cea54bd5dbead9 (patch)
tree42a145211772e876d85dfcc65655fa3130016313 /set-contact-groups.c
parentImprove set-contact- utils (diff)
downloadcontacts-1a21982ebc2747a694558c6e82cea54bd5dbead9.tar.gz
contacts-1a21982ebc2747a694558c6e82cea54bd5dbead9.tar.bz2
contacts-1a21982ebc2747a694558c6e82cea54bd5dbead9.tar.xz
Deduplicate code and make some minor improvements
Signed-off-by: Mattias Andrée <maandree@kth.se>
Diffstat (limited to 'set-contact-groups.c')
-rw-r--r--set-contact-groups.c11
1 files changed, 5 insertions, 6 deletions
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;