コード例 #1
0
ファイル: EdiComposer.cpp プロジェクト: Skier/vault_repo
bool EdiComposer::ComposeTrailer()
{
    BufferClean();  

    BufferWriteRawData(GetTrailer().RecordType, 1);
    BufferWriteRawData(GetTrailer().Carrier, 9);
    wxString total;
    total << GetTrailer().TotalRecords;
    BufferWriteRawData(PrepareString(total, 9), 9);
    wxString added;
    added << GetTrailer().TotalAdds;
    BufferWriteRawData(PrepareString(added, 9), 9);
    wxString changed;
    changed << GetTrailer().TotalChanges;
    BufferWriteRawData(PrepareString(changed, 9), 9);
    wxString moved;
    moved << GetTrailer().TotalMoveHistory;
    BufferWriteRawData(PrepareString(moved, 9), 9);
    wxString rolled;
    BufferWriteRawData(PrepareString(rolled, 9), 9);
    wxString replaced;
    replaced << GetTrailer().TotalReplacements;
    BufferWriteRawData(PrepareString(replaced, 9), 9);

    BufferFlush();
    return true;
};
コード例 #2
0
ファイル: profiserial.c プロジェクト: FMMT666/ProfiLua
//**************************************************************************************
//*** plSerialBufferFlush
//***
//***
//*** LUA STACK IN:
//***  L1 -> handle
//*** LUA STACK OUT:
//***  number   : 0  ->  ERROR
//***             1  ->  OK
//**************************************************************************************
static int plSerialBufferFlush( lua_State *L )
{
	int ret = 0;

	if( lua_gettop(L) == 1 )
		ret = BufferFlush( lua_tonumber(L,1) );

	lua_pushnumber( L, ret );

	return 1;
}
コード例 #3
0
ファイル: EdiComposer.cpp プロジェクト: Skier/vault_repo
bool EdiComposer::ComposeTrailer(const Document& doc) {

    bool result = true;

    BufferClean();
    for (size_t k=0; k<doc.GetTrailerDescriptor().GetSize(); k++) {

        WriteData(doc.GetTrailerFieldDescriptor(k), doc.GetTrailerValue(k));

    }
    BufferFlush();
    return result;
};
コード例 #4
0
ファイル: routing.c プロジェクト: maz/Ruloir
void BufferedWrite(void* handle, const void* data, size_t len){
	while(len>0){
		WriteBuffer *self=(WriteBuffer*)handle;
		size_t remaining=WRITE_BUFFER_LENGTH-self->len;
		if(remaining>=len){
			memcpy(self->buf+self->len, data, len);
			self->len+=len;
			return;
		}else{
			memcpy(self->buf+self->len, data, remaining);
			BufferFlush(handle);
			len-=remaining;
		}
	}
}
コード例 #5
0
ファイル: EdiComposer.cpp プロジェクト: Skier/vault_repo
// private
bool EdiComposer::ComposeHeader(const Document& doc) {

    bool result = true;

    BufferClean();
    for (size_t j=0; j<doc.GetDescriptor().GetSize(); j++) {

        WriteData(doc.GetField(j));
        if ( 0 == doc.GetField(j).GetDescriptor().GetName().Cmp(CARRIER_NAME) ) {
            SetCarrier(doc.GetField(j).GetValue());
            GetTrailer().Carrier = GetCarrier();
        }
    }
    BufferFlush();
    return result;
};
コード例 #6
0
ファイル: InternalComposer.cpp プロジェクト: Skier/vault_repo
bool InternalComposer::ComposeDetail(Descriptor* descriptor, Matrix* matrix)
{
    bool result = true;
    GetTrailer().TotalRecords = GetDetail()->GetNumberRows();
    size_t numberRows = GetDetail()->GetNumberRows();
    for (size_t i=0; i<numberRows; i++) {
        BufferClean();
        wxArrayString row;
        // prepare row
        for (size_t j=0, k=0; j<descriptor->GetSize(); j++) {
            XmlElementDescriptor* colDesc = (XmlElementDescriptor*)descriptor->GetElementDescriptor(j);
            if ( colDesc->IsEnabled() ) {
                row.Add(GetDetail()->GetValue(i, k++));
            } else {
                row.Add(colDesc->GetDefaultValue());
            }
        }
        // transformation for not enabled dependence
        for (size_t l=0; l<descriptor->GetSize(); l++) {
            XmlElementDescriptor* colDesc = (XmlElementDescriptor*)descriptor->GetElementDescriptor(l);
            ElementDependence* dep = colDesc->GetDependence();
            if ( NULL != dep ) {
                size_t index = dep->GetFieldIndex();
                if ( index >= 0 
                     && index < descriptor->GetSize()
                     && !descriptor->GetElementDescriptor(index)->IsEnabled() ) {
                    row[index] = colDesc->DependenceValue(row[l]);
                }
            }
        }
        // writing row to file
        wxString rowStr;
        for (size_t m=0; m<descriptor->GetSize(); m++) {
            ElementDescriptor* ed = GetDetail()->GetDescriptor()->GetElementDescriptor(m);
            bool dataCheck = CheckAndWriteData(ed, row[m]);
            if ( !dataCheck ) {
                LOG_MESSAGE(INFO_MESSAGE_LEVEL, wxString::Format(" Row is [%d].\n", i));
            }
            result = result && dataCheck;
        }
        UpdateTrailer(row[0]);
        BufferFlush();
    }
    return result;
};
コード例 #7
0
ファイル: EdiComposer.cpp プロジェクト: Skier/vault_repo
bool EdiComposer::ComposeDetail(const Document& doc) {
    bool result = true;

    GetTrailer().TotalRecords = doc.GetNumberRows();
    bool fillTrailer = true;

    for (size_t i=0; i<doc.GetNumberRows(); i++) {

        if ( fillTrailer )  {
            UpdateTrailer(doc.GetValue(i,0));
        }
        BufferClean();
        for (size_t j=0; j<doc.GetColCount(); j++) {
            WriteData(doc.GetColumnDescriptor(j), doc.GetValue(i,j));
        }
        BufferFlush();
    }
    return result;
};
コード例 #8
0
ファイル: InternalComposer.cpp プロジェクト: Skier/vault_repo
bool InternalComposer::ComposeHeader(Descriptor* descriptor, Matrix* matrix)
{
    bool result = true;
    BufferClean();
    for (int j=0; j<GetHeader()->GetSize(); j++) {
        bool dataCheck = CheckAndWriteData(
            GetHeader()->GetDescriptor()->GetElementDescriptor(j), 
            GetHeader()->GetField(j)->GetValue());
        if ( !dataCheck ) {
            LOG_MESSAGE(INFO_MESSAGE_LEVEL, wxString::Format(" Row is [%d].\n", 1));
        }
        if ( descriptor->GetElementDescriptor(j)->GetName().Cmp(CARRIER_NAME) == 0 ) {
            SetCarrier(GetHeader()->GetField(j)->GetValue());
            GetTrailer().Carrier = GetCarrier()->c_str();
        }
        result = result && dataCheck;
    }
    BufferFlush();
    return result;
};
//=============================================================================
//  FUNCTION: DBDeleteRecord
// ----------------------------------------------------------------------------
//! This API is used to remove a record, indicated by index passed in 
//! RecordIndex, from the database.
//! 
//! \param RecordIndex
//!     The index of the record that the caller wants to delete.
//!
//! \retval DB_ERROR_NONE
//!     The record was removed from the database.
//! \retval DB_ERROR_INDEX
//!     Invalid index passed in, it does not exist in the database.
//!
//=============================================================================
INT _reentrant DBDeleteRecord(INT RecordIndex)
{
    INT MediaIndex;
    INT TempIndex;
    INT i;
    INT Size;
    INT RetCode;
    LONG FilePosition;
    
    //
    // Get the media Index out of the DBIndex.
    //
    MediaIndex = GetMediaIndex(RecordIndex);

    //
    // Indicate that someone has touched the database.
    //
    g_DB_Dirty = TRUE;

    //
    // Now look for strings that may need to be deleted.
    //
    BufferUpdate(RecordIndex);
    
    //
    // if any reserved bits are set this record was already deleted.
    //
    if (g_DB_Buffer[DB_RECORD_SIZE_WORDS] & 0xffff)
    {
        return(DB_ERROR_INDEX);
    }
    
    //
    // Seek to the file location and get the old handle value.
    //
    if (SUCCESS != Fseek(g_DBState[MediaIndex].hStStore_Idx, 
                        g_DBState[MediaIndex].TopRecord.PutDelRecordIdx,
                        SEEK_SET))
    {
        DebugBuildAssert(0);
    }
    
    //
    // Write the handle out to the deleted index file.
    //
    if (DB_HANDLE_SIZE != Fwrite(g_DBState[MediaIndex].hStStore_Idx, 
                 &RecordIndex, 
                 DB_HANDLE_SIZE, 
                 DEFAULT_MEMORY,-1))
    {
        DebugBuildAssert(0);
    }
    
    //
    // Check if Put needs to wrap or not.
    //
    if (g_DBState[MediaIndex].TopRecord.PutDelRecordIdx == 
         g_DBState[MediaIndex].TopRecord.LastDelRecordIdx)
    { 
        //
        // If Put needs to wrap to the beginning but Get is already there then
        // we need to make space at the end of the index file.
        //
        if (g_DBState[MediaIndex].TopRecord.GetDelRecordIdx == 0)
        {
            g_DBState[MediaIndex].TopRecord.PutDelRecordIdx += DB_HANDLE_SIZE;
            g_DBState[MediaIndex].TopRecord.LastDelRecordIdx += DB_HANDLE_SIZE;
        }
        //
        // Otherwise we need to move Put back to the beginning of the file and
        // move the last valid position back one so that it does not point to 
        // an invalid entry.
        else
        {
            g_DBState[MediaIndex].TopRecord.PutDelRecordIdx = 0;
            g_DBState[MediaIndex].TopRecord.LastDelRecordIdx -= DB_HANDLE_SIZE;
            DebugBuildAssert(g_DBState[MediaIndex].TopRecord.LastDelRecordIdx >= 0);
        }
    }
    else
    {
        g_DBState[MediaIndex].TopRecord.PutDelRecordIdx += DB_HANDLE_SIZE;
        
        //
        // If Put does not need to wrap then make sure it did not just run into 
        // the Get position.  If it did then make room in the index file and 
        // move the Put position to the end of the file.
        //
        if (g_DBState[MediaIndex].TopRecord.PutDelRecordIdx == 
            g_DBState[MediaIndex].TopRecord.GetDelRecordIdx)
        {
            g_DBState[MediaIndex].TopRecord.LastDelRecordIdx += DB_HANDLE_SIZE;
            g_DBState[MediaIndex].TopRecord.PutDelRecordIdx = 
                g_DBState[MediaIndex].TopRecord.LastDelRecordIdx;
            g_DBState[MediaIndex].TopRecord.GetDelRecordIdx = 0;
        }
    }

    g_DBState[MediaIndex].TopRecord.TotalRecords--;
    g_DBState[MediaIndex].TopRecord.TotalDelRecords++;

    if (g_DBState[MediaIndex].TopRecord.GetDelRecordIdx > 
        g_DBState[MediaIndex].TopRecord.PutDelRecordIdx)
    {
        DebugBuildAssert(g_DBState[MediaIndex].TopRecord.LastDelRecordIdx - 
         g_DBState[MediaIndex].TopRecord.GetDelRecordIdx + DB_HANDLE_SIZE +
         g_DBState[MediaIndex].TopRecord.PutDelRecordIdx == 
         g_DBState[MediaIndex].TopRecord.TotalDelRecords * DB_HANDLE_SIZE);
    }
    else
    {
        DebugBuildAssert((g_DBState[MediaIndex].TopRecord.PutDelRecordIdx - 
                         g_DBState[MediaIndex].TopRecord.GetDelRecordIdx) == 
                         g_DBState[MediaIndex].TopRecord.TotalDelRecords * DB_HANDLE_SIZE);
    }

    for (i=0; i < DB_RECORD_SIZE_WORDS; )
    {
        if (g_DB_Buffer[i] & DB_TAG_STRING)
        {
            // 
            // Remove this string from the string database.
            //
            if (DeleteString(&g_DBState[MediaIndex], g_DB_Buffer[i+1]) < 0)
            {
                return(DB_ERROR_CRITICAL);
            }
            i += 2;
        }
        else if (g_DB_Buffer[i] & DB_TAG_BLOCK)
        {
            Size = g_DB_Buffer[i] & DB_TAG_BLOCK_SIZE_MASK;
            // TODO get rid of this divide!!!!
            i += Size/3 + 1;
        }
        else
        {
            i += 2;
        }
    }
    //
    // Mark this record deleted also make it dirty so it gets flushed.
    //
    g_DB_Buffer[DB_RECORD_SIZE_WORDS] = -1;
    g_DB_BufferState |= DB_ENTRY_DIRTY;
    BufferFlush();
    
    return(SUCCESS);
}
コード例 #10
0
ファイル: robot36.c プロジェクト: brainwagon/sstv-encoders
int
main(int argc, char *argv[])
{
    char *fname = argv[1] ;
    int y, i, j, c ;
    HalfImage halfimage ;

    if (ReadImage(fname, image))
	fprintf(stderr, "%s read successfully.\n", fname) ;

    /* downsample */
    for (j=0; j<HALFHEIGHT; j++) {
	for (i=0; i<HALFWIDTH; i++) {
	    for (c=0; c<3; c++)
		halfimage[j][i][c] = 
		    (image[2*j][2*i][c] +
		    image[2*j+1][2*i][c] +
		    image[2*j][2*i+1][c] +
		    image[2*j+1][2*i+1][c]) / 4.0 ;
	}
    }

    /* now, color space convert */
    for (j=0; j<HEIGHT; j++) {
	for (i=0; i<WIDTH; i++) {
	    image[j][i][0] = 0.30 * image[j][i][0] +
			     0.59 * image[j][i][1] +
			     0.11 * image[j][i][2] ;
	}
    }
    /* and the half image */
    for (j=0; j<HALFHEIGHT; j++) {
	for (i=0; i<HALFWIDTH; i++) {
	    float y = 0.30 * halfimage[j][i][0] +
		      0.59 * halfimage[j][i][1] +
		      0.11 * halfimage[j][i][2] ;
	    halfimage[j][i][1] = (halfimage[j][i][1] - y + 1.0) / 2.0 ; 
	    halfimage[j][i][2] = (halfimage[j][i][2] - y + 1.0) / 2.0 ;
	    halfimage[j][i][0] = y ;
	}
     }

    sfinfo.channels = 1 ;
    sfinfo.samplerate = FILESAMPLERATE ;
    sfinfo.format = SF_FORMAT_WAV | SF_FORMAT_PCM_16 ;

    sf = sf_open(argv[2], SFM_WRITE, &sfinfo) ;

    /* generate the "vis" code. */
    blank(500.0) ;
    Vis(128+8) ;

    for (y=0; y<HEIGHT; y += 2)
	ScanlinePair(image, halfimage, y) ;

    blank(500.0) ;

    BufferFlush() ;
    sf_close(sf) ;

    return 0 ;
}