/*
 *	@(#)buffer.h 1.11 91/09/14 Copyright 1990-91 Sun Microsystems
 *
 * This file is a product of Sun Microsystems, Inc. and is provided for
 * unrestricted use provided that this legend is included on all tape
 * media and as a part of the software program in whole or part.  Users
 * may copy or modify this file without charge, but are not authorized to
 * license or distribute it to anyone else except as part of a product
 * or program developed by the user.
 * 
 * THIS FILE IS PROVIDED AS IS WITH NO WARRANTIES OF ANY KIND INCLUDING THE
 * WARRANTIES OF DESIGN, MERCHANTIBILITY AND FITNESS FOR A PARTICULAR
 * PURPOSE, OR ARISING FROM A COURSE OF DEALING, USAGE OR TRADE PRACTICE.
 * 
 * This file is provided with no support and without any obligation on the
 * part of Sun Microsystems, Inc. to assist in its use, correction,
 * modification or enhancement.
 * 
 * SUN MICROSYSTEMS, INC. SHALL HAVE NO LIABILITY WITH RESPECT TO THE
 * INFRINGEMENT OF COPYRIGHTS, TRADE SECRETS OR ANY PATENTS BY THIS FILE
 * OR ANY PART THEREOF.
 * 
 * In no event will Sun Microsystems, Inc. be liable for any lost revenue
 * or profits or other special, indirect and consequential damages, even
 * if Sun has been advised of the possibility of such damages.
 * 
 * Sun Microsystems, Inc.
 * 2550 Garcia Avenue
 * Mountain View, California  94043
 */

/* The client data field in a JotView points at a buffer.  Each buffer
   has keystate and filename and other stuff. */

#ifndef _BUFFER_INCLUDED_
#define _BUFFER_INCLUDED_

#include <jot/jot.h>
#include "keymap.h"

typedef struct buffer {
    JotText	*text;		    /* convenience pointer */
    char	*filename;	    /* default file name */
    char	*directory;	    /* directory */
    dev_t	dev;		    /* uniquely identify a file */
    ino_t	ino;
    int		last_saved;	    /* JotText_Modified() at last save */
    int		check_point;	    /* JotText_Modified() at last chkpnt */
    unsigned	update_modeline:1;
    unsigned	check_pointed:1;    /* has been checkpointed at least once */
    unsigned    check_failed:1;	    /* checkpoint failed - disabled */
    unsigned	quote_next:1;	    /* quote next character */
    unsigned	file_format:2;
} Buffer;

extern JotView	*The_View;
extern Buffer	*current_buffer;
extern int	this_cmd, last_cmd;

#define LINE_CMD    1

#define TEXTONLY	0
#define JOTFORMAT	1
#define UNDETERMINED	2

extern Buffer	*Buffer_New();
extern void	Buffer_InsertFile(Buffer *buffer, char *filename, boolean is_insert);
extern void	Buffer_LoadFile(Buffer *buffer, char *filename);
extern void	Buffer_SaveFile(Buffer *buffer);
extern void	Buffer_SetFileName(Buffer *buffer, char *filename);
extern boolean	Buffer_WriteFile(Buffer *buffer, char *filename, boolean do_warnings);
extern void	Buffer_SetDirectory(Buffer *buffer, char *name);
extern void	Buffer_Checkpoint(Buffer *buffer);
extern void	Buffer_SetCaret(Buffer *buffer, int pos);
extern void	Buffer_CaretVisible(Buffer *buffer);

#define Buffer_Modified(b)	(JotText_Modified((b)->text) > b->last_saved)
#define Buffer_FlushUndo(b)	JotText_SetUndo((b)->text, 0)
#define Buffer_EnableUndo(b)	JotText_SetUndo((b)->text, 50);

#endif
