Exemplo n.º 1
0
void test_token_parse__no_comment(void) {
    token tk = token_parse("\"not # a comment\" \"foo\" bar");
    ass(str_eq(token_str_value(tk), "not # a comment"));

    token tk2 = token_parse(token_rest(tk));
    ass(str_eq(token_str_value(tk2), "foo"));
}
Exemplo n.º 2
0
int main(void)
{
    int exception = 0;

    int i = init((CELL *)calloc(1024, 1), 256);
    if (i != 0) {
        printf("Error in run() tests: init with valid parameters failed\n");
        exit(1);
    }

    start_ass(52);
    ass(O_LITERALI); ilit(37);
    ass(O_HALT);

    assert(single_step() == -259);
    CELL ret = run();

    printf("Return value should be 37 and is %"PRId32"\n", ret);
    if (ret != 37) {
        printf("Error in run() tests: incorrect return value from run\n");
        exit(1);
    }

    printf("EP should now be 56\n");
    if (EP != 60) {
        printf("Error in run() tests: EP = %"PRIu32"\n", EP);
        exit(1);
    }

    assert(exception == 0);
    printf("run() tests ran OK\n");
    return 0;
}
Exemplo n.º 3
0
int main(void)
{
    init((CELL *)malloc(16384), 4096);

    start_ass(EP);
    plit(test); ass(O_LINK); ass(O_ZERO); ass(O_HALT);

    assert(single_step() == -259);   // load first instruction word
    CELL res = run();
    if (res != 0) {
        printf("Error in LINK tests: test aborted with return code %"PRId32"\n", res);
        exit(1);
    }

    printf("Top of stack is %d; should be %d\n", LOAD_CELL(SP), 37);
    show_data_stack();
    if (LOAD_CELL(SP) != 37) {
        printf("Error in LINK tests: incorrect value on top of stack\n");
        exit(1);
    }

    assert(exception == 0);
    printf("LINK tests ran OK\n");
    return 0;
}
Exemplo n.º 4
0
void test_token_parse__comment(void) {
    token tk = token_parse("# abc def\nfoo #ghi jkl \n bar");
    ass(str_eq(token_symbol_value(tk), "foo"));

    token tk2 = token_parse(token_rest(tk));
    ass(str_eq(token_symbol_value(tk2), "bar"));
    ass(str_eq(token_rest(tk2), ""));
}
Exemplo n.º 5
0
void test_token_parse__empty(void) {
    token tk = token_parse("\n \t \r  \n\r");
    ass(token_is_empty(tk));

    token tk2 = token_parse("\n \t foo \n \r\t");
    ass(str_eq(token_symbol_value(tk2), "foo"));

    token tk3 = token_parse(token_rest(tk2));
    ass(token_is_empty(tk3));
}
Exemplo n.º 6
0
void Assembler::assemblyFunction(Core::FunType::PtrType fun,
    Core::Environment* env) {
  if (fun->body == NULL) return;

  std::ostringstream ss;

  Core::AbstractScope::PtrType global_scope(new Core::GlobalScope(env));

  Core::BlockScope::PtrType function_scope(new Core::BlockScope(global_scope));
  for (int i = 0; i < fun->args.size(); i++) {
    function_scope->define(fun->idents[i], fun->args[i]->toLValue());
  }

  Core::BlockScope::PtrType body_scope(new Core::BlockScope(function_scope));



  std::cout << "; " << fun->name << std::endl;
  std::cout << ".method public static " << functionSignature(fun) << std::endl;

  StmtAssembler ass(body_scope, env, ss);
  fun->body->sblock_->accept(&ass);

  std::cout << ".limit stack " << ass.stackLimit << std::endl;
  std::cout << ".limit locals " << global_scope->maxIx() << std::endl;
  std::cout << ss.str();

  if (fun->ret_type->getType() == Core::VOID)
    std::cout << "  return" << std::endl;

  std::cout << ".end method" << std::endl << std::endl;
};
Exemplo n.º 7
0
void Scope::sendMsg(const QString &sender, const QString &msg)
{
    for (const auto &client : clients) client->sendMsg(name, sender, msg);
    try {
        std::unique_ptr<CAS::AbstractArithmetic> result = parser->parse(msg.toStdString());
        QString resultString = QString::fromStdString(result->eval(scope_info)->toString());
        if (result->type() == CAS::AbstractArithmetic::ASSIGNMENT) {
            CAS::Assignment *ass(static_cast<CAS::Assignment*>(result.get()));
            if (ass->getFirstOp()->type() == CAS::AbstractArithmetic::VARIABLE) {
                scope_info.variables[ass->getFirstOp()->toString()] =  std::shared_ptr<CAS::AbstractArithmetic>(ass->getSecondOp()->copy());
                for (const auto &client : clients)
                        client->newVariable(name, QString::fromStdString(ass->getFirstOp()->toString()), QString::fromStdString(ass->getSecondOp()->toString()));
                emit output("NewVariable(" + name + ", " + QString::fromStdString(ass->getFirstOp()->toString()) + ", " + QString::fromStdString(ass->getSecondOp()->toString()) + ")");
                resultString = QString::fromStdString(ass->getSecondOp()->eval(scope_info)->toString());
            } else if (ass->getFirstOp()->type() == CAS::AbstractArithmetic::FUNCTION) {
                const CAS::Function *func = static_cast<const CAS::Function*>(ass->getFirstOp().get());
                std::vector<std::string> argStrings;
                for (const auto &arg : func->getOperands()) argStrings.emplace_back(arg->toString());
                scope_info.functions[std::make_pair(func->getIdentifier(), argStrings.size())] = std::make_pair(argStrings, ass->getSecondOp()->copy());
                QStringList argQStrings;
                for (const auto &arg : argStrings) argQStrings.append(QString::fromStdString(arg));
                for (const auto &client : clients)
                        client->newFunction(name, QString::fromStdString(func->getIdentifier()), argQStrings, QString::fromStdString(ass->getSecondOp()->toString()));
                emit output("NewFunction(" + name + ", " + QString::fromStdString(func->getIdentifier()) + ", \"" + argQStrings.join(",") + "\", " +  QString::fromStdString(ass->getSecondOp()->toString()) + ")");
                resultString = QString::fromStdString(ass->getSecondOp()->eval(scope_info)->toString());
            }
        }
        for (const auto &client : clients) client->sendMsg(name, "Jarvis", resultString);
    } catch (const char *) {
        for (const auto &client : clients) client->sendMsg(name, "Jarvis", "error bro");
    }
}
Exemplo n.º 8
0
static UINT32 sbc_calc_bitrate_from_bitpool( UINT32 bitpool, UINT8 nrof_subbands, UINT8 nrof_blocks, UINT8 channel_mode, UINT32 fs, UINT32 *frame_length )
{   
   UINT8 nrof_channels, join;
   UINT32 frame_length_t, bitrate;

   nrof_channels = ( channel_mode==SBC_CM_MONO )? 1: 2;
   join = ( channel_mode==SBC_CM_JOINT_STEREO)? 1: 0;

   frame_length_t = 4 + ( 4 * nrof_subbands * nrof_channels ) / 8;
   if( channel_mode==SBC_CM_MONO || channel_mode==SBC_CM_DUAL_CHANNEL )
      frame_length_t += (nrof_blocks * nrof_channels * bitpool) / 8;
   else if( channel_mode==SBC_CM_STEREO || channel_mode==SBC_CM_JOINT_STEREO )
      frame_length_t += ( join * nrof_subbands + nrof_blocks * bitpool ) / 8;
   else
   {
   ass(1);
    //  EXT_ASSERT( 0, channel_mode, 0, 0 );
      return( 0 );
   }

   bitrate = ( 8 * frame_length_t * fs ) / ( nrof_subbands * nrof_blocks );
   bitrate = (bitrate + 999) / 1000; // in kb/s with rounding

   if( frame_length!=NULL )
      *frame_length = frame_length_t;
   return( bitrate );
}
Exemplo n.º 9
0
//#####################################################################
// Function assembly_loaded
//#####################################################################
void assembly_loaded(MonoAssembly* assembly, gpointer user_data) {
    assert(assembly != NULL);
    Assembly ass(assembly);
    std::vector<Assembly>* assemblies = (std::vector<Assembly>*)user_data;
    assemblies->push_back(ass);
    printf("Assembly loaded: %s\n", ass.fullname().c_str());
}
Exemplo n.º 10
0
 typename quan::where_<
    quan::meta::and_<
       is_fun_sequence<Seq>,
       quan::meta::bool_<size_seq<Seq>::value ==3>
    >,
    vector3 &
 >::type operator=(Seq const & in)
 {    
    sequence_assign_op<2,operator_equals> ass;
    ass(*this,in);
    return *this;
 }
