29
29
// Necessary includes
30
30
#include " Commander-API.hpp"
31
31
#include " Commander-API-Commands.hpp"
32
+ #include " Commander-Autocomplete.hpp"
33
+
32
34
33
35
34
36
// Use stdio as Channel.
@@ -43,18 +45,120 @@ bool cat_func( char *args, CommandCaller* caller );
43
45
bool dog_func ( char *args, CommandCaller* caller );
44
46
bool sum_func ( char *args, CommandCaller* caller );
45
47
46
- // Add echo and env commands to the API tree.
47
- Commander::systemCommand_t API_tree[] = {
48
- systemCommand ( " cat" , " Description for cat command." , cat_func ),
49
- systemCommand ( " dog" , " Description for dog command." , dog_func ),
50
- systemCommand ( " sum" , " This function sums two number from the argument list." , sum_func )
51
- };
52
-
53
48
char commandBuffer[ COMMAND_SIZE ];
54
49
55
50
char pipeBuffer[ COMMANDER_PIPE_BUFFER_SIZE ];
56
51
commanderPipeChannel pipeChannel;
52
+ /*
53
+ AutoComplete::TrieElement_t trie[ 9 ];
54
+ uint16_t trie_indexes_element_0[] = { 1, 2 };
55
+ uint16_t trie_indexes_element_1[] = { 3 };
56
+ uint16_t trie_indexes_element_2[] = { 4, 5 };
57
+ uint16_t trie_indexes_element_3[] = { 6, 7 };
58
+ uint16_t trie_indexes_element_4[] = { 8 };
59
+ */
60
+
61
+ // Generated with Commander Trie Generator
62
+ // Trie name: trie
63
+ uint16_t trie_element_0_indexes[] = { 1 };
64
+ uint16_t trie_element_1_indexes[] = { 2 };
65
+ uint16_t trie_element_2_indexes[] = { 3 , 4 , 33 , 38 };
66
+ uint16_t trie_element_4_indexes[] = { 5 , 9 , 19 };
67
+ uint16_t trie_element_5_indexes[] = { 6 };
68
+ uint16_t trie_element_6_indexes[] = { 7 };
69
+ uint16_t trie_element_7_indexes[] = { 8 };
70
+ uint16_t trie_element_9_indexes[] = { 10 };
71
+ uint16_t trie_element_10_indexes[] = { 11 };
72
+ uint16_t trie_element_11_indexes[] = { 12 };
73
+ uint16_t trie_element_12_indexes[] = { 13 };
74
+ uint16_t trie_element_13_indexes[] = { 14 };
75
+ uint16_t trie_element_14_indexes[] = { 15 };
76
+ uint16_t trie_element_15_indexes[] = { 16 };
77
+ uint16_t trie_element_16_indexes[] = { 17 };
78
+ uint16_t trie_element_17_indexes[] = { 18 };
79
+ uint16_t trie_element_19_indexes[] = { 20 };
80
+ uint16_t trie_element_20_indexes[] = { 21 };
81
+ uint16_t trie_element_21_indexes[] = { 22 };
82
+ uint16_t trie_element_22_indexes[] = { 23 };
83
+ uint16_t trie_element_23_indexes[] = { 24 };
84
+ uint16_t trie_element_24_indexes[] = { 25 };
85
+ uint16_t trie_element_25_indexes[] = { 26 };
86
+ uint16_t trie_element_26_indexes[] = { 27 };
87
+ uint16_t trie_element_27_indexes[] = { 28 };
88
+ uint16_t trie_element_28_indexes[] = { 29 };
89
+ uint16_t trie_element_29_indexes[] = { 30 };
90
+ uint16_t trie_element_30_indexes[] = { 31 };
91
+ uint16_t trie_element_31_indexes[] = { 32 };
92
+ uint16_t trie_element_33_indexes[] = { 34 };
93
+ uint16_t trie_element_34_indexes[] = { 35 };
94
+ uint16_t trie_element_35_indexes[] = { 36 };
95
+ uint16_t trie_element_36_indexes[] = { 37 };
96
+ uint16_t trie_element_38_indexes[] = { 39 };
97
+ uint16_t trie_element_39_indexes[] = { 40 };
98
+ uint16_t trie_element_40_indexes[] = { 41 };
99
+ uint16_t trie_element_41_indexes[] = { 42 };
100
+ uint16_t trie_element_42_indexes[] = { 43 };
101
+ uint16_t trie_element_43_indexes[] = { 44 };
102
+ uint16_t trie_element_44_indexes[] = { 45 };
103
+
104
+ AutoComplete::TrieElement_t trie[] = {
105
+ { ' \0 ' , false , 1 , trie_element_0_indexes },
106
+ { ' ' , false , 1 , trie_element_1_indexes },
107
+ { ' -' , false , 4 , trie_element_2_indexes },
108
+ { ' h' , true , 0 , NULL },
109
+ { ' -' , false , 3 , trie_element_4_indexes },
110
+ { ' h' , false , 1 , trie_element_5_indexes },
111
+ { ' e' , false , 1 , trie_element_6_indexes },
112
+ { ' l' , false , 1 , trie_element_7_indexes },
113
+ { ' p' , true , 0 , NULL },
114
+ { ' r' , false , 1 , trie_element_9_indexes },
115
+ { ' e' , false , 1 , trie_element_10_indexes },
116
+ { ' b' , false , 1 , trie_element_11_indexes },
117
+ { ' o' , false , 1 , trie_element_12_indexes },
118
+ { ' o' , false , 1 , trie_element_13_indexes },
119
+ { ' t' , true , 1 , trie_element_14_indexes },
120
+ { ' ' , false , 1 , trie_element_15_indexes },
121
+ { ' n' , false , 1 , trie_element_16_indexes },
122
+ { ' o' , false , 1 , trie_element_17_indexes },
123
+ { ' w' , true , 0 , NULL },
124
+ { ' d' , false , 1 , trie_element_19_indexes },
125
+ { ' i' , false , 1 , trie_element_20_indexes },
126
+ { ' s' , false , 1 , trie_element_21_indexes },
127
+ { ' p' , false , 1 , trie_element_22_indexes },
128
+ { ' l' , false , 1 , trie_element_23_indexes },
129
+ { ' a' , false , 1 , trie_element_24_indexes },
130
+ { ' y' , false , 1 , trie_element_25_indexes },
131
+ { ' ' , false , 1 , trie_element_26_indexes },
132
+ { ' "' , false , 1 , trie_element_27_indexes },
133
+ { ' T' , false , 1 , trie_element_28_indexes },
134
+ { ' e' , false , 1 , trie_element_29_indexes },
135
+ { ' x' , false , 1 , trie_element_30_indexes },
136
+ { ' t' , false , 1 , trie_element_31_indexes },
137
+ { ' "' , true , 0 , NULL },
138
+ { ' r' , true , 1 , trie_element_33_indexes },
139
+ { ' ' , false , 1 , trie_element_34_indexes },
140
+ { ' n' , false , 1 , trie_element_35_indexes },
141
+ { ' o' , false , 1 , trie_element_36_indexes },
142
+ { ' w' , true , 0 , NULL },
143
+ { ' d' , false , 1 , trie_element_38_indexes },
144
+ { ' ' , false , 1 , trie_element_39_indexes },
145
+ { ' "' , false , 1 , trie_element_40_indexes },
146
+ { ' T' , false , 1 , trie_element_41_indexes },
147
+ { ' e' , false , 1 , trie_element_42_indexes },
148
+ { ' x' , false , 1 , trie_element_43_indexes },
149
+ { ' t' , false , 1 , trie_element_44_indexes },
150
+ { ' "' , true , 0 , NULL }
151
+ };
57
152
153
+ AutoComplete help_test ( trie );
154
+
155
+
156
+ // Add echo and env commands to the API tree.
157
+ Commander::systemCommand_t API_tree[] = {
158
+ systemCommandWithHelp ( " cat" , " Description for cat command." , cat_func, &help_test ),
159
+ systemCommandWithHelp ( " dog" , " Description for dog command." , dog_func, &help_test ),
160
+ systemCommandWithHelp ( " sum" , " This function sums two number from the argument list." , sum_func, &help_test )
161
+ };
58
162
59
163
60
164
// Main program.
@@ -67,7 +171,6 @@ int main(){
67
171
68
172
}
69
173
70
-
71
174
// There is an option to attach a debug channel to Commander.
72
175
// It can be handy to find any problems during the initialization
73
176
// phase. In this example, we will use stdioChannel for this.
@@ -86,22 +189,51 @@ int main(){
86
189
// Commander at the beginning of your code to prevent stack-overlow.
87
190
commander.init ();
88
191
89
- commander.enablePipeModule ( pipeBuffer, &pipeChannel );
192
+ // commander.enablePipeModule( pipeBuffer, &pipeChannel );
90
193
91
194
stdioChannel.println ();
92
195
stdioChannel.println ( " ---- Init Finished ----" );
93
196
stdioChannel.println ();
94
197
95
- stdioChannel.println ( " Type something" );
96
- stdioChannel.print ( " $: " );
198
+ char buffer[ 200 ];
199
+ int buffer_size = sizeof ( buffer );
200
+ int num_of_hints;
201
+ int i;
202
+
203
+ num_of_hints = commander.generateHint ( " cat --reboot " , buffer, buffer_size );
204
+ stdioChannel.print ( " number of hints: " );
205
+ stdioChannel.println ( num_of_hints );
206
+ for ( i = 0 ; i < num_of_hints; i++ ){
207
+ stdioChannel.print ( " \t " );
208
+ stdioChannel.println ( commander.getHint ( i ) );
209
+ }
210
+
211
+ num_of_hints = commander.generateHint ( " cat --rebo" , buffer, buffer_size );
212
+ stdioChannel.print ( " number of hints: " );
213
+ stdioChannel.println ( num_of_hints );
214
+ for ( i = 0 ; i < num_of_hints; i++ ){
215
+ stdioChannel.print ( " \t " );
216
+ stdioChannel.println ( commander.getHint ( i, true ) );
217
+ }
218
+
219
+ num_of_hints = commander.generateHint ( " c" , buffer, buffer_size );
220
+ stdioChannel.print ( " number of hints: " );
221
+ stdioChannel.println ( num_of_hints );
222
+ for ( i = 0 ; i < num_of_hints; i++ ){
223
+ stdioChannel.print ( " \t " );
224
+ stdioChannel.println ( commander.getHint ( i, true ) );
225
+ }
226
+
227
+ // stdioChannel.println( "Type something" );
228
+ // stdioChannel.print( "$: " );
97
229
98
230
99
231
100
232
// Infinite loop.
101
233
while ( 1 ){
102
234
103
235
104
- commander.update ( commandBuffer, COMMAND_SIZE, &stdioChannel );
236
+ // commander.update( commandBuffer, COMMAND_SIZE, &stdioChannel );
105
237
106
238
107
239
0 commit comments