1
2 /* $Id: shrink_width.cc,v 1.1 1997/03/31 23:12:33 dps Exp $ */
3 /* O(n^2) table width reduction algorithm, n is small in almost all cases */
shrink_widths(int ncols,struct rdata * cols,int mtw)4 static void shrink_widths(int ncols, struct rdata *cols, int mtw)
5 {
6 int i, j, tw, maxw;
7
8 for (tw=0, i=0; i<ncols; i++)
9 tw+=cols[i].w.width;
10
11 mtw-=ncols; // Take account of column seperators
12
13 /* Simply reduce the maximum width column width by one until
14 enougn has been trimed */
15 while (tw>mtw)
16 {
17 maxw=0; j=-1;
18 for (i=0; i<ncols; i++)
19 {
20 if (maxw<cols[i].w.width && cols[i].w.align!=ALIGN_DP)
21 {
22 j=i;
23 maxw=cols[i].w.width;
24 }
25 }
26
27 if (j==-1)
28 {
29 fprintf(stderr, "Can not shrink overwidth table\n");
30 continue;
31 }
32 cols[j].w.width--;
33 tw--;
34 }
35 }
36