1*7c478bd9Sstevel@tonic-gate /* 2*7c478bd9Sstevel@tonic-gate * Copyright 2000 Sun Microsystems, Inc. All rights reserved. 3*7c478bd9Sstevel@tonic-gate * Use is subject to license terms. 4*7c478bd9Sstevel@tonic-gate */ 5*7c478bd9Sstevel@tonic-gate 6*7c478bd9Sstevel@tonic-gate /* Copyright (c) 1983, 1984, 1985, 1986, 1987, 1988, 1989 AT&T */ 7*7c478bd9Sstevel@tonic-gate /* All Rights Reserved */ 8*7c478bd9Sstevel@tonic-gate 9*7c478bd9Sstevel@tonic-gate /* 10*7c478bd9Sstevel@tonic-gate * Copyright (c) 1980 Regents of the University of California. 11*7c478bd9Sstevel@tonic-gate * All rights reserved. The Berkeley Software License Agreement 12*7c478bd9Sstevel@tonic-gate * specifies the terms and conditions for redistribution. 13*7c478bd9Sstevel@tonic-gate */ 14*7c478bd9Sstevel@tonic-gate 15*7c478bd9Sstevel@tonic-gate #pragma ident "%Z%%M% %I% %E% SMI" 16*7c478bd9Sstevel@tonic-gate 17*7c478bd9Sstevel@tonic-gate #include "sh.h" 18*7c478bd9Sstevel@tonic-gate #include "sh.tconst.h" 19*7c478bd9Sstevel@tonic-gate #include <fcntl.h> 20*7c478bd9Sstevel@tonic-gate #include <unistd.h> 21*7c478bd9Sstevel@tonic-gate 22*7c478bd9Sstevel@tonic-gate /* 23*7c478bd9Sstevel@tonic-gate * C Shell 24*7c478bd9Sstevel@tonic-gate */ 25*7c478bd9Sstevel@tonic-gate 26*7c478bd9Sstevel@tonic-gate any(c, s) 27*7c478bd9Sstevel@tonic-gate register int c; 28*7c478bd9Sstevel@tonic-gate register tchar *s; 29*7c478bd9Sstevel@tonic-gate { 30*7c478bd9Sstevel@tonic-gate 31*7c478bd9Sstevel@tonic-gate while (s && *s) 32*7c478bd9Sstevel@tonic-gate if (*s++ == c) 33*7c478bd9Sstevel@tonic-gate return (1); 34*7c478bd9Sstevel@tonic-gate return (0); 35*7c478bd9Sstevel@tonic-gate } 36*7c478bd9Sstevel@tonic-gate 37*7c478bd9Sstevel@tonic-gate onlyread(cp) 38*7c478bd9Sstevel@tonic-gate tchar *cp; 39*7c478bd9Sstevel@tonic-gate { 40*7c478bd9Sstevel@tonic-gate extern char end[]; 41*7c478bd9Sstevel@tonic-gate 42*7c478bd9Sstevel@tonic-gate return ((char *)cp < end); 43*7c478bd9Sstevel@tonic-gate } 44*7c478bd9Sstevel@tonic-gate 45*7c478bd9Sstevel@tonic-gate 46*7c478bd9Sstevel@tonic-gate /* 47*7c478bd9Sstevel@tonic-gate * WARNING: changes here also need to occur in the XFREE macro in sh.h. 48*7c478bd9Sstevel@tonic-gate */ 49*7c478bd9Sstevel@tonic-gate 50*7c478bd9Sstevel@tonic-gate xfree(cp) 51*7c478bd9Sstevel@tonic-gate char *cp; 52*7c478bd9Sstevel@tonic-gate { 53*7c478bd9Sstevel@tonic-gate extern char end[]; 54*7c478bd9Sstevel@tonic-gate 55*7c478bd9Sstevel@tonic-gate #if defined(sparc) 56*7c478bd9Sstevel@tonic-gate if ((char *)cp >= end && (char *)cp < (char *)&cp) 57*7c478bd9Sstevel@tonic-gate free(cp); 58*7c478bd9Sstevel@tonic-gate #elif defined(i386) 59*7c478bd9Sstevel@tonic-gate if ((char *)cp >= end) 60*7c478bd9Sstevel@tonic-gate free(cp); 61*7c478bd9Sstevel@tonic-gate #else 62*7c478bd9Sstevel@tonic-gate #error xfree function is machine dependent and no machine type is recognized 63*7c478bd9Sstevel@tonic-gate #endif 64*7c478bd9Sstevel@tonic-gate } 65*7c478bd9Sstevel@tonic-gate 66*7c478bd9Sstevel@tonic-gate tchar * 67*7c478bd9Sstevel@tonic-gate savestr(s) 68*7c478bd9Sstevel@tonic-gate register tchar *s; 69*7c478bd9Sstevel@tonic-gate { 70*7c478bd9Sstevel@tonic-gate tchar *n; 71*7c478bd9Sstevel@tonic-gate register tchar *p; 72*7c478bd9Sstevel@tonic-gate 73*7c478bd9Sstevel@tonic-gate if (s == 0) 74*7c478bd9Sstevel@tonic-gate s = S_ /* "" */; 75*7c478bd9Sstevel@tonic-gate #ifndef m32 76*7c478bd9Sstevel@tonic-gate for (p = s; *p++; ) 77*7c478bd9Sstevel@tonic-gate ; 78*7c478bd9Sstevel@tonic-gate n = p = (tchar *)xalloc((unsigned) (p - s)*sizeof (tchar)); 79*7c478bd9Sstevel@tonic-gate while (*p++ = *s++) 80*7c478bd9Sstevel@tonic-gate ; 81*7c478bd9Sstevel@tonic-gate return (n); 82*7c478bd9Sstevel@tonic-gate #else 83*7c478bd9Sstevel@tonic-gate p = (tchar *) xalloc((strlen_(s) + 1)*sizeof (tchar)); 84*7c478bd9Sstevel@tonic-gate strcpy_(p, s); 85*7c478bd9Sstevel@tonic-gate return (p); 86*7c478bd9Sstevel@tonic-gate #endif 87*7c478bd9Sstevel@tonic-gate } 88*7c478bd9Sstevel@tonic-gate 89*7c478bd9Sstevel@tonic-gate void * 90*7c478bd9Sstevel@tonic-gate calloc(i, j) 91*7c478bd9Sstevel@tonic-gate register unsigned i; 92*7c478bd9Sstevel@tonic-gate unsigned j; 93*7c478bd9Sstevel@tonic-gate { 94*7c478bd9Sstevel@tonic-gate register char *cp; 95*7c478bd9Sstevel@tonic-gate 96*7c478bd9Sstevel@tonic-gate i *= j; 97*7c478bd9Sstevel@tonic-gate cp = (char *)xalloc(i); 98*7c478bd9Sstevel@tonic-gate bzero(cp, (int)i); 99*7c478bd9Sstevel@tonic-gate return (cp); 100*7c478bd9Sstevel@tonic-gate } 101*7c478bd9Sstevel@tonic-gate 102*7c478bd9Sstevel@tonic-gate nomem(i) 103*7c478bd9Sstevel@tonic-gate unsigned i; 104*7c478bd9Sstevel@tonic-gate { 105*7c478bd9Sstevel@tonic-gate #ifdef debug 106*7c478bd9Sstevel@tonic-gate static tchar *av[2] = {0, 0}; 107*7c478bd9Sstevel@tonic-gate #endif 108*7c478bd9Sstevel@tonic-gate 109*7c478bd9Sstevel@tonic-gate child++; 110*7c478bd9Sstevel@tonic-gate #ifndef debug 111*7c478bd9Sstevel@tonic-gate error("Out of memory"); 112*7c478bd9Sstevel@tonic-gate #ifdef lint 113*7c478bd9Sstevel@tonic-gate i = i; 114*7c478bd9Sstevel@tonic-gate #endif 115*7c478bd9Sstevel@tonic-gate #else 116*7c478bd9Sstevel@tonic-gate showall(av); 117*7c478bd9Sstevel@tonic-gate printf("i=%d: Out of memory\n", i); 118*7c478bd9Sstevel@tonic-gate chdir("/usr/bill/cshcore"); 119*7c478bd9Sstevel@tonic-gate abort(); 120*7c478bd9Sstevel@tonic-gate #endif 121*7c478bd9Sstevel@tonic-gate return (0); /* fool lint */ 122*7c478bd9Sstevel@tonic-gate } 123*7c478bd9Sstevel@tonic-gate 124*7c478bd9Sstevel@tonic-gate tchar ** 125*7c478bd9Sstevel@tonic-gate blkend(up) 126*7c478bd9Sstevel@tonic-gate register tchar **up; 127*7c478bd9Sstevel@tonic-gate { 128*7c478bd9Sstevel@tonic-gate 129*7c478bd9Sstevel@tonic-gate while (*up) 130*7c478bd9Sstevel@tonic-gate up++; 131*7c478bd9Sstevel@tonic-gate return (up); 132*7c478bd9Sstevel@tonic-gate } 133*7c478bd9Sstevel@tonic-gate 134*7c478bd9Sstevel@tonic-gate blkpr(av) 135*7c478bd9Sstevel@tonic-gate register tchar **av; 136*7c478bd9Sstevel@tonic-gate { 137*7c478bd9Sstevel@tonic-gate 138*7c478bd9Sstevel@tonic-gate for (; *av; av++) { 139*7c478bd9Sstevel@tonic-gate printf("%t", *av); 140*7c478bd9Sstevel@tonic-gate if (av[1]) 141*7c478bd9Sstevel@tonic-gate printf(" "); 142*7c478bd9Sstevel@tonic-gate } 143*7c478bd9Sstevel@tonic-gate } 144*7c478bd9Sstevel@tonic-gate 145*7c478bd9Sstevel@tonic-gate blklen(av) 146*7c478bd9Sstevel@tonic-gate register tchar **av; 147*7c478bd9Sstevel@tonic-gate { 148*7c478bd9Sstevel@tonic-gate register int i = 0; 149*7c478bd9Sstevel@tonic-gate 150*7c478bd9Sstevel@tonic-gate while (*av++) 151*7c478bd9Sstevel@tonic-gate i++; 152*7c478bd9Sstevel@tonic-gate return (i); 153*7c478bd9Sstevel@tonic-gate } 154*7c478bd9Sstevel@tonic-gate 155*7c478bd9Sstevel@tonic-gate tchar ** 156*7c478bd9Sstevel@tonic-gate blkcpy(oav, bv) 157*7c478bd9Sstevel@tonic-gate tchar **oav; 158*7c478bd9Sstevel@tonic-gate register tchar **bv; 159*7c478bd9Sstevel@tonic-gate { 160*7c478bd9Sstevel@tonic-gate register tchar **av = oav; 161*7c478bd9Sstevel@tonic-gate 162*7c478bd9Sstevel@tonic-gate while (*av++ = *bv++) 163*7c478bd9Sstevel@tonic-gate continue; 164*7c478bd9Sstevel@tonic-gate return (oav); 165*7c478bd9Sstevel@tonic-gate } 166*7c478bd9Sstevel@tonic-gate 167*7c478bd9Sstevel@tonic-gate tchar ** 168*7c478bd9Sstevel@tonic-gate blkcat(up, vp) 169*7c478bd9Sstevel@tonic-gate tchar **up, **vp; 170*7c478bd9Sstevel@tonic-gate { 171*7c478bd9Sstevel@tonic-gate 172*7c478bd9Sstevel@tonic-gate (void) blkcpy(blkend(up), vp); 173*7c478bd9Sstevel@tonic-gate return (up); 174*7c478bd9Sstevel@tonic-gate } 175*7c478bd9Sstevel@tonic-gate 176*7c478bd9Sstevel@tonic-gate blkfree(av0) 177*7c478bd9Sstevel@tonic-gate tchar **av0; 178*7c478bd9Sstevel@tonic-gate { 179*7c478bd9Sstevel@tonic-gate register tchar **av = av0; 180*7c478bd9Sstevel@tonic-gate 181*7c478bd9Sstevel@tonic-gate for (; *av; av++) 182*7c478bd9Sstevel@tonic-gate XFREE(*av) 183*7c478bd9Sstevel@tonic-gate XFREE((tchar *)av0) 184*7c478bd9Sstevel@tonic-gate } 185*7c478bd9Sstevel@tonic-gate 186*7c478bd9Sstevel@tonic-gate tchar ** 187*7c478bd9Sstevel@tonic-gate saveblk(v) 188*7c478bd9Sstevel@tonic-gate register tchar **v; 189*7c478bd9Sstevel@tonic-gate { 190*7c478bd9Sstevel@tonic-gate register tchar **newv = 191*7c478bd9Sstevel@tonic-gate (tchar **) calloc((unsigned) (blklen(v) + 1), 192*7c478bd9Sstevel@tonic-gate sizeof (tchar **)); 193*7c478bd9Sstevel@tonic-gate tchar **onewv = newv; 194*7c478bd9Sstevel@tonic-gate 195*7c478bd9Sstevel@tonic-gate while (*v) 196*7c478bd9Sstevel@tonic-gate *newv++ = savestr(*v++); 197*7c478bd9Sstevel@tonic-gate return (onewv); 198*7c478bd9Sstevel@tonic-gate } 199*7c478bd9Sstevel@tonic-gate 200*7c478bd9Sstevel@tonic-gate tchar * 201*7c478bd9Sstevel@tonic-gate strspl(cp, dp) 202*7c478bd9Sstevel@tonic-gate tchar *cp, *dp; 203*7c478bd9Sstevel@tonic-gate { 204*7c478bd9Sstevel@tonic-gate tchar *ep; 205*7c478bd9Sstevel@tonic-gate register tchar *p, *q; 206*7c478bd9Sstevel@tonic-gate 207*7c478bd9Sstevel@tonic-gate #ifndef m32 208*7c478bd9Sstevel@tonic-gate for (p = cp; *p++; ) 209*7c478bd9Sstevel@tonic-gate ; 210*7c478bd9Sstevel@tonic-gate for (q = dp; *q++; ) 211*7c478bd9Sstevel@tonic-gate ; 212*7c478bd9Sstevel@tonic-gate ep = (tchar *) xalloc((unsigned) (((p - cp) + 213*7c478bd9Sstevel@tonic-gate (q - dp) - 1))*sizeof (tchar)); 214*7c478bd9Sstevel@tonic-gate for (p = ep, q = cp; *p++ = *q++; ) 215*7c478bd9Sstevel@tonic-gate ; 216*7c478bd9Sstevel@tonic-gate for (p--, q = dp; *p++ = *q++; ) 217*7c478bd9Sstevel@tonic-gate ; 218*7c478bd9Sstevel@tonic-gate #else 219*7c478bd9Sstevel@tonic-gate int len1 = strlen_(cp); 220*7c478bd9Sstevel@tonic-gate int len2 = strlen_(dp); 221*7c478bd9Sstevel@tonic-gate 222*7c478bd9Sstevel@tonic-gate ep = (tchar *)xalloc((unsigned) (len1 + len2 + 1)*sizeof (tchar)); 223*7c478bd9Sstevel@tonic-gate strcpy_(ep, cp); 224*7c478bd9Sstevel@tonic-gate strcat_(ep, dp); 225*7c478bd9Sstevel@tonic-gate #endif 226*7c478bd9Sstevel@tonic-gate return (ep); 227*7c478bd9Sstevel@tonic-gate } 228*7c478bd9Sstevel@tonic-gate 229*7c478bd9Sstevel@tonic-gate tchar ** 230*7c478bd9Sstevel@tonic-gate blkspl(up, vp) 231*7c478bd9Sstevel@tonic-gate register tchar **up, **vp; 232*7c478bd9Sstevel@tonic-gate { 233*7c478bd9Sstevel@tonic-gate register tchar **wp = 234*7c478bd9Sstevel@tonic-gate (tchar **) calloc((unsigned) (blklen(up) + blklen(vp) + 1), 235*7c478bd9Sstevel@tonic-gate sizeof (tchar **)); 236*7c478bd9Sstevel@tonic-gate 237*7c478bd9Sstevel@tonic-gate (void) blkcpy(wp, up); 238*7c478bd9Sstevel@tonic-gate return (blkcat(wp, vp)); 239*7c478bd9Sstevel@tonic-gate } 240*7c478bd9Sstevel@tonic-gate 241*7c478bd9Sstevel@tonic-gate lastchr(cp) 242*7c478bd9Sstevel@tonic-gate register tchar *cp; 243*7c478bd9Sstevel@tonic-gate { 244*7c478bd9Sstevel@tonic-gate 245*7c478bd9Sstevel@tonic-gate if (!*cp) 246*7c478bd9Sstevel@tonic-gate return (0); 247*7c478bd9Sstevel@tonic-gate while (cp[1]) 248*7c478bd9Sstevel@tonic-gate cp++; 249*7c478bd9Sstevel@tonic-gate return (*cp); 250*7c478bd9Sstevel@tonic-gate } 251*7c478bd9Sstevel@tonic-gate 252*7c478bd9Sstevel@tonic-gate donefds() 253*7c478bd9Sstevel@tonic-gate { 254*7c478bd9Sstevel@tonic-gate (void) close(0); 255*7c478bd9Sstevel@tonic-gate (void) close(1); 256*7c478bd9Sstevel@tonic-gate (void) close(2); 257*7c478bd9Sstevel@tonic-gate 258*7c478bd9Sstevel@tonic-gate /* 259*7c478bd9Sstevel@tonic-gate * To avoid NIS+ functions to get hold of 0/1/2, 260*7c478bd9Sstevel@tonic-gate * use descriptor 0, and dup it to 1 and 2. 261*7c478bd9Sstevel@tonic-gate */ 262*7c478bd9Sstevel@tonic-gate open("/dev/null", 0); 263*7c478bd9Sstevel@tonic-gate dup(0); dup(0); 264*7c478bd9Sstevel@tonic-gate didfds = 0; 265*7c478bd9Sstevel@tonic-gate } 266*7c478bd9Sstevel@tonic-gate 267*7c478bd9Sstevel@tonic-gate /* 268*7c478bd9Sstevel@tonic-gate * Move descriptor i to j. 269*7c478bd9Sstevel@tonic-gate * If j is -1 then we just want to get i to a safe place, 270*7c478bd9Sstevel@tonic-gate * i.e. to a unit > 2. This also happens in dcopy. 271*7c478bd9Sstevel@tonic-gate */ 272*7c478bd9Sstevel@tonic-gate dmove(i, j) 273*7c478bd9Sstevel@tonic-gate register int i, j; 274*7c478bd9Sstevel@tonic-gate { 275*7c478bd9Sstevel@tonic-gate int fd; 276*7c478bd9Sstevel@tonic-gate 277*7c478bd9Sstevel@tonic-gate if (i == j || i < 0) 278*7c478bd9Sstevel@tonic-gate return (i); 279*7c478bd9Sstevel@tonic-gate if (j >= 0) { 280*7c478bd9Sstevel@tonic-gate fd = dup2(i, j); 281*7c478bd9Sstevel@tonic-gate if (fd != -1) 282*7c478bd9Sstevel@tonic-gate setfd(fd); 283*7c478bd9Sstevel@tonic-gate } else 284*7c478bd9Sstevel@tonic-gate j = dcopy(i, j); 285*7c478bd9Sstevel@tonic-gate if (j != i) { 286*7c478bd9Sstevel@tonic-gate (void) close(i); 287*7c478bd9Sstevel@tonic-gate unsetfd(i); 288*7c478bd9Sstevel@tonic-gate } 289*7c478bd9Sstevel@tonic-gate return (j); 290*7c478bd9Sstevel@tonic-gate } 291*7c478bd9Sstevel@tonic-gate 292*7c478bd9Sstevel@tonic-gate dcopy(i, j) 293*7c478bd9Sstevel@tonic-gate register int i, j; 294*7c478bd9Sstevel@tonic-gate { 295*7c478bd9Sstevel@tonic-gate 296*7c478bd9Sstevel@tonic-gate int fd; 297*7c478bd9Sstevel@tonic-gate 298*7c478bd9Sstevel@tonic-gate if (i == j || i < 0 || j < 0 && i > 2) 299*7c478bd9Sstevel@tonic-gate return (i); 300*7c478bd9Sstevel@tonic-gate if (j >= 0) { 301*7c478bd9Sstevel@tonic-gate fd = dup2(i, j); 302*7c478bd9Sstevel@tonic-gate if (fd != -1) 303*7c478bd9Sstevel@tonic-gate setfd(fd); 304*7c478bd9Sstevel@tonic-gate return (j); 305*7c478bd9Sstevel@tonic-gate } 306*7c478bd9Sstevel@tonic-gate (void) close(j); 307*7c478bd9Sstevel@tonic-gate unsetfd(j); 308*7c478bd9Sstevel@tonic-gate return (renum(i, j)); 309*7c478bd9Sstevel@tonic-gate } 310*7c478bd9Sstevel@tonic-gate 311*7c478bd9Sstevel@tonic-gate renum(i, j) 312*7c478bd9Sstevel@tonic-gate register int i, j; 313*7c478bd9Sstevel@tonic-gate { 314*7c478bd9Sstevel@tonic-gate register int k = dup(i); 315*7c478bd9Sstevel@tonic-gate 316*7c478bd9Sstevel@tonic-gate if (k < 0) 317*7c478bd9Sstevel@tonic-gate return (-1); 318*7c478bd9Sstevel@tonic-gate if (j == -1 && k > 2) { 319*7c478bd9Sstevel@tonic-gate setfd(k); 320*7c478bd9Sstevel@tonic-gate return (k); 321*7c478bd9Sstevel@tonic-gate } 322*7c478bd9Sstevel@tonic-gate if (k != j) { 323*7c478bd9Sstevel@tonic-gate j = renum(k, j); 324*7c478bd9Sstevel@tonic-gate (void) close(k); /* no need ofr unsetfd() */ 325*7c478bd9Sstevel@tonic-gate return (j); 326*7c478bd9Sstevel@tonic-gate } 327*7c478bd9Sstevel@tonic-gate return (k); 328*7c478bd9Sstevel@tonic-gate } 329*7c478bd9Sstevel@tonic-gate 330*7c478bd9Sstevel@tonic-gate #ifndef copy 331*7c478bd9Sstevel@tonic-gate copy(to, from, size) 332*7c478bd9Sstevel@tonic-gate register tchar *to, *from; 333*7c478bd9Sstevel@tonic-gate register int size; 334*7c478bd9Sstevel@tonic-gate { 335*7c478bd9Sstevel@tonic-gate 336*7c478bd9Sstevel@tonic-gate if (size) 337*7c478bd9Sstevel@tonic-gate do 338*7c478bd9Sstevel@tonic-gate *to++ = *from++; 339*7c478bd9Sstevel@tonic-gate while (--size != 0); 340*7c478bd9Sstevel@tonic-gate } 341*7c478bd9Sstevel@tonic-gate #endif 342*7c478bd9Sstevel@tonic-gate 343*7c478bd9Sstevel@tonic-gate /* 344*7c478bd9Sstevel@tonic-gate * Left shift a command argument list, discarding 345*7c478bd9Sstevel@tonic-gate * the first c arguments. Used in "shift" commands 346*7c478bd9Sstevel@tonic-gate * as well as by commands like "repeat". 347*7c478bd9Sstevel@tonic-gate */ 348*7c478bd9Sstevel@tonic-gate lshift(v, c) 349*7c478bd9Sstevel@tonic-gate register tchar **v; 350*7c478bd9Sstevel@tonic-gate register int c; 351*7c478bd9Sstevel@tonic-gate { 352*7c478bd9Sstevel@tonic-gate register tchar **u = v; 353*7c478bd9Sstevel@tonic-gate 354*7c478bd9Sstevel@tonic-gate while (*u && --c >= 0) 355*7c478bd9Sstevel@tonic-gate xfree(*u++); 356*7c478bd9Sstevel@tonic-gate (void) blkcpy(v, u); 357*7c478bd9Sstevel@tonic-gate } 358*7c478bd9Sstevel@tonic-gate 359*7c478bd9Sstevel@tonic-gate number(cp) 360*7c478bd9Sstevel@tonic-gate tchar *cp; 361*7c478bd9Sstevel@tonic-gate { 362*7c478bd9Sstevel@tonic-gate 363*7c478bd9Sstevel@tonic-gate if (*cp == '-') { 364*7c478bd9Sstevel@tonic-gate cp++; 365*7c478bd9Sstevel@tonic-gate if (!digit(*cp++)) 366*7c478bd9Sstevel@tonic-gate return (0); 367*7c478bd9Sstevel@tonic-gate } 368*7c478bd9Sstevel@tonic-gate while (*cp && digit(*cp)) 369*7c478bd9Sstevel@tonic-gate cp++; 370*7c478bd9Sstevel@tonic-gate return (*cp == 0); 371*7c478bd9Sstevel@tonic-gate } 372*7c478bd9Sstevel@tonic-gate 373*7c478bd9Sstevel@tonic-gate tchar ** 374*7c478bd9Sstevel@tonic-gate copyblk(v) 375*7c478bd9Sstevel@tonic-gate register tchar **v; 376*7c478bd9Sstevel@tonic-gate { 377*7c478bd9Sstevel@tonic-gate register tchar **nv = 378*7c478bd9Sstevel@tonic-gate (tchar **) calloc((unsigned) (blklen(v) + 1), 379*7c478bd9Sstevel@tonic-gate sizeof (tchar **)); 380*7c478bd9Sstevel@tonic-gate 381*7c478bd9Sstevel@tonic-gate return (blkcpy(nv, v)); 382*7c478bd9Sstevel@tonic-gate } 383*7c478bd9Sstevel@tonic-gate 384*7c478bd9Sstevel@tonic-gate tchar * 385*7c478bd9Sstevel@tonic-gate strend(cp) 386*7c478bd9Sstevel@tonic-gate register tchar *cp; 387*7c478bd9Sstevel@tonic-gate { 388*7c478bd9Sstevel@tonic-gate 389*7c478bd9Sstevel@tonic-gate while (*cp) 390*7c478bd9Sstevel@tonic-gate cp++; 391*7c478bd9Sstevel@tonic-gate return (cp); 392*7c478bd9Sstevel@tonic-gate } 393*7c478bd9Sstevel@tonic-gate 394*7c478bd9Sstevel@tonic-gate tchar * 395*7c478bd9Sstevel@tonic-gate strip(cp) 396*7c478bd9Sstevel@tonic-gate tchar *cp; 397*7c478bd9Sstevel@tonic-gate { 398*7c478bd9Sstevel@tonic-gate register tchar *dp = cp; 399*7c478bd9Sstevel@tonic-gate 400*7c478bd9Sstevel@tonic-gate while (*dp++ &= TRIM) 401*7c478bd9Sstevel@tonic-gate continue; 402*7c478bd9Sstevel@tonic-gate return (cp); 403*7c478bd9Sstevel@tonic-gate } 404*7c478bd9Sstevel@tonic-gate 405*7c478bd9Sstevel@tonic-gate udvar(name) 406*7c478bd9Sstevel@tonic-gate tchar *name; 407*7c478bd9Sstevel@tonic-gate { 408*7c478bd9Sstevel@tonic-gate 409*7c478bd9Sstevel@tonic-gate setname(name); 410*7c478bd9Sstevel@tonic-gate bferr("Undefined variable"); 411*7c478bd9Sstevel@tonic-gate } 412*7c478bd9Sstevel@tonic-gate 413*7c478bd9Sstevel@tonic-gate prefix(sub, str) 414*7c478bd9Sstevel@tonic-gate register tchar *sub, *str; 415*7c478bd9Sstevel@tonic-gate { 416*7c478bd9Sstevel@tonic-gate 417*7c478bd9Sstevel@tonic-gate for (;;) { 418*7c478bd9Sstevel@tonic-gate if (*sub == 0) 419*7c478bd9Sstevel@tonic-gate return (1); 420*7c478bd9Sstevel@tonic-gate if (*str == 0) 421*7c478bd9Sstevel@tonic-gate return (0); 422*7c478bd9Sstevel@tonic-gate if (*sub++ != *str++) 423*7c478bd9Sstevel@tonic-gate return (0); 424*7c478bd9Sstevel@tonic-gate } 425*7c478bd9Sstevel@tonic-gate } 426*7c478bd9Sstevel@tonic-gate 427*7c478bd9Sstevel@tonic-gate /* 428*7c478bd9Sstevel@tonic-gate * blk*_ routines 429*7c478bd9Sstevel@tonic-gate */ 430*7c478bd9Sstevel@tonic-gate 431*7c478bd9Sstevel@tonic-gate char ** 432*7c478bd9Sstevel@tonic-gate blkend_(up) 433*7c478bd9Sstevel@tonic-gate register char **up; 434*7c478bd9Sstevel@tonic-gate { 435*7c478bd9Sstevel@tonic-gate 436*7c478bd9Sstevel@tonic-gate while (*up) 437*7c478bd9Sstevel@tonic-gate up++; 438*7c478bd9Sstevel@tonic-gate return (up); 439*7c478bd9Sstevel@tonic-gate } 440*7c478bd9Sstevel@tonic-gate 441*7c478bd9Sstevel@tonic-gate blklen_(av) 442*7c478bd9Sstevel@tonic-gate register char **av; 443*7c478bd9Sstevel@tonic-gate { 444*7c478bd9Sstevel@tonic-gate register int i = 0; 445*7c478bd9Sstevel@tonic-gate 446*7c478bd9Sstevel@tonic-gate while (*av++) 447*7c478bd9Sstevel@tonic-gate i++; 448*7c478bd9Sstevel@tonic-gate return (i); 449*7c478bd9Sstevel@tonic-gate } 450*7c478bd9Sstevel@tonic-gate 451*7c478bd9Sstevel@tonic-gate char ** 452*7c478bd9Sstevel@tonic-gate blkcpy_(oav, bv) 453*7c478bd9Sstevel@tonic-gate char **oav; 454*7c478bd9Sstevel@tonic-gate register char **bv; 455*7c478bd9Sstevel@tonic-gate { 456*7c478bd9Sstevel@tonic-gate register char **av = oav; 457*7c478bd9Sstevel@tonic-gate 458*7c478bd9Sstevel@tonic-gate while (*av++ = *bv++) 459*7c478bd9Sstevel@tonic-gate continue; 460*7c478bd9Sstevel@tonic-gate return (oav); 461*7c478bd9Sstevel@tonic-gate } 462*7c478bd9Sstevel@tonic-gate 463*7c478bd9Sstevel@tonic-gate char ** 464*7c478bd9Sstevel@tonic-gate blkcat_(up, vp) 465*7c478bd9Sstevel@tonic-gate char **up, **vp; 466*7c478bd9Sstevel@tonic-gate { 467*7c478bd9Sstevel@tonic-gate 468*7c478bd9Sstevel@tonic-gate (void) blkcpy_(blkend_(up), vp); 469*7c478bd9Sstevel@tonic-gate return (up); 470*7c478bd9Sstevel@tonic-gate } 471*7c478bd9Sstevel@tonic-gate 472*7c478bd9Sstevel@tonic-gate char ** 473*7c478bd9Sstevel@tonic-gate blkspl_(up, vp) 474*7c478bd9Sstevel@tonic-gate register char **up, **vp; 475*7c478bd9Sstevel@tonic-gate { 476*7c478bd9Sstevel@tonic-gate register char **wp = 477*7c478bd9Sstevel@tonic-gate (char **) calloc((unsigned) (blklen_(up) + blklen_(vp) + 1), 478*7c478bd9Sstevel@tonic-gate sizeof (char **)); 479*7c478bd9Sstevel@tonic-gate 480*7c478bd9Sstevel@tonic-gate (void) blkcpy_(wp, up); 481*7c478bd9Sstevel@tonic-gate return (blkcat_(wp, vp)); 482*7c478bd9Sstevel@tonic-gate } 483