Beispiel #1
0
SLVAL
sl_class_doc(sl_vm_t* vm, SLVAL self)
{
    return get_class(vm, self)->extra->doc;
}
Beispiel #2
0
void do_cmd_power(void)
{
    spell_info spells[MAX_SPELLS];
    int ct = 0; 
    int choice = 0;
    race_t *race_ptr = get_race();
    class_t *class_ptr = get_class();
    
    if (p_ptr->confused)
    {
        msg_print("You are too confused!");
        return;
    }

    /* Hack ... Rethink this a bit, but the alternative of hacking into
       the 'm' command is a million times worse! 
       Doppelgangers need to be able to cancel their current mimicry.
       Also, add Mimic power back first so it always stays in the 'a' slot. */
    if (race_ptr->mimic && p_ptr->prace == RACE_DOPPELGANGER)
    {
        ct += (get_true_race()->get_powers)(spells + ct, MAX_SPELLS - ct);
    }
    
    if (race_ptr->get_powers != NULL)
    {
        ct += (race_ptr->get_powers)(spells + ct, MAX_SPELLS - ct);
    }

    if (class_ptr != NULL && class_ptr->get_powers != NULL)
    {
        ct += (class_ptr->get_powers)(spells + ct, MAX_SPELLS - ct);
    }

    ct += mut_get_powers(spells + ct, MAX_SPELLS - ct);

    if (ct == 0)
    {
        msg_print("You have no powers.");
        return;
    }

    _add_extra_costs_powers(spells, ct);

    choice = choose_spell(spells, ct, "power", p_ptr->csp + p_ptr->chp);

    if (p_ptr->special_defense & (KATA_MUSOU | KATA_KOUKIJIN))
    {
        set_action(ACTION_NONE);
    }

    if (choice >= 0 && choice < ct)
    {
        spell_info *spell = &spells[choice];
        
        if (spell->level > p_ptr->lev)
        {
            msg_print("You can't use that power yet!");
            return;
        }

        if (spell->cost > p_ptr->chp + p_ptr->csp)
        {
            msg_print("Using this power will kill you!  Why not rest a bit first?");
            return;
        }

        /* Check for Failure */
        if (randint0(100) < spell->fail)
        {
            spell_stats_on_fail(spell);
            sound(SOUND_FAIL); /* Doh! */
            fail_spell(spell->fn);
            if (flush_failure) flush();
            msg_print("You failed to concentrate hard enough!");
        }
        else
        {
            if (!cast_spell(spell->fn))
                return;
            spell_stats_on_cast(spell);
            sound(SOUND_ZAP); /* Wahoo! */
        }

        energy_use = get_spell_energy(spell->fn);

        /* Casting costs spill over into hit points */
        if (p_ptr->csp < spell->cost)
        {
            int cost = spell->cost - p_ptr->csp;
            p_ptr->csp = 0;
            take_hit(DAMAGE_USELIFE, cost, "concentrating too hard", -1);
        }
        else 
            p_ptr->csp -= spell->cost;

        p_ptr->redraw |= (PR_MANA);
        p_ptr->redraw |= (PR_HP);
        p_ptr->window |= (PW_SPELL);
    }
}
bool LibElf::ElfIdentification::is_64_bit()
{
    return (get_class() == ELFCLASS64);
}
Beispiel #4
0
BOOL is_void_type(sCLType* cl_type, sCLClass* klass)
{
    sCLClass* klass2 = get_class_from_cl_type(cl_type, klass);
    BOOL result = klass2 == get_class("Null", klass->mFlags & CLASS_FLAGS_JS);
    return result;
}
Beispiel #5
0
JNIEXPORT void JNICALL Java_com_jtxdriggers_android_ventriloid_VentriloInterface_error(JNIEnv* env, jobject obj, jobject eventdata) {
	jclass  event_class = get_class(env, eventdata);
	jobject error = get_object(env, eventdata, event_class, "error", "Lcom/jtxdriggers/android/ventriloid/VentriloEventData$_error;");
	jclass  error_class = get_class(env, error);
	set_byte_array(env, error, error_class, "message", _v3_error(NULL));
}
Beispiel #6
0
void writecode_exp(PARBRE arbre, PATT super_fin_env) {
	char * typeg = NULL;
	char * typed = NULL;
	PATT local_fin_env = NULL;
	char * id = arbre->gauche.S;

	if(arbre)
	switch (arbre->op)
	{

		case New : {
				writecodeln("--NEW");
				
				int c=0;
				writecode("ALLOC ");
				PCLASSE lc = get_class(arbre->gauche.A->gauche.S);
				while(lc){
					PATT att = lc->lattributs;
					while(att){
						c++;
						att = att->suiv;
					}
					lc = get_class(lc->name_parent);
				}
				writecodeiln(1+c);
				writecodeln("DUPN 1"); 
				writecode("PUSHG ");
				writecodeiln( (get_class(arbre->gauche.A->gauche.S))->index );
				writecodeln("STORE 0"); writecodeln("--NEWEND");
				}
				break;
				
		case Bloc : { writecodeln("--BLOC");
				local_fin_env = enrichissement_att_environnement(NULL,arbre->droit.lattributs);

				//Allouer les variables
				PATT att = arbre->droit.lattributs;
				int c = 0;
				while(att){
					c++;
					att = att->suiv;
				}
				writecode("PUSHN ");
				writecodeiln(c);
				writecode_exp( arbre->gauche.A, local_fin_env );
				int i;
				for(i=0;i<c;i++){
					writecodeln("SWAP");
					writecodeln("POPN 1");
				}
				desenrichissement_att_environnement(local_fin_env);
				writecodeln("--BLOCEND");
				} 
				break;

		case Self :
			writecodeln("PUSHL -1");
			//return current_class_name;
			break;
				
		case Id : {
			int index = get_var_index( super_fin_env, id );
			if( current_method == NULL ){ //Main
				writecode("PUSHL ");
				writecodeiln(index + count_classes(definedClasses));
			}else{ 
				if( index > -1 ){
					writecode("PUSHL ");
					writecodeiln(index);				
				}else{
					int indexparam = index_param( current_method , id );
					int n = count_params( current_method );
					if( indexparam ){
						writecode("PUSHL -");
						writecodeiln( n + 2 - indexparam );
					}else{
						int indexatt = index_att( current_class_name , id );
						if( indexatt >=0 ){
							writecodeln("PUSHL -1");
							writecode("LOAD ");
							writecodeiln(indexatt + 1);
						}
					}
				
				}
				
			}
			
			}
			break;
        
		case Fct :{ writecodeln("--APPEL");
			writecodeln("PUSHN 1"); //Pour le retour de la fonction
			
			//Met self au dessus de la pile
			writecodeln("PUSHL -1");
			
			PFONC f = arbre->gauche.F;
			PARG arg = f->largs;
			int c = 0;
			while(arg){
				writecode_exp( arg->expression, super_fin_env );
				writecodeln("SWAP");
				c++;
				arg = arg->suiv;
			}

			writecodeln("DUPN 1");
			writecodeln("LOAD 0");	
			writecode("LOAD ");
			writecodeiln( (get_meth_index( check_type(arbre->gauche.A , NULL, super_fin_env), f->name) ) );
			writecodeln("CALL");
			writecode("POPN ");
			writecodeiln( c + 1 ); //Dépile le destinataire et les paramètres
			writecodeln("--APPELEND");	
		} break;
		
		case Aff: { writecodeln("--AFF");
			writecode_exp(arbre->droit.A, super_fin_env);
			writecodeln("DUPN 1");
			if( arbre->gauche.A->op == '.' ){ //C'est le champ d'un objet
				writecode_exp(arbre->gauche.A->gauche.A, super_fin_env);
				int indexatt = index_att( check_type( arbre->gauche.A->gauche.A, NULL, super_fin_env ) ,
								arbre->gauche.A->droit.S );
				writecodeln("SWAP");
				writecode("STORE ");	
				writecodeiln(indexatt + 2);
			}else { //C'est un id
				
				int index = get_var_index( super_fin_env, arbre->gauche.A->gauche.S );
				if( current_method == NULL ){ //Main
					writecode("STOREL ");
					writecodeiln(index + count_classes(definedClasses));
				}else{
					if( index > -1 ){
						writecode("STOREL ");
						writecodeiln(index);				
					}else{
						int indexparam = index_param( current_method , arbre->gauche.A->gauche.S );
						if( indexparam ){
							int n = count_params( current_method );
							writecode("STOREL -");
							writecodeiln( n + 2 - indexparam );					
						}else{ 
							int indexatt = index_att( current_class_name , arbre->gauche.A->gauche.S );
							if( indexatt >= 0 ){
								writecodeln("PUSHL -1");
								writecodeln("SWAP");
								writecode("STORE ");
								writecodeiln(indexatt + 1);
							}
						}

					}

				}				
			}writecodeln("--AFFEND");
		}

		break;
			
		case ';':
		
			if( arbre->droit.A != NULL ){
				writecode_exp( arbre->gauche.A, super_fin_env );
				writecodeln("POPN 1");
				writecode_exp( arbre->droit.A, super_fin_env );
			}
			break;
			
		case '.' : {
			
			if( arbre->droit.A->op == Id ){	
				writecode_exp( arbre->gauche.A, super_fin_env );
				int index = index_att( check_type( arbre->gauche.A, NULL, super_fin_env ) , arbre->droit.A->gauche.S );
				writecode("LOAD ");
				writecodeiln(index + 2);
				
			}else if( arbre->droit.A->op == Fct ){
				int imprimer = 0;
				PFONC f = arbre->droit.A->gauche.F;
				if( strcmp(f->name,"imprimer")==0 ){
					if( strcmp(check_type( arbre->gauche.A, NULL, super_fin_env ),"Entier")==0 ){
						writecode_exp( arbre->gauche.A, super_fin_env );
						writecodeln("DUPN 1");
						writecodeln("WRITEI");
						imprimer=1;
					}
					if( strcmp(check_type( arbre->gauche.A, NULL, super_fin_env ),"Chaine")==0  ){
						writecode_exp( arbre->gauche.A, super_fin_env );
						writecodeln("DUPN 1");
						writecodeln("WRITES");
						imprimer=1;
					}
				}

				if( !imprimer && arbre->gauche.A->op == Super ){ writecodeln("--APPEL");
						writecodeln("PUSHN 1"); //Pour le retour de la fonction

						PARG arg = f->largs;
						int c = 0;
						while(arg){
							writecode_exp( arg->expression, super_fin_env );
							c++;
							arg = arg->suiv;
						}

						writecodeln("PUSHL -1");
						
						int index = get_class(parent_current_class_name)->index;
						writecode("PUSHG ");
						writecodeiln(index);	
						writecode("LOAD ");
						writecodeiln( (get_meth_index( check_type(arbre->gauche.A, NULL ,super_fin_env), f->name) ) );
						writecodeln("CALL");
						writecode("POPN ");
						writecodeiln( c + 1 ); //Dépile le destinataire et les paramètres
						writecodeln("--APPELEND");
				}else if(!imprimer){		
					writecodeln("--APPEL");	
					writecodeln("PUSHN 1"); //Pour le retour de la fonction
					writecode_exp( arbre->gauche.A, super_fin_env );
				
					PFONC f = arbre->droit.A->gauche.F;
					PARG arg = f->largs;
					int c = 0;
					while(arg){
						writecode_exp( arg->expression, super_fin_env );
						writecodeln("SWAP");
						c++;
						arg = arg->suiv;
					}

					writecodeln("DUPN 1");
					writecodeln("LOAD 0");	
					writecode("LOAD ");
					writecodeiln( (get_meth_index( check_type(arbre->gauche.A, NULL, super_fin_env), f->name) ) );
					writecodeln("CALL");
					writecode("POPN ");
					writecodeiln( c + 1 ); //Dépile le destinataire et les paramètres
					writecodeln("--APPELEND");
				}
			}
			}
			break;
			
		case Cste:	
			writecode("PUSHI ");
			writecodeiln(arbre->gauche.E);
			break;
			
		case String:
			writecode("PUSHS ");
			writecodeln(arbre->gauche.S);
			break;
		
 		case '+':
			writecode_exp(arbre->gauche.A, super_fin_env);
			writecode_exp(arbre->droit.A, super_fin_env);
			writecodeln("ADD");
			break;
		    
		 case '-': 			
			writecode_exp(arbre->gauche.A, super_fin_env);
			writecode_exp(arbre->droit.A, super_fin_env);
			writecodeln("SUB");
			break;
			
		 case '*':
			writecode_exp(arbre->gauche.A, super_fin_env);
			writecode_exp(arbre->droit.A, super_fin_env);
			writecodeln("MUL");
			break;
		
		 case '/':					
			writecode_exp(arbre->gauche.A, super_fin_env);
			writecode_exp(arbre->droit.A, super_fin_env);
			writecodeln("DIV");
			break;

		case ITE :	
			writecode_exp(arbre->gauche.A, super_fin_env);
			int lblelse = newlbl();
			int lblend = newlbl();
			writecode("JZ ");
			writecodeln(lbl(lblelse));
			writecode_exp( arbre->droit.A->gauche.A, super_fin_env );
			writecode("JUMP ");
			writecodeln(lbl(lblend));
			writecode(lbl(lblelse));
			writecodeln(": NOP");
			writecode_exp( arbre->droit.A->droit.A, super_fin_env );
			writecode(lbl(lblend));
			writecodeln(": NOP");
			break;
			
		case LT :	
			writecode_exp(arbre->gauche.A, super_fin_env);
			writecode_exp(arbre->droit.A, super_fin_env);
			writecodeln("INF");
			break;

		case LE :
			writecode_exp(arbre->gauche.A, super_fin_env);
			writecode_exp(arbre->droit.A, super_fin_env);
			writecodeln("INFEQ");
			break;

		case GT :
			writecode_exp(arbre->gauche.A, super_fin_env);
			writecode_exp(arbre->droit.A, super_fin_env);
			writecodeln("SUP");
			break;

		case GE :
			writecode_exp(arbre->gauche.A, super_fin_env);
			writecode_exp(arbre->droit.A, super_fin_env);
			writecodeln("SUPEQ");
			break;

		case EQ :
			writecode_exp(arbre->gauche.A, super_fin_env);
			writecode_exp(arbre->droit.A, super_fin_env);
			writecodeln("EQUAL");
			break;

		case NEQ :
			writecode_exp(arbre->gauche.A, super_fin_env);
			writecode_exp(arbre->droit.A, super_fin_env);
			writecodeln("EQUAL");
			writecodeln("NOT");
			break;
	}
}
Beispiel #7
0
/*
 * New score command by Haus
 */
