home *** CD-ROM | disk | FTP | other *** search
- Subject: v20i093: Perl, a language with features of C/sed/awk/shell/etc, Part10/24
- Newsgroups: comp.sources.unix
- Sender: sources
- Approved: rsalz@uunet.UU.NET
-
- Submitted-by: Larry Wall <lwall@jpl-devvax.jpl.nasa.gov>
- Posting-number: Volume 20, Issue 93
- Archive-name: perl3.0/part10
-
- #! /bin/sh
-
- # Make a new directory for the perl sources, cd to it, and run kits 1
- # thru 24 through sh. When all 24 kits have been run, read README.
-
- echo "This is perl 3.0 kit 10 (of 24). If kit 10 is complete, the line"
- echo '"'"End of kit 10 (of 24)"'" will echo at the end.'
- echo ""
- export PATH || (echo "You didn't use sh, you clunch." ; kill $$)
- mkdir t 2>/dev/null
- echo Extracting cons.c
- sed >cons.c <<'!STUFFY!FUNK!' -e 's/X//'
- X/* $Header: cons.c,v 3.0 89/10/18 15:10:23 lwall Locked $
- 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: cons.c,v $
- X * Revision 3.0 89/10/18 15:10:23 lwall
- X * 3.0 baseline
- X *
- X */
- X
- X#include "EXTERN.h"
- X#include "perl.h"
- X#include "perly.h"
- X
- Xextern char *tokename[];
- Xextern int yychar;
- X
- Xstatic int cmd_tosave();
- Xstatic int arg_tosave();
- Xstatic int spat_tosave();
- X
- Xstatic bool saw_return;
- X
- XSUBR *
- Xmake_sub(name,cmd)
- Xchar *name;
- XCMD *cmd;
- X{
- X register SUBR *sub;
- X STAB *stab = stabent(name,TRUE);
- X
- X Newz(101,sub,1,SUBR);
- X if (stab_sub(stab)) {
- X if (dowarn) {
- X line_t oldline = line;
- X
- X if (cmd)
- X line = cmd->c_line;
- X warn("Subroutine %s redefined",name);
- X line = oldline;
- X }
- X cmd_free(stab_sub(stab)->cmd);
- X afree(stab_sub(stab)->tosave);
- X Safefree(stab_sub(stab));
- X }
- X sub->filename = filename;
- X saw_return = FALSE;
- X tosave = anew(Nullstab);
- X tosave->ary_fill = 0; /* make 1 based */
- X (void)cmd_tosave(cmd,FALSE); /* this builds the tosave array */
- X sub->tosave = tosave;
- X if (saw_return) {
- X struct compcmd mycompblock;
- X
- X mycompblock.comp_true = cmd;
- X mycompblock.comp_alt = Nullcmd;
- X cmd = add_label(savestr("SUB"),make_ccmd(C_BLOCK,Nullarg,mycompblock));
- X saw_return = FALSE;
- X }
- X sub->cmd = cmd;
- X stab_sub(stab) = sub;
- X if (perldb) {
- X STR *str = str_nmake((double)subline);
- X
- X str_cat(str,"-");
- X sprintf(buf,"%ld",(long)line);
- X str_cat(str,buf);
- X name = str_get(subname);
- X hstore(stab_xhash(DBsub),name,strlen(name),str,0);
- X str_set(subname,"main");
- X }
- X subline = 0;
- X return sub;
- X}
- X
- XCMD *
- Xblock_head(tail)
- Xregister CMD *tail;
- X{
- X CMD *head;
- X register int opt;
- X register int last_opt = 0;
- X register STAB *last_stab = Nullstab;
- X register int count = 0;
- X register CMD *switchbeg = Nullcmd;
- X
- X if (tail == Nullcmd) {
- X return tail;
- X }
- X head = tail->c_head;
- X
- X for (tail = head; tail; tail = tail->c_next) {
- X
- X /* save one measly dereference at runtime */
- X if (tail->c_type == C_IF) {
- X if (!(tail->ucmd.ccmd.cc_alt = tail->ucmd.ccmd.cc_alt->c_next))
- X tail->c_flags |= CF_TERM;
- X }
- X else if (tail->c_type == C_EXPR) {
- X ARG *arg;
- X
- X if (tail->ucmd.acmd.ac_expr)
- X arg = tail->ucmd.acmd.ac_expr;
- X else
- X arg = tail->c_expr;
- X if (arg) {
- X if (arg->arg_type == O_RETURN)
- X tail->c_flags |= CF_TERM;
- X else if (arg->arg_type == O_ITEM && arg[1].arg_type == A_CMD)
- X tail->c_flags |= CF_TERM;
- X }
- X }
- X if (!tail->c_next)
- X tail->c_flags |= CF_TERM;
- X
- X if (tail->c_expr && (tail->c_flags & CF_OPTIMIZE) == CFT_FALSE)
- X opt_arg(tail,1, tail->c_type == C_EXPR);
- X
- X /* now do a little optimization on case-ish structures */
- X switch(tail->c_flags & (CF_OPTIMIZE|CF_FIRSTNEG|CF_INVERT)) {
- X case CFT_ANCHOR:
- X if (stabent("*",FALSE)) { /* bad assumption here!!! */
- X opt = 0;
- X break;
- X }
- X /* FALL THROUGH */
- X case CFT_STROP:
- X opt = (tail->c_flags & CF_NESURE) ? CFT_STROP : 0;
- X break;
- X case CFT_CCLASS:
- X opt = CFT_STROP;
- X break;
- X case CFT_NUMOP:
- X opt = (tail->c_slen == O_NE ? 0 : CFT_NUMOP);
- X if ((tail->c_flags&(CF_NESURE|CF_EQSURE)) != (CF_NESURE|CF_EQSURE))
- X opt = 0;
- X break;
- X default:
- X opt = 0;
- X }
- X if (opt && opt == last_opt && tail->c_stab == last_stab)
- X count++;
- X else {
- X if (count >= 3) { /* is this the breakeven point? */
- X if (last_opt == CFT_NUMOP)
- X make_nswitch(switchbeg,count);
- X else
- X make_cswitch(switchbeg,count);
- X }
- X if (opt) {
- X count = 1;
- X switchbeg = tail;
- X }
- X else
- X count = 0;
- X }
- X last_opt = opt;
- X last_stab = tail->c_stab;
- X }
- X if (count >= 3) { /* is this the breakeven point? */
- X if (last_opt == CFT_NUMOP)
- X make_nswitch(switchbeg,count);
- X else
- X make_cswitch(switchbeg,count);
- X }
- X return head;
- X}
- X
- X/* We've spotted a sequence of CMDs that all test the value of the same
- X * spat. Thus we can insert a SWITCH in front and jump directly
- X * to the correct one.
- X */
- Xmake_cswitch(head,count)
- Xregister CMD *head;
- Xint count;
- X{
- X register CMD *cur;
- X register CMD **loc;
- X register int i;
- X register int min = 255;
- X register int max = 0;
- X
- X /* make a new head in the exact same spot */
- X New(102,cur, 1, CMD);
- X#ifdef STRUCTCOPY
- X *cur = *head;
- X#else
- X Copy(head,cur,1,CMD);
- X#endif
- X Zero(head,1,CMD);
- X head->c_type = C_CSWITCH;
- X head->c_next = cur; /* insert new cmd at front of list */
- X head->c_stab = cur->c_stab;
- X
- X Newz(103,loc,258,CMD*);
- X loc++; /* lie a little */
- X while (count--) {
- X if ((cur->c_flags & CF_OPTIMIZE) == CFT_CCLASS) {
- X for (i = 0; i <= 255; i++) {
- X if (!loc[i] && cur->c_short->str_ptr[i>>3] & (1 << (i&7))) {
- X loc[i] = cur;
- X if (i < min)
- X min = i;
- X if (i > max)
- X max = i;
- X }
- X }
- X }
- X else {
- X i = *cur->c_short->str_ptr & 255;
- X if (!loc[i]) {
- X loc[i] = cur;
- X if (i < min)
- X min = i;
- X if (i > max)
- X max = i;
- X }
- X }
- X cur = cur->c_next;
- X }
- X max++;
- X if (min > 0)
- X Copy(&loc[min],&loc[0], max - min, CMD*);
- X loc--;
- X min--;
- X max -= min;
- X for (i = 0; i <= max; i++)
- X if (!loc[i])
- X loc[i] = cur;
- X Renew(loc,max+1,CMD*); /* chop it down to size */
- X head->ucmd.scmd.sc_offset = min;
- X head->ucmd.scmd.sc_max = max;
- X head->ucmd.scmd.sc_next = loc;
- X}
- X
- Xmake_nswitch(head,count)
- Xregister CMD *head;
- Xint count;
- X{
- X register CMD *cur = head;
- X register CMD **loc;
- X register int i;
- X register int min = 32767;
- X register int max = -32768;
- X int origcount = count;
- X double value; /* or your money back! */
- X short changed; /* so triple your money back! */
- X
- X while (count--) {
- X i = (int)str_gnum(cur->c_short);
- X value = (double)i;
- X if (value != cur->c_short->str_u.str_nval)
- X return; /* fractional values--just forget it */
- X changed = i;
- X if (changed != i)
- X return; /* too big for a short */
- X if (cur->c_slen == O_LE)
- X i++;
- X else if (cur->c_slen == O_GE) /* we only do < or > here */
- X i--;
- X if (i < min)
- X min = i;
- X if (i > max)
- X max = i;
- X cur = cur->c_next;
- X }
- X count = origcount;
- X if (max - min > count * 2 + 10) /* too sparse? */
- X return;
- X
- X /* now make a new head in the exact same spot */
- X New(104,cur, 1, CMD);
- X#ifdef STRUCTCOPY
- X *cur = *head;
- X#else
- X Copy(head,cur,1,CMD);
- X#endif
- X Zero(head,1,CMD);
- X head->c_type = C_NSWITCH;
- X head->c_next = cur; /* insert new cmd at front of list */
- X head->c_stab = cur->c_stab;
- X
- X Newz(105,loc, max - min + 3, CMD*);
- X loc++;
- X while (count--) {
- X i = (int)str_gnum(cur->c_short);
- X i -= min;
- X max -= min;
- X max++;
- X switch(cur->c_slen) {
- X case O_LE:
- X i++;
- X case O_LT:
- X for (i--; i >= -1; i--)
- X if (!loc[i])
- X loc[i] = cur;
- X break;
- X case O_GE:
- X i--;
- X case O_GT:
- X for (i++; i <= max; i++)
- X if (!loc[i])
- X loc[i] = cur;
- X break;
- X case O_EQ:
- X if (!loc[i])
- X loc[i] = cur;
- X break;
- X }
- X cur = cur->c_next;
- X }
- X loc--;
- X min--;
- X for (i = 0; i <= max; i++)
- X if (!loc[i])
- X loc[i] = cur;
- X head->ucmd.scmd.sc_offset = min;
- X head->ucmd.scmd.sc_max = max;
- X head->ucmd.scmd.sc_next = loc;
- X}
- X
- XCMD *
- Xappend_line(head,tail)
- Xregister CMD *head;
- Xregister CMD *tail;
- X{
- X if (tail == Nullcmd)
- X return head;
- X if (!tail->c_head) /* make sure tail is well formed */
- X tail->c_head = tail;
- X if (head != Nullcmd) {
- X tail = tail->c_head; /* get to start of tail list */
- X if (!head->c_head)
- X head->c_head = head; /* start a new head list */
- X while (head->c_next) {
- X head->c_next->c_head = head->c_head;
- X head = head->c_next; /* get to end of head list */
- X }
- X head->c_next = tail; /* link to end of old list */
- X tail->c_head = head->c_head; /* propagate head pointer */
- X }
- X while (tail->c_next) {
- X tail->c_next->c_head = tail->c_head;
- X tail = tail->c_next;
- X }
- X return tail;
- X}
- X
- XCMD *
- Xdodb(cur)
- XCMD *cur;
- X{
- X register CMD *cmd;
- X register CMD *head = cur->c_head;
- X register ARG *arg;
- X STR *str;
- X
- X if (!head)
- X head = cur;
- X if (!head->c_line)
- X return cur;
- X str = afetch(lineary,(int)head->c_line,FALSE);
- X if (!str || str->str_nok)
- X return cur;
- X str->str_u.str_nval = (double)head->c_line;
- X str->str_nok = 1;
- X Newz(106,cmd,1,CMD);
- X cmd->c_type = C_EXPR;
- X cmd->ucmd.acmd.ac_stab = Nullstab;
- X cmd->ucmd.acmd.ac_expr = Nullarg;
- X arg = make_op(O_ITEM,1,Nullarg,Nullarg,Nullarg);
- X arg[1].arg_type = A_SINGLE;
- X arg[1].arg_ptr.arg_str = str_nmake((double)head->c_line);
- X cmd->c_expr = make_op(O_SUBR, 2,
- X stab2arg(A_WORD,DBstab),
- X make_list(arg),
- X Nullarg);
- X cmd->c_flags |= CF_COND;
- X cmd->c_line = head->c_line;
- X cmd->c_label = head->c_label;
- X cmd->c_file = filename;
- X return append_line(cmd, cur);
- X}
- X
- XCMD *
- Xmake_acmd(type,stab,cond,arg)
- Xint type;
- XSTAB *stab;
- XARG *cond;
- XARG *arg;
- X{
- X register CMD *cmd;
- X
- X Newz(107,cmd,1,CMD);
- X cmd->c_type = type;
- X cmd->ucmd.acmd.ac_stab = stab;
- X cmd->ucmd.acmd.ac_expr = arg;
- X cmd->c_expr = cond;
- X if (cond)
- X cmd->c_flags |= CF_COND;
- X if (cmdline != NOLINE) {
- X cmd->c_line = cmdline;
- X cmdline = NOLINE;
- X }
- X cmd->c_file = filename;
- X if (perldb)
- X cmd = dodb(cmd);
- X return cmd;
- X}
- X
- XCMD *
- Xmake_ccmd(type,arg,cblock)
- Xint type;
- XARG *arg;
- Xstruct compcmd cblock;
- X{
- X register CMD *cmd;
- X
- X Newz(108,cmd, 1, CMD);
- X cmd->c_type = type;
- X cmd->c_expr = arg;
- X cmd->ucmd.ccmd.cc_true = cblock.comp_true;
- X cmd->ucmd.ccmd.cc_alt = cblock.comp_alt;
- X if (arg)
- X cmd->c_flags |= CF_COND;
- X if (cmdline != NOLINE) {
- X cmd->c_line = cmdline;
- X cmdline = NOLINE;
- X }
- X if (perldb)
- X cmd = dodb(cmd);
- X return cmd;
- X}
- X
- XCMD *
- Xmake_icmd(type,arg,cblock)
- Xint type;
- XARG *arg;
- Xstruct compcmd cblock;
- X{
- X register CMD *cmd;
- X register CMD *alt;
- X register CMD *cur;
- X register CMD *head;
- X struct compcmd ncblock;
- X
- X Newz(109,cmd, 1, CMD);
- X head = cmd;
- X cmd->c_type = type;
- X cmd->c_expr = arg;
- X cmd->ucmd.ccmd.cc_true = cblock.comp_true;
- X cmd->ucmd.ccmd.cc_alt = cblock.comp_alt;
- X if (arg)
- X cmd->c_flags |= CF_COND;
- X if (cmdline != NOLINE) {
- X cmd->c_line = cmdline;
- X cmdline = NOLINE;
- X }
- X cur = cmd;
- X alt = cblock.comp_alt;
- X while (alt && alt->c_type == C_ELSIF) {
- X cur = alt;
- X alt = alt->ucmd.ccmd.cc_alt;
- X }
- X if (alt) { /* a real life ELSE at the end? */
- X ncblock.comp_true = alt;
- X ncblock.comp_alt = Nullcmd;
- X alt = append_line(cur,make_ccmd(C_ELSE,Nullarg,ncblock));
- X cur->ucmd.ccmd.cc_alt = alt;
- X }
- X else
- X alt = cur; /* no ELSE, so cur is proxy ELSE */
- X
- X cur = cmd;
- X while (cmd) { /* now point everyone at the ELSE */
- X cur = cmd;
- X cmd = cur->ucmd.ccmd.cc_alt;
- X cur->c_head = head;
- X if (cur->c_type == C_ELSIF)
- X cur->c_type = C_IF;
- X if (cur->c_type == C_IF)
- X cur->ucmd.ccmd.cc_alt = alt;
- X if (cur == alt)
- X break;
- X cur->c_next = cmd;
- X }
- X if (perldb)
- X cur = dodb(cur);
- X return cur;
- X}
- X
- Xvoid
- Xopt_arg(cmd,fliporflop,acmd)
- Xregister CMD *cmd;
- Xint fliporflop;
- Xint acmd;
- X{
- X register ARG *arg;
- X int opt = CFT_EVAL;
- X int sure = 0;
- X ARG *arg2;
- X int context = 0; /* 0 = normal, 1 = before &&, 2 = before || */
- X int flp = fliporflop;
- X
- X if (!cmd)
- X return;
- X if (!(arg = cmd->c_expr)) {
- X cmd->c_flags &= ~CF_COND;
- X return;
- X }
- X
- X /* Can we turn && and || into if and unless? */
- X
- X if (acmd && !cmd->ucmd.acmd.ac_expr && !(cmd->c_flags & CF_TERM) &&
- X (arg->arg_type == O_AND || arg->arg_type == O_OR) ) {
- X dehoist(arg,1);
- X arg[2].arg_type &= A_MASK; /* don't suppress eval */
- X dehoist(arg,2);
- X cmd->ucmd.acmd.ac_expr = arg[2].arg_ptr.arg_arg;
- X cmd->c_expr = arg[1].arg_ptr.arg_arg;
- X if (arg->arg_type == O_OR)
- X cmd->c_flags ^= CF_INVERT; /* || is like unless */
- X arg->arg_len = 0;
- X free_arg(arg);
- X arg = cmd->c_expr;
- X }
- X
- X /* Turn "if (!expr)" into "unless (expr)" */
- X
- X if (!(cmd->c_flags & CF_TERM)) { /* unless return value wanted */
- X while (arg->arg_type == O_NOT) {
- X dehoist(arg,1);
- X cmd->c_flags ^= CF_INVERT; /* flip sense of cmd */
- X cmd->c_expr = arg[1].arg_ptr.arg_arg; /* hoist the rest of expr */
- X free_arg(arg);
- X arg = cmd->c_expr; /* here we go again */
- X }
- X }
- X
- X if (!arg->arg_len) { /* sanity check */
- X cmd->c_flags |= opt;
- X return;
- X }
- X
- X /* for "cond .. cond" we set up for the initial check */
- X
- X if (arg->arg_type == O_FLIP)
- X context |= 4;
- X
- X /* for "cond && expr" and "cond || expr" we can ignore expr, sort of */
- X
- X morecontext:
- X if (arg->arg_type == O_AND)
- X context |= 1;
- X else if (arg->arg_type == O_OR)
- X context |= 2;
- X if (context && (arg[flp].arg_type & A_MASK) == A_EXPR) {
- X arg = arg[flp].arg_ptr.arg_arg;
- X flp = 1;
- X if (arg->arg_type == O_AND || arg->arg_type == O_OR)
- X goto morecontext;
- X }
- X if ((context & 3) == 3)
- X return;
- X
- X if (arg[flp].arg_flags & (AF_PRE|AF_POST)) {
- X cmd->c_flags |= opt;
- X return; /* side effect, can't optimize */
- X }
- X
- X if (arg->arg_type == O_ITEM || arg->arg_type == O_FLIP ||
- X arg->arg_type == O_AND || arg->arg_type == O_OR) {
- X if ((arg[flp].arg_type & A_MASK) == A_SINGLE) {
- X opt = (str_true(arg[flp].arg_ptr.arg_str) ? CFT_TRUE : CFT_FALSE);
- X cmd->c_short = str_smake(arg[flp].arg_ptr.arg_str);
- X goto literal;
- X }
- X else if ((arg[flp].arg_type & A_MASK) == A_STAB ||
- X (arg[flp].arg_type & A_MASK) == A_LVAL) {
- X cmd->c_stab = arg[flp].arg_ptr.arg_stab;
- X opt = CFT_REG;
- X literal:
- X if (!context) { /* no && or ||? */
- X free_arg(arg);
- X cmd->c_expr = Nullarg;
- X }
- X if (!(context & 1))
- X cmd->c_flags |= CF_EQSURE;
- X if (!(context & 2))
- X cmd->c_flags |= CF_NESURE;
- X }
- X }
- X else if (arg->arg_type == O_MATCH || arg->arg_type == O_SUBST ||
- X arg->arg_type == O_NMATCH || arg->arg_type == O_NSUBST) {
- X if ((arg[1].arg_type == A_STAB || arg[1].arg_type == A_LVAL) &&
- X (arg[2].arg_type & A_MASK) == A_SPAT &&
- X arg[2].arg_ptr.arg_spat->spat_short ) {
- X cmd->c_stab = arg[1].arg_ptr.arg_stab;
- X cmd->c_short = str_smake(arg[2].arg_ptr.arg_spat->spat_short);
- X cmd->c_slen = arg[2].arg_ptr.arg_spat->spat_slen;
- X if (arg[2].arg_ptr.arg_spat->spat_flags & SPAT_ALL &&
- X !(arg[2].arg_ptr.arg_spat->spat_flags & SPAT_ONCE) &&
- X (arg->arg_type == O_MATCH || arg->arg_type == O_NMATCH) )
- X sure |= CF_EQSURE; /* (SUBST must be forced even */
- X /* if we know it will work.) */
- X if (arg->arg_type != O_SUBST) {
- X arg[2].arg_ptr.arg_spat->spat_short = Nullstr;
- X arg[2].arg_ptr.arg_spat->spat_slen = 0; /* only one chk */
- X }
- X sure |= CF_NESURE; /* normally only sure if it fails */
- X if (arg->arg_type == O_NMATCH || arg->arg_type == O_NSUBST)
- X cmd->c_flags |= CF_FIRSTNEG;
- X if (context & 1) { /* only sure if thing is false */
- X if (cmd->c_flags & CF_FIRSTNEG)
- X sure &= ~CF_NESURE;
- X else
- X sure &= ~CF_EQSURE;
- X }
- X else if (context & 2) { /* only sure if thing is true */
- X if (cmd->c_flags & CF_FIRSTNEG)
- X sure &= ~CF_EQSURE;
- X else
- X sure &= ~CF_NESURE;
- X }
- X if (sure & (CF_EQSURE|CF_NESURE)) { /* if we know anything*/
- X if (arg[2].arg_ptr.arg_spat->spat_flags & SPAT_SCANFIRST)
- X opt = CFT_SCAN;
- X else
- X opt = CFT_ANCHOR;
- X if (sure == (CF_EQSURE|CF_NESURE) /* really sure? */
- X && arg->arg_type == O_MATCH
- X && context & 4
- X && fliporflop == 1) {
- X spat_free(arg[2].arg_ptr.arg_spat);
- X arg[2].arg_ptr.arg_spat = Nullspat; /* don't do twice */
- X }
- X cmd->c_flags |= sure;
- X }
- X }
- X }
- X else if (arg->arg_type == O_SEQ || arg->arg_type == O_SNE ||
- X arg->arg_type == O_SLT || arg->arg_type == O_SGT) {
- X if (arg[1].arg_type == A_STAB || arg[1].arg_type == A_LVAL) {
- X if (arg[2].arg_type == A_SINGLE) {
- X cmd->c_stab = arg[1].arg_ptr.arg_stab;
- X cmd->c_short = str_smake(arg[2].arg_ptr.arg_str);
- X cmd->c_slen = cmd->c_short->str_cur+1;
- X switch (arg->arg_type) {
- X case O_SLT: case O_SGT:
- X sure |= CF_EQSURE;
- X cmd->c_flags |= CF_FIRSTNEG;
- X break;
- X case O_SNE:
- X cmd->c_flags |= CF_FIRSTNEG;
- X /* FALL THROUGH */
- X case O_SEQ:
- X sure |= CF_NESURE|CF_EQSURE;
- X break;
- X }
- X if (context & 1) { /* only sure if thing is false */
- X if (cmd->c_flags & CF_FIRSTNEG)
- X sure &= ~CF_NESURE;
- X else
- X sure &= ~CF_EQSURE;
- X }
- X else if (context & 2) { /* only sure if thing is true */
- X if (cmd->c_flags & CF_FIRSTNEG)
- X sure &= ~CF_EQSURE;
- X else
- X sure &= ~CF_NESURE;
- X }
- X if (sure & (CF_EQSURE|CF_NESURE)) {
- X opt = CFT_STROP;
- X cmd->c_flags |= sure;
- X }
- X }
- X }
- X }
- X else if (arg->arg_type == O_EQ || arg->arg_type == O_NE ||
- X arg->arg_type == O_LE || arg->arg_type == O_GE ||
- X arg->arg_type == O_LT || arg->arg_type == O_GT) {
- X if (arg[1].arg_type == A_STAB || arg[1].arg_type == A_LVAL) {
- X if (arg[2].arg_type == A_SINGLE) {
- X cmd->c_stab = arg[1].arg_ptr.arg_stab;
- X if (dowarn) {
- X STR *str = arg[2].arg_ptr.arg_str;
- X
- X if ((!str->str_nok && !looks_like_number(str)))
- X warn("Possible use of == on string value");
- X }
- X cmd->c_short = str_nmake(str_gnum(arg[2].arg_ptr.arg_str));
- X cmd->c_slen = arg->arg_type;
- X sure |= CF_NESURE|CF_EQSURE;
- X if (context & 1) { /* only sure if thing is false */
- X sure &= ~CF_EQSURE;
- X }
- X else if (context & 2) { /* only sure if thing is true */
- X sure &= ~CF_NESURE;
- X }
- X if (sure & (CF_EQSURE|CF_NESURE)) {
- X opt = CFT_NUMOP;
- X cmd->c_flags |= sure;
- X }
- X }
- X }
- X }
- X else if (arg->arg_type == O_ASSIGN &&
- X (arg[1].arg_type == A_STAB || arg[1].arg_type == A_LVAL) &&
- X arg[1].arg_ptr.arg_stab == defstab &&
- X arg[2].arg_type == A_EXPR ) {
- X arg2 = arg[2].arg_ptr.arg_arg;
- X if (arg2->arg_type == O_ITEM && arg2[1].arg_type == A_READ) {
- X opt = CFT_GETS;
- X cmd->c_stab = arg2[1].arg_ptr.arg_stab;
- X if (!(stab_io(arg2[1].arg_ptr.arg_stab)->flags & IOF_ARGV)) {
- X free_arg(arg2);
- X free_arg(arg);
- X cmd->c_expr = Nullarg;
- X }
- X }
- X }
- X else if (arg->arg_type == O_CHOP &&
- X (arg[1].arg_type == A_STAB || arg[1].arg_type == A_LVAL) ) {
- X opt = CFT_CHOP;
- X cmd->c_stab = arg[1].arg_ptr.arg_stab;
- X free_arg(arg);
- X cmd->c_expr = Nullarg;
- X }
- X if (context & 4)
- X opt |= CF_FLIP;
- X cmd->c_flags |= opt;
- X
- X if (cmd->c_flags & CF_FLIP) {
- X if (fliporflop == 1) {
- X arg = cmd->c_expr; /* get back to O_FLIP arg */
- X New(110,arg[3].arg_ptr.arg_cmd, 1, CMD);
- X Copy(cmd, arg[3].arg_ptr.arg_cmd, 1, CMD);
- X New(111,arg[4].arg_ptr.arg_cmd,1,CMD);
- X Copy(cmd, arg[4].arg_ptr.arg_cmd, 1, CMD);
- X opt_arg(arg[4].arg_ptr.arg_cmd,2,acmd);
- X arg->arg_len = 2; /* this is a lie */
- X }
- X else {
- X if ((opt & CF_OPTIMIZE) == CFT_EVAL)
- X cmd->c_flags = (cmd->c_flags & ~CF_OPTIMIZE) | CFT_UNFLIP;
- X }
- X }
- X}
- X
- XCMD *
- Xadd_label(lbl,cmd)
- Xchar *lbl;
- Xregister CMD *cmd;
- X{
- X if (cmd)
- X cmd->c_label = lbl;
- X return cmd;
- X}
- X
- XCMD *
- Xaddcond(cmd, arg)
- Xregister CMD *cmd;
- Xregister ARG *arg;
- X{
- X cmd->c_expr = arg;
- X cmd->c_flags |= CF_COND;
- X return cmd;
- X}
- X
- XCMD *
- Xaddloop(cmd, arg)
- Xregister CMD *cmd;
- Xregister ARG *arg;
- X{
- X void while_io();
- X
- X cmd->c_expr = arg;
- X cmd->c_flags |= CF_COND|CF_LOOP;
- X
- X if (!(cmd->c_flags & CF_INVERT))
- X while_io(cmd); /* add $_ =, if necessary */
- X
- X if (cmd->c_type == C_BLOCK)
- X cmd->c_flags &= ~CF_COND;
- X else {
- X arg = cmd->ucmd.acmd.ac_expr;
- X if (arg && arg->arg_type == O_ITEM && arg[1].arg_type == A_CMD)
- X cmd->c_flags &= ~CF_COND; /* "do {} while" happens at least once */
- X if (arg && arg->arg_type == O_SUBR)
- X cmd->c_flags &= ~CF_COND; /* likewise for "do subr() while" */
- X }
- X return cmd;
- X}
- X
- XCMD *
- Xinvert(cmd)
- Xregister CMD *cmd;
- X{
- X if (cmd->c_head)
- X cmd->c_head->c_flags ^= CF_INVERT;
- X else
- X cmd->c_flags ^= CF_INVERT;
- X return cmd;
- X}
- X
- Xyyerror(s)
- Xchar *s;
- X{
- X char tmpbuf[258];
- X char tmp2buf[258];
- X char *tname = tmpbuf;
- X
- X if (bufptr > oldoldbufptr && bufptr - oldoldbufptr < 200 &&
- X oldoldbufptr != oldbufptr && oldbufptr != bufptr) {
- X while (isspace(*oldoldbufptr))
- X oldoldbufptr++;
- X strncpy(tmp2buf, oldoldbufptr, bufptr - oldoldbufptr);
- X tmp2buf[bufptr - oldoldbufptr] = '\0';
- X sprintf(tname,"next 2 tokens \"%s\"",tmp2buf);
- X }
- X else if (bufptr > oldbufptr && bufptr - oldbufptr < 200 &&
- X oldbufptr != bufptr) {
- X while (isspace(*oldbufptr))
- X oldbufptr++;
- X strncpy(tmp2buf, oldbufptr, bufptr - oldbufptr);
- X tmp2buf[bufptr - oldbufptr] = '\0';
- X sprintf(tname,"next token \"%s\"",tmp2buf);
- X }
- X else if (yychar > 256)
- X tname = "next token ???";
- X else if (!yychar)
- X (void)strcpy(tname,"at EOF");
- X else if (yychar < 32)
- X (void)sprintf(tname,"next char ^%c",yychar+64);
- X else if (yychar == 127)
- X (void)strcpy(tname,"at EOF");
- X else
- X (void)sprintf(tname,"next char %c",yychar);
- X (void)sprintf(buf, "%s in file %s at line %d, %s\n",
- X s,filename,line,tname);
- X if (line == multi_end && multi_start < multi_end)
- X sprintf(buf+strlen(buf),
- X " (Might be a runaway multi-line %c%c string starting on line %d)\n",
- X multi_open,multi_close,multi_start);
- X if (in_eval)
- X str_cat(stab_val(stabent("@",TRUE)),buf);
- X else
- X fputs(buf,stderr);
- X if (++error_count >= 10)
- X fatal("Too many errors\n");
- X}
- X
- Xvoid
- Xwhile_io(cmd)
- Xregister CMD *cmd;
- X{
- X register ARG *arg = cmd->c_expr;
- X STAB *asgnstab;
- X
- X /* hoist "while (<channel>)" up into command block */
- X
- X if (arg && arg->arg_type == O_ITEM && arg[1].arg_type == A_READ) {
- X cmd->c_flags &= ~CF_OPTIMIZE; /* clear optimization type */
- X cmd->c_flags |= CFT_GETS; /* and set it to do the input */
- X cmd->c_stab = arg[1].arg_ptr.arg_stab;
- X if (stab_io(arg[1].arg_ptr.arg_stab)->flags & IOF_ARGV) {
- X cmd->c_expr = l(make_op(O_ASSIGN, 2, /* fake up "$_ =" */
- X stab2arg(A_LVAL,defstab), arg, Nullarg));
- X }
- X else {
- X free_arg(arg);
- X cmd->c_expr = Nullarg;
- X }
- X }
- X else if (arg && arg->arg_type == O_ITEM && arg[1].arg_type == A_INDREAD) {
- X cmd->c_flags &= ~CF_OPTIMIZE; /* clear optimization type */
- X cmd->c_flags |= CFT_INDGETS; /* and set it to do the input */
- X cmd->c_stab = arg[1].arg_ptr.arg_stab;
- X free_arg(arg);
- X cmd->c_expr = Nullarg;
- X }
- X else if (arg && arg->arg_type == O_ITEM && arg[1].arg_type == A_GLOB) {
- X if ((cmd->c_flags & CF_OPTIMIZE) == CFT_ARRAY)
- X asgnstab = cmd->c_stab;
- X else
- X asgnstab = defstab;
- X cmd->c_expr = l(make_op(O_ASSIGN, 2, /* fake up "$foo =" */
- X stab2arg(A_LVAL,asgnstab), arg, Nullarg));
- X cmd->c_flags &= ~CF_OPTIMIZE; /* clear optimization type */
- X }
- X}
- X
- XCMD *
- Xwopt(cmd)
- Xregister CMD *cmd;
- X{
- X register CMD *tail;
- X CMD *newtail;
- X register int i;
- X
- X if (cmd->c_expr && (cmd->c_flags & CF_OPTIMIZE) == CFT_FALSE)
- X opt_arg(cmd,1, cmd->c_type == C_EXPR);
- X
- X while_io(cmd); /* add $_ =, if necessary */
- X
- X /* First find the end of the true list */
- X
- X tail = cmd->ucmd.ccmd.cc_true;
- X if (tail == Nullcmd)
- X return cmd;
- X New(112,newtail, 1, CMD); /* guaranteed continue */
- X for (;;) {
- X /* optimize "next" to point directly to continue block */
- X if (tail->c_type == C_EXPR &&
- X tail->ucmd.acmd.ac_expr &&
- X tail->ucmd.acmd.ac_expr->arg_type == O_NEXT &&
- X (tail->ucmd.acmd.ac_expr->arg_len == 0 ||
- X (cmd->c_label &&
- X strEQ(cmd->c_label,
- X tail->ucmd.acmd.ac_expr[1].arg_ptr.arg_str->str_ptr) )))
- X {
- X arg_free(tail->ucmd.acmd.ac_expr);
- X tail->c_type = C_NEXT;
- X if (cmd->ucmd.ccmd.cc_alt != Nullcmd)
- X tail->ucmd.ccmd.cc_alt = cmd->ucmd.ccmd.cc_alt;
- X else
- X tail->ucmd.ccmd.cc_alt = newtail;
- X tail->ucmd.ccmd.cc_true = Nullcmd;
- X }
- X else if (tail->c_type == C_IF && !tail->ucmd.ccmd.cc_alt) {
- X if (cmd->ucmd.ccmd.cc_alt != Nullcmd)
- X tail->ucmd.ccmd.cc_alt = cmd->ucmd.ccmd.cc_alt;
- X else
- X tail->ucmd.ccmd.cc_alt = newtail;
- X }
- X else if (tail->c_type == C_CSWITCH || tail->c_type == C_NSWITCH) {
- X if (cmd->ucmd.ccmd.cc_alt != Nullcmd) {
- X for (i = tail->ucmd.scmd.sc_max; i >= 0; i--)
- X if (!tail->ucmd.scmd.sc_next[i])
- X tail->ucmd.scmd.sc_next[i] = cmd->ucmd.ccmd.cc_alt;
- X }
- X else {
- X for (i = tail->ucmd.scmd.sc_max; i >= 0; i--)
- X if (!tail->ucmd.scmd.sc_next[i])
- X tail->ucmd.scmd.sc_next[i] = newtail;
- X }
- X }
- X
- X if (!tail->c_next)
- X break;
- X tail = tail->c_next;
- X }
- X
- X /* if there's a continue block, link it to true block and find end */
- X
- X if (cmd->ucmd.ccmd.cc_alt != Nullcmd) {
- X tail->c_next = cmd->ucmd.ccmd.cc_alt;
- X tail = tail->c_next;
- X for (;;) {
- X /* optimize "next" to point directly to continue block */
- X if (tail->c_type == C_EXPR &&
- X tail->ucmd.acmd.ac_expr &&
- X tail->ucmd.acmd.ac_expr->arg_type == O_NEXT &&
- X (tail->ucmd.acmd.ac_expr->arg_len == 0 ||
- X (cmd->c_label &&
- X strEQ(cmd->c_label,
- X tail->ucmd.acmd.ac_expr[1].arg_ptr.arg_str->str_ptr) )))
- X {
- X arg_free(tail->ucmd.acmd.ac_expr);
- X tail->c_type = C_NEXT;
- X tail->ucmd.ccmd.cc_alt = newtail;
- X tail->ucmd.ccmd.cc_true = Nullcmd;
- X }
- X else if (tail->c_type == C_IF && !tail->ucmd.ccmd.cc_alt) {
- X tail->ucmd.ccmd.cc_alt = newtail;
- X }
- X else if (tail->c_type == C_CSWITCH || tail->c_type == C_NSWITCH) {
- X for (i = tail->ucmd.scmd.sc_max; i >= 0; i--)
- X if (!tail->ucmd.scmd.sc_next[i])
- X tail->ucmd.scmd.sc_next[i] = newtail;
- X }
- X
- X if (!tail->c_next)
- X break;
- X tail = tail->c_next;
- X }
- X for ( ; tail->c_next; tail = tail->c_next) ;
- X }
- X
- X /* Here's the real trick: link the end of the list back to the beginning,
- X * inserting a "last" block to break out of the loop. This saves one or
- X * two procedure calls every time through the loop, because of how cmd_exec
- X * does tail recursion.
- X */
- X
- X tail->c_next = newtail;
- X tail = newtail;
- X if (!cmd->ucmd.ccmd.cc_alt)
- X cmd->ucmd.ccmd.cc_alt = tail; /* every loop has a continue now */
- X
- X#ifndef lint
- X (void)bcopy((char *)cmd, (char *)tail, sizeof(CMD));
- X#endif
- X tail->c_type = C_EXPR;
- X tail->c_flags ^= CF_INVERT; /* turn into "last unless" */
- X tail->c_next = tail->ucmd.ccmd.cc_true; /* loop directly back to top */
- X tail->ucmd.acmd.ac_expr = make_op(O_LAST,0,Nullarg,Nullarg,Nullarg);
- X tail->ucmd.acmd.ac_stab = Nullstab;
- X return cmd;
- X}
- X
- XCMD *
- Xover(eachstab,cmd)
- XSTAB *eachstab;
- Xregister CMD *cmd;
- X{
- X /* hoist "for $foo (@bar)" up into command block */
- X
- X cmd->c_flags &= ~CF_OPTIMIZE; /* clear optimization type */
- X cmd->c_flags |= CFT_ARRAY; /* and set it to do the iteration */
- X cmd->c_stab = eachstab;
- X
- X return cmd;
- X}
- X
- Xcmd_free(cmd)
- Xregister CMD *cmd;
- X{
- X register CMD *tofree;
- X register CMD *head = cmd;
- X
- X while (cmd) {
- X if (cmd->c_type != C_WHILE) { /* WHILE block is duplicated */
- X if (cmd->c_label)
- X Safefree(cmd->c_label);
- X if (cmd->c_short)
- X str_free(cmd->c_short);
- X if (cmd->c_spat)
- X spat_free(cmd->c_spat);
- X if (cmd->c_expr)
- X arg_free(cmd->c_expr);
- X }
- X switch (cmd->c_type) {
- X case C_WHILE:
- X case C_BLOCK:
- X case C_ELSE:
- X case C_IF:
- X if (cmd->ucmd.ccmd.cc_true)
- X cmd_free(cmd->ucmd.ccmd.cc_true);
- X break;
- X case C_EXPR:
- X if (cmd->ucmd.acmd.ac_expr)
- X arg_free(cmd->ucmd.acmd.ac_expr);
- X break;
- X }
- X tofree = cmd;
- X cmd = cmd->c_next;
- X Safefree(tofree);
- X if (cmd && cmd == head) /* reached end of while loop */
- X break;
- X }
- X}
- X
- Xarg_free(arg)
- Xregister ARG *arg;
- X{
- X register int i;
- X
- X for (i = 1; i <= arg->arg_len; i++) {
- X switch (arg[i].arg_type & A_MASK) {
- X case A_NULL:
- X break;
- X case A_LEXPR:
- X if (arg->arg_type == O_AASSIGN &&
- X arg[i].arg_ptr.arg_arg->arg_type == O_LARRAY) {
- X char *name =
- X stab_name(arg[i].arg_ptr.arg_arg[1].arg_ptr.arg_stab);
- X
- X if (strnEQ("_GEN_",name, 5)) /* array for foreach */
- X hdelete(defstash,name,strlen(name));
- X }
- X /* FALL THROUGH */
- X case A_EXPR:
- X arg_free(arg[i].arg_ptr.arg_arg);
- X break;
- X case A_CMD:
- X cmd_free(arg[i].arg_ptr.arg_cmd);
- X break;
- X case A_WORD:
- X case A_STAB:
- X case A_LVAL:
- X case A_READ:
- X case A_GLOB:
- X case A_ARYLEN:
- X case A_LARYLEN:
- X case A_ARYSTAB:
- X case A_LARYSTAB:
- X break;
- X case A_SINGLE:
- X case A_DOUBLE:
- X case A_BACKTICK:
- X str_free(arg[i].arg_ptr.arg_str);
- X break;
- X case A_SPAT:
- X spat_free(arg[i].arg_ptr.arg_spat);
- X break;
- X }
- X }
- X free_arg(arg);
- X}
- X
- Xspat_free(spat)
- Xregister SPAT *spat;
- X{
- X register SPAT *sp;
- X HENT *entry;
- X
- X if (spat->spat_runtime)
- X arg_free(spat->spat_runtime);
- X if (spat->spat_repl) {
- X arg_free(spat->spat_repl);
- X }
- X if (spat->spat_short) {
- X str_free(spat->spat_short);
- X }
- X if (spat->spat_regexp) {
- X regfree(spat->spat_regexp);
- X }
- X
- X /* now unlink from spat list */
- X
- X for (entry = defstash->tbl_array['_']; entry; entry = entry->hent_next) {
- X register HASH *stash;
- X STAB *stab = (STAB*)entry->hent_val;
- X
- X if (!stab)
- X continue;
- X stash = stab_hash(stab);
- X if (!stash || stash->tbl_spatroot == Null(SPAT*))
- X continue;
- X if (stash->tbl_spatroot == spat)
- X stash->tbl_spatroot = spat->spat_next;
- X else {
- X for (sp = stash->tbl_spatroot;
- X sp && sp->spat_next != spat;
- X sp = sp->spat_next)
- X ;
- X if (sp)
- X sp->spat_next = spat->spat_next;
- X }
- X }
- X Safefree(spat);
- X}
- X
- X/* Recursively descend a command sequence and push the address of any string
- X * that needs saving on recursion onto the tosave array.
- X */
- X
- Xstatic int
- Xcmd_tosave(cmd,willsave)
- Xregister CMD *cmd;
- Xint willsave; /* willsave passes down the tree */
- X{
- X register CMD *head = cmd;
- X int shouldsave = FALSE; /* shouldsave passes up the tree */
- X int tmpsave;
- X register CMD *lastcmd = Nullcmd;
- X
- X while (cmd) {
- X if (cmd->c_spat)
- X shouldsave |= spat_tosave(cmd->c_spat);
- X if (cmd->c_expr)
- X shouldsave |= arg_tosave(cmd->c_expr,willsave);
- X switch (cmd->c_type) {
- X case C_WHILE:
- X if (cmd->ucmd.ccmd.cc_true) {
- X tmpsave = cmd_tosave(cmd->ucmd.ccmd.cc_true,willsave);
- X
- X /* Here we check to see if the temporary array generated for
- X * a foreach needs to be localized because of recursion.
- X */
- X if (tmpsave && (cmd->c_flags & CF_OPTIMIZE) == CFT_ARRAY &&
- X lastcmd &&
- X lastcmd->c_type == C_EXPR &&
- X lastcmd->ucmd.acmd.ac_expr) {
- X ARG *arg = lastcmd->ucmd.acmd.ac_expr;
- X
- X if (arg->arg_type == O_ASSIGN &&
- X arg[1].arg_type == A_LEXPR &&
- X arg[1].arg_ptr.arg_arg->arg_type == O_LARRAY &&
- X strnEQ("_GEN_",
- X stab_name(arg[1].arg_ptr.arg_arg[1].arg_ptr.arg_stab),
- X 5)) { /* array generated for foreach */
- X (void)localize(arg[1].arg_ptr.arg_arg);
- X }
- X }
- X shouldsave |= tmpsave;
- X }
- X break;
- X case C_BLOCK:
- X case C_ELSE:
- X case C_IF:
- X if (cmd->ucmd.ccmd.cc_true)
- X shouldsave |= cmd_tosave(cmd->ucmd.ccmd.cc_true,willsave);
- X break;
- X case C_EXPR:
- X if (cmd->ucmd.acmd.ac_expr)
- X shouldsave |= arg_tosave(cmd->ucmd.acmd.ac_expr,willsave);
- X break;
- X }
- X lastcmd = cmd;
- X cmd = cmd->c_next;
- X if (cmd && cmd == head) /* reached end of while loop */
- X break;
- X }
- X return shouldsave;
- X}
- X
- Xstatic int
- Xarg_tosave(arg,willsave)
- Xregister ARG *arg;
- Xint willsave;
- X{
- X register int i;
- X int shouldsave = FALSE;
- X
- X for (i = arg->arg_len; i >= 1; i--) {
- X switch (arg[i].arg_type & A_MASK) {
- X case A_NULL:
- X break;
- X case A_LEXPR:
- X case A_EXPR:
- X shouldsave |= arg_tosave(arg[i].arg_ptr.arg_arg,shouldsave);
- X break;
- X case A_CMD:
- X shouldsave |= cmd_tosave(arg[i].arg_ptr.arg_cmd,shouldsave);
- X break;
- X case A_WORD:
- X case A_STAB:
- X case A_LVAL:
- X case A_READ:
- X case A_GLOB:
- X case A_ARYLEN:
- X case A_SINGLE:
- X case A_DOUBLE:
- X case A_BACKTICK:
- X break;
- X case A_SPAT:
- X shouldsave |= spat_tosave(arg[i].arg_ptr.arg_spat);
- X break;
- X }
- X }
- X switch (arg->arg_type) {
- X case O_RETURN:
- X saw_return = TRUE;
- X break;
- X case O_EVAL:
- X case O_SUBR:
- X shouldsave = TRUE;
- X break;
- X }
- X if (willsave)
- X (void)apush(tosave,arg->arg_ptr.arg_str);
- X return shouldsave;
- X}
- X
- Xstatic int
- Xspat_tosave(spat)
- Xregister SPAT *spat;
- X{
- X int shouldsave = FALSE;
- X
- X if (spat->spat_runtime)
- X shouldsave |= arg_tosave(spat->spat_runtime,FALSE);
- X if (spat->spat_repl) {
- X shouldsave |= arg_tosave(spat->spat_repl,FALSE);
- X }
- X
- X return shouldsave;
- X}
- X
- !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/op.list
- sed >t/op.list <<'!STUFFY!FUNK!' -e 's/X//'
- X#!./perl
- X
- X# $Header: op.list,v 3.0 89/10/18 15:29:44 lwall Locked $
- X
- Xprint "1..27\n";
- X
- X@foo = (1, 2, 3, 4);
- Xif ($foo[0] == 1 && $foo[3] == 4) {print "ok 1\n";} else {print "not ok 1\n";}
- X
- X$_ = join(':',@foo);
- Xif ($_ eq '1:2:3:4') {print "ok 2\n";} else {print "not ok 2\n";}
- X
- X($a,$b,$c,$d) = (1,2,3,4);
- Xif ("$a;$b;$c;$d" eq '1;2;3;4') {print "ok 3\n";} else {print "not ok 3\n";}
- X
- X($c,$b,$a) = split(/ /,"111 222 333");
- Xif ("$a;$b;$c" eq '333;222;111') {print "ok 4\n";} else {print "not ok 4\n";}
- X
- X($a,$b,$c) = ($c,$b,$a);
- Xif ("$a;$b;$c" eq '111;222;333') {print "ok 5\n";} else {print "not ok 5 $a;$b;$c\n";}
- X
- X($a, $b) = ($b, $a);
- Xif ("$a;$b;$c" eq '222;111;333') {print "ok 6\n";} else {print "not ok 6\n";}
- X
- X($a, $b[1], $c{2}, $d) = (1, 2, 3, 4);
- Xif ($a eq 1) {print "ok 7\n";} else {print "not ok 7\n";}
- Xif ($b[1] eq 2) {print "ok 8\n";} else {print "not ok 8\n";}
- Xif ($c{2} eq 3) {print "ok 9\n";} else {print "not ok 9\n";}
- Xif ($d eq 4) {print "ok 10\n";} else {print "not ok 10\n";}
- X
- X@foo = (1,2,3,4,5,6,7,8);
- X($a, $b, $c, $d) = @foo;
- Xprint "#11 $a;$b;$c;$d eq 1;2;3;4\n";
- Xif ("$a;$b;$c;$d" eq '1;2;3;4') {print "ok 11\n";} else {print "not ok 11\n";}
- X
- X@foo = @bar = (1);
- Xif (join(':',@foo,@bar) eq '1:1') {print "ok 12\n";} else {print "not ok 12\n";}
- X
- X@foo = ();
- X@foo = 1+2+3;
- Xif (join(':',@foo) eq '6') {print "ok 13\n";} else {print "not ok 13\n";}
- X
- Xfor ($x = 0; $x < 3; $x++) {
- X ($a, $b, $c) =
- X $x == 0?
- X ('ok ', 14, "\n"):
- X $x == 1?
- X ('ok ', 15, "\n"):
- X # default
- X ('ok ', 16, "\n");
- X
- X print $a,$b,$c;
- X}
- X
- X@a = ($x == 12345 || (1,2,3));
- Xif (join('',@a) eq '123') {print "ok 17\n";} else {print "not ok 17\n";}
- X
- X@a = ($x == $x || (4,5,6));
- Xif (join('',@a) eq '1') {print "ok 18\n";} else {print "not ok 18\n";}
- X
- Xif (join('',1,2,(3,4,5)) eq '12345'){print "ok 19\n";}else{print "not ok 19\n";}
- Xif (join('',(1,2,3,4,5)) eq '12345'){print "ok 20\n";}else{print "not ok 20\n";}
- Xif (join('',(1,2,3,4),5) eq '12345'){print "ok 21\n";}else{print "not ok 21\n";}
- Xif (join('',1,(2,3,4),5) eq '12345'){print "ok 22\n";}else{print "not ok 22\n";}
- Xif (join('',1,2,(3,4),5) eq '12345'){print "ok 23\n";}else{print "not ok 23\n";}
- Xif (join('',1,2,3,(4),5) eq '12345'){print "ok 24\n";}else{print "not ok 24\n";}
- X
- Xfor ($x = 0; $x < 3; $x++) {
- X ($a, $b, $c) = do {
- X if ($x == 0) {
- X ('ok ', 25, "\n");
- X }
- X elsif ($x == 1) {
- X ('ok ', 26, "\n");
- X }
- X else {
- X ('ok ', 27, "\n");
- X }
- X };
- X
- X print $a,$b,$c;
- X}
- X
- !STUFFY!FUNK!
- echo Extracting patchlevel.h
- sed >patchlevel.h <<'!STUFFY!FUNK!' -e 's/X//'
- X#define PATCHLEVEL 0
- !STUFFY!FUNK!
- echo ""
- echo "End of kit 10 (of 24)"
- cat /dev/null >kit10isdone
- 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; 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."
- chmod 755 Configure
- ;;
- *) echo "You have run$run."
- echo "You still need to run$todo."
- ;;
- esac
- : Someone might mail this, so...
- exit
-
-