aboutsummaryrefslogtreecommitdiffstats
path: root/argparse.c
diff options
context:
space:
mode:
authorPA4WDH2023-05-24 10:22:28 +0200
committerPA4WDH2023-05-24 10:22:28 +0200
commit38c1ad30b2ad8d71f946045e803fd8c4aa5f2e29 (patch)
tree97556352b05defdddf48cb9787840c13e0ff4295 /argparse.c
parentAdd data log option (diff)
downloadcputemp2maxfreq-38c1ad30b2ad8d71f946045e803fd8c4aa5f2e29.tar.gz
cputemp2maxfreq-38c1ad30b2ad8d71f946045e803fd8c4aa5f2e29.tar.bz2
cputemp2maxfreq-38c1ad30b2ad8d71f946045e803fd8c4aa5f2e29.zip
Detect program name from argv[0]
Diffstat (limited to 'argparse.c')
-rw-r--r--argparse.c18
1 files changed, 15 insertions, 3 deletions
diff --git a/argparse.c b/argparse.c
index 888f445..7df1239 100644
--- a/argparse.c
+++ b/argparse.c
@@ -11,7 +11,7 @@ extern struct s_config config;
void printhelp()
{
printf(
- "Usage: cputemp2maxfreq <options>\n"
+ "Usage: %s <options>\n"
"\n"
"Options:\n"
"-f <frequency> Fallback frequency in KHz, used when everything fails\n"
@@ -30,7 +30,7 @@ void printhelp()
" Default: %ld\n"
"-t <number> Temperature limit\n"
" Default: %ld\n",
- config.fallback_freq,config.governor,config.temp_input,config.logger_name,
+ config.name,config.fallback_freq,config.governor,config.temp_input,config.logger_name,
config.interval,config.freq_step,config.max_temp/1000
);
}
@@ -39,9 +39,19 @@ void argparse(int argc, char **argv)
{
int opt;
struct s_config userconfig;
-
+ char *lastslash;
DEBUG1_ARGPARSE("Started\n");
+ lastslash=strrchr(argv[0],'/');
+ if (lastslash==NULL)
+ {
+ lastslash=argv[0];
+ } else {
+ lastslash++;
+ }
+ strncpy(config.name,lastslash,sizeof(config.name));
+ DEBUG2_ARGPARSE("Detected program name %s\n",config.name);
+
// Copy defaults
memcpy(&userconfig,&config,sizeof(struct s_config));
@@ -85,6 +95,7 @@ void argparse(int argc, char **argv)
}
// Change the logger function pointer
+ DEBUG1_ARGPARSE("Logger is set to %s\n",userconfig.logger_name);
if (strcmp(userconfig.logger_name,"none")==0) userconfig.logger=&logger_none;
else if (strcmp(userconfig.logger_name,"stdout")==0) userconfig.logger=&logger_stdout;
else if (strcmp(userconfig.logger_name,"syslog")==0) userconfig.logger=&logger_syslog;
@@ -93,6 +104,7 @@ void argparse(int argc, char **argv)
config.logger("Invalid value for logger, exiting");
exit(1);
}
+ DEBUG2_ARGPARSE("Logger pointer is %p\n",userconfig.logger);
// Copy modified config to global config
memcpy(&config,&userconfig,sizeof(struct s_config));