/////////////////////////////////////////////////////////////////////////////////////
// adds a document
void TPdfFrontend::AddDocument(String const &name, String const &Title)
{
	if(FileExists(name))
	{
		// create the dest path, if needed
		RealizeDirectory(GetPdfDataPath());
		
		// opens sequence file, if any end read sequence number
		int Seq;
		String SeqPath = GetPdfDataPath() + "seqf";
		if(FileExists(SeqPath))
		{
			FileIn SeqFile(SeqPath);
			Seq = atoi(SeqFile.GetLine());
		}
		else
			Seq = 1;
		
		// creates destination file name
		String DestName = GetPdfDataPath() + FormatIntDec(Seq, 4, '0') + "-" + Title;
		
		// copies the file to data folder
		FileCopy(name, DestName);
		
		// adds to document lists
		DocumentList.Add(Title);
		Documents.Add(DestName);
		
		// stores the next sequence number
		Seq++;
		FileOut SeqFile(SeqPath);
		SeqFile.PutLine(FormatInt(Seq));
	}
	
} // END TPdfFrontend::AddDocument()
Exemple #2
0
// Read and save messages and their attachments
void ReadMessageTest(MAPIEx& mapi, const String &folderName = "") {
	puts("\nRead and save message test");
	MAPIFolder folder;
	if (folderName.IsEmpty()) {
		if(!mapi.OpenInbox(folder))
			return;
	} else {
		if(!mapi.OpenFolder(folderName, folder)) 		// Instead of Inbox open selected folder
			return;
	}
	
	// use SortContents to sort the messages, default is ascending by PR_MESSAGE_DELIVERY_TIME
	folder.SortContents(TABLE_SORT_DESCEND);
	//mapi.SetUnreadOnly();		
	
	MAPIMessage message;
	while(folder.GetNextMessage(message)) {
		Time receivedTime = message.GetReceivedTime();
		Time submitTime = message.GetSubmitTime();
		Time modifTime = message.GetLastModificationTime();
		String recipients;
		if (message.GetRecipients()) {
			String name, email;
			int type;
			while (message.GetNextRecipient(name, email, type)) {
				if (!recipients.IsEmpty())
					recipients += "; ";
				String stype; 
				if (type == MAPI_TO)
					stype = "TO";
				else if (type == MAPI_CC)
					stype = "CC";
				else if (type == MAPI_BCC)
					stype = "BCC";
				else
					stype = "Unknown!";
				recipients += Format("'%s' (%s)(%s)", name, email, stype.Begin());
			}
		}
		puts(Format("Message from '%s' (%s) to %s subject '%s', received time: %s, "
				"sent time: %s, modif time: %s", message.GetSenderName(), 
				message.GetSenderEmail(), recipients, message.GetSubject(), 
				Format(receivedTime), Format(submitTime), Format(modifTime)));
		puts(Format("Body: %s", message.GetBody(false)));
		//puts(Format("HTML: %s", message.GetHTML()));
		if(message.GetAttachmentCount()) {
			printf(Format("Saving attachments to %s...", MSG_ATTACHMENT_FOLDER));
			message.SaveAttachment(MSG_ATTACHMENT_FOLDER);
			puts("done");
		}
		static int num;
		String fileName = "c:\\temp\\" + FormatInt(num) + ".msg";
		printf(Format("Saving message to %s ...", fileName.Begin()));
		message.SaveToFile(fileName);
		num++;
		puts("done");
	}
}
Exemple #3
0
    StringExt *StringExt::FromInt(int nValue)
    {
        char sBuffer[24];
        char *pData = NULL;
        int   nLen;

        FormatInt( nValue, sBuffer, sizeof( sBuffer ), false, 0, 10, &pData, &nLen);
        return new StringExt( pData, nLen );
    }
