Ejemplo n.º 1
0
void Qmax(int n){
	rm.r = 0;
	for (int i = -1000; i < 1000;i=i+1)
	for (int j = -1000; j < 1000; j=j+1){
		ca.mux = i;
		ca.muy = j;
		for (int h = 0; h < 1; h++){
			if (cmp1(qdx(ca), qdy(ca)) && cmp1(qdx(ca), (qzl(ca, Circle[h]) - (Circle[h].r))) && cmp1(qdy(ca), (qzl(ca, Circle[h]) - (Circle[h].r)))){
				int pd=1;
				for (int t = 0;t<n;t++)
				if (cmp2(ca.mux, Circle[t].mux) && cmp2(ca.muy, Circle[t].muy))
					pd = 0;
				if (pd)
				if ((qdx(ca)>rm.r) && !cmp2(qdx(ca),rm.r))
				{  
					rm.mux = i, rm.muy = j; rm.r = qdx(ca);
					
				}
			}
			
		}
		if (n>1)
			Qmax2(n);
		if (n>2)
			Qmax3(n);
	}
	Circle[n].mux = rm.mux;
	Circle[n].muy = rm.muy;
	Circle[n].r = rm.r;
}
Ejemplo n.º 2
0
Archivo: sh_cmp.c Proyecto: jalcim/42sh
int			cmp1(t_linez *linez, t_sh *term, t_linez *hist)
{
	if (!ft_strcmp("env", linez->ep_l))
	{
		if (linez->ep_l[3])
			return (0);
		while (term->env[term->i])
			ft_putendl(term->env[term->i++]);
		return (term->status = 1);
	}
	else if (!ft_strncmp("tchat", linez->ep_l, 5))
		return (tchat(hist, term));
	else if (!ft_strncmp("unset", linez->ep_l, 5) && linez->ep_l[5] != 'e')
	{
		if (linez->ep_l[5] == ' ')
		{
			set_local_var(&(linez->ep_l), 6, term);
			term->status = 1;
		}
		else
			ft_putendl_fd("unset: usage: 'unset var'", 2);
		term->status = 0;
		return (1);
	}
	else
		return (cmp2(linez, term));
}
Ejemplo n.º 3
0
int main(void)
{
	cmp1(NAN, 4);
	cmp2(NAN, NAN);

	assert(a == 0);
	assert(b == 1);
	return 0;
}
Ejemplo n.º 4
0
static void oddEvenMerge(vec<Formula>& fs, int begin, int end) {
    assert(end - begin > 1);
    if (end - begin == 2)
        cmp2(fs,begin);
    else {
        int          mid = (end - begin) / 2;
        vec<Formula> tmp;
        for (int i = 0; i < end - begin; i++)
            tmp.push(fs[begin+i]);
        unriffle(tmp);
        oddEvenMerge(tmp,0,mid);
        oddEvenMerge(tmp,mid,tmp.size());
        riffle(tmp);
        for (int i = 1; i < tmp.size() - 1; i += 2)
            cmp2(tmp,i);
        for (int i = 0; i < tmp.size(); i++)
            fs[i + begin] = tmp[i];
    }
}
Ejemplo n.º 5
0
static void totlizerMerge(vec<Formula>& toMerge, int begin, int end) {
	assert(end - begin > 1);
	if (end - begin == 2)
        cmp2(toMerge,begin);
    else {
		vec<Formula> merged;
		merged.growTo(end-begin,_0_);
		int mid = (end-begin)/2;
		for(int i=0;i<mid;i++) merged[i] = toMerge[begin+i] | toMerge[begin+mid+i];
		for(int i=0;i<mid;i++) 
			for(int j=0;j<mid;j++) 
				merged[i+j+1] |= toMerge[begin+i] & toMerge[begin+mid+j];		
		for(int i=0;i<merged.size();i++) toMerge[begin+i] = merged[i];
    }
}
Ejemplo n.º 6
0
int main()
{
	/////////////////////////////////////////////////////////////////////
	/// Exmaple for use:
	/////////////////////////////////////////////////////////////////////
	std::random_device rd;
	std::mt19937 gen(rd());
	std::uniform_int_distribution<> dis (-100, 100);

	std::vector <int> arr (25);
	std::vector <int> arr1 (25);
	std::vector <int> arr2 (25);

	for(int i = 0 ; i < 25; i++)
	{
		arr  [i] = dis (gen);
		arr1 [i] = arr [i];
		arr2 [i] = arr [i];
	}
	for (int i = 0 ; i < 25 ; i ++)
	{
		std::cout << arr [i] << " ";
	}
	std::cout << std::endl;

	////////////////////////////////////////////////////////////////////
	/// Use Standart Sort
	////////////////////////////////////////////////////////////////////
	std::sort (begin (arr1), end (arr1), cmp2 ());
	for (int i = 0 ; i < 25 ; i ++)
	{
		std::cout << arr1 [i] << " ";
	}
	std::cout << std::endl;

	/////////////////////////////////////////////////////////////////////
	/// Use atdc sort
	/////////////////////////////////////////////////////////////////////
	atdc_sort (std::begin (arr2), std::end (arr2), cmp1 ());
	
	for(int i = 0 ; i < (int)arr2.size () ; i ++)
	{
		std::cout << arr2 [i] << " ";
	}
	std::cout << std::endl;
	return 0;
}
Ejemplo n.º 7
0
void divide(char s[])
{
    int len=strlen(s);
    for(int i=0;i<n;i++)
    {
        if(len==dic[i].len)
        {
            cmp0(s,dic[i]);
        }
        else if(len==dic[i].len-1)
        {
            cmp1(s,dic[i]);
        }
        else if(len==dic[i].len+1)
        {
            cmp2(s,dic[i]);
        }
    }
}
Ejemplo n.º 8
0
int main()
{
	int a = A, b = B;
	unsigned ua = uA;
	unsigned ub = uB;
	unsigned uc = uC;

	printf("cmp1(%d, %d) = %d\n", a, b, cmp1(a, b));
	printf("cmp2(%d, %d) = %d\n", a, b, cmp2(a, b));
	printf("cmp3(%d) = %d\n", a, cmp3(a));
	printf("cmp4(%d) = %d\n", a, cmp4(a));
	printf("cmp5(%d) = %d\n", a, cmp5(a));
	printf("cmp6(%d) = %d\n", a, cmp6(a));
	printf("cmp7(%d) = %d\n", a, cmp7(a));
	printf("cmp8(%d) = %d\n", a, cmp8(a));
	printf("cmp9(%d, %d) = %d\n", a, b, cmp9(a, b));
	printf("cmp10(%d, %d) = %d\n", a, b, cmp10(a, b));
	printf("cmp11(%d) = %d\n", a, cmp11(a));
	printf("cmp12(%d) = %d\n", a, cmp12(a));
	printf("cmp13(%d) = %d\n", a, cmp13(a));
	printf("cmp14(%d) = %d\n", a, cmp14(a));
	printf("cmp15(%d) = %d\n", a, cmp15(a));
	printf("cmp16(%d) = %d\n", a, cmp16(a));
	printf("cmp17(%d, %d) = %d\n", a, b, cmp17(a, b));
	printf("cmp18(%d, %d) = %d\n", a, b, cmp18(a, b));

	printf("cmp19(%u, %u) = %d\n", ua, ub, cmp19(ua, ub));
	printf("cmp20(%u, %u) = %d\n", ua, ub, cmp20(ua, ub));
	printf("cmp21(%u, %u) = %d\n", ua, ub, cmp21(ua, ub));
	printf("cmp22(%u, %u) = %d\n", ua, ub, cmp22(ua, ub));
	printf("cmp23(%u, %u) = %d\n", ua, ub, cmp23(ua, ub));

	printf("cmp19(%u, %u) = %d\n", ua, uc, cmp19(ua, uc));
	printf("cmp20(%u, %u) = %d\n", ua, uc, cmp20(ua, uc));
	printf("cmp21(%u, %u) = %d\n", ua, uc, cmp21(ua, uc));
	printf("cmp22(%u, %u) = %d\n", ua, uc, cmp22(ua, uc));
	printf("cmp23(%u, %u) = %d\n", ua, uc, cmp23(ua, uc));

	return 0;
}
Ejemplo n.º 9
0
void unarySortAdd(vec<Formula>& Xs,vec<Formula>& Ys,vec<Formula>& out_sorter,bool useShortCuts){
 	vec<Formula> propgationShortCuts;
	int XsLen = Xs.size();
    int YsLen = Ys.size();
    if (YsLen==0) {
    	if (XsLen>0) {
    		add(Xs,out_sorter);
    		safeSortNetwork(out_sorter,propgationShortCuts);
    		if (useShortCuts) overwrite(out_sorter,propgationShortCuts);
    	}
    }
    else if (XsLen==0) add(Ys,out_sorter);
    else if (XsLen==1 & YsLen==1) {
    	add(Xs,out_sorter);
    	add(Ys,out_sorter);
    	cmp2(out_sorter, 0);
    }
    else {
    	int Ysize; for (Ysize = 2; Ysize < YsLen; Ysize *= 2);
    	Ys.growTo(Ysize,_0_);
    	propgationShortCuts.growTo(Ysize*2,_0_);
    	addShortCuts(Ys,propgationShortCuts);
    	if (XsLen <= YsLen) {
		    Xs.growTo(Ysize,_0_);
		    sortNetwork(Xs,propgationShortCuts);
		    mergeNetwork(Xs,Ys,out_sorter,propgationShortCuts);
		}
		else {
		    vec<vec<Formula> > SubXs;
		    SubXs.push();
		    add(Ys,SubXs.last());
		    splitToGroups(Xs, Ysize, SubXs);
		    sortGroups(SubXs,propgationShortCuts); 
		    mergeGroups(SubXs, Ysize, out_sorter,propgationShortCuts);
		}
		out_sorter.shrink(out_sorter.size() - XsLen-YsLen);
		if(useShortCuts) overwrite(out_sorter,propgationShortCuts);
    }
}
Ejemplo n.º 10
0
bool DumpMemory()
{
    // whats up?

    if(Active==0) return 0;
    if(Active==2) return 0;
    if(LeakCount==0)
    {
        sLog("sys","no memory leaks detected\n\n");
        return 1;
    }
    if(LeakCount<0)
    {
        sDPrint("!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!\n");
        sDPrint("negative number of leaks - this can't be\n");
        return 0;
    }

    // make linear array of all leaks

    sArray<Leak> Leaks;
    int count = LeakCount;
    Leak *data = (Leak *) sAllocMemSystem(count*sizeof(Leak),4,0);
    Leaks.OverrideStorage(data,count);
    for(int i=0;i<HashSize;i++)
    {
        Leak *n = Hash[i];
        while(n)
        {
            Leaks.Add(*n);
            n = n->Next;
        }
    }
    sASSERT(count==Leaks.GetCount());
    Leaks.QuickSort(cmp());

    // merge

    {
        sptr count = Leaks.GetCount();
        Leak *data = Leaks.GetData();
        int d = 0;
        int s = 0;
        while(s<count)
        {
            if(d>0 && data[d-1].Line==data[s].Line && sCmpString(data[d-1].File,data[s].File)==0)
            {
                data[d-1].Count++;
                data[d-1].Size += data[s].Size;
                data[d-1].Id = sMin(data[d].Id,data[s].Id);
                s++;
            }
            else
            {
                data[d++] = data[s++];
            }
        }
        Leaks.SetSize(d);
    }

    // sort for output

    Leaks.QuickSort(cmp2());

    // output (combined)

    sDPrint("/****************************************************************************/\n");
    sDPrint("/***                                                                      ***/\n");
    sDPrint("/***   memory leaks!                                                      ***/\n");
    sDPrint("/***                                                                      ***/\n");
    sDPrint("/****************************************************************************/\n");
    sDPrint("\n");
    sDPrintF("file(line):                                                   size count    id\n");
    sDPrint("\n");
    for(auto &n : Leaks)
    {
        sString<256> buffer;
        buffer.PrintF("%s(%d):",n.File,n.Line);
        sDPrintF("%-60s%6K %5d %5d\n",buffer,n.Size,n.Count,n.Id);
    }
    sDPrint("\n");
    sDPrint("/****************************************************************************/\n\n");

    // done

    Leaks.OverrideStorage(0,0);

    sFreeMemSystem(data);
    return 0;
}
Ejemplo n.º 11
0
/*
 * Returns an LDAP error code.
 */
