예제 #1
0
// special version for WIDE characters
CDumpContext& CDumpContext::operator<<(LPCWSTR lpsz)
{
	if (lpsz == NULL)
	{
		OutputString("(NULL)");
		return *this;
	}

#ifdef _DEBUG // all CDumpContext output is controlled by afxTraceEnabled
	if (!afxTraceEnabled)
		return *this;
#endif //_DEBUG

	// limited length
	char szBuffer[512];
	_wcstombsz(szBuffer, lpsz, _countof(szBuffer));
	return *this << szBuffer;
}
예제 #2
0
//----------------------------------------------------------------------------------
// Name: StartElement
// Desc: Writes the beginning of an XML open tag.
//----------------------------------------------------------------------------------
BOOL XMLWriter::StartElement( const CHAR* strName )
{
    if( !m_bOpenTagFinished )
    {
        if( !EndOpenTag() ) 
            return FALSE;
        if( !WriteNewline() )
            return FALSE;
    }
    BOOL result = TRUE;
    result &= WriteIndent();
    PushName( strName );
    result &= OutputStringFast( "<", 1 );
    result &= OutputString( strName );
    m_bOpenTagFinished = FALSE;
    m_bWriteCloseTagIndent = FALSE;
    return result;
}
예제 #3
0
void CSkinSliderCtrl::OnLButtonDown(UINT nFlags, CPoint point)
{
	if ( PtInRect(&m_rcThumRect,point) )
	{
		m_bDragging = true;
		m_bPress = TRUE;
		SetCapture();

		RedrawWindow(NULL,NULL,RDW_FRAME|RDW_INVALIDATE|RDW_ERASE|RDW_ERASENOW);
	}
 	else
 	{
		CRect rcClient;
		GetClientRect(&rcClient);
 		if ( PtInRect(&rcClient,point) )
 		{
 			int nMax = 0;  
 			int nMin = 0;  
 			GetRange(nMin,nMax);  
 
			int nPos = 0;

			if ( GetStyle() & TBS_VERT )
 				nPos = (nMax - nMin)*(point.y - m_rcChannelRect.top)/m_rcChannelRect.Height(); 
			else 
				nPos = (nMax - nMin)*(point.x - m_rcChannelRect.left)/m_rcChannelRect.Width(); 
 
 			OutputString(TEXT("Down:%d\n"),nPos);
 			nPos += nMin;
 			SetPos(nPos); 
 			RedrawWindow(NULL,NULL,RDW_FRAME|RDW_INVALIDATE|RDW_ERASE|RDW_ERASENOW);

			if (GetParent() && ::IsWindow(GetParent()->m_hWnd))
			{
				GetParent()->SendMessage(WM_HSCROLL, MAKELONG(SB_THUMBTRACK, GetPos()), 
					(LPARAM)m_hWnd);
			}

 			return;
 		}
 	}

	__super::OnLButtonDown(nFlags, point);
}
static void DrawAngles(FCanvas* Canvas, int32 XPos, int32 YPos, EAxisList::Type ManipAxis, FWidget::EWidgetMode MoveMode, const FRotator& Rotation, const FVector& Translation)
{
	FString OutputString(TEXT(""));
	if (MoveMode == FWidget::WM_Rotate && Rotation.IsZero() == false)
	{
		//Only one value moves at a time
		const FVector EulerAngles = Rotation.Euler();
		if (ManipAxis == EAxisList::X)
		{
			OutputString += FString::Printf(TEXT("Roll: %0.2f"), EulerAngles.X);
		}
		else if (ManipAxis == EAxisList::Y)
		{
			OutputString += FString::Printf(TEXT("Pitch: %0.2f"), EulerAngles.Y);
		}
		else if (ManipAxis == EAxisList::Z)
		{
			OutputString += FString::Printf(TEXT("Yaw: %0.2f"), EulerAngles.Z);
		}
	}
	else if (MoveMode == FWidget::WM_Translate && Translation.IsZero() == false)
	{
		//Only one value moves at a time
		if (ManipAxis == EAxisList::X)
		{
			OutputString += FString::Printf(TEXT(" %0.2f"), Translation.X);
		}
		else if (ManipAxis == EAxisList::Y)
		{
			OutputString += FString::Printf(TEXT(" %0.2f"), Translation.Y);
		}
		else if (ManipAxis == EAxisList::Z)
		{
			OutputString += FString::Printf(TEXT(" %0.2f"), Translation.Z);
		}
	}

	if (OutputString.Len() > 0)
	{
		FCanvasTextItem TextItem( FVector2D(XPos, YPos), FText::FromString( OutputString ), GEngine->GetSmallFont(), FLinearColor::White );
		Canvas->DrawItem( TextItem );
	}
}
// feature PLEXTOR drive
BOOL SetSpeedRead(
	PEXT_ARG pExtArg,
	PDEVICE pDevice,
	BOOL bState
	)
{
	// PX-708, PXW4012 or older doesn't support SpeedRead
	if (pDevice->byPlxtrDrive == PLXTR_DRIVE_TYPE::PX760A ||
		pDevice->byPlxtrDrive == PLXTR_DRIVE_TYPE::PX755A ||
		pDevice->byPlxtrDrive == PLXTR_DRIVE_TYPE::PX716AL ||
		pDevice->byPlxtrDrive == PLXTR_DRIVE_TYPE::PX716A ||
		pDevice->byPlxtrDrive == PLXTR_DRIVE_TYPE::PX714A ||
		pDevice->byPlxtrDrive == PLXTR_DRIVE_TYPE::PX712A ||
		pDevice->byPlxtrDrive == PLXTR_DRIVE_TYPE::PREMIUM2 ||
		pDevice->byPlxtrDrive == PLXTR_DRIVE_TYPE::PREMIUM ||
		pDevice->byPlxtrDrive == PLXTR_DRIVE_TYPE::PXW5224A ||
		pDevice->byPlxtrDrive == PLXTR_DRIVE_TYPE::PXW4824A
		) {
		CONST WORD size = 8;
		BYTE buf[size] = { 0 };

		CDB::_CDB12 cdb = { 0 };
		cdb.OperationCode = SCSIOP_PLXTR_EXTEND;
		cdb.DisablePageOut = TRUE;
		cdb.LogicalBlock[0] = PLXTR_FLAG_SPEED_READ;
		cdb.LogicalBlock[1] = (BYTE)bState;
		cdb.Reserved2 = 0x08;

		BYTE byScsiStatus = 0;
		if (!ScsiPassThroughDirect(pExtArg, pDevice, &cdb, CDB12GENERIC_LENGTH
			, buf, sizeof(buf), &byScsiStatus, _T(__FUNCTION__), __LINE__)
			|| byScsiStatus >= SCSISTAT_CHECK_CONDITION) {
			return FALSE;
		}
#if 0
		for (INT i = 0; i < size; i++) {
			OutputString(_T("%02x "), buf[i]);
		}
		OutputString(_T("\n");
#endif
	}
예제 #6
0
void CNetwork::readInputFile()
{
    // open the TRAF file
    FILE *file_trf = NULL;
    if (file_trf = fopen(m_traf_input_file, "r"))
    {
        sprintf(out_buf, "Opened file: \"%s\".", m_traf_input_file);
        OutputString(out_buf, strlen(out_buf), SIM_COLOR_RGB, RTE_MESSAGE_RGB);
        // parse the time periods
        processTimePeriods(file_trf);
        rewind(file_trf);
        // create the node list
        getNodes(file_trf);
        rewind(file_trf);
        // create the link list
        getLinks(file_trf);
        rewind(file_trf);
        // find the opposing link for each link, if one exists
        int up = 0;
        int down = 0;
        CLink *link = NULL;
        POSITION pos = m_link_list.GetHeadPosition();
        while (pos != NULL)
        {
            link = m_link_list.GetNext(pos);
            up = link->getOpposingNodeId();
            down = link->m_dn_node->getId();
            CLink *opposing = NULL;
            opposing = findLink(up, down);
            link->setOpposingLink(opposing);
        }
        // create the lanes on each link
        createLanes(file_trf);
        rewind(file_trf);
        // NOTE: create here the signal timings for the nodes to be controlled by the algorithm, if you want
        // create the detectors that exist in the TRAF file
        getDetectors(file_trf);
        // close the stream
        fclose(file_trf);
    }
}
예제 #7
0
void CConverter::Write(const void FAR* lpBuf, UINT nCount)
{
	ASSERT(!m_bForeignToRtf);

	m_nBytesWritten += nCount;
	while (nCount != 0)
	{
		WaitForConverter();
		VERIFY(ResetEvent(m_hEventFile));
		if (m_bConvErr)
			AfxThrowFileException(CFileException::generic);
		m_nBytesAvail = min(nCount, BUFFSIZE);
		nCount -= m_nBytesAvail;
		BYTE* pBuf = (BYTE*)GlobalLock(m_hBuff);
		ASSERT(pBuf != NULL);
		memcpy(pBuf, lpBuf, m_nBytesAvail);
		GlobalUnlock(m_hBuff);
		SetEvent(m_hEventConv);
	}
	OutputString(m_strSaving);
}
예제 #8
0
void
DoData(
    char *data,
    FILE *fp
)
{
    char	*cp, buf[LINESIZE], *dp, *sub, prev;
    int		i, mapped;

    /*  Worry about embedded newlines? */

    if (!fp) return;

    /* CLEANUP: this should really all be done in OutputString(). (I think) */

    if (nCharMap) {
	/* for each character, see if it's mapped to something else */
	for (prev=0,cp=data,dp=buf; *cp; cp++) {
	    if (prev == '\\') {
		*dp++ = *cp;
		prev = *cp;
		continue;
	    }
	    for (mapped=0,i=0; i<nCharMap; i++) {
		if (*cp != CharMap[i].name[0]) continue;
		sub = CharMap[i].sval;
		while (*sub) *dp++ = *sub++;
		mapped = 1;
		break;
	    }
	    if (!mapped) *dp++ = *cp;
	    prev = *cp;
	}
	*dp = EOS;
	dp = buf;
    }
    else dp = data;
    OutputString(dp, fp, 1);
}
예제 #9
0
//	o General routines o
//		LoadLibrary : prevent a process from escaping hijack by loading a new dll and calling one of its function
HINSTANCE WINAPI MyLoadLibrary( LPCTSTR lpLibFileName )
{
	HINSTANCE hInst= NULL;
	HMODULE	  hMod = NULL;
	char	 *lDll = NULL;			// dll path in lower case

	OutputString("\n[!] Run time load of DLL => '%s' (%s), patching APIs.\n", lpLibFileName, ExePath);
	
	// Check if Dll was already loaded
	hMod = GetModuleHandle(lpLibFileName);

	hInst = (HINSTANCE) fLoadLibrary(lpLibFileName);
	
	if(hInst) 
	{
		//OutputString(" OK, trying to patch APIs... \n");
		
		// If dll was already loaded, don't set hooks a second time
		if(hMod==NULL)
		{
	
			// Duplicate Dll path "winnt.h"
			lDll = _strdup( (char*)lpLibFileName );
			if(!lDll)
				goto end;
			// Convert it to lower case
			_strlwr(lDll);
			
			SetUpHooks((int)NTI_ON_NEW_DLL, (char*)lDll);
			//HijackApiOfNewModule((HMODULE)hInst, lpLibFileName, "*");
			
			free(lDll);
		}		
	}

end:
  return hInst;
}
예제 #10
0
// https://msdn.microsoft.com/ja-jp/library/ff551396(v=vs.85).aspx
BOOL SetCDSpeed(
	PEXT_ARG pExtArg,
	PDEVICE pDevice,
	DWORD dwCDSpeedNum
	)
{
	if (pDevice->FEATURE.bySetCDSpeed) {
		WORD wSpeed = 0;
		_declspec(align(4)) CDROM_SET_SPEED setspeed;
		if (0 < dwCDSpeedNum && dwCDSpeedNum <= DRIVE_MAX_SPEED) {
			wSpeed = (WORD)(CD_RAW_SECTOR_SIZE * 75 * dwCDSpeedNum / 1000);
			setspeed.ReadSpeed = wSpeed;
		}
		else {
			wSpeed = 0xffff;
			setspeed.ReadSpeed = pDevice->wMaxReadSpeed;
		}
		CDB::_SET_CD_SPEED cdb = { 0 };
		cdb.OperationCode = SCSIOP_SET_CD_SPEED;
		REVERSE_BYTES_SHORT(&cdb.ReadSpeed, &wSpeed);
		setspeed.RequestType = CdromSetSpeed;
		setspeed.RotationControl = CdromDefaultRotation;

		BYTE byScsiStatus = 0;
		if (!ScsiPassThroughDirect(pExtArg, pDevice, &cdb, CDB12GENERIC_LENGTH, &setspeed, 
			sizeof(CDROM_SET_SPEED), &byScsiStatus, _T(__FUNCTION__), __LINE__)
			|| byScsiStatus >= SCSISTAT_CHECK_CONDITION) {
			// Somehow PX-W1210S fails...
			OutputDriveNoSupportLogA(SET_CD_SPEED);
			OutputDriveLogA("Or if you use the SATA/IDE to USB adapter, doesn't support this command\n");
		}
		else {
			OutputSetSpeed(&setspeed);
			OutputString(_T("Set the drive speed: %uKB/sec\n"), setspeed.ReadSpeed);
		}
	}
	return TRUE;
}
예제 #11
0
//----------------------------------------------------------------------------------
// Name: EndElement
// Desc: Writes an element close tag corresponding with the most recent open tag.
//----------------------------------------------------------------------------------
BOOL XMLWriter::EndElement()
{
    const CHAR* strName = PopName();
    if( strName == nullptr )
        return FALSE;
    BOOL result = TRUE;
    if( !m_bOpenTagFinished )
    {
        m_bOpenTagFinished = TRUE;
        result &= OutputStringFast( " />", 3 );
        result &= WriteNewline();
        m_bWriteCloseTagIndent = TRUE;
        return result;
    }
    if( m_bWriteCloseTagIndent )
        result &= WriteIndent();
    result &= OutputStringFast( "</", 2 );
    result &= OutputString( strName );
    result &= OutputStringFast( ">", 1 );
    result &= WriteNewline();
    m_bWriteCloseTagIndent = TRUE;
    return result;
}
예제 #12
0
파일: about.c 프로젝트: t3swing/fcitx-clone
void DrawAboutWindow (void)
{
#ifdef _USE_XFT
    OutputString (aboutWindow, xftVKWindowFont, strTitle, (ABOUT_WINDOW_WIDTH - StringWidth (strTitle, xftVKWindowFont)) / 2, iVKWindowFontSize + 6 + 30, AboutWindowFontColor.color);
#else
    OutputString (aboutWindow, fontSetVKWindow, strTitle, (ABOUT_WINDOW_WIDTH - StringWidth (strTitle, fontSetVKWindow)) / 2, iVKWindowFontSize + 6 + 30, AboutWindowFontColor.gc);
#endif

#ifdef _USE_XFT
    OutputString (aboutWindow, xftVKWindowFont, AboutEmail, (ABOUT_WINDOW_WIDTH - StringWidth (AboutEmail, xftVKWindowFont)) / 2, iVKWindowFontSize + 6 + 60, AboutWindowFontColor.color);
#else
    OutputString (aboutWindow, fontSetVKWindow, AboutEmail, (ABOUT_WINDOW_WIDTH - StringWidth (AboutEmail, fontSetVKWindow)) / 2, iVKWindowFontSize + 6 + 60, AboutWindowFontColor.gc);
#endif

#ifdef _USE_XFT
    OutputString (aboutWindow, xftVKWindowFont, AboutCopyRight, (ABOUT_WINDOW_WIDTH - StringWidth (AboutCopyRight, xftVKWindowFont)) / 2, iVKWindowFontSize + 6 + 80, AboutWindowFontColor.color);
#else
    OutputString (aboutWindow, fontSetVKWindow, AboutCopyRight, (ABOUT_WINDOW_WIDTH - StringWidth (AboutCopyRight, fontSetVKWindow)) / 2, iVKWindowFontSize + 6 + 80, AboutWindowFontColor.gc);
#endif
}
예제 #13
0
파일: xml.cpp 프로젝트: AlexHayton/decoda
// Same as above, but create entities first.
// Translates '<' to "&lt;", '>' to "&gt;" and '&' to "&amp;"
static void OutputStringEnt(wxOutputStream& stream, const wxString& str,
                            wxMBConv *convMem = NULL,
                            wxMBConv *convFile = NULL,
                            int flags = 0)
{
    wxString buf;
    size_t i, last, len;
    wxChar c;

    len = str.Len();
    last = 0;
    for (i = 0; i < len; i++)
    {
        c = str.GetChar(i);
        if (c == wxT('<') || c == wxT('>') ||
            (c == wxT('&') && str.Mid(i+1, 4) != wxT("amp;")) ||
            ((flags & XML_ESCAPE_QUOTES) && c == wxT('"')))
        {
            OutputString(stream, str.Mid(last, i - last), convMem, convFile);
            switch (c)
            {
                case wxT('<'):
                    OutputString(stream, wxT("&lt;"));
                    break;
                case wxT('>'):
                    OutputString(stream, wxT("&gt;"));
                    break;
                case wxT('&'):
                    OutputString(stream, wxT("&amp;"));
                    break;
                case wxT('"'):
                    OutputString(stream, wxT("&quot;"));
                    break;
                default:
                    break;
            }
            last = i + 1;
        }
    }
    OutputString(stream, str.Mid(last, i - last), convMem, convFile);
}
예제 #14
0
// Same as above, but create entities first.
// Translates '<' to "&lt;", '>' to "&gt;" and '&' to "&amp;"
static void OutputStringEnt(wxOutputStream& stream, const wxString& str,
                            wxMBConv *convMem, wxMBConv *convFile,
                            bool escapeQuotes = false)
{
    wxString buf;
    size_t i, last, len;
    wxChar c;

    len = str.Len();
    last = 0;
    for (i = 0; i < len; i++)
    {
        c = str.GetChar(i);
        if (c == wxT('<') || c == wxT('>') ||
            (c == wxT('&') && str.Mid(i+1, 4) != wxT("amp;")) ||
            (escapeQuotes && c == wxT('"')))
        {
            OutputString(stream, str.Mid(last, i - last), convMem, convFile);
            switch (c)
            {
                case wxT('<'):
                    OutputString(stream, wxT("&lt;"), NULL, NULL);
                    break;
                case wxT('>'):
                    OutputString(stream, wxT("&gt;"), NULL, NULL);
                    break;
                case wxT('&'):
                    OutputString(stream, wxT("&amp;"), NULL, NULL);
                    break;
                case wxT('"'):
                    OutputString(stream, wxT("&quot;"), NULL, NULL);
                    break;
                default: break;
            }
            last = i + 1;
        }
    }
    OutputString(stream, str.Mid(last, i - last), convMem, convFile);
}
예제 #15
0
bool Inflator::DecodeBody()
{
    bool blockEnd = false;
    switch (m_blockType)
    {
    case 0:	// stored
        assert(m_reader.BitsBuffered() == 0);
        while (!m_inQueue.IsEmpty() && !blockEnd)
        {
            size_t size;
            const byte *block = m_inQueue.Spy(size);
            size = UnsignedMin(m_storedLen, size);
            OutputString(block, size);
            m_inQueue.Skip(size);
            m_storedLen -= (word16)size;
            if (m_storedLen == 0)
                blockEnd = true;
        }
        break;
    case 1:	// fixed codes
    case 2:	// dynamic codes
        static const unsigned int lengthStarts[] = {
            3, 4, 5, 6, 7, 8, 9, 10, 11, 13, 15, 17, 19, 23, 27, 31,
            35, 43, 51, 59, 67, 83, 99, 115, 131, 163, 195, 227, 258
        };
        static const unsigned int lengthExtraBits[] = {
            0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 2, 2, 2, 2,
            3, 3, 3, 3, 4, 4, 4, 4, 5, 5, 5, 5, 0
        };
        static const unsigned int distanceStarts[] = {
            1, 2, 3, 4, 5, 7, 9, 13, 17, 25, 33, 49, 65, 97, 129, 193,
            257, 385, 513, 769, 1025, 1537, 2049, 3073, 4097, 6145,
            8193, 12289, 16385, 24577
        };
        static const unsigned int distanceExtraBits[] = {
            0, 0, 0, 0, 1, 1, 2, 2, 3, 3, 4, 4, 5, 5, 6, 6,
            7, 7, 8, 8, 9, 9, 10, 10, 11, 11,
            12, 12, 13, 13
        };

        const HuffmanDecoder& literalDecoder = GetLiteralDecoder();
        const HuffmanDecoder& distanceDecoder = GetDistanceDecoder();

        switch (m_nextDecode)
        {
        case LITERAL:
            while (true)
            {
                if (!literalDecoder.Decode(m_reader, m_literal))
                {
                    m_nextDecode = LITERAL;
                    break;
                }
                if (m_literal < 256)
                    OutputByte((byte)m_literal);
                else if (m_literal == 256)	// end of block
                {
                    blockEnd = true;
                    break;
                }
                else
                {
                    if (m_literal > 285)
                        throw BadBlockErr();
                    unsigned int bits;
                case LENGTH_BITS:
                    bits = lengthExtraBits[m_literal-257];
                    if (!m_reader.FillBuffer(bits))
                    {
                        m_nextDecode = LENGTH_BITS;
                        break;
                    }
                    m_literal = m_reader.GetBits(bits) + lengthStarts[m_literal-257];
                case DISTANCE:
                    if (!distanceDecoder.Decode(m_reader, m_distance))
                    {
                        m_nextDecode = DISTANCE;
                        break;
                    }
                case DISTANCE_BITS:
                    bits = distanceExtraBits[m_distance];
                    if (!m_reader.FillBuffer(bits))
                    {
                        m_nextDecode = DISTANCE_BITS;
                        break;
                    }
                    m_distance = m_reader.GetBits(bits) + distanceStarts[m_distance];
                    OutputPast(m_literal, m_distance);
                }
            }
        }
    }
    if (blockEnd)
    {
        if (m_eof)
        {
            FlushOutput();
            m_reader.SkipBits(m_reader.BitsBuffered()%8);
            if (m_reader.BitsBuffered())
            {
                // undo too much lookahead
                SecBlockWithHint<byte, 4> buffer(m_reader.BitsBuffered() / 8);
                for (unsigned int i=0; i<buffer.size(); i++)
                    buffer[i] = (byte)m_reader.GetBits(8);
                m_inQueue.Unget(buffer, buffer.size());
            }
            m_state = POST_STREAM;
        }
        else
            m_state = WAIT_HEADER;
    }
    return blockEnd;
}
예제 #16
0
void print_const(PycRef<PycObject> obj, PycModule* mod)
{
    switch (obj->type()) {
    case PycObject::TYPE_STRING:
    case PycObject::TYPE_STRINGREF:
    case PycObject::TYPE_INTERNED:
        OutputString(obj.cast<PycString>(), (mod->majorVer() == 3) ? 'b' : 0);
        break;
    case PycObject::TYPE_UNICODE:
        OutputString(obj.cast<PycString>(), (mod->majorVer() == 3) ? 0 : 'u');
        break;
    case PycObject::TYPE_TUPLE:
        {
            fprintf(pyc_output, "(");
            PycTuple::value_t values = obj.cast<PycTuple>()->values();
            PycTuple::value_t::const_iterator it = values.begin();
            if (it != values.end()) {
                print_const(*it, mod);
                while (++it != values.end()) {
                    fprintf(pyc_output, ", ");
                    print_const(*it, mod);
                }
            }
            if (values.size() == 1)
                fprintf(pyc_output, ",)");
            else
                fprintf(pyc_output, ")");
        }
        break;
    case PycObject::TYPE_LIST:
        {
            fprintf(pyc_output, "[");
            PycList::value_t values = obj.cast<PycList>()->values();
            PycList::value_t::const_iterator it = values.begin();
            if (it != values.end()) {
                print_const(*it, mod);
                while (++it != values.end()) {
                    fprintf(pyc_output, ", ");
                    print_const(*it, mod);
                }
            }
            fprintf(pyc_output, "]");
        }
        break;
    case PycObject::TYPE_DICT:
        {
            fprintf(pyc_output, "{");
            PycDict::key_t keys = obj.cast<PycDict>()->keys();
            PycDict::value_t values = obj.cast<PycDict>()->values();
            PycDict::key_t::const_iterator ki = keys.begin();
            PycDict::value_t::const_iterator vi = values.begin();
            if (ki != keys.end()) {
                print_const(*ki, mod);
                fprintf(pyc_output, ": ");
                print_const(*vi, mod);
                while (++ki != keys.end()) {
                    ++vi;
                    fprintf(pyc_output, ", ");
                    print_const(*ki, mod);
                    fprintf(pyc_output, ": ");
                    print_const(*vi, mod);
                }
            }
            fprintf(pyc_output, "}");
        }
        break;
    case PycObject::TYPE_SET:
        {
            fprintf(pyc_output, "{");
            PycSet::value_t values = obj.cast<PycSet>()->values();
            PycSet::value_t::const_iterator it = values.begin();
            if (it != values.end()) {
                print_const(*it, mod);
                while (++it != values.end()) {
                    fprintf(pyc_output, ", ");
                    print_const(*it, mod);
                }
            }
            fprintf(pyc_output, "}");
        }
        break;
    case PycObject::TYPE_NONE:
        fprintf(pyc_output, "None");
        break;
    case PycObject::TYPE_TRUE:
        fprintf(pyc_output, "True");
        break;
    case PycObject::TYPE_FALSE:
        fprintf(pyc_output, "False");
        break;
    case PycObject::TYPE_INT:
        fprintf(pyc_output, "%d", obj.cast<PycInt>()->value());
        break;
    case PycObject::TYPE_LONG:
        fprintf(pyc_output, "%s", obj.cast<PycLong>()->repr().c_str());
        break;
    case PycObject::TYPE_FLOAT:
        fprintf(pyc_output, "%s", obj.cast<PycFloat>()->value());
        break;
    case PycObject::TYPE_COMPLEX:
        fprintf(pyc_output, "(%s+%sj)", obj.cast<PycComplex>()->value(),
                                        obj.cast<PycComplex>()->imag());
        break;
    case PycObject::TYPE_BINARY_FLOAT:
        fprintf(pyc_output, "%g", obj.cast<PycCFloat>()->value());
        break;
    case PycObject::TYPE_BINARY_COMPLEX:
        fprintf(pyc_output, "(%g+%gj)", obj.cast<PycCComplex>()->value(),
                                        obj.cast<PycCComplex>()->imag());
        break;
    case PycObject::TYPE_CODE:
    case PycObject::TYPE_CODE2:
        fprintf(pyc_output, "<CODE> %s", obj.cast<PycCode>()->name()->value());
        break;
    }
}
예제 #17
0
int main(int argc, char *argv[]) {
    xlsWorkBook* pWB;
    xlsWorkSheet* pWS;
    unsigned int i;
    int justList = 0;
    char *sheetName = "";

    if(argc < 2) {
        Usage(argv[0]);
    }

    optind = 2; // skip file arg

    int ch;
    while ((ch = getopt(argc, argv, "lt:e:q:f:")) != -1) {
        switch (ch) {
        case 'l':
            justList = 1;
            break;
        case 'e':
            encoding = strdup(optarg);
            break;
        case 't':
            sheetName = strdup(optarg);
            break;
        case 'q':
            stringSeparator = optarg[0];
            break;
        case 'f':
            fieldSeparator = strdup(optarg);
            break;
        default:
            Usage(argv[0]);
            break;
        }
     }

    struct st_row_data* row;
    WORD cellRow, cellCol;

    // open workbook, choose standard conversion
    pWB = xls_open(argv[1], encoding);
    if (!pWB) {
        fprintf(stderr, "File not found");
        fprintf(stderr, "\n");
        return EXIT_FAILURE;
    }

    // check if the requested sheet (if any) exists
    if (sheetName[0]) {
        for (i = 0; i < pWB->sheets.count; i++) {
            if (strcmp(sheetName, pWB->sheets.sheet[i].name) == 0) {
                break;
            }
        }

        if (i == pWB->sheets.count) {
            fprintf(stderr, "Sheet \"%s\" not found", sheetName);
            fprintf(stderr, "\n");
            return EXIT_FAILURE;
        }
    }

    // process all sheets
    for (i = 0; i < pWB->sheets.count; i++) {
        int isFirstLine = 1;

        // just looking for sheet names
        if (justList) {
            printf("%s\n", pWB->sheets.sheet[i].name);
            continue;
        }

        // check if this the sheet we want
        if (sheetName[0]) {
            if (strcmp(sheetName, pWB->sheets.sheet[i].name) != 0) {
                continue;
            }
        }

        // open and parse the sheet
        pWS = xls_getWorkSheet(pWB, i);
        xls_parseWorkSheet(pWS);

        // process all rows of the sheet
        for (cellRow = 0; cellRow <= pWS->rows.lastrow; cellRow++) {
            int isFirstCol = 1;
            row = xls_row(pWS, cellRow);

            // process cells
            if (!isFirstLine) {
                printf("%s", lineSeparator);
            } else {
                isFirstLine = 0;
            }

            for (cellCol = 0; cellCol <= pWS->rows.lastcol; cellCol++) {
                //printf("Processing row=%d col=%d\n", cellRow+1, cellCol+1);

                xlsCell *cell = xls_cell(pWS, cellRow, cellCol);

                if ((!cell) || (cell->isHidden)) {
                    continue;
                }

                if (!isFirstCol) {
                    printf("%s", fieldSeparator);
                } else {
                    isFirstCol = 0;
                }

                // display the colspan as only one cell, but reject rowspans (they can't be converted to CSV)
                if (cell->rowspan > 1) {
                    fprintf(stderr, "Warning: %d rows spanned at col=%d row=%d: output will not match the Excel file.\n", cell->rowspan, cellCol+1, cellRow+1);
                }

                // display the value of the cell (either numeric or string)
                if (cell->id == 0x27e || cell->id == 0x0BD || cell->id == 0x203) {
                    OutputNumber(cell->d);
                } else if (cell->id == 0x06) {
                    // formula
                    if (cell->l == 0) // its a number
                    {
                        OutputNumber(cell->d);
                    } else {
                        if (!strcmp(cell->str, "bool")) // its boolean, and test cell->d
                        {
                            OutputString((int) cell->d ? "true" : "false");
                        } else if (!strcmp(cell->str, "error")) // formula is in error
                        {
                            OutputString("*error*");
                        } else // ... cell->str is valid as the result of a string formula.
                        {
                            OutputString(cell->str);
                        }
                    }
                } else if (cell->str != NULL) {
                    OutputString(cell->str);
                } else {
                    OutputString("");
                }
            }
        }
        xls_close_WS(pWS);
    }

    xls_close(pWB);
    return EXIT_SUCCESS;
}
예제 #18
0
파일: genBench.c 프로젝트: blusjune/.bsrc
/**
 * Generates an experiment (i.e. one run of a micro-bench) using given
 * parameters and writes it to the given file.
 *
 * @param fp output file
 * @param PB a pointer to a structure containing benchmark parameters for this session
 */
static void
GenExp (FILE        *fp,
        UflipParams *PB)
{
  char cm [MAX_STR];

  if (PB->processID > 0)
    {
      sprintf (cm, PAR_PREFIX" "EXEC_PREFIX""PACKAGE_NAME" Run ");
    }
  else
    {
      sprintf (cm, EXEC_PREFIX""PACKAGE_NAME" Run ");
    }

  if (PB->warning != 0)
    sprintf (cm + strlen (cm), "Warn %d ", PB->warning);

  sprintf (cm + strlen (cm), "Com %s ",   PB->comment);
  sprintf (cm + strlen (cm), "Bench %d ", PB->microBenchID);
  sprintf (cm + strlen (cm), "Exp %d ",   PB->expID);
  sprintf (cm + strlen (cm), "Key %d ",   PB->key);
  sprintf (cm + strlen (cm), "Run %d ",   PB->runID);
  sprintf (cm + strlen (cm), "Dev %s ",   uflip_device_to_string (PB->device));
  sprintf (cm + strlen (cm), "IOS %d ",   PB->IOSize);

  switch (PB->microBenchID)
    {
      case ALI:
        sprintf (cm + strlen (cm), "Shift %d ", PB->IOShift);
        break;
      case LOC:
        sprintf (cm + strlen (cm), "TSize %d ", PB->targetSize);
        break;
      case PAT:
        sprintf (cm + strlen (cm), "Part %d ", PB->nbPartition);
        break;
      case ORD:
        sprintf (cm + strlen (cm), "Order %d ", PB->order);
        break;
      case PAR:
        sprintf (cm + strlen (cm), "ParDeg %d PID %d ", PB->parDeg, PB->processID);
        break;
      case MIX:
        sprintf (cm + strlen (cm), "Base2 %s Ratio %d TSize2 %d TOffs2 %d ",
                 PB->base2, PB->ratio, PB->targetSize2, PB->targetOffset2);
        break;
      case PIO:
        sprintf (cm + strlen (cm), "PIO %d ", PB->pauseIO);
        break;
      case PBU:
        sprintf (cm + strlen (cm), "PBurst %d BurstIO %d ",  PB->pauseBurst, PB->burstIO);
        break;
      default:
        /* nothing to do */
        break;
    }

  sprintf (cm + strlen (cm), "Base %s ", PB->base);
  sprintf (cm + strlen (cm), "IOC %d ", PB->IOCount);

  if (PB->microBenchID != LOC)
    sprintf (cm + strlen (cm), "TSize %d ", PB->targetSize);

  sprintf (cm + strlen (cm), "TOffs %d ", PB->targetOffset);
  sprintf (cm + strlen (cm), "IgnIO %d ", PB->ignoreIO);
  sprintf (cm + strlen (cm), "Pause %d ", PB->pauseExp);

  if (PB->collectErase != INT32_MAX)
    sprintf (cm + strlen (cm), "CErase %d ", PB->collectErase);

  if (PB->fake == true)
    strcat (cm, "Fake True ");

  if (PB->bufferType == HW_BUFFERING)
    {
      strcat (cm, "BufferType H ");
    }
  else if (PB->bufferType == FS_BUFFERING)
    {
      strcat (cm, "BufferType S ");
    }
  else if (PB->bufferType == (HW_BUFFERING | FS_BUFFERING))
    {
      strcat (cm, "BufferType A ");
    }

  if (PB->processID > 0)
    sprintf (cm + strlen (cm), " "PAR_SUFFIX);

  strcat (cm, "\n");
  fprintf (fp, "%s", cm);
  OutputString (OUT_LOG, cm);
}
예제 #19
0
파일: genBench.c 프로젝트: blusjune/.bsrc
void
GenBench (UflipParams *PBBench)
{
  bool         finished = false;
  int32_t      prevExp  = 0;
  int32_t      currExp;
  int32_t      numExp;
  FILE        *fp       = NULL;  /* file pointer */
  FILE        *fp2      = NULL;  /* file pointer */
  char         str [MAX_STR];
  int32_t      tabVal [MAX_VARYING_VAL];
  UflipParams *PBExp;
  int32_t      nbVal;
  item        *memList;
  bool         tabSel [MAXBENCH*MAXMODE];
  int32_t      nbExp    = 0;
  int          key      = 0;

  if (parseSel (PBBench, tabSel) == -1)
    HandleError (__func__, "Problem with the experimentation plan!", 0, ERR_ABORT);

  /* Allocate data structure for computing target offset */
  memList = InitMemList ((int32_t) (PBBench->deviceSize));
  if (memList == NULL)
    HandleError (__func__, "Could not allocate memList", errno, ERR_ABORT);

  fp2 = fopen (PBBench->outName, "w");
  if (fp2 == NULL)
    HandleError (__func__, "Could not open output file", errno, ERR_ABORT);

  if (fwrite (SCRIPT_SHEBANGS, sizeof (char), strlen (SCRIPT_SHEBANGS), fp2) < strlen (SCRIPT_SHEBANGS))
    {
      int err = errno;
      fclose (fp2);
      HandleError (__func__, "Could not write to output file", err, ERR_ABORT);
    }

  while (finished == false)
    {
      /* find the next experiment - it is the smallest numExp, greater than prevExp */
      if ((fp = fopen (PBBench->expPlan, "r")) == NULL )
        HandleError (__func__, "Cannot open experimentation plan file", errno, ERR_ABORT);

      currExp = INT32_MAX;
      while (fgets(str, MAX_STR,fp) != NULL)
        {
          numExp = atoi (str);
          if ((numExp > prevExp) && (numExp < currExp))
            currExp = numExp;
        }

      if ((currExp > prevExp) && (currExp != INT32_MAX))
        {
          printf ("===================  Order Number %d\n", currExp);

          /* New param structure */
          PBExp = uflip_params_new ();
          PBExp->device = uflip_device_copy (PBBench->device);
          if (PBExp->device == NULL)
                    HandleError (__func__, "couldn't allocate Param->device subblock", 0, ERR_ABORT);

          InitParams (PBExp);
          PBExp->IOSize       = PBBench->IOSize;
          PBExp->IOCount      = PBBench->IOCount;
          PBExp->IOCountSR    = PBBench->IOCountSR;
          PBExp->IOCountRR    = PBBench->IOCountRR;
          PBExp->IOCountSW    = PBBench->IOCountSW;
          PBExp->IOCountRW    = PBBench->IOCountRW;
          PBExp->ignoreIO     = PBBench->ignoreIO;
          PBExp->ignoreIOSR   = PBBench->ignoreIOSR;
          PBExp->ignoreIORR   = PBBench->ignoreIORR;
          PBExp->ignoreIOSW   = PBBench->ignoreIOSW;
          PBExp->ignoreIORW   = PBBench->ignoreIORW;
          PBExp->collectErase = PBBench->collectErase;
          PBExp->pauseExp     = PBBench->pauseExp;
          PBExp->fake         = PBBench->fake;
          PBExp->bufferType   = PBBench->bufferType;
          PBExp->deviceSize   = PBBench->deviceSize;
          PBExp->burstIO      = PBBench->burstIO;
          PBExp->nbRun        = PBBench->nbRun;

          /* parse the experiment */
          nbVal = parseExp (fp, currExp, PBExp, tabVal);
          if (nbVal == -1)
            HandleError (__func__, "Problem with the experimentation selection!", 0, ERR_ABORT);

          if (tabSel [(PBExp->microBenchID - 1) * MAXMODE + PBExp->expID - 1] == true)
            {
              for (int32_t exp = 0; exp < nbVal; ++exp)
                {
                  /* Compute the different parameters */
                  if (PBExp->microBenchID == PAR)
                    {
                      for (PBExp->runID = 0; PBExp->runID < PBExp->nbRun; ++PBExp->runID)
                        {
                          PBExp->parDeg = tabVal [exp];
                          for (int32_t pID = 0; pID < PBExp->parDeg; ++pID)
                            {
                              PBExp->processID = PBExp->parDeg - pID - 1;
                              PBExp->key       = key++;
                              ComputeParams (PBExp, memList, PBExp->parDeg, nbVal);
                              GenExp (fp2, PBExp);
                              ++nbExp;
                              PBExp->IOSize    = PBBench->IOSize;
                              PBExp->IOCount   = PBBench->IOCount;
                              PBExp->ignoreIO  = PBBench->ignoreIO;
                            }
                        }
                    }
                  else
                    {
                      for (PBExp->runID = 0; PBExp->runID < PBExp->nbRun; ++PBExp->runID)
                        {
                          PBExp->key      = key++;
                          ComputeParams (PBExp, memList, tabVal [exp], nbVal);
                          GenExp (fp2, PBExp);
                          ++nbExp;
                          PBExp->IOSize   = PBBench->IOSize;
                          PBExp->IOCount  = PBBench->IOCount;
                          PBExp->ignoreIO = PBBench->ignoreIO;
                        }
                    }
                }
            }
          else
            {
              printf ("===================  Not Selected\n");
            }
          fprintf (fp2, "\n");
        }
      else
        {
          finished = true;
        }
      prevExp = currExp;
      uflip_params_destroy (PBExp);
      PBExp = NULL;
      if (fp)
        fclose (fp);

    }
  fclose (fp2);

  while (memList)
    {
      item *tmp = memList->next;
      free (memList);
      memList = tmp;
    }

  sprintf (str, "%d Experiments have been generated\n", nbExp);
  OutputString (OUT_LOG, str);
}
예제 #20
0
void OutputTableHTML(void)
{
	int i, j, k;
	int melo = 0 - 1;

	void output_header();
	if (center_tables)
	{
		printf("<CENTER>");
		do_cr();
	}

	SetupExtraction();

	/* Here's where we dump the Html Page out */
	for (i=first_sheet; i<=last_sheet; i++)	/* For each worksheet */
	{
		update_default_font(i);
		if (ws_array[i] == 0)
			continue;
		if ((ws_array[i]->biggest_row == -1)||(ws_array[i]->biggest_col == -1))
			continue;
		if (ws_array[i]->c_array == 0)
			continue;
		trim_sheet_edges(i);

		/* Print its name */
		if (next_ws_title > 0)
		{
			if (ws_array[i]->ws_title.str)
			{
				printf("<H1><CENTER>");
				OutputString(&ws_array[i]->ws_title);
				printf("</CENTER></H1><br>");
				do_cr();
			}
			else
			{
				printf("<H1><CENTER>(Unknown Page)</CENTER></H1><br>");
				do_cr();
			}
		}

		/* Now dump the table */
		printf("<FONT FACE=\"");
		OutputString(&default_font);
		if (default_fontsize != 3)
			printf("\" SIZE=\"%d", default_fontsize);
		printf("\">");
		do_cr();
		printf("<TABLE BORDER=\"1\" CELLSPACING=\"2\">");
		do_cr();
		
		for (j=ws_array[i]->first_row; j<=ws_array[i]->biggest_row; j++)
		{
			update_default_alignment(i, j);
			melo++;
			printf("<TR   title=\"%u\" ",melo);
			if (null_string((U8 *)default_alignment))
				printf(">");
			else
			{
				if (strcmp(default_alignment, "left") != 0)
					printf(" ALIGN=\"%s\"", default_alignment);
				if (!aggressive)
					printf(" VALIGN=\"bottom\">\n");
				else
					printf(">");
			}
			for (k=ws_array[i]->first_col; k<=ws_array[i]->biggest_col; k++)
			{
				output_cell(ws_array[i]->c_array[(j*ws_array[i]->max_cols)+k],0); /* This stuff happens for each cell... */
				if (ws_array[i]->c_array[(j*ws_array[i]->max_cols)+k])
				{
					if (ws_array[i]->c_array[(j*ws_array[i]->max_cols)+k]->colspan != 0)
						 k += ws_array[i]->c_array[(j*ws_array[i]->max_cols)+k]->colspan-1;
				}
			}

			if (!aggressive)
				printf("</TR>\n");
		}
		printf("</table></FONT><HR>");
		do_cr();
	}

	if (center_tables)
	{
		printf("</CENTER>");
		do_cr();
	}

	/* Print the author's name in itallics... */
	if (author.str)
	{
		printf("<FONT SIZE=-1><I>Spreadsheet's Author:&nbsp;");
		OutputString(&author);
		printf("</I></FONT><br>");
		do_cr();
	}
	
	
	printf("<FONT SIZE=8><I>Total rows = %u + 1 header ",melo);
	printf("</I></FONT><br>");
	do_cr();

	/* Print when & how the file was last updated. */
	printf("<FONT SIZE=-1><I>Last Updated ");
	if (lastUpdated)
		printf("%s&nbsp; ", lastUpdated);
	switch (file_version)
	{
		case EXCEL95:
			printf("with Excel 5.0 or 95");
			break;
		case EXCEL97:
			printf("with Excel 97");
			break;
		default:
			printf("with Excel ????");
			break;
	}
	printf("</I></FONT><br>");
	do_cr();

	/* Next print Disclaimers... */
	if (NoFormat)
	{
		printf("<br>* This cell's format is not supported.<br>");
		do_cr();
	}
	if ((notAccurate)&&(formula_warnings))
	{
		printf("<br>** This cell's data may not be accurate.<br>");
		do_cr();
	}
	if (NotImplemented)
	{
		printf("<br>*** This cell's data type will be supported in the future.<br>");
		do_cr();
	}
	if (Unsupported)
	{
		printf("<br>**** This cell's type is unsupported.<br>");
		do_cr();
	}

	/* Now out exceeded capacity warnings... */
	if (MaxWorksheetsExceeded || MaxRowExceeded || MaxColExceeded || MaxStringsExceeded ||
		MaxFontsExceeded || MaxPalExceeded || MaxXFExceeded || MaxFormatsExceeded )
		printf("<FONT COLOR=\"%s\">", colorTab[0x0A]);
	if (MaxWorksheetsExceeded)
	{
		printf("The Maximum Number of Worksheets was exceeded, you might want to increase it.<br>");
		do_cr();
	}
	if (MaxRowExceeded)
	{
		printf("The Maximum Number of Rows was exceeded, you might want to increase it.<br>");
		do_cr();
	}
	if (MaxColExceeded)
	{
		printf("The Maximum Number of Columns was exceeded, you might want to increase it.<br>");
		do_cr();
	}
	if (MaxStringsExceeded)
	{
		printf("The Maximum Number of Strings was exceeded, you might want to increase it.<br>");
		do_cr();
	}
	if (MaxFontsExceeded)
	{
		printf("The Maximum Number of Fonts was exceeded, you might want to increase it.<br>");
		do_cr();
	}
	if (MaxPalExceeded)
	{
		printf("The Maximum Number of Color Palettes was exceeded, you might want to increase it.<br>");
		do_cr();
	}
	if (MaxXFExceeded)
	{
		printf("The Maximum Number of Extended Formats was exceeded, you might want to increase it.<br>");
		do_cr();
	}
	if (MaxFormatsExceeded)
	{
		printf("The Maximum Number of Formats was exceeded, you might want to increase it.<br>");
		do_cr();
	}
	if (MaxWorksheetsExceeded || MaxRowExceeded || MaxColExceeded || MaxStringsExceeded ||
		MaxFontsExceeded || MaxPalExceeded || MaxXFExceeded || MaxFormatsExceeded )
		printf("</FONT>");

	printf("&nbsp;<br>");
	do_cr();

	/* Output Credit */
	printf("<hr><FONT SIZE=-1>Created with <a href=\"http://chicago.sf.net/xlhtml\">xlhtml %s</a></FONT><br>", VERSION);
	do_cr();

	/* Output Tail */
	output_footer();
}
예제 #21
0
int main(               // MAIN-LINE
    int argc,           // - # arguments
    char *argv[] )      // - arguments list
{
#define src_file param[ count ]         // - name of source file
#define tgt_file param[ arg_count-1 ]   // - name of modifications file
    int                 count;              // - current source file #
    char                *p;                // - generic pointer
    SEGMENT             *seg;           // - segment structure
    struct utimbuf      dest_time;
    struct stat         src_time;
    char                *src = NULL;
    char                *tgt = NULL;
    char                *param[32];
    int                 arg_count = 0;

    for( count = 0; count < argc; count++ ) {
        if( argv[count][0] != '@' ) {
            param[arg_count] = malloc( strlen( argv[count] ) + 1 );
            strcpy( param[arg_count++], argv[count] );
        } else {
            FILE        *f;
            char        st[512], separator;
            int         i, j, k;
            size_t      len;

            f = fopen( argv[count] + 1, "r" );
            if( f == NULL ) {
                Error( "Unable to open indirect argument file" );
                continue;
            }

            fgets( st, 512, f );
            fclose( f );

            len = strlen( st );
            if( st[len - 1] == '\n' ) {
                --len;
                st[len] = 0;
            }

            i = 0;
            while( i < len ) {
                while( st[i] == ' ' )
                    i++;
                if( st[i] == 0 )
                    break;
                if( st[i] == '"' ) {
                    separator = '"';
                    i++;
                } else {
                    separator = ' ';
                }
                j = i;
                while( ( st[j] != separator ) && ( st[j] != 0 ) ) {
                    if( ( separator == '"' ) && ( st[j] == '\\' ) )
                        j++;
                    j++;
                }

                param[arg_count] = malloc( j - i + 1 );
                for( k = 0; k < j - i; k++ ) {
                    if( ( separator == '"' ) && ( st[i + k] == '\\' ) )
                        i++;
                    param[arg_count][k] = st[i + k];
                }
                param[arg_count][k] = 0;
                arg_count++;

                i = j;
                if( st[i] == '"' )
                    i++;
            }
        }
    }

    ErrCount = 0;
    if( arg_count < 3 ) {
        puts( "Usage: wsplice {src-file|option} tgt-file\n" );
        puts( "options are:" );
        puts( "    -i path\t\tcheck <path> for included files" );
        puts( "    -k seg_name\t\tSame as :KEEP" );
        puts( "    -r seg_name\t\tSame as :REMOVE" );
        puts( "    -f string\t\tSet output format to be <string>" );
        puts( "    -o string\t\tOutput <string> to tgt-file" );
        puts( "    -t tabstop\t\tSet tab character spacing" );
        puts( "    -u\t\t\tUse Unix style newlines for output file" );
        puts( "    -p\t\t\tpreserve same time stamp as src-file on tgt-file" );
    } else {
        if( 0 == stricmp( tgt_file, "-" ) ) {
            OutputFile = stdout;
        } else {
            OutputFile = fopen( tgt_file, "wb" );
            tgt = tgt_file;
        }
        if( OutputFile == NULL ) {
            Error( "Unable to open output file" );
        } else {
#define get_value() ( (src_file[2]=='\0') ? (++count,src_file) : &src_file[2])
            OutBufferLen = 0;
            for( count = 1; count < arg_count - 1; ++count ) {
                if( src_file[0] == '-' ) {
                    switch( src_file[1] ) {
                    case 'i':
                        p = get_value();
                        AddIncludePathList( p );
                        break;
                    case 'k':
                        p = get_value();
                        seg = SegmentLookUp( p );
                        if( seg != NULL )
                            seg->seg_type = SEG_KEEP;
                        break;
                    case 'r':
                        p = get_value();
                        seg = SegmentLookUp( p );
                        if( seg != NULL )
                            seg->seg_type = SEG_REMOVE;
                        break;
                    case 'f':
                        OutFmt = get_value();
                        break;
                    case 'o':
                        p = get_value();
                        OutputString( p, "" );
                        break;
                    case 't':
                        p = get_value();
                        TabStop = strtoul( p, &p, 0 );
                        if( TabStop == 0 || *p != '\0' ) {
                            Error( "Illegal tab value" );
                            exit( 1 );
                        }
                        break;
                    case 'u':
                        UnixStyle = TRUE;
                        break;
                    case 'p':
                        RestoreTime = TRUE;
                        break;
                    default:
                        Error( "Unknown option '%c'", src_file[1] );
                        break;
                    }
                } 
                else {
                    src = src_file;
                    ProcessSource( src_file );
                }
            }
            if( OutBufferLen > 0 )
                fwrite( OutBuffer, OutBufferLen, 1, OutputFile );
            fclose( OutputFile );
        }
    }
    if( RestoreTime ) {
        if( stat( src, &src_time ) == 0 ) {
            dest_time.actime = src_time.st_atime;
            dest_time.modtime = src_time.st_mtime;
            utime( tgt, &dest_time );
        }
    }

    return( ErrCount );

#undef src_file
#undef tgt_file
}
예제 #22
0
void ComputeParams(sParams* PB, item* memList, int32 value, int32 nbVal ) {
	
	static 	int32 	startAddress = 0;
	static int32 	shift = 0;
	int32 			size;
	int32 			size1;
	int32 			size2;
	bool 			isRead;
	bool 			isSeq;
	
	
	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;
	}
	if (strcasecmp(PB->base, "SW") == 0) {
		PB->ignoreIO = PB->ignoreIORR;
		PB->IOCount = PB->IOCountRR;
		isSeq = TRUE;
		isRead = FALSE;
	}
	if (strcasecmp(PB->base, "RR") == 0) {
		PB->ignoreIO = PB->ignoreIOSW;
		PB->IOCount = PB->IOCountSW;
		isSeq = FALSE;
		isRead = TRUE;
	}
	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
	if (PB->microBenchID == GRA) PB->IOSize = value;
	if (PB->microBenchID == ALI) PB->IOShift = value;
	if (PB->microBenchID == LOC) PB->targetSize = value * PB->IOSize ;
	if (PB->microBenchID == PAT) PB->nbPartition = value;
	if (PB->microBenchID == ORD) PB->order = value;
	if (PB->microBenchID == PAR) PB->parDeg = value;
	if (PB->microBenchID == MIX) PB->ratio = value;
	if (PB->microBenchID == PIO) PB->pauseIO = value;
	if (PB->microBenchID == PBU) PB->burstIO = value;

	// Number of sectors potentially touched by the experiment 
	size = PB->IOSize * PB->IOCount;
	if (PB->IOShift != 0) size += PB->IOSize; 
		
	if (PB->microBenchID == LOC) size = PB->targetSize;
	if (PB->microBenchID == ORD) size = PB->IOSize * abs(PB->order)* PB->IOCount;
	
	// 1-GRANULARITY , 2-ALIGNMENT, 8-PAUSE, 9-BURST
	if ((PB->microBenchID == GRA) || (PB->microBenchID == ALI)|| 
		(PB->microBenchID == PIO)|| (PB->microBenchID == PBU)) {
		
		if (isSeq == FALSE) 
			PB->targetOffset = 0;
		else if (isRead == TRUE) {
			PB->targetOffset = rg.IRandom(0,(int32)((PB->targetSize - size)/BLOCK))*BLOCK;
			PB->targetSize = size;
		}
		else {
			PB->targetOffset = MemSearch(memList, size);
			PB->targetSize = size;
		}
	}
	// 3-LOCALITY
	else if (PB->microBenchID == LOC) {
		if ((isRead == TRUE) || (value > 1024)) 
			PB->targetOffset = rg.IRandom(0,(int32)((PB->deviceSize - size)/BLOCK))*BLOCK;
		else {
			PB->targetOffset = MemSearch(memList, size);
			//printf("==>%d  %d\n",size, PB->targetOffset );
		}
	}
	// 07-MIX 
	else if (PB->microBenchID == MIX) {
		int32 I1, I2, C1, C2;
		
		I1 = PB->ignoreIO;
		C1 = PB->IOCount;
		if (strcasecmp(PB->base2, "SR") == 0) {
			I2 = PB->ignoreIOSR;
			C2 = PB->IOCountSR;
		}
		
		if (strcasecmp(PB->base2, "SW") == 0) {
			I2 = PB->ignoreIOSW;
			C2 = PB->IOCountSW;
		}
				
		if (strcasecmp(PB->base2, "RR") == 0) {
			I2 = PB->ignoreIORR;
			C2 = PB->IOCountRR;
		}

		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)(PB->IOCount/(-PB->ratio + 1)));
			size2 = PB->IOSize * (1+ (int32)((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)(PB->IOCount/(PB->ratio + 1)));
			size2 = PB->IOSize * (1+ (int32)((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 = rg.IRandom(0,(int32)((PB->deviceSize - size1)/BLOCK))*BLOCK;
			PB->targetOffset2 = 0;
			PB->targetSize2 = PB->deviceSize;
		}
		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;
		}
		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;
		}
		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;
		}
		if ((strcasecmp(PB->base, "SR") == 0) &&  (strcasecmp(PB->base2, "SW") == 0)) {
			PB->targetOffset2 = MemSearch(memList, size2);
			PB->targetSize2 = size2;
			PB->targetOffset = rg.IRandom((int32)((PB->deviceSize - MemMinAddress(memList))/2)/BLOCK,(int32)((PB->deviceSize - size1)/BLOCK))*BLOCK;
			PB->targetSize = size1;
		}
	}
	// 6-PARALLELISM
	else if (PB->microBenchID == PAR) {
		PB->targetSize = ((int32)((PB->deviceSize / PB->parDeg)/BLOCK))*BLOCK;
		if (isSeq == FALSE) 
			PB->targetOffset =  PB->processID * PB->targetSize;
		else if (isRead == TRUE) {
			PB->targetOffset =  rg.IRandom((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("ComputeParam", "device too small", 0, ERR_ABORT);
			PB->targetOffset =  MemAllocNearestAfterA(memList, (PB->processID) * PB->targetSize + startAddress, size);
			PB->targetSize = size;
		}
	}
	// 4-PARTITIONING
	else if (PB->microBenchID == PAT) {
		if ((isRead == TRUE) || (PB->nbPartition > 16)) {
			PB->targetOffset =  0;
			PB->targetSize = ((int32) (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) (size / (16*BLOCK)) + 1 ) * (16 * BLOCK);
			PB->targetSize = PB->deviceSize - startAddress - size * nbVal * PB->nbRun;
			PB->targetSize = (int32) (PB->targetSize/ (16 * BLOCK)) * (16 * BLOCK); 
			if (PB->targetSize < size) HandleError("ComputeParam", "device too small", 0, ERR_ABORT);
			PB->targetOffset = startAddress + shift;
			for (int32 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);
			}	
			shift = shift + size/PB->nbPartition;
		}
		
	}
	// 5-ORDER
	else if (PB->microBenchID == ORD) {
		size = PB->IOSize * PB->IOCount * PB->order;
		if (size == 0)  size = BLOCK;
		PB->targetSize = abs(size);
		if (isRead == TRUE) {
			PB->targetOffset =  rg.IRandom(0,(int32)((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 = rg.IRandom(0,(int32)((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;
		}
	}

	if (PB->targetOffset == INT32_MAX) HandleError("ComputeParam", "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);
	}
}
예제 #23
0
/*  Process an "output" translation spec - one of StartText, EndText,
 *  Replace, Message (these are the ones that produce output), or
 *  StartCode and EndCode (these get passed to the interpreter).
 *  Steps done:
 *	Expand attributes and regular varaibles in input string.
 *	Pass thru string, accumulating chars to be sent to output stream.
 *	If we find the start of a special variable, output what we've
 *	  accumulated, then find the special variable's "bounds" (ie, the
 *	  stuff between the curly brackets), and expand that by passing to
 *	  ExpandSpecialVar().  Continue until done the input string.
 *  Arguments:
 *	Input buffer (string) to be expanded and output.
 *	Pointer to element under consideration.
 *	FILE pointer to where to write output.
 *	Flag saying whether to track the character position we're on
 *	  (passed to OutputString).
 */
void
ProcesOutputSpec(
    char	*ib,
    Element_t	*e,
    FILE	*fp,
    int		track_pos
)
{
    char	obuf[LINESIZE];
    char	vbuf[LINESIZE];
    char	*dest, vname[LINESIZE], *cp;
    int		esc;

    obuf[0] = EOS;			/* start with empty output buffer */

    ExpandVariables(ib, vbuf, e);	/* expand regular variables */
    ib = vbuf;
    dest = obuf;

    esc = 0;
    while (*ib) {
	/* Is esc-$ next?  If so, just copy the '$'. */
	if (*ib == '\\' && ib[1] == VDELIM) {
	    ib++;			/* skip esc */
	    *dest++ = *ib++;		/* copy $ */
	    continue;
	}

	/* If not a $, it's a regular char.  Just copy it and go to next. */
	if (*ib != VDELIM) {		/* look for att/variable marker */
	    *dest++ = *ib++;		/* it's not. just copy character */
	    continue;
	}

	/* We have a $.  What we have must be a "special variable" since
	 * regular variables have already been expanded, or just a lone $. */

	if (ib[1] != L_CURLY) {	/* just a stray dollar sign (no variable) */
	    *dest++ = *ib++;
	    continue;
	}

	ib++;				/* point past $ */

	/* Output what we have in buffer so far. */
	*dest = EOS;			/* terminate string */
	if (obuf[0]) OutputString(obuf, fp, track_pos);
	dest = obuf;			/* ready for new stuff in buffer */

	if (!strchr(ib, R_CURLY)) {
	    fprintf(stderr, "Mismatched braces in TranSpec: %s\n", ib);
	    /* how do we recover from this? */
	}
	ib++;
	cp = vname;
	while (*ib && *ib != R_CURLY) *cp++ = *ib++;
	*cp = EOS;			/* terminate att/var name */
	ib++;				/* point past closing curly */
	/* we now have special variable name (stuff in curly {}'s) in vname */
	/* if the special variable is _break and it's true, we're done */
	if (ExpandSpecialVar(&vname[1], e, fp, track_pos) == CONT_BREAK) {
	    break;
	}
    }
    *dest = EOS;			/* terminate string in output buffer */

    if (obuf[0]) OutputString(obuf, fp, track_pos);
}
예제 #24
0
void CNetwork::getNodes(FILE *file)
{
    if (is_log_active && log_level == 2)
    {
        sprintf(out_buf, "Parsing %s ...", "nodes");
        OutputString(out_buf, strlen(out_buf), SIM_COLOR_RGB, RTE_MESSAGE_RGB);
    }
    // get the node information from the TRAF file and create the node list
    char line[81] = { '\0' };
    int card_type = 0;
    CNode *node = NULL;
    POSITION pos = NULL;
    int  node_id = 0;
    char node_ids[5] = { '\0' };
    char control_type[2] = { '\0' };
    char x_pos[7] = { '\0' };
    char y_pos[7] = { '\0' };
    // read data records from the TRAF file
    while (!feof(file))
    {
        // read a line of the file
        card_type = readTRFLine(file, line);
        // parse the line based on its card type
        if (card_type == 36 || card_type == 43)
        {
            // first, extract the node id
            strncpy_s(node_ids, line, 4);
            node_ids[4] = '\0';
            node_id = atoi(node_ids);
            // second, determine if this node is under external control
            strncpy_s(control_type, line + 76, 1);
            control_type[1] = '\0';
            if (node_id < 9000)
            {
                // create a node object
                if (node_id > 8000)
                {
                    node = new CNode(node_id, "source"); // source node
                }
                else
                {
                    if ((control_type[0] == '2') || (control_type[0] == '3'))
                    {
                        // node is controlled by algorithm external to corsim
                        node = new CNode(node_id, "external");
                    }
                    else
                    {
                        // node is controlled by corsim
                        node = new CNode(node_id, "corsim");
                    }
                }
                m_node_list.AddTail(node);
            }
        }
        else if (card_type == 195)
        {
            // first, get the node id
            strncpy_s(node_ids, line, 4);
            node_ids[4] = '\0';
            node_id = atoi(node_ids);
            // second, extract the node coordinates
            strncpy_s(x_pos, line + 6, 6);
            x_pos[6] = '\0';
            strncpy_s(y_pos, line + 14, 6);
            y_pos[6] = '\0';
            // search the node list for the corresponding node object and set its node coordinates
            pos = m_node_list.GetHeadPosition();
            while (pos != NULL)
            {
                node = m_node_list.GetNext(pos);
                if (node->getId() == node_id)
                {
                    node->setLocation(atoi(x_pos), atoi(y_pos));
                }
            }
        }
    }
    // assign the corsim internal id to each node
    int inode_id = 0;
    bool found;
    pos = m_node_list.GetHeadPosition();
    while (pos != NULL)
    {
        inode_id = 0;
        found = false;
        node = m_node_list.GetNext(pos);
        while ((inode_id < IMXNOD) && (!found))
        {
            if (node->getId() == net_node_num[inode_id])
            {
                found = true;
                node->setCorsimId(inode_id);
            }
            inode_id++;
        }
    }
}
예제 #25
0
파일: xml.cpp 프로젝트: 252525fb/rpcs3
static void OutputNode(wxOutputStream& stream, wxXmlNode *node, int indent,
                       wxMBConv *convMem, wxMBConv *convFile, int indentstep)
{
    wxXmlNode *n, *prev;
    wxXmlProperty *prop;

    switch (node->GetType())
    {
        case wxXML_CDATA_SECTION_NODE:
            OutputString( stream, wxT("<![CDATA["));
            OutputString( stream, node->GetContent() );
            OutputString( stream, wxT("]]>") );
            break;

        case wxXML_TEXT_NODE:
            OutputEscapedString(stream, node->GetContent(),
                                convMem, convFile,
                                Escape_Text);
            break;

        case wxXML_ELEMENT_NODE:
            OutputString(stream, wxT("<"));
            OutputString(stream, node->GetName());

            prop = node->GetProperties();
            while (prop)
            {
                OutputString(stream, wxT(" ") + prop->GetName() +  wxT("=\""));
                OutputEscapedString(stream, prop->GetValue(),
                                    convMem, convFile,
                                    Escape_Attribute);
                OutputString(stream, wxT("\""));
                prop = prop->GetNext();
            }

            if (node->GetChildren())
            {
                OutputString(stream, wxT(">"));
                prev = NULL;
                n = node->GetChildren();
                while (n)
                {
                    if (indentstep >= 0 && n && n->GetType() != wxXML_TEXT_NODE)
                        OutputIndentation(stream, indent + indentstep);
                    OutputNode(stream, n, indent + indentstep, convMem, convFile, indentstep);
                    prev = n;
                    n = n->GetNext();
                }
                if (indentstep >= 0 && prev && prev->GetType() != wxXML_TEXT_NODE)
                    OutputIndentation(stream, indent);
                OutputString(stream, wxT("</"));
                OutputString(stream, node->GetName());
                OutputString(stream, wxT(">"));
            }
            else
                OutputString(stream, wxT("/>"));
            break;

        case wxXML_COMMENT_NODE:
            OutputString(stream, wxT("<!--"));
            OutputString(stream, node->GetContent(), convMem, convFile);
            OutputString(stream, wxT("-->"));
            break;

        default:
            wxFAIL_MSG(wxT("unsupported node type"));
    }
}
예제 #26
0
void CNetwork::setDetectorCorsimId(CDetector *detector)
{
    // finds the corsim detector id for the specified detector and sets it in the detector object
    int distance = detector->getDistance();
    CLink *link = detector->getLink();
    CLane *lane = detector->getLane();
    int lane_id = lane->getId();
    int det_id = detector->getId();
    // get the id of the first detector on the same link as detector
    int id = net_lnk_lnk[link->m_corsim_id];
    // compare the position and lane for the first detector with that of detector
    bool found = false;
    int this_lane = 0;
    int this_distance = 0;
    int this_id = 0;
    int tmp = 0;
    this_distance = net_det_pos[id - 1] / 10;
    this_id = net_det_id[id - 1];
    if ((distance == this_distance) && (det_id == this_id))
    {
        while (!found && tmp < 2)
        {
            this_lane = net_det_lane[2 * id - 2 + tmp];
            found = false;
            if (lane_id == this_lane)
                found = true;
            else if (this_lane == 9)
                found = true;
            else if (this_lane == 8)
            {
                int left = link->m_left_turn_bays_num;
                int right = link->m_right_turn_bays_num;
                int nfull = 7 - left - right;
                if (lane_id > 0 && lane_id <= nfull)
                    found = true;
                else if (lane_id > 7)
                    found = true;
            }
            else if (this_lane == 10 && lane_id == 8)
                found = true;
            else if (this_lane == 11 && lane_id == 9)
                found = true;
            tmp++;
        }
    }
    tmp = 0;
    while (!found && id > 0)
    {
        // not found so get the next detector on this link and compare again
        id = net_det_link[id - 1];
        if (id > 0)
        {
            this_distance = net_det_pos[id - 1] / 10;
            this_id = net_det_id[id - 1];
            if ((distance == this_distance) && (det_id == this_id))
            {
                while (!found && tmp < 2)
                {
                    this_lane = net_det_lane[2 * id - 2 + tmp];
                    found = false;
                    if (lane_id == this_lane)
                        found = true;
                    else if (this_lane == 9)
                        found = true;
                    else if (this_lane == 8)
                    {
                        int left = link->m_left_turn_bays_num;
                        int right = link->m_right_turn_bays_num;
                        int nfull = 7 - left - right;
                        if (lane_id > 0 && lane_id <= nfull)
                            found = true;
                        else if (lane_id > 7)
                            found = true;
                    }
                    else if (this_lane == 10 && lane_id == 8)
                        found = true;
                    else if (this_lane == 11 && lane_id == 9)
                        found = true;
                    tmp++;
                }
            }
        }
    }
    if (found)
    {
        detector->setCorsimId(id - 1);
    }
    else
    {
        sprintf_s(out_buf, "Detector: %d was not found", detector->getId());
        OutputString(out_buf, strlen(out_buf), SIM_COLOR_RGB, RTE_MESSAGE_RGB);
    }
}
예제 #27
0
void GenBench(sParams* PBBench) {

	boolean 	finished = FALSE;
	int32		prevExp = 0;
	int32		currExp;
	int32 		numExp;
	FILE*		fp = NULL;	// file pointer
	FILE*		fp2 = NULL;	// file pointer
	char 		str[MAX_STR];
	int32		tabVal[MAX_VARYING_VAL];
	sParams		PBExp;
	int32		nbVal;
	item* 		memList;
	bool		tabSel[MAXBENCH*MAXMODE];
	int32		nbExp = 0;
	int32		key = 0;
	
	parseSel(PBBench, tabSel);
	// Allocate data structure for computing target offset
	memList = InitMemList((int32)(PBBench->deviceSize));
	fp2 = fopen(PBBench->outName, "w");
	if (fp2 == NULL) HandleError("GenBench", "Could not open output file", GetLastError(), ERR_ABORT);
	
	while (finished == FALSE) {
	// find the next experiment - it is the smallest numExp, greater than prevExp 
		if ((fp  = fopen(PBBench->expPlan, "r")) == NULL ) 
			HandleError("GenBench", "Cannot open experimentation plan file", GetLastError(), ERR_ABORT);
		currExp = INT32_MAX;
		while (fgets(str, MAX_STR,fp) != NULL) {
			numExp = atoi(str);
			if ((numExp > prevExp) && (numExp < currExp)) {
				currExp = numExp;
			}
		}
		if ((currExp > prevExp) && (currExp != INT32_MAX)) {
			printf("===================  Order Number %d\n", currExp);
			
			//New param structure
			InitParams(&PBExp);
			PBExp.deviceNum = PBBench->deviceNum;
			PBExp.IOSize = PBBench->IOSize;
			PBExp.IOCount = PBBench->IOCount;
			PBExp.IOCountSR = PBBench->IOCountSR;
			PBExp.IOCountRR = PBBench->IOCountRR;
			PBExp.IOCountSW = PBBench->IOCountSW;
			PBExp.IOCountRW = PBBench->IOCountRW;
			PBExp.ignoreIO = PBBench->ignoreIO;
			PBExp.ignoreIOSR = PBBench->ignoreIOSR;
			PBExp.ignoreIORR = PBBench->ignoreIORR;
			PBExp.ignoreIOSW = PBBench->ignoreIOSW;
			PBExp.ignoreIORW = PBBench->ignoreIORW;
			PBExp.collectErase = PBBench->collectErase;
			PBExp.pauseExp = PBBench->pauseExp;
			PBExp.fake = PBBench->fake;
			PBExp.bufferType = PBBench->bufferType;
			PBExp.deviceSize = PBBench->deviceSize;	
			PBExp.burstIO = PBBench->burstIO;
			PBExp.nbRun = PBBench->nbRun;  
			
			// parse the experiment
			nbVal = parseExp(fp, currExp, &PBExp, tabVal);
			if (tabSel[(PBExp.microBenchID - 1) * MAXMODE + PBExp.expID - 1] == TRUE) {
				for (int32 exp = 0; exp < nbVal; ++exp) {
					// Compute the different parameters
					if (PBExp.microBenchID == PAR)  {
						for (PBExp.runID = 0; PBExp.runID < PBExp.nbRun; (PBExp.runID)++) {
							PBExp.parDeg = tabVal[exp];
							for (int32 pID = 0; pID < PBExp.parDeg; ++pID) {
								PBExp.processID = PBExp.parDeg - pID - 1;
								PBExp.key = key++;
								ComputeParams(&PBExp, memList,PBExp.parDeg, nbVal );
								GenExp(fp2, &PBExp);
								nbExp++;
								PBExp.IOSize = PBBench->IOSize;
								PBExp.IOCount = PBBench->IOCount;
								PBExp.ignoreIO = PBBench->ignoreIO;
								
							}
						}
					}
					else {
						for (PBExp.runID = 0; PBExp.runID < PBExp.nbRun; (PBExp.runID)++) {
							PBExp.key = key++;
							ComputeParams(&PBExp, memList, tabVal[exp], nbVal);
							GenExp(fp2, &PBExp);
							nbExp ++;
							PBExp.IOSize = PBBench->IOSize;
							PBExp.IOCount = PBBench->IOCount;
							PBExp.ignoreIO = PBBench->ignoreIO;
						}
					}
				}
			}
			else
				printf("===================  Not Selected\n");
			fprintf(fp2, "\n");		
		}
		else finished = TRUE;
		prevExp = currExp;
		if (fp) fclose(fp);
	}
	fclose(fp2);							// close the output file if we opened it
	while (memList) {
		item *tmp = memList->next;
		free(memList);
		memList = tmp;
	}
	sprintf(str, "%d Experiments have been generated\n", nbExp);
	OutputString(OUT_LOG, str);

}
예제 #28
0
BOOL frameDTCReader::OnCreateClient(LPCREATESTRUCT lpcs,CCreateContext* pContext)
{
	CString sError;

TRYTRY

EXCEPTION_BOOKMARK(__LINE__)
	if(!CFrameWnd::OnCreateClient(lpcs,pContext))
		return FALSE;

EXCEPTION_BOOKMARK(__LINE__)
	RECT rect;
	GetClientRect(&rect);

EXCEPTION_BOOKMARK(__LINE__)
	if((lpSplitter = new CSplitterWnd) == NULL)
	{
		sError.Format("Memory Error - frameDTCReader::OnClientCreate() [lpSplitter] : %i [0x%X]",GetLastError(),GetLastError());
		OutputString(sError,MESSAGETYPE_ERROR);
	}

	lpSplitter->CreateStatic(this,2,1);
	lpSplitter->CreateView(0,0,RUNTIME_CLASS(frameList),CSize(100,100),pContext);
	lpSplitter->CreateView(1,0,RUNTIME_CLASS(frameList),CSize(100,100),pContext);

EXCEPTION_BOOKMARK(__LINE__)
	lpFont = new CFont;
	LOGFONT lf;

	memset(&lf, 0, sizeof(LOGFONT));
	lf.lfHeight = 0xfffffff5;
	lf.lfWeight = FW_REGULAR;
	lf.lfOutPrecision = OUT_STROKE_PRECIS;
	lf.lfClipPrecision = CLIP_STROKE_PRECIS;
	lf.lfQuality = DRAFT_QUALITY;
	lf.lfPitchAndFamily = 0x22;
	lf.lfCharSet = 0;
	strcpy(lf.lfFaceName,"Tahoma");

	lpFont->CreateFontIndirect(&lf);

EXCEPTION_BOOKMARK(__LINE__)
	frameList* lpFrameList = NULL;
	lpFrameList = (frameList*)lpSplitter->GetPane(0,0);
	lpFrameList->SetFont(lpFont);
	lpFrameList->SetViewStyle(LVS_REPORT,LVS_EX_FULLROWSELECT);
	lpFrameList->AddColumn("Current Trouble Code",150);
	lpFrameList->AddColumn("Current Trouble Code Description",400);

EXCEPTION_BOOKMARK(__LINE__)
	lpFrameList = (frameList*)lpSplitter->GetPane(1,0);
	lpFrameList->SetFont(lpFont);
	lpFrameList->SetViewStyle(LVS_REPORT,LVS_EX_FULLROWSELECT);
	lpFrameList->AddColumn("Historic Trouble Code",150);
	lpFrameList->AddColumn("Historic Trouble Code Description",400);

CATCHCATCH("frameDTCReader::OnCreateClient()");

	if(bExceptionFlag == EXEPT_CONTINUE)
		return FALSE;
	if(bExceptionFlag == EXEPT_ABORT)
		nuke();

	return TRUE;
}
예제 #29
0
local void ProcessRecord( // PROCESS A RECORD OF INPUT
    int kw, // - key-word for record
    char *record )// - record
{
    SEGMENT *seg;       // - current segment

    switch( kw ) {
    case KW_SEGMENT:
        PushSegStack();
        switch( ProcessMode ) {
        case MODE_DELETE:
            ProcessMode = MODE_SKIPPING;
            break;
        case MODE_OUTPUT:
            SegmentCheck();
            break;
        }
        break;
    case KW_ELSESEGMENT:
        switch( ProcessMode ) {
        case MODE_DELETE:
            EatWhite();
            if( *Rptr == '\0' ) {
                ProcessMode = MODE_OUTPUT;
            } else {
                SegmentCheck();
            }
            break;
        case MODE_OUTPUT:
            ProcessMode = MODE_SKIPPING;
            break;
        }
        break;
    case KW_ENDSEGMENT:
        PopSegStack();
        break;
    case KW_KEEP:
        switch( ProcessMode ) {
        case MODE_OUTPUT:
            seg = ScanSegment();
            if( seg != NULL )
                seg->seg_type = SEG_KEEP;
            break;
        }
        break;
    case KW_REMOVE:
        switch( ProcessMode ) {
        case MODE_OUTPUT:
            seg = ScanSegment();
            if( seg != NULL )
                seg->seg_type = SEG_REMOVE;
            break;
        }
        break;
    case KW_INCLUDE:
        switch( ProcessMode ) {
        case MODE_OUTPUT:
            if( ScanString() ) {
                OpenFileNormal( Token, "r" );
            } else {
                Error( "Missing or invalid inclusion file" );
            }
            break;
        }
        break;
    case KW_TEXT:
        switch( ProcessMode ) {
        case MODE_OUTPUT:
            OutputString( OutFmt, record );
            PutNL();
            break;
        }
        break;
    }
}
예제 #30
0
파일: genBench.c 프로젝트: blusjune/.bsrc
/**
 * @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);
    }
}