2002-07-03 21:18:09 +04:00
|
|
|
/* $NetBSD: vis.c,v 1.24 2002/07/03 17:18:09 pooka Exp $ */
|
1995-02-25 18:39:01 +03:00
|
|
|
|
1993-03-21 12:45:37 +03:00
|
|
|
/*-
|
Added new functions
char *
svis(char *dst, int c, int flag, int nextc, const char *extra);
int
strsvis(char *dst, const char *src, int flag, const char *extra);
int
strsvisx(char *dst, const char *src, size_t len, int flag,
const char *extra);
These functions correspond to vis(), strvis(), and strvisx() but have an
additional argument extra, pointing to a NUL terminated list of characters.
These characters will be copied encoded or backslash-escaped into dst. These
functions are useful e. g. to remove the special meaning of certain
characters to shells.
To implement the new functions, vis underwent a major rewrite. Most functions
now use a central macro, SVIS. Performance increase ~ factor 2.
Reviewed by Christos.
1999-11-25 19:50:06 +03:00
|
|
|
* Copyright (c) 1999 The NetBSD Foundation, Inc.
|
1995-02-25 18:39:01 +03:00
|
|
|
* Copyright (c) 1989, 1993
|
1999-11-29 01:51:37 +03:00
|
|
|
* The Regents of the University of California. All rights reserved.
|
1993-03-21 12:45:37 +03:00
|
|
|
*
|
|
|
|
* Redistribution and use in source and binary forms, with or without
|
|
|
|
* modification, are permitted provided that the following conditions
|
|
|
|
* are met:
|
|
|
|
* 1. Redistributions of source code must retain the above copyright
|
|
|
|
* notice, this list of conditions and the following disclaimer.
|
|
|
|
* 2. Redistributions in binary form must reproduce the above copyright
|
|
|
|
* notice, this list of conditions and the following disclaimer in the
|
|
|
|
* documentation and/or other materials provided with the distribution.
|
|
|
|
* 3. All advertising materials mentioning features or use of this software
|
|
|
|
* must display the following acknowledgement:
|
1999-11-29 01:51:37 +03:00
|
|
|
* This product includes software developed by the University of
|
|
|
|
* California, Berkeley and its contributors.
|
1993-03-21 12:45:37 +03:00
|
|
|
* 4. Neither the name of the University nor the names of its contributors
|
|
|
|
* may be used to endorse or promote products derived from this software
|
|
|
|
* without specific prior written permission.
|
|
|
|
*
|
|
|
|
* THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
|
|
|
|
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
|
|
|
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
|
|
|
* ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
|
|
|
|
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
|
|
|
|
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
|
|
|
|
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
|
|
|
|
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
|
|
|
|
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
|
|
|
|
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
|
|
|
|
* SUCH DAMAGE.
|
|
|
|
*/
|
|
|
|
|
1997-07-13 23:43:00 +04:00
|
|
|
#include <sys/cdefs.h>
|
2002-02-01 01:43:33 +03:00
|
|
|
#if defined(LIBC_SCCS) && !defined(lint)
|
2002-07-03 21:18:09 +04:00
|
|
|
__RCSID("$NetBSD: vis.c,v 1.24 2002/07/03 17:18:09 pooka Exp $");
|
2002-02-01 01:43:33 +03:00
|
|
|
#endif /* LIBC_SCCS and not lint */
|
1993-03-21 12:45:37 +03:00
|
|
|
|
1997-07-21 18:06:24 +04:00
|
|
|
#include "namespace.h"
|
1993-03-21 12:45:37 +03:00
|
|
|
#include <sys/types.h>
|
1999-09-16 15:44:54 +04:00
|
|
|
|
|
|
|
#include <assert.h>
|
1993-03-21 12:45:37 +03:00
|
|
|
#include <vis.h>
|
2002-03-23 20:38:27 +03:00
|
|
|
#include <stdlib.h>
|
1993-03-21 12:45:37 +03:00
|
|
|
|
1997-07-21 18:06:24 +04:00
|
|
|
#ifdef __weak_alias
|
2000-01-23 01:19:07 +03:00
|
|
|
__weak_alias(strsvis,_strsvis)
|
|
|
|
__weak_alias(strsvisx,_strsvisx)
|
|
|
|
__weak_alias(strvis,_strvis)
|
|
|
|
__weak_alias(strvisx,_strvisx)
|
|
|
|
__weak_alias(svis,_svis)
|
|
|
|
__weak_alias(vis,_vis)
|
1997-07-21 18:06:24 +04:00
|
|
|
#endif
|
2002-01-22 00:33:42 +03:00
|
|
|
|
2002-07-03 21:18:09 +04:00
|
|
|
#if !HAVE_VIS || !HAVE_SVIS
|
2002-01-22 00:33:42 +03:00
|
|
|
#include <ctype.h>
|
|
|
|
#include <limits.h>
|
|
|
|
#include <stdio.h>
|
|
|
|
#include <string.h>
|
1997-07-21 18:06:24 +04:00
|
|
|
|
Added new functions
char *
svis(char *dst, int c, int flag, int nextc, const char *extra);
int
strsvis(char *dst, const char *src, int flag, const char *extra);
int
strsvisx(char *dst, const char *src, size_t len, int flag,
const char *extra);
These functions correspond to vis(), strvis(), and strvisx() but have an
additional argument extra, pointing to a NUL terminated list of characters.
These characters will be copied encoded or backslash-escaped into dst. These
functions are useful e. g. to remove the special meaning of certain
characters to shells.
To implement the new functions, vis underwent a major rewrite. Most functions
now use a central macro, SVIS. Performance increase ~ factor 2.
Reviewed by Christos.
1999-11-25 19:50:06 +03:00
|
|
|
#undef BELL
|
|
|
|
#define BELL '\a'
|
|
|
|
|
1999-11-29 01:51:37 +03:00
|
|
|
#define isoctal(c) (((u_char)(c)) >= '0' && ((u_char)(c)) <= '7')
|
|
|
|
#define iswhite(c) (c == ' ' || c == '\t' || c == '\n')
|
|
|
|
#define issafe(c) (c == '\b' || c == BELL || c == '\r')
|
2002-03-23 20:38:27 +03:00
|
|
|
#define xtoa(c) "0123456789abcdef"[c]
|
Added new functions
char *
svis(char *dst, int c, int flag, int nextc, const char *extra);
int
strsvis(char *dst, const char *src, int flag, const char *extra);
int
strsvisx(char *dst, const char *src, size_t len, int flag,
const char *extra);
These functions correspond to vis(), strvis(), and strvisx() but have an
additional argument extra, pointing to a NUL terminated list of characters.
These characters will be copied encoded or backslash-escaped into dst. These
functions are useful e. g. to remove the special meaning of certain
characters to shells.
To implement the new functions, vis underwent a major rewrite. Most functions
now use a central macro, SVIS. Performance increase ~ factor 2.
Reviewed by Christos.
1999-11-25 19:50:06 +03:00
|
|
|
|
1999-11-29 01:51:37 +03:00
|
|
|
#define MAXEXTRAS 5
|
Added new functions
char *
svis(char *dst, int c, int flag, int nextc, const char *extra);
int
strsvis(char *dst, const char *src, int flag, const char *extra);
int
strsvisx(char *dst, const char *src, size_t len, int flag,
const char *extra);
These functions correspond to vis(), strvis(), and strvisx() but have an
additional argument extra, pointing to a NUL terminated list of characters.
These characters will be copied encoded or backslash-escaped into dst. These
functions are useful e. g. to remove the special meaning of certain
characters to shells.
To implement the new functions, vis underwent a major rewrite. Most functions
now use a central macro, SVIS. Performance increase ~ factor 2.
Reviewed by Christos.
1999-11-25 19:50:06 +03:00
|
|
|
|
1999-11-29 01:51:37 +03:00
|
|
|
|
2002-03-23 20:38:27 +03:00
|
|
|
#define MAKEEXTRALIST(flag, extra, orig) \
|
1999-11-29 01:51:37 +03:00
|
|
|
do { \
|
2002-03-23 20:38:27 +03:00
|
|
|
const char *o = orig; \
|
|
|
|
char *e; \
|
|
|
|
while (*o++) \
|
|
|
|
continue; \
|
|
|
|
extra = alloca((size_t)((o - orig) + MAXEXTRAS)); \
|
|
|
|
for (o = orig, e = extra; (*e++ = *o++) != '\0';) \
|
|
|
|
continue; \
|
|
|
|
e--; \
|
|
|
|
if (flag & VIS_SP) *e++ = ' '; \
|
|
|
|
if (flag & VIS_TAB) *e++ = '\t'; \
|
|
|
|
if (flag & VIS_NL) *e++ = '\n'; \
|
|
|
|
if ((flag & VIS_NOSLASH) == 0) *e++ = '\\'; \
|
|
|
|
*e = '\0'; \
|
2000-01-23 01:40:58 +03:00
|
|
|
} while (/*CONSTCOND*/0)
|
Added new functions
char *
svis(char *dst, int c, int flag, int nextc, const char *extra);
int
strsvis(char *dst, const char *src, int flag, const char *extra);
int
strsvisx(char *dst, const char *src, size_t len, int flag,
const char *extra);
These functions correspond to vis(), strvis(), and strvisx() but have an
additional argument extra, pointing to a NUL terminated list of characters.
These characters will be copied encoded or backslash-escaped into dst. These
functions are useful e. g. to remove the special meaning of certain
characters to shells.
To implement the new functions, vis underwent a major rewrite. Most functions
now use a central macro, SVIS. Performance increase ~ factor 2.
Reviewed by Christos.
1999-11-25 19:50:06 +03:00
|
|
|
|
2002-03-23 20:38:27 +03:00
|
|
|
|
|
|
|
/*
|
|
|
|
* This is HVIS, the macro of vis used to HTTP style (RFC 1808)
|
|
|
|
*/
|
|
|
|
#define HVIS(dst, c, flag, nextc, extra) \
|
|
|
|
do \
|
|
|
|
if (!isascii(c) || !isalnum(c) || strchr("$-_.+!*'(),", c) != NULL) { \
|
|
|
|
*dst++ = '%'; \
|
|
|
|
*dst++ = xtoa(((unsigned int)c >> 4) & 0xf); \
|
|
|
|
*dst++ = xtoa((unsigned int)c & 0xf); \
|
|
|
|
} else { \
|
|
|
|
SVIS(dst, c, flag, nextc, extra); \
|
|
|
|
} \
|
|
|
|
while (/*CONSTCOND*/0)
|
|
|
|
|
Added new functions
char *
svis(char *dst, int c, int flag, int nextc, const char *extra);
int
strsvis(char *dst, const char *src, int flag, const char *extra);
int
strsvisx(char *dst, const char *src, size_t len, int flag,
const char *extra);
These functions correspond to vis(), strvis(), and strvisx() but have an
additional argument extra, pointing to a NUL terminated list of characters.
These characters will be copied encoded or backslash-escaped into dst. These
functions are useful e. g. to remove the special meaning of certain
characters to shells.
To implement the new functions, vis underwent a major rewrite. Most functions
now use a central macro, SVIS. Performance increase ~ factor 2.
Reviewed by Christos.
1999-11-25 19:50:06 +03:00
|
|
|
/*
|
|
|
|
* This is SVIS, the central macro of vis.
|
1999-11-29 01:51:37 +03:00
|
|
|
* dst: Pointer to the destination buffer
|
|
|
|
* c: Character to encode
|
Added new functions
char *
svis(char *dst, int c, int flag, int nextc, const char *extra);
int
strsvis(char *dst, const char *src, int flag, const char *extra);
int
strsvisx(char *dst, const char *src, size_t len, int flag,
const char *extra);
These functions correspond to vis(), strvis(), and strvisx() but have an
additional argument extra, pointing to a NUL terminated list of characters.
These characters will be copied encoded or backslash-escaped into dst. These
functions are useful e. g. to remove the special meaning of certain
characters to shells.
To implement the new functions, vis underwent a major rewrite. Most functions
now use a central macro, SVIS. Performance increase ~ factor 2.
Reviewed by Christos.
1999-11-25 19:50:06 +03:00
|
|
|
* flag: Flag word
|
|
|
|
* nextc: The character following 'c'
|
|
|
|
* extra: Pointer to the list of extra characters to be
|
1999-11-29 01:51:37 +03:00
|
|
|
* backslash-protected.
|
Added new functions
char *
svis(char *dst, int c, int flag, int nextc, const char *extra);
int
strsvis(char *dst, const char *src, int flag, const char *extra);
int
strsvisx(char *dst, const char *src, size_t len, int flag,
const char *extra);
These functions correspond to vis(), strvis(), and strvisx() but have an
additional argument extra, pointing to a NUL terminated list of characters.
These characters will be copied encoded or backslash-escaped into dst. These
functions are useful e. g. to remove the special meaning of certain
characters to shells.
To implement the new functions, vis underwent a major rewrite. Most functions
now use a central macro, SVIS. Performance increase ~ factor 2.
Reviewed by Christos.
1999-11-25 19:50:06 +03:00
|
|
|
*/
|
1999-11-29 01:51:37 +03:00
|
|
|
#define SVIS(dst, c, flag, nextc, extra) \
|
|
|
|
do { \
|
|
|
|
int isextra, isc; \
|
|
|
|
isextra = strchr(extra, c) != NULL; \
|
1999-12-07 21:20:28 +03:00
|
|
|
if (!isextra && isascii(c) && (isgraph(c) || iswhite(c) || \
|
|
|
|
((flag & VIS_SAFE) && issafe(c)))) { \
|
1999-11-29 01:51:37 +03:00
|
|
|
*dst++ = c; \
|
|
|
|
break; \
|
|
|
|
} \
|
|
|
|
isc = 0; \
|
|
|
|
if (flag & VIS_CSTYLE) { \
|
|
|
|
switch (c) { \
|
|
|
|
case '\n': \
|
|
|
|
isc = 1; *dst++ = '\\'; *dst++ = 'n'; \
|
|
|
|
break; \
|
|
|
|
case '\r': \
|
|
|
|
isc = 1; *dst++ = '\\'; *dst++ = 'r'; \
|
|
|
|
break; \
|
|
|
|
case '\b': \
|
|
|
|
isc = 1; *dst++ = '\\'; *dst++ = 'b'; \
|
|
|
|
break; \
|
|
|
|
case BELL: \
|
|
|
|
isc = 1; *dst++ = '\\'; *dst++ = 'a'; \
|
|
|
|
break; \
|
|
|
|
case '\v': \
|
|
|
|
isc = 1; *dst++ = '\\'; *dst++ = 'v'; \
|
|
|
|
break; \
|
|
|
|
case '\t': \
|
|
|
|
isc = 1; *dst++ = '\\'; *dst++ = 't'; \
|
|
|
|
break; \
|
|
|
|
case '\f': \
|
|
|
|
isc = 1; *dst++ = '\\'; *dst++ = 'f'; \
|
|
|
|
break; \
|
|
|
|
case ' ': \
|
|
|
|
isc = 1; *dst++ = '\\'; *dst++ = 's'; \
|
|
|
|
break; \
|
|
|
|
case '\0': \
|
|
|
|
isc = 1; *dst++ = '\\'; *dst++ = '0'; \
|
|
|
|
if (isoctal(nextc)) { \
|
|
|
|
*dst++ = '0'; \
|
|
|
|
*dst++ = '0'; \
|
|
|
|
} \
|
|
|
|
} \
|
|
|
|
} \
|
|
|
|
if (isc) break; \
|
1999-12-07 21:20:28 +03:00
|
|
|
if (isextra || ((c & 0177) == ' ') || (flag & VIS_OCTAL)) { \
|
1999-11-29 01:51:37 +03:00
|
|
|
*dst++ = '\\'; \
|
|
|
|
*dst++ = (u_char)(((u_int32_t)(u_char)c >> 6) & 03) + '0'; \
|
|
|
|
*dst++ = (u_char)(((u_int32_t)(u_char)c >> 3) & 07) + '0'; \
|
|
|
|
*dst++ = (c & 07) + '0'; \
|
|
|
|
} else { \
|
|
|
|
if ((flag & VIS_NOSLASH) == 0) *dst++ = '\\'; \
|
|
|
|
if (c & 0200) { \
|
|
|
|
c &= 0177; *dst++ = 'M'; \
|
|
|
|
} \
|
|
|
|
if (iscntrl(c)) { \
|
|
|
|
*dst++ = '^'; \
|
|
|
|
if (c == 0177) \
|
|
|
|
*dst++ = '?'; \
|
|
|
|
else \
|
|
|
|
*dst++ = c + '@'; \
|
|
|
|
} else { \
|
|
|
|
*dst++ = '-'; *dst++ = c; \
|
|
|
|
} \
|
|
|
|
} \
|
2000-01-23 01:40:58 +03:00
|
|
|
} while (/*CONSTCOND*/0)
|
Added new functions
char *
svis(char *dst, int c, int flag, int nextc, const char *extra);
int
strsvis(char *dst, const char *src, int flag, const char *extra);
int
strsvisx(char *dst, const char *src, size_t len, int flag,
const char *extra);
These functions correspond to vis(), strvis(), and strvisx() but have an
additional argument extra, pointing to a NUL terminated list of characters.
These characters will be copied encoded or backslash-escaped into dst. These
functions are useful e. g. to remove the special meaning of certain
characters to shells.
To implement the new functions, vis underwent a major rewrite. Most functions
now use a central macro, SVIS. Performance increase ~ factor 2.
Reviewed by Christos.
1999-11-25 19:50:06 +03:00
|
|
|
|
|
|
|
|
|
|
|
/*
|
1999-12-07 21:20:28 +03:00
|
|
|
* svis - visually encode characters, also encoding the characters
|
|
|
|
* pointed to by `extra'
|
Added new functions
char *
svis(char *dst, int c, int flag, int nextc, const char *extra);
int
strsvis(char *dst, const char *src, int flag, const char *extra);
int
strsvisx(char *dst, const char *src, size_t len, int flag,
const char *extra);
These functions correspond to vis(), strvis(), and strvisx() but have an
additional argument extra, pointing to a NUL terminated list of characters.
These characters will be copied encoded or backslash-escaped into dst. These
functions are useful e. g. to remove the special meaning of certain
characters to shells.
To implement the new functions, vis underwent a major rewrite. Most functions
now use a central macro, SVIS. Performance increase ~ factor 2.
Reviewed by Christos.
1999-11-25 19:50:06 +03:00
|
|
|
*/
|
|
|
|
char *
|
|
|
|
svis(dst, c, flag, nextc, extra)
|
1999-11-29 01:51:37 +03:00
|
|
|
char *dst;
|
|
|
|
int c, flag, nextc;
|
|
|
|
const char *extra;
|
Added new functions
char *
svis(char *dst, int c, int flag, int nextc, const char *extra);
int
strsvis(char *dst, const char *src, int flag, const char *extra);
int
strsvisx(char *dst, const char *src, size_t len, int flag,
const char *extra);
These functions correspond to vis(), strvis(), and strvisx() but have an
additional argument extra, pointing to a NUL terminated list of characters.
These characters will be copied encoded or backslash-escaped into dst. These
functions are useful e. g. to remove the special meaning of certain
characters to shells.
To implement the new functions, vis underwent a major rewrite. Most functions
now use a central macro, SVIS. Performance increase ~ factor 2.
Reviewed by Christos.
1999-11-25 19:50:06 +03:00
|
|
|
{
|
2002-03-23 20:38:27 +03:00
|
|
|
char *nextra;
|
1999-11-29 01:51:37 +03:00
|
|
|
_DIAGASSERT(dst != NULL);
|
|
|
|
_DIAGASSERT(extra != NULL);
|
2002-03-23 20:38:27 +03:00
|
|
|
MAKEEXTRALIST(flag, nextra, extra);
|
|
|
|
if (flag & VIS_HTTPSTYLE)
|
|
|
|
HVIS(dst, c, flag, nextc, nextra);
|
|
|
|
else
|
|
|
|
SVIS(dst, c, flag, nextc, nextra);
|
1999-11-29 01:51:37 +03:00
|
|
|
*dst = '\0';
|
|
|
|
return(dst);
|
Added new functions
char *
svis(char *dst, int c, int flag, int nextc, const char *extra);
int
strsvis(char *dst, const char *src, int flag, const char *extra);
int
strsvisx(char *dst, const char *src, size_t len, int flag,
const char *extra);
These functions correspond to vis(), strvis(), and strvisx() but have an
additional argument extra, pointing to a NUL terminated list of characters.
These characters will be copied encoded or backslash-escaped into dst. These
functions are useful e. g. to remove the special meaning of certain
characters to shells.
To implement the new functions, vis underwent a major rewrite. Most functions
now use a central macro, SVIS. Performance increase ~ factor 2.
Reviewed by Christos.
1999-11-25 19:50:06 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
* strsvis, strsvisx - visually encode characters from src into dst
|
|
|
|
*
|
1999-11-29 01:51:37 +03:00
|
|
|
* Extra is a pointer to a \0-terminated list of characters to
|
1999-12-07 21:20:28 +03:00
|
|
|
* be encoded, too. These functions are useful e. g. to
|
|
|
|
* encode strings in such a way so that they are not interpreted
|
1999-11-29 01:51:37 +03:00
|
|
|
* by a shell.
|
|
|
|
*
|
|
|
|
* Dst must be 4 times the size of src to account for possible
|
|
|
|
* expansion. The length of dst, not including the trailing NULL,
|
|
|
|
* is returned.
|
Added new functions
char *
svis(char *dst, int c, int flag, int nextc, const char *extra);
int
strsvis(char *dst, const char *src, int flag, const char *extra);
int
strsvisx(char *dst, const char *src, size_t len, int flag,
const char *extra);
These functions correspond to vis(), strvis(), and strvisx() but have an
additional argument extra, pointing to a NUL terminated list of characters.
These characters will be copied encoded or backslash-escaped into dst. These
functions are useful e. g. to remove the special meaning of certain
characters to shells.
To implement the new functions, vis underwent a major rewrite. Most functions
now use a central macro, SVIS. Performance increase ~ factor 2.
Reviewed by Christos.
1999-11-25 19:50:06 +03:00
|
|
|
*
|
1999-11-29 01:51:37 +03:00
|
|
|
* Strsvisx encodes exactly len bytes from src into dst.
|
|
|
|
* This is useful for encoding a block of data.
|
Added new functions
char *
svis(char *dst, int c, int flag, int nextc, const char *extra);
int
strsvis(char *dst, const char *src, int flag, const char *extra);
int
strsvisx(char *dst, const char *src, size_t len, int flag,
const char *extra);
These functions correspond to vis(), strvis(), and strvisx() but have an
additional argument extra, pointing to a NUL terminated list of characters.
These characters will be copied encoded or backslash-escaped into dst. These
functions are useful e. g. to remove the special meaning of certain
characters to shells.
To implement the new functions, vis underwent a major rewrite. Most functions
now use a central macro, SVIS. Performance increase ~ factor 2.
Reviewed by Christos.
1999-11-25 19:50:06 +03:00
|
|
|
*/
|
|
|
|
int
|
|
|
|
strsvis(dst, src, flag, extra)
|
1999-11-29 01:51:37 +03:00
|
|
|
char *dst;
|
|
|
|
const char *src;
|
|
|
|
int flag;
|
|
|
|
const char *extra;
|
Added new functions
char *
svis(char *dst, int c, int flag, int nextc, const char *extra);
int
strsvis(char *dst, const char *src, int flag, const char *extra);
int
strsvisx(char *dst, const char *src, size_t len, int flag,
const char *extra);
These functions correspond to vis(), strvis(), and strvisx() but have an
additional argument extra, pointing to a NUL terminated list of characters.
These characters will be copied encoded or backslash-escaped into dst. These
functions are useful e. g. to remove the special meaning of certain
characters to shells.
To implement the new functions, vis underwent a major rewrite. Most functions
now use a central macro, SVIS. Performance increase ~ factor 2.
Reviewed by Christos.
1999-11-25 19:50:06 +03:00
|
|
|
{
|
1999-11-29 01:51:37 +03:00
|
|
|
char c;
|
|
|
|
char *start;
|
2002-03-23 20:38:27 +03:00
|
|
|
char *nextra;
|
Added new functions
char *
svis(char *dst, int c, int flag, int nextc, const char *extra);
int
strsvis(char *dst, const char *src, int flag, const char *extra);
int
strsvisx(char *dst, const char *src, size_t len, int flag,
const char *extra);
These functions correspond to vis(), strvis(), and strvisx() but have an
additional argument extra, pointing to a NUL terminated list of characters.
These characters will be copied encoded or backslash-escaped into dst. These
functions are useful e. g. to remove the special meaning of certain
characters to shells.
To implement the new functions, vis underwent a major rewrite. Most functions
now use a central macro, SVIS. Performance increase ~ factor 2.
Reviewed by Christos.
1999-11-25 19:50:06 +03:00
|
|
|
|
1999-11-29 01:51:37 +03:00
|
|
|
_DIAGASSERT(dst != NULL);
|
|
|
|
_DIAGASSERT(src != NULL);
|
|
|
|
_DIAGASSERT(extra != NULL);
|
2002-03-23 20:38:27 +03:00
|
|
|
MAKEEXTRALIST(flag, nextra, extra);
|
|
|
|
if (flag & VIS_HTTPSTYLE) {
|
|
|
|
for (start = dst; (c = *src++) != '\0'; /* empty */)
|
|
|
|
HVIS(dst, c, flag, *src, nextra);
|
|
|
|
} else {
|
|
|
|
for (start = dst; (c = *src++) != '\0'; /* empty */)
|
|
|
|
SVIS(dst, c, flag, *src, nextra);
|
|
|
|
}
|
1999-11-29 01:51:37 +03:00
|
|
|
*dst = '\0';
|
|
|
|
return (dst - start);
|
Added new functions
char *
svis(char *dst, int c, int flag, int nextc, const char *extra);
int
strsvis(char *dst, const char *src, int flag, const char *extra);
int
strsvisx(char *dst, const char *src, size_t len, int flag,
const char *extra);
These functions correspond to vis(), strvis(), and strvisx() but have an
additional argument extra, pointing to a NUL terminated list of characters.
These characters will be copied encoded or backslash-escaped into dst. These
functions are useful e. g. to remove the special meaning of certain
characters to shells.
To implement the new functions, vis underwent a major rewrite. Most functions
now use a central macro, SVIS. Performance increase ~ factor 2.
Reviewed by Christos.
1999-11-25 19:50:06 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
int
|
|
|
|
strsvisx(dst, src, len, flag, extra)
|
1999-11-29 01:51:37 +03:00
|
|
|
char *dst;
|
|
|
|
const char *src;
|
|
|
|
size_t len;
|
|
|
|
int flag;
|
|
|
|
const char *extra;
|
Added new functions
char *
svis(char *dst, int c, int flag, int nextc, const char *extra);
int
strsvis(char *dst, const char *src, int flag, const char *extra);
int
strsvisx(char *dst, const char *src, size_t len, int flag,
const char *extra);
These functions correspond to vis(), strvis(), and strvisx() but have an
additional argument extra, pointing to a NUL terminated list of characters.
These characters will be copied encoded or backslash-escaped into dst. These
functions are useful e. g. to remove the special meaning of certain
characters to shells.
To implement the new functions, vis underwent a major rewrite. Most functions
now use a central macro, SVIS. Performance increase ~ factor 2.
Reviewed by Christos.
1999-11-25 19:50:06 +03:00
|
|
|
{
|
1999-11-29 01:51:37 +03:00
|
|
|
char c;
|
|
|
|
char *start;
|
2002-03-23 20:38:27 +03:00
|
|
|
char *nextra;
|
1999-11-29 01:51:37 +03:00
|
|
|
|
|
|
|
_DIAGASSERT(dst != NULL);
|
|
|
|
_DIAGASSERT(src != NULL);
|
|
|
|
_DIAGASSERT(extra != NULL);
|
2002-03-23 20:38:27 +03:00
|
|
|
MAKEEXTRALIST(flag, nextra, extra);
|
|
|
|
|
|
|
|
if (flag & VIS_HTTPSTYLE) {
|
|
|
|
for (start = dst; len > 0; len--) {
|
|
|
|
c = *src++;
|
|
|
|
HVIS(dst, c, flag, len ? *src : '\0', nextra);
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
for (start = dst; len > 0; len--) {
|
|
|
|
c = *src++;
|
|
|
|
SVIS(dst, c, flag, len ? *src : '\0', nextra);
|
|
|
|
}
|
1999-11-29 01:51:37 +03:00
|
|
|
}
|
|
|
|
*dst = '\0';
|
|
|
|
return (dst - start);
|
Added new functions
char *
svis(char *dst, int c, int flag, int nextc, const char *extra);
int
strsvis(char *dst, const char *src, int flag, const char *extra);
int
strsvisx(char *dst, const char *src, size_t len, int flag,
const char *extra);
These functions correspond to vis(), strvis(), and strvisx() but have an
additional argument extra, pointing to a NUL terminated list of characters.
These characters will be copied encoded or backslash-escaped into dst. These
functions are useful e. g. to remove the special meaning of certain
characters to shells.
To implement the new functions, vis underwent a major rewrite. Most functions
now use a central macro, SVIS. Performance increase ~ factor 2.
Reviewed by Christos.
1999-11-25 19:50:06 +03:00
|
|
|
}
|
2002-07-03 21:18:09 +04:00
|
|
|
#endif
|
Added new functions
char *
svis(char *dst, int c, int flag, int nextc, const char *extra);
int
strsvis(char *dst, const char *src, int flag, const char *extra);
int
strsvisx(char *dst, const char *src, size_t len, int flag,
const char *extra);
These functions correspond to vis(), strvis(), and strvisx() but have an
additional argument extra, pointing to a NUL terminated list of characters.
These characters will be copied encoded or backslash-escaped into dst. These
functions are useful e. g. to remove the special meaning of certain
characters to shells.
To implement the new functions, vis underwent a major rewrite. Most functions
now use a central macro, SVIS. Performance increase ~ factor 2.
Reviewed by Christos.
1999-11-25 19:50:06 +03:00
|
|
|
|
2002-07-03 21:18:09 +04:00
|
|
|
#if !HAVE_VIS
|
1993-03-21 12:45:37 +03:00
|
|
|
/*
|
|
|
|
* vis - visually encode characters
|
|
|
|
*/
|
|
|
|
char *
|
|
|
|
vis(dst, c, flag, nextc)
|
1999-11-29 01:51:37 +03:00
|
|
|
char *dst;
|
|
|
|
int c, flag, nextc;
|
|
|
|
|
1993-03-21 12:45:37 +03:00
|
|
|
{
|
2002-03-23 20:38:27 +03:00
|
|
|
char *extra;
|
1999-09-16 15:44:54 +04:00
|
|
|
|
1999-11-29 01:51:37 +03:00
|
|
|
_DIAGASSERT(dst != NULL);
|
Added new functions
char *
svis(char *dst, int c, int flag, int nextc, const char *extra);
int
strsvis(char *dst, const char *src, int flag, const char *extra);
int
strsvisx(char *dst, const char *src, size_t len, int flag,
const char *extra);
These functions correspond to vis(), strvis(), and strvisx() but have an
additional argument extra, pointing to a NUL terminated list of characters.
These characters will be copied encoded or backslash-escaped into dst. These
functions are useful e. g. to remove the special meaning of certain
characters to shells.
To implement the new functions, vis underwent a major rewrite. Most functions
now use a central macro, SVIS. Performance increase ~ factor 2.
Reviewed by Christos.
1999-11-25 19:50:06 +03:00
|
|
|
|
2002-03-23 20:38:27 +03:00
|
|
|
MAKEEXTRALIST(flag, extra, "");
|
|
|
|
if (flag & VIS_HTTPSTYLE)
|
|
|
|
HVIS(dst, c, flag, nextc, extra);
|
|
|
|
else
|
|
|
|
SVIS(dst, c, flag, nextc, extra);
|
1999-11-29 01:51:37 +03:00
|
|
|
*dst = '\0';
|
|
|
|
return (dst);
|
1993-03-21 12:45:37 +03:00
|
|
|
}
|
|
|
|
|
Added new functions
char *
svis(char *dst, int c, int flag, int nextc, const char *extra);
int
strsvis(char *dst, const char *src, int flag, const char *extra);
int
strsvisx(char *dst, const char *src, size_t len, int flag,
const char *extra);
These functions correspond to vis(), strvis(), and strvisx() but have an
additional argument extra, pointing to a NUL terminated list of characters.
These characters will be copied encoded or backslash-escaped into dst. These
functions are useful e. g. to remove the special meaning of certain
characters to shells.
To implement the new functions, vis underwent a major rewrite. Most functions
now use a central macro, SVIS. Performance increase ~ factor 2.
Reviewed by Christos.
1999-11-25 19:50:06 +03:00
|
|
|
|
1993-03-21 12:45:37 +03:00
|
|
|
/*
|
|
|
|
* strvis, strvisx - visually encode characters from src into dst
|
1999-11-29 01:51:37 +03:00
|
|
|
*
|
|
|
|
* Dst must be 4 times the size of src to account for possible
|
|
|
|
* expansion. The length of dst, not including the trailing NULL,
|
|
|
|
* is returned.
|
1993-03-21 12:45:37 +03:00
|
|
|
*
|
1999-11-29 01:51:37 +03:00
|
|
|
* Strvisx encodes exactly len bytes from src into dst.
|
|
|
|
* This is useful for encoding a block of data.
|
1993-03-21 12:45:37 +03:00
|
|
|
*/
|
|
|
|
int
|
|
|
|
strvis(dst, src, flag)
|
1999-11-29 01:51:37 +03:00
|
|
|
char *dst;
|
|
|
|
const char *src;
|
|
|
|
int flag;
|
1993-03-21 12:45:37 +03:00
|
|
|
{
|
2002-03-23 20:38:27 +03:00
|
|
|
char *extra;
|
1999-09-16 15:44:54 +04:00
|
|
|
|
2002-03-23 20:38:27 +03:00
|
|
|
MAKEEXTRALIST(flag, extra, "");
|
1999-11-29 01:51:37 +03:00
|
|
|
return (strsvis(dst, src, flag, extra));
|
1993-03-21 12:45:37 +03:00
|
|
|
}
|
|
|
|
|
Added new functions
char *
svis(char *dst, int c, int flag, int nextc, const char *extra);
int
strsvis(char *dst, const char *src, int flag, const char *extra);
int
strsvisx(char *dst, const char *src, size_t len, int flag,
const char *extra);
These functions correspond to vis(), strvis(), and strvisx() but have an
additional argument extra, pointing to a NUL terminated list of characters.
These characters will be copied encoded or backslash-escaped into dst. These
functions are useful e. g. to remove the special meaning of certain
characters to shells.
To implement the new functions, vis underwent a major rewrite. Most functions
now use a central macro, SVIS. Performance increase ~ factor 2.
Reviewed by Christos.
1999-11-25 19:50:06 +03:00
|
|
|
|
1993-03-21 12:45:37 +03:00
|
|
|
int
|
|
|
|
strvisx(dst, src, len, flag)
|
1999-11-29 01:51:37 +03:00
|
|
|
char *dst;
|
|
|
|
const char *src;
|
|
|
|
size_t len;
|
|
|
|
int flag;
|
1993-03-21 12:45:37 +03:00
|
|
|
{
|
2002-03-23 20:38:27 +03:00
|
|
|
char *extra;
|
1993-03-21 12:45:37 +03:00
|
|
|
|
2002-03-23 20:38:27 +03:00
|
|
|
MAKEEXTRALIST(flag, extra, "");
|
1999-11-29 01:51:37 +03:00
|
|
|
return (strsvisx(dst, src, len, flag, extra));
|
1993-03-21 12:45:37 +03:00
|
|
|
}
|
2002-01-22 00:33:42 +03:00
|
|
|
#endif
|