[master] 13baaf3 - Code cleanup: moved keyword/type arrays to StyleParse

GitHub FLTK Project   FLTK News RSS Feed  
  FLTK Apps      FLTK Library      Forums      Links     Login 
 All Forums  |  Back to fltk.commit  ]
 
Previous Message ]Next Message ]

[master] 13baaf3 - Code cleanup: moved keyword/type arrays to StyleParse "Greg Ercolano" 19:47 Oct 21 top right image
 
commit 13baaf3d5d61f1196c49a0cf6f3eb69c241c8dcf
Author:     Greg Ercolano <erco@seriss.com>
AuthorDate: Thu Sep 17 23:57:14 2020 -0700
Commit:     Greg Ercolano <erco@seriss.com>
CommitDate: Thu Sep 17 23:57:14 2020 -0700

    Code cleanup: moved keyword/type arrays to StyleParse
    
    Needed to do this to prevent lower StyleParse class from #including upper CodeEditor.

 fluid/CodeEditor.cxx | 105 -------------------------------------------------
 fluid/CodeEditor.h   |   4 --
 fluid/StyleParse.cxx | 109 +++++++++++++++++++++++++++++++++++++++++++++++++--
 3 files changed, 106 insertions(+), 112 deletions(-)

diff --git fluid/CodeEditor.cxx fluid/CodeEditor.cxx
index e6e8d76..c0e91dd 100644
--- fluid/CodeEditor.cxx
+++ 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 fluid/CodeEditor.h fluid/CodeEditor.h
index 617f614..7b79559 100644
--- fluid/CodeEditor.h
+++ 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 fluid/StyleParse.cxx fluid/StyleParse.cxx
index cbe0ba4..97b797e 100644
--- fluid/StyleParse.cxx
+++ 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);
Direct Link to Message ]
 
bottom left image   bottom right image
Previous Message ]Next Message ]
 
 

Comments are owned by the poster. All other content is copyright 1998-2020 by Bill Spitzak and others. This project is hosted by The FLTK Team. Please report site problems to 'erco@seriss.com'.