diff options
author | Campbell Barton <ideasman42@gmail.com> | 2018-06-17 18:05:51 +0300 |
---|---|---|
committer | Campbell Barton <ideasman42@gmail.com> | 2018-06-17 18:05:51 +0300 |
commit | 6fc8a74886a30f89562bb542ef3b24cc64b3208a (patch) | |
tree | df0503b6cf4f6b762eca66b90f4360c495d624aa /source/blender/blenkernel/intern/text.c | |
parent | a262ea8c47f8106f66e16935c556f383ef306861 (diff) |
Cleanup: trailing space for blenkernel
Diffstat (limited to 'source/blender/blenkernel/intern/text.c')
-rw-r--r-- | source/blender/blenkernel/intern/text.c | 346 |
1 files changed, 173 insertions, 173 deletions
diff --git a/source/blender/blenkernel/intern/text.c b/source/blender/blenkernel/intern/text.c index eed3138ec1b..76df163ee3a 100644 --- a/source/blender/blenkernel/intern/text.c +++ b/source/blender/blenkernel/intern/text.c @@ -232,15 +232,15 @@ void BKE_text_init(Text *ta) tmp = (TextLine *) MEM_mallocN(sizeof(TextLine), "textline"); tmp->line = (char *) MEM_mallocN(1, "textline_string"); tmp->format = NULL; - + tmp->line[0] = 0; tmp->len = 0; - + tmp->next = NULL; tmp->prev = NULL; - + BLI_addhead(&ta->lines, tmp); - + ta->curl = ta->lines.first; ta->curc = 0; ta->sell = ta->lines.first; @@ -273,18 +273,18 @@ int txt_extended_ascii_as_utf8(char **str) added++; i += bad_char + 1; } - + if (added != 0) { char *newstr = MEM_mallocN(length + added + 1, "text_line"); ptrdiff_t mi = 0; i = 0; - + while ((*str)[i]) { if ((bad_char = BLI_utf8_invalid_byte((*str) + i, length - i)) == -1) { memcpy(newstr + mi, (*str) + i, length - i + 1); break; } - + memcpy(newstr + mi, (*str) + i, bad_char); BLI_str_utf8_from_unicode((*str)[i + bad_char], newstr + mi + bad_char); @@ -295,7 +295,7 @@ int txt_extended_ascii_as_utf8(char **str) MEM_freeN(*str); *str = newstr; } - + return added; } @@ -392,7 +392,7 @@ bool BKE_text_reload(Text *text) BLI_strncpy(filepath_abs, text->name, FILE_MAX); BLI_path_abs(filepath_abs, BKE_main_blendfile_path_from_global()); - + buffer = BLI_file_read_text_as_mem(filepath_abs, 0, &buffer_len); if (buffer == NULL) { return false; @@ -427,7 +427,7 @@ Text *BKE_text_load_ex(Main *bmain, const char *file, const char *relpath, const BLI_strncpy(filepath_abs, file, FILE_MAX); if (relpath) /* can be NULL (bg mode) */ BLI_path_abs(filepath_abs, relpath); - + buffer = BLI_file_read_text_as_mem(filepath_abs, 0, &buffer_len); if (buffer == NULL) { return false; @@ -457,9 +457,9 @@ Text *BKE_text_load_ex(Main *bmain, const char *file, const char *relpath, const else { ta->mtime = 0; } - + text_from_buf(ta, buffer, buffer_len); - + MEM_freeN(buffer); return ta; @@ -608,7 +608,7 @@ 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 = NULL; @@ -619,16 +619,16 @@ static TextLine *txt_new_line(const char *str) TextLine *tmp; if (!str) str = ""; - + tmp = (TextLine *) MEM_mallocN(sizeof(TextLine), "textline"); tmp->line = MEM_mallocN(strlen(str) + 1, "textline_string"); tmp->format = NULL; - + strcpy(tmp->line, str); - + tmp->len = strlen(str); tmp->next = tmp->prev = NULL; - + return tmp; } @@ -639,29 +639,29 @@ static TextLine *txt_new_linen(const char *str, int n) tmp = (TextLine *) MEM_mallocN(sizeof(TextLine), "textline"); tmp->line = MEM_mallocN(n + 1, "textline_string"); tmp->format = NULL; - + BLI_strncpy(tmp->line, (str) ? str : "", n + 1); - + tmp->len = strlen(tmp->line); tmp->next = tmp->prev = NULL; - + return tmp; } void txt_clean_text(Text *text) -{ +{ TextLine **top, **bot; if (!text->lines.first) { if (text->lines.last) text->lines.first = text->lines.last; else text->lines.first = text->lines.last = txt_new_line(NULL); } - + if (!text->lines.last) text->lines.last = text->lines.first; top = (TextLine **) &text->lines.first; bot = (TextLine **) &text->lines.last; - + while ((*top)->prev) *top = (*top)->prev; while ((*bot)->next) *bot = (*bot)->next; @@ -799,7 +799,7 @@ void txt_move_up(Text *text, const bool sel) int column = txt_utf8_offset_to_column((*linep)->line, *charp); *linep = (*linep)->prev; *charp = txt_utf8_column_to_offset((*linep)->line, column); - + } else { txt_move_bol(text, sel); @@ -891,7 +891,7 @@ void txt_move_left(Text *text, const bool sel) if (text->flags & TXT_TABSTOSPACES) { tabsize = txt_calc_tab_left(*linep, *charp); } - + if (tabsize) { (*charp) -= tabsize; } @@ -927,7 +927,7 @@ void txt_move_right(Text *text, const bool sel) if (text->flags & TXT_TABSTOSPACES) { tabsize = txt_calc_tab_right(*linep, *charp); } - + if (tabsize) { (*charp) += tabsize; } @@ -935,7 +935,7 @@ void txt_move_right(Text *text, const bool sel) (*charp) += BLI_str_utf8_size((*linep)->line + *charp); } } - + if (!sel) txt_pop_sel(text); } @@ -951,7 +951,7 @@ void txt_jump_left(Text *text, const bool sel, const bool use_init_step) BLI_str_cursor_step_utf8((*linep)->line, (*linep)->len, charp, STRCUR_DIR_PREV, STRCUR_JUMP_DELIM, use_init_step); - + if (!sel) txt_pop_sel(text); } @@ -963,11 +963,11 @@ void txt_jump_right(Text *text, const bool sel, const bool use_init_step) if (sel) txt_curs_sel(text, &linep, &charp); else { txt_pop_last(text); txt_curs_cur(text, &linep, &charp); } if (!*linep) return; - + BLI_str_cursor_step_utf8((*linep)->line, (*linep)->len, charp, STRCUR_DIR_NEXT, STRCUR_JUMP_DELIM, use_init_step); - + if (!sel) txt_pop_sel(text); } @@ -979,7 +979,7 @@ void txt_move_bol(Text *text, const bool sel) if (sel) txt_curs_sel(text, &linep, &charp); else txt_curs_cur(text, &linep, &charp); if (!*linep) return; - + *charp = 0; if (!sel) txt_pop_sel(text); @@ -1044,7 +1044,7 @@ void txt_move_to(Text *text, unsigned int line, unsigned int ch, const bool sel) if (sel) txt_curs_sel(text, &linep, &charp); else txt_curs_cur(text, &linep, &charp); if (!*linep) return; - + *linep = text->lines.first; for (i = 0; i < line; i++) { if ((*linep)->next) *linep = (*linep)->next; @@ -1053,7 +1053,7 @@ void txt_move_to(Text *text, unsigned int line, unsigned int ch, const bool sel) if (ch > (unsigned int)((*linep)->len)) ch = (unsigned int)((*linep)->len); *charp = ch; - + if (!sel) txt_pop_sel(text); } @@ -1065,7 +1065,7 @@ static void txt_curs_swap(Text *text) { TextLine *tmpl; int tmpc; - + tmpl = text->curl; text->curl = text->sell; text->sell = tmpl; @@ -1082,7 +1082,7 @@ static void txt_pop_first(Text *text) { txt_curs_swap(text); } - + txt_pop_sel(text); } @@ -1093,7 +1093,7 @@ static void txt_pop_last(Text *text) { txt_curs_swap(text); } - + txt_pop_sel(text); } @@ -1107,7 +1107,7 @@ void txt_order_cursors(Text *text, const bool reverse) { if (!text->curl) return; if (!text->sell) return; - + /* Flip so text->curl is before/after text->sell */ if (reverse == false) { if ((txt_get_span(text->curl, text->sell) < 0) || @@ -1139,7 +1139,7 @@ static void txt_delete_sel(Text *text, TextUndoBuf *utxt) if (!text->sell) return; if (!txt_has_sel(text)) return; - + txt_order_cursors(text, false); if (!undoing) { @@ -1155,15 +1155,15 @@ static void txt_delete_sel(Text *text, TextUndoBuf *utxt) buf[text->curc + (text->sell->len - text->selc)] = 0; make_new_line(text->curl, buf); - + tmpl = text->sell; while (tmpl != text->curl) { tmpl = tmpl->prev; if (!tmpl) break; - + txt_delete_line(text, tmpl->next); } - + text->sell = text->curl; text->selc = text->curc; } @@ -1172,7 +1172,7 @@ void txt_sel_all(Text *text) { text->curl = text->lines.first; text->curc = 0; - + text->sell = text->lines.last; text->selc = text->sell->len; } @@ -1193,7 +1193,7 @@ void txt_sel_clear(Text *text) void txt_sel_line(Text *text) { if (!text->curl) return; - + text->curc = 0; text->sell = text->curl; text->selc = text->sell->len; @@ -1216,7 +1216,7 @@ char *txt_to_buf(Text *text) linef = text->lines.first; charf = 0; - + linel = text->lines.last; charl = linel->len; @@ -1224,7 +1224,7 @@ char *txt_to_buf(Text *text) length = charl - charf; buf = MEM_mallocN(length + 2, "text buffer"); - + BLI_strncpy(buf, linef->line + charf, length + 1); buf[length] = 0; } @@ -1232,37 +1232,37 @@ char *txt_to_buf(Text *text) length = linef->len - charf; length += charl; length += 2; /* For the 2 '\n' */ - + tmp = linef->next; while (tmp && tmp != linel) { length += tmp->len + 1; tmp = tmp->next; } - + buf = MEM_mallocN(length + 1, "cut buffer"); strncpy(buf, linef->line + charf, linef->len - charf); length = linef->len - charf; - + buf[length++] = '\n'; - + tmp = linef->next; while (tmp && tmp != linel) { strncpy(buf + length, tmp->line, tmp->len); length += tmp->len; - + buf[length++] = '\n'; - + tmp = tmp->next; } strncpy(buf + length, linel->line, charl); length += charl; - + /* python compiler wants an empty end line */ buf[length++] = '\n'; buf[length] = 0; } - + return buf; } @@ -1272,11 +1272,11 @@ int txt_find_string(Text *text, const char *findstr, int wrap, int match_case) const char *s = NULL; if (!text->curl || !text->sell) return 0; - + txt_order_cursors(text, false); tl = startl = text->sell; - + if (match_case) s = strstr(&tl->line[text->selc], findstr); else s = BLI_strcasestr(&tl->line[text->selc], findstr); while (!s) { @@ -1293,7 +1293,7 @@ int txt_find_string(Text *text, const char *findstr, int wrap, int match_case) if (tl == startl) break; } - + if (s) { int newl = txt_get_span(text->lines.first, tl); int newc = (int)(s - tl->line); @@ -1314,10 +1314,10 @@ char *txt_sel_to_buf(Text *text) if (!text->curl) return NULL; if (!text->sell) return NULL; - + if (text->curl == text->sell) { linef = linel = text->curl; - + if (text->curc < text->selc) { charf = text->curc; charl = text->selc; @@ -1337,7 +1337,7 @@ char *txt_sel_to_buf(Text *text) else { linef = text->curl; linel = text->sell; - + charf = text->curc; charl = text->selc; } @@ -1346,39 +1346,39 @@ char *txt_sel_to_buf(Text *text) length = charl - charf; buf = MEM_mallocN(length + 1, "sel buffer"); - + BLI_strncpy(buf, linef->line + charf, length + 1); } else { length += linef->len - charf; length += charl; length++; /* For the '\n' */ - + tmp = linef->next; while (tmp && tmp != linel) { length += tmp->len + 1; tmp = tmp->next; } - + buf = MEM_mallocN(length + 1, "sel buffer"); - + strncpy(buf, linef->line + charf, linef->len - charf); length = linef->len - charf; - + buf[length++] = '\n'; - + tmp = linef->next; while (tmp && tmp != linel) { strncpy(buf + length, tmp->line, tmp->len); length += tmp->len; - + buf[length++] = '\n'; - + tmp = tmp->next; } strncpy(buf + length, linel->line, charl); length += charl; - + buf[length] = 0; } @@ -1396,11 +1396,11 @@ void txt_insert_buf(Text *text, TextUndoBuf *utxt, const char *in_buffer) if (!in_buffer) return; txt_delete_sel(text, utxt); - + len = strlen(in_buffer); buffer = BLI_strdupn(in_buffer, len); len += txt_extended_ascii_as_utf8(&buffer); - + if (!undoing) { txt_undo_add_blockop(text, utxt, UNDO_IBLOCK, buffer); } @@ -1410,7 +1410,7 @@ void txt_insert_buf(Text *text, TextUndoBuf *utxt, const char *in_buffer) while (buffer[i] && buffer[i] != '\n') { txt_add_raw_char(text, utxt, BLI_str_utf8_as_unicode_step(buffer, &i)); } - + if (buffer[i] == '\n') { txt_split_curline(text, utxt); i++; @@ -1495,16 +1495,16 @@ void txt_print_undo(Text *text) int op; const char *ops; int linep, charp; - + dump_buffer(text); - + printf("---< Undo Buffer >---\n"); - + printf("UndoPosition is %d\n", utxt->pos); - + while (i <= utxt->pos) { op = utxt->buf[i]; - + if (op == UNDO_INSERT_1) { ops = "Insert ascii "; } @@ -1562,7 +1562,7 @@ void txt_print_undo(Text *text) else { ops = "Unknown"; } - + printf("Op (%o) at %d = %s", op, i, ops); if (op >= UNDO_INSERT_1 && op <= UNDO_DEL_4) { i++; @@ -1603,14 +1603,14 @@ void txt_print_undo(Text *text) linep = linep + (utxt->buf[i] << 8); i++; linep = linep + (utxt->buf[i] << 16); i++; linep = linep + (utxt->buf[i] << 24); i++; - + printf(" (length %d) <", linep); - + while (linep > 0) { putchar(utxt->buf[i]); linep--; i++; } - + linep = utxt->buf[i]; i++; linep = linep + (utxt->buf[i] << 8); i++; linep = linep + (utxt->buf[i] << 16); i++; @@ -1627,7 +1627,7 @@ void txt_print_undo(Text *text) linep = linep + (utxt->buf[i] << 8); i++; linep = linep + (utxt->buf[i] << 16); i++; linep = linep + (utxt->buf[i] << 24); i++; - + printf("to <%d, %d> ", linep, charp); charp = utxt->buf[i]; i++; @@ -1637,17 +1637,17 @@ void txt_print_undo(Text *text) linep = linep + (utxt->buf[i] << 8); i++; linep = linep + (utxt->buf[i] << 16); i++; linep = linep + (utxt->buf[i] << 24); i++; - + printf("from <%d, %d>", linep, charp); } - + printf(" %d\n", i); i++; } } #endif -static void txt_undo_store_uint16(char *undo_buf, int *undo_pos, unsigned short value) +static void txt_undo_store_uint16(char *undo_buf, int *undo_pos, unsigned short value) { undo_buf[*undo_pos] = (value) & 0xff; (*undo_pos)++; @@ -1655,7 +1655,7 @@ static void txt_undo_store_uint16(char *undo_buf, int *undo_pos, unsigned short (*undo_pos)++; } -static void txt_undo_store_uint32(char *undo_buf, int *undo_pos, unsigned int value) +static void txt_undo_store_uint32(char *undo_buf, int *undo_pos, unsigned int value) { undo_buf[*undo_pos] = (value) & 0xff; (*undo_pos)++; @@ -1739,7 +1739,7 @@ static void txt_undo_add_charop(Text *text, TextUndoBuf *utxt, int op_start, uns { char utf8[BLI_UTF8_MAX]; size_t i, utf8_size = BLI_str_utf8_from_unicode(c, utf8); - + if (utf8_size < 4 && 0) { if (!max_undo_test(utxt, 2 + 6 + utf8_size + 1)) { return; @@ -1773,7 +1773,7 @@ static void txt_undo_add_charop(Text *text, TextUndoBuf *utxt, int op_start, uns /* 1 byte */ utxt->buf[utxt->pos] = op_start + 3; } - + txt_undo_end(text, utxt); } @@ -1872,10 +1872,10 @@ static unsigned int txt_undo_read_unicode(const char *undo_buf, int *undo_pos, s { unsigned int unicode; char utf8[BLI_UTF8_MAX + 1]; - + switch (bytes) { case 1: /* ascii */ - unicode = undo_buf[*undo_pos]; (*undo_pos)--; + unicode = undo_buf[*undo_pos]; (*undo_pos)--; break; case 2: /* 2-byte symbol */ utf8[2] = '\0'; @@ -1899,7 +1899,7 @@ static unsigned int txt_undo_read_unicode(const char *undo_buf, int *undo_pos, s unicode = 0; break; } - + return unicode; } @@ -1948,10 +1948,10 @@ static unsigned int txt_redo_read_unicode(const char *undo_buf, int *undo_pos, s { unsigned int unicode; char utf8[BLI_UTF8_MAX + 1]; - + switch (bytes) { case 1: /* ascii */ - unicode = undo_buf[*undo_pos]; (*undo_pos)++; + unicode = undo_buf[*undo_pos]; (*undo_pos)++; break; case 2: /* 2-byte symbol */ utf8[0] = undo_buf[*undo_pos]; (*undo_pos)++; @@ -1975,7 +1975,7 @@ static unsigned int txt_redo_read_unicode(const char *undo_buf, int *undo_pos, s unicode = 0; break; } - + return unicode; } @@ -1989,7 +1989,7 @@ void txt_do_undo(Text *text, TextUndoBuf *utxt) unsigned short curc, selc; unsigned short charp; char *buf; - + if (utxt->pos < 0) { return; } @@ -1997,21 +1997,21 @@ void txt_do_undo(Text *text, TextUndoBuf *utxt) utxt->pos--; undoing = 1; - + switch (op) { case UNDO_INSERT_1: case UNDO_INSERT_2: case UNDO_INSERT_3: case UNDO_INSERT_4: utxt->pos -= op - UNDO_INSERT_1 + 1; - + /* get and restore the cursors */ txt_undo_read_cur(utxt->buf, &utxt->pos, &curln, &curc); txt_move_to(text, curln, curc, 0); txt_move_to(text, curln, curc, 1); - + txt_delete_char(text, utxt); - + utxt->pos--; break; @@ -2021,12 +2021,12 @@ void txt_do_undo(Text *text, TextUndoBuf *utxt) case UNDO_BS_4: charp = op - UNDO_BS_1 + 1; uni_char = txt_undo_read_unicode(utxt->buf, &utxt->pos, charp); - + /* get and restore the cursors */ txt_undo_read_cur(utxt->buf, &utxt->pos, &curln, &curc); txt_move_to(text, curln, curc, 0); txt_move_to(text, curln, curc, 1); - + txt_add_char(text, utxt, uni_char); utxt->pos--; @@ -2072,7 +2072,7 @@ void txt_do_undo(Text *text, TextUndoBuf *utxt) /* move cur to location that needs buff inserted */ txt_move_to(text, curln, curc, 0); - + txt_insert_buf(text, utxt, buf); MEM_freeN(buf); @@ -2081,7 +2081,7 @@ void txt_do_undo(Text *text, TextUndoBuf *utxt) txt_move_to(text, selln, selc, 1); utxt->pos--; - + break; } case UNDO_IBLOCK: @@ -2089,7 +2089,7 @@ void txt_do_undo(Text *text, TextUndoBuf *utxt) int i; /* length of the string in the buffer */ linep = txt_undo_read_uint32(utxt->buf, &utxt->pos); - + /* txt_backspace_char removes utf8-characters, not bytes */ buf = MEM_mallocN(linep + 1, "iblock buffer"); for (i = 0; i < linep; i++) { @@ -2099,29 +2099,29 @@ void txt_do_undo(Text *text, TextUndoBuf *utxt) buf[i] = 0; linep = BLI_strlen_utf8(buf); MEM_freeN(buf); - + /* skip over the length that was stored again */ utxt->pos -= 4; /* get and restore the cursors */ txt_undo_read_cursors(utxt->buf, &utxt->pos, &curln, &curc, &selln, &selc); - + txt_move_to(text, curln, curc, 0); txt_move_to(text, selln, selc, 1); - + if ((curln == selln) && (curc == selc)) { /* disable tabs to spaces since moving right may involve skipping multiple spaces */ prev_flags = text->flags; text->flags &= ~TXT_TABSTOSPACES; - + for (i = 0; i < linep; i++) txt_move_right(text, 1); - + text->flags = prev_flags; } - + txt_delete_selected(text, utxt); - + utxt->pos--; break; } @@ -2134,7 +2134,7 @@ void txt_do_undo(Text *text, TextUndoBuf *utxt) txt_undo_read_cursors(utxt->buf, &utxt->pos, &curln, &curc, &selln, &selc); txt_move_to(text, curln, curc, 0); txt_move_to(text, selln, selc, 1); - + if (op == UNDO_INDENT) { txt_unindent(text, utxt); } @@ -2150,7 +2150,7 @@ void txt_do_undo(Text *text, TextUndoBuf *utxt) else if (op == UNDO_MOVE_LINES_DOWN) { txt_move_lines(text, utxt, TXT_MOVE_LINE_UP); } - + utxt->pos--; break; case UNDO_UNINDENT: @@ -2199,10 +2199,10 @@ void txt_do_undo(Text *text, TextUndoBuf *utxt) default: //XXX error("Undo buffer error - resetting"); utxt->pos = -1; - + break; } - + undoing = 0; } @@ -2215,15 +2215,15 @@ void txt_do_redo(Text *text, TextUndoBuf *utxt) unsigned int uni_uchar; unsigned int curln, selln; unsigned short curc, selc; - + utxt->pos++; op = utxt->buf[utxt->pos]; - + if (!op) { utxt->pos--; return; } - + undoing = 1; switch (op) { @@ -2232,12 +2232,12 @@ void txt_do_redo(Text *text, TextUndoBuf *utxt) case UNDO_INSERT_3: case UNDO_INSERT_4: utxt->pos++; - + /* get and restore the cursors */ txt_redo_read_cur(utxt->buf, &utxt->pos, &curln, &curc); txt_move_to(text, curln, curc, 0); txt_move_to(text, curln, curc, 1); - + charp = op - UNDO_INSERT_1 + 1; uni_uchar = txt_redo_read_unicode(utxt->buf, &utxt->pos, charp); @@ -2256,7 +2256,7 @@ void txt_do_redo(Text *text, TextUndoBuf *utxt) txt_move_to(text, curln, curc, 1); utxt->pos += op - UNDO_BS_1 + 1; - + /* move right so we backspace the correct char */ txt_move_right(text, 0); txt_backspace_char(text, utxt); @@ -2273,7 +2273,7 @@ void txt_do_redo(Text *text, TextUndoBuf *utxt) txt_redo_read_cur(utxt->buf, &utxt->pos, &curln, &curc); txt_move_to(text, curln, curc, 0); txt_move_to(text, curln, curc, 1); - + utxt->pos += op - UNDO_DEL_1 + 1; txt_delete_char(text, utxt); @@ -2290,12 +2290,12 @@ void txt_do_redo(Text *text, TextUndoBuf *utxt) /* length of the block */ linep = txt_redo_read_uint32(utxt->buf, &utxt->pos); - + utxt->pos += linep; /* skip over the length that was stored again */ utxt->pos += 4; - + txt_delete_sel(text, utxt); break; @@ -2315,7 +2315,7 @@ void txt_do_redo(Text *text, TextUndoBuf *utxt) memcpy(buf, &utxt->buf[utxt->pos], linep); utxt->pos += linep; buf[linep] = 0; - + txt_insert_buf(text, utxt, buf); MEM_freeN(buf); @@ -2323,7 +2323,7 @@ void txt_do_redo(Text *text, TextUndoBuf *utxt) utxt->pos += 4; break; - + case UNDO_INDENT: case UNDO_COMMENT: case UNDO_UNCOMMENT: @@ -2392,15 +2392,15 @@ void txt_do_redo(Text *text, TextUndoBuf *utxt) default: //XXX error("Undo buffer error - resetting"); utxt->pos = -1; - + break; } - + undoing = 0; } /**************************/ -/* Line editing functions */ +/* Line editing functions */ /**************************/ void txt_split_curline(Text *text, TextUndoBuf *utxt) @@ -2413,13 +2413,13 @@ void txt_split_curline(Text *text, TextUndoBuf *utxt) txt_delete_sel(text, utxt); if (!undoing) txt_undo_add_charop(text, utxt, UNDO_INSERT_1, '\n'); - + /* Make the two half strings */ left = MEM_mallocN(text->curc + 1, "textline_string"); 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"); memcpy(right, text->curl->line + text->curc, text->curl->len - text->curc + 1); @@ -2427,7 +2427,7 @@ void txt_split_curline(Text *text, TextUndoBuf *utxt) if (text->curl->format) MEM_freeN(text->curl->format); /* Make the new TextLine */ - + ins = MEM_mallocN(sizeof(TextLine), "textline"); ins->line = left; ins->format = NULL; @@ -2436,14 +2436,14 @@ void txt_split_curline(Text *text, TextUndoBuf *utxt) text->curl->line = right; text->curl->format = NULL; text->curl->len = text->curl->len - text->curc; - + BLI_insertlinkbefore(&text->lines, text->curl, ins); - + text->curc = 0; - + txt_make_dirty(text); txt_clean_text(text); - + txt_pop_sel(text); } @@ -2452,7 +2452,7 @@ static void txt_delete_line(Text *text, TextLine *line) if (!text->curl) return; BLI_remlink(&text->lines, line); - + if (line->line) MEM_freeN(line->line); if (line->format) MEM_freeN(line->format); @@ -2465,21 +2465,21 @@ static void txt_delete_line(Text *text, TextLine *line) static void txt_combine_lines(Text *text, TextLine *linea, TextLine *lineb) { char *tmp, *s; - + if (!linea || !lineb) return; tmp = MEM_mallocN(linea->len + lineb->len + 1, "textline_string"); - + s = tmp; s += BLI_strcpy_rlen(s, linea->line); s += BLI_strcpy_rlen(s, lineb->line); (void)s; make_new_line(linea, tmp); - + txt_delete_line(text, lineb); - + txt_make_dirty(text); txt_clean_text(text); } @@ -2487,16 +2487,16 @@ static void txt_combine_lines(Text *text, TextLine *linea, TextLine *lineb) void txt_duplicate_line(Text *text, TextUndoBuf *utxt) { TextLine *textline; - + if (!text->curl) return; - + if (text->curl == text->sell) { textline = txt_new_line(text->curl->line); BLI_insertlinkafter(&text->lines, text->curl, textline); - + txt_make_dirty(text); txt_clean_text(text); - + if (!undoing) txt_undo_add_op(text, utxt, UNDO_DUPLICATE); } } @@ -2523,7 +2523,7 @@ void txt_delete_char(Text *text, TextUndoBuf *utxt) else { /* Just deleting a char */ size_t c_len = 0; c = BLI_str_utf8_as_unicode_and_size(text->curl->line + text->curc, &c_len); - + memmove(text->curl->line + text->curc, text->curl->line + text->curc + c_len, text->curl->len - text->curc - c_len + 1); text->curl->len -= c_len; @@ -2533,7 +2533,7 @@ void txt_delete_char(Text *text, TextUndoBuf *utxt) txt_make_dirty(text); txt_clean_text(text); - + if (!undoing) txt_undo_add_charop(text, utxt, UNDO_DEL_1, c); } @@ -2547,9 +2547,9 @@ void txt_delete_word(Text *text, TextUndoBuf *utxt) void txt_backspace_char(Text *text, TextUndoBuf *utxt) { unsigned int c = '\n'; - + if (!text->curl) return; - + if (txt_has_sel(text)) { /* deleting a selection */ txt_delete_sel(text, utxt); txt_make_dirty(text); @@ -2557,10 +2557,10 @@ void txt_backspace_char(Text *text, TextUndoBuf *utxt) } else if (text->curc == 0) { /* Appending two lines */ if (!text->curl->prev) return; - + text->curl = text->curl->prev; text->curc = text->curl->len; - + txt_combine_lines(text, text->curl, text->curl->next); txt_pop_sel(text); } @@ -2568,7 +2568,7 @@ void txt_backspace_char(Text *text, TextUndoBuf *utxt) size_t c_len = 0; const char *prev = BLI_str_prev_char_utf8(text->curl->line + text->curc); c = BLI_str_utf8_as_unicode_and_size(prev, &c_len); - + /* source and destination overlap, don't use memcpy() */ memmove(text->curl->line + text->curc - c_len, text->curl->line + text->curc, @@ -2582,7 +2582,7 @@ void txt_backspace_char(Text *text, TextUndoBuf *utxt) txt_make_dirty(text); txt_clean_text(text); - + if (!undoing) txt_undo_add_charop(text, utxt, UNDO_BS_1, c); } @@ -2619,7 +2619,7 @@ static bool txt_add_char_intern(Text *text, TextUndoBuf *utxt, unsigned int add, txt_split_curline(text, utxt); return true; } - + /* insert spaces rather than tabs */ if (add == '\t' && replace_tabs) { txt_convert_tab_to_spaces(text, utxt); @@ -2627,23 +2627,23 @@ static bool txt_add_char_intern(Text *text, TextUndoBuf *utxt, unsigned int add, } txt_delete_sel(text, utxt); - + if (!undoing) txt_undo_add_charop(text, utxt, UNDO_INSERT_1, add); add_len = BLI_str_utf8_from_unicode(add, ch); - + tmp = MEM_mallocN(text->curl->len + add_len + 1, "textline_string"); - + memcpy(tmp, text->curl->line, text->curc); memcpy(tmp + text->curc, ch, add_len); memcpy(tmp + text->curc + add_len, text->curl->line + text->curc, text->curl->len - text->curc + 1); make_new_line(text->curl, tmp); - + text->curc += add_len; txt_pop_sel(text); - + txt_make_dirty(text); txt_clean_text(text); @@ -2678,10 +2678,10 @@ bool txt_replace_char(Text *text, TextUndoBuf *utxt, unsigned int add) if (text->curc == text->curl->len || txt_has_sel(text) || add == '\n') { return txt_add_char(text, utxt, add); } - + del = BLI_str_utf8_as_unicode_and_size(text->curl->line + text->curc, &del_size); add_size = BLI_str_utf8_from_unicode(add, ch); - + if (add_size > del_size) { char *tmp = MEM_mallocN(text->curl->len + add_size - del_size + 1, "textline_string"); memcpy(tmp, text->curl->line, text->curc); @@ -2693,11 +2693,11 @@ bool txt_replace_char(Text *text, TextUndoBuf *utxt, unsigned int add) char *tmp = text->curl->line; memmove(tmp + text->curc + add_size, tmp + text->curc + del_size, text->curl->len - text->curc - del_size + 1); } - + memcpy(text->curl->line + text->curc, ch, add_size); text->curc += add_size; text->curl->len += add_size - del_size; - + txt_pop_sel(text); txt_make_dirty(text); txt_clean_text(text); @@ -2752,7 +2752,7 @@ static void txt_select_prefix(Text *text, const char *add) txt_make_dirty(text); txt_clean_text(text); } - + if (text->curl == text->sell) { text->selc += indentlen; break; @@ -2769,7 +2769,7 @@ static void txt_select_prefix(Text *text, const char *add) text->curl = text->curl->prev; num--; } - + /* caller must handle undo */ } @@ -2819,10 +2819,10 @@ static void txt_select_unprefix( (*r_line_index_mask_len) += 1; } } - + txt_make_dirty(text); txt_clean_text(text); - + if (text->curl == text->sell) { if (changed) text->selc = MAX2(text->selc - indentlen, 0); @@ -2833,7 +2833,7 @@ static void txt_select_unprefix( num++; } - + } if (unindented_first) @@ -2901,7 +2901,7 @@ void txt_unindent(Text *text, TextUndoBuf *utxt) const char *prefix = (text->flags & TXT_TABSTOSPACES) ? tab_to_spaces : "\t"; ListBase line_index_mask; int line_index_mask_len; - + if (ELEM(NULL, text->curl, text->sell)) { return; } @@ -2922,13 +2922,13 @@ void txt_move_lines(struct Text *text, TextUndoBuf *utxt, const int direction) BLI_assert(ELEM(direction, TXT_MOVE_LINE_UP, TXT_MOVE_LINE_DOWN)); if (!text->curl || !text->sell) return; - + txt_order_cursors(text, false); line_other = (direction == TXT_MOVE_LINE_DOWN) ? text->sell->next : text->curl->prev; - + if (!line_other) return; - + BLI_remlink(&text->lines, line_other); if (direction == TXT_MOVE_LINE_DOWN) { @@ -2940,7 +2940,7 @@ void txt_move_lines(struct Text *text, TextUndoBuf *utxt, const int direction) txt_make_dirty(text); txt_clean_text(text); - + if (!undoing) { txt_undo_add_op(text, utxt, (direction == TXT_MOVE_LINE_DOWN) ? UNDO_MOVE_LINES_DOWN : UNDO_MOVE_LINES_UP); } @@ -2970,7 +2970,7 @@ int txt_setcurr_tab_spaces(Text *text, int space) /* if we find a ':' on this line, then add a tab but not if it is: * 1) in a comment * 2) within an identifier - * 3) after the cursor (text->curc), i.e. when creating space before a function def [#25414] + * 3) after the cursor (text->curc), i.e. when creating space before a function def [#25414] */ int a; bool is_indent = false; |