xref: /netbsd-src/crypto/external/bsd/netpgp/dist/src/lib/bufgap.h (revision 5b91f35fb9ab15c213fedb89af9b07eb791c8d44)
1*5b91f35fSagc /* $NetBSD: bufgap.h,v 1.2 2009/12/06 17:43:05 agc Exp $ */
291c29c74Sagc 
3*5b91f35fSagc /*-
4*5b91f35fSagc  * Copyright (c) 1996-2009 The NetBSD Foundation, Inc.
5*5b91f35fSagc  * All rights reserved.
6*5b91f35fSagc  *
7*5b91f35fSagc  * This code is derived from software contributed to The NetBSD Foundation
8*5b91f35fSagc  * by Alistair Crooks (agc@NetBSD.org)
991c29c74Sagc  *
1091c29c74Sagc  * Redistribution and use in source and binary forms, with or without
1191c29c74Sagc  * modification, are permitted provided that the following conditions
1291c29c74Sagc  * are met:
1391c29c74Sagc  * 1. Redistributions of source code must retain the above copyright
1491c29c74Sagc  *    notice, this list of conditions and the following disclaimer.
1591c29c74Sagc  * 2. Redistributions in binary form must reproduce the above copyright
1691c29c74Sagc  *    notice, this list of conditions and the following disclaimer in the
1791c29c74Sagc  *    documentation and/or other materials provided with the distribution.
1891c29c74Sagc  *
19*5b91f35fSagc  * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
20*5b91f35fSagc  * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
21*5b91f35fSagc  * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
22*5b91f35fSagc  * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
23*5b91f35fSagc  * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
24*5b91f35fSagc  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
25*5b91f35fSagc  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
26*5b91f35fSagc  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
27*5b91f35fSagc  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
28*5b91f35fSagc  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
29*5b91f35fSagc  * POSSIBILITY OF SUCH DAMAGE.
3091c29c74Sagc  */
3191c29c74Sagc #ifndef BUFGAP_H_
3291c29c74Sagc #define BUFGAP_H_ 20091023
3391c29c74Sagc 
3491c29c74Sagc #include <sys/types.h>
3591c29c74Sagc 
3691c29c74Sagc #include <inttypes.h>
3791c29c74Sagc #include <stdio.h>
3891c29c74Sagc 
3991c29c74Sagc #ifndef BUFGAP_VERSION_STRING
4091c29c74Sagc #define BUFGAP_VERSION_STRING	"20091022"
4191c29c74Sagc #endif
4291c29c74Sagc 
4391c29c74Sagc #ifndef BUFGAP_AUTHOR_STRING
4491c29c74Sagc #define BUFGAP_AUTHOR_STRING	"Alistair Crooks (agc@netbsd.org)"
4591c29c74Sagc #endif
4691c29c74Sagc 
4791c29c74Sagc /* Constants for Buffer Gap routines */
4891c29c74Sagc enum {
4991c29c74Sagc 	BGByte,
5091c29c74Sagc 	BGChar,
5191c29c74Sagc 	BGLine,
5291c29c74Sagc 
5391c29c74Sagc 	BGFromBOF,
5491c29c74Sagc 	BGFromHere,
5591c29c74Sagc 	BGFromEOF
5691c29c74Sagc };
5791c29c74Sagc 
5891c29c74Sagc /* this struct describes a file in memory */
5991c29c74Sagc typedef struct bufgap_t {
6091c29c74Sagc 	uint64_t	 size;		/* size of file */
6191c29c74Sagc 	uint64_t	 abc;		/* # of bytes after the gap */
6291c29c74Sagc 	uint64_t	 bbc;		/* # of bytes before the gap */
6391c29c74Sagc 	uint64_t	 acc;		/* # of utf chars after the gap */
6491c29c74Sagc 	uint64_t	 bcc;		/* # of utf chars before the gap */
6591c29c74Sagc 	uint64_t	 alc;		/* # of records after the gap */
6691c29c74Sagc 	uint64_t	 blc;		/* # of records before the gap */
6791c29c74Sagc 	char		*name;		/* file name - perhaps null */
6891c29c74Sagc 	char		*buf;		/* buffer-gap buffer */
6991c29c74Sagc 	char		 modified;	/* file has been modified */
7091c29c74Sagc } bufgap_t;
7191c29c74Sagc 
7291c29c74Sagc int bufgap_open(bufgap_t *, const char *);
7391c29c74Sagc void bufgap_close(bufgap_t *);
7491c29c74Sagc int bufgap_forwards(bufgap_t *, uint64_t, int);
7591c29c74Sagc int bufgap_backwards(bufgap_t *, uint64_t, int);
7691c29c74Sagc int bufgap_seek(bufgap_t *, int64_t, int, int);
7791c29c74Sagc char *bufgap_getstr(bufgap_t *);
7891c29c74Sagc int bufgap_getbin(bufgap_t *, void *, size_t);
7991c29c74Sagc int64_t bufgap_tell(bufgap_t *, int, int);
8091c29c74Sagc int64_t bufgap_size(bufgap_t *, int);
8191c29c74Sagc int bufgap_insert(bufgap_t *, const char *, int);
8291c29c74Sagc int bufgap_delete(bufgap_t *, uint64_t);
8391c29c74Sagc int bufgap_peek(bufgap_t *, int64_t);
8491c29c74Sagc char *bufgap_gettext(bufgap_t *, int64_t, int64_t);
8591c29c74Sagc int bufgap_write(bufgap_t *, FILE *);
8691c29c74Sagc int bufgap_dirty(bufgap_t *);
8791c29c74Sagc 
8891c29c74Sagc #endif /* !BUFGAP_H_ */
89