Example #1
0
void sym_CreateSymbol(char *tzName, SLONG nValue, SBYTE nBank)
{
    if (strcmp(tzName, "@") == 0)
        return;

    struct ISymbol **ppSym;

    ppSym = &(tHash[calchash(tzName)]);

    while (*ppSym) {
        if (strcmp(tzName, (*ppSym)->pzName)) {
            ppSym = &((*ppSym)->pNext);
        } else {
            if (nBank == -1)
                return;

            sprintf(temptext,
                    "Symbol '%s' defined more than once\n",
                    tzName);
            fatalerror(temptext);
        }
    }

    if ((*ppSym = malloc(sizeof **ppSym))) {
        if (((*ppSym)->pzName = malloc(strlen(tzName) + 1))) {
            strcpy((*ppSym)->pzName, tzName);
            (*ppSym)->nValue = nValue;
            (*ppSym)->nBank = nBank;
            (*ppSym)->pNext = NULL;
        }
    }
}
Example #2
0
/*
 * Create a new symbol by name
 */
struct sSymbol *
createsymbol(char *s)
{
	struct sSymbol **ppsym;
	ULONG hash;

	hash = calchash(s);
	ppsym = &(tHashedSymbols[hash]);

	while ((*ppsym) != NULL)
		ppsym = &((*ppsym)->pNext);

	if (((*ppsym) = malloc(sizeof(struct sSymbol))) != NULL) {
		strcpy((*ppsym)->tzName, s);
		(*ppsym)->nValue = 0;
		(*ppsym)->nType = 0;
		(*ppsym)->pScope = NULL;
		(*ppsym)->pNext = NULL;
		(*ppsym)->pMacro = NULL;
		(*ppsym)->pSection = NULL;
		(*ppsym)->Callback = NULL;
		return (*ppsym);
	} else {
		fatalerror("No memory for symbol");
		return (NULL);
	}
}
Example #3
0
/*
 * Add a symbol to the object
 */
ULONG 
addsymbol(struct sSymbol * pSym)
{
	struct PatchSymbol *pPSym, **ppPSym;
	static ULONG nextID = 0;
	ULONG hash;

	hash = calchash(pSym->tzName);
	ppPSym = &(tHashedPatchSymbols[hash]);

	while ((*ppPSym) != NULL) {
		if (pSym == (*ppPSym)->pSymbol)
			return (*ppPSym)->ID;
		ppPSym = &((*ppPSym)->pBucketNext);
	}

	if ((*ppPSym = pPSym = malloc(sizeof(struct PatchSymbol))) != NULL) {
		pPSym->pNext = NULL;
		pPSym->pBucketNext = NULL;
		pPSym->pSymbol = pSym;
		pPSym->ID = nextID++;
	} else
		fatalerror("No memory for patchsymbol");

	*ppPatchSymbolsTail = pPSym;
	ppPatchSymbolsTail = &(pPSym->pNext);

	return pPSym->ID;
}
void createtable(){
   
char buf1[64],buf2[64],c;
int i,r,pos1=0,pos2=0;

for(i=0;i<256;i++) hash[i]=NULL;

FILE* f1=fopen("table.txt","r");

c=getc(f1);

while(c!=EOF){
  
  pos1=pos2=0; //to push a new word into buf
  
  while(c!=' ' && c!='\n'&& c!= EOF){ //used to fetch a word from table file
    buf1[pos1++]=c;
    c=getc(f1);
  }
  buf1[pos1]='\0';
  
  c=getc(f1);
  
  while(c!=' ' && c!='\n' && c!= EOF){ //used to fetch a word from table file
  buf2[pos2++]=c;
  c=getc(f1);
  }
  
  buf2[pos2]='\0';
   
  int val1=calchash(buf1);
  int val2=calchash(buf2);

  addtotable(buf1,val1,buf2,val2);
  
  c=getc(f1);
  
}//read until end of table file

}//createtable() close
Example #5
0
long
forder(datum key)
{
	long hash;

	hash = calchash(key);
	for (hmask = 0; ; hmask = (hmask<<1)+1) {
		blkno = hash & hmask;
		bitno = blkno + hmask;
		if (getbit() == 0)
			break;
	}
	return (blkno);
}
node search(char buf[]){
 
 int index=calchash(buf); //index in hash table for the current word
    
 node temp=hash[index];
  
 if(temp==NULL) return NULL; 
 
 while(temp!=NULL){
	 
	 if(strcasecmp(temp->ame,buf)==0) return temp;
	 else temp=temp->next;
 }
 
 return temp; 
}//search() close
Example #7
0
SLONG sym_GetBank(char *tzName)
{
    struct ISymbol **ppSym;

    ppSym = &(tHash[calchash(tzName)]);
    while (*ppSym) {
        if (strcmp(tzName, (*ppSym)->pzName)) {
            ppSym = &((*ppSym)->pNext);
        } else {
            return ((*ppSym)->nBank);
        }
    }

    sprintf(temptext, "Unknown symbol '%s'", tzName);
    fatalerror(temptext);
    return (0);
}
Example #8
0
SLONG 
sym_GetBank(char *tzName)
{
	struct ISymbol **ppSym;

	ppSym = &(tHash[calchash(tzName)]);
	while (*ppSym) {
		if (strcmp(tzName, (*ppSym)->pzName)) {
			ppSym = &((*ppSym)->pNext);
		} else {
			return ((*ppSym)->nBank);
		}
	}

	fprintf(stderr, "Unknown symbol '%s'\n", tzName);
	exit(1);
}
Example #9
0
/*
 * Find a symbol by name and scope
 */
struct sSymbol *
findsymbol(char *s, struct sSymbol * scope)
{
	struct sSymbol **ppsym;
	SLONG hash;

	hash = calchash(s);
	ppsym = &(tHashedSymbols[hash]);

	while ((*ppsym) != NULL) {
		if ((strcmp(s, (*ppsym)->tzName) == 0)
		    && ((*ppsym)->pScope == scope)) {
			return (*ppsym);
		} else
			ppsym = &((*ppsym)->pNext);
	}
	return (NULL);
}
Example #10
0
datum
fetch(datum key)
{
	int i;
	datum item;

	dbm_access(calchash(key));
	for (i = 0; ; i += 2) {
		item = makdatum(pagbuf, i);
		if (item.dptr == NULL)
			return (item);
		if (cmpdatum(key, item) == 0) {
			item = makdatum(pagbuf, i+1);
			if (item.dptr == NULL)
				(void) printf("items not in pairs\n");
			return (item);
		}
	}
}