void do_score( CHAR_DATA* ch, const char* argument )
{
   char buf[MAX_STRING_LENGTH];
   AFFECT_DATA *paf;
   int iLang;
   /*const char *suf;
   short day;

   day = ch->pcdata->day + 1;

   if( day > 4 && day < 20 )
      suf = "th";
   else if( day % 10 == 1 )
      suf = "st";
   else if( day % 10 == 2 )
      suf = "nd";
   else if( day % 10 == 3 )
      suf = "rd";
   else
      suf = "th";
   * - Uncomment this if you want Birthdays dispayed on score for players - Kayle 1/22/08
   */

   set_pager_color( AT_SCORE, ch );

   pager_printf( ch, "\r\nScore for %s%s.\r\n", ch->name, IS_NPC(ch) ? "" : ch->pcdata->title );
   if( get_trust( ch ) != ch->level )
      pager_printf( ch, "You are trusted at level %d.\r\n", get_trust( ch ) );

   send_to_pager( "----------------------------------------------------------------------------\r\n", ch );

   /*if( time_info.day == ch->pcdata->day && time_info.month == ch->pcdata->month )
      send_to_char( "Today is your birthday!\r\n", ch );
   else
      ch_printf( ch, "Your birthday is: Day of %s, %d%s day in the Month of %s, in the year %d.\r\n",
                 day_name[ch->pcdata->day % sysdata.daysperweek], day, suf, month_name[ch->pcdata->month], ch->pcdata->year );
   send_to_pager( "----------------------------------------------------------------------------\r\n", ch );
   * - Uncomment this if you want players to see their birthday's on score. - Kayle 1/22/08
   */

   pager_printf( ch, "LEVEL: %-3d         Race : %-10.10s        Played: %ld hours\r\n",
                 ch->level, capitalize( get_race( ch ) ), ( long int )GET_TIME_PLAYED( ch ) );

   pager_printf( ch, "YEARS: %-6d      Class: %-11.11s       Log In: %s\r",
                 calculate_age( ch ), capitalize( get_class( ch ) ), ctime( &( ch->logon ) ) );

   if( ch->level >= 15 || IS_PKILL( ch ) )
   {
      pager_printf( ch, "STR  : %2.2d(%2.2d)    HitRoll: %-4d              Saved:  %s\r",
                    get_curr_str( ch ), ch->perm_str, GET_HITROLL( ch ),
                    ch->save_time ? ctime( &( ch->save_time ) ) : "no save this session\n" );

      pager_printf( ch, "INT  : %2.2d(%2.2d)    DamRoll: %-4d              Time:   %s\r",
                    get_curr_int( ch ), ch->perm_int, GET_DAMROLL( ch ), ctime( &current_time ) );
   }
   else
   {
      pager_printf( ch, "STR  : %2.2d(%2.2d)                               Saved:  %s\r",
                    get_curr_str( ch ), ch->perm_str, ch->save_time ? ctime( &( ch->save_time ) ) : "no\n" );

      pager_printf( ch, "INT  : %2.2d(%2.2d)                               Time:   %s\r",
                    get_curr_int( ch ), ch->perm_int, ctime( &current_time ) );
   }

   if( GET_AC( ch ) >= 101 )
      snprintf( buf, MAX_STRING_LENGTH, "%s", "the rags of a beggar" );
   else if( GET_AC( ch ) >= 80 )
      snprintf( buf, MAX_STRING_LENGTH, "%s", "improper for adventure" );
   else if( GET_AC( ch ) >= 55 )
      snprintf( buf, MAX_STRING_LENGTH, "%s", "shabby and threadbare" );
   else if( GET_AC( ch ) >= 40 )
      snprintf( buf, MAX_STRING_LENGTH, "%s", "of poor quality" );
   else if( GET_AC( ch ) >= 20 )
      snprintf( buf, MAX_STRING_LENGTH, "%s", "scant protection" );
   else if( GET_AC( ch ) >= 10 )
      snprintf( buf, MAX_STRING_LENGTH, "%s", "that of a knave" );
   else if( GET_AC( ch ) >= 0 )
      snprintf( buf, MAX_STRING_LENGTH, "%s", "moderately crafted" );
   else if( GET_AC( ch ) >= -10 )
      snprintf( buf, MAX_STRING_LENGTH, "%s", "well crafted" );
   else if( GET_AC( ch ) >= -20 )
      snprintf( buf, MAX_STRING_LENGTH, "%s", "the envy of squires" );
   else if( GET_AC( ch ) >= -40 )
      snprintf( buf, MAX_STRING_LENGTH, "%s", "excellently crafted" );
   else if( GET_AC( ch ) >= -60 )
      snprintf( buf, MAX_STRING_LENGTH, "%s", "the envy of knights" );
   else if( GET_AC( ch ) >= -80 )
      snprintf( buf, MAX_STRING_LENGTH, "%s", "the envy of barons" );
   else if( GET_AC( ch ) >= -100 )
      snprintf( buf, MAX_STRING_LENGTH, "%s", "the envy of dukes" );
   else if( GET_AC( ch ) >= -200 )
      snprintf( buf, MAX_STRING_LENGTH, "%s", "the envy of emperors" );
   else
      snprintf( buf, MAX_STRING_LENGTH, "%s", "that of an avatar" );
   if( ch->level > 24 )
      pager_printf( ch, "WIS  : %2.2d(%2.2d)      Armor: %4.4d, %s\r\n",
                    get_curr_wis( ch ), ch->perm_wis, GET_AC( ch ), buf );
   else
      pager_printf( ch, "WIS  : %2.2d(%2.2d)      Armor: %s \r\n", get_curr_wis( ch ), ch->perm_wis, buf );

   if( ch->alignment > 900 )
      snprintf( buf, MAX_STRING_LENGTH, "%s", "devout" );
   else if( ch->alignment > 700 )
      snprintf( buf, MAX_STRING_LENGTH, "%s", "noble" );
   else if( ch->alignment > 350 )
      snprintf( buf, MAX_STRING_LENGTH, "%s", "honorable" );
   else if( ch->alignment > 100 )
      snprintf( buf, MAX_STRING_LENGTH, "%s", "worthy" );
   else if( ch->alignment > -100 )
      snprintf( buf, MAX_STRING_LENGTH, "%s", "neutral" );
   else if( ch->alignment > -350 )
      snprintf( buf, MAX_STRING_LENGTH, "%s", "base" );
   else if( ch->alignment > -700 )
      snprintf( buf, MAX_STRING_LENGTH, "%s", "evil" );
   else if( ch->alignment > -900 )
      snprintf( buf, MAX_STRING_LENGTH, "%s", "ignoble" );
   else
      snprintf( buf, MAX_STRING_LENGTH, "%s", "fiendish" );
   if( ch->level < 10 )
      pager_printf( ch, "DEX  : %2.2d(%2.2d)      Align: %-20.20s    Items: %5.5d   (max %5.5d)\r\n",
                    get_curr_dex( ch ), ch->perm_dex, buf, ch->carry_number, can_carry_n( ch ) );
   else
      pager_printf( ch, "DEX  : %2.2d(%2.2d)      Align: %+4.4d, %-14.14s   Items: %5.5d   (max %5.5d)\r\n",
                    get_curr_dex( ch ), ch->perm_dex, ch->alignment, buf, ch->carry_number, can_carry_n( ch ) );

   switch ( ch->position )
   {
      case POS_DEAD:
         snprintf( buf, MAX_STRING_LENGTH, "%s", "slowly decomposing" );
         break;
      case POS_MORTAL:
         snprintf( buf, MAX_STRING_LENGTH, "%s", "mortally wounded" );
         break;
      case POS_INCAP:
         snprintf( buf, MAX_STRING_LENGTH, "%s", "incapacitated" );
         break;
      case POS_STUNNED:
         snprintf( buf, MAX_STRING_LENGTH, "%s", "stunned" );
         break;
      case POS_SLEEPING:
         snprintf( buf, MAX_STRING_LENGTH, "%s", "sleeping" );
         break;
      case POS_RESTING:
         snprintf( buf, MAX_STRING_LENGTH, "%s", "resting" );
         break;
      case POS_STANDING:
         snprintf( buf, MAX_STRING_LENGTH, "%s", "standing" );
         break;
      case POS_FIGHTING:
         snprintf( buf, MAX_STRING_LENGTH, "%s", "fighting" );
         break;
      case POS_EVASIVE:
         snprintf( buf, MAX_STRING_LENGTH, "%s", "fighting (evasive)" );   /* Fighting style support -haus */
         break;
      case POS_DEFENSIVE:
         snprintf( buf, MAX_STRING_LENGTH, "%s", "fighting (defensive)" );
         break;
      case POS_AGGRESSIVE:
         snprintf( buf, MAX_STRING_LENGTH, "%s", "fighting (aggressive)" );
         break;
      case POS_BERSERK:
         snprintf( buf, MAX_STRING_LENGTH, "%s", "fighting (berserk)" );
         break;
      case POS_MOUNTED:
         snprintf( buf, MAX_STRING_LENGTH, "%s", "mounted" );
         break;
      case POS_SITTING:
         snprintf( buf, MAX_STRING_LENGTH, "%s", "sitting" );
         break;
   }
   pager_printf( ch, "CON  : %2.2d(%2.2d)      Pos'n: %-21.21s  Weight: %5.5d (max %7.7d)\r\n",
                 get_curr_con( ch ), ch->perm_con, buf, ch->carry_weight, can_carry_w( ch ) );


   /*
    * Fighting style support -haus
    */
   pager_printf( ch, "CHA  : %2.2d(%2.2d)      Wimpy: %-5d      ", get_curr_cha( ch ), ch->perm_cha, ch->wimpy );

   switch ( ch->style )
   {
      case STYLE_EVASIVE:
         snprintf( buf, MAX_STRING_LENGTH, "%s", "evasive" );
         break;
      case STYLE_DEFENSIVE:
         snprintf( buf, MAX_STRING_LENGTH, "%s", "defensive" );
         break;
      case STYLE_AGGRESSIVE:
         snprintf( buf, MAX_STRING_LENGTH, "%s", "aggressive" );
         break;
      case STYLE_BERSERK:
         snprintf( buf, MAX_STRING_LENGTH, "%s", "berserk" );
         break;
      default:
         snprintf( buf, MAX_STRING_LENGTH, "%s", "standard" );
         break;
   }
   pager_printf( ch, "Style: %-10.10s\r\n", buf );

   pager_printf( ch, "LCK  : %2.2d(%2.2d) \r\n", get_curr_lck( ch ), ch->perm_lck );

   pager_printf( ch, "Glory: %4.4d(%4.4d) \r\n", ch->pcdata->quest_curr, ch->pcdata->quest_accum );

   pager_printf( ch, "PRACT: %3.3d         Hitpoints: %-5d of %5d   Pager: (%c) %3d    AutoExit(%c)\r\n",
                 ch->practice, ch->hit, ch->max_hit,
                 IS_SET( ch->pcdata->flags, PCFLAG_PAGERON ) ? 'X' : ' ',
                 ch->pcdata->pagerlen, xIS_SET( ch->act, PLR_AUTOEXIT ) ? 'X' : ' ' );

   if( IS_VAMPIRE( ch ) )
      pager_printf( ch, "XP   : %-9d       Blood: %-5d of %5d   MKills:  %-5.5d    AutoLoot(%c)\r\n",
                    ch->exp, ch->pcdata->condition[COND_BLOODTHIRST], 10 + ch->level, ch->pcdata->mkills,
                    xIS_SET( ch->act, PLR_AUTOLOOT ) ? 'X' : ' ' );
   else if( ch->Class == CLASS_WARRIOR )
      pager_printf( ch, "XP   : %-9d                               MKills:  %-5.5d    AutoLoot(%c)\r\n",
                    ch->exp, ch->pcdata->mkills, xIS_SET( ch->act, PLR_AUTOLOOT ) ? 'X' : ' ' );
   else
      pager_printf( ch, "XP   : %-9d        Mana: %-5d of %5d   MKills:  %-5.5d    AutoLoot(%c)\r\n",
                    ch->exp, ch->mana, ch->max_mana, ch->pcdata->mkills, xIS_SET( ch->act, PLR_AUTOLOOT ) ? 'X' : ' ' );

   pager_printf( ch, "GOLD : %-13s    Move: %-5d of %5d   Mdeaths: %-5.5d    AutoSac (%c)\r\n",
                 num_punct( ch->gold ), ch->move, ch->max_move, ch->pcdata->mdeaths, xIS_SET( ch->act,
                                                                                              PLR_AUTOSAC ) ? 'X' : ' ' );

   if( !IS_NPC( ch ) && ch->pcdata->condition[COND_DRUNK] > 10 )
      send_to_pager( "You are drunk.\r\n", ch );
   if( !IS_NPC( ch ) && ch->pcdata->condition[COND_THIRST] == 0 )
      send_to_pager( "You are in danger of dehydrating.\r\n", ch );
   if( !IS_NPC( ch ) && ch->pcdata->condition[COND_FULL] == 0 )
      send_to_pager( "You are starving to death.\r\n", ch );
   if( ch->position != POS_SLEEPING )
      switch ( ch->mental_state / 10 )
      {
         default:
            send_to_pager( "You're completely messed up!\r\n", ch );
            break;
         case -10:
            send_to_pager( "You're barely conscious.\r\n", ch );
            break;
         case -9:
            send_to_pager( "You can barely keep your eyes open.\r\n", ch );
            break;
         case -8:
            send_to_pager( "You're extremely drowsy.\r\n", ch );
            break;
         case -7:
            send_to_pager( "You feel very unmotivated.\r\n", ch );
            break;
         case -6:
            send_to_pager( "You feel sedated.\r\n", ch );
            break;
         case -5:
            send_to_pager( "You feel sleepy.\r\n", ch );
            break;
         case -4:
            send_to_pager( "You feel tired.\r\n", ch );
            break;
         case -3:
            send_to_pager( "You could use a rest.\r\n", ch );
            break;
         case -2:
            send_to_pager( "You feel a little under the weather.\r\n", ch );
            break;
         case -1:
            send_to_pager( "You feel fine.\r\n", ch );
            break;
         case 0:
            send_to_pager( "You feel great.\r\n", ch );
            break;
         case 1:
            send_to_pager( "You feel energetic.\r\n", ch );
            break;
         case 2:
            send_to_pager( "Your mind is racing.\r\n", ch );
            break;
         case 3:
            send_to_pager( "You can't think straight.\r\n", ch );
            break;
         case 4:
            send_to_pager( "Your mind is going 100 miles an hour.\r\n", ch );
            break;
         case 5:
            send_to_pager( "You're high as a kite.\r\n", ch );
            break;
         case 6:
            send_to_pager( "Your mind and body are slipping apart.\r\n", ch );
            break;
         case 7:
            send_to_pager( "Reality is slipping away.\r\n", ch );
            break;
         case 8:
            send_to_pager( "You have no idea what is real, and what is not.\r\n", ch );
            break;
         case 9:
            send_to_pager( "You feel immortal.\r\n", ch );
            break;
         case 10:
            send_to_pager( "You are a Supreme Entity.\r\n", ch );
            break;
      }
   else if( ch->mental_state > 45 )
      send_to_pager( "Your sleep is filled with strange and vivid dreams.\r\n", ch );
   else if( ch->mental_state > 25 )
      send_to_pager( "Your sleep is uneasy.\r\n", ch );
   else if( ch->mental_state < -35 )
      send_to_pager( "You are deep in a much needed sleep.\r\n", ch );
   else if( ch->mental_state < -25 )
      send_to_pager( "You are in deep slumber.\r\n", ch );
   send_to_pager( "Languages: ", ch );
   for( iLang = 0; lang_array[iLang] != LANG_UNKNOWN; iLang++ )
      if( knows_language( ch, lang_array[iLang], ch ) || ( IS_NPC( ch ) && ch->speaks == 0 ) )
      {
         if( lang_array[iLang] & ch->speaking || ( IS_NPC( ch ) && !ch->speaking ) )
            set_pager_color( AT_RED, ch );
         send_to_pager( lang_names[iLang], ch );
         send_to_pager( " ", ch );
         set_pager_color( AT_SCORE, ch );
      }
   send_to_pager( "\r\n", ch );

   if( ch->pcdata->bestowments && ch->pcdata->bestowments[0] != '\0' )
      pager_printf( ch, "You are bestowed with the command(s): %s.\r\n", ch->pcdata->bestowments );

   if( ch->morph && ch->morph->morph )
   {
      send_to_pager( "----------------------------------------------------------------------------\r\n", ch );
      if( IS_IMMORTAL( ch ) )
         pager_printf( ch, "Morphed as (%d) %s with a timer of %d.\r\n",
                       ch->morph->morph->vnum, ch->morph->morph->short_desc, ch->morph->timer );
      else
         pager_printf( ch, "You are morphed into a %s.\r\n", ch->morph->morph->short_desc );
      send_to_pager( "----------------------------------------------------------------------------\r\n", ch );
   }
   if( CAN_PKILL( ch ) )
   {
      send_to_pager( "----------------------------------------------------------------------------\r\n", ch );
      pager_printf( ch, "PKILL DATA:  Pkills (%3.3d)     Illegal Pkills (%3.3d)     Pdeaths (%3.3d)\r\n",
                    ch->pcdata->pkills, ch->pcdata->illegal_pk, ch->pcdata->pdeaths );
   }
   if( ch->pcdata->clan && ch->pcdata->clan->clan_type != CLAN_ORDER && ch->pcdata->clan->clan_type != CLAN_GUILD )
   {
      send_to_pager( "----------------------------------------------------------------------------\r\n", ch );
      pager_printf( ch, "CLAN STATS:  %-14.14s  Clan AvPkills : %-5d  Clan NonAvpkills : %-5d\r\n",
                    ch->pcdata->clan->name, ch->pcdata->clan->pkills[6],
                    ( ch->pcdata->clan->pkills[1] + ch->pcdata->clan->pkills[2] +
                      ch->pcdata->clan->pkills[3] + ch->pcdata->clan->pkills[4] + ch->pcdata->clan->pkills[5] ) );
      pager_printf( ch, "                             Clan AvPdeaths: %-5d  Clan NonAvpdeaths: %-5d\r\n",
                    ch->pcdata->clan->pdeaths[6],
                    ( ch->pcdata->clan->pdeaths[1] + ch->pcdata->clan->pdeaths[2] +
                      ch->pcdata->clan->pdeaths[3] + ch->pcdata->clan->pdeaths[4] + ch->pcdata->clan->pdeaths[5] ) );
   }
   if( ch->pcdata->deity )
   {
      send_to_pager( "----------------------------------------------------------------------------\r\n", ch );
      if( ch->pcdata->favor > 2250 )
         snprintf( buf, MAX_STRING_LENGTH, "%s", "loved" );
      else if( ch->pcdata->favor > 2000 )
         snprintf( buf, MAX_STRING_LENGTH, "%s", "cherished" );
      else if( ch->pcdata->favor > 1750 )
         snprintf( buf, MAX_STRING_LENGTH, "%s", "honored" );
      else if( ch->pcdata->favor > 1500 )
         snprintf( buf, MAX_STRING_LENGTH, "%s", "praised" );
      else if( ch->pcdata->favor > 1250 )
         snprintf( buf, MAX_STRING_LENGTH, "%s", "favored" );
      else if( ch->pcdata->favor > 1000 )
         snprintf( buf, MAX_STRING_LENGTH, "%s", "respected" );
      else if( ch->pcdata->favor > 750 )
         snprintf( buf, MAX_STRING_LENGTH, "%s", "liked" );
      else if( ch->pcdata->favor > 250 )
         snprintf( buf, MAX_STRING_LENGTH, "%s", "tolerated" );
      else if( ch->pcdata->favor > -250 )
         snprintf( buf, MAX_STRING_LENGTH, "%s", "ignored" );
      else if( ch->pcdata->favor > -750 )
         snprintf( buf, MAX_STRING_LENGTH, "%s", "shunned" );
      else if( ch->pcdata->favor > -1000 )
         snprintf( buf, MAX_STRING_LENGTH, "%s", "disliked" );
      else if( ch->pcdata->favor > -1250 )
         snprintf( buf, MAX_STRING_LENGTH, "%s", "dishonored" );
      else if( ch->pcdata->favor > -1500 )
         snprintf( buf, MAX_STRING_LENGTH, "%s", "disowned" );
      else if( ch->pcdata->favor > -1750 )
         snprintf( buf, MAX_STRING_LENGTH, "%s", "abandoned" );
      else if( ch->pcdata->favor > -2000 )
         snprintf( buf, MAX_STRING_LENGTH, "%s", "despised" );
      else if( ch->pcdata->favor > -2250 )
         snprintf( buf, MAX_STRING_LENGTH, "%s", "hated" );
      else
         snprintf( buf, MAX_STRING_LENGTH, "%s", "damned" );
      pager_printf( ch, "Deity:  %-20s  Favor: %s\r\n", ch->pcdata->deity->name, buf );
   }
   if( ch->pcdata->clan && ch->pcdata->clan->clan_type == CLAN_ORDER )
   {
      send_to_pager( "----------------------------------------------------------------------------\r\n", ch );
      pager_printf( ch, "Order:  %-20s  Order Mkills:  %-6d   Order MDeaths:  %-6d\r\n",
                    ch->pcdata->clan->name, ch->pcdata->clan->mkills, ch->pcdata->clan->mdeaths );
   }
   if( ch->pcdata->clan && ch->pcdata->clan->clan_type == CLAN_GUILD )
   {
      send_to_pager( "----------------------------------------------------------------------------\r\n", ch );
      pager_printf( ch, "Guild:  %-20s  Guild Mkills:  %-6d   Guild MDeaths:  %-6d\r\n",
                    ch->pcdata->clan->name, ch->pcdata->clan->mkills, ch->pcdata->clan->mdeaths );
   }
   if( IS_IMMORTAL( ch ) )
   {
      send_to_pager( "----------------------------------------------------------------------------\r\n", ch );

      pager_printf( ch, "IMMORTAL DATA:  Wizinvis [%s]  Wizlevel (%d)\r\n",
                    xIS_SET( ch->act, PLR_WIZINVIS ) ? "X" : " ", ch->pcdata->wizinvis );

      pager_printf( ch, "Bamfin:  %s %s\r\n", ch->name, ( ch->pcdata->bamfin[0] != '\0' )
                    ? ch->pcdata->bamfin : "appears in a swirling mist." );
      pager_printf( ch, "Bamfout: %s %s\r\n", ch->name, ( ch->pcdata->bamfout[0] != '\0' )
                    ? ch->pcdata->bamfout : "leaves in a swirling mist." );


      /*
       * Area Loaded info - Scryn 8/11
       */
      if( ch->pcdata->area )
      {
         pager_printf( ch, "Vnums:   Room (%-5.5d - %-5.5d)   Object (%-5.5d - %-5.5d)   Mob (%-5.5d - %-5.5d)\r\n",
                       ch->pcdata->area->low_r_vnum, ch->pcdata->area->hi_r_vnum,
                       ch->pcdata->area->low_o_vnum, ch->pcdata->area->hi_o_vnum,
                       ch->pcdata->area->low_m_vnum, ch->pcdata->area->hi_m_vnum );
         pager_printf( ch, "Area Loaded [%s]\r\n", ( IS_SET( ch->pcdata->area->status, AREA_LOADED ) ) ? "yes" : "no" );
      }
   }
   if( ch->first_affect )
   {
      int i;
      SKILLTYPE *sktmp;

      i = 0;
      send_to_pager( "----------------------------------------------------------------------------\r\n", ch );
      send_to_pager( "AFFECT DATA:                            ", ch );
      for( paf = ch->first_affect; paf; paf = paf->next )
      {
         if( ( sktmp = get_skilltype( paf->type ) ) == NULL )
            continue;
         if( ch->level < 20 )
         {
            pager_printf( ch, "[%-34.34s]    ", sktmp->name );
            if( i == 0 )
               i = 2;
            if( ( ++i % 3 ) == 0 )
               send_to_pager( "\r\n", ch );
         }
         if( ch->level >= 20 )
         {
            if( paf->modifier == 0 )
               pager_printf( ch, "[%-24.24s;%5d rds]    ", sktmp->name, paf->duration );
            else if( paf->modifier > 999 )
               pager_printf( ch, "[%-15.15s; %7.7s;%5d rds]    ",
                             sktmp->name, tiny_affect_loc_name( paf->location ), paf->duration );
            else
               pager_printf( ch, "[%-11.11s;%+-3.3d %7.7s;%5d rds]    ",
                             sktmp->name, paf->modifier, tiny_affect_loc_name( paf->location ), paf->duration );
            if( i == 0 )
               i = 1;
            if( ( ++i % 2 ) == 0 )
               send_to_pager( "\r\n", ch );
         }
      }
   }
   send_to_pager( "\r\n", ch );
   return;
}
Beispiel #8
0
Token_t*
convert_Java_token(JNIEnv *env, jobject token)
   {
     jclass cls;
     jstring java_string;
     const char *text = NULL;
     jmethodID method_id;
     Token_t *our_token = NULL;
     JavaSourceCodePosition * pos_info = NULL;
     jobject jpos_info;

     assert(env != NULL);

  // Need to get the object class so we can use it to retrieve the methods.
  // printf ("Need to get the object class so we can use it to retrieve the methods. \n");  
     cls = get_class(env, token);

  // Get the method ID for the getText() method.
  // printf ("Get the method ID for the getText() method. \n");
     method_id = get_method(env, cls, "getText", "()Ljava/lang/String;");

  // Call getText() to get the Java String object (note that the cast is critical!).
  // printf ("Call getText() to get the Java String object. \n");
     java_string = (jstring) env->CallObjectMethod(token, method_id);

  // Get a C char string for the Java String if the Java String exists.
  // printf ("Get a C char string for the Java String if the Java String exists. \n");
     if (java_string != NULL)
        {
          text = env->GetStringUTFChars(java_string, NULL);
          if (text == NULL)
             {
               fprintf(stderr, "Unable to retrieve text string from String object\n");
               assert(false);
             }
        }
       else
        {
          text = NULL;
        }

  // Get the method ID for the getJavaSourcePositionInformation() method.
     method_id = get_method(env, cls, "getJavaSourcePositionInformation", "()LJavaSourcePositionInformation;");
     jpos_info = (jobject) env->CallObjectMethod(token, method_id);

     // Convert position to its C-based representation
     pos_info = convert_Java_SourcePosition(env, jpos_info);

     // Build a C-based representation of the JavaToken
     our_token = new Token_t(text, pos_info);

#if 0
  // Release the string now that we've made a new copy for ourselves.
  // printf ("Release the string now that we've made a new copy for ourselves. \n");
     if (java_string != NULL)
          env->ReleaseStringUTFChars(java_string, text);
#endif

  // printf ("returning from convert_Java_token()\n");
     return our_token;
   }
