Move unnecessary global and file static variables to the stack

pull/128/head
Bill Somerville 2019-08-25 08:58:19 +01:00
rodzic 97abcdaa81
commit d931bd4e18
Nie znaleziono w bazie danych klucza dla tego podpisu
ID klucza GPG: D864B06D1E81618F
12 zmienionych plików z 98 dodań i 113 usunięć

Wyświetl plik

@ -43,4 +43,6 @@ extern const struct rig_caps netrigctl_caps;
extern const struct rig_caps flrig_caps;
extern const struct rig_caps trxmanager_caps;
int netrigctl_get_vfo_mode(RIG *);
#endif /* _DUMMY_H */

Wyświetl plik

@ -57,28 +57,6 @@
# define __END_DECLS /* empty */
#endif
#ifndef thread_local
# if __STDC_VERSION__ >= 201112 && !defined __STDC_NO_THREADS__
# define thread_local _Thread_local
# elif defined _WIN32 && ( \
defined _MSC_VER || \
defined __ICL || \
defined __DMC__ || \
defined __BORLANDC__ )
# define thread_local __declspec(thread)
/* note that ICC (linux) and Clang are covered by __GNUC__ */
# elif defined __GNUC__ || \
defined __SUNPRO_C || \
defined __xlC__
# define thread_local __thread
# else
# pragma warning "Please see if you can find a thread_local definition for this compiler"
# pragma warning "You can comment out the error after this line but rigctld will not be thread safe for vfo_mode and ext_resp and will require up to 4 rigctld's for the 4 possible combinations of vfo_mode and ext_resp"
# pragma error "Cannot define thread_local"
# define thread_local
# endif
#endif
/* HAMLIB_PARAMS is a macro used to wrap function prototypes, so that compilers
* that don't understand ANSI C prototypes still work, and ANSI C
* compilers can issue warnings about type mismatches. */

Wyświetl plik

@ -25,6 +25,7 @@ rigswr_SOURCES = rigswr.c
rigsmtr_SOURCES = rigsmtr.c
rigmem_SOURCES = rigmem.c memsave.c memload.c memcsv.c sprintflst.c sprintflst.h
rigctl_CPPFLAGS = -I$(top_srcdir) $(AM_CPPFLAGS)
# all the programs need this
LDADD = $(top_builddir)/src/libhamlib.la $(top_builddir)/lib/libmisc.la

Wyświetl plik

