Revision: 15837
          
http://projects.blender.org/plugins/scmsvn/viewcvs.php?view=rev&root=bf-blender&revision=15837
Author:   quorn
Date:     2008-07-28 13:05:35 +0200 (Mon, 28 Jul 2008)

Log Message:
-----------
Complete rewrite of syntax highlighting and formatting. Some improvements:
 - Takes less than half the time to format a full document
 - Where possible only the required lines are re-parsed when text is changed 
(was the whole file, for every key press!)
 - Memory is allocated in one place only (there were all sorts of problems here)
 - Should be easily extensible for other scripting languages
 - Lots of comments to make it very easy to follow / change
 - def and class are now properly coloured. They had a theme colour but the 
checks didn't work.

Modified Paths:
--------------
    branches/soc-2008-quorn/source/blender/blenkernel/intern/text.c
    branches/soc-2008-quorn/source/blender/include/BIF_drawtext.h
    branches/soc-2008-quorn/source/blender/makesdna/DNA_text_types.h
    branches/soc-2008-quorn/source/blender/src/drawtext.c
    branches/soc-2008-quorn/source/blender/src/header_text.c

Modified: branches/soc-2008-quorn/source/blender/blenkernel/intern/text.c
===================================================================
--- branches/soc-2008-quorn/source/blender/blenkernel/intern/text.c     
2008-07-28 11:01:34 UTC (rev 15836)
+++ branches/soc-2008-quorn/source/blender/blenkernel/intern/text.c     
2008-07-28 11:05:35 UTC (rev 15837)
@@ -175,7 +175,7 @@
 
        tmp= (TextLine*) MEM_mallocN(sizeof(TextLine), "textline");
        tmp->line= (char*) MEM_mallocN(1, "textline_string");
-       tmp->format= (char*) MEM_mallocN(2, "Syntax_format");
+       tmp->format= NULL;
        
        tmp->line[0]=0;
        tmp->len= 0;
