Speed hacks for troff (and nroff)
chris at umcp-cs.UUCP
chris at umcp-cs.UUCP
Sat Feb 4 12:36:48 AEST 1984
I've received enough requests that I might as well just post the
diffs. A word of warning: my changes aren't guaranteed in any
way; they will probably only work on 4.1BSD [nt]roff; and they will
probably only work with VMUNIX defined. (They *do* work for us
:->.) (To the curious: the diff listings are off the eneevax
machine, where I have original sources; thus the "Installed CS
version" log messages.)
RCS file: RCS/Makenroff,v; Working file: Makenroff
head: 1.2
locks:
access list:
symbolic names:
comment leader: "# "
total revisions: 2; selected revisions: 2
description:
Makenroff from UCB
----------------------------
revision 1.2
date: 84/01/29 16:31:14; author: bin; state: Exp; lines added/del: 6/14
Installed CS version
----------------------------
revision 1.1
date: 84/01/29 16:09:29; author: bin; state: Exp;
Initial revision
=============================================================================
RCS file: RCS/Makenroff,v
retrieving revision 1.1
diff -b -c1 -r1.1 Makenroff
*** /tmp/,RCSt1025751 Fri Feb 3 20:47:13 1984
--- Makenroff Sun Jan 29 16:31:24 1984
***************
*** 1,2
! CFLAGS = -O -DNROFF -DVMUNIX
c = ni.o nii.o n1.o n2.o n3.o n4.o n5.o n6.o n7.o n8.o n9.o n10.o
--- 1,2 -----
! CFLAGS = -O -DNROFF -DVMUNIX -DBIG=1024 -DFAST
c = ni.o nii.o n1.o n2.o n3.o n4.o n5.o n6.o n7.o n8.o n9.o n10.o
***************
*** 4,6
nroff : $c $s
! $(CC) -z -o nroff $s $c
hytab.o : hytab.c
--- 4,7 -----
nroff : $c $s
! $(CC) $(CFLAGS) -o nroff $s $c -ltermlib
! $c: tdef.h
hytab.o : hytab.c
***************
*** 6,11
hytab.o : hytab.c
! cc -S hytab.c
! /usr/src/cmd/as/:rofix hytab.s
! as -o hytab.o hytab.s
! rm hytab.s
ntab.o: ntab.c
--- 7,9 -----
hytab.o : hytab.c
! cc -R -c hytab.c
ntab.o: ntab.c
***************
*** 11,16
ntab.o: ntab.c
! cc -S ntab.c
! /usr/src/cmd/as/:rofix ntab.s
! as -o ntab.o ntab.s
! rm ntab.s
suftab.o: suftab.c
--- 9,11 -----
ntab.o: ntab.c
! cc -R -c ntab.c
suftab.o: suftab.c
***************
*** 16,21
suftab.o: suftab.c
! cc -S suftab.c
! /usr/src/cmd/as/:rofix suftab.s
! as -o suftab.o suftab.s
! rm suftab.s
--- 11,13 -----
suftab.o: suftab.c
! cc -R -c suftab.c
RCS file: RCS/Maketroff,v; Working file: Maketroff
head: 1.2
locks:
access list:
symbolic names:
comment leader: "# "
total revisions: 2; selected revisions: 2
description:
Maketroff from UCB
----------------------------
revision 1.2
date: 84/01/29 16:31:25; author: bin; state: Exp; lines added/del: 5/10
Installed CS version
----------------------------
revision 1.1
date: 84/01/29 16:09:38; author: bin; state: Exp;
Initial revision
=============================================================================
RCS file: RCS/Maketroff,v
retrieving revision 1.1
diff -b -c1 -r1.1 Maketroff
*** /tmp/,RCSt1025757 Fri Feb 3 20:47:16 1984
--- Maketroff Sun Jan 29 19:17:10 1984
***************
*** 1,2
! CFLAGS = -O -DVMUNIX
c = ni.o nii.o n1.o n2.o n3.o n4.o n5.o t6.o n7.o n8.o n9.o t10.o
--- 1,2 -----
! CFLAGS = -O -DVMUNIX -DBIG=1024 -DFAST
c = ni.o nii.o n1.o n2.o n3.o n4.o n5.o t6.o n7.o n8.o n9.o t10.o
***************
*** 4,6
troff : $c $s
! $(CC) -z -o troff $s $c
hytab.o : hytab.c
--- 4,7 -----
troff : $c $s
! $(CC) $(CFLAGS) -o troff $s $c -ltermlib
! $c: tdef.h
hytab.o : hytab.c
***************
*** 6,11
hytab.o : hytab.c
! cc -S hytab.c
! /usr/src/cmd/as/:rofix hytab.s
! as -o hytab.o hytab.s
! rm hytab.s
suftab.o: suftab.c
--- 7,9 -----
hytab.o : hytab.c
! cc -R -c hytab.c
suftab.o: suftab.c
***************
*** 11,16
suftab.o: suftab.c
! cc -S suftab.c
! /usr/src/cmd/as/:rofix suftab.s
! as -o suftab.o suftab.s
! rm suftab.s
# tab3.o: tab3.c
--- 9,11 -----
suftab.o: suftab.c
! cc -R -c suftab.c
# tab3.o: tab3.c
RCS file: RCS/n1.c,v; Working file: n1.c
head: 1.2
locks:
access list:
symbolic names:
comment leader: " * "
total revisions: 2; selected revisions: 2
description:
n1.c from UCB
----------------------------
revision 1.2
date: 84/02/03 20:11:57; author: bin; state: Exp; lines added/del: 39/3
Installed CS version
----------------------------
revision 1.1
date: 84/02/03 20:11:46; author: bin; state: Exp;
Initial revision
=============================================================================
RCS file: RCS/n1.c,v
retrieving revision 1.1
diff -b -c1 -r1.1 n1.c
*** /tmp/,RCSt1025763 Fri Feb 3 20:47:22 1984
--- n1.c Fri Feb 3 20:12:11 1984
***************
*** 143,144
#endif
--- 143,145 -----
#endif
+ char *getenv ();
***************
*** 251,252
continue;
#endif
--- 252,259 -----
continue;
+ case 'F':
+ {
+ extern char *fontfile;
+ fontfile = &argv[0][2];
+ }
+ continue;
#endif
***************
*** 419,420
static int mode;
--- 426,429 -----
static int mode;
+ char *tbptr;
+ char tbuf[1024];
***************
*** 420,421
if (ttyp==0)
--- 429,439 -----
+ /* 11-3-83 EMA & BNI
+ Added following check so that messages are only turned off
+ if the output is going to the terminal, and the terminal
+ is a hard copy terminal or of unknown type */
+
+ tbptr = getenv ("TERM");
+ if (!isatty (1) || (tgetent (tbuf, tbptr) > 0 && !tgetflag ("hc")))
+ return;
+
if (ttyp==0)
***************
*** 450,452
register i,j;
! extern filep boff();
--- 468,470 -----
register i,j;
! /* extern filep boff(); */
***************
*** 474,476
}
! getch(){
register int i, j, k;
--- 492,496 -----
}
!
! #ifndef FAST
! getch () {
register int i, j, k;
***************
*** 478,479
level++;
g0:
--- 498,508 -----
level++;
+ #else FAST
+ _getch_ () {
+ register int i, j, k;
+
+ level++;
+ /* when we get here we know ch and nlflag are both zero */
+ goto gfast;
+ #endif FAST
+
g0:
***************
*** 491,492
if((k = (i = getch0()) & CMASK) != ESC){
--- 520,522 -----
+ gfast:
if((k = (i = getch0()) & CMASK) != ESC){
***************
*** 703,705
char ifilt[32] = {0,001,002,003,0,005,006,007,010,011,012};
! getch0(){
register int i, j;
--- 733,737 -----
char ifilt[32] = {0,001,002,003,0,005,006,007,010,011,012};
!
! #ifndef FAST
! getch0 () {
register int i, j;
***************
*** 708,709
if(nchar){nchar--; return(rchar);}
--- 740,745 -----
if(nchar){nchar--; return(rchar);}
+ #else FAST
+ _getch0_ () {
+ register int i, j;
+ #endif FAST
RCS file: RCS/n10.c,v; Working file: n10.c
head: 1.2
locks:
access list:
symbolic names:
comment leader: " * "
total revisions: 2; selected revisions: 2
description:
n10.c from UCB
----------------------------
revision 1.2
date: 84/01/29 18:49:45; author: bin; state: Exp; lines added/del: 16/3
Installed CS hacks (with #ifdef PRINTRONIX around the Printronix code)
----------------------------
revision 1.1
date: 84/01/29 18:49:27; author: bin; state: Exp;
Initial revision
=============================================================================
RCS file: RCS/n10.c,v
retrieving revision 1.1
diff -b -c1 -r1.1 n10.c
*** /tmp/,RCSt1025770 Fri Feb 3 20:47:31 1984
--- n10.c Sun Jan 29 18:50:06 1984
***************
*** 83,87
}
! ptout(i)
! int i;
! {
*olinep++ = i;
--- 83,87 -----
}
!
! #ifndef FAST
! ptout (i) int i; {
*olinep++ = i;
***************
*** 89,90
if((i&CMASK) != '\n')return;
olinep--;
--- 89,93 -----
if((i&CMASK) != '\n')return;
+ #else FAST
+ _ptout_ () {
+ #endif FAST
olinep--;
***************
*** 145,146
}
if(xfont == ulfont){
--- 148,150 -----
}
+ #ifndef PRINTRONIX
if(xfont == ulfont){
***************
*** 149,150
}
while(*codep != 0){
--- 153,155 -----
}
+ #endif PRINTRONIX
while(*codep != 0){
***************
*** 162,163
if(!w)for(k=phyw/t.Char;k>0;k--)oput('\b');
}
--- 167,176 -----
if(!w)for(k=phyw/t.Char;k>0;k--)oput('\b');
+ #ifdef PRINTRONIX
+ /* Do underlining here, after the characters are printed. This is
+ the way the Printronix likes them. */
+ if (xfont == ulfont) {
+ for (k = w / t.Char; --k >= 0;) oput ('\b');
+ for (k = w / t.Char; --k >= 0;) oput ('_');
+ }
+ #endif PRINTRONIX
}
RCS file: RCS/n3.c,v; Working file: n3.c
head: 1.2
locks:
access list:
symbolic names:
comment leader: " * "
total revisions: 2; selected revisions: 2
description:
n3.c from UCB
----------------------------
revision 1.2
date: 84/01/29 18:36:27; author: bin; state: Exp; lines added/del: 25/24
Installed CS version -- much speed hacking
----------------------------
revision 1.1
date: 84/01/29 18:36:15; author: bin; state: Exp;
Initial revision
=============================================================================
RCS file: RCS/n3.c,v
retrieving revision 1.1
diff -b -c1 -r1.1 n3.c
*** /tmp/,RCSt1025776 Fri Feb 3 20:47:38 1984
--- n3.c Sun Jan 29 18:36:47 1984
***************
*** 17,18
unsigned blist[NBLIST];
--- 17,21 -----
+ #define blisti(i) (((i)-NEV*EVS)/(BLK))
+ #define boff(i) (((filep)i)*BLK + NEV*EVS)
+
unsigned blist[NBLIST];
***************
*** 135,137
findmn(i)
! int i;
{
--- 138,140 -----
findmn(i)
! register i;
{
***************
*** 138,139
register j;
--- 141,143 -----
register j;
+ register struct contab *p;
***************
*** 139,144
! for(j=0;j<NM;j++){
! if(i == (contab[j].rq & ~MMASK))break;
! }
! if(j==NM)j = -1;
return(j);
--- 143,150 -----
! for (p = contab; p < &contab[NM]; p++)
! if (i == (p->rq & ~MMASK))
! break;
! j = p - contab;
! if (j == NM)
! j = -1;
return(j);
***************
*** 148,150
{
- extern filep boff();
if(i >= 0){
--- 154,155 -----
{
if(i >= 0){
***************
*** 159,161
register i;
- extern filep boff();
register filep savip;
--- 164,165 -----
register i;
register filep savip;
***************
*** 275,277
register i;
- extern filep boff();
filep j;
--- 279,280 -----
register i;
filep j;
***************
*** 300,306
}
! filep boff(i)
! int i;
! {
! return(((filep)i)*BLK + NEV*EVS);
! }
wbt(i)
--- 303,305 -----
}
! #ifndef FAST
wbt(i)
***************
*** 311,312
}
wbf(i)
--- 310,312 -----
}
+ #endif FAST
wbf(i)
***************
*** 347,353
}
! blisti(i)
! filep i;
! {
! return((i-NEV*EVS)/(BLK));
! }
rbf(){
--- 347,350 -----
}
!
! #ifndef FAST
rbf(){
***************
*** 363,364
}
rbf0(p)
--- 360,362 -----
}
+
rbf0(p)
***************
*** 379,380
}
filep incoff(p)
--- 377,380 -----
}
+ #endif FAST
+
filep incoff(p)
***************
*** 380,382
filep incoff(p)
! filep p;
{
--- 380,382 -----
filep incoff(p)
! register filep p;
{
***************
*** 383,387
register i;
! register filep j;
! if(!((j = (++p)) & (BLK-1))){
! if((i = blist[blisti(--p)]) == -1){
prstr("Bad storage allocation.\n");
--- 383,387 -----
register i;
!
! if (!(++p & (BLK-1))) {
! if ((i = blist[blisti(--p)]) == -1) {
prstr("Bad storage allocation.\n");
***************
*** 389,391
}
! j = ((filep)i)<<BLKBITS;
}
--- 389,391 -----
}
! p = ((filep) i) << BLKBITS;
}
***************
*** 391,393
}
! return(j);
}
--- 391,393 -----
}
! return p;
}
***************
*** 393,394
}
popi(){
--- 393,395 -----
}
+
popi(){
RCS file: RCS/t10.c,v; Working file: t10.c
head: 1.2
locks:
access list:
symbolic names:
comment leader: " * "
total revisions: 2; selected revisions: 2
description:
t10.c from UCB
----------------------------
revision 1.2
date: 84/01/29 18:55:53; author: bin; state: Exp; lines added/del: 9/2
Installed CS speed hacks
----------------------------
revision 1.1
date: 84/01/29 18:53:14; author: bin; state: Exp;
Initial revision
=============================================================================
RCS file: RCS/t10.c,v
retrieving revision 1.1
diff -b -c1 -r1.1 t10.c
*** /tmp/,RCSt1025784 Fri Feb 3 20:47:46 1984
--- t10.c Sun Jan 29 18:56:03 1984
***************
*** 67,69
}
! ptout(i)
int i;
--- 67,71 -----
}
!
! #ifndef FAST
! ptout (i)
int i;
***************
*** 69,70
int i;
{
--- 71,75 -----
int i;
+ #else FAST
+ _ptout_ ()
+ #endif FAST
{
***************
*** 74,75
if((i & CMASK) != '\n'){
--- 79,81 -----
+ #ifndef FAST
if((i & CMASK) != '\n'){
***************
*** 78,79
}
if(olinep == oline){
--- 84,86 -----
}
+ #endif FAST
if(olinep == oline){
***************
*** 150,152
ptout0(i)
! int i;
{
--- 157,159 -----
ptout0(i)
! register int i;
{
RCS file: RCS/t6.c,v; Working file: t6.c
head: 1.2
locks:
access list:
symbolic names:
comment leader: " * "
total revisions: 2; selected revisions: 2
description:
t6.c from UCB
----------------------------
revision 1.2
date: 84/01/29 18:52:54; author: bin; state: Exp; lines added/del: 6/3
Installed CS hacks
----------------------------
revision 1.1
date: 84/01/29 18:52:41; author: bin; state: Exp;
Initial revision
=============================================================================
RCS file: RCS/t6.c,v
retrieving revision 1.1
diff -b -c1 -r1.1 t6.c
*** /tmp/,RCSt1025790 Fri Feb 3 20:47:52 1984
--- t6.c Sun Jan 29 18:53:03 1984
***************
*** 50,53
extern int lg;
! char fontfile[] = "/usr/lib/font/ftXX";
! int ffi = 16;
extern int bd;
--- 50,53 -----
extern int lg;
! char *fontfile = "/usr/lib/font/ftXX";
! int ffi;
extern int bd;
***************
*** 111,113
getcw(i)
! int i;
{
--- 111,113 -----
getcw(i)
! register i;
{
***************
*** 507,508
if(skip() || !(j = getrq())){prstr("fp: no font name\n"); return;}
fontfile[ffi] = j & BMASK;
--- 507,511 -----
if(skip() || !(j = getrq())){prstr("fp: no font name\n"); return;}
+ if (ffi == 0)
+ while (fontfile[ffi] != 'X')
+ ffi++;
fontfile[ffi] = j & BMASK;
RCS file: RCS/tdef.h,v; Working file: tdef.h
head: 1.2
locks:
access list:
symbolic names:
comment leader: " * "
total revisions: 2; selected revisions: 2
description:
tdef.h from UCB
----------------------------
revision 1.2
date: 84/01/29 19:06:09; author: bin; state: Exp; lines added/del: 54/10
Installed CS version, including speed hacks
----------------------------
revision 1.1
date: 84/01/29 18:56:21; author: bin; state: Exp;
Initial revision
=============================================================================
RCS file: RCS/tdef.h,v
retrieving revision 1.1
diff -b -c1 -r1.1 tdef.h
*** /tmp/,RCSt1025797 Fri Feb 3 20:48:03 1984
--- tdef.h Sun Jan 29 19:06:45 1984
***************
*** 1,5
! #include <pagsiz.h>
! #define BUFSIZ BSIZE
! #undef BMASK
! #define MAXPTR 0x7fffffff /* max value of any pointer variable */
#ifdef NROFF /*NROFF*/
--- 1,2 -----
! #define MAXPTR (char *)0x7fffffff /* max value of any pointer variable */
#ifdef NROFF /*NROFF*/
***************
*** 13,15
#define UNPAD 0227
! #define PO 0 /*page offset*/
#define ASCII 1
--- 10,12 -----
#define UNPAD 0227
! #define PO INCH /*page offset*/
#define ASCII 1
***************
*** 46,49
#define VS INCH/6 /*vert space; 12points*/
! /* #define NN 132 /*number registers*/
! #define NN 528
#define NNAMES 14 /*predefined reg names*/
--- 43,50 -----
#define VS INCH/6 /*vert space; 12points*/
! #ifdef VMUNIX
! #define NN 528 /*number registers*/
! #else
! #define NN 132 /*number registers*/
! #endif
! /* #define NN 200 */
#define NNAMES 14 /*predefined reg names*/
***************
*** 54,56
#define EVLSZ 10 /*size of ev stack*/
- #define EVS 3*256 /*environment size in words*/
/* #define EVS 4*256 */
--- 55,56 -----
#define EVLSZ 10 /*size of ev stack*/
/* #define EVS 4*256 */
***************
*** 56,57
/* #define EVS 4*256 */
#define NM 300 /*requests + macros*/
--- 56,61 -----
/* #define EVS 4*256 */
+ #ifdef VMUNIX
+ #define NM 600
+ #define EVS 6*256 /*environment size in words*/
+ #else
#define NM 300 /*requests + macros*/
***************
*** 57,58
#define NM 300 /*requests + macros*/
#define DELTA 512 /*delta core bytes*/
--- 61,64 -----
#define NM 300 /*requests + macros*/
+ #define EVS 3*256 /*environment size in words*/
+ #endif
#define DELTA 512 /*delta core bytes*/
***************
*** 62,63
#define NSO 5 /*"so" depth*/
#define WDSIZE 170 /*word buffer size*/
--- 68,73 -----
#define NSO 5 /*"so" depth*/
+ #ifdef VMUNIX
+ #define WDSIZE 340 /*word buffer size*/
+ #define LNSIZE 960 /*line buffer size*/
+ #else
#define WDSIZE 170 /*word buffer size*/
***************
*** 64,65
#define LNSIZE 480 /*line buffer size*/
/* #define LNSIZE 680 */
--- 74,76 -----
#define LNSIZE 480 /*line buffer size*/
+ #endif
/* #define LNSIZE 680 */
***************
*** 95,96
#define NPP 10 /*pads per field*/
#define FBUFSZ 256 /*field buf size words*/
--- 106,112 -----
#define NPP 10 /*pads per field*/
+ #ifdef VMUNIX
+ #define FBUFSZ 1024
+ #define OBUFSZ 1024 /*bytes*/
+ #define IBUFSZ 1024 /*bytes*/
+ #else
#define FBUFSZ 256 /*field buf size words*/
***************
*** 96,99
#define FBUFSZ 256 /*field buf size words*/
! #define OBUFSZ BUFSIZ /*bytes*/
! #define IBUFSZ BUFSIZ /*bytes*/
#define NC 256 /*cbuf size words*/
--- 112,116 -----
#define FBUFSZ 256 /*field buf size words*/
! #define OBUFSZ 512 /*bytes*/
! #define IBUFSZ 512 /*bytes*/
! #endif
#define NC 256 /*cbuf size words*/
***************
*** 126
--- 143,170 -----
+ /* NOTE: THIS WON'T WORK UNDER NON-VMUNIX!! */
+ /* Troff spends about 20% of its time in getch() and getch0(); this
+ is an attempt to speed that up. */
+ /* Copyright (c) 1983 University of Maryland and all that stuff....
+ Maybe I should start putting *my* name in these things. -ACT */
+ #ifdef FAST
+ int _ch_, ch, nlflg, ch0, nchar, rchar, app;
+ int *rbuf, Buf[NBLIST*BLK + NEV*EVS], *olinep;
+ filep roff;
+
+ #define getch() (ch?((((_ch_=ch)&CMASK)=='\n'?nlflg++:0),ch=0,_ch_):\
+ nlflg?'\n':_getch_())
+ #define getch0() (ch0?(_ch_=ch0,ch0=0,_ch_):nchar?(--nchar,rchar):_getch0_())
+ #define rbf0(p) (((p)&~(BLK-1))==roff?rbuf[(p)&(BLK-1)]:\
+ (roff=(p)&(~(BLK-1)),rbuf= &Buf[roff],rbuf[p&(BLK-1)]))
+ #define rbf() (((_ch_=rbf0(ip))==0?(app?0:(_ch_=popi()))\
+ :(ip=incoff(ip))),_ch_)
+ #define wbt(i) (wbf(i),wbfl())
+
+ #ifdef NROFF
+ int oline[LNSIZE+1];
+
+ #define ptout(i) ((olinep>= &oline[LNSIZE]?0:(*olinep++=(i))),\
+ ((i)&CMASK)=='\n'?_ptout_(i):0)
+ #else (TROFF)
+ #define ptout(i) (((i)&CMASK)!='\n'?*olinep++=(i):_ptout_())
+ #endif NROFF
+
+ #endif FAST
--
In-Real-Life: Chris Torek, Univ of MD Comp Sci
UUCP: {seismo,allegra,brl-bmd}!umcp-cs!chris
CSNet: chris at umcp-cs ARPA: chris.umcp-cs at CSNet-Relay
More information about the Comp.sources.unix
mailing list