shithub: vcardfs

Download patch

ref: bb10512127f96aeb40f9f1e8f32768032c6425fe
parent: 8604a6db811e57e632a6e416fcc944e9884ddff5
author: sirjofri <[email protected]>
date: Fri Oct 18 04:09:57 EDT 2024

adds export stub file, default database at /usr/$user/lib/vcarddb.vcf

--- a/README.md
+++ b/README.md
@@ -9,12 +9,15 @@
 
 ### 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
+
 	/mnt/vcf/
 	   ctl
 	   import
 	   John_Doe/
+	      export
 	      fn/
 	         data
 	         params/
@@ -33,6 +36,7 @@
 - Make files writable
 - ctl: make commands work
 - import: make import work
+- export: make export work
 - files: output with newline at the end?
 
 ### libvcard
--- a/vcardfs.c
+++ b/vcardfs.c
@@ -8,14 +8,18 @@
 /* rough structure
 
 /john-doe/
+	export (export single contact as vcard file)
 	/fn/
 		/data (line value)
 		/group (line group)
-		/param (param value)
+		/params/
+			p1 (param value)
+			...
 	/tel/
 		/data (line value)
 		/group (line group)
-		/param (param value)
+		/params/
+			...
 /ctl
 	- "write" (save file)
 /import
@@ -26,7 +30,7 @@
 void
 usage(void)
 {
-	fprint(2, "usage: %s [-s srv] [-m mtpt] file\n", argv0);
+	fprint(2, "usage: %s [-s srv] [-m mtpt] [file]\n", argv0);
 	exits("usage");
 }
 
@@ -55,6 +59,7 @@
 		Qctl,
 		Qimport,
 		Qcard,
+			Qexport,
 			Qline,
 				Qdata,
 				Qgroup,
@@ -197,8 +202,6 @@
 	Vfile *vf;
 	char *s;
 	
-	// TODO: fill with Vfile structure, which points to card data
-	
 	for (c = chain; c; c = c->next) {
 		s = getcardname(c);
 		if (!s)
@@ -208,6 +211,8 @@
 		free(s);
 		if (!fc)
 			sysfatal("%r");
+		vf = emkvfile(Qexport, c, nil, nil);
+		f = createfile(fc, "export", user, 0444, vf);
 		
 		for (l = c->content; l; l = l->next) {
 			vf = emkvfile(Qline, c, l, nil);
@@ -214,24 +219,18 @@
 			fl = createfile(fc, l->name, user, DMDIR|0555, vf);
 			vf = emkvfile(Qdata, c, l, nil);
 			f = createfile(fl, "data", user, 0666, vf);
-	//		closefile(f);
 			if (l->group) {
 				vf = emkvfile(Qgroup, c, l, nil);
 				f = createfile(fl, "group", user, 0666, vf);
-	//			closefile(f);
 			}
 			vf = emkvfile(Qparams, c, l, nil);
 			f = createfile(fl, "params", user, DMDIR|0555, vf);
-	//		closefile(f);
 			
 			for (p = l->params; p; p = p->next) {
 				vf = emkvfile(Qparamdata, c, l, p);
 				fp = createfile(f, p->name, user, 0666, vf);
-	//			closefile(fp);
 			}
-	//		closefile(fl);
 		}
-	//	closefile(fc);
 	}
 }
 
@@ -255,16 +254,20 @@
 	
 	rfork(RFNOTEG);
 	
-	if (argc != 1)
-		usage();
+	user = getuser();
 	
-	file = argv[0];
+	if (argc == 1)
+		file = argv[0];
+	else {
+		file = smprint("/usr/%s/lib/vcarddb.vcf", user);
+		if (!file)
+			sysfatal("%r");
+	}
+	
 	cards = vcparsefile(file);
 	
 	if (!cards)
 		sysfatal("%r");
-	
-	user = getuser();
 	
 	fs.tree = alloctree("vcf", "vcf", DMDIR|0555, nil);
 	createfile(fs.tree->root, "ctl", user, 0666,