17c478bd9Sstevel@tonic-gate /* 27c478bd9Sstevel@tonic-gate * CDDL HEADER START 37c478bd9Sstevel@tonic-gate * 47c478bd9Sstevel@tonic-gate * The contents of this file are subject to the terms of the 57c478bd9Sstevel@tonic-gate * Common Development and Distribution License, Version 1.0 only 67c478bd9Sstevel@tonic-gate * (the "License"). You may not use this file except in compliance 77c478bd9Sstevel@tonic-gate * with the License. 87c478bd9Sstevel@tonic-gate * 97c478bd9Sstevel@tonic-gate * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE 107c478bd9Sstevel@tonic-gate * or http://www.opensolaris.org/os/licensing. 117c478bd9Sstevel@tonic-gate * See the License for the specific language governing permissions 127c478bd9Sstevel@tonic-gate * and limitations under the License. 137c478bd9Sstevel@tonic-gate * 147c478bd9Sstevel@tonic-gate * When distributing Covered Code, include this CDDL HEADER in each 157c478bd9Sstevel@tonic-gate * file and include the License file at usr/src/OPENSOLARIS.LICENSE. 167c478bd9Sstevel@tonic-gate * If applicable, add the following below this CDDL HEADER, with the 177c478bd9Sstevel@tonic-gate * fields enclosed by brackets "[]" replaced with your own identifying 187c478bd9Sstevel@tonic-gate * information: Portions Copyright [yyyy] [name of copyright owner] 197c478bd9Sstevel@tonic-gate * 207c478bd9Sstevel@tonic-gate * CDDL HEADER END 217c478bd9Sstevel@tonic-gate */ 22*b390fe2cSmuffin /* 23*b390fe2cSmuffin * Copyright 2005 Sun Microsystems, Inc. All rights reserved. 24*b390fe2cSmuffin * Use is subject to license terms. 25*b390fe2cSmuffin */ 26*b390fe2cSmuffin 277c478bd9Sstevel@tonic-gate /* Copyright (c) 1984, 1986, 1987, 1988, 1989 AT&T */ 287c478bd9Sstevel@tonic-gate /* All Rights Reserved */ 297c478bd9Sstevel@tonic-gate 30*b390fe2cSmuffin #pragma ident "%Z%%M% %I% %E% SMI" 317c478bd9Sstevel@tonic-gate 327c478bd9Sstevel@tonic-gate #define FATAL 0 337c478bd9Sstevel@tonic-gate #define NFATAL 1 347c478bd9Sstevel@tonic-gate #define BLK sizeof (struct blk) 357c478bd9Sstevel@tonic-gate #define PTRSZ sizeof (int *) 367c478bd9Sstevel@tonic-gate #define HEADSZ 1024 377c478bd9Sstevel@tonic-gate #define STKSZ 100 387c478bd9Sstevel@tonic-gate #define RDSKSZ 100 397c478bd9Sstevel@tonic-gate #define TBLSZ 256 407c478bd9Sstevel@tonic-gate #define ARRAYST 0241 417c478bd9Sstevel@tonic-gate #define NL 1 427c478bd9Sstevel@tonic-gate #define NG 2 437c478bd9Sstevel@tonic-gate #define NE 3 447c478bd9Sstevel@tonic-gate #define length(p) ((p)->wt-(p)->beg) 457c478bd9Sstevel@tonic-gate #define rewind(p) ((p)->rd = (p)->beg) 467c478bd9Sstevel@tonic-gate #define create(p) ((p)->rd = (p)->wt = (p)->beg) 477c478bd9Sstevel@tonic-gate #define fsfile(p) ((p)->rd = (p)->wt) 487c478bd9Sstevel@tonic-gate #define truncate(p) ((p)->wt = (p)->rd) 497c478bd9Sstevel@tonic-gate #define sfeof(p) (((p)->rd >= (p)->wt) ? 1 : 0) 507c478bd9Sstevel@tonic-gate #define sfbeg(p) (((p)->rd == (p)->beg) ? 1 : 0) 517c478bd9Sstevel@tonic-gate #define sungetc(p, c) (*(--(p)->rd) = c) 527c478bd9Sstevel@tonic-gate #define sgetc(p) (((p)->rd == (p)->wt) ? EOF: ctoint((int)*(p)->rd++)) 537c478bd9Sstevel@tonic-gate #define slookc(p) (((p)->rd == (p)->wt) ? EOF: ctoint((int)*(p)->rd)) 547c478bd9Sstevel@tonic-gate #define sbackc(p) (((p)->rd == (p)->beg) ? EOF: ctoint((int)*(--(p)->rd))) 557c478bd9Sstevel@tonic-gate #define sputc(p, c) {if ((p)->wt == (p)->last) more(p); *(p)->wt++ = c; } 567c478bd9Sstevel@tonic-gate #define salterc(p, c) {if ((p)->rd == (p)->last) more(p); *(p)->rd++ = c;\ 577c478bd9Sstevel@tonic-gate if ((p)->rd > (p)->wt) (p)->wt = (p)->rd; } 587c478bd9Sstevel@tonic-gate #define sunputc(p) (*((p)->rd = --(p)->wt)) 597c478bd9Sstevel@tonic-gate #define zero(p) for (pp = (p)->beg; pp < (p)->last; ) *pp++ = '\0' 607c478bd9Sstevel@tonic-gate #define OUTC(x) {printf("%c", x); if (--count == 0)\ 617c478bd9Sstevel@tonic-gate {printf("\\\n"); count = ll; } } 627c478bd9Sstevel@tonic-gate #define TEST2 {if ((count -= 2) <= 0) {printf("\\\n"); count = ll; } } 637c478bd9Sstevel@tonic-gate #define PRINT_MESSAGE printf(gettext("stack empty\n")) 647c478bd9Sstevel@tonic-gate #define EMPTY if (stkerr != 0) {PRINT_MESSAGE; continue; } 657c478bd9Sstevel@tonic-gate #define EMPTYR(x) if (stkerr != 0) {pushp(x); PRINT_MESSAGE; continue; } 667c478bd9Sstevel@tonic-gate #define EMPTYS if (stkerr != 0) {PRINT_MESSAGE; return (1); } 677c478bd9Sstevel@tonic-gate #define EMPTYSR(x) if (stkerr != 0) {PRINT_MESSAGE; pushp(x); return (1); } 687c478bd9Sstevel@tonic-gate #define CHECKEND { \ 697c478bd9Sstevel@tonic-gate if (count == 2) { \ 707c478bd9Sstevel@tonic-gate printf("\\\n"); \ 717c478bd9Sstevel@tonic-gate count = ll; \ 727c478bd9Sstevel@tonic-gate } \ 737c478bd9Sstevel@tonic-gate } 747c478bd9Sstevel@tonic-gate #define error(p) {printf(p); continue; } 757c478bd9Sstevel@tonic-gate #define errorrt(p) {printf(p); return (1); } 767c478bd9Sstevel@tonic-gate struct blk { 777c478bd9Sstevel@tonic-gate char *rd; 787c478bd9Sstevel@tonic-gate char *wt; 797c478bd9Sstevel@tonic-gate char *beg; 807c478bd9Sstevel@tonic-gate char *last; 817c478bd9Sstevel@tonic-gate }; 827c478bd9Sstevel@tonic-gate struct wblk { 837c478bd9Sstevel@tonic-gate struct blk **rdw; 847c478bd9Sstevel@tonic-gate struct blk **wtw; 857c478bd9Sstevel@tonic-gate struct blk **begw; 867c478bd9Sstevel@tonic-gate struct blk **lastw; 877c478bd9Sstevel@tonic-gate }; 887c478bd9Sstevel@tonic-gate struct blk *hfree; 89*b390fe2cSmuffin struct blk *getwd(struct blk *); 90*b390fe2cSmuffin struct blk *lookwd(struct blk *); 91*b390fe2cSmuffin struct blk *getdec(struct blk *, int); 92*b390fe2cSmuffin struct blk *morehd(void); 937c478bd9Sstevel@tonic-gate 947c478bd9Sstevel@tonic-gate struct blk *arg1, *arg2; 957c478bd9Sstevel@tonic-gate int svargc; 967c478bd9Sstevel@tonic-gate char savk; 977c478bd9Sstevel@tonic-gate char **svargv; 987c478bd9Sstevel@tonic-gate int dbg; 997c478bd9Sstevel@tonic-gate int ifile; 1007c478bd9Sstevel@tonic-gate FILE *curfile; 1017c478bd9Sstevel@tonic-gate struct blk *scalptr, *basptr, *tenptr, *inbas; 1027c478bd9Sstevel@tonic-gate struct blk *sqtemp, *chptr, *strptr, *divxyz; 1037c478bd9Sstevel@tonic-gate struct blk *stack[STKSZ]; 1047c478bd9Sstevel@tonic-gate struct blk **stkptr, **stkbeg; 1057c478bd9Sstevel@tonic-gate struct blk **stkend; 1067c478bd9Sstevel@tonic-gate int stkerr; 1077c478bd9Sstevel@tonic-gate int lastchar; 1087c478bd9Sstevel@tonic-gate struct blk *readstk[RDSKSZ]; 1097c478bd9Sstevel@tonic-gate struct blk **readptr; 1107c478bd9Sstevel@tonic-gate struct blk *rem; 1117c478bd9Sstevel@tonic-gate int k; 1127c478bd9Sstevel@tonic-gate struct blk *irem; 1137c478bd9Sstevel@tonic-gate int skd, skr; 114*b390fe2cSmuffin struct blk *pop(void), *readin(void), *add0(struct blk *, int), 115*b390fe2cSmuffin *mult(struct blk *, struct blk *); 116*b390fe2cSmuffin struct blk *scalint(struct blk *); 117*b390fe2cSmuffin struct blk *removc(struct blk *, int); 118*b390fe2cSmuffin struct blk *add(struct blk *, struct blk *), 119*b390fe2cSmuffin *dcdiv(struct blk *, struct blk *), *removr(struct blk *, int); 120*b390fe2cSmuffin struct blk *exp(struct blk *, struct blk *); 121*b390fe2cSmuffin struct blk *sqrt(struct blk *); 122*b390fe2cSmuffin struct blk *salloc(int), *copy(struct blk *, int); 123*b390fe2cSmuffin struct blk *scale(struct blk *, int); 124*b390fe2cSmuffin void commnds(void); 1257c478bd9Sstevel@tonic-gate void init(int, char **); 1267c478bd9Sstevel@tonic-gate void pushp(struct blk *p); 1277c478bd9Sstevel@tonic-gate void chsign(struct blk *p); 128*b390fe2cSmuffin char readc(void); 1297c478bd9Sstevel@tonic-gate void unreadc(char); 1307c478bd9Sstevel@tonic-gate void binop(char); 1317c478bd9Sstevel@tonic-gate void print(struct blk *hptr); 1327c478bd9Sstevel@tonic-gate void tenot(struct blk *p, int sc); 1337c478bd9Sstevel@tonic-gate void oneot(struct blk *p, int sc, char ch); 1347c478bd9Sstevel@tonic-gate void seekc(struct blk *hptr, int n); 1357c478bd9Sstevel@tonic-gate void ospace(char *s); 1367c478bd9Sstevel@tonic-gate void garbage(char *s); 1377c478bd9Sstevel@tonic-gate void more(struct blk *hptr); 1387c478bd9Sstevel@tonic-gate int cond(char c); 139*b390fe2cSmuffin void load(void); 1407c478bd9Sstevel@tonic-gate void sdump(char *s1, struct blk *hptr); 1417c478bd9Sstevel@tonic-gate void salterwd(struct wblk *hptr, struct blk *n); 1427c478bd9Sstevel@tonic-gate void redef(struct blk *p); 1437c478bd9Sstevel@tonic-gate void release(struct blk *p); 1447c478bd9Sstevel@tonic-gate void putwd(struct blk *p, struct blk *c); 1457c478bd9Sstevel@tonic-gate 1467c478bd9Sstevel@tonic-gate int neg; 1477c478bd9Sstevel@tonic-gate struct sym { 1487c478bd9Sstevel@tonic-gate struct sym *next; 1497c478bd9Sstevel@tonic-gate struct blk *val; 1507c478bd9Sstevel@tonic-gate } symlst[TBLSZ]; 1517c478bd9Sstevel@tonic-gate struct sym *stable[TBLSZ]; 1527c478bd9Sstevel@tonic-gate struct sym *sptr, *sfree; 1537c478bd9Sstevel@tonic-gate FILE *fsave; 1547c478bd9Sstevel@tonic-gate long rel; 1557c478bd9Sstevel@tonic-gate long nbytes; 1567c478bd9Sstevel@tonic-gate long all; 1577c478bd9Sstevel@tonic-gate long headmor; 1587c478bd9Sstevel@tonic-gate long obase; 1597c478bd9Sstevel@tonic-gate int fw, fw1, ll; 160*b390fe2cSmuffin void (*outdit)(struct blk *, int); 161*b390fe2cSmuffin void bigot(struct blk *, int), hexot(struct blk *, int); 1627c478bd9Sstevel@tonic-gate int logo; 1637c478bd9Sstevel@tonic-gate int log10; 1647c478bd9Sstevel@tonic-gate int count; 1657c478bd9Sstevel@tonic-gate char *pp; 166*b390fe2cSmuffin void onintr(int); 167*b390fe2cSmuffin char *nalloc(char *, unsigned int); 1687c478bd9Sstevel@tonic-gate char *dummy; 169