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:
Diffstat (limited to 'source/blender/blenkernel/intern/text.c')
-rw-r--r--source/blender/blenkernel/intern/text.c458
1 files changed, 262 insertions, 196 deletions
diff --git a/source/blender/blenkernel/intern/text.c b/source/blender/blenkernel/intern/text.c
index 66759edde65..9715058c51f 100644
--- a/source/blender/blenkernel/intern/text.c
+++ b/source/blender/blenkernel/intern/text.c
@@ -173,7 +173,7 @@ void free_text(Text *text)
BLI_freelistN(&text->lines);
BLI_freelistN(&text->markers);
- if(text->name) MEM_freeN(text->name);
+ if (text->name) MEM_freeN(text->name);
MEM_freeN(text->undo_buf);
#ifdef WITH_PYTHON
if (text->compiled) BPY_text_free_code(text);
@@ -195,7 +195,7 @@ Text *add_empty_text(const char *name)
ta->nlines=1;
ta->flags= TXT_ISDIRTY | TXT_ISMEM;
- if((U.flag & USER_TXT_TABSTOSPACES_DISABLE)==0)
+ if ((U.flag & USER_TXT_TABSTOSPACES_DISABLE)==0)
ta->flags |= TXT_TABSTOSPACES;
ta->lines.first= ta->lines.last= NULL;
@@ -229,7 +229,7 @@ int txt_extended_ascii_as_utf8(char **str)
int length = strlen(*str);
while ((*str)[i]) {
- if((bad_char= BLI_utf8_invalid_byte(*str+i, length-i)) == -1)
+ if ((bad_char= BLI_utf8_invalid_byte(*str+i, length-i)) == -1)
break;
added++;
@@ -242,7 +242,7 @@ int txt_extended_ascii_as_utf8(char **str)
i= 0;
while ((*str)[i]) {
- if((bad_char= BLI_utf8_invalid_byte((*str)+i, length-i)) == -1) {
+ if ((bad_char= BLI_utf8_invalid_byte((*str)+i, length-i)) == -1) {
memcpy(newstr+mi, (*str)+i, length - i + 1);
break;
}
@@ -293,7 +293,7 @@ int reopen_text(Text *text)
BLI_path_abs(str, G.main->name);
fp= BLI_fopen(str, "r");
- if(fp==NULL) return 0;
+ if (fp==NULL) return 0;
/* free memory: */
@@ -329,13 +329,13 @@ int reopen_text(Text *text)
text->nlines=0;
llen=0;
- for(i=0; i<len; i++) {
+ for (i=0; i<len; i++) {
if (buffer[i]=='\n') {
tmp= (TextLine*) MEM_mallocN(sizeof(TextLine), "textline");
tmp->line= (char*) MEM_mallocN(llen+1, "textline_string");
tmp->format= NULL;
- if(llen) memcpy(tmp->line, &buffer[i-llen], llen);
+ if (llen) memcpy(tmp->line, &buffer[i-llen], llen);
tmp->line[llen]=0;
tmp->len= llen;
@@ -355,7 +355,7 @@ int reopen_text(Text *text)
tmp->line= (char*) MEM_mallocN(llen+1, "textline_string");
tmp->format= NULL;
- if(llen) memcpy(tmp->line, &buffer[i-llen], llen);
+ if (llen) memcpy(tmp->line, &buffer[i-llen], llen);
tmp->line[llen]=0;
tmp->len= llen;
@@ -389,7 +389,7 @@ Text *add_text(const char *file, const char *relpath)
BLI_path_abs(str, relpath);
fp= BLI_fopen(str, "r");
- if(fp==NULL) return NULL;
+ if (fp==NULL) return NULL;
ta= alloc_libblock(&bmain->text, ID_TXT, BLI_path_basename(str));
ta->id.us= 1;
@@ -398,7 +398,7 @@ Text *add_text(const char *file, const char *relpath)
ta->markers.first= ta->markers.last= NULL;
ta->curl= ta->sell= NULL;
- if((U.flag & USER_TXT_TABSTOSPACES_DISABLE)==0)
+ if ((U.flag & USER_TXT_TABSTOSPACES_DISABLE)==0)
ta->flags= TXT_TABSTOSPACES;
fseek(fp, 0L, SEEK_END);
@@ -422,13 +422,13 @@ Text *add_text(const char *file, const char *relpath)
ta->nlines=0;
llen=0;
- for(i=0; i<len; i++) {
+ for (i=0; i<len; i++) {
if (buffer[i]=='\n') {
tmp= (TextLine*) MEM_mallocN(sizeof(TextLine), "textline");
tmp->line= (char*) MEM_mallocN(llen+1, "textline_string");
tmp->format= NULL;
- if(llen) memcpy(tmp->line, &buffer[i-llen], llen);
+ if (llen) memcpy(tmp->line, &buffer[i-llen], llen);
tmp->line[llen]=0;
tmp->len= llen;
@@ -454,7 +454,7 @@ Text *add_text(const char *file, const char *relpath)
tmp->line= (char*) MEM_mallocN(llen+1, "textline_string");
tmp->format= NULL;
- if(llen) memcpy(tmp->line, &buffer[i-llen], llen);
+ if (llen) memcpy(tmp->line, &buffer[i-llen], llen);
tmp->line[llen]=0;
tmp->len= llen;
@@ -481,7 +481,7 @@ Text *copy_text(Text *ta)
tan= copy_libblock(&ta->id);
/* file name can be NULL */
- if(ta->name) {
+ if (ta->name) {
tan->name= MEM_mallocN(strlen(ta->name)+1, "text_name");
strcpy(tan->name, ta->name);
}
@@ -531,25 +531,25 @@ void unlink_text(Main *bmain, Text *text)
bConstraint *con;
short update;
- for(ob=bmain->object.first; ob; ob=ob->id.next) {
+ for (ob=bmain->object.first; ob; ob=ob->id.next) {
/* game controllers */
- for(cont=ob->controllers.first; cont; cont=cont->next) {
- if(cont->type==CONT_PYTHON) {
+ for (cont=ob->controllers.first; cont; cont=cont->next) {
+ if (cont->type==CONT_PYTHON) {
bPythonCont *pc;
pc= cont->data;
- if(pc->text==text) pc->text= NULL;
+ if (pc->text==text) pc->text= NULL;
}
}
/* pyconstraints */
update = 0;
- if(ob->type==OB_ARMATURE && ob->pose) {
+ if (ob->type==OB_ARMATURE && ob->pose) {
bPoseChannel *pchan;
- for(pchan= ob->pose->chanbase.first; pchan; pchan= pchan->next) {
- for(con = pchan->constraints.first; con; con=con->next) {
- if(con->type==CONSTRAINT_TYPE_PYTHON) {
+ for (pchan= ob->pose->chanbase.first; pchan; pchan= pchan->next) {
+ for (con = pchan->constraints.first; con; con=con->next) {
+ if (con->type==CONSTRAINT_TYPE_PYTHON) {
bPythonConstraint *data = con->data;
if (data->text==text) data->text = NULL;
update = 1;
@@ -559,15 +559,15 @@ void unlink_text(Main *bmain, Text *text)
}
}
- for(con = ob->constraints.first; con; con=con->next) {
- if(con->type==CONSTRAINT_TYPE_PYTHON) {
+ for (con = ob->constraints.first; con; con=con->next) {
+ if (con->type==CONSTRAINT_TYPE_PYTHON) {
bPythonConstraint *data = con->data;
if (data->text==text) data->text = NULL;
update = 1;
}
}
- if(update)
+ if (update)
DAG_id_tag_update(&ob->id, OB_RECALC_DATA);
}
@@ -575,13 +575,13 @@ void unlink_text(Main *bmain, Text *text)
// XXX nodeDynamicUnlinkText(&text->id);
/* text space */
- for(scr= bmain->screen.first; scr; scr= scr->id.next) {
- for(area= scr->areabase.first; area; area= area->next) {
- for(sl= area->spacedata.first; sl; sl= sl->next) {
- if(sl->spacetype==SPACE_TEXT) {
+ for (scr= bmain->screen.first; scr; scr= scr->id.next) {
+ for (area= scr->areabase.first; area; area= area->next) {
+ for (sl= area->spacedata.first; sl; sl= sl->next) {
+ if (sl->spacetype==SPACE_TEXT) {
SpaceText *st= (SpaceText*) sl;
- if(st->text==text) {
+ if (st->text==text) {
st->text= NULL;
st->top= 0;
}
@@ -636,7 +636,7 @@ static TextLine *txt_new_line(const char *str)
{
TextLine *tmp;
- if(!str) str= "";
+ if (!str) str= "";
tmp= (TextLine *) MEM_mallocN(sizeof(TextLine), "textline");
tmp->line= MEM_mallocN(strlen(str)+1, "textline_string");
@@ -685,13 +685,13 @@ void txt_clean_text (Text *text)
while ((*top)->prev) *top= (*top)->prev;
while ((*bot)->next) *bot= (*bot)->next;
- if(!text->curl) {
- if(text->sell) text->curl= text->sell;
+ if (!text->curl) {
+ if (text->sell) text->curl= text->sell;
else text->curl= text->lines.first;
text->curc= 0;
}
- if(!text->sell) {
+ if (!text->sell) {
text->sell= text->curl;
text->selc= 0;
}
@@ -716,12 +716,12 @@ int txt_get_span (TextLine *from, TextLine *to)
if (!tmp) {
tmp= from;
ret=0;
- while(tmp) {
+ while (tmp) {
if (tmp == to) break;
ret--;
tmp= tmp->prev;
}
- if(!tmp) ret=0;
+ if (!tmp) ret=0;
}
return ret;
@@ -755,10 +755,12 @@ static void txt_curs_first (Text *text, TextLine **linep, int *charp)
*linep= text->curl;
if (text->curc<text->selc) *charp= text->curc;
else *charp= text->selc;
- } else if (txt_get_span(text->lines.first, text->curl)<txt_get_span(text->lines.first, text->sell)) {
+ }
+ else if (txt_get_span(text->lines.first, text->curl)<txt_get_span(text->lines.first, text->sell)) {
*linep= text->curl;
*charp= text->curc;
- } else {
+ }
+ else {
*linep= text->sell;
*charp= text->selc;
}
@@ -808,24 +810,25 @@ void txt_move_up(Text *text, short sel)
/* int old; */ /* UNUSED */
if (!text) return;
- if(sel) txt_curs_sel(text, &linep, &charp);
+ if (sel) txt_curs_sel(text, &linep, &charp);
else { txt_pop_first(text); txt_curs_cur(text, &linep, &charp); }
if (!*linep) return;
/* old= *charp; */ /* UNUSED */
- if((*linep)->prev) {
+ if ((*linep)->prev) {
int index = txt_utf8_offset_to_index((*linep)->line, *charp);
*linep= (*linep)->prev;
if (index > txt_utf8_len((*linep)->line)) *charp= (*linep)->len;
else *charp= txt_utf8_index_to_offset((*linep)->line, index);
- if(!undoing)
+ if (!undoing)
txt_undo_add_op(text, sel?UNDO_SUP:UNDO_CUP);
- } else {
+ }
+ else {
txt_move_bol(text, sel);
}
- if(!sel) txt_pop_sel(text);
+ if (!sel) txt_pop_sel(text);
}
void txt_move_down(Text *text, short sel)
@@ -835,24 +838,25 @@ void txt_move_down(Text *text, short sel)
/* int old; */ /* UNUSED */
if (!text) return;
- if(sel) txt_curs_sel(text, &linep, &charp);
+ if (sel) txt_curs_sel(text, &linep, &charp);
else { txt_pop_last(text); txt_curs_cur(text, &linep, &charp); }
if (!*linep) return;
/* old= *charp; */ /* UNUSED */
- if((*linep)->next) {
+ if ((*linep)->next) {
int index = txt_utf8_offset_to_index((*linep)->line, *charp);
*linep= (*linep)->next;
if (index > txt_utf8_len((*linep)->line)) *charp= (*linep)->len;
else *charp= txt_utf8_index_to_offset((*linep)->line, index);
- if(!undoing)
+ if (!undoing)
txt_undo_add_op(text, sel?UNDO_SDOWN:UNDO_CDOWN);
- } else {
+ }
+ else {
txt_move_eol(text, sel);
}
- if(!sel) txt_pop_sel(text);
+ if (!sel) txt_pop_sel(text);
}
void txt_move_left(Text *text, short sel)
@@ -862,7 +866,7 @@ void txt_move_left(Text *text, short sel)
int tabsize= 0, i= 0;
if (!text) return;
- if(sel) txt_curs_sel(text, &linep, &charp);
+ if (sel) txt_curs_sel(text, &linep, &charp);
else { txt_pop_first(text); txt_curs_cur(text, &linep, &charp); }
if (!*linep) return;
@@ -900,9 +904,9 @@ void txt_move_left(Text *text, short sel)
}
undoing= oundoing;
- if(!undoing) txt_undo_add_op(text, sel?UNDO_SLEFT:UNDO_CLEFT);
+ if (!undoing) txt_undo_add_op(text, sel?UNDO_SLEFT:UNDO_CLEFT);
- if(!sel) txt_pop_sel(text);
+ if (!sel) txt_pop_sel(text);
}
void txt_move_right(Text *text, short sel)
@@ -911,7 +915,7 @@ void txt_move_right(Text *text, short sel)
int *charp, oundoing= undoing, do_tab= 0, i;
if (!text) return;
- if(sel) txt_curs_sel(text, &linep, &charp);
+ if (sel) txt_curs_sel(text, &linep, &charp);
else { txt_pop_last(text); txt_curs_cur(text, &linep, &charp); }
if (!*linep) return;
@@ -945,9 +949,9 @@ void txt_move_right(Text *text, short sel)
}
undoing= oundoing;
- if(!undoing) txt_undo_add_op(text, sel?UNDO_SRIGHT:UNDO_CRIGHT);
+ if (!undoing) txt_undo_add_op(text, sel?UNDO_SRIGHT:UNDO_CRIGHT);
- if(!sel) txt_pop_sel(text);
+ if (!sel) txt_pop_sel(text);
}
void txt_jump_left(Text *text, short sel)
@@ -958,7 +962,7 @@ void txt_jump_left(Text *text, short sel)
int pos;
if (!text) return;
- if(sel) txt_curs_sel(text, &linep, &charp);
+ if (sel) txt_curs_sel(text, &linep, &charp);
else { txt_pop_first(text); txt_curs_cur(text, &linep, &charp); }
if (!*linep) return;
@@ -981,7 +985,7 @@ void txt_jump_left(Text *text, short sel)
text->flags = oldflags;
undoing= oldu;
- if(!undoing) txt_undo_add_toop(text, sel?UNDO_STO:UNDO_CTO, txt_get_span(text->lines.first, oldl), oldc, txt_get_span(text->lines.first, *linep), (unsigned short)*charp);
+ if (!undoing) txt_undo_add_toop(text, sel?UNDO_STO:UNDO_CTO, txt_get_span(text->lines.first, oldl), oldc, txt_get_span(text->lines.first, *linep), (unsigned short)*charp);
}
void txt_jump_right(Text *text, short sel)
@@ -992,7 +996,7 @@ void txt_jump_right(Text *text, short sel)
int pos;
if (!text) return;
- if(sel) txt_curs_sel(text, &linep, &charp);
+ if (sel) txt_curs_sel(text, &linep, &charp);
else { txt_pop_last(text); txt_curs_cur(text, &linep, &charp); }
if (!*linep) return;
@@ -1015,7 +1019,7 @@ void txt_jump_right(Text *text, short sel)
text->flags = oldflags;
undoing= oldu;
- if(!undoing) txt_undo_add_toop(text, sel?UNDO_STO:UNDO_CTO, txt_get_span(text->lines.first, oldl), oldc, txt_get_span(text->lines.first, *linep), (unsigned short)*charp);
+ if (!undoing) txt_undo_add_toop(text, sel?UNDO_STO:UNDO_CTO, txt_get_span(text->lines.first, oldl), oldc, txt_get_span(text->lines.first, *linep), (unsigned short)*charp);
}
void txt_move_bol (Text *text, short sel)
@@ -1024,15 +1028,15 @@ void txt_move_bol (Text *text, short sel)
int *charp, old;
if (!text) return;
- if(sel) txt_curs_sel(text, &linep, &charp);
+ if (sel) txt_curs_sel(text, &linep, &charp);
else txt_curs_cur(text, &linep, &charp);
if (!*linep) return;
old= *charp;
*charp= 0;
- if(!sel) txt_pop_sel(text);
- if(!undoing) txt_undo_add_toop(text, sel?UNDO_STO:UNDO_CTO, txt_get_span(text->lines.first, *linep), old, txt_get_span(text->lines.first, *linep), (unsigned short)*charp);
+ if (!sel) txt_pop_sel(text);
+ if (!undoing) txt_undo_add_toop(text, sel?UNDO_STO:UNDO_CTO, txt_get_span(text->lines.first, *linep), old, txt_get_span(text->lines.first, *linep), (unsigned short)*charp);
}
void txt_move_eol (Text *text, short sel)
@@ -1041,15 +1045,15 @@ void txt_move_eol (Text *text, short sel)
int *charp, old;
if (!text) return;
- if(sel) txt_curs_sel(text, &linep, &charp);
+ if (sel) txt_curs_sel(text, &linep, &charp);
else txt_curs_cur(text, &linep, &charp);
if (!*linep) return;
old= *charp;
*charp= (*linep)->len;
- if(!sel) txt_pop_sel(text);
- if(!undoing) txt_undo_add_toop(text, sel?UNDO_STO:UNDO_CTO, txt_get_span(text->lines.first, *linep), old, txt_get_span(text->lines.first, *linep), (unsigned short)*charp);
+ if (!sel) txt_pop_sel(text);
+ if (!undoing) txt_undo_add_toop(text, sel?UNDO_STO:UNDO_CTO, txt_get_span(text->lines.first, *linep), old, txt_get_span(text->lines.first, *linep), (unsigned short)*charp);
}
void txt_move_bof (Text *text, short sel)
@@ -1058,7 +1062,7 @@ void txt_move_bof (Text *text, short sel)
int *charp, old;
if (!text) return;
- if(sel) txt_curs_sel(text, &linep, &charp);
+ if (sel) txt_curs_sel(text, &linep, &charp);
else txt_curs_cur(text, &linep, &charp);
if (!*linep) return;
old= *charp;
@@ -1066,8 +1070,8 @@ void txt_move_bof (Text *text, short sel)
*linep= text->lines.first;
*charp= 0;
- if(!sel) txt_pop_sel(text);
- if(!undoing) txt_undo_add_toop(text, sel?UNDO_STO:UNDO_CTO, txt_get_span(text->lines.first, *linep), old, txt_get_span(text->lines.first, *linep), (unsigned short)*charp);
+ if (!sel) txt_pop_sel(text);
+ if (!undoing) txt_undo_add_toop(text, sel?UNDO_STO:UNDO_CTO, txt_get_span(text->lines.first, *linep), old, txt_get_span(text->lines.first, *linep), (unsigned short)*charp);
}
void txt_move_eof (Text *text, short sel)
@@ -1076,7 +1080,7 @@ void txt_move_eof (Text *text, short sel)
int *charp, old;
if (!text) return;
- if(sel) txt_curs_sel(text, &linep, &charp);
+ if (sel) txt_curs_sel(text, &linep, &charp);
else txt_curs_cur(text, &linep, &charp);
if (!*linep) return;
old= *charp;
@@ -1084,8 +1088,8 @@ void txt_move_eof (Text *text, short sel)
*linep= text->lines.last;
*charp= (*linep)->len;
- if(!sel) txt_pop_sel(text);
- if(!undoing) txt_undo_add_toop(text, sel?UNDO_STO:UNDO_CTO, txt_get_span(text->lines.first, *linep), old, txt_get_span(text->lines.first, *linep), (unsigned short)*charp);
+ if (!sel) txt_pop_sel(text);
+ if (!undoing) txt_undo_add_toop(text, sel?UNDO_STO:UNDO_CTO, txt_get_span(text->lines.first, *linep), old, txt_get_span(text->lines.first, *linep), (unsigned short)*charp);
}
void txt_move_toline (Text *text, unsigned int line, short sel)
@@ -1101,7 +1105,7 @@ void txt_move_to (Text *text, unsigned int line, unsigned int ch, short sel)
unsigned int i;
if (!text) return;
- if(sel) txt_curs_sel(text, &linep, &charp);
+ if (sel) txt_curs_sel(text, &linep, &charp);
else txt_curs_cur(text, &linep, &charp);
if (!*linep) return;
oldc= *charp;
@@ -1116,8 +1120,8 @@ void txt_move_to (Text *text, unsigned int line, unsigned int ch, short sel)
ch= (unsigned int)((*linep)->len);
*charp= ch;
- if(!sel) txt_pop_sel(text);
- if(!undoing) txt_undo_add_toop(text, sel?UNDO_STO:UNDO_CTO, txt_get_span(text->lines.first, oldl), oldc, txt_get_span(text->lines.first, *linep), (unsigned short)*charp);
+ if (!sel) txt_pop_sel(text);
+ if (!undoing) txt_undo_add_toop(text, sel?UNDO_STO:UNDO_CTO, txt_get_span(text->lines.first, oldl), oldc, txt_get_span(text->lines.first, *linep), (unsigned short)*charp);
}
/****************************/
@@ -1137,7 +1141,7 @@ static void txt_curs_swap (Text *text)
text->curc= text->selc;
text->selc= tmpc;
- if(!undoing) txt_undo_add_op(text, UNDO_SWAP);
+ if (!undoing) txt_undo_add_op(text, UNDO_SWAP);
}
static void txt_pop_first (Text *text)
@@ -1148,7 +1152,7 @@ static void txt_pop_first (Text *text)
txt_curs_swap(text);
}
- if(!undoing) txt_undo_add_toop(text, UNDO_STO,
+ if (!undoing) txt_undo_add_toop(text, UNDO_STO,
txt_get_span(text->lines.first, text->sell),
text->selc,
txt_get_span(text->lines.first, text->curl),
@@ -1164,7 +1168,7 @@ static void txt_pop_last (Text *text)
txt_curs_swap(text);
}
- if(!undoing) txt_undo_add_toop(text, UNDO_STO,
+ if (!undoing) txt_undo_add_toop(text, UNDO_STO,
txt_get_span(text->lines.first, text->sell),
text->selc,
txt_get_span(text->lines.first, text->curl),
@@ -1214,7 +1218,7 @@ static void txt_delete_sel (Text *text)
txt_order_cursors(text);
- if(!undoing) {
+ if (!undoing) {
buf= txt_sel_to_buf(text);
txt_undo_add_block(text, UNDO_DBLOCK, buf);
MEM_freeN(buf);
@@ -1225,7 +1229,8 @@ static void txt_delete_sel (Text *text)
if (text->curl != text->sell) {
txt_clear_marker_region(text, text->curl, text->curc, text->curl->len, 0, 0);
move= txt_get_span(text->curl, text->sell);
- } else {
+ }
+ else {
mrk= txt_find_marker_region(text, text->curl, text->curc, text->selc, 0, 0);
if (mrk && (mrk->start > text->curc || mrk->end < text->selc))
txt_clear_marker_region(text, text->curl, text->curc, text->selc, 0, 0);
@@ -1311,7 +1316,8 @@ char *txt_to_buf (Text *text)
BLI_strncpy(buf, linef->line + charf, length+1);
buf[length]=0;
- } else {
+ }
+ else {
length= linef->len - charf;
length+= charl;
length+= 2; /* For the 2 '\n' */
@@ -1360,7 +1366,7 @@ int txt_find_string(Text *text, const char *findstr, int wrap, int match_case)
tl= startl= text->sell;
- if(match_case) s= strstr(&tl->line[text->selc], findstr);
+ if (match_case) s= strstr(&tl->line[text->selc], findstr);
else s= BLI_strcasestr(&tl->line[text->selc], findstr);
while (!s) {
tl= tl->next;
@@ -1371,7 +1377,7 @@ int txt_find_string(Text *text, const char *findstr, int wrap, int match_case)
break;
}
- if(match_case) s= strstr(tl->line, findstr);
+ if (match_case) s= strstr(tl->line, findstr);
else s= BLI_strcasestr(tl->line, findstr);
if (tl==startl)
break;
@@ -1383,7 +1389,8 @@ int txt_find_string(Text *text, const char *findstr, int wrap, int match_case)
txt_move_to(text, newl, newc, 0);
txt_move_to(text, newl, newc + strlen(findstr), 1);
return 1;
- } else
+ }
+ else
return 0;
}
@@ -1404,17 +1411,20 @@ char *txt_sel_to_buf (Text *text)
if (text->curc < text->selc) {
charf= text->curc;
charl= text->selc;
- } else{
+ }
+ else {
charf= text->selc;
charl= text->curc;
}
- } else if (txt_get_span(text->curl, text->sell)<0) {
+ }
+ else if (txt_get_span(text->curl, text->sell)<0) {
linef= text->sell;
linel= text->curl;
charf= text->selc;
charl= text->curc;
- } else {
+ }
+ else {
linef= text->curl;
linel= text->sell;
@@ -1428,7 +1438,8 @@ char *txt_sel_to_buf (Text *text)
buf= MEM_mallocN(length+1, "sel buffer");
BLI_strncpy(buf, linef->line + charf, length+1);
- } else {
+ }
+ else {
length+= linef->len - charf;
length+= charl;
length++; /* For the '\n' */
@@ -1490,7 +1501,7 @@ void txt_insert_buf(Text *text, const char *in_buffer)
buffer= BLI_strdupn(in_buffer, len);
len+= txt_extended_ascii_as_utf8(&buffer);
- if(!undoing) txt_undo_add_block(text, UNDO_IBLOCK, buffer);
+ if (!undoing) txt_undo_add_block(text, UNDO_IBLOCK, buffer);
u= undoing;
undoing= 1;
@@ -1513,13 +1524,14 @@ void txt_insert_buf(Text *text, const char *in_buffer)
i++; l++;
}
- if(buffer[i]=='\n') {
+ if (buffer[i]=='\n') {
add= txt_new_linen(buffer +(i-l), l);
BLI_insertlinkbefore(&text->lines, text->curl, add);
i++;
count++;
- } else {
- if(count) {
+ }
+ else {
+ if (count) {
txt_shift_markers(text, lineno, count);
count= 0;
}
@@ -1532,7 +1544,7 @@ void txt_insert_buf(Text *text, const char *in_buffer)
MEM_freeN(buffer);
- if(count) {
+ if (count) {
txt_shift_markers(text, lineno, count);
}
@@ -1546,12 +1558,13 @@ void txt_insert_buf(Text *text, const char *in_buffer)
static int max_undo_test(Text *text, int x)
{
while (text->undo_pos+x >= text->undo_len) {
- if(text->undo_len*2 > TXT_MAX_UNDO) {
+ if (text->undo_len*2 > TXT_MAX_UNDO) {
/* XXX error("Undo limit reached, buffer cleared\n"); */
MEM_freeN(text->undo_buf);
init_undo_text(text);
return 0;
- } else {
+ }
+ else {
void *tmp= text->undo_buf;
text->undo_buf= MEM_callocN(text->undo_len*2, "undo buf");
memcpy(text->undo_buf, tmp, text->undo_len);
@@ -1588,63 +1601,92 @@ void txt_print_undo(Text *text)
if (op==UNDO_CLEFT) {
ops= "Cursor left";
- } else if (op==UNDO_CRIGHT) {
+ }
+ else if (op==UNDO_CRIGHT) {
ops= "Cursor right";
- } else if (op==UNDO_CUP) {
+ }
+ else if (op==UNDO_CUP) {
ops= "Cursor up";
- } else if (op==UNDO_CDOWN) {
+ }
+ else if (op==UNDO_CDOWN) {
ops= "Cursor down";
- } else if (op==UNDO_SLEFT) {
+ }
+ else if (op==UNDO_SLEFT) {
ops= "Selection left";
- } else if (op==UNDO_SRIGHT) {
+ }
+ else if (op==UNDO_SRIGHT) {
ops= "Selection right";
- } else if (op==UNDO_SUP) {
+ }
+ else if (op==UNDO_SUP) {
ops= "Selection up";
- } else if (op==UNDO_SDOWN) {
+ }
+ else if (op==UNDO_SDOWN) {
ops= "Selection down";
- } else if (op==UNDO_STO) {
+ }
+ else if (op==UNDO_STO) {
ops= "Selection ";
- } else if (op==UNDO_CTO) {
+ }
+ else if (op==UNDO_CTO) {
ops= "Cursor ";
- } else if (op==UNDO_INSERT_1) {
+ }
+ else if (op==UNDO_INSERT_1) {
ops= "Insert ascii ";
- } else if (op==UNDO_INSERT_2) {
+ }
+ else if (op==UNDO_INSERT_2) {
ops= "Insert 2 bytes ";
- } else if (op==UNDO_INSERT_3) {
+ }
+ else if (op==UNDO_INSERT_3) {
ops= "Insert 3 bytes ";
- } else if (op==UNDO_INSERT_4) {
+ }
+ else if (op==UNDO_INSERT_4) {
ops= "Insert unicode ";
- } else if (op==UNDO_BS_1) {
+ }
+ else if (op==UNDO_BS_1) {
ops= "Backspace for ascii ";
- } else if (op==UNDO_BS_2) {
+ }
+ else if (op==UNDO_BS_2) {
ops= "Backspace for 2 bytes ";
- } else if (op==UNDO_BS_3) {
+ }
+ else if (op==UNDO_BS_3) {
ops= "Backspace for 3 bytes ";
- } else if (op==UNDO_BS_4) {
+ }
+ else if (op==UNDO_BS_4) {
ops= "Backspace for unicode ";
- } else if (op==UNDO_DEL_1) {
+ }
+ else if (op==UNDO_DEL_1) {
ops= "Delete ascii ";
- } else if (op==UNDO_DEL_2) {
+ }
+ else if (op==UNDO_DEL_2) {
ops= "Delete 2 bytes ";
- } else if (op==UNDO_DEL_3) {
+ }
+ else if (op==UNDO_DEL_3) {
ops= "Delete 3 bytes ";
- } else if (op==UNDO_DEL_4) {
+ }
+ else if (op==UNDO_DEL_4) {
ops= "Delete unicode ";
- } else if (op==UNDO_SWAP) {
+ }
+ else if (op==UNDO_SWAP) {
ops= "Cursor swap";
- } else if (op==UNDO_DBLOCK) {
+ }
+ else if (op==UNDO_DBLOCK) {
ops= "Delete text block";
- } else if (op==UNDO_IBLOCK) {
+ }
+ else if (op==UNDO_IBLOCK) {
ops= "Insert text block";
- } else if (op==UNDO_INDENT) {
+ }
+ else if (op==UNDO_INDENT) {
ops= "Indent ";
- } else if (op==UNDO_UNINDENT) {
+ }
+ else if (op==UNDO_UNINDENT) {
ops= "Unindent ";
- } else if (op==UNDO_COMMENT) {
+ }
+ else if (op==UNDO_COMMENT) {
ops= "Comment ";
- } else if (op==UNDO_UNCOMMENT) {
+ }
+ else if (op==UNDO_UNCOMMENT) {
ops= "Uncomment ";
- } else {
+ }
+ else {
ops= "Unknown";
}
@@ -1678,7 +1720,8 @@ void txt_print_undo(Text *text)
puts(c);
}
}
- } else if (op==UNDO_STO || op==UNDO_CTO) {
+ }
+ else if (op==UNDO_STO || op==UNDO_CTO) {
i++;
charp= text->undo_buf[i]; i++;
@@ -1700,7 +1743,8 @@ void txt_print_undo(Text *text)
linep= linep+(text->undo_buf[i]<<24); i++;
printf ("from <%d, %d>", linep, charp);
- } else if (op==UNDO_DBLOCK || op==UNDO_IBLOCK) {
+ }
+ else if (op==UNDO_DBLOCK || op==UNDO_IBLOCK) {
i++;
linep= text->undo_buf[i]; i++;
@@ -1720,7 +1764,8 @@ void txt_print_undo(Text *text)
linep= linep+(text->undo_buf[i]<<16); i++;
linep= linep+(text->undo_buf[i]<<24); i++;
printf ("> (%d)", linep);
- } else if (op==UNDO_INDENT || op==UNDO_UNINDENT) {
+ }
+ else if (op==UNDO_INDENT || op==UNDO_UNINDENT) {
i++;
charp= text->undo_buf[i]; i++;
@@ -1751,7 +1796,7 @@ void txt_print_undo(Text *text)
static void txt_undo_add_op(Text *text, int op)
{
- if(!max_undo_test(text, 2))
+ if (!max_undo_test(text, 2))
return;
text->undo_pos++;
@@ -1783,7 +1828,7 @@ static void txt_undo_add_block(Text *text, int op, const char *buf)
{
unsigned int length= strlen(buf);
- if(!max_undo_test(text, length+11))
+ if (!max_undo_test(text, length+11))
return;
text->undo_pos++;
@@ -1803,7 +1848,7 @@ static void txt_undo_add_block(Text *text, int op, const char *buf)
void txt_undo_add_toop(Text *text, int op, unsigned int froml, unsigned short fromc, unsigned int tol, unsigned short toc)
{
- if(!max_undo_test(text, 15))
+ if (!max_undo_test(text, 15))
return;
if (froml==tol && fromc==toc) return;
@@ -1828,7 +1873,7 @@ static void txt_undo_add_charop(Text *text, int op_start, unsigned int c)
char utf8[BLI_UTF8_MAX];
size_t i, utf8_size = BLI_str_utf8_from_unicode(c, utf8);
- if(!max_undo_test(text, 3 + utf8_size))
+ if (!max_undo_test(text, 3 + utf8_size))
return;
text->undo_pos++;
@@ -1843,7 +1888,8 @@ static void txt_undo_add_charop(Text *text, int op_start, unsigned int c)
}
text->undo_buf[text->undo_pos]= op_start + utf8_size - 1;
- } else {
+ }
+ else {
text->undo_buf[text->undo_pos]= op_start + 3;
text->undo_pos++;
txt_undo_store_uint32(text->undo_buf, &text->undo_pos, c);
@@ -2022,7 +2068,8 @@ void txt_do_undo(Text *text)
txt_move_toline(text, linep, 0);
text->curc= charp;
txt_pop_sel(text);
- } else {
+ }
+ else {
txt_move_toline(text, linep, 1);
text->selc= charp;
}
@@ -2071,7 +2118,7 @@ void txt_do_undo(Text *text)
text->curl= text->lines.first;
while (holdln>0) {
- if(text->curl->next)
+ if (text->curl->next)
text->curl= text->curl->next;
holdln--;
@@ -2145,11 +2192,14 @@ void txt_do_undo(Text *text)
if (op==UNDO_INDENT) {
txt_unindent(text);
- } else if (op== UNDO_UNINDENT) {
+ }
+ else if (op== UNDO_UNINDENT) {
txt_indent(text);
- } else if (op == UNDO_COMMENT) {
+ }
+ else if (op == UNDO_COMMENT) {
txt_uncomment(text);
- } else if (op == UNDO_UNCOMMENT) {
+ }
+ else if (op == UNDO_UNCOMMENT) {
txt_comment(text);
}
@@ -2270,7 +2320,8 @@ void txt_do_redo(Text *text)
txt_move_toline(text, linep, 0);
text->curc= charp;
txt_pop_sel(text);
- } else {
+ }
+ else {
txt_move_toline(text, linep, 1);
text->selc= charp;
}
@@ -2340,11 +2391,14 @@ void txt_do_redo(Text *text)
if (op==UNDO_INDENT) {
txt_indent(text);
- } else if (op== UNDO_UNINDENT) {
+ }
+ else if (op== UNDO_UNINDENT) {
txt_unindent(text);
- } else if (op == UNDO_COMMENT) {
+ }
+ else if (op == UNDO_COMMENT) {
txt_comment(text);
- } else if (op == UNDO_UNCOMMENT) {
+ }
+ else if (op == UNDO_UNCOMMENT) {
txt_uncomment(text);
}
break;
@@ -2383,7 +2437,8 @@ void txt_split_curline (Text *text)
mrk->lineno++;
mrk->start -= text->curc;
mrk->end -= text->curc;
- } else if (mrk->lineno > lineno) {
+ }
+ else if (mrk->lineno > lineno) {
mrk->lineno++;
}
mrk= mrk->next;
@@ -2420,7 +2475,7 @@ void txt_split_curline (Text *text)
txt_clean_text(text);
txt_pop_sel(text);
- if(!undoing) txt_undo_add_charop(text, UNDO_INSERT_1, '\n');
+ if (!undoing) txt_undo_add_charop(text, UNDO_INSERT_1, '\n');
}
static void txt_delete_line (Text *text, TextLine *line)
@@ -2461,7 +2516,7 @@ static void txt_combine_lines (Text *text, TextLine *linea, TextLine *lineb)
if (!text) return;
- if(!linea || !lineb) return;
+ if (!linea || !lineb) return;
mrk= txt_find_marker_region(text, lineb, 0, lineb->len, 0, 0);
if (mrk) {
@@ -2505,7 +2560,8 @@ void txt_delete_char(Text *text)
txt_combine_lines(text, text->curl, text->curl->next);
txt_pop_sel(text);
}
- } else { /* Just deleting a char */
+ }
+ else { /* Just deleting a char */
size_t c_len = 0;
TextMarker *mrk;
c= BLI_str_utf8_as_unicode_and_size(text->curl->line + text->curc, &c_len);
@@ -2516,7 +2572,8 @@ void txt_delete_char(Text *text)
if (mrk->end==text->curc) {
if ((mrk->flags & TMARK_TEMP) && !(mrk->flags & TMARK_EDITALL)) {
txt_clear_markers(text, mrk->group, TMARK_TEMP);
- } else {
+ }
+ else {
BLI_freelinkN(&text->markers, mrk);
}
return;
@@ -2538,7 +2595,7 @@ void txt_delete_char(Text *text)
txt_make_dirty(text);
txt_clean_text(text);
- if(!undoing) txt_undo_add_charop(text, UNDO_DEL_1, c);
+ if (!undoing) txt_undo_add_charop(text, UNDO_DEL_1, c);
}
void txt_delete_word (Text *text)
@@ -2580,7 +2637,8 @@ void txt_backspace_char (Text *text)
if (mrk->start==text->curc) {
if ((mrk->flags & TMARK_TEMP) && !(mrk->flags & TMARK_EDITALL)) {
txt_clear_markers(text, mrk->group, TMARK_TEMP);
- } else {
+ }
+ else {
BLI_freelinkN(&text->markers, mrk);
}
return;
@@ -2603,7 +2661,7 @@ void txt_backspace_char (Text *text)
txt_make_dirty(text);
txt_clean_text(text);
- if(!undoing) txt_undo_add_charop(text, UNDO_BS_1, c);
+ if (!undoing) txt_undo_add_charop(text, UNDO_BS_1, c);
}
void txt_backspace_word (Text *text)
@@ -2676,7 +2734,7 @@ static int txt_add_char_intern (Text *text, unsigned int add, int replace_tabs)
txt_make_dirty(text);
txt_clean_text(text);
- if(!undoing) txt_undo_add_charop(text, UNDO_INSERT_1, add);
+ if (!undoing) txt_undo_add_charop(text, UNDO_INSERT_1, add);
return 1;
}
@@ -2722,7 +2780,8 @@ int txt_replace_char (Text *text, unsigned int add)
memcpy(tmp+text->curc+add_size, text->curl->line+text->curc+del_size, text->curl->len-text->curc-del_size+1);
MEM_freeN(text->curl->line);
text->curl->line = tmp;
- } else if (add_size < del_size) {
+ }
+ else if (add_size < del_size) {
char *tmp= text->curl->line;
memmove(tmp+text->curc+add_size, tmp+text->curc+del_size, text->curl->len-text->curc-del_size+1);
}
@@ -2735,7 +2794,7 @@ int txt_replace_char (Text *text, unsigned int add)
txt_clean_text(text);
/* Should probably create a new op for this */
- if(!undoing) {
+ if (!undoing) {
txt_undo_add_charop(text, UNDO_DEL_1, del);
txt_undo_add_charop(text, UNDO_INSERT_1, add);
}
@@ -2773,11 +2832,11 @@ void txt_indent(Text *text)
tmp= MEM_mallocN(text->curl->len+indentlen+1, "textline_string");
text->curc = 0;
- if(text->curc) memcpy(tmp, text->curl->line, text->curc); /* XXX never true, check prev line */
+ if (text->curc) memcpy(tmp, text->curl->line, text->curc); /* XXX never true, check prev line */
memcpy(tmp+text->curc, add, indentlen);
len= text->curl->len - text->curc;
- if(len>0) memcpy(tmp+text->curc+indentlen, text->curl->line+text->curc, len);
+ if (len>0) memcpy(tmp+text->curc+indentlen, text->curl->line+text->curc, len);
tmp[text->curl->len+indentlen]= 0;
make_new_line(text->curl, tmp);
@@ -2787,23 +2846,24 @@ void txt_indent(Text *text)
txt_make_dirty(text);
txt_clean_text(text);
- if(text->curl == text->sell)
+ if (text->curl == text->sell)
{
text->selc = text->sell->len;
break;
- } else {
+ }
+ else {
text->curl = text->curl->next;
num++;
}
}
text->curc = 0;
- while( num > 0 )
+ while ( num > 0 )
{
text->curl = text->curl->prev;
num--;
}
- if(!undoing)
+ if (!undoing)
{
txt_undo_add_toop(text, UNDO_INDENT, txt_get_span(text->lines.first, text->curl), text->curc, txt_get_span(text->lines.first, text->sell), text->selc);
}
@@ -2828,13 +2888,13 @@ void txt_unindent(Text *text)
indent = spaceslen;
}
- while(TRUE)
+ while (TRUE)
{
int i = 0;
if (BLI_strncasecmp(text->curl->line, remove, indent) == 0)
{
- while(i< text->curl->len) {
+ while (i< text->curl->len) {
text->curl->line[i]= text->curl->line[i+indent];
i++;
}
@@ -2844,24 +2904,25 @@ void txt_unindent(Text *text)
txt_make_dirty(text);
txt_clean_text(text);
- if(text->curl == text->sell)
+ if (text->curl == text->sell)
{
text->selc = text->sell->len;
break;
- } else {
+ }
+ else {
text->curl = text->curl->next;
num++;
}
}
text->curc = 0;
- while( num > 0 )
+ while ( num > 0 )
{
text->curl = text->curl->prev;
num--;
}
- if(!undoing)
+ if (!undoing)
{
txt_undo_add_toop(text, UNDO_UNINDENT, txt_get_span(text->lines.first, text->curl), text->curc, txt_get_span(text->lines.first, text->sell), text->selc);
}
@@ -2883,11 +2944,11 @@ void txt_comment(Text *text)
tmp= MEM_mallocN(text->curl->len+2, "textline_string");
text->curc = 0;
- if(text->curc) memcpy(tmp, text->curl->line, text->curc);
+ if (text->curc) memcpy(tmp, text->curl->line, text->curc);
tmp[text->curc]= add;
len= text->curl->len - text->curc;
- if(len>0) memcpy(tmp+text->curc+1, text->curl->line+text->curc, len);
+ 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);
@@ -2897,23 +2958,24 @@ void txt_comment(Text *text)
txt_make_dirty(text);
txt_clean_text(text);
- if(text->curl == text->sell)
+ if (text->curl == text->sell)
{
text->selc = text->sell->len;
break;
- } else {
+ }
+ else {
text->curl = text->curl->next;
num++;
}
}
text->curc = 0;
- while( num > 0 )
+ while ( num > 0 )
{
text->curl = text->curl->prev;
num--;
}
- if(!undoing)
+ if (!undoing)
{
txt_undo_add_toop(text, UNDO_COMMENT, txt_get_span(text->lines.first, text->curl), text->curc, txt_get_span(text->lines.first, text->sell), text->selc);
}
@@ -2928,13 +2990,13 @@ void txt_uncomment(Text *text)
if (!text->curl) return;
if (!text->sell) return;
- while(TRUE)
+ while (TRUE)
{
int i = 0;
if (text->curl->line[i] == remove)
{
- while(i< text->curl->len) {
+ while (i< text->curl->len) {
text->curl->line[i]= text->curl->line[i+1];
i++;
}
@@ -2945,24 +3007,25 @@ void txt_uncomment(Text *text)
txt_make_dirty(text);
txt_clean_text(text);
- if(text->curl == text->sell)
+ if (text->curl == text->sell)
{
text->selc = text->sell->len;
break;
- } else {
+ }
+ else {
text->curl = text->curl->next;
num++;
}
}
text->curc = 0;
- while( num > 0 )
+ while ( num > 0 )
{
text->curl = text->curl->prev;
num--;
}
- if(!undoing)
+ if (!undoing)
{
txt_undo_add_toop(text, UNDO_UNCOMMENT, txt_get_span(text->lines.first, text->curl), text->curc, txt_get_span(text->lines.first, text->sell), text->selc);
}
@@ -2985,11 +3048,12 @@ int setcurr_tab_spaces (Text *text, int space)
if (i == text->curc)
{
return i;
- } else {
+ }
+ else {
i++;
}
}
- if(strstr(text->curl->line, word))
+ if (strstr(text->curl->line, word))
{
/* if we find a ':' on this line, then add a tab but not if it is:
* 1) in a comment
@@ -2997,14 +3061,16 @@ int setcurr_tab_spaces (Text *text, int space)
* 3) after the cursor (text->curc), i.e. when creating space before a function def [#25414]
*/
int a, is_indent = 0;
- for(a=0; (a < text->curc) && (text->curl->line[a] != '\0'); a++)
+ for (a=0; (a < text->curc) && (text->curl->line[a] != '\0'); a++)
{
char ch= text->curl->line[a];
if (ch=='#') {
break;
- } else if (ch==':') {
+ }
+ else if (ch==':') {
is_indent = 1;
- } else if (ch!=' ' && ch!='\t') {
+ }
+ else if (ch!=' ' && ch!='\t') {
is_indent = 0;
}
}
@@ -3013,12 +3079,12 @@ int setcurr_tab_spaces (Text *text, int space)
}
}
- for(test=0; back_words[test]; test++)
+ for (test=0; back_words[test]; test++)
{
/* if there are these key words then remove a tab because we are done with the block */
- if(strstr(text->curl->line, back_words[test]) && i > 0)
+ if (strstr(text->curl->line, back_words[test]) && i > 0)
{
- if(strcspn(text->curl->line, back_words[test]) < strcspn(text->curl->line, comm))
+ if (strcspn(text->curl->line, back_words[test]) < strcspn(text->curl->line, comm))
{
i -= space;
}
@@ -3184,10 +3250,10 @@ int text_check_bracket(char ch)
char opens[] = "([{";
char close[] = ")]}";
- for(a=0; a<(sizeof(opens)-1); a++) {
- if(ch==opens[a])
+ for (a=0; a<(sizeof(opens)-1); a++) {
+ if (ch==opens[a])
return a+1;
- else if(ch==close[a])
+ else if (ch==close[a])
return -(a+1);
}
return 0;
@@ -3198,8 +3264,8 @@ int text_check_delim(char ch)
int a;
char delims[] = "():\"\' ~!%^&*-+=[]{};/<>|.#\t,";
- for(a=0; a<(sizeof(delims)-1); a++) {
- if(ch==delims[a])
+ for (a=0; a<(sizeof(delims)-1); a++) {
+ if (ch==delims[a])
return 1;
}
return 0;
@@ -3207,25 +3273,25 @@ int text_check_delim(char ch)
int text_check_digit(char ch)
{
- if(ch < '0') return 0;
- if(ch <= '9') return 1;
+ if (ch < '0') return 0;
+ if (ch <= '9') return 1;
return 0;
}
int text_check_identifier(char ch)
{
- if(ch < '0') return 0;
- if(ch <= '9') return 1;
- if(ch < 'A') return 0;
- if(ch <= 'Z' || ch == '_') return 1;
- if(ch < 'a') return 0;
- if(ch <= 'z') return 1;
+ if (ch < '0') return 0;
+ if (ch <= '9') return 1;
+ if (ch < 'A') return 0;
+ if (ch <= 'Z' || ch == '_') return 1;
+ if (ch < 'a') return 0;
+ if (ch <= 'z') return 1;
return 0;
}
int text_check_whitespace(char ch)
{
- if(ch == ' ' || ch == '\t' || ch == '\r' || ch == '\n')
+ if (ch == ' ' || ch == '\t' || ch == '\r' || ch == '\n')
return 1;
return 0;
}