66#include < ctype.h>
77#include < stdlib.h>
88#include < unistd.h>
9+ #include < stdint.h>
910#include " ../src/ui/strlib.h"
1011
1112#define code_t int
@@ -45,6 +46,7 @@ struct spopr_keyword_s {
4546struct HelpItem {
4647 char package[20 ];
4748 char keyword[20 ];
49+ char type[20 ];
4850 char id[20 ];
4951 char signature[128 ];
5052 char help[1024 ];
@@ -177,6 +179,8 @@ bool readHelpReference(strlib::List<HelpItem *> *helpItems) {
177179 break ;
178180 case 1 :
179181 // type
182+ strncpy (item->type , lineBuffer + start, fieldLen);
183+ item->type [fieldLen] = ' \0 ' ;
180184 break ;
181185 case 2 :
182186 // keyword
@@ -215,6 +219,16 @@ bool readHelpReference(strlib::List<HelpItem *> *helpItems) {
215219 return true ;
216220}
217221
222+ uint32_t getHash (const char *key) {
223+ uint32_t hash, i;
224+ for (hash = i = 0 ; key[i] != ' \0 ' ; i++) {
225+ hash += tolower (key[i]);
226+ hash += (hash << 3 );
227+ hash ^= (hash >> 1 );
228+ }
229+ return hash;
230+ }
231+
218232int main (int argc, char *argv[]) {
219233 strlib::List<HelpItem *> helpItems;
220234 if (!readHelpReference (&helpItems)) {
@@ -228,12 +242,44 @@ int main(int argc, char *argv[]) {
228242 fprintf (stdout, " const char *signature;\n " );
229243 fprintf (stdout, " const char *help;\n " );
230244 fprintf (stdout, " } keyword_help[] = {\n " );
245+
246+ int max_keyword_len = 0 ;
231247 List_each (HelpItem *, it, helpItems) {
232248 HelpItem *item = (*it);
233249 fprintf (stdout, " {\" %s\" ,\" %s\" ,\" %s\" ,\" %s\" },\n " , item->package ,
234250 item->keyword , item->signature , item->help );
251+ int len = strlen (item->keyword );
252+ if (len > max_keyword_len) {
253+ max_keyword_len = len;
254+ }
235255 }
236256 fprintf (stdout, " };\n " );
237257 fprintf (stdout, " const int keyword_help_len = %d;\n " , helpItems.size ());
258+ fprintf (stdout, " const int keyword_max_len = %d;\n " , max_keyword_len);
259+
260+ int count = 0 ;
261+ fprintf (stdout, " const uint32_t keyword_hash_statement[] = {\n " );
262+ List_each (HelpItem *, it, helpItems) {
263+ HelpItem *item = (*it);
264+ if (strcasecmp (item->package , " Language" ) == 0 ) {
265+ count++;
266+ fprintf (stdout, " %uu,\n " , getHash (item->keyword ));
267+ }
268+ }
269+ fprintf (stdout, " };\n " );
270+ fprintf (stdout, " const int keyword_hash_statement_len = %d;\n " , count);
271+
272+ count = 0 ;
273+ fprintf (stdout, " const uint32_t keyword_hash_command[] = {\n " );
274+ List_each (HelpItem *, it, helpItems) {
275+ HelpItem *item = (*it);
276+ if (strcasecmp (item->package , " Language" ) != 0 ) {
277+ count++;
278+ fprintf (stdout, " %uu,\n " , getHash (item->keyword ));
279+ }
280+ }
281+ fprintf (stdout, " };\n " );
282+ fprintf (stdout, " const int keyword_hash_command_len = %d;\n " , count);
283+
238284 return 0 ;
239285}
0 commit comments