106 std::optional<Library *> ,
112 const Text *text_src = (
Text *)id_src;
122 text_dst->
curl = text_dst->
sell =
nullptr;
130 line_dst->
len = line_src->len;
131 line_dst->
format =
nullptr;
137 text_dst->
curc = text_dst->
selc = 0;
216 ln->format =
nullptr;
218 if (ln->len !=
int(strlen(ln->line))) {
219 printf(
"Error loading text, line lengths differ\n");
220 ln->len = strlen(ln->line);
268 tmp_next = tmp->next;
296 ptrdiff_t bad_char,
i = 0;
297 const ptrdiff_t
length = ptrdiff_t(strlen(*
str));
320 memcpy(newstr + mi, (*
str) +
i, bad_char);
322 const int mofs = mi + bad_char;
327 newstr[
length + added] =
'\0';
342 for (
i = 0;
i < tl->
len;
i++) {
343 if (tl->
line[
i] <
' ' && tl->
line[
i] !=
'\t') {
358 int i, llen, lines_count;
364 for (
i = 0;
i <
len;
i++) {
365 if (buffer[
i] ==
'\n') {
371 memcpy(tmp->
line, &buffer[
i - llen], llen);
393 if (llen != 0 || lines_count == 0 || buffer[
len - 1] ==
'\n') {
399 memcpy(tmp->
line, &buffer[
i - llen], llen);
430 if (buffer ==
nullptr) {
439 if (
BLI_stat(filepath_abs, &st) != -1) {
440 text->
mtime = st.st_mtime;
453 const char *filepath,
455 const bool is_internal)
463 STRNCPY(filepath_abs, filepath);
467 if (buffer ==
nullptr) {
482 if (is_internal ==
false) {
483 const size_t filepath_len = strlen(filepath);
485 memcpy(ta->
filepath, filepath, filepath_len + 1);
492 if (
BLI_stat(filepath_abs, &st) != -1) {
493 ta->
mtime = st.st_mtime;
548 if ((st.st_mode & S_IFMT) != S_IFREG) {
552 if (st.st_mtime > text->
mtime) {
578 if (
result == -1 || (st.st_mode & S_IFMT) != S_IFREG) {
582 text->
mtime = st.st_mtime;
595 memset(
l->_pad0, 0,
sizeof(
l->_pad0));
608 line->
line = newline;
609 line->
len = strlen(newline);
619 memcpy(tmp->
line,
str, str_len);
620 tmp->
line[str_len] =
'\0';
654 while ((*top)->prev) {
657 while ((*bot)->next) {
736 *charp = &text->
curc;
742 *charp = &text->
selc;
747 return (text->
selc == 0);
781 if ((*linep)->prev) {
783 (*linep)->line, (*linep)->len, *charp,
TXT_TABSIZE);
784 *
linep = (*linep)->prev;
786 (*linep)->line, (*linep)->len, column,
TXT_TABSIZE);
813 if ((*linep)->next) {
815 (*linep)->line, (*linep)->len, *charp,
TXT_TABSIZE);
816 *
linep = (*linep)->next;
818 (*linep)->line, (*linep)->len, column,
TXT_TABSIZE);
835 for (
int i = 0;
i < ch;
i++) {
836 if (tl->
line[
i] !=
' ') {
851 if (tl->
line[ch] ==
' ') {
853 for (
i = 0;
i < ch;
i++) {
854 if (tl->
line[
i] !=
' ') {
888 if ((*linep)->prev) {
890 *charp = (*linep)->len;
929 if (*charp == (*linep)->len) {
930 if ((*linep)->next) {
1042 *charp = (*linep)->len;
1088 *charp = (*linep)->
len;
1117 for (
i = 0;
i < line;
i++) {
1118 if ((*linep)->next) {
1119 *
linep = (*linep)->next;
1125 if (ch >
uint((*linep)->len)) {
1126 ch =
uint((*linep)->len);
1193 if (reverse ==
false) {
1233 size_t(text->
curc) + (
size_t(text->
sell->
len) -
size_t(text->
selc)) + 1,
"textline_string");
1242 while (tmpl != text->
curl) {
1288 if (startl < 0 || endl < 0) {
1291 startl = end + startl + 1;
1294 endl = end + endl + 1;
1301 if (froml ==
nullptr) {
1304 if (startl == endl) {
1309 if (tol ==
nullptr) {
1317 startc = std::max(0, fromllen + startc + 1);
1321 endc = std::max(0, tollen + endc + 1);
1349 buf_len +=
l->len + 1;
1352 char *buf_step = buf;
1354 memcpy(buf_step,
l->line,
l->len);
1358 *r_buf_len = buf_len;
1364 const char *buf_end = buf + buf_len;
1365 const char *buf_step = buf;
1372 while (buf_step != buf_end && l_src) {
1374 const char *buf_step_next = strchr(buf_step,
'\n');
1375 const int len = buf_step_next - buf_step;
1378 l_src = l_src->
next;
1379 if (
l->len !=
len) {
1385 memcpy(
l->line, buf_step,
len);
1386 l->line[
len] =
'\0';
1388 buf_step = buf_step_next + 1;
1392 while (l_src !=
nullptr) {
1402 while (buf_step != buf_end) {
1404 const char *buf_step_next = strchr(buf_step,
'\n');
1405 const int len = buf_step_next - buf_step;
1410 l->format =
nullptr;
1412 memcpy(
l->line, buf_step,
len);
1413 l->line[
len] =
'\0';
1415 buf_step = buf_step_next + 1;
1436 buf_len +=
l->len + 1;
1442 char *buf_step = buf;
1444 memcpy(buf_step,
l->line,
l->len);
1454 *r_buf_strlen = buf_len;
1477 linef = linel = text->
curl;
1503 if (linef == linel) {
1511 length = (linef->
len - charf) + charl + 1;
1513 for (tmp = linef->
next; tmp && tmp != linel; tmp = tmp->
next) {
1519 memcpy(buf, linef->
line + charf, linef->
len - charf);
1523 for (tmp = linef->
next; tmp && tmp != linel; tmp = tmp->
next) {
1543 BLI_assert(in_buffer_len == strlen(in_buffer));
1556 while (buffer[
i] && buffer[
i] !=
'\n') {
1560 if (buffer[
i] ==
'\n') {
1564 while (
i < in_buffer_len) {
1567 while (buffer[
i] && buffer[
i] !=
'\n') {
1572 if (buffer[
i] ==
'\n') {
1578 for (j =
i -
l; j <
i && j < in_buffer_len;) {
1598 const char *s =
nullptr;
1606 tl = startl = text->
sell;
1609 s = strstr(&tl->
line[text->
selc], findstr);
1626 s = strstr(tl->
line, findstr);
1638 int newc = int(s - tl->
line);
1640 txt_move_to(text, newl, newc + strlen(findstr),
true);
1727 if (!linea || !lineb) {
1734 memcpy(s, linea->
line, linea->
len);
1736 memcpy(s, lineb->
line, lineb->
len);
1789 size_t c_len =
pos - text->
curc;
1822 if (text->
curc == 0) {
1836 size_t c_len = text->
curc -
pos;
1844 text->
curc -= c_len;
1890 if (
add ==
'\t' && replace_tabs) {
1902 memcpy(tmp + text->
curc, ch, add_len);
1908 text->
curc += add_len;
1937 size_t del_size = 0, add_size;
1949 del_size = text->
curc;
1951 del_size -= text->
curc;
1955 if (add_size > del_size) {
1959 memcpy(tmp + text->
curc + add_size,
1965 else if (add_size < del_size) {
1967 memmove(tmp + text->
curc + add_size,
1968 tmp + text->
curc + del_size,
1973 text->
curc += add_size;
1974 text->
curl->
len += add_size - del_size;
1989 int len,
num, curc_old, selc_old;
1992 const int indentlen = strlen(
add);
1996 curc_old = text->
curc;
1997 selc_old = text->
selc;
2003 if ((text->
curl->
len != 0) || (skip_blank_lines == 0)) {
2011 memcpy(tmp + text->
curc,
add, indentlen);
2017 tmp[text->
curl->
len + indentlen] = 0;
2021 text->
curc += indentlen;
2029 text->
selc += indentlen;
2044 if (curc_old == 0 && !(text->
curl == text->
sell && curc_old == selc_old)) {
2054 text->
curc = curc_old + indentlen;
2070 const int indentlen = strlen(remove);
2071 bool unindented_first =
false;
2072 bool changed_any =
false;
2081 if (
STREQLEN(
l->line, remove, indentlen)) {
2086 for (
int i = 0;
i <
l->len;
i++) {
2087 if (!
ELEM(
l->line[
i],
'\t',
' ')) {
2092 if (
l == text->
sell) {
2100 bool changed =
false;
2103 unindented_first =
true;
2116 text->
selc = std::max(text->
selc - indentlen, 0);
2125 if (unindented_first) {
2126 text->
curc = std::max(text->
curc - indentlen, 0);
2214 const char *word =
":";
2215 const char *comm =
"#";
2217 static const char *back_words[] = {
"return",
"break",
"continue",
"pass",
"yield",
nullptr};
2225 if (
i == text->
curc) {
2231 if (strstr(text->
curl->
line, word)) {
2238 bool is_indent =
false;
2239 for (a = 0; (a < text->
curc) && (text->
curl->
line[a] !=
'\0'); a++) {
2247 else if (!
ELEM(ch,
' ',
'\t')) {
2256 for (test = 0; back_words[test]; test++) {
2258 if (strstr(text->
curl->
line, back_words[test]) &&
i > 0) {
2259 if (strcspn(text->
curl->
line, back_words[test]) < strcspn(text->
curl->
line, comm)) {
2276 const char opens[] =
"([{";
2277 const char close[] =
")]}";
2279 for (a = 0; a < (
sizeof(opens) - 1); a++) {
2280 if (ch == opens[a]) {
2283 if (ch == close[a]) {
2296 char delims[] =
"():\"\' ~!%^&*-+=[]{};/<>|.#\t,@";
2298 for (a = 0; a < (
sizeof(delims) - 1); a++) {
2299 if (ch == delims[a]) {
2328 if (ch <=
'Z' || ch ==
'_') {
2348 if (ch <=
'Z' || ch ==
'_') {
2374 if (
ELEM(ch,
' ',
'\t',
'\r',
'\n')) {
bool BKE_bpath_foreach_path_allocated_process(BPathForeachPathData *bpath_data, char **path)
@ IDTYPE_FLAGS_APPEND_IS_REUSABLE
@ IDTYPE_FLAGS_NO_ANIMDATA
void * BKE_libblock_alloc(Main *bmain, short type, const char *name, int flag) ATTR_WARN_UNUSED_RESULT
void id_fake_user_set(ID *id)
void * BKE_id_new(Main *bmain, short type, const char *name)
void BKE_id_blend_write(BlendWriter *writer, ID *id)
bool txt_has_sel(const struct Text *text)
#define ATTR_WARN_UNUSED_RESULT
File and directory operations.
int BLI_exists(const char *path) ATTR_WARN_UNUSED_RESULT ATTR_NONNULL()
int BLI_stat(const char *path, BLI_stat_t *buffer) ATTR_WARN_UNUSED_RESULT ATTR_NONNULL()
void * BLI_file_read_text_as_mem(const char *filepath, size_t pad_bytes, size_t *r_size)
void * BLI_findlink(const ListBase *listbase, int number) ATTR_WARN_UNUSED_RESULT ATTR_NONNULL(1)
#define LISTBASE_FOREACH(type, var, list)
BLI_INLINE void BLI_listbase_clear(ListBase *lb)
BLI_INLINE bool BLI_listbase_is_empty(const ListBase *lb)
void BLI_addtail(ListBase *listbase, void *vlink) ATTR_NONNULL(1)
void BLI_insertlinkafter(ListBase *listbase, void *vprevlink, void *vnewlink) ATTR_NONNULL(1)
void BLI_remlink(ListBase *listbase, void *vlink) ATTR_NONNULL(1)
void BLI_addhead(ListBase *listbase, void *vlink) ATTR_NONNULL(1)
int BLI_listbase_count(const ListBase *listbase) ATTR_WARN_UNUSED_RESULT ATTR_NONNULL(1)
void BLI_insertlinkbefore(ListBase *listbase, void *vnextlink, void *vnewlink) ATTR_NONNULL(1)
ATTR_WARN_UNUSED_RESULT const size_t num
bool BLI_path_abs(char path[FILE_MAX], const char *basepath) ATTR_NONNULL(1
void void void const char * BLI_path_basename(const char *path) ATTR_NONNULL(1) ATTR_WARN_UNUSED_RESULT
char * BLI_strdup(const char *str) ATTR_WARN_UNUSED_RESULT ATTR_NONNULL(1) ATTR_MALLOC
char * BLI_strdupn(const char *str, size_t len) ATTR_MALLOC ATTR_WARN_UNUSED_RESULT ATTR_NONNULL(1)
char * STRNCPY(char(&dst)[N], const char *src)
int char * BLI_strcasestr(const char *s, const char *find) ATTR_WARN_UNUSED_RESULT ATTR_NONNULL(1
bool BLI_str_cursor_step_next_utf8(const char *str, int str_maxlen, int *pos)
bool BLI_str_cursor_step_prev_utf8(const char *str, int str_maxlen, int *pos)
void BLI_str_cursor_step_utf8(const char *str, int str_maxlen, int *pos, eStrCursorJumpDirection direction, eStrCursorJumpType jump, bool use_init_step)
int BLI_str_utf8_offset_from_index(const char *str, size_t str_len, int index_target) ATTR_WARN_UNUSED_RESULT ATTR_NONNULL(1)
ptrdiff_t BLI_str_utf8_invalid_byte(const char *str, size_t str_len) ATTR_NONNULL(1)
size_t BLI_strlen_utf8(const char *strc) ATTR_NONNULL(1) ATTR_WARN_UNUSED_RESULT
unsigned int BLI_str_utf8_as_unicode_step_safe(const char *__restrict p, size_t p_len, size_t *__restrict index) ATTR_WARN_UNUSED_RESULT ATTR_NONNULL(1
size_t BLI_str_utf8_from_unicode(unsigned int c, char *dst, size_t dst_maxncpy) ATTR_NONNULL(2)
int BLI_str_utf8_offset_from_column_with_tabs(const char *str, size_t str_len, int column_target, int tab_width) ATTR_WARN_UNUSED_RESULT ATTR_NONNULL(1)
int BLI_str_utf8_offset_to_column_with_tabs(const char *str, size_t str_len, int offset_target, int tab_width) ATTR_WARN_UNUSED_RESULT ATTR_NONNULL(1)
#define STREQLEN(a, b, n)
#define MEMCMP_STRUCT_AFTER_IS_ZERO(struct_var, member)
#define BLO_write_id_struct(writer, struct_name, id_address, id)
#define BLO_write_struct(writer, struct_name, data_ptr)
void BLO_read_string(BlendDataReader *reader, char **ptr_p)
void BLO_write_string(BlendWriter *writer, const char *data_ptr)
#define BLO_read_struct_list(reader, struct_name, list)
#define BLO_read_struct(reader, struct_name, ptr_p)
#define BLT_I18NCONTEXT_ID_TEXT
void BPY_text_free_code(Text *text)
#define ID_BLEND_PATH_FROM_GLOBAL(_id)
@ USER_TXT_TABSTOSPACES_DISABLE
Read Guarded memory(de)allocation.
#define MEM_reallocN(vmemh, len)
ATTR_WARN_UNUSED_RESULT const BMLoop * l
float length(VecOp< float, D >) RET
void * MEM_mallocN(size_t len, const char *str)
void * MEM_malloc_arrayN(size_t len, size_t size, const char *str)
void MEM_freeN(void *vmemh)
static void add(blender::Map< std::string, std::string > &messages, Message &msg)
float wrap(float value, float max, float min)
int text_check_identifier_nodigit_unicode(const uint ch)
void txt_insert_buf(Text *text, const char *in_buffer, int in_buffer_len)
bool txt_add_raw_char(Text *text, uint add)
static void text_foreach_path(ID *id, BPathForeachPathData *bpath_data)
static void text_free_data(ID *id)
static TextLine * txt_new_linen(const char *str, int str_len)
static void txt_curs_swap(Text *text)
int txt_calc_tab_left(const TextLine *tl, int ch)
bool BKE_text_reload(Text *text)
int BKE_text_file_modified_check(const Text *text)
Text * BKE_text_load_ex(Main *bmain, const char *filepath, const char *relbase, const bool is_internal)
bool txt_unindent(Text *text)
static void txt_make_dirty(Text *text)
Text * BKE_text_load(Main *bmain, const char *filepath, const char *relbase)
void txt_sel_set(Text *text, int startl, int startc, int endl, int endc)
void txt_indent(Text *text)
void BKE_text_free_lines(Text *text)
bool text_check_identifier(const char ch)
void txt_sel_all(Text *text)
void txt_clean_text(Text *text)
void BKE_text_write(Text *text, const char *str, int str_len)
int text_check_identifier_unicode(const uint ch)
char * txt_sel_to_buf(const Text *text, size_t *r_buf_strlen)
static void text_blend_read_data(BlendDataReader *reader, ID *id)
bool txt_cursor_is_line_start(const Text *text)
void txt_pop_sel(Text *text)
bool txt_cursor_is_line_end(const Text *text)
static void txt_delete_line(Text *text, TextLine *line)
Text * BKE_text_add(Main *bmain, const char *name)
static TextLine * txt_new_line(const char *str)
void txt_move_bof(Text *text, const bool sel)
void txt_comment(Text *text, const char *prefix)
void txt_delete_word(Text *text)
void txt_from_buf_for_undo(Text *text, const char *buf, size_t buf_len)
bool txt_replace_char(Text *text, uint add)
static void txt_curs_cur(Text *text, TextLine ***linep, int **charp)
void txt_split_curline(Text *text)
char * txt_to_buf(Text *text, size_t *r_buf_strlen)
bool txt_add_char(Text *text, uint add)
static void text_init_data(ID *id)
void txt_jump_right(Text *text, const bool sel, const bool use_init_step)
bool txt_uncomment(Text *text, const char *prefix)
void txt_move_right(Text *text, const bool sel)
bool txt_find_string(Text *text, const char *findstr, int wrap, int match_case)
bool text_check_digit(const char ch)
bool txt_has_sel(const Text *text)
static bool txt_add_char_intern(Text *text, uint add, bool replace_tabs)
void txt_backspace_char(Text *text)
void txt_move_to(Text *text, uint line, uint ch, const bool sel)
void txt_move_eol(Text *text, const bool sel)
static void make_new_line(TextLine *line, char *newline)
void BKE_text_file_modified_ignore(Text *text)
int txt_setcurr_tab_spaces(Text *text, int space)
int text_check_bracket(const char ch)
void txt_move_toline(Text *text, uint line, const bool sel)
bool text_check_delim(const char ch)
void txt_move_bol(Text *text, const bool sel)
static bool txt_select_unprefix(Text *text, const char *remove, const bool require_all)
void txt_delete_char(Text *text)
char * txt_to_buf_for_undo(Text *text, size_t *r_buf_len)
static void txt_pop_last(Text *text)
static void text_from_buf(Text *text, const uchar *buffer, const int len)
static void txt_delete_sel(Text *text)
void txt_move_eof(Text *text, const bool sel)
void txt_move_down(Text *text, const bool sel)
static void cleanup_textline(TextLine *tl)
int txt_calc_tab_right(const TextLine *tl, int ch)
int txt_get_span(const TextLine *from, const TextLine *to)
static void text_blend_write(BlendWriter *writer, ID *id, const void *id_address)
void BKE_text_clear(Text *text)
static void txt_pop_first(Text *text)
static void txt_convert_tab_to_spaces(Text *text)
void txt_move_lines(Text *text, const int direction)
void txt_jump_left(Text *text, const bool sel, const bool use_init_step)
void txt_move_left(Text *text, const bool sel)
void txt_duplicate_line(Text *text)
static void text_copy_data(Main *, std::optional< Library * >, ID *id_dst, const ID *id_src, const int)
static void txt_combine_lines(Text *text, TextLine *linea, TextLine *lineb)
void txt_backspace_word(Text *text)
void txt_order_cursors(Text *text, const bool reverse)
void txt_sel_clear(Text *text)
static TextLine * txt_line_malloc() ATTR_MALLOC ATTR_WARN_UNUSED_RESULT
void txt_move_up(Text *text, const bool sel)
bool text_check_whitespace(const char ch)
static void txt_curs_sel(Text *text, TextLine ***linep, int **charp)
void txt_sel_line(Text *text)
int text_find_identifier_start(const char *str, int i)
static void txt_select_prefix(Text *text, const char *add, bool skip_blank_lines)
void txt_delete_selected(Text *text)
bool text_check_identifier_nodigit(const char ch)
int txt_extended_ascii_as_utf8(char **str)
static char tab_to_spaces[]