X-Git-Url: https://pd.if.org/git/?a=blobdiff_plain;f=funcs.c;h=3623220228d841bc52735d64f52f04e18f665323;hb=d56fdb0ce92c92e27ef45a8315ff26c272a1f23d;hp=f298d7a41497952d5f797f45782a0bd560a7a5ed;hpb=2aac28bc15a87f5fde5daa83352f9f9b675fc635;p=pd_readline diff --git a/funcs.c b/funcs.c index f298d7a..3623220 100644 --- a/funcs.c +++ b/funcs.c @@ -18,21 +18,90 @@ /* array member of the buffer. */ /* Also test for the top and bottom of the history file. */ +/* Error function. */ +void error(void) +{ + printf("Error \n"); +} -/* Move up in history list. */ -buf up(int i) + + +/* Display a buffer */ +void show(buf b) { - + printf("%s", b.array); +} + +/* Enter a char into a buffer and display the buffer array. */ +buf set(buf b, int i) +{ + if ( (b.index < 80) ) + { + b.array[b.index] = i; + b.index += 1 ; + } + else + { + memset(&b.array[0], 0, sizeof(b.array) ); + b.array[0] = i; + b.index += 1 ; + } + + show(b); + return b; + } -/* Move down in history list. */ -buf down(int i) +/* Return a line from hist. */ +buf get(hist h) +{ + buf b; + memcpy(&b.array[0], h.array[h.curindex], 80); + return b; +} + + + +/* Move up in history list. */ +hist up(hist h) { + + buf b; + + if ( (h.curindex > 0) ) + { + h.curindex -= 1; + memset(&b.array[0], 0, sizeof(b.array) ); + memcpy(&b.array[0], h.array[h.curindex], 80); + show(b); + return h; + } + + else error(); + +} +/* Move down in history list. */ +hist down(hist h) +{ + + buf b; + + if ( (h.curindex < 19) ) + { + h.curindex += 1; + memset(&b.array[0], 0, sizeof(b.array) ); + memcpy(&b.array[0], h.array[h.curindex], 80); + show(b); + return h; + } + + else error(); + } @@ -103,11 +172,16 @@ int type(int i) /* Function for special key combinations */ /* (Ctrl, Alt, function keys. */ -int spec(int i) +void spec(hist h) { - - + int j = getch(); + + if ( ( j == 65 ) ) up(h); + else if ( ( j == 66 ) ) down(h); + else if ( ( j == 67 ) ) printf("Right "); + else if ( ( j == 68 ) ) printf("Left "); + }