11556Srgrimes/*- 21556Srgrimes * Copyright (c) 1991, 1993 31556Srgrimes * The Regents of the University of California. All rights reserved. 41556Srgrimes * 51556Srgrimes * This code is derived from software contributed to Berkeley by 61556Srgrimes * Kenneth Almquist. 71556Srgrimes * 81556Srgrimes * Redistribution and use in source and binary forms, with or without 91556Srgrimes * modification, are permitted provided that the following conditions 101556Srgrimes * are met: 111556Srgrimes * 1. Redistributions of source code must retain the above copyright 121556Srgrimes * notice, this list of conditions and the following disclaimer. 131556Srgrimes * 2. Redistributions in binary form must reproduce the above copyright 141556Srgrimes * notice, this list of conditions and the following disclaimer in the 151556Srgrimes * documentation and/or other materials provided with the distribution. 161556Srgrimes * 4. Neither the name of the University nor the names of its contributors 171556Srgrimes * may be used to endorse or promote products derived from this software 181556Srgrimes * without specific prior written permission. 191556Srgrimes * 201556Srgrimes * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND 211556Srgrimes * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 221556Srgrimes * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 231556Srgrimes * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE 241556Srgrimes * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 251556Srgrimes * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 261556Srgrimes * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 271556Srgrimes * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 281556Srgrimes * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 291556Srgrimes * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 301556Srgrimes * SUCH DAMAGE. 311556Srgrimes * 3217987Speter * @(#)output.h 8.2 (Berkeley) 5/4/95 3350471Speter * $FreeBSD$ 341556Srgrimes */ 351556Srgrimes 361556Srgrimes#ifndef OUTPUT_INCL 371556Srgrimes 3817987Speter#include <stdarg.h> 39215303Sjilles#include <stddef.h> 4017987Speter 411556Srgrimesstruct output { 421556Srgrimes char *nextc; 431556Srgrimes int nleft; 441556Srgrimes char *buf; 451556Srgrimes int bufsize; 461556Srgrimes short fd; 471556Srgrimes short flags; 481556Srgrimes}; 491556Srgrimes 50201366Sjillesextern struct output output; /* to fd 1 */ 51201366Sjillesextern struct output errout; /* to fd 2 */ 521556Srgrimesextern struct output memout; 53201366Sjillesextern struct output *out1; /* &memout if backquote, otherwise &output */ 54201366Sjillesextern struct output *out2; /* &memout if backquote with 2>&1, otherwise 55201366Sjilles &errout */ 561556Srgrimes 57215567Sjillesvoid outcslow(int, struct output *); 5890111Simpvoid out1str(const char *); 5997817Stjrvoid out1qstr(const char *); 6090111Simpvoid out2str(const char *); 6197817Stjrvoid out2qstr(const char *); 6290111Simpvoid outstr(const char *, struct output *); 6397817Stjrvoid outqstr(const char *, struct output *); 64215303Sjillesvoid outbin(const void *, size_t, struct output *); 6590111Simpvoid emptyoutbuf(struct output *); 6690111Simpvoid flushall(void); 6790111Simpvoid flushout(struct output *); 6890111Simpvoid freestdout(void); 6990111Simpvoid outfmt(struct output *, const char *, ...) __printflike(2, 3); 7090111Simpvoid out1fmt(const char *, ...) __printflike(1, 2); 71199629Sjillesvoid out2fmt_flush(const char *, ...) __printflike(1, 2); 7290111Simpvoid fmtstr(char *, int, const char *, ...) __printflike(3, 4); 7390111Simpvoid doformat(struct output *, const char *, va_list) __printflike(2, 0); 74200956Sjillesint xwrite(int, const char *, int); 751556Srgrimes 761556Srgrimes#define outc(c, file) (--(file)->nleft < 0? (emptyoutbuf(file), *(file)->nextc++ = (c)) : (*(file)->nextc++ = (c))) 771556Srgrimes#define out1c(c) outc(c, out1); 78215567Sjilles#define out2c(c) outcslow(c, out2); 791556Srgrimes 801556Srgrimes#define OUTPUT_INCL 811556Srgrimes#endif 82