Source-Changes-HG archive
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]
[src/trunk]: src/external/bsd/mdocml/dist move the code to expand variables i...
details: https://anonhg.NetBSD.org/src/rev/bce035fe9748
branches: trunk
changeset: 785595:bce035fe9748
user: christos <christos%NetBSD.org@localhost>
date: Fri Mar 22 01:24:46 2013 +0000
description:
move the code to expand variables in one place and use it to expand
variables inside conditionals. still conditionals with variables don't
work.
diffstat:
external/bsd/mdocml/dist/libmandoc.h | 3 +-
external/bsd/mdocml/dist/read.c | 15 +------
external/bsd/mdocml/dist/roff.c | 77 +++++++++++++++++++++++++++++++++--
3 files changed, 76 insertions(+), 19 deletions(-)
diffs (145 lines):
diff -r c10d061b68a4 -r bce035fe9748 external/bsd/mdocml/dist/libmandoc.h
--- a/external/bsd/mdocml/dist/libmandoc.h Thu Mar 21 23:06:42 2013 +0000
+++ b/external/bsd/mdocml/dist/libmandoc.h Fri Mar 22 01:24:46 2013 +0000
@@ -73,7 +73,8 @@
enum rofferr roff_parseln(struct roff *, int,
char **, size_t *, int, int *);
void roff_endparse(struct roff *);
-size_t roff_expand_nr(struct roff *, const char *, char *, size_t);
+void roff_expand_nr(struct roff *, const char *, int *, size_t,
+ char **, int *, size_t *);
int roff_regisset(const struct roff *, enum regs);
unsigned int roff_regget(const struct roff *, enum regs);
void roff_regunset(struct roff *, enum regs);
diff -r c10d061b68a4 -r bce035fe9748 external/bsd/mdocml/dist/read.c
--- a/external/bsd/mdocml/dist/read.c Thu Mar 21 23:06:42 2013 +0000
+++ b/external/bsd/mdocml/dist/read.c Fri Mar 22 01:24:46 2013 +0000
@@ -354,19 +354,8 @@
}
if ('\\' == blk.buf[i] && 'n' == blk.buf[i + 1]) {
- int j, k;
- i += 2;
- if ('(' == blk.buf[i]) /* ) */
- i++;
- resize_buf(&ln, 256);
- for (j = i, k = pos; i < j + 256
- && i < (int)blk.sz
- && !isspace((unsigned char)blk.buf[i]);)
- ln.buf[k++] = blk.buf[i++];
-
- ln.buf[k] = '\0';
- pos += roff_expand_nr(curp->roff,
- ln.buf + pos, ln.buf + pos, 256);
+ roff_expand_nr(curp->roff,
+ blk.buf, &i, blk.sz, &ln.buf, &pos, &ln.sz);
}
/*
diff -r c10d061b68a4 -r bce035fe9748 external/bsd/mdocml/dist/roff.c
--- a/external/bsd/mdocml/dist/roff.c Thu Mar 21 23:06:42 2013 +0000
+++ b/external/bsd/mdocml/dist/roff.c Fri Mar 22 01:24:46 2013 +0000
@@ -177,6 +177,8 @@
static enum rofferr roff_cond_text(ROFF_ARGS);
static enum rofferr roff_cond_sub(ROFF_ARGS);
static enum rofferr roff_ds(ROFF_ARGS);
+static void roff_expand_nr_inplace(struct roff *, char **, int *,
+ size_t *);
static enum roffrule roff_evalcond(const char *, int *);
static void roff_free1(struct roff *);
static void roff_freestr(struct roffkv *);
@@ -1053,6 +1055,12 @@
ep = &(*bufp)[pos];
for ( ; NULL != (ep = strchr(ep, '\\')); ep++) {
ep++;
+ if (*ep == 'n') {
+ int i = ep - *bufp - 1;
+ roff_expand_nr_inplace(r, bufp, &i, szp);
+ ep = *bufp + i;
+ continue;
+ }
if ('}' != *ep)
continue;
*ep = '&';
@@ -1308,17 +1316,76 @@
return(ROFF_IGN);
}
-size_t
-roff_expand_nr(struct roff *r, const char *key, char *lp, size_t lpl)
+void
+roff_expand_nr(struct roff *r, const char *src, int *sp, size_t slen,
+ char **dst, int *dp, size_t *dlenp)
{
uint32_t hv;
struct roff_nr *h;
+ int l, s, d;
+ char e, *key;
- if ((h = hash_find(r, key, &hv)) == NULL)
- return 0;
+ s = *sp + 2; /* skip \\\n */
+ d = *dp;
+
+ if ('[' == src[s]) { /* XXX: Support builtins */
+ s++;
+ e = ']';
+ } else
+ e = '\0';
+
+ for (l = s; l < (int)slen; l++) {
+ if (e) {
+ if (src[l] == e)
+ break;
+ } else {
+ if (isspace((unsigned char)src[l]))
+ break;
+ }
+ }
+ *sp = l;
+ l -= s;
+ key = mandoc_malloc(l + 1);
+ memcpy(key, src + s, l);
+ key[l] = '\0';
+
+ if ((h = hash_find(r, key, &hv)) == NULL) {
+ free(key);
+ return;
+ }
+ if (*dst == NULL || *dlenp - *dp < 256)
+ *dst = mandoc_realloc(*dst, *dlenp += 256);
/* XXX: support .af */
- return snprintf(lp, lpl, "%jd", h->val);
+ *dp += snprintf(*dst + *dp, *dlenp - *dp, "%jd", h->val);
+}
+
+static void
+roff_expand_nr_inplace(struct roff *r, char **src, int *sp, size_t *slenp)
+{
+ int j, i, k;
+ size_t dlen;
+ char *dst;
+
+ k = i = *sp;
+
+ dst = NULL;
+ j = 0;
+ dlen = 0;
+
+ roff_expand_nr(r, *src, &i, *slenp, &dst, &j, &dlen);
+
+ if (j) {
+ int l = j - (i - k);
+ if (l > 0) {
+ *slenp += l;
+ *src = mandoc_realloc(*src, *slenp);
+ }
+ memmove(*src + j + k, *src + i, *slenp - i);
+ memcpy(*src + k, dst, j);
+ free(dst);
+ }
+ *sp = k + j;
}
/* ARGSUSED */
Home |
Main Index |
Thread Index |
Old Index