-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathdisplay.cc
More file actions
169 lines (130 loc) · 3.47 KB
/
display.cc
File metadata and controls
169 lines (130 loc) · 3.47 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
#include <ctype.h>
#include <sys/types.h>
#include <stdio.h>
#include <syslog.h>
#include "define.h"
#include "struct.h"
/*
* TITLE FUNCTIONS
*/
void send_title( char_data* ch, const char* text )
{
char tmp1 [ FOUR_LINES ];
char tmp2 [ FOUR_LINES ];
char* letter;
int length = strlen( text );
if( !ch->link )
return;
const int width = /*ch->pcdata ? ch->pcdata->columns :*/ 80;
if( length > width ) {
roach( "Send_Title: Length of text > screen width (%d).", width );
roach( "-- Char = %s", ch );
roach( "-- Text = %s", text );
return;
}
snprintf( tmp2, FOUR_LINES, "%*s", (width-length)/2, "" );
snprintf( tmp1, FOUR_LINES, "%s", text );
*tmp1 = toupper( *tmp1 );
for( letter = tmp1; *letter; )
if( *letter++ == ' ' )
*letter = toupper( *letter );
send( ch, tmp2 );
send_color( ch, COLOR_TITLES, tmp1 );
send( ch, "\n\r" );
for( letter = tmp1; *letter; ++letter )
if( *letter != ' ' )
*letter = '-';
send( ch, tmp2 );
send_color( ch, COLOR_TITLES, tmp1 );
send( ch, "\n\r" );
}
void page_title( char_data* ch, const char* text )
{
char tmp1 [ FOUR_LINES ];
char tmp2 [ FOUR_LINES ];
char* letter;
int length = strlen( text );
if( !ch->link )
return;
const int width = /*ch->pcdata ? ch->pcdata->columns :*/ 80;
if( length > width ) {
roach( "Page_Title: Length of text > screen width (%d).", width );
roach( "-- Char = %s", ch );
roach( "-- Text = %s", text );
return;
}
snprintf( tmp2, FOUR_LINES, "%*s", (width-length)/2, "" );
snprintf( tmp1, FOUR_LINES, "%s", text );
*tmp1 = toupper( *tmp1 );
for( letter = tmp1; *letter; )
if( *letter++ == ' ' )
*letter = toupper( *letter );
page( ch, tmp2 );
page_color( ch, COLOR_TITLES, tmp1 );
page( ch, "\n\r" );
for( letter = tmp1; *letter; ++letter )
if( *letter != ' ' )
*letter = '-';
page( ch, tmp2 );
page_color( ch, COLOR_TITLES, tmp1 );
page( ch, "\n\r" );
}
void display_array( char_data *ch, const char *title,
const char *const *entry1,
const char *const *entry2,
int max, bool sort, bool (*func)(const char_data*, int) )
{
if( !ch->pcdata )
return;
const unsigned columns = ch->pcdata->columns / 19;
if( max < 0 ) {
// Count entries.
for( max = 0; **(entry1+max*(entry2-entry1)); ++max );
if( max == 0 )
return;
}
int sorted[ max ];
max = sort_names( entry1, entry2, sorted, max, sort );
// char tmp [ TWO_LINES ];
if( title && *title ) {
if( *title == '+' ) {
page_title( ch, title+1 );
} else {
// snprintf( tmp, TWO_LINES, "%s:\n\r", title );
page( ch, "%s:\n\r", title );
}
}
int j = 0;
for( int i = 0; i < max; ++i ) {
if( !func || func( ch, sorted[i] ) ) {
char **string = (char**) (int)( entry1+sorted[i]*(entry2-entry1) );
/*
snprintf( tmp, TWO_LINES, "%19s%s",
*string,
j%columns == columns-1 ? "\n\r" : "" );
*/
page( ch, "%19s%s",
*string,
j%columns == columns-1 ? "\n\r" : "" );
++j;
}
}
if( j%columns != 0 )
page( ch, "\n\r" );
}
/*
* WORD LIST
*/
const char* word_list( const char** list, int max, bool use_and )
{
if( max == 0 )
return empty_string;
char *tmp = static_string( list[0] );
if( max > 1 ) {
for( int i = 1; i < max; i++ ) {
sprintf( tmp+strlen( tmp ), ", %s%s",
use_and && i+1 == max ? "and " : "", list[i] );
}
}
return tmp;
}