static char sccsid
[] = "@(#)n3.c 4.2 %G%";
macro and string routines, storage allocation
extern struct s
*frame
, *stk
, *nxf
;
int Buf
[NBLIST
*BLK
+ NEV
*EVS
];
if((i
= copyb()) != '.')control(i
,1);
if(((i
=getrq())==0) || ((oldmn
=findmn(i
)) < 0))return;
clrmn(findmn(j
=getrq()));
if(j
)contab
[oldmn
].rq
= (contab
[oldmn
].rq
& MMASK
) | j
;
if((i
=getrq())==0)goto de1
;
if((offset
=finds(i
)) == 0)goto de1
;
if(newmn
)contab
[newmn
].rq
= i
| MMASK
;
if(req
!= '.')control(req
,1);
if(i
== (contab
[j
].rq
& ~MMASK
))break;
if(contab
[i
].rq
& MMASK
)ffree(((filep
)contab
[i
].x
.mx
)<<BLKBITS
);
if(app
&& (oldmn
>= 0) && (contab
[oldmn
].rq
& MMASK
)){
ip
= (((filep
)contab
[oldmn
].x
.mx
)<<BLKBITS
);
if(!diflg
)ip
= incoff(ip
);
if(contab
[i
].rq
== 0)break;
if(macerr
++ > 1)done2(02);
prstr("Too many string/macro names.\n");
contab
[i
].x
.mx
= (unsigned)(nextb
>>BLKBITS
);
if(oldmn
== -1)contab
[i
].rq
= -1;
contab
[i
].rq
= mn
| MMASK
;
while(((i
=getch()) & CMASK
) == ' ');
if(skip() || !(j
=getrq()))j
= '.';
i
= (ii
= getch()) & CMASK
;
if((state
== 1) && (i
== '.')){
if((state
== 2) && (i
== j
)){
if(((i
=getch()) & CMASK
) != '"')wbf(i
);
while(((i
=getch()) & CMASK
) != '\n')wbf(i
);
if((j
= boff(i
)) < NEV
*EVS
)j
= 0;
while((blist
[j
= blisti(i
)]) != -1){
i
= ((filep
)blist
[j
])<<BLKBITS
;
return(((filep
)i
)*BLK
+ NEV
*EVS
);
if(!((++offset
) & (BLK
-1))){
if(blist
[j
= blisti(--offset
)] == -1){
prstr("Out of temp file space.\n");
blist
[j
] = (unsigned)(nextb
>>BLKBITS
);
offset
= ((filep
)blist
[j
])<<BLKBITS
;
lseek(ibf
, ((long)woff
) * sizeof(int), 0);
write(ibf
, (char *)wbuf
, wbfi
* sizeof(int));
if((woff
& (~(BLK
-1))) == (roff
& (~(BLK
-1))))roff
= -1;
return((i
-NEV
*EVS
)/(BLK
));
if((i
= (p
& (~(BLK
-1)))) != roff
){
lseek(ibf
, ((long)roff
) * sizeof(int), 0);
if(read(ibf
, (char *)rbuf
, BLK
* sizeof(int)) == 0)return(0);
return(rbuf
[p
& (BLK
-1)]);
if(!((j
= (++p
)) & (BLK
-1))){
if((i
= blist
[blisti(--p
)]) == -1){
prstr("Bad storage allocation.\n");
if(frame
== stk
)return(0);
* test that the end of the allocation is above a certain location
#define SPACETEST(base, size) while ((enda - (size)) <= (char *)(base)){setbrk(DELTA);}
SPACETEST(nxf
, sizeof(struct s
));
nchar
= rchar
= pendt
= ch0
= ch
= 0;
nxf
= (struct s
*)argtop
;
/* ought to be rounded up by sizeof(int) */
if ( (i
= sbrk(x
)) >= (char *)MAXPTR
) {
prstrfl("Core limit reached.\n");
if ( ((i
= getsn()) == 0)
|| ((i
= findmn(i
)) == -1)
|| !(contab
[i
].rq
& MMASK
)) {
SPACETEST(nxf
, sizeof(struct s
));
return(pushi(((filep
)contab
[i
].x
.mx
)<<BLKBITS
));
#define cbits(x) ((x) & CMASK)
tchar
* *argpp
, **argppend
;
* 1 s structure for the macro descriptor
* APERMAC tchar *'s for pointers into the strings
* space for the tchar's themselves
memp
+= sizeof(struct s
);
* CPERMAC (the total # of characters for ALL arguments)
* to a macros, has been carefully chosen
* so that the distance between stack frames is < DELTA
memp
+= APERMAC
* sizeof(tchar
*);
memp
+= CPERMAC
* sizeof(tchar
);
argpp
= (tchar
**)(savnxf
+ 1);
argppend
= &argpp
[APERMAC
];
SPACETEST(argppend
, sizeof(tchar
*));
strp
= (tchar
*)argppend
;
* Zero out all the string pointers before filling them in.
for (j
= 0; j
< APERMAC
; j
++){
fprintf(stderr
, "savnxf=0x%x,nxf=0x%x,argpp=0x%x,strp=argppend=0x%x,lim=0x%x,enda=0x%x\n",
savnxf
, nxf
, argpp
, strp
, lim
, enda
);
while ((argpp
!= argppend
) && (!skip())) {
if (cbits(i
= getch()) == '"')
if ( nlflg
|| (!quote
&& cbits(i
) == ' '))
&& (cbits(i
= getch()) != '"')) {
if (strflg
&& (strp
>= lim
)) {
fprintf(stderr
, "strp=0x%x, lim = 0x%x\n",
prstrfl("Macro argument too long.\n");
SPACETEST(strp
, 3 * sizeof(tchar
));
nxf
->nargs
= argpp
- (tchar
**)(savnxf
+ 1);
if(((i
= (getch() & CMASK
) - '0') > 0) &&
(i
<= APERMAC
) && (i
<= frame
->nargs
))ap
= *((int **)frame
+ i
-1 + (sizeof(struct s
)/sizeof(int **)));
if(skip() || ((i
=getrq()) == 0)){
prstr("Cannot divert.\n");
for(j
=0; j
<10; j
++)k
[j
] = 0; /*not op and curd*/
dip
->dimac
= dip
->ditrap
= dip
->ditf
= 0;
dip
->ditrap
= vnumb((int *)0);
if((offset
= begin
= alloc()) == 0)return;
if((delim
= getch()) & MOT
){
while(((i
= getch()) & CMASK
) != '\n'){
if((i
& CMASK
) == delim
)i
= IMP
;
wbf(IMP
);wbf(IMP
);wbt(0);
w2
= hseg(width
,(filep
)0);
w3
= hseg(width
,(filep
)0);
if(w2
|| w3
)horiz(j
=quant((lt
- w2
)/2-w1
,HOR
));
if(dip
!= d
){if(dip
->dnl
> dip
->hnl
)dip
->hnl
= dip
->dnl
;}
else{if(v
.nl
> dip
->hnl
)dip
->hnl
= v
.nl
;}
if(!i
|| (i
== IMP
))return(acc
);
if((i
& CMASK
) == pagech
){
if(!((xx
= contab
[i
].rq
) & MMASK
))continue;
j
= (((filep
)contab
[i
].x
.mx
)<<BLKBITS
);
while((j
= blist
[blisti(j
)]) != -1){k
++; j
<<= BLKBITS
;}
if(!(*p
++ = (xx
>> BYTE
) & 0177))*(p
-1) = ' ';
if(k
>=100)*p
++ = k
/100 + '0';
if(k
>=10)*p
++ = (k
%100)/10 + '0';