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));
309 char *newstr =
static_cast<char *
>(
MEM_mallocN(
length + added + 1,
"text_line"));
315 memcpy(newstr + mi, (*
str) + i,
length - i + 1);
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') {
343 memmove(tl->
line + i, tl->
line + i + 1, tl->
len - i);
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);
615 tmp->
line =
static_cast<char *
>(
MEM_mallocN(str_len + 1,
"textline_string"));
618 memcpy(tmp->
line,
str, str_len);
619 tmp->
line[str_len] =
'\0';
653 while ((*top)->prev) {
656 while ((*bot)->next) {
734 *linep = &text->
curl;
735 *charp = &text->
curc;
740 *linep = &text->
sell;
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) {
1231 buf =
static_cast<char *
>(
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;
1350 char *buf =
static_cast<char *
>(
MEM_mallocN(buf_len, __func__));
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;
1407 l->line =
static_cast<char *
>(
MEM_mallocN(
len + 1,
"textline_string"));
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;
1440 char *buf =
static_cast<char *
>(
MEM_mallocN(buf_len + 1, __func__));
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);
1639 txt_move_to(text, newl, newc + strlen(findstr),
true);
1725 if (!linea || !lineb) {
1729 tmp =
static_cast<char *
>(
MEM_mallocN(linea->
len + lineb->
len + 1,
"textline_string"));
1732 memcpy(s, linea->
line, linea->
len);
1734 memcpy(s, lineb->
line, lineb->
len);
1787 size_t c_len =
pos - text->
curc;
1820 if (text->
curc == 0) {
1834 size_t c_len = text->
curc -
pos;
1842 text->
curc -= c_len;
1888 if (
add ==
'\t' && replace_tabs) {
1897 tmp =
static_cast<char *
>(
MEM_mallocN(text->
curl->
len + add_len + 1,
"textline_string"));
1900 memcpy(tmp + text->
curc, ch, add_len);
1906 text->
curc += add_len;
1935 size_t del_size = 0, add_size;
1947 del_size = text->
curc;
1949 del_size -= text->
curc;
1953 if (add_size > del_size) {
1954 char *tmp =
static_cast<char *
>(
1957 memcpy(tmp + text->
curc + add_size,
1963 else if (add_size < del_size) {
1965 memmove(tmp + text->
curc + add_size,
1966 tmp + text->
curc + del_size,
1971 text->
curc += add_size;
1972 text->
curl->
len += add_size - del_size;
1987 int len, num, curc_old, selc_old;
1990 const int indentlen = strlen(
add);
1994 curc_old = text->
curc;
1995 selc_old = text->
selc;
2001 if ((text->
curl->
len != 0) || (skip_blank_lines == 0)) {
2002 tmp =
static_cast<char *
>(
MEM_mallocN(text->
curl->
len + indentlen + 1,
"textline_string"));
2008 memcpy(tmp + text->
curc,
add, indentlen);
2014 tmp[text->
curl->
len + indentlen] = 0;
2018 text->
curc += indentlen;
2026 text->
selc += indentlen;
2041 if (curc_old == 0 && !(text->
curl == text->
sell && curc_old == selc_old)) {
2051 text->
curc = curc_old + indentlen;
2067 const int indentlen = strlen(remove);
2068 bool unindented_first =
false;
2069 bool changed_any =
false;
2078 if (
STREQLEN(
l->line, remove, indentlen)) {
2083 for (
int i = 0; i <
l->len; i++) {
2084 if (!
ELEM(
l->line[i],
'\t',
' ')) {
2089 if (
l == text->
sell) {
2097 bool changed =
false;
2100 unindented_first =
true;
2113 text->
selc = std::max(text->
selc - indentlen, 0);
2122 if (unindented_first) {
2123 text->
curc = std::max(text->
curc - indentlen, 0);
2211 const char *word =
":";
2212 const char *comm =
"#";
2214 static const char *back_words[] = {
"return",
"break",
"continue",
"pass",
"yield",
nullptr};
2220 while (text->
curl->
line[i] == indent) {
2222 if (i == text->
curc) {
2228 if (strstr(text->
curl->
line, word)) {
2235 bool is_indent =
false;
2236 for (a = 0; (a < text->
curc) && (text->
curl->
line[a] !=
'\0'); a++) {
2244 else if (!
ELEM(ch,
' ',
'\t')) {
2253 for (test = 0; back_words[test]; test++) {
2255 if (strstr(text->
curl->
line, back_words[test]) && i > 0) {
2256 if (strcspn(text->
curl->
line, back_words[test]) < strcspn(text->
curl->
line, comm)) {
2273 const char opens[] =
"([{";
2274 const char close[] =
")]}";
2276 for (a = 0; a < (
sizeof(opens) - 1); a++) {
2277 if (ch == opens[a]) {
2280 if (ch == close[a]) {
2293 char delims[] =
"():\"\' ~!%^&*-+=[]{};/<>|.#\t,@";
2295 for (a = 0; a < (
sizeof(delims) - 1); a++) {
2296 if (ch == delims[a]) {
2325 if (ch <=
'Z' || ch ==
'_') {
2345 if (ch <=
'Z' || ch ==
'_') {
2371 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)
BLI_INLINE bool BLI_listbase_is_empty(const struct ListBase *lb)
void BLI_addhead(struct ListBase *listbase, void *vlink) ATTR_NONNULL(1)
#define LISTBASE_FOREACH(type, var, list)
BLI_INLINE void BLI_listbase_clear(struct ListBase *lb)
void BLI_insertlinkafter(struct ListBase *listbase, void *vprevlink, void *vnewlink) ATTR_NONNULL(1)
void * BLI_findlink(const struct ListBase *listbase, int number) ATTR_WARN_UNUSED_RESULT ATTR_NONNULL(1)
void BLI_addtail(struct ListBase *listbase, void *vlink) ATTR_NONNULL(1)
void BLI_remlink(struct ListBase *listbase, void *vlink) ATTR_NONNULL(1)
void BLI_insertlinkbefore(struct ListBase *listbase, void *vnextlink, void *vnewlink) ATTR_NONNULL(1)
int BLI_listbase_count(const struct ListBase *listbase) ATTR_WARN_UNUSED_RESULT ATTR_NONNULL(1)
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
#define STRNCPY(dst, src)
char * BLI_strdupn(const char *str, size_t len) ATTR_MALLOC ATTR_WARN_UNUSED_RESULT ATTR_NONNULL(1)
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)
char size_t ptrdiff_t BLI_str_utf8_invalid_byte(const char *str, size_t length) ATTR_NONNULL(1)
int BLI_str_utf8_offset_from_index(const char *str, size_t str_len, int index_target) ATTR_WARN_UNUSED_RESULT 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
SIMD_FORCE_INLINE btScalar length(const btQuaternion &q)
Return the length of a quaternion.
draw_view push_constant(Type::INT, "radiance_src") .push_constant(Type capture_info_buf storage_buf(1, Qualifier::READ, "ObjectBounds", "bounds_buf[]") .push_constant(Type draw_view int
void *(* MEM_mallocN)(size_t len, 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)
int txt_find_string(Text *text, const char *findstr, int wrap, int match_case)
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 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[]