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);
267 tmp_next = tmp->next;
295 ptrdiff_t bad_char,
i = 0;
296 const ptrdiff_t
length = ptrdiff_t(strlen(*
str));
319 memcpy(newstr + mi, (*
str) +
i, bad_char);
321 const int mofs = mi + bad_char;
326 newstr[
length + added] =
'\0';
341 for (
i = 0;
i < tl->
len;
i++) {
342 if (tl->
line[
i] <
' ' && tl->
line[
i] !=
'\t') {
357 int i, llen, lines_count;
363 for (
i = 0;
i <
len;
i++) {
364 if (buffer[
i] ==
'\n') {
370 memcpy(tmp->
line, &buffer[
i - llen], llen);
392 if (llen != 0 || lines_count == 0 || buffer[
len - 1] ==
'\n') {
398 memcpy(tmp->
line, &buffer[
i - llen], llen);
429 if (buffer ==
nullptr) {
438 if (
BLI_stat(filepath_abs, &st) != -1) {
439 text->
mtime = st.st_mtime;
452 const char *filepath,
454 const bool is_internal)
462 STRNCPY(filepath_abs, filepath);
466 if (buffer ==
nullptr) {
481 if (is_internal ==
false) {
482 const size_t filepath_len = strlen(filepath);
484 memcpy(ta->
filepath, filepath, filepath_len + 1);
491 if (
BLI_stat(filepath_abs, &st) != -1) {
492 ta->
mtime = st.st_mtime;
547 if ((st.st_mode & S_IFMT) != S_IFREG) {
551 if (st.st_mtime > text->
mtime) {
577 if (
result == -1 || (st.st_mode & S_IFMT) != S_IFREG) {
581 text->
mtime = st.st_mtime;
594 memset(
l->_pad0, 0,
sizeof(
l->_pad0));
607 line->
line = newline;
608 line->
len = strlen(newline);
618 memcpy(tmp->
line,
str, str_len);
619 tmp->
line[str_len] =
'\0';
653 while ((*top)->prev) {
656 while ((*bot)->next) {
735 *charp = &text->
curc;
741 *charp = &text->
selc;
746 return (text->
selc == 0);
780 if ((*linep)->prev) {
782 (*linep)->line, (*linep)->len, *charp,
TXT_TABSIZE);
783 *
linep = (*linep)->prev;
785 (*linep)->line, (*linep)->len, column,
TXT_TABSIZE);
812 if ((*linep)->next) {
814 (*linep)->line, (*linep)->len, *charp,
TXT_TABSIZE);
815 *
linep = (*linep)->next;
817 (*linep)->line, (*linep)->len, column,
TXT_TABSIZE);
834 for (
int i = 0;
i < ch;
i++) {
835 if (tl->
line[
i] !=
' ') {
850 if (tl->
line[ch] ==
' ') {
852 for (
i = 0;
i < ch;
i++) {
853 if (tl->
line[
i] !=
' ') {
887 if ((*linep)->prev) {
889 *charp = (*linep)->len;
928 if (*charp == (*linep)->len) {
929 if ((*linep)->next) {
1041 *charp = (*linep)->len;
1087 *charp = (*linep)->
len;
1116 for (
i = 0;
i < line;
i++) {
1117 if ((*linep)->next) {
1118 *
linep = (*linep)->next;
1124 if (ch >
uint((*linep)->len)) {
1125 ch =
uint((*linep)->len);
1192 if (reverse ==
false) {
1232 size_t(text->
curc) + (
size_t(text->
sell->
len) -
size_t(text->
selc)) + 1,
"textline_string");
1241 while (tmpl != text->
curl) {
1287 if (startl < 0 || endl < 0) {
1290 startl = end + startl + 1;
1293 endl = end + endl + 1;
1300 if (froml ==
nullptr) {
1303 if (startl == endl) {
1308 if (tol ==
nullptr) {
1316 startc = std::max(0, fromllen + startc + 1);
1320 endc = std::max(0, tollen + endc + 1);
1348 buf_len +=
l->len + 1;
1351 char *buf_step = buf;
1353 memcpy(buf_step,
l->line,
l->len);
1357 *r_buf_len = buf_len;
1363 const char *buf_end = buf + buf_len;
1364 const char *buf_step = buf;
1371 while (buf_step != buf_end && l_src) {
1373 const char *buf_step_next = strchr(buf_step,
'\n');
1374 const int len = buf_step_next - buf_step;
1377 l_src = l_src->
next;
1378 if (
l->len !=
len) {
1384 memcpy(
l->line, buf_step,
len);
1385 l->line[
len] =
'\0';
1387 buf_step = buf_step_next + 1;
1391 while (l_src !=
nullptr) {
1401 while (buf_step != buf_end) {
1403 const char *buf_step_next = strchr(buf_step,
'\n');
1404 const int len = buf_step_next - buf_step;
1409 l->format =
nullptr;
1411 memcpy(
l->line, buf_step,
len);
1412 l->line[
len] =
'\0';
1414 buf_step = buf_step_next + 1;
1435 buf_len +=
l->len + 1;
1441 char *buf_step = buf;
1443 memcpy(buf_step,
l->line,
l->len);
1453 *r_buf_strlen = buf_len;
1476 linef = linel = text->
curl;
1502 if (linef == linel) {
1510 length = (linef->
len - charf) + charl + 1;
1512 for (tmp = linef->
next; tmp && tmp != linel; tmp = tmp->
next) {
1518 memcpy(buf, linef->
line + charf, linef->
len - charf);
1522 for (tmp = linef->
next; tmp && tmp != linel; tmp = tmp->
next) {
1542 BLI_assert(in_buffer_len == strlen(in_buffer));
1555 while (buffer[
i] && buffer[
i] !=
'\n') {
1559 if (buffer[
i] ==
'\n') {
1563 while (
i < in_buffer_len) {
1566 while (buffer[
i] && buffer[
i] !=
'\n') {
1571 if (buffer[
i] ==
'\n') {
1577 for (j =
i -
l; j <
i && j < in_buffer_len;) {
1597 const char *s =
nullptr;
1605 tl = startl = text->
sell;
1608 s = strstr(&tl->
line[text->
selc], findstr);
1625 s = strstr(tl->
line, findstr);
1637 int newc = int(s - tl->
line);
1639 txt_move_to(text, newl, newc + strlen(findstr),
true);
1726 if (!linea || !lineb) {
1733 memcpy(s, linea->
line, linea->
len);
1735 memcpy(s, lineb->
line, lineb->
len);
1788 size_t c_len =
pos - text->
curc;
1821 if (text->
curc == 0) {
1835 size_t c_len = text->
curc -
pos;
1843 text->
curc -= c_len;
1889 if (
add ==
'\t' && replace_tabs) {
1901 memcpy(tmp + text->
curc, ch, add_len);
1907 text->
curc += add_len;
1936 size_t del_size = 0, add_size;
1948 del_size = text->
curc;
1950 del_size -= text->
curc;
1954 if (add_size > del_size) {
1958 memcpy(tmp + text->
curc + add_size,
1964 else if (add_size < del_size) {
1966 memmove(tmp + text->
curc + add_size,
1967 tmp + text->
curc + del_size,
1972 text->
curc += add_size;
1973 text->
curl->
len += add_size - del_size;
1988 int len,
num, curc_old, selc_old;
1991 const int indentlen = strlen(
add);
1995 curc_old = text->
curc;
1996 selc_old = text->
selc;
2002 if ((text->
curl->
len != 0) || (skip_blank_lines == 0)) {
2010 memcpy(tmp + text->
curc,
add, indentlen);
2016 tmp[text->
curl->
len + indentlen] = 0;
2020 text->
curc += indentlen;
2028 text->
selc += indentlen;
2043 if (curc_old == 0 && !(text->
curl == text->
sell && curc_old == selc_old)) {
2053 text->
curc = curc_old + indentlen;
2069 const int indentlen = strlen(remove);
2070 bool unindented_first =
false;
2071 bool changed_any =
false;
2080 if (
STREQLEN(
l->line, remove, indentlen)) {
2085 for (
int i = 0;
i <
l->len;
i++) {
2086 if (!
ELEM(
l->line[
i],
'\t',
' ')) {
2091 if (
l == text->
sell) {
2099 bool changed =
false;
2102 unindented_first =
true;
2115 text->
selc = std::max(text->
selc - indentlen, 0);
2124 if (unindented_first) {
2125 text->
curc = std::max(text->
curc - indentlen, 0);
2213 const char *word =
":";
2214 const char *comm =
"#";
2216 static const char *back_words[] = {
"return",
"break",
"continue",
"pass",
"yield",
nullptr};
2224 if (
i == text->
curc) {
2230 if (strstr(text->
curl->
line, word)) {
2237 bool is_indent =
false;
2238 for (a = 0; (a < text->
curc) && (text->
curl->
line[a] !=
'\0'); a++) {
2246 else if (!
ELEM(ch,
' ',
'\t')) {
2255 for (test = 0; back_words[test]; test++) {
2257 if (strstr(text->
curl->
line, back_words[test]) &&
i > 0) {
2258 if (strcspn(text->
curl->
line, back_words[test]) < strcspn(text->
curl->
line, comm)) {
2275 const char opens[] =
"([{";
2276 const char close[] =
")]}";
2278 for (a = 0; a < (
sizeof(opens) - 1); a++) {
2279 if (ch == opens[a]) {
2282 if (ch == close[a]) {
2295 char delims[] =
"():\"\' ~!%^&*-+=[]{};/<>|.#\t,@";
2297 for (a = 0; a < (
sizeof(delims) - 1); a++) {
2298 if (ch == delims[a]) {
2327 if (ch <=
'Z' || ch ==
'_') {
2347 if (ch <=
'Z' || ch ==
'_') {
2373 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)
@ USER_TXT_TABSTOSPACES_DISABLE
Read Guarded memory(de)allocation.
ATTR_WARN_UNUSED_RESULT const BMLoop * l
float length(VecOp< float, D >) RET
#define ID_BLEND_PATH_FROM_GLOBAL(_id)
#define MEM_reallocN(vmemh, len)
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[]