aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/preconv.c
diff options
context:
space:
mode:
authorIngo Schwarze <schwarze@openbsd.org>2014-11-01 04:08:43 +0000
committerIngo Schwarze <schwarze@openbsd.org>2014-11-01 04:08:43 +0000
commitc68cbba22d595e6209d32633cbc4f64d2ce3e810 (patch)
tree75e5b3ca8a9e3badb5913a007bbf24424191f049 /preconv.c
parent87762e476141496baf99b8db674bb45f9f50cb03 (diff)
downloadmandoc-c68cbba22d595e6209d32633cbc4f64d2ce3e810.tar.gz
mandoc-c68cbba22d595e6209d32633cbc4f64d2ce3e810.tar.zst
mandoc-c68cbba22d595e6209d32633cbc4f64d2ce3e810.zip
Refactor, no functional change: Remove the parse point from struct buf.
Some functions need multiple parse points, some none at all, and it varies whether any of them need to be passed around. So better pass them as a separate argument, and only when needed.
Diffstat (limited to 'preconv.c')
-rw-r--r--preconv.c23
1 files changed, 12 insertions, 11 deletions
diff --git a/preconv.c b/preconv.c
index 3213c8ad..780eb70b 100644
--- a/preconv.c
+++ b/preconv.c
@@ -1,4 +1,4 @@
-/* $Id: preconv.c,v 1.10 2014/10/26 18:22:51 schwarze Exp $ */
+/* $Id: preconv.c,v 1.11 2014/11/01 04:08:43 schwarze Exp $ */
/*
* Copyright (c) 2011 Kristaps Dzonsons <kristaps@bsd.lv>
* Copyright (c) 2014 Ingo Schwarze <schwarze@openbsd.org>
@@ -25,7 +25,8 @@
#include "libmandoc.h"
int
-preconv_encode(struct buf *ib, struct buf *ob, int *filenc)
+preconv_encode(struct buf *ib, size_t *ii, struct buf *ob, size_t *oi,
+ int *filenc)
{
size_t i;
const long one = 1L;
@@ -45,7 +46,7 @@ preconv_encode(struct buf *ib, struct buf *ob, int *filenc)
if ( ! (*((const char *)(&one))))
be = 1;
- for (i = ib->offs; i < ib->sz; i++) {
+ for (i = *ii; i < ib->sz; i++) {
cu = ib->buf[i];
if (state) {
if ( ! (cu & 128) || (cu & 64)) {
@@ -79,11 +80,11 @@ preconv_encode(struct buf *ib, struct buf *ob, int *filenc)
(accum << 24);
if (accum < 0x80)
- ob->buf[ob->offs++] = accum;
+ ob->buf[(*oi)++] = accum;
else
- ob->offs += snprintf(ob->buf + ob->offs,
+ *oi += snprintf(ob->buf + *oi,
11, "\\[u%.4X]", accum);
- ib->offs = i + 1;
+ *ii = i + 1;
*filenc &= ~MPARSE_LATIN1;
return(1);
} else {
@@ -134,21 +135,21 @@ latin:
if ( ! (*filenc & MPARSE_LATIN1))
return(0);
- ob->offs += snprintf(ob->buf + ob->offs, 11,
- "\\[u%.4X]", (unsigned char)ib->buf[ib->offs++]);
+ *oi += snprintf(ob->buf + *oi, 11,
+ "\\[u%.4X]", (unsigned char)ib->buf[(*ii)++]);
*filenc &= ~MPARSE_UTF8;
return(1);
}
int
-preconv_cue(const struct buf *b)
+preconv_cue(const struct buf *b, size_t offset)
{
const char *ln, *eoln, *eoph;
size_t sz, phsz;
- ln = b->buf + b->offs;
- sz = b->sz - b->offs;
+ ln = b->buf + offset;
+ sz = b->sz - offset;
/* Look for the end-of-line. */