Fri Mar 22 01:24:47 2013 UTC ()
move the code to expand variables in one place and use it to expand
variables inside conditionals. still conditionals with variables don't
work.


(christos)
diff -r1.2 -r1.3 src/external/bsd/mdocml/dist/libmandoc.h
diff -r1.7 -r1.8 src/external/bsd/mdocml/dist/read.c
diff -r1.8 -r1.9 src/external/bsd/mdocml/dist/roff.c

cvs diff -r1.2 -r1.3 src/external/bsd/mdocml/dist/libmandoc.h (expand / switch to unified diff)

--- src/external/bsd/mdocml/dist/libmandoc.h 2013/03/21 21:42:16 1.2
+++ src/external/bsd/mdocml/dist/libmandoc.h 2013/03/22 01:24:46 1.3
@@ -63,27 +63,28 @@ void man_free(struct man *); @@ -63,27 +63,28 @@ void man_free(struct man *);
63struct man *man_alloc(struct roff *, struct mparse *); 63struct man *man_alloc(struct roff *, struct mparse *);
64void man_reset(struct man *); 64void man_reset(struct man *);
65int man_parseln(struct man *, int, char *, int); 65int man_parseln(struct man *, int, char *, int);
66int man_endparse(struct man *); 66int man_endparse(struct man *);
67int man_addspan(struct man *, const struct tbl_span *); 67int man_addspan(struct man *, const struct tbl_span *);
68int man_addeqn(struct man *, const struct eqn *); 68int man_addeqn(struct man *, const struct eqn *);
69 69
70void roff_free(struct roff *); 70void roff_free(struct roff *);
71struct roff *roff_alloc(struct mparse *); 71struct roff *roff_alloc(struct mparse *);
72void roff_reset(struct roff *); 72void roff_reset(struct roff *);
73enum rofferr roff_parseln(struct roff *, int,  73enum rofferr roff_parseln(struct roff *, int,
74 char **, size_t *, int, int *); 74 char **, size_t *, int, int *);
75void roff_endparse(struct roff *); 75void roff_endparse(struct roff *);
76size_t roff_expand_nr(struct roff *, const char *, char *, size_t); 76void roff_expand_nr(struct roff *, const char *, int *, size_t,
 77 char **, int *, size_t *);
77int roff_regisset(const struct roff *, enum regs); 78int roff_regisset(const struct roff *, enum regs);
78unsigned int roff_regget(const struct roff *, enum regs); 79unsigned int roff_regget(const struct roff *, enum regs);
79void roff_regunset(struct roff *, enum regs); 80void roff_regunset(struct roff *, enum regs);
80char *roff_strdup(const struct roff *, const char *); 81char *roff_strdup(const struct roff *, const char *);
81#if 0 82#if 0
82char roff_eqndelim(const struct roff *); 83char roff_eqndelim(const struct roff *);
83void roff_openeqn(struct roff *, const char *,  84void roff_openeqn(struct roff *, const char *,
84 int, int, const char *); 85 int, int, const char *);
85int roff_closeeqn(struct roff *); 86int roff_closeeqn(struct roff *);
86#endif 87#endif
87 88
88const struct tbl_span *roff_span(const struct roff *); 89const struct tbl_span *roff_span(const struct roff *);
89const struct eqn *roff_eqn(const struct roff *); 90const struct eqn *roff_eqn(const struct roff *);

cvs diff -r1.7 -r1.8 src/external/bsd/mdocml/dist/read.c (expand / switch to unified diff)

