Ejemplo n.º 1
0
/*
static int top_index(struct chain *locals)
{
	return ((struct local_var *)ch_top(locals))->index;
}
*/
static int ins_local(struct chain *locals, char *str, int index) {
	struct local_var *nlv = NULL;
	int ins = -E_NOMEM;
	
	if ((MALLOC(nlv))){
		nlv->name = strdup(str);
		nlv->index = index;
		ins = ch_push(locals, nlv);
	} else {
		free(nlv);
	}
	
	return ins;
}
Ejemplo n.º 2
0
int soap::ctx::parse(const char* buf,int len)
{
    for(int i=0;i<len && !err;i++)
    {
        unsigned char ch=((unsigned char*)buf)[i];

        int cht=types[ch];

        if(ch=='\n')
            line++;

        switch(st)
        {
        case 0:
            if(ch=='<')
            {
                st=10;
                data_push();
                tok_reset();
                st_text=0;
            }else
            {
                switch(st_text)
                {
                case 0:
#ifndef NO_TRIM_DATA
                    if(cht==cht_sp) continue;
#endif
                    st_text=10;
                case 10:
                    if(ch=='&') { tok_add(ch); st_text=20; } else ch_push(ch);
                    break;
                case 20:
                    tok_add(ch);
                    if(ch==';')
                    {
                        tok[tok_size]=0;

                        if(!strcmp(tok,"&lt;")) ch_push('<');
                        else if(!strcmp(tok,"&gt;")) ch_push('>');
                        else if(!strcmp(tok,"&apos;")) ch_push('\'');
                        else if(!strcmp(tok,"&quot;")) ch_push('\"');
                        else if(!strcmp(tok,"&amp;")) ch_push('&');
                        tok_reset();
                        st_text=10;
                    }
                    break;
                }
            }
            break;
        case 10:
            if(ch=='/')
            {
                st=20;
                st_close_tag=1;
                continue;
            }else if(ch=='?')
            {
                st=50;
                continue;
            }else if(ch=='!')
            {
                st=60;
                continue;
            }
            st=11;
        case 11:
            if(cht!=cht_sp)
            {
                if(cht==cht_al)
                {
                    tok_add(ch);
                    st=20;
                }else
                    err=1;
            }
            break;
        case 20:
            if(cht==cht_sp) continue; st=21;
        case 21:
            if(ch==':')
                tok_reset();
            else if(cht==cht_sp)
            {
                tok_push();
                st=30;
            }else if(cht&(cht_al|cht_num) || ch=='_' || ch=='-')
                tok_add(ch);
            else if(ch=='/')
                st=40;
            else if(ch=='>')
                tok_push();
            else
                err=1;
            break;
        case 30:
            if(st_quot)
            {
                if(ch=='\"')
                    st_quot=0;
            }else
            {
                if(ch=='\"')
                    st_quot=1;
                else if(ch=='/')
                    st=40;
                else if(ch=='>')
                    st=0;
            }
            break;
        case 40:
            if(ch!='>') err=1; else tok_push();
            break;
        case 50:
            if(ch=='?') st=55;
            break;
        case 55:
            if(ch=='>') st=0; else if(ch!='?') st=50;
            break;
        case 60:
            if(ch=='-') st=61; else err=1;
            break;
        case 61:
            if(ch=='-') st=62; else err=1;
            break;
        case 62:
            if(ch=='-') st=63;
            break;
        case 63:
            if(ch=='-') st=64; else st=62;
            break;
        case 64:
            if(ch=='>')
                st=0;
            else if(ch!='-')
                st=62;
            break;
        }
    }

    return err;
}