From: Zefram <A.Main@dcs.warwick.ac.uk>
To: zsh-workers@math.gatech.edu (Z Shell workers mailing list)
Subject: print option fixes
Date: Sat, 15 Jul 1995 23:51:50 +0100 (BST) [thread overview]
Message-ID: <25122.199507152251@stone.dcs.warwick.ac.uk> (raw)
-----BEGIN PGP SIGNED MESSAGE-----
The patch below makes several combinations of print options work
together. For example, previously -P was overridden by -c, even though
the two do not conflict. Similarly -D. It also fixes a bug that
stopped the -N option from working.
-zefram
*** Src/builtin.c.old Sat Jul 15 22:39:24 1995
--- Src/builtin.c Sat Jul 15 23:42:22 1995
***************
*** 4415,4424 ****
int
bin_print(char *name, char **args, char *ops, int func)
{
! int nnl = 0, fd;
Histent ent;
FILE *fout = stdout;
/* -z option -- push the arguments onto the editing buffer stack */
if (ops['z']) {
permalloc();
--- 4415,4454 ----
int
bin_print(char *name, char **args, char *ops, int func)
{
! int nnl = 0, fd, argc = arrlen(args), n;
! int *len = (int *)alloc(argc * sizeof(int));
Histent ent;
FILE *fout = stdout;
+ /* compute lengths, and interpret according to -P, -D, -e, etc. */
+ for(n = 0; n < argc; n++) {
+ /* first \ sequences */
+ if (!ops['e'] && (ops['R'] || ops['r'] || ops['E']))
+ len[n] = strlen(args[n]);
+ else
+ args[n] = getkeystring(args[n], &len[n],
+ func != BIN_ECHO && !ops['e'], &nnl);
+ /* -P option -- interpret as a prompt sequence */
+ if(ops['P']) {
+ char *arg = putprompt(args[n], &len[n], NULL, 0);
+ args[n] = (char *)alloc(len[n] + 1);
+ memcpy(args[n], arg, len[n]);
+ args[n][len[n]] = 0;
+ free(arg);
+ }
+ /* -D option -- interpret as a directory, and use ~ */
+ if(ops['D']) {
+ int dn = finddir(args[n]);
+ if(dn != -1) {
+ char *arg = alloc(strlen(args[n]) + 1);
+ sprintf(arg, "~%s%s", namdirs[dn].name,
+ args[n] + namdirs[dn].len);
+ args[n] = arg;
+ len[n] = strlen(args[n]);
+ }
+ }
+ }
+
/* -z option -- push the arguments onto the editing buffer stack */
if (ops['z']) {
permalloc();
***************
*** 4439,4446 ****
heapalloc();
return 0;
}
- if (ops['R'])
- ops['r'] = 1; /* -R implies -r */
/* -u and -p -- output to other than standard output */
if (ops['u'] || ops['p']) {
if (ops['u']) {
--- 4469,4474 ----
***************
*** 4460,4465 ****
--- 4488,4494 ----
return 1;
}
}
+
/* -o and -O -- sort the arguments */
if (ops['o']) {
if (ops['i'])
***************
*** 4474,4479 ****
--- 4503,4513 ----
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;
***************
*** 4506,4531 ****
return 0;
}
/* normal output */
! for (; *args; args++) {
! char *arg = *args;
! int len;
!
! if (!ops['e'] && (ops['r'] || ops['E']))
! len = strlen(arg);
! else
! arg = getkeystring(arg, &len, func != BIN_ECHO && !ops['e'], &nnl);
! if (ops['D'])
! fprintdir(arg, fout);
! else {
! if (ops['P'])
! arg = putprompt(arg, &len, NULL, 0);
! fwrite(arg, len, 1, fout);
! if(ops['P'])
! free(arg);
! }
!
if (args[1])
! fputc(ops['l'] ? '\n' : ops['0'] ? '\0' : ' ', fout);
}
if (!(ops['n'] || nnl))
fputc(ops['N'] ? '\0' : '\n', fout);
--- 4540,4549 ----
return 0;
}
/* normal output */
! for (; *args; args++, len++) {
! fwrite(*args, *len, 1, fout);
if (args[1])
! fputc(ops['l'] ? '\n' : ops['N'] ? '\0' : ' ', fout);
}
if (!(ops['n'] || nnl))
fputc(ops['N'] ? '\0' : '\n', fout);
-----BEGIN PGP SIGNATURE-----
Version: 2.6.i
iQBVAgUBMAhGImWJ8JfKi+e9AQHenQH/X/4e0QbuLIYZ/ASInsyzci+JA+qPlb7V
0rmv/fo0DWgpD+0NpNAeEIgt6HqGy71BDsgZcATQ6OmSAi4VSqKAxQ==
=fno6
-----END PGP SIGNATURE-----
reply other threads:[~1995-07-15 22:54 UTC|newest]
Thread overview: [no followups] expand[flat|nested] mbox.gz Atom feed
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=25122.199507152251@stone.dcs.warwick.ac.uk \
--to=a.main@dcs.warwick.ac.uk \
--cc=zsh-workers@math.gatech.edu \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
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).