shithub: scc

Download patch

ref: 652c56f79e42c277cfa92007aef17b7bfe95a659
parent: d17f6bb884dbbd19ef4e47632a627e059118e802
author: Roberto E. Vargas Caballero <k0ga@shike2.com>
date: Sun Sep 24 04:46:45 EDT 2017

[as] Preserve the name of symbols

The code was converting everything to upper case,
which makes that every symbol is going to be emitted
in upper case.

--- a/as/main.c
+++ b/as/main.c
@@ -18,7 +18,7 @@
 {
 	const Ins *ins = f2;
 
-	return strcmp(f1, ins->str);
+	return casecmp(f1, ins->str);
 }
 
 static void
--- a/as/parser.c
+++ b/as/parser.c
@@ -77,9 +77,6 @@
 			if (c == '\0')
 				error("unterminated string");
 			break;
-		default:
-			*s = toupper(*s);
-			break;
 		}
 	}
 
--- a/as/symbol.c
+++ b/as/symbol.c
@@ -1,5 +1,6 @@
 static char sccsid[] = "@(#) ./as/symbol.c";
 
+#include <ctype.h>
 #include <stdio.h>
 #include <stdint.h>
 #include <string.h>
@@ -59,7 +60,7 @@
 	list = &hashtbl[h];
 	for (sym = *list; sym; sym = sym->next) {
 		t = sym->name;
-		if (c == *t && !strcmp(t, name))
+		if (c == *t && !casecmp(t, name))
 			return sym;
 	}
 
--- a/inc/scc.h
+++ b/inc/scc.h
@@ -44,3 +44,4 @@
 extern void dealloc(Alloc *allocp);
 extern void *new(Alloc *allocp);
 extern void delete(Alloc *allocp, void *p);
+extern int casecmp(const char *s1, const char *s2);
--- /dev/null
+++ b/lib/scc/casecmp.c
@@ -1,0 +1,11 @@
+static char sccsid[] = "@(#) ./lib/scc/casecmp.c";
+#include <ctype.h>
+#include "../../inc/scc.h"
+
+int
+casecmp(const char *s1, const char *s2)
+{
+        while (*s1 && toupper(*s1) == toupper(*s2))
+                ++s1, ++s2;
+        return *s1 - *s2;
+}
--- a/lib/scc/libdep.mk
+++ b/lib/scc/libdep.mk
@@ -6,3 +6,4 @@
           $(LIBDIR)/xrealloc.o \
           $(LIBDIR)/xstrdup.o \
           $(LIBDIR)/alloc.o \
+          $(LIBDIR)/casecmp.o \