Patrick Welche <prlw1@cam.ac.uk>
[netbsd-mini2440.git] / crypto / external / bsd / netpgp / dist / src / lib / bufgap.h
blobe8935acdd90d258ccfcc8f4d1e1f444bd0222756
1 /* $NetBSD: bufgap.c,v 1.1 2009/12/05 07:08:18 agc Exp $ */
3 /*-
4 * Copyright (c) 1996-2009 The NetBSD Foundation, Inc.
5 * All rights reserved.
7 * This code is derived from software contributed to The NetBSD Foundation
8 * by Alistair Crooks (agc@NetBSD.org)
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.
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.
31 #ifndef BUFGAP_H_
32 #define BUFGAP_H_ 20091023
34 #include <sys/types.h>
36 #include <inttypes.h>
37 #include <stdio.h>
39 #ifndef BUFGAP_VERSION_STRING
40 #define BUFGAP_VERSION_STRING "20091022"
41 #endif
43 #ifndef BUFGAP_AUTHOR_STRING
44 #define BUFGAP_AUTHOR_STRING "Alistair Crooks (agc@netbsd.org)"
45 #endif
47 /* Constants for Buffer Gap routines */
48 enum {
49 BGByte,
50 BGChar,
51 BGLine,
53 BGFromBOF,
54 BGFromHere,
55 BGFromEOF
58 /* this struct describes a file in memory */
59 typedef 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;
72 int bufgap_open(bufgap_t *, const char *);
73 void bufgap_close(bufgap_t *);
74 int bufgap_forwards(bufgap_t *, uint64_t, int);
75 int bufgap_backwards(bufgap_t *, uint64_t, int);
76 int bufgap_seek(bufgap_t *, int64_t, int, int);
77 char *bufgap_getstr(bufgap_t *);
78 int bufgap_getbin(bufgap_t *, void *, size_t);
79 int64_t bufgap_tell(bufgap_t *, int, int);
80 int64_t bufgap_size(bufgap_t *, int);
81 int bufgap_insert(bufgap_t *, const char *, int);
82 int bufgap_delete(bufgap_t *, uint64_t);
83 int bufgap_peek(bufgap_t *, int64_t);
84 char *bufgap_gettext(bufgap_t *, int64_t, int64_t);
85 int bufgap_write(bufgap_t *, FILE *);
86 int bufgap_dirty(bufgap_t *);
88 #endif /* !BUFGAP_H_ */