
/***** Includes *****/

#include "ProgED:sources/include/Ped.h"



/*****
 *
 * FUNCTION:	ULONG SAVEDS ASM main(char *line,char *sectionname)
 *
 * AIM:		Find the reference to a "#define" in the line which
 *		is pointed from "line". The reference name will
 *		be copied into "sectionname".
 *
 * NOTE:	Use always the function geta4() or the directive __saveds!
 *
 * RESULT:	Lenght of the string copied into "sectionname".
 *		0=reference not found.
 *
 ****/

ULONG SAVEDS ASM main(RG(a0) char *line,RG(a1) char *sectionname)
{
	char	*p,
		*q,
		*d;
	int	i;



	/***** The line starts with "#define" ? *****/
	p=line;
	if (*p)
	{
		if (p[0]=='#')
		if (p[1]=='d')
		if (p[2]=='e')
		if (p[3]=='f')
		if (p[4]=='i')
		if (p[5]=='n')
		if (p[6]=='e')
		{
			/***** If yes, go forward to find the next word
				jumping over spaces and TABs *****/
			p+=7;
			while((*p==32)||(*p==9))	p++;

			/***** Copy the word from here to next space,TAB,
				or '(' and return in D0 the lenght. *****/
			if (*p)
			{
				q=p;
				while((*q!=32)&&(*q!=9)&&(*q!='(')&&(*q))	q++;

				d=sectionname;
				for(i=0;i<q-p;i++)	*d++=p[i];
				*d='\0';
				return(q-p);
			}
		}
	}

	/***** Reference not found! *****/
	return(0);
}
