diff options
Diffstat (limited to 'source/blender/blenkernel/intern/text.c')
-rw-r--r-- | source/blender/blenkernel/intern/text.c | 69 |
1 files changed, 38 insertions, 31 deletions
diff --git a/source/blender/blenkernel/intern/text.c b/source/blender/blenkernel/intern/text.c index ba5d4282416..2c507370288 100644 --- a/source/blender/blenkernel/intern/text.c +++ b/source/blender/blenkernel/intern/text.c @@ -238,7 +238,7 @@ static void cleanup_textline(TextLine * tl) int reopen_text(Text *text) { FILE *fp; - int i, llen, len, res; + int i, llen, len; unsigned char *buffer; TextLine *tmp; char str[FILE_MAXDIR+FILE_MAXFILE]; @@ -281,7 +281,7 @@ int reopen_text(Text *text) fclose(fp); - res= stat(str, &st); + stat(str, &st); text->mtime= st.st_mtime; text->nlines=0; @@ -334,7 +334,7 @@ Text *add_text(const char *file, const char *relpath) { Main *bmain= G.main; FILE *fp; - int i, llen, len, res; + int i, llen, len; unsigned char *buffer; TextLine *tmp; Text *ta; @@ -374,7 +374,7 @@ Text *add_text(const char *file, const char *relpath) fclose(fp); - res= stat(str, &st); + stat(str, &st); ta->mtime= st.st_mtime; ta->nlines=0; @@ -400,7 +400,13 @@ Text *add_text(const char *file, const char *relpath) llen++; } - if (llen!=0 || ta->nlines==0) { + /* create new line in cases: + - rest of line (if last line in file hasn't got \n terminator). + in this case content of such line would be used to fill text line buffer + - file is empty. in this case new line is needed to start editing from. + - last characted in buffer is \n. in this case new line is needed to + deal with newline at end of file. (see [#28087]) (sergey) */ + if (llen!=0 || ta->nlines==0 || buffer[len-1]=='\n') { tmp= (TextLine*) MEM_mallocN(sizeof(TextLine), "textline"); tmp->line= (char*) MEM_mallocN(llen+1, "textline_string"); tmp->format= NULL; @@ -1232,21 +1238,19 @@ char *txt_to_buf (Text *text) return buf; } -int txt_find_string(Text *text, char *findstr, int wrap) +int txt_find_string(Text *text, char *findstr, int wrap, int match_case) { TextLine *tl, *startl; char *s= NULL; - int oldcl, oldsl; if (!text || !text->curl || !text->sell) return 0; txt_order_cursors(text); - oldcl= txt_get_span(text->lines.first, text->curl); - oldsl= txt_get_span(text->lines.first, text->sell); tl= startl= text->sell; - 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; if (!tl) { @@ -1256,7 +1260,8 @@ int txt_find_string(Text *text, char *findstr, int wrap) break; } - s= strstr(tl->line, findstr); + if(match_case) s= strstr(tl->line, findstr); + else s= BLI_strcasestr(tl->line, findstr); if (tl==startl) break; } @@ -1418,6 +1423,8 @@ void txt_insert_buf(Text *text, const char *in_buffer) } undoing= u; + + (void)count; } /******************/ @@ -1892,13 +1899,13 @@ void txt_do_undo(Text *text) if (op==UNDO_INDENT) { - unindent(text); + txt_unindent(text); } else if (op== UNDO_UNINDENT) { - indent(text); + txt_indent(text); } else if (op == UNDO_COMMENT) { - uncomment(text); + txt_uncomment(text); } else if (op == UNDO_UNCOMMENT) { - comment(text); + txt_comment(text); } text->undo_pos--; @@ -2108,13 +2115,13 @@ void txt_do_redo(Text *text) } if (op==UNDO_INDENT) { - indent(text); + txt_indent(text); } else if (op== UNDO_UNINDENT) { - unindent(text); + txt_unindent(text); } else if (op == UNDO_COMMENT) { - comment(text); + txt_comment(text); } else if (op == UNDO_UNCOMMENT) { - uncomment(text); + txt_uncomment(text); } break; default: @@ -2412,7 +2419,7 @@ static int txt_add_char_intern (Text *text, char add, int replace_tabs) return 1; } - /* insert spaces rather then tabs */ + /* insert spaces rather than tabs */ if (add == '\t' && replace_tabs) { txt_convert_tab_to_spaces(text); return 1; @@ -2499,7 +2506,7 @@ int txt_replace_char (Text *text, char add) return 1; } -void indent(Text *text) +void txt_indent(Text *text) { int len, num; char *tmp; @@ -2510,7 +2517,7 @@ void indent(Text *text) /* hardcoded: TXT_TABSIZE = 4 spaces: */ int spaceslen = TXT_TABSIZE; - /* insert spaces rather then tabs */ + /* insert spaces rather than tabs */ if (text->flags & TXT_TABSTOSPACES){ add = tab_to_spaces; indentlen = spaceslen; @@ -2562,7 +2569,7 @@ void indent(Text *text) } } -void unindent(Text *text) +void txt_unindent(Text *text) { int num = 0; const char *remove = "\t"; @@ -2571,7 +2578,7 @@ void unindent(Text *text) /* hardcoded: TXT_TABSIZE = 4 spaces: */ int spaceslen = TXT_TABSIZE; - /* insert spaces rather then tabs */ + /* insert spaces rather than tabs */ if (text->flags & TXT_TABSTOSPACES){ remove = tab_to_spaces; indent = spaceslen; @@ -2620,7 +2627,7 @@ void unindent(Text *text) } } -void comment(Text *text) +void txt_comment(Text *text) { int len, num; char *tmp; @@ -2672,7 +2679,7 @@ void comment(Text *text) } } -void uncomment(Text *text) +void txt_uncomment(Text *text) { int num = 0; char remove = '#'; @@ -2749,19 +2756,19 @@ int setcurr_tab_spaces (Text *text, int space) * 2) within an identifier * 3) after the cursor (text->curc), i.e. when creating space before a function def [#25414] */ - int a, indent = 0; + int a, is_indent = 0; for(a=0; (a < text->curc) && (text->curl->line[a] != '\0'); a++) { char ch= text->curl->line[a]; if (ch=='#') { break; } else if (ch==':') { - indent = 1; - } else if (ch==']' || ch=='}' || ch=='"' || ch=='\'') { - indent = 0; + is_indent = 1; + } else if (ch!=' ' && ch!='\t') { + is_indent = 0; } } - if (indent) { + if (is_indent) { i += space; } } |