Example #1
0
int main() 
{ 
#ifndef VERIFIER
	int data[] = {44, 12, 145, -123, -1, 0, 121, 88}; 
	const unsigned int n = sizeof(data)/sizeof(int);

	printArray(data, n);

	MERGE_SORT(data, 0, n-1); 

	printArray(data, n);
#else
	int *Array = NULL;
	int size = 0;
	int test_case = 0;
	for (; test_case<MAX_TEST_CASE; test_case++)
	{
		Array = FillArray(&size);
		if (!Array)
			return 0;

		MERGE_SORT(Array, 0, size-1);

		CheckArrayElement(Array, size);

		ReleaseArray(Array);
	}
	printf("\n");
#endif

	return 0; 
} 
Example #2
0
static char InitServer( void )
{
    putstring( "init server\r\n" );
    ServRespESRAddr = _ESR( ServResp );
    SAPBroadESRAddr = _ESR( SAPBroad );
    SAPWaitESRAddr = _ESR( SAPWait );

    ServECB.fragmentCount = 2;
    ServECB.fragmentDescriptor[1].address = &ServDummy;
    ServECB.fragmentDescriptor[1].size = sizeof( ServDummy );

    ServECB.ESRAddress = ServRespESRAddr;
    _IPXListenForPacket( &ServECB );

    _INITIPXECB( SAP );
    FillArray( SAPHead.destination.node, 0xff );
    SAPHead.destination.socket = SAP_SOCKET;
    SAPHead.infoType = _SWAPINT( 0x2 );
    SAPHead.serverType = DBG_SERVER_TYPE;
    _IPXGetInternetworkAddress( &SAPHead.address.network.a[0] );
    SAPHead.address.socket = SAPECB.socketNumber;
    SAPHead.intermediateNetworks = _SWAPINT( 0x1 );
    SAPECB.immediateAddress = SAPHead.destination.node;
    SAPECB.ESRAddress = SAPBroadESRAddr;
    _IPXSendPacket( &SAPECB );
    return( 1 );
}
Example #3
0
int _tmain(int argc, _TCHAR* argv[])
{
	if(argc == 1)
		return ErrorReport(L"Please specify a localisation file.");
	else if(argc == 2)
		return ErrorReport(L"Please specify the name of the array.");
	else if(argc == 3)
		return ErrorReport(L"Please specify the name of the name-array.");
	else if(argc == 4)
		return ErrorReport(L"Please specify the counter parameter.");
	else if(argc == 5)
		return ErrorReport(L"Please specify one or more categories you are looking for.");

	tstring file, name, counter_name, id_array_name;
	file = argv[1];
	name = argv[2];
	id_array_name = argv[3];
	counter_name = argv[4];
	int id = 1;

	for(int i = 5 ; i < argc ; ++i)
	{
		std::vector<tstring> information;
		GetHashInfo(argv[i], information);
		FillArray(information, name, id_array_name, file, id);
	}

	tcout << L"set \"" << counter_name << L"=" << (id - 1) << L"\"";

	return 0;
}
Example #4
0
static void Test5 (void)
{
    unsigned char I;
    FillArray ();
    I = 0;
    do {
	Free (V[I]);
	I += 2;
    } while (I != 0);
    do {
       	V[I] = Alloc ();
	I += 2;
    } while (I != 0);
    I = 1;
    do {
	Free (V[I]);
	I += 2;
    } while (I != 1);
    do {
       	V[I] = Alloc ();
	I += 2;
    } while (I != 1);
    I = 0;
    do {
      	Free (V[I]);
	++I;
    } while (I != 0);
    ShowInfo ();
}
Example #5
0
int main ()
{
    enum SearchResult result;
    int searchKey;
    int array[ARRAYSIZE];
    int datasize;
    int count;
    char searchRes[20];
 
    srand(time(0));
 
    printf ("DATA SIZE\tSEARCH KEY\t\tFOUND?\n\n");     // to screen
 
 
    for (datasize = 1; datasize<=ARRAYSIZE; datasize++)
    {
 
        searchKey = rand()% RANGE;
        FillArray(array, datasize);
        count=0;
        enum SearchResult result = RunTest (array, datasize, searchKey,&count);
 
        if (result == FOUND)
            strcpy (searchRes,"FOUND    ");
        else
            strcpy (searchRes,"NOT FOUND");
 
        printf ("%d\t\t%d\t\t\t%s\t\t%d\n",datasize,searchKey,searchRes, count); // screen
    }
 
 
    return 0;
}
int main()
{
    ProcessInput();
    FillArray();

    GenerateCombinationsWithoutRepetition(0, 0);
    return 0;
}
Example #7
0
static char InitServer( void )
{
    ServECB.fragmentCount = 2;
    ServECB.fragmentDescriptor[1].address = &ServDummy;
    ServECB.fragmentDescriptor[1].size = sizeof( ServDummy );

    ServECB.ESRAddress = &ServRespESR;
    CIPXListen( &ServECB );

    SAPStruct.ASServerIDpacket.serverType = DBG_SERVER_TYPE;
    CIPXGetInternetworkAddress((BYTE*)&SAPStruct.ASServerIDpacket.serverAddress);
    AssignArray( SAPStruct.ASServerIDpacket.serverAddress.socket,
                 ServECB.socketNumber );
    SAPStruct.AS_ECB.ESRAddress = NULL;
    SAPStruct.AS_ECB.socketNumber = SAP_SOCKET_VALUE;
    FillArray( SAPStruct.AS_ECB.immediateAddress, '\xFF' );
    SAPStruct.AS_ECB.fragmentCount = 1;
    SAPStruct.AS_ECB.fragmentDescriptor[0].size = sizeof( IPXHeader ) +
            sizeof( SAPIdPacket );
    SAPStruct.AS_ECB.fragmentDescriptor[0].address = &SAPStruct.ASPacket;

    SAPStruct.ASPacket.packetType = 4;
    FillArray( SAPStruct.ASPacket.destination.network, 0 );
    FillArray( SAPStruct.ASPacket.destination.node, '\xFF' );
    {
        LONG        socket;

        socket = SAP_SOCKET;
        AssignArray( SAPStruct.ASPacket.destination.socket, socket );
    }

    SAPStruct.ASServerIDpacket.SAPPacketType = _SWAPINT( 2 );
    SAPStruct.ASServerIDpacket.interveningNetworks = _SWAPINT( 1 );

    CIPXSendPacket( &SAPStruct.AS_ECB );

    SAPTimer.TCallBackProcedure = (void (*)(LONG))Advertiser;
    SAPTimer.TCallBackEBXParameter = (LONG)&SAPTimer;
    SAPTimer.TCallBackWaitTime = 0;
    SAPTimer.TResourceTag = TimerTag;
    CScheduleInterruptTimeCallBack( &SAPTimer );

    return( 1 );
}
Example #8
0
static void Test1 (void)
{
    unsigned char I;
    FillArray ();
    for (I = 0; I < 0x80; ++I) {
	Free (V[0x7F-I]);
	Free (V[0x80+I]);
    }
    ShowInfo ();
}
Example #9
0
static void Test3 (void)
{
    unsigned char I;
    FillArray ();
    I = 0;
    do {
     	--I;
     	Free (V[I]);
    } while (I != 0);
    ShowInfo ();
}
Example #10
0
int main()
{
    int line, column;
    printf("Enter amount of lines in array: ");
    scanf("%d", &line);
    printf("Enter amount of columns in array: ");
    scanf("%d", &column);

    FillArray(line, column);
    OutputArray(line, column);
    SortingArray(line, column);
    printf("\nArray after sorting:\n");
    OutputArray(line, column);

    return 0;
}
int main()
{
    int N=0;
    int MemArr[MAXSIZE*MAXSIZE]={};
    if (!input("N", &N))
    {
        printf("INPUT ERROR\n");
        return 0;
    }
    else
    {
        FillArray (MemArr, N);
        printf("The number of decompositions of %d is %d\n", N, decompositions (N, N, MemArr, N));
    }
    return 0;

}
Example #12
0
pgObject *pgUserFactory::CreateObjects(pgCollection *collection, ctlTree *browser, const wxString &restriction)
{
    pgUser *user = 0;

    wxString tabname;

    if (collection->GetServer()->HasPrivilege(wxT("table"), wxT("pg_shadow"), wxT("SELECT")))
        tabname = wxT("pg_shadow");
    else
        tabname = wxT("pg_user");

    pgSet *users = collection->GetServer()->ExecuteSet(wxT(
                       "SELECT * FROM ") + tabname + restriction + wxT(" ORDER BY usename"));

    if (users)
    {
        while (!users->Eof())
        {

            user = new pgUser(users->GetVal(wxT("usename")));
            user->iSetServer(collection->GetServer());
            user->iSetUserId(users->GetLong(wxT("usesysid")));
            user->iSetCreateDatabase(users->GetBool(wxT("usecreatedb")));
            user->iSetSuperuser(users->GetBool(wxT("usesuper")));
            user->iSetUpdateCatalog(users->GetBool(wxT("usecatupd")));
            user->iSetAccountExpires(users->GetDateTime(wxT("valuntil")));
            user->iSetPassword(users->GetVal(wxT("passwd")));

            wxString cfg = users->GetVal(wxT("useconfig"));
            if (!cfg.IsEmpty())
                FillArray(user->GetConfigList(), cfg.Mid(1, cfg.Length() - 2));

            if (browser)
            {
                browser->AppendObject(collection, user);
                users->MoveNext();
            }
            else
                break;
        }

        delete users;
    }
    return user;
}
Example #13
0
static void Test6 (void)
{
    unsigned char I, J;
    FillArray ();
    I = J = 0;
    do {
	do {
	    Free (V[I]);
	    V[I] = Alloc ();
	    ++I;
	} while (I != 0);
	++J;
    } while (J < 5);
    do {
	Free (V[I]);
	++I;
    } while (I != 0);
    ShowInfo ();
}
Example #14
0
int main()
{
#ifndef VERIFIER
	int a[] = {19,5,2,6,7,12,10,3,8,4,11,18,17};
	const unsigned int n = sizeof(a)/sizeof(int);
	int *b = (int *)malloc(n*sizeof(int));
	if (!b)
		return 0;

	COUNTING_SORT(a, b, VALUE_UPPER_LIMIT, n);

	int i = 0;
	for(; i<n; i++)
		printf("%d ",b[i]);
	printf("\n");

	free(b);
#else
	int *Array = NULL;
	int size = 0;
	int test_case = 0;
	for (; test_case<MAX_TEST_CASE; test_case++)
	{
		Array = FillArray(&size);
		if (!Array)
			return 0;

		int *b = (int *)malloc(size*sizeof(int));
		if (!b)
			return 0;

		COUNTING_SORT(Array, b, VALUE_UPPER_LIMIT, size);

		CheckArrayElement(b, size);

		free(b);
		ReleaseArray(Array);
	}
	printf("\n");
#endif
	return 0;
} 
Example #15
0
static void far Broadcast( void )
{
    _INITIPXECB( SAP );
    FillArray( SAPHead.destNode, 0xff );
    SAPHead.destSocket = SAP_SOCKET;
    SAPHead.infoType = _SWAPINT( 0x2 );
    SAPHead.serverType = DBG_SERVER_TYPE;
    IpxGetInternetworkAddress( (PUCHAR)&SAPHead.addrNet );
    SAPHead.addrSocket = IPXSocket;
    SAPHead.intermediateNetworks = _SWAPINT( 0x1 );
    AssignArray( SAPECB.immediateAddress, SAPHead.destNode );
    for( ;; ) {
        IpxSend( IPXSocket, &SAPECB );
        DosSemClear( &BroadCastStart );
        DosSemWait( &BroadCastStop, 60000 );
        if( ServerDie ) {
            SAPHead.intermediateNetworks = _SWAPINT( 0x10 );
            IpxSend( IPXSocket, &SAPECB );
            ServerDie |= DIE_BROADCAST;
            DosExit( EXIT_THREAD, 0 );
        }
    }
}
Example #16
0
int main (void)
{
    unsigned long T;

    /* Show info at start */
    ShowInfo ();

    /* Remember the time */
    T = clock ();

    /* Do the tests */
    FillArray ();
    ShowInfo ();
    FreeArray ();
    ShowInfo ();

    /* Calculate the time and print it */
    T = clock () - T;
    printf ("Time needed: %lu ticks\n", T);

    /* Done */
    return EXIT_SUCCESS;
}
Example #17
0
pgObject *pgDatabaseFactory::CreateObjects(pgCollection *collection, ctlTree *browser, const wxString &restriction)
{
	pgDatabase *database = 0;

	pgSet *databases;

	wxString datcollate, datctype, datconnlimit, seclabelsql;

	if (collection->GetConnection()->BackendMinimumVersion(8, 1))
	{
		datconnlimit = wxT(", db.datconnlimit as connectionlimit");
	}
	if (collection->GetConnection()->BackendMinimumVersion(8, 4))
	{
		datctype = wxT(", db.datctype as ctype");
		datcollate = wxT(", db.datcollate as collate");
	}
	if (collection->GetConnection()->BackendMinimumVersion(9, 2))
	{
		seclabelsql = wxT(",\n(SELECT array_agg(label) FROM pg_shseclabel sl1 WHERE sl1.objoid=db.oid) AS labels")
		              wxT(",\n(SELECT array_agg(provider) FROM pg_shseclabel sl2 WHERE sl2.objoid=db.oid) AS providers");
	}

	wxString restr = restriction;
	if (!collection->GetServer()->GetDbRestriction().IsEmpty())
	{
		if (restr.IsEmpty())
			restr = wxT(" WHERE datname IN (");
		else
			restr += wxT("   AND datname IN (");

		restr += collection->GetServer()->GetDbRestriction() + wxT(")\n");
	}

	// In 9.0+, database config options are in pg_db_role_setting
	if (collection->GetConnection()->BackendMinimumVersion(9, 0))
	{
		wxString setconfig = wxT("SELECT array(select coalesce('''' || rolname || '''', '') || '=' || unnest(setconfig) ")
		                     wxT("FROM pg_db_role_setting setting LEFT JOIN pg_roles role ON setting.setrole=role.oid ")
		                     wxT("WHERE setdatabase = db.oid)");
		databases = collection->GetServer()->ExecuteSet(
		                wxT("SELECT db.oid, datname, db.dattablespace AS spcoid, spcname, datallowconn, (") + setconfig + wxT(") AS datconfig, datacl, ")
		                wxT("pg_encoding_to_char(encoding) AS serverencoding, pg_get_userbyid(datdba) AS datowner,")
		                wxT("has_database_privilege(db.oid, 'CREATE') as cancreate, \n")
		                wxT("current_setting('default_tablespace') AS default_tablespace, \n")
		                wxT("descr.description\n") +
		                datconnlimit + datcollate + datctype + seclabelsql +
		                wxT("  FROM pg_database db\n")
		                wxT("  LEFT OUTER JOIN pg_tablespace ta ON db.dattablespace=ta.OID\n")
		                wxT("  LEFT OUTER JOIN pg_shdescription descr ON db.oid=descr.objoid\n")
		                + restr +
		                wxT(" ORDER BY datname"));
	}
	else if (collection->GetConnection()->BackendMinimumVersion(8, 0))
		databases = collection->GetServer()->ExecuteSet(
		                wxT("SELECT db.oid, datname, db.dattablespace AS spcoid, spcname, datallowconn, datconfig, datacl, ")
		                wxT("pg_encoding_to_char(encoding) AS serverencoding, pg_get_userbyid(datdba) AS datowner,")
		                wxT("has_database_privilege(db.oid, 'CREATE') as cancreate, \n")
		                wxT("current_setting('default_tablespace') AS default_tablespace, \n")
		                wxT("descr.description\n") +
		                datconnlimit + datcollate + datctype +
		                wxT("  FROM pg_database db\n")
		                wxT("  LEFT OUTER JOIN pg_tablespace ta ON db.dattablespace=ta.OID\n")
		                wxT("  LEFT OUTER JOIN ")
		                + wxString(collection->GetConnection()->BackendMinimumVersion(8, 2) ? wxT("pg_shdescription") : wxT("pg_description")) +
		                wxT(" descr ON db.oid=descr.objoid\n")
		                + restr +
		                wxT(" ORDER BY datname"));
	else
		databases = collection->GetServer()->ExecuteSet(
		                wxT("SELECT db.oid, datname, datpath, datallowconn, datconfig, datacl, ")
		                wxT("pg_encoding_to_char(encoding) AS serverencoding, pg_get_userbyid(datdba) AS datowner,")
		                wxT("has_database_privilege(db.oid, 'CREATE') as cancreate,\n")
		                wxT("descr.description\n")
		                wxT("  FROM pg_database db\n")
		                wxT("  LEFT OUTER JOIN pg_description descr ON db.oid=descr.objoid\n")
		                + restr +
		                wxT(" ORDER BY datname"));

	if (databases)
	{
		while (!databases->Eof())
		{
			wxString name = databases->GetVal(wxT("datname"));
			database = new pgDatabase(name);
			database->iSetServer(collection->GetServer());
			database->iSetOid(databases->GetOid(wxT("oid")));
			database->iSetOwner(databases->GetVal(wxT("datowner")));
			database->iSetAcl(databases->GetVal(wxT("datacl")));
			database->iSetEncoding(databases->GetVal(wxT("serverencoding")));
			database->iSetCreatePrivilege(databases->GetBool(wxT("cancreate")));
			database->iSetComment(databases->GetVal(wxT("description")));
			wxString str = databases->GetVal(wxT("datconfig"));
			if (!collection->GetConnection()->BackendMinimumVersion(8, 5))
			{
				str = TransformToNewDatconfig(str.Mid(1, str.Length() - 2));
				//str = tmp;
			}
			else
				str = str.Mid(1, str.Length() - 2);
			if (!str.IsEmpty())
				FillArray(database->GetVariables(), str);
			database->iSetAllowConnections(databases->GetBool(wxT("datallowconn")));

			if (collection->GetConnection()->BackendMinimumVersion(8, 0))
			{
				database->iSetTablespace(databases->GetVal(wxT("spcname")));
				database->iSetTablespaceOid(databases->GetOid(wxT("spcoid")));
				if (databases->GetVal(wxT("default_tablespace")) == wxEmptyString || databases->GetVal(wxT("default_tablespace")) == wxT("unset"))
					database->iSetDefaultTablespace(databases->GetVal(wxT("spcname")));
				else
					database->iSetDefaultTablespace(databases->GetVal(wxT("default_tablespace")));
			}
			else
				database->iSetPath(databases->GetVal(wxT("datpath")));

			if (collection->GetConnection()->BackendMinimumVersion(8, 1))
			{
				database->iSetConnectionLimit(databases->GetLong(wxT("connectionlimit")));
			}
			if (collection->GetConnection()->BackendMinimumVersion(8, 4))
			{
				database->iSetCollate(databases->GetVal(wxT("collate")));
				database->iSetCType(databases->GetVal(wxT("ctype")));
			}

			if (collection->GetServer()->GetServerIndex())
			{
				wxString value;
				settings->Read(wxT("Servers/") + NumToStr(collection->GetServer()->GetServerIndex())
				               + wxT("/Databases/") + name + wxT("/SchemaRestriction"), &value, wxEmptyString);

				database->iSetSchemaRestriction(value);
			}

			if (collection->GetConnection()->BackendMinimumVersion(9, 2))
			{
				database->iSetProviders(databases->GetVal(wxT("providers")));
				database->iSetLabels(databases->GetVal(wxT("labels")));
			}

			// Add the treeview node if required
			if (settings->GetShowSystemObjects() || !database->GetSystemObject())
			{
				if (browser)
				{
					int icon;
					if (database->GetName() == database->GetServer()->GetDatabaseName())
						icon = databaseFactory.GetIconId();
					else
						icon = databaseFactory.GetClosedIconId();

					browser->AppendItem(collection->GetId(), database->GetIdentifier(), icon, -1, database);
				}
				else
					break;
			}
			else
				delete database;

			databases->MoveNext();
		}
		delete databases;
	}
	return database;
}
Example #18
0
pgObject *pgRoleBaseFactory::CreateObjects(pgCollection *collection, ctlTree *browser, const wxString &restriction)
{
    pgRole *role=0;
    pgSet *roles=0;
    wxString query;

    wxString tabname;

    if (collection->GetServer()->HasPrivilege(wxT("table"), wxT("pg_authid"), wxT("SELECT")))
        tabname=wxT("pg_authid");
    else
        tabname=wxT("pg_roles");

    // In 9.0+, role config options are in pg_db_role_setting
    if (collection->GetServer()->GetConnection()->BackendMinimumVersion(8, 5))
    {
        query = wxT("SELECT tab.oid, tab.*, pg_catalog.shobj_description(tab.oid, 'pg_authid') AS description, setting.setconfig AS rolconfig");
        if (collection->GetServer()->GetConnection()->GetIsGreenplum())
            query += wxT(", (SELECT rsqname FROM pg_resqueue WHERE pg_resqueue.oid = rolresqueue) AS rsqname");
        query += wxT(" FROM ") + tabname + wxT(" tab") +
              wxT("  LEFT OUTER JOIN pg_db_role_setting setting ON (tab.oid=setting.setrole AND setting.setdatabase=0)\n") + 
              restriction +  wxT(" ORDER BY rolname");
    }
    else if (collection->GetServer()->GetConnection()->BackendMinimumVersion(8, 2))
    {
        query = wxT("SELECT oid, *, pg_catalog.shobj_description(oid, 'pg_authid') AS description ");
        if (collection->GetServer()->GetConnection()->GetIsGreenplum())
            query += wxT(", (SELECT rsqname FROM pg_resqueue WHERE pg_resqueue.oid = rolresqueue) AS rsqname");
        query += wxT(" FROM ") + tabname + restriction + wxT(" ORDER BY rolname");
    }
    else
    {
        query = wxT("SELECT oid, *, '' AS description ") ;
        if (collection->GetServer()->GetConnection()->GetIsGreenplum())
            query += wxT(", (SELECT rsqname FROM pg_resqueue WHERE pg_resqueue.oid = rolresqueue) AS rsqname");
        query += wxT(" FROM ") + tabname + restriction + wxT(" ORDER BY rolname");
    }
    roles = collection->GetServer()->ExecuteSet(query);

    if (roles)
    {
        while (!roles->Eof())
        {
            if (roles->GetBool(wxT("rolcanlogin")))
                role = new pgLoginRole(roles->GetVal(wxT("rolname")));
            else
                role = new pgGroupRole(roles->GetVal(wxT("rolname")));
            role->iSetServer(collection->GetServer());
            role->iSetOid(roles->GetLong(wxT("oid")));
            role->iSetCanLogin(roles->GetBool(wxT("rolcanlogin")));
            role->iSetInherits(roles->GetBool(wxT("rolinherit")));
            role->iSetCreateRole(roles->GetBool(wxT("rolcreaterole")));
            role->iSetCreateDatabase(roles->GetBool(wxT("rolcreatedb")));
            role->iSetSuperuser(roles->GetBool(wxT("rolsuper")));
            role->iSetUpdateCatalog(roles->GetBool(wxT("rolcatupdate")));
            role->iSetAccountExpires(roles->GetDateTime(wxT("rolvaliduntil")));
            role->iSetPassword(roles->GetVal(wxT("rolpassword")));
            role->iSetComment(roles->GetVal(wxT("description")));
            role->iSetConnectionLimit(roles->GetLong(wxT("rolconnlimit")));

            if (collection->GetServer()->GetConnection()->BackendMinimumVersion(9, 1))
            {
                role->iSetReplication(roles->GetBool(wxT("rolreplication")));
            }

            if (collection->GetServer()->GetConnection()->GetIsGreenplum())
            {
                role->iSetRolQueueName(roles->GetVal(wxT("rsqname")));	
            }

            wxString cfg=roles->GetVal(wxT("rolconfig"));
            if (!cfg.IsEmpty())
                FillArray(role->GetConfigList(), cfg.Mid(1, cfg.Length()-2));

            if (browser)
            {
                browser->AppendObject(collection, role);
                roles->MoveNext();
            }
            else
                break;
        }

        delete roles;
    }
    return role;
}
Example #19
0
pgFunction *pgFunctionFactory::AppendFunctions(pgObject *obj, pgSchema *schema, ctlTree *browser, const wxString &restriction)
{
	// Caches
	cacheMap typeCache, exprCache;

	pgFunction *function = 0;
	wxString argNamesCol, argDefsCol, proConfigCol, proType, seclab;
	if (obj->GetConnection()->BackendMinimumVersion(8, 0))
		argNamesCol = wxT("proargnames, ");
	if (obj->GetConnection()->HasFeature(FEATURE_FUNCTION_DEFAULTS) && !obj->GetConnection()->BackendMinimumVersion(8, 4))
		argDefsCol = wxT("proargdefvals, COALESCE(substring(array_dims(proargdefvals), E'1:(.*)\\]')::integer, 0) AS pronargdefaults, ");
	if (obj->GetConnection()->BackendMinimumVersion(8, 4))
		argDefsCol = wxT("pg_get_expr(proargdefaults, 'pg_catalog.pg_class'::regclass) AS proargdefaultvals, pronargdefaults, ");
	if (obj->GetConnection()->BackendMinimumVersion(8, 3))
		proConfigCol = wxT("proconfig, ");
	if (obj->GetConnection()->EdbMinimumVersion(8, 1))
		proType = wxT("protype, ");
	if (obj->GetConnection()->BackendMinimumVersion(9, 1))
	{
		seclab = wxT(",\n")
		         wxT("(SELECT array_agg(label) FROM pg_seclabels sl1 WHERE sl1.objoid=pr.oid) AS labels,\n")
		         wxT("(SELECT array_agg(provider) FROM pg_seclabels sl2 WHERE sl2.objoid=pr.oid) AS providers");
	}

	pgSet *functions = obj->GetDatabase()->ExecuteSet(
	                       wxT("SELECT pr.oid, pr.xmin, pr.*, format_type(TYP.oid, NULL) AS typname, typns.nspname AS typnsp, lanname, ") +
	                       argNamesCol  + argDefsCol + proConfigCol + proType +
	                       wxT("       pg_get_userbyid(proowner) as funcowner, description") + seclab + wxT("\n")
	                       wxT("  FROM pg_proc pr\n")
	                       wxT("  JOIN pg_type typ ON typ.oid=prorettype\n")
	                       wxT("  JOIN pg_namespace typns ON typns.oid=typ.typnamespace\n")
	                       wxT("  JOIN pg_language lng ON lng.oid=prolang\n")
	                       wxT("  LEFT OUTER JOIN pg_description des ON des.objoid=pr.oid\n")
	                       + restriction +
	                       wxT(" ORDER BY proname"));

	pgSet *types = obj->GetDatabase()->ExecuteSet(wxT(
	                   "SELECT oid, format_type(oid, NULL) AS typname FROM pg_type"));

	if (types)
	{
		while(!types->Eof())
		{
			typeCache[types->GetVal(wxT("oid"))] = types->GetVal(wxT("typname"));
			types->MoveNext();
		}
	}

	if (functions)
	{
		while (!functions->Eof())
		{
			bool isProcedure = false;
			wxString lanname = functions->GetVal(wxT("lanname"));
			wxString typname = functions->GetVal(wxT("typname"));

			// Is this an EDB Stored Procedure?
			if (obj->GetConnection()->EdbMinimumVersion(8, 1))
			{
				wxString protype = functions->GetVal(wxT("protype"));
				if (protype == wxT("1"))
					isProcedure = true;
			}
			else if (obj->GetConnection()->EdbMinimumVersion(8, 0) &&
			         lanname == wxT("edbspl") && typname == wxT("void"))
				isProcedure = true;

			// Create the new object
			if (isProcedure)
				function = new pgProcedure(schema, functions->GetVal(wxT("proname")));
			else if (typname == wxT("\"trigger\"") || typname == wxT("trigger"))
				function = new pgTriggerFunction(schema, functions->GetVal(wxT("proname")));
			else
				function = new pgFunction(schema, functions->GetVal(wxT("proname")));

			// Tokenize the arguments
			wxStringTokenizer argTypesTkz(wxEmptyString), argModesTkz(wxEmptyString);
			wxString tmp;

			wxArrayString argNamesArray;
			wxArrayString argDefValArray;

			// We always have types
			argTypesTkz.SetString(functions->GetVal(wxT("proargtypes")));

			// We only have names in 8.0+
			if (obj->GetConnection()->BackendMinimumVersion(8, 0))
			{
				tmp = functions->GetVal(wxT("proargnames"));
				if (!tmp.IsEmpty())
					getArrayFromCommaSeparatedList(tmp.Mid(1, tmp.Length() - 2), argNamesArray);
			}

			// EDB 8.0 had modes in pg_proc.proargdirs
			if (!obj->GetConnection()->EdbMinimumVersion(8, 1) && isProcedure)
				argModesTkz.SetString(functions->GetVal(wxT("proargdirs")));

			if (obj->GetConnection()->EdbMinimumVersion(8, 1))
				function->iSetProcType(functions->GetLong(wxT("protype")));

			// EDB 8.1 and PostgreSQL 8.1 have modes in pg_proc.proargmodes
			if (obj->GetConnection()->BackendMinimumVersion(8, 1))
			{
				tmp = functions->GetVal(wxT("proallargtypes"));
				if (!tmp.IsEmpty())
					argTypesTkz.SetString(tmp.Mid(1, tmp.Length() - 2), wxT(","));

				tmp = functions->GetVal(wxT("proargmodes"));
				if (!tmp.IsEmpty())
					argModesTkz.SetString(tmp.Mid(1, tmp.Length() - 2), wxT(","));
			}

			// EDB 8.3: Function defaults
			if (obj->GetConnection()->HasFeature(FEATURE_FUNCTION_DEFAULTS) &&
			        !obj->GetConnection()->BackendMinimumVersion(8, 4))
			{
				tmp = functions->GetVal(wxT("proargdefvals"));
				if (!tmp.IsEmpty())
					getArrayFromCommaSeparatedList(tmp.Mid(1, tmp.Length() - 2), argDefValArray);

				function->iSetArgDefValCount(functions->GetLong(wxT("pronargdefaults")));
			}

			if (obj->GetConnection()->BackendMinimumVersion(8, 4))
			{
				tmp = functions->GetVal(wxT("proargdefaultvals"));
				getArrayFromCommaSeparatedList(tmp, argDefValArray);

				function->iSetArgDefValCount(functions->GetLong(wxT("pronargdefaults")));

				// Check if it is a window function
				function->iSetIsWindow(functions->GetBool(wxT("proiswindow")));
			}
			else
				function->iSetIsWindow(false);

			// Now iterate the arguments and build the arrays
			wxString type, name, mode;
			size_t nArgsIN = 0;
			size_t nArgNames = 0;

			while (argTypesTkz.HasMoreTokens())
			{
				if (nArgNames < argNamesArray.GetCount())
				{
					name = argNamesArray[nArgNames++];
				}
				else
					name = wxEmptyString;
				if (!name.IsEmpty())
				{
					// Now add the name, stripping the quotes and \" if
					// necessary.
					if (name[0] == '"')
						name = name.Mid(1, name.Length() - 2);
					name.Replace(wxT("\\\""), wxT("\""));

					// In EDBAS 90, if an SPL-function has both an OUT-parameter
					// and a return value (which is not possible on PostgreSQL otherwise),
					// the return value is transformed into an extra OUT-parameter
					// named "_retval_"
					if (obj->GetConnection()->EdbMinimumVersion(9, 0))
					{
						if (name == wxT("_retval_"))
						{
							type = argTypesTkz.GetNextToken();
							// this will be the return type for this object
							function->iSetReturnType(typeCache[type]);

							// consume uniformly, mode will definitely be "OUT"
							mode = argModesTkz.GetNextToken();

							continue;
						}
					}
					function->iAddArgName(name);
				}
				else
					function->iAddArgName(wxEmptyString);

				// Add the arg type. This is a type oid, so
				// look it up in the hashmap
				type = argTypesTkz.GetNextToken();
				function->iAddArgType(typeCache[type]);

				// Now the mode
				mode = argModesTkz.GetNextToken();
				if (!mode.IsEmpty())
				{
					if (mode == wxT('o') || mode == wxT("2"))
						mode = wxT("OUT");
					else if (mode == wxT("b") || mode == wxT("3"))
					{
						if (isProcedure)
							mode = wxT("IN OUT");
						else
						{
							mode = wxT("INOUT");
							// 'edbspl' does not support default values for the
							// INOUT parameters.
							if (lanname != wxT("edbspl"))
							{
								nArgsIN++;
							}
						}
					}
					else if (mode == wxT("v"))
					{
						mode = wxT("VARIADIC");
						nArgsIN++;
					}
					else if (mode == wxT("t"))
						mode = wxT("TABLE");
					else
					{
						mode = wxT("IN");
						nArgsIN++;
					}

					function->iAddArgMode(mode);
				}
				else
				{
					function->iAddArgMode(wxEmptyString);
					nArgsIN++;
				}
			}

			function->iSetArgCount(functions->GetLong(wxT("pronargs")));

			wxString strReturnTableArgs;
			// Process default values
			size_t currINindex = 0;
			for (size_t index = 0; index < function->GetArgModesArray().Count(); index++)
			{
				wxString def = wxEmptyString;
				if(function->GetArgModesArray()[index].IsEmpty() ||
				        function->GetArgModesArray()[index] == wxT("IN") ||
				        (function->GetArgModesArray()[index] == wxT("INOUT") &&
				         lanname != wxT("edbspl")) ||
				        function->GetArgModesArray()[index] == wxT("VARIADIC"))
				{
					if (!argDefValArray.IsEmpty() && nArgsIN <= argDefValArray.GetCount())
					{
						def = argDefValArray[currINindex++];

						if (!def.IsEmpty() && def != wxT("-"))
						{
							// Only EDB 8.3 does not support get the default value
							// using pg_get_expr directly
							if (function->GetConnection()->HasFeature(FEATURE_FUNCTION_DEFAULTS) &&
							        !function->GetConnection()->BackendMinimumVersion(8, 4))
							{
								// Check the cache first - if we don't have a value, get it and cache for next time
								wxString val = exprCache[def];

								if (val == wxEmptyString)
								{
									val = obj->GetDatabase()->ExecuteScalar(
									          wxT("SELECT pg_get_expr('") + def.Mid(1, def.Length() - 2) + wxT("', 'pg_catalog.pg_class'::regclass)"));
									exprCache[def] = val;
								}
								def = val;
							}
						}
						else
						{
							def = wxEmptyString;
						}
					}
					nArgsIN--;
				}
				else if(function->GetConnection()->BackendMinimumVersion(8, 4) &&
				        function->GetArgModesArray()[index] == wxT("TABLE"))
				{
					if (strReturnTableArgs.Length() > 0)
						strReturnTableArgs += wxT(", ");
					wxString strName = function->GetArgNamesArray()[index];
					if (!strName.IsEmpty())
						strReturnTableArgs += qtIdent(strName) + wxT(" ");
					strReturnTableArgs += function->GetArgTypesArray()[index];
				}
				function->iAddArgDef(def);
			}

			function->iSetOid(functions->GetOid(wxT("oid")));
			function->iSetXid(functions->GetOid(wxT("xmin")));

			if (browser)
				function->UpdateSchema(browser, functions->GetOid(wxT("pronamespace")));

			function->iSetOwner(functions->GetVal(wxT("funcowner")));
			function->iSetAcl(functions->GetVal(wxT("proacl")));

			// set the return type only if not already set..
			if (function->GetReturnType().IsEmpty())
			{
				wxString strType = functions->GetVal(wxT("typname"));
				if (strType.Lower() == wxT("record") && !strReturnTableArgs.IsEmpty())
				{
					strType = wxT("TABLE(") + strReturnTableArgs + wxT(")");
				}
				function->iSetReturnType(strType);
			}
			function->iSetComment(functions->GetVal(wxT("description")));

			function->iSetLanguage(lanname);
			function->iSetSecureDefiner(functions->GetBool(wxT("prosecdef")));
			function->iSetReturnAsSet(functions->GetBool(wxT("proretset")));
			function->iSetIsStrict(functions->GetBool(wxT("proisstrict")));
			function->iSetSource(functions->GetVal(wxT("prosrc")));
			function->iSetBin(functions->GetVal(wxT("probin")));

			wxString vol = functions->GetVal(wxT("provolatile"));
			function->iSetVolatility(
			    vol.IsSameAs(wxT("i")) ? wxT("IMMUTABLE") :
			    vol.IsSameAs(wxT("s")) ? wxT("STABLE") :
			    vol.IsSameAs(wxT("v")) ? wxT("VOLATILE") : wxT("unknown"));

			// PostgreSQL 8.3 cost/row estimations
			if (obj->GetConnection()->BackendMinimumVersion(8, 3))
			{
				function->iSetCost(functions->GetLong(wxT("procost")));
				function->iSetRows(functions->GetLong(wxT("prorows")));
				wxString cfg = functions->GetVal(wxT("proconfig"));
				if (!cfg.IsEmpty())
					FillArray(function->GetConfigList(), cfg.Mid(1, cfg.Length() - 2));
			}

			if (obj->GetConnection()->BackendMinimumVersion(9, 1))
			{
				function->iSetProviders(functions->GetVal(wxT("providers")));
				function->iSetLabels(functions->GetVal(wxT("labels")));
			}

			if (obj->GetConnection()->BackendMinimumVersion(9, 2))
			{
				function->iSetIsLeakProof(functions->GetBool(wxT("proleakproof")));
			}

			if (browser)
			{
				browser->AppendObject(obj, function);
				functions->MoveNext();
			}
			else
				break;
		}

		delete functions;
		delete types;
	}
	return function;
}
/***************************************************************************
 ** ReadSites --
 **    This function asks the user for the name of the data
 ** file to be used, opens it, reads the website Addresses and
 ** sorts them. The totals are then computed and the tables printed using
 ** other functions within this one.
 **      Inputs: None
 **      Outputs: 4 arrays fll of websites and printed results.
 ***************************************************************************/
