vs_integration/src/SocketConnection.cpp
//--------------------------------------------------------------------------------------------
// This fuction will execute the mrg_diff to create diff file.
//---------------------------------------------------------------------------------------------
This fuction will execute the mrg_diff to create diff file.
This fuction will execute the mrg_diff to create diff file .
int SocketConnection::MapLines(CString& localfile, CString& basefile, CString& diffile, int localline) {
STARTUPINFO si;
PROCESS_INFORMATION pi;
char* root;
CString cmd;
  root = getenv("CODE_ROVER_HOME");
  if(root==NULL) 
	  root = getenv("PSETHOME");
  if((root==NULL ) || (strlen(root)==0)) {
      cmd="C:/Discover/Bin/mrg_update";
  } else {
      cmd=root;
	  cmd+="/bin/mrg_update";
  }
  cmd.Replace("\\","/");
  cmd.Replace("//","/");
  if(cmd.Find(" ")>0) cmd="\""+cmd+"\"";
  cmd+=" -mapL_to_L ";
  CString num;
  num.Format("%d",localline);
  cmd+=num;
  cmd+=" ";
  cmd+="\"";
  cmd+=basefile;
  cmd+="\"";
  cmd+=" ";
  cmd+="\"";
  cmd+=diffile;
  cmd+="\"";
  cmd+=" ";
  cmd+="\"";
  cmd+=localfile;
  cmd+="\"";
  HANDLE ReadHandle;
  HANDLE WriteHandle;
  SECURITY_ATTRIBUTES sattr;
  memset(&sattr, 0, sizeof(sattr));
  sattr.nLength        = sizeof(sattr);
  sattr.bInheritHandle = TRUE;
  if(!CreatePipe(&ReadHandle, &WriteHandle, &sattr, 0)){
    return -1;
  }
  memset(&si,0,sizeof(STARTUPINFO));
  si.cb=sizeof(STARTUPINFO);
  si.hStdInput  = GetStdHandle(STD_INPUT_HANDLE);
  si.hStdOutput = WriteHandle;
  si.hStdError  = GetStdHandle(STD_ERROR_HANDLE);
  si.dwFlags    = STARTF_USESTDHANDLES;
  putenv("DIS_NLUNIXSTYLE=1");
  if(::CreateProcess(NULL,cmd.GetBuffer(10),NULL,NULL,TRUE,CREATE_NO_WINDOW,NULL,NULL,&si,&pi)==FALSE) {
	  return -1;
  }
  WaitForSingleObject(pi.hProcess,INFINITE);
  char lineStr[200];
  unsigned long readed;
  DWORD lo;
  DWORD hi;
  int count=0;
  do {
      lo=GetFileSize(ReadHandle,&hi);
	  if(hi>0 || lo>0) break;
	  Sleep(50);
	  count++;
  } while(hi==0 && lo==0 && count<5);
  if(hi==0 && lo==0) return localline;
  ReadFile(ReadHandle,lineStr,200,&readed,NULL);
  lineStr[readed-2]=0;
  CloseHandle(pi.hProcess);
  CloseHandle(ReadHandle);
  CloseHandle(WriteHandle);
  return atoi(lineStr);
}
int SocketConnection :: MapLines ( CString & localfile , CString & basefile , CString & diffile , int localline ) { STARTUPINFO si ; PROCESS_INFORMATION pi ; char * root ; CString cmd ; root = getenv ( " " ) ; if ( root == NULL ) root = getenv ( " " ) ; if ( ( root == NULL ) || ( strlen ( root ) == 0 ) ) { cmd = " " ; } else { cmd = root ; cmd += " " ; } cmd . Replace ( " \\ " , " " ) ; cmd . Replace ( " " , " " ) ; if ( cmd . Find ( " " ) > 0 ) cmd = " \" " + cmd + " \" " ; cmd += " " ; CString num ; num . Format ( " " , localline ) ; cmd += num ; cmd += " " ; cmd += " \" " ; cmd += basefile ; cmd += " \" " ; cmd += " " ; cmd += " \" " ; cmd += diffile ; cmd += " \" " ; cmd += " " ; cmd += " \" " ; cmd += localfile ; cmd += " \" " ; HANDLE ReadHandle ; HANDLE WriteHandle ; SECURITY_ATTRIBUTES sattr ; memset ( & sattr , 0 , sizeof ( sattr ) ) ; sattr . nLength = sizeof ( sattr ) ; sattr . bInheritHandle = TRUE ; if ( ! CreatePipe ( & ReadHandle , & WriteHandle , & sattr , 0 ) ) { return -1 ; } memset ( & si , 0 , sizeof ( STARTUPINFO ) ) ; si . cb = sizeof ( STARTUPINFO ) ; si . hStdInput = GetStdHandle ( STD_INPUT_HANDLE ) ; si . hStdOutput = WriteHandle ; si . hStdError = GetStdHandle ( STD_ERROR_HANDLE ) ; si . dwFlags = STARTF_USESTDHANDLES ; putenv ( " " ) ; if ( :: CreateProcess ( NULL , cmd . GetBuffer ( 10 ) , NULL , NULL , TRUE , CREATE_NO_WINDOW , NULL , NULL , & si , & pi ) == FALSE ) { return -1 ; } WaitForSingleObject ( pi . hProcess , INFINITE ) ; char lineStr [ 200 ] ; unsigned long readed ; DWORD lo ; DWORD hi ; int count = 0 ; do { lo = GetFileSize ( ReadHandle , & hi ) ; if ( hi > 0 || lo > 0 ) break ; Sleep ( 50 ) ; count ++ ; } while ( hi == 0 && lo == 0 && count < 5 ) ; if ( hi == 0 && lo == 0 ) return localline ; ReadFile ( ReadHandle , lineStr , 200 , & readed , NULL ) ; lineStr [ readed - 2 ] = 0 ; CloseHandle ( pi . hProcess ) ; CloseHandle ( ReadHandle ) ; CloseHandle ( WriteHandle ) ; return atoi ( lineStr ) ; }
This fuction will execute the mrg_diff to create diff file.
This fuction will execute the mrg_diff to create diff file .