Exemple #4
0
int dbDatabase::PutRecord(unsigned int tbHandle, int recno, dbRecord& Record, bool f) {
  unsigned int j, i, r;
  int z;
  char buff[2];

	ArrayMap<String, struct fieldStruct> &fs = fields[tbHandle];
  if( (recno > 0) && (recno <= tables[tbHandle].numOfRecord)) {
    if(IsDeleted(tbHandle, recno)) return MTDB_REC_DELETED;
    tables[tbHandle].record = recno;
  }
  else if((recno == MTDB_TB_APP) || (recno == tables[tbHandle].numOfRecord+1)) {
    tables[tbHandle].numOfRecord++;
    tables[tbHandle].record = tables[tbHandle].numOfRecord;
    recno = tables[tbHandle].record;
    Insert(tables[tbHandle].offset + tables[tbHandle].tableHead + ((recno-1) * tables[tbHandle].recordLenght), tables[tbHandle].recordLenght);
    eodsp += tables[tbHandle].recordLenght;
    for(r=tbHandle+1; r<numOfTables; r++) {
      tables[r].offset += tables[tbHandle].recordLenght;
    }
    dbUpdateHead();
    buff[0] = MTDB_TB_RECORD_ENABLED;
    lseek(fhandle, (int)tables[tbHandle].offset+tables[tbHandle].tableHead+(tables[tbHandle].recordLenght*(recno-1)), 0);
    write(fhandle, buff, 1);
    // verifico ed aggiorno la chiave primaria
    for(i=0; i<tables[tbHandle].numOfFields; i++) {
    	if (_isBitSet(fs[i].flags, MTDB_FD_PRIM_KEY)) {
				lseek(fhandle, (int)tables[tbHandle].offset+tables[tbHandle].tableHead+(tables[tbHandle].recordLenght*(recno-1))+fs[i].prevLength+1, 0);
				write(fhandle, &tables[tbHandle].autoincCntr, fs[i].length);
        tables[tbHandle].autoincCntr++;
  		}
    }
		// fine agg. chiave primaria
		tbUpdateHead(tbHandle);
  }
  else if(recno == MTDB_TB_ACT)
    recno = tables[tbHandle].record;
  else
    return MTDB_INV_RECNO;
  
#ifdef _WITH_DEBUG
RLOG("Put record: " + FormatInt(recno));
#endif

	for(j=0; j<Record.GetCount(); j++) {
		ArrayMap<String, struct fieldStruct> &fs = fields[tbHandle];
		z = fs.Find(Record.GetName(j));
		if(z >= 0) FieldPut(tbHandle, recno, z, Record[j], f);
	}

	Time t = GetSysTime();	
	lseek(fhandle, (int)tables[tbHandle].offset+21, 0);
	write(fhandle, &t, 8);
	tables[tbHandle].lastModifyTime = t;
	
	return MTDB_SUCCESS;
}
Exemple #5
0
    HRESULT FormatDArray( IValueBinder* binder, DArray array, Type* type, int radix, std::wstring& outStr )
    {
        _ASSERT( type->IsDArray() );

        HRESULT         hr = S_OK;
        ITypeDArray*    arrayType = type->AsTypeDArray();

        if ( arrayType == NULL )
            return E_FAIL;

        outStr.append( L"{length=" );

        hr = FormatInt( array.Length, arrayType->GetLengthType(), radix, outStr );
        if ( FAILED( hr ) )
            return hr;

        if ( !arrayType->GetElement()->IsChar() )
        {
            outStr.append( L" ptr=" );

            hr = FormatAddress( array.Addr, arrayType->GetPointerType(), outStr );
            if ( FAILED( hr ) )
                return hr;
        }

        if ( arrayType->GetElement()->IsChar() )
        {
            bool        foundTerm = true;
            uint32_t    len = MaxStringLen;

            // cap it somewhere under the range of a long
            // do it this way, otherwise only truncating could leave us with a tiny array
            // which would not be useful

            if ( array.Length < MaxStringLen )
                len = (uint32_t) array.Length;

            outStr.append( L" \"" );

            FormatString( 
                binder, 
                array.Addr, 
                arrayType->GetElement()->GetSize(),
                true,
                len,
                outStr,
                foundTerm );

            outStr.append( 1, L'"' );
        }

        outStr.append( 1, L'}' );

        return S_OK;
    }
Exemple #6
0
int dbDatabase::PutRecord(const String &tbname, int recno, dbRecord& Record, bool f) {
  int h;

#ifdef _WITH_DEBUG
RLOG("Put record: " + FormatInt(recno));
RLOG("Table: " + tbname);
#endif
  if((h = GetTableHandle(tbname)) == MTDB_TB_NOT_FOUND)
  	return MTDB_TB_NOT_FOUND;

	return PutRecord(h, recno, Record, f);
}
Exemple #7
0
    HRESULT FormatChar( const DataObject& objVal, int radix, std::wstring& outStr )
    {
        // object replacement char U+FFFC
        // replacement character U+FFFD
        const wchar_t   ReplacementChar = L'\xFFFD';

        HRESULT hr = S_OK;

        hr = FormatInt( objVal, radix, outStr );
        if ( FAILED( hr ) )
            return hr;

        outStr.append( L" '" );

        switch ( objVal._Type->GetSize() )
        {
        case 1:
            {
                uint8_t         c = (uint8_t) objVal.Value.UInt64Value;
                wchar_t         wc = ReplacementChar;

                if ( c < 0x80 )
                    wc = (wchar_t) c;

                outStr.append( 1, wc );
            }
            break;

        case 2:
            {
                wchar_t     wc = (wchar_t) objVal.Value.UInt64Value;

                if ( (wc >= 0xD800) && (wc <= 0xDFFF) )
                    wc = ReplacementChar;

                outStr.append( 1, wc );
            }
            break;

        case 4:
            AppendChar32( outStr, (dchar_t) objVal.Value.UInt64Value );
            break;
        }

        outStr.append( 1, L'\'' );

        return S_OK;
    }
