/*
	1802 Cross-Assembler  v 2.3

	May, 1980

	June, 1980 -- Rev. 2.1 consisting of fixing P errors that come
		from EQUing things to the pre-defined symbols, and adding
		the LOAD pseudo-op.

	July, 1980 -- Rev. 2.2 consisting of fixing the M errors that
		come from forward references in WORD and BYTE pseudo-ops.

	October, 1980 -- Rev. 2.3 consisting of modifying the assembly
		language routines and I/O routines to match and take
		advantage of BDS C V1.4.

	Copyright (c) 1980 William C. Colley, III.

File:	a18symb.c

Routines to manipulate the symbol table.
*/

/*  Get Globals:  */

#include "a18.h"

/*
This function adds a new entry to the symbol table.  The function
returns values of either 0 or -1.  If the value is 0, the symbol is
already in the table and the global variable sympoint points to the
existing entry.  If the value is -1, the symbol has just been entered
into the table and sympoint points to the new entry.  If the symbol
table is full, the function triggers an abort of the assembly.
*/

addsym(symbol)
char *symbol;
{
	int t;
	if ((t = slookup(symbol)) > 0)
	{
		wipeout("\nSymbol Table Overflow.\n");
	}
	if (t != 0) movmem(symbol, sympoint, SYMLEN);
	return(t);
}

/*
This function checks the symbol table for a given symbol.  The function returns
one of three values as follows:

	 1 = symbol not found and symbol table full.
	 0 = symbol found.  sympoint points to the matching entry.
	-1 = symbol not found.  sympoint points to where the symbol
	     should have been.

The symbol table is accessed using a hashing function with linear rehashing.
*/

slookup(symbol)
char *symbol;
{
	int temp;
	temp = sympoint = &symtbl[hash(symbol)];
	while((sympoint -> symname[0] & 0x7f) != '\0')
	{
		if (symcmp(symbol,sympoint->symname) == 0) return(0);
		if (++sympoint == symend) sympoint = symtbl;
		if (sympoint == temp) return(1);
	}
	return(-1);
}

/*
This function returns a hash value for a given symbol.  The hash value
is calculated by