From 07f8023d17f96ffc2898d5713a33221ce494301c Mon Sep 17 00:00:00 2001 From: George Baltz N3GB Date: Thu, 29 Feb 2024 20:58:51 -0500 Subject: [PATCH] Convert tests/* to pointers --- tests/ampctld.c | 4 ++-- tests/cachetest.c | 4 ++-- tests/cachetest2.c | 2 +- tests/callback.c | 2 +- tests/dumpmem.c | 2 +- tests/rigctl.c | 8 ++++---- tests/rigctlcom.c | 8 ++++---- tests/rigctld.c | 8 ++++---- tests/rigctlsync.c | 12 ++++++------ tests/rigfreqwalk.c | 2 +- tests/rigmem.c | 4 ++-- tests/rigtestmcast.c | 6 +++--- tests/rotctl.c | 16 ++++++++-------- tests/rotctl_parse.c | 10 ++++------ tests/rotctld.c | 6 +++--- tests/sendraw.c | 3 ++- tests/testcache.c | 2 +- tests/testrig.c | 2 +- tests/testrigopen.c | 2 +- 19 files changed, 51 insertions(+), 52 deletions(-) diff --git a/tests/ampctld.c b/tests/ampctld.c index e827e2539..a2e00aa78 100644 --- a/tests/ampctld.c +++ b/tests/ampctld.c @@ -353,13 +353,13 @@ int main(int argc, char *argv[]) if (amp_file) { - strncpy(my_amp->state.ampport.pathname, amp_file, HAMLIB_FILPATHLEN - 1); + strncpy(AMPPORT(my_amp)->pathname, amp_file, HAMLIB_FILPATHLEN - 1); } /* FIXME: bound checking and port type == serial */ if (serial_rate != 0) { - my_amp->state.ampport.parm.serial.rate = serial_rate; + AMPPORT(my_amp)->parm.serial.rate = serial_rate; } /* diff --git a/tests/cachetest.c b/tests/cachetest.c index 6e5f10a13..468396cb7 100644 --- a/tests/cachetest.c +++ b/tests/cachetest.c @@ -77,9 +77,9 @@ int main(int argc, char *argv[]) /* Set up serial port, baud rate */ rig_file = argv[2]; // your serial device - strncpy(my_rig->state.rigport.pathname, rig_file, HAMLIB_FILPATHLEN - 1); + strncpy(RIGPORT(my_rig)->pathname, rig_file, HAMLIB_FILPATHLEN - 1); - my_rig->state.rigport.parm.serial.rate = baud; // your baud rate + RIGPORT(my_rig)->parm.serial.rate = baud; // your baud rate /* Open my rig */ retcode = rig_open(my_rig); diff --git a/tests/cachetest2.c b/tests/cachetest2.c index 94d43ff31..72ee34a3c 100644 --- a/tests/cachetest2.c +++ b/tests/cachetest2.c @@ -44,7 +44,7 @@ int main(int argc, const char *argv[]) /* Set up serial port, baud rate */ rig_file = "127.0.0.1:4532"; // your serial device - strncpy(my_rig->state.rigport.pathname, rig_file, HAMLIB_FILPATHLEN - 1); + strncpy(RIGPORT(my_rig)->pathname, rig_file, HAMLIB_FILPATHLEN - 1); /* Open my rig */ retcode = rig_open(my_rig); diff --git a/tests/callback.c b/tests/callback.c index 57cada2af..dfa1f5b34 100644 --- a/tests/callback.c +++ b/tests/callback.c @@ -12,7 +12,7 @@ int callback(const struct rig_caps *caps, rig_ptr_t rigp) } const char *port = "/dev/pts/3"; - strcpy(rig->state.rigport.pathname, port); + strcpy(RIGPORT(rig)->pathname, port); printf("%20s:", caps->model_name); fflush(stdout); diff --git a/tests/dumpmem.c b/tests/dumpmem.c index 636b7151e..978e0f556 100644 --- a/tests/dumpmem.c +++ b/tests/dumpmem.c @@ -57,7 +57,7 @@ int main(int argc, const char *argv[]) exit(1); /* whoops! something went wrong (mem alloc?) */ } - strncpy(my_rig->state.rigport.pathname, SERIAL_PORT, HAMLIB_FILPATHLEN - 1); + strncpy(RIGPORT(my_rig)->pathname, SERIAL_PORT, HAMLIB_FILPATHLEN - 1); if (rig_open(my_rig)) { diff --git a/tests/rigctl.c b/tests/rigctl.c index 68ca777de..9d656bba4 100644 --- a/tests/rigctl.c +++ b/tests/rigctl.c @@ -592,7 +592,7 @@ int main(int argc, char *argv[]) if (rig_file) { - strncpy(my_rig->state.rigport.pathname, rig_file, HAMLIB_FILPATHLEN - 1); + strncpy(RIGPORT(my_rig)->pathname, rig_file, HAMLIB_FILPATHLEN - 1); } /* @@ -600,7 +600,7 @@ int main(int argc, char *argv[]) */ if (ptt_type != RIG_PTT_NONE) { - my_rig->state.pttport.type.ptt = ptt_type; + PTTPORT(my_rig)->type.ptt = ptt_type; } if (dcd_type != RIG_DCD_NONE) @@ -610,7 +610,7 @@ int main(int argc, char *argv[]) if (ptt_file) { - strncpy(my_rig->state.pttport.pathname, ptt_file, HAMLIB_FILPATHLEN - 1); + strncpy(PTTPORT(my_rig)->pathname, ptt_file, HAMLIB_FILPATHLEN - 1); } if (dcd_file) @@ -621,7 +621,7 @@ int main(int argc, char *argv[]) /* FIXME: bound checking and port type == serial */ if (serial_rate != 0) { - my_rig->state.rigport.parm.serial.rate = serial_rate; + RIGPORT(my_rig)->parm.serial.rate = serial_rate; my_rig->state.rigport_deprecated.parm.serial.rate = serial_rate; } diff --git a/tests/rigctlcom.c b/tests/rigctlcom.c index 62e40ba0e..f1a285576 100644 --- a/tests/rigctlcom.c +++ b/tests/rigctlcom.c @@ -512,7 +512,7 @@ int main(int argc, char *argv[]) if (rig_file) { - strncpy(my_rig->state.rigport.pathname, rig_file, HAMLIB_FILPATHLEN - 1); + strncpy(RIGPORT(my_rig)->pathname, rig_file, HAMLIB_FILPATHLEN - 1); } if (!rig_file2) @@ -528,7 +528,7 @@ int main(int argc, char *argv[]) */ if (ptt_type != RIG_PTT_NONE) { - my_rig->state.pttport.type.ptt = ptt_type; + PTTPORT(my_rig)->type.ptt = ptt_type; } if (dcd_type != RIG_DCD_NONE) @@ -538,7 +538,7 @@ int main(int argc, char *argv[]) if (ptt_file) { - strncpy(my_rig->state.pttport.pathname, ptt_file, HAMLIB_FILPATHLEN - 1); + strncpy(PTTPORT(my_rig)->pathname, ptt_file, HAMLIB_FILPATHLEN - 1); } if (dcd_file) @@ -549,7 +549,7 @@ int main(int argc, char *argv[]) /* FIXME: bound checking and port type == serial */ if (serial_rate != 0) { - my_rig->state.rigport.parm.serial.rate = serial_rate; + RIGPORT(my_rig)->parm.serial.rate = serial_rate; } if (serial_rate2 != 0) diff --git a/tests/rigctld.c b/tests/rigctld.c index 8bb183839..d10f61f90 100644 --- a/tests/rigctld.c +++ b/tests/rigctld.c @@ -691,7 +691,7 @@ int main(int argc, char *argv[]) if (rig_file) { - strncpy(my_rig->state.rigport.pathname, rig_file, HAMLIB_FILPATHLEN - 1); + strncpy(RIGPORT(my_rig)->pathname, rig_file, HAMLIB_FILPATHLEN - 1); } my_rig->state.twiddle_timeout = twiddle_timeout; @@ -706,7 +706,7 @@ int main(int argc, char *argv[]) */ if (ptt_type != RIG_PTT_NONE) { - my_rig->state.pttport.type.ptt = ptt_type; + PTTPORT(my_rig)->type.ptt = ptt_type; my_rig->state.pttport_deprecated.type.ptt = ptt_type; // This causes segfault since backend rig_caps are const // rigctld will use the rig->state version of this for clients @@ -721,7 +721,7 @@ int main(int argc, char *argv[]) if (ptt_file) { - strncpy(my_rig->state.pttport.pathname, ptt_file, HAMLIB_FILPATHLEN - 1); + strncpy(PTTPORT(my_rig)->pathname, ptt_file, HAMLIB_FILPATHLEN - 1); strncpy(my_rig->state.pttport_deprecated.pathname, ptt_file, HAMLIB_FILPATHLEN - 1); } @@ -736,7 +736,7 @@ int main(int argc, char *argv[]) /* FIXME: bound checking and port type == serial */ if (serial_rate != 0) { - my_rig->state.rigport.parm.serial.rate = serial_rate; + RIGPORT(my_rig)->parm.serial.rate = serial_rate; my_rig->state.rigport_deprecated.parm.serial.rate = serial_rate; } diff --git a/tests/rigctlsync.c b/tests/rigctlsync.c index 54d287cd9..c71d99851 100644 --- a/tests/rigctlsync.c +++ b/tests/rigctlsync.c @@ -540,11 +540,11 @@ int main(int argc, char *argv[]) if (rig_file) { - strncpy(my_rig->state.rigport.pathname, rig_file, HAMLIB_FILPATHLEN - 1); + strncpy(RIGPORT(my_rig)->pathname, rig_file, HAMLIB_FILPATHLEN - 1); } fprintf(stderr, "rig to send frequency to: %s\n", rig_file2); - strncpy(my_rig_sync->state.rigport.pathname, rig_file2, HAMLIB_FILPATHLEN - 1); + strncpy(RIGPORT(my_rig_sync)->pathname, rig_file2, HAMLIB_FILPATHLEN - 1); #if 0 @@ -553,7 +553,7 @@ int main(int argc, char *argv[]) */ if (ptt_type != RIG_PTT_NONE) { - my_rig->state.pttport.type.ptt = ptt_type; + PTTPORT(my_rig)->type.ptt = ptt_type; } if (dcd_type != RIG_DCD_NONE) @@ -563,7 +563,7 @@ int main(int argc, char *argv[]) if (ptt_file) { - strncpy(my_rig->state.pttport.pathname, ptt_file, HAMLIB_FILPATHLEN - 1); + strncpy(PTTPORT(my_rig)->pathname, ptt_file, HAMLIB_FILPATHLEN - 1); } if (dcd_file) @@ -576,12 +576,12 @@ int main(int argc, char *argv[]) /* FIXME: bound checking and port type == serial */ if (serial_rate != 0) { - my_rig->state.rigport.parm.serial.rate = serial_rate; + RIGPORT(my_rig)->parm.serial.rate = serial_rate; } if (serial_rate2 != 0) { - my_rig_sync->state.rigport.parm.serial.rate = serial_rate2; + RIGPORT(my_rig_sync)->parm.serial.rate = serial_rate2; } diff --git a/tests/rigfreqwalk.c b/tests/rigfreqwalk.c index d5884c4f0..5ae1a1394 100644 --- a/tests/rigfreqwalk.c +++ b/tests/rigfreqwalk.c @@ -82,7 +82,7 @@ int main(int argc, const char *argv[]) exit(1); /* whoops! something went wrong (mem alloc?) */ } - strncpy(my_rig->state.rigport.pathname, argv[2], HAMLIB_FILPATHLEN - 1); + rig_set_conf(my_rig, rig_token_lookup(my_rig, "rig_pathname"), argv[2]); retcode = rig_open(my_rig); diff --git a/tests/rigmem.c b/tests/rigmem.c index e3a609a43..23fe12c28 100644 --- a/tests/rigmem.c +++ b/tests/rigmem.c @@ -283,13 +283,13 @@ int main(int argc, char *argv[]) if (rig_file) { - strncpy(rig->state.rigport.pathname, rig_file, HAMLIB_FILPATHLEN - 1); + strncpy(RIGPORT(rig)->pathname, rig_file, HAMLIB_FILPATHLEN - 1); } /* FIXME: bound checking and port type == serial */ if (serial_rate != 0) { - rig->state.rigport.parm.serial.rate = serial_rate; + RIGPORT(rig)->parm.serial.rate = serial_rate; } if (civaddr) diff --git a/tests/rigtestmcast.c b/tests/rigtestmcast.c index b5694ad7d..510691a7c 100644 --- a/tests/rigtestmcast.c +++ b/tests/rigtestmcast.c @@ -25,11 +25,11 @@ int main(int argc, const char *argv[]) } #ifdef _WIN32 - strncpy(rig->state.rigport.pathname, "COM37", HAMLIB_FILPATHLEN - 1); + strncpy(RIGPORT(rig)->pathname, "COM37", HAMLIB_FILPATHLEN - 1); #else - strncpy(rig->state.rigport.pathname, "/dev/ttyUSB0", HAMLIB_FILPATHLEN - 1); + strncpy(RIGPORT(rig)->pathname, "/dev/ttyUSB0", HAMLIB_FILPATHLEN - 1); #endif - rig->state.rigport.parm.serial.rate = 38400; + RIGPORT(rig)->parm.serial.rate = 38400; rig_open(rig); // disabled until we change this to the other multicast capability #if 0 diff --git a/tests/rotctl.c b/tests/rotctl.c index 12d6ce7e2..767cb4eaa 100644 --- a/tests/rotctl.c +++ b/tests/rotctl.c @@ -368,26 +368,26 @@ int main(int argc, char *argv[]) token = strtok(NULL, ","); } + hamlib_port_t *rotp = ROTPORT(my_rot); + hamlib_port_t *rotp2 = ROTPORT2(my_rot); if (rot_file) { - strncpy(my_rot->state.rotport.pathname, rot_file, HAMLIB_FILPATHLEN - 1); + strncpy(rotp->pathname, rot_file, HAMLIB_FILPATHLEN - 1); } if (rot_file2) { - strncpy(my_rot->state.rotport2.pathname, rot_file2, HAMLIB_FILPATHLEN - 1); + strncpy(rotp2->pathname, rot_file2, HAMLIB_FILPATHLEN - 1); } /* FIXME: bound checking and port type == serial */ - my_rot->state.rotport2.parm.serial.rate = - my_rot->state.rotport.parm.serial.rate; - my_rot->state.rotport2.parm.serial.data_bits = - my_rot->state.rotport.parm.serial.data_bits; + rotp2->parm.serial.rate = rotp->parm.serial.rate; + rotp2->parm.serial.data_bits = rotp->parm.serial.data_bits; if (serial_rate != 0) { - my_rot->state.rotport.parm.serial.rate = serial_rate; - my_rot->state.rotport2.parm.serial.rate = serial_rate; + rotp->parm.serial.rate = serial_rate; + rotp2->parm.serial.rate = serial_rate; } /* diff --git a/tests/rotctl_parse.c b/tests/rotctl_parse.c index 49c16135d..d266cf3c0 100644 --- a/tests/rotctl_parse.c +++ b/tests/rotctl_parse.c @@ -2507,7 +2507,7 @@ declare_proto_rot(dump_state) declare_proto_rot(send_cmd) { int retval; - struct rot_state *rs; + hamlib_port_t *rotp = ROTPORT(rot); int backend_num, cmd_len; #define BUFSZ 128 unsigned char bufcmd[BUFSZ]; @@ -2555,11 +2555,9 @@ declare_proto_rot(send_cmd) eom_buf[2] = send_cmd_term; } - rs = &rot->state; + rig_flush(rotp); - rig_flush(&rs->rotport); - - retval = write_block(&rs->rotport, bufcmd, cmd_len); + retval = write_block(rotp, bufcmd, cmd_len); if (retval != RIG_OK) { @@ -2577,7 +2575,7 @@ declare_proto_rot(send_cmd) * assumes CR or LF is end of line char * for all ascii protocols */ - retval = read_string(&rs->rotport, buf, BUFSZ, eom_buf, strlen(eom_buf), 0, 1); + retval = read_string(rotp, buf, BUFSZ, eom_buf, strlen(eom_buf), 0, 1); if (retval < 0) { diff --git a/tests/rotctld.c b/tests/rotctld.c index c231ce93d..0ec26c98f 100644 --- a/tests/rotctld.c +++ b/tests/rotctld.c @@ -376,18 +376,18 @@ int main(int argc, char *argv[]) if (rot_file) { - strncpy(my_rot->state.rotport.pathname, rot_file, HAMLIB_FILPATHLEN - 1); + strncpy(ROTPORT(my_rot)->pathname, rot_file, HAMLIB_FILPATHLEN - 1); } if (rot_file2) { - strncpy(my_rot->state.rotport2.pathname, rot_file2, HAMLIB_FILPATHLEN - 1); + strncpy(ROTPORT2(my_rot)->pathname, rot_file2, HAMLIB_FILPATHLEN - 1); } /* FIXME: bound checking and port type == serial */ if (serial_rate != 0) { - my_rot->state.rotport.parm.serial.rate = serial_rate; + ROTPORT(my_rot)->parm.serial.rate = serial_rate; } /* diff --git a/tests/sendraw.c b/tests/sendraw.c index 99c0ce356..6bcc5b6f4 100644 --- a/tests/sendraw.c +++ b/tests/sendraw.c @@ -2,6 +2,7 @@ #include #include #include +#define PATH "/dev/pts/4" int main() @@ -15,7 +16,7 @@ main() int retcode; my_rig = rig_init(2048); - strcpy(my_rig->state.rigport.pathname, "/dev/pts/4"); + rig_set_conf(my_rig, rig_token_lookup(my_rig, "rig_pathname"), PATH); retcode = rig_open(my_rig); diff --git a/tests/testcache.c b/tests/testcache.c index 017da657f..b1a3d3ef9 100644 --- a/tests/testcache.c +++ b/tests/testcache.c @@ -46,7 +46,7 @@ int main(int argc, char *argv[]) /* Set up serial port, baud rate */ - strncpy(my_rig->state.rigport.pathname, rig_file, HAMLIB_FILPATHLEN - 1); + rig_set_conf(my_rig, rig_token_lookup(my_rig, "rig_pathname"), rig_file); /* Open my rig */ retcode = rig_open(my_rig); diff --git a/tests/testrig.c b/tests/testrig.c index 578ed7750..212d356fa 100644 --- a/tests/testrig.c +++ b/tests/testrig.c @@ -68,7 +68,7 @@ int main(int argc, const char *argv[]) exit(1); /* whoops! something went wrong (mem alloc?) */ } - //strncpy(my_rig->state.rigport.pathname, SERIAL_PORT, HAMLIB_FILPATHLEN - 1); + //strncpy(RIGPORT(my_rig)->pathname, SERIAL_PORT, HAMLIB_FILPATHLEN - 1); retcode = rig_open(my_rig); diff --git a/tests/testrigopen.c b/tests/testrigopen.c index 76d535332..b98064a1e 100644 --- a/tests/testrigopen.c +++ b/tests/testrigopen.c @@ -30,7 +30,7 @@ int callback(struct rig_caps *caps, rig_ptr_t rigp) } const char *port = "/dev/pts/3"; - strcpy(rig->state.rigport.pathname, port); + rig_set_conf(rig, rig_token_lookup(rig, "rig_pathname"), port); printf("%20s:", caps->model_name); fflush(stdout);