1/* $NetBSD: bufgap.c,v 1.1 2009/12/05 07:08:18 agc Exp $ */
2
3/*-
4 * Copyright (c) 1996-2009 The NetBSD Foundation, Inc.
5 * All rights reserved.
6 *
7 * This code is derived from software contributed to The NetBSD Foundation
8 * by Alistair Crooks (agc@NetBSD.org)
9 *
10 * Redistribution and use in source and binary forms, with or without
11 * modification, are permitted provided that the following conditions
12 * are met:
13 * 1. Redistributions of source code must retain the above copyright
14 *    notice, this list of conditions and the following disclaimer.
15 * 2. Redistributions in binary form must reproduce the above copyright
16 *    notice, this list of conditions and the following disclaimer in the
17 *    documentation and/or other materials provided with the distribution.
18 *
19 * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
20 * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
21 * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
22 * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
23 * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
24 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
25 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
26 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
27 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
28 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
29 * POSSIBILITY OF SUCH DAMAGE.
30 */
31#ifndef BUFGAP_H_
32#define BUFGAP_H_ 20091023
33
34#include <sys/types.h>
35
36#include <inttypes.h>
37#include <stdio.h>
38
39#ifndef BUFGAP_VERSION_STRING
40#define BUFGAP_VERSION_STRING	"20091022"
41#endif
42
43#ifndef BUFGAP_AUTHOR_STRING
44#define BUFGAP_AUTHOR_STRING	"Alistair Crooks (agc@netbsd.org)"
45#endif
46
47/* Constants for Buffer Gap routines */
48enum {
49	BGByte,
50	BGChar,
51	BGLine,
52
53	BGFromBOF,
54	BGFromHere,
55	BGFromEOF
56};
57
58/* this struct describes a file in memory */
59typedef struct bufgap_t {
60	uint64_t	 size;		/* size of file */
61	uint64_t	 abc;		/* # of bytes after the gap */
62	uint64_t	 bbc;		/* # of bytes before the gap */
63	uint64_t	 acc;		/* # of utf chars after the gap */
64	uint64_t	 bcc;		/* # of utf chars before the gap */
65	uint64_t	 alc;		/* # of records after the gap */
66	uint64_t	 blc;		/* # of records before the gap */
67	char		*name;		/* file name - perhaps null */
68	char		*buf;		/* buffer-gap buffer */
69	char		 modified;	/* file has been modified */
70} bufgap_t;
71
72int bufgap_open(bufgap_t *, const char *);
73void bufgap_close(bufgap_t *);
74int bufgap_forwards(bufgap_t *, uint64_t, int);
75int bufgap_backwards(bufgap_t *, uint64_t, int);
76int bufgap_seek(bufgap_t *, int64_t, int, int);
77char *bufgap_getstr(bufgap_t *);
78int bufgap_getbin(bufgap_t *, void *, size_t);
79int64_t bufgap_tell(bufgap_t *, int, int);
80int64_t bufgap_size(bufgap_t *, int);
81int bufgap_insert(bufgap_t *, const char *, int);
82int bufgap_delete(bufgap_t *, uint64_t);
83int bufgap_peek(bufgap_t *, int64_t);
84char *bufgap_gettext(bufgap_t *, int64_t, int64_t);
85int bufgap_write(bufgap_t *, FILE *);
86int bufgap_dirty(bufgap_t *);
87
88#endif /* !BUFGAP_H_ */
89