Add '--cfg_path=' command line parameter to point to cfg file directory. If not provided it defaults to the current directory

This commit is contained in:
Ed Gonzalez 2015-01-15 18:37:50 -06:00
parent c48bed03be
commit da0baf098f
3 changed files with 35 additions and 18 deletions

View file

@ -56,7 +56,7 @@ static BOOL console_thread_abort = FALSE;
static sem_t _startup_sem, _communications_sem;
extern const char* APP_NAME;
extern const char* CFG_FILE;
extern char * cfg_path;
void api_setVersion(uint32 version)
{
@ -151,23 +151,26 @@ uint32 register_mode(void)
struct stat statbuf;
char MinRadioVerString[40];
// Check for existence of file before opening, otherwise will segfault.
if(stat(CFG_FILE, &statbuf) == 0)
char cfg_file[1024];
sprintf(cfg_file, "%s%s%s", cfg_path, APP_NAME, ".cfg");
output("READING CONFIG FILE '%s' \n", cfg_file);
if(stat(cfg_file, &statbuf) == 0)
{
output(ANSI_WHITE"Configuration file exists.\n");
}
else
{
output(ANSI_RED"CONFIGURATION FILE DOES NOT EXIST.\n");
output(ANSI_RED"CONFIGURATION FILE '%s' DOES NOT EXIST.\n", cfg_file);
usleep(1000000);
return 999;
}
cfgStream = fopen(CFG_FILE, "r");
cfgStream = fopen(cfg_file, "r");
if (ferror(cfgStream))
{
output(ANSI_YELLOW"Error opening file %s \n", CFG_FILE);
output(ANSI_YELLOW"Error opening file %s \n", cfg_file);
return 999;
}
else{
@ -182,7 +185,7 @@ uint32 register_mode(void)
numRead = getline(&inputBuffer, &nbytes, cfgStream);
if (numRead == -1)
{
output(ANSI_YELLOW"Error reading config file %s\n", CFG_FILE);
output(ANSI_YELLOW"Error reading config file %s\n", cfg_file);
return 999;
}
@ -197,7 +200,7 @@ uint32 register_mode(void)
{
if (ferror(cfgStream))
{
output(ANSI_YELLOW"Read error %s, reached end of file, [header] not found. \n", CFG_FILE);
output(ANSI_YELLOW"Read error %s, reached end of file, [header] not found. \n", cfg_file);
return 999; // should return a fail return -1;
}
}
@ -209,7 +212,7 @@ uint32 register_mode(void)
numRead = getline(&inputBuffer, &nbytes, cfgStream);
if (numRead == -1)
{
output(ANSI_YELLOW"Error reading config file %s\n", CFG_FILE);
output(ANSI_YELLOW"Error reading config file %s\n", cfg_file);
// TODO return here?
}
@ -226,7 +229,7 @@ uint32 register_mode(void)
{
if (ferror(cfgStream))
{
output(ANSI_YELLOW"Read error %s, minimum version not found, reached end of file. \n", CFG_FILE);
output(ANSI_YELLOW"Read error %s, minimum version not found, reached end of file. \n", cfg_file);
return 999;
}
}
@ -238,7 +241,7 @@ uint32 register_mode(void)
numRead = getline(&inputBuffer, &nbytes, cfgStream);
if (numRead == -1)
{
output(ANSI_YELLOW"Error reading config file %s\n", CFG_FILE);
output(ANSI_YELLOW"Error reading config file %s\n", cfg_file);
return 999;
}
@ -253,7 +256,7 @@ uint32 register_mode(void)
{
if (ferror(cfgStream))
{
output(ANSI_YELLOW"Read error %s, [setup] not found. \n", CFG_FILE);
output(ANSI_YELLOW"Read error %s, [setup] not found. \n", cfg_file);
return 999; // should return a fail return -1;
}
}
@ -266,7 +269,7 @@ uint32 register_mode(void)
numRead = getline(&inputBuffer, &nbytes, cfgStream);
if (numRead == -1)
{
output("Error reading config file %s\n", CFG_FILE);
output("Error reading config file %s\n", cfg_file);
return 999;
}
@ -288,7 +291,7 @@ uint32 register_mode(void)
}
else if (ferror(cfgStream))
{
output("End of file %s, reached. \n\n", CFG_FILE);
output("End of file %s, reached. \n\n", cfg_file);
readFlag = FALSE;
}
else
@ -301,11 +304,11 @@ uint32 register_mode(void)
if (fclose(cfgStream) == EOF)
{
output(ANSI_YELLOW"Error closing config file %s\n", CFG_FILE);
output(ANSI_YELLOW"Error closing config file %s\n", cfg_file);
}
else
{
output(ANSI_CYAN "FreeDV: SUCCESS, closed config file %s\n", CFG_FILE);
output(ANSI_CYAN "FreeDV: SUCCESS, closed config file %s\n", cfg_file);
}
return SUCCESS;

View file

@ -356,6 +356,7 @@ static void* _tc_thread(void* arg)
result = register_mode();
if (result != SUCCESS) {
output("** Could not register mode **\n");
tc_abort();
}
/* Initialize UDP connections for TX */

View file

@ -59,7 +59,8 @@
const char* APP_NAME = "FreeDV"; // Name of Application
const char* CFG_FILE = "/home/root/FreeDV.cfg"; // Name of associated configuration file
//const char* CFG_FILE = "FreeDV.cfg"; // Name of associated configuration file
char * cfg_path = NULL;
static sem_t shutdown_sem;
@ -128,6 +129,7 @@ int main( int argc, char * argv[])
{
const char * console_param = "--console";
const char * restrict_ip_param = "--ip=";
const char * config_path_param = "--cfg_path=";
BOOL enable_console = FALSE;
char * restrict_ip = NULL;
@ -148,12 +150,21 @@ int main( int argc, char * argv[])
restrict_ip = safe_malloc(strlen(argv[i]));
strncpy(restrict_ip, argv[i]+strlen(restrict_ip_param), strlen(argv[i]));
output("Restrict IP = '%s'", restrict_ip);
output("Restrict IP = '%s'\n", restrict_ip);
} else if ( strncmp(argv[i], config_path_param ,strlen(config_path_param)) == 0 ) {
cfg_path = safe_malloc(strlen(argv[i]));
strncpy(cfg_path, argv[i] + strlen(config_path_param), strlen(argv[i]));
output("Config Path = '%s'\n", cfg_path);
} else {
output("Unknown console parameter - '%s'\n", argv[i]);
}
}
if ( ! cfg_path ) {
cfg_path = safe_malloc(strlen("./") + 1);
strncpy(cfg_path, "./", strlen("./") + 1);
}
SmartSDR_API_Init(enable_console, restrict_ip);
if ( restrict_ip ) {
@ -163,6 +174,8 @@ int main( int argc, char * argv[])
/* Wait to be notified of shutdown */
sem_wait(&shutdown_sem);
safe_free(cfg_path);
return 0;
}