output.c (348238dbd42306d9fb5d89ab393b840572cfeb0f) output.c (5183ddf2ed56519b669320095ed00528a71a9393)
1/*-
2 * Copyright (c) 1991, 1993
3 * The Regents of the University of California. All rights reserved.
4 *
5 * This code is derived from software contributed to Berkeley by
6 * Kenneth Almquist.
7 *
8 * Redistribution and use in source and binary forms, with or without

--- 57 unchanged lines hidden (view full) ---

66
67
68#define OUTBUFSIZ BUFSIZ
69#define MEM_OUT -2 /* output to dynamically allocated memory */
70#define OUTPUT_ERR 01 /* error occurred on output */
71
72static int doformat_wr(void *, const char *, int);
73
1/*-
2 * Copyright (c) 1991, 1993
3 * The Regents of the University of California. All rights reserved.
4 *
5 * This code is derived from software contributed to Berkeley by
6 * Kenneth Almquist.
7 *
8 * Redistribution and use in source and binary forms, with or without

--- 57 unchanged lines hidden (view full) ---

66
67
68#define OUTBUFSIZ BUFSIZ
69#define MEM_OUT -2 /* output to dynamically allocated memory */
70#define OUTPUT_ERR 01 /* error occurred on output */
71
72static int doformat_wr(void *, const char *, int);
73
74struct output output = {NULL, 0, NULL, OUTBUFSIZ, 1, 0};
75struct output errout = {NULL, 0, NULL, 256, 2, 0};
76struct output memout = {NULL, 0, NULL, 0, MEM_OUT, 0};
74struct output output = {NULL, NULL, NULL, OUTBUFSIZ, 1, 0};
75struct output errout = {NULL, NULL, NULL, 256, 2, 0};
76struct output memout = {NULL, NULL, NULL, 0, MEM_OUT, 0};
77struct output *out1 = &output;
78struct output *out2 = &errout;
79
80void
81outcslow(int c, struct output *file)
82{
83 outc(c, file);
84}

--- 124 unchanged lines hidden (view full) ---

209emptyoutbuf(struct output *dest)
210{
211 int offset;
212
213 if (dest->buf == NULL) {
214 INTOFF;
215 dest->buf = ckmalloc(dest->bufsize);
216 dest->nextc = dest->buf;
77struct output *out1 = &output;
78struct output *out2 = &errout;
79
80void
81outcslow(int c, struct output *file)
82{
83 outc(c, file);
84}

--- 124 unchanged lines hidden (view full) ---

209emptyoutbuf(struct output *dest)
210{
211 int offset;
212
213 if (dest->buf == NULL) {
214 INTOFF;
215 dest->buf = ckmalloc(dest->bufsize);
216 dest->nextc = dest->buf;
217 dest->nleft = dest->bufsize;
217 dest->bufend = dest->buf + dest->bufsize;
218 INTON;
219 } else if (dest->fd == MEM_OUT) {
218 INTON;
219 } else if (dest->fd == MEM_OUT) {
220 offset = dest->bufsize;
220 offset = dest->nextc - dest->buf;
221 INTOFF;
222 dest->bufsize <<= 1;
223 dest->buf = ckrealloc(dest->buf, dest->bufsize);
221 INTOFF;
222 dest->bufsize <<= 1;
223 dest->buf = ckrealloc(dest->buf, dest->bufsize);
224 dest->nleft = dest->bufsize - offset;
224 dest->bufend = dest->buf + dest->bufsize;
225 dest->nextc = dest->buf + offset;
226 INTON;
227 } else {
228 flushout(dest);
229 }
225 dest->nextc = dest->buf + offset;
226 INTON;
227 } else {
228 flushout(dest);
229 }
230 dest->nleft--;
231}
232
233
234void
235flushall(void)
236{
237 flushout(&output);
238 flushout(&errout);

--- 4 unchanged lines hidden (view full) ---

243flushout(struct output *dest)
244{
245
246 if (dest->buf == NULL || dest->nextc == dest->buf || dest->fd < 0)
247 return;
248 if (xwrite(dest->fd, dest->buf, dest->nextc - dest->buf) < 0)
249 dest->flags |= OUTPUT_ERR;
250 dest->nextc = dest->buf;
230}
231
232
233void
234flushall(void)
235{
236 flushout(&output);
237 flushout(&errout);

--- 4 unchanged lines hidden (view full) ---

242flushout(struct output *dest)
243{
244
245 if (dest->buf == NULL || dest->nextc == dest->buf || dest->fd < 0)
246 return;
247 if (xwrite(dest->fd, dest->buf, dest->nextc - dest->buf) < 0)
248 dest->flags |= OUTPUT_ERR;
249 dest->nextc = dest->buf;
251 dest->nleft = dest->bufsize;
252}
253
254
255void
256freestdout(void)
257{
258 INTOFF;
259 if (output.buf) {
260 ckfree(output.buf);
250}
251
252
253void
254freestdout(void)
255{
256 INTOFF;
257 if (output.buf) {
258 ckfree(output.buf);
259 output.nextc = NULL;
261 output.buf = NULL;
260 output.buf = NULL;
262 output.nleft = 0;
261 output.bufend = NULL;
263 }
264 INTON;
265}
266
267
268int
269outiserror(struct output *file)
270{

--- 105 unchanged lines hidden ---
262 }
263 INTON;
264}
265
266
267int
268outiserror(struct output *file)
269{

--- 105 unchanged lines hidden ---