1153486Sphk/*- 2153486Sphk * Copyright (c) 2005 Poul-Henning Kamp 3153486Sphk * All rights reserved. 4153486Sphk * 5153486Sphk * Redistribution and use in source and binary forms, with or without 6153486Sphk * modification, are permitted provided that the following conditions 7153486Sphk * are met: 8153486Sphk * 1. Redistributions of source code must retain the above copyright 9153486Sphk * notice, this list of conditions and the following disclaimer. 10153486Sphk * 2. Redistributions in binary form must reproduce the above copyright 11153486Sphk * notice, this list of conditions and the following disclaimer in the 12153486Sphk * documentation and/or other materials provided with the distribution. 13153486Sphk * 14153486Sphk * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND 15153486Sphk * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 16153486Sphk * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 17153486Sphk * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE 18153486Sphk * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 19153486Sphk * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 20153486Sphk * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 21153486Sphk * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 22153486Sphk * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 23153486Sphk * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 24153486Sphk * SUCH DAMAGE. 25153486Sphk * 26153486Sphk * $FreeBSD$ 27153486Sphk */ 28153486Sphk 29153486Sphk#include <namespace.h> 30153486Sphk#include <stdio.h> 31153486Sphk#include <string.h> 32153486Sphk#include <stdlib.h> 33153486Sphk#include <wchar.h> 34153486Sphk#include <vis.h> 35153486Sphk#include <assert.h> 36153486Sphk#include <sys/time.h> 37153486Sphk#include "printf.h" 38153486Sphk 39153486Sphkint 40153486Sphk__printf_arginfo_vis(const struct printf_info *pi, size_t n, int *argt) 41153486Sphk{ 42153486Sphk 43153486Sphk assert(n >= 1); 44153486Sphk argt[0] = PA_POINTER; 45153486Sphk return (1); 46153486Sphk} 47153486Sphk 48153486Sphkint 49153486Sphk__printf_render_vis(struct __printf_io *io, const struct printf_info *pi, const void *const *arg) 50153486Sphk{ 51153486Sphk char *p, *buf; 52153486Sphk unsigned l; 53153486Sphk int ret; 54153486Sphk 55153486Sphk ret = 0; 56153486Sphk p = *((char **)arg[0]); 57154815Sphk if (p == NULL) 58154815Sphk return (__printf_out(io, pi, "(null)", 6)); 59153486Sphk if (pi->prec >= 0) 60153486Sphk l = pi->prec; 61153486Sphk else 62153486Sphk l = strlen(p); 63153486Sphk buf = malloc(l * 4 + 1); 64153486Sphk if (buf == NULL) 65153486Sphk return (-1); 66153486Sphk if (pi->showsign) 67153486Sphk ret = strvisx(buf, p, l, VIS_WHITE | VIS_HTTPSTYLE); 68153486Sphk else if (pi->pad == '0') 69153486Sphk ret = strvisx(buf, p, l, VIS_WHITE | VIS_OCTAL); 70153486Sphk else if (pi->alt) 71153486Sphk ret = strvisx(buf, p, l, VIS_WHITE); 72153486Sphk else 73153486Sphk ret = strvisx(buf, p, l, VIS_WHITE | VIS_CSTYLE | VIS_OCTAL); 74153486Sphk ret += __printf_out(io, pi, buf, ret); 75153486Sphk __printf_flush(io); 76153486Sphk free(buf); 77153486Sphk return(ret); 78153486Sphk} 79