/*
*
* Retorna o token
*
*/
Token* getToken()
{
	Token* token;
	char* buffer;

	token = (Token*) malloc(sizeof(Token));

	buffer = (char*) malloc(sizeof(char));
	buffer[0] = '\0';

	// We start the machine
	State* current_state;
	State* next_state;
	current_state = NULL;
	next_state = getFirstState(STATEMACHINE);

	// We iterate while the next_state isn't NULL
	int token_noted = 0;
	while(next_state != NULL)
	{
		// We get the next state
		current_state = next_state;
		if(CURRENT_CHAR != EOF)
		{
			next_state = GetNextState(STATEMACHINE, current_state, CURRENT_CHAR);
		}
		else
		{
			next_state = NULL;
		}

		// If the next state is NULL, the state machine has finished reading the string
		if(next_state != NULL)
		{
			// We write the contents on the buffer:
			// If it is in a ignoring state, ignore the buffer (commentary and blank characters
			if(!(next_state->isIgnoringState))
			{
				// Append the char to the buffer
				append_char(&buffer, CURRENT_CHAR);

				// Write the first line and column of the token, if it wasn't
				if(!token_noted)
				{
					token->line = LINE;
					token->column = COLUMN;

					token_noted = 1;
				}
			}

			// We get the next char
			LAST_CHAR = CURRENT_CHAR;
			CURRENT_CHAR = fgetc(SOURCE_CODE);
			update_line_column();
		}
	}

	// We complete the token using the information from the state where we are
	if(current_state != NULL && !(current_state->isIgnoringState)) // If the current state is not null and not a ignoring state
	{
		token->tokenClass = get_class(current_state->name, buffer);

		token->value = (char*) malloc((strlen(buffer) + 1) * sizeof(char));
		strcpy(token->value, buffer);
	}
	else
	{
		if(CURRENT_CHAR == EOF)
		{
			FILE_ENDED = 1;

			token->tokenClass = EOA;
			token->value = NULL;
		}
		else
		{
			token->tokenClass = ERR;

			token->value = (char*) malloc((strlen(buffer) + 1) * sizeof(char));
			strcpy(token->value, buffer);

			token->line = LINE;
			token->column = COLUMN;
		}
	}

	return token;
}
Beispiel #10
0
static SLVAL
sl_class_name(sl_vm_t* vm, SLVAL self)
{
    return get_class(vm, self)->name;
}
bool CL_CSSSelector::select(const std::vector<CL_StringRef> &match_path, int &specificity) const
{
	specificity = 0;

	std::vector<CL_StringRef>::size_type selector_path_pos = path_elements.size();
	std::vector<CL_StringRef>::size_type match_path_pos = match_path.size();
	while (selector_path_pos > 0)
	{
		if (match_path_pos == 0)
			return false;

		const CL_String &selector_path_element = path_elements[selector_path_pos-1];
		const CL_String &match_path_element = match_path[match_path_pos-1];

		if (selector_path_element == "*")
		{
			// path element matched
			match_path_pos--;
			selector_path_pos--;
			continue;
		}

		CL_StringRef selector_path_type = get_type(selector_path_element);
		CL_StringRef selector_path_class = get_class(selector_path_element);
		CL_StringRef selector_path_id = get_id(selector_path_element);
		CL_StringRef selector_path_state = get_state(selector_path_element);

		CL_StringRef match_path_type = get_type(match_path_element);
		CL_StringRef match_path_class = get_class(match_path_element);
		CL_StringRef match_path_id = get_id(match_path_element);
		CL_StringRef match_path_state = get_state(match_path_element);

		if (selector_path_type != match_path_type)
			return false;
		if (!selector_path_class.empty() && selector_path_class != match_path_class)
			return false;
		if (!selector_path_id.empty() && selector_path_id != match_path_id)
			return false;
		if (selector_path_state.empty())
		{
			// path element matched
			match_path_pos--;
			selector_path_pos--;
			continue;
		}

		std::vector<CL_String> selector_states = CL_StringHelp::split_text(selector_path_state, ":");
		std::vector<CL_String> match_states = CL_StringHelp::split_text(match_path_state, ":");

		std::vector<CL_StringRef>::size_type selector_states_pos;
		for (selector_states_pos = 0; selector_states_pos < selector_states.size(); selector_states_pos++)
		{
			CL_String &selector_state = selector_states[selector_states_pos];
			
			std::vector<CL_StringRef>::size_type match_states_pos;
			bool state_matched = false;
			for (match_states_pos = 0; match_states_pos < match_states.size(); match_states_pos++)
			{
				CL_String &match_state = match_states[match_states_pos];
				if (selector_state == match_state)
				{
					state_matched = true;
					break;
				}
			}

			if (!state_matched)
				return false;
		}

		// path_element matched
		match_path_pos--;
		selector_path_pos--;
	}

	for (selector_path_pos = 0; selector_path_pos < path_elements.size(); selector_path_pos++)
	{
		const CL_String &selector_path_element = path_elements[selector_path_pos];

		CL_StringRef selector_path_type = get_type(selector_path_element);
		CL_StringRef selector_path_class = get_class(selector_path_element);
		CL_StringRef selector_path_id = get_id(selector_path_element);
		CL_StringRef selector_path_state = get_state(selector_path_element);

		if (!selector_path_id.empty())
			specificity += 0x010000;
		if (!selector_path_class.empty())
			specificity += 0x000100;
		if (!selector_path_type.empty())
			specificity += 0x000001;
		if (!selector_path_state.empty())
			specificity += 0x000001;
	}

	return true;
}
Beispiel #12
0
void train_crbm(dataset_blas *train_set, int nvisible, int nhidden, int nlabel,
               int epoch, double lr,
               int minibatch, double momentum, char *model_file){
    crbm m;
    int i, j, k;
    int nepoch;
    double *v1, *y1;
    uint8_t *l;
    int batch_size, niter;
    int wc;
    int err;
    double lik;
    double delta;
    int *idx;
    time_t start_t, end_t;

    init_crbm(&m, nvisible, nhidden, nlabel);

    //wc = (int)cblas_dasum(train_set->N * train_set->n_feature, train_set->input, 1);
    niter = (train_set->N-1)/minibatch + 1;
    delta = lr / (1.0*minibatch);
    /*
     * shuffle training data
    v1 = (double*)malloc(minibatch * m.nvisible * sizeof(double));
    y1 = (double*)malloc(minibatch * m.ncat * sizeof(double));
    l = (uint8_t*)malloc(minibatch * sizeof(uint8_t));
    idx = (int*)malloc(train_set->N * sizeof(int));
    for(i = 0; i < train_set->N; i++)
        idx[i] = i;*/
    bzero(w_u, sizeof(w_u));
    bzero(u_u, sizeof(u_u));
    bzero(bh_u, sizeof(bh_u));
    bzero(bv_u, sizeof(bv_u));
    bzero(by_u, sizeof(by_u));

    //shuffle(idx, train_set->N);
    
    for(nepoch = 0; nepoch < epoch; nepoch++){
        
        lik = 0;
        err = 0;
        start_t = time(NULL);

        for(k = 0; k < niter; k++){
#ifdef DEBUG
            if((k+1) % 200 == 0){
                printf("batch %d\n", k+1);
            }
#endif
            if(k == niter - 1){
                batch_size = train_set->N - minibatch * (niter-1);
            }else{
                batch_size = minibatch;
            }

            v1 = train_set->input + train_set->n_feature * minibatch * k;
            y1 = train_set->label + train_set->nlabel * minibatch * k;
            l = train_set->output + minibatch * k;
            /*
             * shuffle training data
            for(i = 0; i < batch_size; i++){
                cblas_dcopy(m.nvisible, train_set->input + m.nvisible * idx[k*minibatch+i],
                            1, v1 + m.nvisible * i, 1);
                cblas_dcopy(m.ncat, train_set->label + m.ncat * idx[k*minibatch+i],
                            1, y1 + m.ncat * i, 1);
                l[i] = train_set->output[idx[k*minibatch+i]];
            }*/
            get_hidden(&m, v1, y1, ph1, batch_size);            
            sample_hidden(&m, ph1, h1, batch_size);

            get_visible(&m, h1, pv, batch_size);
            sample_visible(&m, pv, v2, batch_size);

            get_class(&m, h1, py, batch_size);
            sample_class(&m, py, y2, batch_size);

            get_hidden(&m, v2, y2, ph2, batch_size);
            sample_hidden(&m, ph2, h2, batch_size);
            
            //lik += get_likelihood(&m, v1, pv, batch_size);
            err += get_error(&m, y2, l, batch_size);
            
            //update w_u
            cblas_dgemm(CblasRowMajor, CblasTrans, CblasNoTrans,
                        m.nhidden, m.nvisible, batch_size,
                        1.0, ph2, m.nhidden, v2, m.nvisible,
                        0, a, m.nvisible);
            cblas_dgemm(CblasRowMajor, CblasTrans, CblasNoTrans,
                        m.nhidden, m.nvisible, batch_size,
                        1.0, ph1, m.nhidden, v1, m.nvisible,
                        -1, a, m.nvisible);
            cblas_daxpy(m.nvisible * m.nhidden, momentum, w_u, 1,
                        a, 1);
            cblas_dcopy(m.nvisible * m.nhidden, a, 1, w_u, 1);

            //update u_u
            cblas_dgemm(CblasRowMajor, CblasTrans, CblasNoTrans,
                        m.nhidden, m.ncat, batch_size,
                        1.0, ph2, m.nhidden, y2, m.ncat,
                        0, a, m.ncat);
            cblas_dgemm(CblasRowMajor, CblasTrans, CblasNoTrans,
                        m.nhidden, m.ncat, batch_size,
                        1.0, ph1, m.nhidden, y1, m.ncat,
                        -1, a, m.ncat);
            cblas_daxpy(m.ncat * m.nhidden, momentum, u_u, 1,
                        a, 1);
            cblas_dcopy(m.ncat * m.nhidden, a, 1, u_u, 1);

            //update bv_u
            cblas_dgemm(CblasRowMajor, CblasTrans, CblasNoTrans,
                        m.nvisible, 1, batch_size,
                        1.0, v2, m.nvisible, I, 1,
                        0, a, 1);
            cblas_dgemm(CblasRowMajor, CblasTrans, CblasNoTrans,
                        m.nvisible, 1, batch_size,
                        1.0, v1, m.nvisible, I, 1,
                        -1, a, 1);
            cblas_daxpy(m.nvisible, momentum, bv_u, 1,
                        a, 1);
            cblas_dcopy(m.nvisible, a, 1, bv_u, 1);

            //update by_u
            cblas_dgemm(CblasRowMajor, CblasTrans, CblasNoTrans,
                        m.ncat, 1, batch_size,
                        1.0, y2, m.ncat, I, 1,
                        0, a, 1);
            cblas_dgemm(CblasRowMajor, CblasTrans, CblasNoTrans,
                        m.ncat, 1, batch_size,
                        1.0, y1, m.ncat, I, 1,
                        -1, a, 1);
            cblas_daxpy(m.ncat, momentum, by_u, 1,
                        a, 1);
            cblas_dcopy(m.ncat, a, 1, by_u, 1);

            //update bh_u
            cblas_dgemm(CblasRowMajor, CblasTrans, CblasNoTrans,
                        m.nhidden, 1, batch_size,
                        1.0, ph2, m.nhidden, I, 1,
                        0, a, 1);
            cblas_dgemm(CblasRowMajor, CblasTrans, CblasNoTrans,
                        m.nhidden, 1, batch_size,
                        1.0, ph1, m.nhidden, I, 1,
                        -1, a, 1);
            cblas_daxpy(m.nhidden, momentum, bh_u, 1,
                        a, 1);
            cblas_dcopy(m.nhidden, a, 1, bh_u, 1);

            //change parameter
            cblas_daxpy(m.nvisible * m.nhidden, delta, w_u, 1,
                        m.w, 1);
            cblas_daxpy(m.ncat * m.nhidden, delta, u_u, 1,
                        m.u, 1);
            cblas_daxpy(m.nvisible, delta, bv_u, 1,
                        m.bv, 1);
            cblas_daxpy(m.ncat, delta, by_u, 1,
                        m.by, 1);
            cblas_daxpy(m.nhidden, delta, bh_u, 1,
                        m.bh, 1);
        }
        end_t = time(NULL);

        printf("[epoch %d] error:%.5lf%%\ttime:%.2fmin\n", nepoch + 1, 
               err * 100.0 / train_set->N, (end_t - start_t) / 60.0);
    }
    dump_model(&m, model_file);
    //print_prob(&m, train_set, "../data/rsm/test.prob");

    /*
     * shuffle training data
    free(v1);
    free(y1);
    free(l);*/
    free_crbm(&m);
}
Beispiel #13
0
//--------------------------------------------------------------------------
// Generate text for the current location
int ida_export class_place_t__generate(
									   const cp_t *ths,
									   void *ud,
									   char *lines[],
									   int maxsize,
									   int *default_lnnum,
									   color_t *prefix_color,
									   bgcolor_t *bg_color)
{
	strvec_t &sv = *(strvec_t *)ud;
	uval_t idx = ths->idx;
	if ( idx > get_last_class_idx() || maxsize <= 0 )
		return 0;
	char name[MAXNAMESIZE];

	tid_t tid = get_class_by_idx(idx);
	if (tid==BADNODE)
		return 0;
	switch (ths->section)
	{
	case 0:	
		if (get_class_name(tid, name, MAXNAMESIZE))
		{
			char line[MAXSTR];
			class_t * clas = get_class(tid);
			if(!clas)
				return 0;
			if (clas->parents_tid.size())
				qsnprintf(line, MAXSTR, "class %s: derived from: 0x%p", name, clas->parents_tid.front());
			else
				qsnprintf(line, MAXSTR, "class %s", name );
				
			lines[0] = qstrdup(line);
			*bg_color = 0xC0C0FF;
		}
		break;

	case 1:
		{
			char line[MAXSTR];
			class_t * clas = get_class(tid);
			if(!clas)
				return 0;
			if (clas->virt_table_ea != BADADDR)
				qsnprintf(line, MAXSTR, "vftable: %p", clas->virt_table_ea);
			else
				qsnprintf(line, MAXSTR, "no virtual table");				
			lines[0] = qstrdup(line);
			*bg_color = 0xC0FFC0;
		}
		break;

	case 2:
		{
			char *line;
			class_t * clas = get_class(tid);
			if(!clas)
				return 0;

			ea_t ea = BADADDR;
			if (clas->functions_ea.size() && ths->subsection<=clas->functions_ea.size())
				ea = clas->functions_ea[ths->subsection];
			if (ea!=BADADDR)
			{
				qstring tmpline;
				get_colored_long_name(&tmpline, ea);

				qtype type;
				qtype fields;  
				if (!get_tinfo(ea, &type, &fields))
				{
					if (!guess_func_tinfo(get_func(ea), &type, &fields))
						goto pokracuj; 
				}
				line = qstrdup(tmpline.c_str()); 
				print_type_to_one_line(line, MAXSTR, idati, type.c_str(), line, 0, fields.c_str(), 0);
pokracuj:
				;				

			}
			else qsnprintf(line, MAXSTR, "bad func");
			lines[0] = qstrdup(line);
			*bg_color = 0xC0FFFF;
		}
		break;

	}
	

	//*prefix_color = sv[idx%sv.size()].color;
	//*bg_color = sv[idx%sv.size()].bgcolor;
	*default_lnnum = 0;
	return 1; // generated one line

	//setup_makeline(-1, ..., save_line_in_array, 0)
	//finish_makeline();
}
Beispiel #14
0
SLVAL
sl_class_doc_set(sl_vm_t* vm, SLVAL self, SLVAL doc)
{
    return get_class(vm, self)->extra->doc = doc;
}
Beispiel #15
0
static SLVAL
sl_class_super(sl_vm_t* vm, SLVAL self)
{
    return get_class(vm, self)->super;
}
static nsresult
mdn_normalize(bool do_composition, bool compat,
	  const nsAString& aSrcStr, nsAString& aToStr)
{
	workbuf_t wb;
	nsresult r = NS_OK;
	/*
	 * Initialize working buffer.
	 */
	workbuf_init(&wb);

	nsAString::const_iterator start, end;
	aSrcStr.BeginReading(start); 
	aSrcStr.EndReading(end); 

	while (start != end) {
		PRUint32 c;
		PRUnichar curChar;

		//assert(wb.cur == wb.last);

		/*
		 * Get one character from 'from'.
		 */
		curChar= *start++;

		if (NS_IS_HIGH_SURROGATE(curChar) && start != end && NS_IS_LOW_SURROGATE(*(start)) ) {
			c = SURROGATE_TO_UCS4(curChar, *start);
			++start;
		} else {
			c = curChar;
		}

		/*
		 * Decompose it.
		 */
		if ((r = decompose(&wb, c, compat)) != NS_OK)
			break;

		/*
		 * Get canonical class.
		 */
		get_class(&wb);

		/*
		 * Reorder & compose.
		 */
		for (; wb.cur < wb.last; wb.cur++) {
			if (wb.cur == 0) {
				continue;
			} else if (wb.cclass[wb.cur] > 0) {
				/*
				 * This is not a starter. Try reordering.
				 * Note that characters up to it are
				 * already in canonical order.
				 */
				reorder(&wb);
				continue;
			}

			/*
			 * This is a starter character, and there are
			 * some characters before it.  Those characters
			 * have been reordered properly, and
			 * ready for composition.
			 */
			if (do_composition && wb.cclass[0] == 0)
				compose(&wb);

			/*
			 * If CUR points to a starter character,
			 * then process of characters before CUR are
			 * already finished, because any further
			 * reordering/composition for them are blocked
			 * by the starter CUR points.
			 */
			if (wb.cur > 0 && wb.cclass[wb.cur] == 0) {
				/* Flush everything before CUR. */
				r = flush_before_cur(&wb, aToStr);
				if (r != NS_OK)
					break;
			}
		}
	}

	if (r == NS_OK) {
		if (do_composition && wb.cur > 0 && wb.cclass[0] == 0) {
			/*
			 * There is some characters left in WB.
			 * They are ordered, but not composed yet.
			 * Now CUR points just after the last character in WB,
			 * and since compose() tries to compose characters
			 * between top and CUR inclusive, we must make CUR
			 * one character back during compose().
			 */
			wb.cur--;
			compose(&wb);
			wb.cur++;
		}
		/*
		 * Call this even when WB.CUR == 0, to make TO
		 * NUL-terminated.
		 */
		r = flush_before_cur(&wb, aToStr);
	}

	workbuf_free(&wb);

	return (r);
}
Beispiel #17
0
PMETH check_methodes(PMETH methodes, char * class_name, char * super_class_name, PATT lattributs){
	PMETH lm = methodes;
	PCLASSE super_class = get_class(super_class_name); 
	
	current_class_name = class_name;
	parent_current_class_name = super_class_name;
	  if(super_class_name != NULL )
	  if(! strcmp(class_name, super_class_name) || !strcmp("Entier",super_class_name) || !strcmp("Chaine", super_class_name)){
	      fprintf(stderr, "Erreur! %s ne peut être une classe parente de la classe %s \n", super_class_name, class_name);
	      exit(3);   
	   }	
	  
	
	while(lm){

		current_methode = lm->name;
		//Vérification du type de retour
		check_type_declaration(lm->type,class_name);
		current_methode_return_type = lm->type;		
		//Vérification des paramètres
		check_attributs(lm->lparams,class_name,NULL);
		 if(lattributs){
		  			AttributsEnvironnement = NEW(1,ATTRIBUT);
		  			memcpy(AttributsEnvironnement,lattributs,sizeof(ATTRIBUT));
		  	}else AttributsEnvironnement = NULL;
		  		
		  	if(methodes){
		  			MethodesEnvironnement = NEW(1,METHODE);
		  			memcpy(MethodesEnvironnement, methodes,sizeof(METHODE));
		  } else MethodesEnvironnement = NULL;
		PARBRE a = lm->expression;
		
		PATT local_fin_env = enrichissement_att_environnement(super_class_name,lm->lparams);
		char * type_exp = check_type (a,NULL,local_fin_env);
		desenrichissement_att_environnement(local_fin_env);
		if(type_exp==NULL) 
		{			
			fprintf(stderr,"Methode %s \n",lm->name);
			fprintf(stderr,"Type de retour incorrect\n");
			exit(4);
		}
		
		int found = 0;
		if (strcmp(type_exp,lm->type) != 0) 
		{
			PCLASSE lc = get_class(type_exp);
			
			char * sclass = NULL;
			if(lc){
				sclass= lc->name_parent;
			}else if(!strcmp(type_exp,current_class_name)){
				sclass = super_class_name;
			}
			while(sclass && !found){
				if (strcmp(sclass,lm->type) == 0){
					found = 1;
				}
				lc = get_class(sclass);
				if(lc){
					sclass = lc->name_parent;
				}else sclass = NULL;
			}
		}else found =1;
		if(!found){
			fprintf(stderr, "Erreur de retour (%s): ",type_exp);
			fprintf(stderr, "type attendu %s\n", lm->type);
			exit(4);
		}

		check_superclass_declaration(lm,super_class);
		AttributsEnvironnement = NULL;
		MethodesEnvironnement = NULL;
		lm = lm->suiv;
	}
	current_methode = NULL;
	current_methode_return_type = NULL;
	return methodes;
		
}
Beispiel #18
0
JNIEXPORT jobjectArray JNICALL Java_com_sleepycat_db_xa_DbXAResource__1recover
  (JNIEnv *jnienv, jobject jthis, jint rmid, jint flags)
{
	XID *xids;
	int err;
	int total;
	int cnt;
	int i;
	int curflags;
	size_t nbytes;
	jclass xid_class;
	jmethodID mid;
	jobject obj;
	jobjectArray retval;

	COMPQUIET(jthis, NULL);
	total = 0;
	cnt = 0;
	xids = NULL;
	flags &= ~(DB_FIRST | DB_LAST | DB_NEXT);

	/* Repeatedly call __db_xa_recover to fill up an array of XIDs */
	curflags = flags | DB_FIRST;
	do {
		total += cnt;
		nbytes = sizeof(XID) * (total + 10);
		if ((err = __os_realloc(NULL, nbytes, &xids)) != 0) {
			if (xids != NULL)
				__os_free(NULL, xids);
			verify_return(jnienv, XAER_NOTA, EXCEPTION_XA);
			return (NULL);
		}
		cnt = __db_xa_recover(&xids[total], 10, rmid, curflags);
		curflags = flags | DB_NEXT;
	} while (cnt > 0);

	if (xids != NULL)
		__os_free(NULL, xids);

	if (cnt < 0) {
		verify_return(jnienv, cnt, EXCEPTION_XA);
		return (NULL);
	}

	/* Create the java DbXid array and fill it up */
	if ((xid_class = get_class(jnienv, name_DB_XID)) == NULL)
		return (NULL);
	mid = (*jnienv)->GetMethodID(jnienv, xid_class, "<init>",
				     "(I[B[B)V");
	if ((retval = (*jnienv)->NewObjectArray(jnienv, total, xid_class, 0))
	    == NULL)
		goto out;

	for (i = 0; i < total; i++) {
		jobject gtrid;
		jobject bqual;
		jsize gtrid_len;
		jsize bqual_len;

		gtrid_len = (jsize)xids[i].gtrid_length;
		bqual_len = (jsize)xids[i].bqual_length;
		gtrid = (*jnienv)->NewByteArray(jnienv, gtrid_len);
		bqual = (*jnienv)->NewByteArray(jnienv, bqual_len);
		if (gtrid == NULL || bqual == NULL)
			goto out;
		(*jnienv)->SetByteArrayRegion(jnienv, gtrid, 0, gtrid_len,
		    (jbyte *)&xids[i].data[0]);
		(*jnienv)->SetByteArrayRegion(jnienv, bqual, 0, bqual_len,
		    (jbyte *)&xids[i].data[gtrid_len]);
		if ((obj = (*jnienv)->NewObject(jnienv, xid_class, mid,
		    (jint)xids[i].formatID, gtrid, bqual)) == NULL)
			goto out;
		(*jnienv)->SetObjectArrayElement(jnienv, retval, i, obj);
	}
out:	return (retval);
}
Beispiel #19
0
/**
 * Vérifie le type d'une expression dans l'environnement.
 * L'environnement parent est délimité par super_env_fin, ce qui signifie
 * que ce pointeur pointe dans l'environnement des attributs vers la première
 * variable locale d'un certain noeud de l'arbre.
 */
