Ejemplo n.º 1
0
TokenT *_word(TokenizerT *tk) {
    nextChar(tk);
    if(isalnum(tk->inputIter[0]) || tk->inputIter[0] == '_') {
        return _word(tk);
    } else {
        if(isReservedWord(tk->tokenBuffer)) {
            return makeToken(tk, "reserved word");
        } else {
            return makeToken(tk, "word");
        }
    }
}
Ejemplo n.º 2
0
/*
 * TKGetNextToken returns the next token from the token stream as a
 * character string.  Space for the returned token should be dynamically
 * allocated.  The caller is responsible for freeing the space once it is
 * no longer needed.
 *
 * If the function succeeds, it returns a C string (delimited by '\0')
 * containing the token.  Else it returns 0.
 *
 * You need to fill in this function as part of your implementation.
 */
TokenT *TKGetNextToken(TokenizerT *tk) {
    clearBuffer(tk);
    char curr = tk->inputIter[0];

    // skip all whitespace before next token
    while(isspace(curr)) {
        nextChar(tk);
        clearBuffer(tk);
        curr = tk->inputIter[0];
    }

    if(curr == '\0') {
        return NULL;
    } else if(isalpha(curr) || curr == '_') {
        return _word(tk);
    } else if(curr == '0') {
        return _zero(tk);
    } else if(isdigit(curr)) {
        return _decimal(tk);
    } else if(curr == '!') { // neq
        return _neq(tk);
    } else if(curr == '"') { // double_quote
        return _double_quote(tk);
    } else if(curr == '#') {
        return _pound(tk);
    } else if(curr == '$') { // INVALID
        return _invalid(tk);
    } else if(curr == '%') { // mod, mod_eq
        return _mod(tk);
    } else if(curr == '&') { // bit_and, log_and, address (?)
        return _bit_and(tk);
    } else if(curr == '\'') { // single_quote
        return _single_quote(tk);
    } else if(curr == '(') { // open_paren
        return _open_paren(tk);
    } else if(curr == ')') { // close_paren
        return _close_paren(tk);
    } else if(curr == '*') { // mult, mult_eq, pointer (?)
        return _mult(tk);
    } else if(curr == '+') { // plus, plus_eq, inc
        return _plus(tk);
    } else if(curr == ',') { // comma
        return _comma(tk);
    } else if(curr == '-') { // minus, minus_eq, dec, struct_pointer
        return _minus(tk);
    } else if(curr == '.') { // dot
        return _dot(tk);
    } else if(curr == '/') { // div, div_eq
        return _div(tk);
    } else if(curr == ':') { // ternary_colon
        return _ternary_colon(tk);
    } else if(curr == ';') { // semicolon
        return _semicolon(tk);
    } else if(curr == '<') { // lt, lshift, lt_eq
        return _lt(tk);
    } else if(curr == '=') { // eq, assign
        return _eq(tk);
    } else if(curr == '>') { // gt, rshift, gt_eq
        return _gt(tk);
    } else if(curr == '?') { // ternary_qmark
        return _ternary_qmark(tk);
    } else if(curr == '@') { // INVALID
        return _invalid(tk);
    } else if(curr == '[') { // open_bracket
        return _open_bracket(tk);
    } else if(curr == '\\') { // backslash (?)
        return _invalid(tk);
    } else if(curr == ']') { // close_bracket
        return _close_bracket(tk);
    } else if(curr == '^') { // bit_xor
        return _bit_xor(tk);
    } else if(curr == '`') { // INVALID
        return _invalid(tk);
    } else if(curr == '{') { // open_brace
        return _open_brace(tk);
    } else if(curr == '|') { // bit_or, log_or
        return _bit_or(tk);
    } else if(curr == '}') { // close_brace
        return _close_brace(tk);
    } else if(curr == '~') { // bit_not
        return _bit_not(tk);
    } else {
        return _invalid(tk);
    }
}
Ejemplo n.º 3
0
/*******************************************************************************
	CHARGEMENT ET AFFICHAGE
*******************************************************************************/
static void affiche(char *nom,int wx,int wy,int ww,int wh)
{
/*	int		col[3];*/
	double	xratio,yratio;
	MFDB		src,dst;
	IMG		sld;
	long		count,flen;
	int		pxy[8],xy[8];
	int		xcar,ycar,wcar,hcar,xaff,yaff;
	int		idst,pdst;
	int		pmem,imem;
	int		r,ret;
	int		mask;
	int		i,n;
	int		*ps;
	char		*q;
	char		txt[FILENAME_MAX];

	ret=RIM_NEXT;
	n=0;
	while (ret==RIM_NEXT)
	{
		if (Kbshift(-1)!=shift)
			return;
		ret=_rimLoad(FALSE,nom,&flen,(MFDB *)&sld.mfdb,(char *)sld.type,&imem,&pmem,n);
		if (Kbshift(-1)!=shift)
			return;

		if (ret!=RIM_OK && ret!=RIM_NEXT)
		{
			if (imem!=NO_MEMORY)
				_mFree(imem);
			if (pmem!=NO_MEMORY)
				_mFree(pmem);
			return;
		}
		n+=1;

		idst=NO_MEMORY;
		pdst=NO_MEMORY;

		src.fd_w			=	sld.mfdb.w;
		src.fd_wdwidth	=	sld.mfdb.wdw;
		src.fd_h			=	sld.mfdb.h;
		src.fd_stand	=	sld.mfdb.stand;
		src.fd_nplanes	=	sld.mfdb.nplanes;

		if (sld.mfdb.w>ww || sld.mfdb.h>wh)			/*	Si l'image est plus	*/
		{														/*	grande que l'‚cran en W ou H	*/
			if (glb.opt.sl_zdec)							/*	Zoom diminution ?					*/
			{
				xratio=(double)ww/(double)sld.mfdb.w;
				yratio=(double)wh/(double)sld.mfdb.h;

				if (xratio>=yratio)			/*	Pleine hauteur	*/
				{
					sld.mfdb.w=(int)( (double)sld.mfdb.w * (double)wh / (double)sld.mfdb.h );
					sld.mfdb.h=wh;
					sld.mfdb.wdw=_word(sld.mfdb.w);
				}
				else								/*	Pleine largeur	*/
				{
					sld.mfdb.h=(int)( (double)sld.mfdb.h * (double)ww / (double)sld.mfdb.w );
					sld.mfdb.w=ww;
					sld.mfdb.wdw=_word(sld.mfdb.w);
				}
			}
		}
		else									/*	Alors l'image est plus petite que l'‚cran	*/
		{
			if (glb.opt.sl_zinc)							/*	Zoom Agrandissement ?			*/
			{
				xratio=(double)ww/(double)sld.mfdb.w;
				yratio=(double)wh/(double)sld.mfdb.h;

				if (xratio>=yratio)			/*	Pleine hauteur	*/
				{
					sld.mfdb.w=(int)( (double)sld.mfdb.w * (double)wh / (double)sld.mfdb.h );
					sld.mfdb.h=wh;
					sld.mfdb.wdw=_word(sld.mfdb.w);
				}
				else								/*	Pleine largeur	*/
				{
					sld.mfdb.h=(int)( (double)sld.mfdb.h * (double)ww / (double)sld.mfdb.w );
					sld.mfdb.w=ww;
					sld.mfdb.wdw=_word(sld.mfdb.w);
				}
			}
		}

		dst.fd_w			=	sld.mfdb.w;
		dst.fd_wdwidth	=	sld.mfdb.wdw;
		dst.fd_h			=	sld.mfdb.h;
		dst.fd_stand	=	0;
		dst.fd_nplanes	=	glb.vdi.extnd[4];

		if (Kbshift(-1)!=shift)
			return;
		mask=TRM_IMPORT|TRM_SUGG_PAL|TRM_AUTO;
		r=_trmConvert(FALSE,imem,&idst,pmem,&pdst,&src,&dst,mask,glb.parx.d_trm,0);
		if (Kbshift(-1)!=shift)
			return;

		if (r!=TRM_OK)
		{
			if (imem!=NO_MEMORY)
				_mFree(imem);
			if (pmem!=NO_MEMORY)
				_mFree(pmem);
			if (idst!=NO_MEMORY)
				_mFree(idst);
			if (pdst!=NO_MEMORY)
				_mFree(pdst);
			return;
		}

		if (imem!=idst)
		{
			_mFree(imem);
			imem=idst;
		}
		if (pmem!=pdst)
		{
			_mFree(pmem);
			pmem=pdst;
		}

		if (Kbshift(-1)!=shift)
			return;
		if (!r)
		{
			if (imem!=NO_MEMORY)
				_mFree(imem);
			if (pmem!=NO_MEMORY)
				_mFree(pmem);
			graf_mouse(ARROW,0);
			return;
		}

		r=-1;

		sld.mfdb.seek		=	0L;
		sld.mfdb.w			=	dst.fd_w;
		sld.mfdb.h			=	dst.fd_h;
		sld.mfdb.wdw		=	dst.fd_wdwidth;
		sld.mfdb.stand		=	dst.fd_stand;
		sld.mfdb.nplanes	=	dst.fd_nplanes;
		sld.flag				=	1;
		sld.x					=	0;
		sld.y					=	0;
		sld.w					=	sld.mfdb.w;
		sld.h					=	sld.mfdb.h;

		if (sld.w>ww || sld.h>wh)					/*	Si l'image est plus	*/
		{													/*	grande que l'‚cran en W ou H	*/
			if (sld.w>ww)								/*	Largeur plus grande				*/
			{
				xcar=(sld.w-ww)/2;
				xaff=wx;
				wcar=ww;
			}
			else
			{
				xaff=wx+(ww-sld.w)/2;
				xcar=0;
				wcar=sld.w;
			}
			if (sld.h>wh)								/*	Hauteur plus grande				*/
			{
				ycar=(sld.h-wh)/2;
				yaff=wy;
				hcar=wh;
			}
			else
			{
				yaff=wy+(wh-sld.h)/2;
				ycar=0;
				hcar=sld.h;
			}
		}
		else									/*	Alors l'image est plus petite que l'‚cran	*/
		{
			if (sld.w>ww)					/*	Largeur plus grande				*/
			{
				xcar=(sld.w-ww)/2;
				xaff=wx;
				wcar=ww;
			}
			else
			{
				xaff=wx+(ww-sld.w)/2;
				xcar=0;
				wcar=sld.w;
			}

			if (sld.h>wh)								/*	Hauteur plus grande				*/
			{
				ycar=(sld.h-wh)/2;
				yaff=wy;
				hcar=wh;
			}
			else
			{
				yaff=wy+(wh-sld.h)/2;
				ycar=0;
				hcar=sld.h;
			}
		}

		sld.mfdb.seek	=	(long)glb.mem.adr[imem];
		sld.mfdb.wdw	=	_word(sld.mfdb.w);
		dst.fd_addr		=	0;
		dst.fd_w			=	0;
		dst.fd_h			=	0;
		dst.fd_wdwidth	=	0;
		dst.fd_stand	=	0;
		dst.fd_nplanes	=	0;

		pxy[0]	=	xcar;				pxy[4]	=	xaff;
		pxy[1]	=	ycar;				pxy[5]	=	yaff;
		pxy[2]	=	xcar+wcar-1;	pxy[6]	=	xaff+wcar-1;
		pxy[3]	=	ycar+hcar-1;	pxy[7]	=	yaff+hcar-1;

		time(&t1);
		if (Kbshift(-1)!=shift)
			return;
		if(glb.opt.sl_pause)
		{
			count=1000L*max( 0 , (long)glb.opt.sl_ptime - difftime(t1,t2) );
			evnt_timer( (int)(count&0xFFFFUL) , (int)(count>>16) );
		}
		else