From: Zoltan Hidvegi <hzoli@cs.elte.hu>
To: zsh-workers@math.gatech.edu (Zsh hacking and development)
Subject: PATCH: read builtin cleanup
Date: Fri, 8 May 1998 01:10:58 -0500 (CDT) [thread overview]
Message-ID: <199805080611.BAA02528@hzoli.home> (raw)
This patch does some cleanup in the read builtin and adds proper handling
of backslashes which should escape whithespaces and backslashes.
Zoli
*** Src/builtin.c 1997/06/16 05:11:38 3.1.3.1
--- Src/builtin.c 1997/07/13 05:21:43 3.1.3.2
*************** int
*** 2718,2724 ****
bin_read(char *name, char **args, char *ops, int func)
{
char *reply, *readpmpt;
! int bsiz, c = 0, gotnl = 0, al = 0, first, nchars = 1;
int haso = 0; /* true if /dev/tty has been opened specially */
int isem = !strcmp(term, "emacs");
char *buf, *bptr, *firstarg, *zbuforig;
--- 2718,2724 ----
bin_read(char *name, char **args, char *ops, int func)
{
char *reply, *readpmpt;
! int bsiz, c = 0, gotnl = 0, al = 0, first, nchars = 1, bslash;
int haso = 0; /* true if /dev/tty has been opened specially */
int isem = !strcmp(term, "emacs");
char *buf, *bptr, *firstarg, *zbuforig;
*************** bin_read(char *name, char **args, char *
*** 2767,2793 ****
} else if (ops['u'] && !ops['p']) {
/* -u means take input from the specified file descriptor. *
* -up means take input from the coprocess. */
! for (readfd = 0; readfd < 10; ++readfd)
! if (ops[readfd + '0'])
! break;
! if (readfd == 10)
! readfd = 0;
} else if (ops['p'])
readfd = coprocin;
! else {
! /* last resort: take input from plain old stdin */
! attachtty((jobtab[thisjob].gleader) ? jobtab[thisjob].gleader : mypgrp);
readfd = 0;
! #if 0
! else if (isset(SHINSTDIN) && unset(INTERACTIVE)) {
! /* use stdout or stderr, if either is a tty */
! if (isatty(1))
! readfd = 1;
! else if (isatty(2))
! readfd = 2;
! }
! #endif
! }
/* handle prompt */
if (firstarg) {
for (readpmpt = firstarg;
--- 2767,2778 ----
} else if (ops['u'] && !ops['p']) {
/* -u means take input from the specified file descriptor. *
* -up means take input from the coprocess. */
! for (readfd = 9; readfd && !ops[readfd + '0']; --readfd);
} else if (ops['p'])
readfd = coprocin;
! else
readfd = 0;
!
/* handle prompt */
if (firstarg) {
for (readpmpt = firstarg;
*************** bin_read(char *name, char **args, char *
*** 2874,2895 ****
zbuforig = zbuf = (!ops['z']) ? NULL :
(nonempty(bufstack)) ? (char *) getlinknode(bufstack) : ztrdup("");
first = 1;
while (*args || (ops['A'] && !gotnl)) {
buf = bptr = (char *)zalloc(bsiz = 64);
/* get input, a character at a time */
! for (;;) {
! if (gotnl)
! break;
c = zread();
/* \ at the end of a line indicates a continuation *
* line, except in raw mode (-r option) */
! if (!ops['r'] && c == '\n' && bptr != buf && bptr[-1] == '\\') {
! bptr--;
continue;
}
if (c == EOF || c == '\n')
break;
! if (isep(c)) {
if (bptr != buf || (!iwsep(c) && first)) {
first |= !iwsep(c);
break;
--- 2859,2879 ----
zbuforig = zbuf = (!ops['z']) ? NULL :
(nonempty(bufstack)) ? (char *) getlinknode(bufstack) : ztrdup("");
first = 1;
+ bslash = 0;
while (*args || (ops['A'] && !gotnl)) {
buf = bptr = (char *)zalloc(bsiz = 64);
/* get input, a character at a time */
! while (!gotnl) {
c = zread();
/* \ at the end of a line indicates a continuation *
* line, except in raw mode (-r option) */
! if (bslash && c == '\n') {
! bslash = 0;
continue;
}
if (c == EOF || c == '\n')
break;
! if (!bslash && isep(c)) {
if (bptr != buf || (!iwsep(c) && first)) {
first |= !iwsep(c);
break;
*************** bin_read(char *name, char **args, char *
*** 2897,2902 ****
--- 2881,2889 ----
first |= !iwsep(c);
continue;
}
+ bslash = c == '\\' && !bslash && !ops['r'];
+ if (bslash)
+ continue;
first = 0;
if (imeta(c)) {
*bptr++ = Meta;
*************** bin_read(char *name, char **args, char *
*** 2964,2987 ****
}
buf = bptr = (char *)zalloc(bsiz = 64);
/* any remaining part of the line goes into one parameter */
if (!gotnl)
for (;;) {
c = zread();
/* \ at the end of a line introduces a continuation line, except in
raw mode (-r option) */
! if (!ops['r'] && c == '\n' && bptr != buf && bptr[-1] == '\\') {
! bptr--;
continue;
}
if (c == EOF || (c == '\n' && !zbuf))
break;
! if (isep(c) && bptr == buf)
if (iwsep(c))
continue;
else if (!first) {
first = 1;
continue;
}
if (imeta(c)) {
*bptr++ = Meta;
*bptr++ = c ^ 32;
--- 2951,2978 ----
}
buf = bptr = (char *)zalloc(bsiz = 64);
/* any remaining part of the line goes into one parameter */
+ bslash = 0;
if (!gotnl)
for (;;) {
c = zread();
/* \ at the end of a line introduces a continuation line, except in
raw mode (-r option) */
! if (bslash && c == '\n') {
! bslash = 0;
continue;
}
if (c == EOF || (c == '\n' && !zbuf))
break;
! if (!bslash && isep(c) && bptr == buf)
if (iwsep(c))
continue;
else if (!first) {
first = 1;
continue;
}
+ bslash = c == '\\' && !bslash && !ops['r'];
+ if (bslash)
+ continue;
if (imeta(c)) {
*bptr++ = Meta;
*bptr++ = c ^ 32;
reply other threads:[~1998-05-08 6:18 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=199805080611.BAA02528@hzoli.home \
--to=hzoli@cs.elte.hu \
--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).