changeset 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 2d9b7ae6c329
children 15d1628180e7
files lwasm/list.c lwasm/lwasm.h lwasm/main.c
diffstat 3 files changed, 29 insertions(+), 16 deletions(-) [+]
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++)
--- a/lwasm/lwasm.h	Mon Jul 13 21:37:49 2015 -0600
+++ b/lwasm/lwasm.h	Mon Jul 13 21:52:43 2015 -0600
@@ -401,6 +401,7 @@
 	exportlist_t *exportlist;			// list of exported symbols
 	importlist_t *importlist;			// list of imported symbols
 	char *list_file;					// name of file to list to
+	int tabwidth;						// tab width in list file
 	char *map_file;						// name of map file
 	char *output_file;					// output file name	
 	lw_stringlist_t input_files;		// files to assemble
--- a/lwasm/main.c	Mon Jul 13 21:37:49 2015 -0600
+++ b/lwasm/main.c	Mon Jul 13 21:52:43 2015 -0600
@@ -48,6 +48,7 @@
 	{ "list",		'l',	"FILE",		lw_cmdline_opt_optional,	"Generate list [to FILE]"},
 	{ "symbols",	's',	0,			lw_cmdline_opt_optional,	"Generate symbol list in listing, no effect without --list"},
 	{ "symbols-nolocals", 0x103,	0,	lw_cmdline_opt_optional,	"Same as --symbols but with local labels ignored"},
+	{ "tabs",		't',	"WIDTH",	0,							"Set tab spacing in listing (0=don't expand tabs)" },
 	{ "map",		'm',	"FILE",		lw_cmdline_opt_optional,	"Generate map [to FILE]"},
 	{ "decb",		'b',	0,			0,							"Generate DECB .bin format output, equivalent of --format=decb"},
 	{ "raw",		'r',	0,			0,							"Generate raw binary format output, equivalent of --format=raw"},
@@ -58,7 +59,7 @@
 	{ "6809",		'9',	0,			0,							"Set assembler to 6809 only mode" },
 	{ "6309",		'3',	0,			0,							"Set assembler to 6309 mode (default)" },
 	{ "includedir",	'I',	"PATH",		0,							"Add entry to include path" },
-	{ "define", 'D', "SYM[=VAL]", 0, "Automatically define SYM to be VAL (or 1)"},
+	{ "define",		'D',	"SYM[=VAL]",0,							"Automatically define SYM to be VAL (or 1)"},
 	{ "preprocess",	'P',	0,			0,							"Preprocess macros and conditionals and output revised source to stdout" },
 	{ "unicorns",	0x142,	0,			0,							"Add sooper sekrit sauce"},
 	{ "6800compat",	0x200,	0,			0,							"Enable 6800 compatibility instructions, equivalent to --pragma=6800compat" },
@@ -114,6 +115,11 @@
 #endif
 		break;
 
+	case 't':
+		if (arg)
+			as -> tabwidth = atoi(arg);
+		break;
+
 	case 'l':
 		if (as -> list_file)
 			lw_free(as -> list_file);
@@ -293,6 +299,7 @@
 	asmstate.input_files = lw_stringlist_create();
 	asmstate.nextcontext = 1;
 	asmstate.exprwidth = 16;
+	asmstate.tabwidth = 8;
 	
 	/* parse command line arguments */	
 	lw_cmdline_parse(&cmdline_parser, argc, argv, 0, 0, &asmstate);