diff options
author | Armaan Bhojwani <me@armaanb.net> | 2021-05-09 18:26:59 -0400 |
---|---|---|
committer | Armaan Bhojwani <me@armaanb.net> | 2021-05-09 18:26:59 -0400 |
commit | cfe6868b9e273efbe1cf9c783c00d72d48d0bff9 (patch) | |
tree | fbb9dbc4dd9bf076be33d972e27cf4ffea56488f | |
parent | bb708b3691abc66edeb976ca3279481e11177450 (diff) | |
download | mmenu-cfe6868b9e273efbe1cf9c783c00d72d48d0bff9.tar.gz |
Add option to start on a specific day of the week
-rw-r--r-- | mmenu.1.scd | 7 | ||||
-rw-r--r-- | mmenu.c | 38 |
2 files changed, 40 insertions, 5 deletions
diff --git a/mmenu.1.scd b/mmenu.1.scd index d7abf1b..1cdbc6d 100644 --- a/mmenu.1.scd +++ b/mmenu.1.scd @@ -6,9 +6,12 @@ mmenu - view the Castle menu # SYNOPSIS *mmenu* +*mmenu* [day of the week] + # DESCRIPTION -The *mmenu* utility uses Nobilis in order to display the castle menu. There is -no real command line interface, and the GUI is programmed in Motif. +*mmenu* uses Nobilis in order to display the castle menu. There isn't much of a +command line interface, however, you can optionally specify the day of the +week to open on. The GUI is programmed in Motif. # EXIT CODES *0* all ok,++ @@ -1,6 +1,8 @@ #include <stdlib.h> #include <stdio.h> #include <stdbool.h> +#include <string.h> +#include <ctype.h> #include <Xm/Xm.h> #include <Xm/Text.h> @@ -153,11 +155,41 @@ ArgvToXmStringTable (int argc, char **argv) return new; } +char * +strLower(char *inp) +{ + char *tmp = calloc(strlen(inp), sizeof(char)); + strcpy(tmp, inp); + for (int i = 0; tmp[i]; i++){ + tmp[i] = tolower(tmp[i]); + } + return tmp; +} + int main(int argc, char *argv[]) { - if (argc > 1) { - printf("Usage: %s\n", argv[0]); + // Parse CLI arguments + bool showUsage = false; + if (argc == 2) { + showUsage = true; + char *arg = strLower(argv[1]); + + for (int i = 0; i < 5; i++) { + char *day = strLower(days[i]); + + if (strcmp(day, arg) == 0) { + showUsage = false; + break; + } + + free(day); + } + free(arg); + } + + if (argc > 2 || showUsage) { + printf("Usage: %s [optional: day of the week]\n", argv[0]); exit(3); } @@ -178,7 +210,7 @@ main(int argc, char *argv[]) // Create text widget to display menu n = 0; - char *nl = getmenu(""); + char *nl = getmenu((argv[1]) ? argv[1] : ""); XtSetArg(args[n], XmNvalue, nl); n++; XtSetArg(args[n], XmNeditable, False); n++; XtSetArg(args[n], XmNcolumns, 80); n++; |