char* check_type(PARBRE arbre, char * type, PATT super_fin_env) {
	char * typeg = NULL;
	char * typed = NULL;
	PATT local_fin_env = NULL;
	char * id = arbre->gauche.S;

	if(arbre)
	switch (arbre->op)
	{
		case New :
				return arbre->gauche.A->gauche.S;
				break;
				
		case Bloc : 
				//enrichissement de l'environnement avec les variables locales du bloc
				local_fin_env = enrichissement_att_environnement(NULL,arbre->droit.lattributs);
				//parsage et récupréation du type du bloc dans l'environnement
				char * t = check_type(arbre->gauche.A, NULL,local_fin_env);
				//appauvrissement de l'environnement pour remonter d'un noeud.
				desenrichissement_att_environnement(local_fin_env);
				return t; 
				break;

		case Self :
			return current_class_name;
			break;

		case Super :
			if(parent_current_class_name==NULL){
				fprintf(stderr, "Utilisation de super impossible : \n"); 
				fprintf(stderr, "La classe %s n'a pas de classe parente\n",current_class_name); 				    
				exit(2); 
			}
			return parent_current_class_name;
			break;
				
		case Id : {
			if(type == NULL)  {			// variable 

				PATT la = super_fin_env;//recherche locale
				while(la){
					if(strcmp(id,la->name) == 0) {
						//printf("attribut local %s",la->name);
						return (la->type);
					}
					la = la->suiv;
				}		
				if(current_methode!=NULL){//recherche dans les paramètres de la méthode
					//si on est dans une méthode
					PMETH meth = MethodesEnvironnement;
					int found = 0;
					while(meth && !found){
						if(!strcmp(meth->name,current_methode)){
							found =1;
							la = meth->lparams;
							while(la){
								if(!strcmp(id,la->name)){
									return la->type;
								}
								la = la->suiv;
							}
						}else meth = meth->suiv;
					}
				}
					
				la = AttributsEnvironnement;//recheche globale		
				while(la && la!=super_fin_env){
					if(strcmp(id,la->name) == 0) {
						
						return (la->type);
					}
					la = la->suiv;
				}
				id_not_found(id);
				return NULL;
			}
			else if (current_class_name && strcmp(type,current_class_name) == 0) // apres un self.
			{			
				PATT la = AttributsEnvironnement;//recherche globale
				while(la && la!=super_fin_env){
					if(strcmp(id,la->name) == 0) {
						return (la->type);
					}
					la = la->suiv;
				}
				id_not_found(id);
				return NULL;
				
			}
			else{		// attribut	d'une classe	
				PCLASSE lc = get_class(type);
				if(lc == NULL){ fprintf(stderr,"Classe %s inconnue\n",type); exit(4);}
				PATT la = lc->lattributs;
				while (la) {
					if(strcmp(la->name,id) == 0) {
							return la->type;	
					}
					la = la->suiv;
				}
				id_not_found(id);
				return NULL;
			}
		} break;
        
		case Fct :{	
			
			//Gestion d'un appel de methode
			PFONC f = arbre->gauche.F;
			if( type != NULL && ((!strcmp( type, "Entier" ) || !strcmp( type, "Chaine" )))
				 && !strcmp( f->name, "imprimer" )){
				if( f->largs == NULL ) return type;
				else{ printf("Imprimer ne prend pas de parametres\n"); exit(4); }
			}

			PMETH lm = NULL; 
			PATT am = NULL;
			PARG af = NULL;

			char * param_type;
			
			if(current_methode)
			if(!strcmp(f->name,current_methode)){
				return current_methode_return_type;
			}
			
			if(type) {
				//récupération de la classe
				PCLASSE lc = get_class(type);
				if(lc){//récupération des méthodes de la classe
					lm = lc->lmethodes;
				}else{
					if(type && current_class_name)
					if(strcmp(type,current_class_name) == 0) {
						lm = MethodesEnvironnement;
					}
				}
			}else{
				lm = MethodesEnvironnement;
			}
			PCLASSE super_class = NULL;
			//parcours des méthodes de la classe et vérification de la conformité
			//des appels
			
			do{
				while (lm) {
					if(strcmp(lm->name,f->name) == 0) {
						//on a trouvé la methode de l'appel
						am = lm->lparams;
						af = f->largs;

						
						int i = 0;
						//Vérification des paramètres de l'appel
						while(am!=NULL && am!=super_fin_env && af!=NULL){
							//verification des types des paramètres
							param_type = check_type(af->expression,NULL,super_fin_env);
							if(param_type){
								if(strcmp(param_type,am->type)!=0) {
									int found = 0;
									PCLASSE parent = get_class(param_type);
									parent = get_class(parent->name_parent);
									while(!found && parent){
										if(strcmp(parent->name,am->type)==0)
											found = 1;
										parent = get_class(parent->name_parent);										
									}
									if(!found){
										fprintf(stderr, "Erreur : type incompatible dans l'appel de fonction %s : param %s devrait être %s \n", f->name, param_type,am->type);
										exit(4);
									}
								}
							}
							i++;
							am = am->suiv;
							af = af->suiv;
						}

						if((am!=NULL && am!=super_fin_env) || af!=NULL){
							fprintf(stderr, "Erreur : nombre de paramètre incorrect dans l'appel de fonction %s\n", f->name);
							exit(4);
						}
						return lm->type;
					}
					lm = lm->suiv;
				}
				//recherche dans la hiérarchie
				if(super_class == NULL){
					if(type == NULL){
						super_class = get_class(parent_current_class_name);
					}else{
						if(current_class_name){
							if(!strcmp(current_class_name,type))
								super_class = get_class(parent_current_class_name);
							
						}else{ super_class = get_class(type);
							if(super_class){
								super_class = get_class(super_class->name_parent);
							}
						}
					}
				}else{
					super_class = get_class(super_class->name_parent);
				}

				if(super_class){ 
					lm = super_class->lmethodes;
				}

			}while(super_class);
			fct_not_found(f->name);//aucune methode ne correspond à cet appel
			return NULL;
		} break;
		
		case Aff: {
			//Affectation
			typeg = check_type(arbre->gauche.A, NULL,super_fin_env);

			typed = check_type(arbre->droit.A, NULL,super_fin_env);			
			
			int found = 0;
			if (strcmp(typeg,typed) != 0) 
			{	//recherche des types hiérarchiques
				PCLASSE lc = get_class(typed);
				char * sclass = NULL;
				if(lc){
					sclass= lc->name_parent;
				}else if(!strcmp(typed,current_class_name)){
					sclass = parent_current_class_name;
				}
				while(sclass && !found){
					if (strcmp(sclass,typeg) == 0){
						found = 1;
					}
					lc = get_class(sclass);
					if(lc){
						sclass = lc->name_parent;
					}else sclass = NULL;
				}
			}else found =1;
			if(!found){
				fprintf(stderr, "type incompatible : %s %s %s \n", typeg, ":=", typed);
				exit(4);
			}	
			
			
		}
		return typed;
		break;
			
		case ';':
			//Reconnaissance Expression
			typeg = check_type(arbre->gauche.A, NULL,super_fin_env);
			typed = check_type(arbre->droit.A, NULL,super_fin_env);
			return typed;
			
			break;
			
		case '.' :
			//Accès sur un objet
			typeg = check_type(arbre->gauche.A, NULL,super_fin_env);

			if(typeg == NULL) {
				fprintf(stderr,	 "Type Inconnu\n");
				exit(4);
			}

			int is_methode = is_methode_call(arbre->droit.A);
			int forbidden = 0;
			//Si on tente d'accéder à un attribut, on vérifie si on en a le droit
			if(!is_methode){
				forbidden = 1;
				if(current_class_name!=NULL)
				if(strcmp(typeg,current_class_name)!=0){
					PCLASSE parent = get_class(typeg);
					parent = get_class(parent->name_parent);
					//recherche de l'attribut dans la hiérarchie de l'objet
					while(parent && forbidden){
						if(strcmp(parent->name,current_class_name)==0){
							forbidden = 0;
						}
						parent = get_class(parent->name_parent);
					}
				}else forbidden = 0;
				
				if(forbidden && parent_current_class_name!=NULL)
				if(strcmp(typeg,parent_current_class_name)!=0){
					//l'objet fait partie de la hiérarchie de la classe courante
					PCLASSE parent = get_class(parent_current_class_name);
					parent = get_class(parent->name_parent);
					while(parent && forbidden){
						if(strcmp(parent->name,typeg)==0){
							forbidden = 0;
						}
						parent = get_class(parent->name_parent);					
					}
				}else forbidden = 0;				
			}
			if(forbidden){
				fprintf(stderr, "Acces d'attribut interdit sur : %s\n", typeg);
				exit(4);				
			}

			typed = check_type(arbre->droit.A, typeg,super_fin_env);
			return typed;
			break;
			
		case Cste:			
			//Reconnaissance d'une constante
			return "Entier";
			break;
			
		case String:
			//Reconnaissance d'une Chaine
			return "Chaine";
			break;
		
		
 		case '+':
 //			Operation d'addition
			typeg = check_type(arbre->gauche.A,NULL,super_fin_env);
			typed = check_type(arbre->droit.A,NULL,super_fin_env);
			if(typed!=NULL && typeg!=NULL)			
			if(	strcmp(typeg,typed) != 0) {
				fprintf(stderr, "type incompatible : %s %c %s \n", typeg, '+', typed);
				exit(4);
			}
			return typeg;
		    
		 case '-': 			
			 //			Operation de soustraction		 
			typeg = check_type(arbre->gauche.A,NULL,super_fin_env);
			typed = check_type(arbre->droit.A,NULL,super_fin_env);
			
			if(typed!=NULL && typeg!=NULL)
			if(	strcmp(typeg,typed) != 0) {
				fprintf(stderr, "type incompatible : %s - %s \n", typeg, typed);
				exit(4);
			}
			return typeg;
			
		 case '*':
			typeg = check_type(arbre->gauche.A,NULL,super_fin_env);
			typed = check_type(arbre->droit.A,NULL,super_fin_env);
			
			if(typed!=NULL && typeg!=NULL)
			if(	strcmp(typeg,typed) != 0) {
				fprintf(stderr, "type incompatible : %s * %s \n", typeg, typed);
				exit(4);
			}	
		    return typeg;
		
		 case '/':			
			typeg = check_type(arbre->gauche.A,NULL,super_fin_env);
			typed = check_type(arbre->droit.A,NULL,super_fin_env);
			
			if(typed!=NULL && typeg!=NULL)
			if(	strcmp(typeg,typed) != 0) {
				fprintf(stderr, "type incompatible : %s / %s \n", typeg, typed);
				exit(4);
			}			
			return typeg;
		
		case ITE :
			//if then else
			typeg = check_type(arbre->gauche.A,NULL,super_fin_env);
			typed = check_type(arbre->droit.A,NULL,super_fin_env);
			return typed;
			break;
		
		case CONC : 
			//partie then else d'un if
			typeg = check_type(arbre->gauche.A,NULL,super_fin_env);
			typed = check_type(arbre->droit.A,NULL,super_fin_env);
			
			//recherche de la classe parente commune au renvoi du then et celui du else
			if( typeg == NULL || typed == NULL || strcmp(typed,typeg) != 0) {
				int found = 0;							
				if(typeg!=NULL && typed!=NULL){
					PCLASSE pereG = NULL;
					char * nomG = NULL;
					if(!strcmp(typeg,current_class_name)){
						nomG = current_class_name;
					}else {
						pereG = get_class(typeg);
						if(pereG)
						nomG = pereG->name;
					}
					PCLASSE pereD = NULL;
					char * nomD = NULL;
					while(nomG && !found){
						if(!strcmp(typed,current_class_name)){
							nomD = current_class_name;
						}else{
							pereD = get_class(typed);
							if(pereD)
							nomD = pereD->name;
						}
						while(!found && nomD){
							if(!strcmp(nomG,nomD)){
								found =1;
							}
							if(pereD){
								pereD = get_class(pereD->name_parent);	
							}else{
								pereD = get_class(parent_current_class_name);
							}
							if(pereD){
								nomD = pereD->name;
							}else nomD = NULL;
						}							
						
						if(pereG){
							pereG = get_class(pereG->name_parent);	
						}else{
							pereG = get_class(parent_current_class_name);
						}
						if(pereG){
							nomG = pereG->name;
						}else nomG = NULL;
					}
				}
				if(!found){
					fprintf(stderr, "type du then (%s) incompatible avec le type du else (%s) \n", typeg,typed);
					exit(4);
				}
			}
			return typed;
			break;
			
			case NEQ : case EQ : case GT : case LE : case LT : case GE :
		//Operation relationelle
			typeg = check_type(arbre->gauche.A,NULL,super_fin_env);
			if(strcmp("Entier",typeg) != 0) {
				fprintf(stderr, "type incompatible avec l'operateur relationnel : %s \n", typeg);
				fprintf(stderr, "type attendu : Entier \n");
				exit(4);
			}
			
			typed = check_type(arbre->droit.A,NULL,super_fin_env);
			if(strcmp("Entier",typed	) != 0) {
				fprintf(stderr, "type incompatible avec l'operateur relationnel : %s \n", typed);
				fprintf(stderr, "type attendu : Entier \n");
				exit(4);
			}
			
			return typed;
			break;
		
		default: return NULL;
	}
	return NULL;
}
EAP_FUNC_EXPORT eap_const_string asn1_der_type_c::get_tag_string() const
{

#if defined(USE_EAP_DEBUG_TRACE)

	asn1_class_e asn1_class = get_class();
	asn1_tag_e tag = get_tag();

	if (asn1_class == asn1_class_context_specific)
	{
		static const eap_char context[][4] = { "[0]", "[1]", "[2]", "[3]", "[4]", "[5]", "[6]", "[7]", "[8]", "[9]", };
		if (tag < (sizeof(context)/sizeof(context[0])))
		{
			return context[tag];
		}
		else
		{
			return("<Too big context>");
		}
	}
	else
	{
		EAP_IF_RETURN_STRING(tag, asn1_tag_end_of_content)
		else EAP_IF_RETURN_STRING(tag, asn1_tag_boolean)
		else EAP_IF_RETURN_STRING(tag, asn1_tag_integer)
		else EAP_IF_RETURN_STRING(tag, asn1_tag_bit_string)
		else EAP_IF_RETURN_STRING(tag, asn1_tag_octet_string)
		else EAP_IF_RETURN_STRING(tag, asn1_tag_null)
		else EAP_IF_RETURN_STRING(tag, asn1_tag_object_identifier)
		else EAP_IF_RETURN_STRING(tag, asn1_tag_object_descriptor)
		else EAP_IF_RETURN_STRING(tag, asn1_tag_external)
		else EAP_IF_RETURN_STRING(tag, asn1_tag_real)
		else EAP_IF_RETURN_STRING(tag, asn1_tag_enumerated)
		else EAP_IF_RETURN_STRING(tag, asn1_tag_empedded_pdv)
		else EAP_IF_RETURN_STRING(tag, asn1_tag_utf8_string)
		else EAP_IF_RETURN_STRING(tag, asn1_tag_relative_oid)
		else EAP_IF_RETURN_STRING(tag, asn1_tag_unknown_14)
		else EAP_IF_RETURN_STRING(tag, asn1_tag_unknown_15)
		else EAP_IF_RETURN_STRING(tag, asn1_tag_sequence)
		else EAP_IF_RETURN_STRING(tag, asn1_tag_set)
		else EAP_IF_RETURN_STRING(tag, asn1_tag_numeric_string)
		else EAP_IF_RETURN_STRING(tag, asn1_tag_printable_string)
		else EAP_IF_RETURN_STRING(tag, asn1_tag_t61_string)
		else EAP_IF_RETURN_STRING(tag, asn1_tag_videotex_string)
		else EAP_IF_RETURN_STRING(tag, asn1_tag_ia5_string)
		else EAP_IF_RETURN_STRING(tag, asn1_tag_utc_time)
		else EAP_IF_RETURN_STRING(tag, asn1_tag_unknown_24)
		else EAP_IF_RETURN_STRING(tag, asn1_tag_graphic_string)
		else EAP_IF_RETURN_STRING(tag, asn1_tag_visible_string)
		else EAP_IF_RETURN_STRING(tag, asn1_tag_general_string)
		else EAP_IF_RETURN_STRING(tag, asn1_tag_universal_string)
		else EAP_IF_RETURN_STRING(tag, asn1_tag_character_string)
		else EAP_IF_RETURN_STRING(tag, asn1_tag_bmp_string)
		else EAP_IF_RETURN_STRING(tag, asn1_tag_extented)
		else EAP_IF_RETURN_STRING(tag, asn1_tag_none)
		else
		{
			return("<Unknown Tag>");
		}
	}

#else

	return("<Unknown Tag>");

#endif //#if defined(USE_EAP_DEBUG_TRACE)

}
Beispiel #21
0
inline tid_t get_class_id(const char *name)              // get struct id by name
{
  tid_t id = netnode(name);
  return get_class(id) == NULL ? BADADDR : id;
}
eap_status_e asn1_der_type_c::debug_header(eap_variable_data_c * const debug_buffer)
{
	if (debug_buffer == 0)
	{
		EAP_TRACE_END(m_am_tools, TRACE_FLAGS_DEFAULT);
		return EAP_STATUS_RETURN(m_am_tools, eap_status_illegal_parameter);
	}

	const u32_t max_data_length(m_recursion * SIZE_OF_ONE_OCTET_STRING + m_offset_of_contents_field * SIZE_OF_ONE_OCTET_STRING);

	if (max_data_length > debug_buffer->get_buffer_length())
	{
		EAP_TRACE_END(m_am_tools, TRACE_FLAGS_DEFAULT);
		return EAP_STATUS_RETURN(m_am_tools, eap_status_allocation_error);
	}

	eap_status_e status = debug_buffer->set_data_length(max_data_length);
	if (status != eap_status_ok)
	{
		EAP_TRACE_END(m_am_tools, TRACE_FLAGS_DEFAULT);
		return EAP_STATUS_RETURN(m_am_tools, status);
	}

	u32_t ind(0ul);
	u32_t offset(0ul);

	u8_t * const prefix = reinterpret_cast<u8_t *>(debug_buffer->get_data(max_data_length));

	if (prefix == 0)
	{
		EAP_TRACE_END(m_am_tools, TRACE_FLAGS_DEFAULT);
		return EAP_STATUS_RETURN(m_am_tools, eap_status_allocation_error);
	}

	status = debug_create_prefix(m_recursion, prefix, max_data_length, &offset);
	if (status != eap_status_ok)
	{
		EAP_TRACE_END(m_am_tools, TRACE_FLAGS_DEFAULT);
		return EAP_STATUS_RETURN(m_am_tools, status);
	}

	for (ind = 0ul; ind < m_offset_of_length_field && ind < m_input_data_length; ++ind)
	{
		offset += m_am_tools->snprintf(
			debug_buffer->get_data_offset(offset, debug_buffer->get_data_length() - offset),
			debug_buffer->get_data_length() - offset,
			"%02x \0",
			m_input_data[ind]);
	}

	for (ind = m_offset_of_length_field; ind < m_offset_of_contents_field && ind < m_input_data_length; ++ind)
	{
		offset += m_am_tools->snprintf(
			debug_buffer->get_data_offset(offset, debug_buffer->get_data_length() - offset),
			debug_buffer->get_data_length() - offset,
			"%02x \0",
			m_input_data[ind]);
	}

	status = debug_buffer->add_end_null();
	if (status != eap_status_ok)
	{
		EAP_TRACE_END(m_am_tools, TRACE_FLAGS_DEFAULT);
		return EAP_STATUS_RETURN(m_am_tools, status);
	}

	eap_const_string tag_string = 0;
	eap_char buffer[MAX_STACK_BUFFER];

	if (get_class() == asn1_class_application)
	{
		m_am_tools->snprintf(
			reinterpret_cast<u8_t *>(buffer),
			MAX_STACK_BUFFER,
			"Application[%d]\0",
			get_tag());

		tag_string = buffer;
	}
	else if (get_class() == asn1_class_context_specific)
	{
		m_am_tools->snprintf(
			reinterpret_cast<u8_t *>(buffer),
			MAX_STACK_BUFFER,
			"[%d]\0",
			get_tag());

		tag_string = buffer;
	}
	else
	{
		tag_string = get_tag_string();
	}

	EAP_TRACE_DEBUG(
		m_am_tools,
		TRACE_FLAGS_DEFAULT,
		(EAPL("%s # %s, %s, %s, length=0x%x=%d, this=0x%08x, index=%d\n"),
			debug_buffer->get_data(max_data_length),
			get_class_string(),
			get_pc_string(),
			tag_string,
			get_content_length(),
			get_content_length(),
			this,
			m_index));

	EAP_TRACE_END(m_am_tools, TRACE_FLAGS_DEFAULT);
	return EAP_STATUS_RETURN(m_am_tools, status);
}
Beispiel #23
0
int diff_can_type( hid_t       f_tid1, /* file data type */
                   hid_t       f_tid2, /* file data type */
                   int         rank1,
                   int         rank2,
                   hsize_t     *dims1,
                   hsize_t     *dims2,
                   hsize_t     *maxdim1,
                   hsize_t     *maxdim2,
                   const char  *obj1_name,
                   const char  *obj2_name,
                   diff_opt_t  *options,
                   int         is_compound)
{


    H5T_class_t  tclass1;
    H5T_class_t  tclass2;
    int          maxdim_diff=0;          /* maximum dimensions are different */
    int          dim_diff=0;             /* current dimensions are different */
    int          i;
    int          can_compare = 1;        /* return value */

    /*-------------------------------------------------------------------------
    * check for the same class
    *-------------------------------------------------------------------------
    */

    if ((tclass1=H5Tget_class(f_tid1)) < 0)
        return -1;

    if ((tclass2=H5Tget_class(f_tid2)) < 0)
        return -1;

    if ( tclass1 != tclass2 )
    {

        if ( (options->m_verbose||options->m_list_not_cmp) && obj1_name && obj2_name)
        {

            if ( is_compound )
            {

                parallel_print("Not comparable: <%s> has a class %s and <%s> has a class %s\n",
                    obj1_name, get_class(tclass1),
                    obj2_name, get_class(tclass2) );

            }

            else

            {

                parallel_print("Not comparable: <%s> is of class %s and <%s> is of class %s\n",
                    obj1_name, get_class(tclass1),
                    obj2_name, get_class(tclass2) );

            }

        }


        can_compare = 0;
        options->not_cmp = 1;
        return can_compare;
    }

    /*-------------------------------------------------------------------------
    * check for non supported classes
    *-------------------------------------------------------------------------
    */

    HDassert(tclass1==tclass2);
    switch (tclass1)
    {
    case H5T_INTEGER:
    case H5T_FLOAT:
    case H5T_COMPOUND:
    case H5T_STRING:
    case H5T_ARRAY:
    case H5T_BITFIELD:
    case H5T_OPAQUE:
    case H5T_ENUM:
    case H5T_VLEN:
    case H5T_REFERENCE:

        break;

    default: /*H5T_TIME */


        if ( (options->m_verbose||options->m_list_not_cmp) && obj1_name && obj2_name)
        {
            parallel_print("Not comparable: <%s> and <%s> are of class %s\n",
                obj1_name,obj2_name,get_class(tclass2) );
        }
        can_compare = 0;
        options->not_cmp = 1;
        return can_compare;
    }

    /*-------------------------------------------------------------------------
    * check for equal file datatype; warning only
    *-------------------------------------------------------------------------
    */

    if ( (H5Tequal(f_tid1, f_tid2)==0) &&
        (options->m_verbose) && obj1_name && obj2_name)
    {

        H5T_class_t cl = H5Tget_class(f_tid1);


        parallel_print("Warning: different storage datatype\n");
        if ( cl == H5T_INTEGER || cl == H5T_FLOAT )
        {
            parallel_print("<%s> has file datatype ", obj1_name);
            print_type(f_tid1);
            parallel_print("\n");
            parallel_print("<%s> has file datatype ", obj2_name);
            print_type(f_tid2);
            parallel_print("\n");
        }



    }

    /*-------------------------------------------------------------------------
    * check for the same rank
    *-------------------------------------------------------------------------
    */


    if ( rank1 != rank2 )
    {

        if ( (options->m_verbose||options->m_list_not_cmp) && obj1_name && obj2_name)
        {
            parallel_print("Not comparable: <%s> has rank %d, dimensions ", obj1_name, rank1);
            print_dimensions(rank1,dims1);
            parallel_print(", max dimensions ");
            print_dimensions(rank1,maxdim1);
            parallel_print("\n" );
            parallel_print("and <%s> has rank %d, dimensions ", obj2_name, rank2);
            print_dimensions(rank2,dims2);
            parallel_print(", max dimensions ");
            print_dimensions(rank2,maxdim2);
            parallel_print("\n");
        }

        can_compare = 0;
        options->not_cmp = 1;
        return can_compare;
    }

    /*-------------------------------------------------------------------------
    * check for different dimensions
    *-------------------------------------------------------------------------
    */

    HDassert(rank1==rank2);
    for ( i=0; i<rank1; i++)
    {
        if (maxdim1 && maxdim2)
        {
            if ( maxdim1[i] != maxdim2[i] )
                maxdim_diff=1;
        }
        if ( dims1[i] != dims2[i] )
            dim_diff=1;
    }

    /*-------------------------------------------------------------------------
    * current dimensions
    *-------------------------------------------------------------------------
    */

    if (dim_diff==1)
    {
        if ( (options->m_verbose||options->m_list_not_cmp) && obj1_name && obj2_name)
        {
            parallel_print("Not comparable: <%s> has rank %d, dimensions ", obj1_name, rank1);
            print_dimensions(rank1,dims1);
            if (maxdim1 && maxdim2)
            {
                parallel_print(", max dimensions ");
                print_dimensions(rank1,maxdim1);
                parallel_print("\n" );
                parallel_print("and <%s> has rank %d, dimensions ", obj2_name, rank2);
                print_dimensions(rank2,dims2);
                parallel_print(", max dimensions ");
                print_dimensions(rank2,maxdim2);
                parallel_print("\n");
            }
        }


        can_compare = 0;
        options->not_cmp = 1;
        return can_compare;



    }

    /*-------------------------------------------------------------------------
    * maximum dimensions; just give a warning
    *-------------------------------------------------------------------------
    */
    if (maxdim1 && maxdim2 && maxdim_diff==1 && obj1_name )
    {
        if (options->m_verbose) {
            parallel_print( "Warning: different maximum dimensions\n");
            parallel_print("<%s> has max dimensions ", obj1_name);
            print_dimensions(rank1,maxdim1);
            parallel_print("\n");
            parallel_print("<%s> has max dimensions ", obj2_name);
            print_dimensions(rank2,maxdim2);
            parallel_print("\n");
        }
    }


    if ( tclass1 == H5T_COMPOUND )
    {

        int   nmembs1;
        int   nmembs2;
        int   j;
        hid_t memb_type1;
        hid_t memb_type2;

        nmembs1 = H5Tget_nmembers(f_tid1);
        nmembs2 = H5Tget_nmembers(f_tid2);

        if ( nmembs1 != nmembs2 )
        {

            if ( (options->m_verbose||options->m_list_not_cmp) && obj1_name && obj2_name)
            {
                parallel_print("Not comparable: <%s> has %d members ", obj1_name, nmembs1);
                parallel_print("<%s> has %d members ", obj2_name, nmembs2);
                parallel_print("\n");
            }

            can_compare = 0;
            options->not_cmp = 1;
            return can_compare;
        }

        for (j = 0; j < nmembs1; j++)
        {
            memb_type1 = H5Tget_member_type(f_tid1, (unsigned)j);
            memb_type2 = H5Tget_member_type(f_tid2, (unsigned)j);

            if (diff_can_type(memb_type1,
                memb_type2,
                rank1,
                rank2,
                dims1,
                dims2,
                maxdim1,
                maxdim2,
                obj1_name,
                obj2_name,
                options,
                1)!=1)
            {
                can_compare = 0;
                options->not_cmp = 1;
                H5Tclose(memb_type1);
                H5Tclose(memb_type2);
                return can_compare;
            }

            H5Tclose(memb_type1);
            H5Tclose(memb_type2);

        }





    }





    return can_compare;
}
Beispiel #24
0
bool void_object::operator==( const objref other ) const
{
    return (&other->get_class()==&get_class());
}
Beispiel #25
0
JNIEXPORT void JNICALL Java_com_jtxdriggers_android_ventriloid_VentriloInterface_getevent(JNIEnv* env, jobject obj, jobject eventdata) {
	v3_event *ev = v3_get_event(V3_BLOCK);
	if(ev != NULL) {
		jclass event_class = get_class(env, eventdata);
		set_short(env, eventdata, event_class, "type", ev->type);
		switch(ev->type) {
			case V3_EVENT_PLAY_AUDIO:
				{
					// PCM data.
					jobject pcm = get_object(env, eventdata, event_class, "pcm", "Lcom/jtxdriggers/android/ventriloid/VentriloEventData$_pcm;");
					jclass	pcm_class = get_class(env, pcm);
					set_int	 (env, pcm, pcm_class, "length", ev->pcm.length);
					set_int	 (env, pcm, pcm_class, "rate", ev->pcm.rate);
					set_short(env, pcm, pcm_class, "send_type", ev->pcm.send_type);
					set_byte (env, pcm, pcm_class, "channels", ev->pcm.channels);
					
					// User ID.
					jobject user = get_object(env, eventdata, event_class, "user", "Lcom/jtxdriggers/android/ventriloid/VentriloEventData$_user;");
					jclass  user_class = get_class(env, user);
					set_short(env, user, user_class, "id", ev->user.id);
					
					// Sample.
					jobject data = get_object(env, eventdata, event_class, "data", "Lcom/jtxdriggers/android/ventriloid/VentriloEventData$_data;");
					jclass  data_class = get_class(env, data);
					set_pcm_byte_array(env, data, data_class, "sample", ev->data->sample, ev->pcm.length);
				}
				break;
				
			case V3_EVENT_PING:
				{
					// Ping.
					set_int(env, eventdata, event_class, "ping", ev->ping);
				}
				break;
				
			case V3_EVENT_USER_TALK_END:
			case V3_EVENT_USER_TALK_MUTE:
			case V3_EVENT_CHAT_JOIN:
			case V3_EVENT_CHAT_LEAVE:
			case V3_EVENT_USER_GLOBAL_MUTE_CHANGED:
			case V3_EVENT_USER_CHANNEL_MUTE_CHANGED:
			case V3_EVENT_USER_RANK_CHANGE:
				{
					// User ID.
					jobject user = get_object(env, eventdata, event_class, "user", "Lcom/jtxdriggers/android/ventriloid/VentriloEventData$_user;");
					jclass  user_class = get_class(env, user);
					set_short(env, user, user_class, "id", ev->user.id);
				}
				break;
				
			case V3_EVENT_USER_CHAN_MOVE:
			case V3_EVENT_USER_LOGOUT:
			case V3_EVENT_CHAN_REMOVE:
				{
					// User ID.
					jobject user = get_object(env, eventdata, event_class, "user", "Lcom/jtxdriggers/android/ventriloid/VentriloEventData$_user;");
					jclass  user_class = get_class(env, user);
					set_short(env, user, user_class, "id", ev->user.id);
					
					// Channel ID.
					jobject channel = get_object(env, eventdata, event_class, "channel", "Lcom/jtxdriggers/android/ventriloid/VentriloEventData$_channel;");
					jclass  channel_class = get_class(env, channel);
					set_short(env, channel, channel_class, "id", ev->channel.id);
				}
				break;
			
			case V3_EVENT_USER_MODIFY:
			case V3_EVENT_USER_LOGIN:
				{
					// User ID.
					jobject user = get_object(env, eventdata, event_class, "user", "Lcom/jtxdriggers/android/ventriloid/VentriloEventData$_user;");
					jclass  user_class = get_class(env, user);
					set_short(env, user, user_class, "id", ev->user.id);
					
					// Channel ID.
					jobject channel = get_object(env, eventdata, event_class, "channel", "Lcom/jtxdriggers/android/ventriloid/VentriloEventData$_channel;");
					jclass  channel_class = get_class(env, channel);
					set_short(env, channel, channel_class, "id", ev->channel.id);
					
					// Flags.
					set_int(env, eventdata, event_class, "flags", ev->flags);
				}
				break;
				
			case V3_EVENT_STATUS:
				{
					// Status message & percentage.
					jobject status = get_object(env, eventdata, event_class, "status", "Lcom/jtxdriggers/android/ventriloid/VentriloEventData$_status;");
					jclass  status_class = get_class(env, status);
					set_byte(env, status, status_class, "percent", ev->status.percent);
					set_byte_array(env, status, status_class, "message", ev->status.message);
				}
				break;
				
			case V3_EVENT_LOGIN_COMPLETE:
			case V3_EVENT_LOGIN_FAIL:
			case V3_EVENT_DISCONNECT:
			case V3_EVENT_ADMIN_AUTH:
			case V3_EVENT_CHAN_ADMIN_UPDATED:
			case V3_EVENT_PERMS_UPDATED:
				{
					// No event data for these types!
				}
				break;


			case V3_EVENT_PRIVATE_CHAT_START:
			case V3_EVENT_PRIVATE_CHAT_END:
			case V3_EVENT_PRIVATE_CHAT_AWAY:
			case V3_EVENT_PRIVATE_CHAT_BACK:
				{
					// User IDs.
					jobject user = get_object(env, eventdata, event_class, "user", "Lcom/jtxdriggers/android/ventriloid/VentriloEventData$_user;");
					jclass  user_class = get_class(env, user);
					set_short(env, user, user_class, "privchat_user1", ev->user.privchat_user1);
					set_short(env, user, user_class, "privchat_user2", ev->user.privchat_user2);
				}

			case V3_EVENT_PRIVATE_CHAT_MESSAGE:
				{
					// User IDs.
					jobject user = get_object(env, eventdata, event_class, "user", "Lcom/jtxdriggers/android/ventriloid/VentriloEventData$_user;");
					jclass  user_class = get_class(env, user);
					set_short(env, user, user_class, "privchat_user1", ev->user.privchat_user1);
					set_short(env, user, user_class, "privchat_user2", ev->user.privchat_user2);
					
					// Chat message.
					jobject data = get_object(env, eventdata, event_class, "data", "Lcom/jtxdriggers/android/ventriloid/VentriloEventData$_data;");
					jclass  data_class = get_class(env, data);
					set_byte_array(env, data, data_class, "chatmessage", ev->data->chatmessage);
					
					// Flags.
					set_int(env, eventdata, event_class, "flags", ev->flags);
				}
				break;
				
			case V3_EVENT_USERLIST_ADD:
			case V3_EVENT_USERLIST_MODIFY:
				{
					// Account fields.
					jobject data = get_object(env, eventdata, event_class, "data", "Lcom/jtxdriggers/android/ventriloid/VentriloEventData$_data;");
					jclass  data_class = get_class(env, data);
					jobject account = get_object(env, data, data_class, "account", "Lcom/jtxdriggers/android/ventriloid/VentriloEventData$_data$_account;");
					jclass  account_class = get_class(env, account);
					set_byte_array(env, account, account_class, "username", ev->data->account.username);
				}
				break;
			
			case V3_EVENT_CHAN_ADD:
			case V3_EVENT_CHAN_MODIFY:
				{
					// Channel id.
					jobject channel = get_object(env, eventdata, event_class, "channel", "Lcom/jtxdriggers/android/ventriloid/VentriloEventData$_channel;");
					jclass  channel_class = get_class(env, channel);
					set_short(env, channel, channel_class, "id", ev->channel.id);
				}
				break;
				
			case V3_EVENT_DISPLAY_MOTD:
				{
					/* don't deal with any MOTD events here because they're useless
					// MOTD.
					jobject data = get_object(env, eventdata, event_class, "data", "Lcom/jtxdriggers/android/ventriloid/VentriloEventData$_data;");
					jclass  data_class = get_class(env, data);
					set_byte_array(env, data, data_class, "motd", ev->data->motd);
					
					// Flags.
					set_int(env, eventdata, event_class, "flags", ev->flags);
					*/
				}
				break;
				
			case V3_EVENT_CHAN_BADPASS:
				{
					// Channel ID.
					jobject channel = get_object(env, eventdata, event_class, "channel", "Lcom/jtxdriggers/android/ventriloid/VentriloEventData$_channel;");
					jclass  channel_class = get_class(env, channel);
					set_short(env, channel, channel_class, "id", ev->channel.id);
					
					// Error message.
					jobject error = get_object(env, eventdata, event_class, "error", "Lcom/jtxdriggers/android/ventriloid/VentriloEventData$_error;");
					jclass  error_class = get_class(env, error);
					set_byte_array(env, error, error_class, "message", ev->error.message);
				}
				break;
				
				
			case V3_EVENT_ERROR_MSG:
				{
					// Error message & disconnect flag.
					jobject error = get_object(env, eventdata, event_class, "error", "Lcom/jtxdriggers/android/ventriloid/VentriloEventData$_error;");
					jclass  error_class = get_class(env, error);
					set_byte_array(env, error, error_class, "message", ev->error.message);
					set_bool(env, error, error_class, "disconnected", ev->error.disconnected != 0);	
				}
				break;
				
			case V3_EVENT_USER_TALK_START:
				{
					// PCM data.
					jobject pcm = get_object(env, eventdata, event_class, "pcm", "Lcom/jtxdriggers/android/ventriloid/VentriloEventData$_pcm;");
					jclass  pcm_class = get_class(env, pcm);
					set_int  (env, pcm, pcm_class, "rate", ev->pcm.rate);
					set_short(env, pcm, pcm_class, "send_type", ev->pcm.send_type);
					
					// User ID.
					jobject user = get_object(env, eventdata, event_class, "user", "Lcom/jtxdriggers/android/ventriloid/VentriloEventData$_user;");
					jclass  user_class = get_class(env, user);
					set_short(env, user, user_class, "id", ev->user.id);
				}
				break;
				
			case V3_EVENT_CHAT_MESSAGE:
				{
					// User ID.
					jobject user = get_object(env, eventdata, event_class, "user", "Lcom/jtxdriggers/android/ventriloid/VentriloEventData$_user;");
					jclass  user_class = get_class(env, user);
					set_short(env, user,user_class, "id", ev->user.id);
					
					// Chat message.
					jobject data = get_object(env, eventdata, event_class, "data", "Lcom/jtxdriggers/android/ventriloid/VentriloEventData$_data;");
					jclass  data_class = get_class(env, data);
					set_byte_array(env, data, data_class, "chatmessage", ev->data->chatmessage);
				}
				break;
				
			case V3_EVENT_USERLIST_REMOVE:
				{
					// Account ID.
					jobject data = get_object(env, eventdata, event_class, "data", "Lcom/jtxdriggers/android/ventriloid/VentriloEventData$_data;");
					jclass  data_class = get_class(env, data);
					jobject account = get_object(env, data, data_class, "account", "Lcom/jtxdriggers/android/ventriloid/VentriloEventData$_data$_account;");
					jclass  account_class = get_class(env, account);
					set_short(env, account, account_class, "id", ev->account.id);
				}
				break;
			
			case V3_EVENT_USERLIST_CHANGE_OWNER:
				{
					// Account IDs.
					jobject data = get_object(env, eventdata, event_class, "data", "Lcom/jtxdriggers/android/ventriloid/VentriloEventData$_data;");
					jclass  data_class = get_class(env, data);
					jobject account = get_object(env, data, data_class, "account", "Lcom/jtxdriggers/android/ventriloid/VentriloEventData$_data$_account;");
					jclass  account_class = get_class(env, account);
					set_short(env, account, account_class, "id", ev->account.id);
					set_short(env, account, account_class, "id2", ev->account.id2);
				}
				break;
			case V3_EVENT_USER_PAGE:
				{
					// User ID.
					jobject user = get_object(env, eventdata, event_class, "user", "Lcom/jtxdriggers/android/ventriloid/VentriloEventData$_user;");
					jclass  user_class = get_class(env, user);
					set_short(env, user, user_class, "id", ev->user.id);
				}
				break;
			case V3_EVENT_SERVER_PROPERTY_UPDATED:
				{
					jobject srvprop = get_object(env, eventdata, event_class, "serverproperty", "Lcom/jtxdriggers/android/ventriloid/VentriloEventData$_serverproperty;");
					jclass srvprop_class = get_class(env, srvprop);
					set_short(env, srvprop, srvprop_class, "property", ev->serverproperty.property);
					set_byte(env, srvprop, srvprop_class, "value", ev->serverproperty.value);
				}
				break;
		}
		v3_free_event(ev);
	}
}
Beispiel #26
0
static SLVAL
sl_class_name(sl_vm_t* vm, SLVAL self)
{
    return sl_id_to_string(vm, get_class(vm, self)->name);
}
Beispiel #27
0
/* Report an exception back to the java side.
 */
