Beispiel #1
0
// Retrieve a list of key names of the specified section
void CIni::GetKeyNames(LPCTSTR lpSection, CStringArray *pArray) const
{
	if (pArray == NULL)
		return;

	pArray->RemoveAll();
	const DWORD LEN = GetKeyNames(lpSection, NULL, 0);
	LPTSTR psz = new TCHAR[LEN + 1];
	GetKeyNames(lpSection, psz, LEN);
	ParseDNTString(psz, __SubStrAdd, (LPVOID)pArray);
	delete [] psz;
}
Beispiel #2
0
static void
ParseKeyBindings (xmlDocPtr doc, xmlNodePtr node)
{
	xmlNodePtr keynode,
		   dnode;
	xmlChar* value;

	dnode = node->xmlChildrenNode;
	KeyName *knames = GetKeyNames ();
	PlayerCommand *cmds = GetPlayerCommands ();
	InputDevice *dev;
	DeviceName *devnames = GetDeviceNames ();
	while (dnode != NULL)
	{
		for (int d=0; devnames[d].name;d++)
		{
			if ((!xmlStrcmp (dnode->name, (xmlChar*)devnames[d].name)))
			{
				keynode = dnode->xmlChildrenNode;
				while (keynode != NULL)
				{

					int a=0;
					while (cmds[a].name)
					{
						if ((!xmlStrcmp (keynode->name, (xmlChar*)cmds[a].name)))
						{
							value = xmlNodeListGetString (doc, keynode->xmlChildrenNode, 1);
							int k = 0;
							int key = -1;
							dev = GetInputDevice(devnames[d].type);
							KeyBinding *binds = dev->bindings;
							if (devnames[d].type < JOYSTICK1) // keyboard
							{
								while (knames[k].name)
								{
									if ((!xmlStrcmp (value, (xmlChar*)knames[k].name)))
									{
										key = knames[k].key;
										break;
									}
									k++;
								}
							}
							else // joystick
							{
								if (!xmlStrcmp(value,(xmlChar*)"left"))
									key = JOY_LEFT;
								else if (!xmlStrcmp(value,(xmlChar*)"right"))
									key = JOY_RIGHT;
								else if (!xmlStrcmp(value,(xmlChar*)"down"))
									key = JOY_DOWN;
								else if (!xmlStrcmp(value,(xmlChar*)"up"))
									key = JOY_UP;
								else
								{
									key = atoi ((char*)value);
									if (key >= NUM_JOYBUTTONS)
										key = -1;
								}
							}
							if (key != -1)
							{
								if (binds[a].key1 < 0)
									binds[a].key1 = key;
								else binds[a].key2 = key;
							}
							if (value) xmlFree (value);


							break;
						}
						a++;
					}
					keynode = keynode->next;
				}

				break;
			}
		}
		dnode = dnode->next;
	}
}
Beispiel #3
0
int main(int argc, char* const argv[])
{
	int i;
	char szSimFindIni[MAX_PATH];
	char szTable[MAX_PATH];
	char szOutFile[MAX_PATH];
	char szStatFile[MAX_PATH];
	char szMatchFile[MAX_PATH];
	
#ifdef __APPLE__
	g_bMac = true;
#endif

	// Read specs for run out of INI file
	if (argc > 1)
		strcpy(szSimFindIni, argv[1]);
	else if (g_bMac)
		sprintf(szSimFindIni, "/Users/ipye/Desktop/cmps221/1_hashproj/sub/simhash/MacFind.ini");
	else
		sprintf(szSimFindIni, "WinFind.ini");


	FILE* fp = fopen(szSimFindIni, "rt");
	if (fp == NULL)
	{
		printf("main: failed to load %s\n", szSimFindIni);
		return 1;
	}

	if ((fscanf(fp, "Table=%s\n", szTable) != 1) ||
		(fscanf(fp, "Keys=%d\n", &g_nKeys) != 1) ||
		(fscanf(fp, "OutFile=%s\n", szOutFile) != 1) ||
		(fscanf(fp, "StatFile=%s\n", szStatFile) != 1) ||
		(fscanf(fp, "MatchFile=%s\n", szMatchFile) != 1) ||
		(fscanf(fp, "Tolerance=%f\n", &g_fSumToler) != 1) )
	{
		printf("main: Invalid INI file '%s'\n", szSimFindIni);
		return 1;
	}
	fclose(fp);
	COL_TAG1 = COL_KEY1 + g_nKeys;
	g_pnKeyHits = (int*) calloc(g_nKeys, sizeof(int));
	g_pnCollisions = (int*) calloc(g_nKeys, sizeof(int));
	g_pnSumHits = (int*) calloc(g_nKeys, sizeof(int));

	// Open output file for writing
	if (g_bReportAll)
	{
		fp = fopen(szOutFile, "wt");
		if (fp == NULL)
		{
			printf("main: failed to open '%s'\n", szOutFile);
			return false;
		}
	}
	
	// Open statt file for writing
	FILE* fp2 = fopen(szStatFile, "wt");
	if (fp2 == NULL)
	{
		fclose(fp);
		printf("main: failed to open '%s'\n", szStatFile);
		return false;
	}

	// Open two needed db connections
	g_pdbcon1 = new mysqlpp::Connection(mysqlpp::use_exceptions);
	g_pdbcon2 = new mysqlpp::Connection(mysqlpp::use_exceptions);
	g_pdbcon1->connect(MYSQL_DATABASE, MYSQL_HOST, MYSQL_USER, MYSQL_PASS);
	g_pdbcon2->connect(MYSQL_DATABASE, MYSQL_HOST, MYSQL_USER, MYSQL_PASS);

	// Print header for stats file
	GetKeyNames(szTable);
	fprintf(fp2, "# Table = '%s'\n", szTable);
	fprintf(fp2, "# TOLERANCE ");
	for (i = 0; i < g_nKeys; i++)
		fprintf(fp2, "%s SUMHITS ", g_vStrKeys[i].c_str());
	fprintf(fp2, "\n");
	//fprintf(fp2, "SUMHITS\n");

	// Loop through tolerance values (given in percents)
	//float afTols[] = { 3.2f, 1.0f, 0.32f, 0.1f, 0.032f, 0.01f };
	//float afTols[] = {.32f};
	//float afTols[] = { .01f, .02f, .04f, .08f, .16f, .32f, .64f, 1.28f, 2.56f, 5.12f };
	//for (i = 0; i < sizeof(afTols)/sizeof(float); i++)  
	for (float j = .01; j < 6; j*=1.2)
	{
		ResetCounters(true);
		//g_fSumToler = afTols[i];
		g_fSumToler = j;
		fprintf(fp2, "%8f  ", g_fSumToler);
		
		for (g_i = g_nKeys - 1 ; g_i < g_nKeys; g_i++) //skip every other key w +=2
		{
			ResetCounters(false);
			// Find file similarities
			if (strlen(szMatchFile) > 1)
				FindSimilaritiesForOne(fp, szTable, szMatchFile);
			else
				FindSimilaritiesForAll(fp, szTable);
			fprintf(fp2, "%8d ", g_pnKeyHits[g_i]);
			fprintf(fp2, "%8d ", g_pnSumHits[g_i]);
			
			if (g_bReport)
				printf("Tolerance = %f, Key = : %d\n", g_fSumToler, g_i+1);
		}
		fprintf(fp2, "\n");
	}
	
	fprintf(fp2, "\n# Rows = %d\n", g_nRows);
	fprintf(fp2, "# Total Size = %d\n", g_nDataSize);
	fprintf(fp2, "# Identical = %d\n", g_nIdentical);
	for (i = 0; i < g_nKeys; i++)
		fprintf(fp2, "# '%s' Collisions = %d\n", g_vStrKeys[i].c_str(), g_pnCollisions[i]);

	fclose(fp);
	fclose(fp2);
	delete g_pdbcon1;
	delete g_pdbcon2;
	free(g_pnKeyHits);
	free(g_pnCollisions);
	return 0;
}