Zsh Mailing List Archive
Messages sorted by:
Reverse Date,
Date,
Thread,
Author
print option fixes
- X-seq: zsh-workers 214
- From: Zefram <A.Main@xxxxxxxxxxxxxxxxx>
- To: zsh-workers@xxxxxxxxxxxxxxx (Z Shell workers mailing list)
- Subject: print option fixes
- Date: Sat, 15 Jul 1995 23:51:50 +0100 (BST)
-----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-----
Messages sorted by:
Reverse Date,
Date,
Thread,
Author