2 Copyright (c) 1993 Richard V. Nash.
3 Copyright (c) 2000 Dan Papasian
4 Copyright (C) Andrew Tridgell 2002
6 This program is free software; you can redistribute it and/or modify
7 it under the terms of the GNU General Public License as published by
8 the Free Software Foundation; either version 2 of the License, or
9 (at your option) any later version.
11 This program is distributed in the hope that it will be useful,
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 GNU General Public License for more details.
16 You should have received a copy of the GNU General Public License
17 along with this program; if not, write to the Free Software
18 Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
24 struct multicol *multicol_start(int maxArray)
29 m = (multicol *) malloc(sizeof(multicol));
30 m->arraySize = maxArray;
32 m->strArray = (char **) malloc(sizeof(char *) * m->arraySize);
33 for (i = 0; i < m->arraySize; i++)
34 m->strArray[i] = NULL;
38 int multicol_store(multicol * m, char *str)
40 if (m->num >= m->arraySize)
44 m->strArray[m->num] = strdup(str);
49 int multicol_store_sorted(multicol * m, char *str)
50 /* use this instead of multicol_store to print a list sorted */
54 if (m->num >= m->arraySize)
58 for (i = m->num; (i > 0) && (!found); i--) {
59 if (strcasecmp(str, m->strArray[i - 1]) >= 0) {
61 m->strArray[i] = strdup(str);
63 m->strArray[i] = m->strArray[i - 1];
67 m->strArray[0] = strdup(str);
72 int multicol_pprint(multicol * m, int player, int cols, int space)
83 pprintf(player, "\n");
84 for (i = 0; i < m->num; i++) {
85 tempptr = m->strArray[i];
86 temp = strlen(tempptr); /* loon: yes, this is pathetic */
87 for (; *tempptr; tempptr++) {
88 if (*tempptr == '\033')
95 numPerLine = cols / maxWidth;
97 numPerLine = 1; /* stop a division by 0 on large members */
98 numLines = m->num / numPerLine;
99 if (numLines * numPerLine < m->num)
104 for (i = 0; i < numPerLine; i++) {
105 theone = on + numLines * i;
106 if (theone >= m->num) {
109 tempptr = m->strArray[theone];
110 temp = strlen(tempptr); /* loon: yes, still pathetic */
111 for (; *tempptr; tempptr++) {
112 if (*tempptr == '\033')
115 len = maxWidth - temp;
116 if (i == numPerLine - 1)
118 pprintf(player, "%s", m->strArray[theone]);
120 pprintf(player, " ");
124 pprintf(player, "\n");
132 int multicol_end(multicol * m)
135 for (i = 0; i < m->num; i++)
136 FREE(m->strArray[i]);