Welcome to mirror list, hosted at ThFree Co, Russian Federation.

git.blender.org/blender.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorTon Roosendaal <ton@blender.org>2005-09-20 13:43:03 +0400
committerTon Roosendaal <ton@blender.org>2005-09-20 13:43:03 +0400
commit256a59c36ede5b17de09610f75de329ea08426c6 (patch)
tree3f551b4b693eb07ed96804f27f7f1bf656e054af /source/blender/src/drawtext.c
parent3ef1f0f3e325cb2995f4470abe6996342b572c7e (diff)
Bug fix #3052
Syntax highlight in Text Window crashed with lines > 2000 chars. I now just skip the highlighting code for these cases, it remains a bit weak code...
Diffstat (limited to 'source/blender/src/drawtext.c')
-rw-r--r--source/blender/src/drawtext.c464
1 files changed, 237 insertions, 227 deletions
diff --git a/source/blender/src/drawtext.c b/source/blender/src/drawtext.c
index a6ee39907bb..4de5cf5a048 100644
--- a/source/blender/src/drawtext.c
+++ b/source/blender/src/drawtext.c
@@ -202,58 +202,111 @@ void get_format_string(void)
while(tmp) {
in_line = tmp->line;
+
len = strlen(in_line);
- spot = 0;
- tabs = 0;
- //see how many tabs we have
- for(a = 0; a <len; a++) {
- c = (unsigned char) in_line[a];
- if(c == '\t') {
- tabs++;
- }
+ /* weak code... but we dont want crashes (ton) */
+ if(len>2000-1) {
+ if (tmp->format) MEM_freeN(tmp->format);
+ tmp->format= NULL;
}
- //calculate the amount of MEM_mallocN we neen
- mem_amount = (((tabs*st->tabnumber)-tabs)+2)+len; // +2 for good measure
- if (tmp->format) MEM_freeN(tmp->format);
- tmp->format = MEM_mallocN(mem_amount, "Syntax_format");
-
- for (a = 0; a < len; a++) {
- c = (unsigned char) in_line[a];
+ else {
+
+ spot = 0;
+ tabs = 0;
+ //see how many tabs we have
+ for(a = 0; a <len; a++) {
+ c = (unsigned char) in_line[a];
+ if(c == '\t') {
+ tabs++;
+ }
+ }
+ //calculate the amount of MEM_mallocN we neen
+ mem_amount = (((tabs*st->tabnumber)-tabs)+2)+len; // +2 for good measure
+ if (tmp->format) MEM_freeN(tmp->format);
+ tmp->format = MEM_mallocN(mem_amount, "Syntax_format");
+
+ for (a = 0; a < len; a++) {
+ c = (unsigned char) in_line[a];
- check[0] = c;
- check[1] = '\0';
+ check[0] = c;
+ check[1] = '\0';
- if (check_delim(check))
- {
- switch (c) {
- case '\"':
- if(in_line[a] == '\"' && in_line[a+1] == '\"' && in_line[a+2] == '\"') {
- format[spot] = format[spot+1] = format[spot+2] = 'l';
- spot +=3;
- a += 3;
- while(in_line[a] != '\"' || in_line[a-1] != '\"' || in_line[a-2] != '\"') {
- c = (unsigned char) in_line[a];
- if(a >= len) {
- format[spot] = '\0';
- memcpy(tmp->format, format, strlen(format));
- if(!(tmp= tmp->next)) {
- return;
+ if (check_delim(check))
+ {
+ switch (c) {
+ case '\"':
+ if(in_line[a] == '\"' && in_line[a+1] == '\"' && in_line[a+2] == '\"') {
+ format[spot] = format[spot+1] = format[spot+2] = 'l';
+ spot +=3;
+ a += 3;
+ while(in_line[a] != '\"' || in_line[a-1] != '\"' || in_line[a-2] != '\"') {
+ c = (unsigned char) in_line[a];
+ if(a >= len) {
+ format[spot] = '\0';
+ memcpy(tmp->format, format, strlen(format));
+ if(!(tmp= tmp->next)) {
+ return;
+ } else {
+ in_line = tmp->line;
+ len = strlen(in_line);
+ tabs = 0;
+ for(b = 0; b <len; b++) {
+ c = (unsigned char) in_line[b];
+ if(c == '\t') {
+ tabs++;
+ }
+ }
+ mem_amount = (((tabs*st->tabnumber)-tabs)+2)+len;
+ if (tmp->format) MEM_freeN(tmp->format);
+ tmp->format = MEM_mallocN(mem_amount, "Syntax_format");
+ a = 0; spot = 0;
+ }
} else {
- in_line = tmp->line;
- len = strlen(in_line);
- tabs = 0;
- for(b = 0; b <len; b++) {
- c = (unsigned char) in_line[b];
+ if(c == '\t' || c == ' ') {
if(c == '\t') {
- tabs++;
+ for(b = st->tabnumber-(spot%st->tabnumber); b > 0; b--) {
+ format[spot] = ' ';
+ spot++;
+ }
+ a++;
+ } else {
+ format[spot] = ' ';
+ a++; spot++;
+ }
+ } else {
+ format[spot] = 'l';
+ a++; spot++;
+ }
+ }
+ }
+ format[spot] = 'l';
+ spot++;
+ } else {
+ format[spot] = 'l';
+ a++; spot++;
+ while(in_line[a] != '\"') {
+ c = (unsigned char) in_line[a];
+ if(a >= len) {
+ format[spot] = '\0';
+ memcpy(tmp->format, format, strlen(format));
+ if(!(tmp= tmp->next)) {
+ return;
+ } else {
+ in_line = tmp->line;
+ len = strlen(in_line);
+ for(b = 0; b <len; b++) {
+ c = (unsigned char) in_line[b];
+ if(c == '\t') {
+ tabs++;
+ }
}
+ //calculate the amount of MEM_mallocN we neen
+ mem_amount = (((tabs*st->tabnumber)-tabs)+2)+len;
+ if (tmp->format) MEM_freeN(tmp->format);
+ tmp->format = MEM_mallocN(mem_amount, "Syntax_format");
+ a = 0; spot = 0;
}
- mem_amount = (((tabs*st->tabnumber)-tabs)+2)+len;
- if (tmp->format) MEM_freeN(tmp->format);
- tmp->format = MEM_mallocN(mem_amount, "Syntax_format");
- a = 0; spot = 0;
}
- } else {
if(c == '\t' || c == ' ') {
if(c == '\t') {
for(b = st->tabnumber-(spot%st->tabnumber); b > 0; b--) {
@@ -264,89 +317,89 @@ void get_format_string(void)
} else {
format[spot] = ' ';
a++; spot++;
- }
+ }
} else {
format[spot] = 'l';
a++; spot++;
}
}
+ format[spot] = 'l';
+ spot++;
}
- format[spot] = 'l';
- spot++;
- } else {
- format[spot] = 'l';
- a++; spot++;
- while(in_line[a] != '\"') {
- c = (unsigned char) in_line[a];
- if(a >= len) {
- format[spot] = '\0';
- memcpy(tmp->format, format, strlen(format));
- if(!(tmp= tmp->next)) {
- return;
+ break;
+ case '\'':
+ if(in_line[a] == '\'' && in_line[a+1] == '\'' && in_line[a+2] == '\'') {
+ format[spot] = format[spot+1] = format[spot+2] = 'l';
+ spot +=3;
+ a += 3;
+ while(in_line[a] != '\'' || in_line[a-1] != '\'' || in_line[a-2] != '\'') {
+ c = (unsigned char) in_line[a];
+ if(a >= len) {
+ format[spot] = '\0';
+ memcpy(tmp->format, format, strlen(format));
+ if(!(tmp= tmp->next)) {
+ return;
+ } else {
+ in_line = tmp->line;
+ len = strlen(in_line);
+ tabs = 0;
+ for(b = 0; b <len; b++) {
+ c = (unsigned char) in_line[b];
+ if(c == '\t') {
+ tabs++;
+ }
+ }
+ mem_amount = (((tabs*st->tabnumber)-tabs)+2)+len;
+ if (tmp->format) MEM_freeN(tmp->format);
+ tmp->format = MEM_mallocN(mem_amount, "Syntax_format");
+ a = 0; spot = 0;
+ }
} else {
- in_line = tmp->line;
- len = strlen(in_line);
- for(b = 0; b <len; b++) {
- c = (unsigned char) in_line[b];
+ if(c == '\t' || c == ' ') {
if(c == '\t') {
- tabs++;
+ for(b = st->tabnumber-(spot%st->tabnumber); b > 0; b--) {
+ format[spot] = ' ';
+ spot++;
+ }
+ a++;
+ } else {
+ format[spot] = ' ';
+ a++; spot++;
}
+ } else {
+ format[spot] = 'l';
+ a++; spot++;
}
- //calculate the amount of MEM_mallocN we neen
- mem_amount = (((tabs*st->tabnumber)-tabs)+2)+len;
- if (tmp->format) MEM_freeN(tmp->format);
- tmp->format = MEM_mallocN(mem_amount, "Syntax_format");
- a = 0; spot = 0;
}
}
- if(c == '\t' || c == ' ') {
- if(c == '\t') {
- for(b = st->tabnumber-(spot%st->tabnumber); b > 0; b--) {
- format[spot] = ' ';
- spot++;
- }
- a++;
- } else {
- format[spot] = ' ';
- a++; spot++;
- }
- } else {
- format[spot] = 'l';
- a++; spot++;
- }
- }
- format[spot] = 'l';
- spot++;
- }
- break;
- case '\'':
- if(in_line[a] == '\'' && in_line[a+1] == '\'' && in_line[a+2] == '\'') {
- format[spot] = format[spot+1] = format[spot+2] = 'l';
- spot +=3;
- a += 3;
- while(in_line[a] != '\'' || in_line[a-1] != '\'' || in_line[a-2] != '\'') {
- c = (unsigned char) in_line[a];
- if(a >= len) {
- format[spot] = '\0';
- memcpy(tmp->format, format, strlen(format));
- if(!(tmp= tmp->next)) {
- return;
- } else {
- in_line = tmp->line;
- len = strlen(in_line);
- tabs = 0;
- for(b = 0; b <len; b++) {
- c = (unsigned char) in_line[b];
- if(c == '\t') {
- tabs++;
+ format[spot] = 'l';
+ spot++;
+ } else {
+ format[spot] = 'l';
+ a++; spot++;
+ while(in_line[a] != '\'') {
+ c = (unsigned char) in_line[a];
+ if(a >= len) {
+ format[spot] = '\0';
+ memcpy(tmp->format, format, strlen(format));
+ if(!(tmp= tmp->next)) {
+ return;
+ } else {
+ in_line = tmp->line;
+ len = strlen(in_line);
+ for(b = 0; b <len; b++) {
+ c = (unsigned char) in_line[b];
+ if(c == '\t') {
+ tabs++;
+ }
}
+ //calculate the amount of MEM_mallocN we neen
+ mem_amount = (((tabs*st->tabnumber)-tabs)+2)+len;
+ if (tmp->format) MEM_freeN(tmp->format);
+ tmp->format = MEM_mallocN(mem_amount, "Syntax_format");
+ a = 0; spot = 0;
}
- mem_amount = (((tabs*st->tabnumber)-tabs)+2)+len;
- if (tmp->format) MEM_freeN(tmp->format);
- tmp->format = MEM_mallocN(mem_amount, "Syntax_format");
- a = 0; spot = 0;
}
- } else {
if(c == '\t' || c == ' ') {
if(c == '\t') {
for(b = st->tabnumber-(spot%st->tabnumber); b > 0; b--) {
@@ -363,132 +416,59 @@ void get_format_string(void)
a++; spot++;
}
}
+ format[spot] = 'l';
+ spot++;
}
- format[spot] = 'l';
- spot++;
- } else {
- format[spot] = 'l';
- a++; spot++;
- while(in_line[a] != '\'') {
+ break;
+ case '#':
+ while(a<len) {
c = (unsigned char) in_line[a];
- if(a >= len) {
- format[spot] = '\0';
- memcpy(tmp->format, format, strlen(format));
- if(!(tmp= tmp->next)) {
- return;
- } else {
- in_line = tmp->line;
- len = strlen(in_line);
- for(b = 0; b <len; b++) {
- c = (unsigned char) in_line[b];
- if(c == '\t') {
- tabs++;
- }
- }
- //calculate the amount of MEM_mallocN we neen
- mem_amount = (((tabs*st->tabnumber)-tabs)+2)+len;
- if (tmp->format) MEM_freeN(tmp->format);
- tmp->format = MEM_mallocN(mem_amount, "Syntax_format");
- a = 0; spot = 0;
- }
- }
if(c == '\t' || c == ' ') {
if(c == '\t') {
for(b = st->tabnumber-(spot%st->tabnumber); b > 0; b--) {
- format[spot] = ' ';
+ format[spot] = '#';
spot++;
}
a++;
} else {
- format[spot] = ' ';
- a++; spot++;
- }
- } else {
- format[spot] = 'l';
- a++; spot++;
- }
- }
- format[spot] = 'l';
- spot++;
- }
- break;
- case '#':
- while(a<len) {
- c = (unsigned char) in_line[a];
- if(c == '\t' || c == ' ') {
- if(c == '\t') {
- for(b = st->tabnumber-(spot%st->tabnumber); b > 0; b--) {
format[spot] = '#';
- spot++;
+ a++; spot++;
}
- a++;
} else {
format[spot] = '#';
a++; spot++;
}
- } else {
- format[spot] = '#';
- a++; spot++;
}
- }
- break;
- case ' ':
- format[spot] = ' ';
- spot++;
- break;
- case '\t':
- for(b = st->tabnumber-(spot%st->tabnumber); b > 0; b--) {
+ break;
+ case ' ':
format[spot] = ' ';
spot++;
- }
- break;
- default:
- format[spot] = 'q';
- spot++;
-
- break;
- }
- } else if (check_numbers(check)) {
- while (a < len) {
- c = (unsigned char) in_line[a];
- other[0] = c;
- other[1] = '\0';
- if (check_delim(other) && c != '.') {
- a--; break;
- } else {
- format[spot] = 'n';
- a++; spot++;
- }
- }
- } else {
- letter = 0;
- while (a < len) {
- c = (unsigned char) in_line[a];
- other[0] = c;
- other[1] = '\0';
- if (check_delim(other)) {
- a--;
- break;
- } else {
- check[letter] = (unsigned char) in_line[a];
- letter++;
- a++;
- }
- }
- check[letter] = '\0';
- if (check_builtinfuncs(check)) {
- for (b = 0; b < strlen(check); b++) {
- format[spot] = 'b';
- spot++;
+ break;
+ case '\t':
+ for(b = st->tabnumber-(spot%st->tabnumber); b > 0; b--) {
+ format[spot] = ' ';
+ spot++;
+ }
+ break;
+ default:
+ format[spot] = 'q';
+ spot++;
+
+ break;
}
- } else if (check_specialvars(check)) { /*If TRUE then color and color next word*/
- for (b = 0; b < strlen(check); b++) {
- format[spot] = 'b';
- spot++;
+ } else if (check_numbers(check)) {
+ while (a < len) {
+ c = (unsigned char) in_line[a];
+ other[0] = c;
+ other[1] = '\0';
+ if (check_delim(other) && c != '.') {
+ a--; break;
+ } else {
+ format[spot] = 'n';
+ a++; spot++;
+ }
}
- a++;
- format[spot] = 'q';
- spot++; a++;
+ } else {
letter = 0;
while (a < len) {
c = (unsigned char) in_line[a];
@@ -504,20 +484,50 @@ void get_format_string(void)
}
}
check[letter] = '\0';
- for (b = 0; b < strlen(check); b++) {
- format[spot] = 'v';
- spot++;
- }
- }else {
- for (b = 0; b < strlen(check); b++) {
+ if (check_builtinfuncs(check)) {
+ for (b = 0; b < strlen(check); b++) {
+ format[spot] = 'b';
+ spot++;
+ }
+ } else if (check_specialvars(check)) { /*If TRUE then color and color next word*/
+ for (b = 0; b < strlen(check); b++) {
+ format[spot] = 'b';
+ spot++;
+ }
+ a++;
format[spot] = 'q';
- spot++;
+ spot++; a++;
+ letter = 0;
+ while (a < len) {
+ c = (unsigned char) in_line[a];
+ other[0] = c;
+ other[1] = '\0';
+ if (check_delim(other)) {
+ a--;
+ break;
+ } else {
+ check[letter] = (unsigned char) in_line[a];
+ letter++;
+ a++;
+ }
+ }
+ check[letter] = '\0';
+ for (b = 0; b < strlen(check); b++) {
+ format[spot] = 'v';
+ spot++;
+ }
+ }else {
+ for (b = 0; b < strlen(check); b++) {
+ format[spot] = 'q';
+ spot++;
+ }
}
}
}
+ format[spot] = '\0';
+ memcpy(tmp->format, format, strlen(format));
}
- format[spot] = '\0';
- memcpy(tmp->format, format, strlen(format));
+
tmp = tmp->next;
}
}
@@ -535,7 +545,7 @@ static int text_draw(SpaceText *st, char *str, int cshift, int maxwidth, int dra
w= w-cshift;
if (draw) {
- if(st->showsyntax) {
+ if(st->showsyntax && format) {
int amount, a;
char out[2];
format = format+cshift;