コード例 #1
0
ファイル: File.cpp プロジェクト: donbex/spkutils
bool CFile::CompressFile ( CProgressInfo *progress )
{
#ifdef _WIN32
	// check for file
	if ( m_sName.Empty() )
		return false;
	// check u can read file
	String file = m_sFullDir + "/" + m_sName;
	FILE *id = fopen ( file.c_str(), "rb" );
	if ( !id )
		return false;

	fclose ( id );

	bool done = false;
	if ( LZMAEncodeFile ( file.c_str(), "encodedfile.tmp", (CProgressInfo7Zip*)progress ) )
	{
		id = fopen ( "encodedfile.tmp", "rb" );
		if ( id )
		{
			fseek ( id, 0, SEEK_END );
			m_lDataSize = ftell ( id );
			rewind ( id );

			DeleteData ();
			m_sData = new unsigned char[m_lDataSize];
			if ( !m_sData ) m_iLastError = SPKERR_MALLOC;
			else
			{
				fread ( m_sData, sizeof(unsigned char), m_lDataSize, id );
				if ( ferror(id) )
				{
					m_iLastError = SPKERR_FILEREAD;
					DeleteData ();
				}
				else
				{
					done = true;
					m_iDataCompression = SPKCOMPRESS_7ZIP;
					m_bCompressedToFile = true;
				}
			}
			fclose ( id );
		}
	}

	remove ( "encodedfile.tmp" );

	return done;
#else
	return false;
#endif
}
コード例 #2
0
ファイル: cfield.cpp プロジェクト: adoggie/algorithm_package
/************************************************************************************
函数名称:
bool CField::LoadDataFromBuffer(LPBYTE& lpIndicate, LPBYTE& lpData)
功能说明:虚函數,读取一条记录某一字段的数据,可以用来读取值标签.

详细解释:1.子类实现.      

出入参数:
[in]: 1.lpIndicate:指示字节地址.
      2.lpData    :数据地址.
  
[out]:1.lpIndicate:下一数据块的指示字节地址.
      2.lpData    :下一数据块的数据地址. 

返回类型:bool

制作:YTLI 2002/07/12

修改: 
************************************************************************************/
void CField::LoadDataFromBuffer( LPBYTE& lpData)
{	
	if(m_pValue==NULL)
	{//旧版本
		if(m_nNextModifyField == -1)
		{
			NewData();
			LoadDataFromBuffer(lpData);			
			DeleteData();
		}
		else
		{
			if(m_pFields->IsConvertToLastVersion(this))
			{
				NewData();
				LoadDataFromBuffer(lpData);
				CField* pNewField = m_pFields->m_FieldVersion.GetFieldByAbsolutePos(m_nNextModifyField);
				pNewField->ConvertToCurField(this); 
				DeleteData();
			}
		}
	}
	else
	{//当前最新
		if (GetFieldType() == fString)
		{
			FieldString* pStr = (FieldString*)m_pValue;
			char *pBuf = new char[m_nWidth+2];
			memset(pBuf,0,m_nWidth+2);
			memcpy(pBuf,lpData,m_nWidth);
			*pStr= pBuf;
			/*
  			char* lpstr = pStr->GetBuffer(m_nWidth+2);
			memcpy(lpstr,lpData,m_nWidth);
			*(lpstr+m_nWidth)= 0;
			*(lpstr+m_nWidth+1)= 0;
			pStr->ReleaseBuffer();	
			*/
			//pStr->TrimLeft();//,左边空格保留
			pStr->TrimRight();   

			
			lpData =  lpData + Align4(m_nWidth);
		}
		else
		{
			memcpy( &*((FieldNUM *)m_pValue), lpData, sizeof(FieldNUM) );	//ytli Modify 2002/09/04
			lpData =  lpData + sizeof(FieldNUM);
		}
		
	}
}
コード例 #3
0
ファイル: File.cpp プロジェクト: donbex/spkutils
bool CFile::UncompressData ( CProgressInfo *progress )
{
	// no data to try to uncompress
	if ( (!m_sData) || (!m_lDataSize) )
		return false;

	if ( m_bCompressedToFile )
		return false;

	// if comopression is set to none, dont bother
	if ( m_iDataCompression == SPKCOMPRESS_NONE )
		return true;

	if ( m_iDataCompression == SPKCOMPRESS_ZLIB )
	{
		unsigned long uncomprLen = m_lUncomprDataSize;
		unsigned char *uncompr = new unsigned char[m_lUncomprDataSize];
		int err = uncompress ( uncompr, &uncomprLen, (const unsigned char *)m_sData, m_lDataSize );
		if ( err == Z_OK )
		{
			DeleteData ();
			m_iDataCompression = SPKCOMPRESS_NONE;
			m_lDataSize = uncomprLen;
			m_sData = uncompr;
			return true;
		}
	}
	if ( m_iDataCompression == SPKCOMPRESS_7ZIP )
	{
		long len = m_lUncomprDataSize;
		
		#ifdef _WIN32
		unsigned char *compr = LZMADecodeData ( m_sData, m_lDataSize, len, (CProgressInfo7Zip *)progress );
		#else
		unsigned char *compr = LZMADecode_C ( (unsigned char *)m_sData, m_lDataSize, (size_t*)&len, NULL );
		#endif

		if ( compr )
		{
			DeleteData ();
			m_sData = compr;
			m_lDataSize = len;
			m_iDataCompression = SPKCOMPRESS_NONE;
			return true;
		}
	}

	return false;
}
コード例 #4
0
NS_IMETHODIMP
InsertTextTransaction::UndoTransaction()
{
  ErrorResult rv;
  mTextNode->DeleteData(mOffset, mStringToInsert.Length(), rv);
  return rv.StealNSResult();
}
コード例 #5
0
NS_IMETHODIMP
CompositionTransaction::UndoTransaction() {
  if (NS_WARN_IF(!mEditorBase)) {
    return NS_ERROR_NOT_INITIALIZED;
  }

  // Get the selection first so we'll fail before making any changes if we
  // can't get it
  RefPtr<Selection> selection = mEditorBase->GetSelection();
  NS_ENSURE_TRUE(selection, NS_ERROR_NOT_INITIALIZED);

  ErrorResult err;
  mTextNode->DeleteData(mOffset, mStringToInsert.Length(), err);
  if (NS_WARN_IF(err.Failed())) {
    return err.StealNSResult();
  }

  // set the selection to the insertion point where the string was removed
  nsresult rv = selection->Collapse(mTextNode, mOffset);
  NS_ASSERTION(NS_SUCCEEDED(rv),
               "Selection could not be collapsed after undo of IME insert.");
  NS_ENSURE_SUCCESS(rv, rv);

  return NS_OK;
}
コード例 #6
0
ファイル: Value.cpp プロジェクト: krf/QOds
void
Value::SetDuration(const ods::Duration &r)
{
	DeleteData();
	type_ = ods::Type::Duration;
	data_ = new ods::Duration(r);
}
コード例 #7
0
void RedString::Set(const char Ch)
{
    if (Ch == '\0')
    {
        Empty();
    }
    else
    {
        const unsigned NumBlocksRequired = NumBlocksForSize(1);
        const unsigned AllocSizeRequired = SizeForNumBlocks(NumBlocksRequired);

        char*          NewData           = RedString::AllocData(NumBlocksRequired);

        // Clear Existing Data
        DeleteData();

        // Assign new array and size
        data        = NewData;
        allocsize   = AllocSizeRequired;
        contentsize = 1;

        // Assign content
        data[0] = Ch;

        // Loop to clear the rest of the string
        InitialiseNonContentChars();
    }
}
コード例 #8
0
ファイル: GFFField.cpp プロジェクト: TerrahKitsune/NWNX
GFFField::~GFFField(){

	if (this->Label)
		delete []this->Label;
	
	DeleteData();
}
コード例 #9
0
ファイル: test.c プロジェクト: Andy1985/HashTable
int main(int argc,char* argv[])
{
	hashdata** ht;

	InitHashTable(&ht,N);

	const char* words[15] = {
		"ske","abs","mps","test","tt","total","smtp","mbsc",
		"adfads","asdfa","dfads","13413la","tt","linux","windows"
	};

	int i;
	for (i = 0; i < 15; i++)
	{
		AddData(ht,N,words[i]);
	}
	PrintHashTable(ht,N);

	for (i = 0; i < 15; i++)
	{
		DeleteData(ht,N,words[i]);
	}
	PrintHashTable(ht,N);

	DestroyHashTable(&ht,N);

	return 0;
}
コード例 #10
0
ファイル: Value.cpp プロジェクト: krf/QOds
void
Value::SetDate(const QDateTime &r)
{
	DeleteData();
	type_ = ods::Type::Date;
	data_ = new QDateTime(r);
}
コード例 #11
0
void RedString::Insert(const unsigned Index, const char Ch)
{
    const unsigned NumBlocksRequired = NumBlocksForSize(contentsize+1);
    const unsigned AllocSizeRequired = SizeForNumBlocks(NumBlocksRequired);

    const unsigned FirstHalfLength  = Index - FirstContentIndex();
    const unsigned SecondHalfLength = LastContentIndex() - Index + 1;

    // Create the new data
    char* NewData = RedString::AllocData(NumBlocksRequired);

    // Copy the first half
    strncpy(NewData, data, FirstHalfLength);

    // Add the character
    NewData[Index] = Ch;

    // Copy the second half
    strncpy(&NewData[Index+1], &data[Index], SecondHalfLength);

    // Increment the content size
    contentsize++;

    // Delete the existing data string and using the newly created one
    DeleteData();
    data      = NewData;
    allocsize = AllocSizeRequired;

    // Loop to clear the rest of the string
    InitialiseNonContentChars();
}
コード例 #12
0
CG16bitSprite::~CG16bitSprite (void)

