}
+/* Find if a number is in a given range. */
+int range(int rstart, int rend, int i)
+{
+ if ( (rstart <= i) && (i <= rend) ) return 1;
+ else return 0;
+
+}
+
+
+/* Assign a type depending on the range that a */
+/* number is in. */
+int type(int i)
+{
+ int ret;
+
+ if ( range(0, 9, i) == 1 ) ret = 1;
+ else if ( range(10, 10, i) == 1 ) ret = 2;
+ else if ( range(27, 27, i) == 1 ) ret = 3;
+ else if ( range(32, 126, i) == 1 ) ret = 4;
+ else if ( range(127, 127, i) == 1 ) ret = 5;
+ else ret = 6;
+
+ return ret;
+
+}
+
/* Function for special key combinations */
/* (Ctrl, Alt, function keys. */
static struct termios old, new;
/* Initialize new terminal i/o settings */
-void initTermios(int echo) {
+void initTermios(int echo)
+{
tcgetattr(0, &old); /* grab old terminal i/o settings */
new = old; /* make new settings same as old settings */
new.c_lflag &= ~ICANON; /* disable buffered i/o */
/* Restore old terminal i/o settings */
-void resetTermios(void) {
+void resetTermios(void)
+{
tcsetattr(0, TCSANOW, &old);
}
/* Alt keys are just esc then key (e.g. Alt-g is esc g ). */
/* Ctrl (then letter) keys are just Dec 1 to Dec 26 */
+/* TO DO: Use the helper function range */
+/* ( range(rstart, rend, val). ) */
+/* to handle entire ranges at once. */
+
+
void keyhandler(buf b)
{
int i = getch();
- switch(i)
+ int t = type(i);
+
+ switch(t)
{
+
case (1): break; /* Ctrl a */
case (2): break; /* Ctrl b */
case (3): break; /* Ctrl c */
-
- case (10): enter(); /* Enter */
-
- case (27): spec(i); break; /* esc */
-
- case (32): printf("%c", i); break; /* Printable chars. */
- case (33): printf("%c", i); break; /* Printable chars. */
- case (34): printf("%c", i); break; /* Printable chars. */
-
- case (65): printf("%c", i); break; /* "A" */
- case (66): printf("%c", i); break; /* "B" */
- case (67): printf("%c", i); break; /* "C" */
- case (68): printf("%c", i); break; /* "D" */
- case (69): printf("%c", i); break; /* "E" */
- case (70): printf("%c", i); break; /* "F" */
-
- case (97): printf("%c", i); break; /* "a" */
- case (98): printf("%c", i); break; /* "b" */
- case (99): printf("%c", i); break; /* "c" */
- case (100): printf("%c", i); break; /* "d" */
- case (101): printf("%c", i); break; /* "e" */
- case (102): printf("%c", i); break; /* "f" */
-
- case (126): printf("%c", i); break; /* "~" */
-
- case (127): delch(b); break;
-
- default: break; /* stuff(); */
+ case (4): printf("%c", i); break; /* Printable chars. */
+ case (5): delch(b); break;
+ case (6): break;
+ default: break;
+
}
-}
+}
+
+
--- /dev/null
+
+
+/* range.c */
+
+/* See if an int is in a given range. */
+
+
+
+#include <string.h>
+#include <stdio.h>
+#include <stdlib.h>
+
+
+
+/* Find if a number is in a given range. */
+int range(int rstart, int rend, int i)
+{
+ if ( (rstart <= i) && (i <= rend) ) return 1;
+ else return 0;
+
+}
+
+
+
+int main()
+{
+
+/* Within the range. */
+int a = range(0, 9, 5);
+int b = range(0, 9, 0);
+int c = range(0, 9, 9);
+int d = range(20, 40, 32);
+
+
+/* Outside the range. */
+int e = range(0, 9, -15);
+int f = range(20, 40, 75);
+int g = range(50, 80, 91);
+
+printf("%d %d %d %d %d %d %d \n", a, b, c, d, e, f, g);
+
+
+return 0;
+
+
+}
+
+
+
+
+
+
+
+