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