Touch up rigctld.c and rotctld.c with astyle

Prior reformat had only been a reindent with Emacs.  Now use astyle.
Hamlib-3.1
Nate Bargmann 2016-02-14 18:05:55 -06:00
rodzic 022ba0f48b
commit 4595f77f99
2 zmienionych plików z 160 dodań i 82 usunięć

Wyświetl plik

@ -76,8 +76,7 @@
* TODO: add an option to read from a file * TODO: add an option to read from a file
*/ */
#define SHORT_OPTIONS "m:r:p:d:P:D:s:c:T:t:C:lLuovhV" #define SHORT_OPTIONS "m:r:p:d:P:D:s:c:T:t:C:lLuovhV"
static struct option long_options[] = static struct option long_options[] = {
{
{"model", 1, 0, 'm'}, {"model", 1, 0, 'm'},
{"rig-file", 1, 0, 'r'}, {"rig-file", 1, 0, 'r'},
{"ptt-file", 1, 0, 'p'}, {"ptt-file", 1, 0, 'p'},
@ -128,6 +127,7 @@ static void handle_error (enum rig_debug_level_e lvl, const char *msg)
lpMsgBuf = (LPVOID)"Unknown error"; lpMsgBuf = (LPVOID)"Unknown error";
e = WSAGetLastError(); e = WSAGetLastError();
if (FormatMessage( if (FormatMessage(
FORMAT_MESSAGE_ALLOCATE_BUFFER | FORMAT_MESSAGE_ALLOCATE_BUFFER |
FORMAT_MESSAGE_FROM_SYSTEM | FORMAT_MESSAGE_FROM_SYSTEM |
@ -141,6 +141,7 @@ static void handle_error (enum rig_debug_level_e lvl, const char *msg)
} else { } else {
rig_debug(lvl, "%s: Network error %d\n", msg, e); rig_debug(lvl, "%s: Network error %d\n", msg, e);
} }
#else #else
e = errno; e = errno;
rig_debug(lvl, "%s: Network error %d: %s\n", msg, e, strerror(e)); rig_debug(lvl, "%s: Network error %d: %s\n", msg, e, strerror(e));
@ -177,6 +178,7 @@ int main (int argc, char *argv[])
c = getopt_long(argc, argv, SHORT_OPTIONS, c = getopt_long(argc, argv, SHORT_OPTIONS,
long_options, &option_index); long_options, &option_index);
if (c == -1) if (c == -1)
break; break;
@ -184,42 +186,53 @@ int main (int argc, char *argv[])
case 'h': case 'h':
usage(); usage();
exit(0); exit(0);
case 'V': case 'V':
version(); version();
exit(0); exit(0);
case 'm': case 'm':
if (!optarg) { if (!optarg) {
usage(); /* wrong arg count */ usage(); /* wrong arg count */
exit(1); exit(1);
} }
my_model = atoi(optarg); my_model = atoi(optarg);
break; break;
case 'r': case 'r':
if (!optarg) { if (!optarg) {
usage(); /* wrong arg count */ usage(); /* wrong arg count */
exit(1); exit(1);
} }
rig_file = optarg; rig_file = optarg;
break; break;
case 'p': case 'p':
if (!optarg) { if (!optarg) {
usage(); /* wrong arg count */ usage(); /* wrong arg count */
exit(1); exit(1);
} }
ptt_file = optarg; ptt_file = optarg;
break; break;
case 'd': case 'd':
if (!optarg) { if (!optarg) {
usage(); /* wrong arg count */ usage(); /* wrong arg count */
exit(1); exit(1);
} }
dcd_file = optarg; dcd_file = optarg;
break; break;
case 'P': case 'P':
if (!optarg) { if (!optarg) {
usage(); /* wrong arg count */ usage(); /* wrong arg count */
exit(1); exit(1);
} }
if (!strcmp(optarg, "RIG")) if (!strcmp(optarg, "RIG"))
ptt_type = RIG_PTT_RIG; ptt_type = RIG_PTT_RIG;
else if (!strcmp(optarg, "DTR")) else if (!strcmp(optarg, "DTR"))
@ -234,12 +247,15 @@ int main (int argc, char *argv[])
ptt_type = RIG_PTT_NONE; ptt_type = RIG_PTT_NONE;
else else
ptt_type = atoi(optarg); ptt_type = atoi(optarg);
break; break;
case 'D': case 'D':
if (!optarg) { if (!optarg) {
usage(); /* wrong arg count */ usage(); /* wrong arg count */
exit(1); exit(1);
} }
if (!strcmp(optarg, "RIG")) if (!strcmp(optarg, "RIG"))
dcd_type = RIG_DCD_RIG; dcd_type = RIG_DCD_RIG;
else if (!strcmp(optarg, "DSR")) else if (!strcmp(optarg, "DSR"))
@ -254,59 +270,77 @@ int main (int argc, char *argv[])
dcd_type = RIG_DCD_NONE; dcd_type = RIG_DCD_NONE;
else else
dcd_type = atoi(optarg); dcd_type = atoi(optarg);
break; break;
case 'c': case 'c':
if (!optarg) { if (!optarg) {
usage(); /* wrong arg count */ usage(); /* wrong arg count */
exit(1); exit(1);
} }
civaddr = optarg; civaddr = optarg;
break; break;
case 's': case 's':
if (!optarg) { if (!optarg) {
usage(); /* wrong arg count */ usage(); /* wrong arg count */
exit(1); exit(1);
} }
serial_rate = atoi(optarg); serial_rate = atoi(optarg);
break; break;
case 'C': case 'C':
if (!optarg) { if (!optarg) {
usage(); /* wrong arg count */ usage(); /* wrong arg count */
exit(1); exit(1);
} }
if (*conf_parms != '\0') if (*conf_parms != '\0')
strcat(conf_parms, ","); strcat(conf_parms, ",");
strncat(conf_parms, optarg, MAXCONFLEN - strlen(conf_parms)); strncat(conf_parms, optarg, MAXCONFLEN - strlen(conf_parms));
break; break;
case 't': case 't':
if (!optarg) { if (!optarg) {
usage(); /* wrong arg count */ usage(); /* wrong arg count */
exit(1); exit(1);
} }
portno = optarg; portno = optarg;
break; break;
case 'T': case 'T':
if (!optarg) { if (!optarg) {
usage(); /* wrong arg count */ usage(); /* wrong arg count */
exit(1); exit(1);
} }
src_addr = optarg; src_addr = optarg;
break; break;
case 'o': case 'o':
vfo_mode++; vfo_mode++;
break; break;
case 'v': case 'v':
verbose++; verbose++;
break; break;
case 'L': case 'L':
show_conf++; show_conf++;
break; break;
case 'l': case 'l':
list_models(); list_models();
exit(0); exit(0);
case 'u': case 'u':
dump_caps_opt++; dump_caps_opt++;
break; break;
default: default:
usage(); /* unknown option? */ usage(); /* unknown option? */
exit(1); exit(1);
@ -343,15 +377,20 @@ int main (int argc, char *argv[])
*/ */
if (ptt_type != RIG_PTT_NONE) if (ptt_type != RIG_PTT_NONE)
my_rig->state.pttport.type.ptt = ptt_type; my_rig->state.pttport.type.ptt = ptt_type;
if (dcd_type != RIG_DCD_NONE) if (dcd_type != RIG_DCD_NONE)
my_rig->state.dcdport.type.dcd = dcd_type; my_rig->state.dcdport.type.dcd = dcd_type;
if (ptt_file) if (ptt_file)
strncpy(my_rig->state.pttport.pathname, ptt_file, FILPATHLEN - 1); strncpy(my_rig->state.pttport.pathname, ptt_file, FILPATHLEN - 1);
if (dcd_file) if (dcd_file)
strncpy(my_rig->state.dcdport.pathname, dcd_file, FILPATHLEN - 1); strncpy(my_rig->state.dcdport.pathname, dcd_file, FILPATHLEN - 1);
/* FIXME: bound checking and port type == serial */ /* FIXME: bound checking and port type == serial */
if (serial_rate != 0) if (serial_rate != 0)
my_rig->state.rigport.parm.serial.rate = serial_rate; my_rig->state.rigport.parm.serial.rate = serial_rate;
if (civaddr) if (civaddr)
rig_set_conf(my_rig, rig_token_lookup(my_rig, "civaddr"), civaddr); rig_set_conf(my_rig, rig_token_lookup(my_rig, "civaddr"), civaddr);
@ -398,6 +437,7 @@ int main (int argc, char *argv[])
# endif # endif
WSADATA wsadata; WSADATA wsadata;
if (WSAStartup(MAKEWORD(1, 1), &wsadata) == SOCKET_ERROR) { if (WSAStartup(MAKEWORD(1, 1), &wsadata) == SOCKET_ERROR) {
fprintf(stderr, "WSAStartup socket error\n"); fprintf(stderr, "WSAStartup socket error\n");
exit(1); exit(1);
@ -417,15 +457,18 @@ int main (int argc, char *argv[])
hints.ai_protocol = 0; /* Any protocol */ hints.ai_protocol = 0; /* Any protocol */
retcode = getaddrinfo(src_addr, portno, &hints, &result); retcode = getaddrinfo(src_addr, portno, &hints, &result);
if (retcode != 0) { if (retcode != 0) {
fprintf(stderr, "getaddrinfo: %s\n", gai_strerror(retcode)); fprintf(stderr, "getaddrinfo: %s\n", gai_strerror(retcode));
exit(2); exit(2);
} }
saved_result = result; saved_result = result;
do { do {
sock_listen = socket(result->ai_family, result->ai_socktype, sock_listen = socket(result->ai_family, result->ai_socktype,
result->ai_protocol); result->ai_protocol);
if (sock_listen < 0) { if (sock_listen < 0) {
handle_error(RIG_DEBUG_ERR, "socket"); handle_error(RIG_DEBUG_ERR, "socket");
freeaddrinfo(saved_result); /* No longer needed */ freeaddrinfo(saved_result); /* No longer needed */
@ -440,10 +483,12 @@ int main (int argc, char *argv[])
} }
#ifdef IPV6_V6ONLY #ifdef IPV6_V6ONLY
if (AF_INET6 == result->ai_family) { if (AF_INET6 == result->ai_family) {
/* allow IPv4 mapped to IPv6 clients Windows and BSD default /* allow IPv4 mapped to IPv6 clients Windows and BSD default
this to 1 (i.e. disallowed) and we prefer it off */ this to 1 (i.e. disallowed) and we prefer it off */
sockopt = 0; sockopt = 0;
if (setsockopt(sock_listen, IPPROTO_IPV6, IPV6_V6ONLY, if (setsockopt(sock_listen, IPPROTO_IPV6, IPV6_V6ONLY,
(char *)&sockopt, sizeof(sockopt)) < 0) { (char *)&sockopt, sizeof(sockopt)) < 0) {
handle_error(RIG_DEBUG_ERR, "setsockopt"); handle_error(RIG_DEBUG_ERR, "setsockopt");
@ -451,6 +496,7 @@ int main (int argc, char *argv[])
exit(1); exit(1);
} }
} }
#endif #endif
if (0 == bind(sock_listen, result->ai_addr, result->ai_addrlen)) { if (0 == bind(sock_listen, result->ai_addr, result->ai_addrlen)) {
@ -520,6 +566,7 @@ int main (int argc, char *argv[])
rig_debug(RIG_DEBUG_ERR, "pthread_create: %s\n", strerror(retcode)); rig_debug(RIG_DEBUG_ERR, "pthread_create: %s\n", strerror(retcode));
break; break;
} }
#else #else
handle_socket(arg); handle_socket(arg);
#endif #endif
@ -560,6 +607,7 @@ void * handle_socket(void *arg)
#else #else
fsockin = fdopen(handle_data_arg->sock, "rb"); fsockin = fdopen(handle_data_arg->sock, "rb");
#endif #endif
if (!fsockin) { if (!fsockin) {
rig_debug(RIG_DEBUG_ERR, "fdopen in: %s\n", strerror(errno)); rig_debug(RIG_DEBUG_ERR, "fdopen in: %s\n", strerror(errno));
goto handle_exit; goto handle_exit;
@ -570,6 +618,7 @@ void * handle_socket(void *arg)
#else #else
fsockout = fdopen(handle_data_arg->sock, "wb"); fsockout = fdopen(handle_data_arg->sock, "wb");
#endif #endif
if (!fsockout) { if (!fsockout) {
rig_debug(RIG_DEBUG_ERR, "fdopen out: %s\n", strerror(errno)); rig_debug(RIG_DEBUG_ERR, "fdopen out: %s\n", strerror(errno));
fclose(fsockin); fclose(fsockin);
@ -579,6 +628,7 @@ void * handle_socket(void *arg)
do { do {
retcode = rigctl_parse(handle_data_arg->rig, fsockin, fsockout, NULL, 0); retcode = rigctl_parse(handle_data_arg->rig, fsockin, fsockout, NULL, 0);
if (ferror(fsockin) || ferror(fsockout)) if (ferror(fsockin) || ferror(fsockout))
retcode = 1; retcode = 1;
} while (retcode == 0 || retcode == 2); } while (retcode == 0 || retcode == 2);

Wyświetl plik

@ -83,8 +83,7 @@ void usage();
* TODO: add an option to read from a file * TODO: add an option to read from a file
*/ */
#define SHORT_OPTIONS "m:r:s:C:t:T:LuvhVl" #define SHORT_OPTIONS "m:r:s:C:t:T:LuvhVl"
static struct option long_options[] = static struct option long_options[] = {
{
{"model", 1, 0, 'm'}, {"model", 1, 0, 'm'},
{"rot-file", 1, 0, 'r'}, {"rot-file", 1, 0, 'r'},
{"serial-speed", 1, 0, 's'}, {"serial-speed", 1, 0, 's'},
@ -133,6 +132,7 @@ static void handle_error (enum rig_debug_level_e lvl, const char *msg)
} else { } else {
rig_debug(lvl, "%s: Network error %d\n", msg, e); rig_debug(lvl, "%s: Network error %d\n", msg, e);
} }
#else #else
e = errno; e = errno;
rig_debug(lvl, "%s: Network error %d: %s\n", msg, e, strerror(e)); rig_debug(lvl, "%s: Network error %d: %s\n", msg, e, strerror(e));
@ -166,6 +166,7 @@ int main (int argc, char *argv[])
c = getopt_long(argc, argv, SHORT_OPTIONS, c = getopt_long(argc, argv, SHORT_OPTIONS,
long_options, &option_index); long_options, &option_index);
if (c == -1) if (c == -1)
break; break;
@ -173,65 +174,84 @@ int main (int argc, char *argv[])
case 'h': case 'h':
usage(); usage();
exit(0); exit(0);
case 'V': case 'V':
version(); version();
exit(0); exit(0);
case 'm': case 'm':
if (!optarg) { if (!optarg) {
usage(); /* wrong arg count */ usage(); /* wrong arg count */
exit(1); exit(1);
} }
my_model = atoi(optarg); my_model = atoi(optarg);
break; break;
case 'r': case 'r':
if (!optarg) { if (!optarg) {
usage(); /* wrong arg count */ usage(); /* wrong arg count */
exit(1); exit(1);
} }
rot_file = optarg; rot_file = optarg;
break; break;
case 's': case 's':
if (!optarg) { if (!optarg) {
usage(); /* wrong arg count */ usage(); /* wrong arg count */
exit(1); exit(1);
} }
serial_rate = atoi(optarg); serial_rate = atoi(optarg);
break; break;
case 'C': case 'C':
if (!optarg) { if (!optarg) {
usage(); /* wrong arg count */ usage(); /* wrong arg count */
exit(1); exit(1);
} }
if (*conf_parms != '\0') if (*conf_parms != '\0')
strcat(conf_parms, ","); strcat(conf_parms, ",");
strncat(conf_parms, optarg, MAXCONFLEN - strlen(conf_parms)); strncat(conf_parms, optarg, MAXCONFLEN - strlen(conf_parms));
break; break;
case 't': case 't':
if (!optarg) { if (!optarg) {
usage(); /* wrong arg count */ usage(); /* wrong arg count */
exit(1); exit(1);
} }
portno = optarg; portno = optarg;
break; break;
case 'T': case 'T':
if (!optarg) { if (!optarg) {
usage(); /* wrong arg count */ usage(); /* wrong arg count */
exit(1); exit(1);
} }
src_addr = optarg; src_addr = optarg;
break; break;
case 'v': case 'v':
verbose++; verbose++;
break; break;
case 'L': case 'L':
show_conf++; show_conf++;
break; break;
case 'l': case 'l':
list_models(); list_models();
exit(0); exit(0);
case 'u': case 'u':
dump_caps_opt++; dump_caps_opt++;
break; break;
default: default:
usage(); /* unknown option? */ usage(); /* unknown option? */
exit(1); exit(1);
@ -330,6 +350,7 @@ int main (int argc, char *argv[])
hints.ai_protocol = 0; /* Any protocol */ hints.ai_protocol = 0; /* Any protocol */
retcode = getaddrinfo(src_addr, portno, &hints, &result); retcode = getaddrinfo(src_addr, portno, &hints, &result);
if (retcode != 0) { if (retcode != 0) {
fprintf(stderr, "getaddrinfo: %s\n", gai_strerror(retcode)); fprintf(stderr, "getaddrinfo: %s\n", gai_strerror(retcode));
exit(2); exit(2);
@ -355,6 +376,7 @@ int main (int argc, char *argv[])
} }
#ifdef IPV6_V6ONLY #ifdef IPV6_V6ONLY
if (AF_INET6 == result->ai_family) { if (AF_INET6 == result->ai_family) {
/* allow IPv4 mapped to IPv6 clients, MS & BSD default this /* allow IPv4 mapped to IPv6 clients, MS & BSD default this
to 1 i.e. disallowed */ to 1 i.e. disallowed */
@ -367,11 +389,13 @@ int main (int argc, char *argv[])
exit(1); exit(1);
} }
} }
#endif #endif
if (0 == bind(sock_listen, result->ai_addr, result->ai_addrlen)) { if (0 == bind(sock_listen, result->ai_addr, result->ai_addrlen)) {
break; break;
} }
handle_error(RIG_DEBUG_WARN, "binding failed (trying next interface)"); handle_error(RIG_DEBUG_WARN, "binding failed (trying next interface)");
#ifdef __MINGW32__ #ifdef __MINGW32__
closesocket(sock_listen); closesocket(sock_listen);
@ -438,6 +462,7 @@ int main (int argc, char *argv[])
rig_debug(RIG_DEBUG_ERR, "pthread_create: %s\n", strerror(retcode)); rig_debug(RIG_DEBUG_ERR, "pthread_create: %s\n", strerror(retcode));
break; break;
} }
#else #else
handle_socket(arg); handle_socket(arg);
#endif #endif
@ -478,6 +503,7 @@ void * handle_socket(void *arg)
#else #else
fsockin = fdopen(handle_data_arg->sock, "rb"); fsockin = fdopen(handle_data_arg->sock, "rb");
#endif #endif
if (!fsockin) { if (!fsockin) {
rig_debug(RIG_DEBUG_ERR, "fdopen in: %s\n", strerror(errno)); rig_debug(RIG_DEBUG_ERR, "fdopen in: %s\n", strerror(errno));
goto handle_exit; goto handle_exit;
@ -488,6 +514,7 @@ void * handle_socket(void *arg)
#else #else
fsockout = fdopen(handle_data_arg->sock, "wb"); fsockout = fdopen(handle_data_arg->sock, "wb");
#endif #endif
if (!fsockout) { if (!fsockout) {
rig_debug(RIG_DEBUG_ERR, "fdopen out: %s\n", strerror(errno)); rig_debug(RIG_DEBUG_ERR, "fdopen out: %s\n", strerror(errno));
fclose(fsockin); fclose(fsockin);
@ -496,6 +523,7 @@ void * handle_socket(void *arg)
do { do {
retcode = rotctl_parse(handle_data_arg->rot, fsockin, fsockout, NULL, 0); retcode = rotctl_parse(handle_data_arg->rot, fsockin, fsockout, NULL, 0);
if (ferror(fsockin) || ferror(fsockout)) if (ferror(fsockin) || ferror(fsockout))
retcode = 1; retcode = 1;
} while (retcode == 0 || retcode == 2); } while (retcode == 0 || retcode == 2);