Esempio n. 1
0
bool WinClipboard::getString(StringStorage *str)
{
  UINT strType = CF_UNICODETEXT;

  if (sizeof(TCHAR) == 1) {
    strType = CF_TEXT;
  }
  int uFormat = GetPriorityClipboardFormat(&strType, sizeof(UINT));

  if (uFormat == 0 || uFormat == -1) {
     return false;
  }
  if (OpenClipboard(m_hWnd)) {
     HANDLE hndData = GetClipboardData(uFormat); 

     if (hndData) {
        TCHAR *szData = (TCHAR *)GlobalLock(hndData); 
        StringStorage nativeClipboard = szData;
        //str->setString(szData);
        GlobalUnlock(hndData); 
        CloseClipboard();
        *str = removeCR(&nativeClipboard);
        return true;
      }
    CloseClipboard();
    return false;
  }
  return false;
}
Esempio n. 2
0
int main()
{
	FILE *fp;
	char dict[][50] = {"ChineseFamilyNames","CountryNames","FemaleFirstNames",
			"FuncWord","MaleFirstNames","Months","PlaceNames","PublisherNames","CityNames"};
	char valdict[50] = "LastNames";
	char fileName[1024];
	char data[1024];
	char name[1024];
	double val;
	dbConnect();
	
	dbLock();
	dbCreateTable();
	int i;
	for(i=0;i<9;i++)
	{
		sprintf(fileName,"res/%s",dict[i]);
		fp = fopen(fileName,"r");
		while(fgets(data,1024,fp))
		{
			dbAddNameDict(dict[i],removeCR(data));
			//printf("[%s]\n",removeCR(data));
		}
		fclose(fp);
	}
	sprintf(fileName,"res/%s",valdict);
	fp = fopen(fileName,"r");
	while(fgets(data,1024,fp))
	{
		spilitVal(name,&val,data);
		dbAddValDict(valdict,name,val);
		//printf("[%s]|[%f]\n",name,val);
	}
	dbUnlock();
	fclose(fp);
	
	//////////////////////////////////////////////////////////////
	// boolean
	printf("CityNames,abidjan:%d\n",dbGetNameLikeDict("CityNames","abigail"));
	printf("FemaleFirstNames,abigail:%d\n",dbGetNameDict("FemaleFirstNames","abigail"));
	printf("FemaleFirstNames,Abigail:%d\n",dbGetNameLikeDict("FemaleFirstNames","Abigail"));
	// double
	printf("LastNames,wilson:%f\n",dbGetValDict("LastNames","wilson"));
	printf("LastNames,Wilson:%f\n",dbGetValLikeDict("LastNames","Wilson"));
	//////////////////////////////////////////////////////////////
	
	dbFree();
	
	return 0;
}
Esempio n. 3
0
int CMUSkeleton::readASFfile(const char* asf_filename, double scale)
{
  //open file
  std::ifstream is(asf_filename, std::ios::in);
  if (is.fail()) 
    return -1;

  //
  // ignore header information
  //
  char str[2048], keyword[256];
  while (1)
  {
    is.getline(str, 2048);	
    removeCR(str);
    sscanf(str, "%s", keyword);
    if (strcmp(keyword, ":bonedata") == 0)	
      break;
  }

  //
  // read bone information: global orientation and translation, DOF.
  //
  is.getline(str, 2048);
  removeCR(str);
  char	part[256], *token;
  double length;

  bool done = false;
  for(int i = 1; (!done) && (i < MAX_BONES_IN_ASF_FILE); i++)
  {
    m_pBoneList[i].dof=0;
    m_pBoneList[i].dofrx = m_pBoneList[i].dofry = m_pBoneList[i].dofrz = 0;
    m_pBoneList[i].doftx = m_pBoneList[i].dofty = m_pBoneList[i].doftz = 0;
    m_pBoneList[i].doftl = 0;
    m_pBoneList[i].sibling = NULL; 
    m_pBoneList[i].child = NULL;
    NUM_BONES_IN_ASF_FILE++;
    MOV_BONES_IN_ASF_FILE++;
    while(1)
    {
      is.getline(str, 2048);	
      removeCR(str);
      sscanf(str, "%s", keyword);

      if(strcmp(keyword, "end") == 0) 
	break; 

      if(strcmp(keyword, ":hierarchy") == 0) 
      { 
	MOV_BONES_IN_ASF_FILE -= 1; 
	NUM_BONES_IN_ASF_FILE -= 1; 
	done=true; 
	break; 
      }

      //id of bone
      if(strcmp(keyword, "id") == 0)
        m_pBoneList[i].idx = NUM_BONES_IN_ASF_FILE-1;

      //name of the bone
      if(strcmp(keyword, "name") == 0) 
      {
        sscanf(str, "%s %s", keyword, part);
        sscanf(str, "%s %s", keyword, m_pBoneList[i].name);
      }

      //this line describes the bone's direction vector in global coordinates
      //it will later be converted to local coorinate system
      if(strcmp(keyword, "direction") == 0)  
        sscanf(str, "%s %lf %lf %lf", keyword, &m_pBoneList[i].dir[0], &m_pBoneList[i].dir[1], &m_pBoneList[i].dir[2]);

      //length of the bone
      if(strcmp(keyword, "length") == 0)  
        sscanf(str, "%s %lf", keyword, &length);

      //this line describes the orientation of bone's local coordinate 
      //system relative to the world coordinate system
      if(strcmp(keyword, "axis") == 0)      
        sscanf(str, "%s %lf %lf %lf", keyword, &m_pBoneList[i].axis_x, &m_pBoneList[i].axis_y, &m_pBoneList[i].axis_z);

      // this line describes the bone's dof 
      if(strcmp(keyword, "dof") == 0)       
      {
        token=strtok(str, " "); 
        m_pBoneList[i].dof=0;
        while(token != NULL)      
        {
          int tdof = m_pBoneList[i].dof;

          if(strcmp(token, "rx") == 0) { m_pBoneList[i].dofrx = 1; m_pBoneList[i].dofo[tdof] = 1; }
          else if(strcmp(token, "ry") == 0) { m_pBoneList[i].dofry = 1; m_pBoneList[i].dofo[tdof] = 2; }
          else if(strcmp(token, "rz") == 0) { m_pBoneList[i].dofrz = 1; m_pBoneList[i].dofo[tdof] = 3; }
          else if(strcmp(token, "tx") == 0) { m_pBoneList[i].doftx = 1; m_pBoneList[i].dofo[tdof] = 4; }
          else if(strcmp(token, "ty") == 0) { m_pBoneList[i].dofty = 1; m_pBoneList[i].dofo[tdof] = 5; }
          else if(strcmp(token, "tz") == 0) { m_pBoneList[i].doftz = 1; m_pBoneList[i].dofo[tdof] = 6; }
          else if(strcmp(token, "l") == 0)  { m_pBoneList[i].doftl = 1; m_pBoneList[i].dofo[tdof] = 7; }
          else if(strcmp(token, "dof") == 0) { goto end; }
          else { printf("UNKNOWN %s\n",token); }

          m_pBoneList[i].dof++;
          m_pBoneList[i].dofo[m_pBoneList[i].dof] = 0;
          end:
            token=strtok(NULL, " ");
        }
        printf("Bone %d DOF: ",i);
        for (int x = 0; (x < 7) && (m_pBoneList[i].dofo[x] != 0); x++) 
	  printf("%d ",m_pBoneList[i].dofo[x]);
        printf("\n");
      }
    }

    //store all the info we read from the file into the data structure
    //		m_pBoneList[i].idx = name2idx(part);
    if ((!m_pBoneList[i].dofrx) && (!m_pBoneList[i].dofry) && (!m_pBoneList[i].dofrz))
      MOV_BONES_IN_ASF_FILE -= 1;
    m_pBoneList[i].length = length * scale;
  }
  printf("READ %d\n",NUM_BONES_IN_ASF_FILE);

  //
  //read and build the hierarchy of the skeleton
  //
  char *part_name;
  int j, parent = 0;

  //find "hierarchy" string in the ASF file
  /*	while(1)
  {
  is.getline(str, 2048);	sscanf(str, "%s", keyword);
  if(strcmp(keyword, ":hierarchy") == 0)	
  break;
  } */

  //skip "begin" line
  is.getline(str, 2048);
  removeCR(str);

  //Assign parent/child relationship to the bones
  while(1)
  {
    //read next line
    is.getline(str, 2048);	
    removeCR(str);

    sscanf(str, "%s", keyword);

    //check if we are done
    if(strcmp(keyword, "end") == 0)   
      break;
    else
    {
      //parse this line, it contains parent followed by children
      part_name=strtok(str, " ");
      j=0;
      while(part_name != NULL)
      {
        if(j==0) 
          parent=name2idx(part_name);
        else 
          setChildrenAndSibling(parent, &m_pBoneList[name2idx(part_name)]);
        part_name=strtok(NULL, " ");
        j++;
      }
    }
  }

  is.close();

  return 0;
}
int main(int argc, char * argv[])
{
	int i;

	double lossRate;

	TCHAR temp[STR_SIZE]; //used for conversion from char to TCHAR whenever is needed
	char  tempChar[STR_SIZE];

	HANDLE hFileMailBoxOut[NUM_ROPE_PMF];/*handles for mail boxes so that we can communicate with child proesses*/
	HANDLE hFileMailBoxIn[NUM_ROPE_PMF];

	STARTUPINFO si[NUM_ROPE_PMF];
	PROCESS_INFORMATION pi[NUM_ROPE_PMF];

	char ropePMFConfigFiles[NUM_ROPE_PMF][STR_SIZE];
	char sharedMemNames[NUM_ROPE_PMF][STR_SIZE];
	char mailBoxNamesOut[NUM_ROPE_PMF][STR_SIZE];
	char mailBoxNamesIn[NUM_ROPE_PMF][STR_SIZE];
	char VSconfigFileName[STR_SIZE];

	char cmdLine[NUM_ROPE_PMF][STR_SIZE];
	char cmdLineVS[STR_SIZE];

	FILE *configFile;

	int frameCounter=0;

	if(argc!=3)
	{
		printf("oldesv.exe [configFile] [lossRAte]");
		return -1;
	}

	/*get the loss rate*/
	lossRate = atof(argv[2]);

	/*open the config file for reading*/
	configFile = fopen(argv[1],"rt");
	if(!configFile)
	{
		printf("Error opening config file %s\n",argv[1]);
		return -1;
	}
	/*get the config file names*/
	for(i=0; i<NUM_ROPE_PMF; i++)
	{
		fgets(ropePMFConfigFiles[i], STR_SIZE, configFile);
		removeCR(ropePMFConfigFiles[i], STR_SIZE);
	}
	/*get the share memory names*/
	for(i=0; i<NUM_ROPE_PMF; i++)
	{
		fgets(sharedMemNames[i], STR_SIZE, configFile);
		removeCR(sharedMemNames[i], STR_SIZE);
	}
	/*get the mail box names*/
	for(i=0; i<NUM_ROPE_PMF; i++)
	{
		fgets(mailBoxNamesOut[i], STR_SIZE, configFile);
		removeCR(mailBoxNamesOut[i], STR_SIZE);
		sprintf(tempChar, "\\\\.\\mailslot\\%s", mailBoxNamesOut[i]);
		sprintf(mailBoxNamesOut[i], "%s", tempChar);

		fgets(mailBoxNamesIn[i], STR_SIZE, configFile);
		removeCR(mailBoxNamesIn[i], STR_SIZE);
		sprintf(tempChar, "\\\\.\\mailslot\\%s", mailBoxNamesIn[i]);
		sprintf(mailBoxNamesIn[i], "%s", tempChar);
	}
	/*get the VS config file name*/
	fgets(VSconfigFileName, STR_SIZE, configFile);
	removeCR(VSconfigFileName, STR_SIZE);
	/*close the config file*/
	fclose(configFile);
	
	/*create the incoming mail boxes first before launching the child processes*/
	for(i=0; i<NUM_ROPE_PMF; i++)
	{
		/*create the incoming mail boxes*/
		charToTCHAR(temp, mailBoxNamesIn[i]);
		printf("Main process(%d): incoming mail box:%s\n",GetCurrentProcessId(),mailBoxNamesIn[i]);//debug
		hFileMailBoxIn[i] = CreateMailslot(temp, 
			0,                             // no maximum message size 
			MAILSLOT_WAIT_FOREVER,         // no time-out for operations 
			(LPSECURITY_ATTRIBUTES) NULL); // default security
 
		if (hFileMailBoxIn[i] == INVALID_HANDLE_VALUE) 
		{ 
			printf("CreateMailslot failed with %d\n", GetLastError());
			return -1; 
		}
	}

	/*get the command line ready*/
	for(i=0; i<NUM_ROPE_PMF; i++)
	{
		/*the first two encoders are for the texture*/
		if(i<=1)
		{
			sprintf(cmdLine[i],"lencod_t.exe -f %s %f %s %s %s", ropePMFConfigFiles[i], lossRate, sharedMemNames[i], mailBoxNamesOut[i], mailBoxNamesIn[i]);
		}
		else
		{
			sprintf(cmdLine[i],"lencod_d.exe -f %s %f %s %s %s", ropePMFConfigFiles[i], lossRate, sharedMemNames[i], mailBoxNamesOut[i], mailBoxNamesIn[i]);
		}
	}

	/*launch the processes*/
	for(i=0; i<NUM_ROPE_PMF; i++)
	{
		ZeroMemory( &si[i], sizeof(si[i]) );
		si[i].cb = sizeof(si[i]);
		ZeroMemory( &pi[i], sizeof(pi[i]) );
		charToTCHAR(temp, cmdLine[i]);
		// Start the child process. 
		if( !CreateProcess( NULL,   // No module name (use command line)
			temp,        // Command line
			NULL,           // Process handle not inheritable
			NULL,           // Thread handle not inheritable
			FALSE,          // Set handle inheritance to FALSE
			0,              // No creation flags
			NULL,           // Use parent's environment block
			NULL,           // Use parent's starting directory 
			&si[i],            // Pointer to STARTUPINFO structure
			&pi[i] )           // Pointer to PROCESS_INFORMATION structure
		) 
		{
			printf( "CreateProcess failed (%d).\n", GetLastError() );
			return -1;
		}
	}
	printf("Main process(%d): child processes launched\n",GetCurrentProcessId());


	/*give it some time for the child processes to create the mail boxes*/
	Sleep(6000);
	for(i=0; i<NUM_ROPE_PMF; i++)
	{
		/*create the outgoing mail boxes*/
		charToTCHAR(temp, mailBoxNamesOut[i]);
		printf("Main process(%d): outgoing mail box:%s\n",GetCurrentProcessId(),mailBoxNamesOut[i]);//debug
		hFileMailBoxOut[i] = CreateFile(temp, 
		 GENERIC_WRITE, 
		 FILE_SHARE_READ,
		 (LPSECURITY_ATTRIBUTES) NULL, 
		 OPEN_EXISTING, 
		 FILE_ATTRIBUTE_NORMAL, 
		 (HANDLE) NULL); 
		
		if (hFileMailBoxOut[i] == INVALID_HANDLE_VALUE) 
	    { 
		   printf("CreateFile failed with %d.\n", GetLastError()); 
		   return -1; 
	    }
	}
	printf("Main process(%d): outgoing mail boxes linked\n",GetCurrentProcessId());


	/*main task loop*/
	while(1)
	{
		int frameFinishFlag=0;
		int sequenceFinishFlag=0;
		int message;

		//Sleep(5000);//debug
		//printf("Main process(%d): child processes kicked wait for 5 seconds and then start checking for return messages........\n",GetCurrentProcessId());//debug
		//printf("\nPress enter for next frame\n");//debug
		//getchar();//debug

		/*kick the child processes going*/
		message = MSG_START_FRAME;
		for(i=0; i<NUM_ROPE_PMF; i++)
		{
			msgSend(hFileMailBoxOut[i], &message, sizeof(int));
		}

		/*get responses from the child processes*/
		while(1)
		{
			for(i=0; i<NUM_ROPE_PMF; i++)
			{
				message = msgRead(hFileMailBoxIn[i]);
				if(message==MSG_FRAME_FINISHED)
				{
					frameFinishFlag++;
				}
				else if(message==MSG_SEQUENCE_FINISHED)
				{
					sequenceFinishFlag++;
				}
				else if(message==MSG_NO_MESSAGE)
				{
				}
				else
				{
					printf("Unexpected message\n");
					exit(0);
				}
			}

			/*if all child processes have finished then we exit otherwise we wait for 200ms and then check again*/
			if((frameFinishFlag==NUM_ROPE_PMF) || (sequenceFinishFlag==NUM_ROPE_PMF))
			{
				printf("Main process(%d): frame finish or sequence finish\n",GetCurrentProcessId());//debug
				break;
			}
			Sleep(200);
		}
		if(sequenceFinishFlag==NUM_ROPE_PMF)
		{
			printf("Main process(%d): sequence finish\n",GetCurrentProcessId());//debug
			break;
		}
		else
		{
			int ret;
			/*view synthesizer can be launched using a blocking system call*/
			/*view synthesizer just need to run for a single frame*/
			sprintf(cmdLineVS,"ViewSynVC8d.exe %s %d %s %s %s %s", VSconfigFileName, frameCounter, sharedMemNames[0], sharedMemNames[1], sharedMemNames[2], sharedMemNames[3]);
			ret = system(cmdLineVS);
			if(ret!=0)
			{
				printf("Error lanching the view synthesizer\n");
				exit(0);
			}

			/*open the distortion file and save the distortion*/
			frameDistortionFile = fopen("singleFrameDistortionFile.bin","rb");
			if(frameDistortionFile == NULL)
			{
				printf("Error opening distortion file\n");
				exit(0);
			}
			fread(&frameDistortion[frameCounter],sizeof(double),1,frameDistortionFile);
			fclose(frameDistortionFile);
		}
		frameCounter++;
	}


	/*wait until the child processes finish*/
	for(i=0; i<NUM_ROPE_PMF; i++)
	{
		// Wait until child process exits.
		WaitForSingleObject( pi[i].hProcess, INFINITE );
		// Close process and thread handles. 
		CloseHandle( pi[i].hProcess );
		CloseHandle( pi[i].hThread );
	}
	printf("Main process(%d): Child processes finished\n",GetCurrentProcessId());

	/*close the handles for the mail boxes*/
	for(i=0; i<NUM_ROPE_PMF; i++)
	{
		CloseHandle(hFileMailBoxOut[i]);
		CloseHandle(hFileMailBoxIn[i]);
	}
	printf("Main process(%d): mail boxes closed\n",GetCurrentProcessId());
	
	/*print the distortions*/
	for(i=0; i<frameCounter; i++)
	{
		printf("Frame:%d distortion:%f\n",i,frameDistortion[i]);
	}
	return 0;
}