void ReadSites()
{
   FILE *ifp;
   char filename[SIZE] = "cat";
   char temp[SIZE] = "dog";
   int j = 0;

   /*The  four arrays are declared*/
   WEBSITE t, comSites[SIZE], govSites[SIZE], eduSites[SIZE], netSites[SIZE];

   int TotalNonUniqueSites = 0, TotalUniqueSites = 0, TotalTimeLogged = 0;
   int TotalFunSites = 0, TotalSearchSites = 0, TotalEducationSites = 0;
   int  TotalNewsSites = 0, *pTotalNewsSites, *pTotalNonUniqueSites;
   int *pTotalUniqueSites, *pTotalTimeLogged, *pTotalFunSites; 
   int *pTotalSearchSites, *pTotalEducationSites;

   /*The pointers are set to point to the their corresponding values*/
   pTotalNonUniqueSites = &TotalNonUniqueSites;
   pTotalUniqueSites = &TotalUniqueSites;
   pTotalTimeLogged = &TotalTimeLogged;
   pTotalFunSites = &TotalFunSites;
   pTotalSearchSites = &TotalSearchSites;
   pTotalEducationSites = &TotalEducationSites;
   pTotalNewsSites = &TotalNewsSites;

   /*The are filled with dummy values*/
   FillArray(comSites);
   FillArray(netSites);
   FillArray(eduSites);
   FillArray(govSites);

   /*Asks the user for the file name*/
   fprintf(stdout, "\nPlease enter the file name: ");
   fscanf(stdin, "%s", filename);
   ifp = fopen(filename, "r");

   /*If the file cannot exit and give error message*/
   if(ifp == NULL)
   {
      fprintf(stderr, "The file could not be opened.");
      exit(-1);
   }

   /*Scans every thing in the file until it reaches the end*/
   while(fscanf(ifp, "%s %s %d", temp, t.siteType, &t.seconds) != EOF)
     {
	/*Breaks the string temp  into access code, domain name*/
	/* and domain ending and stores the in the temporary structure*/
	t.webAddress = CreateAddress(temp);
	
	/*Depending on the first letter of the domain ending, stores*/
	/*them into the appropriate array*/
	if(t.webAddress.domainEnding[0] == 'c')
	{
	   /*Finds the index of wherever the website is supposed to go*/
	   j = IsPresent(comSites, t);
	   
	   /*Stores the website in the proper location*/
	   comSites[j].webAddress = t.webAddress;
	   
	   /*Stores the siteType in the corresponding location*/
	   strcpy(comSites[j].siteType, t.siteType);
	   
	   /*Adds the number of hits and the seconds*/
	   comSites[j].hits += 1;
	   comSites[j].seconds += t.seconds;
	} 
	else if(t.webAddress.domainEnding[0] == 'g')
	{
	   j = IsPresent(govSites, t);
	   
	   govSites[j].webAddress = t.webAddress;
	   strcpy(govSites[j].siteType, t.siteType);
	   govSites[j].hits += 1;
	   govSites[j].seconds += t.seconds;
	}
	else if(t.webAddress.domainEnding[0] == 'n')
	{
	   j = IsPresent(netSites, t);
	   
	   netSites[j].webAddress = t.webAddress;
	   strcpy(netSites[j].siteType, t.siteType);
	   netSites[j].hits += 1;
	   netSites[j].seconds += t.seconds;
	 }
       else
	 {
	   j = IsPresent(eduSites, t);
	   
	   eduSites[j].webAddress = t.webAddress;
	   strcpy(eduSites[j].siteType, t.siteType);
	   eduSites[j].hits += 1;
	   eduSites[j].seconds += t.seconds;
	 } 
     }  
   
   /*Sorts the arrays*/
   SortArray(eduSites, ArrayLength(eduSites));
   SortArray(govSites, ArrayLength(govSites));
   SortArray(comSites, ArrayLength(comSites));
   SortArray(netSites, ArrayLength(netSites));
   
   /*Computes the totals using data from all the arrays*/
   ComputeTotals(comSites, pTotalUniqueSites, pTotalNonUniqueSites,
		 pTotalTimeLogged, pTotalFunSites, pTotalSearchSites,
		 pTotalEducationSites, pTotalNewsSites);

   ComputeTotals(eduSites, pTotalUniqueSites, pTotalNonUniqueSites, 
		 pTotalTimeLogged, pTotalFunSites, pTotalSearchSites,
		 pTotalEducationSites, pTotalNewsSites);

   ComputeTotals(netSites, pTotalUniqueSites, pTotalNonUniqueSites,
		 pTotalTimeLogged, pTotalFunSites, pTotalSearchSites,
		 pTotalEducationSites, pTotalNewsSites);

   ComputeTotals(govSites, pTotalUniqueSites, pTotalNonUniqueSites,
		 pTotalTimeLogged, pTotalFunSites, pTotalSearchSites,
		 pTotalEducationSites, pTotalNewsSites);

   /*Prints the results of the read*/
   PrintTable(comSites, netSites, eduSites, govSites);
   
   /*Caclulates the percentages and prints them*/
   CalcStats(TotalUniqueSites, TotalFunSites, TotalSearchSites,
	     TotalNewsSites, TotalEducationSites, TotalTimeLogged,
	     TotalNonUniqueSites);
   
   return;
}
Example #21
0
pgObject *pgTablespaceFactory::CreateObjects(pgCollection *collection, ctlTree *browser, const wxString &restriction)
{
	pgTablespace *tablespace = 0;

	wxString tabname;

	pgSet *tablespaces;
	if (collection->GetConnection()->BackendMinimumVersion(9, 2))
		tablespaces = collection->GetServer()->ExecuteSet(
		                  wxT("SELECT ts.oid, spcname, pg_catalog.pg_tablespace_location(ts.oid) AS spclocation, spcoptions, ")
		                  wxT("pg_get_userbyid(spcowner) as spcuser, spcacl, ")
		                  wxT("pg_catalog.shobj_description(oid, 'pg_tablespace') AS description, ")
		                  wxT("(SELECT array_agg(label) FROM pg_shseclabel sl1 WHERE sl1.objoid=ts.oid) AS labels, ")
		                  wxT("(SELECT array_agg(provider) FROM pg_shseclabel sl2 WHERE sl2.objoid=ts.oid) AS providers ")
		                  wxT("FROM pg_tablespace ts\n")
		                  + restriction + wxT(" ORDER BY spcname"));
	else if (collection->GetConnection()->BackendMinimumVersion(8, 5))
		tablespaces = collection->GetServer()->ExecuteSet(
		                  wxT("SELECT ts.oid, spcname, spclocation, spcoptions, pg_get_userbyid(spcowner) as spcuser, spcacl, pg_catalog.shobj_description(oid, 'pg_tablespace') AS description FROM pg_tablespace ts\n")
		                  + restriction + wxT(" ORDER BY spcname"));
	else if (collection->GetConnection()->BackendMinimumVersion(8, 2))
		tablespaces = collection->GetServer()->ExecuteSet(
		                  wxT("SELECT ts.oid, spcname, spclocation, pg_get_userbyid(spcowner) as spcuser, spcacl, pg_catalog.shobj_description(oid, 'pg_tablespace') AS description FROM pg_tablespace ts\n")
		                  + restriction + wxT(" ORDER BY spcname"));
	else
		tablespaces = collection->GetServer()->ExecuteSet(
		                  wxT("SELECT ts.oid, spcname, spclocation, '' AS description, pg_get_userbyid(spcowner) as spcuser, spcacl FROM pg_tablespace ts\n")
		                  + restriction + wxT(" ORDER BY spcname"));

	if (tablespaces)
	{
		while (!tablespaces->Eof())
		{

			tablespace = new pgTablespace(tablespaces->GetVal(wxT("spcname")));
			tablespace->iSetServer(collection->GetServer());
			tablespace->iSetOid(tablespaces->GetOid(wxT("oid")));
			tablespace->iSetOwner(tablespaces->GetVal(wxT("spcuser")));
			tablespace->iSetLocation(tablespaces->GetVal(wxT("spclocation")));
			tablespace->iSetAcl(tablespaces->GetVal(wxT("spcacl")));
			if (collection->GetConnection()->BackendMinimumVersion(8, 2))
				tablespace->iSetComment(tablespaces->GetVal(wxT("description")));
			if (collection->GetConnection()->BackendMinimumVersion(8, 5))
			{
				wxString str = tablespaces->GetVal(wxT("spcoptions"));
				if (!str.IsEmpty())
					FillArray(tablespace->GetVariables(), str.Mid(1, str.Length() - 2));
			}
			if (collection->GetConnection()->BackendMinimumVersion(9, 2))
			{
				tablespace->iSetProviders(tablespaces->GetVal(wxT("providers")));
				tablespace->iSetLabels(tablespaces->GetVal(wxT("labels")));
			}

			if (browser)
			{
				browser->AppendObject(collection, tablespace);
				tablespaces->MoveNext();
			}
			else
				break;
		}

		delete tablespaces;
	}
	return tablespace;
}
Example #22
0
/**
 *  初期化
 *  Initialize the board.
 */
