From f282d50f98c5b26afd69acdafd650a7e8fc570b4 Mon Sep 17 00:00:00 2001 From: PA4WDH Date: Sun, 21 May 2023 14:45:18 +0200 Subject: Add argument parsing and validation --- Makefile | 2 +- argparse.c | 79 +++++++++++++++++++++++++++++++++++++++++++++++++++++ argparse.h | 6 ++++ cputemp2maxfreq.c | 50 +++++++++++++++++++++++++-------- cputemp2maxfreq.h | 32 ++++++++++++++++++---- generate_debug_h.sh | 2 +- 6 files changed, 152 insertions(+), 19 deletions(-) create mode 100644 argparse.c create mode 100644 argparse.h diff --git a/Makefile b/Makefile index aa4ec70..89fc8b7 100644 --- a/Makefile +++ b/Makefile @@ -1,4 +1,4 @@ -cputemp2maxfreq: version.o debug.o sysfs.o cpufreq.o failsafe.o +cputemp2maxfreq: version.o debug.o sysfs.o cpufreq.o failsafe.o argparse.o version.h: generate_version_h.sh .git/index ./generate_version_h.sh > version.h 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 +#include +#include +#include +#include "cputemp2maxfreq.h" +#include "debug.h" + +extern struct s_config config; + +void printhelp() +{ + printf( + "Usage: cputemp2maxfreq \n" + "\n" + "Options:\n" + "-f Fallback frequency in KHz, used when everything fails\n" + " Default: %ld\n" + "-g cpufreq governor to use, use \"keep\" to keep current governor\n" + " Default: %s\n" + "-h Display this help text\n" + "-i Input for temperature readout, usually somewhere in sysfs\n" + " Default: %s\n" + "-p