diff lwasm/list.c @ 390:1ebb5a0b2874

Add option to specify tab width in listing There is much insistence that generating the asm listing should absolutely not ever in the entire expanse of space and time expand tabs. lwasm, however, does so, and it does so for a reason. That reason is that there are enough users that have enough trouble even understanding what a tab is that it was simpler to just expand them. That said, having a means to actually specify the tab width is pretty much required if you're going to do that, and having a way to disable such expansion is also a good idea. Thanks to Erik G <erik@6809.org> for the base patch to handle this.
author William Astle <lost@l-w.ca>
date Mon, 13 Jul 2015 21:52:43 -0600
parents 35d4213e6657
children 61580fc48f98
line wrap: on
line diff
--- a/lwasm/list.c	Mon Jul 13 21:37:49 2015 -0600
+++ b/lwasm/list.c	Mon Jul 13 21:52:43 2015 -0600
@@ -254,32 +254,37 @@
 			}
 		}
 
-		i = 0;
-		for (tc = cl -> ltext; *tc; tc++)
+		if (as -> tabwidth == 0)
 		{
-			if ((*tc) == '\t')
+			fputs(cl -> ltext, of);
+		}
+		else 
+		{
+			i = 0;
+			for (tc = cl -> ltext; *tc; tc++)
 			{
-				if (i % 8 == 0)
+				if ((*tc) == '\t')
 				{
-					i += 8;
-					fprintf(of, "        ");
-				}
-				else
-				{
-					while (i % 8)
+					if (i % as -> tabwidth == 0)
+					{
+						fputc(' ', of);
+						i++;
+					}
+					while (i % as -> tabwidth)
 					{
 						fputc(' ', of);
 						i++;
 					}
 				}
-			}
-			else
-			{
-				fputc(*tc, of);
-				i++;
+				else
+				{
+					fputc(*tc, of);
+					i++;
+				}
 			}
 		}
 		fputc('\n', of);
+
 		if (obytelen > 8)
 		{
 			for (i = 8; i < obytelen; i++)