Skip to content

Commit

Permalink
Convert tests/* to pointers
Browse files Browse the repository at this point in the history
  • Loading branch information
GeoBaltz committed Mar 1, 2024
1 parent 55db738 commit 07f8023
Show file tree
Hide file tree
Showing 19 changed files with 51 additions and 52 deletions.
4 changes: 2 additions & 2 deletions tests/ampctld.c
Expand Up @@ -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;
}

/*
Expand Down
4 changes: 2 additions & 2 deletions tests/cachetest.c
Expand Up @@ -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);
Expand Down
2 changes: 1 addition & 1 deletion tests/cachetest2.c
Expand Up @@ -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);
Expand Down
2 changes: 1 addition & 1 deletion tests/callback.c
Expand Up @@ -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);
Expand Down
2 changes: 1 addition & 1 deletion tests/dumpmem.c
Expand Up @@ -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))
{
Expand Down
8 changes: 4 additions & 4 deletions tests/rigctl.c
Expand Up @@ -592,15 +592,15 @@ 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);
}

/*
* ex: RIG_PTT_PARALLEL and /dev/parport0
*/
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)
Expand All @@ -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)
Expand All @@ -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;
}

Expand Down
8 changes: 4 additions & 4 deletions tests/rigctlcom.c
Expand Up @@ -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)
Expand All @@ -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)
Expand All @@ -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)
Expand All @@ -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)
Expand Down
8 changes: 4 additions & 4 deletions tests/rigctld.c
Expand Up @@ -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;
Expand All @@ -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
Expand All @@ -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);
}
Expand All @@ -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;
}

Expand Down
12 changes: 6 additions & 6 deletions tests/rigctlsync.c
Expand Up @@ -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

Expand All @@ -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)
Expand All @@ -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)
Expand All @@ -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;
}


Expand Down
2 changes: 1 addition & 1 deletion tests/rigfreqwalk.c
Expand Up @@ -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);

Expand Down
4 changes: 2 additions & 2 deletions tests/rigmem.c
Expand Up @@ -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)
Expand Down
6 changes: 3 additions & 3 deletions tests/rigtestmcast.c
Expand Up @@ -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
Expand Down
16 changes: 8 additions & 8 deletions tests/rotctl.c
Expand Up @@ -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;
}

/*
Expand Down
10 changes: 4 additions & 6 deletions tests/rotctl_parse.c
Expand Up @@ -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];
Expand Down Expand Up @@ -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)
{
Expand All @@ -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)
{
Expand Down
6 changes: 3 additions & 3 deletions tests/rotctld.c
Expand Up @@ -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;
}

/*
Expand Down
3 changes: 2 additions & 1 deletion tests/sendraw.c
Expand Up @@ -2,6 +2,7 @@
#include <stdio.h>
#include <stdlib.h>
#include <hamlib/rig.h>
#define PATH "/dev/pts/4"

int
main()
Expand All @@ -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);

Expand Down
2 changes: 1 addition & 1 deletion tests/testcache.c
Expand Up @@ -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);
Expand Down
2 changes: 1 addition & 1 deletion tests/testrig.c
Expand Up @@ -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);

Expand Down
2 changes: 1 addition & 1 deletion tests/testrigopen.c
Expand Up @@ -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);
Expand Down

0 comments on commit 07f8023

Please sign in to comment.