shithub: vdict

Download patch

ref: a573d608ce237a853699162955a6ed18999d370b
parent: e6cc2ec8fd41382f902b00cff71f86fe7b840d77
author: phil9 <telephil9@gmail.com>
date: Wed Mar 23 12:08:34 EDT 2022

parse definition source

--- a/dictc.c
+++ b/dictc.c
@@ -246,11 +246,25 @@
 	freedictc(c);
 }
 
+char*
+dbdesc(Dictc *c, char *db)
+{
+	Element *e;
+	int i;
+
+	for(i = 0; i < dvlen(c->db); i++){
+		e = dvref(c->db, i);
+		if(strcmp(e->name, db) == 0)
+			return e->desc;
+	}
+	return nil;
+}
+
 Definition*
 parsedefinition(Dictc *c)
 {
 	Definition *d;
-	char *s;
+	char *s, *p, *q, *src;
 	String *sb;
 	int n;
 
@@ -260,11 +274,19 @@
 		return nil;
 	}
 	n = readstatus(s);
-	free(s);
 	if(n != 151){
 		werrstr(Errors[Eunexpected]);
 		return nil;
 	}
+	src = nil;
+	p = strchr(s+5, '"'); /* skip NNN<space>" */
+	if(p != nil){
+		p += 2;
+		q = strchr(p, ' ');
+		*q = '\0';
+		src = dbdesc(c, p);
+	}
+	free(s);
 	sb = s_newalloc(255);
 	for(;;){
 		s = Brdstr(c->bin, '\n', 1);
@@ -283,6 +305,7 @@
 	}
 	s_terminate(sb);
 	d = emalloc(sizeof *d);
+	d->db   = src;
 	d->text = strdup(s_to_c(sb));
 	s_free(sb);
 	return d;