static int
docompare( LDAP *ld1, LDAP *ld2, char *base )
{
    int			rc, msgid;
    LDAPMessage		*res, *e;
    LDAPControl		*ctrls[2], **serverctrls;

    if ( ldaptool_verbose ) {
        printf( "Base: %s\n\n", base );
    }
    if ( ldaptool_not ) {
	return( LDAP_SUCCESS );
    }

    if (( ctrls[0] = ldaptool_create_manage_dsait_control()) != NULL ) {
	ctrls[1] = NULL;
	serverctrls = ctrls;
    } else {
	serverctrls = NULL;
    }

    if ( ldap_search_ext( ld1, base, scope, "objectClass=*", NULL,
	    0, serverctrls, NULL, NULL, -1, &msgid ) != LDAP_SUCCESS ) {
	return( ldaptool_print_lderror( ld1, "ldap_search",
	    LDAPTOOL_CHECK4SSL_IF_APPROP ));
    }
/* XXXmcs: this code should be modified to display referrals and references */
    while ( (rc = ldap_result( ld1, LDAP_RES_ANY, 0, NULL, &res )) == 
        LDAP_RES_SEARCH_ENTRY ) {
        e = ldap_first_entry( ld1, res );
        rc = cmp2( ld1, ld2, e , 0);
        ldap_msgfree( res );
    }
    if ( rc == -1 ) {
	return( ldaptool_print_lderror( ld1, "ldap_result",
		LDAPTOOL_CHECK4SSL_IF_APPROP ));
    }
    if (( rc = ldap_result2error( ld1, res, 0 )) != LDAP_SUCCESS ) {
        (void)ldaptool_print_lderror( ld1, "ldap_search",
		LDAPTOOL_CHECK4SSL_IF_APPROP );
    }
    ldap_msgfree( res );

    if ( ldap_search_ext( ld2, base, scope, "objectClass=*", NULL,
	    0, serverctrls, NULL, NULL, -1, &msgid  ) == -1 ) {
	return( ldaptool_print_lderror( ld2, "ldap_search",
		LDAPTOOL_CHECK4SSL_IF_APPROP ));
    }
/* XXXmcs: this code should be modified to display referrals and references */
    while ( (rc = ldap_result( ld2, LDAP_RES_ANY, 0, NULL, &res )) == 
	    LDAP_RES_SEARCH_ENTRY ) {
	e = ldap_first_entry( ld2, res );
        rc = cmp2( ld2, ld1, e , 1);
        ldap_msgfree( res );
    }
    if ( rc == -1 ) {
	return( ldaptool_print_lderror( ld2, "ldap_result",
		LDAPTOOL_CHECK4SSL_IF_APPROP ));
    }
    if (( rc = ldap_result2error( ld1, res, 0 )) != LDAP_SUCCESS ) {
        (void)ldaptool_print_lderror( ld1, "ldap_search",
		LDAPTOOL_CHECK4SSL_IF_APPROP );
    }
    ldap_msgfree( res );

    return( rc );
}
Ejemplo n.º 12
0
int main()
{
    int ball[12],cmp2_result,cmp3_result,diff=12,err,i;
    char w=' ';
    FILE *fin=fopen("input.txt","r");
    FILE *fout=fopen("output.txt","w");
    for(i=0; i<12; i++)
    ball[i]=fgetc(fin);
    fclose(fin);
        switch(cmp1(ball))
        {
        case 0:
            cmp2_result=cmp2(ball,0,0,0,&err);
            break;
        case 1:
            cmp2_result=cmp2(ball,0,4,1,&err);
            break;
        case 2:
            cmp2_result=cmp2(ball,4,0,1,&err);
            break;
        default:
            break;
        }

        switch(cmp2_result)
        {
        case 0:
            w='l';
            cmp3_result=cmp3(ball,err,1,w);
            break;
        case 1:
            w='h';
            cmp3_result=cmp3(ball,err,1,w);
            break;
        case 2:
            cmp3_result=cmp3(ball,err,0,w);
            break;
        case 3:
            w='h';
            cmp3_result=cmp3(ball,err,1,w);
            break;
        case 4:
            cmp3_result=cmp3(ball,err,0,w);
            break;
        case 5:
            w='l';
            cmp3_result=cmp3(ball,err,1,w);
            break;
        default:
            break;
        }

        switch(cmp3_result)
        {
        case 0:
            diff=11;
            w='h';
            break;
        case 1:
            if(err)
                diff=3;
            else
                diff=7;
            w='h';
            break;
        case 2:
            diff=err+2;
            break;
        case 3:
            diff=err+1;
            break;
        case 4:
            diff=err;
            break;
        case 5:
            diff=err;
            w='l';
            break;
        default:
            break;
        }

       fputs("the error ball is:",fout);
       fprintf(fout,"%d\n",(diff+1));
       fputs("It is ",fout);
        if(w=='h')
               fputs("heavy\n",fout);
        else
               fputs("light\n",fout);
    fclose(fout);
    return 0;
}
Ejemplo n.º 13
0
void ControllerServer::process_command( gpointer connection, ConnectionInfo & info, gchar ** parts , bool * read_again )
{
    guint count = g_strv_length( parts );

    if ( count < 1 )
    {
        return;
    }

    const gchar * cmd = parts[0];

    if ( strlen( cmd ) < 2 )
    {
        return;
    }

    if ( cmp2( cmd, "ID" ) )
    {
        // Device id line
        // ID <version> <name> <cap>*

        * read_again = false;

        // Not enough parts

        if ( count < 3 )
        {
            return;
        }

        // Already have a version

        if ( info.version )
        {
            return;
        }


        info.version = atoi( parts[1] );

        if ( !info.version )
        {
            return;
        }

        if ( info.version < 2 )
        {
            g_warning( "CONTROLLER DOES NOT SUPPORT PROTOCOL VERSION >= 2" );
            info.version = 0;
            return;
        }

        if ( info.version < 3 )
        {
            g_warning( "CONTROLLER DOES NOT SUPPORT PROTOCOL VERSION >= 3" );
            info.version = 0;
            return;
        }

        if ( info.version < 4 )
        {
            g_warning( "CONTROLLER DOES NOT SUPPORT PROTOCOL VERSION >= 4" );
            info.version = 0;
            return;
        }

        const char * name = g_strstrip( parts[2] );

        // Capability entries

        TPControllerSpec spec;

        memset( &spec, 0, sizeof( spec ) );

        for ( guint i = 3; i < count; ++i )
        {
            const gchar * cap = g_strstrip( parts[i] );

            size_t len = strlen( cap );

            if ( len == 2 )
            {
                if ( cmp2( cap, "KY" ) )
                {
                    spec.capabilities |= TP_CONTROLLER_HAS_KEYS;
                }
                else if ( cmp2( cap, "AX" ) )
                {
                    spec.capabilities |= TP_CONTROLLER_HAS_ACCELEROMETER;
                }
                else if ( cmp2( cap, "FM" ) )
                {
                    spec.capabilities |= TP_CONTROLLER_HAS_FULL_MOTION;
                }
                else if ( cmp2( cap, "PT" ) )
                {
                    spec.capabilities |= TP_CONTROLLER_HAS_POINTER;
                }
                else if ( cmp2( cap, "CK" ) )
                {
                    // Deprecated
                    // spec.capabilities |= TP_CONTROLLER_HAS_CLICKS;
                }
                else if ( cmp2( cap, "TC" ) )
                {
                    spec.capabilities |= TP_CONTROLLER_HAS_TOUCHES;
                }
                else if ( cmp2( cap, "MC" ) )
                {
                    spec.capabilities |= TP_CONTROLLER_HAS_MULTIPLE_CHOICE;
                }
                else if ( cmp2( cap, "SD" ) )
                {
                    spec.capabilities |= TP_CONTROLLER_HAS_SOUND;
                }
                else if ( cmp2( cap, "UI" ) )
                {
                    spec.capabilities |= TP_CONTROLLER_HAS_UI;
                }
                else if ( cmp2( cap, "TE" ) )
                {
                    spec.capabilities |= TP_CONTROLLER_HAS_TEXT_ENTRY;
                }
                else if ( cmp2( cap, "PS" ) )
				{
					spec.capabilities |= TP_CONTROLLER_HAS_IMAGES;
				}
                else if ( cmp2( cap, "AC" ) )
				{
					spec.capabilities |= TP_CONTROLLER_HAS_AUDIO_CLIPS;
				}
                else if ( cmp2( cap , "UX" ) )
                {
                    spec.capabilities |= TP_CONTROLLER_HAS_ADVANCED_UI;
                }
                else if ( cmp2( cap , "VR" ) )
                {
                	spec.capabilities |= TP_CONTROLLER_HAS_VIRTUAL_REMOTE;
                }
                else if ( cmp2( cap , "SV" ) )
                {
                	spec.capabilities |= TP_CONTROLLER_HAS_STREAMING_VIDEO;
                }
                else
                {
                    g_warning( "UNKNOWN CONTROLLER CAPABILITY '%s'", cap );
                }
            }
            else if ( len > 3 )
            {
                if ( cmp2( cap, "IS" ) )
                {
                    sscanf( cap, "IS=%ux%u", &spec.input_width, &spec.input_height );
                }
                else if ( cmp2( cap, "US" ) )
                {
                    sscanf( cap, "US=%ux%u", &spec.ui_width, &spec.ui_height );
                }
                else if ( cmp2( cap , "ID" ) )
                {
                	spec.id = cap + 3;
                }
                else
                {
                    g_warning( "UNKNOWN CONTROLLER CAPABILITY '%s'", cap );
                }
            }
        }

        * read_again = true;

        spec.execute_command = execute_command;

        info.controller = tp_context_add_controller( context, name, &spec, this );

        server->write_printf( connection , "WM\t%s\t%u\t%lu\n" , CONTROLLER_PROTOCOL_VERSION , context->get_http_server()->get_port() , info.aui_id );
    }
    else if ( cmp2( cmd, "KP" ) )
    {
        // Key press
        // KP <hex key code> <hex unicode>

        if ( count < 2 || !info.controller )
        {
            return;
        }

        unsigned int key_code = 0;
        unsigned long int unicode = 0;

        sscanf( parts[1], "%x", &key_code );

        if ( count > 2 )
        {
            sscanf( parts[2], "%lx", &unicode );
        }

        tp_controller_key_down( info.controller, key_code, unicode , TP_CONTROLLER_MODIFIER_NONE );
        tp_controller_key_up( info.controller, key_code, unicode , TP_CONTROLLER_MODIFIER_NONE );
    }
    else if ( cmp2( cmd, "KD" ) )
    {
        // Key down
        // KD <hex key code> <hex unicode>

        if ( count < 2 || !info.controller )
        {
            return;
        }

        unsigned int key_code = 0;
        unsigned long int unicode = 0;

        sscanf( parts[1], "%x", &key_code );

        if ( count > 2 )
        {
            sscanf( parts[2], "%lx", &unicode );
        }

        tp_controller_key_down( info.controller, key_code, unicode , TP_CONTROLLER_MODIFIER_NONE );
    }
    else if ( cmp2( cmd, "KU" ) )
    {
        // Key up
        // KU <hex key code> <hex unicode>

        if ( count < 2 || !info.controller )
        {
            return;
        }

        unsigned int key_code = 0;
        unsigned long int unicode = 0;

        sscanf( parts[1], "%x", &key_code );

        if ( count > 2 )
        {
            sscanf( parts[2], "%lx", &unicode );
        }

        tp_controller_key_up( info.controller, key_code, unicode , TP_CONTROLLER_MODIFIER_NONE );
    }
    else if ( cmp2( cmd, "CK" ) )
    {
        // Click
        // CK <x> <y>

        // deprecated

        return;
    }
    else if ( cmp2( cmd, "AX" ) )
    {
        // Acelerometer
        // AX <x> <y> <z>

        if ( count < 4 || !info.controller )
        {
            return;
        }

        tp_controller_accelerometer( info.controller, atof( parts[1] ), atof( parts[2] ), atof( parts[3] ) , TP_CONTROLLER_MODIFIER_NONE );
    }
    else if ( cmp2( cmd, "GY" ) )
    {
        // Acelerometer
        // AX <x> <y> <z>

        if ( count < 4 || !info.controller )
        {
            return;
        }

        tp_controller_gyroscope( info.controller, atof( parts[1] ), atof( parts[2] ), atof( parts[3] ) , TP_CONTROLLER_MODIFIER_NONE );
    }
    else if ( cmp2( cmd, "MM" ) )
    {
        // Acelerometer
        // AX <x> <y> <z>

        if ( count < 4 || !info.controller )
        {
            return;
        }

        tp_controller_magnetometer( info.controller, atof( parts[1] ), atof( parts[2] ), atof( parts[3] ) , TP_CONTROLLER_MODIFIER_NONE );
    }
    else if ( cmp2( cmd, "AT" ) )
    {
        // Acelerometer
        // AX <x> <y> <z>

        if ( count < 4 || !info.controller )
        {
            return;
        }

        tp_controller_attitude( info.controller, atof( parts[1] ), atof( parts[2] ), atof( parts[3] ) , TP_CONTROLLER_MODIFIER_NONE );
    }
    else if ( cmp2( cmd, "UI" ) )
    {
        // UI
        // UI <type> <txt>

        if ( count < 2 || !info.controller || strlen(parts[1]) != 2)
        {
            return;
        }

        // Enter text or multiple-choice
        if(cmp2( parts[1], "ET") || cmp2( parts[1], "MC"))
        {
            if(count < 3)
            {
                return;
            }
            tp_controller_ui_event( info.controller, parts[2] );
        }
        // Advanced UI event
        else if (cmp2( parts[1] , "UX" ) )
        {
        	if ( count < 3 )
        	{
        		return;
        	}
        	tp_controller_advanced_ui_event( info.controller , parts[ 2 ] );
        }
        // Cancel image
        else if(cmp2( parts[1], "CI"))
        {
            tp_controller_cancel_image( info.controller );
        }
        // Cancel audio
        else if(cmp2( parts[1], "CA"))
        {
            tp_controller_cancel_audio_clip( info.controller );
        }
    }
    else if ( cmp2( cmd, "PD" ) )
    {
        // Pointer button down
        // PD <button> <x> <y>

        if ( count < 4 || !info.controller )
        {
            return;
        }

        tp_controller_pointer_button_down( info.controller, atoi( parts[1] ), atoi( parts[2] ) , atoi( parts[ 3 ] ) , TP_CONTROLLER_MODIFIER_NONE );
    }
    else if ( cmp2( cmd, "PM" ) )
    {
        // Pointer move
        // PM <x> <y>

        if ( count < 3 || !info.controller )
        {
            return;
        }

        tp_controller_pointer_move( info.controller, atoi( parts[1] ), atoi( parts[2] ) , TP_CONTROLLER_MODIFIER_NONE );
    }
    else if ( cmp2( cmd, "PU" ) )
    {
        // Pointer button up
        // PU <button> <x> <y>

        if ( count < 4 || !info.controller )
        {
            return;
        }

        tp_controller_pointer_button_up( info.controller, atoi( parts[1] ), atoi( parts[2] ) , atoi( parts[ 3 ] ) , TP_CONTROLLER_MODIFIER_NONE );
    }
    else if ( cmp2( cmd, "TD" ) )
    {
        // Touch down
        // TD <finger> <x> <y>

        if ( count < 4 || !info.controller )
        {
            return;
        }

        tp_controller_touch_down( info.controller, atoi( parts[1] ), atoi( parts[2] ) , atoi( parts[ 3 ] ) , TP_CONTROLLER_MODIFIER_NONE );
    }
    else if ( cmp2( cmd, "TM" ) )
    {
        // Touch move
        // TM <finger> <x> <y>

        if ( count < 4 || !info.controller )
        {
            return;
        }

        tp_controller_touch_move( info.controller, atoi( parts[1] ), atoi( parts[2] ) , atoi( parts[ 3 ] ) , TP_CONTROLLER_MODIFIER_NONE );
    }
    else if ( cmp2( cmd, "TU" ) )
    {
        // Touch up
        // TU <finger> <x> <y>

        if ( count < 4 || !info.controller )
        {
            return;
        }

        tp_controller_touch_up( info.controller, atoi( parts[1] ), atoi( parts[2] ) , atoi( parts[ 3 ] ) , TP_CONTROLLER_MODIFIER_NONE );
    }
    else if ( cmp2( cmd , "UX" ) )
    {
        // Stop reading from this connection. We will only read
        // synchronously after we write. If there is a problem with the UX message,
        // we stop reading anyway - they only get one shot at it.

        * read_again = false;

        if ( count < 2 )
        {
            return;
        }

        gulong id = 0;

        if ( sscanf( parts[1], "%lu", & id ) != 1 )
        {
            return;
        }

        // The ID is bad

        if ( id == 0 )
        {
            return;
        }

        ConnectionInfo * parent_info = 0;

        for ( ConnectionMap::iterator it = connections.begin(); it != connections.end(); ++it )
        {
            if ( it->second.aui_id == id )
            {
                parent_info = & it->second;
                break;
            }
        }

        // Could not find a connection for this ID

        if ( ! parent_info )
        {
            return;
        }

        // The controller connection for this ID has not identified itself yet

        if ( ! parent_info->version )
        {
            return;
        }

        // OK, everything is cool

        // Set this connection's version, so it does not get booted.

        info.version = parent_info->version;

        // Tell the parent that this connection belongs to it

        parent_info->aui_connection = connection;

        // Now, generate the event that it is ready

        tp_controller_advanced_ui_ready( parent_info->controller );
    }
    else if ( cmp4( cmd, "SVCC" ) )
    {
        // Streaming video call connected
        // SVCC <address>

        if ( count < 2 || !info.controller )
        {
            return;
        }

        tp_controller_streaming_video_connected( info.controller, parts[1] );
    }
    else if ( cmp4( cmd, "SVCF" ) )
    {
        // Streaming video call failed
        // SVCF <address> <reason>

        if ( count < 3 || !info.controller )
        {
            return;
        }

        tp_controller_streaming_video_failed( info.controller, parts[1], parts[2] );
    }
    else if ( cmp4( cmd, "SVCD" ) )
    {
        // Streaming video call was dropped
        // SVCD <address> <reason>

        if ( count < 3 || !info.controller )
        {
            return;
        }

        tp_controller_streaming_video_dropped( info.controller, parts[1], parts[2] );
    }
    else if ( cmp4( cmd, "SVCE" ) )
    {
        // Streaming video call ended
        // SVCE <address> <who>

        if ( count < 3 || !info.controller )
        {
            return;
        }

        tp_controller_streaming_video_ended( info.controller, parts[1], parts[2] );
    }
    else if ( cmp4( cmd, "SVCS" ) )
    {
        // Streaming video call status
        // SVCS <status> <address>

        if ( count < 3 || !info.controller )
        {
            return;
        }

        tp_controller_streaming_video_status( info.controller, parts[1], parts[2] );
    }
    else
    {
        g_warning( "UNKNOWN CONTROLLER COMMAND '%s'", cmd );
    }
}
Ejemplo n.º 14
0
	static inline void split(vec<Formula>& toSplit,int n, int startPos) {
		for(int i1=startPos, i2=0; i2<n/2; i2++, i1++) {
			int j = i1 + n/2;
			cmp2(toSplit,i1,j);
		}
	}
Ejemplo n.º 15
0
	static inline void combine(vec<Formula>& toMerge,int n, int startPos, int m) {
		for(int i1=startPos + m, i2=1; i2 < n/2; i1+= 2*m, i2++) {
			int j = i1 + m;
			cmp2(toMerge,i1,j);
		}
	}