//	CG16bitSprite destructor

	{
	DeleteData();
	}
コード例 #13
0
ファイル: File.cpp プロジェクト: donbex/spkutils
CFile::~CFile()
{
	DeleteData ();

	if ( !m_sTmpFile.Empty() )
		remove ( m_sTmpFile.c_str() );
}
コード例 #14
0
void RedString::Set(const char* pText)
{
    if (pText == NULL)
    {
        Empty();
    }
    else
    {
        const unsigned StrLenNewData     = (unsigned)strlen(pText);
        const unsigned NumBlocksRequired = NumBlocksForSize(StrLenNewData);
        const unsigned AllocSizeRequired = SizeForNumBlocks(NumBlocksRequired);

        char*          NewData           = RedString::AllocData(NumBlocksRequired);

        // Clear Existing Data
        DeleteData();

        // Assign new array and size
        data      = NewData;
        allocsize = AllocSizeRequired;

        // Assign content
        strncpy(data, pText, StrLenNewData);
        contentsize = StrLenNewData;

        // Loop to clear the rest of the string
        InitialiseNonContentChars();
    }
}
コード例 #15
0
ファイル: BZDoc.cpp プロジェクト: tnzk/bz
DWORD CBZDoc::DoUndo()
{
    DWORD dwSize = *((DWORD*)(m_pUndo+m_dwUndo-4));
    m_dwUndo -= dwSize;
    dwSize -= 9;
    LPBYTE p = m_pUndo + m_dwUndo;
    DWORD dwPtr = *((DWORD*&)p)++;
    UndoMode mode = (UndoMode)*p++;
#ifdef FILE_MAPPING
    QueryMapView(m_pData, dwPtr);
#endif //FILE_MAPPING
    if(mode == UNDO_DEL) {
        DeleteData(dwPtr, *((DWORD*)p));
    } else {
        InsertData(dwPtr, dwSize, mode == UNDO_INS);
        memcpy(m_pData+dwPtr, p, dwSize);
    }
    if(m_dwUndo)
        m_pUndo = (LPBYTE)MemReAlloc(m_pUndo, m_dwUndo);
    else {				// ### 1.54
        MemFree(m_pUndo);
        m_pUndo = NULL;
        if(m_dwUndoSaved)
            m_dwUndoSaved = UINT_MAX;
    }
    // if(!m_pUndo)
    TouchDoc();
    return dwPtr;
}
コード例 #16
0
ファイル: Value.cpp プロジェクト: krf/QOds
void
Value::SetString(const QString &s)
{
	DeleteData();
	type_ = ods::Type::String;
	data_ = new QString();
	*AsString() = s;
}
コード例 #17
0
ファイル: Value.cpp プロジェクト: krf/QOds
void
Value::SetDouble(const double d)
{
	DeleteData();
	type_ = ods::Type::Double;
	data_ = new double();
	*AsDouble() = d;
}
コード例 #18
0
ファイル: yapp_history.cpp プロジェクト: 0xmono/miranda-ng
void PopupHistoryList::Clear()
{
	for (int i = 0; i < count; i++)
	{
		DeleteData(i);
	}
	count = 0;
}
コード例 #19
0
ファイル: yapp_history.cpp プロジェクト: 0xmono/miranda-ng
void PopupHistoryList::RemoveItem(int index)
{
	DeleteData(index); //free the mem for that particular item
	for (int i = index + 1; i < count; i++)
	{
		historyData[i - 1] = historyData[i]; //shift all items to the left
	}
}
コード例 #20
0
ファイル: XYChart.cpp プロジェクト: robertjolson/ifcb-acq
// Deletes every data set
void	CXYChart::DeleteAllData( void )
{
	BOOL		keepGoing = TRUE;

	while( keepGoing == TRUE && m_DataSetCount > 0 )
	{
		keepGoing = DeleteData( m_DataID[0] );
	}
}
コード例 #21
0
void RedString::Empty(void)
{
    // Delete recreate the stored string
    DeleteData();
    data = AllocData(1);

    // Update the string size
    allocsize   = SizeForNumBlocks(1);
    contentsize = 0;
}
コード例 #22
0
ファイル: File.cpp プロジェクト: donbex/spkutils
/*
	Func:	ReadFromFile
	Return:	Boolean - Returns true if read was successfull
	Desc:	Reads data from file pointer into data stream
			As its read from a file, there will be no compression, so its set to None
*/
bool CFile::ReadFromFile ()
{
	FILE *id = fopen ( GetFilePointer().c_str(), "rb" );
	if ( !id )
	{
		m_iLastError = SPKERR_FILEOPEN;
		return false;
	}

	if ( !m_lSize )
	{
		fseek ( id, 0, SEEK_END );
		m_lSize = ftell ( id );
		rewind ( id );
	}

	m_iDataCompression = SPKCOMPRESS_NONE;
	m_lDataSize = m_lUncomprDataSize = m_lSize;

	DeleteData ();
	
	m_sData = new unsigned char[m_lSize];
	if ( !m_sData ) { fclose ( id ); m_iLastError = SPKERR_MALLOC; return false; }

	fread ( m_sData, sizeof(unsigned char), m_lSize, id );
	if ( ferror(id) )
	{
		m_iLastError = SPKERR_FILEREAD;
		DeleteData ();
		m_lDataSize = 0;
		fclose ( id );
		return false;
	}

	m_iLastError = SPKERR_NONE;

	m_bLoaded = true;

	fclose ( id );

	return true;
}
コード例 #23
0
ファイル: File.cpp プロジェクト: donbex/spkutils
/*
	Func:	ReadFromData
	Accept:	data - The data stream to read
			size - The length of the data stream
	Return: Boolean - Return true if successfull
	Desc:	Copys data to the data stream in the file
			Used when data is already loaded into memory
*/
bool CFile::ReadFromData ( char *data, long size )
{
	DeleteData ();

	m_lDataSize = size ;
	m_sData = new unsigned char[m_lDataSize];

	memcpy ( m_sData, data, size );

	return true;
}
コード例 #24
0
ファイル: Value.cpp プロジェクト: ralincristian/QOds-1
void
Value::AppendString(const QString &s)
{
	if (!IsString() || data_ == nullptr)
	{
		DeleteData();
		type_ = ods::Type::String;
		data_ = new QString();
	}
	QString *str = (QString*) data_;
	*str += s;
}
コード例 #25
0
ファイル: Value.cpp プロジェクト: krf/QOds
void
Value::Read(ods::Ns &ns, ods::Attrs &attrs)
{
	DeleteData();
	auto *type_attr = attrs.Get(ns.office(), ods::ns::kValueType);
	if (type_attr == nullptr)
	{ // shouldn't happen
		type_ = ods::Type::Fail;
		return;
	}
	type_ = ods::TypeFromString(type_attr->value());
	auto *value_attr = attrs.Get(ns.office(), ods::ns::kValue);
	if (value_attr == nullptr)
	{
		type_ = ods::Type::Fail;
		return;
	}

	if (IsDouble() || IsPercentage() || IsCurrency())
	{
		double num;
		if (!value_attr->ToDouble(num))
		{
			mtl_warn("ToDouble()");
			return;
		}
		set(new double(num), type_);
	} else if (IsString()) {
		set(new QString(value_attr->value()), ods::Type::String);
	} else if (IsDate()) {
		auto *custom_attr = attrs.Get(ns.office(), ods::ns::kDateValue);
		if (custom_attr == nullptr)
		{
			mtl_warn("custom_attr == nullptr");
			return;
		}
		auto dt = QDateTime::fromString(custom_attr->value(), Qt::ISODate);
		set(new QDateTime(dt), type_);
	} else if (IsDuration()) {
		auto *custom_attr = attrs.Get(ns.office(), ods::ns::kTimeValue);
		if (custom_attr == nullptr)
		{
			mtl_warn("custom_attr == nullptr");
			return;
		}
		auto *t = new ods::Duration();
		t->Decode(custom_attr->value());
		set(t, type_);
	} else {
		type_ = ods::Type::NotSet;
	}
}
コード例 #26
0
ファイル: ActorEditorListCtrl.cpp プロジェクト: 2asoft/0ad
void ActorEditorListCtrl::DoImport(AtObj& in)
{
	DeleteData();

	for (AtIter group = in["group"]; group.defined(); ++group)
	{
		for (AtIter variant = group["variant"]; variant.defined(); ++variant)
			AddRow(variant);

		AtObj blank;
		AddRow(blank);
	}

	UpdateDisplay();
}
コード例 #27
0
void RedString::Append(const char Ch)
{
    if (IsEmpty())
    {
        Set(Ch);
    }
    else
    {
        const unsigned NumBlocksRequired = NumBlocksForSize(contentsize+1);
        const unsigned AllocSizeRequired = SizeForNumBlocks(NumBlocksRequired);

        // If we can fit the characters into the current size, tack it on.
        if (AllocSizeRequired == allocsize)
        {
            // Add the character
            data[contentsize] = Ch;

            // Increment the content size
            contentsize++;

            // Initialise the new terminator character for robustness
            data[contentsize] = '\0';
        }
        // Else, we need to allocate into a larger string
        else
        {
            // Create the new data
            char* NewData = RedString::AllocData(NumBlocksRequired);

            // Copy the existing data
            strncpy(NewData, data, contentsize);

            // Add the character
            NewData[contentsize] = Ch;

            // Increment the content size
            contentsize++;

            // Delete the existing data string and using the newly created one
            DeleteData();
            data      = NewData;
            allocsize = AllocSizeRequired;

            // Loop to clear the rest of the string
            InitialiseNonContentChars();
        }
    }
}
コード例 #28
0
void RedString::Append(const char* Str)
{
    if (IsEmpty())
    {
        Set(Str);
    }
    else
    {
        const unsigned AppendSize           = (unsigned)strlen(Str);
        const unsigned NumBlocksRequired    = NumBlocksForSize(contentsize+AppendSize);
        const unsigned AllocSizeRequired    = SizeForNumBlocks(NumBlocksRequired);

        // If we can fit the characters into the current size, tack it on.
        if (AllocSizeRequired == allocsize)
        {
            // Append the new data
            strncpy(&data[contentsize], Str, AppendSize);

            // Increment the content size
            contentsize += AppendSize;

            // Initialise the new terminator character for robustness
            data[contentsize] = '\0';
        }
        // Else, we need to allocate into a larger string
        else
        {
            // Create the new data
            char* NewData = RedString::AllocData(NumBlocksRequired);

            // Copy the existing data
            strncpy(NewData, data, contentsize);

            // Append the new data
            strncpy(&NewData[contentsize], Str, AppendSize);

            // Assign all the new data and increment the size
            DeleteData();
            data      = NewData;
            allocsize = AllocSizeRequired;
            contentsize += AppendSize;

            // Loop to clear the rest of the string
            InitialiseNonContentChars();
        }
    }
}
コード例 #29
0
ファイル: PROG1.C プロジェクト: lucasxyang/cs222-final
/* main encoder */
void Encode (void)
{
	unsigned int dictpos, deleteflag, sectorlen;
	unsigned long bytescompressed;

	InitEncode();

	dictpos = deleteflag = 0;

	bytescompressed = 0;

	while (1)
	{
		/* delete old data from dictionary */
		if (deleteflag) DeleteData(dictpos);

		/* grab more data to compress */
		if ((sectorlen = LoadDict(dictpos)) == 0) break;

		/* hash the data */
		HashData(dictpos, sectorlen);

		/* find dictionary matches */
		DictSearch(dictpos, sectorlen);

		bytescompressed += sectorlen;

		printf("\r%ld", bytescompressed);

		dictpos += SECTORLEN;

		/* wrap back to beginning of dictionary when its full */
		if (dictpos == DICTSIZE)
		{
			dictpos = 0;
			deleteflag = 1;   /* ok to delete now */
		}
	}

	/* Send EOF flag */
	SendMatch(MAXMATCH + 1, 0);

	/* Flush bit buffer */
	if (bitsin) SendBits(0, 8 - bitsin);

	return;
}
コード例 #30
0
ファイル: File.cpp プロジェクト: donbex/spkutils
/*
	Func:	Reset()
	Desc:	Resets the file data, clears all data inside
			Clears the Data stream
*/
void CFile::Reset ()
{
	m_iLastError = SPKERR_NONE;
	m_bLoaded = false;
	m_iFileType = -1;
	m_lSize = 0;
	m_iVersion = 0; 
	m_bSigned = false;
	m_iUsed = 0; 
	m_tTime = 0; 
	m_lDataSize = m_lUncomprDataSize = 0; 
	DeleteData ();
	m_iDataCompression = 0;
	m_bSkip = false;
	m_bShared = false;
	m_bCompressedToFile = false;
}