Example #1
0
void __fastcall TConfDlg::OnPluginChange(TMessage &Message) {
	int i;
    CHostRef *Host;
	ActivePlugin = PluginManager.GetActualPlugin();

    FreeContext(&GlobalConfig);
    //if(Message.WParam) {
	    for(i=0;i<SelectedBox->Items->Count;++i) {
    		Host = (CHostRef *)SelectedBox->Items->Objects[i];
        	FreeContext(*Host);
    	}

    	for(i=0;i<LastList->Count;++i) {
    		Host = (CHostRef *)LastList->Objects[i];
        	FreeContext(*Host);
    	}
    //}

    if(Message.WParam) {
    	UpdateSelState = true;
    	RefreshButtonClick(0);
    } else  {
    	Servers->EnumData(Handle);
        UpdateParams();
        HostBox->Refresh();
    }

}
Example #2
0
int main(int ac, char **av)
{
    context_t context;
    int r;
    if(SDL_Init(SDL_INIT_VIDEO) < 0)
    {
        fprintf(stderr, "Failed to init SDL : '%s'\n", SDL_GetError());
        return EXIT_FAILURE;
    }
    atexit(SDL_Quit);
    SDL_WM_SetCaption("Minesweeper", NULL);
    SDL_WM_SetIcon(SDL_LoadBMP("ico.bmp"), NULL);
    InitContext(&context);
    do
    {
        switch(r = Menu(&context))
        {
        case PLAY:
            Play(&context);
            break;
        case SETTINGS:
            Settings(&context);
            break;
        default:
            break;
        }
    }
    while(r != EXIT);
    FreeContext(&context);
    return 0;
    (void)ac;
    (void)av;
}
Example #3
0
int main (int argc, char *argv[]) {
    if (InitCVIRTE (0, argv, 0) == 0)
        return -1;    /* out of memory */
    
    if (argc != 2) {
        fprintf(stderr, "you must pass the path to a module to test");
        return -1;
    }
    
    char *testModule = argv[1];
    if (!FileExists(testModule, 0)) {
        fprintf(stderr, "you must pass the path to a module to test");
    }
    
    ListType names;
    SymbolParser *parser = MakeParser(testModule);
    names = GetExports(parser);
    
    context = CreateContext();
    LoadTestInfo info = { .parser = parser, .executeOnContext = context->ExecuteTests };
    ListApplyToEach(names, 1, LoadUserTests, &info);
    
    DeleteParser(parser);
    FreeContext(context);
    return 0;
}
Example #4
0
int main(int argc, char **argv)
{
    int tmp;
    context_t context;
    if(SDL_Init(SDL_INIT_VIDEO) < 0)
        return EXIT_FAILURE;
    atexit(SDL_Quit);
    if(!InitContext(&context))
    {
        fprintf(stderr, "Unable to load screen\n");
        return EXIT_FAILURE;
    }
    SDL_ShowCursor(0);
    SDL_WM_SetCaption("Minecraft Sokoban", NULL);
    SDL_WM_SetIcon(SDL_LoadBMP("ico32.bmp"), NULL);
    SDL_EnableKeyRepeat(125, 125);
    do
    {
        SDL_FreeSurface(context.screen);
        context.screen = SDL_SetVideoMode(768, 768, 32, SDL_HWSURFACE|SDL_DOUBLEBUF);
        tmp = Menu(context.screen);
        if(tmp == PLAY)
            Play(&context, 1);
        else if(tmp == EDIT)
            Editor(&context);
        else if(tmp == TILE)
            ChoseTileset(&context);
    }
    while(tmp != EXIT);
    FreeContext(&context);
    return EXIT_SUCCESS;
    (void)argc;
    (void)argv;
}
Example #5
0
extern "C" BOOL BKL_Deinit(DWORD dwContext)
{
    BKL_MDD_INFO *pBKLinfo = NULL;
    DEBUGMSG(ZONE_BACKLIGHT, (TEXT("BKL_Deinit().\r\n")));

    // Verify our context
    if(! dwContext)
    {
        DEBUGMSG(ZONE_ERROR, (L"ERROR: BKL_Deinit: "
            L"Incorrect context paramer\r\n" ));

        return FALSE;
    }

    pBKLinfo = (BKL_MDD_INFO *) dwContext;

    FreeContext(pBKLinfo);

    if (g_pBacklight)
    {
        delete g_pBacklight;
    }
    
    return TRUE;
}
BOOLEAN
DestroyContext (CONTEXT ContextRef)
{
	if (ContextRef == 0)
		return (FALSE);

	if (_pCurContext && _pCurContext == ContextRef)
		SetContext ((CONTEXT)0);

#ifdef DEBUG
	// Unlink the context.
	{
		CONTEXT *contextPtr = FindContextPtr (ContextRef);
		if (contextEnd == &ContextRef->next)
			contextEnd = contextPtr;
		*contextPtr = ContextRef->next;
	}
#endif  /* DEBUG */

	FreeContext (ContextRef);
	return TRUE;
}
Example #7
0
//---------------------------------------------------------------------------
BOOL TConfDlg::LoadConfig(const AnsiString &File) {
	HANDLE file;
    DWORD type, fileversion;
    HostData *actData;
    char PlgName[30]="NONE",*N = PlgName;
    int i;
    bool ignoreContext=false;

    file = CreateFileA(File.c_str(),GENERIC_READ,FILE_SHARE_READ,0,OPEN_EXISTING,
                     FILE_FLAG_SEQUENTIAL_SCAN,0);
    if(file == INVALID_HANDLE_VALUE) {
  	    Application->MessageBox("Cannot open file!","Error",MB_OK|MB_ICONERROR);
	    return FALSE;
    }
    type = ReadType(file);
    if(type != MAGIC) {
    	CloseHandle(file);
        Application->MessageBox("Invalid file format!",
                                "Error",MB_OK|MB_ICONERROR);
        return FALSE;
    }
    fileversion = ReadType(file);
    if(fileversion != FILE_VERSION) {

        i = Application->MessageBox("Wrong file version! Try anyway?","Error",MB_YESNO|MB_ICONERROR);
        if (i == ID_NO)  {
          CloseHandle(file);
          return FALSE;
          }
    }

    // This should not happen...
    while(SelectedBox->Items->Count) {
       	RemoveSelHost(0,true);
    }
    for(i=0;i<LastList->Count;++i) {
    	delete LastList->Objects[i];
        LastList->Objects[i] = 0;
    }
    LastList->Clear();

    actData = &GlobalConfig;
    FreeProcData(actData);
    SetHostAccount(actData,0);

	do {
    	type = ReadType(file);
        switch(type) {
        case TYPE_CONFIG: ReadConfigData(file,actData,fileversion);
                            if(ignoreContext) FreeContext(actData);
        					break;
		case TYPE_ACCOUNT: ReadAccount(file,actData);
        					
         					break;
        case TYPE_ACCOUNT_ENCRYPTED: ReadAccountEncrypted(file,actData); break;
		case TYPE_HOST: actData = 0;
                        ReadHost(file,&actData);
                        if(actData) {
                        	CopyStateData(actData,(*Servers)[actData->Name]);
                        	LastList->AddObject(actData->Name,new CHostRef(actData));
                        }
                        break;
        case TYPE_PLUGIN: ReadString(file,&N);
        			      if(!PluginManager.SetActualPlugin(PlgName))
                          	ignoreContext = true;
                          break;

		case TYPE_VERSION:
        case TYPE_GLOBAL:
		case TYPE_NONE:
        default: break;
        }
    } while(type != TYPE_NONE);
    CloseHandle(file);
    return TRUE;
}
Example #8
0
int main(int argc, char ** argv)
{
	int i;
	const char * szWhere = NULL;
	bool fDir = false;
        bool fCorners = false;
		bool fMemory = false;

	for (i = 1; i < argc; i++) {
		printf("arg: '%s'\n", argv[i]);
		if (argv[i][0] == '-') {
			if (strcmp(argv[i], "--dir") == 0) {
				fDir = true;
			}
			else if (strcmp(argv[i], "--corners") == 0) {
				fCorners = true;
			}
			else if (strcmp(argv[i], "--memory") == 0) {
				fMemory = true;
			}
		}
		else {
			szWhere = argv[i];
		}
	}

	//
	//  If we are given a file name, then process the file name
	//

	if (fMemory) {
		if (szWhere == NULL) {
			fprintf(stderr, "Must specify a file name\n");
			exit(1);
		}
		RunMemoryTest(szWhere);
	}
	else if (szWhere != NULL) {
		if (szWhere == NULL) {
			fprintf(stderr, "Must specify a file name\n");
			exit(1);
		}
		if (fDir) RunTestsInDirectory(szWhere);
		else RunFileTest(szWhere);
	}
	else if (fCorners) {
		RunCorners();
	}
	else {
#ifdef USE_CBOR_CONTEXT
		context = CreateContext((unsigned int) -1);
#endif
#if INCLUDE_MAC
		MacMessage();
#endif
#if INCLUDE_SIGN
		SignMessage();
#endif
#if INCLUDE_ENCRYPT
		EncryptMessage();
#endif
#ifdef USE_CBOR_CONTEXT
		FreeContext(context);
#endif
	}

	if (CFails > 0) fprintf(stderr, "Failed %d tests\n", CFails);
	else fprintf(stderr, "SUCCESS\n");

	exit(CFails);
}
Example #9
0
File: VP.c Project: berkus/nemesis
static void FreeContext_m (VP_cl   *self,
			   VP_ContextSlot  cs /* IN */ )
{
    VP$FreeContext(self,cs);
}
Example #10
0
BOOL WINAPI
BackupRead(
    HANDLE  hFile,
    LPBYTE  lpBuffer,
    DWORD   nNumberOfBytesToRead,
    LPDWORD lpNumberOfBytesRead,
    BOOL    bAbort,
    BOOL    bProcessSecurity,
    LPVOID  *lpContext)
{
    BACKUPCONTEXT *pbuc;
    BACKUPIOFRAME bif;
    BOOL fSuccess = FALSE;

    pbuc = *lpContext;
    bif.pIoBuffer = lpBuffer;
    bif.cbRequest = nNumberOfBytesToRead;
    bif.pcbTransfered = lpNumberOfBytesRead;
    bif.fProcessSecurity = bProcessSecurity;

    if (bAbort) {
	if (pbuc != NULL) {
	    FreeContext(lpContext);
	}
	return(TRUE);
    }
    *bif.pcbTransfered = 0;

    if (pbuc == INVALID_HANDLE_VALUE || bif.cbRequest == 0) {
	return(TRUE);
    }

    if (pbuc != NULL && mwStreamList[pbuc->StreamIndex] == BACKUP_INVALID) {
	FreeContext(lpContext);
	return(TRUE);
    }

    // Allocate our Context Control Block on first call.

    if (pbuc == NULL) {
	pbuc = AllocContext(CBMIN_BUFFER);	// Alloc initial buffer
    }

    if (pbuc != NULL) {
	*lpContext = pbuc;

	do {

	    if (pbuc->fStreamStart) {
		pbuc->head.Size.LowPart = 0;
		pbuc->head.Size.HighPart = 0;

		pbuc->liStreamOffset.LowPart = 0;
		pbuc->liStreamOffset.HighPart = 0;

		pbuc->fMultiStreamType = FALSE;
	    }
	    fSuccess = TRUE;

	    switch (mwStreamList[pbuc->StreamIndex]) {
		case BACKUP_DATA:
		    fSuccess = BackupReadData(hFile, pbuc, &bif);
		    break;

		case BACKUP_ALTERNATE_DATA:
		    fSuccess = BackupReadAlternateData(hFile, pbuc, &bif);
		    break;

		case BACKUP_EA_DATA:
		    fSuccess = BackupReadEaData(hFile, pbuc, &bif);
		    break;

		case BACKUP_SECURITY_DATA:
		    fSuccess = BackupReadSecurityData(hFile, pbuc, &bif);
		    break;

#ifdef BACKUP_OLEINFO
		case BACKUP_PROPERTY_DATA:
		    fSuccess = BackupReadOleData(hFile, pbuc, &bif);
		    break;
#endif // BACKUP_OLEINFO

		default:
		    pbuc->StreamIndex++;
		    pbuc->fStreamStart = TRUE;
		    break;
	    }

	    // if we're in the phase of reading the header, copy the header

	    if (pbuc->liStreamOffset.LowPart < pbuc->cbHeader &&
		pbuc->liStreamOffset.HighPart == 0) {

		DWORD cbrequest;

		//  Send the current stream header;

		cbrequest = min(
		    pbuc->cbHeader - pbuc->liStreamOffset.LowPart,
		    bif.cbRequest);

		RtlCopyMemory(
		    bif.pIoBuffer,
		    (BYTE *) &pbuc->head + pbuc->liStreamOffset.LowPart,
		    cbrequest);

		ReportTransfer(pbuc, &bif, cbrequest);
	    }

	    //
	    // if we are at the end of a stream then
	    //	  start at the beginning of the next stream
	    //

	    else {
		BackupTestRestartStream(pbuc);
	    }
	} while (fSuccess &&
	         mwStreamList[pbuc->StreamIndex] != BACKUP_INVALID &&
	         bif.cbRequest != 0);
    }
    if (fSuccess && *bif.pcbTransfered == 0) {
	FreeContext(lpContext);
    }
    return(fSuccess);
}
Example #11
0
BOOL WINAPI
BackupWrite(
    HANDLE  hFile,
    LPBYTE  lpBuffer,
    DWORD   nNumberOfBytesToWrite,
    LPDWORD lpNumberOfBytesWritten,
    BOOL    bAbort,
    BOOL    bProcessSecurity,
    LPVOID  *lpContext)
{
    BACKUPCONTEXT *pbuc;
    BACKUPIOFRAME bif;
    BOOL fSuccess = FALSE;

    pbuc = *lpContext;
    bif.pIoBuffer = lpBuffer;
    bif.cbRequest = nNumberOfBytesToWrite;
    bif.pcbTransfered = lpNumberOfBytesWritten;
    bif.fProcessSecurity = bProcessSecurity;

    //
    // Allocate our Context Control Block on first call.
    //

    if (bAbort) {
	if (pbuc != NULL) {
	    FreeContext(lpContext);
	}
	return(TRUE);
    }

    *bif.pcbTransfered = 0;
    if (pbuc == INVALID_HANDLE_VALUE) {
	return(TRUE);
    }

    // Allocate our Context Control Block on first call.

    if (pbuc == NULL) {
	pbuc = AllocContext(0);			// No initial buffer
    }

    if (pbuc != NULL) {
	*lpContext = pbuc;

	do {
	    DWORD cbrequest;
	    LARGE_INTEGER licbRemain;

	    if (pbuc->cbHeader == 0) {		// we expect a stream header

		// fill up to the stream name

		BackupWriteHeader(pbuc, &bif, CB_NAMELESSHEADER);
	    }

	    if (bif.cbRequest == 0) {
		return(TRUE);
	    }

	    if (pbuc->cbHeader == CB_NAMELESSHEADER &&
		pbuc->head.dwStreamNameSize != 0) {

		//  now fill in the stream name if it exists

		BackupWriteHeader(
		    pbuc,
		    &bif,
		    pbuc->cbHeader + pbuc->head.dwStreamNameSize);

		if (bif.cbRequest == 0) {
		    return(TRUE);
		}
	    }
	    cbrequest = ComputeRequestSize(pbuc, bif.cbRequest);

	    ComputeRemainingSize(pbuc, &licbRemain);

	    if (pbuc->fAccessError &&
		licbRemain.HighPart == 0 &&
		licbRemain.LowPart == 0) {

		ReportTransfer(pbuc, &bif, cbrequest);
		continue;
	    }
	    pbuc->fAccessError = FALSE;

	    switch (pbuc->head.dwStreamId) {
		case BACKUP_DATA:
		    pbuc->fStreamStart = FALSE;
		    fSuccess = BackupWriteStream(hFile, pbuc, &bif);
		    break;

		case BACKUP_ALTERNATE_DATA:
		    fSuccess = BackupWriteAlternateData(hFile, pbuc, &bif);
		    break;

		case BACKUP_EA_DATA:
		    fSuccess = BackupWriteEaData(hFile, pbuc, &bif);
		    break;

		case BACKUP_SECURITY_DATA:
		    fSuccess = BackupWriteSecurityData(hFile, pbuc, &bif);
		    break;

		case BACKUP_LINK:
		    fSuccess = BackupWriteLinkData(hFile, pbuc, &bif);
		    break;

#ifdef BACKUP_OLEINFO
		case BACKUP_PROPERTY_DATA:
		    fSuccess = BackupWriteOleData(hFile, pbuc, &bif);
		    break;
#endif // BACKUP_OLEINFO

	       default:
		    SetLastError(ERROR_INVALID_DATA);
		    fSuccess = FALSE;
		    break;
	    }

	    BackupTestRestartStream(pbuc);
	} while (fSuccess && bif.cbRequest != 0);
    }

    if (fSuccess && *bif.pcbTransfered == 0) {
	FreeContext(lpContext);
    }
    return(fSuccess);
}
Example #12
0
/* 
    pContext [in]: Pointer to a string containing the registry path to the active key 
    for the stream interface driver

    lpvBusContext [in]: Potentially process-mapped pointer passed as the fourth parameter to ActivateDeviceEx. 
    If this driver was loaded through legacy mechanisms, then lpvBusContext is zero.    
*/
extern "C" DWORD BKL_Init(
  LPCTSTR pContext, 
  LPCVOID lpvBusContext
)
{   
    DWORD dwStatus, dwSize, dwType;
    HKEY hkDevice = NULL;
    BKL_MDD_INFO *pBKLinfo = NULL;

    UNREFERENCED_PARAMETER(lpvBusContext);
   
    if (IsDVIMode())
        return 0;
    
    DEBUGMSG(ZONE_BACKLIGHT, (TEXT("+BKL_Init() context %s.\r\n"), pContext));


    g_pBacklight = GetBacklightObject();
    if (g_pBacklight == NULL)
    {
        goto error;
    }

    // Allocate enough storage for this instance of our backlight
    pBKLinfo = (BKL_MDD_INFO *)LocalAlloc(LPTR, sizeof(BKL_MDD_INFO));
    if (pBKLinfo == NULL)
    {
        DEBUGMSG(ZONE_ERROR, (L"ERROR: BKL_Init: "
            L"Failed allocate BKL_MDD_INFO device structure\r\n" ));
        goto error;
    }

    // get device name from registry
    dwStatus = RegOpenKeyEx(HKEY_LOCAL_MACHINE, pContext, 0, 0, &hkDevice);
    if(dwStatus != ERROR_SUCCESS) 
    {
        DEBUGMSG(ZONE_ERROR, (TEXT("BLK_Init: OpenDeviceKey failed with %u\r\n"), dwStatus));
        goto error;
    }
    dwSize = sizeof(pBKLinfo->szName);
    dwStatus = RegQueryValueEx(hkDevice, DEVLOAD_DEVNAME_VALNAME, NULL, &dwType, (LPBYTE)pBKLinfo->szName, &dwSize);
    if(dwStatus != ERROR_SUCCESS)
    {
        DEBUGMSG(ZONE_ERROR, (TEXT("BLK_Init: RegQueryValueEx failed with %u\r\n"), dwStatus));
        goto error;

    }
    RegCloseKey(hkDevice);
    hkDevice = NULL;

    // create exit event to be set by deinit:
    pBKLinfo->hExitEvent = CreateEvent(NULL, FALSE, FALSE, NULL);
    if(NULL == pBKLinfo->hExitEvent)
    {
        DEBUGMSG(ZONE_ERROR, (TEXT("BLK_Init: OpenDeviceKey failed with %u\r\n"), dwStatus));
        goto error;
    }

    pBKLinfo->hCoreDll = LoadLibrary(TEXT("coredll.dll"));
    if (NULL != pBKLinfo->hCoreDll) 
    {
        pBKLinfo->pfnGetSystemPowerStatusEx2 = (PFN_GetSystemPowerStatusEx2)
            GetProcAddress(pBKLinfo->hCoreDll, TEXT("GetSystemPowerStatusEx2"));
        if (!pBKLinfo->pfnGetSystemPowerStatusEx2) 
        {
            DEBUGMSG(ZONE_WARN,  (TEXT("GetProcAddress failed for GetSystemPowerStatusEx2. Assuming always on AC power.\r\n")));
        }
    }

//MYS     pBKLinfo->dwPddContext = BacklightInit(pContext, lpvBusContext, &(pBKLinfo->dwCurState));
    if (g_pBacklight->Initialize(pContext) == FALSE)
        {
        DEBUGMSG(ZONE_ERROR, (L"ERROR: BKL_Init: "
            L"Failed to initialize backlight object\r\n"
            ));
        goto error;
        }
    
    // if there are no user settings for this, we act as if they are selected:
    pBKLinfo->fBatteryTapOn = TRUE;
    pBKLinfo->fExternalTapOn = TRUE;

    // in case there is no setting for this:
    pBKLinfo->dwBattTimeout = 0;
    pBKLinfo->dwACTimeout = 0;

    pBKLinfo->dwCurState = D0;
    g_pBacklight->SetPowerState(pBKLinfo->dwCurState);
 
    //create thread to wait for reg / power source changes:
    pBKLinfo->hBklThread = CreateThread(0, 0, (LPTHREAD_START_ROUTINE)fnBackLightThread, pBKLinfo, 0, NULL);
    if(NULL == pBKLinfo->hBklThread)
    {
        DEBUGMSG(ZONE_ERROR, (TEXT("BLK_Init: OpenDeviceKey failed with %u\r\n"), dwStatus));
        goto error;
    }

    DEBUGMSG(ZONE_BACKLIGHT, (TEXT("-BKL_Init().\r\n")));

    return (DWORD) pBKLinfo;

error:
    if(hkDevice)
    {
        RegCloseKey(hkDevice);
    }

    FreeContext(pBKLinfo);    

    return 0;

}