"Fossies" - the Fresh Open Source Software Archive  

Source code changes of the file "sh.dol.c" between
tcsh-6.22.02.tar.gz and tcsh-6.22.03.tar.gz

About: Tcsh is a version of the Berkeley C-Shell, with the addition of: A command line editor, command and file name completion, listing, ...

sh.dol.c  (tcsh-6.22.02):sh.dol.c  (tcsh-6.22.03)
skipping to change at line 67 skipping to change at line 67
/* /*
* The following variables give the information about the current * The following variables give the information about the current
* $ expansion, recording the current word position, the remaining * $ expansion, recording the current word position, the remaining
* words within this expansion, the count of remaining words, and the * words within this expansion, the count of remaining words, and the
* information about any : modifier which is being applied. * information about any : modifier which is being applied.
*/ */
static Char *dolp; /* Remaining chars from this word */ static Char *dolp; /* Remaining chars from this word */
static Char **dolnxt; /* Further words */ static Char **dolnxt; /* Further words */
static int dolcnt; /* Count of further words */ static int dolcnt; /* Count of further words */
static struct Strbuf dolmod; /* = Strbuf_INIT; : modifier characters */ static struct Strbuf dolmod; /* = Strbuf_INIT; : modifier characters */
static int dolmcnt; /* :gx -> INT_MAX, else 1 */
static int dol_flag_a; /* :ax -> 1, else 0 */ static int ndolflags; /* keep track of mod counts for each modifier */
static int *dolmcnts; /* :gx -> INT_MAX, else 1 */
static int *dolaflags; /* :ax -> 1, else 0 */
static Char **Dfix2 (Char *const *); static Char **Dfix2 (Char *const *);
static int Dpack (struct Strbuf *); static int Dpack (struct Strbuf *);
static int Dword (struct blk_buf *); static int Dword (struct blk_buf *);
static void dolerror (Char *); static void dolerror (Char *);
static eChar DgetC (int); static eChar DgetC (int);
static void Dgetdol (void); static void Dgetdol (void);
static void fixDolMod (void); static void fixDolMod (void);
static void setDolp (Char *); static void setDolp (Char *);
static void unDredc (eChar); static void unDredc (eChar);
skipping to change at line 380 skipping to change at line 382
{ {
Char *np; Char *np;
struct varent *vp = NULL; struct varent *vp = NULL;
struct Strbuf *name = Strbuf_alloc(); struct Strbuf *name = Strbuf_alloc();
eChar c, sc; eChar c, sc;
int subscr = 0, lwb = 1, upb = 0; int subscr = 0, lwb = 1, upb = 0;
int dimen = 0, bitset = 0, length = 0; int dimen = 0, bitset = 0, length = 0;
static Char *dolbang = NULL; static Char *dolbang = NULL;
cleanup_push(name, Strbuf_free); cleanup_push(name, Strbuf_free);
dolmod.len = dolmcnt = dol_flag_a = 0; dolmod.len = ndolflags = 0;
c = sc = DgetC(0); c = sc = DgetC(0);
if (c == DEOF) { if (c == DEOF) {
stderror(ERR_SYNTAX); stderror(ERR_SYNTAX);
return; return;
} }
if (c == '{') if (c == '{')
c = DgetC(0); /* sc is { to take } later */ c = DgetC(0); /* sc is { to take } later */
if ((c & TRIM) == '#') if ((c & TRIM) == '#')
dimen++, c = DgetC(0); /* $# takes dimension */ dimen++, c = DgetC(0); /* $# takes dimension */
else if (c == '?') else if (c == '?')
skipping to change at line 720 skipping to change at line 722
} }
} }
static void static void
fixDolMod(void) fixDolMod(void)
{ {
eChar c; eChar c;
c = DgetC(0); c = DgetC(0);
if (c == ':') { if (c == ':') {
ndolflags = 0;
do { do {
c = DgetC(0), dolmcnt = 1, dol_flag_a = 0; ++ndolflags;
dolmcnts = xrealloc(dolmcnts, ndolflags * sizeof(int));
dolaflags = xrealloc(dolaflags, ndolflags * sizeof(int));
c = DgetC(0), dolmcnts[ndolflags - 1] = 1, dolaflags[ndolflags - 1] =
0;
if (c == 'g' || c == 'a') { if (c == 'g' || c == 'a') {
if (c == 'g') if (c == 'g') {
dolmcnt = INT_MAX; dolmcnts[ndolflags - 1] = INT_MAX;
else } else {
dol_flag_a = 1; dolaflags[ndolflags - 1] = 1;
}
c = DgetC(0); c = DgetC(0);
} }
if ((c == 'g' && dolmcnt != INT_MAX) || if ((c == 'g' && dolmcnts[ndolflags - 1] != INT_MAX) ||
(c == 'a' && dol_flag_a == 0)) { (c == 'a' && dolaflags[ndolflags - 1] == 0)) {
if (c == 'g') if (c == 'g') {
dolmcnt = INT_MAX; dolmcnts[ndolflags - 1] = INT_MAX;
else } else {
dol_flag_a = 1; dolaflags[ndolflags - 1] = 1;
}
c = DgetC(0); c = DgetC(0);
} }
if (c == 's') { /* [eichin:19910926.0755EST] */ if (c == 's') { /* [eichin:19910926.0755EST] */
int delimcnt = 2; int delimcnt = 2;
eChar delim = DgetC(0); eChar delim = DgetC(0);
Strbuf_append1(&dolmod, (Char) c); Strbuf_append1(&dolmod, (Char) c);
Strbuf_append1(&dolmod, (Char) delim); Strbuf_append1(&dolmod, (Char) delim);
if (delim == DEOF || !delim || letter(delim) if (delim == DEOF || !delim || letter(delim)
skipping to change at line 760 skipping to change at line 768
Strbuf_append1(&dolmod, (Char) c); Strbuf_append1(&dolmod, (Char) c);
if(c == delim) delimcnt--; if(c == delim) delimcnt--;
if(!delimcnt) break; if(!delimcnt) break;
} }
if(delimcnt) { if(delimcnt) {
seterror(ERR_BADSUBST); seterror(ERR_BADSUBST);
break; break;
} }
continue; continue;
} }
if (!any("luhtrqxes", c)) if (!any(TCSH_MODIFIERS, c))
stderror(ERR_BADMOD, (int)c); stderror(ERR_BADMOD, (int)c);
Strbuf_append1(&dolmod, (Char) c); Strbuf_append1(&dolmod, (Char) c);
if (c == 'q') if (c == 'q') {
dolmcnt = INT_MAX; dolmcnts[ndolflags - 1] = INT_MAX;
}
} }
while ((c = DgetC(0)) == ':'); while ((c = DgetC(0)) == ':');
unDredc(c); unDredc(c);
} }
else else
unDredc(c); unDredc(c);
} }
static int
all_dolmcnts_are_0()
{
int i = 0;
for(; i < ndolflags; ++i) {
if(dolmcnts[i] != 0)
return 0;
}
return 1;
}
static void static void
setDolp(Char *cp) setDolp(Char *cp)
{ {
Char *dp; Char *dp;
size_t i; size_t i;
int nthMod = 0;
if (dolmod.len == 0 || dolmcnt == 0) { if (dolmod.len == 0 || all_dolmcnts_are_0()) {
dolp = cp; dolp = cp;
return; return;
} }
cp = Strsave(cp); cp = Strsave(cp);
for (i = 0; i < dolmod.len; i++) { for (i = 0; i < dolmod.len; i++) {
int didmod = 0; int didmod = 0;
/* handle s// [eichin:19910926.0510EST] */ /* handle s// [eichin:19910926.0510EST] */
if(dolmod.s[i] == 's') { if(dolmod.s[i] == 's') {
Char delim; Char delim;
Char *lhsub, *rhsub, *np; Char *lhsub, *rhsub, *np;
size_t lhlen = 0, rhlen = 0; size_t lhlen = 0, rhlen = 0;
/* keep track of where the last :a match hit */
ptrdiff_t last_match = 0;
delim = dolmod.s[++i]; delim = dolmod.s[++i];
if (!delim || letter(delim) if (!delim || letter(delim)
|| Isdigit(delim) || any(" \t\n", delim)) { || Isdigit(delim) || any(" \t\n", delim)) {
seterror(ERR_BADSUBST); seterror(ERR_BADSUBST);
break; break;
} }
lhsub = &dolmod.s[++i]; lhsub = &dolmod.s[++i];
while(dolmod.s[i] != delim && dolmod.s[++i]) { while(dolmod.s[i] != delim && dolmod.s[++i]) {
lhlen++; lhlen++;
} }
dolmod.s[i] = 0; dolmod.s[i] = 0;
rhsub = &dolmod.s[++i]; rhsub = &dolmod.s[++i];
while(dolmod.s[i] != delim && dolmod.s[++i]) { while(dolmod.s[i] != delim && dolmod.s[++i]) {
rhlen++; rhlen++;
} }
dolmod.s[i] = 0; dolmod.s[i] = 0;
strip(lhsub); strip(lhsub);
strip(rhsub); strip(rhsub);
strip(cp); if(dolmcnts[nthMod] != 0) {
dp = cp; strip(cp);
do { dp = cp;
dp = Strstr(dp, lhsub); do {
if (dp) { dp = Strstr(dp + last_match, lhsub);
ptrdiff_t diff = dp - cp; if (dp) {
size_t len = (Strlen(cp) + 1 - lhlen + rhlen); ptrdiff_t diff = dp - cp;
np = xmalloc(len * sizeof(Char)); size_t len = (Strlen(cp) + 1 - lhlen + rhlen);
(void) Strncpy(np, cp, diff); np = xmalloc(len * sizeof(Char));
(void) Strcpy(np + diff, rhsub); (void) Strncpy(np, cp, diff);
(void) Strcpy(np + diff + rhlen, dp + lhlen); (void) Strcpy(np + diff, rhsub);
(void) Strcpy(np + diff + rhlen, dp + lhlen);
xfree(cp); last_match = diff + rhlen;
dp = cp = np;
cp[--len] = '\0'; xfree(cp);
didmod = 1; dp = cp = np;
if (diff >= (ssize_t)len) cp[--len] = '\0';
break; didmod = 1;
} else { if (diff >= (ssize_t)len)
/* should this do a seterror? */ break;
break; } else {
} /* should this do a seterror? */
} break;
while (dol_flag_a != 0); }
}
while (dolaflags[nthMod] != 0);
}
/* /*
* restore dolmod for additional words * restore dolmod for additional words
*/ */
dolmod.s[i] = rhsub[-1] = (Char) delim; dolmod.s[i] = rhsub[-1] = (Char) delim;
} else { } else if(dolmcnts[nthMod] != 0) {
do { do {
if ((dp = domod(cp, dolmod.s[i])) != NULL) { if ((dp = domod(cp, dolmod.s[i])) != NULL) {
didmod = 1; didmod = 1;
if (Strcmp(cp, dp) == 0) { if (Strcmp(cp, dp) == 0) {
xfree(cp); xfree(cp);
cp = dp; cp = dp;
break; break;
} }
else { else {
xfree(cp); xfree(cp);
cp = dp; cp = dp;
} }
} }
else else
break; break;
} }
while (dol_flag_a != 0); while (dolaflags[nthMod] != 0);
} }
if (didmod && dolmcnt != INT_MAX) if(didmod && dolmcnts[nthMod] != INT_MAX)
dolmcnt--; dolmcnts[nthMod]--;
#ifdef notdef #ifdef notdef
else else
break; break;
#endif #endif
++nthMod;
} }
addla(cp); addla(cp);
dolp = STRNULL; dolp = STRNULL;
if (seterr) if (seterr)
stderror(ERR_OLD); stderror(ERR_OLD);
} }
static void static void
 End of changes. 17 change blocks. 
46 lines changed or deleted 75 lines changed or added

Home  |  About  |  Features  |  All  |  Newest  |  Dox  |  Diffs  |  RSS Feeds  |  Screenshots  |  Comments  |  Imprint  |  Privacy  |  HTTP(S)