t6.c revision b55148877d473978f0b46d593fd6213fa526fcc5
1457c899Thomas Gleixner/*
25274f05Jens Axboe * Copyright 1990 Sun Microsystems, Inc.  All rights reserved.
35274f05Jens Axboe * Use is subject to license terms.
45274f05Jens Axboe */
55274f05Jens Axboe
65274f05Jens Axboe/*	Copyright (c) 1984, 1986, 1987, 1988, 1989 AT&T	*/
75274f05Jens Axboe/*	  All Rights Reserved  	*/
85274f05Jens Axboe
95274f05Jens Axboe
105274f05Jens Axboe/*
115274f05Jens Axboe * Copyright (c) 1980 Regents of the University of California.
125274f05Jens Axboe * All rights reserved. The Berkeley software License Agreement
13c2058e0Jens Axboe * specifies the terms and conditions for redistribution.
14c2058e0Jens Axboe */
155274f05Jens Axboe
160fe2347Jens Axboe#pragma ident	"%Z%%M%	%I%	%E% SMI"
17c2058e0Jens Axboe
18c2058e0Jens Axboe /* t6.c: compute tab stops */
195274f05Jens Axboe# define tx(a) (a>(char *)0 && a<(char *)128)
205274f05Jens Axboe# include "t..c"
21be29796Christoph Hellwig
225274f05Jens Axboevoid	wide(char *, char *, char *);
235274f05Jens Axboe
245274f05Jens Axboevoid
25d6b29d7Jens Axboemaktab(void)
2608e552cKAMEZAWA Hiroyuki{
275274f05Jens Axboe# define FN(i,c) font[stynum[i]][c]
285abc97aJens Axboe# define SZ(i,c) csize[stynum[i]][c]
294f6f0bdJens Axboe/* define the tab stops of the table */
30630d9c4Paul Gortmakerint icol, ilin, tsep, k, ik, vforml, il, text;
314f6f0bdJens Axboeint doubled[MAXCOL], acase[MAXCOL];
32912d35fJens Axboechar *s;
3329ce205James Morrisfor(icol=0; icol <ncol; icol++)
345a0e3adTejun Heo	{
3535f9c09Eric Dumazet	doubled[icol] = acase[icol] = 0;
3676b021dAl Viro	fprintf(tabout, ".nr %d 0\n", icol+CRIGHT);
37174cd4bIngo Molnar   for(text=0; text<2; text++)
38174cd4bIngo Molnar	{
3906ae43fAl Viro	if (text)
405274f05Jens Axboe		fprintf(tabout, ".%02d\n.rm %02d\n", icol+80, icol+80);
4183f9135Jens Axboe	for(ilin=0; ilin<nlin; ilin++)
4283f9135Jens Axboe		{
4383f9135Jens Axboe		if (instead[ilin]|| fullbot[ilin]) continue;
4483f9135Jens Axboe		vforml=ilin;
4583f9135Jens Axboe		for(il=prev(ilin); il>=0 && vspen(table[il][icol].col); il=prev(il))
4683f9135Jens Axboe			vforml=il;
4776ad4d1Jens Axboe		if (fspan(vforml,icol)) continue;
485abc97aJens Axboe		if (filler(table[ilin][icol].col)) continue;
495abc97aJens Axboe		switch(ctype(vforml,icol))
505abc97aJens Axboe			{
519e94cd4Jens Axboe			case 'a':
525abc97aJens Axboe				acase[icol]=1;
539e0267cJens Axboe				s = table[ilin][icol].col;
549e0267cJens Axboe				if (s>(char *)0 && s<(char *)128 && text)
559e94cd4Jens Axboe					{
569e94cd4Jens Axboe					if (doubled[icol]==0)
579e94cd4Jens Axboe						fprintf(tabout, ".nr %d 0\n.nr %d 0\n",S1,S2);
585abc97aJens Axboe					doubled[icol]=1;
599e94cd4Jens Axboe					fprintf(tabout, ".if \\n(%c->\\n(%d .nr %d \\n(%c-\n",s,S2,S2,s);
609e94cd4Jens Axboe					}
619e94cd4Jens Axboe			case 'n':
629e94cd4Jens Axboe				if (table[ilin][icol].rcol!=0)
639e94cd4Jens Axboe					{
649e94cd4Jens Axboe					if (doubled[icol]==0 && text==0)
659e94cd4Jens Axboe						fprintf(tabout, ".nr %d 0\n.nr %d 0\n", S1, S2);
669e94cd4Jens Axboe					doubled[icol]=1;
679e94cd4Jens Axboe					if (real(s=table[ilin][icol].col) && !vspen(s))
68ad8d6f0Jens Axboe						{
69266cf65David Howells						if (tx(s) != text) continue;
70266cf65David Howells						fprintf(tabout, ".nr %d ", TMP);
71ca39d65Jens Axboe						wide(s, FN(vforml,icol), SZ(vforml,icol)); fprintf(tabout, "\n");
724f6f0bdJens Axboe						fprintf(tabout, ".if \\n(%d<\\n(%d .nr %d \\n(%d\n", S1, TMP, S1, TMP);
739e94cd4Jens Axboe						}
749e94cd4Jens Axboe					if (text==0 && real(s=table[ilin][icol].rcol) && !vspen(s) && !barent(s))
759e94cd4Jens Axboe						{
769e94cd4Jens Axboe						fprintf(tabout, ".nr %d \\w%c%s%c\n",TMP, F1, s, F1);
779e94cd4Jens Axboe						fprintf(tabout, ".if \\n(%d<\\n(%d .nr %d \\n(%d\n",S2,TMP,S2,TMP);
789e94cd4Jens Axboe						}
799e94cd4Jens Axboe					continue;
809e94cd4Jens Axboe					}
819e0267cJens Axboe			case 'r':
825abc97aJens Axboe			case 'c':
839e94cd4Jens Axboe			case 'l':
849e94cd4Jens Axboe				if (real(s=table[ilin][icol].col) && !vspen(s))
859e94cd4Jens Axboe					{
869e94cd4Jens Axboe					if (tx(s) != text) continue;
87ca39d65Jens Axboe					fprintf(tabout, ".nr %d ", TMP);
889e94cd4Jens Axboe					wide(s, FN(vforml,icol), SZ(vforml,icol)); fprintf(tabout, "\n");
899e94cd4Jens Axboe					fprintf(tabout, ".if \\n(%d<\\n(%d .nr %d \\n(%d\n", icol+CRIGHT, TMP, icol+CRIGHT, TMP);
905abc97aJens Axboe					}
915abc97aJens Axboe			}
9276ad4d1Jens Axboe		}
935274f05Jens Axboe		}
945274f05Jens Axboe	if (acase[icol])
9509cbfeaKirill A. Shutemov		{
961432873Jens Axboe		fprintf(tabout, ".if \\n(%d>=\\n(%d .nr %d \\n(%du+2n\n",S2,icol+CRIGHT,icol+CRIGHT,S2);
975274f05Jens Axboe		}
985274f05Jens Axboe	if (doubled[icol])
990845718Jens Axboe		{
1000845718Jens Axboe		fprintf(tabout, ".nr %d \\n(%d\n", icol+CMID, S1);
1010845718Jens Axboe		fprintf(tabout, ".nr %d \\n(%d+\\n(%d\n",TMP,icol+CMID,S2);
1020845718Jens Axboe		fprintf(tabout, ".if \\n(%d>\\n(%d .nr %d \\n(%d\n",TMP,icol+CRIGHT,icol+CRIGHT,TMP);
103cac36bbJens Axboe		fprintf(tabout, ".if \\n(%d<\\n(%d .nr %d +(\\n(%d-\\n(%d)/2\n",TMP,icol+CRIGHT,icol+CMID,icol+CRIGHT,TMP);
104cac36bbJens Axboe		}
1055274f05Jens Axboe	if (cll[icol][0])
1065274f05Jens Axboe		{
10749d0b21Jens Axboe		fprintf(tabout, ".nr %d %sn\n", TMP, cll[icol]);
1085274f05Jens Axboe		fprintf(tabout, ".if \\n(%d<\\n(%d .nr %d \\n(%d\n",icol+CRIGHT, TMP, icol+CRIGHT, TMP);
1095274f05Jens Axboe		}
11049d0b21Jens Axboe	for(ilin=0; ilin<nlin; ilin++)
11149d0b21Jens Axboe	if (k=lspan(ilin, icol))
11249d0b21Jens Axboe		{
11349d0b21Jens Axboe		s=table[ilin][icol-k].col;
11473d62d8Ingo Molnar		if (!real(s) || barent(s) || vspen(s) ) continue;
11549d0b21Jens Axboe		fprintf(tabout, ".nr %d ", TMP);
11649d0b21Jens Axboe		wide(table[ilin][icol-k].col, FN(ilin,icol-k), SZ(ilin,icol-k));
11749d0b21Jens Axboe		for(ik=k; ik>=0; ik--)
11849d0b21Jens Axboe			{
11949d0b21Jens Axboe			fprintf(tabout, "-\\n(%d",CRIGHT+icol-ik);
1205274f05Jens Axboe			if (!expflg && ik>0) fprintf(tabout, "-%dn", sep[icol-ik]);
12149d0b21Jens Axboe			}
12273d62d8Ingo Molnar		fprintf(tabout, "\n");
12349d0b21Jens Axboe		fprintf(tabout, ".if \\n(%d>0 .nr %d \\n(%d/%d\n", TMP, TMP, TMP, k);
12449d0b21Jens Axboe		fprintf(tabout, ".if \\n(%d<0 .nr %d 0\n", TMP, TMP);
12549d0b21Jens Axboe		for(ik=0; ik<k; ik++)
12649d0b21Jens Axboe			{
12749d0b21Jens Axboe			if (doubled[icol-k+ik])
12849d0b21Jens Axboe				fprintf(tabout, ".nr %d +\\n(%d/2\n", icol-k+ik+CMID, TMP);
12949d0b21Jens Axboe			fprintf(tabout, ".nr %d +\\n(%d\n", icol-k+ik+CRIGHT, TMP);
130f84d751Jens Axboe			}
13149d0b21Jens Axboe		}
1325274f05Jens Axboe	}
1335274f05Jens Axboeif (textflg) untext();
1345274f05Jens Axboe/* if even requested, make all columns widest width */
135f84d751Jens Axboe# define TMP1 S1
13649d0b21Jens Axboe# define TMP2 S2
13749d0b21Jens Axboeif (evenflg)
138f84d751Jens Axboe	{
1397052449Jens Axboe	fprintf(tabout, ".nr %d 0\n", TMP);
1407052449Jens Axboe	for(icol=0; icol<ncol; icol++)
141708e350Hugh Dickins		{
142cac36bbJens Axboe		if (evenup[icol]==0) continue;
1435274f05Jens Axboe		fprintf(tabout, ".if \\n(%d>\\n(%d .nr %d \\n(%d\n",
1445abc97aJens Axboe		icol+CRIGHT, TMP, TMP, icol+CRIGHT);
145f84d751Jens Axboe		}
1465274f05Jens Axboe	for(icol=0; icol<ncol; icol++)
1475274f05Jens Axboe		{
148912d35fJens Axboe		if (evenup[icol]==0)
149912d35fJens Axboe			/* if column not evened just retain old interval */
150912d35fJens Axboe			continue;
1517afa6fdJens Axboe		if (doubled[icol])
1527afa6fdJens Axboe			fprintf(tabout, ".nr %d (100*\\n(%d/\\n(%d)*\\n(%d/100\n",
1537afa6fdJens Axboe				icol+CMID, icol+CMID, icol+CRIGHT, TMP);
1541432873Jens Axboe				/* that nonsense with the 100's and parens tries
155330ab71Jens Axboe				   to avoid overflow while proportionally shifting
156912d35fJens Axboe				   the middle of the number */
157912d35fJens Axboe		fprintf(tabout, ".nr %d \\n(%d\n", icol+CRIGHT, TMP);
158d4c3ccaEric Dumazet		}
159cac36bbJens Axboe	}
160912d35fJens Axboe/* now adjust for total table width */
161912d35fJens Axboefor(tsep=icol=0; icol<ncol; icol++)
162f84d751Jens Axboe	tsep+= sep[icol];
163912d35fJens Axboeif (expflg)
164912d35fJens Axboe	{
165825cdcbNamhyung Kim	fprintf(tabout, ".nr %d 0", TMP);
166825cdcbNamhyung Kim	for(icol=0; icol<ncol; icol++)
167825cdcbNamhyung Kim		fprintf(tabout, "+\\n(%d", icol+CRIGHT);
168825cdcbNamhyung Kim	fprintf(tabout, "\n");
169825cdcbNamhyung Kim	fprintf(tabout, ".nr %d \\n(.l-\\n(.i-\\n(%d\n", TMP, TMP);
170825cdcbNamhyung Kim	if (boxflg || dboxflg || allflg)
171825cdcbNamhyung Kim		tsep += 1;
172825cdcbNamhyung Kim	else
173932cc6dJens Axboe		tsep -= sep[ncol-1];
174932cc6dJens Axboe	fprintf(tabout, ".nr %d \\n(%d/%d\n", TMP, TMP,  tsep);
175932cc6dJens Axboe	fprintf(tabout, ".if \\n(%d<1n .nr %d 1n\n", TMP, TMP);
176932cc6dJens Axboe	}
177932cc6dJens Axboeelse
178932cc6dJens Axboe	fprintf(tabout, ".nr %d 1n\n", TMP);
17979685b8Randy Dunlapfprintf(tabout, ".nr %d 0\n",CRIGHT-1);
180932cc6dJens Axboetsep= (boxflg || allflg || dboxflg || left1flg) ? 1 : 0;
181932cc6dJens Axboefor(icol=0; icol<ncol; icol++)
182932cc6dJens Axboe	{
18383f9135Jens Axboe	fprintf(tabout, ".nr %d \\n(%d+(%d*\\n(%d)\n",icol+CLEFT, icol+CRIGHT-1, tsep, TMP);
184d6b29d7Jens Axboe	fprintf(tabout, ".nr %d +\\n(%d\n",icol+CRIGHT, icol+CLEFT);
185d6b29d7Jens Axboe	if (doubled[icol])
1865274f05Jens Axboe		{
18700de00bJens Axboe		/* the next line is last-ditch effort to avoid zero field width */
1888cefc10David Howells		/*fprintf(tabout, ".if \\n(%d=0 .nr %d 1\n",icol+CMID, icol+CMID);*/
1898cefc10David Howells		fprintf(tabout, ".nr %d +\\n(%d\n", icol+CMID, icol+CLEFT);
1908cefc10David Howells	/*  fprintf(tabout, ".if n .if \\n(%d%%24>0 .nr %d +12u\n",icol+CMID, icol+CMID); */
1918924fefAl Viro		}
1925274f05Jens Axboe	tsep=sep[icol];
193d6785d9Rabin Vincent	}
194d6785d9Rabin Vincentif (rightl)
195d6785d9Rabin Vincent	fprintf(tabout, ".nr %d (\\n(%d+\\n(%d)/2\n",ncol+CRIGHT-1, ncol+CLEFT-1, ncol+CRIGHT-2);
1968924fefAl Virofprintf(tabout, ".nr TW \\n(%d\n", ncol+CRIGHT-1);
1978924fefAl Viroif (boxflg || allflg || dboxflg)
1988924fefAl Viro	fprintf(tabout, ".nr TW +%d*\\n(%d\n", sep[ncol-1], TMP);
1998924fefAl Virofprintf(tabout,
2008924fefAl Viro ".if t .if \\n(TW>\\n(.li .tm Table at line %d file %s is too wide - \\n(TW units\n", iline-1, ifile);
2015274f05Jens Axboereturn;
2026718b6fDavid Howells}
2038cefc10David Howells
2045274f05Jens Axboevoid
2058924fefAl Virowide(char *s, char *fn, char *size)
2068924fefAl Viro{
2078924fefAl Viroif (point(s))
2088924fefAl Viro	{
2098924fefAl Viro	fprintf(tabout, "\\w%c", F1);
2105a81e6aMiklos Szeredi	if (*fn>0) putfont(fn);
2115274f05Jens Axboe	if (*size) putsize(size);
2128cefc10David Howells	fprintf(tabout, "%s", s);
2138cefc10David Howells	if (*fn>0) putfont("P");
2148924fefAl Viro	if (*size) putsize("0");
2158924fefAl Viro	fprintf(tabout, "%c",F1);
21629e3509Linus Torvalds	}
2178924fefAl Viroelse
2185274f05Jens Axboe	fprintf(tabout, "\\n(%c-", s);
2195274f05Jens Axboe}
2205274f05Jens Axboe
2218924fefAl Viroint
2228924fefAl Virofiller(char *s)
2235274f05Jens Axboe{
2248924fefAl Viroreturn (point(s) && s[0]=='\\' && s[1] == 'R');
22500de00bJens Axboe}
226bbdfc2fJens Axboe