@ -71,15 +71,14 @@ extern int read_history();
#include "iofunc.h"
#include "serial.h"
#include "sprintflst.h"
#include "dummy/dummy.h"
#include "rigctl_parse.h"
#define MAXNAMSIZ 32
#define MAXNBOPT 100 /* max number of different options */
void usage(void);
extern int netrigctl_get_vfo_mode(RIG *rig);
static void usage(void);
/*
* Reminder: when adding long options,
@ -114,6 +113,7 @@ static struct option long_options[] =
{"help", 0, 0, 'h'},
{"version", 0, 0, 'V'},
{0, 0, 0, 0}
};
#define MAXCONFLEN 128
@ -124,12 +124,6 @@ static const int have_rl = 1;
#endif
thread_local int interactive = 1; /* if no cmd on command line, switch to interactive */
thread_local int prompt = 1; /* Print prompt in rigctl */
thread_local int vfo_mode = 0; /* vfo_mode = 0 means target VFO is 'currVFO' */
thread_local char send_cmd_term = '\r'; /* send_cmd termination char */
int main(int argc, char *argv[])
{
RIG *my_rig; /* handle to rig (instance) */
@ -157,6 +151,12 @@ int main(int argc, char *argv[])
int serial_rate = 0;
char *civaddr = NULL; /* NULL means no need to set conf */
char conf_parms[MAXCONFLEN] = "";
int interactive = 1; /* if no cmd on command line, switch to interactive */
int prompt = 1; /* Print prompt in rigctl */
int vfo_mode = 0; /* vfo_mode = 0 means target VFO is 'currVFO' */
char send_cmd_term = '\r'; /* send_cmd termination char */
int ext_resp = 0;
char resp_sep = '\n';
while (1)
{
@ -597,7 +597,9 @@ int main(int argc, char *argv[])
do
{
retcode = rigctl_parse(my_rig, stdin, stdout, argv, argc, NULL);
retcode = rigctl_parse(my_rig, stdin, stdout, argv, argc, NULL,
interactive, prompt, vfo_mode, send_cmd_term,
&ext_resp, &resp_sep);
if (retcode == 2)
{

Wyświetl plik

@ -135,6 +135,11 @@ struct test_table
FILE *,
FILE *,
int,
int,
int,
char,
int,
char,
const struct test_table *,
vfo_t,
const char *,
@ -155,6 +160,11 @@ struct test_table
FILE *fout, \
FILE *fin, \
int interactive, \
int prompt, \
int vfo_mode, \
char send_cmd_term, \
int ext_resp, \
char resp_sep, \
const struct test_table *cmd, \
vfo_t vfo, \
const char *arg1, \
@ -587,14 +597,9 @@ static int next_word(char *buffer, int argc, char *argv[], int newline)
})
extern thread_local int interactive;
extern thread_local int prompt;
extern thread_local int vfo_mode;
extern thread_local char send_cmd_term;
thread_local int ext_resp = 0;
thread_local unsigned char resp_sep = '\n'; /* Default response separator */
int rigctl_parse(RIG *my_rig, FILE *fin, FILE *fout, char *argv[], int argc, sync_cb_t sync_cb)
int rigctl_parse(RIG *my_rig, FILE *fin, FILE *fout, char *argv[], int argc, sync_cb_t sync_cb,
int interactive, int prompt, int vfo_mode, char send_cmd_term,
int * ext_resp_ptr, char * resp_sep_ptr)
{
int retcode; /* generic return code from functions */
unsigned char cmd;
@ -629,7 +634,7 @@ int rigctl_parse(RIG *my_rig, FILE *fin, FILE *fout, char *argv[], int argc, syn
*/
if (cmd == '+' && !prompt)
{
ext_resp = 1;
*ext_resp_ptr = 1;
if (scanfc(fin, "%c", &cmd) < 1)
{
@ -648,8 +653,8 @@ int rigctl_parse(RIG *my_rig, FILE *fin, FILE *fout, char *argv[], int argc, syn
&& !prompt)
{
ext_resp = 1;
resp_sep = cmd;
*ext_resp_ptr = 1;
*resp_sep_ptr = cmd;
if (scanfc(fin, "%c", &cmd) < 1)
{
@ -1525,7 +1530,7 @@ int rigctl_parse(RIG *my_rig, FILE *fin, FILE *fout, char *argv[], int argc, syn
* 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_ptr && !prompt && cmd != 0xf0)
{
char a1[MAXARGSZ + 2];
char a2[MAXARGSZ + 2];
@ -1548,13 +1553,18 @@ int rigctl_parse(RIG *my_rig, FILE *fin, FILE *fout, char *argv[], int argc, syn
a1,
a2,
a3,
resp_sep);
*resp_sep_ptr);
}
retcode = (*cmd_entry->rig_routine)(my_rig,
fout,
fin,
interactive,
prompt,
vfo_mode,
send_cmd_term,
*ext_resp_ptr,
*resp_sep_ptr,
cmd_entry,
vfo,
p1,
@ -1570,8 +1580,8 @@ int rigctl_parse(RIG *my_rig, FILE *fin, FILE *fout, char *argv[], int argc, syn
if (interactive && !prompt)
{
fprintf(fout, NETRIGCTL_RET "%d\n", retcode);
ext_resp = 0;
resp_sep = '\n';
*ext_resp_ptr = 0;
*resp_sep_ptr = '\n';
}
else
{
@ -1588,17 +1598,17 @@ int rigctl_parse(RIG *my_rig, FILE *fin, FILE *fout, char *argv[], int argc, syn
{
/* netrigctl RIG_OK */
if (!(cmd_entry->flags & ARG_OUT)
&& !ext_resp && cmd != 0xf0)
&& !*ext_resp_ptr && cmd != 0xf0)
{
fprintf(fout, NETRIGCTL_RET "0\n");
}
/* Extended Response protocol */
else if (ext_resp && cmd != 0xf0)
else if (*ext_resp_ptr && cmd != 0xf0)
{
fprintf(fout, NETRIGCTL_RET "0\n");
ext_resp = 0;
resp_sep = '\n';
*ext_resp_ptr = 0;
*resp_sep_ptr = '\n';
}
}
}

Wyświetl plik

@ -46,6 +46,8 @@ int print_conf_list(const struct confparams *cfp, rig_ptr_t data);
int set_conf(RIG *my_rig, char *conf_parms);
typedef void (*sync_cb_t)(int);
int rigctl_parse(RIG *my_rig, FILE *fin, FILE *fout, char *argv[], int argc, sync_cb_t sync_cb);
int rigctl_parse(RIG *my_rig, FILE *fin, FILE *fout, char *argv[], int argc, sync_cb_t sync_cb,
int interactive, int prompt, int vfo_mode, char send_cmd_term,
int * ext_resp_ptr, char * resp_sep_ptr);
#endif /* RIGCTL_PARSE_H */

Wyświetl plik

@ -71,10 +71,8 @@
#include "iofunc.h"
#include "serial.h"
#include "sprintflst.h"
#include "rigctl_parse.h"
/*
* Reminder: when adding long options,
* keep up to date SHORT_OPTIONS, usage()'s output and man page. thanks.
@ -105,16 +103,6 @@ static struct option long_options[] =
{0, 0, 0, 0}
};
struct handle_data
{
RIG *rig;
int sock;
struct sockaddr_storage cli_addr;
socklen_t clilen;
};
void usage();
static int handle_ts2000(void *arg);
@ -128,12 +116,6 @@ static sig_atomic_t volatile ctrl_c;
static int volatile ctrl_c;
#endif
thread_local int interactive = 1; /* no cmd because of daemon */
thread_local int prompt = 0; /* Daemon mode for rigparse return string */
thread_local int vfo_mode = 0; /* vfo_mode=0 means target VFO is current VFO */
thread_local char send_cmd_term = '\r'; /* send_cmd termination char */
#define MAXCONFLEN 128
#if 0

Wyświetl plik

@ -117,6 +117,7 @@ struct handle_data
int sock;
struct sockaddr_storage cli_addr;
socklen_t clilen;
int vfo_mode;
};
@ -137,12 +138,6 @@ static sig_atomic_t volatile ctrl_c;
static int volatile ctrl_c;
#endif
thread_local int interactive = 1; /* no cmd because of daemon */
thread_local int prompt = 0; /* Daemon mode for rigparse return string */
thread_local int vfo_mode = 0; /* vfo_mode=0 means target VFO is current VFO */
thread_local char send_cmd_term = '\r'; /* send_cmd termination char */
const char *portno = "4532";
const char *src_addr = NULL; /* INADDR_ANY */
@ -254,6 +249,7 @@ int main(int argc, char *argv[])
pthread_attr_t attr;
#endif
struct handle_data *arg;
int vfo_mode = 0; /* vfo_mode=0 means target VFO is current VFO */
while (1)
{
@ -794,6 +790,7 @@ int main(int argc, char *argv[])
else {
arg->rig = my_rig;
arg->clilen = sizeof(arg->cli_addr);
arg->vfo_mode = vfo_mode;
arg->sock = accept(sock_listen,
(struct sockaddr *)&arg->cli_addr,
&arg->clilen);
@ -874,6 +871,9 @@ void * handle_socket(void *arg)
int retcode = RIG_OK;
char host[NI_MAXHOST];
char serv[NI_MAXSERV];
char send_cmd_term = '\r'; /* send_cmd termination char */
int ext_resp = 0;
char resp_sep = '\n';
#ifdef __MINGW32__
int sock_osfhandle = _open_osfhandle(handle_data_arg->sock, _O_RDONLY);
@ -933,7 +933,8 @@ void * handle_socket(void *arg)
do
{
retcode = rigctl_parse(handle_data_arg->rig, fsockin, fsockout, NULL, 0, sync_callback);
retcode = rigctl_parse(handle_data_arg->rig, fsockin, fsockout, NULL, 0, sync_callback,
1, 0, handle_data_arg->vfo_mode, send_cmd_term, &ext_resp, &resp_sep);
if (ferror(fsockin) || ferror(fsockout))
{
retcode = 1;

Wyświetl plik

@ -111,13 +111,6 @@ static struct option long_options[] =
static const int have_rl = 1;
#endif
thread_local int interactive = 1; /* if no cmd on command line, switch to interactive */
thread_local int prompt = 1; /* Print prompt in rotctl */
thread_local char send_cmd_term = '\r'; /* send_cmd termination char */
int main(int argc, char *argv[])
{
ROT *my_rot; /* handle to rot (instance) */
@ -142,6 +135,11 @@ int main(int argc, char *argv[])
const char *rot_file = NULL;
int serial_rate = 0;
char conf_parms[MAXCONFLEN] = "";
int interactive = 1; /* if no cmd on command line, switch to interactive */
int prompt = 1; /* Print prompt in rotctl */
char send_cmd_term = '\r'; /* send_cmd termination char */
int ext_resp = 0;
char resp_sep = '\n';
while (1)
{
@ -402,7 +400,9 @@ int main(int argc, char *argv[])
do
{
retcode = rotctl_parse(my_rot, stdin, stdout, argv, argc);
retcode = rotctl_parse(my_rot, stdin, stdout, argv, argc,
interactive, prompt, send_cmd_term,
&ext_resp, &resp_sep);
if (retcode == 2)
{

Wyświetl plik

@ -136,6 +136,10 @@ struct test_table
int (*rot_routine)(ROT *,
FILE *,
int,
int,
char,
int,
char,
const struct test_table *,
const char *,
const char *,
@ -158,6 +162,10 @@ struct test_table
#define declare_proto_rot(f) static int (ACTION(f))(ROT *rot, \
FILE *fout, \
int interactive, \
int prompt, \
char send_cmd_term, \
int ext_resp, \
char resp_sep, \
const struct test_table *cmd, \
const char *arg1, \
const char *arg2, \
@ -495,14 +503,9 @@ static int next_word(char *buffer, int argc, char *argv[], int newline)
})
extern thread_local int interactive;
extern thread_local int prompt;
extern thread_local char send_cmd_term;
thread_local int ext_resp = 0;
thread_local unsigned char resp_sep = '\n'; /* Default response separator */
int rotctl_parse(ROT *my_rot, FILE *fin, FILE *fout, char *argv[], int argc)
int rotctl_parse(ROT *my_rot, FILE *fin, FILE *fout, char *argv[], int argc,
int interactive, int prompt, char send_cmd_term,
int * ext_resp_ptr, char * resp_sep_ptr)
{
int retcode; /* generic return code from functions */
unsigned char cmd;
@ -539,7 +542,7 @@ int rotctl_parse(ROT *my_rot, FILE *fin, FILE *fout, char *argv[], int argc)
*/
if (cmd == '+' && !prompt)
{
ext_resp = 1;
*ext_resp_ptr = 1;
if (scanfc(fin, "%c", &cmd) < 1)
{
@ -558,8 +561,8 @@ int rotctl_parse(ROT *my_rot, FILE *fin, FILE *fout, char *argv[], int argc)
&& !prompt)
{
ext_resp = 1;
resp_sep = cmd;
*ext_resp_ptr = 1;
*resp_sep_ptr = cmd;
if (scanfc(fin, "%c", &cmd) < 1)
{
@ -1397,7 +1400,7 @@ int rotctl_parse(ROT *my_rot, FILE *fin, FILE *fout, char *argv[], int argc)
* Extended Response protocol: output received command name and arguments
* response.
*/
if (interactive && ext_resp && !prompt)
if (interactive && *ext_resp_ptr && !prompt)
{
char a1[MAXARGSZ + 2];
char a2[MAXARGSZ + 2];
@ -1409,12 +1412,16 @@ int rotctl_parse(ROT *my_rot, FILE *fin, FILE *fout, char *argv[], int argc)
p3 == NULL ? a3[0] = '\0' : snprintf(a3, sizeof(a3), " %s", p3);
p4 == NULL ? a4[0] = '\0' : snprintf(a4, sizeof(a4), " %s", p4);
fprintf(fout, "%s:%s%s%s%s%c", cmd_entry->name, a1, a2, a3, a4, resp_sep);
fprintf(fout, "%s:%s%s%s%s%c", cmd_entry->name, a1, a2, a3, a4, *resp_sep_ptr);
}
retcode = (*cmd_entry->rot_routine)(my_rot,
fout,
interactive,
prompt,
send_cmd_term,
*ext_resp_ptr,
*resp_sep_ptr,
cmd_entry,
p1,
p2 ? p2 : "",
@ -1434,8 +1441,8 @@ int rotctl_parse(ROT *my_rot, FILE *fin, FILE *fout, char *argv[], int argc)
if (interactive && !prompt)
{
fprintf(fout, NETROTCTL_RET "%d\n", retcode);
ext_resp = 0;
resp_sep = '\n';
*ext_resp_ptr = 0;
*resp_sep_ptr = '\n';
}
else
{
@ -1448,17 +1455,17 @@ int rotctl_parse(ROT *my_rot, FILE *fin, FILE *fout, char *argv[], int argc)
if (interactive && !prompt)
{
/* netrotctl RIG_OK */
if (!(cmd_entry->flags & ARG_OUT) && !ext_resp)
if (!(cmd_entry->flags & ARG_OUT) && !*ext_resp_ptr)
{
fprintf(fout, NETROTCTL_RET "0\n");
}
/* Extended Response protocol */
else if (ext_resp && cmd != 0xf0)
else if (*ext_resp_ptr && cmd != 0xf0)
{
fprintf(fout, NETROTCTL_RET "0\n");
ext_resp = 0;
resp_sep = '\n';
*ext_resp_ptr = 0;
*resp_sep_ptr = '\n';
}
}
}

Wyświetl plik

@ -44,6 +44,8 @@ void list_models();
int print_conf_list(const struct confparams *cfp, rig_ptr_t data);
int set_conf(ROT *my_rot, char *conf_parms);
int rotctl_parse(ROT *my_rot, FILE *fin, FILE *fout, char *argv[], int argc);
int rotctl_parse(ROT *my_rot, FILE *fin, FILE *fout, char *argv[], int argc,
int interactive, int prompt, char send_cmd_term,
int * ext_resp_ptr, char * resp_sep_ptr);
#endif /* ROTCTL_PARSE_H */

Wyświetl plik

@ -103,13 +103,8 @@ static struct option long_options[] =
{0, 0, 0, 0}
};
thread_local int interactive = 1; /* no cmd because of daemon */
thread_local int prompt = 0 ; /* Daemon mode for rigparse return string */
thread_local const char *portno = "4533";
thread_local const char *src_addr = NULL; /* INADDR_ANY */
thread_local char send_cmd_term = '\r'; /* send_cmd termination char */
const char *portno = "4533";
const char *src_addr = NULL; /* INADDR_ANY */
#define MAXCONFLEN 128
@ -596,6 +591,8 @@ void * handle_socket(void *arg)
int retcode;
char host[NI_MAXHOST];
char serv[NI_MAXSERV];
int ext_resp = 0;
char resp_sep = '\n';
#ifdef __MINGW32__
int sock_osfhandle = _open_osfhandle(handle_data_arg->sock, _O_RDONLY);
@ -632,7 +629,8 @@ void * handle_socket(void *arg)
do
{
retcode = rotctl_parse(handle_data_arg->rot, fsockin, fsockout, NULL, 0);
retcode = rotctl_parse(handle_data_arg->rot, fsockin, fsockout, NULL, 0, 1,
0, '\r', &ext_resp, &resp_sep);
if (ferror(fsockin) || ferror(fsockout))
{