version 1.243, 2014/12/16 23:44:41 |
version 1.250, 2015/01/16 16:53:49 |
|
|
/* $Id$ */ |
/* $Id$ */ |
/* |
/* |
* Copyright (c) 2010, 2011, 2012 Kristaps Dzonsons <kristaps@bsd.lv> |
* Copyright (c) 2010, 2011, 2012, 2014 Kristaps Dzonsons <kristaps@bsd.lv> |
* Copyright (c) 2010-2014 Ingo Schwarze <schwarze@openbsd.org> |
* Copyright (c) 2010-2015 Ingo Schwarze <schwarze@openbsd.org> |
* |
* |
* Permission to use, copy, modify, and distribute this software for any |
* Permission to use, copy, modify, and distribute this software for any |
* purpose with or without fee is hereby granted, provided that the above |
* purpose with or without fee is hereby granted, provided that the above |
|
|
|
|
#include <assert.h> |
#include <assert.h> |
#include <ctype.h> |
#include <ctype.h> |
|
#include <limits.h> |
#include <stdio.h> |
#include <stdio.h> |
#include <stdlib.h> |
#include <stdlib.h> |
#include <string.h> |
#include <string.h> |
|
|
ROFF_T_, |
ROFF_T_, |
ROFF_EQ, |
ROFF_EQ, |
ROFF_EN, |
ROFF_EN, |
|
ROFF_IX, |
ROFF_cblock, |
ROFF_cblock, |
ROFF_USERDEF, |
ROFF_USERDEF, |
ROFF_MAX |
ROFF_MAX |
Line 273 static struct roffmac roffs[ROFF_MAX] = { |
|
Line 275 static struct roffmac roffs[ROFF_MAX] = { |
|
{ "T&", roff_T_, NULL, NULL, 0, NULL }, |
{ "T&", roff_T_, NULL, NULL, 0, NULL }, |
{ "EQ", roff_EQ, NULL, NULL, 0, NULL }, |
{ "EQ", roff_EQ, NULL, NULL, 0, NULL }, |
{ "EN", roff_EN, NULL, NULL, 0, NULL }, |
{ "EN", roff_EN, NULL, NULL, 0, NULL }, |
|
{ "IX", roff_line_ignore, NULL, NULL, 0, NULL }, |
{ ".", roff_cblock, NULL, NULL, 0, NULL }, |
{ ".", roff_cblock, NULL, NULL, 0, NULL }, |
{ NULL, roff_userdef, NULL, NULL, 0, NULL }, |
{ NULL, roff_userdef, NULL, NULL, 0, NULL }, |
}; |
}; |
Line 650 roff_res(struct roff *r, struct buf *buf, int ln, int |
|
Line 653 roff_res(struct roff *r, struct buf *buf, int ln, int |
|
r->parse, ln, (int)(stesc - buf->buf), |
r->parse, ln, (int)(stesc - buf->buf), |
"%.*s", (int)naml, stnam); |
"%.*s", (int)naml, stnam); |
res = ""; |
res = ""; |
|
} else if (buf->sz + strlen(res) > SHRT_MAX) { |
|
mandoc_msg(MANDOCERR_ROFFLOOP, r->parse, |
|
ln, (int)(stesc - buf->buf), NULL); |
|
return(ROFF_IGN); |
} |
} |
|
|
/* Replace the escape sequence by the string. */ |
/* Replace the escape sequence by the string. */ |
Line 1158 roff_cond_sub(ROFF_ARGS) |
|
Line 1165 roff_cond_sub(ROFF_ARGS) |
|
*ep = '&'; |
*ep = '&'; |
roff_ccond(r, ln, ep - buf->buf - 1); |
roff_ccond(r, ln, ep - buf->buf - 1); |
} |
} |
++ep; |
if (*ep != '\0') |
|
++ep; |
} |
} |
return(rr ? ROFF_CONT : ROFF_IGN); |
return(rr ? ROFF_CONT : ROFF_IGN); |
} |
} |
Line 1178 roff_cond_text(ROFF_ARGS) |
|
Line 1186 roff_cond_text(ROFF_ARGS) |
|
*ep = '&'; |
*ep = '&'; |
roff_ccond(r, ln, ep - buf->buf - 1); |
roff_ccond(r, ln, ep - buf->buf - 1); |
} |
} |
++ep; |
if (*ep != '\0') |
|
++ep; |
} |
} |
return(rr ? ROFF_CONT : ROFF_IGN); |
return(rr ? ROFF_CONT : ROFF_IGN); |
} |
} |
Line 1576 roff_evalnum(struct roff *r, int ln, const char *v, |
|
Line 1585 roff_evalnum(struct roff *r, int ln, const char *v, |
|
*res *= operand2; |
*res *= operand2; |
break; |
break; |
case '/': |
case '/': |
if (0 == operand2) { |
if (operand2 == 0) { |
mandoc_msg(MANDOCERR_DIVZERO, |
mandoc_msg(MANDOCERR_DIVZERO, |
r->parse, ln, *pos, v); |
r->parse, ln, *pos, v); |
*res = 0; |
*res = 0; |
Line 1585 roff_evalnum(struct roff *r, int ln, const char *v, |
|
Line 1594 roff_evalnum(struct roff *r, int ln, const char *v, |
|
*res /= operand2; |
*res /= operand2; |
break; |
break; |
case '%': |
case '%': |
|
if (operand2 == 0) { |
|
mandoc_msg(MANDOCERR_DIVZERO, |
|
r->parse, ln, *pos, v); |
|
*res = 0; |
|
break; |
|
} |
*res %= operand2; |
*res %= operand2; |
break; |
break; |
case '<': |
case '<': |
Line 2090 roff_tr(ROFF_ARGS) |
|
Line 2105 roff_tr(ROFF_ARGS) |
|
static enum rofferr |
static enum rofferr |
roff_so(ROFF_ARGS) |
roff_so(ROFF_ARGS) |
{ |
{ |
char *name; |
char *name, *cp; |
|
|
name = buf->buf + pos; |
name = buf->buf + pos; |
mandoc_vmsg(MANDOCERR_SO, r->parse, ln, ppos, "so %s", name); |
mandoc_vmsg(MANDOCERR_SO, r->parse, ln, ppos, "so %s", name); |
Line 2105 roff_so(ROFF_ARGS) |
|
Line 2120 roff_so(ROFF_ARGS) |
|
if (*name == '/' || strstr(name, "../") || strstr(name, "/..")) { |
if (*name == '/' || strstr(name, "../") || strstr(name, "/..")) { |
mandoc_vmsg(MANDOCERR_SO_PATH, r->parse, ln, ppos, |
mandoc_vmsg(MANDOCERR_SO_PATH, r->parse, ln, ppos, |
".so %s", name); |
".so %s", name); |
return(ROFF_ERR); |
buf->sz = mandoc_asprintf(&cp, |
|
".sp\nSee the file %s.\n.sp", name) + 1; |
|
free(buf->buf); |
|
buf->buf = cp; |
|
*offs = 0; |
|
return(ROFF_REPARSE); |
} |
} |
|
|
*offs = pos; |
*offs = pos; |
Line 2156 roff_userdef(ROFF_ARGS) |
|
Line 2176 roff_userdef(ROFF_ARGS) |
|
buf->buf = n1; |
buf->buf = n1; |
if (buf->sz == 0) |
if (buf->sz == 0) |
buf->sz = strlen(buf->buf) + 1; |
buf->sz = strlen(buf->buf) + 1; |
|
*offs = 0; |
|
|
return(buf->sz > 1 && buf->buf[buf->sz - 2] == '\n' ? |
return(buf->sz > 1 && buf->buf[buf->sz - 2] == '\n' ? |
ROFF_REPARSE : ROFF_APPEND); |
ROFF_REPARSE : ROFF_APPEND); |