Exemple #8
0
String HelpTopicTextModuleTitle(String space, String nesting, String topic, Index<String>& used_names)
{
	String title;
	AdjustCat(title, space, 8);
	CatUnder(title);
	if(!IsNull(nesting))
	{
		AdjustCat(title, nesting, 16);
		CatUnder(title);
	}
	AdjustCat(title, topic, 32);
	String base = title;
	int i = 0;
	while(used_names.Find(title) >= 0)
		title = base + FormatInt(++i);
	return title;
}
Exemple #9
0
    HRESULT FormatBasicValue( const DataObject& objVal, int radix, std::wstring& outStr )
    {
        _ASSERT( objVal._Type->IsBasic() );

        HRESULT hr = S_OK;
        Type*   type = NULL;

        if ( (objVal._Type == NULL) || !objVal._Type->IsScalar() )
            return E_FAIL;

        type = objVal._Type;

        if ( type->IsBool() )
        {
            hr = FormatBool( objVal, outStr );
        }
        else if ( type->IsChar() )
        {
            hr = FormatChar( objVal, radix, outStr );
        }
        else if ( type->IsIntegral() )
        {
            hr = FormatInt( objVal, radix, outStr );
        }
        else if ( type->IsComplex() )
        {
            hr = FormatComplex( objVal, outStr );
        }
        else if ( type->IsReal() )
        {
            hr = FormatSimpleReal( objVal.Value.Float80Value, outStr );
        }
        else if ( type->IsImaginary() )
        {
            hr = FormatSimpleReal( objVal.Value.Float80Value, outStr );
            outStr.append( 1, L'i' );
        }
        else
            return E_FAIL;

        if ( FAILED( hr ) )
            return hr;

        return S_OK;
    }
Exemple #10
0
    HRESULT FormatEnum( const DataObject& objVal, int radix, std::wstring& outStr )
    {
        UNREFERENCED_PARAMETER( radix );
        _ASSERT( objVal._Type->AsTypeEnum() != NULL );

        HRESULT hr = S_OK;

        if ( (objVal._Type == NULL) || (objVal._Type->AsTypeEnum() == NULL) )
            return E_FAIL;

        ITypeEnum*  enumType = objVal._Type->AsTypeEnum();
        RefPtr<Declaration> decl;
        const wchar_t* name = NULL;

        decl = enumType->FindObjectByValue( objVal.Value.UInt64Value );

        if ( decl != NULL )
        {
            name = decl->GetName();
        }

        if ( name != NULL )
        {
            objVal._Type->ToString( outStr );
            outStr.append( 1, L'.' );
            outStr.append( name );
        }
        else
        {
            hr = FormatInt( objVal, radix, outStr );
            if ( FAILED( hr ) )
                return hr;
        }

        return S_OK;
    }
