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
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.
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]
23 * Copyright (c) 1999 by Sun Microsystems, Inc.
24 * All rights reserved.
27 #pragma ident "%Z%%M% %I% %E% SMI"
32 #include <fcode/private.h>
34 #define DIGIT(x) (((x) > 9) ? ((x) + 'a' - 10) : ((x) + '0'))
37 to_digit(fcode_env_t
*env
)
39 CHECK_DEPTH(env
, 1, ">digit");
44 pic_hold(fcode_env_t
*env
)
46 CHECK_DEPTH(env
, 1, "hold");
47 *(--env
->picturebufpos
) = (char) POP(DS
);
51 pic_start(fcode_env_t
*env
)
53 env
->picturebufpos
= env
->picturebuf
+ env
->picturebuflen
- 1;
54 *env
->picturebufpos
= 0;
58 pic_ustop(fcode_env_t
*env
)
60 CHECK_DEPTH(env
, 1, "u#>");
62 push_string(env
, env
->picturebufpos
, strlen(env
->picturebufpos
));
66 pic_unsigned(fcode_env_t
*env
)
70 CHECK_DEPTH(env
, 1, "u#");
72 b
= a
% env
->num_base
;
73 TOS
= (fstack_t
) (a
/ env
->num_base
);
74 *(--env
->picturebufpos
) = DIGIT(b
);
78 pic_sign(fcode_env_t
*env
)
82 CHECK_DEPTH(env
, 1, "sign");
91 pic_uremainder(fcode_env_t
*env
)
93 CHECK_DEPTH(env
, 1, "u#s");
100 format_number(fcode_env_t
*env
, int neg
, int width
)
108 if (env
->num_base
== 10 && neg
) {
112 width
-= strlen(env
->picturebufpos
);
122 convert_num(fcode_env_t
*env
)
126 CHECK_DEPTH(env
, 1, "(.)");
128 if (env
->num_base
== 10 && TOS
< 0) {
132 format_number(env
, n
, 0);
136 do_dot_r(fcode_env_t
*env
)
140 CHECK_DEPTH(env
, 2, ".r");
143 if (env
->num_base
== 10 && TOS
< 0) {
147 format_number(env
, n
, w
);
152 do_udot_r(fcode_env_t
*env
)
156 CHECK_DEPTH(env
, 2, "u.r");
158 format_number(env
, 0, w
);
163 do_dot(fcode_env_t
*env
)
165 CHECK_DEPTH(env
, 1, ".");
171 do_dot_d(fcode_env_t
*env
)
175 CHECK_DEPTH(env
, 1, ".d");
176 base
= env
->num_base
;
179 env
->num_base
= base
;
183 do_dot_x(fcode_env_t
*env
)
187 CHECK_DEPTH(env
, 1, ".x");
188 base
= env
->num_base
;
191 env
->num_base
= base
;
195 do_udot(fcode_env_t
*env
)
197 CHECK_DEPTH(env
, 1, "u.");
203 pic_dunsigned(fcode_env_t
*env
)
208 CHECK_DEPTH(env
, 2, "#");
210 b
= a
% env
->num_base
;
213 *(--env
->picturebufpos
) = DIGIT(b
);
217 pic_dremainder(fcode_env_t
*env
)
219 CHECK_DEPTH(env
, 2, "#s");
222 } while (peek_double(env
));
226 pic_dstop(fcode_env_t
*env
)
228 CHECK_DEPTH(env
, 2, "#>");
229 (void) pop_double(env
);
230 push_string(env
, env
->picturebufpos
, strlen(env
->picturebufpos
));
239 fcode_env_t
*env
= initial_env
;
243 env
->picturebuflen
= 0x100;
244 env
->picturebuf
= MALLOC(env
->picturebuflen
);
246 ANSI(0x095, 0, "hold", pic_hold
);
247 ANSI(0x096, 0, "<#", pic_start
);
248 ANSI(0x097, 0, "u#>", pic_ustop
);
249 ANSI(0x098, 0, "sign", pic_sign
);
250 ANSI(0x099, 0, "u#", pic_unsigned
);
251 ANSI(0x09a, 0, "u#s", pic_uremainder
);
252 ANSI(0x09b, 0, "u.", do_udot
);
253 P1275(0x09c, 0, "u.r", do_udot_r
);
254 P1275(0x09d, 0, ".", do_dot
);
255 ANSI(0x09e, 0, ".r", do_dot_r
);
257 ANSI(0x0c7, 0, "#", pic_dunsigned
);
258 ANSI(0x0c8, 0, "#s", pic_dremainder
);
259 ANSI(0x0c9, 0, "#>", pic_dstop
);
261 FORTH(0, ">digit", to_digit
);
262 FORTH(0, "(.)", convert_num
);
263 FORTH(0, ".d", do_dot_d
);
264 FORTH(0, ".x", do_dot_x
);