--- src/external/bsd/mdocml/dist/read.c 2013/03/21 21:42:16 1.7
+++ src/external/bsd/mdocml/dist/read.c 2013/03/22 01:24:46 1.8
@@ -344,39 +344,28 @@ mparse_buf_r(struct mparse *curp, struct @@ -344,39 +344,28 @@ mparse_buf_r(struct mparse *curp, struct
344 continue; 344 continue;
345 } 345 }
346 346
347 /* Trailing backslash = a plain char. */ 347 /* Trailing backslash = a plain char. */
348 348
349 if ('\\' != blk.buf[i] || i + 1 == (int)blk.sz) { 349 if ('\\' != blk.buf[i] || i + 1 == (int)blk.sz) {
350 if (pos >= (int)ln.sz) 350 if (pos >= (int)ln.sz)
351 resize_buf(&ln, 256); 351 resize_buf(&ln, 256);
352 ln.buf[pos++] = blk.buf[i++]; 352 ln.buf[pos++] = blk.buf[i++];
353 continue; 353 continue;
354 } 354 }
355 355
356 if ('\\' == blk.buf[i] && 'n' == blk.buf[i + 1]) { 356 if ('\\' == blk.buf[i] && 'n' == blk.buf[i + 1]) {
357 int j, k; 357 roff_expand_nr(curp->roff,
358 i += 2; 358 blk.buf, &i, blk.sz, &ln.buf, &pos, &ln.sz);
359 if ('(' == blk.buf[i]) /* ) */ 
360 i++; 
361 resize_buf(&ln, 256); 
362 for (j = i, k = pos; i < j + 256  
363 && i < (int)blk.sz 
364 && !isspace((unsigned char)blk.buf[i]);) 
365 ln.buf[k++] = blk.buf[i++]; 
366 
367 ln.buf[k] = '\0'; 
368 pos += roff_expand_nr(curp->roff, 
369 ln.buf + pos, ln.buf + pos, 256); 
370 } 359 }
371 360
372 /* 361 /*
373 * Found escape and at least one other character. 362 * Found escape and at least one other character.
374 * When it's a newline character, skip it. 363 * When it's a newline character, skip it.
375 * When there is a carriage return in between, 364 * When there is a carriage return in between,
376 * skip that one as well. 365 * skip that one as well.
377 */ 366 */
378 367
379 if ('\r' == blk.buf[i + 1] && i + 2 < (int)blk.sz && 368 if ('\r' == blk.buf[i + 1] && i + 2 < (int)blk.sz &&
380 '\n' == blk.buf[i + 2]) 369 '\n' == blk.buf[i + 2])
381 ++i; 370 ++i;
382 if ('\n' == blk.buf[i + 1]) { 371 if ('\n' == blk.buf[i + 1]) {

cvs diff -r1.8 -r1.9 src/external/bsd/mdocml/dist/roff.c (expand / switch to unified diff)

--- src/external/bsd/mdocml/dist/roff.c 2013/03/21 21:42:16 1.8
+++ src/external/bsd/mdocml/dist/roff.c 2013/03/22 01:24:46 1.9
@@ -167,26 +167,28 @@ static void roffhash_init(void); @@ -167,26 +167,28 @@ static void roffhash_init(void);
167static void roffnode_cleanscope(struct roff *); 167static void roffnode_cleanscope(struct roff *);
168static void roffnode_pop(struct roff *); 168static void roffnode_pop(struct roff *);
169static void roffnode_push(struct roff *, enum rofft, 169static void roffnode_push(struct roff *, enum rofft,
170 const char *, int, int); 170 const char *, int, int);
171static enum rofferr roff_block(ROFF_ARGS); 171static enum rofferr roff_block(ROFF_ARGS);
172static enum rofferr roff_block_text(ROFF_ARGS); 172static enum rofferr roff_block_text(ROFF_ARGS);
173static enum rofferr roff_block_sub(ROFF_ARGS); 173static enum rofferr roff_block_sub(ROFF_ARGS);
174static enum rofferr roff_cblock(ROFF_ARGS); 174static enum rofferr roff_cblock(ROFF_ARGS);
175static enum rofferr roff_ccond(ROFF_ARGS); 175static enum rofferr roff_ccond(ROFF_ARGS);
176static enum rofferr roff_cond(ROFF_ARGS); 176static enum rofferr roff_cond(ROFF_ARGS);
177static enum rofferr roff_cond_text(ROFF_ARGS); 177static enum rofferr roff_cond_text(ROFF_ARGS);
178static enum rofferr roff_cond_sub(ROFF_ARGS); 178static enum rofferr roff_cond_sub(ROFF_ARGS);
179static enum rofferr roff_ds(ROFF_ARGS); 179static enum rofferr roff_ds(ROFF_ARGS);
 180static void roff_expand_nr_inplace(struct roff *, char **, int *,
 181 size_t *);
180static enum roffrule roff_evalcond(const char *, int *); 182static enum roffrule roff_evalcond(const char *, int *);
181static void roff_free1(struct roff *); 183static void roff_free1(struct roff *);
182static void roff_freestr(struct roffkv *); 184static void roff_freestr(struct roffkv *);
183static char *roff_getname(struct roff *, char **, int, int); 185static char *roff_getname(struct roff *, char **, int, int);
184static const char *roff_getstrn(const struct roff *,  186static const char *roff_getstrn(const struct roff *,
185 const char *, size_t); 187 const char *, size_t);
186static enum rofferr roff_line_ignore(ROFF_ARGS); 188static enum rofferr roff_line_ignore(ROFF_ARGS);
187static enum rofferr roff_nr(ROFF_ARGS); 189static enum rofferr roff_nr(ROFF_ARGS);
188static void roff_openeqn(struct roff *, const char *, 190static void roff_openeqn(struct roff *, const char *,
189 int, int, const char *); 191 int, int, const char *);
190static enum rofft roff_parse(struct roff *, const char *, int *); 192static enum rofft roff_parse(struct roff *, const char *, int *);
191static enum rofferr roff_parsetext(char *); 193static enum rofferr roff_parsetext(char *);
192static enum rofferr roff_res(struct roff *,  194static enum rofferr roff_res(struct roff *,
@@ -1043,26 +1045,32 @@ roff_cond_sub(ROFF_ARGS) @@ -1043,26 +1045,32 @@ roff_cond_sub(ROFF_ARGS)
1043/* ARGSUSED */ 1045/* ARGSUSED */
1044static enum rofferr 1046static enum rofferr
1045roff_cond_text(ROFF_ARGS) 1047roff_cond_text(ROFF_ARGS)
1046{ 1048{
1047 char *ep; 1049 char *ep;
1048 enum roffrule rr; 1050 enum roffrule rr;
1049 1051
1050 rr = r->last->rule; 1052 rr = r->last->rule;
1051 roffnode_cleanscope(r); 1053 roffnode_cleanscope(r);
1052 1054
1053 ep = &(*bufp)[pos]; 1055 ep = &(*bufp)[pos];
1054 for ( ; NULL != (ep = strchr(ep, '\\')); ep++) { 1056 for ( ; NULL != (ep = strchr(ep, '\\')); ep++) {
1055 ep++; 1057 ep++;
 1058 if (*ep == 'n') {
 1059 int i = ep - *bufp - 1;
 1060 roff_expand_nr_inplace(r, bufp, &i, szp);
 1061 ep = *bufp + i;
 1062 continue;
 1063 }
1056 if ('}' != *ep) 1064 if ('}' != *ep)
1057 continue; 1065 continue;
1058 *ep = '&'; 1066 *ep = '&';
1059 roff_ccond(r, ROFF_ccond, bufp, szp,  1067 roff_ccond(r, ROFF_ccond, bufp, szp,
1060 ln, pos, pos + 2, offs); 1068 ln, pos, pos + 2, offs);
1061 } 1069 }
1062 return(ROFFRULE_DENY == rr ? ROFF_IGN : ROFF_CONT); 1070 return(ROFFRULE_DENY == rr ? ROFF_IGN : ROFF_CONT);
1063} 1071}
1064 1072
1065static enum roffrule 1073static enum roffrule
1066roff_evalcond(const char *v, int *pos) 1074roff_evalcond(const char *v, int *pos)
1067{ 1075{
1068 1076
@@ -1298,37 +1306,96 @@ roff_nr(ROFF_ARGS) @@ -1298,37 +1306,96 @@ roff_nr(ROFF_ARGS)
1298 h->val = mandoc_strntoi(val, strlen(val), 10); 1306 h->val = mandoc_strntoi(val, strlen(val), 10);
1299 1307
1300 if (0 == strcmp(key, "nS")) { 1308 if (0 == strcmp(key, "nS")) {
1301 r->regs[(int)REG_nS].set = 1; 1309 r->regs[(int)REG_nS].set = 1;
1302 if (h->val >= 0) 1310 if (h->val >= 0)
1303 r->regs[(int)REG_nS].u = (unsigned)h->val; 1311 r->regs[(int)REG_nS].u = (unsigned)h->val;
1304 else 1312 else
1305 r->regs[(int)REG_nS].u = 0u; 1313 r->regs[(int)REG_nS].u = 0u;
1306 } 1314 }
1307 1315
1308 return(ROFF_IGN); 1316 return(ROFF_IGN);
1309} 1317}
1310 1318
1311size_t 1319void
1312roff_expand_nr(struct roff *r, const char *key, char *lp, size_t lpl) 1320roff_expand_nr(struct roff *r, const char *src, int *sp, size_t slen,
 1321 char **dst, int *dp, size_t *dlenp)
1313{ 1322{
1314 uint32_t hv; 1323 uint32_t hv;
1315 struct roff_nr *h; 1324 struct roff_nr *h;
 1325 int l, s, d;
 1326 char e, *key;
1316 1327
1317 if ((h = hash_find(r, key, &hv)) == NULL) 1328 s = *sp + 2; /* skip \\\n */
1318 return 0; 1329 d = *dp;
 1330
 1331 if ('[' == src[s]) { /* XXX: Support builtins */
 1332 s++;
 1333 e = ']';
 1334 } else
 1335 e = '\0';
 1336
 1337 for (l = s; l < (int)slen; l++) {
 1338 if (e) {
 1339 if (src[l] == e)
 1340 break;
 1341 } else {
 1342 if (isspace((unsigned char)src[l]))
 1343 break;
 1344 }
 1345 }
 1346 *sp = l;
 1347 l -= s;
 1348 key = mandoc_malloc(l + 1);
 1349 memcpy(key, src + s, l);
 1350 key[l] = '\0';
 1351
 1352 if ((h = hash_find(r, key, &hv)) == NULL) {
 1353 free(key);
 1354 return;
 1355 }
 1356 if (*dst == NULL || *dlenp - *dp < 256)
 1357 *dst = mandoc_realloc(*dst, *dlenp += 256);
1319 1358
1320 /* XXX: support .af */ 1359 /* XXX: support .af */
1321 return snprintf(lp, lpl, "%jd", h->val); 1360 *dp += snprintf(*dst + *dp, *dlenp - *dp, "%jd", h->val);
 1361}
 1362
 1363static void
 1364roff_expand_nr_inplace(struct roff *r, char **src, int *sp, size_t *slenp)
 1365{
 1366 int j, i, k;
 1367 size_t dlen;
 1368 char *dst;
 1369
 1370 k = i = *sp;
 1371
 1372 dst = NULL;
 1373 j = 0;
 1374 dlen = 0;
 1375
 1376 roff_expand_nr(r, *src, &i, *slenp, &dst, &j, &dlen);
 1377
 1378 if (j) {
 1379 int l = j - (i - k);
 1380 if (l > 0) {
 1381 *slenp += l;
 1382 *src = mandoc_realloc(*src, *slenp);
 1383 }
 1384 memmove(*src + j + k, *src + i, *slenp - i);
 1385 memcpy(*src + k, dst, j);
 1386 free(dst);
 1387 }
 1388 *sp = k + j;
1322} 1389}
1323 1390
1324/* ARGSUSED */ 1391/* ARGSUSED */
1325static enum rofferr 1392static enum rofferr
1326roff_rm(ROFF_ARGS) 1393roff_rm(ROFF_ARGS)
1327{ 1394{
1328 const char *name; 1395 const char *name;
1329 char *cp; 1396 char *cp;
1330 1397
1331 cp = *bufp + pos; 1398 cp = *bufp + pos;
1332 while ('\0' != *cp) { 1399 while ('\0' != *cp) {
1333 name = roff_getname(r, &cp, ln, (int)(cp - *bufp)); 1400 name = roff_getname(r, &cp, ln, (int)(cp - *bufp));
1334 if ('\0' != *name) 1401 if ('\0' != *name)