From 0bcd50d7a1ae7a6ae87fd33686b80582dcbdaea0 Mon Sep 17 00:00:00 2001 From: Juha Niskanen Date: Fri, 19 May 2017 07:13:12 -0600 Subject: [PATCH] apps/: Make more globals static to avoid name clashes --- examples/ostest/ostest_main.c | 19 +++-- examples/ostest/sporadic.c | 9 +-- netutils/netlib/netlib_parsehttpurl.c | 2 +- system/cdcacm/cdcacm.h | 6 -- system/cdcacm/cdcacm_main.c | 2 +- system/cu/cu.h | 4 - system/cu/cu_main.c | 6 +- system/i2c/i2c_common.c | 103 ++++++++++++++------------ system/i2c/i2c_dev.c | 2 +- system/i2c/i2c_get.c | 2 +- system/i2c/i2c_main.c | 7 +- system/i2c/i2c_set.c | 2 +- system/i2c/i2c_verf.c | 2 +- system/i2c/i2ctool.h | 5 +- 14 files changed, 79 insertions(+), 92 deletions(-) diff --git a/examples/ostest/ostest_main.c b/examples/ostest/ostest_main.c index 4cfe61cd7..f3d2bda09 100644 --- a/examples/ostest/ostest_main.c +++ b/examples/ostest/ostest_main.c @@ -95,18 +95,17 @@ static struct mallinfo g_mmprevious; static struct mallinfo g_mmafter; #ifndef CONFIG_DISABLE_ENVIRON -const char g_var1_name[] = "Variable1"; -const char g_var1_value[] = "GoodValue1"; -const char g_var2_name[] = "Variable2"; -const char g_var2_value[] = "GoodValue2"; -const char g_var3_name[] = "Variable3"; -const char g_var3_value[] = "GoodValue3"; +static const char g_var1_name[] = "Variable1"; +static const char g_var1_value[] = "GoodValue1"; +static const char g_var2_name[] = "Variable2"; +static const char g_var2_value[] = "GoodValue2"; +static const char g_var3_name[] = "Variable3"; +static const char g_var3_value[] = "GoodValue3"; -const char g_bad_value1[] = "BadValue1"; -const char g_bad_value2[] = "BadValue2"; - -const char g_putenv_value[] = "Variable1=BadValue3"; +static const char g_bad_value1[] = "BadValue1"; +static const char g_bad_value2[] = "BadValue2"; +static const char g_putenv_value[] = "Variable1=BadValue3"; #endif /**************************************************************************** diff --git a/examples/ostest/sporadic.c b/examples/ostest/sporadic.c index db3c19563..fcf15c669 100644 --- a/examples/ostest/sporadic.c +++ b/examples/ostest/sporadic.c @@ -63,10 +63,6 @@ #define sched_lock() #define sched_unlock() -#ifndef NULL -# define NULL (void*)0 -#endif - #ifndef MIN # define MIN(a,b) (((a) < (b)) ? (a) : (b)) #endif @@ -82,7 +78,7 @@ static time_t g_start_time; * Private Functions ****************************************************************************/ -void my_mdelay(unsigned int milliseconds) +static void my_mdelay(unsigned int milliseconds) { volatile unsigned int i; volatile unsigned int j; @@ -94,6 +90,7 @@ void my_mdelay(unsigned int milliseconds) } } } + static void *nuisance_func(void *parameter) { /* Synchronized start */ @@ -368,4 +365,4 @@ void sporadic_test(void) } } -#endif /* CONFIG_SCHED_SPORADIC */ \ No newline at end of file +#endif /* CONFIG_SCHED_SPORADIC */ diff --git a/netutils/netlib/netlib_parsehttpurl.c b/netutils/netlib/netlib_parsehttpurl.c index c5d09c1bb..6282edcb5 100644 --- a/netutils/netlib/netlib_parsehttpurl.c +++ b/netutils/netlib/netlib_parsehttpurl.c @@ -49,7 +49,7 @@ * Private Data ****************************************************************************/ -const char g_http[] = "http://"; +static const char g_http[] = "http://"; #define HTTPLEN 7 /**************************************************************************** diff --git a/system/cdcacm/cdcacm.h b/system/cdcacm/cdcacm.h index d8a351239..79ca68749 100644 --- a/system/cdcacm/cdcacm.h +++ b/system/cdcacm/cdcacm.h @@ -132,12 +132,6 @@ struct cdcacm_state_s * Public Data ****************************************************************************/ -/* All global variables used by this add-on are packed into a structure in - * order to avoid name collisions. - */ - -extern struct cdcacm_state_s g_cdcacm; - /**************************************************************************** * Public Functions ****************************************************************************/ diff --git a/system/cdcacm/cdcacm_main.c b/system/cdcacm/cdcacm_main.c index b3bb4606b..82d97b901 100644 --- a/system/cdcacm/cdcacm_main.c +++ b/system/cdcacm/cdcacm_main.c @@ -58,7 +58,7 @@ * order to avoid name collisions. */ -struct cdcacm_state_s g_cdcacm; +static struct cdcacm_state_s g_cdcacm; /**************************************************************************** * Public Functions diff --git a/system/cu/cu.h b/system/cu/cu.h index 51d3956fa..d73e43731 100644 --- a/system/cu/cu.h +++ b/system/cu/cu.h @@ -78,10 +78,6 @@ struct cu_globals_s * Public Data ****************************************************************************/ -/* terminal state data */ - -extern struct cu_globals_s g_cu; - /**************************************************************************** * Public Function Prototypes ****************************************************************************/ diff --git a/system/cu/cu_main.c b/system/cu/cu_main.c index f476182e3..8031a86bd 100644 --- a/system/cu/cu_main.c +++ b/system/cu/cu_main.c @@ -76,14 +76,12 @@ enum parity_mode * Private Data ****************************************************************************/ +static struct cu_globals_s g_cu; + /**************************************************************************** * Public Data ****************************************************************************/ -/* terminal state data */ - -struct cu_globals_s g_cu; - /**************************************************************************** * Private Functions ****************************************************************************/ diff --git a/system/i2c/i2c_common.c b/system/i2c/i2c_common.c index a3b3fce23..0e4a505d5 100644 --- a/system/i2c/i2c_common.c +++ b/system/i2c/i2c_common.c @@ -43,15 +43,67 @@ #include "i2ctool.h" +/**************************************************************************** + * Private Functions + ****************************************************************************/ + +/**************************************************************************** + * Name: arg_string + ****************************************************************************/ + +static int arg_string(FAR char **arg, FAR char **value) +{ + FAR char *ptr = *arg; + + if (ptr[2] == '\0') + { + *value = arg[1]; + return 2; + } + else + { + *value = &ptr[2]; + return 1; + } +} + +/**************************************************************************** + * Name: arg_decimal + ****************************************************************************/ + +static int arg_decimal(FAR char **arg, FAR long *value) +{ + FAR char *string; + int ret; + + ret = arg_string(arg, &string); + *value = strtol(string, NULL, 10); + return ret; +} + +/**************************************************************************** + * Name: arg_hex + ****************************************************************************/ + +static int arg_hex(FAR char **arg, FAR long *value) +{ + FAR char *string; + int ret; + + ret = arg_string(arg, &string); + *value = strtol(string, NULL, 16); + return ret; +} + /**************************************************************************** * Public Functions ****************************************************************************/ /**************************************************************************** - * Name: common_args + * Name: i2ctool_common_args ****************************************************************************/ -int common_args(FAR struct i2ctool_s *i2ctool, FAR char **arg) +int i2ctool_common_args(FAR struct i2ctool_s *i2ctool, FAR char **arg) { FAR char *ptr = *arg; long value; @@ -148,50 +200,3 @@ out_of_range: return ERROR; } -/**************************************************************************** - * Name: arg_string - ****************************************************************************/ - -int arg_string(FAR char **arg, FAR char **value) -{ - FAR char *ptr = *arg; - - if (ptr[2] == '\0') - { - *value = arg[1]; - return 2; - } - else - { - *value = &ptr[2]; - return 1; - } -} - -/**************************************************************************** - * Name: arg_decimal - ****************************************************************************/ - -int arg_decimal(FAR char **arg, FAR long *value) -{ - FAR char *string; - int ret; - - ret = arg_string(arg, &string); - *value = strtol(string, NULL, 10); - return ret; -} - -/**************************************************************************** - * Name: arg_hex - ****************************************************************************/ - -int arg_hex(FAR char **arg, FAR long *value) -{ - FAR char *string; - int ret; - - ret = arg_string(arg, &string); - *value = strtol(string, NULL, 16); - return ret; -} diff --git a/system/i2c/i2c_dev.c b/system/i2c/i2c_dev.c index 7151a2f5c..b504699b9 100644 --- a/system/i2c/i2c_dev.c +++ b/system/i2c/i2c_dev.c @@ -88,7 +88,7 @@ int i2ccmd_dev(FAR struct i2ctool_s *i2ctool, int argc, char **argv) /* Otherwise, check for common options */ - nargs = common_args(i2ctool, &argv[argndx]); + nargs = i2ctool_common_args(i2ctool, &argv[argndx]); if (nargs < 0) { return ERROR; diff --git a/system/i2c/i2c_get.c b/system/i2c/i2c_get.c index acdea6b2a..56258c88f 100644 --- a/system/i2c/i2c_get.c +++ b/system/i2c/i2c_get.c @@ -79,7 +79,7 @@ int i2ccmd_get(FAR struct i2ctool_s *i2ctool, int argc, FAR char **argv) /* Otherwise, check for common options */ - nargs = common_args(i2ctool, &argv[argndx]); + nargs = i2ctool_common_args(i2ctool, &argv[argndx]); if (nargs < 0) { return ERROR; diff --git a/system/i2c/i2c_main.c b/system/i2c/i2c_main.c index 0d80d39f2..8d3cf3192 100644 --- a/system/i2c/i2c_main.c +++ b/system/i2c/i2c_main.c @@ -63,7 +63,7 @@ static int i2ccmd_unrecognized(FAR struct i2ctool_s *i2ctool, int argc, char **a * Private Data ****************************************************************************/ -struct i2ctool_s g_i2ctool; +static struct i2ctool_s g_i2ctool; static const struct cmdmap_s g_i2ccmds[] = { @@ -202,7 +202,8 @@ static int i2c_execute(FAR struct i2ctool_s *i2ctool, int argc, char *argv[]) * Name: i2c_argument ****************************************************************************/ -FAR char *i2c_argument(FAR struct i2ctool_s *i2ctool, int argc, char *argv[], int *pindex) +static FAR char *i2c_argument(FAR struct i2ctool_s *i2ctool, + int argc, char *argv[], int *pindex) { FAR char *arg; int index = *pindex; @@ -247,7 +248,7 @@ FAR char *i2c_argument(FAR struct i2ctool_s *i2ctool, int argc, char *argv[], in * Name: i2c_parse ****************************************************************************/ -int i2c_parse(FAR struct i2ctool_s *i2ctool, int argc, char *argv[]) +static int i2c_parse(FAR struct i2ctool_s *i2ctool, int argc, char *argv[]) { FAR char *newargs[MAX_ARGUMENTS+2]; FAR char *cmd; diff --git a/system/i2c/i2c_set.c b/system/i2c/i2c_set.c index ce3638280..f7eba267f 100644 --- a/system/i2c/i2c_set.c +++ b/system/i2c/i2c_set.c @@ -79,7 +79,7 @@ int i2ccmd_set(FAR struct i2ctool_s *i2ctool, int argc, FAR char **argv) /* Otherwise, check for common options */ - nargs = common_args(i2ctool, &argv[argndx]); + nargs = i2ctool_common_args(i2ctool, &argv[argndx]); if (nargs < 0) { return ERROR; diff --git a/system/i2c/i2c_verf.c b/system/i2c/i2c_verf.c index ed67d1409..48d5d6e2f 100644 --- a/system/i2c/i2c_verf.c +++ b/system/i2c/i2c_verf.c @@ -81,7 +81,7 @@ int i2ccmd_verf(FAR struct i2ctool_s *i2ctool, int argc, FAR char **argv) /* Otherwise, check for common options */ - nargs = common_args(i2ctool, &argv[argndx]); + nargs = i2ctool_common_args(i2ctool, &argv[argndx]); if (nargs < 0) { return ERROR; diff --git a/system/i2c/i2ctool.h b/system/i2c/i2ctool.h index ea43f7035..ddc5f50ec 100644 --- a/system/i2c/i2ctool.h +++ b/system/i2c/i2ctool.h @@ -199,10 +199,7 @@ int i2ctool_set(FAR struct i2ctool_s *i2ctool, int fd, uint8_t regaddr, /* Common logic */ -int common_args(FAR struct i2ctool_s *i2ctool, FAR char **arg); -int arg_string(FAR char **arg, FAR char **value); -int arg_decimal(FAR char **arg, FAR long *value); -int arg_hex(FAR char **arg, FAR long *value); +int i2ctool_common_args(FAR struct i2ctool_s *i2ctool, FAR char **arg); /* Driver access utilities */