version 1.389, 2022/05/30 23:03:47 |
version 1.393, 2022/06/03 12:15:55 |
Line 1375 roff_expand(struct roff *r, struct buf *buf, int ln, i |
|
Line 1375 roff_expand(struct roff *r, struct buf *buf, int ln, i |
|
int iarg; /* index beginning the argument */ |
int iarg; /* index beginning the argument */ |
int iendarg; /* index right after the argument */ |
int iendarg; /* index right after the argument */ |
int iend; /* index right after the sequence */ |
int iend; /* index right after the sequence */ |
|
int isrc, idst; /* to reduce \\ and \. in names */ |
int deftype; /* type of definition to paste */ |
int deftype; /* type of definition to paste */ |
int argi; /* macro argument index */ |
int argi; /* macro argument index */ |
int quote_args; /* true for \\$@, false for \\$* */ |
int quote_args; /* true for \\$@, false for \\$* */ |
Line 1410 roff_expand(struct roff *r, struct buf *buf, int ln, i |
|
Line 1411 roff_expand(struct roff *r, struct buf *buf, int ln, i |
|
* it to backslashes and translate backslashes to \e. |
* it to backslashes and translate backslashes to \e. |
*/ |
*/ |
|
|
if (roff_escape(buf->buf, ln, pos, |
if (roff_escape(buf->buf, ln, pos, &iesc, &inam, |
&iesc, &iarg, &iendarg, &iend) != ESCAPE_EXPAND) { |
&iarg, &iendarg, &iend) != ESCAPE_EXPAND) { |
while (pos < iend) { |
while (pos < iend) { |
if (buf->buf[pos] == ec) { |
if (buf->buf[pos] == ec) { |
buf->buf[pos] = '\\'; |
buf->buf[pos] = '\\'; |
Line 1428 roff_expand(struct roff *r, struct buf *buf, int ln, i |
|
Line 1429 roff_expand(struct roff *r, struct buf *buf, int ln, i |
|
continue; |
continue; |
} |
} |
|
|
/* |
/* Reduce \\ and \. in names. */ |
* Treat "\E" just like "\"; |
|
* it only makes a difference in copy mode. |
|
*/ |
|
|
|
inam = iesc + 1; |
if (buf->buf[inam] == '*' || buf->buf[inam] == 'n') { |
while (buf->buf[inam] == 'E') |
isrc = idst = iarg; |
inam++; |
while (isrc < iendarg) { |
|
if (isrc + 1 < iendarg && |
|
buf->buf[isrc] == '\\' && |
|
(buf->buf[isrc + 1] == '\\' || |
|
buf->buf[isrc + 1] == '.')) |
|
isrc++; |
|
buf->buf[idst++] = buf->buf[isrc++]; |
|
} |
|
iendarg -= isrc - idst; |
|
} |
|
|
/* Handle expansion. */ |
/* Handle expansion. */ |
|
|
Line 1520 roff_expand(struct roff *r, struct buf *buf, int ln, i |
|
Line 1527 roff_expand(struct roff *r, struct buf *buf, int ln, i |
|
*dst++ = '"'; |
*dst++ = '"'; |
} |
} |
continue; |
continue; |
|
case 'A': |
|
ubuf[0] = iendarg > iarg ? '1' : '0'; |
|
ubuf[1] = '\0'; |
|
res = ubuf; |
|
break; |
case 'B': |
case 'B': |
npos = 0; |
npos = 0; |
ubuf[0] = iendarg > iarg && iend > iendarg && |
ubuf[0] = iendarg > iarg && iend > iendarg && |
Line 1535 roff_expand(struct roff *r, struct buf *buf, int ln, i |
|
Line 1547 roff_expand(struct roff *r, struct buf *buf, int ln, i |
|
roff_expand_patch(buf, iendarg, "}", iend); |
roff_expand_patch(buf, iendarg, "}", iend); |
roff_expand_patch(buf, iesc, "${", iarg); |
roff_expand_patch(buf, iesc, "${", iarg); |
continue; |
continue; |
|
case 'g': |
|
break; |
case 'n': |
case 'n': |
if (iendarg > iarg) |
if (iendarg > iarg) |
(void)snprintf(ubuf, sizeof(ubuf), "%d", |
(void)snprintf(ubuf, sizeof(ubuf), "%d", |
|
|
roff_getname(struct roff *r, char **cpp, int ln, int pos) |
roff_getname(struct roff *r, char **cpp, int ln, int pos) |
{ |
{ |
char *name, *cp; |
char *name, *cp; |
size_t namesz; |
int namesz, inam, iend; |
|
|
name = *cpp; |
name = *cpp; |
if (*name == '\0') |
if (*name == '\0') |
Line 4012 roff_getname(struct roff *r, char **cpp, int ln, int p |
|
Line 4026 roff_getname(struct roff *r, char **cpp, int ln, int p |
|
|
|
/* Advance cp to the byte after the end of the name. */ |
/* Advance cp to the byte after the end of the name. */ |
|
|
for (cp = name; 1; cp++) { |
cp = name; |
namesz = cp - name; |
namesz = 0; |
|
for (;;) { |
if (*cp == '\0') |
if (*cp == '\0') |
break; |
break; |
if (*cp == ' ' || *cp == '\t') { |
if (*cp == ' ' || *cp == '\t') { |
cp++; |
cp++; |
break; |
break; |
} |
} |
if (*cp != '\\') |
if (*cp != '\\') { |
|
if (name + namesz < cp) { |
|
name[namesz] = *cp; |
|
*cp = ' '; |
|
} |
|
namesz++; |
|
cp++; |
continue; |
continue; |
|
} |
if (cp[1] == '{' || cp[1] == '}') |
if (cp[1] == '{' || cp[1] == '}') |
break; |
break; |
if (*++cp == '\\') |
if (roff_escape(cp, 0, 0, NULL, &inam, |
continue; |
NULL, NULL, &iend) != ESCAPE_UNDEF) { |
mandoc_msg(MANDOCERR_NAMESC, ln, pos, |
mandoc_msg(MANDOCERR_NAMESC, ln, pos, |
"%.*s", (int)(cp - name + 1), name); |
"%.*s%.*s", namesz, name, iend, cp); |
mandoc_escape((const char **)&cp, NULL, NULL); |
cp += iend; |
break; |
break; |
|
} |
|
|
|
/* |
|
* In an identifier, \\, \., \G and so on |
|
* are reduced to \, ., G and so on, |
|
* vaguely similar to copy mode. |
|
*/ |
|
|
|
name[namesz++] = cp[inam]; |
|
while (iend--) { |
|
if (cp >= name + namesz) |
|
*cp = ' '; |
|
cp++; |
|
} |
} |
} |
|
|
/* Read past spaces. */ |
/* Read past spaces. */ |