]> pd.if.org Git - pd_readline/blob - funcs.c
More work.
[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 /*  Display a buffer  */ 
23 void show(buf b)
24
25    printf("%s", b.array);                       
26 }       
27
28
29
30 /* Enter a char into a buffer and display the buffer array.  */ 
31 buf set(buf b, int i)
32
33   if ( (b.index < 80)  )  
34     { 
35            b.array[b.index] = i;        
36            b.index += 1 ;
37     } 
38   else
39     { 
40            memset(b.array[0], 0, sizeof(b.array) ); 
41            b.array[0] = i;
42            b.index += 1 ;               
43     }           
44   
45   show(b); 
46   return b;     
47         
48
49
50
51
52 /* Move up in history list. */ 
53 buf up(buf b) 
54
55   
56
57
58
59
60
61 /* Move down in history list. */ 
62 buf down(buf b) 
63
64
65
66
67
68
69 /* Move cursor to left. */ 
70 buf left(buf b) 
71 {
72
73
74
75
76
77 /* Move cursor to right. */ 
78 buf right(buf b) 
79
80
81
82
83
84
85 /* Delete a char. */ 
86 buf delch(buf b) 
87
88
89
90
91
92
93 /* Insert a char. */ 
94 buf insch(buf b) 
95
96
97
98
99
100
101 void enter(void) 
102
103         printf("Enter ");               
104 }       
105
106
107 /* Find if a number is in a given range. */ 
108 int range(int rstart, int rend, int i)
109 {
110    if ( (rstart <= i) && (i <= rend) ) return 1;
111    else return 0;       
112         
113 }       
114
115
116 /* Assign a type depending on the range that a  */ 
117 /* number is in.                                */ 
118 int type(int i)
119
120    int ret; 
121    
122         if ( range(0, 9, i) == 1 )       ret = 1; 
123    else if ( range(10, 10, i) == 1 )     ret = 2; 
124    else if ( range(27, 27, i) == 1 )     ret = 3; 
125    else if ( range(32, 126, i) == 1 )    ret = 4;          
126    else if ( range(127, 127, i) == 1 )   ret = 5;
127    else ret = 6;           
128     
129    return ret; 
130    
131 }     
132         
133
134 /*  Function for special key combinations  */ 
135 /*  (Ctrl, Alt, function keys.             */ 
136 void spec(void)
137
138         
139   int j = getch();  
140    
141        if ( ( j == 65 ) )  printf("Up ");  
142   else if ( ( j == 66 ) )  printf("Down "); 
143   else if ( ( j == 67 ) )  printf("Right "); 
144   else if ( ( j == 68 ) )  printf("Left "); 
145                 
146 }       
147
148
149
150
151