Exemple #11
0
	bool CReserveListView::CReserveListItem::GetText(int ID,LPTSTR pszText,int MaxLength) const
	{
		pszText[0]=_T('\0');

		switch (ID) {
		case COLUMN_TITLE:
			if (!m_pReserveData->title.empty())
				::lstrcpyn(pszText,m_pReserveData->title.c_str(),MaxLength);
			break;

		case COLUMN_TIME:
			{
				SYSTEMTIME EndTime;
				TCHAR szStartTime[64],szEndTime[64];

				GetEndTime(m_pReserveData->startTime,m_pReserveData->durationSecond,&EndTime);
				FormatSystemTime(m_pReserveData->startTime,szStartTime, _countof(szStartTime),
								 SYSTEMTIME_FORMAT_TIME | SYSTEMTIME_FORMAT_SECONDS);
				FormatSystemTime(EndTime,szEndTime, _countof(szEndTime),
								 SYSTEMTIME_FORMAT_TIMEONLY | SYSTEMTIME_FORMAT_SECONDS);
				FormatString(pszText,MaxLength,TEXT("%s 〜 %s"),szStartTime,szEndTime);
			}
			break;

		case COLUMN_SERVICE:
			if (!m_pReserveData->stationName.empty())
				::lstrcpyn(pszText,m_pReserveData->stationName.c_str(),MaxLength);
			break;

		case COLUMN_STATUS:
			{
				LPCTSTR pszStatus=NULL;

				if (m_pReserveData->recSetting.recMode==RECMODE_NO) {
					pszStatus=TEXT("無効");
				} else {
					switch (m_pReserveData->overlapMode) {
					case 0:	pszStatus=TEXT("正常");				break;
					case 1:	pszStatus=TEXT("一部実行");			break;
					case 2:	pszStatus=TEXT("チューナー不足");	break;
					}
				}
				if (pszStatus!=NULL)
					::lstrcpyn(pszText,pszStatus,MaxLength);
			}
			break;

		case COLUMN_RECMODE:
			{
				LPCTSTR pszRecMode;

				switch (m_pReserveData->recSetting.recMode) {
				case RECMODE_ALL:
					pszRecMode=TEXT("全サービス");
					break;
				case RECMODE_SERVICE:
					pszRecMode=TEXT("指定サービス");
					break;
				case RECMODE_ALL_NOB25:
					pszRecMode=TEXT("全サービス(スクランブル解除なし)");
					break;
				case RECMODE_SERVICE_NOB25:
					pszRecMode=TEXT("指定サービス(スクランブル解除なし)");
					break;
				case RECMODE_VIEW:
					pszRecMode=TEXT("視聴");
					break;
				case RECMODE_NO:
					pszRecMode=TEXT("無効");
					break;
				case RECMODE_EPG:
					pszRecMode=TEXT("EPG取得");
					break;
				default:
					pszRecMode=NULL;
				}
				if (pszRecMode!=NULL)
					::lstrcpyn(pszText,pszRecMode,MaxLength);
			}
			break;

		case COLUMN_PRIORITY:
			FormatInt(m_pReserveData->recSetting.priority,pszText,MaxLength);
			break;

		default:
			return false;
		}

		return true;
	}
