/********************************************************/ /* */ /* 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. */ /* */ /********************************************************/ /*feb 19, 1984*/ /*Jan 14, 1984*/ #include "roff4.h" char *malloc(); insert() /*takes a command line in LINE and adds its entry to the table; no space check is made of TRTBL */ { int i; char *pc,*s2,*s3,*fnd,*sptr; int dum; char *find2(); if DEBUG fprintf(STDERR,"insert: LINE <%s>\n",LINE); SEND++; sptr=STAB[SEND]=(char *)malloc(STABSZ); pc=sptr; gettl3(LINE,sptr,&s2,&s3); /*if(fnd=find2(sptr,STAB,SEND,&dum)) {fprintf(STDERR,"%cWarning: <%s> was defined to be <%s>\n",BELL,pc,fnd); fprintf(STDERR,"...now it is defined to be <%s>\n",s2); }*/ } /****************************************/ showit() /* displays the list of entries in the string substitution table pointed to by HEAD. */ {int i; fprintf(STDERR,"ENTRIES:\n"); for (i=0;i<=SEND;i++) { if (strlen(STAB[i])<1) break; fprintf(STDERR,"%s\n",STAB[i]); } dashes(); } /****************************************/ putback(c) /*cf K & P, p256*/ char c; {if UNBUG fprintf(STDERR,"unbug: beginning putback\n"); if(++BINP >= BACKSIZE) {printf(STDERR,"Too many characters pushed back\n"); exit(); } BACKBUF[BINP]=c; if UNBUG fprintf(STDERR,"unbug: leaving putback\n"); } /****************************************/ int ngetc(fp) FILE *fp; {char c,kgetc(); if UNBUG fprintf(STDERR,"unbug: beginning ngetc\n"); if(BINP) c=BACKBUF[BINP]; else {if(KEYBD) c=kgetc(); else c=getc(fp); BACKBUF[BINP=1]=c; } if((c!=CPMEOF)&&c!=EOF) BINP--; if(c=='\r') {c=ngetc(fp); if(c!='\n') {putback(c); if UNBUG fprintf(STDERR,"unbug: leaving ngetc return 1\n"); return('\r'); } } if UNBUG fprintf(STDERR,"unbug: leaving ngetc\n"); return(c); } /****************************************/ char kgetc() /*like getc(),from keyboard, line-buffered*/ {int i; if UNBUG fprintf(STDERR,"unbug: beginning kgetc\n"); if(!*KPTR) {fprintf(STDERR,"%c",KEYBD); gets(KLINE); i=strlen(KLINE); KLINE[i++]='\n'; KLINE[i]='\0'; KPTR=KLINE; } if UNBUG fprintf(STDERR,"unbug: leaving kgetc\n"); return(*(KPTR++)); } /****************************************/ pbstr(s) /*put back string on input;cf K&P,p257*/ char s[LSZ]; {int i; if UNBUG fprintf(STDERR,"unbug: beginning pbstr\n"); for(i=strlen(s);i>0;) putback(s[--i]); if UNBUG fprintf(STDERR,"unbug: leaving pbstr\n"); } /****************************************/ minsert() /*takes a .DM and following lines and places the information in the table; no macro definition nesting permitted*/ {char c, *pc,*pc2,*mptr,*tptr; int *pw1; /*pass over command and following white space*/ for(pc=LINE,c= *pc; (c!=' ')&&(c!='\n')&&(c!='\t'); pc++) c= *pc; for(; (c==' ')||(c=='\t'); pc++) c= *pc; start(); if(c=='\n') {fprintf(STDERR,".DM is UNnamed\n"); } else { MEND++; mptr=MTAB[MEND]=(char *) malloc(MTABSZ); while(class(c)==BLACK) {*(mptr++)=c; c= *(pc++); } } *(mptr++)='\0'; tptr=mptr; if DEBUG fprintf(STDERR," macro %s \n",MTAB[MEND]); while(fgets2(LINE,fp)) /*until EOF or CPMEOF*/ {pw1=LINE; if((*LINE==COMMAND)&&(comtyp(LINE)==EM)) break; else {transfer(&pw1,&mptr,0); *(mptr-1)='\n'; } } *(mptr++)='\0'; complete(); if DEBUG fprintf(STDERR,"%s",tptr); } /****************************************/ showm() /*lists macro definitions*/ {int i; fprintf(STDERR,"MACROS DEFINED:\n"); for (i=0;i<=MEND;i++) { if (strlen(MTAB[i])<1) break; fprintf(STDERR,"%s\n",MTAB[i]); } dashes(); } /****************************************/ char *macq(line) /*looks up name to see if it is a macro definition. If it is, returns the corresponding string, else returns FALSE. */ char *line; {char c,*pc,wb[LSZ],*find2(); int dum; pc=wb; while(class(c= *(++line))==BLACK) *(pc++)=c; *pc='\0'; return(find2(wb,MTAB,MEND,&dum)); } /****************************************/ char *find2(s,link,maxv,loc) /*finds or doesn't find s in table of substitutions pointed to by link*/ char *s,*link[MAXTAB]; int *loc,maxv; {char *pc; int i,length; if DEBUG fprintf(STDERR,"find2: beginning maxv: <%d>\n",maxv); for(i=0;i<=maxv;i++) { if DEBUG fprintf(STDERR,"find2: s <%s> link[%d] <%s>\n", s,i,link[i]); if (!strcmp(s,link[i])) { pc=link[i]; length = strlen(pc); pc += length; pc++; *loc=i; return(pc); } } return(FALSE); } /****************************************/