Get multiple-undo sort of working.
This commit is contained in:
parent
359c2bd72f
commit
489f5e8adf
37
Loggable.C
37
Loggable.C
|
@ -26,9 +26,9 @@
|
|||
#include <stdarg.h>
|
||||
|
||||
FILE *Loggable::_fp;
|
||||
|
||||
int Loggable::_log_id = 0;
|
||||
int Loggable::_level = 0;
|
||||
int Loggable::_undo_index = 1;
|
||||
|
||||
vector <Loggable *> Loggable::_loggables;
|
||||
|
||||
|
@ -101,24 +101,44 @@ Loggable::undo ( void )
|
|||
|
||||
// fflush( _fp );
|
||||
|
||||
fseek( _fp, 0 - BUFSIZ, SEEK_END );
|
||||
fseek( _fp, 0, SEEK_END );
|
||||
size_t len = ftell( _fp );
|
||||
|
||||
// fseek( _fp, 0, SEEK_SET );
|
||||
fseek( _fp, 0 - (BUFSIZ > len ? len : BUFSIZ), SEEK_END );
|
||||
|
||||
size_t len = fread( buf, 1, BUFSIZ, _fp );
|
||||
len = fread( buf, 1, BUFSIZ, _fp );
|
||||
|
||||
char *s = buf + len - 1;
|
||||
|
||||
// FIXME: handle blocks
|
||||
for ( --s; *s && s > buf; --s )
|
||||
int i = 1;
|
||||
|
||||
/* move back _undo_index lines from the end */
|
||||
for ( int j = _undo_index; j-- ; )
|
||||
for ( --s; *s && s >= buf; --s, ++i )
|
||||
{
|
||||
if ( *s == '\n' )
|
||||
{
|
||||
s++;
|
||||
// s++;
|
||||
break;
|
||||
}
|
||||
}
|
||||
s++;
|
||||
|
||||
buf[ len ] = NULL;
|
||||
|
||||
// fsync( fileno( _fp ) );
|
||||
/* pop the entry off the end */
|
||||
|
||||
/* fseek( _fp, 0 - i, SEEK_END ); */
|
||||
/* ftruncate( fileno( _fp ), ftell( _fp ) ); */
|
||||
|
||||
if ( ! strlen( s ) )
|
||||
{
|
||||
printf( "corrupt undo file or no undo entries.\n" );
|
||||
return;
|
||||
}
|
||||
|
||||
printf( "undoing \"%s\"\n", s );
|
||||
|
||||
int id;
|
||||
|
@ -142,8 +162,9 @@ Loggable::undo ( void )
|
|||
|
||||
}
|
||||
|
||||
delete buf;
|
||||
++_undo_index;
|
||||
|
||||
delete buf;
|
||||
}
|
||||
|
||||
|
||||
|
@ -158,6 +179,8 @@ Loggable::log ( const char *fmt, ... )
|
|||
vfprintf( _fp, fmt, args );
|
||||
va_end( args );
|
||||
}
|
||||
|
||||
fflush( _fp );
|
||||
}
|
||||
|
||||
|
||||
|
|
|
@ -36,6 +36,7 @@ class Loggable
|
|||
static FILE *_fp;
|
||||
static int _log_id;
|
||||
static int _level;
|
||||
static int _undo_index;
|
||||
|
||||
static vector <Loggable *> _loggables;
|
||||
|
||||
|
|
Loading…
Reference in New Issue