diff options
| author | Greg Ercolano <erco@seriss.com> | 2020-09-17 23:57:14 -0700 |
|---|---|---|
| committer | Greg Ercolano <erco@seriss.com> | 2020-11-01 12:16:23 -0800 |
| commit | 890533a863718ba10925a807b90e621d7a8cf24a (patch) | |
| tree | 3e78cb33ba143e4f478ca977e8ecd656f5fd5854 | |
| parent | cec029dbee435e7f608b9f6a4a3d8e98f2c5a398 (diff) | |
Code cleanup: moved keyword/type arrays to StyleParse
Needed to do this to prevent lower StyleParse class from #including upper CodeEditor.
| -rw-r--r-- | fluid/CodeEditor.cxx | 105 | ||||
| -rw-r--r-- | fluid/CodeEditor.h | 4 | ||||
| -rw-r--r-- | fluid/StyleParse.cxx | 109 |
3 files changed, 106 insertions, 112 deletions
diff --git a/fluid/CodeEditor.cxx b/fluid/CodeEditor.cxx index e6e8d762a..c0e91ddd4 100644 --- a/fluid/CodeEditor.cxx +++ b/fluid/CodeEditor.cxx @@ -36,84 +36,6 @@ Fl_Text_Display::Style_Table_Entry CodeEditor:: { FL_BLUE, FL_COURIER_BOLD, 11 } // G - Keywords }; -const char * const CodeEditor:: - code_keywords[] = { // Sorted list of C/C++ keywords... - "and", - "and_eq", - "asm", - "bitand", - "bitor", - "break", - "case", - "catch", - "compl", - "continue", - "default", - "delete", - "do", - "else", - "false", - "for", - "goto", - "if", - "new", - "not", - "not_eq", - "operator", - "or", - "or_eq", - "return", - "switch", - "template", - "this", - "throw", - "true", - "try", - "while", - "xor", - "xor_eq" - }; - -const char * const CodeEditor:: - code_types[] = { // Sorted list of C/C++ types... - "auto", - "bool", - "char", - "class", - "const", - "const_cast", - "double", - "dynamic_cast", - "enum", - "explicit", - "extern", - "float", - "friend", - "inline", - "int", - "long", - "mutable", - "namespace", - "private", - "protected", - "public", - "register", - "short", - "signed", - "sizeof", - "static", - "static_cast", - "struct", - "template", - "typedef", - "typename", - "union", - "unsigned", - "virtual", - "void", - "volatile" - }; - // attempt to make the fluid code editor widget honour textsize setting void CodeEditor::textsize(Fl_Fontsize s) { Fl_Text_Editor::textsize(s); // call base class method @@ -125,31 +47,6 @@ void CodeEditor::textsize(Fl_Fontsize s) { } // textsize -// 'compare_keywords()' - Compare two keywords... -extern "C" { - static int compare_keywords(const void *a, const void *b) { - return strcmp(*((const char **)a), *((const char **)b)); - } -} - -// See if 'find' is a C/C++ keyword. -// Refer to bsearch(3) for return value. -// -void* CodeEditor::search_keywords(char *find) { - return bsearch(&find, code_keywords, - sizeof(code_keywords) / sizeof(code_keywords[0]), - sizeof(code_keywords[0]), compare_keywords); -} - -// See if 'find' is a C/C++ type. -// Refer to bsearch(3) for return value. -// -void* CodeEditor::search_types(char *find) { - return bsearch(&find, code_types, - sizeof(code_types) / sizeof(code_types[0]), - sizeof(code_types[0]), compare_keywords); -} - // 'style_parse()' - Parse text and produce style data. void CodeEditor::style_parse(const char *in_tbuff, // text buffer to parse char *in_sbuff, // style buffer we modify @@ -239,9 +136,7 @@ void CodeEditor::style_update(int pos, int nInserted, int nDeleted, text = editor->mBuffer->text_range(0, len); style = editor->mStyleBuffer->text_range(0, len); - //DEBUG printf("BEFORE:\n"); show_buffer(editor); printf("-- END BEFORE\n"); style_parse(text, style, editor->mBuffer->length(), 'A'); - //DEBUG printf("AFTER:\n"); show_buffer(editor); printf("-- END AFTER\n"); editor->mStyleBuffer->replace(0, len, style); editor->redisplay_range(0, len); diff --git a/fluid/CodeEditor.h b/fluid/CodeEditor.h index 617f61413..7b7955991 100644 --- a/fluid/CodeEditor.h +++ b/fluid/CodeEditor.h @@ -32,10 +32,6 @@ class CodeEditor : public Fl_Text_Editor { static Fl_Text_Display::Style_Table_Entry styletable[]; - static const char * const code_keywords[]; - static const char * const code_types[]; - static void* search_types(char *find); - static void* search_keywords(char *find); // 'style_parse()' - Parse text and produce style data. static void style_parse(const char *tbuff, char *sbuff, int len, char style); diff --git a/fluid/StyleParse.cxx b/fluid/StyleParse.cxx index cbe0ba408..97b797eaf 100644 --- a/fluid/StyleParse.cxx +++ b/fluid/StyleParse.cxx @@ -17,8 +17,111 @@ #include <stdio.h> #include <string.h> #include <ctype.h> +#include <stdlib.h> // bsearch() #include "StyleParse.h" -#include "CodeEditor.h" + +// Sorted list of C/C++ keywords... +static const char * const code_keywords[] = { + "and", + "and_eq", + "asm", + "bitand", + "bitor", + "break", + "case", + "catch", + "compl", + "continue", + "default", + "delete", + "do", + "else", + "false", + "for", + "goto", + "if", + "new", + "not", + "not_eq", + "operator", + "or", + "or_eq", + "return", + "switch", + "template", + "this", + "throw", + "true", + "try", + "while", + "xor", + "xor_eq" +}; + +// Sorted list of C/C++ types... +static const char * const code_types[] = { + "auto", + "bool", + "char", + "class", + "const", + "const_cast", + "double", + "dynamic_cast", + "enum", + "explicit", + "extern", + "float", + "friend", + "inline", + "int", + "long", + "mutable", + "namespace", + "private", + "protected", + "public", + "register", + "short", + "signed", + "sizeof", + "static", + "static_cast", + "struct", + "template", + "typedef", + "typename", + "union", + "unsigned", + "virtual", + "void", + "volatile" +}; + +// 'compare_keywords()' - Compare two keywords... +extern "C" { + static int compare_keywords(const void *a, const void *b) { + return strcmp(*((const char **)a), *((const char **)b)); + } +} + +// See if 'find' is a C/C++ keyword. +// Refer to bsearch(3) for return value. +// +static void* search_keywords(char *find) { + return bsearch(&find, code_keywords, + sizeof(code_keywords) / sizeof(code_keywords[0]), + sizeof(code_keywords[0]), compare_keywords); +} + +// See if 'find' is a C/C++ type. +// Refer to bsearch(3) for return value. +// +static void* search_types(char *find) { + return bsearch(&find, code_types, + sizeof(code_types) / sizeof(code_types[0]), + sizeof(code_types[0]), compare_keywords); +} // Handle style parsing over a character // Handles updating col counter when \n encountered. @@ -145,10 +248,10 @@ int StyleParse::parse_keyword() { buffer_keyword(); char *key = keyword; // C/C++ type? (void, char..) - if ( CodeEditor::search_types(key) ) + if ( search_types(key) ) return parse_over_key(key, 'F'); // 'type' style // C/C++ Keyword? (switch, return..) - else if ( CodeEditor::search_keywords(key) ) + else if ( search_keywords(key) ) return parse_over_key(key, 'G'); // 'keyword' style // Not a type or keyword? Parse over it return parse_over_key(key, style); |
