=================================================================== RCS file: /cvs/mandoc/preconv.c,v retrieving revision 1.14 retrieving revision 1.17 diff -u -p -r1.14 -r1.17 --- mandoc/preconv.c 2015/03/06 09:24:59 1.14 +++ mandoc/preconv.c 2018/12/13 11:55:47 1.17 @@ -1,4 +1,4 @@ -/* $Id: preconv.c,v 1.14 2015/03/06 09:24:59 kristaps Exp $ */ +/* $Id: preconv.c,v 1.17 2018/12/13 11:55:47 schwarze Exp $ */ /* * Copyright (c) 2011 Kristaps Dzonsons * Copyright (c) 2014 Ingo Schwarze @@ -22,18 +22,21 @@ #include #include #include + #include "mandoc.h" +#include "roff.h" +#include "mandoc_parse.h" #include "libmandoc.h" int -preconv_encode(struct buf *ib, size_t *ii, struct buf *ob, size_t *oi, +preconv_encode(const struct buf *ib, size_t *ii, struct buf *ob, size_t *oi, int *filenc) { - unsigned char *cu; - int nby; - unsigned int accum; + const unsigned char *cu; + int nby; + unsigned int accum; - cu = (unsigned char *)ib->buf + *ii; + cu = (const unsigned char *)ib->buf + *ii; assert(*cu & 0x80); if ( ! (*filenc & MPARSE_UTF8)) @@ -90,19 +93,19 @@ preconv_encode(struct buf *ib, size_t *ii, struct buf assert(accum < 0xd800 || accum > 0xdfff); *oi += snprintf(ob->buf + *oi, 11, "\\[u%.4X]", accum); - *ii = (char *)cu - ib->buf; + *ii = (const char *)cu - ib->buf; *filenc &= ~MPARSE_LATIN1; - return(1); + return 1; latin: if ( ! (*filenc & MPARSE_LATIN1)) - return(0); + return 0; *oi += snprintf(ob->buf + *oi, 11, "\\[u%.4X]", (unsigned char)ib->buf[(*ii)++]); *filenc &= ~MPARSE_UTF8; - return(1); + return 1; } int @@ -123,7 +126,7 @@ preconv_cue(const struct buf *b, size_t offset) if ((sz = (size_t)(eoln - ln)) < 10 || memcmp(ln, ".\\\" -*-", 7) || memcmp(eoln - 3, "-*-", 3)) - return(MPARSE_UTF8 | MPARSE_LATIN1); + return MPARSE_UTF8 | MPARSE_LATIN1; /* Move after the header and adjust for the trailer. */ @@ -162,15 +165,15 @@ preconv_cue(const struct buf *b, size_t offset) sz--; } if (0 == sz) - return(0); + return 0; /* Check us against known encodings. */ if (phsz > 4 && !strncasecmp(ln, "utf-8", 5)) - return(MPARSE_UTF8); + return MPARSE_UTF8; if (phsz > 10 && !strncasecmp(ln, "iso-latin-1", 11)) - return(MPARSE_LATIN1); - return(0); + return MPARSE_LATIN1; + return 0; } - return(MPARSE_UTF8 | MPARSE_LATIN1); + return MPARSE_UTF8 | MPARSE_LATIN1; }