aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAmit Arora <amit.arora@linaro.org>2010-08-05 13:31:20 +0530
committerAmit Arora <amit.arora@linaro.org>2010-08-05 13:31:20 +0530
commitfefe8bfe2cefe20c763f1b4594e2a792101fc5f3 (patch)
treea5203999c933420aa414b4366a9a83e8638ab473
parent83faf0e7acefbed321a52d064935137cb00d8dcd (diff)
Add version string and long options
-rw-r--r--output.c21
-rw-r--r--powerdebug.c78
-rw-r--r--powerdebug.h3
3 files changed, 68 insertions, 34 deletions
diff --git a/output.c b/output.c
index b8f5b8e..6d4de01 100644
--- a/output.c
+++ b/output.c
@@ -3,14 +3,20 @@
void usage(char **argv)
{
printf("Usage: %s [OPTIONS]\n", argv[0]);
- printf(" -r Show regulator information\n");
- printf(" -s Show sensor information\n");
- printf(" -v Verbose\n");
- printf(" -h Help\n");
+ printf(" -r, --regulator Show regulator information\n");
+ printf(" -s, --sensor Show sensor information\n");
+ printf(" -v, --verbose Verbose mode (use with -r and/or -s)\n");
+ printf(" -V, --version Show Version\n");
+ printf(" -h, --help Help\n");
exit(0);
}
-
+
+void version()
+{
+ printf("powerdebug version %s\n", VERSION);
+ exit(0);
+}
void print_regulator_info(int verbose)
{
@@ -52,4 +58,9 @@ void print_regulator_info(int verbose)
printf("\tnum_users=%d\n", regulators_info[i].num_users);
printf("\n");
}
+
+ if (!numregulators && verbose) {
+ printf("Could not find regulator information!");
+ printf(" Looks like /sys/class/regulator is empty.\n\n");
+ }
}
diff --git a/powerdebug.c b/powerdebug.c
index 18a2382..2bd5c69 100644
--- a/powerdebug.c
+++ b/powerdebug.c
@@ -215,40 +215,60 @@ int main(int argc, char **argv)
int c;
int regulators = 0, sensors = 0, verbose = 0;
- /* Options:
- * -r : regulator
- * -s : sensors
- * -v : verbose
- * no option / default : all
+ /*
+ * Options:
+ * -r, --regulator : regulator
+ * -s, --sensor : sensors
+ * -v, --verbose : verbose
+ * -V, --version : version
+ * -h, --help : help
+ * no option / default : show usage!
*/
- while ((c = getopt (argc, argv, "rsvh")) != -1)
- switch (c)
- {
- case 'r':
- regulators = 1;
- break;
- case 's':
- sensors = 1;
- break;
- case 'v':
- verbose = 1;
- break;
- case 'h':
- usage (argv);
- case '?':
- fprintf (stderr, "Unknown option %c'.\n", optopt);
- return 1;
- default:
- usage(argv);
+ while (1) {
+ int optindex = 0;
+ static struct option long_options[] = {
+ {"regulator", 0, 0, 'r'},
+ {"sensor", 0, 0, 's'},
+ {"verbose", 0, 0, 'v'},
+ {"version", 0, 0, 'V'},
+ {"help", 0, 0, 'h'},
+ {0, 0, 0, 0}
+ };
+
+ c = getopt_long(argc, argv, "rsvVh", long_options, &optindex);
+ if (c == -1)
+ break;
+
+ switch (c) {
+ case 'r':
+ regulators = 1;
+ break;
+ case 's':
+ sensors = 1;
+ break;
+ case 'v':
+ verbose = 1;
+ break;
+ case 'V':
+ version();
+ break;
+ case 'h':
+ usage(argv);
+ break;
+ case '?':
+ fprintf (stderr, "%s: Unknown option %c'.\n",
+ argv[0], optopt);
+ exit(1);
+ default:
+ usage(argv);
+ break;
+ }
}
- /* By default print both regulator and sensor information */
+
+ /* Need atleast one option specified */
if (!regulators && !sensors) {
- /* What should be the default behavior ?
- regulators = 1;
- sensors = 1;
- */
usage(argv);
}
diff --git a/powerdebug.h b/powerdebug.h
index 27ed37c..df8877d 100644
--- a/powerdebug.h
+++ b/powerdebug.h
@@ -6,6 +6,8 @@
#include <getopt.h>
#include <errno.h>
+#define VERSION "1.0"
+
//#define PATH_MAX 1024
//#define NAME_MAX 128
#define VALUE_MAX 16
@@ -29,6 +31,7 @@ struct regulator_info {
extern int numregulators;
extern void usage(char **argv);
+extern void version(void);
extern void print_regulator_info(int verbose);
extern void get_sensor_info(char *path, char *name, char *sensor, int verbose);