Browse Source

Clean up compaction code.

tags/non-daw-v1.1.0
Jonathan Moore Liles 17 years ago
parent
commit
05ebbc073b
2 changed files with 11 additions and 17 deletions
  1. +8
    -15
      Timeline/Loggable.C
  2. +3
    -2
      Timeline/Loggable.H

+ 8
- 15
Timeline/Loggable.C View File

@@ -327,13 +327,13 @@ Loggable::undo ( void )
}

/** write a snapshot of the state of all loggable objects, sufficient
* for later reconstruction, to /file/ */
* for later reconstruction, to /fp/ */
bool
Loggable::snapshot( const char *file )
Loggable::snapshot( FILE *fp )
{
FILE *ofp = _fp;

if ( ! ( _fp = fopen( file, "w" ) ) )
if ( ! ( _fp = fp ) )
{
_fp = ofp;
return false;
@@ -345,8 +345,6 @@ Loggable::snapshot( const char *file )
_loggables[ i ]->log_create();
}

fclose( _fp );

_fp = ofp;

return true;
@@ -355,19 +353,14 @@ Loggable::snapshot( const char *file )
void
Loggable::compact ( void )
{
fclose( _fp );
_fp = NULL;

/* FIXME: don't use name here */
snapshot( "history" );
fseek( _fp, 0, SEEK_SET );
ftruncate( fileno( _fp ), 0 );

if ( ! ( _fp = fopen( "history", "a+" ) ) )
{
printf( "Could not open log file for writing!" );
// return false;
}
}
snapshot( _fp );

_undo_index = 0;
}


void


+ 3
- 2
Timeline/Loggable.H View File

@@ -68,6 +68,7 @@ class Loggable
static queue <char *> _transaction;

private:

int _id;

char **_old_state;
@@ -88,14 +89,14 @@ private:
log( "\t" );
}

static bool snapshot( FILE * fp );

public:

static bool open ( const char *filename );
static void undo ( void );
static int undo_index ( void ) { return _undo_index; }
static bool snapshot( const char *file );
static void compact( void );
static void compact ( void );

static
void


Loading…
Cancel
Save