mirror of
https://github.com/fltk/fltk.git
synced 2026-05-30 13:05:35 +08:00
Code cleanup: moved keyword/type arrays to StyleParse
Needed to do this to prevent lower StyleParse class from #including upper CodeEditor.
This commit is contained in:
@@ -36,84 +36,6 @@ Fl_Text_Display::Style_Table_Entry CodeEditor::
|
|||||||
{ FL_BLUE, FL_COURIER_BOLD, 11 } // G - Keywords
|
{ 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
|
// attempt to make the fluid code editor widget honour textsize setting
|
||||||
void CodeEditor::textsize(Fl_Fontsize s) {
|
void CodeEditor::textsize(Fl_Fontsize s) {
|
||||||
Fl_Text_Editor::textsize(s); // call base class method
|
Fl_Text_Editor::textsize(s); // call base class method
|
||||||
@@ -125,31 +47,6 @@ void CodeEditor::textsize(Fl_Fontsize s) {
|
|||||||
} // textsize
|
} // 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.
|
// 'style_parse()' - Parse text and produce style data.
|
||||||
void CodeEditor::style_parse(const char *in_tbuff, // text buffer to parse
|
void CodeEditor::style_parse(const char *in_tbuff, // text buffer to parse
|
||||||
char *in_sbuff, // style buffer we modify
|
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);
|
text = editor->mBuffer->text_range(0, len);
|
||||||
style = editor->mStyleBuffer->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');
|
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->mStyleBuffer->replace(0, len, style);
|
||||||
editor->redisplay_range(0, len);
|
editor->redisplay_range(0, len);
|
||||||
|
|||||||
@@ -32,10 +32,6 @@
|
|||||||
|
|
||||||
class CodeEditor : public Fl_Text_Editor {
|
class CodeEditor : public Fl_Text_Editor {
|
||||||
static Fl_Text_Display::Style_Table_Entry styletable[];
|
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.
|
// 'style_parse()' - Parse text and produce style data.
|
||||||
static void style_parse(const char *tbuff, char *sbuff, int len, char style);
|
static void style_parse(const char *tbuff, char *sbuff, int len, char style);
|
||||||
|
|||||||
+106
-3
@@ -17,8 +17,111 @@
|
|||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
#include <ctype.h>
|
#include <ctype.h>
|
||||||
|
#include <stdlib.h> // bsearch()
|
||||||
#include "StyleParse.h"
|
#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
|
// Handle style parsing over a character
|
||||||
// Handles updating col counter when \n encountered.
|
// Handles updating col counter when \n encountered.
|
||||||
@@ -145,10 +248,10 @@ int StyleParse::parse_keyword() {
|
|||||||
buffer_keyword();
|
buffer_keyword();
|
||||||
char *key = keyword;
|
char *key = keyword;
|
||||||
// C/C++ type? (void, char..)
|
// C/C++ type? (void, char..)
|
||||||
if ( CodeEditor::search_types(key) )
|
if ( search_types(key) )
|
||||||
return parse_over_key(key, 'F'); // 'type' style
|
return parse_over_key(key, 'F'); // 'type' style
|
||||||
// C/C++ Keyword? (switch, return..)
|
// C/C++ Keyword? (switch, return..)
|
||||||
else if ( CodeEditor::search_keywords(key) )
|
else if ( search_keywords(key) )
|
||||||
return parse_over_key(key, 'G'); // 'keyword' style
|
return parse_over_key(key, 'G'); // 'keyword' style
|
||||||
// Not a type or keyword? Parse over it
|
// Not a type or keyword? Parse over it
|
||||||
return parse_over_key(key, style);
|
return parse_over_key(key, style);
|
||||||
|
|||||||
Reference in New Issue
Block a user