]> git.pld-linux.org Git - packages/ash.git/blob - ash-memout.patch
- dropped pre-cvs changelog
[packages/ash.git] / ash-memout.patch
1 diff -u ash-0.4.0/eval.c ash-0.4.0-/eval.c
2 --- ash-0.4.0/eval.c    Tue Apr 24 00:53:12 2001
3 +++ ash-0.4.0-/eval.c   Tue Apr 24 00:13:57 2001
4 @@ -879,9 +879,13 @@
5  #endif
6                 mode = (cmdentry.u.index == EXECCMD)? 0 : REDIR_PUSH;
7                 if (flags == EV_BACKCMD) {
8 +#if defined(_GNU_SOURCE) && !defined(__UCLIBC__)
9 +                       openmemout();
10 +#else
11                         memout.nleft = 0;
12                         memout.nextc = memout.buf;
13                         memout.bufsize = 64;
14 +#endif
15                         mode |= REDIR_BACKQ;
16                 }
17                 redirect(cmd->ncmd.redirect, mode);
18 @@ -928,10 +932,18 @@
19                 if (cmdentry.u.index != EXECCMD)
20                         popredir();
21                 if (flags == EV_BACKCMD) {
22 +#if defined(_GNU_SOURCE) && !defined(__UCLIBC__)
23 +                       closememout();
24 +#endif
25                         backcmd->buf = memout.buf;
26 +#if defined(_GNU_SOURCE) && !defined(__UCLIBC__)
27 +                       backcmd->nleft = memout.bufsize;
28 +#else
29                         backcmd->nleft = memout.nextc - memout.buf;
30 +#endif
31                         memout.buf = NULL;
32                 }
33 +               cmdenviron = NULL;
34         } else {
35  #ifdef DEBUG
36                 trputs("normal command:  ");  trargs(argv);
37 Common subdirectories: ash-0.4.0/funcs and ash-0.4.0-/funcs
38 diff -u ash-0.4.0/output.c ash-0.4.0-/output.c
39 --- ash-0.4.0/output.c  Fri Jan 12 17:50:39 2001
40 +++ ash-0.4.0-/output.c Tue Apr 24 00:43:44 2001
41 @@ -65,6 +65,10 @@
42  #include <errno.h>
43  #include <unistd.h>
44  #include <stdlib.h>
45 +#if defined(_GNU_SOURCE) && !defined(__UCLIBC__)
46 +#undef CEOF                    /* get rid of the redefine warning */
47 +#include <fcntl.h>
48 +#endif
49  
50  #include "shell.h"
51  #include "syntax.h"
52 @@ -79,9 +83,15 @@
53  #define OUTPUT_ERR 01          /* error occurred on output */
54  
55  
56 +#if defined(_GNU_SOURCE) && !defined(__UCLIBC__)
57 +struct output output = {NULL, NULL, 0, NULL, 0, 1, 0};
58 +struct output errout = {NULL, NULL, 0, NULL, 0, 2, 0};
59 +struct output memout = {NULL, NULL, 0, NULL, 0, MEM_OUT, 0};
60 +#else
61  struct output output = {NULL, 0, NULL, OUTBUFSIZ, 1, 0};
62  struct output errout = {NULL, 0, NULL, 100, 2, 0};
63  struct output memout = {NULL, 0, NULL, 0, MEM_OUT, 0};
64 +#endif
65  struct output *out1 = &output;
66  struct output *out2 = &errout;
67  
68 @@ -92,9 +102,19 @@
69  INCLUDE "output.h"
70  INCLUDE "memalloc.h"
71  
72 +INIT {
73 +#if defined(_GNU_SOURCE) && !defined(__UCLIBC__)
74 +       initstreams();
75 +#endif
76 +}
77 +
78  RESET {
79         out1 = &output;
80         out2 = &errout;
81 +#if defined(_GNU_SOURCE) && !defined(__UCLIBC__)
82 +       if (memout.stream != NULL)
83 +               closememout();
84 +#endif
85         if (memout.buf != NULL) {
86                 ckfree(memout.buf);
87                 memout.buf = NULL;
88 @@ -124,33 +144,22 @@
89  
90  
91  void
92 -out1str(p)
93 -       const char *p;
94 -       {
95 -       outstr(p, out1);
96 -}
97 -
98 -
99 -void
100 -out2str(p)
101 -       const char *p;
102 -       {
103 -       outstr(p, out2);
104 -}
105 -
106 -
107 -void
108  outstr(p, file)
109         const char *p;
110         struct output *file;
111         {
112 +#if defined(_GNU_SOURCE) && !defined(__UCLIBC__)
113 +       fputs(p, file->stream);
114 +#else
115         while (*p)
116                 outc(*p++, file);
117 +#endif
118         if (file == out2)
119                 flushout(file);
120  }
121  
122  
123 +#if !defined(_GNU_SOURCE) || defined(__UCLIBC__)
124  char out_junk[16];
125  
126  
127 @@ -183,6 +192,7 @@
128         }
129         dest->nleft--;
130  }
131 +#endif
132  
133  
134  void
135 @@ -192,11 +202,11 @@
136  }
137  
138  
139 +#if !defined(_GNU_SOURCE) || defined(__UCLIBC__)
140  void
141  flushout(dest)
142         struct output *dest;
143         {
144 -
145         if (dest->buf == NULL || dest->nextc == dest->buf || dest->fd < 0)
146                 return;
147         if (xwrite(dest->fd, dest->buf, dest->nextc - dest->buf) < 0)
148 @@ -204,6 +214,7 @@
149         dest->nextc = dest->buf;
150         dest->nleft = dest->bufsize;
151  }
152 +#endif
153  
154  
155  void
156 @@ -264,6 +275,7 @@
157         va_end(ap);
158  }
159  
160 +#if !defined(__GLIBC__) && !defined(__UCLIBC__)
161  void
162  #ifdef __STDC__
163  dprintf(const char *fmt, ...)
164 @@ -285,6 +297,7 @@
165         va_end(ap);
166         flushout(out2);
167  }
168 +#endif
169  
170  void
171  #ifdef __STDC__
172 @@ -295,7 +308,9 @@
173  #endif
174  {
175         va_list ap;
176 +#if !defined(_GNU_SOURCE) || defined(__UCLIBC__)
177         struct output strout;
178 +#endif
179  #ifndef __STDC__
180         char *outbuf;
181         size_t length;
182 @@ -308,6 +323,9 @@
183  #else
184         va_start(ap, fmt);
185  #endif
186 +#if defined(_GNU_SOURCE) && !defined(__UCLIBC__)
187 +       vsnprintf(outbuf, length, fmt, ap);
188 +#else
189         strout.nextc = outbuf;
190         strout.nleft = length;
191         strout.fd = BLOCK_OUT;
192 @@ -316,8 +334,10 @@
193         outc('\0', &strout);
194         if (strout.flags & OUTPUT_ERR)
195                 outbuf[length - 1] = '\0';
196 +#endif
197  }
198  
199 +#if !defined(_GNU_SOURCE) || defined(__UCLIBC__)
200  /*
201   * Formatted output.  This routine handles a subset of the printf formats:
202   * - Formats supported: d, u, o, p, X, s, and c.
203 @@ -534,7 +554,7 @@
204         }
205  #endif /* !HAVE_VASPRINTF */
206  }
207 -
208 +#endif
209  
210  
211  /*
212 @@ -544,7 +564,7 @@
213  int
214  xwrite(fd, buf, nbytes)
215         int fd;
216 -       char *buf;
217 +       const char *buf;
218         int nbytes;
219         {
220         int ntry;
221 @@ -570,6 +590,8 @@
222  }
223  
224  
225 +
226 +#ifdef notdef
227  /*
228   * Version of ioctl that retries after a signal is caught.
229   * XXX unused function
230 @@ -586,3 +608,27 @@
231         while ((i = ioctl(fd, request, arg)) == -1 && errno == EINTR);
232         return i;
233  }
234 +#endif
235 +
236 +
237 +#if defined(_GNU_SOURCE) && !defined(__UCLIBC__)
238 +void initstreams() {
239 +       output.stream = stdout;
240 +       errout.stream = stderr;
241 +}
242 +
243 +
244 +void
245 +openmemout() {
246 +       memout.stream = open_memstream(&memout.buf, &memout.bufsize);
247 +}
248 +
249 +
250 +void
251 +closememout() {
252 +       INTOFF;
253 +       fclose(memout.stream);
254 +       memout.stream = NULL;
255 +       INTON;
256 +}
257 +#endif
258 diff -u ash-0.4.0/output.h ash-0.4.0-/output.h
259 --- ash-0.4.0/output.h  Sat Jan 31 19:28:11 1998
260 +++ ash-0.4.0-/output.h Tue Apr 24 00:13:57 2001
261 @@ -45,13 +45,19 @@
262  #else
263  #include <varargs.h>
264  #endif
265 +#if defined(_GNU_SOURCE) && !defined(__UCLIBC__)
266 +#include <stdio.h>
267 +#endif
268  
269  struct output {
270 +#if defined(_GNU_SOURCE) && !defined(__UCLIBC__)
271 +       FILE *stream;
272 +#endif
273         char *nextc;
274         int nleft;
275         char *buf;
276         int bufsize;
277 -       short fd;
278 +       int fd;
279         short flags;
280  };
281  
282 @@ -61,29 +67,44 @@
283  extern struct output *out1;
284  extern struct output *out2;
285  
286 -void open_mem __P((char *, int, struct output *));
287 -void out1str __P((const char *));
288 -void out2str __P((const char *));
289  void outstr __P((const char *, struct output *));
290 +#ifndef _GNU_SOURCE
291  void emptyoutbuf __P((struct output *));
292 +#endif
293  void flushall __P((void));
294 +#ifndef _GNU_SOURCE
295  void flushout __P((struct output *));
296 +#endif
297  void freestdout __P((void));
298  void outfmt __P((struct output *, const char *, ...))
299      __attribute__((__format__(__printf__,2,3)));
300  void out1fmt __P((const char *, ...))
301      __attribute__((__format__(__printf__,1,2)));
302 +#if !defined(__GLIBC__) && !defined(__UCLIBC__)
303  void dprintf __P((const char *, ...))
304      __attribute__((__format__(__printf__,1,2)));
305 +#endif
306  void fmtstr __P((char *, size_t, const char *, ...))
307      __attribute__((__format__(__printf__,3,4)));
308 +#ifndef _GNU_SOURCE
309  void doformat __P((struct output *, const char *, va_list));
310 -int xwrite __P((int, char *, int));
311 -int xioctl __P((int, unsigned long, char *));
312 +#endif
313 +int xwrite __P((int, const char *, int));
314 +#if defined(_GNU_SOURCE) && !defined(__UCLIBC__)
315 +void initstreams __P((void));
316 +void openmemout __P((void));
317 +void closememout __P((void));
318  
319 +#define outc(c, o)     putc(c, (o)->stream)
320 +#define flushout(o)    fflush((o)->stream)
321 +#define doformat(d, f, a)      vfprintf((d)->stream, f, a)
322 +#else
323  #define outc(c, file)  (--(file)->nleft < 0? (emptyoutbuf(file), *(file)->nextc++ = (c)) : (*(file)->nextc++ = (c)))
324 -#define out1c(c)       outc(c, out1);
325 -#define out2c(c)       outc(c, out2);
326 +#endif
327 +#define out1c(c)       outc(c, out1)
328 +#define out2c(c)       outc(c, out2)
329 +#define out1str(s)     outstr(s, out1)
330 +#define out2str(s)     outstr(s, out2)
331  
332  #define OUTPUT_INCL
333  #endif
This page took 0.166584 seconds and 3 git commands to generate.