/********************************************************/ /* */ /* ROFF4, Version 1.60 */ /* */ /*(C) 1983,4 by Ernest E. Bergmann */ /* Physics, Building #16 */ /* Lehigh Univerisity */ /* Bethlehem, Pa. 18015 */ /* */ /* Permission is hereby granted for all commercial and */ /* non-commercial reproduction and distribution of this */ /* material provided this notice is included. */ /* */ /********************************************************/ /*Jan 14, 1984*/ #include "roff4.h" char *malloc(); /**************************************************/ int value(base,string) /*unsigned conversion*/ int base; /*radix for conversion*/ char *string; /*no leading blanks please!*/ /*trailing whitespace or '\0'*/ {int val,d; char c; val=0; for(d=digit(*string);d>=0 && d9) i++; if(num>99) i++; if(num>999) i++; } else if((c!=TCVAL)&&(c!=CFVAL)) {if((c<=' ')&&(word)) goto error; else i++; } else if(c==CFVAL) {c= *(++s); if(c==TCVAL) goto error;/*both CFVAL,TCVAL*/ switch(c) {case 'h': case 'H':if(i>i2) i2=i; if(i) i--; else goto error;/*before start*/ break; case '+': h--; if(hb) b=h; break; case 'B': case 'b': case 'D': case 'd': case 'u': case 'U': case 'X': case 'x': break; case '(': p1=i; break; case '[': p2=i; break; case '{': p3=i; break; case ')': if(i>i2) i2=i; i=p1; break; case ']': if(i>i2) i2=i; i=p2; break; case '}': if(i>i2) i2=i; i=p3; break; default: if(CPTR[c-' ']) break; goto error; /*undecipherable*/ }} else/*c==TCVAL*/ {if(class(*(s+1))!=BLACK) goto error; /*illegal translation*/ } } if(h) goto error; if(word){WTOP=t; WBOT=b; } else {LTOP=t; LBOT=b; } if(i>=i2)return(i); /* else prints beyond last character: */ error: /*should be fprint -> STDERR*/ fprintf(STDERR,"STRLN3:<%s> is illegally formed\n", ss); return(strlen(ss)); } /* A properly formed token string has its first printable character indicating the lefthand edge and the last printable character at the right hand edge. Only legal control pairs accepted. It must consist of printable symbols. */ /************************************ set stack like set() sets a variable *************************************/ setS(param,val,arg_typ,defval,minval,maxval) int param[STKSIZ],val,defval,minval,maxval; char arg_typ; {int i; if(val==NO_VAL) {for(i=0;i,base=<%d>", wrdbuf, base); } else return(FALSE); /*error: missing arg*/ start(); *ncode = 0; while(*ncode<127) {while(getwrd(LINE,wrdbuf)!=WE_HAVE_A_WORD) fgets2(LINE,fp); if DEBUG fprintf(STDERR,"\nGETTR: next token is <%s>", wrdbuf); if(';'== *wrdbuf) fgets2(LINE,fp);/*comment*/ else if('.'== *wrdbuf) { /*save #*/ complete(); return(*wrdbuf); } else { if((code=value(base,wrdbuf)) > -1) {*(PCHR++) = code; (*ncode)++ ; } else {complete(); return(*wrdbuf); /*conversion error*/ } } } complete(); fprintf(STDERR,"\nGETCODE: code sequence too long"); return(FALSE); } /**************************************************/ ocode() /*process .ou*/ {char wrdbuf[MAXLINE]; getwrd(LINE,wrdbuf); /*remove .ou*/ PCHR = OUSTRING; if('.'==getcode(&OUNUM)) outstr(OUSTRING,OUNUM); else fprintf(STDERR,"\nOCODE: error in:\n%s",LINE); } /**************************************************/ outstr(p,maxval) /*print string whose bytecount is *p */ char *p; int maxval; {int i; for (i=1;i<=maxval;i++) { if DEBUG fprintf(STDERR,"outstr: p[%d] is <%x>\n",i,*p); putchar(*p); p +=1; } } /**************************************************/ getfr() /*process .FR ;cf. ocode() */ {char getcode(),wrdbuf[MAXLINE]; getwrd(LINE,wrdbuf); if(getwrd(LINE,wrdbuf)==WE_HAVE_A_WORD) FRVAL = atoi(wrdbuf); else return; FRVAL=max(1,FRVAL); FRVAL=min(FRVAL,4); PCHR = FRSTRING; if('.'!=getcode(&FRNUM)) fprintf(STDERR,"\nError for .FR in:\n%s\n", LINE); } /**************************************************/ getwh() /*process .WH ;cf. gettr() */ {char getcode(), wrdbuf[MAXLINE]; getwrd(LINE,wrdbuf); PCHR = WHSTRING; if('.'!=getcode(&WHNUM)) fprintf(STDERR,"\nError for .WH in:\n%s\n", LINE); }