From: Louis.Granboulan@ens.fr (Louis Granboulan)
To: zsh-workers@math.gatech.edu
Subject: Prompt escape sequences.
Date: Tue, 1 Oct 1996 19:11:33 +0200 (MET DST) [thread overview]
Message-ID: <199610011711.TAA05214@pleurote.ens.fr> (raw)
I wanted to add a new escape sequence %${varname} to print the
content of a variable. Looking at putpromptchar, I found some
bugs...
print -P %2147483648v
does a segmentation fault because 2147483648 is translated
to a negative number by zstrtol.
The patch below corrects this bug.
print -P %-%7-
outputs '%-%-' instead of '%-%7-'.
I did not correct this behaviour.
It may be easy to do.
print -P 'a\0b'
outputs 'a', since \0 ends the string.
"print 'a\0b'" does output a null character.
I did not correct this behaviour.
We may need to rewrite the whole function.
*** Src/zle_misc.c.orig Tue Aug 13 22:24:14 1996
--- Src/zle_misc.c Tue Oct 1 19:05:11 1996
***************
*** 859,865 ****
putpromptchar(int doprint, int endchar)
{
char buf3[PATH_MAX], *ss;
! int t0, arg, test, sep;
struct tm *tm;
time_t timet;
Nameddir nd;
--- 859,866 ----
putpromptchar(int doprint, int endchar)
{
char buf3[PATH_MAX], *ss;
! int t0, test, sep;
! unsigned int arg;
struct tm *tm;
time_t timet;
Nameddir nd;
***************
*** 894,909 ****
case '.':
case '~':
if ((nd = finddir(ss))) {
! arg--;
ss += strlen(nd->dir);
}
case '/':
case 'C':
for (; *ss; ss++)
if (*ss == '/')
! arg--;
! if (arg <= 0)
! test = 1;
break;
case 't':
case 'T':
--- 895,909 ----
case '.':
case '~':
if ((nd = finddir(ss))) {
! test++;
ss += strlen(nd->dir);
}
case '/':
case 'C':
for (; *ss; ss++)
if (*ss == '/')
! test++;
! test = (arg <= test);
break;
case 't':
case 'T':
***************
*** 1230,1235 ****
--- 1230,1262 ----
addbufspc(1);
*bp++ = (geteuid())? '%' : '#';
break;
+ case '$':
+ if (fm[1] != '{') {
+ *bp++ = '%';
+ *bp++ = '$';
+ break;
+ }
+ else {
+ char **array, *variable, endname;
+ fm++; variable = fm+1;
+ while (*fm && *fm != '}') fm++;
+ /* We don't need to allocate something for the var name */
+ endname = *fm;
+ *fm = NULL;
+ if (arg) {
+ array = getaparam(variable);
+ variable = NULL;
+ if ( array && (arrlen(array) >= arg) )
+ variable = array[arg-1];
+ }
+ else
+ variable = getsparam(variable);
+ stradd(variable ? variable : "");
+ *fm = endname;
+ }
+ if(!*fm)
+ return 0;
+ break;
case 'v':
if (!arg)
arg = 1;
***************
*** 1241,1247 ****
break;
case '_':
if (cmdsp) {
! if (arg > cmdsp || arg <= 0)
arg = cmdsp;
for (t0 = cmdsp - arg; arg--; t0++) {
stradd(cmdnames[cmdstack[t0]]);
--- 1268,1274 ----
break;
case '_':
if (cmdsp) {
! if (arg > cmdsp || !arg)
arg = cmdsp;
for (t0 = cmdsp - arg; arg--; t0++) {
stradd(cmdnames[cmdstack[t0]]);
*** Doc/zshparam.man.orig Tue Aug 13 22:24:13 1996
--- Doc/zshparam.man Tue Oct 1 19:05:08 1996
***************
*** 579,584 ****
--- 579,589 ----
The value of the first element of the $psvar array parameter. Following
the '%' with an integer gives that element of the array.
.TP
+ .B %${\fIvarname\fB}
+ The value of the variable $varname.
+ Following the '%' with an integer gives that element of the array.
+ Using the $psvar array is faster.
+ .TP
\fB%{\fP...\fB%}\fP
Include a string as a literal escape sequence.
The string within the braces should not change the cursor
*** Doc/zsh.texi.orig Thu Aug 15 18:47:39 1996
--- Doc/zsh.texi Tue Oct 1 19:09:00 1996
***************
*** 4144,4149 ****
--- 4144,4154 ----
Following the @code{%} with an integer gives that element of the
array.
+ @item %$@{@var{varname}@}
+ The value of the variable @code{varname}.
+ Following the @code{%} with an integer gives that element of the array.
+ Using the $psvar array is faster.
+
@item %@{@dots{}%@}
Include a string as a literal escape sequence. The string within the
braces should not change the cursor position.
next reply other threads:[~1996-10-01 17:38 UTC|newest]
Thread overview: 5+ messages / expand[flat|nested] mbox.gz Atom feed top
1996-10-01 17:11 Louis Granboulan [this message]
1996-10-02 23:18 ` Zoltan Hidvegi
1996-10-03 6:09 ` Richard Coleman
[not found] <20071008034223.GA789@primenet.com.au>
[not found] ` <071007210217.ZM24374@torch.brasslantern.com>
[not found] ` <20071008042759.GA2413@primenet.com.au>
2007-10-08 15:44 ` PROMPT " Bart Schaefer
2007-10-09 3:23 ` Geoff Wing
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=199610011711.TAA05214@pleurote.ens.fr \
--to=louis.granboulan@ens.fr \
--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).