mirror of
https://github.com/bobbimanners/emailler.git
synced 2025-02-11 11:30:51 +00:00
Fixed code style.
This commit is contained in:
parent
9f652e7c21
commit
d21fc5bf40
50
test/peer.c
50
test/peer.c
@ -1,11 +1,14 @@
|
||||
#include <stdio.h>
|
||||
|
||||
#ifdef _WIN32
|
||||
|
||||
#include <conio.h>
|
||||
#define WIN32_LEAN_AND_MEAN
|
||||
#include <winsock2.h>
|
||||
#pragma comment(lib, "ws2_32.lib")
|
||||
|
||||
#else
|
||||
|
||||
#include <unistd.h>
|
||||
#include <stdlib.h>
|
||||
#include <errno.h>
|
||||
@ -25,7 +28,6 @@
|
||||
#define ioctlsocket ioctl
|
||||
#define SOCKADDR struct sockaddr
|
||||
#define SOCKADDR_IN struct sockaddr_in
|
||||
#define getch cgetc
|
||||
|
||||
static void Sleep(u_int msec)
|
||||
{
|
||||
@ -35,13 +37,13 @@ static void Sleep(u_int msec)
|
||||
nanosleep(&ts, NULL);
|
||||
}
|
||||
|
||||
/* kbhit() and cgetc() for Unix: */
|
||||
/* kbhit() and getch() for Unix: */
|
||||
|
||||
static int __conio_initialized;
|
||||
|
||||
static struct termios tty,otty;
|
||||
|
||||
static __inline__ void makecooked(void)
|
||||
static void makecooked(void)
|
||||
{
|
||||
tcsetattr(0, TCSANOW, &otty);
|
||||
}
|
||||
@ -56,7 +58,10 @@ static void sighand( int num )
|
||||
|
||||
static void exitfn(void)
|
||||
{
|
||||
if (__conio_initialized) makecooked();
|
||||
if (__conio_initialized)
|
||||
{
|
||||
makecooked();
|
||||
}
|
||||
printf("\n");
|
||||
}
|
||||
|
||||
@ -64,9 +69,11 @@ static void makeraw(void)
|
||||
{
|
||||
static int first_call = 1;
|
||||
|
||||
if (first_call) {
|
||||
if (first_call)
|
||||
{
|
||||
first_call = 0;
|
||||
if (tcgetattr(0, &tty)) { /* input terminal */
|
||||
if (tcgetattr(0, &tty))
|
||||
{ /* input terminal */
|
||||
fprintf(stderr, "cannot get terminal attributes: %s\n", strerror(errno));
|
||||
exit(1);
|
||||
}
|
||||
@ -88,7 +95,8 @@ static void makeraw(void)
|
||||
|
||||
static void __init_conio(void)
|
||||
{
|
||||
if (! __conio_initialized) {
|
||||
if (! __conio_initialized)
|
||||
{
|
||||
signal(SIGINT, sighand);
|
||||
signal(SIGTERM, sighand);
|
||||
signal(SIGHUP, sighand);
|
||||
@ -100,18 +108,25 @@ static void __init_conio(void)
|
||||
|
||||
static void __makeraw(void)
|
||||
{
|
||||
if (! __conio_initialized) __init_conio();
|
||||
else makeraw();
|
||||
if (! __conio_initialized)
|
||||
{
|
||||
__init_conio();
|
||||
}
|
||||
else
|
||||
{
|
||||
makeraw();
|
||||
}
|
||||
}
|
||||
|
||||
static void __makecooked(void)
|
||||
{
|
||||
if (__conio_initialized) {
|
||||
if (__conio_initialized)
|
||||
{
|
||||
makecooked();
|
||||
}
|
||||
}
|
||||
|
||||
static char cgetc (void)
|
||||
static char getch (void)
|
||||
{
|
||||
char c;
|
||||
|
||||
@ -128,17 +143,22 @@ static unsigned char kbhit (void)
|
||||
|
||||
__makeraw();
|
||||
|
||||
again:
|
||||
again:
|
||||
FD_ZERO(&fds);
|
||||
FD_SET(0, &fds);
|
||||
tv.tv_sec = tv.tv_usec = 0;
|
||||
retval = select(1, &fds, NULL, NULL, &tv);
|
||||
if (retval == -1) {
|
||||
if (errno == EINTR) goto again;
|
||||
if (retval == -1)
|
||||
{
|
||||
if (errno == EINTR)
|
||||
{
|
||||
goto again;
|
||||
}
|
||||
__makecooked();
|
||||
exit(1);
|
||||
}
|
||||
if (FD_ISSET(0, &fds)) {
|
||||
if (FD_ISSET(0, &fds))
|
||||
{
|
||||
return 1;
|
||||
}
|
||||
return 0;
|
||||
|
Loading…
x
Reference in New Issue
Block a user