Apply Linux C Style to parallel.c

Hamlib-3.1
Nate Bargmann 2016-02-21 15:06:16 -06:00
rodzic 6a3214fd43
commit 0db862e560
1 zmienionych plików z 69 dodań i 50 usunięć

Wyświetl plik

@ -138,11 +138,14 @@ int par_open(hamlib_port_t *port)
#ifdef HAVE_LINUX_PPDEV_H
/* TODO: open with O_NONBLOCK ? */
fd = open(port->pathname, O_RDWR);
if (fd < 0) {
rig_debug(RIG_DEBUG_ERR, "Opening device \"%s\": %s\n", port->pathname, strerror(errno));
return -RIG_EIO;
}
mode = IEEE1284_MODE_COMPAT;
if (ioctl(fd, PPSETMODE, &mode) != 0) {
rig_debug(RIG_DEBUG_ERR, "PPSETMODE \"%s\": %s\n", port->pathname, strerror(errno));
close(fd);
@ -152,6 +155,7 @@ int par_open(hamlib_port_t *port)
#elif defined(HAVE_DEV_PPBUS_PPI_H)
fd = open(port->pathname, O_RDWR);
if (fd < 0) {
rig_debug(RIG_DEBUG_ERR, "Opening device \"%s\": %s\n", port->pathname, strerror(errno));
return -RIG_EIO;
@ -160,6 +164,7 @@ int par_open(hamlib_port_t *port)
#elif defined(__WIN64__) || defined(__WIN32__)
handle = CreateFile(port->pathname, GENERIC_READ | GENERIC_WRITE,
0, NULL, OPEN_EXISTING, 0, NULL);
if (handle == INVALID_HANDLE_VALUE) {
rig_debug(RIG_DEBUG_ERR, "Opening device \"%s\"\n", port->pathname);
CloseHandle(handle);
@ -170,6 +175,7 @@ int par_open(hamlib_port_t *port)
if (fd == -1)
return -RIG_EIO;
}
#else
return -RIG_ENIMPL;
#endif
@ -222,6 +228,7 @@ int HAMLIB_API par_write_data(hamlib_port_t *port, unsigned char data)
return -RIG_EIO;
}
}
return RIG_OK;
#else
return -RIG_ENIMPL;
@ -277,8 +284,10 @@ int HAMLIB_API par_write_control(hamlib_port_t *port, unsigned char control)
int status;
unsigned char ctrl = control ^ CP_ACTIVE_LOW_BITS;
status = ioctl(port->fd, PPWCONTROL, &ctrl);
if (status < 0)
rig_debug(RIG_DEBUG_ERR, "ioctl(PPWCONTROL) failed: %s\n", strerror(errno));
return status == 0 ? RIG_OK : -RIG_EIO;
#elif defined(HAVE_DEV_PPBUS_PPI_H)
int status;
@ -295,8 +304,7 @@ int HAMLIB_API par_write_control(hamlib_port_t *port, unsigned char control)
C1284_NSELECTIN);
intptr_t handle;
if (ctr & 0x20)
{
if (ctr & 0x20) {
rig_debug(RIG_DEBUG_WARN, "use ieee1284_data_dir to change data line direction!\n");
}
@ -313,6 +321,7 @@ int HAMLIB_API par_write_control(hamlib_port_t *port, unsigned char control)
return -RIG_EIO;
}
}
return RIG_OK;
#else
return -RIG_ENIMPL;
@ -330,8 +339,10 @@ int HAMLIB_API par_read_control(hamlib_port_t *port, unsigned char *control)
int status;
unsigned char ctrl;
status = ioctl(port->fd, PPRCONTROL, &ctrl);
if (status < 0)
rig_debug(RIG_DEBUG_ERR, "ioctl(PPRCONTROL) failed: %s\n", strerror(errno));
*control = ctrl ^ CP_ACTIVE_LOW_BITS;
return status == 0 ? RIG_OK : -RIG_EIO;
#elif defined(HAVE_DEV_PPBUS_PPI_H)
@ -414,10 +425,12 @@ int HAMLIB_API par_read_status(hamlib_port_t *port, unsigned char *status)
int HAMLIB_API par_lock(hamlib_port_t *port)
{
#ifdef HAVE_LINUX_PPDEV_H
if (ioctl(port->fd, PPCLAIM) < 0) {
rig_debug(RIG_DEBUG_ERR, "Claiming device \"%s\": %s\n", port->pathname, strerror(errno));
return -RIG_EIO;
}
return RIG_OK;
#elif defined(HAVE_DEV_PPBUS_PPI_H)
return RIG_OK;
@ -436,10 +449,12 @@ int HAMLIB_API par_lock(hamlib_port_t *port)
int HAMLIB_API par_unlock(hamlib_port_t *port)
{
#ifdef HAVE_LINUX_PPDEV_H
if (ioctl(port->fd, PPRELEASE) < 0) {
rig_debug(RIG_DEBUG_ERR, "Releasing device \"%s\": %s\n", port->pathname, strerror(errno));
return -RIG_EIO;
}
return RIG_OK;
#elif defined(HAVE_DEV_PPBUS_PPI_H)
return RIG_OK;
@ -466,13 +481,13 @@ int HAMLIB_API par_unlock(hamlib_port_t *port)
int par_ptt_set(hamlib_port_t *p, ptt_t pttx)
{
switch (p->type.ptt) {
case RIG_PTT_PARALLEL:
{
case RIG_PTT_PARALLEL: {
unsigned char ctl;
int status;
par_lock(p);
status = par_read_control(p, &ctl);
if (status != RIG_OK)
return status;
@ -491,11 +506,13 @@ int par_ptt_set(hamlib_port_t *p, ptt_t pttx)
par_unlock(p);
return status;
}
default:
rig_debug(RIG_DEBUG_ERR, "Unsupported PTT type %d\n",
p->type.ptt);
return -RIG_EINVAL;
}
return RIG_OK;
}
@ -508,8 +525,7 @@ int par_ptt_set(hamlib_port_t *p, ptt_t pttx)
int par_ptt_get(hamlib_port_t *p, ptt_t *pttx)
{
switch (p->type.ptt) {
case RIG_PTT_PARALLEL:
{
case RIG_PTT_PARALLEL: {
unsigned char ctl;
int status;
@ -522,11 +538,13 @@ int par_ptt_get(hamlib_port_t *p, ptt_t *pttx)
RIG_PTT_ON : RIG_PTT_OFF;
return status;
}
default:
rig_debug(RIG_DEBUG_ERR, "Unsupported PTT type %d\n",
p->type.ptt);
return -RIG_ENAVAIL;
}
return RIG_OK;
}
@ -539,8 +557,7 @@ int par_ptt_get(hamlib_port_t *p, ptt_t *pttx)
int par_dcd_get(hamlib_port_t *p, dcd_t *dcdx)
{
switch (p->type.dcd) {
case RIG_DCD_PARALLEL:
{
case RIG_DCD_PARALLEL: {
unsigned char reg;
int status;
@ -549,11 +566,13 @@ int par_dcd_get(hamlib_port_t *p, dcd_t *dcdx)
RIG_DCD_ON : RIG_DCD_OFF;
return status;
}
default:
rig_debug(RIG_DEBUG_ERR, "Unsupported DCD type %d\n",
p->type.dcd);
return -RIG_ENAVAIL;
}
return RIG_OK;
}