void report_exception(JNIEnv *jnienv, const char *text, int err,
		      unsigned long expect_mask)
{
	jstring textString;
	jclass dbexcept;
	jclass javaexcept;
	jmethodID constructId;
	jthrowable obj;

	textString = NULL;
	dbexcept = NULL;
	javaexcept = NULL;
	constructId = NULL;
	obj = NULL;

	switch (err) {
	/* DB_JAVA_CALLBACK is returned by dbji_call_append_recno()
	 * (the append_recno callback) when the Java version of the
	 * callback has thrown an exception, and we want to pass the
	 * exception on.  The exception has already been thrown, we
	 * don't want to throw a new one.
	 */
	case DB_JAVA_CALLBACK:
		break;
	case ENOMEM:
		dbexcept = get_class(jnienv, name_DB_MEMORY_EX);
		break;
	case ENOENT:
		/* In this case there is a corresponding standard java
		 * exception type that we'll use.  First we make sure
		 * that the calling function expected this kind of error,
		 * if not we give an 'internal error' DbException, since
		 * we must not throw an exception type that isn't
		 * declared in the signature.
		 *
		 * We'll make this a little more general if/when we add
		 * more java standard exceptions.
		 */
		if ((expect_mask & EXCEPTION_FILE_NOT_FOUND) == 0) {
			char errstr[1024];

			strncpy(errstr, "internal error: unexpected errno: ",
				sizeof(errstr));
			strncat(errstr, text, sizeof(errstr));
			textString = get_java_string(jnienv, errstr);
			dbexcept = get_class(jnienv, name_DB_EXCEPTION);
		}
		else {
			javaexcept =
			  (*jnienv)->FindClass(jnienv, "java/io/FileNotFoundException");
		}
		break;
	case DB_RUNRECOVERY:
		dbexcept = get_class(jnienv, name_DB_RUNRECOVERY_EX);
		break;
	case DB_LOCK_DEADLOCK:
		dbexcept = get_class(jnienv, name_DB_DEADLOCK_EX);
		break;
	default:
		dbexcept = get_class(jnienv, name_DB_EXCEPTION);
		break;
	}
	if (dbexcept != NULL) {
		if (textString == NULL)
			textString = get_java_string(jnienv, text);
		constructId = (*jnienv)->GetMethodID(jnienv, dbexcept,
						     "<init>",
						     "(Ljava/lang/String;I)V");
		obj = (jthrowable)(*jnienv)->NewObject(jnienv, dbexcept,
						       constructId, textString,
						       err);
		(*jnienv)->Throw(jnienv, obj);
	}
	else if (javaexcept != NULL) {
		javaexcept =
			(*jnienv)->FindClass(jnienv, "java/io/FileNotFoundException");
		(*jnienv)->ThrowNew(jnienv, javaexcept, text);
	}
}
Beispiel #28
0
static SLVAL
sl_class_in(sl_vm_t* vm, SLVAL self)
{
    return get_class(vm, self)->in;
}
Beispiel #29
0
vector<action*> * entity::get_actions() {

    return action::defs_for(get_class()->actions);
}
int diff_can_type( hid_t       f_tid1, /* file data type */
                   hid_t       f_tid2, /* file data type */
                   int         rank1,
                   int         rank2,
                   hsize_t     *dims1,
                   hsize_t     *dims2,
                   hsize_t     *maxdim1,
                   hsize_t     *maxdim2,
                   const char  *obj1_name,
                   const char  *obj2_name,
                   diff_opt_t  *options )
{


 H5T_class_t  tclass1;
 H5T_class_t  tclass2;
 int          maxdim_diff=0;          /* maximum dimensions are different */
 int          dim_diff=0;             /* current dimensions are different */
 int          i;

/*-------------------------------------------------------------------------
 * check for the same class
 *-------------------------------------------------------------------------
 */

 if ((tclass1=H5Tget_class(f_tid1))<0)
  return -1;

 if ((tclass2=H5Tget_class(f_tid2))<0)
  return -1;

 if ( tclass1 != tclass2 )
 {
  if (options->m_verbose && obj1_name) {
   printf("Comparison not possible: <%s> is of class %s and <%s> is of class %s\n",
    obj1_name, get_class(tclass1),
    obj2_name, get_class(tclass2) );
  }
  return 0;
 }

/*-------------------------------------------------------------------------
 * check for non supported classes
 *-------------------------------------------------------------------------
 */

 assert(tclass1==tclass2);
 switch (tclass1)
 {
 case H5T_INTEGER:
 case H5T_FLOAT:
 case H5T_COMPOUND:
 case H5T_STRING:
 case H5T_ARRAY:
 case H5T_BITFIELD:
 case H5T_OPAQUE:
 case H5T_ENUM:
 case H5T_VLEN:
 case H5T_REFERENCE:

  break;

 default: /*H5T_TIME */
  if (options->m_verbose && obj1_name )
   printf("Comparison not supported: <%s> and <%s> are of class %s\n",
    obj1_name,obj2_name,get_class(tclass2) );
  return 0;
 }

/*-------------------------------------------------------------------------
 * check for equal file datatype; warning only
 *-------------------------------------------------------------------------
 */

 if ( (H5Tequal(f_tid1, f_tid2)==0) && options->m_verbose && obj1_name)
 {
  printf("Warning: different storage datatype\n");
  printf("<%s> has file datatype ", obj1_name);
  print_type(f_tid1);
  printf("\n");
  printf("<%s> has file datatype ", obj2_name);
  print_type(f_tid2);
  printf("\n");
 }

/*-------------------------------------------------------------------------
 * check for the same rank
 *-------------------------------------------------------------------------
 */

 if ( rank1 != rank2 )
 {
  if (options->m_verbose && obj1_name) {
   printf("Comparison not supported: <%s> has rank %d, dimensions ", obj1_name, rank1);
   print_dimensions(rank1,dims1);
   printf(", max dimensions ");
   print_dimensions(rank1,maxdim1);
   printf("\n" );
   printf("<%s> has rank %d, dimensions ", obj2_name, rank2);
   print_dimensions(rank2,dims2);
   printf(", max dimensions ");
   print_dimensions(rank2,maxdim2);
  }
  return 0;
 }

/*-------------------------------------------------------------------------
 * check for different dimensions
 *-------------------------------------------------------------------------
 */

 assert(rank1==rank2);
 for ( i=0; i<rank1; i++)
 {
  if (maxdim1 && maxdim2)
  {
   if ( maxdim1[i] != maxdim2[i] )
    maxdim_diff=1;
  }
  if ( dims1[i] != dims2[i] )
   dim_diff=1;
 }

/*-------------------------------------------------------------------------
 * current dimensions
 *-------------------------------------------------------------------------
 */

 if (dim_diff==1)
 {
  if (options->m_verbose && obj1_name) {
   printf("Comparison not supported: <%s> has rank %d, dimensions ", obj1_name, rank1);
   print_dimensions(rank1,dims1);
   if (maxdim1 && maxdim2) {
    printf(", max dimensions ");
    print_dimensions(rank1,maxdim1);
    printf("\n" );
    printf("<%s> has rank %d, dimensions ", obj2_name, rank2);
    print_dimensions(rank2,dims2);
    printf(", max dimensions ");
    print_dimensions(rank2,maxdim2);
   }
  }
  return 0;
 }

/*-------------------------------------------------------------------------
 * maximum dimensions; just give a warning
 *-------------------------------------------------------------------------
 */
 if (maxdim1 && maxdim2 && maxdim_diff==1 && obj1_name )
 {
  if (options->m_verbose) {
   printf( "Warning: different maximum dimensions\n");
   printf("<%s> has max dimensions ", obj1_name);
   print_dimensions(rank1,maxdim1);
   printf("\n");
   printf("<%s> has max dimensions ", obj2_name);
   print_dimensions(rank2,maxdim2);
   printf("\n");
  }
 }

 return 1;
}