/* Program to read the symbol table produced by 'nm' and make a C
 * file which is the symbol table.
 *
 * It reads stdin which should be the output from nm and writes to stdout
 * a file which should be assembled and linked in with DDT.
 */

#include	<stdio.h>

main()
{
	unsigned	address;
	char		name[128];
	char		type;

	printf("\t.data\n");
	printf("\t.align 2\n");
	printf("\t.globl\t_D_SYMT\n");
	printf("_D_SYMT:\n");

	while (scanf("%x %c%s", &address, &type, name) != EOF) {
		if (type == 'U') continue;
		do_entry(name);
	}

	do_entry("_end");
	do_entry("_etext");
	do_entry("_edata");

	printf("\t.long\t0\n");
	printf("\t.long\t0\n");
}

do_entry(name)
char	*name;
{
	static	int	count = 101;

	printf("\t.data 2\n");
	printf("L%d:\n", count);
	printf("\t.ascii\t\"%s\\0\"\n", name);
	printf("\t.data\n");
	printf("\t.long\tL%d\n", count++);
	printf("\t.long\t%s\n", name);
}
