diff --git a/tests/dumpcaps.c b/tests/dumpcaps.c index 26de7256a..6ed40d55c 100644 --- a/tests/dumpcaps.c +++ b/tests/dumpcaps.c @@ -51,7 +51,8 @@ int dumpcaps(RIG *rig, FILE *fout) int backend_warnings = 0; static char prntbuf[1024]; /* a malloc would be better.. */ - if (!rig || !rig->caps) { + if (!rig || !rig->caps) + { return -RIG_EINVAL; } @@ -65,7 +66,8 @@ int dumpcaps(RIG *rig, FILE *fout) fprintf(fout, "Backend status:\t%s\n", rig_strstatus(caps->status)); fprintf(fout, "Rig type:\t"); - switch (caps->rig_type & RIG_TYPE_MASK) { + switch (caps->rig_type & RIG_TYPE_MASK) + { case RIG_TYPE_TRANSCEIVER: fprintf(fout, "Transceiver\n"); break; @@ -113,7 +115,8 @@ int dumpcaps(RIG *rig, FILE *fout) fprintf(fout, "PTT type:\t"); - switch (caps->ptt_type) { + switch (caps->ptt_type) + { case RIG_PTT_RIG: fprintf(fout, "Rig capable\n"); break; @@ -145,7 +148,8 @@ int dumpcaps(RIG *rig, FILE *fout) fprintf(fout, "DCD type:\t"); - switch (caps->dcd_type) { + switch (caps->dcd_type) + { case RIG_DCD_RIG: fprintf(fout, "Rig capable\n"); break; @@ -177,7 +181,8 @@ int dumpcaps(RIG *rig, FILE *fout) fprintf(fout, "Port type:\t"); - switch (caps->port_type) { + switch (caps->port_type) + { case RIG_PORT_SERIAL: fprintf(fout, "RS-232\n"); fprintf(fout, @@ -186,9 +191,9 @@ int dumpcaps(RIG *rig, FILE *fout) caps->serial_rate_max, caps->serial_data_bits, caps->serial_parity == RIG_PARITY_NONE ? 'N' : - caps->serial_parity == RIG_PARITY_ODD ? 'O' : - caps->serial_parity == RIG_PARITY_EVEN ? 'E' : - caps->serial_parity == RIG_PARITY_MARK ? 'M' : 'S', + caps->serial_parity == RIG_PARITY_ODD ? 'O' : + caps->serial_parity == RIG_PARITY_EVEN ? 'E' : + caps->serial_parity == RIG_PARITY_MARK ? 'M' : 'S', caps->serial_stop_bits, caps->serial_handshake == RIG_HANDSHAKE_NONE ? "" : (caps->serial_handshake == RIG_HANDSHAKE_XONXOFF ? "XONXOFF" : "CTS/RTS") @@ -257,22 +262,26 @@ int dumpcaps(RIG *rig, FILE *fout) fprintf(fout, "Preamp:"); - for (i = 0; i < MAXDBLSTSIZ && caps->preamp[i] != 0; i++) { + for (i = 0; i < MAXDBLSTSIZ && caps->preamp[i] != 0; i++) + { fprintf(fout, " %ddB", caps->preamp[i]); } - if (i == 0) { + if (i == 0) + { fprintf(fout, " None"); } fprintf(fout, "\n"); fprintf(fout, "Attenuator:"); - for (i = 0; i < MAXDBLSTSIZ && caps->attenuator[i] != 0; i++) { + for (i = 0; i < MAXDBLSTSIZ && caps->attenuator[i] != 0; i++) + { fprintf(fout, " %ddB", caps->attenuator[i]); } - if (i == 0) { + if (i == 0) + { fprintf(fout, " None"); } @@ -280,15 +289,19 @@ int dumpcaps(RIG *rig, FILE *fout) fprintf(fout, "CTCSS:"); - for (i = 0; caps->ctcss_list && i < 60 && caps->ctcss_list[i] != 0; i++) { + for (i = 0; caps->ctcss_list && i < 60 && caps->ctcss_list[i] != 0; i++) + { fprintf(fout, " %d.%1d", caps->ctcss_list[i] / 10, caps->ctcss_list[i] % 10); } - if (i == 0) { + if (i == 0) + { fprintf(fout, " None"); - } else { + } + else + { fprintf(fout, " Hz, %d tones", i); } @@ -296,13 +309,17 @@ int dumpcaps(RIG *rig, FILE *fout) fprintf(fout, "DCS:"); - for (i = 0; caps->dcs_list && i < 128 && caps->dcs_list[i] != 0; i++) { + for (i = 0; caps->dcs_list && i < 128 && caps->dcs_list[i] != 0; i++) + { fprintf(fout, " %d", caps->dcs_list[i]); } - if (i == 0) { + if (i == 0) + { fprintf(fout, " None"); - } else { + } + else + { fprintf(fout, ", %d codes", i); } @@ -317,24 +334,27 @@ int dumpcaps(RIG *rig, FILE *fout) sprintf_level_gran(prntbuf, caps->has_get_level, caps->level_gran); fprintf(fout, "Get level: %s\n", prntbuf); - if ((caps->has_get_level & RIG_LEVEL_SQLSTAT)) { + if ((caps->has_get_level & RIG_LEVEL_SQLSTAT)) + { fprintf(fout, "Warning--backend uses deprecated SQLSTAT level!\n"); backend_warnings++; } if ((caps->has_get_level & RIG_LEVEL_RAWSTR) && caps->str_cal.size == 0 - && !(caps->has_get_level & RIG_LEVEL_STRENGTH)) { + && !(caps->has_get_level & RIG_LEVEL_STRENGTH)) + { - fprintf(fout, - "Warning--backend has get RAWSTR, but not calibration data\n"); - backend_warnings++; + fprintf(fout, + "Warning--backend has get RAWSTR, but not calibration data\n"); + backend_warnings++; } sprintf_level_gran(prntbuf, caps->has_set_level, caps->level_gran); fprintf(fout, "Set level: %s\n", prntbuf); - if (caps->has_set_level & RIG_LEVEL_READONLY_LIST) { + if (caps->has_set_level & RIG_LEVEL_READONLY_LIST) + { fprintf(fout, "Warning--backend can set readonly levels!\n"); backend_warnings++; } @@ -349,7 +369,8 @@ int dumpcaps(RIG *rig, FILE *fout) sprintf_parm_gran(prntbuf, caps->has_set_parm, caps->parm_gran); fprintf(fout, "Set parameters: %s\n", prntbuf); - if (caps->has_set_parm & RIG_PARM_READONLY_LIST) { + if (caps->has_set_parm & RIG_PARM_READONLY_LIST) + { fprintf(fout, "Warning--backend can set readonly parms!\n"); backend_warnings++; } @@ -359,18 +380,24 @@ int dumpcaps(RIG *rig, FILE *fout) fprintf(fout, "\n"); - if (rig->state.mode_list != 0) { + if (rig->state.mode_list != 0) + { sprintf_mode(prntbuf, rig->state.mode_list); - } else { + } + else + { strcpy(prntbuf, "None. This backend might be bogus!\n"); backend_warnings++; } fprintf(fout, "Mode list: %s\n", prntbuf); - if (rig->state.vfo_list != 0) { + if (rig->state.vfo_list != 0) + { sprintf_vfo(prntbuf, rig->state.vfo_list); - } else { + } + else + { strcpy(prntbuf, "None. This backend might be bogus!\n"); backend_warnings++; } @@ -388,7 +415,8 @@ int dumpcaps(RIG *rig, FILE *fout) fprintf(fout, "Memories:"); - for (i = 0; i < CHANLSTSIZ && caps->chan_list[i].type; i++) { + for (i = 0; i < CHANLSTSIZ && caps->chan_list[i].type; i++) + { fprintf(fout, "\n\t%d..%d: \t%s", caps->chan_list[i].start, @@ -398,7 +426,8 @@ int dumpcaps(RIG *rig, FILE *fout) dump_chan_caps(&caps->chan_list[i].mem_caps, fout); } - if (i == 0) { + if (i == 0) + { fprintf(fout, " None"); } @@ -411,7 +440,8 @@ int dumpcaps(RIG *rig, FILE *fout) status ? "Bad" : "OK", status); - if (status) { + if (status) + { backend_warnings++; } @@ -421,7 +451,8 @@ int dumpcaps(RIG *rig, FILE *fout) status ? "Bad" : "OK", status); - if (status) { + if (status) + { backend_warnings++; } @@ -431,7 +462,8 @@ int dumpcaps(RIG *rig, FILE *fout) status ? "Bad" : "OK", status); - if (status) { + if (status) + { backend_warnings++; } @@ -441,16 +473,21 @@ int dumpcaps(RIG *rig, FILE *fout) status ? "Bad" : "OK", status); - if (status) { + if (status) + { backend_warnings++; } fprintf(fout, "Tuning steps:"); - for (i = 0; i < TSLSTSIZ && !RIG_IS_TS_END(caps->tuning_steps[i]); i++) { - if (caps->tuning_steps[i].ts == RIG_TS_ANY) { + for (i = 0; i < TSLSTSIZ && !RIG_IS_TS_END(caps->tuning_steps[i]); i++) + { + if (caps->tuning_steps[i].ts == RIG_TS_ANY) + { strcpy(freqbuf, "ANY"); /* strcpy! Looks safe for now */ - } else { + } + else + { sprintf_freq(freqbuf, caps->tuning_steps[i].ts); } @@ -458,7 +495,8 @@ int dumpcaps(RIG *rig, FILE *fout) fprintf(fout, "\n\t%s: \t%s", freqbuf, prntbuf); } - if (i == 0) { + if (i == 0) + { fprintf(fout, " None! This backend might be bogus!"); backend_warnings++; } @@ -467,16 +505,21 @@ int dumpcaps(RIG *rig, FILE *fout) status = ts_sanity_check(caps->tuning_steps); fprintf(fout, "Tuning steps status:\t%s (%d)\n", status ? "Bad" : "OK", status); - if (status) { + if (status) + { backend_warnings++; } fprintf(fout, "Filters:"); - for (i = 0; i < FLTLSTSIZ && !RIG_IS_FLT_END(caps->filters[i]); i++) { - if (caps->filters[i].width == RIG_FLT_ANY) { + for (i = 0; i < FLTLSTSIZ && !RIG_IS_FLT_END(caps->filters[i]); i++) + { + if (caps->filters[i].width == RIG_FLT_ANY) + { strcpy(freqbuf, "ANY"); - } else { + } + else + { sprintf_freq(freqbuf, caps->filters[i].width); } @@ -484,7 +527,8 @@ int dumpcaps(RIG *rig, FILE *fout) fprintf(fout, "\n\t%s: \t%s", freqbuf, prntbuf); } - if (i == 0) { + if (i == 0) + { fprintf(fout, " None. This backend might be bogus!"); backend_warnings++; } @@ -493,10 +537,12 @@ int dumpcaps(RIG *rig, FILE *fout) fprintf(fout, "Bandwidths:"); - for (i = 1; i < RIG_MODE_TESTS_MAX; i <<= 1) { + for (i = 1; i < RIG_MODE_TESTS_MAX; i <<= 1) + { pbwidth_t pbnorm = rig_passband_normal(rig, i); - if (pbnorm == 0) { + if (pbnorm == 0) + { continue; } @@ -690,35 +736,46 @@ int range_sanity_check(const struct freq_range_list range_list[], int rx) { int i; - for (i = 0; i < FRQRANGESIZ; i++) { - if (range_list[i].start == 0 && range_list[i].end == 0) { + for (i = 0; i < FRQRANGESIZ; i++) + { + if (range_list[i].start == 0 && range_list[i].end == 0) + { break; } - if (range_list[i].start > range_list[i].end) { + if (range_list[i].start > range_list[i].end) + { return -1; } - if (range_list[i].modes == 0) { + if (range_list[i].modes == 0) + { return -2; } - if (rx) { - if (range_list[i].low_power > 0 && range_list[i].high_power > 0) { + if (rx) + { + if (range_list[i].low_power > 0 && range_list[i].high_power > 0) + { return -3; } - } else { - if (!(range_list[i].low_power > 0 && range_list[i].high_power > 0)) { + } + else + { + if (!(range_list[i].low_power > 0 && range_list[i].high_power > 0)) + { return -3; } - if (range_list[i].low_power > range_list[i].high_power) { + if (range_list[i].low_power > range_list[i].high_power) + { return -3; } } } - if (i == FRQRANGESIZ) { + if (i == FRQRANGESIZ) + { return -4; } @@ -742,19 +799,23 @@ int ts_sanity_check(const struct tuning_step_list tuning_step[]) last_ts = 0; last_modes = RIG_MODE_NONE; - for (i = 0; i < TSLSTSIZ; i++) { - if (RIG_IS_TS_END(tuning_step[i])) { + for (i = 0; i < TSLSTSIZ; i++) + { + if (RIG_IS_TS_END(tuning_step[i])) + { break; } if (tuning_step[i].ts != RIG_TS_ANY && tuning_step[i].ts < last_ts - && last_modes == tuning_step[i].modes) { + && last_modes == tuning_step[i].modes) + { - return -1; + return -1; } - if (tuning_step[i].modes == 0) { + if (tuning_step[i].modes == 0) + { return -2; } @@ -762,7 +823,8 @@ int ts_sanity_check(const struct tuning_step_list tuning_step[]) last_modes = tuning_step[i].modes; } - if (i == TSLSTSIZ) { + if (i == TSLSTSIZ) + { return -4; } @@ -772,99 +834,123 @@ int ts_sanity_check(const struct tuning_step_list tuning_step[]) static void dump_chan_caps(const channel_cap_t *chan, FILE *fout) { - if (chan->bank_num) { + if (chan->bank_num) + { fprintf(fout, "BANK "); } - if (chan->ant) { + if (chan->ant) + { fprintf(fout, "ANT "); } - if (chan->freq) { + if (chan->freq) + { fprintf(fout, "FREQ "); } - if (chan->mode) { + if (chan->mode) + { fprintf(fout, "MODE "); } - if (chan->width) { + if (chan->width) + { fprintf(fout, "WIDTH "); } - if (chan->tx_freq) { + if (chan->tx_freq) + { fprintf(fout, "TXFREQ "); } - if (chan->tx_mode) { + if (chan->tx_mode) + { fprintf(fout, "TXMODE "); } - if (chan->tx_width) { + if (chan->tx_width) + { fprintf(fout, "TXWIDTH "); } - if (chan->split) { + if (chan->split) + { fprintf(fout, "SPLIT "); } - if (chan->rptr_shift) { + if (chan->rptr_shift) + { fprintf(fout, "RPTRSHIFT "); } - if (chan->rptr_offs) { + if (chan->rptr_offs) + { fprintf(fout, "RPTROFS "); } - if (chan->tuning_step) { + if (chan->tuning_step) + { fprintf(fout, "TS "); } - if (chan->rit) { + if (chan->rit) + { fprintf(fout, "RIT "); } - if (chan->xit) { + if (chan->xit) + { fprintf(fout, "XIT "); } - if (chan->funcs) { + if (chan->funcs) + { fprintf(fout, "FUNC "); /* TODO: iterate over the list */ } - if (chan->levels) { + if (chan->levels) + { fprintf(fout, "LEVEL "); /* TODO: iterate over the list */ } - if (chan->ctcss_tone) { + if (chan->ctcss_tone) + { fprintf(fout, "TONE "); } - if (chan->ctcss_sql) { + if (chan->ctcss_sql) + { fprintf(fout, "CTCSS "); } - if (chan->dcs_code) { + if (chan->dcs_code) + { fprintf(fout, "DCSCODE "); } - if (chan->dcs_sql) { + if (chan->dcs_sql) + { fprintf(fout, "DCSSQL "); } - if (chan->scan_group) { + if (chan->scan_group) + { fprintf(fout, "SCANGRP "); } - if (chan->flags) { + if (chan->flags) + { fprintf(fout, "FLAG "); /* TODO: iterate over the RIG_CHFLAG's */ } - if (chan->channel_desc) { + if (chan->channel_desc) + { fprintf(fout, "NAME "); } - if (chan->ext_levels) { + if (chan->ext_levels) + { fprintf(fout, "EXTLVL "); } } diff --git a/tests/dumpcaps_rot.c b/tests/dumpcaps_rot.c index b5d18f5d4..f6b2ee103 100644 --- a/tests/dumpcaps_rot.c +++ b/tests/dumpcaps_rot.c @@ -42,7 +42,8 @@ int dumpcaps_rot(ROT *rot, FILE *fout) const struct rot_caps *caps; int backend_warnings = 0; - if (!rot || !rot->caps) { + if (!rot || !rot->caps) + { return -RIG_EINVAL; } @@ -56,7 +57,8 @@ int dumpcaps_rot(ROT *rot, FILE *fout) fprintf(fout, "Backend status:\t\t%s\n", rig_strstatus(caps->status)); fprintf(fout, "Rot type:\t\t"); - switch (caps->rot_type & ROT_TYPE_MASK) { + switch (caps->rot_type & ROT_TYPE_MASK) + { case ROT_TYPE_OTHER: fprintf(fout, "Other\n"); break; @@ -80,7 +82,8 @@ int dumpcaps_rot(ROT *rot, FILE *fout) fprintf(fout, "Port type:\t\t"); - switch (caps->port_type) { + switch (caps->port_type) + { case RIG_PORT_SERIAL: fprintf(fout, "RS-232\n"); fprintf(fout, @@ -88,10 +91,10 @@ int dumpcaps_rot(ROT *rot, FILE *fout) caps->serial_rate_min, caps->serial_rate_max, caps->serial_data_bits, - caps->serial_parity == RIG_PARITY_NONE ? 'N' : - caps->serial_parity == RIG_PARITY_ODD ? 'O' : - caps->serial_parity == RIG_PARITY_EVEN ? 'E' : - caps->serial_parity == RIG_PARITY_MARK ? 'M' : 'S', + caps->serial_parity == RIG_PARITY_NONE ? 'N' : + caps->serial_parity == RIG_PARITY_ODD ? 'O' : + caps->serial_parity == RIG_PARITY_EVEN ? 'E' : + caps->serial_parity == RIG_PARITY_MARK ? 'M' : 'S', caps->serial_stop_bits, caps->serial_handshake == RIG_HANDSHAKE_NONE ? "" : (caps->serial_handshake == RIG_HANDSHAKE_XONXOFF ? " XONXOFF" : " CTS/RTS") diff --git a/tests/dumpmem.c b/tests/dumpmem.c index 8b4336abd..c07a80d7e 100644 --- a/tests/dumpmem.c +++ b/tests/dumpmem.c @@ -44,14 +44,16 @@ int main(int argc, char *argv[]) RIG *my_rig; int status, i, j; - if (argc != 2) { + if (argc != 2) + { fprintf(stderr, "%s \n", argv[0]); exit(1); } my_rig = rig_init(atoi(argv[1])); - if (!my_rig) { + if (!my_rig) + { fprintf(stderr, "Unknown rig num: %d\n", atoi(argv[1])); fprintf(stderr, "Please check riglist.h\n"); exit(1); /* whoops! something went wrong (mem alloc?) */ @@ -59,14 +61,16 @@ int main(int argc, char *argv[]) strncpy(my_rig->state.rigport.pathname, SERIAL_PORT, FILPATHLEN - 1); - if (rig_open(my_rig)) { + if (rig_open(my_rig)) + { exit(2); } status = rig_set_vfo(my_rig, RIG_VFO_B); - if (status != RIG_OK) { + if (status != RIG_OK) + { printf("rig_set_vfo: error = %s \n", rigerror(status)); } @@ -82,9 +86,11 @@ int main(int argc, char *argv[]) * } */ - for (i = 0; my_rig->state.chan_list[i].type && i < CHANLSTSIZ; i++) { + for (i = 0; my_rig->state.chan_list[i].type && i < CHANLSTSIZ; i++) + { for (j = my_rig->state.chan_list[i].start; - j <= my_rig->state.chan_list[i].end; j++) { + j <= my_rig->state.chan_list[i].end; j++) + { dump_chan(my_rig, j); } } @@ -108,33 +114,40 @@ static char * decode_modes(rmode_t modes) buf[0] = '\0'; - if (modes & RIG_MODE_AM) { + if (modes & RIG_MODE_AM) + { strcat(buf, "AM "); } - if (modes & RIG_MODE_CW) { + if (modes & RIG_MODE_CW) + { strcat(buf, "CW "); } - if (modes & RIG_MODE_USB) { + if (modes & RIG_MODE_USB) + { strcat(buf, "USB "); } - if (modes & RIG_MODE_LSB) { + if (modes & RIG_MODE_LSB) + { strcat(buf, "LSB "); } - if (modes & RIG_MODE_RTTY) { + if (modes & RIG_MODE_RTTY) + { strcat(buf, "RTTY "); } - if (modes & RIG_MODE_FM) { + if (modes & RIG_MODE_FM) + { strcat(buf, "FM "); } #ifdef RIG_MODE_WFM - if (modes & RIG_MODE_WFM) { + if (modes & RIG_MODE_WFM) + { strcat(buf, "WFM "); } @@ -154,7 +167,8 @@ int dump_chan(RIG *rig, int chan_num) chan.channel_num = chan_num; status = rig_get_channel(rig, &chan); - if (status != RIG_OK) { + if (status != RIG_OK) + { printf("rig_get_channel: error = %s \n", rigerror(status)); return status; } @@ -199,150 +213,187 @@ int dump_chan(RIG *rig, int chan_num) printf("Functions: "); - if (chan.funcs != 0) { - if (chan.funcs & RIG_FUNC_FAGC) { + if (chan.funcs != 0) + { + if (chan.funcs & RIG_FUNC_FAGC) + { printf("FAGC "); } - if (chan.funcs & RIG_FUNC_NB) { + if (chan.funcs & RIG_FUNC_NB) + { printf("NB "); } - if (chan.funcs & RIG_FUNC_COMP) { + if (chan.funcs & RIG_FUNC_COMP) + { printf("COMP "); } - if (chan.funcs & RIG_FUNC_VOX) { + if (chan.funcs & RIG_FUNC_VOX) + { printf("VOX "); } - if (chan.funcs & RIG_FUNC_TONE) { + if (chan.funcs & RIG_FUNC_TONE) + { printf("TONE "); } - if (chan.funcs & RIG_FUNC_TSQL) { + if (chan.funcs & RIG_FUNC_TSQL) + { printf("TSQL "); } - if (chan.funcs & RIG_FUNC_SBKIN) { + if (chan.funcs & RIG_FUNC_SBKIN) + { printf("SBKIN "); } - if (chan.funcs & RIG_FUNC_FBKIN) { + if (chan.funcs & RIG_FUNC_FBKIN) + { printf("FBKIN "); } - if (chan.funcs & RIG_FUNC_ANF) { + if (chan.funcs & RIG_FUNC_ANF) + { printf("ANF "); } - if (chan.funcs & RIG_FUNC_NR) { + if (chan.funcs & RIG_FUNC_NR) + { printf("NR "); } - if (chan.funcs & RIG_FUNC_AIP) { + if (chan.funcs & RIG_FUNC_AIP) + { printf("AIP "); } - if (chan.funcs & RIG_FUNC_APF) { + if (chan.funcs & RIG_FUNC_APF) + { printf("APF "); } - if (chan.funcs & RIG_FUNC_MON) { + if (chan.funcs & RIG_FUNC_MON) + { printf("MON "); } - if (chan.funcs & RIG_FUNC_MN) { + if (chan.funcs & RIG_FUNC_MN) + { printf("MN "); } - if (chan.funcs & RIG_FUNC_RF) { + if (chan.funcs & RIG_FUNC_RF) + { printf("RF "); } printf("\n"); - } else { + } + else + { printf("none\n"); } - if (rig_has_set_level(rig, RIG_LEVEL_PREAMP)) { + if (rig_has_set_level(rig, RIG_LEVEL_PREAMP)) + { printf("PREAMP: %ddB\n", chan.levels[rig_setting2idx(RIG_LEVEL_PREAMP)].i); } - if (rig_has_set_level(rig, RIG_LEVEL_ATT)) { + if (rig_has_set_level(rig, RIG_LEVEL_ATT)) + { printf("ATT: %ddB\n", chan.levels[rig_setting2idx(RIG_LEVEL_ATT)].i); } - if (rig_has_set_level(rig, RIG_LEVEL_AF)) { + if (rig_has_set_level(rig, RIG_LEVEL_AF)) + { printf("AF: %g%%\n", 100 * chan.levels[rig_setting2idx(RIG_LEVEL_AF)].f); } - if (rig_has_set_level(rig, RIG_LEVEL_RF)) { + if (rig_has_set_level(rig, RIG_LEVEL_RF)) + { printf("RF: %g%%\n", 100 * chan.levels[rig_setting2idx(RIG_LEVEL_RF)].f); } - if (rig_has_set_level(rig, RIG_LEVEL_SQL)) { + if (rig_has_set_level(rig, RIG_LEVEL_SQL)) + { printf("SQL: %g%%\n", 100 * chan.levels[rig_setting2idx(RIG_LEVEL_SQL)].f); } - if (rig_has_set_level(rig, RIG_LEVEL_IF)) { + if (rig_has_set_level(rig, RIG_LEVEL_IF)) + { printf("IF: %dHz\n", chan.levels[rig_setting2idx(RIG_LEVEL_IF)].i); } - if (rig_has_set_level(rig, RIG_LEVEL_APF)) { + if (rig_has_set_level(rig, RIG_LEVEL_APF)) + { printf("APF: %g%%\n", 100 * chan.levels[rig_setting2idx(RIG_LEVEL_APF)].f); } - if (rig_has_set_level(rig, RIG_LEVEL_NR)) { + if (rig_has_set_level(rig, RIG_LEVEL_NR)) + { printf("NR: %g%%\n", 100 * chan.levels[rig_setting2idx(RIG_LEVEL_NR)].f); } - if (rig_has_set_level(rig, RIG_LEVEL_PBT_IN)) { + if (rig_has_set_level(rig, RIG_LEVEL_PBT_IN)) + { printf("PBT_IN: %g%%\n", 100 * chan.levels[rig_setting2idx(RIG_LEVEL_PBT_IN)].f); } - if (rig_has_set_level(rig, RIG_LEVEL_PBT_OUT)) { + if (rig_has_set_level(rig, RIG_LEVEL_PBT_OUT)) + { printf("PBT_OUT: %g%%\n", 100 * chan.levels[rig_setting2idx(RIG_LEVEL_PBT_OUT)].f); } - if (rig_has_set_level(rig, RIG_LEVEL_CWPITCH)) { + if (rig_has_set_level(rig, RIG_LEVEL_CWPITCH)) + { printf("CWPITCH: %dHz\n", chan.levels[rig_setting2idx(RIG_LEVEL_CWPITCH)].i); } - if (rig_has_set_level(rig, RIG_LEVEL_RFPOWER)) { + if (rig_has_set_level(rig, RIG_LEVEL_RFPOWER)) + { printf("RFPOWER: %g%%\n", 100 * chan.levels[rig_setting2idx(RIG_LEVEL_RFPOWER)].f); } - if (rig_has_set_level(rig, RIG_LEVEL_MICGAIN)) { + if (rig_has_set_level(rig, RIG_LEVEL_MICGAIN)) + { printf("MICGAIN: %g%%\n", 100 * chan.levels[rig_setting2idx(RIG_LEVEL_MICGAIN)].f); } - if (rig_has_set_level(rig, RIG_LEVEL_COMP)) { + if (rig_has_set_level(rig, RIG_LEVEL_COMP)) + { printf("COMP: %g%%\n", 100 * chan.levels[rig_setting2idx(RIG_LEVEL_COMP)].f); } - if (rig_has_set_level(rig, RIG_LEVEL_BALANCE)) { + if (rig_has_set_level(rig, RIG_LEVEL_BALANCE)) + { printf("BALANCE: %g%%\n", 100 * chan.levels[rig_setting2idx(RIG_LEVEL_BALANCE)].f); } - if (rig_has_set_level(rig, RIG_LEVEL_KEYSPD)) { + if (rig_has_set_level(rig, RIG_LEVEL_KEYSPD)) + { printf("KEYSPD: %d\n", chan.levels[rig_setting2idx(RIG_LEVEL_KEYSPD)].i); } - if (rig_has_set_level(rig, RIG_LEVEL_NOTCHF)) { + if (rig_has_set_level(rig, RIG_LEVEL_NOTCHF)) + { printf("NOTCHF: %d\n", chan.levels[rig_setting2idx(RIG_LEVEL_NOTCHF)].i); } - if (rig_has_set_level(rig, RIG_LEVEL_AGC)) { + if (rig_has_set_level(rig, RIG_LEVEL_AGC)) + { printf("AGC: %d\n", chan.levels[rig_setting2idx(RIG_LEVEL_AGC)].i); } - if (rig_has_set_level(rig, RIG_LEVEL_BKINDL)) { + if (rig_has_set_level(rig, RIG_LEVEL_BKINDL)) + { printf("BKINDL: %d\n", chan.levels[rig_setting2idx(RIG_LEVEL_BKINDL)].i); } diff --git a/tests/example.c b/tests/example.c index a9571d3d0..e4275978e 100644 --- a/tests/example.c +++ b/tests/example.c @@ -61,7 +61,8 @@ int main() /* Current mode */ status = rig_get_mode(my_rig, RIG_VFO_CURR, &mode, &width); - switch (mode) { + switch (mode) + { case RIG_MODE_USB: mm = "USB"; break; diff --git a/tests/listrigs.c b/tests/listrigs.c index 21a2847c7..496c74746 100644 --- a/tests/listrigs.c +++ b/tests/listrigs.c @@ -38,7 +38,8 @@ int print_caps_sum(const struct rig_caps *caps, void *data) printf("%-10s\t", rig_strstatus(caps->status)); - switch (caps->rig_type & RIG_TYPE_MASK) { + switch (caps->rig_type & RIG_TYPE_MASK) + { case RIG_TYPE_TRANSCEIVER: printf("Transceiver\n"); break; @@ -93,7 +94,8 @@ int main(int argc, char *argv[]) status = rig_list_foreach(print_caps_sum, NULL); - if (status != RIG_OK) { + if (status != RIG_OK) + { printf("rig_list_foreach: error = %s \n", rigerror(status)); exit(3); } diff --git a/tests/memcsv.c b/tests/memcsv.c index 01da84feb..fe3a0920c 100644 --- a/tests/memcsv.c +++ b/tests/memcsv.c @@ -86,11 +86,13 @@ int csv_save(RIG *rig, const char *outfilename) f = fopen(outfilename, "w"); - if (!f) { + if (!f) + { return -1; } - if (rig->caps->clone_combo_get) { + if (rig->caps->clone_combo_get) + { printf("About to save data, enter cloning mode: %s\n", rig->caps->clone_combo_get); } @@ -123,12 +125,14 @@ int csv_load(RIG *rig, const char *infilename) f = fopen(infilename, "r"); - if (!f) { + if (!f) + { return -1; } /* First read the first line, containing the key */ - if (fgets(keys, sizeof(keys), f) != NULL) { + if (fgets(keys, sizeof(keys), f) != NULL) + { /* fgets stores '\n' in a buffer, get rid of it */ keys[ strlen(keys) - 1 ] = '\0'; @@ -138,25 +142,30 @@ int csv_load(RIG *rig, const char *infilename) if (!tokenize_line(keys, key_list, sizeof(key_list) / sizeof(char *), - ',')) { + ',')) + { fprintf(stderr, "Invalid (possibly too long or empty) key line, cannot continue.\n"); fclose(f); return -1; } - } else { + } + else + { /* File exists, but is empty */ fclose(f); return -1; } /* Next, read the file line by line */ - while (fgets(line, sizeof line, f) != NULL) { + while (fgets(line, sizeof line, f) != NULL) + { /* Tokenize the line */ if (!tokenize_line(line, value_list, sizeof(value_list) / sizeof(char *), - ',')) { + ',')) + { fprintf(stderr, "Invalid (possibly too long or empty) line ignored\n"); continue; @@ -168,7 +177,8 @@ int csv_load(RIG *rig, const char *infilename) /* Write a rig memory */ status = rig_set_channel(rig, &chan); - if (status != RIG_OK) { + if (status != RIG_OK) + { fprintf(stderr, "rig_get_channel: error = %s \n", rigerror(status)); fclose(f); return status; @@ -193,18 +203,20 @@ int csv_load(RIG *rig, const char *infilename) \return number of tokens on success, 0 if \param token_list is too small to contain all the tokens, or if line was empty. */ -static int tokenize_line(char *line, char **token_list, size_t siz, char delim) +static int tokenize_line(char *line, char **token_list, size_t siz, char delim) { size_t i; char *tok; /* Erase the table */ - for (i = 0; i < siz; i++) { + for (i = 0; i < siz; i++) + { token_list[i] = NULL; } /* Empty line passed? */ - if (line == NULL) { + if (line == NULL) + { return 0; } @@ -213,18 +225,21 @@ static int tokenize_line(char *line, char **token_list, size_t siz, char delim) tok = mystrtok(line, delim); /* Line contains no delim */ - if (tok == NULL) { + if (tok == NULL) + { return 0; } token_list[ i++ ] = tok; /* Find the remaining tokens */ - while (i < siz) { + while (i < siz) + { tok = mystrtok(NULL, delim); /* If NULL, no more tokens left */ - if (tok == NULL) { + if (tok == NULL) + { break; } @@ -233,9 +248,12 @@ static int tokenize_line(char *line, char **token_list, size_t siz, char delim) } /* Any tokens left? */ - if (i == siz) { + if (i == siz) + { return 0; - } else { + } + else + { return i; } } @@ -254,25 +272,33 @@ static char * mystrtok(char *s, char delim) static size_t pos = 0, length = 0; static char *str = 0; - if (s != NULL) { + if (s != NULL) + { str = s; pos = 0; length = strlen(str); - } else { + } + else + { } - if (str[ pos + 1 ] == '\0') { + if (str[ pos + 1 ] == '\0') + { return NULL; } size_t i, ent_pos = pos; - for (i = pos; i < length;) { - if (str[i] == delim) { + for (i = pos; i < length;) + { + if (str[i] == delim) + { str[i] = '\0'; pos = i + 1; return str + ent_pos; - } else { + } + else + { i++; } } @@ -297,7 +323,8 @@ static int print_parm_val(RIG *rig, const struct confparams *cfp, rig_ptr_t ptr) FILE *f = (FILE *)ptr; rig_get_ext_parm(rig, cfp->token, &val); - switch (cfp->type) { + switch (cfp->type) + { case RIG_CONF_CHECKBUTTON: case RIG_CONF_COMBO: fprintf(f, "%d%c", val.i, csv_sep); @@ -327,14 +354,17 @@ int csv_parm_save(RIG *rig, const char *outfilename) f = fopen(outfilename, "w"); - if (!f) { + if (!f) + { return -1; } - for (i = 0; i < RIG_SETTING_MAX; i++) { + for (i = 0; i < RIG_SETTING_MAX; i++) + { const char *ms = rig_strparm(get_parm & rig_idx2setting(i)); - if (!ms || !ms[0]) { + if (!ms || !ms[0]) + { continue; } @@ -344,26 +374,32 @@ int csv_parm_save(RIG *rig, const char *outfilename) rig_ext_parm_foreach(rig, print_parm_name, f); fprintf(f, "\n"); - for (i = 0; i < RIG_SETTING_MAX; i++) { + for (i = 0; i < RIG_SETTING_MAX; i++) + { const char *ms; value_t val; parm = get_parm & rig_idx2setting(i); ms = rig_strparm(parm); - if (!ms || !ms[0]) { + if (!ms || !ms[0]) + { continue; } ret = rig_get_parm(rig, parm, &val); - if (ret != RIG_OK) { + if (ret != RIG_OK) + { return ret; } - if (RIG_PARM_IS_FLOAT(parm)) { + if (RIG_PARM_IS_FLOAT(parm)) + { fprintf(f, "%f%c", val.f, csv_sep); - } else { + } + else + { fprintf(f, "%d%c", val.i, csv_sep); } } @@ -391,99 +427,123 @@ void dump_csv_name(const channel_cap_t *mem_caps, FILE *f) { fprintf(f, "num%c", csv_sep); - if (mem_caps->bank_num) { + if (mem_caps->bank_num) + { fprintf(f, "bank_num%c", csv_sep); } - if (mem_caps->channel_desc) { + if (mem_caps->channel_desc) + { fprintf(f, "channel_desc%c", csv_sep); } - if (mem_caps->vfo) { + if (mem_caps->vfo) + { fprintf(f, "vfo%c", csv_sep); } - if (mem_caps->ant) { + if (mem_caps->ant) + { fprintf(f, "ant%c", csv_sep); } - if (mem_caps->freq) { + if (mem_caps->freq) + { fprintf(f, "freq%c", csv_sep); } - if (mem_caps->mode) { + if (mem_caps->mode) + { fprintf(f, "mode%c", csv_sep); } - if (mem_caps->width) { + if (mem_caps->width) + { fprintf(f, "width%c", csv_sep); } - if (mem_caps->tx_freq) { + if (mem_caps->tx_freq) + { fprintf(f, "tx_freq%c", csv_sep); } - if (mem_caps->tx_mode) { + if (mem_caps->tx_mode) + { fprintf(f, "tx_mode%c", csv_sep); } - if (mem_caps->tx_width) { + if (mem_caps->tx_width) + { fprintf(f, "tx_width%c", csv_sep); } - if (mem_caps->split) { + if (mem_caps->split) + { fprintf(f, "split%c", csv_sep); } - if (mem_caps->tx_vfo) { + if (mem_caps->tx_vfo) + { fprintf(f, "tx_vfo%c", csv_sep); } - if (mem_caps->rptr_shift) { + if (mem_caps->rptr_shift) + { fprintf(f, "rptr_shift%c", csv_sep); } - if (mem_caps->rptr_offs) { + if (mem_caps->rptr_offs) + { fprintf(f, "rptr_offs%c", csv_sep); } - if (mem_caps->tuning_step) { + if (mem_caps->tuning_step) + { fprintf(f, "tuning_step%c", csv_sep); } - if (mem_caps->rit) { + if (mem_caps->rit) + { fprintf(f, "rit%c", csv_sep); } - if (mem_caps->xit) { + if (mem_caps->xit) + { fprintf(f, "xit%c", csv_sep); } - if (mem_caps->funcs) { + if (mem_caps->funcs) + { fprintf(f, "funcs%c", csv_sep); } - if (mem_caps->ctcss_tone) { + if (mem_caps->ctcss_tone) + { fprintf(f, "ctcss_tone%c", csv_sep); } - if (mem_caps->ctcss_sql) { + if (mem_caps->ctcss_sql) + { fprintf(f, "ctcss_sql%c", csv_sep); } - if (mem_caps->dcs_code) { + if (mem_caps->dcs_code) + { fprintf(f, "dcs_code%c", csv_sep); } - if (mem_caps->dcs_sql) { + if (mem_caps->dcs_sql) + { fprintf(f, "dcs_sql%c", csv_sep); } - if (mem_caps->scan_group) { + if (mem_caps->scan_group) + { fprintf(f, "scan_group%c", csv_sep); } - if (mem_caps->flags) { + if (mem_caps->flags) + { fprintf(f, "flags%c", csv_sep); } @@ -503,12 +563,14 @@ int dump_csv_chan(RIG *rig, static int first_time = 1; const channel_cap_t *mem_caps = &chan_list->mem_caps; - if (first_time) { + if (first_time) + { dump_csv_name(mem_caps, f); first_time = 0; } - if (*chan_pp == NULL) { + if (*chan_pp == NULL) + { /* * Hamlib frontend demand application an allocated * channel_t pointer for next round. @@ -520,99 +582,123 @@ int dump_csv_chan(RIG *rig, fprintf(f, "%d%c", chan.channel_num, csv_sep); - if (mem_caps->bank_num) { + if (mem_caps->bank_num) + { fprintf(f, "%d%c", chan.bank_num, csv_sep); } - if (mem_caps->channel_desc) { + if (mem_caps->channel_desc) + { fprintf(f, "%s%c", chan.channel_desc, csv_sep); } - if (mem_caps->vfo) { + if (mem_caps->vfo) + { fprintf(f, "%s%c", rig_strvfo(chan.vfo), csv_sep); } - if (mem_caps->ant) { + if (mem_caps->ant) + { fprintf(f, "%d%c", chan.ant, csv_sep); } - if (mem_caps->freq) { + if (mem_caps->freq) + { fprintf(f, "%.0"PRIfreq"%c", chan.freq, csv_sep); } - if (mem_caps->mode) { + if (mem_caps->mode) + { fprintf(f, "%s%c", rig_strrmode(chan.mode), csv_sep); } - if (mem_caps->width) { + if (mem_caps->width) + { fprintf(f, "%d%c", (int)chan.width, csv_sep); } - if (mem_caps->tx_freq) { + if (mem_caps->tx_freq) + { fprintf(f, "%.0"PRIfreq"%c", chan.tx_freq, csv_sep); } - if (mem_caps->tx_mode) { + if (mem_caps->tx_mode) + { fprintf(f, "%s%c", rig_strrmode(chan.tx_mode), csv_sep); } - if (mem_caps->tx_width) { + if (mem_caps->tx_width) + { fprintf(f, "%d%c", (int)chan.tx_width, csv_sep); } - if (mem_caps->split) { + if (mem_caps->split) + { fprintf(f, "%s%c", chan.split == RIG_SPLIT_ON ? "on" : "off", csv_sep); } - if (mem_caps->tx_vfo) { + if (mem_caps->tx_vfo) + { fprintf(f, "%s%c", rig_strvfo(chan.tx_vfo), csv_sep); } - if (mem_caps->rptr_shift) { + if (mem_caps->rptr_shift) + { fprintf(f, "%s%c", rig_strptrshift(chan.rptr_shift), csv_sep); } - if (mem_caps->rptr_offs) { + if (mem_caps->rptr_offs) + { fprintf(f, "%d%c", (int)chan.rptr_offs, csv_sep); } - if (mem_caps->tuning_step) { + if (mem_caps->tuning_step) + { fprintf(f, "%d%c", (int)chan.tuning_step, csv_sep); } - if (mem_caps->rit) { + if (mem_caps->rit) + { fprintf(f, "%d%c", (int)chan.rit, csv_sep); } - if (mem_caps->xit) { + if (mem_caps->xit) + { fprintf(f, "%d%c", (int)chan.xit, csv_sep); } - if (mem_caps->funcs) { + if (mem_caps->funcs) + { fprintf(f, "%lx%c", chan.funcs, csv_sep); } - if (mem_caps->ctcss_tone) { + if (mem_caps->ctcss_tone) + { fprintf(f, "%d%c", chan.ctcss_tone, csv_sep); } - if (mem_caps->ctcss_sql) { + if (mem_caps->ctcss_sql) + { fprintf(f, "%d%c", chan.ctcss_sql, csv_sep); } - if (mem_caps->dcs_code) { + if (mem_caps->dcs_code) + { fprintf(f, "%d%c", chan.dcs_code, csv_sep); } - if (mem_caps->dcs_sql) { + if (mem_caps->dcs_sql) + { fprintf(f, "%d%c", chan.dcs_sql, csv_sep); } - if (mem_caps->scan_group) { + if (mem_caps->scan_group) + { fprintf(f, "%d%c", chan.scan_group, csv_sep); } - if (mem_caps->flags) { + if (mem_caps->flags) + { fprintf(f, "%x%c", chan.flags, csv_sep); } @@ -623,7 +709,6 @@ int dump_csv_chan(RIG *rig, * to chan being static */ - return RIG_OK; } @@ -650,7 +735,8 @@ int set_channel_data(RIG *rig, i = find_on_list(line_key_list, "num"); - if (i < 0) { + if (i < 0) + { fprintf(stderr, "No channel number\n"); return -1; } @@ -659,99 +745,125 @@ int set_channel_data(RIG *rig, /* find chanel caps of appropriate memory group? */ for (j = 0; j < CHANLSTSIZ; j++) - if (rig->state.chan_list[j].start <= n && rig->state.chan_list[j].end >= n) { + { + if (rig->state.chan_list[j].start <= n && rig->state.chan_list[j].end >= n) + { break; } + } printf("Requested channel number %d, list number %d\n", n, j); const channel_cap_t *mem_caps = &rig->state.chan_list[j].mem_caps; - if (mem_caps->bank_num) { + if (mem_caps->bank_num) + { i = find_on_list(line_key_list, "bank_num"); - if (i >= 0) { + if (i >= 0) + { chan->bank_num = atoi(line_data_list[ i ]); } } - if (mem_caps->channel_desc) { + if (mem_caps->channel_desc) + { i = find_on_list(line_key_list, "channel_desc"); - if (i >= 0) { + if (i >= 0) + { strncpy(chan->channel_desc, line_data_list[ i ], rig->caps->chan_desc_sz - 1); chan->channel_desc[ rig->caps->chan_desc_sz ] = '\0'; } } - if (mem_caps->ant) { + if (mem_caps->ant) + { i = find_on_list(line_key_list, "ant"); - if (i >= 0) { + if (i >= 0) + { chan->ant = atoi(line_data_list[ i ]); } } - if (mem_caps->freq) { + if (mem_caps->freq) + { i = find_on_list(line_key_list, "freq"); - if (i >= 0) { + if (i >= 0) + { chan->freq = atoi(line_data_list[ i ]); } } - if (mem_caps->mode) { + if (mem_caps->mode) + { i = find_on_list(line_key_list, "mode"); - if (i >= 0) { + if (i >= 0) + { chan->mode = rig_parse_mode(line_data_list[ i ]); } } - if (mem_caps->width) { + if (mem_caps->width) + { i = find_on_list(line_key_list, "width"); - if (i >= 0) { + if (i >= 0) + { chan->width = atoi(line_data_list[ i ]); } } - if (mem_caps->tx_freq) { + if (mem_caps->tx_freq) + { i = find_on_list(line_key_list, "tx_freq"); - if (i >= 0) { + if (i >= 0) + { sscanf(line_data_list[i], "%"SCNfreq, &chan->tx_freq); } } - if (mem_caps->tx_mode) { + if (mem_caps->tx_mode) + { i = find_on_list(line_key_list, "tx_mode"); - if (i >= 0) { + if (i >= 0) + { chan->tx_mode = rig_parse_mode(line_data_list[ i ]); } } - if (mem_caps->tx_width) { + if (mem_caps->tx_width) + { i = find_on_list(line_key_list, "tx_width"); - if (i >= 0) { + if (i >= 0) + { chan->tx_width = atoi(line_data_list[ i ]); } } - if (mem_caps->split) { + if (mem_caps->split) + { chan->split = RIG_SPLIT_OFF; i = find_on_list(line_key_list, "split"); - if (i >= 0) { - if (strcmp(line_data_list[i], "on") == 0) { + if (i >= 0) + { + if (strcmp(line_data_list[i], "on") == 0) + { chan->split = RIG_SPLIT_ON; - if (mem_caps->tx_vfo) { + if (mem_caps->tx_vfo) + { i = find_on_list(line_key_list, "tx_vfo"); - if (i >= 0) { + if (i >= 0) + { sscanf(line_data_list[i], "%x", &chan->tx_vfo); } } @@ -759,11 +871,14 @@ int set_channel_data(RIG *rig, } } - if (mem_caps->rptr_shift) { + if (mem_caps->rptr_shift) + { i = find_on_list(line_key_list, "rptr_shift"); - if (i >= 0) { - switch (line_data_list[i][0]) { + if (i >= 0) + { + switch (line_data_list[i][0]) + { case '=': chan->rptr_shift = RIG_RPT_SHIFT_NONE; break; @@ -777,92 +892,114 @@ int set_channel_data(RIG *rig, break; } - if (mem_caps->rptr_offs && chan->rptr_shift != RIG_RPT_SHIFT_NONE) { + if (mem_caps->rptr_offs && chan->rptr_shift != RIG_RPT_SHIFT_NONE) + { i = find_on_list(line_key_list, "rptr_offs"); - if (i >= 0) { + if (i >= 0) + { chan->rptr_offs = atoi(line_data_list[ i ]); } } } } - if (mem_caps->tuning_step) { + if (mem_caps->tuning_step) + { i = find_on_list(line_key_list, "tuning_step"); - if (i >= 0) { + if (i >= 0) + { chan->tuning_step = atoi(line_data_list[ i ]); } } - if (mem_caps->rit) { + if (mem_caps->rit) + { i = find_on_list(line_key_list, "rit"); - if (i >= 0) { + if (i >= 0) + { chan->rit = atoi(line_data_list[ i ]); } } - if (mem_caps->xit) { + if (mem_caps->xit) + { i = find_on_list(line_key_list, "xit"); - if (i >= 0) { + if (i >= 0) + { chan->xit = atoi(line_data_list[ i ]); } } - if (mem_caps->funcs) { + if (mem_caps->funcs) + { i = find_on_list(line_key_list, "funcs"); - if (i >= 0) { + if (i >= 0) + { sscanf(line_data_list[i], "%lx", &chan->funcs); } } - if (mem_caps->ctcss_tone) { + if (mem_caps->ctcss_tone) + { i = find_on_list(line_key_list, "ctcss_tone"); - if (i >= 0) { + if (i >= 0) + { chan->ctcss_tone = atoi(line_data_list[ i ]); } } - if (mem_caps->ctcss_sql) { + if (mem_caps->ctcss_sql) + { i = find_on_list(line_key_list, "ctcss_sql"); - if (i >= 0) { + if (i >= 0) + { chan->ctcss_sql = atoi(line_data_list[ i ]); } } - if (mem_caps->dcs_code) { + if (mem_caps->dcs_code) + { i = find_on_list(line_key_list, "dcs_code"); - if (i >= 0) { + if (i >= 0) + { chan->dcs_code = atoi(line_data_list[ i ]); } } - if (mem_caps->dcs_sql) { + if (mem_caps->dcs_sql) + { i = find_on_list(line_key_list, "dcs_sql"); - if (i >= 0) { + if (i >= 0) + { chan->dcs_sql = atoi(line_data_list[ i ]); } } - if (mem_caps->scan_group) { + if (mem_caps->scan_group) + { i = find_on_list(line_key_list, "scan_group"); - if (i >= 0) { + if (i >= 0) + { chan->scan_group = atoi(line_data_list[ i ]); } } - if (mem_caps->flags) { + if (mem_caps->flags) + { i = find_on_list(line_key_list, "flags"); - if (i >= 0) { + if (i >= 0) + { sscanf(line_data_list[i], "%x", &chan->flags); } } @@ -881,21 +1018,29 @@ int find_on_list(char **list, char *what) { int i = 0; - if (!what) { + if (!what) + { return -1; } - while (list[i] != NULL) { - if (strcmp(list[i], what) == 0) { + while (list[i] != NULL) + { + if (strcmp(list[i], what) == 0) + { return i; - } else { + } + else + { i++; } } - if (!list[i]) { + if (!list[i]) + { return -1; - } else { + } + else + { return i; } } diff --git a/tests/memload.c b/tests/memload.c index f448bbaf2..d4ebca6a9 100644 --- a/tests/memload.c +++ b/tests/memload.c @@ -48,43 +48,52 @@ int xml_load(RIG *my_rig, const char *infilename) /* load xlm Doc */ Doc = xmlParseFile(infilename); - if (Doc == NULL) { + if (Doc == NULL) + { fprintf(stderr, "xmlParse failed\n"); exit(2); } node = xmlDocGetRootElement(Doc); - if (node == NULL) { + if (node == NULL) + { fprintf(stderr, "get root failed\n"); exit(2); } - if (strcmp((char *) node->name, "hamlib")) { + if (strcmp((char *) node->name, "hamlib")) + { fprintf(stderr, "no hamlib tag found\n"); exit(2); } - for (node = node->xmlChildrenNode; node != NULL; node = node->next) { - if (xmlNodeIsText(node)) { + for (node = node->xmlChildrenNode; node != NULL; node = node->next) + { + if (xmlNodeIsText(node)) + { continue; } - if (strcmp((char *) node->name, "channels") == 0) { + if (strcmp((char *) node->name, "channels") == 0) + { break; } } - if (node == NULL) { + if (node == NULL) + { fprintf(stderr, "no channels\n"); exit(2); } - for (node = node->xmlChildrenNode; node != NULL; node = node->next) { + for (node = node->xmlChildrenNode; node != NULL; node = node->next) + { channel_t chan; int status; - if (xmlNodeIsText(node)) { + if (xmlNodeIsText(node)) + { continue; } @@ -92,7 +101,8 @@ int xml_load(RIG *my_rig, const char *infilename) status = rig_set_channel(my_rig, &chan); - if (status != RIG_OK) { + if (status != RIG_OK) + { printf("rig_get_channel: error = %s \n", rigerror(status)); return status; } @@ -126,107 +136,134 @@ int set_chan(RIG *rig, channel_t *chan, xmlNodePtr node) prop = xmlGetProp(node, (unsigned char *) "num"); - if (prop == NULL) { + if (prop == NULL) + { fprintf(stderr, "no num\n"); return -1; } n = chan->channel_num = atoi((char *) prop); - /* find chanel caps */ + /* find channel caps */ for (i = 0; i < CHANLSTSIZ ; i++) + { if (rig->state.chan_list[i].start <= n - && rig->state.chan_list[i].end >= n) { + && rig->state.chan_list[i].end >= n) + { break; } + } fprintf(stderr, "node %d %d\n", n, i); - if (rig->state.chan_list[i].mem_caps.bank_num) { + if (rig->state.chan_list[i].mem_caps.bank_num) + { prop = xmlGetProp(node, (unsigned char *) "bank_num"); - if (prop != NULL) { + if (prop != NULL) + { chan->bank_num = atoi((char *) prop); } } - if (rig->state.chan_list[i].mem_caps.channel_desc) { + if (rig->state.chan_list[i].mem_caps.channel_desc) + { prop = xmlGetProp(node, (unsigned char *) "channel_desc"); - if (prop != NULL) { + if (prop != NULL) + { strncpy(chan->channel_desc, (char *) prop, 7); } } - if (rig->state.chan_list[i].mem_caps.ant) { + if (rig->state.chan_list[i].mem_caps.ant) + { prop = xmlGetProp(node, (unsigned char *) "ant"); - if (prop != NULL) { + if (prop != NULL) + { chan->ant = atoi((char *) prop); } } - if (rig->state.chan_list[i].mem_caps.freq) { + if (rig->state.chan_list[i].mem_caps.freq) + { prop = xmlGetProp(node, (unsigned char *) "freq"); - if (prop != NULL) { + if (prop != NULL) + { sscanf((char *) prop, "%"SCNfreq, &chan->freq); } } - if (rig->state.chan_list[i].mem_caps.mode) { + if (rig->state.chan_list[i].mem_caps.mode) + { prop = xmlGetProp(node, (unsigned char *) "mode"); - if (prop != NULL) { + if (prop != NULL) + { chan->mode = rig_parse_mode((char *) prop); } } - if (rig->state.chan_list[i].mem_caps.width) { + if (rig->state.chan_list[i].mem_caps.width) + { prop = xmlGetProp(node, (unsigned char *) "width"); - if (prop != NULL) { + if (prop != NULL) + { chan->width = atoi((char *) prop); } } - if (rig->state.chan_list[i].mem_caps.tx_freq) { + if (rig->state.chan_list[i].mem_caps.tx_freq) + { prop = xmlGetProp(node, (unsigned char *) "tx_freq"); - if (prop != NULL) { + if (prop != NULL) + { sscanf((char *) prop, "%"SCNfreq, &chan->tx_freq); } } - if (rig->state.chan_list[i].mem_caps.tx_mode) { + if (rig->state.chan_list[i].mem_caps.tx_mode) + { prop = xmlGetProp(node, (unsigned char *)"tx_mode"); - if (prop != NULL) { + if (prop != NULL) + { chan->tx_mode = rig_parse_mode((char *) prop); } } - if (rig->state.chan_list[i].mem_caps.tx_width) { + if (rig->state.chan_list[i].mem_caps.tx_width) + { prop = xmlGetProp(node, (unsigned char *)"tx_width"); - if (prop != NULL) { + if (prop != NULL) + { chan->tx_width = atoi((char *) prop); } } - if (rig->state.chan_list[i].mem_caps.split) { + if (rig->state.chan_list[i].mem_caps.split) + { chan->split = RIG_SPLIT_OFF; prop = xmlGetProp(node, (unsigned char *)"split"); - if (prop != NULL) { - if (strcmp((char *) prop, "on") == 0) { + if (prop != NULL) + { + if (strcmp((char *) prop, "on") == 0) + { chan->split = RIG_SPLIT_ON; - if (rig->state.chan_list[i].mem_caps.tx_vfo) { + if (rig->state.chan_list[i].mem_caps.tx_vfo) + { prop = xmlGetProp(node, (unsigned char *)"tx_vfo"); - if (prop != NULL) { + if (prop != NULL) + { sscanf((char *) prop, "%x", &chan->tx_vfo); } } @@ -234,11 +271,14 @@ int set_chan(RIG *rig, channel_t *chan, xmlNodePtr node) } } - if (rig->state.chan_list[i].mem_caps.rptr_shift) { + if (rig->state.chan_list[i].mem_caps.rptr_shift) + { prop = xmlGetProp(node, (unsigned char *)"rptr_shift"); if (prop) - switch (prop[0]) { + { + switch (prop[0]) + { case '=': chan->rptr_shift = RIG_RPT_SHIFT_NONE; break; @@ -251,93 +291,116 @@ int set_chan(RIG *rig, channel_t *chan, xmlNodePtr node) chan->rptr_shift = RIG_RPT_SHIFT_MINUS; break; } + } if (rig->state.chan_list[i].mem_caps.rptr_offs - && chan->rptr_shift != RIG_RPT_SHIFT_NONE) { + && chan->rptr_shift != RIG_RPT_SHIFT_NONE) + { prop = xmlGetProp(node, (unsigned char *)"rptr_offs"); - if (prop != NULL) { + if (prop != NULL) + { chan->rptr_offs = atoi((char *) prop); } } } - if (rig->state.chan_list[i].mem_caps.tuning_step) { + if (rig->state.chan_list[i].mem_caps.tuning_step) + { prop = xmlGetProp(node, (unsigned char *)"tuning_step"); - if (prop != NULL) { + if (prop != NULL) + { chan->tuning_step = atoi((char *) prop); } } - if (rig->state.chan_list[i].mem_caps.rit) { + if (rig->state.chan_list[i].mem_caps.rit) + { prop = xmlGetProp(node, (unsigned char *)"rit"); - if (prop != NULL) { + if (prop != NULL) + { chan->rit = atoi((char *) prop); } } - if (rig->state.chan_list[i].mem_caps.xit) { + if (rig->state.chan_list[i].mem_caps.xit) + { prop = xmlGetProp(node, (unsigned char *)"xit"); - if (prop != NULL) { + if (prop != NULL) + { chan->xit = atoi((char *) prop); } } - if (rig->state.chan_list[i].mem_caps.funcs) { + if (rig->state.chan_list[i].mem_caps.funcs) + { prop = xmlGetProp(node, (unsigned char *)"funcs"); - if (prop != NULL) { + if (prop != NULL) + { sscanf((char *) prop, "%lx", &chan->funcs); } } - if (rig->state.chan_list[i].mem_caps.ctcss_tone) { + if (rig->state.chan_list[i].mem_caps.ctcss_tone) + { prop = xmlGetProp(node, (unsigned char *)"ctcss_tone"); - if (prop != NULL) { + if (prop != NULL) + { chan->ctcss_tone = atoi((char *) prop); } } - if (rig->state.chan_list[i].mem_caps.ctcss_sql) { + if (rig->state.chan_list[i].mem_caps.ctcss_sql) + { prop = xmlGetProp(node, (unsigned char *)"ctcss_sql"); - if (prop != NULL) { + if (prop != NULL) + { chan->ctcss_sql = atoi((char *) prop); } } - if (rig->state.chan_list[i].mem_caps.dcs_code) { + if (rig->state.chan_list[i].mem_caps.dcs_code) + { prop = xmlGetProp(node, (unsigned char *)"dcs_code"); - if (prop != NULL) { + if (prop != NULL) + { chan->dcs_code = atoi((char *) prop); } } - if (rig->state.chan_list[i].mem_caps.dcs_sql) { + if (rig->state.chan_list[i].mem_caps.dcs_sql) + { prop = xmlGetProp(node, (unsigned char *)"dcs_sql"); - if (prop != NULL) { + if (prop != NULL) + { chan->dcs_sql = atoi((char *) prop); } } - if (rig->state.chan_list[i].mem_caps.scan_group) { + if (rig->state.chan_list[i].mem_caps.scan_group) + { prop = xmlGetProp(node, (unsigned char *)"scan_group"); - if (prop != NULL) { + if (prop != NULL) + { chan->scan_group = atoi((char *) prop); } } - if (rig->state.chan_list[i].mem_caps.flags) { + if (rig->state.chan_list[i].mem_caps.flags) + { prop = xmlGetProp(node, (unsigned char *)"flags"); - if (prop != NULL) { + if (prop != NULL) + { sscanf((char *) prop, "%x", &chan->flags); } } diff --git a/tests/memsave.c b/tests/memsave.c index 2778d4532..fca02853b 100644 --- a/tests/memsave.c +++ b/tests/memsave.c @@ -63,7 +63,8 @@ int xml_save(RIG *rig, const char *outfilename) retval = rig_get_chan_all_cb(rig, dump_xml_chan, root); - if (retval != RIG_OK) { + if (retval != RIG_OK) + { return retval; } @@ -104,7 +105,8 @@ int dump_xml_chan(RIG *rig, const channel_cap_t *mem_caps = &chan_list->mem_caps; - if (*chan_pp == NULL) { + if (*chan_pp == NULL) + { /* * Hamlib frontend demand application an allocated * channel_t pointer for next round. @@ -114,13 +116,15 @@ int dump_xml_chan(RIG *rig, return RIG_OK; } - if (chan_list->type == RIG_MTYPE_NONE) { + if (chan_list->type == RIG_MTYPE_NONE) + { return RIG_OK; } mtype = rig_strmtype(chan_list->type); - for (i = 0; i < strlen(mtype); i++) { + for (i = 0; i < strlen(mtype); i++) + { attrbuf[i] = tolower(mtype[i]); } @@ -128,7 +132,8 @@ int dump_xml_chan(RIG *rig, node = xmlNewChild(root, NULL, (unsigned char *)attrbuf, NULL); - if (mem_caps->bank_num) { + if (mem_caps->bank_num) + { sprintf(attrbuf, "%d", chan.bank_num); xmlNewProp(node, (unsigned char *) "bank_num", (unsigned char *) attrbuf); } @@ -136,57 +141,68 @@ int dump_xml_chan(RIG *rig, sprintf(attrbuf, "%d", chan.channel_num); xmlNewProp(node, (unsigned char *) "num", (unsigned char *) attrbuf); - if (mem_caps->channel_desc && chan.channel_desc[0] != '\0') { + if (mem_caps->channel_desc && chan.channel_desc[0] != '\0') + { xmlNewProp(node, (unsigned char *) "channel_desc", (unsigned char *) chan.channel_desc); } - if (mem_caps->vfo) { + if (mem_caps->vfo) + { sprintf(attrbuf, "%d", chan.vfo); xmlNewProp(node, (unsigned char *) "vfo", (unsigned char *) attrbuf); } - if (mem_caps->ant && chan.ant != RIG_ANT_NONE) { + if (mem_caps->ant && chan.ant != RIG_ANT_NONE) + { sprintf(attrbuf, "%d", chan.ant); xmlNewProp(node, (unsigned char *) "ant", (unsigned char *) attrbuf); } - if (mem_caps->freq && chan.freq != RIG_FREQ_NONE) { + if (mem_caps->freq && chan.freq != RIG_FREQ_NONE) + { sprintf(attrbuf, "%"PRIll, (int64_t)chan.freq); xmlNewProp(node, (unsigned char *) "freq", (unsigned char *) attrbuf); } - if (mem_caps->mode && chan.mode != RIG_MODE_NONE) { + if (mem_caps->mode && chan.mode != RIG_MODE_NONE) + { xmlNewProp(node, (unsigned char *) "mode", (unsigned char *) rig_strrmode(chan.mode)); } - if (mem_caps->width && chan.width != 0) { + if (mem_caps->width && chan.width != 0) + { sprintf(attrbuf, "%d", (int)chan.width); xmlNewProp(node, (unsigned char *) "width", (unsigned char *) attrbuf); } - if (mem_caps->tx_freq && chan.tx_freq != RIG_FREQ_NONE) { + if (mem_caps->tx_freq && chan.tx_freq != RIG_FREQ_NONE) + { sprintf(attrbuf, "%"PRIll, (int64_t)chan.tx_freq); xmlNewProp(node, (unsigned char *) "tx_freq", (unsigned char *) attrbuf); } - if (mem_caps->tx_mode && chan.tx_mode != RIG_MODE_NONE) { + if (mem_caps->tx_mode && chan.tx_mode != RIG_MODE_NONE) + { xmlNewProp(node, (unsigned char *) "tx_mode", (unsigned char *) rig_strrmode(chan.tx_mode)); } - if (mem_caps->tx_width && chan.tx_width != 0) { + if (mem_caps->tx_width && chan.tx_width != 0) + { sprintf(attrbuf, "%d", (int)chan.tx_width); xmlNewProp(node, (unsigned char *) "tx_width", (unsigned char *) attrbuf); } - if (mem_caps->split && chan.split != RIG_SPLIT_OFF) { + if (mem_caps->split && chan.split != RIG_SPLIT_OFF) + { xmlNewProp(node, (unsigned char *) "split", (unsigned char *) "on"); - if (mem_caps->tx_vfo) { + if (mem_caps->tx_vfo) + { sprintf(attrbuf, "%x", chan.tx_vfo); xmlNewProp(node, (unsigned char *) "tx_vfo", @@ -194,12 +210,14 @@ int dump_xml_chan(RIG *rig, } } - if (mem_caps->rptr_shift && chan.rptr_shift != RIG_RPT_SHIFT_NONE) { + if (mem_caps->rptr_shift && chan.rptr_shift != RIG_RPT_SHIFT_NONE) + { xmlNewProp(node, (unsigned char *) "rptr_shift", (unsigned char *) rig_strptrshift(chan.rptr_shift)); - if (mem_caps->rptr_offs && (int)chan.rptr_offs != 0) { + if (mem_caps->rptr_offs && (int)chan.rptr_offs != 0) + { sprintf(attrbuf, "%d", (int)chan.rptr_offs); xmlNewProp(node, (unsigned char *) "rptr_offs", @@ -207,52 +225,62 @@ int dump_xml_chan(RIG *rig, } } - if (mem_caps->tuning_step && chan.tuning_step != 0) { + if (mem_caps->tuning_step && chan.tuning_step != 0) + { sprintf(attrbuf, "%d", (int)chan.tuning_step); xmlNewProp(node, (unsigned char *) "tuning_step", (unsigned char *) attrbuf); } - if (mem_caps->rit && chan.rit != 0) { + if (mem_caps->rit && chan.rit != 0) + { sprintf(attrbuf, "%d", (int)chan.rit); xmlNewProp(node, (unsigned char *) "rit", (unsigned char *) attrbuf); } - if (mem_caps->xit && chan.xit != 0) { + if (mem_caps->xit && chan.xit != 0) + { sprintf(attrbuf, "%d", (int)chan.xit); xmlNewProp(node, (unsigned char *) "xit", (unsigned char *) attrbuf); } - if (mem_caps->funcs) { + if (mem_caps->funcs) + { sprintf(attrbuf, "%lx", chan.funcs); xmlNewProp(node, (unsigned char *) "funcs", (unsigned char *) attrbuf); } - if (mem_caps->ctcss_tone && chan.ctcss_tone != 0) { + if (mem_caps->ctcss_tone && chan.ctcss_tone != 0) + { sprintf(attrbuf, "%d", chan.ctcss_tone); xmlNewProp(node, (unsigned char *) "ctcss_tone", (unsigned char *) attrbuf); } - if (mem_caps->ctcss_sql && chan.ctcss_sql != 0) { + if (mem_caps->ctcss_sql && chan.ctcss_sql != 0) + { sprintf(attrbuf, "%d", chan.ctcss_sql); xmlNewProp(node, (unsigned char *) "ctcss_sql", (unsigned char *) attrbuf); } - if (mem_caps->dcs_code && chan.dcs_code != 0) { + if (mem_caps->dcs_code && chan.dcs_code != 0) + { sprintf(attrbuf, "%d", chan.dcs_code); xmlNewProp(node, (unsigned char *) "dcs_code", (unsigned char *) attrbuf); } - if (mem_caps->dcs_sql && chan.dcs_sql != 0) { + if (mem_caps->dcs_sql && chan.dcs_sql != 0) + { sprintf(attrbuf, "%d", chan.dcs_sql); xmlNewProp(node, (unsigned char *) "dcs_sql", (unsigned char *) attrbuf); } - if (mem_caps->scan_group) { + if (mem_caps->scan_group) + { sprintf(attrbuf, "%d", chan.scan_group); xmlNewProp(node, (unsigned char *) "scan_group", (unsigned char *) attrbuf); } - if (mem_caps->flags) { + if (mem_caps->flags) + { sprintf(attrbuf, "%x", chan.flags); xmlNewProp(node, (unsigned char *) "flags", (unsigned char *) attrbuf); } diff --git a/tests/rig_bench.c b/tests/rig_bench.c index b1d1659ef..c43c235b9 100644 --- a/tests/rig_bench.c +++ b/tests/rig_bench.c @@ -30,7 +30,8 @@ int main(int argc, char *argv[]) * allocate memory, setup & open port */ - if (argc < 2) { + if (argc < 2) + { hamlib_port_t myport; /* may be overriden by backend probe */ myport.type.rig = RIG_PORT_SERIAL; @@ -43,13 +44,16 @@ int main(int argc, char *argv[]) rig_load_all_backends(); myrig_model = rig_probe(&myport); - } else { + } + else + { myrig_model = atoi(argv[1]); } my_rig = rig_init(myrig_model); - if (!my_rig) { + if (!my_rig) + { fprintf(stderr, "Unknown rig num: %d\n", myrig_model); fprintf(stderr, "Please check riglist.h\n"); exit(1); /* whoops! something went wrong (mem alloc?) */ @@ -69,7 +73,8 @@ int main(int argc, char *argv[]) retcode = rig_open(my_rig); - if (retcode != RIG_OK) { + if (retcode != RIG_OK) + { printf("rig_open: error = %s\n", rigerror(retcode)); exit(2); } @@ -82,21 +87,24 @@ int main(int argc, char *argv[]) */ gettimeofday(&tv1, NULL); - for (i = 0; i < LOOP_COUNT; i++) { + for (i = 0; i < LOOP_COUNT; i++) + { freq_t freq; rmode_t rmode; pbwidth_t width; retcode = rig_get_freq(my_rig, RIG_VFO_CURR, &freq); - if (retcode != RIG_OK) { + if (retcode != RIG_OK) + { printf("rig_get_freq: error = %s \n", rigerror(retcode)); exit(1); } retcode = rig_get_mode(my_rig, RIG_VFO_CURR, &rmode, &width); - if (retcode != RIG_OK) { + if (retcode != RIG_OK) + { printf("rig_get_mode: error = %s \n", rigerror(retcode)); exit(1); } diff --git a/tests/rigctl.c b/tests/rigctl.c index 62d8aaab3..43413d7c8 100644 --- a/tests/rigctl.c +++ b/tests/rigctl.c @@ -88,7 +88,8 @@ void usage(void); * TODO: add an option to read from a file */ #define SHORT_OPTIONS "+m:r:p:d:P:D:s:c:t:lC:LuonvhV" -static struct option long_options[] = { +static struct option long_options[] = +{ {"model", 1, 0, 'm'}, {"rig-file", 1, 0, 'r'}, {"ptt-file", 1, 0, 'p'}, @@ -156,7 +157,8 @@ int main(int argc, char *argv[]) char *civaddr = NULL; /* NULL means no need to set conf */ char conf_parms[MAXCONFLEN] = ""; - while (1) { + while (1) + { int c; int option_index = 0; @@ -166,11 +168,13 @@ int main(int argc, char *argv[]) long_options, &option_index); - if (c == -1) { + if (c == -1) + { break; } - switch (c) { + switch (c) + { case 'h': usage(); exit(0); @@ -180,7 +184,8 @@ int main(int argc, char *argv[]) exit(0); case 'm': - if (!optarg) { + if (!optarg) + { usage(); /* wrong arg count */ exit(1); } @@ -189,7 +194,8 @@ int main(int argc, char *argv[]) break; case 'r': - if (!optarg) { + if (!optarg) + { usage(); /* wrong arg count */ exit(1); } @@ -198,7 +204,8 @@ int main(int argc, char *argv[]) break; case 'p': - if (!optarg) { + if (!optarg) + { usage(); /* wrong arg count */ exit(1); } @@ -207,7 +214,8 @@ int main(int argc, char *argv[]) break; case 'd': - if (!optarg) { + if (!optarg) + { usage(); /* wrong arg count */ exit(1); } @@ -216,61 +224,96 @@ int main(int argc, char *argv[]) break; case 'P': - if (!optarg) { + if (!optarg) + { usage(); /* wrong arg count */ exit(1); } - if (!strcmp(optarg, "RIG")) { + if (!strcmp(optarg, "RIG")) + { ptt_type = RIG_PTT_RIG; - } else if (!strcmp(optarg, "DTR")) { + } + else if (!strcmp(optarg, "DTR")) + { ptt_type = RIG_PTT_SERIAL_DTR; - } else if (!strcmp(optarg, "RTS")) { + } + else if (!strcmp(optarg, "RTS")) + { ptt_type = RIG_PTT_SERIAL_RTS; - } else if (!strcmp(optarg, "PARALLEL")) { + } + else if (!strcmp(optarg, "PARALLEL")) + { ptt_type = RIG_PTT_PARALLEL; - } else if (!strcmp(optarg, "CM108")) { + } + else if (!strcmp(optarg, "CM108")) + { ptt_type = RIG_PTT_CM108; - } else if (!strcmp(optarg, "GPIO")) { + } + else if (!strcmp(optarg, "GPIO")) + { ptt_type = RIG_PTT_GPIO; - } else if (!strcmp(optarg, "GPION")) { + } + else if (!strcmp(optarg, "GPION")) + { ptt_type = RIG_PTT_GPION; - } else if (!strcmp(optarg, "NONE")) { + } + else if (!strcmp(optarg, "NONE")) + { ptt_type = RIG_PTT_NONE; - } else { + } + else + { ptt_type = atoi(optarg); } break; case 'D': - if (!optarg) { + if (!optarg) + { usage(); /* wrong arg count */ exit(1); } - if (!strcmp(optarg, "RIG")) { + if (!strcmp(optarg, "RIG")) + { dcd_type = RIG_DCD_RIG; - } else if (!strcmp(optarg, "DSR")) { + } + else if (!strcmp(optarg, "DSR")) + { dcd_type = RIG_DCD_SERIAL_DSR; - } else if (!strcmp(optarg, "CTS")) { + } + else if (!strcmp(optarg, "CTS")) + { dcd_type = RIG_DCD_SERIAL_CTS; - } else if (!strcmp(optarg, "CD")) { + } + else if (!strcmp(optarg, "CD")) + { dcd_type = RIG_DCD_SERIAL_CAR; - } else if (!strcmp(optarg, "PARALLEL")) { + } + else if (!strcmp(optarg, "PARALLEL")) + { dcd_type = RIG_DCD_PARALLEL; - } else if (!strcmp(optarg, "CM108")) { + } + else if (!strcmp(optarg, "CM108")) + { dcd_type = RIG_DCD_CM108; - } else if (!strcmp(optarg, "NONE")) { + } + else if (!strcmp(optarg, "NONE")) + { dcd_type = RIG_DCD_NONE; - } else { + } + else + { dcd_type = atoi(optarg); } break; case 'c': - if (!optarg) { + if (!optarg) + { usage(); /* wrong arg count */ exit(1); } @@ -279,21 +322,26 @@ int main(int argc, char *argv[]) break; case 't': - if (!optarg) { + if (!optarg) + { usage(); /* wrong arg count */ exit(1); } - if (strlen(optarg) > 1) { + if (strlen(optarg) > 1) + { send_cmd_term = strtol(optarg, NULL, 0); - } else { + } + else + { send_cmd_term = optarg[0]; } break; case 's': - if (!optarg) { + if (!optarg) + { usage(); /* wrong arg count */ exit(1); } @@ -302,12 +350,14 @@ int main(int argc, char *argv[]) break; case 'C': - if (!optarg) { + if (!optarg) + { usage(); /* wrong arg count */ exit(1); } - if (*conf_parms != '\0') { + if (*conf_parms != '\0') + { strcat(conf_parms, ","); } @@ -365,13 +415,15 @@ int main(int argc, char *argv[]) * at least one command on command line, * disable interactive mode */ - if (optind < argc) { + if (optind < argc) + { interactive = 0; } my_rig = rig_init(my_model); - if (!my_rig) { + if (!my_rig) + { fprintf(stderr, "Unknown rig num %d, or initialization error.\n", my_model); @@ -381,47 +433,56 @@ int main(int argc, char *argv[]) retcode = set_conf(my_rig, conf_parms); - if (retcode != RIG_OK) { + if (retcode != RIG_OK) + { fprintf(stderr, "Config parameter error: %s\n", rigerror(retcode)); exit(2); } - if (rig_file) { + if (rig_file) + { strncpy(my_rig->state.rigport.pathname, rig_file, FILPATHLEN - 1); } /* * ex: RIG_PTT_PARALLEL and /dev/parport0 */ - if (ptt_type != RIG_PTT_NONE) { + if (ptt_type != RIG_PTT_NONE) + { 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; } - if (ptt_file) { + if (ptt_file) + { 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); } /* FIXME: bound checking and port type == serial */ - if (serial_rate != 0) { + if (serial_rate != 0) + { 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); } /* * print out conf parameters */ - if (show_conf) { + if (show_conf) + { dumpconf(my_rig, stdout); } @@ -429,7 +490,8 @@ int main(int argc, char *argv[]) * print out capabilities, and exit immediately * We may be interested only in only caps, and rig_open may fail. */ - if (dump_caps_opt) { + if (dump_caps_opt) + { dumpcaps(my_rig, stdout); rig_cleanup(my_rig); /* if you care about memory */ exit(0); @@ -437,12 +499,14 @@ int main(int argc, char *argv[]) retcode = rig_open(my_rig); - if (retcode != RIG_OK) { + if (retcode != RIG_OK) + { fprintf(stderr, "rig_open: error = %s \n", rigerror(retcode)); exit(2); } - if (verbose > 0) { + if (verbose > 0) + { printf("Opened rig model %d, '%s'\n", my_rig->caps->rig_model, my_rig->caps->model_name); @@ -457,19 +521,23 @@ int main(int argc, char *argv[]) #ifdef HAVE_LIBREADLINE - if (interactive && prompt && have_rl) { + if (interactive && prompt && have_rl) + { rl_readline_name = "rigctl"; #ifdef HAVE_READLINE_HISTORY using_history(); /* Initialize Readline History */ - if (rd_hist || sv_hist) { - if (!(hist_dir = getenv("RIGCTL_HIST_DIR"))) { + if (rd_hist || sv_hist) + { + if (!(hist_dir = getenv("RIGCTL_HIST_DIR"))) + { hist_dir = getenv("HOME"); } if (((stat(hist_dir, &hist_dir_stat) == -1) && (errno == ENOENT)) - || !(S_ISDIR(hist_dir_stat.st_mode))) { + || !(S_ISDIR(hist_dir_stat.st_mode))) + { fprintf(stderr, "Warning: %s is not a directory!\n", hist_dir); } @@ -482,8 +550,10 @@ int main(int argc, char *argv[]) strncat(hist_path, hist_file, strlen(hist_file)); } - if (rd_hist && hist_path) { - if (read_history(hist_path) == ENOENT) { + if (rd_hist && hist_path) + { + if (read_history(hist_path) == ENOENT) + { fprintf(stderr, "Warning: Could not read history from %s\n", hist_path); @@ -495,28 +565,35 @@ int main(int argc, char *argv[]) #endif /* HAVE_LIBREADLINE */ - do { + do + { retcode = rigctl_parse(my_rig, stdin, stdout, argv, argc); - if (retcode == 2) { + if (retcode == 2) + { exitcode = 2; } - } while (retcode == 0 || retcode == 2 || retcode == -RIG_ENAVAIL); + } + while (retcode == 0 || retcode == 2 || retcode == -RIG_ENAVAIL); #ifdef HAVE_LIBREADLINE - if (interactive && prompt && have_rl) { + if (interactive && prompt && have_rl) + { #ifdef HAVE_READLINE_HISTORY - if (sv_hist && hist_path) { - if (write_history(hist_path) == ENOENT) { + if (sv_hist && hist_path) + { + if (write_history(hist_path) == ENOENT) + { fprintf(stderr, "\nWarning: Could not write history to %s\n", hist_path); } } - if ((rd_hist || sv_hist) && hist_path) { + if ((rd_hist || sv_hist) && hist_path) + { free(hist_path); hist_path = (char *)NULL; } @@ -539,28 +616,28 @@ void usage(void) printf( - " -m, --model=ID select radio model number. See model list\n" - " -r, --rig-file=DEVICE set device of the radio to operate on\n" - " -p, --ptt-file=DEVICE set device of the PTT device to operate on\n" - " -d, --dcd-file=DEVICE set device of the DCD device to operate on\n" - " -P, --ptt-type=TYPE set type of the PTT device to operate on\n" - " -D, --dcd-type=TYPE set type of the DCD device to operate on\n" - " -s, --serial-speed=BAUD set serial speed of the serial port\n" - " -c, --civaddr=ID set CI-V address, decimal (for Icom rigs only)\n" - " -t, --send-cmd-term=CHAR set send_cmd command termination char\n" - " -C, --set-conf=PARM=VAL set config parameters\n" - " -L, --show-conf list all config parameters\n" - " -l, --list list all model numbers and exit\n" - " -u, --dump-caps dump capabilities and exit\n" - " -o, --vfo do not default to VFO_CURR, require extra vfo arg\n" - " -n, --no-restore-ai do not restore auto information mode on rig\n" + " -m, --model=ID select radio model number. See model list\n" + " -r, --rig-file=DEVICE set device of the radio to operate on\n" + " -p, --ptt-file=DEVICE set device of the PTT device to operate on\n" + " -d, --dcd-file=DEVICE set device of the DCD device to operate on\n" + " -P, --ptt-type=TYPE set type of the PTT device to operate on\n" + " -D, --dcd-type=TYPE set type of the DCD device to operate on\n" + " -s, --serial-speed=BAUD set serial speed of the serial port\n" + " -c, --civaddr=ID set CI-V address, decimal (for Icom rigs only)\n" + " -t, --send-cmd-term=CHAR set send_cmd command termination char\n" + " -C, --set-conf=PARM=VAL set config parameters\n" + " -L, --show-conf list all config parameters\n" + " -l, --list list all model numbers and exit\n" + " -u, --dump-caps dump capabilities and exit\n" + " -o, --vfo do not default to VFO_CURR, require extra vfo arg\n" + " -n, --no-restore-ai do not restore auto information mode on rig\n" #ifdef HAVE_READLINE_HISTORY - " -i, --read-history read prior interactive session history\n" - " -I, --save-history save current interactive session history\n" + " -i, --read-history read prior interactive session history\n" + " -I, --save-history save current interactive session history\n" #endif - " -v, --verbose set verbose mode, cumulative (-v to -vvvvv)\n" - " -h, --help display this help and exit\n" - " -V, --version output version information and exit\n\n" + " -v, --verbose set verbose mode, cumulative (-v to -vvvvv)\n" + " -h, --help display this help and exit\n" + " -V, --version output version information and exit\n\n" ); usage_rig(stdout); diff --git a/tests/rigctl_parse.c b/tests/rigctl_parse.c index dbd14fe1b..538c20ef4 100644 --- a/tests/rigctl_parse.c +++ b/tests/rigctl_parse.c @@ -82,7 +82,7 @@ extern int read_history(); * */ #if (defined(HAVE_SSLEEP) || defined(_WIN32)) && (!defined(HAVE_SLEEP)) -#include "hl_sleep.h" +# include "hl_sleep.h" #endif #include "rigctl_parse.h" @@ -91,7 +91,7 @@ extern int read_history(); #include "uthash.h" #ifdef HAVE_PTHREAD -#include +# include static pthread_mutex_t rig_mutex = PTHREAD_MUTEX_INITIALIZER; #endif @@ -115,7 +115,7 @@ static pthread_mutex_t rig_mutex = PTHREAD_MUTEX_INITIALIZER; #define ARG_NOVFO 0x8000 #define ARG_IN (ARG_IN1|ARG_IN2|ARG_IN3|ARG_IN4) -#define ARG_OUT (ARG_OUT1|ARG_OUT2|ARG_OUT3|ARG_OUT4) +#define ARG_OUT (ARG_OUT1|ARG_OUT2|ARG_OUT3|ARG_OUT4) /* variables for readline support */ #ifdef HAVE_LIBREADLINE @@ -133,7 +133,8 @@ static const int have_rl = 0; #endif -struct test_table { +struct test_table +{ unsigned char cmd; const char *name; int (*rig_routine)(RIG *, @@ -246,21 +247,22 @@ declare_proto_rig(pause); * * Available alphabetic letters: -.--------------*-----W-Y- */ -static struct test_table test_list[] = { +static struct test_table test_list[] = +{ { 'F', "set_freq", ACTION(set_freq), ARG_IN, "Frequency" }, - { 'f', "get_freq", ACTION(get_freq), ARG_OUT,"Frequency" }, + { 'f', "get_freq", ACTION(get_freq), ARG_OUT, "Frequency" }, { 'M', "set_mode", ACTION(set_mode), ARG_IN, "Mode", "Passband" }, - { 'm', "get_mode", ACTION(get_mode), ARG_OUT,"Mode", "Passband" }, + { 'm', "get_mode", ACTION(get_mode), ARG_OUT, "Mode", "Passband" }, { 'I', "set_split_freq", ACTION(set_split_freq), ARG_IN, "TX Frequency" }, - { 'i', "get_split_freq", ACTION(get_split_freq), ARG_OUT,"TX Frequency" }, + { 'i', "get_split_freq", ACTION(get_split_freq), ARG_OUT, "TX Frequency" }, { 'X', "set_split_mode", ACTION(set_split_mode), ARG_IN, "TX Mode", "TX Passband" }, - { 'x', "get_split_mode", ACTION(get_split_mode), ARG_OUT,"TX Mode", "TX Passband" }, + { 'x', "get_split_mode", ACTION(get_split_mode), ARG_OUT, "TX Mode", "TX Passband" }, { 'K', "set_split_freq_mode", ACTION(set_split_freq_mode), ARG_IN, "TX Frequency", "TX Mode", "TX Passband" }, { 'k', "get_split_freq_mode", ACTION(get_split_freq_mode), ARG_OUT, "TX Frequency", "TX Mode", "TX Passband" }, { 'S', "set_split_vfo", ACTION(set_split_vfo), ARG_IN, "Split", "TX VFO" }, - { 's', "get_split_vfo", ACTION(get_split_vfo), ARG_OUT,"Split", "TX VFO" }, + { 's', "get_split_vfo", ACTION(get_split_vfo), ARG_OUT, "Split", "TX VFO" }, { 'N', "set_ts", ACTION(set_ts), ARG_IN, "Tuning Step" }, - { 'n', "get_ts", ACTION(get_ts), ARG_OUT,"Tuning Step" }, + { 'n', "get_ts", ACTION(get_ts), ARG_OUT, "Tuning Step" }, { 'L', "set_level", ACTION(set_level), ARG_IN, "Level", "Level Value" }, { 'l', "get_level", ACTION(get_level), ARG_IN1 | ARG_OUT2, "Level", "Level Value" }, { 'U', "set_func", ACTION(set_func), ARG_IN, "Func", "Func Status" }, @@ -272,41 +274,41 @@ static struct test_table test_list[] = { { 'A', "set_trn", ACTION(set_trn), ARG_IN | ARG_NOVFO, "Transceive" }, { 'a', "get_trn", ACTION(get_trn), ARG_OUT | ARG_NOVFO, "Transceive" }, { 'R', "set_rptr_shift", ACTION(set_rptr_shift), ARG_IN, "Rptr Shift" }, - { 'r', "get_rptr_shift", ACTION(get_rptr_shift), ARG_OUT,"Rptr Shift" }, + { 'r', "get_rptr_shift", ACTION(get_rptr_shift), ARG_OUT, "Rptr Shift" }, { 'O', "set_rptr_offs", ACTION(set_rptr_offs), ARG_IN, "Rptr Offset" }, - { 'o', "get_rptr_offs", ACTION(get_rptr_offs), ARG_OUT,"Rptr Offset" }, + { 'o', "get_rptr_offs", ACTION(get_rptr_offs), ARG_OUT, "Rptr Offset" }, { 'C', "set_ctcss_tone", ACTION(set_ctcss_tone), ARG_IN, "CTCSS Tone" }, - { 'c', "get_ctcss_tone", ACTION(get_ctcss_tone), ARG_OUT,"CTCSS Tone" }, + { 'c', "get_ctcss_tone", ACTION(get_ctcss_tone), ARG_OUT, "CTCSS Tone" }, { 'D', "set_dcs_code", ACTION(set_dcs_code), ARG_IN, "DCS Code" }, - { 'd', "get_dcs_code", ACTION(get_dcs_code), ARG_OUT,"DCS Code" }, + { 'd', "get_dcs_code", ACTION(get_dcs_code), ARG_OUT, "DCS Code" }, { 0x90, "set_ctcss_sql", ACTION(set_ctcss_sql), ARG_IN, "CTCSS Sql" }, - { 0x91, "get_ctcss_sql", ACTION(get_ctcss_sql), ARG_OUT,"CTCSS Sql" }, + { 0x91, "get_ctcss_sql", ACTION(get_ctcss_sql), ARG_OUT, "CTCSS Sql" }, { 0x92, "set_dcs_sql", ACTION(set_dcs_sql), ARG_IN, "DCS Sql" }, - { 0x93, "get_dcs_sql", ACTION(get_dcs_sql), ARG_OUT,"DCS Sql" }, + { 0x93, "get_dcs_sql", ACTION(get_dcs_sql), ARG_OUT, "DCS Sql" }, { 'V', "set_vfo", ACTION(set_vfo), ARG_IN | ARG_NOVFO, "VFO" }, - { 'v', "get_vfo", ACTION(get_vfo), ARG_OUT,"VFO" }, + { 'v', "get_vfo", ACTION(get_vfo), ARG_OUT, "VFO" }, { 'T', "set_ptt", ACTION(set_ptt), ARG_IN, "PTT" }, - { 't', "get_ptt", ACTION(get_ptt), ARG_OUT,"PTT" }, + { 't', "get_ptt", ACTION(get_ptt), ARG_OUT, "PTT" }, { 'E', "set_mem", ACTION(set_mem), ARG_IN, "Memory#" }, - { 'e', "get_mem", ACTION(get_mem), ARG_OUT,"Memory#" }, + { 'e', "get_mem", ACTION(get_mem), ARG_OUT, "Memory#" }, { 'H', "set_channel", ACTION(set_channel), ARG_IN | ARG_NOVFO, "Channel" }, { 'h', "get_channel", ACTION(get_channel), ARG_IN | ARG_NOVFO, "Channel" }, { 'B', "set_bank", ACTION(set_bank), ARG_IN, "Bank" }, { '_', "get_info", ACTION(get_info), ARG_OUT | ARG_NOVFO, "Info" }, { 'J', "set_rit", ACTION(set_rit), ARG_IN, "RIT" }, - { 'j', "get_rit", ACTION(get_rit), ARG_OUT,"RIT" }, + { 'j', "get_rit", ACTION(get_rit), ARG_OUT, "RIT" }, { 'Z', "set_xit", ACTION(set_xit), ARG_IN, "XIT" }, - { 'z', "get_xit", ACTION(get_xit), ARG_OUT,"XIT" }, + { 'z', "get_xit", ACTION(get_xit), ARG_OUT, "XIT" }, { 'Y', "set_ant", ACTION(set_ant), ARG_IN, "Antenna" }, - { 'y', "get_ant", ACTION(get_ant), ARG_OUT,"Antenna" }, + { 'y', "get_ant", ACTION(get_ant), ARG_OUT, "Antenna" }, { 0x87, "set_powerstat", ACTION(set_powerstat), ARG_IN | ARG_NOVFO, "Power Status" }, { 0x88, "get_powerstat", ACTION(get_powerstat), ARG_OUT | ARG_NOVFO, "Power Status" }, { 0x89, "send_dtmf", ACTION(send_dtmf), ARG_IN, "Digits" }, - { 0x8a, "recv_dtmf", ACTION(recv_dtmf), ARG_OUT,"Digits" }, + { 0x8a, "recv_dtmf", ACTION(recv_dtmf), ARG_OUT, "Digits" }, { '*', "reset", ACTION(reset), ARG_IN, "Reset" }, { 'w', "send_cmd", ACTION(send_cmd), ARG_IN1 | ARG_IN_LINE | ARG_OUT2 | ARG_NOVFO, "Cmd", "Reply" }, { 'b', "send_morse", ACTION(send_morse), ARG_IN | ARG_IN_LINE, "Morse" }, - { 0x8b, "get_dcd", ACTION(get_dcd), ARG_OUT,"DCD" }, + { 0x8b, "get_dcd", ACTION(get_dcd), ARG_OUT, "DCD" }, { '2', "power2mW", ACTION(power2mW), ARG_IN1 | ARG_IN2 | ARG_IN3 | ARG_OUT1 | ARG_NOVFO, "Power [0.0..1.0]", "Frequency", "Mode", "Power mW" }, { '4', "mW2power", ACTION(mW2power), ARG_IN1 | ARG_IN2 | ARG_IN3 | ARG_OUT1 | ARG_NOVFO, "Power mW", "Frequency", "Mode", "Power [0.0..1.0]" }, { '1', "dump_caps", ACTION(dump_caps), ARG_NOVFO }, @@ -319,17 +321,20 @@ static struct test_table test_list[] = { }; -static struct test_table *find_cmd_entry(int cmd) +static struct test_table * find_cmd_entry(int cmd) { int i; - for (i = 0; i < MAXNBOPT && test_list[i].cmd != 0x00; i++) { - if (test_list[i].cmd == cmd) { + for (i = 0; i < MAXNBOPT && test_list[i].cmd != 0x00; i++) + { + if (test_list[i].cmd == cmd) + { break; } } - if (i >= MAXNBOPT || test_list[i].cmd == 0x00) { + if (i >= MAXNBOPT || test_list[i].cmd == 0x00) + { return NULL; } @@ -342,7 +347,8 @@ static struct test_table *find_cmd_entry(int cmd) * Structure and hash funtions patterned after/copied from example.c * distributed with the uthash package. See: http://uthash.sourceforge.net/ */ -struct mod_lst { +struct mod_lst +{ int id; /* caps->rig_model This is the hash key */ char mfg_name[32]; /* caps->mfg_name */ char model_name[32]; /* caps->model_name */ @@ -395,7 +401,8 @@ void hash_delete_all() { struct mod_lst *current_model, *tmp; - HASH_ITER(hh, models, current_model, tmp) { + HASH_ITER(hh, models, current_model, tmp) + { HASH_DEL(models, current_model); /* delete it (models advances to next) */ free(current_model); /* free it */ } @@ -411,16 +418,19 @@ static void rp_getline(const char *s) int i; /* free allocated memory and set pointers to NULL */ - if (input_line) { + if (input_line) + { free(input_line); input_line = (char *)NULL; } - if (result) { + if (result) + { result = (char *)NULL; } - for (i = 0; i < 5; i++) { + for (i = 0; i < 5; i++) + { parsed_input[i] = NULL; } @@ -439,8 +449,10 @@ static char parse_arg(const char *arg) { int i; - for (i = 0; i < MAXNBOPT && test_list[i].cmd != 0; i++) { - if (!strncmp(arg, test_list[i].name, MAXNAMSIZ)) { + for (i = 0; i < MAXNBOPT && test_list[i].cmd != 0; i++) + { + if (!strncmp(arg, test_list[i].name, MAXNAMSIZ)) + { return test_list[i].cmd; } } @@ -456,11 +468,14 @@ static int scanfc(FILE *fin, const char *format, void *p) { int ret; - do { + do + { ret = fscanf(fin, format, p); - if (ret < 0) { - if (errno == EINTR) { + if (ret < 0) + { + if (errno == EINTR) + { continue; } @@ -472,7 +487,8 @@ static int scanfc(FILE *fin, const char *format, void *p) } return ret; - } while (1); + } + while (1); } @@ -491,40 +507,58 @@ static int next_word(char *buffer, int argc, char *argv[], int newline) char c; static int reading_stdin; - if (!reading_stdin) { - if (optind >= argc) { + if (!reading_stdin) + { + if (optind >= argc) + { return EOF; - } else if (newline && '-' == argv[optind][0] && 1 == strlen(argv[optind])) { + } + else if (newline && '-' == argv[optind][0] && 1 == strlen(argv[optind])) + { ++optind; reading_stdin = 1; } } - if (reading_stdin) { - do { - do { + if (reading_stdin) + { + do + { + do + { ret = scanf(" %c%" STR(MAXARGSZ) "[^ \t\n#]", &c, &buffer[1]); - } while (EINTR == ret); + } + while (EINTR == ret); - if (ret > 0 && '#' == c) { - do { + if (ret > 0 && '#' == c) + { + do + { ret = scanf("%*[^\n]"); - } while (EINTR == ret); /* consume comments */ + } + while (EINTR == ret); /* consume comments */ ret = 0; } - } while (!ret); + } + while (!ret); - if (EOF == ret) { + if (EOF == ret) + { reading_stdin = 0; - } else if (ret < 0) { + } + else if (ret < 0) + { rig_debug(RIG_DEBUG_ERR, "scanf: %s\n", strerror(errno)); reading_stdin = 0; - } else { + } + else + { buffer[0] = c; buffer[1 == ret ? 1 : MAXARGSZ] = '\0'; - if (newline) { + if (newline) + { putchar('\n'); } @@ -533,12 +567,16 @@ static int next_word(char *buffer, int argc, char *argv[], int newline) } } - if (!reading_stdin) { - if (optind < argc) { + if (!reading_stdin) + { + if (optind < argc) + { strncpy(buffer, argv[optind++], MAXARGSZ); buffer[MAXARGSZ] = '\0'; ret = 1; - } else { + } + else + { ret = EOF; } } @@ -577,27 +615,36 @@ int rigctl_parse(RIG *my_rig, FILE *fin, FILE *fout, char *argv[], int argc) vfo_t vfo = RIG_VFO_CURR; /* cmd, internal, rigctld */ - if (!(interactive && prompt && have_rl)) { - if (interactive) { - if (prompt) { + if (!(interactive && prompt && have_rl)) + { + if (interactive) + { + if (prompt) + { fprintf_flush(fout, "\nRig command: "); } - do { - if (scanfc(fin, "%c", &cmd) < 1) { + do + { + if (scanfc(fin, "%c", &cmd) < 1) + { return -1; } /* Extended response protocol requested with leading '+' on command * string--rigctld only! */ - if (cmd == '+' && !prompt) { + if (cmd == '+' && !prompt) + { ext_resp = 1; - if (scanfc(fin, "%c", &cmd) < 1) { + if (scanfc(fin, "%c", &cmd) < 1) + { return -1; } - } else if (cmd == '+' && prompt) { + } + else if (cmd == '+' && prompt) + { return 0; } @@ -605,35 +652,43 @@ int rigctl_parse(RIG *my_rig, FILE *fin, FILE *fout, char *argv[], int argc) && cmd != '_' && cmd != '#' && ispunct(cmd) - && !prompt) { + && !prompt) + { ext_resp = 1; resp_sep = cmd; - if (scanfc(fin, "%c", &cmd) < 1) { + if (scanfc(fin, "%c", &cmd) < 1) + { return -1; } - } else if (cmd != '\\' - && cmd != '?' - && cmd != '_' - && cmd != '#' - && ispunct(cmd) - && prompt) { + } + else if (cmd != '\\' + && cmd != '?' + && cmd != '_' + && cmd != '#' + && ispunct(cmd) + && prompt) + { return 0; } /* command by name */ - if (cmd == '\\') { + if (cmd == '\\') + { unsigned char cmd_name[MAXNAMSIZ], *pcmd = cmd_name; int c_len = MAXNAMSIZ; - if (scanfc(fin, "%c", pcmd) < 1) { + if (scanfc(fin, "%c", pcmd) < 1) + { return -1; } - while (c_len-- && (isalnum(*pcmd) || *pcmd == '_')) { - if (scanfc(fin, "%c", ++pcmd) < 1) { + while (c_len-- && (isalnum(*pcmd) || *pcmd == '_')) + { + if (scanfc(fin, "%c", ++pcmd) < 1) + { return -1; } } @@ -643,9 +698,12 @@ int rigctl_parse(RIG *my_rig, FILE *fin, FILE *fout, char *argv[], int argc) break; } - if (cmd == 0x0a || cmd == 0x0d) { - if (last_was_ret) { - if (prompt) { + if (cmd == 0x0a || cmd == 0x0d) + { + if (last_was_ret) + { + if (prompt) + { fprintf(fout, "? for help, q to quit.\n"); fprintf_flush(fout, "\nRig command: "); } @@ -655,14 +713,18 @@ int rigctl_parse(RIG *my_rig, FILE *fin, FILE *fout, char *argv[], int argc) last_was_ret = 1; } - } while (cmd == 0x0a || cmd == 0x0d); + } + while (cmd == 0x0a || cmd == 0x0d); last_was_ret = 0; /* comment line */ - if (cmd == '#') { - while (cmd != '\n' && cmd != '\r') { - if (scanfc(fin, "%c", &cmd) < 1) { + if (cmd == '#') + { + while (cmd != '\n' && cmd != '\r') + { + if (scanfc(fin, "%c", &cmd) < 1) + { return -1; } } @@ -670,55 +732,76 @@ int rigctl_parse(RIG *my_rig, FILE *fin, FILE *fout, char *argv[], int argc) return 0; } - if (cmd == 'Q' || cmd == 'q') { + if (cmd == 'Q' || cmd == 'q') + { return 1; } - if (cmd == '?') { + if (cmd == '?') + { usage_rig(fout); fflush(fout); return 0; } - } else { + } + else + { /* parse rest of command line */ retcode = next_word(command, argc, argv, 1); - if (EOF == retcode) { + if (EOF == retcode) + { return 1; - } else if (retcode < 0) { + } + else if (retcode < 0) + { return retcode; - } else if ('\0' == command[1]) { + } + else if ('\0' == command[1]) + { cmd = command[0]; - } else { + } + else + { cmd = parse_arg(command); } } cmd_entry = find_cmd_entry(cmd); - if (!cmd_entry) { + if (!cmd_entry) + { fprintf(stderr, "Command '%c' not found!\n", cmd); return 0; } - if (!(cmd_entry->flags & ARG_NOVFO) && vfo_mode) { - if (interactive) { - if (prompt) { + if (!(cmd_entry->flags & ARG_NOVFO) && vfo_mode) + { + if (interactive) + { + if (prompt) + { fprintf_flush(fout, "VFO: "); } - if (scanfc(fin, "%s", arg1) < 1) { + if (scanfc(fin, "%s", arg1) < 1) + { return -1; } vfo = rig_parse_vfo(arg1); - } else { + } + else + { retcode = next_word(arg1, argc, argv, 0); - if (EOF == retcode) { + if (EOF == retcode) + { fprintf(stderr, "Invalid arg for command '%s'\n", cmd_entry->name); - } else if (retcode < 0) { + } + else if (retcode < 0) + { return retcode; } @@ -728,64 +811,86 @@ int rigctl_parse(RIG *my_rig, FILE *fin, FILE *fout, char *argv[], int argc) if ((cmd_entry->flags & ARG_IN_LINE) && (cmd_entry->flags & ARG_IN1) - && cmd_entry->arg1) { + && cmd_entry->arg1) + { - if (interactive) { + if (interactive) + { char *nl; - if (prompt) { + if (prompt) + { fprintf_flush(fout, "%s: ", cmd_entry->arg1); } - if (fgets(arg1, MAXARGSZ, fin) == NULL) { + if (fgets(arg1, MAXARGSZ, fin) == NULL) + { return -1; } - if (arg1[0] == 0xa) { - if (fgets(arg1, MAXARGSZ, fin) == NULL) { + if (arg1[0] == 0xa) + { + if (fgets(arg1, MAXARGSZ, fin) == NULL) + { return -1; } } nl = strchr(arg1, 0xa); - if (nl) { + if (nl) + { *nl = '\0'; /* chomp */ } p1 = arg1[0] == ' ' ? arg1 + 1 : arg1; - } else { + } + else + { retcode = next_word(arg1, argc, argv, 0); - if (EOF == retcode) { + if (EOF == retcode) + { fprintf(stderr, "Invalid arg for command '%s'\n", cmd_entry->name); return 1; - } else if (retcode < 0) { + } + else if (retcode < 0) + { return retcode; } p1 = arg1; } - } else if ((cmd_entry->flags & ARG_IN1) && cmd_entry->arg1) { - if (interactive) { - if (prompt) { + } + else if ((cmd_entry->flags & ARG_IN1) && cmd_entry->arg1) + { + if (interactive) + { + if (prompt) + { fprintf_flush(fout, "%s: ", cmd_entry->arg1); } - if (scanfc(fin, "%s", arg1) < 1) { + if (scanfc(fin, "%s", arg1) < 1) + { return -1; } p1 = arg1; - } else { + } + else + { retcode = next_word(arg1, argc, argv, 0); - if (EOF == retcode) { + if (EOF == retcode) + { fprintf(stderr, "Invalid arg for command '%s'\n", cmd_entry->name); return 1; - } else if (retcode < 0) { + } + else if (retcode < 0) + { return retcode; } @@ -796,26 +901,35 @@ int rigctl_parse(RIG *my_rig, FILE *fin, FILE *fout, char *argv[], int argc) if (p1 && p1[0] != '?' && (cmd_entry->flags & ARG_IN2) - && cmd_entry->arg2) { + && cmd_entry->arg2) + { - if (interactive) { - if (prompt) { + if (interactive) + { + if (prompt) + { fprintf_flush(fout, "%s: ", cmd_entry->arg2); } - if (scanfc(fin, "%s", arg2) < 1) { + if (scanfc(fin, "%s", arg2) < 1) + { return -1; } p2 = arg2; - } else { + } + else + { retcode = next_word(arg2, argc, argv, 0); - if (EOF == retcode) { + if (EOF == retcode) + { fprintf(stderr, "Invalid arg for command '%s'\n", cmd_entry->name); return 1; - } else if (retcode < 0) { + } + else if (retcode < 0) + { return retcode; } @@ -826,26 +940,36 @@ int rigctl_parse(RIG *my_rig, FILE *fin, FILE *fout, char *argv[], int argc) if (p1 && p1[0] != '?' && (cmd_entry->flags & ARG_IN3) - && cmd_entry->arg3) { + && cmd_entry->arg3) + { - if (interactive) { - if (prompt) { + if (interactive) + { + if (prompt) + { fprintf_flush(fout, "%s: ", cmd_entry->arg3); } - if (scanfc(fin, "%s", arg3) < 1) { + if (scanfc(fin, "%s", arg3) < 1) + { return -1; } p3 = arg3; - } else { + } + else + { retcode = next_word(arg3, argc, argv, 0); - if (EOF == retcode) { - fprintf(stderr, "Invalid arg for command '%s'\n", + if (EOF == retcode) + { + fprintf(stderr, + "Invalid arg for command '%s'\n", cmd_entry->name); return 1; - } else if (retcode < 0) { + } + else if (retcode < 0) + { return retcode; } @@ -856,7 +980,8 @@ int rigctl_parse(RIG *my_rig, FILE *fin, FILE *fout, char *argv[], int argc) #ifdef HAVE_LIBREADLINE - if (interactive && prompt && have_rl) { + if (interactive && prompt && have_rl) + { int j, x; #ifdef HAVE_READLINE_HISTORY @@ -872,30 +997,35 @@ int rigctl_parse(RIG *my_rig, FILE *fin, FILE *fout, char *argv[], int argc) rp_getline("\nRig command: "); /* EOF (Ctl-D) received on empty input line, bail out gracefully. */ - if (!input_line) { + if (!input_line) + { fprintf_flush(fout, "\n"); return 1; } /* Q or q to quit */ - if (!(strncasecmp(input_line, "q", 1))) { + if (!(strncasecmp(input_line, "q", 1))) + { return 1; } /* '?' for help */ - if (!(strncmp(input_line, "?", 1))) { + if (!(strncmp(input_line, "?", 1))) + { usage_rig(fout); fflush(fout); return 0; } /* '#' for comment */ - if (!(strncmp(input_line, "#", 1))) { + if (!(strncmp(input_line, "#", 1))) + { return 0; } /* Blank line entered */ - if (!(strcmp(input_line, ""))) { + if (!(strcmp(input_line, ""))) + { fprintf(fout, "? for help, q to quit.\n"); fflush(fout); return 0; @@ -913,9 +1043,12 @@ int rigctl_parse(RIG *my_rig, FILE *fin, FILE *fout, char *argv[], int argc) /* parsed_input stores pointers into input_line where the token strings * start. */ - if (result) { + if (result) + { parsed_input[0] = result; - } else { + } + else + { /* Oops! Invoke GDB!! */ fprintf_flush(fout, "\n"); return 1; @@ -927,33 +1060,38 @@ int rigctl_parse(RIG *my_rig, FILE *fin, FILE *fout, char *argv[], int argc) */ /* Single character command */ - if ((strlen(parsed_input[0]) == 1) && (*parsed_input[0] != '\\')) { + if ((strlen(parsed_input[0]) == 1) && (*parsed_input[0] != '\\')) + { cmd = *parsed_input[0]; #ifdef HAVE_READLINE_HISTORY /* Store what is typed, not validated, for history. */ - if (rp_hist_buf) { + if (rp_hist_buf) + { strncpy(rp_hist_buf, parsed_input[0], 1); } #endif } /* Test the command token, parsed_input[0] */ - else if ((*parsed_input[0] == '\\') && (strlen(parsed_input[0]) > 1)) { + else if ((*parsed_input[0] == '\\') && (strlen(parsed_input[0]) > 1)) + { char cmd_name[MAXNAMSIZ]; /* if there is no terminating '\0' character in the source string, * srncpy() doesn't add one even if the supplied length is less * than the destination array. Truncate the source string here. */ - if (strlen(parsed_input[0] + 1) >= MAXNAMSIZ) { + if (strlen(parsed_input[0] + 1) >= MAXNAMSIZ) + { *(parsed_input[0] + MAXNAMSIZ) = '\0'; } #ifdef HAVE_READLINE_HISTORY - if (rp_hist_buf) { + if (rp_hist_buf) + { strncpy(rp_hist_buf, parsed_input[0], MAXNAMSIZ); } @@ -968,8 +1106,10 @@ int rigctl_parse(RIG *my_rig, FILE *fin, FILE *fout, char *argv[], int argc) /* Sanity check as valid multiple character commands consist of * alpha-numeric characters and the underscore ('_') character. */ - for (j = 0; cmd_name[j] != '\0'; j++) { - if (!(isalnum((int)cmd_name[j]) || cmd_name[j] == '_')) { + for (j = 0; cmd_name[j] != '\0'; j++) + { + if (!(isalnum((int)cmd_name[j]) || cmd_name[j] == '_')) + { fprintf(stderr, "Valid multiple character command names contain alpha-numeric characters plus '_'\n"); return 0; @@ -979,21 +1119,27 @@ int rigctl_parse(RIG *my_rig, FILE *fin, FILE *fout, char *argv[], int argc) cmd = parse_arg(cmd_name); } /* Single '\' entered, prompt again */ - else if ((*parsed_input[0] == '\\') && (strlen(parsed_input[0]) == 1)) { + else if ((*parsed_input[0] == '\\') && (strlen(parsed_input[0]) == 1)) + { return 0; } /* Multiple characters but no leading '\' */ - else { + else + { fprintf(stderr, "Precede multiple character command names with '\\'\n"); return 0; } cmd_entry = find_cmd_entry(cmd); - if (!cmd_entry) { - if (cmd == '\0') { + if (!cmd_entry) + { + if (cmd == '\0') + { fprintf(stderr, "Command '%s' not found!\n", parsed_input[0]); - } else { + } + else + { fprintf(stderr, "Command '%c' not found!\n", cmd); } @@ -1003,26 +1149,31 @@ int rigctl_parse(RIG *my_rig, FILE *fin, FILE *fout, char *argv[], int argc) /* If vfo_mode is enabled (-o|--vfo) check if already given * or prompt for it. */ - if (!(cmd_entry->flags & ARG_NOVFO) && vfo_mode) { + if (!(cmd_entry->flags & ARG_NOVFO) && vfo_mode) + { /* Check if VFO was given with command. */ result = strtok(NULL, " "); - if (result) { + if (result) + { x = 1; parsed_input[x] = result; } /* Need to prompt if a VFO string was not given. */ - else { + else + { x = 0; rp_getline("VFO: "); - if (!input_line) { + if (!input_line) + { fprintf_flush(fout, "\n"); return 1; } /* Blank line entered */ - if (!(strcmp(input_line, ""))) { + if (!(strcmp(input_line, ""))) + { fprintf(fout, "? for help, q to quit.\n"); fflush(fout); return 0; @@ -1033,9 +1184,12 @@ int rigctl_parse(RIG *my_rig, FILE *fin, FILE *fout, char *argv[], int argc) */ result = strtok(input_line, " "); - if (result) { + if (result) + { parsed_input[x] = result; - } else { + } + else + { fprintf_flush(fout, "\n"); return 1; } @@ -1044,13 +1198,15 @@ int rigctl_parse(RIG *my_rig, FILE *fin, FILE *fout, char *argv[], int argc) /* VFO name tokens are presently quite short. Truncate excessively * long strings. */ - if (strlen(parsed_input[x]) >= MAXNAMSIZ) { + if (strlen(parsed_input[x]) >= MAXNAMSIZ) + { *(parsed_input[x] + (MAXNAMSIZ - 1)) = '\0'; } #ifdef HAVE_READLINE_HISTORY - if (rp_hist_buf) { + if (rp_hist_buf) + { strncat(rp_hist_buf, " ", 1); strncat(rp_hist_buf, parsed_input[x], MAXNAMSIZ); } @@ -1058,8 +1214,10 @@ int rigctl_parse(RIG *my_rig, FILE *fin, FILE *fout, char *argv[], int argc) #endif /* Sanity check, VFO names are alpha only. */ - for (j = 0; j < MAXNAMSIZ && parsed_input[x][j] != '\0'; j++) { - if (!(isalpha((int)parsed_input[x][j]))) { + for (j = 0; j < MAXNAMSIZ && parsed_input[x][j] != '\0'; j++) + { + if (!(isalpha((int)parsed_input[x][j]))) + { parsed_input[x][j] = '\0'; break; @@ -1068,7 +1226,8 @@ int rigctl_parse(RIG *my_rig, FILE *fin, FILE *fout, char *argv[], int argc) vfo = rig_parse_vfo(parsed_input[x]); - if (vfo == RIG_VFO_NONE) { + if (vfo == RIG_VFO_NONE) + { fprintf(stderr, "Warning: VFO '%s' unrecognized, using 'currVFO' instead.\n", parsed_input[x]); @@ -1079,19 +1238,25 @@ int rigctl_parse(RIG *my_rig, FILE *fin, FILE *fout, char *argv[], int argc) /* \send_cmd, \send_morse */ if ((cmd_entry->flags & ARG_IN_LINE) && (cmd_entry->flags & ARG_IN1) - && cmd_entry->arg1) { + && cmd_entry->arg1) + { /* Check for a non-existent delimiter so as to not break up * remaining line into separate tokens (spaces OK). */ result = strtok(NULL, "\0"); - if (vfo_mode && result) { + if (vfo_mode && result) + { x = 2; parsed_input[x] = result; - } else if (result) { + } + else if (result) + { x = 1; parsed_input[x] = result; - } else { + } + else + { x = 0; char pmptstr[(strlen(cmd_entry->arg1) + 3)]; @@ -1101,28 +1266,34 @@ int rigctl_parse(RIG *my_rig, FILE *fin, FILE *fout, char *argv[], int argc) rp_getline(pmptstr); /* Blank line entered */ - if (!(strcmp(input_line, ""))) { + if (!(strcmp(input_line, ""))) + { fprintf(fout, "? for help, q to quit.\n"); fflush(fout); return 0; } - if (input_line) { + if (input_line) + { parsed_input[x] = input_line; - } else { + } + else + { fprintf_flush(fout, "\n"); return 1; } } /* The arg1 array size is MAXARGSZ + 1 so truncate it to fit if larger. */ - if (strlen(parsed_input[x]) > MAXARGSZ) { + if (strlen(parsed_input[x]) > MAXARGSZ) + { parsed_input[x][MAXARGSZ] = '\0'; } #ifdef HAVE_READLINE_HISTORY - if (rp_hist_buf) { + if (rp_hist_buf) + { strncat(rp_hist_buf, " ", 1); strncat(rp_hist_buf, parsed_input[x], MAXARGSZ); } @@ -1133,16 +1304,22 @@ int rigctl_parse(RIG *my_rig, FILE *fin, FILE *fout, char *argv[], int argc) } /* Normal argument parsing. */ - else if ((cmd_entry->flags & ARG_IN1) && cmd_entry->arg1) { + else if ((cmd_entry->flags & ARG_IN1) && cmd_entry->arg1) + { result = strtok(NULL, " "); - if (vfo_mode && result) { + if (vfo_mode && result) + { x = 2; parsed_input[x] = result; - } else if (result) { + } + else if (result) + { x = 1; parsed_input[x] = result; - } else { + } + else + { x = 0; char pmptstr[(strlen(cmd_entry->arg1) + 3)]; @@ -1151,7 +1328,8 @@ int rigctl_parse(RIG *my_rig, FILE *fin, FILE *fout, char *argv[], int argc) rp_getline(pmptstr); - if (!(strcmp(input_line, ""))) { + if (!(strcmp(input_line, ""))) + { fprintf(fout, "? for help, q to quit.\n"); fflush(fout); return 0; @@ -1159,21 +1337,26 @@ int rigctl_parse(RIG *my_rig, FILE *fin, FILE *fout, char *argv[], int argc) result = strtok(input_line, " "); - if (result) { + if (result) + { parsed_input[x] = result; - } else { + } + else + { fprintf_flush(fout, "\n"); return 1; } } - if (strlen(parsed_input[x]) > MAXARGSZ) { + if (strlen(parsed_input[x]) > MAXARGSZ) + { parsed_input[x][MAXARGSZ] = '\0'; } #ifdef HAVE_READLINE_HISTORY - if (rp_hist_buf) { + if (rp_hist_buf) + { strncat(rp_hist_buf, " ", 1); strncat(rp_hist_buf, parsed_input[x], MAXARGSZ); } @@ -1186,17 +1369,23 @@ int rigctl_parse(RIG *my_rig, FILE *fin, FILE *fout, char *argv[], int argc) if (p1 && p1[0] != '?' && (cmd_entry->flags & ARG_IN2) - && cmd_entry->arg2) { + && cmd_entry->arg2) + { result = strtok(NULL, " "); - if (vfo_mode && result) { + if (vfo_mode && result) + { x = 3; parsed_input[x] = result; - } else if (result) { + } + else if (result) + { x = 2; parsed_input[x] = result; - } else { + } + else + { x = 0; char pmptstr[(strlen(cmd_entry->arg2) + 3)]; @@ -1205,7 +1394,8 @@ int rigctl_parse(RIG *my_rig, FILE *fin, FILE *fout, char *argv[], int argc) rp_getline(pmptstr); - if (!(strcmp(input_line, ""))) { + if (!(strcmp(input_line, ""))) + { fprintf(fout, "? for help, q to quit.\n"); fflush(fout); return 0; @@ -1213,21 +1403,26 @@ int rigctl_parse(RIG *my_rig, FILE *fin, FILE *fout, char *argv[], int argc) result = strtok(input_line, " "); - if (result) { + if (result) + { parsed_input[x] = result; - } else { + } + else + { fprintf_flush(fout, "\n"); return 1; } } - if (strlen(parsed_input[x]) > MAXARGSZ) { + if (strlen(parsed_input[x]) > MAXARGSZ) + { parsed_input[x][MAXARGSZ] = '\0'; } #ifdef HAVE_READLINE_HISTORY - if (rp_hist_buf) { + if (rp_hist_buf) + { strncat(rp_hist_buf, " ", 1); strncat(rp_hist_buf, parsed_input[x], MAXARGSZ); } @@ -1240,17 +1435,23 @@ int rigctl_parse(RIG *my_rig, FILE *fin, FILE *fout, char *argv[], int argc) if (p1 && p1[0] != '?' && (cmd_entry->flags & ARG_IN3) - && cmd_entry->arg3) { + && cmd_entry->arg3) + { result = strtok(NULL, " "); - if (vfo_mode && result) { + if (vfo_mode && result) + { x = 4; parsed_input[x] = result; - } else if (result) { + } + else if (result) + { x = 3; parsed_input[x] = result; - } else { + } + else + { x = 0; char pmptstr[(strlen(cmd_entry->arg3) + 3)]; @@ -1259,7 +1460,8 @@ int rigctl_parse(RIG *my_rig, FILE *fin, FILE *fout, char *argv[], int argc) rp_getline(pmptstr); - if (!(strcmp(input_line, ""))) { + if (!(strcmp(input_line, ""))) + { fprintf(fout, "? for help, q to quit.\n"); fflush(fout); return 0; @@ -1267,21 +1469,26 @@ int rigctl_parse(RIG *my_rig, FILE *fin, FILE *fout, char *argv[], int argc) result = strtok(input_line, " "); - if (result) { + if (result) + { parsed_input[x] = result; - } else { + } + else + { fprintf_flush(fout, "\n"); return 1; } } - if (strlen(parsed_input[x]) > MAXARGSZ) { + if (strlen(parsed_input[x]) > MAXARGSZ) + { parsed_input[x][MAXARGSZ] = '\0'; } #ifdef HAVE_READLINE_HISTORY - if (rp_hist_buf) { + if (rp_hist_buf) + { strncat(rp_hist_buf, " ", 1); strncat(rp_hist_buf, parsed_input[x], MAXARGSZ); } @@ -1293,7 +1500,8 @@ int rigctl_parse(RIG *my_rig, FILE *fin, FILE *fout, char *argv[], int argc) #ifdef HAVE_READLINE_HISTORY - if (rp_hist_buf) { + if (rp_hist_buf) + { add_history(rp_hist_buf); free(rp_hist_buf); rp_hist_buf = (char *)NULL; @@ -1313,7 +1521,8 @@ int rigctl_parse(RIG *my_rig, FILE *fin, FILE *fout, char *argv[], int argc) pthread_mutex_lock(&rig_mutex); #endif - if (!prompt) { + if (!prompt) + { rig_debug(RIG_DEBUG_TRACE, "rigctl(d): %c '%s' '%s' '%s' '%s'\n", cmd, @@ -1327,7 +1536,8 @@ int rigctl_parse(RIG *my_rig, FILE *fin, FILE *fout, char *argv[], int argc) * Extended Response protocol: output received command name and arguments * response. Don't send command header on '\chk_vfo' command. */ - if (interactive && ext_resp && !prompt && cmd != 0xf0) { + if (interactive && ext_resp && !prompt && cmd != 0xf0) + { char a1[MAXARGSZ + 1]; char a2[MAXARGSZ + 1]; char a3[MAXARGSZ + 1]; @@ -1367,29 +1577,38 @@ int rigctl_parse(RIG *my_rig, FILE *fin, FILE *fout, char *argv[], int argc) #endif - if (retcode != RIG_OK) { + if (retcode != RIG_OK) + { /* only for rigctld */ - if (interactive && !prompt) { + if (interactive && !prompt) + { fprintf(fout, NETRIGCTL_RET "%d\n", retcode); ext_resp = 0; resp_sep = '\n'; - } else { + } + else + { fprintf(fout, "%s: error = %s\n", cmd_entry->name, rigerror(retcode)); } - } else { + } + else + { /* only for rigctld */ - if (interactive && !prompt) { + if (interactive && !prompt) + { /* netrigctl RIG_OK */ if (!(cmd_entry->flags & ARG_OUT) - && !ext_resp && cmd != 0xf0) { + && !ext_resp && cmd != 0xf0) + { fprintf(fout, NETRIGCTL_RET "0\n"); } /* Extended Response protocol */ - else if (ext_resp && cmd != 0xf0) { + else if (ext_resp && cmd != 0xf0) + { fprintf(fout, NETRIGCTL_RET "0\n"); ext_resp = 0; resp_sep = '\n'; @@ -1399,7 +1618,8 @@ int rigctl_parse(RIG *my_rig, FILE *fin, FILE *fout, char *argv[], int argc) fflush(fout); - if (retcode == -RIG_ENAVAIL) { + if (retcode == -RIG_ENAVAIL) + { return retcode; } @@ -1420,7 +1640,8 @@ void usage_rig(FILE *fout) fprintf(fout, "Commands (some may not be available for this rig):\n"); - for (i = 0; test_list[i].cmd != 0; i++) { + for (i = 0; test_list[i].cmd != 0; i++) + { fprintf(fout, "%c: %-16s(", isprint(test_list[i].cmd) ? test_list[i].cmd : '?', @@ -1428,21 +1649,27 @@ void usage_rig(FILE *fout) nbspaces = 18; - if (test_list[i].arg1 && (test_list[i].flags & ARG_IN1)) { + if (test_list[i].arg1 && (test_list[i].flags & ARG_IN1)) + { nbspaces -= fprintf(fout, "%s", test_list[i].arg1); } - if (test_list[i].arg2 && (test_list[i].flags & ARG_IN2)) { + if (test_list[i].arg2 && (test_list[i].flags & ARG_IN2)) + { nbspaces -= fprintf(fout, ",%s", test_list[i].arg2); } - if (test_list[i].arg3 && (test_list[i].flags & ARG_IN3)) { + if (test_list[i].arg3 && (test_list[i].flags & ARG_IN3)) + { nbspaces -= fprintf(fout, ",%s", test_list[i].arg3); } - if (i % 2) { + if (i % 2) + { fprintf(fout, ")\n"); - } else { + } + else + { fprintf(fout, ")%*s", nbspaces, " "); } } @@ -1469,7 +1696,8 @@ int print_conf_list(const struct confparams *cfp, rig_ptr_t data) cfp->dflt, buf); - switch (cfp->type) { + switch (cfp->type) + { case RIG_CONF_NUMERIC: printf("\tRange: %.1f..%.1f, step %.1f\n", cfp->u.n.min, @@ -1478,13 +1706,15 @@ int print_conf_list(const struct confparams *cfp, rig_ptr_t data) break; case RIG_CONF_COMBO: - if (!cfp->u.c.combostr[0]) { + if (!cfp->u.c.combostr[0]) + { break; } printf("\tCombo: %s", cfp->u.c.combostr[0]); - for (i = 1 ; i < RIG_COMBO_MAX && cfp->u.c.combostr[i]; i++) { + for (i = 1 ; i < RIG_COMBO_MAX && cfp->u.c.combostr[i]; i++) + { printf(", %s", cfp->u.c.combostr[i]); } @@ -1527,7 +1757,8 @@ void print_model_list() { struct mod_lst *s; - for (s = models; s != NULL; s = (struct mod_lst *)(s->hh.next)) { + for (s = models; s != NULL; s = (struct mod_lst *)(s->hh.next)) + { printf("%6d %-23s%-24s%-16s%s\n", s->id, s->mfg_name, @@ -1547,7 +1778,8 @@ void list_models() printf(" Rig # Mfg Model Version Status\n"); status = rig_list_foreach(hash_model_list, NULL); - if (status != RIG_OK) { + if (status != RIG_OK) + { printf("rig_list_foreach: error = %s \n", rigerror(status)); exit(2); } @@ -1565,24 +1797,28 @@ int set_conf(RIG *my_rig, char *conf_parms) p = conf_parms; - while (p && *p != '\0') { + while (p && *p != '\0') + { /* FIXME: left hand value of = cannot be null */ q = strchr(p, '='); - if (!q) { + if (!q) + { return -RIG_EINVAL; } *q++ = '\0'; n = strchr(q, ','); - if (n) { + if (n) + { *n++ = '\0'; } ret = rig_set_conf(my_rig, rig_token_lookup(my_rig, p), q); - if (ret != RIG_OK) { + if (ret != RIG_OK) + { return ret; } @@ -1616,11 +1852,13 @@ declare_proto_rig(get_freq) status = rig_get_freq(rig, vfo, &freq); - if (status != RIG_OK) { + if (status != RIG_OK) + { return status; } - if ((interactive && prompt) || (interactive && !prompt && ext_resp)) { + if ((interactive && prompt) || (interactive && !prompt && ext_resp)) + { fprintf(fout, "%s: ", cmd->arg1); /* i.e. "Frequency" */ } @@ -1648,11 +1886,13 @@ declare_proto_rig(get_rit) status = rig_get_rit(rig, vfo, &rit); - if (status != RIG_OK) { + if (status != RIG_OK) + { return status; } - if ((interactive && prompt) || (interactive && !prompt && ext_resp)) { + if ((interactive && prompt) || (interactive && !prompt && ext_resp)) + { fprintf(fout, "%s: ", cmd->arg1); } @@ -1680,11 +1920,13 @@ declare_proto_rig(get_xit) status = rig_get_xit(rig, vfo, &xit); - if (status != RIG_OK) { + if (status != RIG_OK) + { return status; } - if ((interactive && prompt) || (interactive && !prompt && ext_resp)) { + if ((interactive && prompt) || (interactive && !prompt && ext_resp)) + { fprintf(fout, "%s: ", cmd->arg1); } @@ -1700,7 +1942,8 @@ declare_proto_rig(set_mode) rmode_t mode; pbwidth_t width; - if (!strcmp(arg1, "?")) { + if (!strcmp(arg1, "?")) + { char s[SPRINTF_MAX_SIZE]; sprintf_mode(s, rig->state.mode_list); fprintf(fout, "%s\n", s); @@ -1722,17 +1965,20 @@ declare_proto_rig(get_mode) status = rig_get_mode(rig, vfo, &mode, &width); - if (status != RIG_OK) { + if (status != RIG_OK) + { return status; } - if ((interactive && prompt) || (interactive && !prompt && ext_resp)) { + if ((interactive && prompt) || (interactive && !prompt && ext_resp)) + { fprintf(fout, "%s: ", cmd->arg1); } fprintf(fout, "%s%c", rig_strrmode(mode), resp_sep); - if ((interactive && prompt) || (interactive && !prompt && ext_resp)) { + if ((interactive && prompt) || (interactive && !prompt && ext_resp)) + { fprintf(fout, "%s: ", cmd->arg2); } @@ -1745,7 +1991,8 @@ declare_proto_rig(get_mode) /* 'V' */ declare_proto_rig(set_vfo) { - if (!strcmp(arg1, "?")) { + if (!strcmp(arg1, "?")) + { char s[SPRINTF_MAX_SIZE]; sprintf_vfo(s, rig->state.vfo_list); fprintf(fout, "%s\n", s); @@ -1763,11 +2010,13 @@ declare_proto_rig(get_vfo) status = rig_get_vfo(rig, &vfo); - if (status != RIG_OK) { + if (status != RIG_OK) + { return status; } - if ((interactive && prompt) || (interactive && !prompt && ext_resp)) { + if ((interactive && prompt) || (interactive && !prompt && ext_resp)) + { fprintf(fout, "%s: ", cmd->arg1); } @@ -1794,12 +2043,14 @@ declare_proto_rig(set_ptt) * Currently, this is not really necessary here because it is taken * case of in rig_set_ptt, but you never know .... */ - switch (ptt) { + switch (ptt) + { case RIG_PTT_ON_MIC: case RIG_PTT_ON_DATA: // map to a legal value - if (rig->state.pttport.type.ptt != RIG_PTT_RIG_MICDATA) { + if (rig->state.pttport.type.ptt != RIG_PTT_RIG_MICDATA) + { ptt = RIG_PTT_ON; } @@ -1829,11 +2080,13 @@ declare_proto_rig(get_ptt) status = rig_get_ptt(rig, vfo, &ptt); - if (status != RIG_OK) { + if (status != RIG_OK) + { return status; } - if ((interactive && prompt) || (interactive && !prompt && ext_resp)) { + if ((interactive && prompt) || (interactive && !prompt && ext_resp)) + { fprintf(fout, "%s: ", cmd->arg1); } @@ -1852,11 +2105,13 @@ declare_proto_rig(get_dcd) status = rig_get_dcd(rig, vfo, &dcd); - if (status != RIG_OK) { + if (status != RIG_OK) + { return status; } - if ((interactive && prompt) || (interactive && !prompt && ext_resp)) { + if ((interactive && prompt) || (interactive && !prompt && ext_resp)) + { fprintf(fout, "%s: ", cmd->arg1); } @@ -1884,11 +2139,13 @@ declare_proto_rig(get_rptr_shift) status = rig_get_rptr_shift(rig, vfo, &rptr_shift); - if (status != RIG_OK) { + if (status != RIG_OK) + { return status; } - if ((interactive && prompt) || (interactive && !prompt && ext_resp)) { + if ((interactive && prompt) || (interactive && !prompt && ext_resp)) + { fprintf(fout, "%s: ", cmd->arg1); } @@ -1916,11 +2173,13 @@ declare_proto_rig(get_rptr_offs) status = rig_get_rptr_offs(rig, vfo, &rptr_offs); - if (status != RIG_OK) { + if (status != RIG_OK) + { return status; } - if ((interactive && prompt) || (interactive && !prompt && ext_resp)) { + if ((interactive && prompt) || (interactive && !prompt && ext_resp)) + { fprintf(fout, "%s: ", cmd->arg1); } @@ -1948,11 +2207,13 @@ declare_proto_rig(get_ctcss_tone) status = rig_get_ctcss_tone(rig, vfo, &tone); - if (status != RIG_OK) { + if (status != RIG_OK) + { return status; } - if ((interactive && prompt) || (interactive && !prompt && ext_resp)) { + if ((interactive && prompt) || (interactive && !prompt && ext_resp)) + { fprintf(fout, "%s: ", cmd->arg1); } @@ -1980,11 +2241,13 @@ declare_proto_rig(get_dcs_code) status = rig_get_dcs_code(rig, vfo, &code); - if (status != RIG_OK) { + if (status != RIG_OK) + { return status; } - if ((interactive && prompt) || (interactive && !prompt && ext_resp)) { + if ((interactive && prompt) || (interactive && !prompt && ext_resp)) + { fprintf(fout, "%s: ", cmd->arg1); } @@ -2012,11 +2275,13 @@ declare_proto_rig(get_ctcss_sql) status = rig_get_ctcss_sql(rig, vfo, &tone); - if (status != RIG_OK) { + if (status != RIG_OK) + { return status; } - if ((interactive && prompt) || (interactive && !prompt && ext_resp)) { + if ((interactive && prompt) || (interactive && !prompt && ext_resp)) + { fprintf(fout, "%s: ", cmd->arg1); } @@ -2044,11 +2309,13 @@ declare_proto_rig(get_dcs_sql) status = rig_get_dcs_sql(rig, vfo, &code); - if (status != RIG_OK) { + if (status != RIG_OK) + { return status; } - if ((interactive && prompt) || (interactive && !prompt && ext_resp)) { + if ((interactive && prompt) || (interactive && !prompt && ext_resp)) + { fprintf(fout, "%s: ", cmd->arg1); } @@ -2078,11 +2345,13 @@ declare_proto_rig(get_split_freq) status = rig_get_split_freq(rig, txvfo, &txfreq); - if (status != RIG_OK) { + if (status != RIG_OK) + { return status; } - if ((interactive && prompt) || (interactive && !prompt && ext_resp)) { + if ((interactive && prompt) || (interactive && !prompt && ext_resp)) + { fprintf(fout, "%s: ", cmd->arg1); } @@ -2099,7 +2368,8 @@ declare_proto_rig(set_split_mode) int width; vfo_t txvfo = RIG_VFO_TX; - if (!strcmp(arg1, "?")) { + if (!strcmp(arg1, "?")) + { char s[SPRINTF_MAX_SIZE]; sprintf_mode(s, rig->state.mode_list); fprintf(fout, "%s\n", s); @@ -2122,17 +2392,20 @@ declare_proto_rig(get_split_mode) status = rig_get_split_mode(rig, txvfo, &mode, &width); - if (status != RIG_OK) { + if (status != RIG_OK) + { return status; } - if ((interactive && prompt) || (interactive && !prompt && ext_resp)) { + if ((interactive && prompt) || (interactive && !prompt && ext_resp)) + { fprintf(fout, "%s: ", cmd->arg1); } fprintf(fout, "%s%c", rig_strrmode(mode), resp_sep); - if ((interactive && prompt) || (interactive && !prompt && ext_resp)) { + if ((interactive && prompt) || (interactive && !prompt && ext_resp)) + { fprintf(fout, "%s: ", cmd->arg2); } @@ -2150,7 +2423,8 @@ declare_proto_rig(set_split_freq_mode) int width; vfo_t txvfo = RIG_VFO_TX; - if (!strcmp(arg1, "?")) { + if (!strcmp(arg1, "?")) + { char s[SPRINTF_MAX_SIZE]; sprintf_mode(s, rig->state.mode_list); fprintf(fout, "%s\n", s); @@ -2175,23 +2449,27 @@ declare_proto_rig(get_split_freq_mode) status = rig_get_split_freq_mode(rig, txvfo, &freq, &mode, &width); - if (status != RIG_OK) { + if (status != RIG_OK) + { return status; } - if ((interactive && prompt) || (interactive && !prompt && ext_resp)) { + if ((interactive && prompt) || (interactive && !prompt && ext_resp)) + { fprintf(fout, "%s: ", cmd->arg1); } fprintf(fout, "%"PRIll"%c", (int64_t)freq, resp_sep); - if ((interactive && prompt) || (interactive && !prompt && ext_resp)) { + if ((interactive && prompt) || (interactive && !prompt && ext_resp)) + { fprintf(fout, "%s: ", cmd->arg2); } fprintf(fout, "%s%c", rig_strrmode(mode), resp_sep); - if ((interactive && prompt) || (interactive && !prompt && ext_resp)) { + if ((interactive && prompt) || (interactive && !prompt && ext_resp)) + { fprintf(fout, "%s: ", cmd->arg3); } @@ -2209,7 +2487,8 @@ declare_proto_rig(set_split_vfo) CHKSCN1ARG(sscanf(arg1, "%d", &split)); - if (!strcmp(arg2, "?")) { + if (!strcmp(arg2, "?")) + { char s[SPRINTF_MAX_SIZE]; sprintf_vfo(s, rig->state.vfo_list); fprintf(fout, "%s\n", s); @@ -2218,7 +2497,8 @@ declare_proto_rig(set_split_vfo) tx_vfo = rig_parse_vfo(arg2); - if (tx_vfo == RIG_VFO_NONE) { + if (tx_vfo == RIG_VFO_NONE) + { return -RIG_EINVAL; } @@ -2235,17 +2515,20 @@ declare_proto_rig(get_split_vfo) status = rig_get_split_vfo(rig, vfo, &split, &tx_vfo); - if (status != RIG_OK) { + if (status != RIG_OK) + { return status; } - if ((interactive && prompt) || (interactive && !prompt && ext_resp)) { + if ((interactive && prompt) || (interactive && !prompt && ext_resp)) + { fprintf(fout, "%s: ", cmd->arg1); } fprintf(fout, "%d%c", split, resp_sep); - if ((interactive && prompt) || (interactive && !prompt && ext_resp)) { + if ((interactive && prompt) || (interactive && !prompt && ext_resp)) + { fprintf(fout, "%s: ", cmd->arg2); } @@ -2273,11 +2556,13 @@ declare_proto_rig(get_ts) status = rig_get_ts(rig, vfo, &ts); - if (status != RIG_OK) { + if (status != RIG_OK) + { return status; } - if ((interactive && prompt) || (interactive && !prompt && ext_resp)) { + if ((interactive && prompt) || (interactive && !prompt && ext_resp)) + { fprintf(fout, "%s: ", cmd->arg1); } @@ -2302,11 +2587,13 @@ declare_proto_rig(power2mW) status = rig_power2mW(rig, &mwp, power, freq, mode); - if (status != RIG_OK) { + if (status != RIG_OK) + { return status; } - if ((interactive && prompt) || (interactive && !prompt && ext_resp)) { + if ((interactive && prompt) || (interactive && !prompt && ext_resp)) + { fprintf(fout, "%s: ", cmd->arg4); } @@ -2331,11 +2618,13 @@ declare_proto_rig(mW2power) status = rig_mW2power(rig, &power, mwp, freq, mode); - if (status != RIG_OK) { + if (status != RIG_OK) + { return status; } - if ((interactive && prompt) || (interactive && !prompt && ext_resp)) { + if ((interactive && prompt) || (interactive && !prompt && ext_resp)) + { fprintf(fout, "%s: ", cmd->arg4); } @@ -2359,12 +2648,14 @@ declare_proto_rig(set_level) setting_t level; value_t val; - if (!strcmp(arg1, "?")) { + if (!strcmp(arg1, "?")) + { char s[SPRINTF_MAX_SIZE]; sprintf_level(s, rig->state.has_set_level); fputs(s, fout); - if (rig->caps->set_ext_level) { + if (rig->caps->set_ext_level) + { sprintf_level_ext(s, rig->caps->extlevels); fputs(s, fout); } @@ -2375,16 +2666,19 @@ declare_proto_rig(set_level) level = rig_parse_level(arg1); - if (!rig_has_set_level(rig, level)) { + if (!rig_has_set_level(rig, level)) + { const struct confparams *cfp; cfp = rig_ext_lookup(rig, arg1); - if (!cfp) { + if (!cfp) + { return -RIG_ENAVAIL; /* no such parameter */ } - switch (cfp->type) { + switch (cfp->type) + { case RIG_CONF_BUTTON: /* arg is ignored */ val.i = 0; // avoid passing uninitialized data @@ -2410,9 +2704,12 @@ declare_proto_rig(set_level) return rig_set_ext_level(rig, vfo, cfp->token, val); } - if (RIG_LEVEL_IS_FLOAT(level)) { + if (RIG_LEVEL_IS_FLOAT(level)) + { CHKSCN1ARG(sscanf(arg2, "%f", &val.f)); - } else { + } + else + { CHKSCN1ARG(sscanf(arg2, "%d", &val.i)); } @@ -2427,12 +2724,14 @@ declare_proto_rig(get_level) setting_t level; value_t val; - if (!strcmp(arg1, "?")) { + if (!strcmp(arg1, "?")) + { char s[SPRINTF_MAX_SIZE]; sprintf_level(s, rig->state.has_get_level); fputs(s, fout); - if (rig->caps->get_ext_level) { + if (rig->caps->get_ext_level) + { sprintf_level_ext(s, rig->caps->extlevels); fputs(s, fout); } @@ -2443,26 +2742,31 @@ declare_proto_rig(get_level) level = rig_parse_level(arg1); - if (!rig_has_get_level(rig, level)) { + if (!rig_has_get_level(rig, level)) + { const struct confparams *cfp; cfp = rig_ext_lookup(rig, arg1); - if (!cfp) { + if (!cfp) + { return -RIG_EINVAL; /* no such parameter */ } status = rig_get_ext_level(rig, vfo, cfp->token, &val); - if (status != RIG_OK) { + if (status != RIG_OK) + { return status; } - if (interactive && prompt) { + if (interactive && prompt) + { fprintf(fout, "%s: ", cmd->arg2); } - switch (cfp->type) { + switch (cfp->type) + { case RIG_CONF_BUTTON: /* there's no sense in retrieving value of stateless button */ return -RIG_EINVAL; @@ -2489,17 +2793,22 @@ declare_proto_rig(get_level) status = rig_get_level(rig, vfo, level, &val); - if (status != RIG_OK) { + if (status != RIG_OK) + { return status; } - if (interactive && prompt) { + if (interactive && prompt) + { fprintf(fout, "%s: ", cmd->arg2); } - if (RIG_LEVEL_IS_FLOAT(level)) { + if (RIG_LEVEL_IS_FLOAT(level)) + { fprintf(fout, "%f\n", val.f); - } else { + } + else + { fprintf(fout, "%d\n", val.i); } @@ -2513,7 +2822,8 @@ declare_proto_rig(set_func) setting_t func; int func_stat; - if (!strcmp(arg1, "?")) { + if (!strcmp(arg1, "?")) + { char s[SPRINTF_MAX_SIZE]; sprintf_func(s, rig->state.has_set_func); fprintf(fout, "%s\n", s); @@ -2522,7 +2832,8 @@ declare_proto_rig(set_func) func = rig_parse_func(arg1); - if (RIG_FUNC_NONE == func) { + if (RIG_FUNC_NONE == func) + { return -RIG_EINVAL; } @@ -2538,7 +2849,8 @@ declare_proto_rig(get_func) setting_t func; int func_stat; - if (!strcmp(arg1, "?")) { + if (!strcmp(arg1, "?")) + { char s[SPRINTF_MAX_SIZE]; sprintf_func(s, rig->state.has_get_func); fprintf(fout, "%s\n", s); @@ -2547,17 +2859,20 @@ declare_proto_rig(get_func) func = rig_parse_func(arg1); - if (RIG_FUNC_NONE == func) { + if (RIG_FUNC_NONE == func) + { return -RIG_EINVAL; } status = rig_get_func(rig, vfo, func, &func_stat); - if (status != RIG_OK) { + if (status != RIG_OK) + { return status; } - if (interactive && prompt) { + if (interactive && prompt) + { fprintf(fout, "%s: ", cmd->arg2); } @@ -2573,7 +2888,8 @@ declare_proto_rig(set_parm) setting_t parm; value_t val; - if (!strcmp(arg1, "?")) { + if (!strcmp(arg1, "?")) + { char s[SPRINTF_MAX_SIZE]; sprintf_parm(s, rig->state.has_set_parm); fprintf(fout, "%s\n", s); @@ -2582,16 +2898,19 @@ declare_proto_rig(set_parm) parm = rig_parse_parm(arg1); - if (!rig_has_set_parm(rig, parm)) { + if (!rig_has_set_parm(rig, parm)) + { const struct confparams *cfp; cfp = rig_ext_lookup(rig, arg1); - if (!cfp) { + if (!cfp) + { return -RIG_EINVAL; /* no such parameter */ } - switch (cfp->type) { + switch (cfp->type) + { case RIG_CONF_BUTTON: /* arg is ignored */ val.i = 0; // avoid passing uninitialized data @@ -2617,9 +2936,12 @@ declare_proto_rig(set_parm) return rig_set_ext_parm(rig, cfp->token, val); } - if (RIG_PARM_IS_FLOAT(parm)) { + if (RIG_PARM_IS_FLOAT(parm)) + { CHKSCN1ARG(sscanf(arg2, "%f", &val.f)); - } else { + } + else + { CHKSCN1ARG(sscanf(arg2, "%d", &val.i)); } @@ -2634,7 +2956,8 @@ declare_proto_rig(get_parm) setting_t parm; value_t val; - if (!strcmp(arg1, "?")) { + if (!strcmp(arg1, "?")) + { char s[SPRINTF_MAX_SIZE]; sprintf_parm(s, rig->state.has_get_parm); fprintf(fout, "%s\n", s); @@ -2643,26 +2966,31 @@ declare_proto_rig(get_parm) parm = rig_parse_parm(arg1); - if (!rig_has_get_parm(rig, parm)) { + if (!rig_has_get_parm(rig, parm)) + { const struct confparams *cfp; cfp = rig_ext_lookup(rig, arg1); - if (!cfp) { + if (!cfp) + { return -RIG_EINVAL; /* no such parameter */ } status = rig_get_ext_parm(rig, cfp->token, &val); - if (status != RIG_OK) { + if (status != RIG_OK) + { return status; } - if (interactive && prompt) { + if (interactive && prompt) + { fprintf(fout, "%s: ", cmd->arg2); } - switch (cfp->type) { + switch (cfp->type) + { case RIG_CONF_BUTTON: /* there's not sense in retrieving value of stateless button */ return -RIG_EINVAL; @@ -2689,17 +3017,22 @@ declare_proto_rig(get_parm) status = rig_get_parm(rig, parm, &val); - if (status != RIG_OK) { + if (status != RIG_OK) + { return status; } - if (interactive && prompt) { + if (interactive && prompt) + { fprintf(fout, "%s: ", cmd->arg2); } - if (RIG_PARM_IS_FLOAT(parm)) { + if (RIG_PARM_IS_FLOAT(parm)) + { fprintf(fout, "%f\n", val.f); - } else { + } + else + { fprintf(fout, "%d\n", val.i); } @@ -2735,11 +3068,13 @@ declare_proto_rig(get_mem) status = rig_get_mem(rig, vfo, &ch); - if (status != RIG_OK) { + if (status != RIG_OK) + { return status; } - if ((interactive && prompt) || (interactive && !prompt && ext_resp)) { + if ((interactive && prompt) || (interactive && !prompt && ext_resp)) + { fprintf(fout, "%s: ", cmd->arg1); } @@ -2754,7 +3089,8 @@ declare_proto_rig(vfo_op) { vfo_op_t op; - if (!strcmp(arg1, "?")) { + if (!strcmp(arg1, "?")) + { char s[SPRINTF_MAX_SIZE]; sprintf_vfop(s, rig->caps->vfo_ops); fprintf(fout, "%s\n", s); @@ -2763,7 +3099,8 @@ declare_proto_rig(vfo_op) op = rig_parse_vfo_op(arg1); - if (RIG_OP_NONE == op) { + if (RIG_OP_NONE == op) + { return -RIG_EINVAL; } @@ -2777,7 +3114,8 @@ declare_proto_rig(scan) scan_t op; int ch; - if (!strcmp(arg1, "?")) { + if (!strcmp(arg1, "?")) + { char s[SPRINTF_MAX_SIZE]; sprintf_scan(s, rig->caps->scan_ops); fprintf(fout, "%s\n", s); @@ -2801,7 +3139,8 @@ declare_proto_rig(set_channel) memset(&chan, 0, sizeof(channel_t)); - if (isdigit((int)arg1[0])) { + if (isdigit((int)arg1[0])) + { chan.vfo = RIG_VFO_MEM; CHKSCN1ARG(sscanf(arg1, "%d", &chan.channel_num)); /* @@ -2809,11 +3148,14 @@ declare_proto_rig(set_channel) */ chan_list = rig_lookup_mem_caps(rig, chan.channel_num); - if (chan_list) { + if (chan_list) + { mem_caps = &chan_list->mem_caps; } - } else { + } + else + { chan.vfo = rig_parse_vfo(arg1); chan.channel_num = 0; @@ -2821,12 +3163,15 @@ declare_proto_rig(set_channel) /* either from mem, or reverse computed from caps */ } - if (!mem_caps) { + if (!mem_caps) + { return -RIG_ECONF; } - if (mem_caps->bank_num) { - if ((interactive && prompt) || (interactive && !prompt && ext_resp)) { + if (mem_caps->bank_num) + { + if ((interactive && prompt) || (interactive && !prompt && ext_resp)) + { fprintf_flush(fout, "Bank Num: "); } @@ -2835,8 +3180,10 @@ declare_proto_rig(set_channel) #if 0 - if (mem_caps->vfo) { - if ((interactive && prompt) || (interactive && !prompt && ext_resp)) { + if (mem_caps->vfo) + { + if ((interactive && prompt) || (interactive && !prompt && ext_resp)) + { fprintf_flush(fout, "vfo (VFOA,MEM,etc...): "); } @@ -2846,24 +3193,30 @@ declare_proto_rig(set_channel) #endif - if (mem_caps->ant) { - if ((interactive && prompt) || (interactive && !prompt && ext_resp)) { + if (mem_caps->ant) + { + if ((interactive && prompt) || (interactive && !prompt && ext_resp)) + { fprintf_flush(fout, "ant: "); } CHKSCN1ARG(scanfc(fin, "%d", &chan.ant)); } - if (mem_caps->freq) { - if ((interactive && prompt) || (interactive && !prompt && ext_resp)) { + if (mem_caps->freq) + { + if ((interactive && prompt) || (interactive && !prompt && ext_resp)) + { fprintf_flush(fout, "Frequency: "); } CHKSCN1ARG(scanfc(fin, "%"SCNfreq, &chan.freq)); } - if (mem_caps->mode) { - if ((interactive && prompt) || (interactive && !prompt && ext_resp)) { + if (mem_caps->mode) + { + if ((interactive && prompt) || (interactive && !prompt && ext_resp)) + { fprintf_flush(fout, "mode (FM,LSB,etc...): "); } @@ -2871,24 +3224,30 @@ declare_proto_rig(set_channel) chan.mode = rig_parse_mode(s); } - if (mem_caps->width) { - if ((interactive && prompt) || (interactive && !prompt && ext_resp)) { + if (mem_caps->width) + { + if ((interactive && prompt) || (interactive && !prompt && ext_resp)) + { fprintf_flush(fout, "width: "); } CHKSCN1ARG(scanfc(fin, "%ld", &chan.width)); } - if (mem_caps->tx_freq) { - if ((interactive && prompt) || (interactive && !prompt && ext_resp)) { + if (mem_caps->tx_freq) + { + if ((interactive && prompt) || (interactive && !prompt && ext_resp)) + { fprintf_flush(fout, "tx freq: "); } CHKSCN1ARG(scanfc(fin, "%"SCNfreq, &chan.tx_freq)); } - if (mem_caps->tx_mode) { - if ((interactive && prompt) || (interactive && !prompt && ext_resp)) { + if (mem_caps->tx_mode) + { + if ((interactive && prompt) || (interactive && !prompt && ext_resp)) + { fprintf_flush(fout, "tx mode (FM,LSB,etc...): "); } @@ -2896,16 +3255,20 @@ declare_proto_rig(set_channel) chan.tx_mode = rig_parse_mode(s); } - if (mem_caps->tx_width) { - if ((interactive && prompt) || (interactive && !prompt && ext_resp)) { + if (mem_caps->tx_width) + { + if ((interactive && prompt) || (interactive && !prompt && ext_resp)) + { fprintf_flush(fout, "tx width: "); } CHKSCN1ARG(scanfc(fin, "%ld", &chan.tx_width)); } - if (mem_caps->split) { - if ((interactive && prompt) || (interactive && !prompt && ext_resp)) { + if (mem_caps->split) + { + if ((interactive && prompt) || (interactive && !prompt && ext_resp)) + { fprintf_flush(fout, "split (0,1): "); } @@ -2913,8 +3276,10 @@ declare_proto_rig(set_channel) chan.split = status; } - if (mem_caps->tx_vfo) { - if ((interactive && prompt) || (interactive && !prompt && ext_resp)) { + if (mem_caps->tx_vfo) + { + if ((interactive && prompt) || (interactive && !prompt && ext_resp)) + { fprintf_flush(fout, "tx vfo (VFOA,MEM,etc...): "); } @@ -2922,8 +3287,10 @@ declare_proto_rig(set_channel) chan.tx_vfo = rig_parse_vfo(s); } - if (mem_caps->rptr_shift) { - if ((interactive && prompt) || (interactive && !prompt && ext_resp)) { + if (mem_caps->rptr_shift) + { + if ((interactive && prompt) || (interactive && !prompt && ext_resp)) + { fprintf_flush(fout, "rptr shift (+-0): "); } @@ -2931,40 +3298,50 @@ declare_proto_rig(set_channel) chan.rptr_shift = rig_parse_rptr_shift(s); } - if (mem_caps->rptr_offs) { - if ((interactive && prompt) || (interactive && !prompt && ext_resp)) { + if (mem_caps->rptr_offs) + { + if ((interactive && prompt) || (interactive && !prompt && ext_resp)) + { fprintf_flush(fout, "rptr offset: "); } CHKSCN1ARG(scanfc(fin, "%ld", &chan.rptr_offs)); } - if (mem_caps->tuning_step) { - if ((interactive && prompt) || (interactive && !prompt && ext_resp)) { + if (mem_caps->tuning_step) + { + if ((interactive && prompt) || (interactive && !prompt && ext_resp)) + { fprintf_flush(fout, "tuning step: "); } CHKSCN1ARG(scanfc(fin, "%ld", &chan.tuning_step)); } - if (mem_caps->rit) { - if ((interactive && prompt) || (interactive && !prompt && ext_resp)) { + if (mem_caps->rit) + { + if ((interactive && prompt) || (interactive && !prompt && ext_resp)) + { fprintf_flush(fout, "rit (Hz,0=off): "); } CHKSCN1ARG(scanfc(fin, "%ld", &chan.rit)); } - if (mem_caps->xit) { - if ((interactive && prompt) || (interactive && !prompt && ext_resp)) { + if (mem_caps->xit) + { + if ((interactive && prompt) || (interactive && !prompt && ext_resp)) + { fprintf_flush(fout, "xit (Hz,0=off): "); } CHKSCN1ARG(scanfc(fin, "%ld", &chan.xit)); } - if (mem_caps->funcs) { - if ((interactive && prompt) || (interactive && !prompt && ext_resp)) { + if (mem_caps->funcs) + { + if ((interactive && prompt) || (interactive && !prompt && ext_resp)) + { fprintf_flush(fout, "funcs: "); } @@ -2974,62 +3351,77 @@ declare_proto_rig(set_channel) #if 0 /* for all levels (except READONLY), ask */ - if (mem_caps->levels) { + if (mem_caps->levels) + { sscanf(arg1, "%d", &chan.levels); } #endif - if (mem_caps->ctcss_tone) { - if ((interactive && prompt) || (interactive && !prompt && ext_resp)) { + if (mem_caps->ctcss_tone) + { + if ((interactive && prompt) || (interactive && !prompt && ext_resp)) + { fprintf_flush(fout, "ctcss tone freq in tenth of Hz (0=off): "); } CHKSCN1ARG(scanfc(fin, "%d", &chan.ctcss_tone)); } - if (mem_caps->ctcss_sql) { - if ((interactive && prompt) || (interactive && !prompt && ext_resp)) { + if (mem_caps->ctcss_sql) + { + if ((interactive && prompt) || (interactive && !prompt && ext_resp)) + { fprintf_flush(fout, "ctcss sql freq in tenth of Hz (0=off): "); } CHKSCN1ARG(scanfc(fin, "%d", &chan.ctcss_sql)); } - if (mem_caps->dcs_code) { - if ((interactive && prompt) || (interactive && !prompt && ext_resp)) { + if (mem_caps->dcs_code) + { + if ((interactive && prompt) || (interactive && !prompt && ext_resp)) + { fprintf_flush(fout, "dcs code: "); } CHKSCN1ARG(scanfc(fin, "%d", &chan.dcs_code)); } - if (mem_caps->dcs_sql) { - if ((interactive && prompt) || (interactive && !prompt && ext_resp)) { + if (mem_caps->dcs_sql) + { + if ((interactive && prompt) || (interactive && !prompt && ext_resp)) + { fprintf_flush(fout, "dcs sql: "); } CHKSCN1ARG(scanfc(fin, "%d", &chan.dcs_sql)); } - if (mem_caps->scan_group) { - if ((interactive && prompt) || (interactive && !prompt && ext_resp)) { + if (mem_caps->scan_group) + { + if ((interactive && prompt) || (interactive && !prompt && ext_resp)) + { fprintf_flush(fout, "scan group: "); } CHKSCN1ARG(scanfc(fin, "%d", &chan.scan_group)); } - if (mem_caps->flags) { - if ((interactive && prompt) || (interactive && !prompt && ext_resp)) { + if (mem_caps->flags) + { + if ((interactive && prompt) || (interactive && !prompt && ext_resp)) + { fprintf_flush(fout, "flags: "); } CHKSCN1ARG(scanfc(fin, "%d", &chan.flags)); } - if (mem_caps->channel_desc) { - if ((interactive && prompt) || (interactive && !prompt && ext_resp)) { + if (mem_caps->channel_desc) + { + if ((interactive && prompt) || (interactive && !prompt && ext_resp)) + { fprintf_flush(fout, "channel desc: "); } @@ -3040,7 +3432,8 @@ declare_proto_rig(set_channel) #if 0 /* TODO: same as levels, allocate/free the array */ - if (mem_caps->ext_levels) { + if (mem_caps->ext_levels) + { sscanf(arg1, "%d", &chan.ext_levels[i].val.i); } @@ -3060,23 +3453,28 @@ declare_proto_rig(get_channel) memset(&chan, 0, sizeof(channel_t)); - if (isdigit((int)arg1[0])) { + if (isdigit((int)arg1[0])) + { chan.vfo = RIG_VFO_MEM; CHKSCN1ARG(sscanf(arg1, "%d", &chan.channel_num)); - } else { + } + else + { chan.vfo = rig_parse_vfo(arg1); chan.channel_num = 0; } status = rig_get_channel(rig, &chan); - if (status != RIG_OK) { + if (status != RIG_OK) + { return status; } status = dump_chan(fout, rig, &chan); - if (chan.ext_levels) { + if (chan.ext_levels) + { free(chan.ext_levels); } @@ -3136,22 +3534,31 @@ declare_proto_rig(set_trn) { int trn; - if (!strcmp(arg1, "?")) { + if (!strcmp(arg1, "?")) + { fprintf(fout, "OFF RIG POLL\n"); return RIG_OK; } - if (!strcmp(arg1, "OFF")) { + if (!strcmp(arg1, "OFF")) + { trn = RIG_TRN_OFF; - } else if (!strcmp(arg1, "RIG") || !strcmp(arg1, "ON")) { + } + else if (!strcmp(arg1, "RIG") || !strcmp(arg1, "ON")) + { trn = RIG_TRN_RIG; - } else if (!strcmp(arg1, "POLL")) { + } + else if (!strcmp(arg1, "POLL")) + { trn = RIG_TRN_POLL; - } else { + } + else + { return -RIG_EINVAL; } - if (trn != RIG_TRN_OFF) { + if (trn != RIG_TRN_OFF) + { rig_set_freq_callback(rig, myfreq_event, NULL); rig_set_mode_callback(rig, mymode_event, NULL); rig_set_vfo_callback(rig, myvfo_event, NULL); @@ -3168,7 +3575,8 @@ declare_proto_rig(get_trn) { int status; int trn; - static const char *trn_txt[] = { + static const char *trn_txt[] = + { "OFF", "RIG", "POLL" @@ -3176,15 +3584,18 @@ declare_proto_rig(get_trn) status = rig_get_trn(rig, &trn); - if (status != RIG_OK) { + if (status != RIG_OK) + { return status; } - if ((interactive && prompt) || (interactive && !prompt && ext_resp)) { + if ((interactive && prompt) || (interactive && !prompt && ext_resp)) + { fprintf(fout, "%s: ", cmd->arg1); } - if (trn >= 0 && trn <= 2) { + if (trn >= 0 && trn <= 2) + { fprintf(fout, "%s%c", trn_txt[trn], resp_sep); } @@ -3199,7 +3610,8 @@ declare_proto_rig(get_info) s = rig_get_info(rig); - if ((interactive && prompt) || (interactive && !prompt && ext_resp)) { + if ((interactive && prompt) || (interactive && !prompt && ext_resp)) + { fprintf(fout, "%s: ", cmd->arg1); } @@ -3271,49 +3683,61 @@ int dump_chan(FILE *fout, RIG *rig, channel_t *chan) fprintf(fout, "Levels:"); - for (idx = 0; idx < RIG_SETTING_MAX; idx++) { + for (idx = 0; idx < RIG_SETTING_MAX; idx++) + { setting_t level = rig_idx2setting(idx); const char *level_s; if (!RIG_LEVEL_SET(level) || (!rig_has_set_level(rig, level) - && !rig_has_get_level(rig, level))) { + && !rig_has_get_level(rig, level))) + { continue; } level_s = rig_strlevel(level); - if (!level_s || level_s[0] == '\0') { + if (!level_s || level_s[0] == '\0') + { continue; /* duh! */ } - if (firstloop) { + if (firstloop) + { firstloop = 0; - } else { + } + else + { fprintf(fout, ",\t"); } - if (RIG_LEVEL_IS_FLOAT(level)) { + if (RIG_LEVEL_IS_FLOAT(level)) + { fprintf(fout, " %s: %g%%", level_s, 100 * chan->levels[idx].f); - } else { + } + else + { fprintf(fout, " %s: %d", level_s, chan->levels[idx].i); } } /* ext_levels */ for (idx = 0; chan->ext_levels - && !RIG_IS_EXT_END(chan->ext_levels[idx]); idx++) { + && !RIG_IS_EXT_END(chan->ext_levels[idx]); idx++) + { const struct confparams *cfp; char lstr[32]; cfp = rig_ext_lookup_tok(rig, chan->ext_levels[idx].token); - if (!cfp) { + if (!cfp) + { return -RIG_EINVAL; } - switch (cfp->type) { + switch (cfp->type) + { case RIG_CONF_STRING: strcpy(lstr, chan->ext_levels[idx].val.s); break; @@ -3369,7 +3793,8 @@ declare_proto_rig(dump_state) fprintf(fout, "%d\n", rig->caps->rig_model); fprintf(fout, "%d\n", rs->itu_region); - for (i = 0; i < FRQRANGESIZ && !RIG_IS_FRNG_END(rs->rx_range_list[i]); i++) { + for (i = 0; i < FRQRANGESIZ && !RIG_IS_FRNG_END(rs->rx_range_list[i]); i++) + { fprintf(fout, "%"FREQFMT" %"FREQFMT" 0x%x %d %d 0x%x 0x%x\n", rs->rx_range_list[i].start, @@ -3383,7 +3808,8 @@ declare_proto_rig(dump_state) fprintf(fout, "0 0 0 0 0 0 0\n"); - for (i = 0; i < FRQRANGESIZ && !RIG_IS_FRNG_END(rs->tx_range_list[i]); i++) { + for (i = 0; i < FRQRANGESIZ && !RIG_IS_FRNG_END(rs->tx_range_list[i]); i++) + { fprintf(fout, "%"FREQFMT" %"FREQFMT" 0x%x %d %d 0x%x 0x%x\n", rs->tx_range_list[i].start, @@ -3397,7 +3823,8 @@ declare_proto_rig(dump_state) fprintf(fout, "0 0 0 0 0 0 0\n"); - for (i = 0; i < TSLSTSIZ && !RIG_IS_TS_END(rs->tuning_steps[i]); i++) { + for (i = 0; i < TSLSTSIZ && !RIG_IS_TS_END(rs->tuning_steps[i]); i++) + { fprintf(fout, "0x%x %ld\n", rs->tuning_steps[i].modes, @@ -3406,7 +3833,8 @@ declare_proto_rig(dump_state) fprintf(fout, "0 0\n"); - for (i = 0; i < FLTLSTSIZ && !RIG_IS_FLT_END(rs->filters[i]); i++) { + for (i = 0; i < FLTLSTSIZ && !RIG_IS_FLT_END(rs->filters[i]); i++) + { fprintf(fout, "0x%x %ld\n", rs->filters[i].modes, @@ -3424,13 +3852,15 @@ declare_proto_rig(dump_state) fprintf(fout, "%ld\n", rs->max_ifshift); fprintf(fout, "%d\n", rs->announces); - for (i = 0; i < MAXDBLSTSIZ && rs->preamp[i]; i++) { + for (i = 0; i < MAXDBLSTSIZ && rs->preamp[i]; i++) + { fprintf(fout, "%d ", rs->preamp[i]); } fprintf(fout, "\n"); - for (i = 0; i < MAXDBLSTSIZ && rs->attenuator[i]; i++) { + for (i = 0; i < MAXDBLSTSIZ && rs->attenuator[i]; i++) + { fprintf(fout, "%d ", rs->attenuator[i]); } @@ -3479,11 +3909,13 @@ declare_proto_rig(get_ant) status = rig_get_ant(rig, vfo, &ant); - if (status != RIG_OK) { + if (status != RIG_OK) + { return status; } - if ((interactive && prompt) || (interactive && !prompt && ext_resp)) { + if ((interactive && prompt) || (interactive && !prompt && ext_resp)) + { fprintf(fout, "%s: ", cmd->arg1); } @@ -3525,11 +3957,13 @@ declare_proto_rig(recv_dtmf) len = MAXARGSZ - 1; status = rig_recv_dtmf(rig, vfo, digits, &len); - if (status != RIG_OK) { + if (status != RIG_OK) + { return status; } - if (interactive && prompt) { + if (interactive && prompt) + { fprintf(fout, "%s: ", cmd->arg1); } @@ -3557,11 +3991,13 @@ declare_proto_rig(get_powerstat) status = rig_get_powerstat(rig, &stat); - if (status != RIG_OK) { + if (status != RIG_OK) + { return status; } - if ((interactive && prompt) || (interactive && !prompt && ext_resp)) { + if ((interactive && prompt) || (interactive && !prompt && ext_resp)) + { fprintf(fout, "%s: ", cmd->arg1); } @@ -3596,12 +4032,14 @@ declare_proto_rig(send_cmd) || backend_num == RIG_YAESU || backend_num == RIG_ICOM || backend_num == RIG_KACHINA - || backend_num == RIG_MICROTUNE) { + || backend_num == RIG_MICROTUNE) + { const char *p = arg1, *pp = NULL; int i; - for (i = 0; i < BUFSZ - 1 && p != pp; i++) { + for (i = 0; i < BUFSZ - 1 && p != pp; i++) + { pp = p + 1; bufcmd[i] = strtol(p + 1, (char **) &p, 0); } @@ -3611,14 +4049,17 @@ declare_proto_rig(send_cmd) /* no End Of Message chars */ eom_buf[0] = '\0'; - } else { + } + else + { /* text protocol */ strncpy(bufcmd, arg1, BUFSZ); bufcmd[BUFSZ - 2] = '\0'; cmd_len = strlen(bufcmd); /* Automatic termination char */ - if (send_cmd_term != 0) { + if (send_cmd_term != 0) + { bufcmd[cmd_len++] = send_cmd_term; } @@ -3631,33 +4072,42 @@ declare_proto_rig(send_cmd) retval = write_block(&rs->rigport, bufcmd, cmd_len); - if (retval != RIG_OK) { + if (retval != RIG_OK) + { return retval; } - if (interactive && prompt) { + if (interactive && prompt) + { fprintf(fout, "%s: ", cmd->arg2); } - do { + do + { /* Assumes CR or LF is end of line char for all ASCII protocols. */ retval = read_string(&rs->rigport, buf, BUFSZ, eom_buf, strlen(eom_buf)); - if (retval < 0) { + if (retval < 0) + { break; } - if (retval < BUFSZ) { + if (retval < BUFSZ) + { buf[retval] = '\0'; - } else { + } + else + { buf[BUFSZ - 1] = '\0'; } fprintf(fout, "%s\n", buf); - } while (retval > 0); + } + while (retval > 0); - if (retval > 0 || retval == -RIG_ETIMEOUT) { + if (retval > 0 || retval == -RIG_ETIMEOUT) + { retval = RIG_OK; } diff --git a/tests/rigctld.c b/tests/rigctld.c index c9db91659..18f22b610 100644 --- a/tests/rigctld.c +++ b/tests/rigctld.c @@ -81,7 +81,8 @@ * 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'}, @@ -104,7 +105,8 @@ static struct option long_options[] = { }; -struct handle_data { +struct handle_data +{ RIG *rig; int sock; struct sockaddr_storage cli_addr; @@ -112,7 +114,7 @@ struct handle_data { }; -void * handle_socket(void *arg); +void *handle_socket(void *arg); void usage(void); @@ -143,11 +145,14 @@ static void handle_error(enum rig_debug_level_e lvl, const char *msg) NULL, e, MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT), // Default language - (LPTSTR)&lpMsgBuf, 0, NULL)) { + (LPTSTR)&lpMsgBuf, 0, NULL)) + { rig_debug(lvl, "%s: Network error %d: %s\n", msg, e, lpMsgBuf); LocalFree(lpMsgBuf); - } else { + } + else + { rig_debug(lvl, "%s: Network error %d\n", msg, e); } @@ -188,7 +193,8 @@ int main(int argc, char *argv[]) #endif struct handle_data *arg; - while (1) { + while (1) + { int c; int option_index = 0; @@ -198,11 +204,13 @@ int main(int argc, char *argv[]) long_options, &option_index); - if (c == -1) { + if (c == -1) + { break; } - switch (c) { + switch (c) + { case 'h': usage(); exit(0); @@ -212,7 +220,8 @@ int main(int argc, char *argv[]) exit(0); case 'm': - if (!optarg) { + if (!optarg) + { usage(); /* wrong arg count */ exit(1); } @@ -221,7 +230,8 @@ int main(int argc, char *argv[]) break; case 'r': - if (!optarg) { + if (!optarg) + { usage(); /* wrong arg count */ exit(1); } @@ -230,7 +240,8 @@ int main(int argc, char *argv[]) break; case 'p': - if (!optarg) { + if (!optarg) + { usage(); /* wrong arg count */ exit(1); } @@ -239,7 +250,8 @@ int main(int argc, char *argv[]) break; case 'd': - if (!optarg) { + if (!optarg) + { usage(); /* wrong arg count */ exit(1); } @@ -248,55 +260,84 @@ int main(int argc, char *argv[]) break; case 'P': - if (!optarg) { + if (!optarg) + { usage(); /* wrong arg count */ exit(1); } - if (!strcmp(optarg, "RIG")) { + if (!strcmp(optarg, "RIG")) + { ptt_type = RIG_PTT_RIG; - } else if (!strcmp(optarg, "DTR")) { + } + else if (!strcmp(optarg, "DTR")) + { ptt_type = RIG_PTT_SERIAL_DTR; - } else if (!strcmp(optarg, "RTS")) { + } + else if (!strcmp(optarg, "RTS")) + { ptt_type = RIG_PTT_SERIAL_RTS; - } else if (!strcmp(optarg, "PARALLEL")) { + } + else if (!strcmp(optarg, "PARALLEL")) + { ptt_type = RIG_PTT_PARALLEL; - } else if (!strcmp(optarg, "CM108")) { + } + else if (!strcmp(optarg, "CM108")) + { ptt_type = RIG_PTT_CM108; - } else if (!strcmp(optarg, "NONE")) { + } + else if (!strcmp(optarg, "NONE")) + { ptt_type = RIG_PTT_NONE; - } else { + } + else + { ptt_type = atoi(optarg); } break; case 'D': - if (!optarg) { + if (!optarg) + { usage(); /* wrong arg count */ exit(1); } - if (!strcmp(optarg, "RIG")) { + if (!strcmp(optarg, "RIG")) + { dcd_type = RIG_DCD_RIG; - } else if (!strcmp(optarg, "DSR")) { + } + else if (!strcmp(optarg, "DSR")) + { dcd_type = RIG_DCD_SERIAL_DSR; - } else if (!strcmp(optarg, "CTS")) { + } + else if (!strcmp(optarg, "CTS")) + { dcd_type = RIG_DCD_SERIAL_CTS; - } else if (!strcmp(optarg, "CD")) { + } + else if (!strcmp(optarg, "CD")) + { dcd_type = RIG_DCD_SERIAL_CAR; - } else if (!strcmp(optarg, "PARALLEL")) { + } + else if (!strcmp(optarg, "PARALLEL")) + { dcd_type = RIG_DCD_PARALLEL; - } else if (!strcmp(optarg, "NONE")) { + } + else if (!strcmp(optarg, "NONE")) + { dcd_type = RIG_DCD_NONE; - } else { + } + else + { dcd_type = atoi(optarg); } break; case 'c': - if (!optarg) { + if (!optarg) + { usage(); /* wrong arg count */ exit(1); } @@ -305,7 +346,8 @@ int main(int argc, char *argv[]) break; case 's': - if (!optarg) { + if (!optarg) + { usage(); /* wrong arg count */ exit(1); } @@ -314,12 +356,14 @@ int main(int argc, char *argv[]) break; case 'C': - if (!optarg) { + if (!optarg) + { usage(); /* wrong arg count */ exit(1); } - if (*conf_parms != '\0') { + if (*conf_parms != '\0') + { strcat(conf_parms, ","); } @@ -327,7 +371,8 @@ int main(int argc, char *argv[]) break; case 't': - if (!optarg) { + if (!optarg) + { usage(); /* wrong arg count */ exit(1); } @@ -336,7 +381,8 @@ int main(int argc, char *argv[]) break; case 'T': - if (!optarg) { + if (!optarg) + { usage(); /* wrong arg count */ exit(1); } @@ -378,7 +424,8 @@ int main(int argc, char *argv[]) my_rig = rig_init(my_model); - if (!my_rig) { + if (!my_rig) + { fprintf(stderr, "Unknown rig num %d, or initialization error.\n", my_model); @@ -389,47 +436,56 @@ int main(int argc, char *argv[]) retcode = set_conf(my_rig, conf_parms); - if (retcode != RIG_OK) { + if (retcode != RIG_OK) + { fprintf(stderr, "Config parameter error: %s\n", rigerror(retcode)); exit(2); } - if (rig_file) { + if (rig_file) + { strncpy(my_rig->state.rigport.pathname, rig_file, FILPATHLEN - 1); } /* * ex: RIG_PTT_PARALLEL and /dev/parport0 */ - if (ptt_type != RIG_PTT_NONE) { + if (ptt_type != RIG_PTT_NONE) + { 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; } - if (ptt_file) { + if (ptt_file) + { 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); } /* FIXME: bound checking and port type == serial */ - if (serial_rate != 0) { + if (serial_rate != 0) + { 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); } /* * print out conf parameters */ - if (show_conf) { + if (show_conf) + { rig_token_foreach(my_rig, print_conf_list, (rig_ptr_t)my_rig); } @@ -437,7 +493,8 @@ int main(int argc, char *argv[]) * print out conf parameters, and exits immediately * We may be interested only in only caps, and rig_open may fail. */ - if (dump_caps_opt) { + if (dump_caps_opt) + { dumpcaps(my_rig, stdout); rig_cleanup(my_rig); /* if you care about memory */ exit(0); @@ -445,12 +502,14 @@ int main(int argc, char *argv[]) retcode = rig_open(my_rig); - if (retcode != RIG_OK) { + if (retcode != RIG_OK) + { fprintf(stderr, "rig_open: error = %s \n", rigerror(retcode)); exit(2); } - if (verbose > 0) { + if (verbose > 0) + { printf("Opened rig model %d, '%s'\n", my_rig->caps->rig_model, my_rig->caps->model_name); @@ -472,7 +531,8 @@ int main(int argc, char *argv[]) WSADATA wsadata; - if (WSAStartup(MAKEWORD(1, 1), &wsadata) == SOCKET_ERROR) { + if (WSAStartup(MAKEWORD(1, 1), &wsadata) == SOCKET_ERROR) + { fprintf(stderr, "WSAStartup socket error\n"); exit(1); } @@ -493,19 +553,22 @@ int main(int argc, char *argv[]) retcode = getaddrinfo(src_addr, portno, &hints, &result); - if (retcode != 0) { + if (retcode != 0) + { fprintf(stderr, "getaddrinfo: %s\n", gai_strerror(retcode)); exit(2); } saved_result = result; - do { + do + { sock_listen = socket(result->ai_family, result->ai_socktype, result->ai_protocol); - if (sock_listen < 0) { + if (sock_listen < 0) + { handle_error(RIG_DEBUG_ERR, "socket"); freeaddrinfo(saved_result); /* No longer needed */ exit(2); @@ -516,7 +579,8 @@ int main(int argc, char *argv[]) SO_REUSEADDR, (char *)&reuseaddr, sizeof(reuseaddr)) - < 0) { + < 0) + { handle_error(RIG_DEBUG_ERR, "setsockopt"); freeaddrinfo(saved_result); /* No longer needed */ @@ -525,7 +589,8 @@ int main(int argc, char *argv[]) #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 this to 1 (i.e. disallowed) and we prefer it off */ sockopt = 0; @@ -535,7 +600,8 @@ int main(int argc, char *argv[]) IPV6_V6ONLY, (char *)&sockopt, sizeof(sockopt)) - < 0) { + < 0) + { handle_error(RIG_DEBUG_ERR, "setsockopt"); freeaddrinfo(saved_result); /* No longer needed */ @@ -545,7 +611,8 @@ int main(int argc, char *argv[]) #endif - if (0 == bind(sock_listen, result->ai_addr, result->ai_addrlen)) { + if (0 == bind(sock_listen, result->ai_addr, result->ai_addrlen)) + { break; } @@ -555,16 +622,19 @@ int main(int argc, char *argv[]) #else close(sock_listen); #endif - } while ((result = result->ai_next) != NULL); + } + while ((result = result->ai_next) != NULL); freeaddrinfo(saved_result); /* No longer needed */ - if (NULL == result) { + if (NULL == result) + { rig_debug(RIG_DEBUG_ERR, "bind error - no available interface\n"); exit(1); } - if (listen(sock_listen, 4) < 0) { + if (listen(sock_listen, 4) < 0) + { handle_error(RIG_DEBUG_ERR, "listening"); exit(1); } @@ -579,25 +649,30 @@ int main(int argc, char *argv[]) act.sa_handler = SIG_IGN; act.sa_flags = SA_RESTART; - if (sigaction(SIGPIPE, &act, NULL)) { + if (sigaction(SIGPIPE, &act, NULL)) + { handle_error(RIG_DEBUG_ERR, "sigaction"); } #elif HAVE_SIGNAL - if (SIG_ERR == signal(SIGPIPE, SIG_IGN)) { + if (SIG_ERR == signal(SIGPIPE, SIG_IGN)) + { handle_error(RIG_DEBUG_ERR, "signal"); } + #endif #endif /* * main loop accepting connections */ - do { + do + { arg = malloc(sizeof(struct handle_data)); - if (!arg) { + if (!arg) + { rig_debug(RIG_DEBUG_ERR, "malloc: %s\n", strerror(errno)); exit(1); } @@ -608,7 +683,8 @@ int main(int argc, char *argv[]) (struct sockaddr *)&arg->cli_addr, &arg->clilen); - if (arg->sock < 0) { + if (arg->sock < 0) + { handle_error(RIG_DEBUG_ERR, "accept"); break; } @@ -620,12 +696,18 @@ int main(int argc, char *argv[]) serv, sizeof(serv), NI_NOFQDN)) - < 0) { + < 0) + { - rig_debug(RIG_DEBUG_WARN, "Peer lookup error: %s", gai_strerror(retcode)); + rig_debug(RIG_DEBUG_WARN, + "Peer lookup error: %s", + gai_strerror(retcode)); } - rig_debug(RIG_DEBUG_VERBOSE, "Connection opened from %s:%s\n", host, serv); + rig_debug(RIG_DEBUG_VERBOSE, + "Connection opened from %s:%s\n", + host, + serv); #ifdef HAVE_PTHREAD pthread_attr_init(&attr); @@ -633,7 +715,8 @@ int main(int argc, char *argv[]) retcode = pthread_create(&thread, &attr, handle_socket, arg); - if (retcode != 0) { + if (retcode != 0) + { rig_debug(RIG_DEBUG_ERR, "pthread_create: %s\n", strerror(retcode)); break; } @@ -641,7 +724,8 @@ int main(int argc, char *argv[]) #else handle_socket(arg); #endif - } while (retcode == 0); + } + while (retcode == 0); rig_close(my_rig); /* close port */ rig_cleanup(my_rig); /* if you care about memory */ @@ -669,7 +753,8 @@ void * handle_socket(void *arg) #ifdef __MINGW32__ int sock_osfhandle = _open_osfhandle(handle_data_arg->sock, _O_RDONLY); - if (sock_osfhandle == -1) { + if (sock_osfhandle == -1) + { rig_debug(RIG_DEBUG_ERR, "_open_osfhandle error: %s\n", strerror(errno)); goto handle_exit; } @@ -679,7 +764,8 @@ void * handle_socket(void *arg) fsockin = fdopen(handle_data_arg->sock, "rb"); #endif - if (!fsockin) { + if (!fsockin) + { rig_debug(RIG_DEBUG_ERR, "fdopen in: %s\n", strerror(errno)); goto handle_exit; } @@ -690,20 +776,24 @@ void * handle_socket(void *arg) fsockout = fdopen(handle_data_arg->sock, "wb"); #endif - if (!fsockout) { + if (!fsockout) + { rig_debug(RIG_DEBUG_ERR, "fdopen out: %s\n", strerror(errno)); fclose(fsockin); goto handle_exit; } - do { + do + { retcode = rigctl_parse(handle_data_arg->rig, fsockin, fsockout, NULL, 0); - if (ferror(fsockin) || ferror(fsockout)) { + if (ferror(fsockin) || ferror(fsockout)) + { retcode = 1; } - } while (retcode == 0 || retcode == 2 || retcode == -RIG_ENAVAIL); + } + while (retcode == 0 || retcode == 2 || retcode == -RIG_ENAVAIL); if ((retcode = getnameinfo((struct sockaddr const *)&handle_data_arg->cli_addr, handle_data_arg->clilen, @@ -712,13 +802,16 @@ void * handle_socket(void *arg) serv, sizeof(serv), NI_NOFQDN)) - < 0) { + < 0) + { rig_debug(RIG_DEBUG_WARN, "Peer lookup error: %s", gai_strerror(retcode)); } - rig_debug(RIG_DEBUG_VERBOSE, "Connection closed from %s:%s\n", - host, serv); + rig_debug(RIG_DEBUG_VERBOSE, + "Connection closed from %s:%s\n", + host, + serv); fclose(fsockin); #ifndef __MINGW32__ @@ -747,24 +840,24 @@ void usage(void) printf( - " -m, --model=ID select radio model number. See model list\n" - " -r, --rig-file=DEVICE set device of the radio to operate on\n" - " -p, --ptt-file=DEVICE set device of the PTT device to operate on\n" - " -d, --dcd-file=DEVICE set device of the DCD device to operate on\n" - " -P, --ptt-type=TYPE set type of the PTT device to operate on\n" - " -D, --dcd-type=TYPE set type of the DCD device to operate on\n" - " -s, --serial-speed=BAUD set serial speed of the serial port\n" - " -c, --civaddr=ID set CI-V address, decimal (for Icom rigs only)\n" - " -t, --port=NUM set TCP listening port, default %s\n" - " -T, --listen-addr=IPADDR set listening IP address, default ANY\n" - " -C, --set-conf=PARM=VAL set config parameters\n" - " -L, --show-conf list all config parameters\n" - " -l, --list list all model numbers and exit\n" - " -u, --dump-caps dump capabilities and exit\n" - " -o, --vfo do not default to VFO_CURR, require extra vfo arg\n" - " -v, --verbose set verbose mode, cumulative (-v to -vvvvv)\n" - " -h, --help display this help and exit\n" - " -V, --version output version information and exit\n\n", + " -m, --model=ID select radio model number. See model list\n" + " -r, --rig-file=DEVICE set device of the radio to operate on\n" + " -p, --ptt-file=DEVICE set device of the PTT device to operate on\n" + " -d, --dcd-file=DEVICE set device of the DCD device to operate on\n" + " -P, --ptt-type=TYPE set type of the PTT device to operate on\n" + " -D, --dcd-type=TYPE set type of the DCD device to operate on\n" + " -s, --serial-speed=BAUD set serial speed of the serial port\n" + " -c, --civaddr=ID set CI-V address, decimal (for Icom rigs only)\n" + " -t, --port=NUM set TCP listening port, default %s\n" + " -T, --listen-addr=IPADDR set listening IP address, default ANY\n" + " -C, --set-conf=PARM=VAL set config parameters\n" + " -L, --show-conf list all config parameters\n" + " -l, --list list all model numbers and exit\n" + " -u, --dump-caps dump capabilities and exit\n" + " -o, --vfo do not default to VFO_CURR, require extra vfo arg\n" + " -v, --verbose set verbose mode, cumulative (-v to -vvvvv)\n" + " -h, --help display this help and exit\n" + " -V, --version output version information and exit\n\n", portno); usage_rig(stdout); diff --git a/tests/rigmatrix.c b/tests/rigmatrix.c index bbc11192c..6afb2afb4 100644 --- a/tests/rigmatrix.c +++ b/tests/rigmatrix.c @@ -48,7 +48,8 @@ int print_caps_sum(const struct rig_caps *caps, void *data) caps->version, rig_strstatus(caps->status)); - switch (caps->rig_type & RIG_TYPE_MASK) { + switch (caps->rig_type & RIG_TYPE_MASK) + { case RIG_TYPE_TRANSCEIVER: printf("Transceiver"); break; @@ -116,7 +117,8 @@ int print_caps_parameters(const struct rig_caps *caps, void *data) caps->rig_model, caps->model_name); - switch (caps->ptt_type) { + switch (caps->ptt_type) + { case RIG_PTT_RIG: printf("rig"); break; @@ -140,7 +142,8 @@ int print_caps_parameters(const struct rig_caps *caps, void *data) printf(""); - switch (caps->dcd_type) { + switch (caps->dcd_type) + { case RIG_DCD_RIG: printf("rig"); break; @@ -164,7 +167,8 @@ int print_caps_parameters(const struct rig_caps *caps, void *data) printf(""); - switch (caps->port_type) { + switch (caps->port_type) + { case RIG_PORT_SERIAL: printf("serial"); break; @@ -194,9 +198,9 @@ int print_caps_parameters(const struct rig_caps *caps, void *data) caps->serial_rate_max, caps->serial_data_bits, caps->serial_parity == RIG_PARITY_NONE ? 'N' : - caps->serial_parity == RIG_PARITY_ODD ? 'O' : - caps->serial_parity == RIG_PARITY_EVEN ? 'E' : - caps->serial_parity == RIG_PARITY_MARK ? 'M' : 'S', + caps->serial_parity == RIG_PARITY_ODD ? 'O' : + caps->serial_parity == RIG_PARITY_EVEN ? 'E' : + caps->serial_parity == RIG_PARITY_MARK ? 'M' : 'S', caps->serial_stop_bits, caps->serial_handshake == RIG_HANDSHAKE_NONE ? "none" : (caps->serial_handshake == RIG_HANDSHAKE_XONXOFF ? "XONXOFF" : "CTS/RTS")); @@ -271,7 +275,8 @@ int print_caps_parm(const struct rig_caps *caps, void *data) setting_t parm; int i; - if (!data) { + if (!data) + { return 0; } @@ -285,8 +290,10 @@ int print_caps_parm(const struct rig_caps *caps, void *data) /* * bitmap_parm: only those who have a label */ - for (i = 0; i < RIG_SETTING_MAX; i++) { - if (rig_idx2setting(i) & bitmap_parm) { + for (i = 0; i < RIG_SETTING_MAX; i++) + { + if (rig_idx2setting(i) & bitmap_parm) + { print_yn(parm & rig_idx2setting(i)); } } @@ -305,7 +312,8 @@ int print_caps_level(const struct rig_caps *caps, void *data) setting_t level; int i; - if (!data) { + if (!data) + { return 0; } @@ -319,8 +327,10 @@ int print_caps_level(const struct rig_caps *caps, void *data) /* * bitmap_level: only those who have a label */ - for (i = 0; i < 32; i++) { - if (rig_idx2setting(i) & bitmap_level) { + for (i = 0; i < 32; i++) + { + if (rig_idx2setting(i) & bitmap_level) + { print_yn(level & rig_idx2setting(i)); } } @@ -339,7 +349,8 @@ int print_caps_func(const struct rig_caps *caps, void *data) setting_t func; int i; - if (!data) { + if (!data) + { return 0; } @@ -353,8 +364,10 @@ int print_caps_func(const struct rig_caps *caps, void *data) /* * bitmap_func: only those who have a label */ - for (i = 0; i < RIG_SETTING_MAX; i++) { - if (rig_idx2setting(i) & bitmap_func) { + for (i = 0; i < RIG_SETTING_MAX; i++) + { + if (rig_idx2setting(i) & bitmap_func) + { print_yn(func & rig_idx2setting(i)); } } @@ -409,10 +422,12 @@ static void draw_range(const freq_range_t range_list[], { int i; - for (i = 0; i < FRQRANGESIZ; i++) { + for (i = 0; i < FRQRANGESIZ; i++) + { float start_pix, end_pix; - if (range_list[i].start == 0 && range_list[i].end == 0) { + if (range_list[i].start == 0 && range_list[i].end == 0) + { break; } @@ -422,11 +437,13 @@ static void draw_range(const freq_range_t range_list[], /* * HF */ - if (range_list[i].start < MHz(30)) { + if (range_list[i].start < MHz(30)) + { start_pix = start_pix / MHz(30) * RANGE_WIDTH; end_pix = end_pix / MHz(30) * RANGE_WIDTH; - if (end_pix >= RANGE_WIDTH) { + if (end_pix >= RANGE_WIDTH) + { end_pix = RANGE_WIDTH - 1; } @@ -447,17 +464,20 @@ static void draw_range(const freq_range_t range_list[], end_pix = range_list[i].end; if ((range_list[i].start > MHz(30) && range_list[i].start < MHz(300)) - || (range_list[i].start < MHz(30) - && range_list[i].end > MHz(30))) { + || (range_list[i].start < MHz(30) + && range_list[i].end > MHz(30))) + { start_pix = (start_pix - MHz(30)) / MHz(300) * RANGE_WIDTH; end_pix = (end_pix - MHz(30)) / MHz(300) * RANGE_WIDTH; - if (start_pix < 0) { + if (start_pix < 0) + { start_pix = 0; } - if (end_pix >= RANGE_WIDTH) { + if (end_pix >= RANGE_WIDTH) + { end_pix = RANGE_WIDTH - 1; } @@ -478,17 +498,20 @@ static void draw_range(const freq_range_t range_list[], end_pix = range_list[i].end; if ((range_list[i].start > MHz(300) && range_list[i].start < GHz(3)) - || (range_list[i].start < MHz(300) - && range_list[i].end > MHz(300))) { + || (range_list[i].start < MHz(300) + && range_list[i].end > MHz(300))) + { start_pix = (start_pix - MHz(300)) / GHz(3) * RANGE_WIDTH; end_pix = (end_pix - MHz(300)) / GHz(3) * RANGE_WIDTH; - if (start_pix < 0) { + if (start_pix < 0) + { start_pix = 0; } - if (end_pix >= RANGE_WIDTH) { + if (end_pix >= RANGE_WIDTH) + { end_pix = RANGE_WIDTH - 1; } @@ -673,11 +696,13 @@ int main(int argc, char *argv[]) prntbuf[0] = '\0'; pbuf = prntbuf; - for (i = 0; i < RIG_SETTING_MAX; i++) { + for (i = 0; i < RIG_SETTING_MAX; i++) + { setting_t func = rig_idx2setting(i); const char *s = rig_strfunc(func); - if (!s) { + if (!s) + { continue; } @@ -707,11 +732,13 @@ int main(int argc, char *argv[]) prntbuf[0] = '\0'; pbuf = prntbuf; - for (i = 0; i < RIG_SETTING_MAX; i++) { + for (i = 0; i < RIG_SETTING_MAX; i++) + { setting_t level = rig_idx2setting(i); const char *s = rig_strlevel(level); - if (!s) { + if (!s) + { continue; } @@ -741,11 +768,13 @@ int main(int argc, char *argv[]) prntbuf[0] = '\0'; pbuf = prntbuf; - for (i = 0; i < RIG_SETTING_MAX; i++) { + for (i = 0; i < RIG_SETTING_MAX; i++) + { setting_t parm = rig_idx2setting(i); const char *s = rig_strparm(parm); - if (!s) { + if (!s) + { continue; } diff --git a/tests/rigmem.c b/tests/rigmem.c index 5d00b2ca5..e047331c6 100644 --- a/tests/rigmem.c +++ b/tests/rigmem.c @@ -72,20 +72,21 @@ int clear_chans(RIG *rig, const char *infilename); * NB: do NOT use -W since it's reserved by POSIX. */ #define SHORT_OPTIONS "m:r:s:c:C:p:axvhV" -static struct option long_options[] = { - {"model", 1, 0, 'm'}, - {"rig-file", 1, 0, 'r'}, - {"serial-speed", 1, 0, 's'}, - {"civaddr", 1, 0, 'c'}, - {"set-conf", 1, 0, 'C'}, - {"set-separator", 1, 0, 'p'}, - {"all", 0, 0, 'a'}, +static struct option long_options[] = +{ + {"model", 1, 0, 'm'}, + {"rig-file", 1, 0, 'r'}, + {"serial-speed", 1, 0, 's'}, + {"civaddr", 1, 0, 'c'}, + {"set-conf", 1, 0, 'C'}, + {"set-separator", 1, 0, 'p'}, + {"all", 0, 0, 'a'}, #ifdef HAVE_XML2 - {"xml", 0, 0, 'x'}, + {"xml", 0, 0, 'x'}, #endif - {"verbose", 0, 0, 'v'}, - {"help", 0, 0, 'h'}, - {"version", 0, 0, 'V'}, + {"verbose", 0, 0, 'v'}, + {"help", 0, 0, 'h'}, + {"version", 0, 0, 'V'}, {0, 0, 0, 0} }; @@ -107,17 +108,20 @@ int main(int argc, char *argv[]) char conf_parms[MAXCONFLEN] = ""; extern char csv_sep; - while (1) { + while (1) + { int c; int option_index = 0; c = getopt_long(argc, argv, SHORT_OPTIONS, long_options, &option_index); - if (c == -1) { + if (c == -1) + { break; } - switch (c) { + switch (c) + { case 'h': usage(); exit(0); @@ -127,7 +131,8 @@ int main(int argc, char *argv[]) exit(0); case 'm': - if (!optarg) { + if (!optarg) + { usage(); /* wrong arg count */ exit(1); } @@ -136,7 +141,8 @@ int main(int argc, char *argv[]) break; case 'r': - if (!optarg) { + if (!optarg) + { usage(); /* wrong arg count */ exit(1); } @@ -145,7 +151,8 @@ int main(int argc, char *argv[]) break; case 'c': - if (!optarg) { + if (!optarg) + { usage(); /* wrong arg count */ exit(1); } @@ -154,7 +161,8 @@ int main(int argc, char *argv[]) break; case 's': - if (!optarg) { + if (!optarg) + { usage(); /* wrong arg count */ exit(1); } @@ -163,12 +171,14 @@ int main(int argc, char *argv[]) break; case 'C': - if (!optarg) { + if (!optarg) + { usage(); /* wrong arg count */ exit(1); } - if (*conf_parms != '\0') { + if (*conf_parms != '\0') + { strcat(conf_parms, ","); } @@ -176,7 +186,8 @@ int main(int argc, char *argv[]) break; case 'p': - if (!optarg) { + if (!optarg) + { usage(); /* wrong arg count */ exit(1); } @@ -211,14 +222,16 @@ int main(int argc, char *argv[]) "Report bugs to " "\n\n"); - if (optind + 1 >= argc) { + if (optind + 1 >= argc) + { usage(); exit(1); } rig = rig_init(my_model); - if (!rig) { + if (!rig) + { fprintf(stderr, "Unknown rig num %d, or initialization error.\n", my_model); @@ -229,7 +242,8 @@ int main(int argc, char *argv[]) retcode = set_conf(rig, conf_parms); - if (retcode != RIG_OK) { + if (retcode != RIG_OK) + { fprintf(stderr, "Config parameter error: %s\n", rigerror(retcode)); exit(2); } @@ -239,7 +253,8 @@ int main(int argc, char *argv[]) && rig->caps->get_channel == NULL && rig->caps->set_chan_all_cb == NULL && rig->caps->get_chan_all_cb == NULL - && (rig->caps->set_mem == NULL || rig->caps->set_vfo == NULL)) { + && (rig->caps->set_mem == NULL || rig->caps->set_vfo == NULL)) + { fprintf(stderr, "Error: rig num %d has no memory support implemented/available.\n", @@ -248,33 +263,39 @@ int main(int argc, char *argv[]) } /* check channel description */ - if (rig->caps->chan_list[0].type == 0) { + if (rig->caps->chan_list[0].type == 0) + { fprintf(stderr, "Error: rig num %d has no channel list.\n", my_model); exit(3); } - if (rig_file) { + if (rig_file) + { strncpy(rig->state.rigport.pathname, rig_file, FILPATHLEN - 1); } /* FIXME: bound checking and port type == serial */ - if (serial_rate != 0) { + if (serial_rate != 0) + { rig->state.rigport.parm.serial.rate = serial_rate; } - if (civaddr) { + if (civaddr) + { rig_set_conf(rig, rig_token_lookup(rig, "civaddr"), civaddr); } retcode = rig_open(rig); - if (retcode != RIG_OK) { + if (retcode != RIG_OK) + { fprintf(stderr, "rig_open: error = %s \n", rigerror(retcode)); exit(2); } - if (verbose > 0) { + if (verbose > 0) + { printf("Opened rig model %d, '%s'\n", rig->caps->rig_model, rig->caps->model_name); @@ -288,33 +309,56 @@ int main(int argc, char *argv[]) /* on some rigs, this accelerates the backup/restore */ rig_set_vfo(rig, RIG_VFO_MEM); - if (!strcmp(argv[optind], "save")) { - if (xml) { + if (!strcmp(argv[optind], "save")) + { + if (xml) + { retcode = xml_save(rig, argv[optind + 1]); - } else { + } + else + { retcode = csv_save(rig, argv[optind + 1]); } - } else if (!strcmp(argv[optind], "load")) { - if (xml) { + } + else if (!strcmp(argv[optind], "load")) + { + if (xml) + { retcode = xml_load(rig, argv[optind + 1]); - } else { + } + else + { retcode = csv_load(rig, argv[optind + 1]); } - } else if (!strcmp(argv[optind], "save_parm")) { - if (xml) { + } + else if (!strcmp(argv[optind], "save_parm")) + { + if (xml) + { retcode = xml_parm_save(rig, argv[optind + 1]); - } else { + } + else + { retcode = csv_parm_save(rig, argv[optind + 1]); } - } else if (!strcmp(argv[optind], "load_parm")) { - if (xml) { + } + else if (!strcmp(argv[optind], "load_parm")) + { + if (xml) + { retcode = xml_parm_load(rig, argv[optind + 1]); - } else { + } + else + { retcode = csv_parm_load(rig, argv[optind + 1]); } - } else if (!strcmp(argv[optind], "clear")) { + } + else if (!strcmp(argv[optind], "clear")) + { retcode = clear_chans(rig, argv[optind + 1]); - } else { + } + else + { usage(); exit(1); } @@ -322,7 +366,8 @@ int main(int argc, char *argv[]) rig_close(rig); /* close port */ rig_cleanup(rig); /* if you care about memory */ - if (retcode != 0) { + if (retcode != 0) + { fprintf(stderr, "Hamlib error: %s\n", rigerror(retcode)); exit(2); } @@ -345,19 +390,19 @@ void usage() printf( - " -m, --model=ID select radio model number. See model list\n" - " -r, --rig-file=DEVICE set device of the radio to operate on\n" - " -s, --serial-speed=BAUD set serial speed of the serial port\n" - " -c, --civaddr=ID set CI-V address, decimal (for Icom rigs only)\n" - " -C, --set-conf=PARM=VAL set config parameters\n" - " -p, --set-separator=SEP set character separator instead of the CSV comma\n" - " -a, --all bypass mem_caps, apply to all fields of channel_t\n" + " -m, --model=ID select radio model number. See model list\n" + " -r, --rig-file=DEVICE set device of the radio to operate on\n" + " -s, --serial-speed=BAUD set serial speed of the serial port\n" + " -c, --civaddr=ID set CI-V address, decimal (for Icom rigs only)\n" + " -C, --set-conf=PARM=VAL set config parameters\n" + " -p, --set-separator=SEP set character separator instead of the CSV comma\n" + " -a, --all bypass mem_caps, apply to all fields of channel_t\n" #ifdef HAVE_XML2 - " -x, --xml use XML format instead of CSV\n" + " -x, --xml use XML format instead of CSV\n" #endif - " -v, --verbose set verbose mode, cumulative\n" - " -h, --help display this help and exit\n" - " -V, --version output version information and exit\n\n" + " -v, --verbose set verbose mode, cumulative\n" + " -h, --help display this help and exit\n" + " -V, --version output version information and exit\n\n" ); printf( @@ -381,24 +426,28 @@ int set_conf(RIG *rig, char *conf_parms) p = conf_parms; - while (p && *p != '\0') { + while (p && *p != '\0') + { /* FIXME: left hand value of = cannot be null */ q = strchr(p, '='); - if (!q) { + if (!q) + { return RIG_EINVAL; } *q++ = '\0'; n = strchr(q, ','); - if (n) { + if (n) + { *n++ = '\0'; } ret = rig_set_conf(rig, rig_token_lookup(rig, p), q); - if (ret != RIG_OK) { + if (ret != RIG_OK) + { return ret; } @@ -424,14 +473,17 @@ int clear_chans(RIG *rig, const char *infilename) chan.tx_mode = RIG_MODE_NONE; chan.vfo = RIG_VFO_MEM; - for (i = 0; rig->state.chan_list[i].type && i < CHANLSTSIZ; i++) { + for (i = 0; rig->state.chan_list[i].type && i < CHANLSTSIZ; i++) + { for (j = rig->state.chan_list[i].start; - j <= rig->state.chan_list[i].end; j++) { + j <= rig->state.chan_list[i].end; j++) + { chan.channel_num = j; ret = rig_set_channel(rig, &chan); - if (ret != RIG_OK) { + if (ret != RIG_OK) + { return ret; } } diff --git a/tests/rigsmtr.c b/tests/rigsmtr.c index 2d17db588..9c89df20a 100644 --- a/tests/rigsmtr.c +++ b/tests/rigsmtr.c @@ -53,7 +53,8 @@ static int set_conf_rot(ROT *rot, char *conf_parms); * NB: do NOT use -W since it's reserved by POSIX. */ #define SHORT_OPTIONS "m:r:s:c:C:M:R:S:N:vhV" -static struct option long_options[] = { +static struct option long_options[] = +{ {"model", 1, 0, 'm'}, {"rig-file", 1, 0, 'r'}, {"serial-speed", 1, 0, 's'}, @@ -94,17 +95,20 @@ int main(int argc, char *argv[]) elevation_t elevation; unsigned step = 1000000; /* 1e6 us */ - while (1) { + while (1) + { int c; int option_index = 0; c = getopt_long(argc, argv, SHORT_OPTIONS, long_options, &option_index); - if (c == -1) { + if (c == -1) + { break; } - switch (c) { + switch (c) + { case 'h': usage(); exit(0); @@ -114,7 +118,8 @@ int main(int argc, char *argv[]) exit(0); case 'm': - if (!optarg) { + if (!optarg) + { usage(); /* wrong arg count */ exit(1); } @@ -123,7 +128,8 @@ int main(int argc, char *argv[]) break; case 'r': - if (!optarg) { + if (!optarg) + { usage(); /* wrong arg count */ exit(1); } @@ -132,7 +138,8 @@ int main(int argc, char *argv[]) break; case 'c': - if (!optarg) { + if (!optarg) + { usage(); /* wrong arg count */ exit(1); } @@ -141,7 +148,8 @@ int main(int argc, char *argv[]) break; case 's': - if (!optarg) { + if (!optarg) + { usage(); /* wrong arg count */ exit(1); } @@ -150,12 +158,14 @@ int main(int argc, char *argv[]) break; case 'C': - if (!optarg) { + if (!optarg) + { usage(); /* wrong arg count */ exit(1); } - if (*rig_conf_parms != '\0') { + if (*rig_conf_parms != '\0') + { strcat(rig_conf_parms, ","); } @@ -163,7 +173,8 @@ int main(int argc, char *argv[]) break; case 'M': - if (!optarg) { + if (!optarg) + { usage(); /* wrong arg count */ exit(1); } @@ -172,7 +183,8 @@ int main(int argc, char *argv[]) break; case 'R': - if (!optarg) { + if (!optarg) + { usage(); /* wrong arg count */ exit(1); } @@ -181,7 +193,8 @@ int main(int argc, char *argv[]) break; case 'S': - if (!optarg) { + if (!optarg) + { usage(); /* wrong arg count */ exit(1); } @@ -190,12 +203,14 @@ int main(int argc, char *argv[]) break; case 'N': - if (!optarg) { + if (!optarg) + { usage(); /* wrong arg count */ exit(1); } - if (*rot_conf_parms != '\0') { + if (*rot_conf_parms != '\0') + { strcat(rot_conf_parms, ","); } @@ -223,7 +238,8 @@ int main(int argc, char *argv[]) */ rig = rig_init(rig_model); - if (!rig) { + if (!rig) + { fprintf(stderr, "Unknown rig num %d, or initialization error.\n", rig_model); @@ -234,26 +250,31 @@ int main(int argc, char *argv[]) retcode = set_conf_rig(rig, rig_conf_parms); - if (retcode != RIG_OK) { + if (retcode != RIG_OK) + { fprintf(stderr, "Config parameter error: %s\n", rigerror(retcode)); exit(2); } - if (rig_file) { + if (rig_file) + { strncpy(rig->state.rigport.pathname, rig_file, FILPATHLEN - 1); } /* FIXME: bound checking and port type == serial */ - if (serial_rate != 0) { + if (serial_rate != 0) + { rig->state.rigport.parm.serial.rate = serial_rate; } - if (civaddr) { + if (civaddr) + { rig_set_conf(rig, rig_token_lookup(rig, "civaddr"), civaddr); } - if (!rig_has_get_level(rig, RIG_LEVEL_STRENGTH)) { + if (!rig_has_get_level(rig, RIG_LEVEL_STRENGTH)) + { fprintf(stderr, "rig backend for %s could not get S-Meter" "or has unsufficient capability\nSorry\n", @@ -263,12 +284,14 @@ int main(int argc, char *argv[]) retcode = rig_open(rig); - if (retcode != RIG_OK) { + if (retcode != RIG_OK) + { fprintf(stderr, "rig_open: error = %s \n", rigerror(retcode)); exit(2); } - if (verbose > 0) { + if (verbose > 0) + { printf("Opened rig model %d, '%s'\n", rig->caps->rig_model, rig->caps->model_name); @@ -279,7 +302,8 @@ int main(int argc, char *argv[]) */ rot = rot_init(rot_model); - if (!rot) { + if (!rot) + { fprintf(stderr, "Unknown rot num %d, or initialization error.\n", rot_model); @@ -290,23 +314,27 @@ int main(int argc, char *argv[]) retcode = set_conf_rot(rot, rot_conf_parms); - if (retcode != RIG_OK) { + if (retcode != RIG_OK) + { fprintf(stderr, "Config parameter error: %s\n", rigerror(retcode)); exit(2); } - if (rot_file) { + if (rot_file) + { strncpy(rot->state.rotport.pathname, rot_file, FILPATHLEN - 1); } /* FIXME: bound checking and port type == serial */ - if (rot_serial_rate != 0) { + if (rot_serial_rate != 0) + { rot->state.rotport.parm.serial.rate = rot_serial_rate; } retcode = rot_open(rot); - if (retcode != RIG_OK && rot_model != ROT_MODEL_DUMMY) { + if (retcode != RIG_OK && rot_model != ROT_MODEL_DUMMY) + { fprintf(stderr, "rot_open: error = %s \n", rigerror(retcode)); exit(2); } @@ -317,14 +345,16 @@ int main(int argc, char *argv[]) /* if (rot_model == ROT_MODEL_DUMMY) */ /* with_rot = 1; */ - if (verbose > 0) { + if (verbose > 0) + { printf("Opened rotator model %d, '%s'\n", rot->caps->rot_model, rot->caps->model_name); } /*******************************/ - if (optind < argc) { + if (optind < argc) + { step = atof(argv[optind]) * 1e6; } @@ -333,7 +363,8 @@ int main(int argc, char *argv[]) fprintf(stderr, "Wait for rotator to move...\n"); rot_get_position(rot, &azimuth, &elevation); - while (fabs(azimuth - rot->state.min_az) > 1.) { + while (fabs(azimuth - rot->state.min_az) > 1.) + { rot_get_position(rot, &azimuth, &elevation); usleep(step); } @@ -344,7 +375,8 @@ int main(int argc, char *argv[]) /* TODO: check CW or CCW */ /* disable AGC? */ - while (fabs(rot->state.max_az - azimuth) > 1.) { + while (fabs(rot->state.max_az - azimuth) > 1.) + { value_t strength; rig_get_level(rig, RIG_VFO_CURR, RIG_LEVEL_STRENGTH, &strength); @@ -375,18 +407,18 @@ void usage() "Input S-Meter vs Azimuth.\n\n"); printf( - " -m, --model=ID select radio model number. See model list\n" - " -r, --rig-file=DEVICE set device of the radio to operate on\n" - " -s, --serial-speed=BAUD set serial speed of the serial port\n" - " -c, --civaddr=ID set CI-V address, decimal (for Icom rigs only)\n" - " -C, --set-conf=PARM=VAL set config parameters\n" - " -M, --rot-model=ID select rotator model number. See model list\n" - " -R, --rot-file=DEVICE set device of the rotator to operate on\n" - " -S, --rot-serial-speed=BAUD set serial speed of the serial port\n" - " -N, --rot-set-conf=PARM=VAL set rotator config parameters\n" - " -v, --verbose set verbose mode, cumulative\n" - " -h, --help display this help and exit\n" - " -V, --version output version information and exit\n\n" + " -m, --model=ID select radio model number. See model list\n" + " -r, --rig-file=DEVICE set device of the radio to operate on\n" + " -s, --serial-speed=BAUD set serial speed of the serial port\n" + " -c, --civaddr=ID set CI-V address, decimal (for Icom rigs only)\n" + " -C, --set-conf=PARM=VAL set config parameters\n" + " -M, --rot-model=ID select rotator model number. See model list\n" + " -R, --rot-file=DEVICE set device of the rotator to operate on\n" + " -S, --rot-serial-speed=BAUD set serial speed of the serial port\n" + " -N, --rot-set-conf=PARM=VAL set rotator config parameters\n" + " -v, --verbose set verbose mode, cumulative\n" + " -h, --help display this help and exit\n" + " -V, --version output version information and exit\n\n" ); printf("\nReport bugs to .\n"); @@ -401,24 +433,28 @@ int set_conf_rig(RIG *rig, char *conf_parms) p = conf_parms; - while (p && *p != '\0') { + while (p && *p != '\0') + { /* FIXME: left hand value of = cannot be null */ q = strchr(p, '='); - if (!q) { + if (!q) + { return RIG_EINVAL; } *q++ = '\0'; n = strchr(q, ','); - if (n) { + if (n) + { *n++ = '\0'; } ret = rig_set_conf(rig, rig_token_lookup(rig, p), q); - if (ret != RIG_OK) { + if (ret != RIG_OK) + { return ret; } @@ -436,23 +472,27 @@ int set_conf_rot(ROT *rot, char *conf_parms) p = conf_parms; - while (p && *p != '\0') { + while (p && *p != '\0') + { /* FIXME: left hand value of = cannot be null */ q = strchr(p, '='); - if (q) { + if (q) + { *q++ = '\0'; } n = strchr(q, ','); - if (n) { + if (n) + { *n++ = '\0'; } ret = rot_set_conf(rot, rot_token_lookup(rot, p), q); - if (ret != RIG_OK) { + if (ret != RIG_OK) + { return ret; } diff --git a/tests/rigswr.c b/tests/rigswr.c index b6b31a8e3..f952734de 100644 --- a/tests/rigswr.c +++ b/tests/rigswr.c @@ -50,7 +50,8 @@ static int set_conf(RIG *rig, char *conf_parms); * NB: do NOT use -W since it's reserved by POSIX. */ #define SHORT_OPTIONS "m:r:s:c:C:p:P:vhV" -static struct option long_options[] = { +static struct option long_options[] = +{ {"model", 1, 0, 'm'}, {"rig-file", 1, 0, 'r'}, {"serial-speed", 1, 0, 's'}, @@ -84,17 +85,20 @@ int main(int argc, char *argv[]) freq_t step = kHz(100); value_t pwr; - while (1) { + while (1) + { int c; int option_index = 0; c = getopt_long(argc, argv, SHORT_OPTIONS, long_options, &option_index); - if (c == -1) { + if (c == -1) + { break; } - switch (c) { + switch (c) + { case 'h': usage(); exit(0); @@ -104,7 +108,8 @@ int main(int argc, char *argv[]) exit(0); case 'm': - if (!optarg) { + if (!optarg) + { usage(); /* wrong arg count */ exit(1); } @@ -113,7 +118,8 @@ int main(int argc, char *argv[]) break; case 'r': - if (!optarg) { + if (!optarg) + { usage(); /* wrong arg count */ exit(1); } @@ -122,7 +128,8 @@ int main(int argc, char *argv[]) break; case 'c': - if (!optarg) { + if (!optarg) + { usage(); /* wrong arg count */ exit(1); } @@ -131,7 +138,8 @@ int main(int argc, char *argv[]) break; case 's': - if (!optarg) { + if (!optarg) + { usage(); /* wrong arg count */ exit(1); } @@ -140,12 +148,14 @@ int main(int argc, char *argv[]) break; case 'C': - if (!optarg) { + if (!optarg) + { usage(); /* wrong arg count */ exit(1); } - if (*conf_parms != '\0') { + if (*conf_parms != '\0') + { strcat(conf_parms, ","); } @@ -153,7 +163,8 @@ int main(int argc, char *argv[]) break; case 'p': - if (!optarg) { + if (!optarg) + { usage(); /* wrong arg count */ exit(1); } @@ -162,22 +173,34 @@ int main(int argc, char *argv[]) break; case 'P': - if (!optarg) { + if (!optarg) + { usage(); /* wrong arg count */ exit(1); } - if (!strcmp(optarg, "RIG")) { + if (!strcmp(optarg, "RIG")) + { ptt_type = RIG_PTT_RIG; - } else if (!strcmp(optarg, "DTR")) { + } + else if (!strcmp(optarg, "DTR")) + { ptt_type = RIG_PTT_SERIAL_DTR; - } else if (!strcmp(optarg, "RTS")) { + } + else if (!strcmp(optarg, "RTS")) + { ptt_type = RIG_PTT_SERIAL_RTS; - } else if (!strcmp(optarg, "PARALLEL")) { + } + else if (!strcmp(optarg, "PARALLEL")) + { ptt_type = RIG_PTT_PARALLEL; - } else if (!strcmp(optarg, "NONE")) { + } + else if (!strcmp(optarg, "NONE")) + { ptt_type = RIG_PTT_NONE; - } else { + } + else + { ptt_type = atoi(optarg); } @@ -199,14 +222,16 @@ int main(int argc, char *argv[]) rig_debug(RIG_DEBUG_VERBOSE, "Report bugs to \n\n"); - if (optind + 1 >= argc) { + if (optind + 1 >= argc) + { usage(); exit(1); } rig = rig_init(my_model); - if (!rig) { + if (!rig) + { fprintf(stderr, "Unknown rig num %d, or initialization error.\n", my_model); @@ -217,35 +242,42 @@ int main(int argc, char *argv[]) retcode = set_conf(rig, conf_parms); - if (retcode != RIG_OK) { + if (retcode != RIG_OK) + { fprintf(stderr, "Config parameter error: %s\n", rigerror(retcode)); exit(2); } - if (ptt_type != RIG_PTT_NONE) { + if (ptt_type != RIG_PTT_NONE) + { rig->state.pttport.type.ptt = ptt_type; } - if (ptt_file) { + if (ptt_file) + { strncpy(rig->state.pttport.pathname, ptt_file, FILPATHLEN - 1); } - if (rig_file) { + if (rig_file) + { strncpy(rig->state.rigport.pathname, rig_file, FILPATHLEN - 1); } /* FIXME: bound checking and port type == serial */ - if (serial_rate != 0) { + if (serial_rate != 0) + { rig->state.rigport.parm.serial.rate = serial_rate; } - if (civaddr) { + if (civaddr) + { rig_set_conf(rig, rig_token_lookup(rig, "civaddr"), civaddr); } if (!rig_has_get_level(rig, RIG_LEVEL_SWR) - || rig->state.pttport.type.ptt == RIG_PTT_NONE) { + || rig->state.pttport.type.ptt == RIG_PTT_NONE) + { fprintf(stderr, "rig backend for %s could not get SWR" @@ -257,12 +289,14 @@ int main(int argc, char *argv[]) retcode = rig_open(rig); - if (retcode != RIG_OK) { + if (retcode != RIG_OK) + { fprintf(stderr, "rig_open: error = %s \n", rigerror(retcode)); exit(2); } - if (verbose > 0) { + if (verbose > 0) + { printf("Opened rig model %d, '%s'\n", rig->caps->rig_model, rig->caps->model_name); @@ -271,7 +305,8 @@ int main(int argc, char *argv[]) freq = atof(argv[optind++]); freqstop = atof(argv[optind++]); - if (optind < argc) { + if (optind < argc) + { step = atof(argv[optind]); } @@ -281,7 +316,8 @@ int main(int argc, char *argv[]) pwr.f = 0.25; /* 25% of RF POWER */ rig_set_level(rig, RIG_VFO_CURR, RIG_LEVEL_RFPOWER, pwr); - while (freq <= freqstop) { + while (freq <= freqstop) + { value_t swr; rig_set_ptt(rig, RIG_VFO_CURR, RIG_PTT_ON); @@ -314,16 +350,16 @@ void usage() printf( - " -m, --model=ID select radio model number. See model list\n" - " -r, --rig-file=DEVICE set device of the radio to operate on\n" - " -s, --serial-speed=BAUD set serial speed of the serial port\n" - " -c, --civaddr=ID set CI-V address, decimal (for Icom rigs only)\n" - " -C, --set-conf=PARM=VAL set config parameters\n" - " -p, --ptt-file=DEVICE set device of the PTT device to operate on\n" - " -P, --ptt-type=TYPE set type of the PTT device to operate on\n" - " -v, --verbose set verbose mode, cumulative\n" - " -h, --help display this help and exit\n" - " -V, --version output version information and exit\n\n" + " -m, --model=ID select radio model number. See model list\n" + " -r, --rig-file=DEVICE set device of the radio to operate on\n" + " -s, --serial-speed=BAUD set serial speed of the serial port\n" + " -c, --civaddr=ID set CI-V address, decimal (for Icom rigs only)\n" + " -C, --set-conf=PARM=VAL set config parameters\n" + " -p, --ptt-file=DEVICE set device of the PTT device to operate on\n" + " -P, --ptt-type=TYPE set type of the PTT device to operate on\n" + " -v, --verbose set verbose mode, cumulative\n" + " -h, --help display this help and exit\n" + " -V, --version output version information and exit\n\n" ); printf("\nReport bugs to .\n"); @@ -338,24 +374,28 @@ int set_conf(RIG *rig, char *conf_parms) p = conf_parms; - while (p && *p != '\0') { + while (p && *p != '\0') + { /* FIXME: left hand value of = cannot be null */ q = strchr(p, '='); - if (!q) { + if (!q) + { return RIG_EINVAL; } *q++ = '\0'; n = strchr(q, ','); - if (n) { + if (n) + { *n++ = '\0'; } ret = rig_set_conf(rig, rig_token_lookup(rig, p), q); - if (ret != RIG_OK) { + if (ret != RIG_OK) + { return ret; } diff --git a/tests/rotctl.c b/tests/rotctl.c index a8c1814c0..16e412fef 100644 --- a/tests/rotctl.c +++ b/tests/rotctl.c @@ -62,7 +62,7 @@ extern int read_history(); # endif /* defined(HAVE_READLINE_HISTORY_H) */ #else /* no history */ -#define HST_SHRT_OPTS "" +# define HST_SHRT_OPTS "" #endif /* HAVE_READLINE_HISTORY */ @@ -83,7 +83,8 @@ void usage(); * TODO: add an option to read from a file */ #define SHORT_OPTIONS "+m:r:s:C:t:LvhVlu" -static struct option long_options[] = { +static struct option long_options[] = +{ {"model", 1, 0, 'm'}, {"rot-file", 1, 0, 'r'}, {"serial-speed", 1, 0, 's'}, @@ -141,7 +142,8 @@ int main(int argc, char *argv[]) int serial_rate = 0; char conf_parms[MAXCONFLEN] = ""; - while (1) { + while (1) + { int c; int option_index = 0; @@ -151,11 +153,13 @@ int main(int argc, char *argv[]) long_options, &option_index); - if (c == -1) { + if (c == -1) + { break; } - switch (c) { + switch (c) + { case 'h': usage(); exit(0); @@ -165,7 +169,8 @@ int main(int argc, char *argv[]) exit(0); case 'm': - if (!optarg) { + if (!optarg) + { usage(); /* wrong arg count */ exit(1); } @@ -174,7 +179,8 @@ int main(int argc, char *argv[]) break; case 'r': - if (!optarg) { + if (!optarg) + { usage(); /* wrong arg count */ exit(1); } @@ -183,7 +189,8 @@ int main(int argc, char *argv[]) break; case 's': - if (!optarg) { + if (!optarg) + { usage(); /* wrong arg count */ exit(1); } @@ -192,12 +199,14 @@ int main(int argc, char *argv[]) break; case 'C': - if (!optarg) { + if (!optarg) + { usage(); /* wrong arg count */ exit(1); } - if (*conf_parms != '\0') { + if (*conf_parms != '\0') + { strcat(conf_parms, ","); } @@ -205,14 +214,18 @@ int main(int argc, char *argv[]) break; case 't': - if (!optarg) { + if (!optarg) + { usage(); /* wrong arg count */ exit(1); } - if (strlen(optarg) > 1) { + if (strlen(optarg) > 1) + { send_cmd_term = strtol(optarg, NULL, 0); - } else { + } + else + { send_cmd_term = optarg[0]; } @@ -261,13 +274,15 @@ int main(int argc, char *argv[]) * at least one command on command line, * disable interactive mode */ - if (optind < argc) { + if (optind < argc) + { interactive = 0; } my_rot = rot_init(my_model); - if (!my_rot) { + if (!my_rot) + { fprintf(stderr, "Unknown rot num %d, or initialization error.\n", my_model); @@ -278,24 +293,28 @@ int main(int argc, char *argv[]) retcode = set_conf(my_rot, conf_parms); - if (retcode != RIG_OK) { + if (retcode != RIG_OK) + { fprintf(stderr, "Config parameter error: %s\n", rigerror(retcode)); exit(2); } - if (rot_file) { + if (rot_file) + { strncpy(my_rot->state.rotport.pathname, rot_file, FILPATHLEN - 1); } /* FIXME: bound checking and port type == serial */ - if (serial_rate != 0) { + if (serial_rate != 0) + { my_rot->state.rotport.parm.serial.rate = serial_rate; } /* * print out conf parameters */ - if (show_conf) { + if (show_conf) + { rot_token_foreach(my_rot, print_conf_list, (rig_ptr_t)my_rot); } @@ -303,7 +322,8 @@ int main(int argc, char *argv[]) * Print out capabilities, and exits immediately as we may be interested * only in caps, and rig_open may fail. */ - if (dump_caps_opt) { + if (dump_caps_opt) + { dumpcaps_rot(my_rot, stdout); rot_cleanup(my_rot); /* if you care about memory */ exit(0); @@ -311,12 +331,14 @@ int main(int argc, char *argv[]) retcode = rot_open(my_rot); - if (retcode != RIG_OK) { + if (retcode != RIG_OK) + { fprintf(stderr, "rot_open: error = %s \n", rigerror(retcode)); exit(2); } - if (verbose > 0) { + if (verbose > 0) + { printf("Opened rot model %d, '%s'\n", my_rot->caps->rot_model, my_rot->caps->model_name); @@ -331,18 +353,22 @@ int main(int argc, char *argv[]) #ifdef HAVE_LIBREADLINE - if (interactive && prompt && have_rl) { + if (interactive && prompt && have_rl) + { rl_readline_name = "rotctl"; #ifdef HAVE_READLINE_HISTORY using_history(); /* Initialize Readline History */ - if (rd_hist || sv_hist) { - if (!(hist_dir = getenv("ROTCTL_HIST_DIR"))) { + if (rd_hist || sv_hist) + { + if (!(hist_dir = getenv("ROTCTL_HIST_DIR"))) + { hist_dir = getenv("HOME"); } if (((stat(hist_dir, &hist_dir_stat) == -1) && (errno == ENOENT)) - || !(S_ISDIR(hist_dir_stat.st_mode))) { + || !(S_ISDIR(hist_dir_stat.st_mode))) + { fprintf(stderr, "Warning: %s is not a directory!\n", hist_dir); } @@ -356,8 +382,10 @@ int main(int argc, char *argv[]) strncat(hist_path, hist_file, strlen(hist_file)); } - if (rd_hist && hist_path) { - if (read_history(hist_path) == ENOENT) { + if (rd_hist && hist_path) + { + if (read_history(hist_path) == ENOENT) + { fprintf(stderr, "Warning: Could not read history from %s\n", hist_path); @@ -369,28 +397,35 @@ int main(int argc, char *argv[]) #endif /* HAVE_LIBREADLINE */ - do { + do + { retcode = rotctl_parse(my_rot, stdin, stdout, argv, argc); - if (retcode == 2) { + if (retcode == 2) + { exitcode = 2; } - } while (retcode == 0 || retcode == 2); + } + while (retcode == 0 || retcode == 2); #ifdef HAVE_LIBREADLINE - if (interactive && prompt && have_rl) { + if (interactive && prompt && have_rl) + { #ifdef HAVE_READLINE_HISTORY - if (sv_hist && hist_path) { - if (write_history(hist_path) == ENOENT) { + if (sv_hist && hist_path) + { + if (write_history(hist_path) == ENOENT) + { fprintf(stderr, "\nWarning: Could not write history to %s\n", hist_path); } } - if ((rd_hist || sv_hist) && hist_path) { + if ((rd_hist || sv_hist) && hist_path) + { free(hist_path); hist_path = (char *)NULL; } @@ -411,23 +446,22 @@ void usage() printf("Usage: rotctl [OPTION]... [COMMAND]...\n" "Send COMMANDs to a connected antenna rotator.\n\n"); - printf( - " -m, --model=ID select rotator model number. See model list\n" - " -r, --rot-file=DEVICE set device of the rotator to operate on\n" - " -s, --serial-speed=BAUD set serial speed of the serial port\n" - " -t, --send-cmd-term=CHAR set send_cmd command termination char\n" - " -C, --set-conf=PARM=VAL set config parameters\n" - " -L, --show-conf list all config parameters\n" - " -l, --list list all model numbers and exit\n" - " -u, --dump-caps dump capabilities and exit\n" + " -m, --model=ID select rotator model number. See model list\n" + " -r, --rot-file=DEVICE set device of the rotator to operate on\n" + " -s, --serial-speed=BAUD set serial speed of the serial port\n" + " -t, --send-cmd-term=CHAR set send_cmd command termination char\n" + " -C, --set-conf=PARM=VAL set config parameters\n" + " -L, --show-conf list all config parameters\n" + " -l, --list list all model numbers and exit\n" + " -u, --dump-caps dump capabilities and exit\n" #ifdef HAVE_READLINE_HISTORY - " -i, --read-history read prior interactive session history\n" - " -I, --save-history save current interactive session history\n" + " -i, --read-history read prior interactive session history\n" + " -I, --save-history save current interactive session history\n" #endif - " -v, --verbose set verbose mode, cumulative\n" - " -h, --help display this help and exit\n" - " -V, --version output version information and exit\n\n" + " -v, --verbose set verbose mode, cumulative\n" + " -h, --help display this help and exit\n" + " -V, --version output version information and exit\n\n" ); usage_rot(stdout); diff --git a/tests/rotctl_parse.c b/tests/rotctl_parse.c index fe6cd0cba..3d10b3ab9 100644 --- a/tests/rotctl_parse.c +++ b/tests/rotctl_parse.c @@ -79,7 +79,7 @@ extern int read_history(); * */ #if (defined(HAVE_SSLEEP) || defined(_WIN32)) && (!defined(HAVE_SLEEP)) -#include "hl_sleep.h" +# include "hl_sleep.h" #endif #include "rotctl_parse.h" @@ -88,7 +88,7 @@ extern int read_history(); #include "uthash.h" #ifdef HAVE_PTHREAD -#include +# include static pthread_mutex_t rot_mutex = PTHREAD_MUTEX_INITIALIZER; #endif @@ -129,7 +129,8 @@ static char *rp_hist_buf = (char *)NULL; static const int have_rl = 0; #endif -struct test_table { +struct test_table +{ unsigned char cmd; const char *name; int (*rot_routine)(ROT *, @@ -193,7 +194,8 @@ declare_proto_rot(pause); * * NB: 'q' 'Q' '?' are reserved by interactive mode interface */ -struct test_table test_list[] = { +struct test_table test_list[] = +{ { 'P', "set_pos", ACTION(set_position), ARG_IN, "Azimuth", "Elevation" }, { 'p', "get_pos", ACTION(get_position), ARG_OUT, "Azimuth", "Elevation" }, { 'K', "park", ACTION(park), ARG_NONE, }, @@ -225,11 +227,13 @@ struct test_table *find_cmd_entry(int cmd) int i; for (i = 0; i < MAXNBOPT && test_list[i].cmd != 0x00; i++) - if (test_list[i].cmd == cmd) { + if (test_list[i].cmd == cmd) + { break; } - if (i >= MAXNBOPT || test_list[i].cmd == 0x00) { + if (i >= MAXNBOPT || test_list[i].cmd == 0x00) + { return NULL; } @@ -242,7 +246,8 @@ struct test_table *find_cmd_entry(int cmd) * Structure and hash funtions patterned after/copied from example.c * distributed with the uthash package. See: http://uthash.sourceforge.net/ */ -struct mod_lst { +struct mod_lst +{ int id; /* caps->rot_model This is the hash key */ char mfg_name[32]; /* caps->mfg_name */ char model_name[32]; /* caps->model_name */ @@ -294,7 +299,8 @@ void hash_delete_all() { struct mod_lst *current_model, *tmp; - HASH_ITER(hh, models, current_model, tmp) { + HASH_ITER(hh, models, current_model, tmp) + { /* delete it (models advances to next) */ HASH_DEL(models, current_model); free(current_model); /* free it */ @@ -311,19 +317,22 @@ static void rp_getline(const char *s) int i; /* free allocated memory and set pointers to NULL */ - if (input_line) { + if (input_line) + { free(input_line); input_line = (char *)NULL; } - if (result) { + if (result) + { result = (char *)NULL; } /* cmd, arg1, arg2, arg3, arg4, arg5, arg6 * arg5 and arg 6 are currently unused. */ - for (i = 0; i < 7; i++) { + for (i = 0; i < 7; i++) + { parsed_input[i] = NULL; } @@ -342,8 +351,10 @@ char parse_arg(const char *arg) { int i; - for (i = 0; i < MAXNBOPT && test_list[i].cmd != 0; i++) { - if (!strncmp(arg, test_list[i].name, MAXNAMSIZ)) { + for (i = 0; i < MAXNBOPT && test_list[i].cmd != 0; i++) + { + if (!strncmp(arg, test_list[i].name, MAXNAMSIZ)) + { return test_list[i].cmd; } } @@ -359,11 +370,14 @@ static int scanfc(FILE *fin, const char *format, void *p) { int ret; - do { + do + { ret = fscanf(fin, format, p); - if (ret < 0) { - if (errno == EINTR) { + if (ret < 0) + { + if (errno == EINTR) + { continue; } @@ -372,7 +386,8 @@ static int scanfc(FILE *fin, const char *format, void *p) } return ret; - } while (1); + } + while (1); } @@ -391,43 +406,61 @@ static int next_word(char *buffer, int argc, char *argv[], int newline) char c; static int reading_stdin; - if (!reading_stdin) { - if (optind >= argc) { + if (!reading_stdin) + { + if (optind >= argc) + { return EOF; - } else if (newline - && '-' == argv[optind][0] - && 1 == strlen(argv[optind])) { + } + else if (newline + && '-' == argv[optind][0] + && 1 == strlen(argv[optind])) + { ++optind; reading_stdin = 1; } } - if (reading_stdin) { - do { - do { + if (reading_stdin) + { + do + { + do + { ret = scanf(" %c%" STR(MAXARGSZ) "[^ \t\n#]", &c, &buffer[1]); - } while (EINTR == ret); + } + while (EINTR == ret); - if (ret > 0 && '#' == c) { - do { + if (ret > 0 && '#' == c) + { + do + { ret = scanf("%*[^\n]"); - } while (EINTR == ret); /* consume comments */ + } + while (EINTR == ret); /* consume comments */ ret = 0; } - } while (!ret); + } + while (!ret); - if (EOF == ret) { + if (EOF == ret) + { reading_stdin = 0; - } else if (ret < 0) { + } + else if (ret < 0) + { rig_debug(RIG_DEBUG_ERR, "scanf: %s\n", strerror(errno)); reading_stdin = 0; - } else { + } + else + { buffer[0] = c; buffer[1 == ret ? 1 : MAXARGSZ] = '\0'; - if (newline) { + if (newline) + { putchar('\n'); } @@ -436,12 +469,16 @@ static int next_word(char *buffer, int argc, char *argv[], int newline) } } - if (!reading_stdin) { - if (optind < argc) { + if (!reading_stdin) + { + if (optind < argc) + { strncpy(buffer, argv[optind++], MAXARGSZ); buffer[MAXARGSZ] = '\0'; ret = 1; - } else { + } + else + { ret = EOF; } } @@ -481,27 +518,36 @@ int rotctl_parse(ROT *my_rot, FILE *fin, FILE *fout, char *argv[], int argc) static int last_was_ret = 1; /* cmd, internal, rotctld */ - if (!(interactive && prompt && have_rl)) { - if (interactive) { - if (prompt) { + if (!(interactive && prompt && have_rl)) + { + if (interactive) + { + if (prompt) + { fprintf_flush(fout, "\nRotator command: "); } - do { - if (scanfc(fin, "%c", &cmd) < 1) { + do + { + if (scanfc(fin, "%c", &cmd) < 1) + { return -1; } /* Extended response protocol requested with leading '+' on command * string--rotctld only! */ - if (cmd == '+' && !prompt) { + if (cmd == '+' && !prompt) + { ext_resp = 1; - if (scanfc(fin, "%c", &cmd) < 1) { + if (scanfc(fin, "%c", &cmd) < 1) + { return -1; } - } else if (cmd == '+' && prompt) { + } + else if (cmd == '+' && prompt) + { return 0; } @@ -509,34 +555,42 @@ int rotctl_parse(ROT *my_rot, FILE *fin, FILE *fout, char *argv[], int argc) && cmd != '_' && cmd != '#' && ispunct(cmd) - && !prompt) { + && !prompt) + { ext_resp = 1; resp_sep = cmd; - if (scanfc(fin, "%c", &cmd) < 1) { + if (scanfc(fin, "%c", &cmd) < 1) + { return -1; } - } else if (cmd != '\\' - && cmd != '?' - && cmd != '_' - && cmd != '#' - && ispunct(cmd) - && prompt) { + } + else if (cmd != '\\' + && cmd != '?' + && cmd != '_' + && cmd != '#' + && ispunct(cmd) + && prompt) + { return 0; } /* command by name */ - if (cmd == '\\') { + if (cmd == '\\') + { unsigned char cmd_name[MAXNAMSIZ], *pcmd = cmd_name; int c_len = MAXNAMSIZ; - if (scanfc(fin, "%c", pcmd) < 1) { + if (scanfc(fin, "%c", pcmd) < 1) + { return -1; } - while (c_len-- && (isalnum(*pcmd) || *pcmd == '_')) { - if (scanfc(fin, "%c", ++pcmd) < 1) { + while (c_len-- && (isalnum(*pcmd) || *pcmd == '_')) + { + if (scanfc(fin, "%c", ++pcmd) < 1) + { return -1; } } @@ -546,9 +600,12 @@ int rotctl_parse(ROT *my_rot, FILE *fin, FILE *fout, char *argv[], int argc) break; } - if (cmd == 0x0a || cmd == 0x0d) { - if (last_was_ret) { - if (prompt) { + if (cmd == 0x0a || cmd == 0x0d) + { + if (last_was_ret) + { + if (prompt) + { fprintf_flush(fout, "? for help, q to quit.\n"); } @@ -557,14 +614,18 @@ int rotctl_parse(ROT *my_rot, FILE *fin, FILE *fout, char *argv[], int argc) last_was_ret = 1; } - } while (cmd == 0x0a || cmd == 0x0d); + } + while (cmd == 0x0a || cmd == 0x0d); last_was_ret = 0; /* comment line */ - if (cmd == '#') { - while (cmd != '\n' && cmd != '\r') { - if (scanfc(fin, "%c", &cmd) < 1) { + if (cmd == '#') + { + while (cmd != '\n' && cmd != '\r') + { + if (scanfc(fin, "%c", &cmd) < 1) + { return -1; } } @@ -572,99 +633,133 @@ int rotctl_parse(ROT *my_rot, FILE *fin, FILE *fout, char *argv[], int argc) return 0; } - if (cmd == 'Q' || cmd == 'q') { + if (cmd == 'Q' || cmd == 'q') + { return 1; } - if (cmd == '?') { + if (cmd == '?') + { usage_rot(fout); fflush(fout); return 0; } - } else { + } + else + { /* parse rest of command line */ retcode = next_word(command, argc, argv, 1); - if (EOF == retcode) { + if (EOF == retcode) + { return 1; - } else if (retcode < 0) { + } + else if (retcode < 0) + { return retcode; - } else if ('\0' == command[1]) { + } + else if ('\0' == command[1]) + { cmd = command[0]; - } else { + } + else + { cmd = parse_arg(command); } } cmd_entry = find_cmd_entry(cmd); - if (!cmd_entry) { + if (!cmd_entry) + { fprintf_flush(stderr, "Command '%c' not found!\n", cmd); return 0; } if ((cmd_entry->flags & ARG_IN_LINE) && (cmd_entry->flags & ARG_IN1) - && cmd_entry->arg1) { + && cmd_entry->arg1) + { - if (interactive) { + if (interactive) + { char *nl; - if (prompt) { + if (prompt) + { fprintf_flush(fout, "%s: ", cmd_entry->arg1); } - if (fgets(arg1, MAXARGSZ, fin) == NULL) { + if (fgets(arg1, MAXARGSZ, fin) == NULL) + { return -1; } - if (arg1[0] == 0xa) { - if (fgets(arg1, MAXARGSZ, fin) == NULL) { + if (arg1[0] == 0xa) + { + if (fgets(arg1, MAXARGSZ, fin) == NULL) + { return -1; } } nl = strchr(arg1, 0xa); - if (nl) { + if (nl) + { *nl = '\0'; /* chomp */ } p1 = arg1[0] == ' ' ? arg1 + 1 : arg1; - } else { + } + else + { retcode = next_word(arg1, argc, argv, 0); - if (EOF == retcode) { + if (EOF == retcode) + { fprintf(stderr, "Invalid arg for command '%s'\n", cmd_entry->name); return 1; - } else if (retcode < 0) { + } + else if (retcode < 0) + { return retcode; } p1 = arg1; } - } else if ((cmd_entry->flags & ARG_IN1) && cmd_entry->arg1) { - if (interactive) { - if (prompt) { + } + else if ((cmd_entry->flags & ARG_IN1) && cmd_entry->arg1) + { + if (interactive) + { + if (prompt) + { fprintf_flush(fout, "%s: ", cmd_entry->arg1); } - if (scanfc(fin, "%s", arg1) < 1) { + if (scanfc(fin, "%s", arg1) < 1) + { return -1; } p1 = arg1; - } else { + } + else + { retcode = next_word(arg1, argc, argv, 0); - if (EOF == retcode) { + if (EOF == retcode) + { fprintf(stderr, "Invalid arg for command '%s'\n", cmd_entry->name); return 1; - } else if (retcode < 0) { + } + else if (retcode < 0) + { return retcode; } @@ -675,27 +770,36 @@ int rotctl_parse(ROT *my_rot, FILE *fin, FILE *fout, char *argv[], int argc) if (p1 && p1[0] != '?' && (cmd_entry->flags & ARG_IN2) - && cmd_entry->arg2) { + && cmd_entry->arg2) + { - if (interactive) { - if (prompt) { + if (interactive) + { + if (prompt) + { fprintf_flush(fout, "%s: ", cmd_entry->arg2); } - if (scanfc(fin, "%s", arg2) < 1) { + if (scanfc(fin, "%s", arg2) < 1) + { return -1; } p2 = arg2; - } else { + } + else + { retcode = next_word(arg2, argc, argv, 0); - if (EOF == retcode) { + if (EOF == retcode) + { fprintf(stderr, "Invalid arg for command '%s'\n", cmd_entry->name); return 1; - } else if (retcode < 0) { + } + else if (retcode < 0) + { return retcode; } @@ -706,27 +810,36 @@ int rotctl_parse(ROT *my_rot, FILE *fin, FILE *fout, char *argv[], int argc) if (p1 && p1[0] != '?' && (cmd_entry->flags & ARG_IN3) - && cmd_entry->arg3) { + && cmd_entry->arg3) + { - if (interactive) { - if (prompt) { + if (interactive) + { + if (prompt) + { fprintf_flush(fout, "%s: ", cmd_entry->arg3); } - if (scanfc(fin, "%s", arg3) < 1) { + if (scanfc(fin, "%s", arg3) < 1) + { return -1; } p3 = arg3; - } else { + } + else + { retcode = next_word(arg3, argc, argv, 0); - if (EOF == retcode) { + if (EOF == retcode) + { fprintf(stderr, "Invalid arg for command '%s'\n", cmd_entry->name); return 1; - } else if (retcode < 0) { + } + else if (retcode < 0) + { return retcode; } @@ -737,27 +850,36 @@ int rotctl_parse(ROT *my_rot, FILE *fin, FILE *fout, char *argv[], int argc) if (p1 && p1[0] != '?' && (cmd_entry->flags & ARG_IN4) - && cmd_entry->arg4) { + && cmd_entry->arg4) + { - if (interactive) { - if (prompt) { + if (interactive) + { + if (prompt) + { fprintf_flush(fout, "%s: ", cmd_entry->arg4); } - if (scanfc(fin, "%s", arg4) < 1) { + if (scanfc(fin, "%s", arg4) < 1) + { return -1; } p4 = arg4; - } else { + } + else + { retcode = next_word(arg4, argc, argv, 0); - if (EOF == retcode) { + if (EOF == retcode) + { fprintf(stderr, "Invalid arg for command '%s'\n", cmd_entry->name); return 1; - } else if (retcode < 0) { + } + else if (retcode < 0) + { return retcode; } @@ -768,7 +890,8 @@ int rotctl_parse(ROT *my_rot, FILE *fin, FILE *fout, char *argv[], int argc) #ifdef HAVE_LIBREADLINE - if (interactive && prompt && have_rl) { + if (interactive && prompt && have_rl) + { int j, x; #ifdef HAVE_READLINE_HISTORY @@ -784,30 +907,35 @@ int rotctl_parse(ROT *my_rot, FILE *fin, FILE *fout, char *argv[], int argc) rp_getline("\nRotator command: "); /* EOF (Ctl-D) received on empty input line, bail out gracefully. */ - if (!input_line) { + if (!input_line) + { fprintf_flush(fout, "\n"); return 1; } /* Q or q to quit */ - if (!(strncasecmp(input_line, "q", 1))) { + if (!(strncasecmp(input_line, "q", 1))) + { return 1; } /* '?' for help */ - if (!(strncmp(input_line, "?", 1))) { + if (!(strncmp(input_line, "?", 1))) + { usage_rot(fout); fflush(fout); return 0; } /* '#' for comment */ - if (!(strncmp(input_line, "#", 1))) { + if (!(strncmp(input_line, "#", 1))) + { return 0; } /* Blank line entered */ - if (!(strcmp(input_line, ""))) { + if (!(strcmp(input_line, ""))) + { fprintf(fout, "? for help, q to quit.\n"); fflush(fout); return 0; @@ -825,9 +953,12 @@ int rotctl_parse(ROT *my_rot, FILE *fin, FILE *fout, char *argv[], int argc) /* parsed_input stores pointers into input_line where the token strings * start. */ - if (result) { + if (result) + { parsed_input[0] = result; - } else { + } + else + { /* Oops! Invoke GDB!! */ fprintf_flush(fout, "\n"); return 1; @@ -839,33 +970,38 @@ int rotctl_parse(ROT *my_rot, FILE *fin, FILE *fout, char *argv[], int argc) */ /* Single character command */ - if ((strlen(parsed_input[0]) == 1) && (*parsed_input[0] != '\\')) { + if ((strlen(parsed_input[0]) == 1) && (*parsed_input[0] != '\\')) + { cmd = *parsed_input[0]; #ifdef HAVE_READLINE_HISTORY /* Store what is typed, not validated, for history. */ - if (rp_hist_buf) { + if (rp_hist_buf) + { strncpy(rp_hist_buf, parsed_input[0], 1); } #endif } /* Test the command token, parsed_input[0] */ - else if ((*parsed_input[0] == '\\') && (strlen(parsed_input[0]) > 1)) { + else if ((*parsed_input[0] == '\\') && (strlen(parsed_input[0]) > 1)) + { char cmd_name[MAXNAMSIZ]; /* if there is no terminating '\0' character in the source string, * srncpy() doesn't add one even if the supplied length is less * than the destination array. Truncate the source string here. */ - if (strlen(parsed_input[0] + 1) >= MAXNAMSIZ) { + if (strlen(parsed_input[0] + 1) >= MAXNAMSIZ) + { *(parsed_input[0] + MAXNAMSIZ) = '\0'; } #ifdef HAVE_READLINE_HISTORY - if (rp_hist_buf) { + if (rp_hist_buf) + { strncpy(rp_hist_buf, parsed_input[0], MAXNAMSIZ); } @@ -880,8 +1016,10 @@ int rotctl_parse(ROT *my_rot, FILE *fin, FILE *fout, char *argv[], int argc) /* Sanity check as valid multiple character commands consist of * alpha-numeric characters and the underscore ('_') character. */ - for (j = 0; cmd_name[j] != '\0'; j++) { - if (!(isalnum((int)cmd_name[j]) || cmd_name[j] == '_')) { + for (j = 0; cmd_name[j] != '\0'; j++) + { + if (!(isalnum((int)cmd_name[j]) || cmd_name[j] == '_')) + { fprintf(stderr, "Valid multiple character command names contain alpha-numeric characters plus '_'\n"); return 0; @@ -891,21 +1029,27 @@ int rotctl_parse(ROT *my_rot, FILE *fin, FILE *fout, char *argv[], int argc) cmd = parse_arg(cmd_name); } /* Single '\' entered, prompt again */ - else if ((*parsed_input[0] == '\\') && (strlen(parsed_input[0]) == 1)) { + else if ((*parsed_input[0] == '\\') && (strlen(parsed_input[0]) == 1)) + { return 0; } /* Multiple characters but no leading '\' */ - else { + else + { fprintf(stderr, "Precede multiple character command names with '\\'\n"); return 0; } cmd_entry = find_cmd_entry(cmd); - if (!cmd_entry) { - if (cmd == '\0') { + if (!cmd_entry) + { + if (cmd == '\0') + { fprintf(stderr, "Command '%s' not found!\n", parsed_input[0]); - } else { + } + else + { fprintf(stderr, "Command '%c' not found!\n", cmd); } @@ -915,17 +1059,21 @@ int rotctl_parse(ROT *my_rot, FILE *fin, FILE *fout, char *argv[], int argc) /* \send_cmd */ if ((cmd_entry->flags & ARG_IN_LINE) && (cmd_entry->flags & ARG_IN1) - && cmd_entry->arg1) { + && cmd_entry->arg1) + { /* Check for a non-existent delimiter so as to not break up * remaining line into separate tokens (spaces OK). */ result = strtok(NULL, "\0"); - if (result) { + if (result) + { x = 1; parsed_input[x] = result; - } else { + } + else + { x = 0; char pmptstr[(strlen(cmd_entry->arg1) + 3)]; @@ -935,28 +1083,34 @@ int rotctl_parse(ROT *my_rot, FILE *fin, FILE *fout, char *argv[], int argc) rp_getline(pmptstr); /* Blank line entered */ - if (!(strcmp(input_line, ""))) { + if (!(strcmp(input_line, ""))) + { fprintf(fout, "? for help, q to quit.\n"); fflush(fout); return 0; } - if (input_line) { + if (input_line) + { parsed_input[x] = input_line; - } else { + } + else + { fprintf_flush(fout, "\n"); return 1; } } /* The arg1 array size is MAXARGSZ + 1 so truncate it to fit if larger. */ - if (strlen(parsed_input[x]) > MAXARGSZ) { + if (strlen(parsed_input[x]) > MAXARGSZ) + { parsed_input[x][MAXARGSZ] = '\0'; } #ifdef HAVE_READLINE_HISTORY - if (rp_hist_buf) { + if (rp_hist_buf) + { strncat(rp_hist_buf, " ", 1); strncat(rp_hist_buf, parsed_input[x], MAXARGSZ); } @@ -967,13 +1121,17 @@ int rotctl_parse(ROT *my_rot, FILE *fin, FILE *fout, char *argv[], int argc) } /* Normal argument parsing. */ - else if ((cmd_entry->flags & ARG_IN1) && cmd_entry->arg1) { + else if ((cmd_entry->flags & ARG_IN1) && cmd_entry->arg1) + { result = strtok(NULL, " "); - if (result) { + if (result) + { x = 1; parsed_input[x] = result; - } else { + } + else + { x = 0; char pmptstr[(strlen(cmd_entry->arg1) + 3)]; @@ -982,7 +1140,8 @@ int rotctl_parse(ROT *my_rot, FILE *fin, FILE *fout, char *argv[], int argc) rp_getline(pmptstr); - if (!(strcmp(input_line, ""))) { + if (!(strcmp(input_line, ""))) + { fprintf(fout, "? for help, q to quit.\n"); fflush(fout); return 0; @@ -990,21 +1149,26 @@ int rotctl_parse(ROT *my_rot, FILE *fin, FILE *fout, char *argv[], int argc) result = strtok(input_line, " "); - if (result) { + if (result) + { parsed_input[x] = result; - } else { + } + else + { fprintf_flush(fout, "\n"); return 1; } } - if (strlen(parsed_input[x]) > MAXARGSZ) { + if (strlen(parsed_input[x]) > MAXARGSZ) + { parsed_input[x][MAXARGSZ] = '\0'; } #ifdef HAVE_READLINE_HISTORY - if (rp_hist_buf) { + if (rp_hist_buf) + { strncat(rp_hist_buf, " ", 1); strncat(rp_hist_buf, parsed_input[x], MAXARGSZ); } @@ -1017,14 +1181,18 @@ int rotctl_parse(ROT *my_rot, FILE *fin, FILE *fout, char *argv[], int argc) if (p1 && p1[0] != '?' && (cmd_entry->flags & ARG_IN2) - && cmd_entry->arg2) { + && cmd_entry->arg2) + { result = strtok(NULL, " "); - if (result) { + if (result) + { x = 2; parsed_input[x] = result; - } else { + } + else + { x = 0; char pmptstr[(strlen(cmd_entry->arg2) + 3)]; @@ -1033,7 +1201,8 @@ int rotctl_parse(ROT *my_rot, FILE *fin, FILE *fout, char *argv[], int argc) rp_getline(pmptstr); - if (!(strcmp(input_line, ""))) { + if (!(strcmp(input_line, ""))) + { fprintf(fout, "? for help, q to quit.\n"); fflush(fout); return 0; @@ -1041,21 +1210,26 @@ int rotctl_parse(ROT *my_rot, FILE *fin, FILE *fout, char *argv[], int argc) result = strtok(input_line, " "); - if (result) { + if (result) + { parsed_input[x] = result; - } else { + } + else + { fprintf_flush(fout, "\n"); return 1; } } - if (strlen(parsed_input[x]) > MAXARGSZ) { + if (strlen(parsed_input[x]) > MAXARGSZ) + { parsed_input[x][MAXARGSZ] = '\0'; } #ifdef HAVE_READLINE_HISTORY - if (rp_hist_buf) { + if (rp_hist_buf) + { strncat(rp_hist_buf, " ", 1); strncat(rp_hist_buf, parsed_input[x], MAXARGSZ); } @@ -1068,14 +1242,18 @@ int rotctl_parse(ROT *my_rot, FILE *fin, FILE *fout, char *argv[], int argc) if (p1 && p1[0] != '?' && (cmd_entry->flags & ARG_IN3) - && cmd_entry->arg3) { + && cmd_entry->arg3) + { result = strtok(NULL, " "); - if (result) { + if (result) + { x = 3; parsed_input[x] = result; - } else { + } + else + { x = 0; char pmptstr[(strlen(cmd_entry->arg3) + 3)]; @@ -1084,7 +1262,8 @@ int rotctl_parse(ROT *my_rot, FILE *fin, FILE *fout, char *argv[], int argc) rp_getline(pmptstr); - if (!(strcmp(input_line, ""))) { + if (!(strcmp(input_line, ""))) + { fprintf(fout, "? for help, q to quit.\n"); fflush(fout); return 0; @@ -1092,21 +1271,26 @@ int rotctl_parse(ROT *my_rot, FILE *fin, FILE *fout, char *argv[], int argc) result = strtok(input_line, " "); - if (result) { + if (result) + { parsed_input[x] = result; - } else { + } + else + { fprintf_flush(fout, "\n"); return 1; } } - if (strlen(parsed_input[x]) > MAXARGSZ) { + if (strlen(parsed_input[x]) > MAXARGSZ) + { parsed_input[x][MAXARGSZ] = '\0'; } #ifdef HAVE_READLINE_HISTORY - if (rp_hist_buf) { + if (rp_hist_buf) + { strncat(rp_hist_buf, " ", 1); strncat(rp_hist_buf, parsed_input[x], MAXARGSZ); } @@ -1119,14 +1303,18 @@ int rotctl_parse(ROT *my_rot, FILE *fin, FILE *fout, char *argv[], int argc) if (p1 && p1[0] != '?' && (cmd_entry->flags & ARG_IN4) - && cmd_entry->arg4) { + && cmd_entry->arg4) + { result = strtok(NULL, " "); - if (result) { + if (result) + { x = 4; parsed_input[x] = result; - } else { + } + else + { x = 0; char pmptstr[(strlen(cmd_entry->arg4) + 3)]; @@ -1135,7 +1323,8 @@ int rotctl_parse(ROT *my_rot, FILE *fin, FILE *fout, char *argv[], int argc) rp_getline(pmptstr); - if (!(strcmp(input_line, ""))) { + if (!(strcmp(input_line, ""))) + { fprintf(fout, "? for help, q to quit.\n"); fflush(fout); return 0; @@ -1143,21 +1332,26 @@ int rotctl_parse(ROT *my_rot, FILE *fin, FILE *fout, char *argv[], int argc) result = strtok(input_line, " "); - if (result) { + if (result) + { parsed_input[x] = result; - } else { + } + else + { fprintf_flush(fout, "\n"); return 1; } } - if (strlen(parsed_input[x]) > MAXARGSZ) { + if (strlen(parsed_input[x]) > MAXARGSZ) + { parsed_input[x][MAXARGSZ] = '\0'; } #ifdef HAVE_READLINE_HISTORY - if (rp_hist_buf) { + if (rp_hist_buf) + { strncat(rp_hist_buf, " ", 1); strncat(rp_hist_buf, parsed_input[x], MAXARGSZ); } @@ -1169,7 +1363,8 @@ int rotctl_parse(ROT *my_rot, FILE *fin, FILE *fout, char *argv[], int argc) #ifdef HAVE_READLINE_HISTORY - if (rp_hist_buf) { + if (rp_hist_buf) + { add_history(rp_hist_buf); free(rp_hist_buf); rp_hist_buf = (char *)NULL; @@ -1190,6 +1385,7 @@ int rotctl_parse(ROT *my_rot, FILE *fin, FILE *fout, char *argv[], int argc) #endif if (!prompt) + { rig_debug(RIG_DEBUG_TRACE, "rotctl(d): %c '%s' '%s' '%s' '%s'\n", cmd, @@ -1197,12 +1393,14 @@ int rotctl_parse(ROT *my_rot, FILE *fin, FILE *fout, char *argv[], int argc) p2 ? p2 : "", p3 ? p3 : "", p4 ? p4 : ""); + } /* * Extended Response protocol: output received command name and arguments * response. */ - if (interactive && ext_resp && !prompt) { + if (interactive && ext_resp && !prompt) + { char a1[MAXARGSZ + 1]; char a2[MAXARGSZ + 1]; char a3[MAXARGSZ + 1]; @@ -1231,25 +1429,34 @@ int rotctl_parse(ROT *my_rot, FILE *fin, FILE *fout, char *argv[], int argc) pthread_mutex_unlock(&rot_mutex); #endif - if (retcode != RIG_OK) { + if (retcode != RIG_OK) + { /* only for rotctld */ - if (interactive && !prompt) { + if (interactive && !prompt) + { fprintf(fout, NETROTCTL_RET "%d\n", retcode); ext_resp = 0; resp_sep = '\n'; - } else { + } + else + { fprintf(fout, "%s: error = %s\n", cmd_entry->name, rigerror(retcode)); } - } else { + } + else + { /* only for rotctld */ - if (interactive && !prompt) { + if (interactive && !prompt) + { /* netrotctl RIG_OK */ - if (!(cmd_entry->flags & ARG_OUT) && !ext_resp) { + if (!(cmd_entry->flags & ARG_OUT) && !ext_resp) + { fprintf(fout, NETROTCTL_RET "0\n"); } /* Extended Response protocol */ - else if (ext_resp && cmd != 0xf0) { + else if (ext_resp && cmd != 0xf0) + { fprintf(fout, NETROTCTL_RET "0\n"); ext_resp = 0; resp_sep = '\n'; @@ -1277,25 +1484,32 @@ void usage_rot(FILE *fout) fprintf(fout, "Commands (some may not be available for this rotator):\n"); - for (i = 0; test_list[i].cmd != 0; i++) { - fprintf(fout, "%c: %-12s(", isprint(test_list[i].cmd) ? - test_list[i].cmd : '?', test_list[i].name); + for (i = 0; test_list[i].cmd != 0; i++) + { + fprintf(fout, + "%c: %-12s(", + isprint(test_list[i].cmd) ? test_list[i].cmd : '?', + test_list[i].name); nbspaces = 16; - if (test_list[i].arg1 && (test_list[i].flags & ARG_IN1)) { + if (test_list[i].arg1 && (test_list[i].flags & ARG_IN1)) + { nbspaces -= fprintf(fout, "%s", test_list[i].arg1); } - if (test_list[i].arg2 && (test_list[i].flags & ARG_IN2)) { + if (test_list[i].arg2 && (test_list[i].flags & ARG_IN2)) + { nbspaces -= fprintf(fout, ", %s", test_list[i].arg2); } - if (test_list[i].arg3 && (test_list[i].flags & ARG_IN3)) { + if (test_list[i].arg3 && (test_list[i].flags & ARG_IN3)) + { nbspaces -= fprintf(fout, ", %s", test_list[i].arg3); } - if (test_list[i].arg4 && (test_list[i].flags & ARG_IN4)) { + if (test_list[i].arg4 && (test_list[i].flags & ARG_IN4)) + { nbspaces -= fprintf(fout, ", %s", test_list[i].arg4); } @@ -1324,7 +1538,8 @@ int print_conf_list(const struct confparams *cfp, rig_ptr_t data) cfp->dflt, buf); - switch (cfp->type) { + switch (cfp->type) + { case RIG_CONF_NUMERIC: printf("\tRange: %.1f..%.1f, step %.1f\n", cfp->u.n.min, @@ -1333,13 +1548,15 @@ int print_conf_list(const struct confparams *cfp, rig_ptr_t data) break; case RIG_CONF_COMBO: - if (!cfp->u.c.combostr[0]) { + if (!cfp->u.c.combostr[0]) + { break; } printf("\tCombo: %s", cfp->u.c.combostr[0]); - for (i = 1 ; i < RIG_COMBO_MAX && cfp->u.c.combostr[i]; i++) { + for (i = 1 ; i < RIG_COMBO_MAX && cfp->u.c.combostr[i]; i++) + { printf(", %s", cfp->u.c.combostr[i]); } @@ -1369,7 +1586,8 @@ void print_model_list() { struct mod_lst *s; - for (s = models; s != NULL; s = (struct mod_lst *)(s->hh.next)) { + for (s = models; s != NULL; s = (struct mod_lst *)(s->hh.next)) + { printf("%6d %-23s%-24s%-16s%s\n", s->id, s->mfg_name, @@ -1389,7 +1607,8 @@ void list_models() printf(" Rig # Mfg Model Version Status\n"); status = rot_list_foreach(hash_model_list, NULL); - if (status != RIG_OK) { + if (status != RIG_OK) + { printf("rot_list_foreach: error = %s \n", rigerror(status)); exit(2); } @@ -1407,24 +1626,28 @@ int set_conf(ROT *my_rot, char *conf_parms) p = conf_parms; - while (p && *p != '\0') { + while (p && *p != '\0') + { /* FIXME: left hand value of = cannot be null */ q = strchr(p, '='); - if (!q) { + if (!q) + { return RIG_EINVAL; } *q++ = '\0'; n = strchr(q, ','); - if (n) { + if (n) + { *n++ = '\0'; } ret = rot_set_conf(my_rot, rot_token_lookup(my_rot, p), q); - if (ret != RIG_OK) { + if (ret != RIG_OK) + { return ret; } @@ -1461,17 +1684,20 @@ declare_proto_rot(get_position) status = rot_get_position(rot, &az, &el); - if (status != RIG_OK) { + if (status != RIG_OK) + { return status; } - if ((interactive && prompt) || (interactive && !prompt && ext_resp)) { + if ((interactive && prompt) || (interactive && !prompt && ext_resp)) + { fprintf(fout, "%s: ", cmd->arg1); } fprintf(fout, "%f%c", az, resp_sep); - if ((interactive && prompt) || (interactive && !prompt && ext_resp)) { + if ((interactive && prompt) || (interactive && !prompt && ext_resp)) + { fprintf(fout, "%s: ", cmd->arg2); } @@ -1512,7 +1738,8 @@ declare_proto_rot(get_info) s = rot_get_info(rot); - if ((interactive && prompt) || (interactive && !prompt && ext_resp)) { + if ((interactive && prompt) || (interactive && !prompt && ext_resp)) + { fprintf(fout, "%s: ", cmd->arg1); } @@ -1528,15 +1755,24 @@ declare_proto_rot(move) int direction; int speed; - if (!strcmp(arg1, "LEFT") || !strcmp(arg1, "CCW")) { + if (!strcmp(arg1, "LEFT") || !strcmp(arg1, "CCW")) + { direction = ROT_MOVE_LEFT; - } else if (!strcmp(arg1, "RIGHT") || !strcmp(arg1, "CW")) { + } + else if (!strcmp(arg1, "RIGHT") || !strcmp(arg1, "CW")) + { direction = ROT_MOVE_RIGHT; - } else if (!strcmp(arg1, "UP")) { + } + else if (!strcmp(arg1, "UP")) + { direction = ROT_MOVE_UP; - } else if (!strcmp(arg1, "DOWN")) { + } + else if (!strcmp(arg1, "DOWN")) + { direction = ROT_MOVE_DOWN; - } else { + } + else + { CHKSCN1ARG(sscanf(arg1, "%d", &direction)); } @@ -1552,7 +1788,8 @@ declare_proto_rot(inter_set_conf) CHKSCN1ARG(sscanf(arg1, "%ld", &token)); - if (!arg2 || arg2[0] == '\0') { + if (!arg2 || arg2[0] == '\0') + { return -RIG_EINVAL; } @@ -1581,37 +1818,43 @@ declare_proto_rot(dump_state) */ #define ROTCTLD_PROT_VER 0 - if ((interactive && prompt) || (interactive && !prompt && ext_resp)) { + if ((interactive && prompt) || (interactive && !prompt && ext_resp)) + { fprintf(fout, "rotctld Protocol Ver: "); } fprintf(fout, "%d%c", ROTCTLD_PROT_VER, resp_sep); - if ((interactive && prompt) || (interactive && !prompt && ext_resp)) { + if ((interactive && prompt) || (interactive && !prompt && ext_resp)) + { fprintf(fout, "Rotor Model: "); } fprintf(fout, "%d%c", rot->caps->rot_model, resp_sep); - if ((interactive && prompt) || (interactive && !prompt && ext_resp)) { + if ((interactive && prompt) || (interactive && !prompt && ext_resp)) + { fprintf(fout, "Minimum Azimuth: "); } fprintf(fout, "%lf%c", rs->min_az, resp_sep); - if ((interactive && prompt) || (interactive && !prompt && ext_resp)) { + if ((interactive && prompt) || (interactive && !prompt && ext_resp)) + { fprintf(fout, "Maximum Azimuth: "); } fprintf(fout, "%lf%c", rs->max_az, resp_sep); - if ((interactive && prompt) || (interactive && !prompt && ext_resp)) { + if ((interactive && prompt) || (interactive && !prompt && ext_resp)) + { fprintf(fout, "Minimum Elevation: "); } fprintf(fout, "%lf%c", rs->min_el, resp_sep); - if ((interactive && prompt) || (interactive && !prompt && ext_resp)) { + if ((interactive && prompt) || (interactive && !prompt && ext_resp)) + { fprintf(fout, "Maximum Elevation: "); } @@ -1644,11 +1887,13 @@ declare_proto_rot(send_cmd) */ backend_num = ROT_BACKEND_NUM(rot->caps->rot_model); - if (send_cmd_term == -1 || backend_num == -1) { + if (send_cmd_term == -1 || backend_num == -1) + { const char *p = arg1, *pp = NULL; int i; - for (i = 0; i < BUFSZ - 1 && p != pp; i++) { + for (i = 0; i < BUFSZ - 1 && p != pp; i++) + { pp = p + 1; bufcmd[i] = strtol(p + 1, (char **) &p, 0); } @@ -1658,7 +1903,9 @@ declare_proto_rot(send_cmd) /* no End Of Message chars */ eom_buf[0] = '\0'; - } else { + } + else + { /* text protocol */ strncpy(bufcmd, arg1, BUFSZ); bufcmd[BUFSZ - 2] = '\0'; @@ -1666,7 +1913,8 @@ declare_proto_rot(send_cmd) cmd_len = strlen(bufcmd); /* Automatic termination char */ - if (send_cmd_term != 0) { + if (send_cmd_term != 0) + { bufcmd[cmd_len++] = send_cmd_term; } @@ -1679,36 +1927,45 @@ declare_proto_rot(send_cmd) retval = write_block(&rs->rotport, bufcmd, cmd_len); - if (retval != RIG_OK) { + if (retval != RIG_OK) + { return retval; } - if (interactive && prompt) { + if (interactive && prompt) + { fprintf(fout, "%s: ", cmd->arg2); } - do { + do + { /* * 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)); - if (retval < 0) { + if (retval < 0) + { break; } - if (retval < BUFSZ) { + if (retval < BUFSZ) + { buf[retval] = '\0'; - } else { + } + else + { buf[BUFSZ - 1] = '\0'; } fprintf(fout, "%s\n", buf); - } while (retval > 0); + } + while (retval > 0); - if (retval > 0 || retval == -RIG_ETIMEOUT) { + if (retval > 0 || retval == -RIG_ETIMEOUT) + { retval = RIG_OK; } @@ -1731,11 +1988,13 @@ declare_proto_rot(lonlat2loc) err = longlat2locator(lon, lat, (char *)&loc, pair); - if (err != RIG_OK) { + if (err != RIG_OK) + { return err; } - if ((interactive && prompt) || (interactive && !prompt && ext_resp)) { + if ((interactive && prompt) || (interactive && !prompt && ext_resp)) + { fprintf(fout, "%s: ", cmd->arg4); } @@ -1756,17 +2015,20 @@ declare_proto_rot(loc2lonlat) status = locator2longlat(&lon, &lat, (const char *)loc); - if (status != RIG_OK) { + if (status != RIG_OK) + { return status; } - if ((interactive && prompt) || (interactive && !prompt && ext_resp)) { + if ((interactive && prompt) || (interactive && !prompt && ext_resp)) + { fprintf(fout, "%s: ", cmd->arg2); } fprintf(fout, "%f%c", lon, resp_sep); - if ((interactive && prompt) || (interactive && !prompt && ext_resp)) { + if ((interactive && prompt) || (interactive && !prompt && ext_resp)) + { fprintf(fout, "%s: ", cmd->arg3); } @@ -1789,7 +2051,8 @@ declare_proto_rot(d_m_s2dec) dec_deg = dms2dec(deg, min, sec, sw); - if ((interactive && prompt) || (interactive && !prompt && ext_resp)) { + if ((interactive && prompt) || (interactive && !prompt && ext_resp)) + { fprintf(fout, "%s: ", cmd->arg5); } @@ -1809,29 +2072,34 @@ declare_proto_rot(dec2d_m_s) err = dec2dms(dec_deg, °, &min, &sec, &sw); - if (err != RIG_OK) { + if (err != RIG_OK) + { return err; } - if ((interactive && prompt) || (interactive && !prompt && ext_resp)) { + if ((interactive && prompt) || (interactive && !prompt && ext_resp)) + { fprintf(fout, "%s: ", cmd->arg2); } fprintf(fout, "%d%c", deg, resp_sep); - if ((interactive && prompt) || (interactive && !prompt && ext_resp)) { + if ((interactive && prompt) || (interactive && !prompt && ext_resp)) + { fprintf(fout, "%s: ", cmd->arg3); } fprintf(fout, "%d%c", min, resp_sep); - if ((interactive && prompt) || (interactive && !prompt && ext_resp)) { + if ((interactive && prompt) || (interactive && !prompt && ext_resp)) + { fprintf(fout, "%s: ", cmd->arg4); } fprintf(fout, "%lf%c", sec, resp_sep); - if ((interactive && prompt) || (interactive && !prompt && ext_resp)) { + if ((interactive && prompt) || (interactive && !prompt && ext_resp)) + { fprintf(fout, "%s: ", cmd->arg5); } @@ -1853,7 +2121,8 @@ declare_proto_rot(d_mm2dec) dec_deg = dmmm2dec(deg, min, sw); - if ((interactive && prompt) || (interactive && !prompt && ext_resp)) { + if ((interactive && prompt) || (interactive && !prompt && ext_resp)) + { fprintf(fout, "%s: ", cmd->arg4); } @@ -1873,23 +2142,27 @@ declare_proto_rot(dec2d_mm) err = dec2dmmm(dec_deg, °, &min, &sw); - if (err != RIG_OK) { + if (err != RIG_OK) + { return err; } - if ((interactive && prompt) || (interactive && !prompt && ext_resp)) { + if ((interactive && prompt) || (interactive && !prompt && ext_resp)) + { fprintf(fout, "%s: ", cmd->arg2); } fprintf(fout, "%d%c", deg, resp_sep); - if ((interactive && prompt) || (interactive && !prompt && ext_resp)) { + if ((interactive && prompt) || (interactive && !prompt && ext_resp)) + { fprintf(fout, "%s: ", cmd->arg3); } fprintf(fout, "%lf%c", min, resp_sep); - if ((interactive && prompt) || (interactive && !prompt && ext_resp)) { + if ((interactive && prompt) || (interactive && !prompt && ext_resp)) + { fprintf(fout, "%s: ", cmd->arg4); } @@ -1912,17 +2185,20 @@ declare_proto_rot(coord2qrb) err = qrb(lon1, lat1, lon2, lat2, &dist, &az); - if (err != RIG_OK) { + if (err != RIG_OK) + { return err; } - if ((interactive && prompt) || (interactive && !prompt && ext_resp)) { + if ((interactive && prompt) || (interactive && !prompt && ext_resp)) + { fprintf(fout, "%s: ", cmd->arg5); } fprintf(fout, "%lf%c", dist, resp_sep); - if ((interactive && prompt) || (interactive && !prompt && ext_resp)) { + if ((interactive && prompt) || (interactive && !prompt && ext_resp)) + { fprintf(fout, "%s: ", cmd->arg6); } @@ -1941,11 +2217,13 @@ declare_proto_rot(az_sp2az_lp) az_lp = azimuth_long_path(az_sp); - if (az_lp < 0) { + if (az_lp < 0) + { return -RIG_EINVAL; } - if ((interactive && prompt) || (interactive && !prompt && ext_resp)) { + if ((interactive && prompt) || (interactive && !prompt && ext_resp)) + { fprintf(fout, "%s: ", cmd->arg2); } @@ -1964,7 +2242,8 @@ declare_proto_rot(dist_sp2dist_lp) dist_lp = distance_long_path(dist_sp); - if ((interactive && prompt) || (interactive && !prompt && ext_resp)) { + if ((interactive && prompt) || (interactive && !prompt && ext_resp)) + { fprintf(fout, "%s: ", cmd->arg2); } diff --git a/tests/rotctld.c b/tests/rotctld.c index a12c4f0a0..763f76d90 100644 --- a/tests/rotctld.c +++ b/tests/rotctld.c @@ -66,7 +66,8 @@ #include "rotctl_parse.h" -struct handle_data { +struct handle_data +{ ROT *rot; int sock; struct sockaddr_storage cli_addr; @@ -84,7 +85,8 @@ 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'}, @@ -129,11 +131,14 @@ static void handle_error(enum rig_debug_level_e lvl, const char *msg) MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT), (LPTSTR)&lpMsgBuf, 0, - NULL)) { + NULL)) + { rig_debug(lvl, "%s: Network error %d: %s\n", msg, e, lpMsgBuf); LocalFree(lpMsgBuf); - } else { + } + else + { rig_debug(lvl, "%s: Network error %d\n", msg, e); } @@ -171,17 +176,20 @@ int main(int argc, char *argv[]) #endif struct handle_data *arg; - while (1) { + while (1) + { int c; int option_index = 0; c = getopt_long(argc, argv, SHORT_OPTIONS, long_options, &option_index); - if (c == -1) { + if (c == -1) + { break; } - switch (c) { + switch (c) + { case 'h': usage(); exit(0); @@ -191,7 +199,8 @@ int main(int argc, char *argv[]) exit(0); case 'm': - if (!optarg) { + if (!optarg) + { usage(); /* wrong arg count */ exit(1); } @@ -200,7 +209,8 @@ int main(int argc, char *argv[]) break; case 'r': - if (!optarg) { + if (!optarg) + { usage(); /* wrong arg count */ exit(1); } @@ -209,7 +219,8 @@ int main(int argc, char *argv[]) break; case 's': - if (!optarg) { + if (!optarg) + { usage(); /* wrong arg count */ exit(1); } @@ -218,12 +229,14 @@ int main(int argc, char *argv[]) break; case 'C': - if (!optarg) { + if (!optarg) + { usage(); /* wrong arg count */ exit(1); } - if (*conf_parms != '\0') { + if (*conf_parms != '\0') + { strcat(conf_parms, ","); } @@ -231,7 +244,8 @@ int main(int argc, char *argv[]) break; case 't': - if (!optarg) { + if (!optarg) + { usage(); /* wrong arg count */ exit(1); } @@ -240,7 +254,8 @@ int main(int argc, char *argv[]) break; case 'T': - if (!optarg) { + if (!optarg) + { usage(); /* wrong arg count */ exit(1); } @@ -278,7 +293,8 @@ int main(int argc, char *argv[]) my_rot = rot_init(my_model); - if (!my_rot) { + if (!my_rot) + { fprintf(stderr, "Unknown rot num %d, or initialization error.\n", my_model); @@ -289,24 +305,28 @@ int main(int argc, char *argv[]) retcode = set_conf(my_rot, conf_parms); - if (retcode != RIG_OK) { + if (retcode != RIG_OK) + { fprintf(stderr, "Config parameter error: %s\n", rigerror(retcode)); exit(2); } - if (rot_file) { + if (rot_file) + { strncpy(my_rot->state.rotport.pathname, rot_file, FILPATHLEN - 1); } /* FIXME: bound checking and port type == serial */ - if (serial_rate != 0) { + if (serial_rate != 0) + { my_rot->state.rotport.parm.serial.rate = serial_rate; } /* * print out conf parameters */ - if (show_conf) { + if (show_conf) + { rot_token_foreach(my_rot, print_conf_list, (rig_ptr_t)my_rot); } @@ -314,7 +334,8 @@ int main(int argc, char *argv[]) * Print out conf parameters, and exits immediately as we may be * interested only in only caps, and rig_open may fail. */ - if (dump_caps_opt) { + if (dump_caps_opt) + { dumpcaps_rot(my_rot, stdout); rot_cleanup(my_rot); /* if you care about memory */ exit(0); @@ -322,12 +343,14 @@ int main(int argc, char *argv[]) retcode = rot_open(my_rot); - if (retcode != RIG_OK) { + if (retcode != RIG_OK) + { fprintf(stderr, "rot_open: error = %s \n", rigerror(retcode)); exit(2); } - if (verbose > 0) { + if (verbose > 0) + { printf("Opened rot model %d, '%s'\n", my_rot->caps->rot_model, my_rot->caps->model_name); @@ -339,19 +362,20 @@ int main(int argc, char *argv[]) rig_strstatus(my_rot->caps->status)); #ifdef __MINGW32__ -# ifndef SO_OPENTYPE -# define SO_OPENTYPE 0x7008 -# endif -# ifndef SO_SYNCHRONOUS_NONALERT -# define SO_SYNCHRONOUS_NONALERT 0x20 -# endif -# ifndef INVALID_SOCKET -# define INVALID_SOCKET -1 -# endif +# ifndef SO_OPENTYPE +# define SO_OPENTYPE 0x7008 +# endif +# ifndef SO_SYNCHRONOUS_NONALERT +# define SO_SYNCHRONOUS_NONALERT 0x20 +# endif +# ifndef INVALID_SOCKET +# define INVALID_SOCKET -1 +# endif WSADATA wsadata; - if (WSAStartup(MAKEWORD(1, 1), &wsadata) == SOCKET_ERROR) { + if (WSAStartup(MAKEWORD(1, 1), &wsadata) == SOCKET_ERROR) + { fprintf(stderr, "WSAStartup socket error\n"); exit(1); } @@ -375,26 +399,30 @@ int main(int argc, char *argv[]) retcode = getaddrinfo(src_addr, portno, &hints, &result); - if (retcode != 0) { + if (retcode != 0) + { fprintf(stderr, "getaddrinfo: %s\n", gai_strerror(retcode)); exit(2); } saved_result = result; - do { + do + { sock_listen = socket(result->ai_family, result->ai_socktype, result->ai_protocol); - if (sock_listen < 0) { + if (sock_listen < 0) + { handle_error(RIG_DEBUG_ERR, "socket"); freeaddrinfo(result); /* No longer needed */ exit(1); } if (setsockopt(sock_listen, SOL_SOCKET, SO_REUSEADDR, - (char *)&reuseaddr, sizeof(reuseaddr)) < 0) { + (char *)&reuseaddr, sizeof(reuseaddr)) < 0) + { handle_error(RIG_DEBUG_ERR, "setsockopt"); freeaddrinfo(result); /* No longer needed */ @@ -403,7 +431,8 @@ int main(int argc, char *argv[]) #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 to 1 i.e. disallowed */ sockopt = 0; @@ -413,7 +442,8 @@ int main(int argc, char *argv[]) IPV6_V6ONLY, (char *)&sockopt, sizeof(sockopt)) - < 0) { + < 0) + { handle_error(RIG_DEBUG_ERR, "setsockopt"); freeaddrinfo(saved_result); /* No longer needed */ @@ -423,7 +453,8 @@ int main(int argc, char *argv[]) #endif - if (0 == bind(sock_listen, result->ai_addr, result->ai_addrlen)) { + if (0 == bind(sock_listen, result->ai_addr, result->ai_addrlen)) + { break; } @@ -433,16 +464,19 @@ int main(int argc, char *argv[]) #else close(sock_listen); #endif - } while ((result = result->ai_next) != NULL); + } + while ((result = result->ai_next) != NULL); freeaddrinfo(saved_result); /* No longer needed */ - if (NULL == result) { + if (NULL == result) + { rig_debug(RIG_DEBUG_ERR, "bind error - no available interface\n"); exit(1); } - if (listen(sock_listen, 4) < 0) { + if (listen(sock_listen, 4) < 0) + { handle_error(RIG_DEBUG_ERR, "listening"); exit(1); } @@ -457,25 +491,30 @@ int main(int argc, char *argv[]) act.sa_handler = SIG_IGN; act.sa_flags = SA_RESTART; - if (sigaction(SIGPIPE, &act, NULL)) { + if (sigaction(SIGPIPE, &act, NULL)) + { handle_error(RIG_DEBUG_ERR, "sigaction"); } #elif HAVE_SIGNAL - if (SIG_ERR == signal(SIGPIPE, SIG_IGN)) { + if (SIG_ERR == signal(SIGPIPE, SIG_IGN)) + { handle_error(RIG_DEBUG_ERR, "signal"); } + #endif #endif /* * main loop accepting connections */ - do { + do + { arg = malloc(sizeof(struct handle_data)); - if (!arg) { + if (!arg) + { rig_debug(RIG_DEBUG_ERR, "malloc: %s\n", strerror(errno)); exit(1); } @@ -486,7 +525,8 @@ int main(int argc, char *argv[]) (struct sockaddr *) &arg->cli_addr, &arg->clilen); - if (arg->sock < 0) { + if (arg->sock < 0) + { handle_error(RIG_DEBUG_ERR, "accept"); break; } @@ -498,7 +538,8 @@ int main(int argc, char *argv[]) serv, sizeof(serv), NI_NOFQDN)) - < 0) { + < 0) + { rig_debug(RIG_DEBUG_WARN, "Peer lookup error: %s", @@ -516,7 +557,8 @@ int main(int argc, char *argv[]) retcode = pthread_create(&thread, &attr, handle_socket, arg); - if (retcode != 0) { + if (retcode != 0) + { rig_debug(RIG_DEBUG_ERR, "pthread_create: %s\n", strerror(retcode)); break; } @@ -524,7 +566,8 @@ int main(int argc, char *argv[]) #else handle_socket(arg); #endif - } while (retcode == 0); + } + while (retcode == 0); rot_close(my_rot); /* close port */ rot_cleanup(my_rot); /* if you care about memory */ @@ -552,7 +595,8 @@ void * handle_socket(void *arg) #ifdef __MINGW32__ int sock_osfhandle = _open_osfhandle(handle_data_arg->sock, _O_RDONLY); - if (sock_osfhandle == -1) { + if (sock_osfhandle == -1) + { rig_debug(RIG_DEBUG_ERR, "_open_osfhandle error: %s\n", strerror(errno)); goto handle_exit; } @@ -562,7 +606,8 @@ void * handle_socket(void *arg) fsockin = fdopen(handle_data_arg->sock, "rb"); #endif - if (!fsockin) { + if (!fsockin) + { rig_debug(RIG_DEBUG_ERR, "fdopen in: %s\n", strerror(errno)); goto handle_exit; } @@ -573,19 +618,23 @@ void * handle_socket(void *arg) fsockout = fdopen(handle_data_arg->sock, "wb"); #endif - if (!fsockout) { + if (!fsockout) + { rig_debug(RIG_DEBUG_ERR, "fdopen out: %s\n", strerror(errno)); fclose(fsockin); goto handle_exit; } - do { + do + { retcode = rotctl_parse(handle_data_arg->rot, fsockin, fsockout, NULL, 0); - if (ferror(fsockin) || ferror(fsockout)) { + if (ferror(fsockin) || ferror(fsockout)) + { retcode = 1; } - } while (retcode == 0 || retcode == 2); + } + while (retcode == 0 || retcode == 2); if ((retcode = getnameinfo((struct sockaddr const *)&handle_data_arg->cli_addr, handle_data_arg->clilen, @@ -594,7 +643,8 @@ void * handle_socket(void *arg) serv, sizeof(serv), NI_NOFQDN)) - < 0) { + < 0) + { rig_debug(RIG_DEBUG_WARN, "Peer lookup error: %s", @@ -632,18 +682,18 @@ void usage() "Daemon serving COMMANDs to a connected antenna rotator.\n\n"); printf( - " -m, --model=ID select rotator model number. See model list\n" - " -r, --rot-file=DEVICE set device of the rotator to operate on\n" - " -s, --serial-speed=BAUD set serial speed of the serial port\n" - " -t, --port=NUM set TCP listening port, default %s\n" - " -T, --listen-addr=IPADDR set listening IP address, default ANY\n" - " -C, --set-conf=PARM=VAL set config parameters\n" - " -L, --show-conf list all config parameters\n" - " -l, --list list all model numbers and exit\n" - " -u, --dump-caps dump capabilities and exit\n" - " -v, --verbose set verbose mode, cumulative\n" - " -h, --help display this help and exit\n" - " -V, --version output version information and exit\n\n", + " -m, --model=ID select rotator model number. See model list\n" + " -r, --rot-file=DEVICE set device of the rotator to operate on\n" + " -s, --serial-speed=BAUD set serial speed of the serial port\n" + " -t, --port=NUM set TCP listening port, default %s\n" + " -T, --listen-addr=IPADDR set listening IP address, default ANY\n" + " -C, --set-conf=PARM=VAL set config parameters\n" + " -L, --show-conf list all config parameters\n" + " -l, --list list all model numbers and exit\n" + " -u, --dump-caps dump capabilities and exit\n" + " -v, --verbose set verbose mode, cumulative\n" + " -h, --help display this help and exit\n" + " -V, --version output version information and exit\n\n", portno); usage_rot(stdout); diff --git a/tests/sprintflst.c b/tests/sprintflst.c index 5b7687106..fdec2c739 100644 --- a/tests/sprintflst.c +++ b/tests/sprintflst.c @@ -47,44 +47,52 @@ int sprintf_vfo(char *str, vfo_t vfo) *str = '\0'; - if (vfo == RIG_VFO_NONE) { + if (vfo == RIG_VFO_NONE) + { return 0; } sv = rig_strvfo(vfo & RIG_VFO_CURR); - if (sv && sv[0]) { + if (sv && sv[0]) + { len += sprintf(str + len, "%s ", sv); } sv = rig_strvfo(vfo & RIG_VFO_MEM); - if (sv && sv[0]) { + if (sv && sv[0]) + { len += sprintf(str + len, "%s ", sv); } sv = rig_strvfo(vfo & RIG_VFO_VFO); - if (sv && sv[0]) { + if (sv && sv[0]) + { len += sprintf(str + len, "%s ", sv); } sv = rig_strvfo(vfo & RIG_VFO_MAIN); - if (sv && sv[0]) { + if (sv && sv[0]) + { len += sprintf(str + len, "%s ", sv); } sv = rig_strvfo(vfo & RIG_VFO_SUB); - if (sv && sv[0]) { + if (sv && sv[0]) + { len += sprintf(str + len, "%s ", sv); } - for (i = 0; i < 16; i++) { + for (i = 0; i < 16; i++) + { sv = rig_strvfo(vfo & RIG_VFO_N(i)); - if (sv && sv[0]) { + if (sv && sv[0]) + { len += sprintf(str + len, "%s ", sv); } } @@ -99,14 +107,17 @@ int sprintf_mode(char *str, rmode_t mode) *str = '\0'; - if (mode == RIG_MODE_NONE) { + if (mode == RIG_MODE_NONE) + { return 0; } - for (i = 0; i < 30; i++) { + for (i = 0; i < 30; i++) + { const char *ms = rig_strrmode(mode & (1UL << i)); - if (!ms || !ms[0]) { + if (!ms || !ms[0]) + { continue; /* unknown, FIXME! */ } @@ -125,14 +136,17 @@ int sprintf_func(char *str, setting_t func) *str = '\0'; - if (func == RIG_FUNC_NONE) { + if (func == RIG_FUNC_NONE) + { return 0; } - for (i = 0; i < RIG_SETTING_MAX; i++) { + for (i = 0; i < RIG_SETTING_MAX; i++) + { const char *ms = rig_strfunc(func & rig_idx2setting(i)); - if (!ms || !ms[0]) { + if (!ms || !ms[0]) + { continue; /* unknown, FIXME! */ } @@ -151,14 +165,17 @@ int sprintf_level(char *str, setting_t level) *str = '\0'; - if (level == RIG_LEVEL_NONE) { + if (level == RIG_LEVEL_NONE) + { return 0; } - for (i = 0; i < RIG_SETTING_MAX; i++) { + for (i = 0; i < RIG_SETTING_MAX; i++) + { const char *ms = rig_strlevel(level & rig_idx2setting(i)); - if (!ms || !ms[0]) { + if (!ms || !ms[0]) + { continue; /* unknown, FIXME! */ } @@ -177,16 +194,20 @@ int sprintf_level_ext(char *str, const struct confparams *extlevels) *str = '\0'; - if (!extlevels) { + if (!extlevels) + { return 0; } - for (; extlevels->token != RIG_CONF_END; extlevels++) { - if (!extlevels->name) { + for (; extlevels->token != RIG_CONF_END; extlevels++) + { + if (!extlevels->name) + { continue; /* no name */ } - switch (extlevels->type) { + switch (extlevels->type) + { case RIG_CONF_CHECKBUTTON: case RIG_CONF_COMBO: case RIG_CONF_NUMERIC: @@ -212,35 +233,43 @@ int sprintf_level_gran(char *str, setting_t level, const gran_t gran[]) *str = '\0'; - if (level == RIG_LEVEL_NONE) { + if (level == RIG_LEVEL_NONE) + { return 0; } - for (i = 0; i < RIG_SETTING_MAX; i++) { + for (i = 0; i < RIG_SETTING_MAX; i++) + { const char *ms; - if (!(level & rig_idx2setting(i))) { + if (!(level & rig_idx2setting(i))) + { continue; } ms = rig_strlevel(level & rig_idx2setting(i)); - if (!ms || !ms[0]) { - if (level != DUMMY_ALL && level != RIG_LEVEL_SET(DUMMY_ALL)) { + if (!ms || !ms[0]) + { + if (level != DUMMY_ALL && level != RIG_LEVEL_SET(DUMMY_ALL)) + { rig_debug(RIG_DEBUG_BUG, "unknown level idx %d\n", i); } continue; } - if (RIG_LEVEL_IS_FLOAT(rig_idx2setting(i))) { + if (RIG_LEVEL_IS_FLOAT(rig_idx2setting(i))) + { len += sprintf(str + len, "%s(%g..%g/%g) ", ms, gran[i].min.f, gran[i].max.f, gran[i].step.f); - } else { + } + else + { len += sprintf(str + len, "%s(%d..%d/%d) ", ms, @@ -260,14 +289,17 @@ int sprintf_parm(char *str, setting_t parm) *str = '\0'; - if (parm == RIG_PARM_NONE) { + if (parm == RIG_PARM_NONE) + { return 0; } - for (i = 0; i < RIG_SETTING_MAX; i++) { + for (i = 0; i < RIG_SETTING_MAX; i++) + { const char *ms = rig_strparm(parm & rig_idx2setting(i)); - if (!ms || !ms[0]) { + if (!ms || !ms[0]) + { continue; /* unknown, FIXME! */ } @@ -286,35 +318,43 @@ int sprintf_parm_gran(char *str, setting_t parm, const gran_t gran[]) *str = '\0'; - if (parm == RIG_PARM_NONE) { + if (parm == RIG_PARM_NONE) + { return 0; } - for (i = 0; i < RIG_SETTING_MAX; i++) { + for (i = 0; i < RIG_SETTING_MAX; i++) + { const char *ms; - if (!(parm & rig_idx2setting(i))) { + if (!(parm & rig_idx2setting(i))) + { continue; } ms = rig_strparm(parm & rig_idx2setting(i)); - if (!ms || !ms[0]) { - if (parm != DUMMY_ALL && parm != RIG_PARM_SET(DUMMY_ALL)) { + if (!ms || !ms[0]) + { + if (parm != DUMMY_ALL && parm != RIG_PARM_SET(DUMMY_ALL)) + { rig_debug(RIG_DEBUG_BUG, "unknown parm idx %d\n", i); } continue; } - if (RIG_PARM_IS_FLOAT(rig_idx2setting(i))) { + if (RIG_PARM_IS_FLOAT(rig_idx2setting(i))) + { len += sprintf(str + len, "%s(%g..%g/%g) ", ms, gran[i].min.f, gran[i].max.f, gran[i].step.f); - } else { + } + else + { len += sprintf(str + len, "%s(%d..%d/%d) ", ms, @@ -334,14 +374,17 @@ int sprintf_vfop(char *str, vfo_op_t op) *str = '\0'; - if (op == RIG_OP_NONE) { + if (op == RIG_OP_NONE) + { return 0; } - for (i = 0; i < 30; i++) { + for (i = 0; i < 30; i++) + { const char *ms = rig_strvfop(op & (1UL << i)); - if (!ms || !ms[0]) { + if (!ms || !ms[0]) + { continue; /* unknown, FIXME! */ } @@ -360,14 +403,17 @@ int sprintf_scan(char *str, scan_t rscan) *str = '\0'; - if (rscan == RIG_SCAN_NONE) { + if (rscan == RIG_SCAN_NONE) + { return 0; } - for (i = 0; i < 30; i++) { + for (i = 0; i < 30; i++) + { const char *ms = rig_strscan(rscan & (1UL << i)); - if (!ms || !ms[0]) { + if (!ms || !ms[0]) + { continue; /* unknown, FIXME! */ } diff --git a/tests/testbcd.c b/tests/testbcd.c index f2268f856..1443ce560 100644 --- a/tests/testbcd.c +++ b/tests/testbcd.c @@ -22,17 +22,20 @@ int main(int argc, char *argv[]) int digits = 10; int i; - if (argc != 2 && argc != 3) { + if (argc != 2 && argc != 3) + { fprintf(stderr, "Usage: %s [digits]\n", argv[0]); exit(1); } f = (freq_t)atoll(argv[1]); - if (argc > 2) { + if (argc > 2) + { digits = atoi(argv[2]); - if (digits > MAXDIGITS) { + if (digits > MAXDIGITS) + { exit(1); } } @@ -42,7 +45,8 @@ int main(int argc, char *argv[]) to_bcd(b, f, digits); printf("BCD: %2.2x", b[0]); - for (i = 1; i < (digits + 1) / 2; i++) { + for (i = 1; i < (digits + 1) / 2; i++) + { printf(",%2.2x", b[i]); } @@ -53,7 +57,8 @@ int main(int argc, char *argv[]) to_bcd_be(b, f, digits); printf("BCD: %2.2x", b[0]); - for (i = 1; i < (digits + 1) / 2; i++) { + for (i = 1; i < (digits + 1) / 2; i++) + { printf(",%2.2x", b[i]); } diff --git a/tests/testfreq.c b/tests/testfreq.c index 2315560d8..d76218437 100644 --- a/tests/testfreq.c +++ b/tests/testfreq.c @@ -20,7 +20,8 @@ int main(int argc, char *argv[]) #if 0 - if (argc != 2) { + if (argc != 2) + { fprintf(stderr, "Usage: %s \n", argv[0]); exit(1); } diff --git a/tests/testloc.c b/tests/testloc.c index 70daa2d67..8eb255c07 100644 --- a/tests/testloc.c +++ b/tests/testloc.c @@ -24,7 +24,8 @@ int main(int argc, char *argv[]) double distance, az, mmm, sec; int deg, min, retcode, loc_len, nesw = 0; - if (argc < 2) { + if (argc < 2) + { fprintf(stderr, "Usage: %s []\n", argv[0]); @@ -40,7 +41,8 @@ int main(int argc, char *argv[]) /* hamlib function to convert maidenhead to decimal degrees */ retcode = locator2longlat(&lon1, &lat1, loc1); - if (retcode != RIG_OK) { + if (retcode != RIG_OK) + { fprintf(stderr, "locator2longlat() failed with malformed input.\n"); exit(2); } @@ -48,14 +50,18 @@ int main(int argc, char *argv[]) /* hamlib function to convert decimal degrees to deg, min, sec */ retcode = dec2dms(lon1, °, &min, &sec, &nesw); - if (retcode != RIG_OK) { + if (retcode != RIG_OK) + { fprintf(stderr, "dec2dms() failed, invalid paramter address.\n"); exit(2); } - if (nesw == 1) { + if (nesw == 1) + { sign = '-'; - } else { + } + else + { sign = '\0'; } @@ -68,14 +74,18 @@ int main(int argc, char *argv[]) /* hamlib function to convert decimal degrees to deg decimal minutes */ retcode = dec2dmmm(lon1, °, &mmm, &nesw); - if (retcode != RIG_OK) { + if (retcode != RIG_OK) + { fprintf(stderr, "dec2dmmm() failed, invalid paramter address.\n"); exit(2); } - if (nesw == 1) { + if (nesw == 1) + { sign = '-'; - } else { + } + else + { sign = '\0'; } @@ -88,14 +98,18 @@ int main(int argc, char *argv[]) /* hamlib function to convert decimal degrees to deg, min, sec */ retcode = dec2dms(lat1, °, &min, &sec, &nesw); - if (retcode != RIG_OK) { + if (retcode != RIG_OK) + { fprintf(stderr, "dec2dms() failed, invalid paramter address.\n"); exit(2); } - if (nesw == 1) { + if (nesw == 1) + { sign = '-'; - } else { + } + else + { sign = '\0'; } @@ -108,14 +122,18 @@ int main(int argc, char *argv[]) /* hamlib function to convert decimal degrees to deg decimal minutes */ retcode = dec2dmmm(lat1, °, &mmm, &nesw); - if (retcode != RIG_OK) { + if (retcode != RIG_OK) + { fprintf(stderr, "dec2dmmm() failed, invalid paramter address.\n"); exit(2); } - if (nesw == 1) { + if (nesw == 1) + { sign = '-'; - } else { + } + else + { sign = '\0'; } @@ -128,14 +146,16 @@ int main(int argc, char *argv[]) /* hamlib function to convert decimal degrees to maidenhead */ retcode = longlat2locator(lon1, lat1, recodedloc, loc_len); - if (retcode != RIG_OK) { + if (retcode != RIG_OK) + { fprintf(stderr, "longlat2locator() failed, precision out of range.\n"); exit(2); } printf(" Recoded:\t%s\n", recodedloc); - if (loc2 == NULL) { + if (loc2 == NULL) + { exit(0); } @@ -144,7 +164,8 @@ int main(int argc, char *argv[]) retcode = locator2longlat(&lon2, &lat2, loc2); - if (retcode != RIG_OK) { + if (retcode != RIG_OK) + { fprintf(stderr, "locator2longlat() failed with malformed input.\n"); exit(2); } @@ -152,14 +173,18 @@ int main(int argc, char *argv[]) /* hamlib function to convert decimal degrees to deg, min, sec */ retcode = dec2dms(lon2, °, &min, &sec, &nesw); - if (retcode != RIG_OK) { + if (retcode != RIG_OK) + { fprintf(stderr, "dec2dms() failed, invalid paramter address.\n"); exit(2); } - if (nesw == 1) { + if (nesw == 1) + { sign = '-'; - } else { + } + else + { sign = '\0'; } @@ -172,14 +197,18 @@ int main(int argc, char *argv[]) /* hamlib function to convert decimal degrees to deg decimal minutes */ retcode = dec2dmmm(lon2, °, &mmm, &nesw); - if (retcode != RIG_OK) { + if (retcode != RIG_OK) + { fprintf(stderr, "dec2dmmm() failed, invalid paramter address.\n"); exit(2); } - if (nesw == 1) { + if (nesw == 1) + { sign = '-'; - } else { + } + else + { sign = '\0'; } @@ -192,14 +221,18 @@ int main(int argc, char *argv[]) /* hamlib function to convert decimal degrees to deg, min, sec */ retcode = dec2dms(lat2, °, &min, &sec, &nesw); - if (retcode != RIG_OK) { + if (retcode != RIG_OK) + { fprintf(stderr, "dec2dms() failed, invalid paramter address.\n"); exit(2); } - if (nesw == 1) { + if (nesw == 1) + { sign = '-'; - } else { + } + else + { sign = '\0'; } @@ -212,14 +245,18 @@ int main(int argc, char *argv[]) /* hamlib function to convert decimal degrees to deg decimal minutes */ retcode = dec2dmmm(lat2, °, &mmm, &nesw); - if (retcode != RIG_OK) { + if (retcode != RIG_OK) + { fprintf(stderr, "dec2dmmm() failed, invalid paramter address.\n"); exit(2); } - if (nesw == 1) { + if (nesw == 1) + { sign = '-'; - } else { + } + else + { sign = '\0'; } @@ -232,7 +269,8 @@ int main(int argc, char *argv[]) /* hamlib function to convert decimal degrees to maidenhead */ retcode = longlat2locator(lon2, lat2, recodedloc, loc_len); - if (retcode != RIG_OK) { + if (retcode != RIG_OK) + { fprintf(stderr, "longlat2locator() failed, precision out of range.\n"); exit(2); } @@ -241,7 +279,8 @@ int main(int argc, char *argv[]) retcode = qrb(lon1, lat1, lon2, lat2, &distance, &az); - if (retcode != RIG_OK) { + if (retcode != RIG_OK) + { fprintf(stderr, "QRB error: %d\n", retcode); exit(2); } @@ -249,9 +288,12 @@ int main(int argc, char *argv[]) dec2dms(az, °, &min, &sec, &nesw); printf("\nDistance: %.6fkm\n", distance); - if (nesw == 1) { + if (nesw == 1) + { sign = '-'; - } else { + } + else + { sign = '\0'; } diff --git a/tests/testrig.c b/tests/testrig.c index 51ffcd9c3..250b7e25a 100644 --- a/tests/testrig.c +++ b/tests/testrig.c @@ -57,7 +57,8 @@ int main(int argc, char *argv[]) * allocate memory, setup & open port */ - if (argc < 2) { + if (argc < 2) + { hamlib_port_t myport; /* may be overriden by backend probe */ myport.type.rig = RIG_PORT_SERIAL; @@ -70,13 +71,16 @@ int main(int argc, char *argv[]) rig_load_all_backends(); myrig_model = rig_probe(&myport); - } else { + } + else + { myrig_model = atoi(argv[1]); } my_rig = rig_init(myrig_model); - if (!my_rig) { + if (!my_rig) + { fprintf(stderr, "Unknown rig num: %d\n", myrig_model); fprintf(stderr, "Please check riglist.h\n"); exit(1); /* whoops! something went wrong (mem alloc?) */ @@ -86,7 +90,8 @@ int main(int argc, char *argv[]) retcode = rig_open(my_rig); - if (retcode != RIG_OK) { + if (retcode != RIG_OK) + { printf("rig_open: error = %s\n", rigerror(retcode)); exit(2); } @@ -107,7 +112,8 @@ int main(int argc, char *argv[]) retcode = rig_set_vfo(my_rig, RIG_VFO_B); - if (retcode != RIG_OK) { + if (retcode != RIG_OK) + { printf("rig_set_vfo: error = %s \n", rigerror(retcode)); } @@ -126,7 +132,8 @@ int main(int argc, char *argv[]) retcode = rig_set_mode(my_rig, RIG_VFO_CURR, RIG_MODE_FM, rig_passband_narrow(my_rig, RIG_MODE_FM)); - if (retcode != RIG_OK) { + if (retcode != RIG_OK) + { printf("rig_set_freq: error = %s \n", rigerror(retcode)); } @@ -150,7 +157,8 @@ int main(int argc, char *argv[]) RIG_MODE_USB, rig_passband_normal(my_rig, RIG_MODE_USB)); - if (retcode != RIG_OK) { + if (retcode != RIG_OK) + { printf("rig_set_freq: error = %s \n", rigerror(retcode)); } @@ -171,7 +179,8 @@ int main(int argc, char *argv[]) RIG_MODE_LSB, RIG_PASSBAND_NORMAL); - if (retcode != RIG_OK) { + if (retcode != RIG_OK) + { printf("rig_set_freq: error = %s \n", rigerror(retcode)); } @@ -179,7 +188,9 @@ int main(int argc, char *argv[]) rig_get_mode(my_rig, RIG_VFO_CURR, &rmode, &width); printf(" Freq: %.6f MHz, Mode: %s, Passband: %.3f kHz\n\n", - freq / 1000000, rig_strrmode(rmode), width / 1000.0); + freq / 1000000, + rig_strrmode(rmode), + width / 1000.0); sleep(1); /* 80m AM Narrow */ @@ -192,7 +203,8 @@ int main(int argc, char *argv[]) RIG_MODE_AM, rig_passband_narrow(my_rig, RIG_MODE_AM)); - if (retcode != RIG_OK) { + if (retcode != RIG_OK) + { printf("rig_set_freq: error = %s \n", rigerror(retcode)); } @@ -201,7 +213,8 @@ int main(int argc, char *argv[]) printf(" Freq: %.6f MHz, Mode: %s, Passband: %.3f kHz\n\n", freq / 1000000, - rig_strrmode(rmode), width / 1000.0); + rig_strrmode(rmode), + width / 1000.0); sleep(1); @@ -215,7 +228,8 @@ int main(int argc, char *argv[]) RIG_MODE_CW, RIG_PASSBAND_NORMAL); - if (retcode != RIG_OK) { + if (retcode != RIG_OK) + { printf("rig_set_freq: error = %s \n", rigerror(retcode)); } @@ -224,7 +238,8 @@ int main(int argc, char *argv[]) printf(" Freq: %.3f kHz, Mode: %s, Passband: %li Hz\n\n", freq / 1000, - rig_strrmode(rmode), width); + rig_strrmode(rmode), + width); sleep(1); @@ -237,7 +252,8 @@ int main(int argc, char *argv[]) RIG_MODE_CW, rig_passband_narrow(my_rig, RIG_MODE_CW)); - if (retcode != RIG_OK) { + if (retcode != RIG_OK) + { printf("rig_set_freq: error = %s \n", rigerror(retcode)); } @@ -246,7 +262,8 @@ int main(int argc, char *argv[]) printf(" Freq: %.3f kHz, Mode: %s, Passband: %li Hz\n\n", freq / 1000, - rig_strrmode(rmode), width); + rig_strrmode(rmode), + width); sleep(1); @@ -260,7 +277,8 @@ int main(int argc, char *argv[]) RIG_MODE_AM, RIG_PASSBAND_NORMAL); - if (retcode != RIG_OK) { + if (retcode != RIG_OK) + { printf("rig_set_freq: error = %s \n", rigerror(retcode)); } @@ -269,7 +287,8 @@ int main(int argc, char *argv[]) printf(" Freq: %.3f kHz, Mode: %s, Passband: %.3f kHz\n\n", freq / 1000, - rig_strrmode(rmode), width / 1000.0); + rig_strrmode(rmode), + width / 1000.0); sleep(1); @@ -280,7 +299,8 @@ int main(int argc, char *argv[]) retcode = rig_set_vfo(my_rig, RIG_VFO_A); retcode = rig_set_freq(my_rig, RIG_VFO_CURR, 14250375); /* cq de vk3fcs */ - if (retcode != RIG_OK) { + if (retcode != RIG_OK) + { printf("rig_set_freq: error = %s \n", rigerror(retcode)); } @@ -296,7 +316,8 @@ int main(int argc, char *argv[]) printf("Setting 20m on VFO A with one function...\n"); retcode = rig_set_freq(my_rig, RIG_VFO_A, 14295125); /* cq de vk3fcs */ - if (retcode != RIG_OK) { + if (retcode != RIG_OK) + { printf("rig_set_freq: error = %s \n", rigerror(retcode)); } @@ -321,7 +342,8 @@ int main(int argc, char *argv[]) RIG_MODE_LSB, RIG_PASSBAND_NORMAL); - if (retcode != RIG_OK) { + if (retcode != RIG_OK) + { printf("rig_set_mode: error = %s \n", rigerror(retcode)); } @@ -330,7 +352,8 @@ int main(int argc, char *argv[]) printf("Setting rig PTT ON.\n"); retcode = rig_set_ptt(my_rig, RIG_VFO_A, RIG_PTT_ON); /* stand back ! */ - if (retcode != RIG_OK) { + if (retcode != RIG_OK) + { printf("rig_set_ptt: error = %s \n", rigerror(retcode)); } @@ -339,7 +362,8 @@ int main(int argc, char *argv[]) printf("Setting rig PTT OFF.\n"); retcode = rig_set_ptt(my_rig, RIG_VFO_A, RIG_PTT_OFF); /* phew ! */ - if (retcode != RIG_OK) { + if (retcode != RIG_OK) + { printf("rig_set_ptt: error = %s \n", rigerror(retcode)); } @@ -353,52 +377,68 @@ int main(int argc, char *argv[]) printf("\nGet various raw rig values:\n"); retcode = rig_get_vfo(my_rig, &vfo); /* try to get vfo info */ - if (retcode == RIG_OK) { + if (retcode == RIG_OK) + { printf("rig_get_vfo: vfo = %i \n", vfo); - } else { + } + else + { printf("rig_get_vfo: error = %s \n", rigerror(retcode)); } retcode = rig_get_freq(my_rig, RIG_VFO_CURR, &freq); - if (retcode == RIG_OK) { + if (retcode == RIG_OK) + { printf("rig_get_freq: freq = %"PRIfreq"\n", freq); - } else { + } + else + { printf("rig_get_freq: error = %s \n", rigerror(retcode)); } retcode = rig_get_mode(my_rig, RIG_VFO_CURR, &rmode, &width); - if (retcode == RIG_OK) { + if (retcode == RIG_OK) + { printf("rig_get_mode: mode = %i \n", rmode); - } else { + } + else + { printf("rig_get_mode: error = %s \n", rigerror(retcode)); } retcode = rig_get_strength(my_rig, RIG_VFO_CURR, &strength); - if (retcode == RIG_OK) { + if (retcode == RIG_OK) + { printf("rig_get_strength: strength = %i \n", strength); - } else { + } + else + { printf("rig_get_strength: error = %s \n", rigerror(retcode)); } - if (rig_has_set_func(my_rig, RIG_FUNC_RIT)) { + if (rig_has_set_func(my_rig, RIG_FUNC_RIT)) + { retcode = rig_set_func(my_rig, RIG_VFO_CURR, RIG_FUNC_RIT, 1); printf("rig_set_func: Setting RIT ON\n"); } - if (rig_has_get_func(my_rig, RIG_FUNC_RIT)) { + if (rig_has_get_func(my_rig, RIG_FUNC_RIT)) + { retcode = rig_get_func(my_rig, RIG_VFO_CURR, RIG_FUNC_RIT, &rit); printf("rig_get_func: RIT: %d\n", rit); } - if (rig_has_set_func(my_rig, RIG_FUNC_XIT)) { + if (rig_has_set_func(my_rig, RIG_FUNC_XIT)) + { retcode = rig_set_func(my_rig, RIG_VFO_CURR, RIG_FUNC_XIT, 1); printf("rig_set_func: Setting XIT ON\n"); } - if (rig_has_get_func(my_rig, RIG_FUNC_XIT)) { + if (rig_has_get_func(my_rig, RIG_FUNC_XIT)) + { retcode = rig_get_func(my_rig, RIG_VFO_CURR, RIG_FUNC_XIT, &xit); printf("rig_get_func: XIT: %d\n", xit); } diff --git a/tests/testtrn.c b/tests/testtrn.c index 097aff0c1..2d8dc9ae0 100644 --- a/tests/testtrn.c +++ b/tests/testtrn.c @@ -50,12 +50,13 @@ int main(int argc, char *argv[]) int retcode; /* generic return code from functions */ int i, count = 0; - if (argc != 2) { + if (argc != 2) + { fprintf(stderr, "%s \n", argv[0]); exit(1); } - printf("testrig:hello, I am your main() !\n"); + printf("testrig: Hello, I am your main() !\n"); /* * allocate memory, setup & open port @@ -63,7 +64,8 @@ int main(int argc, char *argv[]) my_rig = rig_init(atoi(argv[1])); - if (!my_rig) { + if (!my_rig) + { fprintf(stderr, "Unknown rig num: %d\n", atoi(argv[1])); fprintf(stderr, "Please check riglist.h\n"); exit(1); /* whoops! something went wrong (mem alloc?) */ @@ -71,7 +73,8 @@ int main(int argc, char *argv[]) strncpy(my_rig->state.rigport.pathname, SERIAL_PORT, FILPATHLEN - 1); - if (rig_open(my_rig)) { + if (rig_open(my_rig)) + { exit(2); } @@ -85,7 +88,8 @@ int main(int argc, char *argv[]) retcode = rig_set_freq(my_rig, RIG_VFO_CURR, 439700000); - if (retcode != RIG_OK) { + if (retcode != RIG_OK) + { printf("rig_set_freq: error = %s \n", rigerror(retcode)); } @@ -93,12 +97,14 @@ int main(int argc, char *argv[]) retcode = rig_set_trn(my_rig, RIG_TRN_RIG); - if (retcode != RIG_OK) { + if (retcode != RIG_OK) + { printf("rig_set_trn: error = %s \n", rigerror(retcode)); } - for (i = 0; i < 12; i++) { + for (i = 0; i < 12; i++) + { printf("Loop count: %d\n", i); sleep(10); /* or anything smarter */ }