Module Name: othersrc
Committed By: agc
Date: Thu Oct 13 15:59:10 UTC 2011
Modified Files:
othersrc/external/bsd/bufgap/dist: bufgap.3 bufgap.c bufgap.h
Log Message:
add a bufgap_getline() function which retrieves, in allocated storage, a
line from a buffer gap instance.
add commented out field names to function prototypes, and update the
minimalist documentation.
To generate a diff of this commit:
cvs rdiff -u -r1.2 -r1.3 othersrc/external/bsd/bufgap/dist/bufgap.3
cvs rdiff -u -r1.1.1.1 -r1.2 othersrc/external/bsd/bufgap/dist/bufgap.c \
othersrc/external/bsd/bufgap/dist/bufgap.h
Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.
Modified files:
Index: othersrc/external/bsd/bufgap/dist/bufgap.3
diff -u othersrc/external/bsd/bufgap/dist/bufgap.3:1.2 othersrc/external/bsd/bufgap/dist/bufgap.3:1.3
--- othersrc/external/bsd/bufgap/dist/bufgap.3:1.2 Mon Jun 13 20:43:55 2011
+++ othersrc/external/bsd/bufgap/dist/bufgap.3 Thu Oct 13 15:59:10 2011
@@ -1,4 +1,4 @@
-.\" $NetBSD: bufgap.3,v 1.2 2011/06/13 20:43:55 wiz Exp $
+.\" $NetBSD: bufgap.3,v 1.3 2011/10/13 15:59:10 agc Exp $
.\"
.\" Copyright (c) 1996-2011 Alistair Crooks <[email protected]>
.\" All rights reserved.
@@ -23,7 +23,7 @@
.\" (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
.\" THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
.\"
-.Dd June 3, 2011
+.Dd October 13, 2011
.Dt BUFGAP 3
.Os
.Sh NAME
@@ -79,6 +79,10 @@
.Fo bufgap_gettext
.Fa "bufgap_t *bufgap" "int64_t off" "int64_t size"
.Fc
+.Ft char *
+.Fo bufgap_getline
+.Fa "bufgap_t *bufgap" "int64_t line"
+.Fc
.Ft int
.Fo bufgap_write
.Fa "bufgap_t *bufgap" "FILE *fp"
Index: othersrc/external/bsd/bufgap/dist/bufgap.c
diff -u othersrc/external/bsd/bufgap/dist/bufgap.c:1.1.1.1 othersrc/external/bsd/bufgap/dist/bufgap.c:1.2
--- othersrc/external/bsd/bufgap/dist/bufgap.c:1.1.1.1 Sun Jun 12 07:48:28 2011
+++ othersrc/external/bsd/bufgap/dist/bufgap.c Thu Oct 13 15:59:10 2011
@@ -1,4 +1,4 @@
-/* $NetBSD: bufgap.c,v 1.1.1.1 2011/06/12 07:48:28 agc Exp $ */
+/* $NetBSD: bufgap.c,v 1.2 2011/10/13 15:59:10 agc Exp $ */
/*-
* Copyright (c) 1996-2011 Alistair Crooks <[email protected]>
@@ -490,6 +490,33 @@ bufgap_gettext(bufgap_t *bp, int64_t fro
return text;
}
+/* return, in malloc'd storage, a line from the buffer gap */
+char *
+bufgap_getline(bufgap_t *bp, int64_t line)
+{
+ int64_t from;
+ int64_t to;
+ int64_t n;
+ char *text;
+
+ if (!bufgap_seek(bp, line, BGFromBOF, BGLine)) {
+ return NULL;
+ }
+ from = bufgap_tell(bp, BGFromBOF, BGChar);
+ if (!bufgap_seek(bp, line + 1, BGFromBOF, BGLine)) {
+ return NULL;
+ }
+ to = bufgap_tell(bp, BGFromBOF, BGChar);
+ NEWARRAY(char, text, (to - from + 1), "bufgap_gettext", return NULL);
+ (void) bufgap_seek(bp, from, BGFromBOF, BGChar);
+ for (n = 0 ; n < to - from ; n++) {
+ text[(int)n] = BEFSUB(bp, bp->bbc - n);
+ }
+ text[(int)n] = 0x0;
+ (void) bufgap_seek(bp, from, BGFromBOF, BGChar);
+ return text;
+}
+
/* return 1 if we wrote the file correctly */
int
bufgap_write(bufgap_t *bp, FILE *filep)
Index: othersrc/external/bsd/bufgap/dist/bufgap.h
diff -u othersrc/external/bsd/bufgap/dist/bufgap.h:1.1.1.1 othersrc/external/bsd/bufgap/dist/bufgap.h:1.2
--- othersrc/external/bsd/bufgap/dist/bufgap.h:1.1.1.1 Sun Jun 12 07:48:28 2011
+++ othersrc/external/bsd/bufgap/dist/bufgap.h Thu Oct 13 15:59:10 2011
@@ -1,4 +1,4 @@
-/* $NetBSD: bufgap.h,v 1.1.1.1 2011/06/12 07:48:28 agc Exp $ */
+/* $NetBSD: bufgap.h,v 1.2 2011/10/13 15:59:10 agc Exp $ */
/*-
* Copyright (c) 1996-2011 Alistair Crooks <[email protected]>
@@ -32,6 +32,18 @@
#include <inttypes.h>
#include <stdio.h>
+#ifndef __BEGIN_DECLS
+# if defined(__cplusplus)
+# define __BEGIN_DECLS extern "C" {
+# define __END_DECLS }
+# else
+# define __BEGIN_DECLS
+# define __END_DECLS
+# endif
+#endif
+
+__BEGIN_DECLS
+
#ifndef BUFGAP_VERSION_STRING
#define BUFGAP_VERSION_STRING "20091022"
#endif
@@ -65,20 +77,23 @@ typedef struct bufgap_t {
char modified; /* file has been modified */
} bufgap_t;
-int bufgap_open(bufgap_t *, const char *);
-void bufgap_close(bufgap_t *);
-int bufgap_forwards(bufgap_t *, uint64_t, int);
-int bufgap_backwards(bufgap_t *, uint64_t, int);
-int bufgap_seek(bufgap_t *, int64_t, int, int);
-char *bufgap_getstr(bufgap_t *);
-int bufgap_getbin(bufgap_t *, void *, size_t);
-int64_t bufgap_tell(bufgap_t *, int, int);
-int64_t bufgap_size(bufgap_t *, int);
-int bufgap_insert(bufgap_t *, const char *, int);
-int bufgap_delete(bufgap_t *, uint64_t);
-int bufgap_peek(bufgap_t *, int64_t);
-char *bufgap_gettext(bufgap_t *, int64_t, int64_t);
-int bufgap_write(bufgap_t *, FILE *);
-int bufgap_dirty(bufgap_t *);
+int bufgap_open(bufgap_t */*bp*/, const char */*filename*/);
+void bufgap_close(bufgap_t */*bp*/);
+int bufgap_forwards(bufgap_t */*bp*/, uint64_t /*off*/, int /*type*/);
+int bufgap_backwards(bufgap_t */*bp*/, uint64_t /*off*/, int /*type*/);
+int bufgap_seek(bufgap_t */*bp*/, int64_t /*off*/, int, int /*type*/);
+char *bufgap_getstr(bufgap_t */*bp*/);
+int bufgap_getbin(bufgap_t */*bp*/, void */*dest*/, size_t /*len*/);
+int64_t bufgap_tell(bufgap_t */*bp*/, int /*whence*/, int /*type*/);
+int64_t bufgap_size(bufgap_t */*bp*/, int /*type*/);
+int bufgap_insert(bufgap_t */*bp*/, const char */*text*/, int /*len*/);
+int bufgap_delete(bufgap_t */*bp*/, uint64_t /*len*/);
+int bufgap_peek(bufgap_t */*bp*/, int64_t /* delta */);
+char *bufgap_gettext(bufgap_t */*bp*/, int64_t /*from*/, int64_t /*to*/);
+char *bufgap_getline(bufgap_t */*bp*/, int64_t /*line*/);
+int bufgap_write(bufgap_t */*bp*/, FILE */*fp*/);
+int bufgap_dirty(bufgap_t */*bp*/);
+
+__END_DECLS
#endif /* !BUFGAP_H_ */