diff --git a/fbclock.c b/fbclock.c index 3643f7a..bd88389 100644 --- a/fbclock.c +++ b/fbclock.c @@ -4,6 +4,7 @@ * Requires: libpng */ +#include #include #include #include @@ -21,9 +22,24 @@ int main(int argc, char *argv[]) { struct framebuffer fb; /* Display offset from top left of screen, in pixels */ - /* TODO: turn into command-line option */ - int x_offset = 0; - int y_offset = 0; + unsigned int x_offset = 0; + unsigned int y_offset = 0; + + /* Parse command-line options */ + int opt; + while ((opt = getopt(argc, argv, "x:y:")) != -1) { + switch (opt) { + case 'x': + x_offset = atoi(optarg); + break; + case 'y': + y_offset = atoi(optarg); + break; + default: + print_usage(argv[0]); + exit(EXIT_FAILURE); + } + } /* Set up framebuffer */ new_framebuffer(&fb, "/dev/fb0"); @@ -98,3 +114,10 @@ void display_time(struct tm *tp, struct framebuffer *fb, int x_offset, return; } + +/* print_usage: print a usage message */ +void print_usage(char *name) { + fprintf(stderr, "Usage: %s [-x x_offset] [-y y_offset]\n", name); + return; +} + diff --git a/fbclock.h b/fbclock.h index f65794a..552d186 100644 --- a/fbclock.h +++ b/fbclock.h @@ -35,3 +35,4 @@ char *short_month_filenames[] = { /* Function prototypes */ void display_time(struct tm *tp, struct framebuffer *fb, int x_offset, int y_offset); +void print_usage();