1 /* $OpenBSD: prtable.c,v 1.11 2008/08/04 18:42:09 millert Exp $ */
2 /* $NetBSD: prtable.c,v 1.2 1995/03/21 12:14:42 cgd Exp $ */
6 * The Regents of the University of California. All rights reserved.
8 * This code is derived from software contributed to Berkeley by
11 * Redistribution and use in source and binary forms, with or without
12 * modification, are permitted provided that the following conditions
14 * 1. Redistributions of source code must retain the above copyright
15 * notice, this list of conditions and the following disclaimer.
16 * 2. Redistributions in binary form must reproduce the above copyright
17 * notice, this list of conditions and the following disclaimer in the
18 * documentation and/or other materials provided with the distribution.
19 * 3. Neither the name of the University nor the names of its contributors
20 * may be used to endorse or promote products derived from this software
21 * without specific prior written permission.
23 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
24 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
25 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
26 * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
27 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
28 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
29 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
30 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
31 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
32 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
35 * @(#)prtable.c 8.1 (Berkeley) 6/11/93
44 static int get_maxlen(char **, int, int (*)(char **, int));
47 * Routine to print a table
48 * Modified from 'ls.c' mods (BJB/83)
50 * base - address of first entry
51 * num - number of entries
52 * d_cols - number of columns to use if > 0, "best" size if == 0
53 * width - max line width if not zero
54 * prentry - address of the routine to call to print the string
55 * length - address of the routine to call to determine the length
56 * of string to be printed
58 * prtable and length are called with the address of the base and
62 prtable(char **base
, int num
, int d_cols
, int width
,
63 void (*prentry
)(char **, int), int (*length
)(char **, int))
66 int a
, b
, cols
, loc
, maxlen
, nrows
, z
;
67 int col __unused
, row
;
71 maxlen
= get_maxlen(base
, num
, length
) + 1;
75 cols
= width
/ maxlen
;
78 nrows
= (num
- 1) / cols
+ 1;
79 for (a
= 1; a
<= nrows
; a
++) {
81 for (j
= 0; j
< num
; j
++) {
88 loc
+= (*length
)(base
, j
);
91 for (j
++; j
< num
; j
++) {
97 while (loc
< z
* maxlen
) {
103 getyx(stdscr
, row
, col
);
105 if (row
+ 1 == lastline
&& a
!= nrows
) {
111 } while (j
!= ' ' && j
!= 'q' && j
!= 'Q');
112 if (j
== 'q' || j
== 'Q') {
117 move(LIST_LINE
, LIST_COL
);
125 get_maxlen(char **base
, int num
, int (*length
)(char **, int))
129 max
= (*length
)(base
, 0);
130 for (i
= 0; i
< num
; i
++) {
131 if ((len
= (*length
)(base
, i
)) > max
)