* PATCH: print -f with -s/-z
@ 2002-03-19 14:21 Oliver Kiddle
2002-03-21 18:39 ` Borsenkow Andrej
0 siblings, 1 reply; 3+ messages in thread
From: Oliver Kiddle @ 2002-03-19 14:21 UTC (permalink / raw)
To: zsh-workers
This patch is basically the same as 16259 except that I've sorted
out those things which held me back from committing it before
(open_memstream prototype and use of gettempname()).
Oliver
Index: zshconfig.ac
===================================================================
RCS file: /cvsroot/zsh/zsh/zshconfig.ac,v
retrieving revision 1.25
diff -u -r1.25 zshconfig.ac
--- zshconfig.ac 19 Feb 2002 02:14:08 -0000 1.25
+++ zshconfig.ac 19 Mar 2002 14:12:35 -0000
@@ -951,7 +951,7 @@
tgetent tigetflag tigetnum tigetstr setupterm \
pcre_compile pcre_study pcre_exec \
nl_langinfo \
- erand48)
+ erand48 open_memstream)
AC_FUNC_STRCOLL
dnl Check if tgetent accepts NULL (and will allocate its own termcap buffer)
Index: Src/builtin.c
===================================================================
RCS file: /cvsroot/zsh/zsh/Src/builtin.c,v
retrieving revision 1.71
diff -u -r1.71 builtin.c
--- Src/builtin.c 4 Mar 2002 15:52:00 -0000 1.71
+++ Src/builtin.c 19 Mar 2002 14:12:35 -0000
@@ -27,6 +27,9 @@
*
*/
+/* this is defined so we get the prototype for open_memstream */
+#define _GNU_SOURCE 1
+
#include "zsh.mdh"
#include "builtin.pro"
@@ -2909,10 +2912,11 @@
int flen, width, prec, type, argc, n, narg;
int nnl = 0, ret = 0, maxarg = 0;
int flags[5], *len;
- char *start, *endptr, *c, *d, *flag, spec[11], *fmt = NULL;
+ char *start, *endptr, *c, *d, *flag, *buf, *tmpf, spec[11], *fmt = NULL;
char **first, *curarg, *flagch = "0+- #", save = '\0', nullstr = '\0';
- zlong count;
+ size_t rcount, mcount, count = 0;
FILE *fout = stdout;
+ Histent ent;
mnumber mnumval;
double doubleval;
@@ -2984,61 +2988,6 @@
}
}
- /* -o and -O -- sort the arguments */
- if (ops['o']) {
- if (fmt && !*args) return 0;
- if (ops['i'])
- qsort(args, arrlen(args), sizeof(char *), cstrpcmp);
- else
- qsort(args, arrlen(args), sizeof(char *), strpcmp);
- } else if (ops['O']) {
- if (fmt && !*args) return 0;
- if (ops['i'])
- qsort(args, arrlen(args), sizeof(char *), invcstrpcmp);
- else
- qsort(args, arrlen(args), sizeof(char *), invstrpcmp);
- }
- /* after sorting arguments, recalculate lengths */
- if(ops['o'] || ops['O'])
- for(n = 0; n < argc; n++)
- len[n] = strlen(args[n]);
-
- /* -z option -- push the arguments onto the editing buffer stack */
- if (ops['z']) {
- queue_signals();
- zpushnode(bufstack, sepjoin(args, NULL, 0));
- unqueue_signals();
- return 0;
- }
- /* -s option -- add the arguments to the history list */
- if (ops['s']) {
- int nwords = 0, nlen, iwords;
- char **pargs = args;
- Histent ent;
-
- queue_signals();
- ent = prepnexthistent();
- while (*pargs++)
- nwords++;
- if ((ent->nwords = nwords)) {
- ent->words = (short *)zalloc(nwords*2*sizeof(short));
- nlen = iwords = 0;
- for (pargs = args; *pargs; pargs++) {
- ent->words[iwords++] = nlen;
- nlen += strlen(*pargs);
- ent->words[iwords++] = nlen;
- nlen++;
- }
- } else
- ent->words = (short *)NULL;
- ent->text = zjoin(args, ' ', 0);
- ent->stim = ent->ftim = time(NULL);
- ent->flags = 0;
- addhistnode(histtab, ent->text, ent);
- unqueue_signals();
- return 0;
- }
-
/* -u and -p -- output to other than standard output */
if (ops['u'] || ops['p']) {
int fd;
@@ -3061,6 +3010,25 @@
}
}
+ /* -o and -O -- sort the arguments */
+ if (ops['o']) {
+ if (fmt && !*args) return 0;
+ if (ops['i'])
+ qsort(args, arrlen(args), sizeof(char *), cstrpcmp);
+ else
+ qsort(args, arrlen(args), sizeof(char *), strpcmp);
+ } else if (ops['O']) {
+ if (fmt && !*args) return 0;
+ if (ops['i'])
+ qsort(args, arrlen(args), sizeof(char *), invcstrpcmp);
+ else
+ qsort(args, arrlen(args), sizeof(char *), invstrpcmp);
+ }
+ /* after sorting arguments, recalculate lengths */
+ if(ops['o'] || ops['O'])
+ for(n = 0; n < argc; n++)
+ len[n] = strlen(args[n]);
+
/* -c -- output in columns */
if (ops['c']) {
int l, nc, nr, sc, n, t, i;
@@ -3099,6 +3067,41 @@
/* normal output */
if (!fmt) {
+ /* -z option -- push the arguments onto the editing buffer stack */
+ if (ops['z']) {
+ queue_signals();
+ zpushnode(bufstack, sepjoin(args, NULL, 0));
+ unqueue_signals();
+ return 0;
+ }
+ /* -s option -- add the arguments to the history list */
+ if (ops['s']) {
+ int nwords = 0, nlen, iwords;
+ char **pargs = args;
+
+ queue_signals();
+ ent = prepnexthistent();
+ while (*pargs++)
+ nwords++;
+ if ((ent->nwords = nwords)) {
+ ent->words = (short *)zalloc(nwords*2*sizeof(short));
+ nlen = iwords = 0;
+ for (pargs = args; *pargs; pargs++) {
+ ent->words[iwords++] = nlen;
+ nlen += strlen(*pargs);
+ ent->words[iwords++] = nlen;
+ nlen++;
+ }
+ } else
+ ent->words = (short *)NULL;
+ ent->text = zjoin(args, ' ', 0);
+ ent->stim = ent->ftim = time(NULL);
+ ent->flags = 0;
+ addhistnode(histtab, ent->text, ent);
+ unqueue_signals();
+ return 0;
+ }
+
for (; *args; args++, len++) {
fwrite(*args, *len, 1, fout);
if (args[1])
@@ -3115,10 +3118,22 @@
return ret;
}
+ if (ops['z'] || ops['s']) {
+#ifdef HAVE_OPEN_MEMSTREAM
+ if ((fout = open_memstream(&buf, &mcount)) == NULL)
+ zwarnnam(name, "open_memstream failed", NULL, 0);
+#else
+ tmpf = gettempname();
+ if ((fout = fopen(tmpf, "w+")) == NULL)
+ zwarnnam(name, "can't open temp file: %e", NULL, errno);
+ unlink(tmpf);
+#endif
+ }
+
/* printf style output */
*spec='%';
do {
- count = 0;
+ rcount = count;
if (maxarg) {
first += maxarg;
argc -= maxarg;
@@ -3287,7 +3302,7 @@
type=3;
break;
case 'n':
- if (curarg) setiparam(curarg, count);
+ if (curarg) setiparam(curarg, count - rcount);
break;
default:
if (*c) {
@@ -3363,6 +3378,31 @@
if (maxarg) args = first + maxarg;
/* if there are remaining args, reuse format string */
} while (*args && args != first && !ops['r']);
+
+ if (ops['z'] || ops['s']) {
+#ifdef HAVE_OPEN_MEMSTREAM
+ putc(0, fout);
+ fflush(fout);
+ count = mcount;
+#else
+ rewind(fout);
+ buf = (char *)zalloc(count + 1);
+ fread(buf, count, 1, fout);
+ buf[count] = '\0';
+#endif
+ queue_signals();
+ if (ops['z']) {
+ zpushnode(bufstack, buf);
+ } else {
+ ent = prepnexthistent();
+ ent->text = buf;
+ ent->stim = ent->ftim = time(NULL);
+ ent->flags = 0;
+ ent->words = (short *)NULL;
+ addhistnode(histtab, ent->text, ent);
+ }
+ unqueue_signals();
+ }
/* Testing EBADF special-cases >&- redirections */
if ((fout != stdout) ? (fclose(fout) != 0) :
--
This e-mail and any attachment is for authorised use by the intended recipient(s) only. It may contain proprietary material, confidential information and/or be subject to legal privilege. It should not be copied, disclosed to, retained or used by, any other party. If you are not an intended recipient then please promptly delete this e-mail and any attachment and all copies and inform the sender. Thank you.
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: PATCH: print -f with -s/-z
2002-03-19 14:21 PATCH: print -f with -s/-z Oliver Kiddle
@ 2002-03-21 18:39 ` Borsenkow Andrej
2002-03-22 11:45 ` Oliver Kiddle
0 siblings, 1 reply; 3+ messages in thread
From: Borsenkow Andrej @ 2002-03-21 18:39 UTC (permalink / raw)
To: Oliver Kiddle; +Cc: Zsh hackers list
В Втр, 19.03.2002, в 17:21, Oliver Kiddle написал:
> This patch is basically the same as 16259 except that I've sorted
> out those things which held me back from committing it before
> (open_memstream prototype and use of gettempname()).
>
...
> Index: Src/builtin.c
> ===================================================================
> RCS file: /cvsroot/zsh/zsh/Src/builtin.c,v
> retrieving revision 1.71
> diff -u -r1.71 builtin.c
> --- Src/builtin.c 4 Mar 2002 15:52:00 -0000 1.71
> +++ Src/builtin.c 19 Mar 2002 14:12:35 -0000
> @@ -27,6 +27,9 @@
> *
> */
>
> +/* this is defined so we get the prototype for open_memstream */
> +#define _GNU_SOURCE 1
> +
It is a bit weird to define it unconditionally even on a system that has
nothing to do with GNU.
If some extra steps are needed to pull in prototype for open_memstream I
prefer configure to test for them instead.
-andrej
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: PATCH: print -f with -s/-z
2002-03-21 18:39 ` Borsenkow Andrej
@ 2002-03-22 11:45 ` Oliver Kiddle
0 siblings, 0 replies; 3+ messages in thread
From: Oliver Kiddle @ 2002-03-22 11:45 UTC (permalink / raw)
To: Borsenkow Andrej; +Cc: Zsh hackers list
On Thu, Mar 21, 2002 at 09:39:03PM +0300, Borsenkow Andrej wrote:
> >
> > +/* this is defined so we get the prototype for open_memstream */
> > +#define _GNU_SOURCE 1
> > +
>
> It is a bit weird to define it unconditionally even on a system that has
> nothing to do with GNU.
>
> If some extra steps are needed to pull in prototype for open_memstream I
> prefer configure to test for them instead.
I could put #ifdef HAVE_OPEN_MEMSTREAM around it if that would be less
weird? I'd have thought that _GNU_SOURCE was going to be ignored on
any non-GNU system and so would be harmless.
That define is the only step I know of for pulling in the prototype
(other than explicitly writing the prototype) and I can't think how
any configure test could more directly test for it.
Oliver
This e-mail and any attachment is for authorised use by the intended recipient(s) only. It may contain proprietary material, confidential information and/or be subject to legal privilege. It should not be copied, disclosed to, retained or used by, any other party. If you are not an intended recipient then please promptly delete this e-mail and any attachment and all copies and inform the sender. Thank you.
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2002-03-22 11:46 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2002-03-19 14:21 PATCH: print -f with -s/-z Oliver Kiddle
2002-03-21 18:39 ` Borsenkow Andrej
2002-03-22 11:45 ` Oliver Kiddle
Code repositories for project(s) associated with this public inbox
https://git.vuxu.org/mirror/zsh/
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).