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

Wyświetl plik

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