summaryrefslogtreecommitdiff
path: root/dumb/dumb-kode54/make/dumbask.c
diff options
context:
space:
mode:
authorGravatar Alexey Yakovenko <wakeroid@gmail.com>2009-07-19 11:31:03 +0200
committerGravatar Alexey Yakovenko <wakeroid@gmail.com>2009-07-19 11:31:03 +0200
commitbe5c03f0510d62bb86c9a11b77977123239b2c7e (patch)
tree33ffc42a8135109e7ca9185072c61d21ddcb3289 /dumb/dumb-kode54/make/dumbask.c
parentde9ab352f11a333eaf49030e581bb911b30abb3c (diff)
switched to kode54's version of dumb
Diffstat (limited to 'dumb/dumb-kode54/make/dumbask.c')
-rw-r--r--dumb/dumb-kode54/make/dumbask.c30
1 files changed, 30 insertions, 0 deletions
diff --git a/dumb/dumb-kode54/make/dumbask.c b/dumb/dumb-kode54/make/dumbask.c
new file mode 100644
index 00000000..8c1b3757
--- /dev/null
+++ b/dumb/dumb-kode54/make/dumbask.c
@@ -0,0 +1,30 @@
+#include <stdio.h>
+#include <ctype.h>
+
+
+int main(int argc, const char *const argv[])
+{
+ const char *message = argv[1];
+ const char *options;
+
+ if (!message) {
+ fprintf(stderr,
+ "dumbask: asks the user a question.\n"
+ "Specify a message as the first argument (quoted!).\n"
+ "You may optionally specify the choices as the second argument.\n"
+ "Default choices are YN. Exit code is 0 for first, 1 for second, etc.\n");
+ return 0;
+ }
+
+ options = argv[2] ? : "YN"; /* I _had_ to use a GNU Extension _somewhere_! */
+
+ printf("%s", argv[1]);
+
+ for (;;) {
+ char c = toupper(getchar());
+ int i;
+ for (i = 0; options[i]; i++)
+ if (c == toupper(options[i]))
+ return i;
+ }
+}