diff lwlink/objdump.c @ 387:a741d2e4869f

Various bugfixes; fixed lwobjdump to display symbols with unprintable characters more sensibly; start of a (nonfunctional for now) testing framework
author lost@l-w.ca
date Wed, 14 Jul 2010 20:15:23 -0600
parents 1c31e9005ff7
children
line wrap: on
line diff
--- a/lwlink/objdump.c	Sun May 16 13:03:17 2010 -0600
+++ b/lwlink/objdump.c	Wed Jul 14 20:15:23 2010 -0600
@@ -34,6 +34,42 @@
 void read_lwobj16v0(unsigned char *filedata, long filesize);
 char *program_name;
 
+char *string_cleanup(char *sym)
+{
+	static char symbuf[4096];
+	int optr = 0;
+	while (*sym)
+	{
+		if (*sym < 33 || *sym > 126)
+		{
+			int c;
+			symbuf[optr++] = '\\';
+			c = *sym >> 4;
+			c+= 48;
+			if (c > 57)
+				c += 7;
+			symbuf[optr++] = c;
+			c = *sym & 15;
+			c += 48;
+			if (c > 57)
+				c += 7;
+			symbuf[optr++] = c;
+		}
+		else if (*sym == '\\')
+		{
+			symbuf[optr++] = '\\';
+			symbuf[optr++] = '\\';
+		}
+		else
+		{
+			symbuf[optr++] = *sym;
+		}
+		sym++;
+	}
+	symbuf[optr] = '\0';
+	return symbuf;
+}
+
 /*
 The logic of reading the entire file into memory is simple. All the symbol
 names in the file are NUL terminated strings and can be used directly without
@@ -185,7 +221,7 @@
 			NEXTBYTE();
 			// val is now the symbol value
 			
-			printf("        %s=%04X\n", fp, val);
+			printf("        %s=%04X\n", string_cleanup(fp), val);
 			
 		}
 		// skip terminating NUL
@@ -205,7 +241,7 @@
 			NEXTBYTE();
 			// val is now the symbol value
 			
-			printf("        %s=%04X\n", fp, val);
+			printf("        %s=%04X\n", string_cleanup(fp), val);
 		}
 		// skip terminating NUL
 		NEXTBYTE();
@@ -237,12 +273,12 @@
 				
 				case 0x02:
 					// external symbol reference
-					printf(" ES=%s", CURSTR());
+					printf(" ES=%s", string_cleanup(CURSTR()));
 					break;
 					
 				case 0x03:
 					// internal symbol reference
-					printf(" IS=%s", CURSTR());
+					printf(" IS=%s", string_cleanup(CURSTR()));
 					break;
 				
 				case 0x04: