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...
This commit is contained in:
Ton Roosendaal 2005-09-20 09:43:03 +00:00
parent 3ef1f0f3e3
commit 256a59c36e

@ -202,151 +202,111 @@ void get_format_string(void)
while(tmp) { while(tmp) {
in_line = tmp->line; 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++;
}
}
//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++) { len = strlen(in_line);
c = (unsigned char) in_line[a]; /* weak code... but we dont want crashes (ton) */
if(len>2000-1) {
if (tmp->format) MEM_freeN(tmp->format);
tmp->format= NULL;
}
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[0] = c;
check[1] = '\0'; check[1] = '\0';
if (check_delim(check)) if (check_delim(check))
{ {
switch (c) { switch (c) {
case '\"': case '\"':
if(in_line[a] == '\"' && in_line[a+1] == '\"' && in_line[a+2] == '\"') { if(in_line[a] == '\"' && in_line[a+1] == '\"' && in_line[a+2] == '\"') {
format[spot] = format[spot+1] = format[spot+2] = 'l'; format[spot] = format[spot+1] = format[spot+2] = 'l';
spot +=3; spot +=3;
a += 3; a += 3;
while(in_line[a] != '\"' || in_line[a-1] != '\"' || in_line[a-2] != '\"') { while(in_line[a] != '\"' || in_line[a-1] != '\"' || in_line[a-2] != '\"') {
c = (unsigned char) in_line[a]; c = (unsigned char) in_line[a];
if(a >= len) { if(a >= len) {
format[spot] = '\0'; format[spot] = '\0';
memcpy(tmp->format, format, strlen(format)); memcpy(tmp->format, format, strlen(format));
if(!(tmp= tmp->next)) { if(!(tmp= tmp->next)) {
return; 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 {
if(c == '\t' || c == ' ') {
if(c == '\t') {
for(b = st->tabnumber-(spot%st->tabnumber); b > 0; b--) {
format[spot] = ' ';
spot++;
}
a++;
} else { } else {
format[spot] = ' '; 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 {
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++; a++; spot++;
} }
} else {
format[spot] = 'l';
a++; spot++;
} }
} }
} format[spot] = 'l';
format[spot] = 'l'; spot++;
spot++; } else {
} else { format[spot] = 'l';
format[spot] = 'l'; a++; spot++;
a++; spot++; while(in_line[a] != '\"') {
while(in_line[a] != '\"') { c = (unsigned char) in_line[a];
c = (unsigned char) in_line[a]; if(a >= len) {
if(a >= len) { format[spot] = '\0';
format[spot] = '\0'; memcpy(tmp->format, format, strlen(format));
memcpy(tmp->format, format, strlen(format)); if(!(tmp= tmp->next)) {
if(!(tmp= tmp->next)) { return;
return; } else {
} else { in_line = tmp->line;
in_line = tmp->line; len = strlen(in_line);
len = strlen(in_line); for(b = 0; b <len; b++) {
for(b = 0; b <len; b++) { c = (unsigned char) in_line[b];
c = (unsigned char) in_line[b]; if(c == '\t') {
if(c == '\t') { tabs++;
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;
} }
//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++;
}
}
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' || c == ' ') {
if(c == '\t') { if(c == '\t') {
for(b = st->tabnumber-(spot%st->tabnumber); b > 0; b--) { for(b = st->tabnumber-(spot%st->tabnumber); b > 0; b--) {
@ -363,132 +323,152 @@ void get_format_string(void)
a++; spot++; a++; spot++;
} }
} }
format[spot] = 'l';
spot++;
} }
format[spot] = 'l'; break;
spot++; case '\'':
} else { if(in_line[a] == '\'' && in_line[a+1] == '\'' && in_line[a+2] == '\'') {
format[spot] = 'l'; format[spot] = format[spot+1] = format[spot+2] = 'l';
a++; spot++; spot +=3;
while(in_line[a] != '\'') { a += 3;
c = (unsigned char) in_line[a]; while(in_line[a] != '\'' || in_line[a-1] != '\'' || in_line[a-2] != '\'') {
if(a >= len) { c = (unsigned char) in_line[a];
format[spot] = '\0'; if(a >= len) {
memcpy(tmp->format, format, strlen(format)); format[spot] = '\0';
if(!(tmp= tmp->next)) { memcpy(tmp->format, format, strlen(format));
return; if(!(tmp= tmp->next)) {
} else { return;
in_line = tmp->line; } else {
len = strlen(in_line); in_line = tmp->line;
for(b = 0; b <len; b++) { len = strlen(in_line);
c = (unsigned char) in_line[b]; tabs = 0;
if(c == '\t') { for(b = 0; b <len; b++) {
tabs++; 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 {
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++;
} }
//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;
} }
} }
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;
}
}
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 '#':
while(a<len) {
c = (unsigned char) in_line[a];
if(c == '\t' || c == ' ') { if(c == '\t' || c == ' ') {
if(c == '\t') { if(c == '\t') {
for(b = st->tabnumber-(spot%st->tabnumber); b > 0; b--) { for(b = st->tabnumber-(spot%st->tabnumber); b > 0; b--) {
format[spot] = ' '; format[spot] = '#';
spot++; spot++;
} }
a++; a++;
} else { } 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] = '#'; format[spot] = '#';
spot++; a++; spot++;
} }
a++;
} else { } else {
format[spot] = '#'; format[spot] = '#';
a++; spot++; a++; spot++;
} }
} else {
format[spot] = '#';
a++; spot++;
} }
} break;
break; case ' ':
case ' ':
format[spot] = ' ';
spot++;
break;
case '\t':
for(b = st->tabnumber-(spot%st->tabnumber); b > 0; b--) {
format[spot] = ' '; format[spot] = ' ';
spot++; 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_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++;
} }
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 {
} 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++;
}
} 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++; a++;
letter = 0; letter = 0;
while (a < len) { while (a < len) {
c = (unsigned char) in_line[a]; c = (unsigned char) in_line[a];
@ -504,20 +484,50 @@ void get_format_string(void)
} }
} }
check[letter] = '\0'; check[letter] = '\0';
for (b = 0; b < strlen(check); b++) { if (check_builtinfuncs(check)) {
format[spot] = 'v'; for (b = 0; b < strlen(check); b++) {
spot++; format[spot] = 'b';
} spot++;
}else { }
for (b = 0; b < strlen(check); b++) { } 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'; 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; tmp = tmp->next;
} }
} }
@ -535,7 +545,7 @@ static int text_draw(SpaceText *st, char *str, int cshift, int maxwidth, int dra
w= w-cshift; w= w-cshift;
if (draw) { if (draw) {
if(st->showsyntax) { if(st->showsyntax && format) {
int amount, a; int amount, a;
char out[2]; char out[2];
format = format+cshift; format = format+cshift;