]> pd.if.org Git - pd_readline/blob - funcs.c
8ac14c685c0d129e797959084f007ad2ee7a3d14
[pd_readline] / funcs.c
1
2
3 /*  funcs.c                                          */ 
4 /*  Functions to handle cursor movement for          */ 
5 /*  pd_readline.                                     */      
6 /*  This code is released to the public domain.      */ 
7 /*  "Share and enjoy...."  ;)                        */  
8 /*  See the UNLICENSE file for details.              */ 
9
10
11 #include <string.h>   
12 #include <stdio.h> 
13 #include <stdlib.h> 
14 #include "pd_readline.h"  
15
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.  */     
20
21
22 /* Move up in history list. */ 
23 buf up(int i) 
24
25   
26
27
28
29
30
31 /* Move down in history list. */ 
32 buf down(int i) 
33
34
35
36
37
38
39 /* Move cursor to left. */ 
40 buf left(buf b) 
41 {
42
43
44
45
46
47 /* Move cursor to right. */ 
48 buf right(buf b) 
49
50
51
52
53
54
55 /* Delete a char. */ 
56 buf delch(buf b) 
57
58
59
60
61
62
63 /* Insert a char. */ 
64 buf insch(buf b) 
65
66
67
68
69
70
71 void enter(void) 
72
73         printf("Enter ");               
74 }       
75
76
77 /* Find if a number is in a given range. */ 
78 int range(int rstart, int rend, int i)
79 {
80    if ( (rstart <= i) && (i <= rend) ) return 1;
81    else return 0;       
82         
83 }       
84
85
86 /* Assign a type depending on the range that a  */ 
87 /* number is in.                                */ 
88 int type(int i)
89
90    int ret; 
91    
92         if ( range(0, 9, i) == 1 )       ret = 1; 
93    else if ( range(10, 10, i) == 1 )     ret = 2; 
94    else if ( range(27, 27, i) == 1 )     ret = 3; 
95    else if ( range(32, 126, i) == 1 )    ret = 4;          
96    else if ( range(127, 127, i) == 1 )   ret = 5;
97    else ret = 6;           
98     
99    return ret; 
100    
101 }     
102         
103
104 /*  Function for special key combinations  */ 
105 /*  (Ctrl, Alt, function keys.             */ 
106 void spec(void)
107
108         
109   int j = getch();  
110    
111        if ( ( j == 65 ) )  printf("Up ");  
112   else if ( ( j == 66 ) )  printf("Down "); 
113   else if ( ( j == 67 ) )  printf("Right "); 
114   else if ( ( j == 68 ) )  printf("Left "); 
115                 
116 }       
117
118
119
120
121