4 /* Functions to handle cursor movement for */
6 /* This code is released to the public domain. */
7 /* "Share and enjoy...." ;) */
8 /* See the UNLICENSE file for details. */
14 #include "pd_readline.h"
16 /* Note - make the up and down funcs return a buffer. */
17 /* A line from the history file can be put into the */
18 /* array member of the buffer. */
19 /* Also test for the top and bottom of the history file. */
29 /* Display a buffer */
32 printf("%s", b.array);
37 /* Enter a char into a buffer and display the buffer array. */
47 memset(&b.array[0], 0, sizeof(b.array) );
58 /* Return a line from hist. */
62 memcpy(&b.array[0], h.array[h.curindex], 80);
68 /* Move up in history list. */
74 if ( (h.curindex > 0) )
77 memset(&b.array[0], 0, sizeof(b.array) );
78 memcpy(&b.array[0], h.array[h.curindex], 80);
88 /* Move down in history list. */
94 if ( (h.curindex < 19) )
97 memset(&b.array[0], 0, sizeof(b.array) );
98 memcpy(&b.array[0], h.array[h.curindex], 80);
108 /* Move cursor to left. */
116 /* Move cursor to right. */
146 /* Find if a number is in a given range. */
147 int range(int rstart, int rend, int i)
149 if ( (rstart <= i) && (i <= rend) ) return 1;
155 /* Assign a type depending on the range that a */
161 if ( range(0, 9, i) == 1 ) ret = 1;
162 else if ( range(10, 10, i) == 1 ) ret = 2;
163 else if ( range(27, 27, i) == 1 ) ret = 3;
164 else if ( range(32, 126, i) == 1 ) ret = 4;
165 else if ( range(127, 127, i) == 1 ) ret = 5;
173 /* Function for special key combinations */
174 /* (Ctrl, Alt, function keys. */
180 if ( ( j == 65 ) ) up(h);
181 else if ( ( j == 66 ) ) down(h);
182 else if ( ( j == 67 ) ) printf("Right ");
183 else if ( ( j == 68 ) ) printf("Left ");