Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2025-01-18 09:54:02

0001 /*  $NetBSD: vis.h,v 1.25 2017/04/23 01:57:36 christos Exp $    */
0002 
0003 /*-
0004  * Copyright (c) 1990, 1993
0005  *  The Regents of the University of California.  All rights reserved.
0006  *
0007  * Redistribution and use in source and binary forms, with or without
0008  * modification, are permitted provided that the following conditions
0009  * are met:
0010  * 1. Redistributions of source code must retain the above copyright
0011  *    notice, this list of conditions and the following disclaimer.
0012  * 2. Redistributions in binary form must reproduce the above copyright
0013  *    notice, this list of conditions and the following disclaimer in the
0014  *    documentation and/or other materials provided with the distribution.
0015  * 3. Neither the name of the University nor the names of its contributors
0016  *    may be used to endorse or promote products derived from this software
0017  *    without specific prior written permission.
0018  *
0019  * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
0020  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
0021  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
0022  * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
0023  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
0024  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
0025  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
0026  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
0027  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
0028  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
0029  * SUCH DAMAGE.
0030  *
0031  *  @(#)vis.h   8.1 (Berkeley) 6/2/93
0032  */
0033 
0034 #ifndef LIBBSD_VIS_H
0035 #define LIBBSD_VIS_H
0036 
0037 #include <sys/types.h>
0038 
0039 /*
0040  * to select alternate encoding format
0041  */
0042 #define VIS_OCTAL   0x0001  /* use octal \ddd format */
0043 #define VIS_CSTYLE  0x0002  /* use \[nrft0..] where appropriate */
0044 
0045 /*
0046  * to alter set of characters encoded (default is to encode all
0047  * non-graphic except space, tab, and newline).
0048  */
0049 #define VIS_SP      0x0004  /* also encode space */
0050 #define VIS_TAB     0x0008  /* also encode tab */
0051 #define VIS_NL      0x0010  /* also encode newline */
0052 #define VIS_WHITE   (VIS_SP | VIS_TAB | VIS_NL)
0053 #define VIS_SAFE    0x0020  /* only encode "unsafe" characters */
0054 #define VIS_DQ      0x8000  /* also encode double quotes */
0055 
0056 /*
0057  * other
0058  */
0059 #define VIS_NOSLASH 0x0040  /* inhibit printing '\' */
0060 #define VIS_HTTP1808    0x0080  /* http-style escape % hex hex */
0061 #define VIS_HTTPSTYLE   0x0080  /* http-style escape % hex hex */
0062 #define VIS_MIMESTYLE   0x0100  /* mime-style escape = HEX HEX */
0063 #define VIS_HTTP1866    0x0200  /* http-style &#num; or &string; */
0064 #define VIS_NOESCAPE    0x0400  /* don't decode `\' */
0065 #define _VIS_END    0x0800  /* for unvis */
0066 #define VIS_GLOB    0x1000  /* encode glob(3) magic characters */
0067 #define VIS_SHELL   0x2000  /* encode shell special characters [not glob] */
0068 #define VIS_META    (VIS_WHITE | VIS_GLOB | VIS_SHELL)
0069 #define VIS_NOLOCALE    0x4000  /* encode using the C locale */
0070 
0071 /*
0072  * unvis return codes
0073  */
0074 #define UNVIS_VALID  1  /* character valid */
0075 #define UNVIS_VALIDPUSH  2  /* character valid, push back passed char */
0076 #define UNVIS_NOCHAR     3  /* valid sequence, no character produced */
0077 #define UNVIS_SYNBAD    -1  /* unrecognized escape sequence */
0078 #define UNVIS_ERROR -2  /* decoder in unknown state (unrecoverable) */
0079 
0080 /*
0081  * unvis flags
0082  */
0083 #define UNVIS_END   _VIS_END    /* no more characters */
0084 
0085 #ifdef LIBBSD_OVERLAY
0086 #include <sys/cdefs.h>
0087 #else
0088 #include <bsd/sys/cdefs.h>
0089 #endif
0090 
0091 /*
0092  * NetBSD added an strnvis and unfortunately made it incompatible with the
0093  * existing one in OpenBSD and Freedesktop's libbsd (the former having existed
0094  * for over ten years). Despite this incompatibility being reported during
0095  * development (see http://gnats.netbsd.org/44977) they still shipped it.
0096  * Even more unfortunately FreeBSD and later macOS picked up this incompatible
0097  * implementation.
0098  *
0099  * Provide both implementations and default for now on the historical one to
0100  * avoid breakage, we will switch to the NetBSD one in libbsd 0.10.0 or so.
0101  * Define LIBBSD_NETBSD_VIS to switch to the NetBSD one now.
0102  * Define LIBBSD_OPENBSD_VIS to keep using the OpenBSD one.
0103  */
0104 #if defined(LIBBSD_OPENBSD_VIS)
0105 #undef LIBBSD_NETBSD_VIS
0106 #elif !defined(LIBBSD_NETBSD_VIS)
0107 #warning "NetBSD added incompatible strnvis() and strnunvis(), please see <bsd/vis.h> for more detils."
0108 #endif
0109 
0110 __BEGIN_DECLS
0111 char    *vis(char *, int, int, int);
0112 char    *nvis(char *, size_t, int, int, int);
0113 
0114 char    *svis(char *, int, int, int, const char *);
0115 char    *snvis(char *, size_t, int, int, int, const char *);
0116 
0117 int strvis(char *, const char *, int);
0118 int stravis(char **, const char *, int);
0119 #ifdef LIBBSD_NETBSD_VIS
0120 /* NetBSD prototype. */
0121 int LIBBSD_REDIRECT(strnvis, (char *, size_t, const char *, int),
0122                         strnvis_netbsd);
0123 #else
0124 /* OpenBSD prototype (current default). */
0125 int strnvis(char *, const char *, size_t, int);
0126 #endif
0127 
0128 int strsvis(char *, const char *, int, const char *);
0129 int strsnvis(char *, size_t, const char *, int, const char *);
0130 
0131 int strvisx(char *, const char *, size_t, int);
0132 int strnvisx(char *, size_t, const char *, size_t, int);
0133 int strenvisx(char *, size_t, const char *, size_t, int, int *);
0134 
0135 int strsvisx(char *, const char *, size_t, int, const char *);
0136 int strsnvisx(char *, size_t, const char *, size_t, int, const char *);
0137 int strsenvisx(char *, size_t, const char *, size_t , int, const char *,
0138     int *);
0139 
0140 int strunvis(char *, const char *);
0141 #ifdef LIBBSD_NETBSD_VIS
0142 /* NetBSD prototype. */
0143 int LIBBSD_REDIRECT(strnunvis, (char *, size_t, const char *),
0144                         strnunvis_netbsd);
0145 #else
0146 /* OpenBSD prototype (current default). */
0147 ssize_t strnunvis(char *, const char *, size_t);
0148 #endif
0149 
0150 int strunvisx(char *, const char *, int);
0151 int strnunvisx(char *, size_t, const char *, int);
0152 
0153 int unvis(char *, int, int *, int);
0154 __END_DECLS
0155 
0156 #endif /* !LIBBSD_VIS_H */