Add a new flag to vis(3): VIS_GLOB which encodes the glob(3) magic

characters '*', '?' and '['.
This commit is contained in:
Poul-Henning Kamp 2003-10-30 10:40:49 +00:00
parent 7645e88596
commit 347fb1d46e
Notes: svn2git 2020-12-20 02:59:44 +00:00
svn path=/head/; revision=121728
3 changed files with 8 additions and 2 deletions

View File

@ -65,6 +65,7 @@ typedef __size_t size_t;
*/
#define VIS_NOSLASH 0x40 /* inhibit printing '\' */
#define VIS_HTTPSTYLE 0x80 /* http-style escape % HEX HEX */
#define VIS_GLOB 0x100 /* encode glob(3) magics */
/*
* unvis return codes

View File

@ -137,6 +137,9 @@ except space, tab, and newline are encoded.
The following flags
alter this:
.Bl -tag -width VIS_WHITEX
.It Dv VIS_GLOB
Also encode magic characters ('*', '?', '[') recognized by
.Xr glob 3
.It Dv VIS_SP
Also encode space.
.It Dv VIS_TAB

View File

@ -71,7 +71,9 @@ vis(dst, c, flag, nextc)
}
}
if (isgraph(c) ||
if ((flag & VIS_GLOB) && (c == '*' || c == '?' || c == '['))
;
else if (isgraph(c) ||
((flag & VIS_SP) == 0 && c == ' ') ||
((flag & VIS_TAB) == 0 && c == '\t') ||
((flag & VIS_NL) == 0 && c == '\n') ||
@ -127,7 +129,7 @@ vis(dst, c, flag, nextc)
goto done;
}
}
if (((c & 0177) == ' ') || (flag & VIS_OCTAL)) {
if (((c & 0177) == ' ') || isgraph(c) || (flag & VIS_OCTAL)) {
*dst++ = '\\';
*dst++ = ((u_char)c >> 6 & 07) + '0';
*dst++ = ((u_char)c >> 3 & 07) + '0';