tu.c revision b55148877d473978f0b46d593fd6213fa526fcc5
823N/A/*
823N/A * Copyright 1990 Sun Microsystems, Inc. All rights reserved.
823N/A * Use is subject to license terms.
823N/A */
823N/A
823N/A/* Copyright (c) 1984, 1986, 1987, 1988, 1989 AT&T */
823N/A/* All Rights Reserved */
823N/A
823N/A/*
823N/A * Copyright (c) 1980 Regents of the University of California.
823N/A * All rights reserved. The Berkeley software License Agreement
823N/A * specifies the terms and conditions for redistribution.
823N/A */
823N/A
823N/A#pragma ident "%Z%%M% %I% %E% SMI"
823N/A
823N/A /* tu.c: draws horizontal lines */
823N/A# include "t..c"
823N/A
823N/Avoid drawline(int, int, int, int, int, int);
823N/A
823N/Avoid
823N/Amakeline(int i, int c, int lintype)
823N/A{
823N/Aint cr, type, shortl;
823N/Atype = thish(i,c);
823N/Aif (type==0) return;
823N/Acr=c;
823N/Ashortl = (table[i][c].col[0]=='\\');
823N/Aif (c>0 && !shortl && thish(i,c-1) == type)return;
823N/Aif (shortl==0)
823N/A for(cr=c; cr < ncol && (ctype(i,cr)=='s'||type==thish(i,cr)); cr++);
823N/Aelse
823N/A for(cr=c+1; cr<ncol && ctype(i,cr)=='s'; cr++);
823N/Adrawline(i, c, cr-1, lintype, 0, shortl);
823N/A}
823N/A
823N/Avoid
823N/Afullwide(int i, int lintype)
823N/A{
823N/Aint cr, cl;
823N/Aif (!pr1403)
823N/A fprintf(tabout, ".nr %d \\n(.v\n.vs \\n(.vu-\\n(.sp\n", SVS);
823N/Acr= 0;
823N/Awhile (cr<ncol)
823N/A {
823N/A cl=cr;
823N/A while (i>0 && vspand(prev(i),cl,1))
823N/A cl++;
823N/A for(cr=cl; cr<ncol; cr++)
823N/A if (i>0 && vspand(prev(i),cr,1))
823N/A break;
823N/A if (cl<ncol)
823N/A drawline(i,cl,(cr<ncol?cr-1:cr),lintype,1,0);
823N/A }
823N/Afprintf(tabout, "\n");
823N/Aif (!pr1403)
823N/A fprintf(tabout, ".vs \\n(%du\n", SVS);
823N/A}
823N/A
823N/Avoid
823N/Adrawline(int i, int cl, int cr, int lintype, int noheight, int shortl)
823N/A{
823N/A char *exhr, *exhl, *lnch;
823N/A int lcount, ln, linpos, oldpos, nodata;
823N/Alcount=0;
823N/Aexhr=exhl= "";
823N/Aswitch(lintype)
823N/A {
823N/A case '-': lcount=1;break;
823N/A case '=': lcount = pr1403? 1 : 2; break;
823N/A case SHORTLINE: lcount=1; break;
823N/A }
823N/Aif (lcount<=0) return;
823N/Anodata = cr-cl>=ncol || noheight || allh(i);
823N/A if (!nodata)
823N/A fprintf(tabout, "\\v'-.5m'");
823N/Afor(ln=oldpos=0; ln<lcount; ln++)
823N/A {
823N/A linpos = 2*ln - lcount +1;
823N/A if (linpos != oldpos)
823N/A fprintf(tabout, "\\v'%dp'", linpos-oldpos);
823N/A oldpos=linpos;
823N/A if (shortl==0)
823N/A {
823N/A tohcol(cl);
823N/A if (lcount>1)
823N/A {
823N/A switch(interv(i,cl))
823N/A {
823N/A case TOP: exhl = ln==0 ? "1p" : "-1p"; break;
823N/A case BOT: exhl = ln==1 ? "1p" : "-1p"; break;
823N/A case THRU: exhl = "1p"; break;
823N/A }
823N/A if (exhl[0])
823N/A fprintf(tabout, "\\h'%s'", exhl);
823N/A }
823N/A else if (lcount==1)
823N/A {
823N/A switch(interv(i,cl))
823N/A {
823N/A case TOP: case BOT: exhl = "-1p"; break;
823N/A case THRU: exhl = "1p"; break;
823N/A }
823N/A if (exhl[0])
823N/A fprintf(tabout, "\\h'%s'", exhl);
823N/A }
823N/A if (lcount>1)
823N/A {
823N/A switch(interv(i,cr+1))
823N/A {
823N/A case TOP: exhr = ln==0 ? "-1p" : "+1p"; break;
823N/A case BOT: exhr = ln==1 ? "-1p" : "+1p"; break;
823N/A case THRU: exhr = "-1p"; break;
823N/A }
823N/A }
823N/A else if (lcount==1)
823N/A {
823N/A switch(interv(i,cr+1))
823N/A {
823N/A case TOP: case BOT: exhr = "+1p"; break;
823N/A case THRU: exhr = "-1p"; break;
823N/A }
823N/A }
823N/A }
823N/A else
823N/A fprintf(tabout, "\\h'|\\n(%du'", cl+CLEFT);
823N/A fprintf(tabout, "\\s\\n(%d",LSIZE);
823N/A if (linsize)
823N/A fprintf(tabout, "\\v'-\\n(%dp/6u'", LSIZE);
823N/A if (shortl)
823N/A fprintf(tabout, "\\l'|\\n(%du'", cr+CRIGHT);
823N/A else
823N/A {
823N/A lnch = "\\(ul";
823N/A if (pr1403)
823N/A lnch = lintype==2 ? "=" : "\\(ru";
823N/A if (cr+1>=ncol)
823N/A fprintf(tabout, "\\l'|\\n(TWu%s%s'", exhr,lnch);
823N/A else
823N/A fprintf(tabout, "\\l'(|\\n(%du+|\\n(%du)/2u%s%s'", cr+CRIGHT,
823N/A cr+1+CLEFT, exhr, lnch);
823N/A }
823N/A if (linsize)
823N/A fprintf(tabout, "\\v'\\n(%dp/6u'", LSIZE);
823N/A fprintf(tabout, "\\s0");
823N/A }
823N/Aif (oldpos!=0)
823N/A fprintf(tabout, "\\v'%dp'", -oldpos);
823N/Aif (!nodata)
823N/A fprintf(tabout, "\\v'+.5m'");
823N/A}
823N/A
823N/Avoid
823N/Agetstop(void)
823N/A{
823N/Aint i,c,k,junk, stopp;
823N/Astopp=1;
823N/Afor(i=0; i<MAXLIN; i++)
823N/A linestop[i]=0;
823N/Afor(i=0; i<nlin; i++)
823N/A for(c=0; c<ncol; c++)
823N/A {
823N/A k = left(i,c,&junk);
823N/A if (k>=0 && linestop[k]==0)
823N/A linestop[k]= ++stopp;
823N/A }
823N/Aif (boxflg || allflg || dboxflg)
823N/A linestop[0]=1;
823N/A}
823N/A
823N/Aint
823N/Aleft(int i, int c, int *lwidp)
823N/A{
823N/Aint kind, li, lj;
823N/A /* returns -1 if no line to left */
823N/A /* returns number of line where it starts */
823N/A /* stores into lwid the kind of line */
823N/A*lwidp=0;
823N/Akind = lefdata(i,c);
823N/Aif (kind==0) return(-1);
823N/Aif (i+1<nlin)
823N/Aif (lefdata(next(i),c)== kind) return(-1);
823N/Awhile (i>=0 && lefdata(i,c)==kind)
823N/A i=prev(li=i);
823N/Aif (prev(li)== -1) li=0;
823N/A*lwidp=kind;
823N/Afor(lj= i+1; lj<li; lj++)
823N/A if (instead[lj] && strcmp(instead[lj], ".TH")==0)
823N/A return(li);
823N/Afor(i= i+1; i<li; i++)
823N/A if (fullbot[i])
823N/A li=i;
823N/Areturn(li);
823N/A}
823N/A
823N/Aint
823N/Alefdata(int i, int c)
823N/A{
823N/Aint ck;
823N/Aif (i>=nlin) i=nlin-1;
823N/Aif (ctype(i,c) == 's')
823N/A {
823N/A for(ck=c; ctype(i,ck)=='s'; ck--);
823N/A if (thish(i,ck)==0)
823N/A return(0);
823N/A }
823N/Ai =stynum[i];
823N/Ai = lefline[i][c];
823N/Aif (i>0) return(i);
823N/Aif (dboxflg && c==0) return(2);
823N/Aif (allflg)return(1);
823N/Aif (boxflg && c==0) return(1);
823N/Areturn(0);
823N/A}
823N/A
823N/Aint
823N/Anext(int i)
823N/A{
823N/Awhile (i+1 <nlin)
823N/A {
823N/A i++;
823N/A if (!fullbot[i] && !instead[i]) break;
823N/A }
823N/Areturn(i);
823N/A}
823N/A
823N/Aint
823N/Aprev(int i)
823N/A{
823N/Awhile (--i >=0 && (fullbot[i] || instead[i]))
823N/A ;
823N/Areturn(i);
823N/A}
823N/A