home *** CD-ROM | disk | FTP | other *** search
- From: lwall@netlabs.com (Larry Wall)
- Newsgroups: comp.sources.misc
- Subject: v18i033: perl - The perl programming language, Part15/36
- Message-ID: <1991Apr16.000130.23012@sparky.IMD.Sterling.COM>
- Date: 16 Apr 91 00:01:30 GMT
- Approved: kent@sparky.imd.sterling.com
- X-Checksum-Snefru: 240705d4 4f939858 e1bffa83 a217750d
-
- Submitted-by: Larry Wall <lwall@netlabs.com>
- Posting-number: Volume 18, Issue 33
- Archive-name: perl/part15
-
- [There are 36 kits for perl version 4.0.]
-
- #! /bin/sh
-
- # Make a new directory for the perl sources, cd to it, and run kits 1
- # thru 36 through sh. When all 36 kits have been run, read README.
-
- echo "This is perl 4.0 kit 15 (of 36). If kit 15 is complete, the line"
- echo '"'"End of kit 15 (of 36)"'" will echo at the end.'
- echo ""
- export PATH || (echo "You didn't use sh, you clunch." ; kill $$)
- mkdir t t/cmd 2>/dev/null
- echo Extracting str.c
- sed >str.c <<'!STUFFY!FUNK!' -e 's/X//'
- X/* $RCSfile: str.c,v $$Revision: 4.0.1.1 $$Date: 91/04/12 09:15:30 $
- X *
- X * Copyright (c) 1989, Larry Wall
- X *
- X * You may distribute under the terms of the GNU General Public License
- X * as specified in the README file that comes with the perl 3.0 kit.
- X *
- X * $Log: str.c,v $
- X * Revision 4.0.1.1 91/04/12 09:15:30 lwall
- X * patch1: fixed undefined environ problem
- X * patch1: substr($ENV{"PATH"},0,0) = "/foo:" didn't modify environment
- X * patch1: $foo .= <BAR> could cause core dump for certain lengths of $foo
- X *
- X * Revision 4.0 91/03/20 01:39:55 lwall
- X * 4.0 baseline.
- X *
- X */
- X
- X#include "EXTERN.h"
- X#include "perl.h"
- X#include "perly.h"
- X
- X#ifndef str_get
- Xchar *
- Xstr_get(str)
- XSTR *str;
- X{
- X#ifdef TAINT
- X tainted |= str->str_tainted;
- X#endif
- X return str->str_pok ? str->str_ptr : str_2ptr(str);
- X}
- X#endif
- X
- X/* dlb ... guess we have a "crippled cc".
- X * dlb the following functions are usually macros.
- X */
- X#ifndef str_true
- Xstr_true(Str)
- XSTR *Str;
- X{
- X if (Str->str_pok) {
- X if (*Str->str_ptr > '0' ||
- X Str->str_cur > 1 ||
- X (Str->str_cur && *Str->str_ptr != '0'))
- X return 1;
- X return 0;
- X }
- X if (Str->str_nok)
- X return (Str->str_u.str_nval != 0.0);
- X return 0;
- X}
- X#endif /* str_true */
- X
- X#ifndef str_gnum
- Xdouble str_gnum(Str)
- XSTR *Str;
- X{
- X#ifdef TAINT
- X tainted |= Str->str_tainted;
- X#endif /* TAINT*/
- X if (Str->str_nok)
- X return Str->str_u.str_nval;
- X return str_2num(Str);
- X}
- X#endif /* str_gnum */
- X/* dlb ... end of crutch */
- X
- Xchar *
- Xstr_grow(str,newlen)
- Xregister STR *str;
- X#ifndef MSDOS
- Xregister int newlen;
- X#else
- Xunsigned long newlen;
- X#endif
- X{
- X register char *s = str->str_ptr;
- X
- X#ifdef MSDOS
- X if (newlen >= 0x10000) {
- X fprintf(stderr, "Allocation too large: %lx\n", newlen);
- X exit(1);
- X }
- X#endif /* MSDOS */
- X if (str->str_state == SS_INCR) { /* data before str_ptr? */
- X str->str_len += str->str_u.str_useful;
- X str->str_ptr -= str->str_u.str_useful;
- X str->str_u.str_useful = 0L;
- X bcopy(s, str->str_ptr, str->str_cur+1);
- X s = str->str_ptr;
- X str->str_state = SS_NORM; /* normal again */
- X if (newlen > str->str_len)
- X newlen += 10 * (newlen - str->str_cur); /* avoid copy each time */
- X }
- X if (newlen > str->str_len) { /* need more room? */
- X if (str->str_len)
- X Renew(s,newlen,char);
- X else
- X New(703,s,newlen,char);
- X str->str_ptr = s;
- X str->str_len = newlen;
- X }
- X return s;
- X}
- X
- Xstr_numset(str,num)
- Xregister STR *str;
- Xdouble num;
- X{
- X if (str->str_pok) {
- X str->str_pok = 0; /* invalidate pointer */
- X if (str->str_state == SS_INCR)
- X Str_Grow(str,0);
- X }
- X str->str_u.str_nval = num;
- X str->str_state = SS_NORM;
- X str->str_nok = 1; /* validate number */
- X#ifdef TAINT
- X str->str_tainted = tainted;
- X#endif
- X}
- X
- Xchar *
- Xstr_2ptr(str)
- Xregister STR *str;
- X{
- X register char *s;
- X int olderrno;
- X
- X if (!str)
- X return "";
- X if (str->str_nok) {
- X STR_GROW(str, 30);
- X s = str->str_ptr;
- X olderrno = errno; /* some Xenix systems wipe out errno here */
- X#if defined(scs) && defined(ns32000)
- X gcvt(str->str_u.str_nval,20,s);
- X#else
- X#ifdef apollo
- X if (str->str_u.str_nval == 0.0)
- X (void)strcpy(s,"0");
- X else
- X#endif /*apollo*/
- X (void)sprintf(s,"%.20g",str->str_u.str_nval);
- X#endif /*scs*/
- X errno = olderrno;
- X while (*s) s++;
- X#ifdef hcx
- X if (s[-1] == '.')
- X s--;
- X#endif
- X }
- X else {
- X if (str == &str_undef)
- X return No;
- X if (dowarn)
- X warn("Use of uninitialized variable");
- X STR_GROW(str, 30);
- X s = str->str_ptr;
- X }
- X *s = '\0';
- X str->str_cur = s - str->str_ptr;
- X str->str_pok = 1;
- X#ifdef DEBUGGING
- X if (debug & 32)
- X fprintf(stderr,"0x%lx ptr(%s)\n",str,str->str_ptr);
- X#endif
- X return str->str_ptr;
- X}
- X
- Xdouble
- Xstr_2num(str)
- Xregister STR *str;
- X{
- X if (!str)
- X return 0.0;
- X if (str->str_state == SS_INCR)
- X Str_Grow(str,0); /* just force copy down */
- X str->str_state = SS_NORM;
- X if (str->str_len && str->str_pok)
- X str->str_u.str_nval = atof(str->str_ptr);
- X else {
- X if (str == &str_undef)
- X return 0.0;
- X if (dowarn)
- X warn("Use of uninitialized variable");
- X str->str_u.str_nval = 0.0;
- X }
- X str->str_nok = 1;
- X#ifdef DEBUGGING
- X if (debug & 32)
- X fprintf(stderr,"0x%lx num(%g)\n",str,str->str_u.str_nval);
- X#endif
- X return str->str_u.str_nval;
- X}
- X
- X/* Note: str_sset() should not be called with a source string that needs
- X * be reused, since it may destroy the source string if it is marked
- X * as temporary.
- X */
- X
- Xstr_sset(dstr,sstr)
- XSTR *dstr;
- Xregister STR *sstr;
- X{
- X#ifdef TAINT
- X if (sstr)
- X tainted |= sstr->str_tainted;
- X#endif
- X if (sstr == dstr || dstr == &str_undef)
- X return;
- X if (!sstr)
- X dstr->str_pok = dstr->str_nok = 0;
- X else if (sstr->str_pok) {
- X
- X /*
- X * Check to see if we can just swipe the string. If so, it's a
- X * possible small lose on short strings, but a big win on long ones.
- X * It might even be a win on short strings if dstr->str_ptr
- X * has to be allocated and sstr->str_ptr has to be freed.
- X */
- X
- X if (sstr->str_pok & SP_TEMP) { /* slated for free anyway? */
- X if (dstr->str_ptr) {
- X if (dstr->str_state == SS_INCR)
- X dstr->str_ptr -= dstr->str_u.str_useful;
- X Safefree(dstr->str_ptr);
- X }
- X dstr->str_ptr = sstr->str_ptr;
- X dstr->str_len = sstr->str_len;
- X dstr->str_cur = sstr->str_cur;
- X dstr->str_state = sstr->str_state;
- X dstr->str_pok = sstr->str_pok & ~SP_TEMP;
- X#ifdef TAINT
- X dstr->str_tainted = sstr->str_tainted;
- X#endif
- X sstr->str_ptr = Nullch;
- X sstr->str_len = 0;
- X sstr->str_pok = 0; /* wipe out any weird flags */
- X sstr->str_state = 0; /* so sstr frees uneventfully */
- X }
- X else { /* have to copy actual string */
- X if (dstr->str_ptr) {
- X if (dstr->str_state == SS_INCR) {
- X Str_Grow(dstr,0);
- X }
- X }
- X str_nset(dstr,sstr->str_ptr,sstr->str_cur);
- X }
- X if (dstr->str_nok = sstr->str_nok)
- X dstr->str_u.str_nval = sstr->str_u.str_nval;
- X else {
- X#ifdef STRUCTCOPY
- X dstr->str_u = sstr->str_u;
- X#else
- X dstr->str_u.str_nval = sstr->str_u.str_nval;
- X#endif
- X if (dstr->str_cur == sizeof(STBP)) {
- X char *tmps = dstr->str_ptr;
- X
- X if (*tmps == 'S' && bcmp(tmps,"StB",4) == 0) {
- X if (!dstr->str_magic) {
- X dstr->str_magic = str_smake(sstr->str_magic);
- X dstr->str_magic->str_rare = 'X';
- X }
- X }
- X }
- X }
- X }
- X else if (sstr->str_nok)
- X str_numset(dstr,sstr->str_u.str_nval);
- X else {
- X if (dstr->str_state == SS_INCR)
- X Str_Grow(dstr,0); /* just force copy down */
- X
- X#ifdef STRUCTCOPY
- X dstr->str_u = sstr->str_u;
- X#else
- X dstr->str_u.str_nval = sstr->str_u.str_nval;
- X#endif
- X dstr->str_pok = dstr->str_nok = 0;
- X }
- X}
- X
- Xstr_nset(str,ptr,len)
- Xregister STR *str;
- Xregister char *ptr;
- Xregister STRLEN len;
- X{
- X if (str == &str_undef)
- X return;
- X STR_GROW(str, len + 1);
- X if (ptr)
- X (void)bcopy(ptr,str->str_ptr,len);
- X str->str_cur = len;
- X *(str->str_ptr+str->str_cur) = '\0';
- X str->str_nok = 0; /* invalidate number */
- X str->str_pok = 1; /* validate pointer */
- X#ifdef TAINT
- X str->str_tainted = tainted;
- X#endif
- X}
- X
- Xstr_set(str,ptr)
- Xregister STR *str;
- Xregister char *ptr;
- X{
- X register STRLEN len;
- X
- X if (str == &str_undef)
- X return;
- X if (!ptr)
- X ptr = "";
- X len = strlen(ptr);
- X STR_GROW(str, len + 1);
- X (void)bcopy(ptr,str->str_ptr,len+1);
- X str->str_cur = len;
- X str->str_nok = 0; /* invalidate number */
- X str->str_pok = 1; /* validate pointer */
- X#ifdef TAINT
- X str->str_tainted = tainted;
- X#endif
- X}
- X
- Xstr_chop(str,ptr) /* like set but assuming ptr is in str */
- Xregister STR *str;
- Xregister char *ptr;
- X{
- X register STRLEN delta;
- X
- X if (!ptr || !(str->str_pok))
- X return;
- X delta = ptr - str->str_ptr;
- X str->str_len -= delta;
- X str->str_cur -= delta;
- X str->str_ptr += delta;
- X if (str->str_state == SS_INCR)
- X str->str_u.str_useful += delta;
- X else {
- X str->str_u.str_useful = delta;
- X str->str_state = SS_INCR;
- X }
- X str->str_nok = 0; /* invalidate number */
- X str->str_pok = 1; /* validate pointer (and unstudy str) */
- X}
- X
- Xstr_ncat(str,ptr,len)
- Xregister STR *str;
- Xregister char *ptr;
- Xregister STRLEN len;
- X{
- X if (str == &str_undef)
- X return;
- X if (!(str->str_pok))
- X (void)str_2ptr(str);
- X STR_GROW(str, str->str_cur + len + 1);
- X (void)bcopy(ptr,str->str_ptr+str->str_cur,len);
- X str->str_cur += len;
- X *(str->str_ptr+str->str_cur) = '\0';
- X str->str_nok = 0; /* invalidate number */
- X str->str_pok = 1; /* validate pointer */
- X#ifdef TAINT
- X str->str_tainted |= tainted;
- X#endif
- X}
- X
- Xstr_scat(dstr,sstr)
- XSTR *dstr;
- Xregister STR *sstr;
- X{
- X#ifdef TAINT
- X tainted |= sstr->str_tainted;
- X#endif
- X if (!sstr)
- X return;
- X if (!(sstr->str_pok))
- X (void)str_2ptr(sstr);
- X if (sstr)
- X str_ncat(dstr,sstr->str_ptr,sstr->str_cur);
- X}
- X
- Xstr_cat(str,ptr)
- Xregister STR *str;
- Xregister char *ptr;
- X{
- X register STRLEN len;
- X
- X if (str == &str_undef)
- X return;
- X if (!ptr)
- X return;
- X if (!(str->str_pok))
- X (void)str_2ptr(str);
- X len = strlen(ptr);
- X STR_GROW(str, str->str_cur + len + 1);
- X (void)bcopy(ptr,str->str_ptr+str->str_cur,len+1);
- X str->str_cur += len;
- X str->str_nok = 0; /* invalidate number */
- X str->str_pok = 1; /* validate pointer */
- X#ifdef TAINT
- X str->str_tainted |= tainted;
- X#endif
- X}
- X
- Xchar *
- Xstr_append_till(str,from,fromend,delim,keeplist)
- Xregister STR *str;
- Xregister char *from;
- Xregister char *fromend;
- Xregister int delim;
- Xchar *keeplist;
- X{
- X register char *to;
- X register STRLEN len;
- X
- X if (str == &str_undef)
- X return Nullch;
- X if (!from)
- X return Nullch;
- X len = fromend - from;
- X STR_GROW(str, str->str_cur + len + 1);
- X str->str_nok = 0; /* invalidate number */
- X str->str_pok = 1; /* validate pointer */
- X to = str->str_ptr+str->str_cur;
- X for (; from < fromend; from++,to++) {
- X if (*from == '\\' && from+1 < fromend && delim != '\\') {
- X if (!keeplist) {
- X if (from[1] == delim || from[1] == '\\')
- X from++;
- X else
- X *to++ = *from++;
- X }
- X else if (from[1] && index(keeplist,from[1]))
- X *to++ = *from++;
- X else
- X from++;
- X }
- X else if (*from == delim)
- X break;
- X *to = *from;
- X }
- X *to = '\0';
- X str->str_cur = to - str->str_ptr;
- X return from;
- X}
- X
- XSTR *
- X#ifdef LEAKTEST
- Xstr_new(x,len)
- Xint x;
- X#else
- Xstr_new(len)
- X#endif
- XSTRLEN len;
- X{
- X register STR *str;
- X
- X if (freestrroot) {
- X str = freestrroot;
- X freestrroot = str->str_magic;
- X str->str_magic = Nullstr;
- X str->str_state = SS_NORM;
- X }
- X else {
- X Newz(700+x,str,1,STR);
- X }
- X if (len)
- X STR_GROW(str, len + 1);
- X return str;
- X}
- X
- Xvoid
- Xstr_magic(str, stab, how, name, namlen)
- Xregister STR *str;
- XSTAB *stab;
- Xint how;
- Xchar *name;
- XSTRLEN namlen;
- X{
- X if (str == &str_undef || str->str_magic)
- X return;
- X str->str_magic = Str_new(75,namlen);
- X str = str->str_magic;
- X str->str_u.str_stab = stab;
- X str->str_rare = how;
- X if (name)
- X str_nset(str,name,namlen);
- X}
- X
- Xvoid
- Xstr_insert(bigstr,offset,len,little,littlelen)
- XSTR *bigstr;
- XSTRLEN offset;
- XSTRLEN len;
- Xchar *little;
- XSTRLEN littlelen;
- X{
- X register char *big;
- X register char *mid;
- X register char *midend;
- X register char *bigend;
- X register int i;
- X
- X if (bigstr == &str_undef)
- X return;
- X bigstr->str_nok = 0;
- X bigstr->str_pok = SP_VALID; /* disable possible screamer */
- X
- X i = littlelen - len;
- X if (i > 0) { /* string might grow */
- X STR_GROW(bigstr, bigstr->str_cur + i + 1);
- X big = bigstr->str_ptr;
- X mid = big + offset + len;
- X midend = bigend = big + bigstr->str_cur;
- X bigend += i;
- X *bigend = '\0';
- X while (midend > mid) /* shove everything down */
- X *--bigend = *--midend;
- X (void)bcopy(little,big+offset,littlelen);
- X bigstr->str_cur += i;
- X STABSET(bigstr);
- X return;
- X }
- X else if (i == 0) {
- X (void)bcopy(little,bigstr->str_ptr+offset,len);
- X STABSET(bigstr);
- X return;
- X }
- X
- X big = bigstr->str_ptr;
- X mid = big + offset;
- X midend = mid + len;
- X bigend = big + bigstr->str_cur;
- X
- X if (midend > bigend)
- X fatal("panic: str_insert");
- X
- X if (mid - big > bigend - midend) { /* faster to shorten from end */
- X if (littlelen) {
- X (void)bcopy(little, mid, littlelen);
- X mid += littlelen;
- X }
- X i = bigend - midend;
- X if (i > 0) {
- X (void)bcopy(midend, mid, i);
- X mid += i;
- X }
- X *mid = '\0';
- X bigstr->str_cur = mid - big;
- X }
- X else if (i = mid - big) { /* faster from front */
- X midend -= littlelen;
- X mid = midend;
- X str_chop(bigstr,midend-i);
- X big += i;
- X while (i--)
- X *--midend = *--big;
- X if (littlelen)
- X (void)bcopy(little, mid, littlelen);
- X }
- X else if (littlelen) {
- X midend -= littlelen;
- X str_chop(bigstr,midend);
- X (void)bcopy(little,midend,littlelen);
- X }
- X else {
- X str_chop(bigstr,midend);
- X }
- X STABSET(bigstr);
- X}
- X
- X/* make str point to what nstr did */
- X
- Xvoid
- Xstr_replace(str,nstr)
- Xregister STR *str;
- Xregister STR *nstr;
- X{
- X if (str == &str_undef)
- X return;
- X if (str->str_state == SS_INCR)
- X Str_Grow(str,0); /* just force copy down */
- X if (nstr->str_state == SS_INCR)
- X Str_Grow(nstr,0);
- X if (str->str_ptr)
- X Safefree(str->str_ptr);
- X str->str_ptr = nstr->str_ptr;
- X str->str_len = nstr->str_len;
- X str->str_cur = nstr->str_cur;
- X str->str_pok = nstr->str_pok;
- X str->str_nok = nstr->str_nok;
- X#ifdef STRUCTCOPY
- X str->str_u = nstr->str_u;
- X#else
- X str->str_u.str_nval = nstr->str_u.str_nval;
- X#endif
- X#ifdef TAINT
- X str->str_tainted = nstr->str_tainted;
- X#endif
- X if (nstr->str_magic)
- X str_free(nstr->str_magic);
- X Safefree(nstr);
- X}
- X
- Xvoid
- Xstr_free(str)
- Xregister STR *str;
- X{
- X if (!str || str == &str_undef)
- X return;
- X if (str->str_state) {
- X if (str->str_state == SS_FREE) /* already freed */
- X return;
- X if (str->str_state == SS_INCR && !(str->str_pok & 2)) {
- X str->str_ptr -= str->str_u.str_useful;
- X str->str_len += str->str_u.str_useful;
- X }
- X }
- X if (str->str_magic)
- X str_free(str->str_magic);
- X str->str_magic = freestrroot;
- X#ifdef LEAKTEST
- X if (str->str_len) {
- X Safefree(str->str_ptr);
- X str->str_ptr = Nullch;
- X }
- X if ((str->str_pok & SP_INTRP) && str->str_u.str_args)
- X arg_free(str->str_u.str_args);
- X Safefree(str);
- X#else /* LEAKTEST */
- X if (str->str_len) {
- X if (str->str_len > 127) { /* next user not likely to want more */
- X Safefree(str->str_ptr); /* so give it back to malloc */
- X str->str_ptr = Nullch;
- X str->str_len = 0;
- X }
- X else
- X str->str_ptr[0] = '\0';
- X }
- X if ((str->str_pok & SP_INTRP) && str->str_u.str_args)
- X arg_free(str->str_u.str_args);
- X str->str_cur = 0;
- X str->str_nok = 0;
- X str->str_pok = 0;
- X str->str_state = SS_FREE;
- X#ifdef TAINT
- X str->str_tainted = 0;
- X#endif
- X freestrroot = str;
- X#endif /* LEAKTEST */
- X}
- X
- XSTRLEN
- Xstr_len(str)
- Xregister STR *str;
- X{
- X if (!str)
- X return 0;
- X if (!(str->str_pok))
- X (void)str_2ptr(str);
- X if (str->str_ptr)
- X return str->str_cur;
- X else
- X return 0;
- X}
- X
- Xstr_eq(str1,str2)
- Xregister STR *str1;
- Xregister STR *str2;
- X{
- X if (!str1 || str1 == &str_undef)
- X return (str2 == Nullstr || str2 == &str_undef || !str2->str_cur);
- X if (!str2 || str2 == &str_undef)
- X return !str1->str_cur;
- X
- X if (!str1->str_pok)
- X (void)str_2ptr(str1);
- X if (!str2->str_pok)
- X (void)str_2ptr(str2);
- X
- X if (str1->str_cur != str2->str_cur)
- X return 0;
- X
- X return !bcmp(str1->str_ptr, str2->str_ptr, str1->str_cur);
- X}
- X
- Xstr_cmp(str1,str2)
- Xregister STR *str1;
- Xregister STR *str2;
- X{
- X int retval;
- X
- X if (!str1 || str1 == &str_undef)
- X return (str2 == Nullstr || str2 == &str_undef || !str2->str_cur)?0:-1;
- X if (!str2 || str2 == &str_undef)
- X return str1->str_cur != 0;
- X
- X if (!str1->str_pok)
- X (void)str_2ptr(str1);
- X if (!str2->str_pok)
- X (void)str_2ptr(str2);
- X
- X if (str1->str_cur < str2->str_cur) {
- X if (retval = memcmp(str1->str_ptr, str2->str_ptr, str1->str_cur))
- X return retval < 0 ? -1 : 1;
- X else
- X return -1;
- X }
- X else if (retval = memcmp(str1->str_ptr, str2->str_ptr, str2->str_cur))
- X return retval < 0 ? -1 : 1;
- X else if (str1->str_cur == str2->str_cur)
- X return 0;
- X else
- X return 1;
- X}
- X
- Xchar *
- Xstr_gets(str,fp,append)
- Xregister STR *str;
- Xregister FILE *fp;
- Xint append;
- X{
- X register char *bp; /* we're going to steal some values */
- X register int cnt; /* from the stdio struct and put EVERYTHING */
- X register STDCHAR *ptr; /* in the innermost loop into registers */
- X register int newline = rschar;/* (assuming >= 6 registers) */
- X int i;
- X STRLEN bpx;
- X int shortbuffered;
- X
- X if (str == &str_undef)
- X return Nullch;
- X#ifdef STDSTDIO /* Here is some breathtakingly efficient cheating */
- X cnt = fp->_cnt; /* get count into register */
- X str->str_nok = 0; /* invalidate number */
- X str->str_pok = 1; /* validate pointer */
- X if (str->str_len <= cnt + 1) { /* make sure we have the room */
- X if (cnt > 80 && str->str_len > append) {
- X shortbuffered = cnt - str->str_len + append + 1;
- X cnt -= shortbuffered;
- X }
- X else {
- X shortbuffered = 0;
- X STR_GROW(str, append+cnt+2);/* (remembering cnt can be -1) */
- X }
- X }
- X else
- X shortbuffered = 0;
- X bp = str->str_ptr + append; /* move these two too to registers */
- X ptr = fp->_ptr;
- X for (;;) {
- X screamer:
- X while (--cnt >= 0) { /* this */ /* eat */
- X if ((*bp++ = *ptr++) == newline) /* really */ /* dust */
- X goto thats_all_folks; /* screams */ /* sed :-) */
- X }
- X
- X if (shortbuffered) { /* oh well, must extend */
- X cnt = shortbuffered;
- X shortbuffered = 0;
- X bpx = bp - str->str_ptr; /* prepare for possible relocation */
- X str->str_cur = bpx;
- X STR_GROW(str, str->str_len + append + cnt + 2);
- X bp = str->str_ptr + bpx; /* reconstitute our pointer */
- X continue;
- X }
- X
- X fp->_cnt = cnt; /* deregisterize cnt and ptr */
- X fp->_ptr = ptr;
- X i = _filbuf(fp); /* get more characters */
- X cnt = fp->_cnt;
- X ptr = fp->_ptr; /* reregisterize cnt and ptr */
- X
- X bpx = bp - str->str_ptr; /* prepare for possible relocation */
- X str->str_cur = bpx;
- X STR_GROW(str, bpx + cnt + 2);
- X bp = str->str_ptr + bpx; /* reconstitute our pointer */
- X
- X if (i == newline) { /* all done for now? */
- X *bp++ = i;
- X goto thats_all_folks;
- X }
- X else if (i == EOF) /* all done for ever? */
- X goto thats_really_all_folks;
- X *bp++ = i; /* now go back to screaming loop */
- X }
- X
- Xthats_all_folks:
- X if (rslen > 1 && (bp - str->str_ptr < rslen || bcmp(bp - rslen, rs, rslen)))
- X goto screamer; /* go back to the fray */
- Xthats_really_all_folks:
- X if (shortbuffered)
- X cnt += shortbuffered;
- X fp->_cnt = cnt; /* put these back or we're in trouble */
- X fp->_ptr = ptr;
- X *bp = '\0';
- X str->str_cur = bp - str->str_ptr; /* set length */
- X
- X#else /* !STDSTDIO */ /* The big, slow, and stupid way */
- X
- X {
- X static char buf[8192];
- X char * bpe = buf + sizeof(buf) - 3;
- X
- Xscreamer:
- X bp = buf;
- X while ((i = getc(fp)) != EOF && (*bp++ = i) != newline && bp < bpe) ;
- X
- X *bp = '\0';
- X if (append)
- X str_cat(str, buf);
- X else
- X str_set(str, buf);
- X if (i != EOF /* joy */
- X &&
- X (i != newline
- X ||
- X (rslen > 1
- X &&
- X (str->str_cur < rslen
- X ||
- X bcmp(str->str_ptr + str->str_cur - rslen, rs, rslen)
- X )
- X )
- X )
- X )
- X {
- X append = -1;
- X goto screamer;
- X }
- X }
- X
- X#endif /* STDSTDIO */
- X
- X return str->str_cur - append ? str->str_ptr : Nullch;
- X}
- X
- XARG *
- Xparselist(str)
- XSTR *str;
- X{
- X register CMD *cmd;
- X register ARG *arg;
- X CMD *oldcurcmd = curcmd;
- X int oldperldb = perldb;
- X int retval;
- X
- X perldb = 0;
- X str_sset(linestr,str);
- X in_eval++;
- X oldoldbufptr = oldbufptr = bufptr = str_get(linestr);
- X bufend = bufptr + linestr->str_cur;
- X if (++loop_ptr >= loop_max) {
- X loop_max += 128;
- X Renew(loop_stack, loop_max, struct loop);
- X }
- X loop_stack[loop_ptr].loop_label = "_EVAL_";
- X loop_stack[loop_ptr].loop_sp = 0;
- X#ifdef DEBUGGING
- X if (debug & 4) {
- X deb("(Pushing label #%d _EVAL_)\n", loop_ptr);
- X }
- X#endif
- X if (setjmp(loop_stack[loop_ptr].loop_env)) {
- X in_eval--;
- X loop_ptr--;
- X perldb = oldperldb;
- X fatal("%s\n",stab_val(stabent("@",TRUE))->str_ptr);
- X }
- X#ifdef DEBUGGING
- X if (debug & 4) {
- X char *tmps = loop_stack[loop_ptr].loop_label;
- X deb("(Popping label #%d %s)\n",loop_ptr,
- X tmps ? tmps : "" );
- X }
- X#endif
- X loop_ptr--;
- X error_count = 0;
- X curcmd = &compiling;
- X curcmd->c_line = oldcurcmd->c_line;
- X retval = yyparse();
- X curcmd = oldcurcmd;
- X perldb = oldperldb;
- X in_eval--;
- X if (retval || error_count)
- X fatal("Invalid component in string or format");
- X cmd = eval_root;
- X arg = cmd->c_expr;
- X if (cmd->c_type != C_EXPR || cmd->c_next || arg->arg_type != O_LIST)
- X fatal("panic: error in parselist %d %x %d", cmd->c_type,
- X cmd->c_next, arg ? arg->arg_type : -1);
- X Safefree(cmd);
- X eval_root = Nullcmd;
- X return arg;
- X}
- X
- Xvoid
- Xintrpcompile(src)
- XSTR *src;
- X{
- X register char *s = str_get(src);
- X register char *send = s + src->str_cur;
- X register STR *str;
- X register char *t;
- X STR *toparse;
- X STRLEN len;
- X register int brackets;
- X register char *d;
- X STAB *stab;
- X char *checkpoint;
- X int sawcase = 0;
- X
- X toparse = Str_new(76,0);
- X str = Str_new(77,0);
- X
- X str_nset(str,"",0);
- X str_nset(toparse,"",0);
- X t = s;
- X while (s < send) {
- X if (*s == '\\' && s[1] && index("$@[{\\]}lLuUE",s[1])) {
- X str_ncat(str, t, s - t);
- X ++s;
- X if (isalpha(*s)) {
- X str_ncat(str, "$c", 2);
- X sawcase = (*s != 'E');
- X }
- X else {
- X if (*nointrp && s+1 < send)
- X if (*s != '@' && (*s != '$' || index(nointrp,s[1])))
- X str_ncat(str,s-1,1);
- X str_ncat(str, "$b", 2);
- X }
- X str_ncat(str, s, 1);
- X ++s;
- X t = s;
- X }
- X else if ((*s == '@' || (*s == '$' && !index(nointrp,s[1]))) &&
- X s+1 < send) {
- X str_ncat(str,t,s-t);
- X t = s;
- X if (*s == '$' && s[1] == '#' && (isalpha(s[2]) || s[2] == '_'))
- X s++;
- X s = scanident(s,send,tokenbuf);
- X if (*t == '@' &&
- X (!(stab = stabent(tokenbuf,FALSE)) ||
- X (*s == '{' ? !stab_xhash(stab) : !stab_xarray(stab)) )) {
- X str_ncat(str,"@",1);
- X s = ++t;
- X continue; /* grandfather @ from old scripts */
- X }
- X str_ncat(str,"$a",2);
- X str_ncat(toparse,",",1);
- X if (t[1] != '{' && (*s == '[' || *s == '{' /* }} */ ) &&
- X (stab = stabent(tokenbuf,FALSE)) &&
- X ((*s == '[') ? (stab_xarray(stab) != 0) : (stab_xhash(stab) != 0)) ) {
- X brackets = 0;
- X checkpoint = s;
- X do {
- X switch (*s) {
- X case '[':
- X if (s[-1] != '$')
- X brackets++;
- X break;
- X case '{':
- X brackets++;
- X break;
- X case ']':
- X if (s[-1] != '$')
- X brackets--;
- X break;
- X case '}':
- X brackets--;
- X break;
- X case '\'':
- X case '"':
- X if (s[-1] != '$') {
- X s = cpytill(tokenbuf,s+1,send,*s,&len);
- X if (s >= send)
- X fatal("Unterminated string");
- X }
- X break;
- X }
- X s++;
- X } while (brackets > 0 && s < send);
- X if (s > send)
- X fatal("Unmatched brackets in string");
- X if (*nointrp) { /* we're in a regular expression */
- X d = checkpoint;
- X if (*d == '{' && s[-1] == '}') { /* maybe {n,m} */
- X ++d;
- X if (isdigit(*d)) { /* matches /^{\d,?\d*}$/ */
- X if (*++d == ',')
- X ++d;
- X while (isdigit(*d))
- X d++;
- X if (d == s - 1)
- X s = checkpoint; /* Is {n,m}! Backoff! */
- X }
- X }
- X else if (*d == '[' && s[-1] == ']') { /* char class? */
- X int weight = 2; /* let's weigh the evidence */
- X char seen[256];
- X unsigned char un_char = 0, last_un_char;
- X
- X Zero(seen,256,char);
- X *--s = '\0';
- X if (d[1] == '^')
- X weight += 150;
- X else if (d[1] == '$')
- X weight -= 3;
- X if (isdigit(d[1])) {
- X if (d[2]) {
- X if (isdigit(d[2]) && !d[3])
- X weight -= 10;
- X }
- X else
- X weight -= 100;
- X }
- X for (d++; d < s; d++) {
- X last_un_char = un_char;
- X un_char = (unsigned char)*d;
- X switch (*d) {
- X case '&':
- X case '$':
- X weight -= seen[un_char] * 10;
- X if (isalpha(d[1]) || isdigit(d[1]) ||
- X d[1] == '_') {
- X d = scanident(d,s,tokenbuf);
- X if (stabent(tokenbuf,FALSE))
- X weight -= 100;
- X else
- X weight -= 10;
- X }
- X else if (*d == '$' && d[1] &&
- X index("[#!%*<>()-=",d[1])) {
- X if (!d[2] || /*{*/ index("])} =",d[2]))
- X weight -= 10;
- X else
- X weight -= 1;
- X }
- X break;
- X case '\\':
- X un_char = 254;
- X if (d[1]) {
- X if (index("wds",d[1]))
- X weight += 100;
- X else if (seen['\''] || seen['"'])
- X weight += 1;
- X else if (index("rnftb",d[1]))
- X weight += 40;
- X else if (isdigit(d[1])) {
- X weight += 40;
- X while (d[1] && isdigit(d[1]))
- X d++;
- X }
- X }
- X else
- X weight += 100;
- X break;
- X case '-':
- X if (last_un_char < (unsigned char) d[1]
- X || d[1] == '\\') {
- X if (index("aA01! ",last_un_char))
- X weight += 30;
- X if (index("zZ79~",d[1]))
- X weight += 30;
- X }
- X else
- X weight -= 1;
- X default:
- X if (isalpha(*d) && d[1] && isalpha(d[1])) {
- X bufptr = d;
- X if (yylex() != WORD)
- X weight -= 150;
- X d = bufptr;
- X }
- X if (un_char == last_un_char + 1)
- X weight += 5;
- X weight -= seen[un_char];
- X break;
- X }
- X seen[un_char]++;
- X }
- X#ifdef DEBUGGING
- X if (debug & 512)
- X fprintf(stderr,"[%s] weight %d\n",
- X checkpoint+1,weight);
- X#endif
- X *s++ = ']';
- X if (weight >= 0) /* probably a character class */
- X s = checkpoint;
- X }
- X }
- X }
- X if (*t == '@')
- X str_ncat(toparse, "join($\",", 8);
- X if (t[1] == '{' && s[-1] == '}') {
- X str_ncat(toparse, t, 1);
- X str_ncat(toparse, t+2, s - t - 3);
- X }
- X else
- X str_ncat(toparse, t, s - t);
- X if (*t == '@')
- X str_ncat(toparse, ")", 1);
- X t = s;
- X }
- X else
- X s++;
- X }
- X str_ncat(str,t,s-t);
- X if (sawcase)
- X str_ncat(str, "$cE", 3);
- X if (toparse->str_ptr && *toparse->str_ptr == ',') {
- X *toparse->str_ptr = '(';
- X str_ncat(toparse,",$$);",5);
- X str->str_u.str_args = parselist(toparse);
- X str->str_u.str_args->arg_len--; /* ignore $$ reference */
- X }
- X else
- X str->str_u.str_args = Nullarg;
- X str_free(toparse);
- X str->str_pok |= SP_INTRP;
- X str->str_nok = 0;
- X str_replace(src,str);
- X}
- X
- XSTR *
- Xinterp(str,src,sp)
- Xregister STR *str;
- XSTR *src;
- Xint sp;
- X{
- X register char *s;
- X register char *t;
- X register char *send;
- X register STR **elem;
- X int docase = 0;
- X int l = 0;
- X int u = 0;
- X int L = 0;
- X int U = 0;
- X
- X if (str == &str_undef)
- X return Nullstr;
- X if (!(src->str_pok & SP_INTRP)) {
- X int oldsave = savestack->ary_fill;
- X
- X (void)savehptr(&curstash);
- X curstash = curcmd->c_stash; /* so stabent knows right package */
- X intrpcompile(src);
- X restorelist(oldsave);
- X }
- X s = src->str_ptr; /* assumed valid since str_pok set */
- X t = s;
- X send = s + src->str_cur;
- X
- X if (src->str_u.str_args) {
- X (void)eval(src->str_u.str_args,G_ARRAY,sp);
- X /* Assuming we have correct # of args */
- X elem = stack->ary_array + sp;
- X }
- X
- X str_nset(str,"",0);
- X while (s < send) {
- X if (*s == '$' && s+1 < send) {
- X if (s-t > 0)
- X str_ncat(str,t,s-t);
- X switch(*++s) {
- X case 'a':
- X str_scat(str,*++elem);
- X break;
- X case 'b':
- X str_ncat(str,++s,1);
- X break;
- X case 'c':
- X if (docase && str->str_cur >= docase) {
- X char *b = str->str_ptr + --docase;
- X
- X if (L)
- X lcase(b, str->str_ptr + str->str_cur);
- X else if (U)
- X ucase(b, str->str_ptr + str->str_cur);
- X
- X if (u) /* note that l & u are independent of L & U */
- X ucase(b, b+1);
- X else if (l)
- X lcase(b, b+1);
- X l = u = 0;
- X }
- X docase = str->str_cur + 1;
- X switch (*++s) {
- X case 'u':
- X u = 1;
- X l = 0;
- X break;
- X case 'U':
- X U = 1;
- X L = 0;
- X break;
- X case 'l':
- X l = 1;
- X u = 0;
- X break;
- X case 'L':
- X L = 1;
- X U = 0;
- X break;
- X case 'E':
- X docase = L = U = l = u = 0;
- X break;
- X }
- X break;
- X }
- X t = ++s;
- X }
- X else
- X s++;
- X }
- X if (s-t > 0)
- X str_ncat(str,t,s-t);
- X return str;
- X}
- X
- Xucase(s,send)
- Xregister char *s;
- Xregister char *send;
- X{
- X while (s < send) {
- X if (isascii(*s) && islower(*s))
- X *s = toupper(*s);
- X s++;
- X }
- X}
- X
- Xlcase(s,send)
- Xregister char *s;
- Xregister char *send;
- X{
- X while (s < send) {
- X if (isascii(*s) && isupper(*s))
- X *s = tolower(*s);
- X s++;
- X }
- X}
- X
- Xvoid
- Xstr_inc(str)
- Xregister STR *str;
- X{
- X register char *d;
- X
- X if (!str || str == &str_undef)
- X return;
- X if (str->str_nok) {
- X str->str_u.str_nval += 1.0;
- X str->str_pok = 0;
- X return;
- X }
- X if (!str->str_pok || !*str->str_ptr) {
- X str->str_u.str_nval = 1.0;
- X str->str_nok = 1;
- X str->str_pok = 0;
- X return;
- X }
- X d = str->str_ptr;
- X while (isalpha(*d)) d++;
- X while (isdigit(*d)) d++;
- X if (*d) {
- X str_numset(str,atof(str->str_ptr) + 1.0); /* punt */
- X return;
- X }
- X d--;
- X while (d >= str->str_ptr) {
- X if (isdigit(*d)) {
- X if (++*d <= '9')
- X return;
- X *(d--) = '0';
- X }
- X else {
- X ++*d;
- X if (isalpha(*d))
- X return;
- X *(d--) -= 'z' - 'a' + 1;
- X }
- X }
- X /* oh,oh, the number grew */
- X STR_GROW(str, str->str_cur + 2);
- X str->str_cur++;
- X for (d = str->str_ptr + str->str_cur; d > str->str_ptr; d--)
- X *d = d[-1];
- X if (isdigit(d[1]))
- X *d = '1';
- X else
- X *d = d[1];
- X}
- X
- Xvoid
- Xstr_dec(str)
- Xregister STR *str;
- X{
- X if (!str || str == &str_undef)
- X return;
- X if (str->str_nok) {
- X str->str_u.str_nval -= 1.0;
- X str->str_pok = 0;
- X return;
- X }
- X if (!str->str_pok) {
- X str->str_u.str_nval = -1.0;
- X str->str_nok = 1;
- X return;
- X }
- X str_numset(str,atof(str->str_ptr) - 1.0);
- X}
- X
- X/* Make a string that will exist for the duration of the expression
- X * evaluation. Actually, it may have to last longer than that, but
- X * hopefully cmd_exec won't free it until it has been assigned to a
- X * permanent location. */
- X
- Xstatic long tmps_size = -1;
- X
- XSTR *
- Xstr_mortal(oldstr)
- XSTR *oldstr;
- X{
- X register STR *str = Str_new(78,0);
- X
- X str_sset(str,oldstr);
- X if (++tmps_max > tmps_size) {
- X tmps_size = tmps_max;
- X if (!(tmps_size & 127)) {
- X if (tmps_size)
- X Renew(tmps_list, tmps_size + 128, STR*);
- X else
- X New(702,tmps_list, 128, STR*);
- X }
- X }
- X tmps_list[tmps_max] = str;
- X if (str->str_pok)
- X str->str_pok |= SP_TEMP;
- X return str;
- X}
- X
- X/* same thing without the copying */
- X
- XSTR *
- Xstr_2mortal(str)
- Xregister STR *str;
- X{
- X if (str == &str_undef)
- X return str;
- X if (++tmps_max > tmps_size) {
- X tmps_size = tmps_max;
- X if (!(tmps_size & 127)) {
- X if (tmps_size)
- X Renew(tmps_list, tmps_size + 128, STR*);
- X else
- X New(704,tmps_list, 128, STR*);
- X }
- X }
- X tmps_list[tmps_max] = str;
- X if (str->str_pok)
- X str->str_pok |= SP_TEMP;
- X return str;
- X}
- X
- XSTR *
- Xstr_make(s,len)
- Xchar *s;
- XSTRLEN len;
- X{
- X register STR *str = Str_new(79,0);
- X
- X if (!len)
- X len = strlen(s);
- X str_nset(str,s,len);
- X return str;
- X}
- X
- XSTR *
- Xstr_nmake(n)
- Xdouble n;
- X{
- X register STR *str = Str_new(80,0);
- X
- X str_numset(str,n);
- X return str;
- X}
- X
- X/* make an exact duplicate of old */
- X
- XSTR *
- Xstr_smake(old)
- Xregister STR *old;
- X{
- X register STR *new = Str_new(81,0);
- X
- X if (!old)
- X return Nullstr;
- X if (old->str_state == SS_FREE) {
- X warn("semi-panic: attempt to dup freed string");
- X return Nullstr;
- X }
- X if (old->str_state == SS_INCR && !(old->str_pok & 2))
- X Str_Grow(old,0);
- X if (new->str_ptr)
- X Safefree(new->str_ptr);
- X Copy(old,new,1,STR);
- X if (old->str_ptr) {
- X new->str_ptr = nsavestr(old->str_ptr,old->str_len);
- X new->str_pok &= ~SP_TEMP;
- X }
- X return new;
- X}
- X
- Xstr_reset(s,stash)
- Xregister char *s;
- XHASH *stash;
- X{
- X register HENT *entry;
- X register STAB *stab;
- X register STR *str;
- X register int i;
- X register SPAT *spat;
- X register int max;
- X
- X if (!*s) { /* reset ?? searches */
- X for (spat = stash->tbl_spatroot;
- X spat != Nullspat;
- X spat = spat->spat_next) {
- X spat->spat_flags &= ~SPAT_USED;
- X }
- X return;
- X }
- X
- X /* reset variables */
- X
- X if (!stash->tbl_array)
- X return;
- X while (*s) {
- X i = *s;
- X if (s[1] == '-') {
- X s += 2;
- X }
- X max = *s++;
- X for ( ; i <= max; i++) {
- X for (entry = stash->tbl_array[i];
- X entry;
- X entry = entry->hent_next) {
- X stab = (STAB*)entry->hent_val;
- X str = stab_val(stab);
- X str->str_cur = 0;
- X str->str_nok = 0;
- X#ifdef TAINT
- X str->str_tainted = tainted;
- X#endif
- X if (str->str_ptr != Nullch)
- X str->str_ptr[0] = '\0';
- X if (stab_xarray(stab)) {
- X aclear(stab_xarray(stab));
- X }
- X if (stab_xhash(stab)) {
- X hclear(stab_xhash(stab), FALSE);
- X if (stab == envstab)
- X environ[0] = Nullch;
- X }
- X }
- X }
- X }
- X}
- X
- X#ifdef TAINT
- Xtaintproper(s)
- Xchar *s;
- X{
- X#ifdef DEBUGGING
- X if (debug & 2048)
- X fprintf(stderr,"%s %d %d %d\n",s,tainted,uid, euid);
- X#endif
- X if (tainted && (!euid || euid != uid || egid != gid)) {
- X if (!unsafe)
- X fatal("%s", s);
- X else if (dowarn)
- X warn("%s", s);
- X }
- X}
- X
- Xtaintenv()
- X{
- X register STR *envstr;
- X
- X envstr = hfetch(stab_hash(envstab),"PATH",4,FALSE);
- X if (envstr == &str_undef || envstr->str_tainted) {
- X tainted = 1;
- X if (envstr->str_tainted == 2)
- X taintproper("Insecure directory in PATH");
- X else
- X taintproper("Insecure PATH");
- X }
- X envstr = hfetch(stab_hash(envstab),"IFS",3,FALSE);
- X if (envstr != &str_undef && envstr->str_tainted) {
- X tainted = 1;
- X taintproper("Insecure IFS");
- X }
- X}
- X#endif /* TAINT */
- !STUFFY!FUNK!
- echo Extracting Copying
- sed >Copying <<'!STUFFY!FUNK!' -e 's/X//'
- X GNU GENERAL PUBLIC LICENSE
- X Version 1, February 1989
- X
- X Copyright (C) 1989 Free Software Foundation, Inc.
- X 675 Mass Ave, Cambridge, MA 02139, USA
- X Everyone is permitted to copy and distribute verbatim copies
- X of this license document, but changing it is not allowed.
- X
- X Preamble
- X
- X The license agreements of most software companies try to keep users
- Xat the mercy of those companies. By contrast, our General Public
- XLicense is intended to guarantee your freedom to share and change free
- Xsoftware--to make sure the software is free for all its users. The
- XGeneral Public License applies to the Free Software Foundation's
- Xsoftware and to any other program whose authors commit to using it.
- XYou can use it for your programs, too.
- X
- X When we speak of free software, we are referring to freedom, not
- Xprice. Specifically, the General Public License is designed to make
- Xsure that you have the freedom to give away or sell copies of free
- Xsoftware, that you receive source code or can get it if you want it,
- Xthat you can change the software or use pieces of it in new free
- Xprograms; and that you know you can do these things.
- X
- X To protect your rights, we need to make restrictions that forbid
- Xanyone to deny you these rights or to ask you to surrender the rights.
- XThese restrictions translate to certain responsibilities for you if you
- Xdistribute copies of the software, or if you modify it.
- X
- X For example, if you distribute copies of a such a program, whether
- Xgratis or for a fee, you must give the recipients all the rights that
- Xyou have. You must make sure that they, too, receive or can get the
- Xsource code. And you must tell them their rights.
- X
- X We protect your rights with two steps: (1) copyright the software, and
- X(2) offer you this license which gives you legal permission to copy,
- Xdistribute and/or modify the software.
- X
- X Also, for each author's protection and ours, we want to make certain
- Xthat everyone understands that there is no warranty for this free
- Xsoftware. If the software is modified by someone else and passed on, we
- Xwant its recipients to know that what they have is not the original, so
- Xthat any problems introduced by others will not reflect on the original
- Xauthors' reputations.
- X
- X The precise terms and conditions for copying, distribution and
- Xmodification follow.
- X
- X GNU GENERAL PUBLIC LICENSE
- X TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION
- X
- X 0. This License Agreement applies to any program or other work which
- Xcontains a notice placed by the copyright holder saying it may be
- Xdistributed under the terms of this General Public License. The
- X"Program", below, refers to any such program or work, and a "work based
- Xon the Program" means either the Program or any work containing the
- XProgram or a portion of it, either verbatim or with modifications. Each
- Xlicensee is addressed as "you".
- X
- X 1. You may copy and distribute verbatim copies of the Program's source
- Xcode as you receive it, in any medium, provided that you conspicuously and
- Xappropriately publish on each copy an appropriate copyright notice and
- Xdisclaimer of warranty; keep intact all the notices that refer to this
- XGeneral Public License and to the absence of any warranty; and give any
- Xother recipients of the Program a copy of this General Public License
- Xalong with the Program. You may charge a fee for the physical act of
- Xtransferring a copy.
- X
- X 2. You may modify your copy or copies of the Program or any portion of
- Xit, and copy and distribute such modifications under the terms of Paragraph
- X1 above, provided that you also do the following:
- X
- X a) cause the modified files to carry prominent notices stating that
- X you changed the files and the date of any change; and
- X
- X b) cause the whole of any work that you distribute or publish, that
- X in whole or in part contains the Program or any part thereof, either
- X with or without modifications, to be licensed at no charge to all
- X third parties under the terms of this General Public License (except
- X that you may choose to grant warranty protection to some or all
- X third parties, at your option).
- X
- X c) If the modified program normally reads commands interactively when
- X run, you must cause it, when started running for such interactive use
- X in the simplest and most usual way, to print or display an
- X announcement including an appropriate copyright notice and a notice
- X that there is no warranty (or else, saying that you provide a
- X warranty) and that users may redistribute the program under these
- X conditions, and telling the user how to view a copy of this General
- X Public License.
- X
- X d) You may charge a fee for the physical act of transferring a
- X copy, and you may at your option offer warranty protection in
- X exchange for a fee.
- X
- XMere aggregation of another independent work with the Program (or its
- Xderivative) on a volume of a storage or distribution medium does not bring
- Xthe other work under the scope of these terms.
- X
- X 3. You may copy and distribute the Program (or a portion or derivative of
- Xit, under Paragraph 2) in object code or executable form under the terms of
- XParagraphs 1 and 2 above provided that you also do one of the following:
- X
- X a) accompany it with the complete corresponding machine-readable
- X source code, which must be distributed under the terms of
- X Paragraphs 1 and 2 above; or,
- X
- X b) accompany it with a written offer, valid for at least three
- X years, to give any third party free (except for a nominal charge
- X for the cost of distribution) a complete machine-readable copy of the
- X corresponding source code, to be distributed under the terms of
- X Paragraphs 1 and 2 above; or,
- X
- X c) accompany it with the information you received as to where the
- X corresponding source code may be obtained. (This alternative is
- X allowed only for noncommercial distribution and only if you
- X received the program in object code or executable form alone.)
- X
- XSource code for a work means the preferred form of the work for making
- Xmodifications to it. For an executable file, complete source code means
- Xall the source code for all modules it contains; but, as a special
- Xexception, it need not include source code for modules which are standard
- Xlibraries that accompany the operating system on which the executable
- Xfile runs, or for standard header files or definitions files that
- Xaccompany that operating system.
- X
- X 4. You may not copy, modify, sublicense, distribute or transfer the
- XProgram except as expressly provided under this General Public License.
- XAny attempt otherwise to copy, modify, sublicense, distribute or transfer
- Xthe Program is void, and will automatically terminate your rights to use
- Xthe Program under this License. However, parties who have received
- Xcopies, or rights to use copies, from you under this General Public
- XLicense will not have their licenses terminated so long as such parties
- Xremain in full compliance.
- X
- X 5. By copying, distributing or modifying the Program (or any work based
- Xon the Program) you indicate your acceptance of this license to do so,
- Xand all its terms and conditions.
- X
- X 6. Each time you redistribute the Program (or any work based on the
- XProgram), the recipient automatically receives a license from the original
- Xlicensor to copy, distribute or modify the Program subject to these
- Xterms and conditions. You may not impose any further restrictions on the
- Xrecipients' exercise of the rights granted herein.
- X
- X 7. The Free Software Foundation may publish revised and/or new versions
- Xof the General Public License from time to time. Such new versions will
- Xbe similar in spirit to the present version, but may differ in detail to
- Xaddress new problems or concerns.
- X
- XEach version is given a distinguishing version number. If the Program
- Xspecifies a version number of the license which applies to it and "any
- Xlater version", you have the option of following the terms and conditions
- Xeither of that version or of any later version published by the Free
- XSoftware Foundation. If the Program does not specify a version number of
- Xthe license, you may choose any version ever published by the Free Software
- XFoundation.
- X
- X 8. If you wish to incorporate parts of the Program into other free
- Xprograms whose distribution conditions are different, write to the author
- Xto ask for permission. For software which is copyrighted by the Free
- XSoftware Foundation, write to the Free Software Foundation; we sometimes
- Xmake exceptions for this. Our decision will be guided by the two goals
- Xof preserving the free status of all derivatives of our free software and
- Xof promoting the sharing and reuse of software generally.
- X
- X NO WARRANTY
- X
- X 9. BECAUSE THE PROGRAM IS LICENSED FREE OF CHARGE, THERE IS NO WARRANTY
- XFOR THE PROGRAM, TO THE EXTENT PERMITTED BY APPLICABLE LAW. EXCEPT WHEN
- XOTHERWISE STATED IN WRITING THE COPYRIGHT HOLDERS AND/OR OTHER PARTIES
- XPROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED
- XOR IMPLIED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
- XMERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. THE ENTIRE RISK AS
- XTO THE QUALITY AND PERFORMANCE OF THE PROGRAM IS WITH YOU. SHOULD THE
- XPROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF ALL NECESSARY SERVICING,
- XREPAIR OR CORRECTION.
- X
- X 10. IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING
- XWILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MAY MODIFY AND/OR
- XREDISTRIBUTE THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES,
- XINCLUDING ANY GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING
- XOUT OF THE USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED
- XTO LOSS OF DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY
- XYOU OR THIRD PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER
- XPROGRAMS), EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE
- XPOSSIBILITY OF SUCH DAMAGES.
- X
- X END OF TERMS AND CONDITIONS
- X
- X Appendix: How to Apply These Terms to Your New Programs
- X
- X If you develop a new program, and you want it to be of the greatest
- Xpossible use to humanity, the best way to achieve this is to make it
- Xfree software which everyone can redistribute and change under these
- Xterms.
- X
- X To do so, attach the following notices to the program. It is safest to
- Xattach them to the start of each source file to most effectively convey
- Xthe exclusion of warranty; and each file should have at least the
- X"copyright" line and a pointer to where the full notice is found.
- X
- X <one line to give the program's name and a brief idea of what it does.>
- X Copyright (C) 19yy <name of author>
- X
- X This program is free software; you can redistribute it and/or modify
- X it under the terms of the GNU General Public License as published by
- X the Free Software Foundation; either version 1, or (at your option)
- X any later version.
- X
- X This program is distributed in the hope that it will be useful,
- X but WITHOUT ANY WARRANTY; without even the implied warranty of
- X MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- X GNU General Public License for more details.
- X
- X You should have received a copy of the GNU General Public License
- X along with this program; if not, write to the Free Software
- X Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
- X
- XAlso add information on how to contact you by electronic and paper mail.
- X
- XIf the program is interactive, make it output a short notice like this
- Xwhen it starts in an interactive mode:
- X
- X Gnomovision version 69, Copyright (C) 19xx name of author
- X Gnomovision comes with ABSOLUTELY NO WARRANTY; for details type `show w'.
- X This is free software, and you are welcome to redistribute it
- X under certain conditions; type `show c' for details.
- X
- XThe hypothetical commands `show w' and `show c' should show the
- Xappropriate parts of the General Public License. Of course, the
- Xcommands you use may be called something other than `show w' and `show
- Xc'; they could even be mouse-clicks or menu items--whatever suits your
- Xprogram.
- X
- XYou should also get your employer (if you work as a programmer) or your
- Xschool, if any, to sign a "copyright disclaimer" for the program, if
- Xnecessary. Here a sample; alter the names:
- X
- X Yoyodyne, Inc., hereby disclaims all copyright interest in the
- X program `Gnomovision' (a program to direct compilers to make passes
- X at assemblers) written by James Hacker.
- X
- X <signature of Ty Coon>, 1 April 1989
- X Ty Coon, President of Vice
- X
- XThat's all there is to it!
- !STUFFY!FUNK!
- echo Extracting t/cmd/switch.t
- sed >t/cmd/switch.t <<'!STUFFY!FUNK!' -e 's/X//'
- X#!./perl
- X
- X# $Header: switch.t,v 4.0 91/03/20 01:49:44 lwall Locked $
- X
- Xprint "1..18\n";
- X
- Xsub foo1 {
- X $_ = shift(@_);
- X $a = 0;
- X until ($a++) {
- X next if $_ eq 1;
- X next if $_ eq 2;
- X next if $_ eq 3;
- X next if $_ eq 4;
- X return 20;
- X }
- X continue {
- X return $_;
- X }
- X}
- X
- Xprint do foo1(0) == 20 ? "ok 1\n" : "not ok 1\n";
- Xprint do foo1(1) == 1 ? "ok 2\n" : "not ok 2\n";
- Xprint do foo1(2) == 2 ? "ok 3\n" : "not ok 3\n";
- Xprint do foo1(3) == 3 ? "ok 4\n" : "not ok 4\n";
- Xprint do foo1(4) == 4 ? "ok 5\n" : "not ok 5\n";
- Xprint do foo1(5) == 20 ? "ok 6\n" : "not ok 6\n";
- X
- Xsub foo2 {
- X $_ = shift(@_);
- X {
- X last if $_ == 1;
- X last if $_ == 2;
- X last if $_ == 3;
- X last if $_ == 4;
- X }
- X continue {
- X return 20;
- X }
- X return $_;
- X}
- X
- Xprint do foo2(0) == 20 ? "ok 7\n" : "not ok 1\n";
- Xprint do foo2(1) == 1 ? "ok 8\n" : "not ok 8\n";
- Xprint do foo2(2) == 2 ? "ok 9\n" : "not ok 9\n";
- Xprint do foo2(3) == 3 ? "ok 10\n" : "not ok 10\n";
- Xprint do foo2(4) == 4 ? "ok 11\n" : "not ok 11\n";
- Xprint do foo2(5) == 20 ? "ok 12\n" : "not ok 12\n";
- X
- Xsub foo3 {
- X $_ = shift(@_);
- X if (/^1/) {
- X return 1;
- X }
- X elsif (/^2/) {
- X return 2;
- X }
- X elsif (/^3/) {
- X return 3;
- X }
- X elsif (/^4/) {
- X return 4;
- X }
- X else {
- X return 20;
- X }
- X return 40;
- X}
- X
- Xprint do foo3(0) == 20 ? "ok 13\n" : "not ok 13\n";
- Xprint do foo3(1) == 1 ? "ok 14\n" : "not ok 14\n";
- Xprint do foo3(2) == 2 ? "ok 15\n" : "not ok 15\n";
- Xprint do foo3(3) == 3 ? "ok 16\n" : "not ok 16\n";
- Xprint do foo3(4) == 4 ? "ok 17\n" : "not ok 17\n";
- Xprint do foo3(5) == 20 ? "ok 18\n" : "not ok 18\n";
- !STUFFY!FUNK!
- echo " "
- echo "End of kit 15 (of 36)"
- cat /dev/null >kit15isdone
- run=''
- config=''
- for iskit in 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36; do
- if test -f kit${iskit}isdone; then
- run="$run $iskit"
- else
- todo="$todo $iskit"
- fi
- done
- case $todo in
- '')
- echo "You have run all your kits. Please read README and then type Configure."
- for combo in *:AA; do
- if test -f "$combo"; then
- realfile=`basename $combo :AA`
- cat $realfile:[A-Z][A-Z] >$realfile
- rm -rf $realfile:[A-Z][A-Z]
- fi
- done
- rm -rf kit*isdone
- chmod 755 Configure
- ;;
- *) echo "You have run$run."
- echo "You still need to run$todo."
- ;;
- esac
- : Someone might mail this, so...
- exit
-
- exit 0 # Just in case...
- --
- Kent Landfield INTERNET: kent@sparky.IMD.Sterling.COM
- Sterling Software, IMD UUCP: uunet!sparky!kent
- Phone: (402) 291-8300 FAX: (402) 291-4362
- Please send comp.sources.misc-related mail to kent@uunet.uu.net.
-