harmonize coding style

This commit is contained in:
marschap
2006-04-08 16:10:19 +00:00
parent 51dc6dcdfc
commit a1d741745a
+48 -95
View File
@@ -35,11 +35,7 @@ unsigned char GLKBufferEmpty = 0xff ;
* Open and configure a serial port for communication with
* a Matrix Orbital module (GLK or otherwise)
*/
GLKDisplay *
glkopen(
char * name,
tcflag_t speed
)
GLKDisplay *glkopen(char *name, tcflag_t speed)
{
int fd;
struct termios new;
@@ -49,12 +45,12 @@ GLKDisplay *
/* Invalid arguments */
errno = EINVAL;
return(NULL);
};
}
fd = open(name, O_RDWR | O_NOCTTY);
if (fd < 0) {
return(NULL);
};
}
/* Get current settings */
if (tcgetattr(fd, &new) < 0) {
@@ -62,13 +58,13 @@ GLKDisplay *
close(fd);
errno = errsave;
return(NULL);
};
}
retval = malloc(sizeof(GLKDisplay));
if (retval == NULL) {
errno = ENOMEM;
return(NULL);
};
}
retval->fd = fd;
retval->saved = new;
retval->ungetin = retval->ungetout = 0;
@@ -106,7 +102,7 @@ GLKDisplay *
glkclose(retval);
errno = errsave;
return(NULL);
};
}
return(retval);
}
@@ -117,28 +113,25 @@ GLKDisplay *
* a read will block (glkget) waiting on data.
*/
int
glktimeout(
GLKDisplay * fd,
int timeout
)
glktimeout(GLKDisplay *fd, int timeout)
{
struct termios t;
if (timeout < 0 || timeout > 255) {
errno = EINVAL; /* Invalid argument */
return(1); /* Failure */
};
}
if (tcgetattr(fd->fd, &t) < 0) {
return(1);
};
}
fd->timeout = timeout;
t.c_cc[VTIME] = timeout;
if (tcsetattr(fd->fd, TCSANOW, &t) < 0) {
return(1);
};
}
return(0); /* Success */
}
@@ -151,25 +144,20 @@ int
*/
#define GLKBUF (96)
int
glkflow(
GLKDisplay * fd,
int full,
int empty
)
glkflow(GLKDisplay *fd, int full, int empty)
{
struct termios t;
if( full > GLKBUF -1
|| empty > GLKBUF -1
|| full + empty > GLKBUF -1
) {
if ((full > GLKBUF -1)
|| (empty > GLKBUF -1)
|| (full + empty > GLKBUF -1)) {
errno = EINVAL;
return(1);
};
}
if (tcgetattr(fd->fd, &t) < 0) {
return(1); /* Failure */
};
}
if (full < 0 || empty < 0) {
/* Turn it off */
@@ -178,7 +166,8 @@ int
t.c_cc[VSTART] = GLKBufferEmpty;
t.c_cc[VSTOP] = GLKBufferFull;
fd->flow = GLKFLOW_DISABLE;
} else {
}
else {
/* Turn it on */
glkputl(fd, GLKCommand, 0x3a, full, empty, EOF);
/* Control what we send */
@@ -189,11 +178,11 @@ int
t.c_cc[VSTART] = GLKBufferEmpty;
t.c_cc[VSTOP] = GLKBufferFull;
fd->flow = GLKFLOW_OK;
};
}
if (tcsetattr(fd->fd, TCSANOW, &t) < 0) {
return(1);
};
}
return(0); /* Success */
}
@@ -203,16 +192,14 @@ int
* Close a serial port and restore settings if provided.
*/
int
glkclose(
GLKDisplay * fd
)
glkclose(GLKDisplay *fd)
{
int retval = 0;
if (fd->fd < 0) {
/* Probably already closed */
return(0); /* Success? */
};
}
/* Trash any unread data */
tcflush(fd->fd, TCIFLUSH);
@@ -234,10 +221,7 @@ int
* Send a character to the GLK
*/
int INLINE
glkput(
GLKDisplay * fd,
int c
)
glkput(GLKDisplay *fd, int c)
{
unsigned char val;
ssize_t retval;
@@ -262,15 +246,12 @@ int INLINE
* flow control signals
*/
int
glkunget(
GLKDisplay * fd,
int c
)
glkunget(GLKDisplay *fd, int c)
{
/* Is buffer already full? */
if (((fd->ungetin + 1) & (~UNGETBUFSIZE)) == fd->ungetout) {
return(1); /* Failure */
};
}
fd->ungetbuf[fd->ungetin] = c;
fd->ungetin = (fd->ungetin + 1) & (~UNGETBUFSIZE);
@@ -283,9 +264,7 @@ int
* Read a character from the GLK
*/
int INLINE
glkget(
GLKDisplay * fd
)
glkget(GLKDisplay *fd)
{
unsigned char c;
ssize_t retval;
@@ -295,7 +274,7 @@ int INLINE
return(-1);
} else {
return((int) c);
};
}
}
/* glkpoll
@@ -304,10 +283,7 @@ int INLINE
* GLK.
*/
int
glkpoll(
GLKDisplay * fd,
int timeout
)
glkpoll(GLKDisplay *fd, int timeout)
{
struct pollfd fds;
int retval;
@@ -319,7 +295,7 @@ int
if (retval < 0) {
/* Some error. Ignore it, and return "no data" */
retval = 0;
};
}
return(retval);
}
@@ -332,9 +308,7 @@ int
* GLKBufferFull and GLKBufferEmpty whereas glkgetc wil NOT.
*/
int
glkgetc(
GLKDisplay * fd
)
glkgetc(GLKDisplay *fd)
{
int c;
@@ -351,20 +325,19 @@ int
} else if (c == GLKBufferEmpty) {
fd->flow = GLKFLOW_OK;
continue;
};
};
}
}
/* Must be what we're looking for */
break;
};
} else {
}
}
else {
/* Get one of the "ungotten" char's */
c = fd->ungetbuf[fd->ungetout];
fd->ungetout = (fd->ungetout + 1) & (~UNGETBUFSIZE);
};
}
return(c);
}
@@ -375,10 +348,7 @@ int
* confirmation of echo
*/
int
glkput_confirm(
GLKDisplay * fd,
int c
)
glkput_confirm(GLKDisplay *fd, int c)
{
int echo;
@@ -391,7 +361,7 @@ int
echo = glkget(fd);
if (echo < 0) {
return(1); /* Failure */
};
}
if (echo == c) {
glkput(fd, GLKConfirm);
@@ -408,11 +378,7 @@ int
* confirmation.
*/
int
glkputa_confirm(
GLKDisplay * fd,
int len,
unsigned char * str
)
glkputa_confirm(GLKDisplay *fd, int len, unsigned char *str)
{
int i;
int retval;
@@ -420,7 +386,7 @@ int
retval = 0; /* Assume Success */
for (i = len; !retval && i; ++str, --i) {
retval = glkput_confirm(fd, *str);
};
}
return(retval);
}
@@ -430,10 +396,7 @@ int
* Send a character to the GLK on fd with echo expected
*/
int
glkput_echo(
GLKDisplay * fd,
int c
)
glkput_echo(GLKDisplay *fd, int c)
{
int echo;
@@ -446,7 +409,7 @@ int
echo = glkget(fd);
if (echo < 0) {
return(1); /* Failure */
};
}
if (echo == c) {
return(0); /* Success */
@@ -461,10 +424,7 @@ int
* terminated by an EOF valued argument.
*/
int
glkputl(
GLKDisplay * fd,
...
)
glkputl(GLKDisplay *fd, ...)
{
va_list ap;
int value;
@@ -477,7 +437,7 @@ int
while (!retval && value != EOF) {
retval = glkput(fd, value);
value = va_arg(ap, int);
};
}
return(retval);
}
@@ -488,10 +448,7 @@ int
* GLK.
*/
int
glkputs(
GLKDisplay * fd,
char * str
)
glkputs(GLKDisplay *fd, char *str)
{
register char *p = str;
int retval;
@@ -499,7 +456,7 @@ int
retval = 0; /* Success */
for (p = str; !retval && *p; ++p) {
retval = glkput(fd, *p);
};
}
return(retval);
}
@@ -509,11 +466,7 @@ int
* Send an array of characters.
*/
int
glkputa(
GLKDisplay * fd,
int len,
unsigned char * str
)
glkputa(GLKDisplay *fd, int len, unsigned char *str)
{
register unsigned char *p = str;
int i;
@@ -522,7 +475,7 @@ int
retval = 0; /* Assume Success */
for (i = len; !retval && i; ++p, --i) {
retval = glkput(fd, *p);
};
}
return(retval);
}