@@ -271,7 +271,7 @@
                if (buffer[i]=='\n') {
                        tmp= (TextLine*) MEM_mallocN(sizeof(TextLine), 
"textline");
                        tmp->line= (char*) MEM_mallocN(llen+1, 
"textline_string");
-                       tmp->format= (char*) MEM_mallocN(llen+2, 
"Syntax_format");
+                       tmp->format= NULL;
                        
                        if(llen) memcpy(tmp->line, &buffer[i-llen], llen);
                        tmp->line[llen]=0;
@@ -291,7 +291,7 @@
        if (llen!=0 || text->nlines==0) {
                tmp= (TextLine*) MEM_mallocN(sizeof(TextLine), "textline");
                tmp->line= (char*) MEM_mallocN(llen+1, "textline_string");
-               tmp->format= (char*) MEM_mallocN(llen+2, "Syntax_format");
+               tmp->format= NULL;
                
                if(llen) memcpy(tmp->line, &buffer[i-llen], llen);
 
@@ -367,7 +367,7 @@
                if (buffer[i]=='\n') {
                        tmp= (TextLine*) MEM_mallocN(sizeof(TextLine), 
"textline");
                        tmp->line= (char*) MEM_mallocN(llen+1, 
"textline_string");
-                       tmp->format= (char*) MEM_mallocN(llen+2, 
"Syntax_format");
+                       tmp->format= NULL;
                        
                        if(llen) memcpy(tmp->line, &buffer[i-llen], llen);
                        tmp->line[llen]=0;
@@ -387,7 +387,7 @@
        if (llen!=0 || ta->nlines==0) {
                tmp= (TextLine*) MEM_mallocN(sizeof(TextLine), "textline");
                tmp->line= (char*) MEM_mallocN(llen+1, "textline_string");
-               tmp->format= (char*) MEM_mallocN(llen+2, "Syntax_format");
+               tmp->format= NULL;
                
                if(llen) memcpy(tmp->line, &buffer[i-llen], llen);
 
@@ -430,7 +430,7 @@
        while (line) {
                tmp= (TextLine*) MEM_mallocN(sizeof(TextLine), "textline");
                tmp->line= MEM_mallocN(line->len+1, "textline_string");
-               tmp->format= MEM_mallocN(line->len+2, "Syntax_format");
+               tmp->format= NULL;
                
                strcpy(tmp->line, line->line);
 
@@ -451,14 +451,14 @@
 /* Editing utility functions */
 /*****************************/
 
-static void make_new_line (TextLine *line, char *newline, char *newformat) 
+static void make_new_line (TextLine *line, char *newline) 
 {
        if (line->line) MEM_freeN(line->line);
        if (line->format) MEM_freeN(line->format);
        
        line->line= newline;
        line->len= strlen(newline);
-       line->format= newformat;
+       line->format= NULL;
 }
 
 static TextLine *txt_new_line(char *str)
@@ -469,7 +469,7 @@
        
        tmp= (TextLine *) MEM_mallocN(sizeof(TextLine), "textline");
        tmp->line= MEM_mallocN(strlen(str)+1, "textline_string");
-       tmp->format= MEM_mallocN(strlen(str)+2, "Syntax_format");
+       tmp->format= NULL;
        
        strcpy(tmp->line, str);
        
@@ -487,7 +487,7 @@
        
        tmp= (TextLine *) MEM_mallocN(sizeof(TextLine), "textline");
        tmp->line= MEM_mallocN(n+1, "textline_string");
-       tmp->format= MEM_mallocN(n+2, "Syntax_format");
+       tmp->format= NULL;
        
        BLI_strncpy(tmp->line, str, n+1);
        
@@ -948,7 +948,7 @@
 static void txt_delete_sel (Text *text)
 {
        TextLine *tmpl;
-       char *buf, *format;
+       char *buf;
        
        if (!text) return;
        if (!text->curl) return;
@@ -965,13 +965,12 @@
        }
 
        buf= MEM_mallocN(text->curc+(text->sell->len - text->selc)+1, 
"textline_string");
-       format= MEM_mallocN(text->curc+(text->sell->len - text->selc)+2, 
"Syntax_format");
        
        strncpy(buf, text->curl->line, text->curc);
        strcpy(buf+text->curc, text->sell->line + text->selc);
        buf[text->curc+(text->sell->len - text->selc)]=0;
 
-       make_new_line(text->curl, buf, format);
+       make_new_line(text->curl, buf);
        
        tmpl= text->sell;
        while (tmpl != text->curl) {
@@ -2045,7 +2044,7 @@
 void txt_split_curline (Text *text) 
 {
        TextLine *ins;
-       char *left, *right, *fleft, *fright;
+       char *left, *right;
        
        if (!text) return;
        if (!text->curl) return;
@@ -2055,12 +2054,10 @@
        /* Make the two half strings */
 
        left= MEM_mallocN(text->curc+1, "textline_string");
-       fleft= MEM_mallocN(text->curc+2, "Syntax_format");
        if (text->curc) memcpy(left, text->curl->line, text->curc);
        left[text->curc]=0;
        
        right= MEM_mallocN(text->curl->len - text->curc+1, "textline_string");
-       fright= MEM_mallocN(text->curl->len - text->curc+2, "Syntax_format");
        if (text->curl->len - text->curc) memcpy(right, 
text->curl->line+text->curc, text->curl->len-text->curc);
        right[text->curl->len - text->curc]=0;
 
@@ -2071,11 +2068,11 @@
        
        ins= MEM_mallocN(sizeof(TextLine), "textline");
        ins->line= left;
-       ins->format= fleft;
+       ins->format= NULL;
        ins->len= text->curc;
        
        text->curl->line= right;
-       text->curl->format= fright;
+       text->curl->format= NULL;
        text->curl->len= text->curl->len - text->curc;
        
        BLI_insertlinkbefore(&text->lines, text->curl, ins);    
@@ -2107,19 +2104,18 @@
 
 static void txt_combine_lines (Text *text, TextLine *linea, TextLine *lineb)
 {
-       char *tmp, *format;
+       char *tmp;
        
        if (!text) return;
        
        if(!linea || !lineb) return;
        
        tmp= MEM_mallocN(linea->len+lineb->len+1, "textline_string");
-       format= MEM_mallocN(linea->len+lineb->len+1, "Syntax_format");
        
        strcpy(tmp, linea->line);
        strcat(tmp, lineb->line);
 
-       make_new_line(linea, tmp, format);
+       make_new_line(linea, tmp);
        
        txt_delete_line(text, lineb); 
        
@@ -2217,7 +2213,7 @@
 int txt_add_char (Text *text, char add) 
 {
        int len;
-       char *tmp, *format;
+       char *tmp;
        
        if (!text) return 0;
        if (!text->curl) return 0;
@@ -2230,7 +2226,6 @@
        txt_delete_sel(text);
        
        tmp= MEM_mallocN(text->curl->len+2, "textline_string");
-       format= MEM_mallocN(text->curl->len+4, "Syntax_format");
        
        if(text->curc) memcpy(tmp, text->curl->line, text->curc);
        tmp[text->curc]= add;
@@ -2238,7 +2233,7 @@
        len= text->curl->len - text->curc;
        if(len>0) memcpy(tmp+text->curc+1, text->curl->line+text->curc, len);
        tmp[text->curl->len+1]=0;
-       make_new_line(text->curl, tmp, format);
+       make_new_line(text->curl, tmp);
                
        text->curc++;
 
@@ -2282,7 +2277,7 @@
 void indent(Text *text)
 {
        int len, num;
-       char *tmp, *format;
+       char *tmp;
        char add = '\t';
        
        if (!text) return;
@@ -2293,7 +2288,6 @@
        while (TRUE)
        {
                tmp= MEM_mallocN(text->curl->len+2, "textline_string");
-               format= MEM_mallocN(text->curl->len+3, "Syntax_format");
                
                text->curc = 0; 
                if(text->curc) memcpy(tmp, text->curl->line, text->curc);
@@ -2303,7 +2297,7 @@
                if(len>0) memcpy(tmp+text->curc+1, text->curl->line+text->curc, 
len);
                tmp[text->curl->len+1]=0;
 
-               make_new_line(text->curl, tmp, format);
+               make_new_line(text->curl, tmp);
                        
                text->curc++;
                
@@ -2384,7 +2378,7 @@
 void comment(Text *text)
 {
        int len, num;
-       char *tmp, *format;
+       char *tmp;
        char add = '#';
        
        if (!text) return;
@@ -2395,7 +2389,6 @@
        while (TRUE)
        {
                tmp= MEM_mallocN(text->curl->len+2, "textline_string");
-               format = MEM_mallocN(text->curl->len+3, "Syntax_format");
                
                text->curc = 0; 
                if(text->curc) memcpy(tmp, text->curl->line, text->curc);
@@ -2405,7 +2398,7 @@
                if(len>0) memcpy(tmp+text->curc+1, text->curl->line+text->curc, 
len);
                tmp[text->curl->len+1]=0;
 
-               make_new_line(text->curl, tmp, format);
+               make_new_line(text->curl, tmp);
                        
                text->curc++;
                

Modified: branches/soc-2008-quorn/source/blender/include/BIF_drawtext.h
===================================================================
--- branches/soc-2008-quorn/source/blender/include/BIF_drawtext.h       
2008-07-28 11:01:34 UTC (rev 15836)
+++ branches/soc-2008-quorn/source/blender/include/BIF_drawtext.h       
2008-07-28 11:05:35 UTC (rev 15837)
@@ -45,7 +45,8 @@
 void free_txt_data(void);
 void pop_space_text(struct SpaceText *st);
 
-void get_format_string(struct SpaceText *st);
+void txt_format_text(struct SpaceText *st);
+void txt_format_line(struct SpaceText *st, struct TextLine *line, int do_next);
 void do_brackets(void);
 
 #endif

Modified: branches/soc-2008-quorn/source/blender/makesdna/DNA_text_types.h
===================================================================
--- branches/soc-2008-quorn/source/blender/makesdna/DNA_text_types.h    
2008-07-28 11:01:34 UTC (rev 15836)
+++ branches/soc-2008-quorn/source/blender/makesdna/DNA_text_types.h    
2008-07-28 11:05:35 UTC (rev 15837)
@@ -76,4 +76,12 @@
 #define TXT_READONLY            0x0100
 #define TXT_FOLLOW              0x0200 /* always follow cursor (console) */
 
+/* format continuation flags */
+#define TXT_NOCONT                             0x00 /* no continuation */
+#define TXT_SNGQUOTSTR                 0x01 /* single quotes */
+#define TXT_DBLQUOTSTR                 0x02 /* double quotes */
+#define TXT_TRISTR                             0x04 /* triplets of quotes: """ 
or ''' */
+#define TXT_SNGTRISTR                  0x05 /*(TXT_TRISTR | TXT_SNGQUOTSTR)*/
+#define TXT_DBLTRISTR                  0x06 /*(TXT_TRISTR | TXT_DBLQUOTSTR)*/
+
 #endif

Modified: branches/soc-2008-quorn/source/blender/src/drawtext.c
===================================================================
--- branches/soc-2008-quorn/source/blender/src/drawtext.c       2008-07-28 
11:01:34 UTC (rev 15836)
+++ branches/soc-2008-quorn/source/blender/src/drawtext.c       2008-07-28 
11:05:35 UTC (rev 15837)
@@ -134,10 +134,10 @@
 void txt_copy_selectbuffer (Text *text);
 void do_brackets();
 
-void get_selection_buffer(Text *text);
-int check_bracket(char *string);
-static int check_delim(char *string);
-static int check_numbers(char *string);
+static void get_selection_buffer(Text *text);
+static int check_bracket(char ch);
+static int check_delim(char ch);
+static int check_digit(char ch);
 static int check_builtinfuncs(char *string);
 static int check_specialvars(char *string);
 static int check_identifier(char ch);
@@ -237,351 +237,205 @@
        return r;
 }
 
-void get_format_string(SpaceText *st) 
+static int find_builtinfunc(char *string)
 {
-       Text *text = st->text;
-       TextLine *tmp;
-       char *in_line;
-       char format[2000], check[200], other[2];
-       unsigned char c;
-       int spot, letter, tabs, mem_amount;
-       size_t a, b, len;
-       
-       if(!text) return;
-       tmp = text->lines.first;
-       
-       while(tmp) {
-               in_line = tmp->line;
-               
-               len = strlen(in_line);
-               /* weak code... but we dont want crashes (ton) */
-               if(len>2000-1) {
-                       if (tmp->format) MEM_freeN(tmp->format);
-                       tmp->format= NULL;
+       int a, i;
+       char builtinfuncs[][11] = {"and", "as", "assert", "break", "class", 
"continue", "def",
+                                                               "del", "elif", 
"else", "except", "exec", "finally",
+                                                               "for", "from", 
"global", "if", "import", "in",
+                                                               "is", "lambda", 
"not", "or", "pass", "print",

@@ Diff output truncated at 10240 characters. @@

_______________________________________________
Bf-blender-cvs mailing list
[email protected]
http://lists.blender.org/mailman/listinfo/bf-blender-cvs

Reply via email to