10Sstevel@tonic-gate /* 20Sstevel@tonic-gate * CDDL HEADER START 30Sstevel@tonic-gate * 40Sstevel@tonic-gate * The contents of this file are subject to the terms of the 50Sstevel@tonic-gate * Common Development and Distribution License, Version 1.0 only 60Sstevel@tonic-gate * (the "License"). You may not use this file except in compliance 70Sstevel@tonic-gate * with the License. 80Sstevel@tonic-gate * 90Sstevel@tonic-gate * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE 100Sstevel@tonic-gate * or http://www.opensolaris.org/os/licensing. 110Sstevel@tonic-gate * See the License for the specific language governing permissions 120Sstevel@tonic-gate * and limitations under the License. 130Sstevel@tonic-gate * 140Sstevel@tonic-gate * When distributing Covered Code, include this CDDL HEADER in each 150Sstevel@tonic-gate * file and include the License file at usr/src/OPENSOLARIS.LICENSE. 160Sstevel@tonic-gate * If applicable, add the following below this CDDL HEADER, with the 170Sstevel@tonic-gate * fields enclosed by brackets "[]" replaced with your own identifying 180Sstevel@tonic-gate * information: Portions Copyright [yyyy] [name of copyright owner] 190Sstevel@tonic-gate * 200Sstevel@tonic-gate * CDDL HEADER END 210Sstevel@tonic-gate */ 22*335Smuffin /* 23*335Smuffin * Copyright 2005 Sun Microsystems, Inc. All rights reserved. 24*335Smuffin * Use is subject to license terms. 25*335Smuffin */ 26*335Smuffin 270Sstevel@tonic-gate /* Copyright (c) 1984, 1986, 1987, 1988, 1989 AT&T */ 280Sstevel@tonic-gate /* All Rights Reserved */ 290Sstevel@tonic-gate 30*335Smuffin #pragma ident "%Z%%M% %I% %E% SMI" 310Sstevel@tonic-gate 320Sstevel@tonic-gate #define FATAL 0 330Sstevel@tonic-gate #define NFATAL 1 340Sstevel@tonic-gate #define BLK sizeof (struct blk) 350Sstevel@tonic-gate #define PTRSZ sizeof (int *) 360Sstevel@tonic-gate #define HEADSZ 1024 370Sstevel@tonic-gate #define STKSZ 100 380Sstevel@tonic-gate #define RDSKSZ 100 390Sstevel@tonic-gate #define TBLSZ 256 400Sstevel@tonic-gate #define ARRAYST 0241 410Sstevel@tonic-gate #define NL 1 420Sstevel@tonic-gate #define NG 2 430Sstevel@tonic-gate #define NE 3 440Sstevel@tonic-gate #define length(p) ((p)->wt-(p)->beg) 450Sstevel@tonic-gate #define rewind(p) ((p)->rd = (p)->beg) 460Sstevel@tonic-gate #define create(p) ((p)->rd = (p)->wt = (p)->beg) 470Sstevel@tonic-gate #define fsfile(p) ((p)->rd = (p)->wt) 480Sstevel@tonic-gate #define truncate(p) ((p)->wt = (p)->rd) 490Sstevel@tonic-gate #define sfeof(p) (((p)->rd >= (p)->wt) ? 1 : 0) 500Sstevel@tonic-gate #define sfbeg(p) (((p)->rd == (p)->beg) ? 1 : 0) 510Sstevel@tonic-gate #define sungetc(p, c) (*(--(p)->rd) = c) 520Sstevel@tonic-gate #define sgetc(p) (((p)->rd == (p)->wt) ? EOF: ctoint((int)*(p)->rd++)) 530Sstevel@tonic-gate #define slookc(p) (((p)->rd == (p)->wt) ? EOF: ctoint((int)*(p)->rd)) 540Sstevel@tonic-gate #define sbackc(p) (((p)->rd == (p)->beg) ? EOF: ctoint((int)*(--(p)->rd))) 550Sstevel@tonic-gate #define sputc(p, c) {if ((p)->wt == (p)->last) more(p); *(p)->wt++ = c; } 560Sstevel@tonic-gate #define salterc(p, c) {if ((p)->rd == (p)->last) more(p); *(p)->rd++ = c;\ 570Sstevel@tonic-gate if ((p)->rd > (p)->wt) (p)->wt = (p)->rd; } 580Sstevel@tonic-gate #define sunputc(p) (*((p)->rd = --(p)->wt)) 590Sstevel@tonic-gate #define zero(p) for (pp = (p)->beg; pp < (p)->last; ) *pp++ = '\0' 600Sstevel@tonic-gate #define OUTC(x) {printf("%c", x); if (--count == 0)\ 610Sstevel@tonic-gate {printf("\\\n"); count = ll; } } 620Sstevel@tonic-gate #define TEST2 {if ((count -= 2) <= 0) {printf("\\\n"); count = ll; } } 630Sstevel@tonic-gate #define PRINT_MESSAGE printf(gettext("stack empty\n")) 640Sstevel@tonic-gate #define EMPTY if (stkerr != 0) {PRINT_MESSAGE; continue; } 650Sstevel@tonic-gate #define EMPTYR(x) if (stkerr != 0) {pushp(x); PRINT_MESSAGE; continue; } 660Sstevel@tonic-gate #define EMPTYS if (stkerr != 0) {PRINT_MESSAGE; return (1); } 670Sstevel@tonic-gate #define EMPTYSR(x) if (stkerr != 0) {PRINT_MESSAGE; pushp(x); return (1); } 680Sstevel@tonic-gate #define CHECKEND { \ 690Sstevel@tonic-gate if (count == 2) { \ 700Sstevel@tonic-gate printf("\\\n"); \ 710Sstevel@tonic-gate count = ll; \ 720Sstevel@tonic-gate } \ 730Sstevel@tonic-gate } 740Sstevel@tonic-gate #define error(p) {printf(p); continue; } 750Sstevel@tonic-gate #define errorrt(p) {printf(p); return (1); } 760Sstevel@tonic-gate struct blk { 770Sstevel@tonic-gate char *rd; 780Sstevel@tonic-gate char *wt; 790Sstevel@tonic-gate char *beg; 800Sstevel@tonic-gate char *last; 810Sstevel@tonic-gate }; 820Sstevel@tonic-gate struct wblk { 830Sstevel@tonic-gate struct blk **rdw; 840Sstevel@tonic-gate struct blk **wtw; 850Sstevel@tonic-gate struct blk **begw; 860Sstevel@tonic-gate struct blk **lastw; 870Sstevel@tonic-gate }; 880Sstevel@tonic-gate struct blk *hfree; 89*335Smuffin struct blk *getwd(struct blk *); 90*335Smuffin struct blk *lookwd(struct blk *); 91*335Smuffin struct blk *getdec(struct blk *, int); 92*335Smuffin struct blk *morehd(void); 930Sstevel@tonic-gate 940Sstevel@tonic-gate struct blk *arg1, *arg2; 950Sstevel@tonic-gate int svargc; 960Sstevel@tonic-gate char savk; 970Sstevel@tonic-gate char **svargv; 980Sstevel@tonic-gate int dbg; 990Sstevel@tonic-gate int ifile; 1000Sstevel@tonic-gate FILE *curfile; 1010Sstevel@tonic-gate struct blk *scalptr, *basptr, *tenptr, *inbas; 1020Sstevel@tonic-gate struct blk *sqtemp, *chptr, *strptr, *divxyz; 1030Sstevel@tonic-gate struct blk *stack[STKSZ]; 1040Sstevel@tonic-gate struct blk **stkptr, **stkbeg; 1050Sstevel@tonic-gate struct blk **stkend; 1060Sstevel@tonic-gate int stkerr; 1070Sstevel@tonic-gate int lastchar; 1080Sstevel@tonic-gate struct blk *readstk[RDSKSZ]; 1090Sstevel@tonic-gate struct blk **readptr; 1100Sstevel@tonic-gate struct blk *rem; 1110Sstevel@tonic-gate int k; 1120Sstevel@tonic-gate struct blk *irem; 1130Sstevel@tonic-gate int skd, skr; 114*335Smuffin struct blk *pop(void), *readin(void), *add0(struct blk *, int), 115*335Smuffin *mult(struct blk *, struct blk *); 116*335Smuffin struct blk *scalint(struct blk *); 117*335Smuffin struct blk *removc(struct blk *, int); 118*335Smuffin struct blk *add(struct blk *, struct blk *), 119*335Smuffin *dcdiv(struct blk *, struct blk *), *removr(struct blk *, int); 120*335Smuffin struct blk *exp(struct blk *, struct blk *); 121*335Smuffin struct blk *sqrt(struct blk *); 122*335Smuffin struct blk *salloc(int), *copy(struct blk *, int); 123*335Smuffin struct blk *scale(struct blk *, int); 124*335Smuffin void commnds(void); 1250Sstevel@tonic-gate void init(int, char **); 1260Sstevel@tonic-gate void pushp(struct blk *p); 1270Sstevel@tonic-gate void chsign(struct blk *p); 128*335Smuffin char readc(void); 1290Sstevel@tonic-gate void unreadc(char); 1300Sstevel@tonic-gate void binop(char); 1310Sstevel@tonic-gate void print(struct blk *hptr); 1320Sstevel@tonic-gate void tenot(struct blk *p, int sc); 1330Sstevel@tonic-gate void oneot(struct blk *p, int sc, char ch); 1340Sstevel@tonic-gate void seekc(struct blk *hptr, int n); 1350Sstevel@tonic-gate void ospace(char *s); 1360Sstevel@tonic-gate void garbage(char *s); 1370Sstevel@tonic-gate void more(struct blk *hptr); 1380Sstevel@tonic-gate int cond(char c); 139*335Smuffin void load(void); 1400Sstevel@tonic-gate void sdump(char *s1, struct blk *hptr); 1410Sstevel@tonic-gate void salterwd(struct wblk *hptr, struct blk *n); 1420Sstevel@tonic-gate void redef(struct blk *p); 1430Sstevel@tonic-gate void release(struct blk *p); 1440Sstevel@tonic-gate void putwd(struct blk *p, struct blk *c); 1450Sstevel@tonic-gate 1460Sstevel@tonic-gate int neg; 1470Sstevel@tonic-gate struct sym { 1480Sstevel@tonic-gate struct sym *next; 1490Sstevel@tonic-gate struct blk *val; 1500Sstevel@tonic-gate } symlst[TBLSZ]; 1510Sstevel@tonic-gate struct sym *stable[TBLSZ]; 1520Sstevel@tonic-gate struct sym *sptr, *sfree; 1530Sstevel@tonic-gate FILE *fsave; 1540Sstevel@tonic-gate long rel; 1550Sstevel@tonic-gate long nbytes; 1560Sstevel@tonic-gate long all; 1570Sstevel@tonic-gate long headmor; 1580Sstevel@tonic-gate long obase; 1590Sstevel@tonic-gate int fw, fw1, ll; 160*335Smuffin void (*outdit)(struct blk *, int); 161*335Smuffin void bigot(struct blk *, int), hexot(struct blk *, int); 1620Sstevel@tonic-gate int logo; 1630Sstevel@tonic-gate int log10; 1640Sstevel@tonic-gate int count; 1650Sstevel@tonic-gate char *pp; 166*335Smuffin void onintr(int); 167*335Smuffin char *nalloc(char *, unsigned int); 1680Sstevel@tonic-gate char *dummy; 169