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