xref: /illumos-gate/usr/src/cmd/dc/dc.h (revision 2a8bcb4efb45d99ac41c94a75c396b362c414f7f)
1 /*
2  * CDDL HEADER START
3  *
4  * The contents of this file are subject to the terms of the
5  * Common Development and Distribution License, Version 1.0 only
6  * (the "License").  You may not use this file except in compliance
7  * with the License.
8  *
9  * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
10  * or http://www.opensolaris.org/os/licensing.
11  * See the License for the specific language governing permissions
12  * and limitations under the License.
13  *
14  * When distributing Covered Code, include this CDDL HEADER in each
15  * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
16  * If applicable, add the following below this CDDL HEADER, with the
17  * fields enclosed by brackets "[]" replaced with your own identifying
18  * information: Portions Copyright [yyyy] [name of copyright owner]
19  *
20  * CDDL HEADER END
21  */
22 /*
23  * Copyright 2005 Sun Microsystems, Inc.  All rights reserved.
24  * Use is subject to license terms.
25  */
26 
27 /*	Copyright (c) 1984, 1986, 1987, 1988, 1989 AT&T	*/
28 /*	  All Rights Reserved  	*/
29 
30 #define	FATAL 0
31 #define	NFATAL 1
32 #define	BLK sizeof (struct blk)
33 #define	PTRSZ sizeof (int *)
34 #define	HEADSZ 1024
35 #define	STKSZ 100
36 #define	RDSKSZ 100
37 #define	TBLSZ 256
38 #define	ARRAYST 0241
39 #define	NL 1
40 #define	NG 2
41 #define	NE 3
42 #define	length(p) ((p)->wt-(p)->beg)
43 #define	rewind(p) ((p)->rd = (p)->beg)
44 #define	create(p)	((p)->rd = (p)->wt = (p)->beg)
45 #define	fsfile(p)	((p)->rd = (p)->wt)
46 #define	truncate(p)	((p)->wt = (p)->rd)
47 #define	sfeof(p)	(((p)->rd >= (p)->wt) ? 1 : 0)
48 #define	sfbeg(p)	(((p)->rd == (p)->beg) ? 1 : 0)
49 #define	sungetc(p, c)	(*(--(p)->rd) = c)
50 #define	sgetc(p)	(((p)->rd == (p)->wt) ? EOF: ctoint((int)*(p)->rd++))
51 #define	slookc(p)	(((p)->rd == (p)->wt) ? EOF: ctoint((int)*(p)->rd))
52 #define	sbackc(p)	(((p)->rd == (p)->beg) ? EOF: ctoint((int)*(--(p)->rd)))
53 #define	sputc(p, c)	{if ((p)->wt == (p)->last) more(p); *(p)->wt++ = c; }
54 #define	salterc(p, c)	{if ((p)->rd == (p)->last) more(p); *(p)->rd++ = c;\
55 			    if ((p)->rd > (p)->wt) (p)->wt = (p)->rd; }
56 #define	sunputc(p)	(*((p)->rd = --(p)->wt))
57 #define	zero(p)		for (pp = (p)->beg; pp < (p)->last; ) *pp++ = '\0'
58 #define	OUTC(x) {printf("%c", x); if (--count == 0)\
59 			    {printf("\\\n"); count = ll; } }
60 #define	TEST2	{if ((count -= 2) <= 0) {printf("\\\n"); count = ll; } }
61 #define	PRINT_MESSAGE	printf(gettext("stack empty\n"))
62 #define	EMPTY		if (stkerr != 0) {PRINT_MESSAGE; continue; }
63 #define	EMPTYR(x)	if (stkerr != 0) {pushp(x); PRINT_MESSAGE; continue; }
64 #define	EMPTYS		if (stkerr != 0) {PRINT_MESSAGE; return (1); }
65 #define	EMPTYSR(x)	if (stkerr != 0) {PRINT_MESSAGE; pushp(x); return (1); }
66 #define	CHECKEND	{ \
67 				if (count == 2) { \
68 					printf("\\\n"); \
69 					count = ll; \
70 				} \
71 			}
72 #define	error(p)	{printf(p); continue; }
73 #define	errorrt(p)	{printf(p); return (1); }
74 struct blk {
75 	char	*rd;
76 	char	*wt;
77 	char	*beg;
78 	char	*last;
79 };
80 struct	wblk {
81 	struct blk **rdw;
82 	struct blk **wtw;
83 	struct blk **begw;
84 	struct blk **lastw;
85 };
86 struct	blk *hfree;
87 struct	blk *getwd(struct blk *);
88 struct	blk *lookwd(struct blk *);
89 struct	blk *getdec(struct blk *, int);
90 struct	blk *morehd(void);
91 
92 struct	blk *arg1, *arg2;
93 int	svargc;
94 char	savk;
95 char	**svargv;
96 int	dbg;
97 int	ifile;
98 FILE	*curfile;
99 struct	blk *scalptr, *basptr, *tenptr, *inbas;
100 struct	blk *sqtemp, *chptr, *strptr, *divxyz;
101 struct	blk *stack[STKSZ];
102 struct	blk **stkptr, **stkbeg;
103 struct	blk **stkend;
104 int	stkerr;
105 int	lastchar;
106 struct	blk *readstk[RDSKSZ];
107 struct	blk **readptr;
108 struct	blk *rem;
109 int	k;
110 struct	blk *irem;
111 int	skd, skr;
112 struct	blk *pop(void), *readin(void), *add0(struct blk *, int),
113     *mult(struct blk *, struct blk *);
114 struct	blk *scalint(struct blk *);
115 struct	blk *removc(struct blk *, int);
116 struct	blk *add(struct blk *, struct blk *),
117     *dcdiv(struct blk *, struct blk *), *removr(struct blk *, int);
118 struct	blk *exp(struct blk *, struct blk *);
119 struct	blk *sqrt(struct blk *);
120 struct	blk *salloc(int), *copy(struct blk *, int);
121 struct	blk *scale(struct blk *, int);
122 void	commnds(void);
123 void	init(int, char **);
124 void	pushp(struct blk *p);
125 void	chsign(struct blk *p);
126 char	readc(void);
127 void	unreadc(char);
128 void	binop(char);
129 void	print(struct blk *hptr);
130 void	tenot(struct blk *p, int sc);
131 void	oneot(struct blk *p, int sc, char ch);
132 void	seekc(struct blk *hptr, int n);
133 void	ospace(char *s);
134 void	garbage(char *s);
135 void	more(struct blk *hptr);
136 int	cond(char c);
137 void	load(void);
138 void	sdump(char *s1, struct blk *hptr);
139 void	salterwd(struct wblk *hptr, struct blk *n);
140 void	redef(struct blk *p);
141 void	release(struct blk *p);
142 void	putwd(struct blk *p, struct blk *c);
143 
144 int	neg;
145 struct	sym {
146 	struct	sym *next;
147 	struct	blk *val;
148 } symlst[TBLSZ];
149 struct	sym *stable[TBLSZ];
150 struct	sym *sptr, *sfree;
151 FILE	*fsave;
152 long	rel;
153 long	nbytes;
154 long	all;
155 long	headmor;
156 long	obase;
157 int	fw, fw1, ll;
158 void	(*outdit)(struct blk *, int);
159 void	bigot(struct blk *, int), hexot(struct blk *, int);
160 int	logo;
161 int	log10;
162 int	count;
163 char	*pp;
164 void	onintr(int);
165 char	*nalloc(char *, unsigned int);
166 char	*dummy;
167