1326324Sbrooks/*	$NetBSD: vis.h,v 1.25 2017/04/23 01:57:36 christos Exp $	*/
2244401Sbrooks/*	$FreeBSD: stable/10/contrib/libc-vis/vis.h 326324 2017-11-28 17:20:53Z brooks $	*/
3241236Sbrooks
4241236Sbrooks/*-
5241236Sbrooks * Copyright (c) 1990, 1993
6241236Sbrooks *	The Regents of the University of California.  All rights reserved.
7241236Sbrooks *
8241236Sbrooks * Redistribution and use in source and binary forms, with or without
9241236Sbrooks * modification, are permitted provided that the following conditions
10241236Sbrooks * are met:
11241236Sbrooks * 1. Redistributions of source code must retain the above copyright
12241236Sbrooks *    notice, this list of conditions and the following disclaimer.
13241236Sbrooks * 2. Redistributions in binary form must reproduce the above copyright
14241236Sbrooks *    notice, this list of conditions and the following disclaimer in the
15241236Sbrooks *    documentation and/or other materials provided with the distribution.
16241236Sbrooks * 3. Neither the name of the University nor the names of its contributors
17241236Sbrooks *    may be used to endorse or promote products derived from this software
18241236Sbrooks *    without specific prior written permission.
19241236Sbrooks *
20241236Sbrooks * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
21241236Sbrooks * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
22241236Sbrooks * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
23241236Sbrooks * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
24241236Sbrooks * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
25241236Sbrooks * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
26241236Sbrooks * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
27241236Sbrooks * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
28241236Sbrooks * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
29241236Sbrooks * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
30241236Sbrooks * SUCH DAMAGE.
31241236Sbrooks *
32241236Sbrooks *	@(#)vis.h	8.1 (Berkeley) 6/2/93
33241236Sbrooks */
34241236Sbrooks
35241236Sbrooks#ifndef _VIS_H_
36241236Sbrooks#define	_VIS_H_
37241236Sbrooks
38241236Sbrooks#include <sys/types.h>
39241236Sbrooks
40241236Sbrooks/*
41241236Sbrooks * to select alternate encoding format
42241236Sbrooks */
43244230Sbrooks#define	VIS_OCTAL	0x0001	/* use octal \ddd format */
44244230Sbrooks#define	VIS_CSTYLE	0x0002	/* use \[nrft0..] where appropiate */
45241236Sbrooks
46241236Sbrooks/*
47241236Sbrooks * to alter set of characters encoded (default is to encode all
48241236Sbrooks * non-graphic except space, tab, and newline).
49241236Sbrooks */
50244230Sbrooks#define	VIS_SP		0x0004	/* also encode space */
51244230Sbrooks#define	VIS_TAB		0x0008	/* also encode tab */
52244230Sbrooks#define	VIS_NL		0x0010	/* also encode newline */
53241236Sbrooks#define	VIS_WHITE	(VIS_SP | VIS_TAB | VIS_NL)
54244230Sbrooks#define	VIS_SAFE	0x0020	/* only encode "unsafe" characters */
55326324Sbrooks#define	VIS_DQ		0x8000	/* also encode double quotes */
56241236Sbrooks
57241236Sbrooks/*
58241236Sbrooks * other
59241236Sbrooks */
60244230Sbrooks#define	VIS_NOSLASH	0x0040	/* inhibit printing '\' */
61244230Sbrooks#define	VIS_HTTP1808	0x0080	/* http-style escape % hex hex */
62244230Sbrooks#define	VIS_HTTPSTYLE	0x0080	/* http-style escape % hex hex */
63244401Sbrooks#define	VIS_GLOB	0x0100	/* encode glob(3) magic characters */
64244401Sbrooks#define	VIS_MIMESTYLE	0x0200	/* mime-style escape = HEX HEX */
65244401Sbrooks#define	VIS_HTTP1866	0x0400	/* http-style &#num; or &string; */
66244401Sbrooks#define	VIS_NOESCAPE	0x0800	/* don't decode `\' */
67244401Sbrooks#define	_VIS_END	0x1000	/* for unvis */
68326324Sbrooks#define	VIS_SHELL	0x2000	/* encode shell special characters [not glob] */
69326324Sbrooks#define	VIS_META	(VIS_WHITE | VIS_GLOB | VIS_SHELL)
70326324Sbrooks#define	VIS_NOLOCALE	0x4000	/* encode using the C locale */
71241236Sbrooks
72241236Sbrooks/*
73241236Sbrooks * unvis return codes
74241236Sbrooks */
75241236Sbrooks#define	UNVIS_VALID	 1	/* character valid */
76241236Sbrooks#define	UNVIS_VALIDPUSH	 2	/* character valid, push back passed char */
77241236Sbrooks#define	UNVIS_NOCHAR	 3	/* valid sequence, no character produced */
78241236Sbrooks#define	UNVIS_SYNBAD	-1	/* unrecognized escape sequence */
79241236Sbrooks#define	UNVIS_ERROR	-2	/* decoder in unknown state (unrecoverable) */
80241236Sbrooks
81241236Sbrooks/*
82241236Sbrooks * unvis flags
83241236Sbrooks */
84241236Sbrooks#define	UNVIS_END	_VIS_END	/* no more characters */
85241236Sbrooks
86241236Sbrooks#include <sys/cdefs.h>
87241236Sbrooks
88241236Sbrooks__BEGIN_DECLS
89241236Sbrookschar	*vis(char *, int, int, int);
90241236Sbrookschar	*nvis(char *, size_t, int, int, int);
91241236Sbrooks
92241236Sbrookschar	*svis(char *, int, int, int, const char *);
93241236Sbrookschar	*snvis(char *, size_t, int, int, int, const char *);
94241236Sbrooks
95241236Sbrooksint	strvis(char *, const char *, int);
96326324Sbrooksint	stravis(char **, const char *, int);
97241236Sbrooksint	strnvis(char *, size_t, const char *, int);
98241236Sbrooks
99241236Sbrooksint	strsvis(char *, const char *, int, const char *);
100241236Sbrooksint	strsnvis(char *, size_t, const char *, int, const char *);
101241236Sbrooks
102241236Sbrooksint	strvisx(char *, const char *, size_t, int);
103241236Sbrooksint	strnvisx(char *, size_t, const char *, size_t, int);
104248302Sbrooksint 	strenvisx(char *, size_t, const char *, size_t, int, int *);
105241236Sbrooks
106241236Sbrooksint	strsvisx(char *, const char *, size_t, int, const char *);
107241236Sbrooksint	strsnvisx(char *, size_t, const char *, size_t, int, const char *);
108248302Sbrooksint	strsenvisx(char *, size_t, const char *, size_t , int, const char *,
109248302Sbrooks    int *);
110241236Sbrooks
111241236Sbrooksint	strunvis(char *, const char *);
112241236Sbrooksint	strnunvis(char *, size_t, const char *);
113241236Sbrooks
114241236Sbrooksint	strunvisx(char *, const char *, int);
115241236Sbrooksint	strnunvisx(char *, size_t, const char *, int);
116241236Sbrooks
117241236Sbrooks#ifndef __LIBC12_SOURCE__
118244401Sbrooksint	unvis(char *, int, int *, int);
119241236Sbrooks#endif
120241236Sbrooks__END_DECLS
121241236Sbrooks
122241236Sbrooks#endif /* !_VIS_H_ */
123