#include <stdio.h>

main(argc, argv)
int argc;
char *argv[];
{
	unsigned val;
	int s;

	if (argc < 2)
		exit();

	s = symval("unix", argv[1], &val);

	if (s)
		printf("Symbol %s not found\n", argv[1]);
	else
		printf("Symbol %s = %x\n", argv[1], val);
}



#define SLEN 6

symval(program, name, val)
char *program;
char *name;
unsigned *val;
{
	int n;
	FILE *f;
	char fname[20];
	char sname[SLEN+2];
	char rdname[20];

	strncpy(fname, program, 15);
	strcat(fname, ".sym");

	/* Copy the symbol name, adding the trailing '?', changing '_' to
	'@', and trimming to SLEN chars */

	strncat(sname, name, SLEN);
	strcat(sname, "?");
	sname[SLEN] = '\0';
	for (n=0; n < SLEN; ++n)
	{
		sname[n] = chupper(sname[n]);
		if (sname[n] == '_')
			sname[n] = '@';
	}

	f = fopen(fname, "r");

	if (f == NULL)
		return (-1);

	for(;;)
	{
		n = fscanf(f, "%x %18s", val, rdname);
		if (n != 2 || ferror(f))
			break;

		if (!strcmp(sname, rdname))
		{
			fclose(f);
			return (0);
		}
	}

	fclose(f);
	return (-1);
}
