コード例 #1
0
ファイル: DFA.c プロジェクト: bingone/regular
DState*
dstate(List *l)
{
	int i;
	DState **dp, *d;

	qsort(l->s, l->n, sizeof l->s[0], ptrcmp);
	dp = &alldstates;
	while((d = *dp) != NULL){
		i = listcmp(l, &d->l);
		if(i < 0)
			dp = &d->left;
		else if(i > 0)
			dp = &d->right;
		else
			return d;
	}
	
	d = malloc(sizeof *d + l->n*sizeof l->s[0]);
	memset(d, 0, sizeof *d);
	d->l.s = (State**)(d+1);
	memmove(d->l.s, l->s, l->n*sizeof l->s[0]);
	d->l.n = l->n;
	*dp = d;
	return d;
}
コード例 #2
0
ファイル: expr.c プロジェクト: aryx/fork-kencc
void
oeq(Node *n, Node *res)
{
	Node l, r;

	expr(n->left, &l);
	expr(n->right, &r);
	res->nstore.fmt = 'D';
	res->op = OCONST;
	res->type = TINT;
	res->nstore.u0.sival = 0;
	switch(l.type) {
	default:
		break;
	case TINT:
		switch(r.type) {
		case TINT:
			res->nstore.u0.sival = l.nstore.u0.sival == r.nstore.u0.sival;
			break;
		case TFLOAT:
			res->nstore.u0.sival = l.nstore.u0.sival == r.nstore.u0.sfval;
			break;
		default:
			break;
		}
		break;
	case TFLOAT:
		switch(r.type) {
		case TINT:
			res->nstore.u0.sival = l.nstore.u0.sfval == r.nstore.u0.sival;
			break;
		case TFLOAT:
			res->nstore.u0.sival = l.nstore.u0.sfval == r.nstore.u0.sfval;
			break;
		default:
			break;
		}
		break;
	case TSTRING:
		if(r.type == TSTRING) {
			res->nstore.u0.sival = scmp(r.nstore.u0.sstring, l.nstore.u0.sstring);
			break;
		}
		break;
	case TLIST:
		if(r.type == TLIST) {
			res->nstore.u0.sival = listcmp(l.nstore.u0.sl, r.nstore.u0.sl);
			break;
		}
		break;
	}
	if(n->op == ONEQ)
		res->nstore.u0.sival = !res->nstore.u0.sival;
}
コード例 #3
0
ファイル: list.c プロジェクト: carriercomm/plan9-gpl
int
listcmp(List *l, List *r)
{
	if(l == r)
		return 1;

	while(l) {
		if(r == 0)
			return 0;
		if(l->type != r->type)
			return 0;
		switch(l->type) {
		case TINT:
			if(l->ival != r->ival)
				return 0;
			break;
		case TFLOAT:
			if(l->fval != r->fval)
				return 0;
			break;
		case TSTRING:
			if(scmp(l->string, r->string) == 0)
				return 0;
			break;
		case TLIST:
			if(listcmp(l->l, r->l) == 0)
				return 0;
			break;
		}
		l = l->next;
		r = r->next;
	}
	if(l != r)
		return 0;
	return 1;
}
コード例 #4
0
int32_t process_NXT_event(struct NXThandler_info *mp,int32_t histmode,char *txid,int64_t type,int64_t subtype,struct NXT_AMhdr *AMhdr,char *sender,char *receiver,char *assetid,int64_t assetoshis,char *comment,cJSON *json)
{
    int32_t i,count,highest_priority;
    NXT_handler NXT_handler = 0;
    void *handlerdata = 0;
    struct NXT_protocol *p;
    struct NXT_protocol_parms PARMS;
    count = 0;
    highest_priority = -1;
    memset(&PARMS,0,sizeof(PARMS));
    if ( Num_NXThandlers == 0 )
        printf("WARNING: process_NXT_event Num_NXThandlers.%d\n",Num_NXThandlers);
    for (i=0; i<Num_NXThandlers; i++)
    {
        if ( (p= NXThandlers[i]) != 0 )
        {
            if ( AMhdr != 0 || ((p->type < 0 || p->type == type) && (p->subtype < 0 || p->subtype == subtype)) )
            {
                if ( AMhdr != 0 )
                {
                    if ( p->AMsigfilter != 0 && p->AMsigfilter != AMhdr->sig )
                        continue;
                }
                else if ( p->assetlist != 0 && assetid != 0 && listcmp(p->assetlist,assetid) != 0 )
                    continue;
                if ( strcmp(sender,GENESISACCT) == 0 || strcmp(receiver,GENESISACCT) == 0 || //is_gateway_addr(sender) != 0 ||
                     (AMhdr == 0 || p->whitelist == 0 || listcmp(p->whitelist,sender) == 0) ||
                     (AMhdr != 0 && cmp_nxt64bits(sender,AMhdr->nxt64bits) == 0) )
                {
                    if ( p->priority > highest_priority )
                    {
                        count = 1;
                        highest_priority = p->priority;
                        NXT_handler = p->NXT_handler;
                        handlerdata = p->handlerdata;
                        PARMS.argjson = json; PARMS.txid = txid; PARMS.sender = sender; PARMS.receiver = receiver;
                        PARMS.type = (int32_t)type; PARMS.subtype = (int32_t)subtype; PARMS.priority = highest_priority; PARMS.histflag = histmode;
                        if ( AMhdr != 0 )
                        {
                            PARMS.mode = NXTPROTOCOL_AMTXID;
                            PARMS.AMptr = AMhdr;
                        }
                        else
                        {
                            PARMS.mode = NXTPROTOCOL_TYPEMATCH;
                            PARMS.assetid = assetid;
                            PARMS.assetoshis = assetoshis;
                            PARMS.comment = comment;
                        }
                        //printf("call NXT_handler\n");
                        (*NXT_handler)(mp,&PARMS,handlerdata);
                   }
                    else if ( p->priority == highest_priority )
                        count++;
                }
                //printf("end iter\n");
            }
        }
    }
    if ( count > 1 )
        printf("WARNING: (%s) claimed %d times, priority.%d\n",cJSON_Print(json),count,highest_priority);  // this is bad, also leaks mem!
    if ( 0 && highest_priority >= 0 && NXT_handler != 0 )
    {
        //printf("count.%d handler.%p NXThandler_info_handler.%p AMhdr.%p\n",count,NXT_handler,multigateway_handler,AMhdr);
        PARMS.argjson = json; PARMS.txid = txid; PARMS.sender = sender; PARMS.receiver = receiver;
        PARMS.type = (int32_t)type; PARMS.subtype = (int32_t)subtype; PARMS.priority = highest_priority; PARMS.histflag = histmode;
        if ( AMhdr != 0 )
        {
            PARMS.mode = NXTPROTOCOL_AMTXID;
            PARMS.AMptr = AMhdr;
        }
        else
        {
            PARMS.mode = NXTPROTOCOL_TYPEMATCH;
            PARMS.assetid = assetid;
            PARMS.assetoshis = assetoshis;
            PARMS.comment = comment;
        }
        (*NXT_handler)(mp,&PARMS,handlerdata);///histmode,txid,AMhdr,sender,receiver,assetid,assetoshis,comment,json);
    }
    return(count != 0);
}