Work on block undo.

This commit is contained in:
Jonathan Moore Liles 2008-03-05 01:05:08 -06:00
parent 790f371456
commit bccdecdee6
1 changed files with 77 additions and 43 deletions

View File

@ -24,6 +24,7 @@
#include <stdlib.h>
#include <stdio.h>
#include <stdarg.h>
#include <string.h>
FILE *Loggable::_fp;
int Loggable::_log_id = 0;
@ -198,15 +199,21 @@ Loggable::undo ( void )
if ( *(s + 1) == '\t' )
continue;
if ( *(s + 1) == '}' )
{
*(s + 1) = NULL;
continue;
}
break;
}
}
s++;
strtok( s, "\n" );
buf[ len ] = NULL;
// fsync( fileno( _fp ) );
/* pop the entry off the end */
@ -219,6 +226,35 @@ Loggable::undo ( void )
return;
}
char *b = s;
s += strlen( s ) - 1;
if ( strtok( b, "\n" ) == NULL )
{
printf( "error, empty undo transaction!\n" );
abort();
}
int n = 1;
while ( strtok( NULL, "\n" ) )
++n;
int ui = _undo_index;
while ( n-- )
{
while ( s >= b && *(--s) );
s++;
if ( ( ! strcmp( s, "{" ) )
|| ( ! strcmp( s, "}" ) ) )
continue;
if ( *s == '\t' )
s++;
printf( "undoing \"%s\"\n", s );
int id;
@ -233,17 +269,12 @@ Loggable::undo ( void )
sscanf( s, "%s %*X %s %*[^\n<] << %a[^\n]", classname, command, &arguments );
int ui = _undo_index;
/* if ( ! l ) */
/* { */
/* printf( "corrupt undo?\n" ); */
/* abort(); */
/* } */
if ( ! strcmp( command, "destroy" ) )
{
char **sa = parse_alist( arguments );
@ -279,12 +310,15 @@ Loggable::undo ( void )
_loggables[ id ] = NULL;
}
s -= 2;
}
// FIXME: bogus... needs to account for multiple events.
_undo_index = ui + 1;
++_undo_index;
delete buf;
}