]>
git.cameronkatri.com Git - bsdgames-darwin.git/blob - boggle/boggle/prtable.c
1 /* $NetBSD: prtable.c,v 1.11 2021/05/02 12:50:43 rillig Exp $ */
5 * The Regents of the University of California. All rights reserved.
7 * This code is derived from software contributed to Berkeley by
10 * Redistribution and use in source and binary forms, with or without
11 * modification, are permitted provided that the following conditions
13 * 1. Redistributions of source code must retain the above copyright
14 * notice, this list of conditions and the following disclaimer.
15 * 2. Redistributions in binary form must reproduce the above copyright
16 * notice, this list of conditions and the following disclaimer in the
17 * documentation and/or other materials provided with the distribution.
18 * 3. Neither the name of the University nor the names of its contributors
19 * may be used to endorse or promote products derived from this software
20 * without specific prior written permission.
22 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
23 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
24 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
25 * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
26 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
27 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
28 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
29 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
30 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
31 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
34 * @(#)prtable.c 8.1 (Berkeley) 6/11/93
37 #include <sys/cdefs.h>
39 __RCSID("$NetBSD: prtable.c,v 1.11 2021/05/02 12:50:43 rillig Exp $");
43 #define __USE(a) (/*LINTED*/(void)(a))
49 static int get_maxlen(const char *const [], int, int (*)(const char *const *, int));
52 * Routine to print a table
53 * Modified from 'ls.c' mods (BJB/83)
55 * base - address of first entry
56 * num - number of entries
57 * d_cols - number of columns to use if > 0, "best" size if == 0
58 * width - max line width if not zero
59 * prentry - address of the routine to call to print the string
60 * length - address of the routine to call to determine the length
61 * of string to be printed
63 * prtable and length are called with the address of the base and
67 prtable(const char *const base
[], int num
, int d_cols
, int width
,
68 void (*prentry
)(const char *const [], int),
69 int (*length
)(const char *const [], int))
72 int a
, b
, cols
, loc
, maxlen
, nrows
, z
;
77 maxlen
= get_maxlen(base
, num
, length
) + 1;
81 cols
= width
/ maxlen
;
84 nrows
= (num
- 1) / cols
+ 1;
85 for (a
= 1; a
<= nrows
; a
++) {
87 for (j
= 0; j
< num
; j
++) {
94 loc
+= (*length
)(base
, j
);
97 for (j
++; j
< num
; j
++) {
103 while (loc
< z
* maxlen
) {
109 getyx(stdscr
, row
, col
);
117 get_maxlen(const char *const base
[], int num
,
118 int (*length
)(const char *const *, int))
122 max
= (*length
)(base
, 0);
123 for (i
= 0; i
< num
; i
++) {
124 if ((len
= (*length
)(base
, i
)) > max
)