Exemplo n.º 11
0
int main(void) {
	epollfd *lol = new epollfd();
	async ass(lol, 0, EPOLLIN, test2);
	lol->cycle();
	lol->subscribe(1, EPOLLIN, test);
	while (!ass.isDone()) {
		lol->cycle();
	}
	if (ass.isDone()) {
		printf("Done");
	}
	return 0;
}
Exemplo n.º 12
0
//============================ A2DP Service ===============================
void sbc_PutData( SSHdl *hdl, UINT8 *buf, UINT32 length )
{
   INT32 cnt;
   INT32 length_t = (INT32)length;
   
// MCI_TRACE (TSTDOUT | MCI_AUDIO_TRC,0, " Entry sbc_PutData!! length=%d  ", length);


   ass( hdl == NULL );
   if( !is_SSHdl_valid( hdl ) )
      return;

    
   cnt = SSHdl_GetFreeSpace( hdl );
   if( cnt<length )
   { // Buffer overflow
     MCI_TRACE (TSTDOUT | MCI_AUDIO_TRC,0, " Buffer overflow!!  length_t:%d,-cnt:%d,hdl->wait:%d",length_t, -cnt, hdl->wait);
/*
    hdl->overflow        = TRUE;
    hdl->overflow_size = length;
    ass( length >= SBC_OVERFLOW_SIZE );
     memcpy( hdl->overflow_buf, buf, length );
   */
      return;
      // ass(0);
   }

   while( length>0 )
   {
      UINT8 *dest;
      SSHdl_GetWriteBuffer( hdl, &dest, &cnt );
      if( cnt > length )
         cnt = length;
      memcpy( dest, buf, cnt );
      SSHdl_ShiftWritePointer( hdl, cnt );
      buf += cnt;
      length -= cnt;
   }

   cnt = SSHdl_GetDataCount( hdl );
//   MCI_TRACE ( TSTDOUT | MCI_AUDIO_TRC,0, " Entry sbc_PutData!! length_t:%d,cnt:%d,hdl->wait:%d",length_t, cnt, hdl->wait);

   if( hdl->wait == FALSE && cnt >= hdl->rb_threshold )
   {
  
      hdl->wait = TRUE;
      hdl->callback( 0 );
   }


}
Exemplo n.º 13
0
void sbc_Flush( SSHdl *hdl )
{
   INT32 cnt;
    MCI_TRACE (TSTDOUT | MCI_AUDIO_TRC,0,"dafRTPSS_Flush ");
   ass( hdl == NULL );
   if( !is_SSHdl_valid( hdl ) )
      return;
   
   cnt = SSHdl_GetDataCount( hdl );

  MCI_TRACE (TSTDOUT | MCI_AUDIO_TRC,0, "-cnt:%d,hdl->wait:%d", cnt, hdl->wait);


   if( cnt > 0 )
      hdl->callback( (void *)2 );
}
Exemplo n.º 14
0
void test_token_parse__index(void) {
    token tk = token_parse(" \n [0] [12] bar");
    ass(token_is_index(tk));
    ass(token_index_value(tk) == 0);
    ass(str_eq(token_rest(tk), " [12] bar"));

    token tk2 = token_parse(token_rest(tk));
    ass(token_is_index(tk2));
    ass(token_index_value(tk2) == 12);
    ass(str_eq(token_rest(tk2), " bar"));
}
Exemplo n.º 15
0
void test_token_parse__str(void) {
    token tk = token_parse("\n \"hello world!\" \n \" foobar \" 3 4");
    ass(token_is_str(tk));
    ass(str_eq(token_str_value(tk), "hello world!"));
    ass(str_eq(token_rest(tk), " \n \" foobar \" 3 4"));

    token tk2 = token_parse(token_rest(tk));
    ass(token_is_str(tk2));
    ass(str_eq(token_str_value(tk2), " foobar "));
    ass(str_eq(token_rest(tk2), " 3 4"));
}
Exemplo n.º 16
0
void test_token_parse__float(void) {
    token tk = token_parse("3.14 -2.72 foo bar");
    ass(token_is_float(tk));
    ass(token_float_value(tk) == 3.14);
    ass(str_eq(token_rest(tk), " -2.72 foo bar"));

    token tk2 = token_parse(token_rest(tk));
    ass(token_is_float(tk2));
    ass(token_float_value(tk2) == -2.72);
    ass(str_eq(token_rest(tk2), " foo bar"));
}
Exemplo n.º 17
0
void test_token_parse__symbol(void) {
    //TODO foo#comment
    token tk = token_parse("\nfoo   bar\nspam\teggs");
    ass(token_is_symbol(tk));
    ass(str_eq(token_symbol_value(tk), "foo"));
    ass(str_eq(token_rest(tk), "   bar\nspam\teggs"));
    
    token tk2 = token_parse(token_rest(tk));
    ass(token_is_symbol(tk2));
    ass(str_eq(token_symbol_value(tk2), "bar"));
    ass(str_eq(token_rest(tk2), "\nspam\teggs"));
}
Exemplo n.º 18
0
void test_token_parse__def(void) {
    token tk = token_parse(" foo: bar # abc \nspam: eggs");
    ass(token_is_def(tk));
    ass(str_eq(token_def_value(tk), "foo"));

    token tk2 = token_parse(token_rest(tk));
    ass(token_is_symbol(tk2));
    ass(str_eq(token_symbol_value(tk2), "bar"));

    token tk3 = token_parse(token_rest(tk2));
    ass(token_is_def(tk3));
    ass(str_eq(token_def_value(tk3), "spam"));
}
Exemplo n.º 19
0
Arquivo: chess.cpp Projeto: ponyatov/L
void DrawBoard(void) {
	// blit board
	int x,y; SDL_Surface* f;
	for (char i = 0; i < sizeof(BOARD); i++) {
		// chess col/row
		x=i%8; y=i/8;
		// get cell draw offset in pixels
		rect.x=x*rect.w+rect.w/2; rect.y=y*rect.h+rect.h/2;
		// blit black/white empty cell
		if ((i+y)%2) f=FIG[BC]; else f=FIG[WC];
		SDL_BlitSurface(f, NULL, scr, &rect);
		// blit figure if cell not empty
		if (BOARD[i]!=ZZ) SDL_BlitSurface(FIG[BOARD[i]], NULL, scr, &rect);
	}
	// apply texts
	ass(0,0,msg,scr);
	// Update Screen
	SDL_Flip(scr);
}
Exemplo n.º 20
0
int main(void)
{
    int exception = 0;

    init((CELL *)calloc(1024, 1), 256);

    start_ass(EP);
    ass(O_ZERO); ass(O_ONE); ass(O_MONE); ass(O_CELL);
    ass(O_MCELL); ass(O_ROT); ass(O_PLUS); ass(O_PLUS);
    ass(O_MINUS); ass(O_PLUS1); ass(O_MINUS1); ass(O_SWAP);
    ass(O_PLUSCELL); ass(O_MINUSCELL); ass(O_MONE); ass(O_CELL);
    ass(O_STAR); ass(O_SWAPMINUS); ass(O_SLASHMOD); ass(O_SLASH);
    ass(O_MONE); ass(O_MOD); ass(O_PLUS1); ass(O_CELLS);
    ass(O_SLASH2); ass(O_DROP); ass(O_CELL); ass(O_NEGATE);
    ass(O_ABS); ass(O_ABS); ass(O_ONE); ass(O_MAX);
    ass(O_MCELL); ass(O_MIN); ass(O_LITERALI); ilit(3);
    ass(O_SSLASHREM); ass(O_DROP); ass(O_LITERALI); ilit(-2);
    ass(O_USLASHMOD);

    assert(single_step() == -259);   // load first instruction word

    for (size_t i = 0; i < sizeof(correct) / sizeof(correct[0]); i++) {
        show_data_stack();
        printf("Correct stack: %s\n\n", correct[i - i / 5]);
        if (strcmp(correct[i - i / 5], val_data_stack())) {
            printf("Error in arithmetic tests: EP = %"PRIu32"\n", EP);
            exit(1);
        }
        single_step();
        printf("I = %s\n", disass(I));
    }

    assert(exception == 0);
    printf("Arithmetic tests ran OK\n");
    return 0;
}
Exemplo n.º 21
0
static UINT32 sbc_config(bt_a2dp_sbc_codec_cap_struct *sbc_config_data)
{
//   UINT8 bitpool_t;
   UINT32 bit_rate;
   UINT32 frame_length_t=0;
   UINT32 headerstream;;
   if( sbc_config_data!=NULL )
   {
      UINT8 header_data = 0;
      
      if( sbc_config_data->block_len==1 )
      {
         sbc.frame_state.blocks = 16;
         header_data = SBC_NB_16<<4;
      }
      else if( sbc_config_data->block_len==2 )
      {
         sbc.frame_state.blocks = 12;
         header_data = SBC_NB_12<<4;
      }
      else if( sbc_config_data->block_len==4 )
      {
         sbc.frame_state.blocks = 8;
         header_data = SBC_NB_8<<4;
      }
      else if( sbc_config_data->block_len==8 )
      {
         sbc.frame_state.blocks = 4;
         header_data = SBC_NB_4<<4;
      }
      else
      {
          ass(1);
    //     EXT_ASSERT(0, sbc_config_data->block_len, 0, 0);
      }

      if( sbc_config_data->subband_num==1 )
      {
         sbc.frame_state.subbands = 8;
         header_data |= SBC_SB_8;
      }
      else if( sbc_config_data->subband_num==2 )
      {
         sbc.frame_state.subbands = 4;
         header_data |= SBC_SB_4;
      }
      else
      {
          ass(1);
   //      EXT_ASSERT(0, sbc_config_data->subband_num, 0, 0);
      }

      if( sbc_config_data->alloc_method==1 )
      {
         sbc.frame_state.allocation_method = SBC_AM_LOUDNESS;
         header_data |= SBC_AM_LOUDNESS<<1;
      }
      else if( sbc_config_data->alloc_method==2 )
      {
         sbc.frame_state.allocation_method = SBC_AM_SNR;
         header_data |= SBC_AM_SNR<<1;
      }
      else
      {
          ass(1);
     //    EXT_ASSERT(0, sbc_config_data->alloc_method, 0, 0);
      }

      if( sbc_config_data->sample_rate==1 )
      {
         sbc.frame_state.sampling_frequency = 48000;
         header_data |= SBC_FS_48<<6;
      }
      else if( sbc_config_data->sample_rate==2 )
      {
         sbc.frame_state.sampling_frequency = 44100;
         header_data |= SBC_FS_44<<6;
      }
      else if( sbc_config_data->sample_rate==4 )
      {
         sbc.frame_state.sampling_frequency = 32000;
         header_data |= SBC_FS_32<<6;
      }
      else if( sbc_config_data->sample_rate==8 )
      {
         sbc.frame_state.sampling_frequency = 16000;
         header_data |= SBC_FS_16<<6;
      }
      else
      {
          ass(1);
   //      EXT_ASSERT(0, sbc_config_data->sample_rate, 0, 0);
      }

      if( sbc_config_data->channel_mode==1 )
      {
         sbc.frame_state.channel_mode = SBC_CM_JOINT_STEREO;
         header_data |= SBC_CM_JOINT_STEREO<<2;
      }
      else if( sbc_config_data->channel_mode==2 )
      {
         sbc.frame_state.channel_mode = SBC_CM_STEREO;
         header_data |= SBC_CM_STEREO<<2;
      }
      else if( sbc_config_data->channel_mode==4 )
      {
         sbc.frame_state.channel_mode = SBC_CM_DUAL_CHANNEL;
         header_data |= SBC_CM_DUAL_CHANNEL<<2;
      }
      else if( sbc_config_data->channel_mode==8 )
      {
         sbc.frame_state.channel_mode = SBC_CM_MONO;
         header_data |= SBC_CM_MONO<<2;
      }
      else
      {
      ass(1);
  //       EXT_ASSERT(0, sbc_config_data->channel_mode, 0, 0);
      }

      if( sbc.frame_state.channel_mode==SBC_CM_MONO )
         sbc.frame_state.channels = 1;
      else
         sbc.frame_state.channels = 2;

      sbc.frame_state.sbc_frame_header_data = header_data;

      sbc.max_bit_pool = sbc_config_data->max_bit_pool;
      sbc.min_bit_pool = sbc_config_data->min_bit_pool;
   }



 // MCI_TRACE ( TSTDOUT | MCI_AUDIO_TRC,0,"sbc_config bit_rate=%d",bit_rate);

  
    
   	headerstream =  (SBC_SYNCWORD<<24| sbc.frame_state.sbc_frame_header_data<<16|SBC_BIT_POOL<<8|0);

        memcpy(&sbc.config_header, &headerstream, 4);
	
	 MCI_TRACE ( TSTDOUT | MCI_AUDIO_TRC,0,"sbc.config_header=%x ,  sampling_frequency = %d  ",sbc.config_header,  sbc.frame_state.sampling_frequency  );
	 
     bit_rate =sbc_calc_bitrate_from_bitpool( SBC_BIT_POOL, sbc.frame_state.subbands, sbc.frame_state.blocks, sbc.frame_state.channel_mode, sbc.frame_state.sampling_frequency, &frame_length_t );


   sbc.frame_state.bitpool = SBC_BIT_POOL;
   sbc.current_frame_size = frame_length_t;

/*
   SBC_TRACE( TRACE_INFO, L1SBC_CONFIG_REPORT, 
      sbc.frame_state.sampling_frequency, sbc.frame_state.channel_mode, 
      sbc.min_bit_pool, sbc.frame_state.bitpool, sbc.max_bit_pool );
  */ 
//kal_prompt_trace(0, "sbc_config bit_rate=%d",bit_rate);

   return( bit_rate );
}
Exemplo n.º 22
0
UINT32 sbc_GetData( SSHdl *hdl, UINT8 *buf, UINT32 buf_len, UINT32 *sample_cnt )
{
	UINT8 uSbcHeaderWord[4];
	UINT32 headerstream,skip_num=0;
	sbcHeaderStruct stSbcHeader;
	UINT32 get_length=0,frame_length,offset =0;
	UINT8 media_head=0;
	UINT16 nframe=0;
	sbc_struct*ihdl = (sbc_struct *)hdl;
	ass( hdl == NULL );
	
	if( SSHdl_GetDataCount( hdl ) == 0 )
		return 0;
//	 MCI_TRACE ( TSTDOUT | MCI_AUDIO_TRC,0,"sbc_GetData is called,ihdl->current_frame_size=%d",ihdl->current_frame_size);
	     frame_length=ihdl->current_frame_size;
           nframe = (UINT16)   buf_len/frame_length;	
		   
	do
	{
	
	     if( SSHdl_GetDataCount( hdl ) >= 4 )
	     	{
			SSHdl_SniffNBytes( hdl, 0, 4, uSbcHeaderWord );
	
		     headerstream = GET_UINT32( uSbcHeaderWord );
		     memcpy(&stSbcHeader, &headerstream, 4);

			
			if((stSbcHeader.Sync==ihdl->config_header.Sync)&&
				(stSbcHeader.Subbands==ihdl->config_header.Subbands)&&
			//	(stSbcHeader.Sample_rate==ihdl->config_header.Sample_rate)&&
				(stSbcHeader.ChannelMode==ihdl->config_header.ChannelMode)&&
				(stSbcHeader.Blocks==ihdl->config_header.Blocks)&&
				(stSbcHeader.Bitpool==ihdl->config_header.Bitpool)&&
				(stSbcHeader.Allocation_method==ihdl->config_header.Allocation_method)
				)
			{

				get_length=nframe*(frame_length);
				media_head=nframe;
				if(SSHdl_GetDataCount( hdl ) >(get_length+4))
				{
					offset=get_length;
				}
				else 
				{	

					get_length=(nframe-1)*(frame_length);
					media_head=(nframe-1);

					
					if(SSHdl_GetDataCount( hdl ) >(get_length+4))
						offset=get_length;
					else
					{
						MCI_TRACE ( TSTDOUT | MCI_AUDIO_TRC,0,"sbc_GetData rb no enough data");
						break;
					}
				}

	
				break;
			}
			else
			{
				MCI_TRACE ( TSTDOUT | MCI_AUDIO_TRC,0,"skip 1 byte");

				SSHdl_ShiftReadPointer( hdl, 1 );//skip 1 byte 
				if((++skip_num)>frame_length)
					{
						skip_num=0;
						MCI_TRACE ( TSTDOUT | MCI_AUDIO_TRC,0,"***skip_num>frame_length");
                                        break;
					//	ass(1);
					}

               
			}
	  
	     	}
             else
             	{
                 MCI_TRACE ( TSTDOUT | MCI_AUDIO_TRC,0,"rb number <4bytes");
                    break;
		 }
		 
	}while(1);

     skip_num=0;
	if(offset )
	{
		UINT8 flag=0;
		do
		{
			SSHdl_SniffNBytes( hdl, offset, 4, uSbcHeaderWord );
			
			headerstream = GET_UINT32( uSbcHeaderWord );
		      memcpy(&stSbcHeader, &headerstream, 4);

			if((stSbcHeader.Sync==ihdl->config_header.Sync)&&
				(stSbcHeader.Subbands==ihdl->config_header.Subbands)&&
			//	(stSbcHeader.Sample_rate==ihdl->config_header.Sample_rate)&&
				(stSbcHeader.ChannelMode==ihdl->config_header.ChannelMode)&&
				(stSbcHeader.Blocks==ihdl->config_header.Blocks)&&
				(stSbcHeader.Bitpool==ihdl->config_header.Bitpool)&&
				(stSbcHeader.Allocation_method==ihdl->config_header.Allocation_method)
				)			
			{
				flag=1;
				break;
			}
			else 
			{
				offset++;
				get_length++;
				MCI_TRACE ( TSTDOUT | MCI_AUDIO_TRC,0,"skip 1 byte next packet");
				if((++skip_num)>frame_length)
					{
						skip_num=0;
						MCI_TRACE ( TSTDOUT | MCI_AUDIO_TRC,0,"***skip 1 byte next packet>frame_length");
						//ass(1);
						break;
					}
			
			}
				
		}while(1);
	//	MCI_TRACE ( TSTDOUT | MCI_AUDIO_TRC,0,"flag=%d",flag);

		if(flag)
		{
                 UINT32 cnt=get_length, cnt2=0;
		   *buf=media_head;
		   buf++;
		   buf_len--;
		   //if(buf_len<cnt)		?????? 
		    while( cnt > 0 )
                  {
                     UINT8 *src;
                     SSHdl_GetReadBuffer( hdl, &src, &cnt2 );
                     if( cnt2 > cnt )
                        cnt2 = cnt;
                     memcpy( buf, src, cnt2 );
                     SSHdl_ShiftReadPointer( hdl, cnt2 );
                     buf += cnt2;
                     cnt -= cnt2;
                  }
	//	    MCI_TRACE ( TSTDOUT | MCI_AUDIO_TRC,0,"sbc_GetData success ~!~!get_length=%d",get_length);	
		    return get_length+1;	
		}
		else
			{

			MCI_TRACE ( TSTDOUT | MCI_AUDIO_TRC,0,"sbc_GetData flag =0!!");	
			return 0;
			}
			
		
	}
	else
	{
		MCI_TRACE ( TSTDOUT | MCI_AUDIO_TRC,0,"sbc rb is null!!");
		return 0;

	}

	
	
}
Exemplo n.º 23
0
void test_token_find_symbol(void) {
    token tk = token_find_symbol("abc # def \n ghi return foo \"bar\"", "return");
    ass(token_is_symbol(tk));
    ass(str_eq(token_symbol_value(tk), "return"));
    ass(str_eq(token_rest(tk), " foo \"bar\""));
}
Exemplo n.º 24
0
int controller::doQOS(demand_t* demand) {

    //lock the vectors so they don't change size
    objs->readLock();
    robots->readLock();

    //create an array of robot pointers
    Robot** r;
    if (robots->size() - used_robots->size() > 0) {
        r = new Robot*[robots->size()];
    } else {
        r = NULL;
    }

    //create an array of object pointers
    Object** o;
    double* dem;
    if (objs->size() > 0) {
        o = new Object*[objs->size()];
        dem = new double[objs->size()];
    } else {
        o = NULL;
        dem = NULL;
    } 

    //add unused robots to the array
    for (int i = 0; i < robots->size(); ++i) {
        bool used = false;

        //make sure the robot[i] has not been commendeered by an admin
        for(int j = 0; j < used_robots->size(); ++j){
            if(robots->at(i) == robots->at(j)){
                used = true;
                break;
            }
        }

        //if it hasn't, add it to the list to give to the qos and lock it
        if(!used){
            r[i] = robots->at(i);
            r[i]->lock();
        }
    }

    //add all the objects to the array
    for (int i = 0; i < objs->size(); ++i) {
        o[i] = objs->at(i);;
        o[i]->lock();
        dem[i] =(*demand)[o[i]->getOID()];
    }

    std::map<Robot*, int>* assign = NULL;
    //set up the qos stuff and wait for it to comput
    if ( r && o && dem ) {
        Qos q(r, robots->size(), o, objs->size(), dem);
        Assignment ass(r, robots->size(), o, objs->size(), dem, &q);
        
        std::cout <<"Start QoS" <<'\n';
        //Display the Qos at start
        q.calcQos();
        assign = ass.calcAssignments();
        q.calcQos();

        // send the assignemnts to the robots
        robo->sendAssignments(assign);
    } else {
        std::cerr << "[controller] skipping QOS this round\n";
    }


    // unlock of the robots
    /*
    for (int i = 0; i < robots->size(); ++i) {
        r[i]->unlock();
    }
    */
    for (int i = 0; i < robots->size(); ++i) {
        bool used = false;

        //make sure the robot[i] has not been commendeered by an admin
        for(int j = 0; j < used_robots->size(); ++j){
            if(robots->at(i) == robots->at(j)){
                used = true;
                break;
            }
        }

        //if it hasn't, unlock it
        if(!used){
            robots->at(i)->unlock();
        }
    }

    //unlock all of the objects
    for (int i = 0; i < objs->size(); ++i) {
        o[i]->unlock();
    }

    //delete all of the arrays
    if (o)
        delete[] o;
    if (r)
        delete[] r;
    if (dem)
        delete[] dem;

    //unlock the vectors
    robots->readUnlock();
    objs->readUnlock();


    return 0;
}
Exemplo n.º 25
0
int main() {
    printf("=============================================\n");

 /* * * * * * * *       
  * str.h tests
  */
    
    char* s = "test string";
    
    // str_new()
    char* str_new_ = str_new(s);
    ass(str_new_ != s, "defferent ptr");
    ass_eq(str_new_, s);
    
    // str_auto()
    char* str_auto_ = str_auto(str_new_);
    ass(str_auto_ != str_new_, "different ptr");
    ass_eq(str_auto_, str_new_);

    // str_cat_new()
    char* str_cat_new_ = str_cat_new(s, " gnirts tset");
    ass(str_cat_new_ != s, "different ptr");
    ass_eq(str_cat_new_, "test string gnirts tset");

    // str_cat_auto()
    char* str_cat_auto_ = str_cat_auto(str_cat_new_, "!!");
    ass(str_cat_auto_ != str_cat_new_, "dif ptr");
    ass_eq(str_cat_auto_, "test string gnirts tset!!");

    // str_sub_new()
    char* str_sub_new_ = str_sub_new(s, 0, 4);
    ass_eq(str_sub_new_, "test");

    // str_sub_auto()
    char* str_sub_auto_ = str_sub_auto(s, 5, 200); // overalocated?
    ass_eq(str_sub_auto_, "string");
    ass_eq(str_sub_auto(s, 5, 5), "");
    ass_eq(str_sub_auto(s, 9, 1), "");

    // str_slice_new()
    char* str_slice_new_ = str_slice_new(s, 0, 4);
    ass_eq(str_slice_new_, "test");
    ass_eq(str_slice_new(s, 0, 0), "test string");
    ass_eq(str_slice_new(s, 5, 0), "string");
    ass_eq(str_slice_new(s,-6, 0), "string");

    // str_slice_auto()  
    ass_eq(str_slice_auto(s,-6,-3), "str");
    ass_eq(str_slice_auto(s,-1,-2), "");
    ass_eq(str_slice_auto(s, 2, 1), "");
    ass_eq(str_slice_auto(s, 5, 200), "string"); // overallocated?

    // str_input_dest()
    // str_input_new()
    // str_input_auto()

    // str_format_dest()  // sprintf
    // str_format_new()  // asprintf
    // str_format_auto()

    // str_len()  // strlen
    
    // str_is_alnum()
    ass(str_is_alnum("abc123"));
    ass(! str_is_alnum("(@^*^&"));

    // str_is_alpha()
    ass(str_is_alpha("abcdEFG"));
    ass(! str_is_alpha("!@#$@#$"));

    // str_from_file_new()
    char* str_from_file_new_ = str_from_file_new("file.test");
    ass_eq(str_from_file_new_, "file.test:test\n");

    // str_eq()
    ass(str_eq("abc", "abc"));
    ass(str_eq("", ""));

    // str_endswith()
    ass(str_endswith(s, "string"));
    ass(str_endswith(s, "ing"));
    ass(str_endswith(s, "test string"));
    //ass(str_endswith(s, "")); //hm...
    //logs(str_slice_auto(s, -1 * strlen(""), 0));
    ass(!str_endswith(s, "swing"));
    ass(!str_endswith(s, " test string"));

    // str_startswith()
    ass(str_startswith(s, "test"));
    ass(str_startswith(s, "test string"));
    ass(str_startswith(s, ""));

}
Exemplo n.º 26
0
int main(void)
{
    init((CELL *)malloc(1024), 256);

    start_ass(EP);
    ass(O_LESS); ass(O_LESS); ass(O_LESS); ass(O_LESS);
    ass(O_GREATER); ass(O_GREATER); ass(O_GREATER); ass(O_GREATER);
    ass(O_EQUAL); ass(O_EQUAL); ass(O_NEQUAL); ass(O_NEQUAL);
    ass(O_LESS0); ass(O_LESS0); ass(O_LESS0); ass(O_GREATER0);
    ass(O_GREATER0); ass(O_GREATER0); ass(O_EQUAL0); ass(O_EQUAL0);
    ass(O_ULESS); ass(O_ULESS); ass(O_ULESS); ass(O_ULESS);
    ass(O_UGREATER); ass(O_UGREATER); ass(O_UGREATER); ass(O_UGREATER);

    assert(single_step() == -259);   // load first instruction word

    stack1();       // set up the stack with four standard pairs to compare
    step(0, 5);     // do the < tests
    stack1();
    step(5, 10);     // do the > tests
    stack2();       // set up the stack with two standard pairs to compare
    step(10, 12);   // do the = tests
    stack2();
    step(12, 15);   // do the <> tests
    stack3();       // set up the stack with three standard values
    step(15, 18);   // do the 0< tests
    stack3();
    step(18, 22);   // do the 0> tests
    SP = S0;  PUSH(237); PUSH(0);	// set up the stack with two values
    step(22, 25);   // do the 0= tests
    stack1();       // set up the stack with four standard pairs to compare
    step(25, 30);   // do the U< tests
    stack1();
    step(30, 35);   // do the U> tests

    assert(exception == 0);
    printf("Comparison tests ran OK\n");
    return 0;
}
Exemplo n.º 27
0
void test_token_find_def(void) {
    token tk = token_find_def("abc def: #ghi jkl: \n foo: bar", "foo");
    ass(token_is_def(tk));
    ass(str_eq(token_def_value(tk), "foo"));
    ass(str_eq(token_rest(tk), " bar"));
}
Exemplo n.º 28
0
void renderScene(void) {
	glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
    glPushMatrix();
                   alas();
    glPopMatrix();
    
    //bianglala
    glPushMatrix();
                   
                   glTranslatef(-20,16,-20);
                   glScalef(3,3,3);
                   glRotatef(135,0,1,0);
                   ada();
                   ass();
                   kaki();
                   glPushMatrix();
                                  glRotatef(qwe,0,0,1);
                                  duduk();
                   glPopMatrix();
                   glColor3f(1.0,1.0,1.0);
   glPopMatrix();
   /////////////////bianglala////////////////////////
        
    //rajawali
    glPushMatrix();
                   
                   glTranslatef(20,17,-20);
                   glScalef(3,3,3);
                   glRotatef(0,1,0,0);
                   glPushMatrix();
                                  if(asd<70){
                                  glTranslatef( 0, asd/10, 0);}
                                  else {glTranslatef(0, fgh/10, 0);}
                                  donat();
                   glPopMatrix();
                   tiang();
                   glColor3f(1.0,1.0,1.0);
   glPopMatrix();
   /////////////rajawali//////////////
   
   //hysteria
   glPushMatrix();
                  
                  glTranslatef(20,13.5,20);
                  glScalef(3,3,3);
                  glPushMatrix();
                  if(ert<60){
                  glTranslatef( 0, ert/10, 0);}
                  else {glTranslatef(0, yui/10, 0);}
                  yangbiru();
                  glPopMatrix();
                  top();
   glPopMatrix();
   //////////hysteria////////////
   
  	
	//Menggambar Halaman
	glColor3f(0, 3, 0);
	glBegin(GL_QUADS);
		glVertex3f(-40.0, 0.1, -40.0);
		glVertex3f(-40.0, 0.1,  40.0);
		glVertex3f( 40.0, 0.1,  40.0);
		glVertex3f( 40.0, 0.1, -40.0);
	glEnd();
	
	
    glutSwapBuffers();
}