| 117 |
|
|
| 118 |
static void process_bar(int n, int len) |
static void process_bar(int n, int len) |
| 119 |
{ |
{ |
| 120 |
char buf[256]; |
char buf[LINE_BUFFER_LEN]; |
| 121 |
char buf2[256]; |
char buf2[LINE_BUFFER_LEN]; |
| 122 |
char *ptr; |
|
| 123 |
char *ptr2; |
if (len > LINE_BUFFER_LEN) |
| 124 |
char *ptr3; |
{ |
| 125 |
|
len = LINE_BUFFER_LEN - 1; |
| 126 |
|
} |
| 127 |
|
if (n < 0) |
| 128 |
|
{ |
| 129 |
|
n = 0; |
| 130 |
|
} |
| 131 |
|
else if (n > len) |
| 132 |
|
{ |
| 133 |
|
n = len; |
| 134 |
|
} |
| 135 |
|
|
| 136 |
moveto(4, 0); |
moveto(4, 0); |
| 137 |
prints(" ------------------------------ \r\n"); |
prints(" ------------------------------ \r\n"); |
| 138 |
snprintf(buf2, sizeof(buf2), " %3d%% ", n * 100 / len); |
snprintf(buf, sizeof(buf), " %3d%% ", n * 100 / len); |
| 139 |
ptr = buf; |
strncpy(buf2, buf, (size_t) n); |
| 140 |
ptr2 = buf2; |
buf2[n] = '\0'; |
| 141 |
ptr3 = buf + n; |
prints("|\033[46m%s\033[44m%s\033[m|\r\n", buf2, buf + n); |
|
while (ptr != ptr3) |
|
|
*ptr++ = *ptr2++; |
|
|
*ptr++ = '\x1b'; |
|
|
*ptr++ = '['; |
|
|
*ptr++ = '4'; |
|
|
*ptr++ = '4'; |
|
|
*ptr++ = 'm'; |
|
|
while (*ptr2 != '\0') |
|
|
*ptr++ = *ptr2++; |
|
|
*ptr++ = '\0'; |
|
|
prints("|\033[46m%s\033[m|\r\n", buf); |
|
| 142 |
prints(" ------------------------------ \r\n"); |
prints(" ------------------------------ \r\n"); |
| 143 |
iflush(); |
iflush(); |
| 144 |
} |
} |
| 145 |
|
|
| 146 |
int bbsnet_connect(int n) |
int bbsnet_connect(int n) |
| 147 |
{ |
{ |
| 148 |
int sock, result, loop; |
int sock, ret, loop; |
| 149 |
ssize_t len; |
ssize_t len; |
| 150 |
struct sockaddr_in sin; |
struct sockaddr_in sin; |
| 151 |
char buf[LINE_BUFFER_LEN]; |
char buf[LINE_BUFFER_LEN]; |
| 205 |
remote_addr[sizeof(remote_addr) - 1] = '\0'; |
remote_addr[sizeof(remote_addr) - 1] = '\0'; |
| 206 |
remote_port = ntohs(sin.sin_port); |
remote_port = ntohs(sin.sin_port); |
| 207 |
|
|
| 208 |
prints("\033[1;32m穿梭进度条提示您当前已使用的时间,按Ctrl-C中断。\033[m\r\n"); |
prints("\033[1;32m穿梭进度条提示您当前已使用的时间,按\033[1;33mCtrl+C\033[1;32m中断。\033[m\r\n"); |
| 209 |
process_bar(0, MAX_PROCESS_BAR_LEN); |
process_bar(0, MAX_PROCESS_BAR_LEN); |
| 210 |
for (i = 0; i < MAX_PROCESS_BAR_LEN; i++) |
for (i = 0; i < MAX_PROCESS_BAR_LEN; i++) |
| 211 |
{ |
{ |
| 258 |
timeout.tv_sec = 0; |
timeout.tv_sec = 0; |
| 259 |
timeout.tv_usec = 100 * 1000; // 0.1 second |
timeout.tv_usec = 100 * 1000; // 0.1 second |
| 260 |
|
|
| 261 |
result = SignalSafeSelect(FD_SETSIZE, &testfds, (fd_set *)NULL, |
ret = select(FD_SETSIZE, &testfds, NULL, NULL, &timeout); |
|
(fd_set *)NULL, &timeout); |
|
| 262 |
|
|
| 263 |
if (result == 0) |
if (ret == 0) |
| 264 |
{ |
{ |
| 265 |
if (time(0) - BBS_last_access_tm >= MAX_DELAY_TIME) |
if (time(0) - BBS_last_access_tm >= MAX_DELAY_TIME) |
| 266 |
{ |
{ |
| 267 |
loop = 0; |
loop = 0; |
| 268 |
} |
} |
| 269 |
} |
} |
| 270 |
if (result < 0) |
else if (ret < 0) |
| 271 |
{ |
{ |
| 272 |
log_error("select() error (%d) !\n", result); |
if (errno != EINTR) |
| 273 |
loop = 0; |
{ |
| 274 |
|
log_error("select() error (%d) !\n", errno); |
| 275 |
|
loop = 0; |
| 276 |
|
} |
| 277 |
} |
} |
| 278 |
if (result > 0) |
else if (ret > 0) |
| 279 |
{ |
{ |
| 280 |
if (FD_ISSET(STDIN_FILENO, &testfds)) |
if (FD_ISSET(STDIN_FILENO, &testfds)) |
| 281 |
{ |
{ |