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 307c478bd9Sstevel@tonic-gate #define FATAL 0 317c478bd9Sstevel@tonic-gate #define NFATAL 1 327c478bd9Sstevel@tonic-gate #define BLK sizeof (struct blk) 337c478bd9Sstevel@tonic-gate #define PTRSZ sizeof (int *) 347c478bd9Sstevel@tonic-gate #define HEADSZ 1024 357c478bd9Sstevel@tonic-gate #define STKSZ 100 367c478bd9Sstevel@tonic-gate #define RDSKSZ 100 377c478bd9Sstevel@tonic-gate #define TBLSZ 256 387c478bd9Sstevel@tonic-gate #define ARRAYST 0241 397c478bd9Sstevel@tonic-gate #define NL 1 407c478bd9Sstevel@tonic-gate #define NG 2 417c478bd9Sstevel@tonic-gate #define NE 3 427c478bd9Sstevel@tonic-gate #define length(p) ((p)->wt-(p)->beg) 437c478bd9Sstevel@tonic-gate #define rewind(p) ((p)->rd = (p)->beg) 447c478bd9Sstevel@tonic-gate #define create(p) ((p)->rd = (p)->wt = (p)->beg) 457c478bd9Sstevel@tonic-gate #define fsfile(p) ((p)->rd = (p)->wt) 467c478bd9Sstevel@tonic-gate #define truncate(p) ((p)->wt = (p)->rd) 477c478bd9Sstevel@tonic-gate #define sfeof(p) (((p)->rd >= (p)->wt) ? 1 : 0) 487c478bd9Sstevel@tonic-gate #define sfbeg(p) (((p)->rd == (p)->beg) ? 1 : 0) 497c478bd9Sstevel@tonic-gate #define sungetc(p, c) (*(--(p)->rd) = c) 507c478bd9Sstevel@tonic-gate #define sgetc(p) (((p)->rd == (p)->wt) ? EOF: ctoint((int)*(p)->rd++)) 517c478bd9Sstevel@tonic-gate #define slookc(p) (((p)->rd == (p)->wt) ? EOF: ctoint((int)*(p)->rd)) 527c478bd9Sstevel@tonic-gate #define sbackc(p) (((p)->rd == (p)->beg) ? EOF: ctoint((int)*(--(p)->rd))) 537c478bd9Sstevel@tonic-gate #define sputc(p, c) {if ((p)->wt == (p)->last) more(p); *(p)->wt++ = c; } 547c478bd9Sstevel@tonic-gate #define salterc(p, c) {if ((p)->rd == (p)->last) more(p); *(p)->rd++ = c;\ 557c478bd9Sstevel@tonic-gate if ((p)->rd > (p)->wt) (p)->wt = (p)->rd; } 567c478bd9Sstevel@tonic-gate #define sunputc(p) (*((p)->rd = --(p)->wt)) 577c478bd9Sstevel@tonic-gate #define zero(p) for (pp = (p)->beg; pp < (p)->last; ) *pp++ = '\0' 587c478bd9Sstevel@tonic-gate #define OUTC(x) {printf("%c", x); if (--count == 0)\ 597c478bd9Sstevel@tonic-gate {printf("\\\n"); count = ll; } } 607c478bd9Sstevel@tonic-gate #define TEST2 {if ((count -= 2) <= 0) {printf("\\\n"); count = ll; } } 617c478bd9Sstevel@tonic-gate #define PRINT_MESSAGE printf(gettext("stack empty\n")) 627c478bd9Sstevel@tonic-gate #define EMPTY if (stkerr != 0) {PRINT_MESSAGE; continue; } 637c478bd9Sstevel@tonic-gate #define EMPTYR(x) if (stkerr != 0) {pushp(x); PRINT_MESSAGE; continue; } 647c478bd9Sstevel@tonic-gate #define EMPTYS if (stkerr != 0) {PRINT_MESSAGE; return (1); } 657c478bd9Sstevel@tonic-gate #define EMPTYSR(x) if (stkerr != 0) {PRINT_MESSAGE; pushp(x); return (1); } 667c478bd9Sstevel@tonic-gate #define CHECKEND { \ 677c478bd9Sstevel@tonic-gate if (count == 2) { \ 687c478bd9Sstevel@tonic-gate printf("\\\n"); \ 697c478bd9Sstevel@tonic-gate count = ll; \ 707c478bd9Sstevel@tonic-gate } \ 717c478bd9Sstevel@tonic-gate } 727c478bd9Sstevel@tonic-gate #define error(p) {printf(p); continue; } 737c478bd9Sstevel@tonic-gate #define errorrt(p) {printf(p); return (1); } 747c478bd9Sstevel@tonic-gate struct blk { 757c478bd9Sstevel@tonic-gate char *rd; 767c478bd9Sstevel@tonic-gate char *wt; 777c478bd9Sstevel@tonic-gate char *beg; 787c478bd9Sstevel@tonic-gate char *last; 797c478bd9Sstevel@tonic-gate }; 807c478bd9Sstevel@tonic-gate struct wblk { 817c478bd9Sstevel@tonic-gate struct blk **rdw; 827c478bd9Sstevel@tonic-gate struct blk **wtw; 837c478bd9Sstevel@tonic-gate struct blk **begw; 847c478bd9Sstevel@tonic-gate struct blk **lastw; 857c478bd9Sstevel@tonic-gate }; 867c478bd9Sstevel@tonic-gate struct blk *hfree; 87*b390fe2cSmuffin struct blk *getwd(struct blk *); 88*b390fe2cSmuffin struct blk *lookwd(struct blk *); 89*b390fe2cSmuffin struct blk *getdec(struct blk *, int); 90*b390fe2cSmuffin struct blk *morehd(void); 917c478bd9Sstevel@tonic-gate 927c478bd9Sstevel@tonic-gate struct blk *arg1, *arg2; 937c478bd9Sstevel@tonic-gate int svargc; 947c478bd9Sstevel@tonic-gate char savk; 957c478bd9Sstevel@tonic-gate char **svargv; 967c478bd9Sstevel@tonic-gate int dbg; 977c478bd9Sstevel@tonic-gate int ifile; 987c478bd9Sstevel@tonic-gate FILE *curfile; 997c478bd9Sstevel@tonic-gate struct blk *scalptr, *basptr, *tenptr, *inbas; 1007c478bd9Sstevel@tonic-gate struct blk *sqtemp, *chptr, *strptr, *divxyz; 1017c478bd9Sstevel@tonic-gate struct blk *stack[STKSZ]; 1027c478bd9Sstevel@tonic-gate struct blk **stkptr, **stkbeg; 1037c478bd9Sstevel@tonic-gate struct blk **stkend; 1047c478bd9Sstevel@tonic-gate int stkerr; 1057c478bd9Sstevel@tonic-gate int lastchar; 1067c478bd9Sstevel@tonic-gate struct blk *readstk[RDSKSZ]; 1077c478bd9Sstevel@tonic-gate struct blk **readptr; 1087c478bd9Sstevel@tonic-gate struct blk *rem; 1097c478bd9Sstevel@tonic-gate int k; 1107c478bd9Sstevel@tonic-gate struct blk *irem; 1117c478bd9Sstevel@tonic-gate int skd, skr; 112*b390fe2cSmuffin struct blk *pop(void), *readin(void), *add0(struct blk *, int), 113*b390fe2cSmuffin *mult(struct blk *, struct blk *); 114*b390fe2cSmuffin struct blk *scalint(struct blk *); 115*b390fe2cSmuffin struct blk *removc(struct blk *, int); 116*b390fe2cSmuffin struct blk *add(struct blk *, struct blk *), 117*b390fe2cSmuffin *dcdiv(struct blk *, struct blk *), *removr(struct blk *, int); 118*b390fe2cSmuffin struct blk *exp(struct blk *, struct blk *); 119*b390fe2cSmuffin struct blk *sqrt(struct blk *); 120*b390fe2cSmuffin struct blk *salloc(int), *copy(struct blk *, int); 121*b390fe2cSmuffin struct blk *scale(struct blk *, int); 122*b390fe2cSmuffin void commnds(void); 1237c478bd9Sstevel@tonic-gate void init(int, char **); 1247c478bd9Sstevel@tonic-gate void pushp(struct blk *p); 1257c478bd9Sstevel@tonic-gate void chsign(struct blk *p); 126*b390fe2cSmuffin char readc(void); 1277c478bd9Sstevel@tonic-gate void unreadc(char); 1287c478bd9Sstevel@tonic-gate void binop(char); 1297c478bd9Sstevel@tonic-gate void print(struct blk *hptr); 1307c478bd9Sstevel@tonic-gate void tenot(struct blk *p, int sc); 1317c478bd9Sstevel@tonic-gate void oneot(struct blk *p, int sc, char ch); 1327c478bd9Sstevel@tonic-gate void seekc(struct blk *hptr, int n); 1337c478bd9Sstevel@tonic-gate void ospace(char *s); 1347c478bd9Sstevel@tonic-gate void garbage(char *s); 1357c478bd9Sstevel@tonic-gate void more(struct blk *hptr); 1367c478bd9Sstevel@tonic-gate int cond(char c); 137*b390fe2cSmuffin void load(void); 1387c478bd9Sstevel@tonic-gate void sdump(char *s1, struct blk *hptr); 1397c478bd9Sstevel@tonic-gate void salterwd(struct wblk *hptr, struct blk *n); 1407c478bd9Sstevel@tonic-gate void redef(struct blk *p); 1417c478bd9Sstevel@tonic-gate void release(struct blk *p); 1427c478bd9Sstevel@tonic-gate void putwd(struct blk *p, struct blk *c); 1437c478bd9Sstevel@tonic-gate 1447c478bd9Sstevel@tonic-gate int neg; 1457c478bd9Sstevel@tonic-gate struct sym { 1467c478bd9Sstevel@tonic-gate struct sym *next; 1477c478bd9Sstevel@tonic-gate struct blk *val; 1487c478bd9Sstevel@tonic-gate } symlst[TBLSZ]; 1497c478bd9Sstevel@tonic-gate struct sym *stable[TBLSZ]; 1507c478bd9Sstevel@tonic-gate struct sym *sptr, *sfree; 1517c478bd9Sstevel@tonic-gate FILE *fsave; 1527c478bd9Sstevel@tonic-gate long rel; 1537c478bd9Sstevel@tonic-gate long nbytes; 1547c478bd9Sstevel@tonic-gate long all; 1557c478bd9Sstevel@tonic-gate long headmor; 1567c478bd9Sstevel@tonic-gate long obase; 1577c478bd9Sstevel@tonic-gate int fw, fw1, ll; 158*b390fe2cSmuffin void (*outdit)(struct blk *, int); 159*b390fe2cSmuffin void bigot(struct blk *, int), hexot(struct blk *, int); 1607c478bd9Sstevel@tonic-gate int logo; 1617c478bd9Sstevel@tonic-gate int log10; 1627c478bd9Sstevel@tonic-gate int count; 1637c478bd9Sstevel@tonic-gate char *pp; 164*b390fe2cSmuffin void onintr(int); 165*b390fe2cSmuffin char *nalloc(char *, unsigned int); 1667c478bd9Sstevel@tonic-gate char *dummy; 167