summary refs log tree commit diff
diff options
context:
space:
mode:
authorwrmr2024-11-05 23:04:49 -0500
committerwrmr2024-11-05 23:04:49 -0500
commit9c932e49a7516570b6c1ff9863595d495e3a3212 (patch)
treecfd5205bd322da368699c47de59c16737ea7da24
parent9ee9d3c7dec6090316d21c2eed40992372ac3efa (diff)
doc_add_link
-rw-r--r--buf.c2
-rw-r--r--buf.h2
-rw-r--r--doc.c5
-rw-r--r--doc.h3
4 files changed, 10 insertions, 2 deletions
diff --git a/buf.c b/buf.c
index 8460631..fb3af82 100644
--- a/buf.c
+++ b/buf.c
@@ -25,7 +25,7 @@ void buf_grow(buf_t *b, size_t n) {
 	}
 }
 
-void buf_cat(buf_t *b, char *src, size_t n) {
+void buf_cat(buf_t *b, const char *src, size_t n) {
 	buf_grow(b, n);
 	memcpy(&b->buf[b->sz], src, n);
 	b->sz += n;
diff --git a/buf.h b/buf.h
index c275f9c..59c521b 100644
--- a/buf.h
+++ b/buf.h
@@ -12,7 +12,7 @@ void buf_init(buf_t *, size_t);
 void buf_grow(buf_t *, size_t);
 void buf_free(buf_t *);
 
-void buf_cat(buf_t *b, char *src, size_t n);
+void buf_cat(buf_t *b, const char *src, size_t n);
 void buf_catc(buf_t *b, char c);
 
 #endif
diff --git a/doc.c b/doc.c
index 3d1b378..3f63ba8 100644
--- a/doc.c
+++ b/doc.c
@@ -54,6 +54,11 @@ void doc_add_textn(struct doc *d, const char *s, size_t n) {
 	dl->len += n;
 }
 
+unsigned short doc_add_link(struct doc *d, const char *url) {
+	buf_cat(&d->lnk, url, strlen(url) + 1);
+	return d->linkc++;
+}
+
 /* line navigation */
 
 struct doc_line *doc_line_at(struct doc *d, size_t ofs) {
diff --git a/doc.h b/doc.h
index 01a8235..ea9a521 100644
--- a/doc.h
+++ b/doc.h
@@ -20,6 +20,7 @@ enum doc_type {
 struct doc {
 	buf_t txt, lnk;
 	size_t latest;
+	unsigned short linkc;
 };
 
 void doc_init(struct doc *);
@@ -34,4 +35,6 @@ struct doc_line *doc_line_at(struct doc *d, size_t ofs);
 int doc_line_prev(struct doc *d, size_t *ofs);
 int doc_line_next(struct doc *d, size_t *ofs);
 
+unsigned short doc_add_link(struct doc *d, const char *url);
+
 #endif