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