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 2003 Sun Microsystems, Inc. All rights reserved.
24 * Use is subject to license terms.
27 /* Copyright (c) 1984, 1986, 1987, 1988, 1989 AT&T */
28 /* All Rights Reserved */
30 #pragma ident "%Z%%M% %I% %E% SMI"
36 #include <sys/types.h>
43 long longest
= 0, maxsize
= 0, active
= 0;
44 int lall
= 0, lrel
= 0, lcopy
= 0, lmore
= 0, lbytes
= 0;
47 * Routine to handle sign extension of characters on systems that do not
48 * do automatic sign extension. This should be portable to all 2's and 1's
49 * complement systems that do or do not provide automatic sign
50 * extension. If the system provides automatic sign extension or the
51 * value of 'c' is positive, ctoint() will always return quickly,
52 * otherwise ctoint() will search for the negative value by attempting
53 * to wrap 'c' to 0. The number of increments needed to get to 0 is the
56 * Note: This assummes that the representation of values stored in chars
57 * is sequential and allowed to wrap, and that values < 128 are
58 * positive. While this is true on 1's and 2's complement machines, it
59 * may vary on less common architectures.
67 ctoint(unsigned char c
)
72 if ((unsigned char)c
<= SCHAR_MAX
)
73 return ((int)c
); /* Normal promotion will work */
74 for (i
= 0; c
++; i
--); /* Scan for negative value */
78 #if !defined(TEXT_DOMAIN) /* Should be defined by cc -D */
79 #define TEXT_DOMAIN "SYS_TEST" /* Use this only if it weren't. */
82 void commnds(void) __NORETURN
;
85 main(int argc
, char **argv
)
87 (void) setlocale(LC_ALL
, "");
88 (void) textdomain(TEXT_DOMAIN
);
102 struct blk
**ptr
, *s
, *t
;
106 int scalev
; /* scaling value for converting blks to integers */
109 if (((c
= readc()) >= '0' && c
<= '9') ||
110 (c
>= 'A' && c
<= 'F') || c
== '.') {
123 sdump("stk", *stkptr
);
125 ("all %ld rel %ld headmor %ld\n"), all
, rel
,
127 printf(gettext("nbytes %ld\n"), nbytes
);
129 ("longest %ld active %ld maxsize %ld\n"), longest
,
132 ("new all %d rel %d copy %d more %d lbytes %d\n"),
133 lall
, lrel
, lcopy
, lmore
, lbytes
);
134 lall
= lrel
= lcopy
= lmore
= lbytes
= 0;
161 savk
= n
= sk1
+ sk2
;
162 if (n
> k
&& n
> sk1
&& n
> sk2
) {
168 p
= removc(p
, n
- sk
);
194 p
= add0(rem
, skd
- (skr
+ k
));
205 if (length(p
) == 0) {
210 if ((c
= sbackc(p
)) < 0) {
211 error(gettext("sqrt of neg number\n"));
228 if (sunputc(arg1
) != 0)
229 error(gettext("exp not an integer\n"));
232 if (sfbeg(arg1
) == 0 && sbackc(arg1
) < 0) {
236 if (length(arg1
) >= 3)
237 error(gettext("exp too big\n"));
238 savk
= sunputc(arg2
);
245 else if (sfeof(arg1
) == 0)
246 c
= sgetc(arg1
) * 100 + c
;
254 q
= removc(p
, d
- n
);
284 n
= (length(p
) - 1) << 1;
288 if ((c
= sbackc(p
)) < 0) {
293 if ((c
= sbackc(p
)) == 0)
319 * input base must be between 2 and 16
326 error(gettext("input base is too large\n"));
328 error(gettext("input base is too small\n"));
330 error(gettext("input base is too large\n"));
337 p
= copy(inbas
, length(inbas
) + 1);
359 while (sfbeg(q
) == 0)
360 l
= l
* 100 + sbackc(q
);
366 * Check that output base is less than or equal
370 error(gettext("output base is too large\n"));
379 if (n
== 1 && sign
== 0) {
387 * Line length is 70 characters,
403 if ((c
= sbackc(t
)) > 9)
413 * Line length is 70 characters including newline
421 p
= copy(basptr
, length(basptr
) + 1);
429 if ((c
= readc()) == ']') {
447 * Make sure scaling factor is between 0 and
448 * BC_SCALE_MAX. Copy p to q and figure the
455 if ((sfbeg(q
) == 0) && ((c
= sbackc(q
)) < 0))
456 error(gettext("invalid scale factor\n"));
459 while (c
< BC_SCALE_MAX
&& sfbeg(q
) == 0)
460 c
= (c
* (scalev
*= 100)) + sbackc(q
);
462 if (c
> BC_SCALE_MAX
)
463 error(gettext("scale factor is too large\n"));
467 k
= sfeof(p
) ? 0 : sgetc(p
);
473 p
= copy(scalptr
, length(scalptr
) + 1);
495 if ((c
= sgetc(p
)) < 0) {
496 error(gettext("neg Q\n"));
500 if (readptr
== &readstk
[0]) {
509 if (readptr
<= &readstk
[1])
519 if (stkptr
== &stack
[0])
520 printf(gettext("empty stack\n"));
522 for (ptr
= stkptr
; ptr
> &stack
[0]; ) {
528 if (stkptr
== &stack
[0])
529 printf(gettext("empty stack\n"));
538 printf("%s", p
->beg
);
542 if (stkptr
== &stack
[0]) {
543 printf(gettext("empty stack\n"));
548 p
= copy(*stkptr
, n
);
552 while (stkerr
== 0) {
559 if (stkptr
== &stack
[0]) {
560 error(gettext("save: args\n"));
564 sp
= stable
[c
] = sfree
;
572 q
= copy(p
, length(p
) + PTRSZ
);
573 for (n
= 0; n
< PTRSZ
; n
++) {
582 error(gettext("symbol table overflow\n"));
584 if (stkptr
== &stack
[0]) {
585 error(gettext("save:args\n"));
593 while (sfeof(p
) == 0)
598 sptr
= stable
[c
] = sfree
;
616 stable
[c
] = sptr
->next
;
622 while (sfeof(p
) == 0) {
638 * Make sure index is between 0 and BC_DIM_MAX-1
641 if ((sfbeg(q
) == 0) && ((c
= sbackc(q
)) < 0))
642 error(gettext("invalid index\n"));
644 while (c
< BC_DIM_MAX
&& sfbeg(q
) == 0)
645 c
= (c
* (scalev
*= 100)) + sbackc(q
);
648 error(gettext("index is too large\n"));
654 sptr
= stable
[n
] = sfree
;
659 p
= salloc((c
+ PTRSZ
) * PTRSZ
);
663 if (length(p
) - PTRSZ
< c
* PTRSZ
) {
664 q
= copy(p
, (c
+ PTRSZ
) * PTRSZ
);
675 salterwd((struct wblk
*)p
, s
);
687 * Make sure index is between 0 and BC_DIM_MAX-1
690 if ((sfbeg(q
) == 0) && ((c
= sbackc(q
)) < 0))
691 error(gettext("invalid index\n"));
693 while (c
< BC_DIM_MAX
&& sfbeg(q
) == 0)
694 c
= (c
* (scalev
*= 100)) + sbackc(q
);
697 error(gettext("index is too large\n"));
704 if (length(p
) - PTRSZ
>= c
* PTRSZ
) {
708 q
= copy(s
, length(s
));
714 q
= salloc(1); /* uninitializd array elt prints as 0 */
722 if ((readptr
!= &readstk
[0]) && (*readptr
!= 0)) {
723 if ((*readptr
)->rd
== (*readptr
)->wt
)
726 if (readptr
++ == &readstk
[RDSKSZ
]) {
728 ("nesting depth\n"));
737 if ((c
= readc()) != '\n')
742 if (++readptr
== &readstk
[RDSKSZ
]) {
743 error(gettext("nesting depth\n"));
748 while ((c
= readc()) == '!')
752 while ((c
= readc()) != '\n') {
771 printf(gettext("%o is unimplemented\n"), c
);
777 dcdiv(struct blk
*ddivd
, struct blk
*ddivr
)
779 int divsign
, remsign
, offset
, divcarry
;
780 int carry
, dig
, magic
, d
, dd
, under
;
783 struct blk
*p
, *divd
, *divr
;
787 if (length(ddivr
) == 0) {
789 printf(gettext("divide by 0\n"));
792 divsign
= remsign
= 0;
795 if (sbackc(divr
) == -1) {
796 divr
= copy(ddivr
, length(ddivr
));
800 divd
= copy(ddivd
, length(ddivd
));
802 if (sfbeg(divd
) == 0 && sbackc(divd
) == -1) {
807 offset
= length(divd
) - length(divr
);
810 seekc(p
, offset
+ 1);
817 c
= c
* 100 + (sfbeg(divr
)?0:sbackc(divr
));
819 c
= (c
* 100 +(sfbeg(divr
)?0:sbackc(divr
)))*2;
822 while (offset
>= 0) {
824 td
= sbackc(divd
) * 100;
825 dd
= sfbeg(divd
)?0:sbackc(divd
);
826 td
= (td
+ dd
) * 100;
827 dd
= sfbeg(divd
)?0:sbackc(divd
);
838 if (td
%cc
< 8 && dig
> 0 && magic
) {
845 while (sfeof(divr
) == 0) {
846 d
= sgetc(divr
) * dig
+ carry
;
848 salterc(divxyz
, d
% 100);
850 salterc(divxyz
, carry
);
854 while (sfeof(divd
) == 0) {
856 d
= d
- (sfeof(divxyz
) ? 0 : sgetc(divxyz
)) - carry
;
870 if ((d
!= 0) && /* !divcarry */ (offset
!= 0)) {
871 d
= sbackc(divd
) + 100;
878 if (under
) { /* undershot last - adjust */
879 px
= copy(divr
, length(divr
)); /* 11/88 don't corrupt ddivr */
883 if (length(ps
) > 0 && sbackc(ps
) < 0) {
884 release(ps
); /* only adjust in really undershot */
894 ps
= add(divr
, divd
);
901 while (sfeof(p
) == 0) {
902 d
= slookc(p
) + divcarry
;
911 salterc(p
, divcarry
);
913 while (sfbeg(p
) == 0) {
921 while (sfbeg(divd
) == 0) {
922 if (sbackc(divd
) == 0)
938 struct blk
*dd
, *dr
, *r
;
949 if (sfbeg(dr
) == 1 || (sfbeg(dr
) == 0 && sbackc(dr
) == 0)) {
952 printf(gettext("divide by 0\n"));
955 if (sfbeg(dd
) == 1 || (sfbeg(dd
) == 0 && sbackc(dd
) == 0)) {
978 removr(struct blk
*p
, int n
)
981 struct blk
*q
, *s
, *r
;
994 while (sfeof(p
) == 0)
998 s
= dcdiv(r
, tenptr
);
1001 if (sfeof(rem
) == 0)
1002 sputc(q
, sgetc(rem
));
1026 struct blk
*r
, *q
, *s
, *t
;
1033 c
= c
* 100 + (sfbeg(p
) ? 0 : sbackc(p
));
1039 while ((c
-= nn
) >= 0)
1055 q
= dcdiv(s
, sqtemp
);
1058 s
= copy(r
, length(r
));
1063 nn
= sfbeg(t
) ? 0 : sbackc(t
);
1077 exp(struct blk
*base
, struct blk
*ex
)
1079 struct blk
*r
, *e
, *p
, *e1
, *t
, *cp
;
1083 p
= copy(base
, length(base
));
1084 e
= copy(ex
, length(ex
));
1094 while (length(e
) != 0) {
1095 e1
= dcdiv(e
, sqtemp
);
1105 t
= copy(p
, length(p
));
1112 if ((c
= length(base
)) == 0) {
1119 if ((c
= sgetc(base
)) <= 1) {
1133 init(int argc
, char **argv
)
1139 if (signal(SIGINT
, SIG_IGN
) != SIG_IGN
)
1140 signal(SIGINT
, onintr
);
1141 setbuf(stdout
, (char *)NULL
);
1144 while (svargc
> 0 && svargv
[1][0] == '-') {
1145 switch (svargv
[1][1]) {
1158 if (stat(svargv
[1], &tsb
) < 0) {
1159 printf(gettext("Cannot stat %s: "), svargv
[1]);
1164 if (S_ISREG(tsb
.st_mode
)) {
1165 if ((curfile
= fopen(svargv
[1], "r")) == NULL
) {
1166 printf(gettext("can't open file %s\n"), \
1171 printf(gettext("invalid file type: %s\n"), \
1177 dummy
= dcmalloc(0);
1178 scalptr
= salloc(1);
1187 * default line length is 70 characters including newline
1202 stkbeg
= stkptr
= &stack
[0];
1203 stkend
= &stack
[STKSZ
];
1205 readptr
= &readstk
[0];
1207 sp
= sptr
= &symlst
[0];
1208 while (sptr
< &symlst
[TBLSZ
]) {
1220 signal(sig
, onintr
);
1221 while (readptr
!= &readstk
[0]) {
1231 pushp(struct blk
*p
)
1233 if (stkptr
== stkend
)
1234 printf(gettext("out of stack space\n"));
1244 if (stkptr
== stack
) {
1272 if (c
>= 'A' && c
<= 'F')
1275 if (c
>= '0' && c
<= '9')
1299 /* if not base 10, then scale fractional input to precision */
1300 if (((int)*(inbas
->beg
)) != 10) {
1316 * returns pointer to struct with ct 0's & p
1319 add0(struct blk
*p
, int ct
)
1323 q
= salloc(length(p
) + (ct
+ 1) / 2);
1329 while (sfeof(p
) == 0) {
1334 t
= mult(tenptr
, q
);
1342 mult(struct blk
*p
, struct blk
*q
)
1344 struct blk
*mp
, *mq
, *mr
;
1345 int sign
, offset
, carry
;
1346 int cq
, cp
, mt
, mcr
;
1351 if (sfbeg(p
) == 0) {
1352 if (sbackc(p
) < 0) {
1353 mp
= copy(p
, length(p
));
1360 if (sfbeg(q
) == 0) {
1361 if (sbackc(q
) < 0) {
1362 mq
= copy(q
, length(q
));
1367 mr
= salloc(length(mp
) + length(mq
));
1370 while (sfeof(mq
) == 0) {
1376 while (sfeof(mp
) == 0) {
1378 mcr
= sfeof(mr
) ? 0 : slookc(mr
);
1379 mt
= cp
*cq
+ carry
+ mcr
;
1381 salterc(mr
, mt
% 100);
1385 mcr
= sfeof(mr
) ? 0 : slookc(mr
);
1386 salterc(mr
, mcr
+ carry
);
1400 chsign(struct blk
*p
)
1407 while (sfeof(p
) == 0) {
1408 ct
= 100 - slookc(p
) - carry
;
1437 if ((readptr
!= &readstk
[0]) && (*readptr
!= 0)) {
1438 if (sfeof(*readptr
) == 0)
1439 return (lastchar
= sgetc(*readptr
));
1444 lastchar
= getc(curfile
);
1445 if (lastchar
!= EOF
)
1447 if (readptr
!= &readptr
[0]) {
1453 if (curfile
!= stdin
) {
1465 if ((readptr
!= &readstk
[0]) && (*readptr
!= 0)) {
1466 sungetc(*readptr
, c
);
1478 r
= add(arg1
, arg2
);
1481 r
= mult(arg1
, arg2
);
1484 r
= dcdiv(arg1
, arg2
);
1494 print(struct blk
*hptr
)
1496 struct blk
*p
, *q
, *dec
;
1501 while (sfeof(hptr
) == 0) {
1502 if (sgetc(hptr
) > 99) {
1504 while (sfeof(hptr
) == 0) {
1505 printf("%c", sgetc(hptr
));
1512 sc
= sbackc(hptr
); /* read scale off end of blk */
1513 if (sfbeg(hptr
) != 0) {
1518 p
= copy(hptr
, length(hptr
));
1521 if (sbackc(p
) < 0) {
1525 if ((obase
== 0) || (obase
== -1)) {
1539 dout
= ((dig
/ 10) + dig
) / logo
;
1540 dec
= getdec(p
, sc
);
1542 while (length(p
) != 0) {
1543 q
= dcdiv(p
, basptr
);
1552 while (sfbeg(strptr
) == 0)
1553 OUTC(sbackc(strptr
));
1563 if (ct
!= 0 && obase
> 16)
1565 q
= mult(basptr
, dec
);
1567 dec
= getdec(q
, sc
);
1570 } while (++ct
< dout
);
1573 while (sfeof(strptr
) == 0)
1574 OUTC(sgetc(strptr
));
1579 getdec(struct blk
*p
, int sc
)
1582 struct blk
*q
, *t
, *s
;
1585 if (length(p
) * 2 < sc
) {
1586 q
= copy(p
, length(p
));
1589 q
= salloc(length(p
));
1595 t
= mult(q
, tenptr
);
1596 s
= salloc(cc
= length(q
));
1603 t
= dcdiv(s
, tenptr
);
1612 tenot(struct blk
*p
, int sc
)
1621 * at this point, the number is stored as base 100 (two decimal
1622 * digits per char) stuck in a buf (character array) backwards.
1623 * sc indicates the scaling factor.
1626 while ((sfbeg(p
) == 0) && ((p
->rd
-p
->beg
-1)*2 >= sc
)) {
1628 * get numbers from the buf until we are the beginning of
1629 * the buf (i.e., there are no more numbers) or the numbers
1630 * remaining fall within the scaled (to the right of the
1631 * decimal point) portion.
1637 * as we output digits, we have to watch the line length (ll)
1638 * which should include a '\' and a newline.
1642 * if the number is less than 10, we need to output
1643 * a space-holding '0' (unless this is the first time
1657 printf("%d", c
/ 10);
1661 printf("%d", c
% 10);
1669 * no scaling factor, so we must have exited loop because we
1670 * ran out of numbers.
1677 if ((p
->rd
- p
->beg
) * 2 > sc
) {
1681 printf("%d", c
/ 10);
1689 printf("%d", c
% 10);
1699 if (sc
> (p
->rd
- p
->beg
) * 2) {
1700 while (sc
> (p
->rd
- p
->beg
) * 2) {
1709 /* now go through the scaled portion of the number */
1722 printf("%d", c
/ 10);
1726 printf("%d", c
% 10);
1732 if (sc
== 1) { /* just in case the scaling factor was odd */
1734 printf("%d", sbackc(p
) / 10);
1742 oneot(struct blk
*p
, int sc
, char ch
)
1749 while (length(q
) > 0) {
1760 hexot(struct blk
*p
, int flg
)
1765 if (sfeof(p
) != 0) {
1773 printf(gettext("hex digit > 16"));
1776 sputc(strptr
, c
< 10 ? c
+ '0' : c
- 10 + 'A');
1780 bigot(struct blk
*p
, int flg
)
1790 l
= length(strptr
) + fw
- 1;
1793 if (length(p
) != 0) {
1795 if (sbackc(p
) < 0) {
1799 while (length(p
) != 0) {
1800 q
= dcdiv(p
, tenptr
);
1804 sputc(t
, sfeof(rem
) ? '0' : sgetc(rem
) + '0');
1810 l
= fw1
- length(t
);
1818 while (sfbeg(t
) == 0)
1819 sputc(strptr
, sbackc(t
));
1822 l
-= length(strptr
);
1833 add(struct blk
*a1
, struct blk
*a2
)
1840 size
= length(a1
) > length(a2
) ? length(a1
) : length(a2
);
1845 while (--size
>= 0) {
1846 n1
= sfeof(a1
) ? 0 : sgetc(a1
);
1847 n2
= sfeof(a2
) ? 0 : sgetc(a2
);
1848 n
= n1
+ n2
+ carry
;
1863 if (sfbeg(p
) == 0) {
1864 while (sfbeg(p
) == 0 && (c
= sbackc(p
)) == 0);
1870 if (sfbeg(p
) == 0 && sbackc(p
) == -1) {
1871 while ((c
= sbackc(p
)) == 99) {
1901 p
= add0(p
, skq
- skp
);
1904 q
= add0(q
, skp
- skq
);
1912 removc(struct blk
*p
, int n
)
1922 while (sfeof(p
) == 0)
1925 r
= dcdiv(q
, tenptr
);
1935 scalint(struct blk
*p
)
1945 scale(struct blk
*p
, int n
)
1947 struct blk
*q
, *s
, *t
;
1967 savk
= sunputc(arg1
);
1981 char line
[100], *sl
;
1986 switch (c
= readc()) {
1996 while ((c
= readc()) != '\n')
1999 if ((pid
= fork()) == (pid_t
)0) {
2000 execl("/usr/bin/sh", "sh", "-c", line
, 0);
2003 savint
= signal(SIGINT
, SIG_IGN
);
2004 while ((rpid
= wait(&retcode
)) != pid
&& rpid
!= (pid_t
)-1);
2005 signal(SIGINT
, savint
);
2006 printf(gettext("!\n"));
2021 if (length(p
) == 0) {
2023 if (c
== '<' || c
== '>' || c
== NE
) {
2044 if ((cc
< 0 && (c
== '<' || c
== NG
)) ||
2045 (cc
> 0) && (c
== '>' || c
== NL
)) {
2057 struct blk
*p
, *q
, *t
, *s
;
2064 q
= salloc(length(p
));
2066 while (sfeof(p
) == 0) {
2069 putwd(q
, (struct blk
*)NULL
);
2071 t
= copy(s
, length(s
));
2077 q
= copy(p
, length(p
));
2084 ("function %c undefined\n"), c
+ 'a' - 1);
2106 while ((n
= n
<< 1) > 0)
2119 if (all
- rel
> active
)
2123 if (nbytes
> maxsize
)
2127 ptr
= dcmalloc((unsigned)size
);
2130 if ((ptr
= dcmalloc((unsigned)size
)) == 0)
2133 if ((hdr
= hfree
) == 0)
2135 hfree
= (struct blk
*)hdr
->rd
;
2136 hdr
->rd
= hdr
->wt
= hdr
->beg
= ptr
;
2137 hdr
->last
= ptr
+ size
;
2149 hfree
= h
= (struct blk
*)dcmalloc(HEADSZ
);
2152 if ((hfree
= h
= (struct blk
*)dcmalloc(HEADSZ
)) == 0)
2156 while (h
< hfree
+ (HEADSZ
/BLK
))
2157 (h
++)->rd
= (char *)++kk
;
2163 copy(struct blk
*hptr
, int size
)
2179 ptr
= nalloc(hptr
->beg
, (unsigned)size
);
2182 if ((ptr
= nalloc(hptr
->beg
, (unsigned)size
)) == NULL
) {
2183 printf(gettext("copy size %d\n"), size
);
2187 if ((hdr
= hfree
) == 0)
2189 hfree
= (struct blk
*)hdr
->rd
;
2190 hdr
->rd
= hdr
->beg
= ptr
;
2191 hdr
->last
= ptr
+ size
;
2194 while (ptr
< hdr
->last
)
2200 sdump(char *s1
, struct blk
*hptr
)
2205 printf("%s %o rd %o wt %o beg %o last %o\n", s1
, hptr
,
2206 hptr
->rd
, hptr
->wt
, hptr
->beg
, hptr
->last
);
2208 while (p
< hptr
->wt
)
2209 printf("%d ", *p
++);
2212 printf("%s %o\n", s1
, hptr
);
2216 seekc(struct blk
*hptr
, int n
)
2221 if (nn
> hptr
->last
) {
2222 nbytes
+= nn
- hptr
->last
;
2223 if (nbytes
> maxsize
)
2225 lbytes
+= nn
- hptr
->last
;
2228 p
= realloc(hptr
->beg
, (unsigned)n
);
2230 hptr
->beg
= realloc(hptr
->beg
,
2231 (unsigned)(hptr
->last
- hptr
->beg
));
2233 if ((p
= realloc(hptr
->beg
, (unsigned)n
)) == 0)
2237 hptr
->wt
= hptr
->last
= hptr
->rd
= p
+ n
;
2246 salterwd(struct wblk
*hptr
, struct blk
*n
)
2248 if (hptr
->rdw
== hptr
->lastw
)
2249 more((struct blk
*)hptr
);
2251 if (hptr
->rdw
> hptr
->wtw
)
2252 hptr
->wtw
= hptr
->rdw
;
2256 more(struct blk
*hptr
)
2261 if ((size
= (hptr
->last
- hptr
->beg
) * 2) == 0)
2264 if (nbytes
> maxsize
)
2270 p
= realloc(hptr
->beg
, (unsigned)size
);
2272 hptr
->beg
= realloc(hptr
->beg
,
2273 (unsigned)(hptr
->last
- hptr
->beg
));
2275 if ((p
= realloc(hptr
->beg
, size
)) == 0)
2278 hptr
->rd
= hptr
->rd
- hptr
->beg
+ p
;
2279 hptr
->wt
= hptr
->wt
- hptr
->beg
+ p
;
2281 hptr
->last
= p
+ size
;
2287 printf(gettext("out of space: %s\n"), s
);
2288 printf(gettext("all %ld rel %ld headmor %ld\n"), all
, rel
, headmor
);
2289 printf(gettext("nbytes %ld\n"), nbytes
);
2290 sdump("stk", *stkptr
);
2294 #define G1 gettext("array %o elt %d odd\n")
2295 #define G2 gettext("tmps %o p %o\n")
2304 printf(gettext("got to garbage %s\n"), s
);
2305 for (i
= 0; i
< TBLSZ
; i
++) {
2311 if (((int)p
->beg
& 01) != 0) {
2314 sdump("odd beg", p
);
2318 } while (tmps
!= 0);
2325 while ((q
= getwd(p
)) != NULL
) {
2328 if (((int)q
->beg
& 01)
2341 } while (tmps
!= 0);
2348 redef(struct blk
*p
)
2354 if ((int)p
->beg
& 01) {
2355 printf(gettext("odd ptr %o hdr %o\n"), p
->beg
, p
);
2356 ospace("redef-bad");
2359 dummy
= dcmalloc(0);
2362 newp
= realloc(p
->beg
, (unsigned)(p
->last
- p
->beg
));
2365 offset
= newp
- p
->beg
;
2373 release(struct blk
*p
)
2377 nbytes
-= p
->last
- p
->beg
;
2378 p
->rd
= (char *)hfree
;
2385 getwd(struct blk
*p
)
2389 wp
= (struct wblk
*)p
;
2390 if (wp
->rdw
== wp
->wtw
)
2392 return (*wp
->rdw
++);
2396 putwd(struct blk
*p
, struct blk
*c
)
2400 wp
= (struct wblk
*)p
;
2401 if (wp
->wtw
== wp
->lastw
)
2407 lookwd(struct blk
*p
)
2411 wp
= (struct wblk
*)p
;
2412 if (wp
->rdw
== wp
->wtw
)
2418 nalloc(char *p
, unsigned int nbytes
)
2422 q
= r
= dcmalloc(nbytes
);
2433 return (malloc(size
? size
: 1));