/* buffer.h - include file for the gap-buffer package */

#ifndef _BUFFER_H_
#define _BUFFER_H_

#include <sys/types.h>
#include "undo.h"


/* Buffer. */

typedef struct {
    char* bytes;
    size_t size, len, gap;
    size_t point, mark, first, last;
    bool modified, readonly;
    bool undo_enabled;
    int undo_group;
    undo_stack* us;
    } buffer;

buffer* buffer_create( void );
void buffer_clear( buffer* buf );
void buffer_destroy( buffer* buf );
void buffer_readonly( buffer* buf );
size_t buffer_len( buffer* buf );
char buffer_get_byte( buffer* buf, size_t ind );
bool buffer_set_byte( buffer* buf, size_t ind, char c );
bool buffer_insert_byte( buffer* buf, char c );
bool buffer_insert_bytes( buffer* buf, char* bytes, size_t len );
bool buffer_insert_string( buffer* buf, char* s );
bool buffer_delete_backward( buffer* buf, size_t len );
bool buffer_delete_forward( buffer* buf, size_t len );
bool buffer_get_parts( buffer* buf, size_t ind, size_t len, char** part1_bytesP, size_t* part1_lenP, char** part2_bytesP, size_t* part2_lenP );


/* Buffer undo. */

bool buffer_undo_enable( buffer* buf );
bool buffer_undo_aggregate( buffer* buf );
bool buffer_undo_save( buffer* buf, size_t loc, size_t len, ssize_t delta );
bool buffer_undo_save_null( buffer* buf );
bool buffer_undo_disable( buffer* buf );
bool buffer_undo_revert( buffer* buf );

#endif /* _BUFFER_H_ */
