shithub: scc

Download patch

ref: 5a274755b0b8da4357c3ed3193033dcba6f6796d
parent: 96a486d98ec1ed5fceae00c6f4f0fb3ff29c8519
author: Roberto E. Vargas Caballero <k0ga@shike2.com>
date: Thu Jul 4 11:53:41 EDT 2013

Add find fuction

This function allows locate a symbol. It is similar to lookup, but it
doesn't allocate the symbol in case of not being present.

--- a/symbol.c
+++ b/symbol.c
@@ -63,6 +63,22 @@
 }
 
 struct symbol *
+find(const char *s, register char ns)
+{
+	register struct symbol *sym;
+	static unsigned char l;
+
+	l = strlen(s);
+	for (sym = htab[hash(s)]; sym; sym = sym->hash) {
+		if (ns != NS_ANY && ns != sym->ns)
+			continue;
+		if (!memcmp(sym->name, s, l))
+			return sym;
+	}
+	return NULL;
+}
+
+struct symbol *
 lookup(register const char *s, char ns)
 {
 	register struct symbol *sym;
--- a/symbol.h
+++ b/symbol.h
@@ -62,6 +62,7 @@
 extern void del_ctx(void);
 extern void freesyms(void);
 extern struct symbol *lookup(register const char *s, char ns);
+extern struct symbol *find(register const char *s, char ns);
 extern void insert(struct symbol *sym, unsigned char ctx);
 extern void storage(struct ctype *cp, unsigned char mod);
 extern struct ctype *newctype(void);
--