From 790820ab22cde0b8a251356d3513ad41f20f1f3c Mon Sep 17 00:00:00 2001 From: Daniele Forsi IU5HKX Date: Mon, 4 Aug 2025 10:47:02 +0200 Subject: [PATCH] Refactor to remove code duplication of one version of getmyline() --- simulators/sim.h | 19 +++++++++++++++++++ simulators/simelecraft.c | 18 ------------------ simulators/simelecraftk4.c | 18 ------------------ simulators/simft450.c | 18 ------------------ simulators/simft710.c | 18 ------------------ simulators/simft818.c | 18 ------------------ simulators/simft991.c | 18 ------------------ simulators/simftdx101.c | 18 ------------------ simulators/simftdx1200.c | 18 ------------------ simulators/simftdx3000.c | 18 ------------------ simulators/simftdx5000.c | 18 ------------------ simulators/simkenwood.c | 18 ------------------ simulators/simpowersdr.c | 18 ------------------ simulators/simqrplabs.c | 18 ------------------ simulators/simtrusdx.c | 18 ------------------ simulators/simts450.c | 18 ------------------ simulators/simts890.c | 18 ------------------ simulators/simts950.c | 18 ------------------ simulators/simts990.c | 18 ------------------ simulators/simyaesu.c | 18 ------------------ 20 files changed, 19 insertions(+), 342 deletions(-) diff --git a/simulators/sim.h b/simulators/sim.h index afb889042..6d0122ec3 100644 --- a/simulators/sim.h +++ b/simulators/sim.h @@ -96,6 +96,25 @@ int openPort(char *comport) // doesn't matter for using pts devices // Size of command buffer #define BUFSIZE 256 +int +getmyline(int fd, char *buf) +{ + char c; + int i = 0; + memset(buf, 0, BUFSIZE); + + while (read(fd, &c, 1) > 0) + { + buf[i++] = c; + + if (c == ';') { return strlen(buf); } + } + + if (strlen(buf) == 0) { hl_usleep(10 * 1000); } + + return strlen(buf); +} + int getmyline5(int fd, unsigned char *buf) { diff --git a/simulators/simelecraft.c b/simulators/simelecraft.c index 500c5e1e2..38164ecb0 100644 --- a/simulators/simelecraft.c +++ b/simulators/simelecraft.c @@ -39,24 +39,6 @@ int modea = 2; int modeb = 2; int ptt = 0; -int -getmyline(int fd, char *buf) -{ - char c; - int i = 0; - memset(buf, 0, BUFSIZE); - - while (read(fd, &c, 1) > 0) - { - buf[i++] = c; - - if (c == ';') { return strlen(buf); } - } - - if (strlen(buf) == 0) { hl_usleep(10 * 1000); } - - return strlen(buf); -} diff --git a/simulators/simelecraftk4.c b/simulators/simelecraftk4.c index 2b63b0e78..bfb8d482e 100644 --- a/simulators/simelecraftk4.c +++ b/simulators/simelecraftk4.c @@ -39,24 +39,6 @@ int modeB = 2; int ptt = 0; // int freqa = 14074000, freqb = 14073500; -int -getmyline(int fd, char *buf) -{ - char c; - int i = 0; - memset(buf, 0, BUFSIZE); - - while (read(fd, &c, 1) > 0) - { - buf[i++] = c; - - if (c == ';') { return strlen(buf); } - } - - if (strlen(buf) == 0) { hl_usleep(10 * 1000); } - - return strlen(buf); -} diff --git a/simulators/simft450.c b/simulators/simft450.c index 8456e13dd..50b73f823 100644 --- a/simulators/simft450.c +++ b/simulators/simft450.c @@ -45,24 +45,6 @@ int gt = 0; int ex016 = 0; int ex020 = 0; -int -getmyline(int fd, char *buf) -{ - char c; - int i = 0; - memset(buf, 0, BUFSIZE); - - while (read(fd, &c, 1) > 0) - { - buf[i++] = c; - - if (c == ';') { return strlen(buf); } - } - - if (strlen(buf) == 0) { hl_usleep(10 * 1000); } - - return strlen(buf); -} #include "sim.h" diff --git a/simulators/simft710.c b/simulators/simft710.c index 83471fdfb..d3f01e6f4 100644 --- a/simulators/simft710.c +++ b/simulators/simft710.c @@ -46,24 +46,6 @@ int ex016 = 0; int ex020 = 0; int st = 0; -int -getmyline(int fd, char *buf) -{ - char c; - int i = 0; - memset(buf, 0, BUFSIZE); - - while (read(fd, &c, 1) > 0) - { - buf[i++] = c; - - if (c == ';') { return strlen(buf); } - } - - if (strlen(buf) == 0) { hl_usleep(10 * 1000); } - - return strlen(buf); -} #include "sim.h" diff --git a/simulators/simft818.c b/simulators/simft818.c index f14e7e002..e9843b2c8 100644 --- a/simulators/simft818.c +++ b/simulators/simft818.c @@ -21,24 +21,6 @@ char modeB = '1'; int width = 0; int ptt; -int -getmyline(int fd, char *buf) -{ - char c; - int i = 0; - memset(buf, 0, BUFSIZE); - - while (read(fd, &c, 1) > 0) - { - buf[i++] = c; - - if (c == ';') { return strlen(buf); } - } - - if (strlen(buf) == 0) { hl_usleep(10 * 1000); } - - return strlen(buf); -} #include "sim.h" diff --git a/simulators/simft991.c b/simulators/simft991.c index b9e4b9448..603007d85 100644 --- a/simulators/simft991.c +++ b/simulators/simft991.c @@ -24,24 +24,6 @@ int vd = 0; int sm0 = 0; int sm1 = 0; -int -getmyline(int fd, char *buf) -{ - char c; - int i = 0; - memset(buf, 0, BUFSIZE); - - while (read(fd, &c, 1) > 0) - { - buf[i++] = c; - - if (c == ';') { return strlen(buf); } - } - - if (strlen(buf) == 0) { hl_usleep(10 * 1000); } - - return strlen(buf); -} #include "sim.h" diff --git a/simulators/simftdx101.c b/simulators/simftdx101.c index 6bbde4374..1304f7f40 100644 --- a/simulators/simftdx101.c +++ b/simulators/simftdx101.c @@ -32,24 +32,6 @@ int rport_gain_psk = 50; int syncvfo = 0; int ant = 1; -int -getmyline(int fd, char *buf) -{ - char c; - int i = 0; - memset(buf, 0, BUFSIZE); - - while (read(fd, &c, 1) > 0) - { - buf[i++] = c; - - if (c == ';') { return strlen(buf); } - } - - if (strlen(buf) == 0) { hl_usleep(10 * 1000); } - - return strlen(buf); -} #include "sim.h" diff --git a/simulators/simftdx1200.c b/simulators/simftdx1200.c index d91db1c79..a53c8e0c7 100644 --- a/simulators/simftdx1200.c +++ b/simulators/simftdx1200.c @@ -23,24 +23,6 @@ int na = 0; int ex039 = 0; int keyspd = 20; -int -getmyline(int fd, char *buf) -{ - char c; - int i = 0; - memset(buf, 0, BUFSIZE); - - while (read(fd, &c, 1) > 0) - { - buf[i++] = c; - - if (c == ';') { return strlen(buf); } - } - - if (strlen(buf) == 0) { hl_usleep(10 * 1000); } - - return strlen(buf); -} #include "sim.h" diff --git a/simulators/simftdx3000.c b/simulators/simftdx3000.c index dbfa63d51..8e7917062 100644 --- a/simulators/simftdx3000.c +++ b/simulators/simftdx3000.c @@ -22,24 +22,6 @@ int sh = 25; int na = 0; int ex039 = 0; -int -getmyline(int fd, char *buf) -{ - char c; - int i = 0; - memset(buf, 0, BUFSIZE); - - while (read(fd, &c, 1) > 0) - { - buf[i++] = c; - - if (c == ';') { return strlen(buf); } - } - - if (strlen(buf) == 0) { hl_usleep(10 * 1000); } - - return strlen(buf); -} #include "sim.h" diff --git a/simulators/simftdx5000.c b/simulators/simftdx5000.c index a60d39380..034e528d1 100644 --- a/simulators/simftdx5000.c +++ b/simulators/simftdx5000.c @@ -24,24 +24,6 @@ int na = 0; int ex039 = 0; int ex103 = 0; -int -getmyline(int fd, char *buf) -{ - char c; - int i = 0; - memset(buf, 0, BUFSIZE); - - while (read(fd, &c, 1) > 0) - { - buf[i++] = c; - - if (c == ';') { return strlen(buf); } - } - - if (strlen(buf) == 0) { hl_usleep(10 * 1000); } - - return strlen(buf); -} #include "sim.h" diff --git a/simulators/simkenwood.c b/simulators/simkenwood.c index 0ec10f0c7..bdf1b780f 100644 --- a/simulators/simkenwood.c +++ b/simulators/simkenwood.c @@ -18,24 +18,6 @@ int filternum = 7; int datamode = 0; int vfo, vfo_tx, ptt, ptt_data, ptt_mic, ptt_tune; -int -getmyline(int fd, char *buf) -{ - char c; - int i = 0; - memset(buf, 0, BUFSIZE); - - while (read(fd, &c, 1) > 0) - { - buf[i++] = c; - - if (c == ';') { return strlen(buf); } - } - - if (strlen(buf) == 0) { hl_usleep(10 * 1000); } - - return strlen(buf); -} #include "sim.h" diff --git a/simulators/simpowersdr.c b/simulators/simpowersdr.c index 5049702f5..d38276929 100644 --- a/simulators/simpowersdr.c +++ b/simulators/simpowersdr.c @@ -19,24 +19,6 @@ int keyspd = 20; double alc = 0; int tx; -int -getmyline(int fd, char *buf) -{ - char c; - int i = 0; - memset(buf, 0, BUFSIZE); - - while (read(fd, &c, 1) > 0) - { - buf[i++] = c; - - if (c == ';') { return strlen(buf); } - } - - if (strlen(buf) == 0) { hl_usleep(10 * 1000); } - - return strlen(buf); -} #include "sim.h" diff --git a/simulators/simqrplabs.c b/simulators/simqrplabs.c index 4492e28f1..be177e2e3 100644 --- a/simulators/simqrplabs.c +++ b/simulators/simqrplabs.c @@ -20,24 +20,6 @@ int datamode = 0; int vfo, vfo_tx, ptt, ptt_data, ptt_mic, ptt_tune; int tomode = 0; -int -getmyline(int fd, char *buf) -{ - char c; - int i = 0; - memset(buf, 0, BUFSIZE); - - while (read(fd, &c, 1) > 0) - { - buf[i++] = c; - - if (c == ';') { return strlen(buf); } - } - - if (strlen(buf) == 0) { hl_usleep(10 * 1000); } - - return strlen(buf); -} #include "sim.h" diff --git a/simulators/simtrusdx.c b/simulators/simtrusdx.c index c666f012f..ac51c0bbf 100644 --- a/simulators/simtrusdx.c +++ b/simulators/simtrusdx.c @@ -21,24 +21,6 @@ int vfo, vfo_tx, ptt, ptt_data, ptt_mic, ptt_tune; int tomode = 0; int keyspd = 25; -int -getmyline(int fd, char *buf) -{ - char c; - int i = 0; - memset(buf, 0, BUFSIZE); - - while (read(fd, &c, 1) > 0) - { - buf[i++] = c; - - if (c == ';') { return strlen(buf); } - } - - if (strlen(buf) == 0) { hl_usleep(10 * 1000); } - - return strlen(buf); -} #include "sim.h" diff --git a/simulators/simts450.c b/simulators/simts450.c index 7e5b87bd1..6d159eafc 100644 --- a/simulators/simts450.c +++ b/simulators/simts450.c @@ -21,24 +21,6 @@ int vfo, vfo_tx, ptt, ptt_data, ptt_mic, ptt_tune; int tomode = 0; int keyspd = 25; -int -getmyline(int fd, char *buf) -{ - char c; - int i = 0; - memset(buf, 0, BUFSIZE); - - while (read(fd, &c, 1) > 0) - { - buf[i++] = c; - - if (c == ';') { return strlen(buf); } - } - - if (strlen(buf) == 0) { hl_usleep(10 * 1000); } - - return strlen(buf); -} #include "sim.h" diff --git a/simulators/simts890.c b/simulators/simts890.c index 25d6f357a..4d78c3a83 100644 --- a/simulators/simts890.c +++ b/simulators/simts890.c @@ -212,24 +212,6 @@ int hl_usleep(unsigned long usec); // Until it's replaced #include "sim.h" -int -getmyline(int fd, char *buf) -{ - char c; - int i = 0; - memset(buf, 0, BUFSIZE); - - while (read(fd, &c, 1) > 0) - { - buf[i++] = c; - - if (c == ';') { return strlen(buf); } - } - - if (strlen(buf) == 0) { hl_usleep(10 * 1000); } - - return strlen(buf); -} int main(int argc, char *argv[]) { diff --git a/simulators/simts950.c b/simulators/simts950.c index 5baaabdc2..50cc626af 100644 --- a/simulators/simts950.c +++ b/simulators/simts950.c @@ -20,24 +20,6 @@ int filternum2 = 8; int datamode = 0; int vfo, vfo_tx, ptt, ptt_data, ptt_mic, ptt_tune; -int -getmyline(int fd, char *buf) -{ - char c; - int i = 0; - memset(buf, 0, BUFSIZE); - - while (read(fd, &c, 1) > 0) - { - buf[i++] = c; - - if (c == ';') { return strlen(buf); } - } - - if (strlen(buf) == 0) { hl_usleep(10 * 1000); } - - return strlen(buf); -} #include "sim.h" diff --git a/simulators/simts990.c b/simulators/simts990.c index c321f9ccb..5285dbcda 100644 --- a/simulators/simts990.c +++ b/simulators/simts990.c @@ -62,24 +62,6 @@ int pc = 50; #include "sim.h" -int -getmyline(int fd, char *buf) -{ - char c; - int i = 0; - memset(buf, 0, BUFSIZE); - - while (read(fd, &c, 1) > 0) - { - buf[i++] = c; - - if (c == ';') { return strlen(buf); } - } - - if (strlen(buf) == 0) { hl_usleep(10 * 1000); } - - return strlen(buf); -} diff --git a/simulators/simyaesu.c b/simulators/simyaesu.c index ea126f8fd..9a79ee759 100644 --- a/simulators/simyaesu.c +++ b/simulators/simyaesu.c @@ -26,24 +26,6 @@ int width_sub = 0; int ex039 = 0; int lk = 0; -int -getmyline(int fd, char *buf) -{ - char c; - int i = 0; - memset(buf, 0, BUFSIZE); - - while (read(fd, &c, 1) > 0) - { - buf[i++] = c; - - if (c == ';') { return strlen(buf); } - } - - if (strlen(buf) == 0) { hl_usleep(10 * 1000); } - - return strlen(buf); -} #include "sim.h"