ref: e23fd2fce14cd0ea17a924503c334f9d63b8470a
parent: 614e174dca25e4fa70b5a79be5e08a3b3ba3474a
author: sirjofri <[email protected]>
date: Fri Oct 18 14:28:54 EDT 2024
compose name from N field (first and last name only)
--- a/README.md
+++ b/README.md
@@ -34,8 +34,9 @@
Future plans:
-- ctl: make commands work
-- import: make import work
+- ctl: make commands work (write/save, new)
+- export: uppercase properties, line breaks
+- import: update existing entries (how?)
- files: output with newline at the end?
### libvcard
--- a/vcardfs.c
+++ b/vcardfs.c
@@ -440,8 +440,6 @@
free(vf->serialized);
vf->serialized = nil;
- fprint(2, "serialized:\n%p", ncards);
-
initcardfiles(ncards);
for (nc = cards; nc->next; nc = nc->next)
@@ -457,10 +455,6 @@
.destroyfid = fsdestroyfid,
};
-/* TODO: LOOKAT:
- /sys/src/cmd/webcookies.c:/createfile
- /sys/src/cmd/aux/gps/gpsfs.c:/createfile
-*/
static char*
safename(char *n)
{
@@ -483,10 +477,36 @@
}
static char*
+composename(char *oname)
+{
+ char *s, *t;
+ char *args[5];
+
+ /* see also: rfc 6350, section 6.2.2 */
+ args[0] = /* last name */
+ args[1] = /* first name */
+ args[2] = /* additional names */
+ args[3] = /* honorific prefixes */
+ args[4] = nil; /* honorific suffixes */
+
+ s = estrdup(oname);
+ getfields(s, args, 5, 0, ";");
+ t = smprint(
+ "%s" /* first name */
+ "%s%s", /* last name */
+ args[1][0] ? args[1] : "",
+ args[0][0] ? " " : "", args[0][0] ? args[0] : ""
+ );
+ free(s);
+ return t;
+}
+
+static char*
getcardname(Vcard *c)
{
Vline *l;
Vline *fn = nil, *n = nil;
+ char *s, *sn;
for (l = c->content; l; l = l->next) {
if (cistrcmp(l->name, "fn") == 0)
@@ -499,8 +519,12 @@
if (fn)
return safename(fn->value);
- if (n)
- return safename(n->value);
+ if (n) {
+ s = composename(n->value);
+ sn = safename(s);
+ free(s);
+ return sn;
+ }
return nil;
}