Пример #1
0
rb_red_blk_tree* buildEventMap()
{
    printf("--- Generating Event Rule Map ... \n");
    rb_red_blk_tree* EventTree = RBTreeCreate(Compare_EventType,DestroyEventType,DestroyInfoEventKey,PrintEventKey,PrintInfoEventKey);

    if(!EventTree)
    {
        printf("Error Building the Event Rule Map.\n");
        return NULL;
    }

    int i=0;
    term_t a0 = PL_new_term_refs(3);
    term_t b0 = PL_new_term_refs(2);

    static predicate_t p;
    static functor_t event_functor;

    char myEvents[256][256];
    int  arity;
    eventType* temp=NULL;

    if ( !event_functor )
        event_functor = PL_new_functor(PL_new_atom("event"), 2);
    PL_cons_functor(a0+1,event_functor,b0,b0+1);

    if ( !p )
        p = PL_predicate("trClause", 3, NULL);

    qid_t qid = PL_open_query(NULL, PL_Q_NORMAL, p, a0);
    while(PL_next_solution(qid) != FALSE)
    {
        //termToString(b0,myEvents[i]);
        atom_t name;
        PL_get_name_arity(b0, &name, &arity);
        sprintf(myEvents[i],"%s",PL_atom_chars(name));
        temp=(eventType*)calloc(1,sizeof(eventType));
        trClause* trc=(trClause*)calloc(1,sizeof(trClause));

        strcpy(temp->name,PL_atom_chars(name));
        temp->arity = arity;
        RBTreeInsert(EventTree,temp,trc);
        temp=NULL;
        trc=NULL;
        padding(' ',4);
        printf("+New Event Signature : %s/%d\n",myEvents[i],arity);
        i++;
    }
    PL_close_query(qid);
#if DEBUG
    RBTreePrint(EventTree);
#endif
    printf("--- Done!\n");


    return EventTree;
}
Пример #2
0
static int
put_name_arity(term_t t, functor_t f)
{ GET_LD
  FunctorDef fdef = valueFunctor(f);
  term_t a;

  if ( (a=PL_new_term_refs(2)) )
  { PL_put_atom(a+0, fdef->name);

    return (PL_put_integer(a+1, fdef->arity) &&
	    PL_cons_functor(t, FUNCTOR_divide2, a+0, a+1));
  }

  return FALSE;
}