static asstring_t *QAS_FormatInt( asINT64 value, const asstring_t &options, asUINT width )
{
    std::string s( options.buffer );
    std::string ret = FormatInt( value, s, width );
    return objectString_FactoryBuffer( ret.c_str(), ret.length() );
}
Exemple #13
0
    StringExt *StringExt::AppendFormatV(char *sFormat, va_list sArgList)
    {
        StringExtFormatArg uArg;
        int nIndex, nWidth, nPrecision;
        bool bReverseAlign, bZeroFill;
        StringExtFormatType eFormatType;
        char sBuffer[65];
        int nLen;
        char *pCur, *pTemp, *sTemp;

        int nArgsLen = 0;
        int nArgsSize = 8;
        StringExtFormatArg *arrArgs = (StringExtFormatArg *)MemUtilsMallocArray( nArgsSize, sizeof(StringExtFormatArg));

        pCur = sFormat;
        while ( *pCur )
        {
            if ( *pCur == '{' )
            {
                ++pCur;
                if ( *pCur == '{' )
                {
                    ++pCur;
                    Append('{');
                }
                else
                {
                    // Разбираем форматированную строку
                    if ( !(*pCur >= '0' && *pCur <= '9') )
                        break;
                    nIndex = *pCur - '0';
                    for (++pCur; *pCur >= '0' && *pCur <= '9'; ++pCur )
                        nIndex = 10 * nIndex + (*pCur - '0');

                    if ( *pCur != ':' )
                        break;
                    ++pCur;
                    if ( *pCur == '-' )
                    {
                        bReverseAlign = true;
                        ++pCur;
                    }
                    else
                        bReverseAlign = false;
                    nWidth = 0;
                    bZeroFill = *pCur == '0';
                    for (; *pCur >= '0' && *pCur <= '9'; ++pCur )
                        nWidth = 10 * nWidth + (*pCur - '0');
                    if ( *pCur == '.' )
                    {
                        ++pCur;
                        nPrecision = 0;
                        for (; *pCur >= '0' && *pCur <= '9'; ++pCur )
                        {
                            nPrecision = 10 * nPrecision + (*pCur - '0');
                        }
                    }
                    else
                    {
                        nPrecision = 0;
                    }
                    for ( eFormatType = (StringExtFormatType)0;
                        c_arrsFormatStrings[ eFormatType ];
                    eFormatType = (StringExtFormatType)( eFormatType + 1 ) )
                    {
                        if (!strncmp( pCur, c_arrsFormatStrings[ eFormatType ], strlen(c_arrsFormatStrings[ eFormatType ])))
                        {
                            break;
                        }
                    }
                    if ( !c_arrsFormatStrings[ eFormatType ] )
                    {
                        break;
                    }
                    pCur += strlen( c_arrsFormatStrings[ eFormatType ] );
                    if (*pCur != '}')
                    {
                        break;
                    }
                    ++pCur;
                    // fetch the argument
                    if ( nIndex > nArgsLen )
                    {
                        break;
                    }
                    if ( nIndex == nArgsLen )
                    {
                        if ( nArgsLen == nArgsSize )
                        {
                            nArgsSize *= 2;
                            arrArgs = (StringExtFormatArg *)MemUtilsReallocArray( arrArgs, nArgsSize, sizeof(StringExtFormatArg));
                        }
                        switch ( eFormatType )
                        {
                        case fmtIntDecimal:
                        case fmtIntHex:
                        case fmtIntOctal:
                        case fmtIntBinary:
                        case fmtSpace:
                            arrArgs[nArgsLen].iValue = va_arg( sArgList, int );
                            break;
                        case fmtUIntDecimal:
                        case fmtUIntHex:
                        case fmtUIntOctal:
                        case fmtUIntBinary:
                            arrArgs[nArgsLen].uiValue = va_arg( sArgList, unsigned int );
                            break;
                        case fmtLongDecimal:
                        case fmtLongHex:
                        case fmtLongOctal:
                        case fmtLongBinary:
                            arrArgs[nArgsLen].lValue = va_arg( sArgList, long );
                            break;
                        case fmtULongDecimal:
                        case fmtULongHex:
                        case fmtULongOctal:
                        case fmtULongBinary:
                            arrArgs[nArgsLen].ulValue = va_arg( sArgList, unsigned long );
                            break;
                        case fmtDouble:
                        case fmtDoubleTrim:
                            arrArgs[nArgsLen].fValue = va_arg( sArgList, double );
                            break;
                        case fmtChar:
                            arrArgs[nArgsLen].cValue = (char)va_arg( sArgList, int );
                            break;
                        case fmtString:
                            arrArgs[nArgsLen].sValue = va_arg( sArgList, char * );
                            break;
                        case fmtStringExt:
                            arrArgs[nArgsLen].seValue = va_arg(sArgList, StringExt *);
                            break;
                        }
                        ++nArgsLen;
                    }

                    uArg = arrArgs[ nIndex ];
                    switch ( eFormatType )
                    {
                    case fmtIntDecimal:
                        FormatInt( uArg.iValue, sBuffer, sizeof(sBuffer), bZeroFill, nWidth, 10, &sTemp, &nLen );
                        break;
                    case fmtIntHex:
                        FormatInt( uArg.iValue, sBuffer, sizeof(sBuffer), bZeroFill, nWidth, 16, &sTemp, &nLen );
                        break;
                    case fmtIntOctal:
                        FormatInt( uArg.iValue, sBuffer, sizeof(sBuffer), bZeroFill, nWidth, 8, &sTemp, &nLen );
                        break;
                    case fmtIntBinary:
                        FormatInt( uArg.iValue, sBuffer, sizeof(sBuffer), bZeroFill, nWidth, 2, &sTemp, &nLen );
                        break;
                    case fmtUIntDecimal:
                        FormatUInt( uArg.uiValue, sBuffer, sizeof(sBuffer), bZeroFill, nWidth, 10, &sTemp, &nLen );
                        break;
                    case fmtUIntHex:
                        FormatUInt( uArg.uiValue, sBuffer, sizeof(sBuffer), bZeroFill, nWidth, 16, &sTemp, &nLen );
                        break;
                    case fmtUIntOctal:
                        FormatUInt( uArg.uiValue, sBuffer, sizeof(sBuffer), bZeroFill, nWidth, 8, &sTemp, &nLen );
                        break;
                    case fmtUIntBinary:
                        FormatUInt( uArg.uiValue, sBuffer, sizeof(sBuffer), bZeroFill, nWidth, 2, &sTemp, &nLen );
                        break;
                    case fmtLongDecimal:
                        FormatInt( uArg.lValue, sBuffer, sizeof(sBuffer), bZeroFill, nWidth, 10, &sTemp, &nLen );
                        break;
                    case fmtLongHex:
                        FormatInt( uArg.lValue, sBuffer, sizeof(sBuffer), bZeroFill, nWidth, 16, &sTemp, &nLen );
                        break;
                    case fmtLongOctal:
                        FormatInt( uArg.lValue, sBuffer, sizeof(sBuffer), bZeroFill, nWidth, 8, &sTemp, &nLen );
                        break;
                    case fmtLongBinary:
                        FormatInt( uArg.lValue, sBuffer, sizeof(sBuffer), bZeroFill, nWidth, 2, &sTemp, &nLen );
                        break;
                    case fmtULongDecimal:
                        FormatUInt( uArg.ulValue, sBuffer, sizeof(sBuffer), bZeroFill, nWidth, 10, &sTemp, &nLen );
                        break;
                    case fmtULongHex:
                        FormatUInt( uArg.ulValue, sBuffer, sizeof(sBuffer), bZeroFill, nWidth, 16, &sTemp, &nLen );
                        break;
                    case fmtULongOctal:
                        FormatUInt( uArg.ulValue, sBuffer, sizeof(sBuffer), bZeroFill, nWidth, 8, &sTemp, &nLen );
                        break;
                    case fmtULongBinary:
                        FormatUInt( uArg.ulValue, sBuffer, sizeof(sBuffer), bZeroFill, nWidth, 2, &sTemp, &nLen );
                        break;
                    case fmtDouble:
                        FormatDouble( uArg.fValue, sBuffer, sizeof(sBuffer), nPrecision, false, &sTemp, &nLen );
                        break;
                    case fmtDoubleTrim:
                        FormatDouble( uArg.fValue, sBuffer, sizeof(sBuffer), nPrecision, true, &sTemp, &nLen );
                        break;
                    case fmtChar:
                        sBuffer[0] = uArg.cValue;
                        sTemp = sBuffer;
                        nLen = 1;
                        bReverseAlign = !bReverseAlign;
                        break;
                    case fmtString:
                        sTemp = uArg.sValue;
                        nLen = strlen( sTemp );
                        bReverseAlign = !bReverseAlign;
                        break;
                    case fmtStringExt:
                        sTemp = uArg.seValue->GetBuffer();
                        nLen = uArg.seValue->GetLength();
                        bReverseAlign = !bReverseAlign;
                        break;
                    case fmtSpace:
                        sTemp = sBuffer;
                        nLen = 0;
                        nWidth = uArg.iValue;
                        break;
                    }
                    // Добавляем аргумент в нужном формате, с нужным прилеганием
                    if ( !bReverseAlign && nLen < nWidth )
                    {
                        for (int nCounter = nLen; nCounter < nWidth; ++nCounter )
                            Append(' ');
                    }
                    Append( sTemp, nLen);
                    if ( bReverseAlign && nLen < nWidth )
                    {
                        for (int nCounter = nLen; nCounter < nWidth; ++nCounter )
                            Append(' ');
                    }
                }
            }
            else if ( *pCur == '}' )
Exemple #14
0
static int UppValueSimplify(VarItem &varItem, int step)
{
	enum { SMALL = 0, MEDIUM = 31 }; // SMALL has to be 0 because of GetSpecial and because is it ending zero
	enum { KIND = 14, SLEN = 15, LLEN = 2, SPECIAL = 13 };
	enum { STRING = 0, REF = 255, VOIDV = 3 };

	// get the embedded 'data' string 'chr' member
	// it contains info about value type
	union
	{
		char chr[16];
		char  *ptr;
		dword *wptr;
		qword *qptr;
		word   v[8];
		dword  w[4];
		qword  q[2];
		
		int iData;
		int64 i64Data;
		double dData;
		bool bData;
		struct
		{
			byte   day;
			byte   month;
			int16  year;
			byte   hour;
			byte   minute;
			byte   second;
		};
	} u;
	
	// see Upp::String code for how it works....
	MIValue val = varItem.EvaluateExpression("(" + varItem.evaluableExpression + ").data.chr");
	if(!val.IsString())
		return 0;
	String chrs = val.ToString();
	memcpy(u.chr, ~chrs, 16);

	// get value type, among the fixed ones
	// we could try later to decode registered types....
	dword type;
	bool isSpecial = !u.v[7] && u.v[6];
	if(!isSpecial)
		type = STRING_V;
	else
	{
		byte st = u.chr[SPECIAL];
		if(st == REF)
		{
			// ptr()->GetType()
			// by now, just mark as ref...
			type = REF;
		}
		else if(st == VOIDV)
			type = VOID_V;
		else
			type = st;
	}
	
	// by now, treat all types beyond VALUEMAP_V as unknown
	if(type > VALUEMAP_V)
		type = UNKNOWN_V;
	
	// now, based on type, we can decode it
	varItem.kind = VarItem::SIMPLE;
	switch(type)
	{
		case VOID_V:
		{
			varItem.value = "<VOID>";
			return 0;
		}
			
		case INT_V:
		{
			varItem.value = FormatInt(u.iData);
			return 0;
		}
			
		case DOUBLE_V:
		{
			varItem.value = FormatDouble(u.dData);
			return 0;
		}
			
		case STRING_V:
		{
			// we simply replace the VarItem with the string
			VarItem vItem(&varItem.Debugger(), "(" + varItem.evaluableExpression + ").data");
			vItem.evaluableExpression = varItem.evaluableExpression;
			vItem.shortExpression = varItem.shortExpression;
			varItem = vItem;
			return 0;
		}
			
		case DATE_V:
		{
			varItem.value = Format("Upp::Date = %02d/%02d/%04d", u.day, u.month, u.year);
			return 0;
		}
			
		case TIME_V:
		{
			varItem.value = Format("Upp::Time = %02d/%02d/%04d - %02d:%02d:%02d", u.day, u.month, u.year, u.hour, u.minute, u.second);
			return 0;
		}
			break;
			
		case ERROR_V:
		{
			varItem.value = "<ERROR_V>";
			return 0;
		}
			
		case VALUE_V:
		{
			varItem.value = "<VALUE_V>";
			return 0;
		}
			
		case WSTRING_V:
		{
			varItem.value = "<WSTRING_V>";
			return 0;
		}
			
		case VALUEARRAY_V:
		{
			varItem.value = "<VALUEARRAY_V>";
			return 0;
		}
			
		case INT64_V:
		{
			varItem.value = FormatInt64(u.i64Data);
			return 0;
		}
			
		case BOOL_V:
		{
			varItem.value = (u.bData ? "TRUE" : "FALSE");
			return 0;
		}
			
		case VALUEMAP_V:
		{
			varItem.value = "<VALUEMAP_V>";
			return 0;
		}
			
		case UNKNOWN_V:
		default:
		{
			varItem.value = "<UNKNOWN_V>";
			return 0;
		}
	}

}
Exemple #15
0
void ValueView::InsertInt(LPINTEGER i, LONG lHint)
{
    CListCtrl& list = GetListCtrl();
    list.InsertItem(0, FormatInt(i, lHint));
}
Exemple #16
0
void DlgSqlExport::Run(Sql& cursor, String command, String tablename)
{
	Title(Nvl(tablename, t_("SQL query")) + t_(" export"));
	object_name <<= tablename;
	if(!cursor.Execute(command)) {
		Exclamation(NFormat(t_("Error executing [* \1%s\1]: \1%s"), command, cursor.GetLastError()));
		return;
	}
	for(int i = 0; i < cursor.GetColumns(); i++) {
		const SqlColumnInfo& sci = cursor.GetColumnInfo(i);
		String type;
		switch(sci.valuetype) {
			case BOOL_V:
			case INT_V: type = t_("integer"); break;
			case DOUBLE_V: type = t_("real number"); break;
			case STRING_V:
			case WSTRING_V: type = t_("string"); break;
			case DATE_V: type = t_("date"); break;
			case TIME_V: type = t_("date/time"); break;
			case /*ORA_BLOB_V*/-1: type = t_("BLOB"); break;
			case /*ORA_CLOB_V*/-2: type = t_("CLOB"); break;
			default: type = FormatInt(sci.valuetype); break;
		}
		columns.Add(sci.name, sci.valuetype, sci.width, 1);
	}
	static String cfg;
	LoadFromString(*this, cfg);
	SyncUI();
	while(TopWindow::Run() == IDOK)
		try {
			String out_table = ~object_name;
			String delim;
			switch((int)~delimiters) {
				case DELIM_TAB: delim = "\t"; break;
				case DELIM_SEMICOLON: delim = ";"; break;
			}
			Vector<int> out;
			String colstr;
			String title;
			for(int i = 0; i < columns.GetCount(); i++)
				if(columns.Get(i, 3)) {
					out.Add(i);
					String cname = cursor.GetColumnInfo(i).name;
					colstr << (i ? ", " : "") << cname;
					if(i) title << delim;
					title << cname;
				}
			if(out.IsEmpty()) {
				throw Exc(t_("No columns selected!"));
				continue;
			}
			String rowbegin, rowend;
			int fmt = ~format;
			FileSel fsel;
			String ext;
			switch(fmt) {
				case FMT_TEXT: {
					rowend = "";
					ext = ".txt";
					fsel.Type(t_("Text files (*.txt)"), "*.txt");
					break;
				}
				case FMT_SQL: {
					if(identity_insert)
						rowbegin << "set identity_insert " << out_table << " on ";
					rowbegin << "insert into " << out_table << "(" << colstr << ") values (";
					rowend = ");";
					ext = ".sql";
					fsel.Type(t_("SQL scripts (*.sql)"), "*.sql");
					break;
				}
			}
			fsel.AllFilesType().DefaultExt(ext.Mid(1));
			if(!IsNull(recent_file))
				fsel <<= ForceExt(recent_file, ext);
			if(!fsel.ExecuteSaveAs(t_("Save export as")))
				continue;
			recent_file = ~fsel;
			FileOut fo;
			if(!fo.Open(recent_file)) {
				Exclamation(NFormat(t_("Error creating file [* \1%s\1]."), recent_file));
				continue;
			}
			if(fmt == FMT_TEXT)
				fo.PutLine(title);
			Progress progress(t_("Exporting row %d"));
			while(cursor.Fetch()) {
				String script = rowbegin;
				for(int i = 0; i < out.GetCount(); i++) {
					Value v = cursor[out[i]];
					switch(fmt) {
						case FMT_TEXT: {
							if(i)
								script.Cat(delim);
							if(IsString(v) && quote) {
								String s = v;
								script << '\"';
								for(const char *p = s, *e = s.End(); p < e; p++)
									if(*p == '\"')
										script.Cat("\"\"");
									else
										script.Cat(*p);
								script << '\"';
							}
							else
								script << StdFormat(v);
							break;
						}
						case FMT_SQL: {
							if(i) script.Cat(", ");
//							script << SqlCompile(SQLD_ORACLE, SqlFormat(v));
							break;
						}
					}
				}
				script << rowend;
				fo.PutLine(script);
/*
				if(autocommit && --left <= 0) {
					fo.PutLine("commit;");
					left = autocommit;
				}
*/
				if(progress.StepCanceled()) {
					Exclamation(t_("Export aborted!"));
					return;
				}
			}
			fo.Close();
			if(fo.IsError())
				throw Exc(NFormat(t_("Error writing file %s."), recent_file));
			break;
		}
		catch(Exc e) {
			ShowExc(e);
		}

	cfg = StoreAsString(*this);
}
Exemple #17
0
 HRESULT FormatInt( const DataObject& objVal, int radix, std::wstring& outStr )
 {
     return FormatInt( objVal.Value.UInt64Value, objVal._Type, radix, outStr );
 }
Exemple #18
0
 HRESULT FormatAddress( Address addr, Type* type, std::wstring& outStr )
 {
     return FormatInt( addr, type, 16, outStr );
 }
Exemple #19
0
static int UppStringSimplify(VarItem &varItem, int step)
{
	enum { SMALL = 0, MEDIUM = 31 }; // SMALL has to be 0 because of GetSpecial and because is it ending zero
	enum { KIND = 14, SLEN = 15, LLEN = 2, SPECIAL = 13 };
	union
	{
		char chr[16];
		char  *ptr;
		dword *wptr;
		qword *qptr;
		word   v[8];
		dword  w[4];
		qword  q[2];
	} u;
	
	// see Upp::String code for how it works....
	MIValue val = varItem.EvaluateExpression("(" + varItem.evaluableExpression + ")." + "chr");
	if(!val.IsString())
		return 0;
	String chrs = val.ToString();
	memcpy(u.chr, ~chrs, 16);

	bool isSmall = (u.chr[14] == 0);
	String s;
	if(isSmall)
	{
		byte len = u.chr[SLEN];
		s = chrs.Left(len);
	}
	else
	{
		dword len = u.w[LLEN];
		MIValue val = varItem.EvaluateExpression("(" + varItem.evaluableExpression + ").ptr[0]@" + FormatInt(len));
		if(!val.IsString())
			return 0;
		s = val.ToString();
	}
	varItem.value = "\"" + s + "\"";
	varItem.kind = VarItem::SIMPLE;
	return 0;
}