commit b287a2ae09aa7e51261645bc5a1e6584f6531bf3
parent 6fc51e2569cbb4e197987cecbb44d4967f540b2c
Author: Roberto E. Vargas Caballero <k0ga@shike2.com>
Date: Sun, 24 Sep 2017 08:46:45 +0200
[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.
Diffstat:
6 files changed, 16 insertions(+), 5 deletions(-)
diff --git a/as/main.c b/as/main.c
@@ -18,7 +18,7 @@ cmp(const void *f1, const void *f2)
{
const Ins *ins = f2;
- return strcmp(f1, ins->str);
+ return casecmp(f1, ins->str);
}
static void
diff --git a/as/parser.c b/as/parser.c
@@ -77,9 +77,6 @@ field(char **oldp)
if (c == '\0')
error("unterminated string");
break;
- default:
- *s = toupper(*s);
- break;
}
}
diff --git 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 @@ lookup(char *name)
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;
}
diff --git a/inc/scc.h b/inc/scc.h
@@ -44,3 +44,4 @@ extern Alloc *alloc(size_t size, size_t nmemb);
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);
diff --git a/lib/scc/casecmp.c b/lib/scc/casecmp.c
@@ -0,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;
+}
diff --git a/lib/scc/libdep.mk b/lib/scc/libdep.mk
@@ -6,3 +6,4 @@ LIB-OBJ = $(LIBDIR)/debug.o \
$(LIBDIR)/xrealloc.o \
$(LIBDIR)/xstrdup.o \
$(LIBDIR)/alloc.o \
+ $(LIBDIR)/casecmp.o \