148238Sbostic /*- 248238Sbostic * Copyright (c) 1991 The Regents of the University of California. 348238Sbostic * All rights reserved. 448238Sbostic * 548238Sbostic * %sccs.include.proprietary.c% 648238Sbostic */ 748238Sbostic 810927Srrh #ifndef lint 948238Sbostic char copyright[] = 1048238Sbostic "@(#) Copyright (c) 1991 The Regents of the University of California.\n\ 1148238Sbostic All rights reserved.\n"; 1248238Sbostic #endif /* not lint */ 1310927Srrh 1448238Sbostic #ifndef lint 15*58168Storek static char sccsid[] = "@(#)dc.c 5.2 (Berkeley) 02/23/93"; 1648238Sbostic #endif /* not lint */ 1748238Sbostic 1837869Sbostic #include <sys/signal.h> 1910927Srrh #include <stdio.h> 2010927Srrh #include "dc.h" 2148238Sbostic #include <paths.h> 2237869Sbostic 2310927Srrh main(argc,argv) 2410927Srrh int argc; 2510927Srrh char *argv[]; 2610927Srrh { 2710927Srrh init(argc,argv); 2810927Srrh commnds(); 2910927Srrh } 3010927Srrh commnds(){ 3110927Srrh register int c; 3210927Srrh register struct blk *p,*q; 3310927Srrh long l; 3410927Srrh int sign; 3510927Srrh struct blk **ptr,*s,*t; 3610927Srrh struct sym *sp; 3710927Srrh int sk,sk1,sk2; 3810927Srrh int n,d; 3910927Srrh 4010927Srrh while(1){ 4110927Srrh if(((c = readc())>='0' && c <= '9')|| (c>='A' && c <='F') || c == '.'){ 4210927Srrh unreadc(c); 4310927Srrh p = readin(); 4410927Srrh pushp(p); 4510927Srrh continue; 4610927Srrh } 4710927Srrh switch(c){ 4810927Srrh case ' ': 4910927Srrh case '\n': 5010927Srrh case 0377: 5110927Srrh case EOF: 5210927Srrh continue; 5310927Srrh case 'Y': 5410927Srrh sdump("stk",*stkptr); 5510927Srrh printf("all %ld rel %ld headmor %ld\n",all,rel,headmor); 5610927Srrh printf("nbytes %ld\n",nbytes); 5710927Srrh continue; 5810927Srrh case '_': 5910927Srrh p = readin(); 6010927Srrh savk = sunputc(p); 6110927Srrh chsign(p); 6210927Srrh sputc(p,savk); 6310927Srrh pushp(p); 6410927Srrh continue; 6510927Srrh case '-': 6610927Srrh subt(); 6710927Srrh continue; 6810927Srrh case '+': 6910927Srrh if(eqk() != 0)continue; 7010927Srrh binop('+'); 7110927Srrh continue; 7210927Srrh case '*': 7310927Srrh arg1 = pop(); 7410927Srrh EMPTY; 7510927Srrh arg2 = pop(); 7610927Srrh EMPTYR(arg1); 7710927Srrh sk1 = sunputc(arg1); 7810927Srrh sk2 = sunputc(arg2); 7910927Srrh binop('*'); 8010927Srrh p = pop(); 8110927Srrh sunputc(p); 8232267Sbostic savk = n = sk1+sk2; 8332267Sbostic if(n>k && n>sk1 && n>sk2){ 8410927Srrh sk = sk1; 8510927Srrh if(sk<sk2)sk = sk2; 8610927Srrh if(sk<k)sk = k; 8732267Sbostic p = removc(p,n-sk); 8810927Srrh savk = sk; 8910927Srrh } 9010927Srrh sputc(p,savk); 9110927Srrh pushp(p); 9210927Srrh continue; 9310927Srrh case '/': 9410927Srrh casediv: 9510927Srrh if(dscale() != 0)continue; 9610927Srrh binop('/'); 9710927Srrh if(irem != 0)release(irem); 9810927Srrh release(rem); 9910927Srrh continue; 10010927Srrh case '%': 10110927Srrh if(dscale() != 0)continue; 10210927Srrh binop('/'); 10310927Srrh p = pop(); 10410927Srrh release(p); 10510927Srrh if(irem == 0){ 10610927Srrh sputc(rem,skr+k); 10710927Srrh pushp(rem); 10810927Srrh continue; 10910927Srrh } 11010927Srrh p = add0(rem,skd-(skr+k)); 11110927Srrh q = add(p,irem); 11210927Srrh release(p); 11310927Srrh release(irem); 11410927Srrh sputc(q,skd); 11510927Srrh pushp(q); 11610927Srrh continue; 11710927Srrh case 'v': 11810927Srrh p = pop(); 11910927Srrh EMPTY; 12010927Srrh savk = sunputc(p); 12110927Srrh if(length(p) == 0){ 12210927Srrh sputc(p,savk); 12310927Srrh pushp(p); 12410927Srrh continue; 12510927Srrh } 12610927Srrh if((c = sbackc(p))<0){ 12710927Srrh error("sqrt of neg number\n"); 12810927Srrh } 12910927Srrh if(k<savk)n = savk; 13010927Srrh else{ 13110927Srrh n = k*2-savk; 13210927Srrh savk = k; 13310927Srrh } 13410927Srrh arg1 = add0(p,n); 135*58168Storek arg2 = dcsqrt(arg1); 13610927Srrh sputc(arg2,savk); 13710927Srrh pushp(arg2); 13810927Srrh continue; 13910927Srrh case '^': 14010927Srrh neg = 0; 14110927Srrh arg1 = pop(); 14210927Srrh EMPTY; 14310927Srrh if(sunputc(arg1) != 0)error("exp not an integer\n"); 14410927Srrh arg2 = pop(); 14510927Srrh EMPTYR(arg1); 14610927Srrh if(sfbeg(arg1) == 0 && sbackc(arg1)<0){ 14710927Srrh neg++; 14810927Srrh chsign(arg1); 14910927Srrh } 15010927Srrh if(length(arg1)>=3){ 15110927Srrh error("exp too big\n"); 15210927Srrh } 15310927Srrh savk = sunputc(arg2); 15410927Srrh p = exp(arg2,arg1); 15510927Srrh release(arg2); 15610927Srrh rewind(arg1); 15710927Srrh c = sgetc(arg1); 15810927Srrh if(sfeof(arg1) == 0) 15910927Srrh c = sgetc(arg1)*100 + c; 16010927Srrh d = c*savk; 16110927Srrh release(arg1); 16210927Srrh if(neg == 0){ 16310927Srrh if(k>=savk)n = k; 16410927Srrh else n = savk; 16510927Srrh if(n<d){ 16610927Srrh q = removc(p,d-n); 16710927Srrh sputc(q,n); 16810927Srrh pushp(q); 16910927Srrh } 17010927Srrh else { 17110927Srrh sputc(p,d); 17210927Srrh pushp(p); 17310927Srrh } 17410927Srrh } 17510927Srrh else { 17610927Srrh sputc(p,d); 17710927Srrh pushp(p); 17810927Srrh } 17910927Srrh if(neg == 0)continue; 18010927Srrh p = pop(); 18110927Srrh q = salloc(2); 18210927Srrh sputc(q,1); 18310927Srrh sputc(q,0); 18410927Srrh pushp(q); 18510927Srrh pushp(p); 18610927Srrh goto casediv; 18710927Srrh case 'z': 18810927Srrh p = salloc(2); 18910927Srrh n = stkptr - stkbeg; 19010927Srrh if(n >= 100){ 19110927Srrh sputc(p,n/100); 19210927Srrh n %= 100; 19310927Srrh } 19410927Srrh sputc(p,n); 19510927Srrh sputc(p,0); 19610927Srrh pushp(p); 19710927Srrh continue; 19810927Srrh case 'Z': 19910927Srrh p = pop(); 20010927Srrh EMPTY; 20110927Srrh n = (length(p)-1)<<1; 20210927Srrh fsfile(p); 20310927Srrh sbackc(p); 20410927Srrh if(sfbeg(p) == 0){ 20510927Srrh if((c = sbackc(p))<0){ 20610927Srrh n -= 2; 20710927Srrh if(sfbeg(p) == 1)n += 1; 20810927Srrh else { 20910927Srrh if((c = sbackc(p)) == 0)n += 1; 21010927Srrh else if(c > 90)n -= 1; 21110927Srrh } 21210927Srrh } 21310927Srrh else if(c < 10) n -= 1; 21410927Srrh } 21510927Srrh release(p); 21610927Srrh q = salloc(1); 21710927Srrh if(n >= 100){ 21810927Srrh sputc(q,n%100); 21910927Srrh n /= 100; 22010927Srrh } 22110927Srrh sputc(q,n); 22210927Srrh sputc(q,0); 22310927Srrh pushp(q); 22410927Srrh continue; 22510927Srrh case 'i': 22610927Srrh p = pop(); 22710927Srrh EMPTY; 22810927Srrh p = scalint(p); 22910927Srrh release(inbas); 23010927Srrh inbas = p; 23110927Srrh continue; 23210927Srrh case 'I': 23310927Srrh p = copy(inbas,length(inbas)+1); 23410927Srrh sputc(p,0); 23510927Srrh pushp(p); 23610927Srrh continue; 23710927Srrh case 'o': 23810927Srrh p = pop(); 23910927Srrh EMPTY; 24010927Srrh p = scalint(p); 24110927Srrh sign = 0; 24210927Srrh n = length(p); 24310927Srrh q = copy(p,n); 24410927Srrh fsfile(q); 24510927Srrh l = c = sbackc(q); 24610927Srrh if(n != 1){ 24710927Srrh if(c<0){ 24810927Srrh sign = 1; 24910927Srrh chsign(q); 25010927Srrh n = length(q); 25110927Srrh fsfile(q); 25210927Srrh l = c = sbackc(q); 25310927Srrh } 25410927Srrh if(n != 1){ 25510927Srrh while(sfbeg(q) == 0)l = l*100+sbackc(q); 25610927Srrh } 25710927Srrh } 25810927Srrh logo = log2(l); 25910927Srrh obase = l; 26010927Srrh release(basptr); 26110927Srrh if(sign == 1)obase = -l; 26210927Srrh basptr = p; 26310927Srrh outdit = bigot; 26410927Srrh if(n == 1 && sign == 0){ 26510927Srrh if(c <= 16){ 26610927Srrh outdit = hexot; 26710927Srrh fw = 1; 26810927Srrh fw1 = 0; 26910927Srrh ll = 70; 27010927Srrh release(q); 27110927Srrh continue; 27210927Srrh } 27310927Srrh } 27410927Srrh n = 0; 27510927Srrh if(sign == 1)n++; 27610927Srrh p = salloc(1); 27710927Srrh sputc(p,-1); 27810927Srrh t = add(p,q); 27910927Srrh n += length(t)*2; 28010927Srrh fsfile(t); 28110927Srrh if((c = sbackc(t))>9)n++; 28210927Srrh release(t); 28310927Srrh release(q); 28410927Srrh release(p); 28510927Srrh fw = n; 28610927Srrh fw1 = n-1; 28710927Srrh ll = 70; 28810927Srrh if(fw>=ll)continue; 28910927Srrh ll = (70/fw)*fw; 29010927Srrh continue; 29110927Srrh case 'O': 29210927Srrh p = copy(basptr,length(basptr)+1); 29310927Srrh sputc(p,0); 29410927Srrh pushp(p); 29510927Srrh continue; 29610927Srrh case '[': 29710927Srrh n = 0; 29810927Srrh p = salloc(0); 29910927Srrh while(1){ 30010927Srrh if((c = readc()) == ']'){ 30110927Srrh if(n == 0)break; 30210927Srrh n--; 30310927Srrh } 30410927Srrh sputc(p,c); 30510927Srrh if(c == '[')n++; 30610927Srrh } 30710927Srrh pushp(p); 30810927Srrh continue; 30910927Srrh case 'k': 31010927Srrh p = pop(); 31110927Srrh EMPTY; 31210927Srrh p = scalint(p); 31310927Srrh if(length(p)>1){ 31410927Srrh error("scale too big\n"); 31510927Srrh } 31610927Srrh rewind(p); 31710927Srrh k = sfeof(p)?0:sgetc(p); 31810927Srrh release(scalptr); 31910927Srrh scalptr = p; 32010927Srrh continue; 32110927Srrh case 'K': 32210927Srrh p = copy(scalptr,length(scalptr)+1); 32310927Srrh sputc(p,0); 32410927Srrh pushp(p); 32510927Srrh continue; 32610927Srrh case 'X': 32710927Srrh p = pop(); 32810927Srrh EMPTY; 32910927Srrh fsfile(p); 33010927Srrh n = sbackc(p); 33110927Srrh release(p); 33210927Srrh p = salloc(2); 33310927Srrh sputc(p,n); 33410927Srrh sputc(p,0); 33510927Srrh pushp(p); 33610927Srrh continue; 33710927Srrh case 'Q': 33810927Srrh p = pop(); 33910927Srrh EMPTY; 34010927Srrh if(length(p)>2){ 34110927Srrh error("Q?\n"); 34210927Srrh } 34310927Srrh rewind(p); 34410927Srrh if((c = sgetc(p))<0){ 34510927Srrh error("neg Q\n"); 34610927Srrh } 34710927Srrh release(p); 34810927Srrh while(c-- > 0){ 34910927Srrh if(readptr == &readstk[0]){ 35010927Srrh error("readstk?\n"); 35110927Srrh } 35210927Srrh if(*readptr != 0)release(*readptr); 35310927Srrh readptr--; 35410927Srrh } 35510927Srrh continue; 35610927Srrh case 'q': 35710927Srrh if(readptr <= &readstk[1])exit(0); 35810927Srrh if(*readptr != 0)release(*readptr); 35910927Srrh readptr--; 36010927Srrh if(*readptr != 0)release(*readptr); 36110927Srrh readptr--; 36210927Srrh continue; 36310927Srrh case 'f': 36410927Srrh if(stkptr == &stack[0])printf("empty stack\n"); 36510927Srrh else { 36610927Srrh for(ptr = stkptr; ptr > &stack[0];){ 36710927Srrh print(*ptr--); 36810927Srrh } 36910927Srrh } 37010927Srrh continue; 37110927Srrh case 'p': 37210927Srrh if(stkptr == &stack[0])printf("empty stack\n"); 37310927Srrh else{ 37410927Srrh print(*stkptr); 37510927Srrh } 37610927Srrh continue; 37710927Srrh case 'P': 37810927Srrh p = pop(); 37910927Srrh EMPTY; 38010927Srrh sputc(p,0); 38110927Srrh printf("%s",p->beg); 38210927Srrh release(p); 38310927Srrh continue; 38410927Srrh case 'd': 38510927Srrh if(stkptr == &stack[0]){ 38610927Srrh printf("empty stack\n"); 38710927Srrh continue; 38810927Srrh } 38910927Srrh q = *stkptr; 39010927Srrh n = length(q); 39110927Srrh p = copy(*stkptr,n); 39210927Srrh pushp(p); 39310927Srrh continue; 39410927Srrh case 'c': 39510927Srrh while(stkerr == 0){ 39610927Srrh p = pop(); 39710927Srrh if(stkerr == 0)release(p); 39810927Srrh } 39910927Srrh continue; 40010927Srrh case 'S': 40110927Srrh if(stkptr == &stack[0]){ 40210927Srrh error("save: args\n"); 40310927Srrh } 40410927Srrh c = readc() & 0377; 40510927Srrh sptr = stable[c]; 40610927Srrh sp = stable[c] = sfree; 40710927Srrh sfree = sfree->next; 40810927Srrh if(sfree == 0)goto sempty; 40910927Srrh sp->next = sptr; 41010927Srrh p = pop(); 41110927Srrh EMPTY; 41210927Srrh if(c >= ARRAYST){ 41310927Srrh q = copy(p,PTRSZ); 41410927Srrh for(n = 0;n < PTRSZ-1;n++)sputc(q,0); 41510927Srrh release(p); 41610927Srrh p = q; 41710927Srrh } 41810927Srrh sp->val = p; 41910927Srrh continue; 42010927Srrh sempty: 42110927Srrh error("symbol table overflow\n"); 42210927Srrh case 's': 42310927Srrh if(stkptr == &stack[0]){ 42410927Srrh error("save:args\n"); 42510927Srrh } 42610927Srrh c = readc() & 0377; 42710927Srrh sptr = stable[c]; 42810927Srrh if(sptr != 0){ 42910927Srrh p = sptr->val; 43010927Srrh if(c >= ARRAYST){ 43110927Srrh rewind(p); 43210927Srrh while(sfeof(p) == 0)release(getwd(p)); 43310927Srrh } 43410927Srrh release(p); 43510927Srrh } 43610927Srrh else{ 43710927Srrh sptr = stable[c] = sfree; 43810927Srrh sfree = sfree->next; 43910927Srrh if(sfree == 0)goto sempty; 44010927Srrh sptr->next = 0; 44110927Srrh } 44210927Srrh p = pop(); 44310927Srrh sptr->val = p; 44410927Srrh continue; 44510927Srrh case 'l': 44610927Srrh load(); 44710927Srrh continue; 44810927Srrh case 'L': 44910927Srrh c = readc() & 0377; 45010927Srrh sptr = stable[c]; 45110927Srrh if(sptr == 0){ 45210927Srrh error("L?\n"); 45310927Srrh } 45410927Srrh stable[c] = sptr->next; 45510927Srrh sptr->next = sfree; 45610927Srrh sfree = sptr; 45710927Srrh p = sptr->val; 45810927Srrh if(c >= ARRAYST){ 45910927Srrh rewind(p); 46010927Srrh while(sfeof(p) == 0){ 46110927Srrh q = getwd(p); 46210927Srrh if(q != 0)release(q); 46310927Srrh } 46410927Srrh } 46510927Srrh pushp(p); 46610927Srrh continue; 46710927Srrh case ':': 46810927Srrh p = pop(); 46910927Srrh EMPTY; 47010927Srrh q = scalint(p); 47110927Srrh fsfile(q); 47210927Srrh c = 0; 47310927Srrh if((sfbeg(q) == 0) && ((c = sbackc(q))<0)){ 47410927Srrh error("neg index\n"); 47510927Srrh } 47610927Srrh if(length(q)>2){ 47710927Srrh error("index too big\n"); 47810927Srrh } 47910927Srrh if(sfbeg(q) == 0)c = c*100+sbackc(q); 48010927Srrh if(c >= MAXIND){ 48110927Srrh error("index too big\n"); 48210927Srrh } 48310927Srrh release(q); 48410927Srrh n = readc() & 0377; 48510927Srrh sptr = stable[n]; 48610927Srrh if(sptr == 0){ 48710927Srrh sptr = stable[n] = sfree; 48810927Srrh sfree = sfree->next; 48910927Srrh if(sfree == 0)goto sempty; 49010927Srrh sptr->next = 0; 49110927Srrh p = salloc((c+PTRSZ)*PTRSZ); 49210927Srrh zero(p); 49310927Srrh } 49410927Srrh else{ 49510927Srrh p = sptr->val; 49610927Srrh if(length(p)-PTRSZ < c*PTRSZ){ 49710927Srrh q = copy(p,(c+PTRSZ)*PTRSZ); 49810927Srrh release(p); 49910927Srrh p = q; 50010927Srrh } 50110927Srrh } 50210927Srrh seekc(p,c*PTRSZ); 50310927Srrh q = lookwd(p); 50410927Srrh if (q!=NULL) release(q); 50510927Srrh s = pop(); 50610927Srrh EMPTY; 50710927Srrh salterwd(p,s); 50810927Srrh sptr->val = p; 50910927Srrh continue; 51010927Srrh case ';': 51110927Srrh p = pop(); 51210927Srrh EMPTY; 51310927Srrh q = scalint(p); 51410927Srrh fsfile(q); 51510927Srrh c = 0; 51610927Srrh if((sfbeg(q) == 0) && ((c = sbackc(q))<0)){ 51710927Srrh error("neg index\n"); 51810927Srrh } 51910927Srrh if(length(q)>2){ 52010927Srrh error("index too big\n"); 52110927Srrh } 52210927Srrh if(sfbeg(q) == 0)c = c*100+sbackc(q); 52310927Srrh if(c >= MAXIND){ 52410927Srrh error("index too big\n"); 52510927Srrh } 52610927Srrh release(q); 52710927Srrh n = readc() & 0377; 52810927Srrh sptr = stable[n]; 52910927Srrh if(sptr != 0){ 53010927Srrh p = sptr->val; 53110927Srrh if(length(p)-PTRSZ >= c*PTRSZ){ 53210927Srrh seekc(p,c*PTRSZ); 53310927Srrh s = getwd(p); 53410927Srrh if(s != 0){ 53510927Srrh q = copy(s,length(s)); 53610927Srrh pushp(q); 53710927Srrh continue; 53810927Srrh } 53910927Srrh } 54010927Srrh } 54110927Srrh q = salloc(PTRSZ); 54210927Srrh putwd(q, (struct blk *)0); 54310927Srrh pushp(q); 54410927Srrh continue; 54510927Srrh case 'x': 54610927Srrh execute: 54710927Srrh p = pop(); 54810927Srrh EMPTY; 54910927Srrh if((readptr != &readstk[0]) && (*readptr != 0)){ 55010927Srrh if((*readptr)->rd == (*readptr)->wt) 55110927Srrh release(*readptr); 55210927Srrh else{ 55310927Srrh if(readptr++ == &readstk[RDSKSZ]){ 55410927Srrh error("nesting depth\n"); 55510927Srrh } 55610927Srrh } 55710927Srrh } 55810927Srrh else readptr++; 55910927Srrh *readptr = p; 56010927Srrh if(p != 0)rewind(p); 56110927Srrh else{ 56210927Srrh if((c = readc()) != '\n')unreadc(c); 56310927Srrh } 56410927Srrh continue; 56510927Srrh case '?': 56610927Srrh if(++readptr == &readstk[RDSKSZ]){ 56710927Srrh error("nesting depth\n"); 56810927Srrh } 56910927Srrh *readptr = 0; 57010927Srrh fsave = curfile; 57110927Srrh curfile = stdin; 57210927Srrh while((c = readc()) == '!')command(); 57310927Srrh p = salloc(0); 57410927Srrh sputc(p,c); 57510927Srrh while((c = readc()) != '\n'){ 57610927Srrh sputc(p,c); 57710927Srrh if(c == '\\')sputc(p,readc()); 57810927Srrh } 57910927Srrh curfile = fsave; 58010927Srrh *readptr = p; 58110927Srrh continue; 58210927Srrh case '!': 58310927Srrh if(command() == 1)goto execute; 58410927Srrh continue; 58510927Srrh case '<': 58610927Srrh case '>': 58710927Srrh case '=': 58810927Srrh if(cond(c) == 1)goto execute; 58910927Srrh continue; 59010927Srrh default: 59110927Srrh printf("%o is unimplemented\n",c); 59210927Srrh } 59310927Srrh } 59410927Srrh } 59510927Srrh struct blk * 59610927Srrh div(ddivd,ddivr) 59710927Srrh struct blk *ddivd,*ddivr; 59810927Srrh { 59910927Srrh int divsign,remsign,offset,divcarry; 60010927Srrh int carry, dig,magic,d,dd; 60110927Srrh long c,td,cc; 60210927Srrh struct blk *ps; 60310927Srrh register struct blk *p,*divd,*divr; 60410927Srrh 60510927Srrh rem = 0; 60610927Srrh p = salloc(0); 60710927Srrh if(length(ddivr) == 0){ 60810927Srrh pushp(ddivr); 60932128Sbostic printf("divide by 0\n"); 61032128Sbostic return((struct blk *)1); 61110927Srrh } 61210927Srrh divsign = remsign = 0; 61310927Srrh divr = ddivr; 61410927Srrh fsfile(divr); 61510927Srrh if(sbackc(divr) == -1){ 61610927Srrh divr = copy(ddivr,length(ddivr)); 61710927Srrh chsign(divr); 61810927Srrh divsign = ~divsign; 61910927Srrh } 62010927Srrh divd = copy(ddivd,length(ddivd)); 62110927Srrh fsfile(divd); 62210927Srrh if(sfbeg(divd) == 0 && sbackc(divd) == -1){ 62310927Srrh chsign(divd); 62410927Srrh divsign = ~divsign; 62510927Srrh remsign = ~remsign; 62610927Srrh } 62710927Srrh offset = length(divd) - length(divr); 62810927Srrh if(offset < 0)goto ddone; 62910927Srrh seekc(p,offset+1); 63010927Srrh sputc(divd,0); 63110927Srrh magic = 0; 63210927Srrh fsfile(divr); 63310927Srrh c = sbackc(divr); 63410927Srrh if(c<10)magic++; 63510927Srrh c = c*100 + (sfbeg(divr)?0:sbackc(divr)); 63610927Srrh if(magic>0){ 63710927Srrh c = (c*100 +(sfbeg(divr)?0:sbackc(divr)))*2; 63810927Srrh c /= 25; 63910927Srrh } 64010927Srrh while(offset >= 0){ 64110927Srrh fsfile(divd); 64210927Srrh td = sbackc(divd)*100; 64310927Srrh dd = sfbeg(divd)?0:sbackc(divd); 64410927Srrh td = (td+dd)*100; 64510927Srrh dd = sfbeg(divd)?0:sbackc(divd); 64610927Srrh td = td+dd; 64710927Srrh cc = c; 64810927Srrh if(offset == 0)td += 1; 64910927Srrh else cc += 1; 65010927Srrh if(magic != 0)td = td<<3; 65110927Srrh dig = td/cc; 65210927Srrh rewind(divr); 65310927Srrh rewind(divxyz); 65410927Srrh carry = 0; 65510927Srrh while(sfeof(divr) == 0){ 65610927Srrh d = sgetc(divr)*dig+carry; 65710927Srrh carry = d / 100; 65810927Srrh salterc(divxyz,d%100); 65910927Srrh } 66010927Srrh salterc(divxyz,carry); 66110927Srrh rewind(divxyz); 66210927Srrh seekc(divd,offset); 66310927Srrh carry = 0; 66410927Srrh while(sfeof(divd) == 0){ 66510927Srrh d = slookc(divd); 66610927Srrh d = d-(sfeof(divxyz)?0:sgetc(divxyz))-carry; 66710927Srrh carry = 0; 66810927Srrh if(d < 0){ 66910927Srrh d += 100; 67010927Srrh carry = 1; 67110927Srrh } 67210927Srrh salterc(divd,d); 67310927Srrh } 67410927Srrh divcarry = carry; 67510927Srrh sbackc(p); 67610927Srrh salterc(p,dig); 67710927Srrh sbackc(p); 67832267Sbostic if(--offset >= 0){ 67932267Sbostic if(d > 0){ 68032267Sbostic sbackc(divd); 68132267Sbostic dd=sbackc(divd); 68232267Sbostic salterc(divd,dd+100); 68332267Sbostic } 68432267Sbostic divd->wt--; 68532267Sbostic } 68610927Srrh } 68710927Srrh if(divcarry != 0){ 68810927Srrh salterc(p,dig-1); 68910927Srrh salterc(divd,-1); 69010927Srrh ps = add(divr,divd); 69110927Srrh release(divd); 69210927Srrh divd = ps; 69310927Srrh } 69410927Srrh 69510927Srrh rewind(p); 69610927Srrh divcarry = 0; 69710927Srrh while(sfeof(p) == 0){ 69810927Srrh d = slookc(p)+divcarry; 69910927Srrh divcarry = 0; 70010927Srrh if(d >= 100){ 70110927Srrh d -= 100; 70210927Srrh divcarry = 1; 70310927Srrh } 70410927Srrh salterc(p,d); 70510927Srrh } 70610927Srrh if(divcarry != 0)salterc(p,divcarry); 70710927Srrh fsfile(p); 70810927Srrh while(sfbeg(p) == 0){ 70910927Srrh if(sbackc(p) == 0)truncate(p); 71010927Srrh else break; 71110927Srrh } 71210927Srrh if(divsign < 0)chsign(p); 71310927Srrh fsfile(divd); 71410927Srrh while(sfbeg(divd) == 0){ 71510927Srrh if(sbackc(divd) == 0)truncate(divd); 71610927Srrh else break; 71710927Srrh } 71810927Srrh ddone: 71910927Srrh if(remsign<0)chsign(divd); 72010927Srrh if(divr != ddivr)release(divr); 72110927Srrh rem = divd; 72210927Srrh return(p); 72310927Srrh } 72410927Srrh dscale(){ 72510927Srrh register struct blk *dd,*dr; 72610927Srrh register struct blk *r; 72710927Srrh int c; 72810927Srrh 72910927Srrh dr = pop(); 73010927Srrh EMPTYS; 73110927Srrh dd = pop(); 73210927Srrh EMPTYSR(dr); 73310927Srrh fsfile(dd); 73410927Srrh skd = sunputc(dd); 73510927Srrh fsfile(dr); 73610927Srrh skr = sunputc(dr); 73710927Srrh if(sfbeg(dr) == 1 || (sfbeg(dr) == 0 && sbackc(dr) == 0)){ 73810927Srrh sputc(dr,skr); 73910927Srrh pushp(dr); 74010927Srrh errorrt("divide by 0\n"); 74110927Srrh } 74210927Srrh c = k-skd+skr; 74310927Srrh if(c < 0)r = removr(dd,-c); 74410927Srrh else { 74510927Srrh r = add0(dd,c); 74610927Srrh irem = 0; 74710927Srrh } 74810927Srrh arg1 = r; 74910927Srrh arg2 = dr; 75010927Srrh savk = k; 75110927Srrh return(0); 75210927Srrh } 75310927Srrh struct blk * 75410927Srrh removr(p,n) 75510927Srrh struct blk *p; 75610927Srrh { 75710927Srrh int nn; 75810927Srrh register struct blk *q,*s,*r; 75910927Srrh 76010927Srrh rewind(p); 76110927Srrh nn = (n+1)/2; 76210927Srrh q = salloc(nn); 76310927Srrh while(n>1){ 76410927Srrh sputc(q,sgetc(p)); 76510927Srrh n -= 2; 76610927Srrh } 76710927Srrh r = salloc(2); 76810927Srrh while(sfeof(p) == 0)sputc(r,sgetc(p)); 76910927Srrh release(p); 77010927Srrh if(n == 1){ 77110927Srrh s = div(r,tenptr); 77210927Srrh release(r); 77310927Srrh rewind(rem); 77410927Srrh if(sfeof(rem) == 0)sputc(q,sgetc(rem)); 77510927Srrh release(rem); 77610927Srrh irem = q; 77710927Srrh return(s); 77810927Srrh } 77910927Srrh irem = q; 78010927Srrh return(r); 78110927Srrh } 78210927Srrh struct blk * 783*58168Storek dcsqrt(p) 78410927Srrh struct blk *p; 78510927Srrh { 78610927Srrh struct blk *t; 78710927Srrh struct blk *r,*q,*s; 78810927Srrh int c,n,nn; 78910927Srrh 79010927Srrh n = length(p); 79110927Srrh fsfile(p); 79210927Srrh c = sbackc(p); 79310927Srrh if((n&1) != 1)c = c*100+(sfbeg(p)?0:sbackc(p)); 79410927Srrh n = (n+1)>>1; 79510927Srrh r = salloc(n); 79610927Srrh zero(r); 79710927Srrh seekc(r,n); 79810927Srrh nn=1; 79910927Srrh while((c -= nn)>=0)nn+=2; 80010927Srrh c=(nn+1)>>1; 80110927Srrh fsfile(r); 80210927Srrh sbackc(r); 80310927Srrh if(c>=100){ 80410927Srrh c -= 100; 80510927Srrh salterc(r,c); 80610927Srrh sputc(r,1); 80710927Srrh } 80810927Srrh else salterc(r,c); 80910927Srrh while(1){ 81010927Srrh q = div(p,r); 81110927Srrh s = add(q,r); 81210927Srrh release(q); 81310927Srrh release(rem); 81410927Srrh q = div(s,sqtemp); 81510927Srrh release(s); 81610927Srrh release(rem); 81710927Srrh s = copy(r,length(r)); 81810927Srrh chsign(s); 81910927Srrh t = add(s,q); 82010927Srrh release(s); 82110927Srrh fsfile(t); 82210927Srrh nn = sfbeg(t)?0:sbackc(t); 82310927Srrh if(nn>=0)break; 82410927Srrh release(r); 82510927Srrh release(t); 82610927Srrh r = q; 82710927Srrh } 82810927Srrh release(t); 82910927Srrh release(q); 83010927Srrh release(p); 83110927Srrh return(r); 83210927Srrh } 83310927Srrh struct blk * 83410927Srrh exp(base,ex) 83510927Srrh struct blk *base,*ex; 83610927Srrh { 83710927Srrh register struct blk *r,*e,*p; 83810927Srrh struct blk *e1,*t,*cp; 83910927Srrh int temp,c,n; 84010927Srrh r = salloc(1); 84110927Srrh sputc(r,1); 84210927Srrh p = copy(base,length(base)); 84310927Srrh e = copy(ex,length(ex)); 84410927Srrh fsfile(e); 84510927Srrh if(sfbeg(e) != 0)goto edone; 84610927Srrh temp=0; 84710927Srrh c = sbackc(e); 84810927Srrh if(c<0){ 84910927Srrh temp++; 85010927Srrh chsign(e); 85110927Srrh } 85210927Srrh while(length(e) != 0){ 85310927Srrh e1=div(e,sqtemp); 85410927Srrh release(e); 85510927Srrh e = e1; 85610927Srrh n = length(rem); 85710927Srrh release(rem); 85810927Srrh if(n != 0){ 85910927Srrh e1=mult(p,r); 86010927Srrh release(r); 86110927Srrh r = e1; 86210927Srrh } 86310927Srrh t = copy(p,length(p)); 86410927Srrh cp = mult(p,t); 86510927Srrh release(p); 86610927Srrh release(t); 86710927Srrh p = cp; 86810927Srrh } 86910927Srrh if(temp != 0){ 87010927Srrh if((c = length(base)) == 0){ 87110927Srrh goto edone; 87210927Srrh } 87310927Srrh if(c>1)create(r); 87410927Srrh else{ 87510927Srrh rewind(base); 87610927Srrh if((c = sgetc(base))<=1){ 87710927Srrh create(r); 87810927Srrh sputc(r,c); 87910927Srrh } 88010927Srrh else create(r); 88110927Srrh } 88210927Srrh } 88310927Srrh edone: 88410927Srrh release(p); 88510927Srrh release(e); 88610927Srrh return(r); 88710927Srrh } 88810927Srrh init(argc,argv) 88910927Srrh int argc; 89010927Srrh char *argv[]; 89110927Srrh { 89210927Srrh register struct sym *sp; 89310927Srrh 89410927Srrh if (signal(SIGINT, SIG_IGN) != SIG_IGN) 89510927Srrh signal(SIGINT,onintr); 89610927Srrh setbuf(stdout,(char *)NULL); 89710927Srrh svargc = --argc; 89810927Srrh svargv = argv; 89910927Srrh while(svargc>0 && svargv[1][0] == '-'){ 90010927Srrh switch(svargv[1][1]){ 90110927Srrh default: 90210927Srrh dbg=1; 90310927Srrh } 90410927Srrh svargc--; 90510927Srrh svargv++; 90610927Srrh } 90710927Srrh ifile=1; 90810927Srrh if(svargc<=0)curfile = stdin; 90910927Srrh else if((curfile = fopen(svargv[1],"r")) == NULL){ 91010927Srrh printf("can't open file %s\n",svargv[1]); 91110927Srrh exit(1); 91210927Srrh } 91310927Srrh scalptr = salloc(1); 91410927Srrh sputc(scalptr,0); 91510927Srrh basptr = salloc(1); 91610927Srrh sputc(basptr,10); 91710927Srrh obase=10; 91810927Srrh log10=log2(10L); 91910927Srrh ll=70; 92010927Srrh fw=1; 92110927Srrh fw1=0; 92210927Srrh tenptr = salloc(1); 92310927Srrh sputc(tenptr,10); 92410927Srrh obase=10; 92510927Srrh inbas = salloc(1); 92610927Srrh sputc(inbas,10); 92710927Srrh sqtemp = salloc(1); 92810927Srrh sputc(sqtemp,2); 92910927Srrh chptr = salloc(0); 93010927Srrh strptr = salloc(0); 93110927Srrh divxyz = salloc(0); 93210927Srrh stkbeg = stkptr = &stack[0]; 93310927Srrh stkend = &stack[STKSZ]; 93410927Srrh stkerr = 0; 93510927Srrh readptr = &readstk[0]; 93610927Srrh k=0; 93710927Srrh sp = sptr = &symlst[0]; 93811774Ssam while(sptr < &symlst[TBLSZ-1]){ 93910927Srrh sptr->next = ++sp; 94010927Srrh sptr++; 94110927Srrh } 94210927Srrh sptr->next=0; 94310927Srrh sfree = &symlst[0]; 94410927Srrh return; 94510927Srrh } 94639168Sbostic void 94710927Srrh onintr(){ 94810927Srrh 94910927Srrh signal(SIGINT,onintr); 95010927Srrh while(readptr != &readstk[0]){ 95110927Srrh if(*readptr != 0){release(*readptr);} 95210927Srrh readptr--; 95310927Srrh } 95410927Srrh curfile = stdin; 95510927Srrh commnds(); 95610927Srrh } 95710927Srrh pushp(p) 95810927Srrh struct blk *p; 95910927Srrh { 96010927Srrh if(stkptr == stkend){ 96110927Srrh printf("out of stack space\n"); 96210927Srrh return; 96310927Srrh } 96410927Srrh stkerr=0; 96510927Srrh *++stkptr = p; 96610927Srrh return; 96710927Srrh } 96810927Srrh struct blk * 96910927Srrh pop(){ 97010927Srrh if(stkptr == stack){ 97110927Srrh stkerr=1; 97210927Srrh return(0); 97310927Srrh } 97410927Srrh return(*stkptr--); 97510927Srrh } 97610927Srrh struct blk * 97710927Srrh readin(){ 97810927Srrh register struct blk *p,*q; 97910927Srrh int dp,dpct; 98010927Srrh register int c; 98110927Srrh 98210927Srrh dp = dpct=0; 98310927Srrh p = salloc(0); 98410927Srrh while(1){ 98510927Srrh c = readc(); 98610927Srrh switch(c){ 98710927Srrh case '.': 98810927Srrh if(dp != 0){ 98910927Srrh unreadc(c); 99010927Srrh break; 99110927Srrh } 99210927Srrh dp++; 99310927Srrh continue; 99410927Srrh case '\\': 99510927Srrh readc(); 99610927Srrh continue; 99710927Srrh default: 99810927Srrh if(c >= 'A' && c <= 'F')c = c - 'A' + 10; 99910927Srrh else if(c >= '0' && c <= '9')c -= '0'; 100010927Srrh else goto gotnum; 100110927Srrh if(dp != 0){ 100210927Srrh if(dpct >= 99)continue; 100310927Srrh dpct++; 100410927Srrh } 100510927Srrh create(chptr); 100610927Srrh if(c != 0)sputc(chptr,c); 100710927Srrh q = mult(p,inbas); 100810927Srrh release(p); 100910927Srrh p = add(chptr,q); 101010927Srrh release(q); 101110927Srrh } 101210927Srrh } 101310927Srrh gotnum: 101410927Srrh unreadc(c); 101510927Srrh if(dp == 0){ 101610927Srrh sputc(p,0); 101710927Srrh return(p); 101810927Srrh } 101910927Srrh else{ 102010927Srrh q = scale(p,dpct); 102110927Srrh return(q); 102210927Srrh } 102310927Srrh } 102410927Srrh struct blk * 102510927Srrh add0(p,ct) 102610927Srrh int ct; 102710927Srrh struct blk *p; 102810927Srrh { 102910927Srrh /* returns pointer to struct with ct 0's & p */ 103010927Srrh register struct blk *q,*t; 103110927Srrh 103210927Srrh q = salloc(length(p)+(ct+1)/2); 103310927Srrh while(ct>1){ 103410927Srrh sputc(q,0); 103510927Srrh ct -= 2; 103610927Srrh } 103710927Srrh rewind(p); 103810927Srrh while(sfeof(p) == 0){ 103910927Srrh sputc(q,sgetc(p)); 104010927Srrh } 104110927Srrh release(p); 104210927Srrh if(ct == 1){ 104310927Srrh t = mult(tenptr,q); 104410927Srrh release(q); 104510927Srrh return(t); 104610927Srrh } 104710927Srrh return(q); 104810927Srrh } 104910927Srrh struct blk * 105010927Srrh mult(p,q) 105110927Srrh struct blk *p,*q; 105210927Srrh { 105310927Srrh register struct blk *mp,*mq,*mr; 105410927Srrh int sign,offset,carry; 105510927Srrh int cq,cp,mt,mcr; 105610927Srrh 105710927Srrh offset = sign = 0; 105810927Srrh fsfile(p); 105910927Srrh mp = p; 106010927Srrh if(sfbeg(p) == 0){ 106110927Srrh if(sbackc(p)<0){ 106210927Srrh mp = copy(p,length(p)); 106310927Srrh chsign(mp); 106410927Srrh sign = ~sign; 106510927Srrh } 106610927Srrh } 106710927Srrh fsfile(q); 106810927Srrh mq = q; 106910927Srrh if(sfbeg(q) == 0){ 107010927Srrh if(sbackc(q)<0){ 107110927Srrh mq = copy(q,length(q)); 107210927Srrh chsign(mq); 107310927Srrh sign = ~sign; 107410927Srrh } 107510927Srrh } 107610927Srrh mr = salloc(length(mp)+length(mq)); 107710927Srrh zero(mr); 107810927Srrh rewind(mq); 107910927Srrh while(sfeof(mq) == 0){ 108010927Srrh cq = sgetc(mq); 108110927Srrh rewind(mp); 108210927Srrh rewind(mr); 108310927Srrh mr->rd += offset; 108410927Srrh carry=0; 108510927Srrh while(sfeof(mp) == 0){ 108610927Srrh cp = sgetc(mp); 108710927Srrh mcr = sfeof(mr)?0:slookc(mr); 108810927Srrh mt = cp*cq + carry + mcr; 108910927Srrh carry = mt/100; 109010927Srrh salterc(mr,mt%100); 109110927Srrh } 109210927Srrh offset++; 109310927Srrh if(carry != 0){ 109410927Srrh mcr = sfeof(mr)?0:slookc(mr); 109510927Srrh salterc(mr,mcr+carry); 109610927Srrh } 109710927Srrh } 109810927Srrh if(sign < 0){ 109910927Srrh chsign(mr); 110010927Srrh } 110110927Srrh if(mp != p)release(mp); 110210927Srrh if(mq != q)release(mq); 110310927Srrh return(mr); 110410927Srrh } 110510927Srrh chsign(p) 110610927Srrh struct blk *p; 110710927Srrh { 110810927Srrh register int carry; 110910927Srrh register char ct; 111010927Srrh 111110927Srrh carry=0; 111210927Srrh rewind(p); 111310927Srrh while(sfeof(p) == 0){ 111410927Srrh ct=100-slookc(p)-carry; 111510927Srrh carry=1; 111610927Srrh if(ct>=100){ 111710927Srrh ct -= 100; 111810927Srrh carry=0; 111910927Srrh } 112010927Srrh salterc(p,ct); 112110927Srrh } 112210927Srrh if(carry != 0){ 112310927Srrh sputc(p,-1); 112410927Srrh fsfile(p); 112510927Srrh sbackc(p); 112610927Srrh ct = sbackc(p); 112710927Srrh if(ct == 99){ 112810927Srrh truncate(p); 112910927Srrh sputc(p,-1); 113010927Srrh } 113110927Srrh } 113210927Srrh else{ 113310927Srrh fsfile(p); 113410927Srrh ct = sbackc(p); 113510927Srrh if(ct == 0)truncate(p); 113610927Srrh } 113710927Srrh return; 113810927Srrh } 113910927Srrh readc(){ 114010927Srrh loop: 114110927Srrh if((readptr != &readstk[0]) && (*readptr != 0)){ 114210927Srrh if(sfeof(*readptr) == 0)return(lastchar = sgetc(*readptr)); 114310927Srrh release(*readptr); 114410927Srrh readptr--; 114510927Srrh goto loop; 114610927Srrh } 114710927Srrh lastchar = getc(curfile); 114810927Srrh if(lastchar != EOF)return(lastchar); 114910927Srrh if(readptr != &readptr[0]){ 115010927Srrh readptr--; 115110927Srrh if(*readptr == 0)curfile = stdin; 115210927Srrh goto loop; 115310927Srrh } 115410927Srrh if(curfile != stdin){ 115510927Srrh fclose(curfile); 115610927Srrh curfile = stdin; 115710927Srrh goto loop; 115810927Srrh } 115910927Srrh exit(0); 116010927Srrh } 116110927Srrh unreadc(c) 116210927Srrh char c; 116310927Srrh { 116410927Srrh 116510927Srrh if((readptr != &readstk[0]) && (*readptr != 0)){ 116610927Srrh sungetc(*readptr,c); 116710927Srrh } 116810927Srrh else ungetc(c,curfile); 116910927Srrh return; 117010927Srrh } 117110927Srrh binop(c) 117210927Srrh char c; 117310927Srrh { 117410927Srrh register struct blk *r; 117510927Srrh 117610927Srrh switch(c){ 117710927Srrh case '+': 117810927Srrh r = add(arg1,arg2); 117910927Srrh break; 118010927Srrh case '*': 118110927Srrh r = mult(arg1,arg2); 118210927Srrh break; 118310927Srrh case '/': 118410927Srrh r = div(arg1,arg2); 118510927Srrh break; 118610927Srrh } 118710927Srrh release(arg1); 118810927Srrh release(arg2); 118910927Srrh sputc(r,savk); 119010927Srrh pushp(r); 119110927Srrh return; 119210927Srrh } 119310927Srrh print(hptr) 119410927Srrh struct blk *hptr; 119510927Srrh { 119610927Srrh int sc; 119710927Srrh register struct blk *p,*q,*dec; 119810927Srrh int dig,dout,ct; 119910927Srrh 120010927Srrh rewind(hptr); 120110927Srrh while(sfeof(hptr) == 0){ 120210927Srrh if(sgetc(hptr)>99){ 120310927Srrh rewind(hptr); 120410927Srrh while(sfeof(hptr) == 0){ 120510927Srrh printf("%c",sgetc(hptr)); 120610927Srrh } 120710927Srrh printf("\n"); 120810927Srrh return; 120910927Srrh } 121010927Srrh } 121110927Srrh fsfile(hptr); 121210927Srrh sc = sbackc(hptr); 121310927Srrh if(sfbeg(hptr) != 0){ 121410927Srrh printf("0\n"); 121510927Srrh return; 121610927Srrh } 121710927Srrh count = ll; 121810927Srrh p = copy(hptr,length(hptr)); 121910927Srrh sunputc(p); 122010927Srrh fsfile(p); 122110927Srrh if(sbackc(p)<0){ 122210927Srrh chsign(p); 122310927Srrh OUTC('-'); 122410927Srrh } 122510927Srrh if((obase == 0) || (obase == -1)){ 122610927Srrh oneot(p,sc,'d'); 122710927Srrh return; 122810927Srrh } 122910927Srrh if(obase == 1){ 123010927Srrh oneot(p,sc,'1'); 123110927Srrh return; 123210927Srrh } 123310927Srrh if(obase == 10){ 123410927Srrh tenot(p,sc); 123510927Srrh return; 123610927Srrh } 123710927Srrh create(strptr); 123810927Srrh dig = log10*sc; 123910927Srrh dout = ((dig/10) + dig) /logo; 124010927Srrh dec = getdec(p,sc); 124110927Srrh p = removc(p,sc); 124210927Srrh while(length(p) != 0){ 124310927Srrh q = div(p,basptr); 124410927Srrh release(p); 124510927Srrh p = q; 124610927Srrh (*outdit)(rem,0); 124710927Srrh } 124810927Srrh release(p); 124910927Srrh fsfile(strptr); 125010927Srrh while(sfbeg(strptr) == 0)OUTC(sbackc(strptr)); 125110927Srrh if(sc == 0){ 125210927Srrh release(dec); 125310927Srrh printf("\n"); 125410927Srrh return; 125510927Srrh } 125610927Srrh create(strptr); 125710927Srrh OUTC('.'); 125810927Srrh ct=0; 125910927Srrh do{ 126010927Srrh q = mult(basptr,dec); 126110927Srrh release(dec); 126210927Srrh dec = getdec(q,sc); 126310927Srrh p = removc(q,sc); 126410927Srrh (*outdit)(p,1); 126510927Srrh }while(++ct < dout); 126610927Srrh release(dec); 126710927Srrh rewind(strptr); 126810927Srrh while(sfeof(strptr) == 0)OUTC(sgetc(strptr)); 126910927Srrh printf("\n"); 127010927Srrh return; 127110927Srrh } 127210927Srrh 127310927Srrh struct blk * 127410927Srrh getdec(p,sc) 127510927Srrh struct blk *p; 127610927Srrh { 127710927Srrh int cc; 127810927Srrh register struct blk *q,*t,*s; 127910927Srrh 128010927Srrh rewind(p); 128110927Srrh if(length(p)*2 < sc){ 128210927Srrh q = copy(p,length(p)); 128310927Srrh return(q); 128410927Srrh } 128510927Srrh q = salloc(length(p)); 128610927Srrh while(sc >= 1){ 128710927Srrh sputc(q,sgetc(p)); 128810927Srrh sc -= 2; 128910927Srrh } 129010927Srrh if(sc != 0){ 129110927Srrh t = mult(q,tenptr); 129210927Srrh s = salloc(cc = length(q)); 129310927Srrh release(q); 129410927Srrh rewind(t); 129510927Srrh while(cc-- > 0)sputc(s,sgetc(t)); 129610927Srrh sputc(s,0); 129710927Srrh release(t); 129810927Srrh t = div(s,tenptr); 129910927Srrh release(s); 130010927Srrh release(rem); 130110927Srrh return(t); 130210927Srrh } 130310927Srrh return(q); 130410927Srrh } 130510927Srrh tenot(p,sc) 130610927Srrh struct blk *p; 130710927Srrh { 130810927Srrh register int c,f; 130910927Srrh 131010927Srrh fsfile(p); 131110927Srrh f=0; 131210927Srrh while((sfbeg(p) == 0) && ((p->rd-p->beg-1)*2 >= sc)){ 131310927Srrh c = sbackc(p); 131410927Srrh if((c<10) && (f == 1))printf("0%d",c); 131510927Srrh else printf("%d",c); 131610927Srrh f=1; 131710927Srrh TEST2; 131810927Srrh } 131910927Srrh if(sc == 0){ 132010927Srrh printf("\n"); 132110927Srrh release(p); 132210927Srrh return; 132310927Srrh } 132410927Srrh if((p->rd-p->beg)*2 > sc){ 132510927Srrh c = sbackc(p); 132610927Srrh printf("%d.",c/10); 132710927Srrh TEST2; 132810927Srrh OUTC(c%10 +'0'); 132910927Srrh sc--; 133010927Srrh } 133110927Srrh else { 133210927Srrh OUTC('.'); 133310927Srrh } 133410927Srrh if(sc > (p->rd-p->beg)*2){ 133510927Srrh while(sc>(p->rd-p->beg)*2){ 133610927Srrh OUTC('0'); 133710927Srrh sc--; 133810927Srrh } 133910927Srrh } 134010927Srrh while(sc > 1){ 134110927Srrh c = sbackc(p); 134210927Srrh if(c<10)printf("0%d",c); 134310927Srrh else printf("%d",c); 134410927Srrh sc -= 2; 134510927Srrh TEST2; 134610927Srrh } 134710927Srrh if(sc == 1){ 134810927Srrh OUTC(sbackc(p)/10 +'0'); 134910927Srrh } 135010927Srrh printf("\n"); 135110927Srrh release(p); 135210927Srrh return; 135310927Srrh } 135410927Srrh oneot(p,sc,ch) 135510927Srrh struct blk *p; 135610927Srrh char ch; 135710927Srrh { 135810927Srrh register struct blk *q; 135910927Srrh 136010927Srrh q = removc(p,sc); 136110927Srrh create(strptr); 136210927Srrh sputc(strptr,-1); 136310927Srrh while(length(q)>0){ 136410927Srrh p = add(strptr,q); 136510927Srrh release(q); 136610927Srrh q = p; 136710927Srrh OUTC(ch); 136810927Srrh } 136910927Srrh release(q); 137010927Srrh printf("\n"); 137110927Srrh return; 137210927Srrh } 137310927Srrh hexot(p,flg) 137410927Srrh struct blk *p; 137510927Srrh { 137610927Srrh register int c; 137710927Srrh rewind(p); 137810927Srrh if(sfeof(p) != 0){ 137910927Srrh sputc(strptr,'0'); 138010927Srrh release(p); 138110927Srrh return; 138210927Srrh } 138310927Srrh c = sgetc(p); 138410927Srrh release(p); 138510927Srrh if(c >= 16){ 138610927Srrh printf("hex digit > 16"); 138710927Srrh return; 138810927Srrh } 138910927Srrh sputc(strptr,c<10?c+'0':c-10+'A'); 139010927Srrh return; 139110927Srrh } 139210927Srrh bigot(p,flg) 139310927Srrh struct blk *p; 139410927Srrh { 139510927Srrh register struct blk *t,*q; 139610927Srrh register int l; 139710927Srrh int neg; 139810927Srrh 139910927Srrh if(flg == 1)t = salloc(0); 140010927Srrh else{ 140110927Srrh t = strptr; 140210927Srrh l = length(strptr)+fw-1; 140310927Srrh } 140410927Srrh neg=0; 140510927Srrh if(length(p) != 0){ 140610927Srrh fsfile(p); 140710927Srrh if(sbackc(p)<0){ 140810927Srrh neg=1; 140910927Srrh chsign(p); 141010927Srrh } 141110927Srrh while(length(p) != 0){ 141210927Srrh q = div(p,tenptr); 141310927Srrh release(p); 141410927Srrh p = q; 141510927Srrh rewind(rem); 141610927Srrh sputc(t,sfeof(rem)?'0':sgetc(rem)+'0'); 141710927Srrh release(rem); 141810927Srrh } 141910927Srrh } 142010927Srrh release(p); 142110927Srrh if(flg == 1){ 142210927Srrh l = fw1-length(t); 142310927Srrh if(neg != 0){ 142410927Srrh l--; 142510927Srrh sputc(strptr,'-'); 142610927Srrh } 142710927Srrh fsfile(t); 142810927Srrh while(l-- > 0)sputc(strptr,'0'); 142910927Srrh while(sfbeg(t) == 0)sputc(strptr,sbackc(t)); 143010927Srrh release(t); 143110927Srrh } 143210927Srrh else{ 143310927Srrh l -= length(strptr); 143410927Srrh while(l-- > 0)sputc(strptr,'0'); 143510927Srrh if(neg != 0){ 143610927Srrh sunputc(strptr); 143710927Srrh sputc(strptr,'-'); 143810927Srrh } 143910927Srrh } 144010927Srrh sputc(strptr,' '); 144110927Srrh return; 144210927Srrh } 144310927Srrh struct blk * 144410927Srrh add(a1,a2) 144510927Srrh struct blk *a1,*a2; 144610927Srrh { 144710927Srrh register struct blk *p; 144810927Srrh register int carry,n; 144910927Srrh int size; 145010927Srrh int c,n1,n2; 145110927Srrh 145210927Srrh size = length(a1)>length(a2)?length(a1):length(a2); 145310927Srrh p = salloc(size); 145410927Srrh rewind(a1); 145510927Srrh rewind(a2); 145610927Srrh carry=0; 145710927Srrh while(--size >= 0){ 145810927Srrh n1 = sfeof(a1)?0:sgetc(a1); 145910927Srrh n2 = sfeof(a2)?0:sgetc(a2); 146010927Srrh n = n1 + n2 + carry; 146110927Srrh if(n>=100){ 146210927Srrh carry=1; 146310927Srrh n -= 100; 146410927Srrh } 146510927Srrh else if(n<0){ 146610927Srrh carry = -1; 146710927Srrh n += 100; 146810927Srrh } 146910927Srrh else carry = 0; 147010927Srrh sputc(p,n); 147110927Srrh } 147210927Srrh if(carry != 0)sputc(p,carry); 147310927Srrh fsfile(p); 147410927Srrh if(sfbeg(p) == 0){ 147510927Srrh while(sfbeg(p) == 0 && (c = sbackc(p)) == 0); 147610927Srrh if(c != 0)salterc(p,c); 147710927Srrh truncate(p); 147810927Srrh } 147910927Srrh fsfile(p); 148010927Srrh if(sfbeg(p) == 0 && sbackc(p) == -1){ 148110927Srrh while((c = sbackc(p)) == 99){ 148210927Srrh if(c == EOF)break; 148310927Srrh } 148410927Srrh sgetc(p); 148510927Srrh salterc(p,-1); 148610927Srrh truncate(p); 148710927Srrh } 148810927Srrh return(p); 148910927Srrh } 149010927Srrh eqk(){ 149110927Srrh register struct blk *p,*q; 149210927Srrh register int skp; 149310927Srrh int skq; 149410927Srrh 149510927Srrh p = pop(); 149610927Srrh EMPTYS; 149710927Srrh q = pop(); 149810927Srrh EMPTYSR(p); 149910927Srrh skp = sunputc(p); 150010927Srrh skq = sunputc(q); 150110927Srrh if(skp == skq){ 150210927Srrh arg1=p; 150310927Srrh arg2=q; 150410927Srrh savk = skp; 150510927Srrh return(0); 150610927Srrh } 150710927Srrh else if(skp < skq){ 150810927Srrh savk = skq; 150910927Srrh p = add0(p,skq-skp); 151010927Srrh } 151110927Srrh else { 151210927Srrh savk = skp; 151310927Srrh q = add0(q,skp-skq); 151410927Srrh } 151510927Srrh arg1=p; 151610927Srrh arg2=q; 151710927Srrh return(0); 151810927Srrh } 151910927Srrh struct blk * 152010927Srrh removc(p,n) 152110927Srrh struct blk *p; 152210927Srrh { 152310927Srrh register struct blk *q,*r; 152410927Srrh 152510927Srrh rewind(p); 152610927Srrh while(n>1){ 152710927Srrh sgetc(p); 152810927Srrh n -= 2; 152910927Srrh } 153010927Srrh q = salloc(2); 153110927Srrh while(sfeof(p) == 0)sputc(q,sgetc(p)); 153210927Srrh if(n == 1){ 153310927Srrh r = div(q,tenptr); 153410927Srrh release(q); 153510927Srrh release(rem); 153610927Srrh q = r; 153710927Srrh } 153810927Srrh release(p); 153910927Srrh return(q); 154010927Srrh } 154110927Srrh struct blk * 154210927Srrh scalint(p) 154310927Srrh struct blk *p; 154410927Srrh { 154510927Srrh register int n; 154610927Srrh n = sunputc(p); 154710927Srrh p = removc(p,n); 154810927Srrh return(p); 154910927Srrh } 155010927Srrh struct blk * 155110927Srrh scale(p,n) 155210927Srrh struct blk *p; 155310927Srrh { 155410927Srrh register struct blk *q,*s,*t; 155510927Srrh 155610927Srrh t = add0(p,n); 155710927Srrh q = salloc(1); 155810927Srrh sputc(q,n); 155910927Srrh s = exp(inbas,q); 156010927Srrh release(q); 156110927Srrh q = div(t,s); 156210927Srrh release(t); 156310927Srrh release(s); 156410927Srrh release(rem); 156510927Srrh sputc(q,n); 156610927Srrh return(q); 156710927Srrh } 156810927Srrh subt(){ 156910927Srrh arg1=pop(); 157010927Srrh EMPTYS; 157110927Srrh savk = sunputc(arg1); 157210927Srrh chsign(arg1); 157310927Srrh sputc(arg1,savk); 157410927Srrh pushp(arg1); 157510927Srrh if(eqk() != 0)return(1); 157610927Srrh binop('+'); 157710927Srrh return(0); 157810927Srrh } 157910927Srrh command(){ 158010927Srrh int c; 158110927Srrh char line[100],*sl; 158239168Sbostic register int pid, rpid; 158339168Sbostic sig_t savint; 158410927Srrh int retcode; 158510927Srrh 158610927Srrh switch(c = readc()){ 158710927Srrh case '<': 158810927Srrh return(cond(NL)); 158910927Srrh case '>': 159010927Srrh return(cond(NG)); 159110927Srrh case '=': 159210927Srrh return(cond(NE)); 159310927Srrh default: 159410927Srrh sl = line; 159510927Srrh *sl++ = c; 159610927Srrh while((c = readc()) != '\n')*sl++ = c; 159710927Srrh *sl = 0; 159810927Srrh if((pid = fork()) == 0){ 159937869Sbostic execl(_PATH_BSHELL,"sh","-c",line,0); 160010927Srrh exit(0100); 160110927Srrh } 160210927Srrh savint = signal(SIGINT, SIG_IGN); 160310927Srrh while((rpid = wait(&retcode)) != pid && rpid != -1); 160410927Srrh signal(SIGINT,savint); 160510927Srrh printf("!\n"); 160610927Srrh return(0); 160710927Srrh } 160810927Srrh } 160910927Srrh cond(c) 161010927Srrh char c; 161110927Srrh { 161210927Srrh register struct blk *p; 161310927Srrh register char cc; 161410927Srrh 161510927Srrh if(subt() != 0)return(1); 161610927Srrh p = pop(); 161710927Srrh sunputc(p); 161810927Srrh if(length(p) == 0){ 161910927Srrh release(p); 162010927Srrh if(c == '<' || c == '>' || c == NE){ 162110927Srrh readc(); 162210927Srrh return(0); 162310927Srrh } 162410927Srrh load(); 162510927Srrh return(1); 162610927Srrh } 162710927Srrh else { 162810927Srrh if(c == '='){ 162910927Srrh release(p); 163010927Srrh readc(); 163110927Srrh return(0); 163210927Srrh } 163310927Srrh } 163410927Srrh if(c == NE){ 163510927Srrh release(p); 163610927Srrh load(); 163710927Srrh return(1); 163810927Srrh } 163910927Srrh fsfile(p); 164010927Srrh cc = sbackc(p); 164110927Srrh release(p); 164210927Srrh if((cc<0 && (c == '<' || c == NG)) || 164310927Srrh (cc >0) && (c == '>' || c == NL)){ 164410927Srrh readc(); 164510927Srrh return(0); 164610927Srrh } 164710927Srrh load(); 164810927Srrh return(1); 164910927Srrh } 165010927Srrh load(){ 165110927Srrh register int c; 165210927Srrh register struct blk *p,*q; 165310927Srrh struct blk *t,*s; 165410927Srrh c = readc() & 0377; 165510927Srrh sptr = stable[c]; 165610927Srrh if(sptr != 0){ 165710927Srrh p = sptr->val; 165810927Srrh if(c >= ARRAYST){ 165910927Srrh q = salloc(length(p)); 166010927Srrh rewind(p); 166110927Srrh while(sfeof(p) == 0){ 166210927Srrh s = getwd(p); 166310927Srrh if(s == 0){putwd(q, (struct blk *)NULL);} 166410927Srrh else{ 166510927Srrh t = copy(s,length(s)); 166610927Srrh putwd(q,t); 166710927Srrh } 166810927Srrh } 166910927Srrh pushp(q); 167010927Srrh } 167110927Srrh else{ 167210927Srrh q = copy(p,length(p)); 167310927Srrh pushp(q); 167410927Srrh } 167510927Srrh } 167610927Srrh else{ 167710927Srrh q = salloc(1); 167810927Srrh sputc(q,0); 167910927Srrh pushp(q); 168010927Srrh } 168110927Srrh return; 168210927Srrh } 168310927Srrh log2(n) 168410927Srrh long n; 168510927Srrh { 168610927Srrh register int i; 168710927Srrh 168810927Srrh if(n == 0)return(0); 168910927Srrh i=31; 169010927Srrh if(n<0)return(i); 169110927Srrh while((n= n<<1) >0)i--; 169210927Srrh return(--i); 169310927Srrh } 169410927Srrh 169510927Srrh struct blk * 169610927Srrh salloc(size) 169710927Srrh int size; 169810927Srrh { 169910927Srrh register struct blk *hdr; 170010927Srrh register char *ptr; 170110927Srrh all++; 170210927Srrh nbytes += size; 170310927Srrh ptr = malloc((unsigned)size); 170410927Srrh if(ptr == 0){ 170510927Srrh garbage("salloc"); 170610927Srrh if((ptr = malloc((unsigned)size)) == 0) 170710927Srrh ospace("salloc"); 170810927Srrh } 170910927Srrh if((hdr = hfree) == 0)hdr = morehd(); 171010927Srrh hfree = (struct blk *)hdr->rd; 171110927Srrh hdr->rd = hdr->wt = hdr->beg = ptr; 171210927Srrh hdr->last = ptr+size; 171310927Srrh return(hdr); 171410927Srrh } 171510927Srrh struct blk * 171610927Srrh morehd(){ 171710927Srrh register struct blk *h,*kk; 171810927Srrh headmor++; 171910927Srrh nbytes += HEADSZ; 172010927Srrh hfree = h = (struct blk *)malloc(HEADSZ); 172110927Srrh if(hfree == 0){ 172210927Srrh garbage("morehd"); 172310927Srrh if((hfree = h = (struct blk *)malloc(HEADSZ)) == 0) 172410927Srrh ospace("headers"); 172510927Srrh } 172610927Srrh kk = h; 172710927Srrh while(h<hfree+(HEADSZ/BLK))(h++)->rd = (char *)++kk; 172810927Srrh (--h)->rd=0; 172910927Srrh return(hfree); 173010927Srrh } 173110927Srrh /* 173210927Srrh sunputc(hptr) 173310927Srrh struct blk *hptr; 173410927Srrh { 173510927Srrh hptr->wt--; 173610927Srrh hptr->rd = hptr->wt; 173710927Srrh return(*hptr->wt); 173810927Srrh } 173910927Srrh */ 174010927Srrh struct blk * 174110927Srrh copy(hptr,size) 174210927Srrh struct blk *hptr; 174310927Srrh int size; 174410927Srrh { 174510927Srrh register struct blk *hdr; 174610927Srrh register unsigned sz; 174710927Srrh register char *ptr; 174810927Srrh 174910927Srrh all++; 175010927Srrh nbytes += size; 175110927Srrh sz = length(hptr); 175210927Srrh ptr = nalloc(hptr->beg, (unsigned)size); 175310927Srrh if(ptr == 0){ 175410927Srrh garbage("copy"); 175510927Srrh if((ptr = nalloc(hptr->beg, (unsigned)size)) == NULL){ 175610927Srrh printf("copy size %d\n",size); 175710927Srrh ospace("copy"); 175810927Srrh } 175910927Srrh } 176010927Srrh if((hdr = hfree) == 0)hdr = morehd(); 176110927Srrh hfree = (struct blk *)hdr->rd; 176210927Srrh hdr->rd = hdr->beg = ptr; 176310927Srrh hdr->last = ptr+size; 176410927Srrh hdr->wt = ptr+sz; 176510927Srrh ptr = hdr->wt; 176610927Srrh while(ptr<hdr->last)*ptr++ = '\0'; 176710927Srrh return(hdr); 176810927Srrh } 176910927Srrh sdump(s1,hptr) 177010927Srrh char *s1; 177110927Srrh struct blk *hptr; 177210927Srrh { 177310927Srrh char *p; 177410927Srrh printf("%s %o rd %o wt %o beg %o last %o\n",s1,hptr,hptr->rd,hptr->wt,hptr->beg,hptr->last); 177510927Srrh p = hptr->beg; 177610927Srrh while(p < hptr->wt)printf("%d ",*p++); 177710927Srrh printf("\n"); 177810927Srrh } 177910927Srrh seekc(hptr,n) 178010927Srrh struct blk *hptr; 178110927Srrh { 178210927Srrh register char *nn,*p; 178310927Srrh 178410927Srrh nn = hptr->beg+n; 178510927Srrh if(nn > hptr->last){ 178610927Srrh nbytes += nn - hptr->last; 178710927Srrh p = realloc(hptr->beg, (unsigned)n); 178810927Srrh if(p == 0){ 178910927Srrh hptr->beg = realloc(hptr->beg, (unsigned)(hptr->last-hptr->beg)); 179010927Srrh garbage("seekc"); 179110927Srrh if((p = realloc(hptr->beg, (unsigned)n)) == 0) 179210927Srrh ospace("seekc"); 179310927Srrh } 179410927Srrh hptr->beg = p; 179510927Srrh hptr->wt = hptr->last = hptr->rd = p+n; 179610927Srrh return; 179710927Srrh } 179810927Srrh hptr->rd = nn; 179910927Srrh if(nn>hptr->wt)hptr->wt = nn; 180010927Srrh return; 180110927Srrh } 180210927Srrh salterwd(hptr,n) 180310927Srrh struct wblk *hptr; 180410927Srrh struct blk *n; 180510927Srrh { 180610927Srrh if(hptr->rdw == hptr->lastw)more(hptr); 180710927Srrh *hptr->rdw++ = n; 180810927Srrh if(hptr->rdw > hptr->wtw)hptr->wtw = hptr->rdw; 180910927Srrh return; 181010927Srrh } 181110927Srrh more(hptr) 181210927Srrh struct blk *hptr; 181310927Srrh { 181410927Srrh register unsigned size; 181510927Srrh register char *p; 181610927Srrh 181710927Srrh if((size=(hptr->last-hptr->beg)*2) == 0)size=1; 181810927Srrh nbytes += size/2; 181910927Srrh p = realloc(hptr->beg, (unsigned)size); 182010927Srrh if(p == 0){ 182110927Srrh hptr->beg = realloc(hptr->beg, (unsigned)(hptr->last-hptr->beg)); 182210927Srrh garbage("more"); 182327447Slepreau if((p = realloc(hptr->beg,(unsigned)size)) == 0) 182410927Srrh ospace("more"); 182510927Srrh } 182610927Srrh hptr->rd = hptr->rd-hptr->beg+p; 182710927Srrh hptr->wt = hptr->wt-hptr->beg+p; 182810927Srrh hptr->beg = p; 182910927Srrh hptr->last = p+size; 183010927Srrh return; 183110927Srrh } 183210927Srrh ospace(s) 183310927Srrh char *s; 183410927Srrh { 183510927Srrh printf("out of space: %s\n",s); 183610927Srrh printf("all %ld rel %ld headmor %ld\n",all,rel,headmor); 183710927Srrh printf("nbytes %ld\n",nbytes); 183810927Srrh sdump("stk",*stkptr); 183910927Srrh abort(); 184010927Srrh } 184110927Srrh garbage(s) 184210927Srrh char *s; 184310927Srrh { 184410927Srrh int i; 184510927Srrh struct blk *p, *q; 184610927Srrh struct sym *tmps; 184710927Srrh int ct; 184810927Srrh 184910927Srrh /* printf("got to garbage %s\n",s); */ 185010927Srrh for(i=0;i<TBLSZ;i++){ 185110927Srrh tmps = stable[i]; 185210927Srrh if(tmps != 0){ 185310927Srrh if(i < ARRAYST){ 185410927Srrh do { 185510927Srrh p = tmps->val; 185610927Srrh if(((int)p->beg & 01) != 0){ 185710927Srrh printf("string %o\n",i); 185810927Srrh sdump("odd beg",p); 185910927Srrh } 186010927Srrh redef(p); 186110927Srrh tmps = tmps->next; 186210927Srrh } while(tmps != 0); 186310927Srrh continue; 186410927Srrh } 186510927Srrh else { 186610927Srrh do { 186710927Srrh p = tmps->val; 186810927Srrh rewind(p); 186910927Srrh ct = 0; 187010927Srrh while((q = getwd(p)) != NULL){ 187110927Srrh ct++; 187210927Srrh if(q != 0){ 187310927Srrh if(((int)q->beg & 01) != 0){ 187410927Srrh printf("array %o elt %d odd\n",i-ARRAYST,ct); 187510927Srrh printf("tmps %o p %o\n",tmps,p); 187610927Srrh sdump("elt",q); 187710927Srrh } 187810927Srrh redef(q); 187910927Srrh } 188010927Srrh } 188110927Srrh tmps = tmps->next; 188210927Srrh } while(tmps != 0); 188310927Srrh } 188410927Srrh } 188510927Srrh } 188610927Srrh } 188710927Srrh redef(p) 188810927Srrh struct blk *p; 188910927Srrh { 189010927Srrh register offset; 189110927Srrh register char *newp; 189210927Srrh 189310927Srrh if ((int)p->beg&01) { 189410927Srrh printf("odd ptr %o hdr %o\n",p->beg,p); 189510927Srrh ospace("redef-bad"); 189610927Srrh } 189710927Srrh newp = realloc(p->beg, (unsigned)(p->last-p->beg)); 189810927Srrh if(newp == NULL)ospace("redef"); 189910927Srrh offset = newp - p->beg; 190010927Srrh p->beg = newp; 190110927Srrh p->rd += offset; 190210927Srrh p->wt += offset; 190310927Srrh p->last += offset; 190410927Srrh } 190510927Srrh 190610927Srrh release(p) 190710927Srrh register struct blk *p; 190810927Srrh { 190910927Srrh rel++; 191010927Srrh nbytes -= p->last - p->beg; 191110927Srrh p->rd = (char *)hfree; 191210927Srrh hfree = p; 191310927Srrh free(p->beg); 191410927Srrh } 191510927Srrh 191610927Srrh struct blk * 191710927Srrh getwd(p) 191810927Srrh struct blk *p; 191910927Srrh { 192010927Srrh register struct wblk *wp; 192110927Srrh 192210927Srrh wp = (struct wblk *)p; 192310927Srrh if (wp->rdw == wp->wtw) 192410927Srrh return(NULL); 192510927Srrh return(*wp->rdw++); 192610927Srrh } 192710927Srrh 192810927Srrh putwd(p, c) 192910927Srrh struct blk *p, *c; 193010927Srrh { 193110927Srrh register struct wblk *wp; 193210927Srrh 193310927Srrh wp = (struct wblk *)p; 193410927Srrh if (wp->wtw == wp->lastw) 193510927Srrh more(p); 193610927Srrh *wp->wtw++ = c; 193710927Srrh } 193810927Srrh 193910927Srrh struct blk * 194010927Srrh lookwd(p) 194110927Srrh struct blk *p; 194210927Srrh { 194310927Srrh register struct wblk *wp; 194410927Srrh 194510927Srrh wp = (struct wblk *)p; 194610927Srrh if (wp->rdw == wp->wtw) 194710927Srrh return(NULL); 194810927Srrh return(*wp->rdw); 194910927Srrh } 195010927Srrh char * 195110927Srrh nalloc(p,nbytes) 195210927Srrh register char *p; 195310927Srrh unsigned nbytes; 195410927Srrh { 195510927Srrh char *malloc(); 195610927Srrh register char *q, *r; 195710927Srrh q = r = malloc(nbytes); 195810927Srrh if(q==0) 195910927Srrh return(0); 196010927Srrh while(nbytes--) 196110927Srrh *q++ = *p++; 196210927Srrh return(r); 196310927Srrh } 1964