aboutsummaryrefslogtreecommitdiffstats
path: root/argparse.c
diff options
context:
space:
mode:
Diffstat (limited to 'argparse.c')
-rw-r--r--argparse.c79
1 files changed, 79 insertions, 0 deletions
diff --git a/argparse.c b/argparse.c
new file mode 100644
index 0000000..01b6c57
--- /dev/null
+++ b/argparse.c
@@ -0,0 +1,79 @@
+#include <stdio.h>
+#include <unistd.h>
+#include <stdlib.h>
+#include <string.h>
+#include "cputemp2maxfreq.h"
+#include "debug.h"
+
+extern struct s_config config;
+
+void printhelp()
+{
+ printf(
+ "Usage: cputemp2maxfreq <options>\n"
+ "\n"
+ "Options:\n"
+ "-f <frequency> Fallback frequency in KHz, used when everything fails\n"
+ " Default: %ld\n"
+ "-g <governor> cpufreq governor to use, use \"keep\" to keep current governor\n"
+ " Default: %s\n"
+ "-h Display this help text\n"
+ "-i <file> Input for temperature readout, usually somewhere in sysfs\n"
+ " Default: %s\n"
+ "-p <time> Poll interval in seconds\n"
+ " Default: %d\n"
+ "-s <step> Step size in Khz when increasing/decreasing CPU speed\n"
+ " Default: %ld\n"
+ "-t <number> Temperature limit\n"
+ " Default: %ld\n",
+ config.fallback_freq,config.governor,config.temp_input,config.interval,
+ config.freq_step,config.max_temp/1000
+ );
+}
+
+void argparse(int argc, char **argv)
+{
+ int opt;
+ struct s_config userconfig;
+
+ DEBUG1_ARGPARSE("Started\n");
+
+// Copy defaults
+ memcpy(&userconfig,&config,sizeof(struct s_config));
+
+// Parse options
+ while((opt=getopt(argc,argv,"f:g:hi:p:s:t:"))!=-1)
+ {
+ DEBUG1_ARGPARSE("Argument: %c Value: %s\n",opt,optarg);
+ switch(opt)
+ {
+ case 'f':
+ userconfig.fallback_freq=strtoll(optarg,NULL,10);
+ break;
+ case 'g':
+ strncpy(userconfig.governor,optarg,sizeof(userconfig.governor));
+ break;
+ case 'h':
+ printhelp();
+ exit(1);
+ case 'i':
+ strncpy(userconfig.temp_input,optarg,sizeof(userconfig.temp_input));
+ break;
+ case 'p':
+ userconfig.interval=strtoll(optarg,NULL,10);
+ break;
+ case 's':
+ userconfig.freq_step=strtoll(optarg,NULL,10);
+ break;
+ case 't':
+ userconfig.max_temp=strtoll(optarg,NULL,10)*1000;
+ break;
+ default:
+ printhelp();
+ exit(1);
+ }
+ }
+
+// Copy modified config to global config
+ memcpy(&config,&userconfig,sizeof(struct s_config));
+}