diff -u ash-0.4.0/eval.c ash-0.4.0-/eval.c --- ash-0.4.0/eval.c Tue Apr 24 00:53:12 2001 +++ ash-0.4.0-/eval.c Tue Apr 24 00:13:57 2001 @@ -879,9 +879,13 @@ #endif mode = (cmdentry.u.index == EXECCMD)? 0 : REDIR_PUSH; if (flags == EV_BACKCMD) { +#if defined(_GNU_SOURCE) && !defined(__UCLIBC__) + openmemout(); +#else memout.nleft = 0; memout.nextc = memout.buf; memout.bufsize = 64; +#endif mode |= REDIR_BACKQ; } redirect(cmd->ncmd.redirect, mode); @@ -928,10 +932,18 @@ if (cmdentry.u.index != EXECCMD) popredir(); if (flags == EV_BACKCMD) { +#if defined(_GNU_SOURCE) && !defined(__UCLIBC__) + closememout(); +#endif backcmd->buf = memout.buf; +#if defined(_GNU_SOURCE) && !defined(__UCLIBC__) + backcmd->nleft = memout.bufsize; +#else backcmd->nleft = memout.nextc - memout.buf; +#endif memout.buf = NULL; } + cmdenviron = NULL; } else { #ifdef DEBUG trputs("normal command: "); trargs(argv); Common subdirectories: ash-0.4.0/funcs and ash-0.4.0-/funcs diff -u ash-0.4.0/output.c ash-0.4.0-/output.c --- ash-0.4.0/output.c Fri Jan 12 17:50:39 2001 +++ ash-0.4.0-/output.c Tue Apr 24 00:43:44 2001 @@ -65,6 +65,10 @@ #include #include #include +#if defined(_GNU_SOURCE) && !defined(__UCLIBC__) +#undef CEOF /* get rid of the redefine warning */ +#include +#endif #include "shell.h" #include "syntax.h" @@ -79,9 +83,15 @@ #define OUTPUT_ERR 01 /* error occurred on output */ +#if defined(_GNU_SOURCE) && !defined(__UCLIBC__) +struct output output = {NULL, NULL, 0, NULL, 0, 1, 0}; +struct output errout = {NULL, NULL, 0, NULL, 0, 2, 0}; +struct output memout = {NULL, NULL, 0, NULL, 0, MEM_OUT, 0}; +#else struct output output = {NULL, 0, NULL, OUTBUFSIZ, 1, 0}; struct output errout = {NULL, 0, NULL, 100, 2, 0}; struct output memout = {NULL, 0, NULL, 0, MEM_OUT, 0}; +#endif struct output *out1 = &output; struct output *out2 = &errout; @@ -92,9 +102,19 @@ INCLUDE "output.h" INCLUDE "memalloc.h" +INIT { +#if defined(_GNU_SOURCE) && !defined(__UCLIBC__) + initstreams(); +#endif +} + RESET { out1 = &output; out2 = &errout; +#if defined(_GNU_SOURCE) && !defined(__UCLIBC__) + if (memout.stream != NULL) + closememout(); +#endif if (memout.buf != NULL) { ckfree(memout.buf); memout.buf = NULL; @@ -124,33 +144,22 @@ void -out1str(p) - const char *p; - { - outstr(p, out1); -} - - -void -out2str(p) - const char *p; - { - outstr(p, out2); -} - - -void outstr(p, file) const char *p; struct output *file; { +#if defined(_GNU_SOURCE) && !defined(__UCLIBC__) + fputs(p, file->stream); +#else while (*p) outc(*p++, file); +#endif if (file == out2) flushout(file); } +#if !defined(_GNU_SOURCE) || defined(__UCLIBC__) char out_junk[16]; @@ -183,6 +192,7 @@ } dest->nleft--; } +#endif void @@ -192,11 +202,11 @@ } +#if !defined(_GNU_SOURCE) || defined(__UCLIBC__) void flushout(dest) struct output *dest; { - if (dest->buf == NULL || dest->nextc == dest->buf || dest->fd < 0) return; if (xwrite(dest->fd, dest->buf, dest->nextc - dest->buf) < 0) @@ -204,6 +214,7 @@ dest->nextc = dest->buf; dest->nleft = dest->bufsize; } +#endif void @@ -264,6 +275,7 @@ va_end(ap); } +#if !defined(__GLIBC__) && !defined(__UCLIBC__) void #ifdef __STDC__ dprintf(const char *fmt, ...) @@ -285,6 +297,7 @@ va_end(ap); flushout(out2); } +#endif void #ifdef __STDC__ @@ -295,7 +308,9 @@ #endif { va_list ap; +#if !defined(_GNU_SOURCE) || defined(__UCLIBC__) struct output strout; +#endif #ifndef __STDC__ char *outbuf; size_t length; @@ -308,6 +323,9 @@ #else va_start(ap, fmt); #endif +#if defined(_GNU_SOURCE) && !defined(__UCLIBC__) + vsnprintf(outbuf, length, fmt, ap); +#else strout.nextc = outbuf; strout.nleft = length; strout.fd = BLOCK_OUT; @@ -316,8 +334,10 @@ outc('\0', &strout); if (strout.flags & OUTPUT_ERR) outbuf[length - 1] = '\0'; +#endif } +#if !defined(_GNU_SOURCE) || defined(__UCLIBC__) /* * Formatted output. This routine handles a subset of the printf formats: * - Formats supported: d, u, o, p, X, s, and c. @@ -534,7 +554,7 @@ } #endif /* !HAVE_VASPRINTF */ } - +#endif /* @@ -544,7 +564,7 @@ int xwrite(fd, buf, nbytes) int fd; - char *buf; + const char *buf; int nbytes; { int ntry; @@ -570,6 +590,8 @@ } + +#ifdef notdef /* * Version of ioctl that retries after a signal is caught. * XXX unused function @@ -586,3 +608,27 @@ while ((i = ioctl(fd, request, arg)) == -1 && errno == EINTR); return i; } +#endif + + +#if defined(_GNU_SOURCE) && !defined(__UCLIBC__) +void initstreams() { + output.stream = stdout; + errout.stream = stderr; +} + + +void +openmemout() { + memout.stream = open_memstream(&memout.buf, &memout.bufsize); +} + + +void +closememout() { + INTOFF; + fclose(memout.stream); + memout.stream = NULL; + INTON; +} +#endif diff -u ash-0.4.0/output.h ash-0.4.0-/output.h --- ash-0.4.0/output.h Sat Jan 31 19:28:11 1998 +++ ash-0.4.0-/output.h Tue Apr 24 00:13:57 2001 @@ -45,13 +45,19 @@ #else #include #endif +#if defined(_GNU_SOURCE) && !defined(__UCLIBC__) +#include +#endif struct output { +#if defined(_GNU_SOURCE) && !defined(__UCLIBC__) + FILE *stream; +#endif char *nextc; int nleft; char *buf; int bufsize; - short fd; + int fd; short flags; }; @@ -61,29 +67,44 @@ extern struct output *out1; extern struct output *out2; -void open_mem __P((char *, int, struct output *)); -void out1str __P((const char *)); -void out2str __P((const char *)); void outstr __P((const char *, struct output *)); +#ifndef _GNU_SOURCE void emptyoutbuf __P((struct output *)); +#endif void flushall __P((void)); +#ifndef _GNU_SOURCE void flushout __P((struct output *)); +#endif void freestdout __P((void)); void outfmt __P((struct output *, const char *, ...)) __attribute__((__format__(__printf__,2,3))); void out1fmt __P((const char *, ...)) __attribute__((__format__(__printf__,1,2))); +#if !defined(__GLIBC__) && !defined(__UCLIBC__) void dprintf __P((const char *, ...)) __attribute__((__format__(__printf__,1,2))); +#endif void fmtstr __P((char *, size_t, const char *, ...)) __attribute__((__format__(__printf__,3,4))); +#ifndef _GNU_SOURCE void doformat __P((struct output *, const char *, va_list)); -int xwrite __P((int, char *, int)); -int xioctl __P((int, unsigned long, char *)); +#endif +int xwrite __P((int, const char *, int)); +#if defined(_GNU_SOURCE) && !defined(__UCLIBC__) +void initstreams __P((void)); +void openmemout __P((void)); +void closememout __P((void)); +#define outc(c, o) putc(c, (o)->stream) +#define flushout(o) fflush((o)->stream) +#define doformat(d, f, a) vfprintf((d)->stream, f, a) +#else #define outc(c, file) (--(file)->nleft < 0? (emptyoutbuf(file), *(file)->nextc++ = (c)) : (*(file)->nextc++ = (c))) -#define out1c(c) outc(c, out1); -#define out2c(c) outc(c, out2); +#endif +#define out1c(c) outc(c, out1) +#define out2c(c) outc(c, out2) +#define out1str(s) outstr(s, out1) +#define out2str(s) outstr(s, out2) #define OUTPUT_INCL #endif