-/* $Header: dolist.c,v 3.0.1.7 90/03/27 15:48:42 lwall Locked $
+/* $Header: dolist.c,v 3.0.1.8 90/08/09 03:15:56 lwall Locked $
*
* Copyright (c) 1989, Larry Wall
*
* as specified in the README file that comes with the perl 3.0 kit.
*
* $Log: dolist.c,v $
+ * Revision 3.0.1.8 90/08/09 03:15:56 lwall
+ * patch19: certain kinds of matching cause "panic: hint"
+ * patch19: $' broke on embedded nulls
+ * patch19: split on /\s+/, /^/ and ' ' is now special cased for speed
+ * patch19: split on /x/i didn't work
+ * patch19: couldn't unpack an 'A' or 'a' field in a scalar context
+ * patch19: unpack called bcopy on each character of a C/c field
+ * patch19: pack/unpack know about uudecode lines
+ * patch19: fixed sort on undefined strings and sped up slightly
+ * patch19: each and keys returned garbage on null key in DBM file
+ *
* Revision 3.0.1.7 90/03/27 15:48:42 lwall
* patch16: MSDOS support
* patch16: use of $`, $& or $' sometimes causes memory leakage
register char *s = str_get(st[sp]);
char *strend = s + st[sp]->str_cur;
STR *tmpstr;
+ char *myhint = hint;
+ hint = Nullch;
if (!spat) {
if (gimme == G_ARRAY)
return --sp;
if (spat->spat_regexp)
regfree(spat->spat_regexp);
spat->spat_regexp = regcomp(t,t+tmpstr->str_cur,
- spat->spat_flags & SPAT_FOLD,1);
+ spat->spat_flags & SPAT_FOLD);
if (!*spat->spat_regexp->precomp && lastspat)
spat = lastspat;
if (spat->spat_flags & SPAT_KEEP) {
if (!*spat->spat_regexp->precomp && lastspat)
spat = lastspat;
t = s;
- if (hint) {
- if (hint < s || hint > strend)
+ if (myhint) {
+ if (myhint < s || myhint > strend)
fatal("panic: hint in do_match");
- s = hint;
- hint = Nullch;
+ s = myhint;
if (spat->spat_regexp->regback >= 0) {
s -= spat->spat_regexp->regback;
if (s < t)
if (spat->spat_regexp->subbase)
Safefree(spat->spat_regexp->subbase);
tmps = spat->spat_regexp->subbase = nsavestr(t,strend-t);
+ spat->spat_regexp->subend = tmps + (strend-t);
tmps = spat->spat_regexp->startp[0] = tmps + (s - t);
spat->spat_regexp->endp[0] = tmps + spat->spat_short->str_cur;
curspat = spat;
if (spat->spat_regexp)
regfree(spat->spat_regexp);
spat->spat_regexp = regcomp(m,m+dstr->str_cur,
- spat->spat_flags & SPAT_FOLD,1);
+ spat->spat_flags & SPAT_FOLD);
if (spat->spat_flags & SPAT_KEEP ||
(spat->spat_runtime->arg_type == O_ITEM &&
(spat->spat_runtime[1].arg_type & A_MASK) == A_SINGLE) ) {
}
if (!limit)
limit = maxiters + 2;
- if (spat->spat_short) {
+ if (strEQ("\\s+",spat->spat_regexp->precomp)) {
+ while (--limit) {
+ for (m = s; m < strend && !isspace(*m); m++) ;
+ if (m >= strend)
+ break;
+ if (realarray)
+ dstr = Str_new(30,m-s);
+ else
+ dstr = str_static(&str_undef);
+ str_nset(dstr,s,m-s);
+ (void)astore(ary, ++sp, dstr);
+ for (s = m + 1; s < strend && isspace(*s); s++) ;
+ }
+ }
+ else if (strEQ("^",spat->spat_regexp->precomp)) {
+ while (--limit) {
+ for (m = s; m < strend && *m != '\n'; m++) ;
+ m++;
+ if (m >= strend)
+ break;
+ if (realarray)
+ dstr = Str_new(30,m-s);
+ else
+ dstr = str_static(&str_undef);
+ str_nset(dstr,s,m-s);
+ (void)astore(ary, ++sp, dstr);
+ s = m;
+ }
+ }
+ else if (spat->spat_short) {
i = spat->spat_short->str_cur;
if (i == 1) {
+ int fold = (spat->spat_flags & SPAT_FOLD);
+
i = *spat->spat_short->str_ptr;
+ if (fold && isupper(i))
+ i = tolower(i);
while (--limit) {
- for (m = s; m < strend && *m != i; m++) ;
+ if (fold) {
+ for ( m = s;
+ m < strend && *m != i &&
+ (!isupper(*m) || tolower(*m) != i);
+ m++)
+ ;
+ }
+ else
+ for (m = s; m < strend && *m != i; m++) ;
if (m >= strend)
break;
if (realarray)
iters++;
}
else {
-#ifndef I286
+#ifndef I286x
while (iters > 0 && ary->ary_array[sp]->str_cur == 0)
iters--,sp--;
#else
register char *pat = str_get(st[sp++]);
register char *s = str_get(st[sp]);
char *strend = s + st[sp--]->str_cur;
+ char *strbeg = s;
register char *patend = pat + st[sp]->str_cur;
int datumtype;
register int len;
unsigned int auint;
unsigned long aulong;
char *aptr;
+ float afloat;
+ double adouble;
+ int checksum = 0;
+ unsigned long culong;
+ double cdouble;
if (gimme != G_ARRAY) { /* arrange to do first one only */
- patend = pat+1;
- if (*pat == 'a' || *pat == 'A') {
- while (isdigit(*patend))
+ for (patend = pat; !isalpha(*patend); patend++);
+ if (*patend == 'a' || *patend == 'A' || *pat == '%') {
+ patend++;
+ while (isdigit(*patend) || *patend == '*')
patend++;
}
+ else
+ patend++;
}
sp--;
while (pat < patend) {
+ reparse:
datumtype = *pat++;
- if (isdigit(*pat)) {
+ if (pat >= patend)
+ len = 1;
+ else if (*pat == '*')
+ len = strend - strbeg; /* long enough */
+ else if (isdigit(*pat)) {
len = *pat++ - '0';
while (isdigit(*pat))
len = (len * 10) + (*pat++ - '0');
}
else
- len = 1;
+ len = (datumtype != '@');
switch(datumtype) {
default:
break;
+ case '%':
+ if (len == 1 && pat[-1] != '1')
+ len = 16;
+ checksum = len;
+ culong = 0;
+ cdouble = 0;
+ if (pat < patend)
+ goto reparse;
+ break;
+ case '@':
+ if (len > strend - s)
+ fatal("@ outside of string");
+ s = strbeg + len;
+ break;
+ case 'X':
+ if (len > s - strbeg)
+ fatal("X outside of string");
+ s -= len;
+ break;
case 'x':
+ if (len > strend - s)
+ fatal("x outside of string");
s += len;
break;
case 'A':
case 'a':
- if (s + len > strend)
+ if (len > strend - s)
len = strend - s;
+ if (checksum)
+ goto uchar_checksum;
str = Str_new(35,len);
str_nset(str,s,len);
s += len;
(void)astore(stack, ++sp, str_2static(str));
break;
case 'c':
- while (len-- > 0) {
- if (s + sizeof(char) > strend)
- achar = 0;
- else {
- bcopy(s,(char*)&achar,sizeof(char));
- s += sizeof(char);
+ if (len > strend - s)
+ len = strend - s;
+ if (checksum) {
+ while (len-- > 0) {
+ aint = *s++;
+ if (aint >= 128) /* fake up signed chars */
+ aint -= 256;
+ culong += aint;
+ }
+ }
+ else {
+ while (len-- > 0) {
+ aint = *s++;
+ if (aint >= 128) /* fake up signed chars */
+ aint -= 256;
+ str = Str_new(36,0);
+ str_numset(str,(double)aint);
+ (void)astore(stack, ++sp, str_2static(str));
}
- str = Str_new(36,0);
- aint = achar;
- if (aint >= 128) /* fake up signed chars */
- aint -= 256;
- str_numset(str,(double)aint);
- (void)astore(stack, ++sp, str_2static(str));
}
break;
case 'C':
- while (len-- > 0) {
- if (s + sizeof(unsigned char) > strend)
- auchar = 0;
- else {
- bcopy(s,(char*)&auchar,sizeof(unsigned char));
- s += sizeof(unsigned char);
+ if (len > strend - s)
+ len = strend - s;
+ if (checksum) {
+ uchar_checksum:
+ while (len-- > 0) {
+ auint = *s++ & 255;
+ culong += auint;
+ }
+ }
+ else {
+ while (len-- > 0) {
+ auint = *s++ & 255;
+ str = Str_new(37,0);
+ str_numset(str,(double)auint);
+ (void)astore(stack, ++sp, str_2static(str));
}
- str = Str_new(37,0);
- auint = auchar; /* some can't cast uchar to double */
- str_numset(str,(double)auint);
- (void)astore(stack, ++sp, str_2static(str));
}
break;
case 's':
- while (len-- > 0) {
- if (s + sizeof(short) > strend)
- ashort = 0;
- else {
+ along = (strend - s) / sizeof(short);
+ if (len > along)
+ len = along;
+ if (checksum) {
+ while (len-- > 0) {
bcopy(s,(char*)&ashort,sizeof(short));
s += sizeof(short);
+ culong += ashort;
+ }
+ }
+ else {
+ while (len-- > 0) {
+ bcopy(s,(char*)&ashort,sizeof(short));
+ s += sizeof(short);
+ str = Str_new(38,0);
+ str_numset(str,(double)ashort);
+ (void)astore(stack, ++sp, str_2static(str));
}
- str = Str_new(38,0);
- str_numset(str,(double)ashort);
- (void)astore(stack, ++sp, str_2static(str));
}
break;
case 'n':
case 'S':
- while (len-- > 0) {
- if (s + sizeof(unsigned short) > strend)
- aushort = 0;
- else {
+ along = (strend - s) / sizeof(unsigned short);
+ if (len > along)
+ len = along;
+ if (checksum) {
+ while (len-- > 0) {
bcopy(s,(char*)&aushort,sizeof(unsigned short));
s += sizeof(unsigned short);
+#ifdef NTOHS
+ if (datumtype == 'n')
+ aushort = ntohs(aushort);
+#endif
+ culong += aushort;
}
- str = Str_new(39,0);
+ }
+ else {
+ while (len-- > 0) {
+ bcopy(s,(char*)&aushort,sizeof(unsigned short));
+ s += sizeof(unsigned short);
+ str = Str_new(39,0);
#ifdef NTOHS
- if (datumtype == 'n')
- aushort = ntohs(aushort);
+ if (datumtype == 'n')
+ aushort = ntohs(aushort);
#endif
- str_numset(str,(double)aushort);
- (void)astore(stack, ++sp, str_2static(str));
+ str_numset(str,(double)aushort);
+ (void)astore(stack, ++sp, str_2static(str));
+ }
}
break;
case 'i':
- while (len-- > 0) {
- if (s + sizeof(int) > strend)
- aint = 0;
- else {
+ along = (strend - s) / sizeof(int);
+ if (len > along)
+ len = along;
+ if (checksum) {
+ while (len-- > 0) {
bcopy(s,(char*)&aint,sizeof(int));
s += sizeof(int);
+ if (checksum > 32)
+ cdouble += (double)aint;
+ else
+ culong += aint;
+ }
+ }
+ else {
+ while (len-- > 0) {
+ bcopy(s,(char*)&aint,sizeof(int));
+ s += sizeof(int);
+ str = Str_new(40,0);
+ str_numset(str,(double)aint);
+ (void)astore(stack, ++sp, str_2static(str));
}
- str = Str_new(40,0);
- str_numset(str,(double)aint);
- (void)astore(stack, ++sp, str_2static(str));
}
break;
case 'I':
- while (len-- > 0) {
- if (s + sizeof(unsigned int) > strend)
- auint = 0;
- else {
+ along = (strend - s) / sizeof(unsigned int);
+ if (len > along)
+ len = along;
+ if (checksum) {
+ while (len-- > 0) {
bcopy(s,(char*)&auint,sizeof(unsigned int));
s += sizeof(unsigned int);
+ if (checksum > 32)
+ cdouble += (double)auint;
+ else
+ culong += auint;
+ }
+ }
+ else {
+ while (len-- > 0) {
+ bcopy(s,(char*)&auint,sizeof(unsigned int));
+ s += sizeof(unsigned int);
+ str = Str_new(41,0);
+ str_numset(str,(double)auint);
+ (void)astore(stack, ++sp, str_2static(str));
}
- str = Str_new(41,0);
- str_numset(str,(double)auint);
- (void)astore(stack, ++sp, str_2static(str));
}
break;
case 'l':
- while (len-- > 0) {
- if (s + sizeof(long) > strend)
- along = 0;
- else {
+ along = (strend - s) / sizeof(long);
+ if (len > along)
+ len = along;
+ if (checksum) {
+ while (len-- > 0) {
bcopy(s,(char*)&along,sizeof(long));
s += sizeof(long);
+ if (checksum > 32)
+ cdouble += (double)along;
+ else
+ culong += along;
+ }
+ }
+ else {
+ while (len-- > 0) {
+ bcopy(s,(char*)&along,sizeof(long));
+ s += sizeof(long);
+ str = Str_new(42,0);
+ str_numset(str,(double)along);
+ (void)astore(stack, ++sp, str_2static(str));
}
- str = Str_new(42,0);
- str_numset(str,(double)along);
- (void)astore(stack, ++sp, str_2static(str));
}
break;
case 'N':
case 'L':
- while (len-- > 0) {
- if (s + sizeof(unsigned long) > strend)
- aulong = 0;
- else {
+ along = (strend - s) / sizeof(unsigned long);
+ if (len > along)
+ len = along;
+ if (checksum) {
+ while (len-- > 0) {
bcopy(s,(char*)&aulong,sizeof(unsigned long));
s += sizeof(unsigned long);
+#ifdef NTOHL
+ if (datumtype == 'N')
+ aulong = ntohl(aulong);
+#endif
+ if (checksum > 32)
+ cdouble += (double)aulong;
+ else
+ culong += aulong;
}
- str = Str_new(43,0);
+ }
+ else {
+ while (len-- > 0) {
+ bcopy(s,(char*)&aulong,sizeof(unsigned long));
+ s += sizeof(unsigned long);
+ str = Str_new(43,0);
#ifdef NTOHL
- if (datumtype == 'N')
- aulong = ntohl(aulong);
+ if (datumtype == 'N')
+ aulong = ntohl(aulong);
#endif
- str_numset(str,(double)aulong);
- (void)astore(stack, ++sp, str_2static(str));
+ str_numset(str,(double)aulong);
+ (void)astore(stack, ++sp, str_2static(str));
+ }
}
break;
case 'p':
+ along = (strend - s) / sizeof(char*);
+ if (len > along)
+ len = along;
while (len-- > 0) {
- if (s + sizeof(char*) > strend)
- aptr = 0;
+ if (sizeof(char*) > strend - s)
+ break;
else {
bcopy(s,(char*)&aptr,sizeof(char*));
s += sizeof(char*);
(void)astore(stack, ++sp, str_2static(str));
}
break;
+ /* float and double added gnb@melba.bby.oz.au 22/11/89 */
+ case 'f':
+ case 'F':
+ along = (strend - s) / sizeof(float);
+ if (len > along)
+ len = along;
+ if (checksum) {
+ while (len-- > 0) {
+ bcopy(s, (char *)&afloat, sizeof(float));
+ s += sizeof(float);
+ cdouble += afloat;
+ }
+ }
+ else {
+ while (len-- > 0) {
+ bcopy(s, (char *)&afloat, sizeof(float));
+ s += sizeof(float);
+ str = Str_new(47, 0);
+ str_numset(str, (double)afloat);
+ (void)astore(stack, ++sp, str_2static(str));
+ }
+ }
+ break;
+ case 'd':
+ case 'D':
+ along = (strend - s) / sizeof(double);
+ if (len > along)
+ len = along;
+ if (checksum) {
+ while (len-- > 0) {
+ bcopy(s, (char *)&adouble, sizeof(double));
+ s += sizeof(double);
+ cdouble += adouble;
+ }
+ }
+ else {
+ while (len-- > 0) {
+ bcopy(s, (char *)&adouble, sizeof(double));
+ s += sizeof(double);
+ str = Str_new(48, 0);
+ str_numset(str, (double)adouble);
+ (void)astore(stack, ++sp, str_2static(str));
+ }
+ }
+ break;
+ case 'u':
+ along = (strend - s) * 3 / 4;
+ str = Str_new(42,along);
+ while (s < strend && *s > ' ' && *s < 'a') {
+ int a,b,c,d;
+ char hunk[4];
+
+ hunk[3] = '\0';
+ len = (*s++ - ' ') & 077;
+ while (len > 0) {
+ if (s < strend && *s >= ' ')
+ a = (*s++ - ' ') & 077;
+ else
+ a = 0;
+ if (s < strend && *s >= ' ')
+ b = (*s++ - ' ') & 077;
+ else
+ b = 0;
+ if (s < strend && *s >= ' ')
+ c = (*s++ - ' ') & 077;
+ else
+ c = 0;
+ if (s < strend && *s >= ' ')
+ d = (*s++ - ' ') & 077;
+ else
+ d = 0;
+ hunk[0] = a << 2 | b >> 4;
+ hunk[1] = b << 4 | c >> 2;
+ hunk[2] = c << 6 | d;
+ str_ncat(str,hunk, len > 3 ? 3 : len);
+ len -= 3;
+ }
+ if (*s == '\n')
+ s++;
+ else if (s[1] == '\n') /* possible checksum byte */
+ s += 2;
+ }
+ (void)astore(stack, ++sp, str_2static(str));
+ break;
+ }
+ if (checksum) {
+ str = Str_new(42,0);
+ if (index("fFdD", datumtype) ||
+ (checksum > 32 && index("iIlLN", datumtype)) ) {
+ double modf();
+ double trouble;
+
+ adouble = 1.0;
+ while (checksum >= 16) {
+ checksum -= 16;
+ adouble *= 65536.0;
+ }
+ while (checksum >= 4) {
+ checksum -= 4;
+ adouble *= 16.0;
+ }
+ while (checksum--)
+ adouble *= 2.0;
+ along = (1 << checksum) - 1;
+ while (cdouble < 0.0)
+ cdouble += adouble;
+ cdouble = modf(cdouble / adouble, &trouble) * adouble;
+ str_numset(str,cdouble);
+ }
+ else {
+ along = (1 << checksum) - 1;
+ culong &= (unsigned long)along;
+ str_numset(str,(double)culong);
+ }
+ (void)astore(stack, ++sp, str_2static(str));
+ checksum = 0;
}
}
return sp;
}
int
-do_splice(ary,str,gimme,arglast)
+do_splice(ary,gimme,arglast)
register ARRAY *ary;
-STR *str;
int gimme;
int *arglast;
{
int gimme;
int *arglast;
{
- STR **st = stack->ary_array;
+ register STR **st = stack->ary_array;
int sp = arglast[1];
register STR **up;
register int max = arglast[2] - sp;
return sp;
}
up = &st[sp];
- for (i = 0; i < max; i++) {
- if ((*up = up[1]) && !(*up)->str_pok)
- (void)str_2ptr(*up);
- up++;
+ st += sp; /* temporarily make st point to args */
+ for (i = 1; i <= max; i++) {
+ if (*up = st[i]) {
+ if (!(*up)->str_pok)
+ (void)str_2ptr(*up);
+ up++;
+ }
}
+ st -= sp;
+ max = up - &st[sp];
sp--;
if (max > 1) {
if (stab_sub(stab) && (sortcmd = stab_sub(stab)->cmd)) {
qsort((char*)(st+sp+1),max,sizeof(STR*),sortcmp);
#endif
}
- up = &st[arglast[1]];
- while (max > 0 && !*up)
- max--,up--;
return sp+max;
}
STR **str1;
STR **str2;
{
- if (!*str1)
- return -1;
- if (!*str2)
- return 1;
stab_val(firststab) = *str1;
stab_val(secondstab) = *str2;
cmd_exec(sortcmd,G_SCALAR,-1);
register STR *str2 = *strp2;
int retval;
- if (!str1)
- return -1;
- if (!str2)
- return 1;
-
if (str1->str_cur < str2->str_cur) {
if (retval = memcmp(str1->str_ptr, str2->str_ptr, str1->str_cur))
return retval;
while (entry = hiternext(hash)) {
if (dokeys) {
tmps = hiterkey(entry,&i);
+ if (!i)
+ tmps = "";
(void)astore(ary,++sp,str_2static(str_make(tmps,i)));
}
if (dovalues) {
if (entry) {
if (gimme == G_ARRAY) {
tmps = hiterkey(entry, &i);
+ if (!i)
+ tmps = "";
st[++sp] = mystrk = str_make(tmps,i);
}
st[++sp] = str;
-/* $Header: util.c,v 3.0.1.5 90/03/27 16:35:13 lwall Locked $
+/* $Header: util.c,v 3.0.1.6 90/08/09 05:44:55 lwall Locked $
*
* Copyright (c) 1989, Larry Wall
*
* as specified in the README file that comes with the perl 3.0 kit.
*
* $Log: util.c,v $
+ * Revision 3.0.1.6 90/08/09 05:44:55 lwall
+ * patch19: fixed double include of <signal.h>
+ * patch19: various MSDOS and OS/2 patches folded in
+ * patch19: open(STDOUT,"|command") left wrong descriptor attached to STDOUT
+ *
* Revision 3.0.1.5 90/03/27 16:35:13 lwall
* patch16: MSDOS support
* patch16: support for machines that can't cast negative floats to unsigned ints
#include "EXTERN.h"
#include "perl.h"
+
+#ifndef NSIG
#include <signal.h>
+#endif
#ifdef I_VFORK
# include <vfork.h>
char *
safemalloc(size)
+#ifdef MSDOS
+unsigned long size;
+#else
MEM_SIZE size;
+#endif /* MSDOS */
{
char *ptr;
char *malloc();
+#ifdef MSDOS
+ if (size > 0xffff) {
+ fprintf(stderr, "Allocation too large: %lx\n", size) FLUSH;
+ exit(1);
+ }
+#endif /* MSDOS */
ptr = malloc(size?size:1); /* malloc(0) is NASTY on our system */
#ifdef DEBUGGING
# ifndef I286
char *
saferealloc(where,size)
char *where;
+#ifndef MSDOS
MEM_SIZE size;
+#else
+unsigned long size;
+#endif /* MSDOS */
{
char *ptr;
char *realloc();
+#ifdef MSDOS
+ if (size > 0xffff) {
+ fprintf(stderr, "Reallocation too large: %lx\n", size) FLUSH;
+ exit(1);
+ }
+#endif /* MSDOS */
if (!where)
fatal("Null realloc");
ptr = realloc(where,size?size:1); /* realloc(0) is NASTY on our system */
char *
cpytill(to,from,fromend,delim,retlen)
-register char *to, *from;
+register char *to;
+register char *from;
register char *fromend;
register int delim;
int *retlen;
int rarest = 0;
int frequency = 256;
- str_grow(str,len+258);
+ Str_Grow(str,len+258);
#ifndef lint
table = (unsigned char*)(str->str_ptr + len + 1);
#else
#else
table = Null(unsigned char*);
#endif
- s = big + --littlelen;
+ if (--littlelen >= bigend - big)
+ return Nullch;
+ s = big + littlelen;
oldlittle = little = table - 2;
if (littlestr->str_pok & SP_CASEFOLD) { /* case insensitive? */
while (s < bigend) {
top1:
if (tmp = table[*s]) {
- s += tmp;
+#ifdef POINTERRIGOR
+ if (bigend - s > tmp) {
+ s += tmp;
+ goto top1;
+ }
+#else
+ if ((s += tmp) < bigend)
+ goto top1;
+#endif
+ return Nullch;
}
else {
tmp = littlelen; /* less expensive than calling strncmp() */
while (s < bigend) {
top2:
if (tmp = table[*s]) {
- s += tmp;
+#ifdef POINTERRIGOR
+ if (bigend - s > tmp) {
+ s += tmp;
+ goto top2;
+ }
+#else
+ if ((s += tmp) < bigend)
+ goto top2;
+#endif
+ return Nullch;
}
else {
tmp = littlelen; /* less expensive than calling strncmp() */
(void)sprintf(s,pat,a1,a2,a3,a4);
s += strlen(s);
if (s[-1] != '\n') {
- if (line) {
- (void)sprintf(s," at %s line %ld",
- in_eval?filename:origfilename, (long)line);
+ if (curcmd->c_line) {
+ (void)sprintf(s," at %s line %ld", filename, (long)curcmd->c_line);
s += strlen(s);
}
if (last_in_stab &&
s += strlen(s);
if (s[-1] != '\n') {
- if (line) {
- (void)sprintf(s," at %s line %ld",
- in_eval?filename:origfilename, (long)line);
+ if (curcmd->c_line) {
+ (void)sprintf(s," at %s line %ld", filename, (long)curcmd->c_line);
s += strlen(s);
}
if (last_in_stab &&
New(904, environ[i], strlen(nam) + strlen(val) + 2, char);
/* this may or may not be in */
/* the old environ structure */
+#ifndef MSDOS
(void)sprintf(environ[i],"%s=%s",nam,val);/* all that work just for this */
+#else
+ /* MS-DOS requires environment variable names to be in uppercase */
+ strcpy(environ[i],nam); strupr(environ[i],nam);
+ (void)sprintf(environ[i] + strlen(nam),"=%s",val);
+#endif /* MSDOS */
}
int
#undef THIS
#undef THAT
}
+ do_execfree(); /* free any memory malloced by child on vfork */
close(p[that]);
+ if (p[that] < p[this]) {
+ dup2(p[this], p[that]);
+ close(p[this]);
+ p[this] = p[that];
+ }
str = afetch(pidstatary,p[this],TRUE);
str_numset(str,(double)pid);
str->str_cur = 0;
int oldfd;
int newfd;
{
- int fdtmp[10];
+#if defined(FCNTL) && defined(F_DUPFD)
+ close(newfd);
+ fcntl(oldfd, F_DUPFD, newfd);
+#else
+ int fdtmp[20];
int fdx = 0;
int fd;
fdtmp[fdx++] = fd;
while (fdx > 0)
close(fdtmp[--fdx]);
+#endif
}
#endif
mypclose(ptr)
FILE *ptr;
{
- register int result;
#ifdef VOIDSIG
void (*hstat)(), (*istat)(), (*qstat)();
#else
if (pid < 0) /* already exited? */
status = str->str_cur;
else {
+ int result;
+
while ((result = wait(&status)) != pid && result >= 0)
pidgone(result,status);
if (result < 0)
return (unsigned long)along;
}
#endif
+
+#ifndef RENAME
+int
+same_dirent(a,b)
+char *a;
+char *b;
+{
+ char *fa = rindex(a,'/');
+ char *fb = rindex(b,'/');
+ struct stat tmpstatbuf1;
+ struct stat tmpstatbuf2;
+#ifndef MAXPATHLEN
+#define MAXPATHLEN 1024
+#endif
+ char tmpbuf[MAXPATHLEN+1];
+
+ if (fa)
+ fa++;
+ else
+ fa = a;
+ if (fb)
+ fb++;
+ else
+ fb = b;
+ if (strNE(a,b))
+ return FALSE;
+ if (fa == a)
+ strcpy(tmpbuf,".")
+ else
+ strncpy(tmpbuf, a, fa - a);
+ if (stat(tmpbuf, &tmpstatbuf1) < 0)
+ return FALSE;
+ if (fb == b)
+ strcpy(tmpbuf,".")
+ else
+ strncpy(tmpbuf, b, fb - b);
+ if (stat(tmpbuf, &tmpstatbuf2) < 0)
+ return FALSE;
+ return tmpstatbuf1.st_dev == tmpstatbuf2.st_dev &&
+ tmpstatbuf1.st_ino == tmpstatbuf2.st_ino;
+}
+#endif /* !RENAME */
-/* $Header: walk.c,v 3.0.1.4 90/03/01 10:32:45 lwall Locked $
+/* $Header: walk.c,v 3.0.1.5 90/08/09 05:55:01 lwall Locked $
*
* Copyright (c) 1989, Larry Wall
*
* as specified in the README file that comes with the perl 3.0 kit.
*
* $Log: walk.c,v $
+ * Revision 3.0.1.5 90/08/09 05:55:01 lwall
+ * patch19: a2p emited local($_) without a semicolon
+ * patch19: a2p didn't make explicit split on whitespace skip leading whitespace
+ * patch19: foreach on a normal array was iterating on values instead of indexes
+ *
* Revision 3.0.1.4 90/03/01 10:32:45 lwall
* patch9: a2p didn't put a $ on ExitValue
*
str_cat(str," $FNRbase = $. if eof;\n");
}
if (len & 1)
- str_cat(str," local($_)\n");
+ str_cat(str," local($_);\n");
if (len & 2)
str_cat(str,
" if ($getline_ok = (($_ = <$fh>) ne ''))");
str_scat(str,fstr=walk(1,level,ops[node+1].ival,&numarg,prec));
str_free(fstr);
break;
+ case OCOND:
+ prec = P_COND;
+ str = walk(1,level,ops[node+1].ival,&numarg,prec);
+ str_cat(str," ? ");
+ str_scat(str,fstr=walk(1,level,ops[node+2].ival,&numarg,prec+1));
+ str_free(fstr);
+ str_cat(str," : ");
+ str_scat(str,fstr=walk(1,level,ops[node+3].ival,&numarg,prec+1));
+ str_free(fstr);
+ break;
case OCPAREN:
str = str_new(0);
str_set(str,"(");
i = fstr->str_ptr[1] & 127;
if (index("*+?.[]()|^$\\",i))
sprintf(tokenbuf,"/\\%c/",i);
+ else if (i = ' ')
+ sprintf(tokenbuf,"' '");
else
sprintf(tokenbuf,"/%c/",i);
str_cat(str,tokenbuf);
str_cat(str,", ");
str_scat(str,fstr=walk(1,level,ops[node+1].ival,&numarg,P_COMMA+1));
str_free(fstr);
- str_cat(str,", 999)");
+ str_cat(str,", 9999)");
if (useval) {
str_cat(str,")");
}
tmp2str = hfetch(symtab,str->str_ptr);
if (tmp2str && atoi(tmp2str->str_ptr)) {
sprintf(tokenbuf,
- "foreach %s (@%s) ",
+ "foreach %s ($[ .. $#%s) ",
s,
d+1);
}
str_cat(str,tokenbuf);
}
if (const_FS) {
- sprintf(tokenbuf," = split(/[%c\\n]/, $_, 999);\n",const_FS);
+ sprintf(tokenbuf," = split(/[%c\\n]/, $_, 9999);\n",const_FS);
str_cat(str,tokenbuf);
}
else if (saw_FS)
- str_cat(str," = split($FS, $_, 999);\n");
+ str_cat(str," = split($FS, $_, 9999);\n");
else
- str_cat(str," = split(' ', $_, 999);\n");
+ str_cat(str," = split(' ', $_, 9999);\n");
tab(str,level);
}