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
|
/* $Id$ */
#include "bbs.h"
// TODO move stuff to libbbs(or util)/string.c, ...
// this file can be removed (or not?)
char *
Ptt_prints(char *str, size_t size, int mode)
{
char *strbuf = alloca(size);
int r, w;
for( r = w = 0 ; str[r] != 0 && w < (size - 1) ; ++r )
if( str[r] != ESC_CHR )
strbuf[w++] = str[r];
else{
if( str[++r] != '*' ){
if(w+2>=size-1) break;
strbuf[w++] = ESC_CHR;
strbuf[w++] = str[r];
}
else{
/* Note, w will increased by copied length after */
switch( str[++r] ){
// secure content
case 't': // current time
strlcpy(strbuf+w, Cdate(&now), size-w);
w += strlen(strbuf+w);
break;
case 'u': // current online users
w += snprintf(&strbuf[w], size - w,
"%d", SHM->UTMPnumber);
break;
// insecure content
case 's': // current user id
strlcpy(strbuf+w, cuser.userid, size-w);
w += strlen(strbuf+w);
break;
case 'n': // current user nickname
strlcpy(strbuf+w, cuser.nickname, size-w);
w += strlen(strbuf+w);
break;
case 'l': // current user logins
w += snprintf(&strbuf[w], size - w,
"%d", cuser.numlogins);
break;
case 'p': // current user posts
w += snprintf(&strbuf[w], size - w,
"%d", cuser.numposts);
break;
/* It's saver not to send these undefined escape string.
default:
strbuf[w++] = ESC_CHR;
strbuf[w++] = '*';
strbuf[w++] = str[r];
*/
}
}
}
strbuf[w] = 0;
strip_ansi(str, strbuf, mode);
return str;
}
// utility from screen.c
void
outs_n(const char *str, int n)
{
while (*str && n--) {
outc(*str++);
}
}
// XXX left-right (for large term)
// TODO someday please add ANSI detection version
void
outslr(const char *left, int leftlen, const char *right, int rightlen)
{
if (left == NULL)
left = "";
if (right == NULL)
right = "";
if(*left && leftlen < 0)
leftlen = strlen(left);
if(*right && rightlen < 0)
rightlen = strlen(right);
// now calculate padding
rightlen = t_columns - leftlen - rightlen;
outs(left);
// ignore right msg if we need to.
if(rightlen >= 0)
{
while(--rightlen > 0)
outc(' ');
outs(right);
} else {
rightlen = t_columns - leftlen;
while(--rightlen > 0)
outc(' ');
}
}
/* Jaky */
void
out_lines(const char *str, int line)
{
int y, x;
getyx(&y, &x);
while (*str && line) {
if (*str == '\n')
{
move(++y, 0);
line--;
} else
{
outc(*str);
}
str++;
}
}
void
outmsg(const char *msg)
{
move(b_lines - msg_occupied, 0);
clrtoeol();
outs(msg);
}
void
outmsglr(const char *msg, int llen, const char *rmsg, int rlen)
{
move(b_lines - msg_occupied, 0);
clrtoeol();
outslr(msg, llen, rmsg, rlen);
outs(ANSI_RESET ANSI_CLRTOEND);
}
void
prints(const char *fmt,...)
{
va_list args;
char buff[1024];
va_start(args, fmt);
vsnprintf(buff, sizeof(buff), fmt, args);
va_end(args);
outs(buff);
}
void
mouts(int y, int x, const char *str)
{
move(y, x);
clrtoeol();
outs(str);
}
// vim:ts=4
|