1139743Simp/*- 243412Snewton * Copyright (c) 1991, 1993 343412Snewton * The Regents of the University of California. All rights reserved. 443412Snewton * 543412Snewton * This code is derived from software contributed to Berkeley by 643412Snewton * Kenneth Almquist. 743412Snewton * 843412Snewton * Redistribution and use in source and binary forms, with or without 943412Snewton * modification, are permitted provided that the following conditions 1043412Snewton * are met: 1143412Snewton * 1. Redistributions of source code must retain the above copyright 1243412Snewton * notice, this list of conditions and the following disclaimer. 1343412Snewton * 2. Redistributions in binary form must reproduce the above copyright 1443412Snewton * notice, this list of conditions and the following disclaimer in the 1543412Snewton * documentation and/or other materials provided with the distribution. 1643412Snewton * 4. Neither the name of the University nor the names of its contributors 1743412Snewton * may be used to endorse or promote products derived from this software 1843412Snewton * without specific prior written permission. 1943412Snewton * 2043412Snewton * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND 2143412Snewton * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 2243412Snewton * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 2343412Snewton * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE 2443412Snewton * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 2543412Snewton * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 2643412Snewton * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 2749267Snewton * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 2850477Speter * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 2943412Snewton * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 3043412Snewton * SUCH DAMAGE. 3143412Snewton * 3243412Snewton * @(#)output.h 8.2 (Berkeley) 5/4/95 3343412Snewton * $FreeBSD: releng/10.2/bin/sh/output.h 244162 2012-12-12 22:01:10Z jilles $ 3443412Snewton */ 3543412Snewton 3643412Snewton#ifndef OUTPUT_INCL 3743412Snewton 3843412Snewton#include <stdarg.h> 3943412Snewton#include <stddef.h> 4043412Snewton 4143412Snewtonstruct output { 42141486Sjhb char *nextc; 4343412Snewton int nleft; 4443412Snewton char *buf; 45150663Srwatson int bufsize; 4643412Snewton short fd; 4743412Snewton short flags; 4843412Snewton}; 4943412Snewton 5043412Snewtonextern struct output output; /* to fd 1 */ 5143412Snewtonextern struct output errout; /* to fd 2 */ 5243412Snewtonextern struct output memout; 5343412Snewtonextern struct output *out1; /* &memout if backquote, otherwise &output */ 5443412Snewtonextern struct output *out2; /* &memout if backquote with 2>&1, otherwise 5543412Snewton &errout */ 5643412Snewton 5783366Sjulianvoid outcslow(int, struct output *); 5843412Snewtonvoid out1str(const char *); 5943412Snewtonvoid out1qstr(const char *); 6043412Snewtonvoid out2str(const char *); 6143412Snewtonvoid out2qstr(const char *); 6243412Snewtonvoid outstr(const char *, struct output *); 6343412Snewtonvoid outqstr(const char *, struct output *); 6443412Snewtonvoid outbin(const void *, size_t, struct output *); 6543412Snewtonvoid emptyoutbuf(struct output *); 6643412Snewtonvoid flushall(void); 67121275Stjrvoid flushout(struct output *); 68121275Stjrvoid freestdout(void); 69121275Stjrint outiserror(struct output *); 70121275Stjrvoid outclearerror(struct output *); 7143412Snewtonvoid outfmt(struct output *, const char *, ...) __printflike(2, 3); 7243412Snewtonvoid out1fmt(const char *, ...) __printflike(1, 2); 7343412Snewtonvoid out2fmt_flush(const char *, ...) __printflike(1, 2); 74141486Sjhbvoid fmtstr(char *, int, const char *, ...) __printflike(3, 4); 7543412Snewtonvoid doformat(struct output *, const char *, va_list) __printflike(2, 0); 76141486Sjhbint xwrite(int, const char *, int); 7749770Snewton 7849770Snewton#define outc(c, file) (--(file)->nleft < 0? (emptyoutbuf(file), *(file)->nextc++ = (c)) : (*(file)->nextc++ = (c))) 7949770Snewton#define out1c(c) outc(c, out1); 80141486Sjhb#define out2c(c) outcslow(c, out2); 81141486Sjhb 8249770Snewton#define OUTPUT_INCL 8349770Snewton#endif 8443412Snewton