shithub: vcardfs

Download patch

ref: e0cac8cff0fad58496578de0bf11f111f765d3a8
parent: bd24302cfec1f1e0566297e227e0570c4367a5d0
author: sirjofri <sirjofri@sirjofri.de>
date: Thu Nov 7 12:28:40 EST 2024

adjusts documentation, forces imported version to 4.0, supports 2.1 params

--- a/README.md
+++ b/README.md
@@ -9,7 +9,7 @@
 
 ### vcardfs
 
-Usage: vcardfs [-m mtpt] [-s srv] [database.vcf]
+Usage: `vcardfs [-m mtpt] [-s srv] [database.vcf]`
 
 Default database is at: /usr/$user/lib/vcarddb.vcf
 
@@ -19,15 +19,15 @@
 	   export
 	   John_Doe/
 	      export
-	      groupname.fn/
+	      0:groupname.fn/
 	         data
 	         group
 	         params/
 	            ...
-	      n/
+	      0:n/
 	         data
 	         ...
-	      tel/
+	      0:tel/
 	         data
 	         ...
 	   Jane_Doe/
@@ -39,6 +39,7 @@
 - `rm /mnt/vcard/John_Doe/fn` deletes the selected line
 - `rm /mnt/vcard/John_Doe/fn/params/type` deletes the param
 - `rm /mnt/vcard/John_Doe/fn/group` will delete the group association (not implemented yet)
+- `mkdir /mnt/vcard/John_Doe/tel` will create a new phone number field
 
 Future plans:
 
--- a/libvcard/vcard.y
+++ b/libvcard/vcard.y
@@ -58,7 +58,10 @@
 	vl = mallocz(sizeof(Vline), 1);
 	vl->name = name;
 	iltolower(vl->name);
-	vl->value = value;
+	if (strcmp(vl->name, "version") == 0)
+		vl->value = strdup("4.0");
+	else
+		vl->value = value;
 	vl->params = params;
 	vl->group = group;
 	/*
@@ -82,6 +85,31 @@
 	return vp;
 }
 
+static Vparam*
+appv2param(Vparam* p1, Vparam* p2)
+{
+	char *s;
+	s = smprint("%s,%s", p1->value, p2->value);
+	if (!s)
+		sysfatal("out of memory: %r");
+	free(p1->value);
+	free(p2->value);
+	free(p2->name);
+	free(p2);
+	p1->value = s;
+	return p1;
+}
+
+static Vparam*
+addv2param(char *s)
+{
+	Vparam *vp;
+	vp = mallocz(sizeof(Vparam), 1);
+	vp->name = strdup("type");
+	vp->value = s;
+	return vp;
+}
+
 %}
 
 %union {
@@ -101,6 +129,7 @@
 %type	<vc>	vclist vcard
 %type	<vl>	cline clinel
 %type	<vp>	params param
+%type   <vp>    v2params v2param
 %type	<s> 	group name value
 
 %%
@@ -124,7 +153,16 @@
 	  group '.' name params ':' value CRLF { $$ = mkline($3, $4, $6, $1); }
 	| name params ':' value CRLF { $$ = mkline($1, $2, $4, nil); }
 	| name ':' value CRLF { $$ = mkline($1, nil, $3, nil); }
+	| name v2params ':' value CRLF { $$ = mkline($1, $2, $4, nil); }
+	| group '.' name v2params ':' value CRLF { $$ = mkline($3, $4, $6, $1); }
 	;
+
+v2params:
+	  ';' v2param { $$ = $2; }
+	| ';' v2param v2params { $$ = $2; appv2param($2, $3); }
+    ;
+
+v2param: SWORD { $$ = addv2param($1); };
 
 params:
 	  ';' param { $$ = $2; }