void Board::Clear() {

	// 黒番-> (my, her) = (1, 0), 白番 -> (0, 1).
	// if black's turn, (my, her) = (1, 0) else (0, 1).
	my = 1;
	her = 0;
	empty_cnt = 0;
	FillArray(sum_prob_rank, 0.0);
	FillArray(is_placed, false);
	FillArray(is_ptn_updated, false);

	for (int i=0;i<EBVCNT;++i) {

		next_ren_v[i] = i;
		ren_idx[i] = i;

		ren[i].SetNull();

		int ex = etox[i];
		int ey = etoy[i];

		// outer boundary
		if (ex == 0 || ex == EBSIZE - 1 || ey == 0 || ey == EBSIZE - 1) {
			color[i] = 1;
			empty_idx[i] = VNULL;	//442
			ptn[i].SetNull();		//0xffffffff

			prob[0][i] = prob[1][i] = 0;
		}
		// real board
		else {
			// empty vertex
			color[i] = 0;
			empty_idx[i] = empty_cnt;
			empty[empty_cnt] = i;
			++empty_cnt;
		}

	}

	for(int i=0;i<BVCNT;++i){

		int v = rtoe[i];

		ptn[v].Clear();	// 0x00000000

		// 周囲8点のcolorを登録する
		// Set colors around v.
		forEach8Nbr(v, v_nbr8, d_nbr, d_opp, {
			ptn[v].SetColor(d_nbr, color[v_nbr8]);
		});

		// 確率分布を初期化
		// Initialize probability distribution.

		// 評価値.着手確率 = prob[pl][v]/sum(prob[pl])
		// Probability. Selected probability = prob[pl][v]/sum(prob[pl])
		prob[0][v] = prob_dist_base[v] * ptn[v].GetProb3x3(0,false);
		prob[1][v] = prob_dist_base[v] * ptn[v].GetProb3x3(1,false);

		// 実盤面のn段目のprobの和
		// Sum of prob[pl][v] in the Nth rank on the real board.
		sum_prob_rank[0][rtoy[i]] += prob[0][v];
		sum_prob_rank[1][rtoy[i]] += prob[1][v];

	}