| ... | ... |
@@ -131,6 +131,22 @@ void draw(){
|
| 131 | 131 |
fflush(ttyout); |
| 132 | 132 |
} |
| 133 | 133 |
|
| 134 |
+void emit(){
|
|
| 135 |
+ int i; |
|
| 136 |
+ for(i = 0; i < choices_n; i++){
|
|
| 137 |
+ double rank = match(search, choices[i]); |
|
| 138 |
+ if(rank > 0){
|
|
| 139 |
+ /* Output the first match */ |
|
| 140 |
+ printf("%s\n", choices[i]);
|
|
| 141 |
+ exit(EXIT_SUCCESS); |
|
| 142 |
+ } |
|
| 143 |
+ } |
|
| 144 |
+ |
|
| 145 |
+ /* No match, output the query instead */ |
|
| 146 |
+ printf("%s\n", search);
|
|
| 147 |
+ exit(EXIT_SUCCESS); |
|
| 148 |
+} |
|
| 149 |
+ |
|
| 134 | 150 |
void run(){
|
| 135 | 151 |
draw(); |
| 136 | 152 |
char ch; |
| ... | ... |
@@ -153,7 +169,7 @@ void run(){
|
| 153 | 169 |
draw(); |
| 154 | 170 |
}else if(ch == 10){ /* Enter */
|
| 155 | 171 |
clear(); |
| 156 |
- exit(0); |
|
| 172 |
+ emit(); |
|
| 157 | 173 |
}else{
|
| 158 | 174 |
printf("'%c' (%i)\n", ch, ch);
|
| 159 | 175 |
} |