Пример #1
0
// Test -  char* StringUppercase(char* string0);
void Test7(StringOO& stringObj)
{
	const char * resultStr = "HELLO WORLD";
	const char * uppercaseStr = stringObj.StringUppercase(stringObj);

	if (strcmp(uppercaseStr, resultStr) == 0)
	{
		PrintOut("Test 6", "StringUppercase", "Successful");
	}
	else
	{
		PrintOut("Test 6", "StringUppercase", "Failed");
	}
}
Пример #2
0
// Test -  char* FindInString(char* string1, char* string2);
void Test8(StringOO& stringObj)
{
	StringOO stringObj2 = "world";
	bool result = stringObj.FindInString(stringObj, stringObj2);

	if (result)
	{
		PrintOut("Test 6", "StringUppercase", "Successful");
	}
	else
	{
		PrintOut("Test 6", "StringUppercase", "Failed");
	}
}
Пример #3
0
// Test -  char* StringPrepend(char* string1, char* string2);
void Test4(StringOO& stringObj1, StringOO& stringObj2)
{
	StringOO resultStr = "hello world";
	StringOO prependedStr = stringObj1.StringPrepend(stringObj1, stringObj2);

	if (stringObj1.StringCompare(prependedStr, resultStr))
	{
		PrintOut("Test 4", "StringPrepend", "Successful");
	}
	else
	{
		PrintOut("Test 4", "StringPrepend", "Failed");
	}
}
Пример #4
0
// Test -  char* StringCstyle(char* string0);
void Test5(StringOO& stringObj)
{
	const char * resultStr = "hello world";
	const char * cstyleStr = stringObj.StringCstyle(stringObj);

	if (strcmp(cstyleStr, resultStr) == 0)
	{
		PrintOut("Test 5", "StringCstyle", "Successful");
	}
	else
	{
		PrintOut("Test 5", "StringCstyle", "Failed");
	}
}
Пример #5
0
// Test -  char* StringLowercase(char* string0);
void Test6(StringOO& stringObj)
{
	const char * resultStr = "hello world";
	const char * lowercaseStr = stringObj.StringLowercase(stringObj);

	if (strcmp(lowercaseStr, resultStr) == 0)
	{
		PrintOut("Test 6", "StringLowercase", "Successful");
	}
	else
	{
		PrintOut("Test 6", "StringLowercase", "Failed");
	}
}
Пример #6
0
void Symbols::ResolveSearchPath( )
{
    CString searchPath;
    LRESULT lRet;
    HKEY hKey = NULL;

    //C:\Users\User\AppData\Local\Temp\SymbolCache
    for (int i = 14; i >= 8; i--)
    {
        CString regPath = _T( "Software\\Microsoft\\VisualStudio\\" );
        wchar_t version[4];
        _itow_s( i, version, 10 );

        #ifdef UNICODE
        regPath.Append( version );
        #else
        regPath.Append( CW2A( version ) );
        #endif

        regPath.Append( _T( ".0\\Debugger" ) );

        lRet = RegOpenKeyEx( HKEY_CURRENT_USER, regPath.GetString( ), 0, KEY_READ, &hKey );
        if (hKey)
        {
            TCHAR szBuffer[MAX_PATH];
            DWORD dwBufferSize = MAX_PATH;
            lRet = RegQueryValueEx( hKey, _T( "SymbolCacheDir" ), 0, NULL, (LPBYTE)szBuffer, &dwBufferSize );
            if (lRet == ERROR_SUCCESS && szBuffer)
            {
                searchPath = szBuffer;
                RegCloseKey( hKey );
                break;
            }
            RegCloseKey( hKey );
        }
    }

    if (!searchPath.IsEmpty( ))
    {
        m_strSearchPath.Format( _T( "srv*%s*http://msdl.microsoft.com/download/symbols" ), searchPath.GetString( ) );
        PrintOut( _T( "Symbol server path found from Visual Studio config: %s" ), searchPath.GetString( ) );
    }
    else
    {
        TCHAR szWindowsDir[MAX_PATH];
        GetCurrentDirectory( MAX_PATH, szWindowsDir );
        m_strSearchPath.Format( _T( "srv*%s\\symbols*http://msdl.microsoft.com/download/symbols" ), szWindowsDir );
        PrintOut( _T( "Symbol server path not found, using windows dir: %s" ), szWindowsDir );
    }
}
Пример #7
0
// Test - char FindCharacter(char* string0);
void Test1(StringOO& stringObj)
{
	int index = 6;
	char letter = ' ';
	letter = stringObj.FindCharacter(stringObj, index);

	if (letter == 'w')
	{
		PrintOut("Test 1", "FindCharacter", "Successful");
	}
	else
	{
		PrintOut("Test 1", "FindCharacter", "Failed");
	}
}
Пример #8
0
// Test -  int StringLength(char* string0);
void Test0(StringOO& stringObj)
{
	int length = 0;
	length = stringObj.StringLength(stringObj);

	// expected string object legth is 11
	if (length > 0 && length == 11)
	{
		PrintOut("Test 0", "StringLength", "Successful");
	}
	else
	{
		PrintOut("Test 0", "StringLength", "Failed");
	}	
}
Пример #9
0
CStringW ReadMemoryStringW( size_t address, SIZE_T max )
{
	auto buffer = std::make_unique<wchar_t[ ]>( max + 1 );
	SIZE_T bytesRead;

	if ( ReadMemory( (PVOID) address, buffer.get( ), max * sizeof( wchar_t ), &bytesRead ) != 0 )
	{
		bytesRead /= sizeof( wchar_t );
		
		for ( int i = 0; i < bytesRead; i++ )
		{
			if ( !( iswprint( buffer[ i ] ) ) && buffer[ i ] != '\0' )
				buffer[ i ] = '.';
		}
		
		buffer[ bytesRead ] = '\0';

		return CStringW( buffer.get( ) );
	} else {
#ifdef _DEBUG
		PrintOut( _T( "[ReadMemoryString]: Failed to read memory, GetLastError() = %s" ), Utils::GetLastErrorString( ).GetString( ) );
#endif
		return CStringW( L".." );
	}
}
Пример #10
0
BOOLEAN Symbols::LoadSymbolsForPdb( CString PdbPath )
{
    int idx = -1;
    CString PdbFileName;
    const TCHAR* szSearchPath = NULL;
    SymbolReader* reader = NULL;
    BOOLEAN bSucc = FALSE;

    idx = PdbPath.ReverseFind( '/' );
    if (idx == -1)
        idx = PdbPath.ReverseFind( '\\' );
    PdbFileName = PdbPath.Mid( ++idx );

    if (!m_strSearchPath.IsEmpty( ))
        szSearchPath = m_strSearchPath.GetString( );

    reader = new SymbolReader( );

    ntdll::RtlEnterCriticalSection( &m_CriticalSection );

    bSucc = reader->LoadFile( PdbFileName, PdbPath, 0, 0, szSearchPath );

    ntdll::RtlLeaveCriticalSection( &m_CriticalSection );

    if (bSucc)
    {
        PrintOut( _T( "[Symbols::LoadSymbolsForPdb] Symbols for module %s loaded" ), PdbFileName.GetString( ) );
        m_SymbolNames.insert( std::make_pair( PdbFileName, reader ) );
        return TRUE;
    }

    delete reader;

    return FALSE;
}
Пример #11
0
/*******************************************************************************
 PROCESS START
*******************************************************************************/
int ProcessStart(int idx)
{
	int pid, i;
	char pname[BUF_SIZE];
	char errbuf[MAX_ERRBUF_LEN];

    for(i = 0;i < strlen(blocks[idx].bname);i++)
        pname[i] = toupper(blocks[idx].bname[i]);

    pname[strlen(blocks[idx].bname)] = 0x00;

	pid = fork();

	if(pid < 0)
	{
		return -1;
	}
	else if(pid == 0)
	{
		freopen("/dev/null", "w", stdout);
        freopen("/dev/null", "r", stdout);
		if (execl(blocks[idx].fname, pname, (char *)0) < 0)
		{
			sprintf(errbuf, "CAN'T EXECUTE FILE : %s [%s]\n", blocks[idx].fname, strerror(errno));
			PrintOut(TIFB_FAIL, errbuf);
		}
		exit(0);
	}
	else
	{
		return pid;
	}
}
Пример #12
0
void final_isr( int Signo )
{
	char errbuf[MAX_ERRBUF_LEN];

	sprintf(errbuf, "STOPPED BY USER REQUEST\n");
	PrintOut(TIFB_SUCCESS, errbuf);
	exit(0);
}
Пример #13
0
// Test -  bool StringCompare(char* string1, char* string2);
void Test2(StringOO& stringObj)
{
	bool result = false;
	bool result2 = true;
	StringOO string2 = "hello world";
	StringOO string3 = "hall0 werld";
	result = stringObj.StringCompare(stringObj, string2);
	result2 = stringObj.StringCompare(stringObj, string3);

	if (result && !result2)
	{
		PrintOut("Test 2", "StringCompare", "Successful");
	}
	else
	{
		PrintOut("Test 2", "StringCompare", "Failed");
	}
}
Пример #14
0
/*******************************************************************************
 WRONG COMMAND, PRINT FUNCTION
*******************************************************************************/
void UsageExit()
{
	char errbuf[2048];

	sprintf(errbuf, "ILLEGAL USE\n  USAGE: StartMC \n");
	strcat(errbuf, "         StartMC -b Block_Name\n");
	PrintOut(TIFB_FAIL, errbuf);
	exit(0);
}
int main()
{
  int i;
  int configParam;

  PrintOut("===TestStartUserProgram===\n", 27);
  
  configParam = GetConfigArg();
  PrintOut("Will Exec teststartuserprogramsub ", 34);
  PrintNumber(configParam);
  PrintOut(" times\n", 7);
  
  for(i=0; i < configParam; i++)
  {
    Exec("../test/teststartuserprogramsub");  
  }

  PrintOut("===TestStartUserProgram Completed===\n", 37);
  Exit(0);
}
Пример #16
0
void PrintSuccessBlocks()
{
	int i, success;
	char errbuf[MAX_ERRBUF_LEN];

	for(i=success=0;i < cntr;i++)
		if(inits[i].isinit == _TRUE)
			success++;

	sprintf(errbuf, "MAIN COMPUTER PROCESS INITIALIZATION SUCCESSFULLY COMPLETED\n  NO OF INITIALIZED PROCESS = %d\n", success);
	PrintOut(TIFB_SUCCESS, errbuf);
}
Пример #17
0
void PrintCombinations(std::vector<std::vector<DataType>::size_type>& outputs,
    std::vector<DataType>::size_type startIdxIn,
    const std::vector<DataType>& arrayNoDup,
    std::vector<DataType>::size_type endIdxOut)
{
    for (std::vector<DataType>::size_type idx=startIdxIn; idx<arrayNoDup.size(); ++idx)
    {
        outputs[endIdxOut++] = idx;
        PrintOut(outputs, 0, endIdxOut, arrayNoDup);
        PrintCombinations(outputs, idx+1, arrayNoDup, endIdxOut);
        --endIdxOut;
    }
}
Пример #18
0
/*---------------------------------------------------------------------
 DoubleTriangle builds the initial double triangle.  It first finds 3 
 noncollinear points and makes two faces out of them, in opposite order.
 It then finds a fourth point that is not coplanar with that face.  The  
 vertices are stored in the face structure in counterclockwise order so 
 that the volume between the face and the point is negative. Lastly, the
 3 newfaces to the fourth point are constructed and the data structures
 are cleaned up. 
---------------------------------------------------------------------*/
void    DoubleTriangle( void )
{
   tVertex  v0, v1, v2, v3;
   tFace    f0, f1 = NULL;
   int      vol;
	
   /* Find 3 noncollinear points. */
   v0 = vertices;
   while ( Collinear( v0, v0->next, v0->next->next ) )
      if ( ( v0 = v0->next ) == vertices )
         printf("DoubleTriangle:  All points are Collinear!\n"), exit(0);
   v1 = v0->next;
   v2 = v1->next;
	
   /* Mark the vertices as processed. */
   v0->mark = PROCESSED;
   v1->mark = PROCESSED;
   v2->mark = PROCESSED;
   
   /* Create the two "twin" faces. */
   f0 = MakeFace( v0, v1, v2, f1 );
   f1 = MakeFace( v2, v1, v0, f0 );

   /* Link adjacent face fields. */
   f0->edge[0]->adjface[1] = f1;
   f0->edge[1]->adjface[1] = f1;
   f0->edge[2]->adjface[1] = f1;
   f1->edge[0]->adjface[1] = f0;
   f1->edge[1]->adjface[1] = f0;
   f1->edge[2]->adjface[1] = f0;
	
   /* Find a fourth, noncoplanar point to form tetrahedron. */
   v3 = v2->next;
   vol = VolumeSign( f0, v3 );
   while ( !vol )   {
      if ( ( v3 = v3->next ) == v0 ) 
         printf("DoubleTriangle:  All points are coplanar!\n"), exit(0);
      vol = VolumeSign( f0, v3 );
   }
	
   /* Insure that v3 will be the first added. */
   vertices = v3;
   if ( debug ) {
      fprintf(stderr, "DoubleTriangle: finished. Head repositioned at v3.\n");
      PrintOut( vertices );
   }

	
}
Пример #19
0
BOOLEAN Symbols::Init( )
{
    if (m_bInitialized == FALSE)
    {
        HRESULT hr = S_OK;
        hr = CoInitialize( NULL );
        if (FAILED( hr ))
        {
            PrintOut( _T( "[Symbols::Init] CoInitialize failed - HRESULT = %08X" ), hr );
            return FALSE;
        }
        m_bInitialized = TRUE;
    }
    return TRUE;
}
Пример #20
0
void PrintAllCombinationsClean(const std::vector<DataType>& arrayNoDup)
{
    std::vector<int>::size_type length = arrayNoDup.size();
    std::vector<int> fromVec(length, 0);
    std::vector<int> toVec(length, 1);
    std::vector<int> selectVec(length, 0);

    std::vector<int>::size_type curDigit;
    do 
    {
        PrintOut(selectVec, arrayNoDup);
        for (curDigit=0;
            curDigit<length && ++selectVec[curDigit]>toVec[curDigit];
            selectVec[curDigit] = fromVec[curDigit], ++curDigit);
    } while (curDigit<length);
}
Пример #21
0
bool wxExcelWorksheet::PrintOut(long* from, long* to, long* copies, wxXlTribool preview, const wxString& activePrinter,
                                 wxXlTribool printToFile, wxXlTribool collate, const wxString& prToFileName, wxXlTribool ignorePrintAreas)
{
    wxVariantVector args;

    WXAUTOEXCEL_OPTIONALCPP_TO_OPTIONALVARIANT_NAME_VECTOR(From, from, args);
    WXAUTOEXCEL_OPTIONALCPP_TO_OPTIONALVARIANT_NAME_VECTOR(To, to, args);
    WXAUTOEXCEL_OPTIONALCPP_TO_OPTIONALVARIANT_NAME_VECTOR(Copies, copies, args);
    WXAUTOEXCEL_OPTIONALCPPTBOOL_TO_OPTIONALVARIANT_NAME_VECTOR(Preview, preview, args);
    WXAUTOEXCEL_OPTIONALCPPSTR_TO_OPTIONALVARIANT_NAME_VECTOR(ActivePrinter, activePrinter, args);
    WXAUTOEXCEL_OPTIONALCPPTBOOL_TO_OPTIONALVARIANT_NAME_VECTOR(PrintToFile, printToFile, args);
    WXAUTOEXCEL_OPTIONALCPPTBOOL_TO_OPTIONALVARIANT_NAME_VECTOR(Collate, collate, args);
    WXAUTOEXCEL_OPTIONALCPPSTR_TO_OPTIONALVARIANT_NAME_VECTOR(PrToFileName, prToFileName, args);
    WXAUTOEXCEL_OPTIONALCPPTBOOL_TO_OPTIONALVARIANT_NAME_VECTOR(IgnorePrintAreas, ignorePrintAreas, args);

    return PrintOut(args);
}
Пример #22
0
/*---------------------------------------------------------------------
AddOne is passed a vertex.  It first determines all faces visible from 
that point.  If none are visible then the point is marked as not 
onhull.  Next is a loop over edges.  If both faces adjacent to an edge
are visible, then the edge is marked for deletion.  If just one of the
adjacent faces is visible then a new face is constructed.
---------------------------------------------------------------------*/
int 	AddOne( tVertex p )
{
   tFace  f; 
   tEdge  e, temp;
   int 	  vol;
   int	  vis = FALSE;

   if ( debug ) {
      fprintf(stderr, "AddOne: starting to add v%d.\n", p->vnum);
      PrintOut( vertices );
   }

   /* Mark faces visible from p. */
   f = faces;
   do {
      vol = VolumeSign( f, p );
      if (debug) fprintf(stderr, 
         "faddr: %p   paddr: %p   Vol = %d\n", f,p,vol);
      if ( vol < 0 ) {
	 f->visible = VISIBLE;  
	 vis = TRUE;                      
      }
      f = f->next;
   } while ( f != faces );

   /* If no faces are visible from p, then p is inside the hull. */
   if ( !vis ) {
     p->onhull = !ONHULL;  
      return FALSE; 
   }

   /* Mark edges in interior of visible region for deletion.
      Erect a newface based on each border edge. */
   e = edges;
   do {
      temp = e->next;
      if ( e->adjface[0]->visible && e->adjface[1]->visible )
	 /* e interior: mark for deletion. */
	 e->deleted = REMOVED;
      else if ( e->adjface[0]->visible || e->adjface[1]->visible ) 
	 /* e border: make a new face. */
	 e->newface = MakeConeFace( e, p );
      e = temp;
   } while ( e != edges );
   return TRUE;
}
Пример #23
0
void init_isr( int Signo )
{
	int err;
	char errbuf[MAX_ERRBUF_LEN];

	fprintf(stderr, "\n\tDo you want to stop initialization(y/n) ? ");
	err = GetYorN();

	if(err == _YES)
	{
		sprintf(errbuf, "INITIALIZATION STOPPED IN PROGRESS\n");
		strcat(errbuf, "  BLOCKS ALREADY INITLAIZED CAN'T AUTOMATICALLY CANCELLED\n");
		PrintOut(TIFB_FAIL, errbuf);
		exit(0);
	}

    signal(SIGQUIT, init_isr);
}
Пример #24
0
Файл: hw07.c Проект: 0lumide/cs
int main()
{
  //LOCAL DECLARATION
  int input[SIZE] = {0};//This is an array of 25 that holds the users input
  int output[SIZE] = {0};//This is an array of 25 that holds the nearly sorted data
  int set_size; //This is the variable that holds the amount of input entered by the user
  int i; //for loop control variable

  //EXECUTABLE STATEMENT
  set_size = getInput(input);

  for (i = 0; i < set_size; i++)
  {
    output[i] = input[i];
  }

  SortData(output, set_size);
  PrintOut(input, output, set_size);

  return(0);
}
Пример #25
0
void SendFile(HANDLE hPipe, HANDLE hOut, LPCTSTR asFileName)
{
	TCHAR szPath[MAX_PATH] = _T("");
	GetModuleFileName(NULL, szPath, MAX_PATH);
	TCHAR* pszSlash = _tcsrchr(szPath, _T('\\'));
	lstrcpy(pszSlash ? pszSlash+1 : szPath, asFileName);
	HANDLE hFile = CreateFile(szPath, GENERIC_READ, FILE_SHARE_READ, NULL, OPEN_EXISTING, 0, NULL);
	if (hFile == INVALID_HANDLE_VALUE)
	{
		DWORD nWrite;
		PrintOut("File was not found, code=%u\n");
		WriteConsole(hOut, szPath, lstrlen(szPath), &nWrite, NULL);
		return;
	}
	DWORD nSize = GetFileSize(hFile, NULL);
	char* pszData = (char*)calloc(nSize+1,1);
	if (nSize && pszData && ReadFile(hFile, pszData, nSize, &nSize, NULL))
	{
		SendAnsi(hPipe, hOut, pszData);
	}
	CloseHandle(hFile);
}
Пример #26
0
/*---------------------------------------------------------------------
ConstructHull adds the vertices to the hull one at a time.  The hull
vertices are those in the list marked as onhull.
---------------------------------------------------------------------*/
void	ConstructHull( void )
{
   tVertex  v, vnext;

   v = vertices;
   do {
      vnext = v->next;
      if ( !v->mark ) {
         v->mark = PROCESSED;
	 AddOne( v );
	 CleanUp( &vnext ); /* Pass down vnext in case it gets deleted. */

	 if ( check ) {
	    fprintf(stderr,"ConstructHull: After Add of %d & Cleanup:\n", 
               v->vnum);
	    Checks();
	 }
	 if ( debug )
            PrintOut( v );
      }
      v = vnext;
   } while ( v != vertices );
}
Пример #27
0
BOOLEAN Symbols::LoadSymbolsForModule( CString ModulePath, ULONG_PTR ModuleBaseAddress, ULONG SizeOfModule )
{
    int idx;
    CString ModuleName;
    const TCHAR* szSearchPath;
    SymbolReader* pReader;
    BOOLEAN bSucc;

    idx = ModulePath.ReverseFind( _T( '/' ) );
    if (idx == -1)
        idx = ModulePath.ReverseFind( _T( '\\' ) );
    ModuleName = ModulePath.Mid( ++idx );

    if (!m_strSearchPath.IsEmpty( ))
        szSearchPath = m_strSearchPath.GetString( );
    else 
        szSearchPath = NULL;

    pReader = new SymbolReader( );

    ntdll::RtlEnterCriticalSection( &m_CriticalSection );

    bSucc = pReader->LoadFile( ModuleName, ModulePath, ModuleBaseAddress, SizeOfModule, szSearchPath );

    ntdll::RtlLeaveCriticalSection( &m_CriticalSection );

    if (bSucc)
    {
        PrintOut( _T( "[Symbols::LoadSymbolsForModule] Symbols for module %s loaded" ), ModuleName.GetString( ) );
        m_SymbolAddresses.insert( std::make_pair( ModuleBaseAddress, pReader ) );
        return TRUE;
    }

    delete pReader;

    return FALSE;
}
Пример #28
0
int btContent::InitialFromMI(const char *metainfo_fname,const char *saveas)
{
#define ERR_RETURN()	{if(b) delete []b; return -1;}
  unsigned char *ptr = m_shake_buffer;
  char *b;
  const char *s;
  size_t flen, q, r;

  b = _file2mem(metainfo_fname,&flen);
  if ( !b ) return -1;

  // announce
  if( !meta_str("announce",&s,&r) ) ERR_RETURN();
  if( r > MAXPATHLEN ) ERR_RETURN();
  m_announce = new char [r + 1];
  memcpy(m_announce, s, r);
  m_announce[r] = '\0';
  
  // infohash
  if( !(r = meta_pos("info")) ) ERR_RETURN();
  if( !(q = decode_dict(b + r, flen - r, (char *) 0)) ) ERR_RETURN();
  Sha1(b + r, q, m_shake_buffer + 28);

  if( meta_int("creation date",&r)) m_create_date = (time_t) r;
 
  // hash table
  if( !meta_str("info|pieces",&s,&m_hashtable_length) ||
      m_hashtable_length % 20 != 0) ERR_RETURN();

  m_hash_table = new unsigned char[m_hashtable_length];

#ifndef WINDOWS
  if( !m_hash_table ) ERR_RETURN();
#endif
  memcpy(m_hash_table, s, m_hashtable_length);

  if(!meta_int("info|piece length",&m_piece_length)) ERR_RETURN();
  m_npieces = m_hashtable_length / 20;

  if( m_piece_length > cfg_max_slice_size * cfg_req_queue_length ){
    fprintf(stderr,"error, piece length too long[%u]. please recomplie CTorrent with a larger cfg_max_slice_size in <btconfig.h>.\n", m_piece_length);
    ERR_RETURN();
  }

  if( m_piece_length < cfg_req_slice_size )
    cfg_req_slice_size = m_piece_length;
  else{
    for( ;(m_piece_length / cfg_req_slice_size) >= cfg_req_queue_length; ){
      cfg_req_slice_size *= 2;
      if( cfg_req_slice_size > cfg_max_slice_size ) ERR_RETURN();
    }
  }
  
  if( m_btfiles.BuildFromMI(b, flen, saveas) < 0) ERR_RETURN();

  delete []b;
  PrintOut();
  
  if( arg_flg_exam_only ) return 0;

  if( ( r = m_btfiles.CreateFiles() ) < 0) ERR_RETURN();

  global_piece_buffer = new char[m_piece_length];
#ifndef WINDOWS
  if( !global_piece_buffer ) ERR_RETURN();
#endif

  pBF = new BitField(m_npieces);
#ifndef WINDOWS
  if( !pBF ) ERR_RETURN();
#endif

  m_left_bytes = m_btfiles.GetTotalLength() / m_piece_length;
  if( m_btfiles.GetTotalLength() % m_piece_length ) m_left_bytes++;
  if( m_left_bytes != m_npieces ) ERR_RETURN();
  
  m_left_bytes = m_btfiles.GetTotalLength();

  if( arg_bitfield_file ){

    if( !arg_flg_check_only ){
      if( pBF->SetReferFile(arg_bitfield_file) >= 0){
	size_t idx;
	r = 0;
	for( idx = 0; idx < m_npieces; idx++ )
	  if( pBF->IsSet(idx) ) m_left_bytes -= GetPieceLength(idx);
      }
      else{
	fprintf(stderr,"warn, couldn't set bit field refer file %s.\n",arg_bitfield_file);
      }
    }
    
    if( r ) CheckExist();
    
  }else if( arg_flg_force_seed_mode ){
    pBF->SetAll();
    m_left_bytes = 0;
  }else if( r ){
    CheckExist();
  }
  
  printf("Already/Total: %u/%u\n",pBF->Count(),m_npieces);
  
  if( arg_flg_check_only ){
    if( arg_bitfield_file ) pBF->WriteToFile(arg_bitfield_file);
    exit(1);
  }
  
  CacheConfigure();

  *ptr = (unsigned char) 19; ptr++; // protocol string length
  memcpy(ptr,"BitTorrent protocol",19); ptr += 19; //  protocol string
  memset(ptr,0,8);		// reserved set zero.

  {				// peer id
    int i;
    ptr = m_shake_buffer + 48;
    for( i = 0; i < 20; i++,ptr++) *ptr = (unsigned char)(rand() & 0xFF);
  }

  return 0;
}
Пример #29
0
void CChildView::ReplaceSelectedWithType(NodeType Type)
{
	std::vector<CNodeBase*> newSelected;

	PrintOut(_T("Replace Node Type %Ts"), NodeTypeToString(Type));

	for (UINT i = 0; i < Selected.size(); i++)
	{
		if (!theApp.IsNodeValid(Selected[i].object))
			continue;
		if (Selected[i].object->pParent->GetType() == nt_vtable)
			Type = nt_function;

		CNodeBase* pNewNode = theApp.CreateNewNode(Type);

		if (Type == nt_class)	MakeBasicClass((CNodeClass*)pNewNode);
		if (Type == nt_custom)	((CNodeCustom*)pNewNode)->memsize = Selected[i].object->GetMemorySize();
		if (Type == nt_text)	((CNodeText*)pNewNode)->memsize = Selected[i].object->GetMemorySize();
		if (Type == nt_unicode)	((CNodeUnicode*)pNewNode)->memsize = Selected[i].object->GetMemorySize();
		if (Type == nt_vtable)
		{
			for (int i = 0; i < 10; i++)
			{
				CNodeVTable* pVTable = (CNodeVTable*)pNewNode;
				CNodeFunctionPtr* pFun = new CNodeFunctionPtr;
				pFun->offset = i * 8;
				pFun->pParent = pVTable;
				pVTable->Nodes.push_back(pFun);
			}
		}
		if (Type == nt_pointer)
		{
			CNodePtr*	pPtr = (CNodePtr*)pNewNode;
			CNodeClass* pClass = (CNodeClass*)theApp.CreateNewNode(nt_class);
			MakeBasicClass(pClass);
			pPtr->pNode = pClass;
		}
		if (Type == nt_array)
		{
			CNodeArray* pArray = (CNodeArray*)pNewNode;
			CNodeClass* pClass = (CNodeClass*)theApp.CreateNewNode(nt_class);
			MakeBasicClass(pClass);
			pArray->pNode = pClass;
		}
		if (Type == nt_instance)
		{
			CNodeClassInstance* pInstance = (CNodeClassInstance*)pNewNode;
			CNodeClass*			pClass = (CNodeClass*)theApp.CreateNewNode(nt_class);
			MakeBasicClass(pClass);
			pInstance->pNode = pClass;
		}

		ReplaceNode((CNodeClass*)Selected[i].object->pParent, FindNodeIndex(Selected[i].object), pNewNode);
		newSelected.push_back(pNewNode);
	}

	Selected.clear();
	for (UINT i = 0; i < newSelected.size(); i++)
	{
		newSelected[i]->bSelected = true;
		CNodeClass* pClass = (CNodeClass*)newSelected[i]->pParent;

		HotSpot spot;
		spot.Address = pClass->offset + newSelected[i]->offset;
		spot.object = newSelected[i];
		Selected.push_back(spot);
	}

	Invalidate(FALSE);
}
Пример #30
0
int main(){
/***********clock************************/
/*clock_t start, end;

  start = clock();
  printf("***********************************************************************\n");
  printf( "star time:%d\n", start );
/***********clock************************/

 T newtask[]={
   {1,0,10,3,3,1.0,0,0,1},
   {2,0,10,4,4,1.0,0,0,1},
   {3,0,10,5,5,1.0,0,0,1},
   {4,0,9,8,8,1.0,0,0,1},
   {5,0,8,6,6,1.0,0,0,1},
 
 
 }; 

int size =sizeof(newtask)/sizeof(T); //size=Numbers of Task ,last task--> task[size-1]
int timer=0;
int CompletesTure=0;
int cnt=0;
 int i;
int total_job=0;
		/****TOTALJOBS**/
		for(i=0;i<size;i++){
		  total_job+=maxtime/newtask[i].deadline;
		}

		printf("TOTAL JOBS :%d\n",total_job);
/***************AcO loop***********/
while(timer<maxtime){
if(TaskRelease(newtask,timer,size)||CompletesTure){
ExeProb(newtask,timer,size);//#1figure out Exe.Probability.##first
FixSequence(newtask,timer,size);
SuccessRate(newtask,timer,size);//include ##UPdate Pheromon
ExeProb(newtask,timer,size);//#1figure out Exe.Probability.##second
FixSequence(newtask,timer,size);
if(printout)
PrintOut(newtask,timer,size);
}
CompletesTure=ExeTask(newtask,timer,size);//## Exe Task
if(CompletesTure)
cnt++;
timer++;
}

printf("\n");
printf("\n");
printf("             RESULT   ACO Shah                         \n");
 printf("     maxtime=%d\n     apha=%d beat=%d \n     SuccessJob=%d(%4.1f%%)\n      \n",maxtime,apha,beta,cnt,(float)cnt/total_job*100);
/***********clock************************/
/* end = clock();
  printf("***********************************************************************\n");
  printf( "end time:%d\n", end );
  printf( "exetime :%d[ms]\n", end - start );
    printf("***********************************************************************\n");
	
/***********clock************************/
return 0;
}