11 #include <sys/types.h>
115 const Text *text_src = (
Text *)id_src;
134 line_dst->
len = line_src->len;
140 text_dst->
curc = text_dst->
selc = 0;
221 if (ln->len != (
int)strlen(ln->line)) {
222 printf(
"Error loading text, line lengths differ\n");
223 ln->len = strlen(ln->line);
234 .struct_size =
sizeof(
Text),
236 .name_plural =
"texts",
239 .asset_type_info =
NULL,
246 .foreach_cache =
NULL,
252 .blend_read_lib =
NULL,
253 .blend_read_expand =
NULL,
255 .blend_read_undo_preserve =
NULL,
257 .lib_override_apply_post =
NULL,
269 tmp_next = tmp->next;
297 ptrdiff_t bad_char, i = 0;
298 const ptrdiff_t
length = (ptrdiff_t)strlen(*
str);
317 memcpy(newstr + mi, (*
str) + i,
length - i + 1);
321 memcpy(newstr + mi, (*
str) + i, bad_char);
323 const int mofs = mi + bad_char;
328 newstr[
length + added] =
'\0';
343 for (i = 0; i < tl->
len; i++) {
344 if (tl->
line[i] <
' ' && tl->
line[i] !=
'\t') {
345 memmove(tl->
line + i, tl->
line + i + 1, tl->
len - i);
359 int i, llen, lines_count;
365 for (i = 0; i <
len; i++) {
396 if (llen != 0 || lines_count == 0 ||
buffer[
len - 1] ==
'\n') {
458 const char *filepath,
460 const bool is_internal)
487 if (is_internal ==
false) {
488 const size_t filepath_len = strlen(filepath);
490 memcpy(ta->
filepath, filepath, filepath_len + 1);
553 if ((
st.st_mode & S_IFMT) != S_IFREG) {
557 if (
st.st_mtime > text->
mtime) {
583 if (
result == -1 || (
st.st_mode & S_IFMT) != S_IFREG) {
605 line->
line = newline;
606 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) {
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 = (*linep)->
prev;
810 if ((*linep)->next) {
812 *linep = (*linep)->
next;
830 for (
int i = 0; i < ch; i++) {
831 if (tl->
line[i] !=
' ') {
846 if (tl->
line[ch] ==
' ') {
848 for (i = 0; i < ch; i++) {
849 if (tl->
line[i] !=
' ') {
883 if ((*linep)->prev) {
885 *charp = (*linep)->len;
900 *charp =
prev - (*linep)->line;
925 if (*charp == (*linep)->len) {
926 if ((*linep)->next) {
1038 *charp = (*linep)->len;
1084 *charp = (*linep)->len;
1113 for (i = 0; i < line; i++) {
1114 if ((*linep)->next) {
1115 *linep = (*linep)->
next;
1121 if (ch > (
unsigned int)((*linep)->len)) {
1122 ch = (
unsigned int)((*linep)->len);
1187 if (reverse ==
false) {
1233 while (tmpl != text->
curl) {
1277 int fromllen, tollen;
1280 if (startl < 0 || endl < 0) {
1283 startl = end + startl + 1;
1286 endl = end + endl + 1;
1293 if (froml ==
NULL) {
1296 if (startl == endl) {
1311 startc = fromllen + startc + 1;
1314 endc = tollen + endc + 1;
1317 CLAMP(startc, 0, fromllen);
1318 CLAMP(endc, 0, tollen);
1345 buf_len +=
l->len + 1;
1348 char *buf_step = buf;
1350 memcpy(buf_step,
l->line,
l->len);
1354 *r_buf_len = buf_len;
1360 const char *buf_end = buf + buf_len;
1361 const char *buf_step = buf;
1368 while (buf_step != buf_end && l_src) {
1370 const char *buf_step_next = strchr(buf_step,
'\n');
1371 const int len = buf_step_next - buf_step;
1374 l_src = l_src->
next;
1375 if (
l->len !=
len) {
1381 memcpy(
l->line, buf_step,
len);
1382 l->line[
len] =
'\0';
1384 buf_step = buf_step_next + 1;
1388 while (l_src !=
NULL) {
1398 while (buf_step != buf_end) {
1400 const char *buf_step_next = strchr(buf_step,
'\n');
1401 const int len = buf_step_next - buf_step;
1408 memcpy(
l->line, buf_step,
len);
1409 l->line[
len] =
'\0';
1411 buf_step = buf_step_next + 1;
1432 buf_len +=
l->len + 1;
1438 char *buf_step = buf;
1440 memcpy(buf_step,
l->line,
l->len);
1450 *r_buf_strlen = buf_len;
1473 linef = linel = text->
curl;
1499 if (linef == linel) {
1507 length = (linef->
len - charf) + charl + 1;
1509 for (tmp = linef->
next; tmp && tmp != linel; tmp = tmp->
next) {
1515 memcpy(buf, linef->
line + charf, linef->
len - charf);
1519 for (tmp = linef->
next; tmp && tmp != linel; tmp = tmp->
next) {
1539 BLI_assert(in_buffer_len == strlen(in_buffer));
1560 while (i < in_buffer_len) {
1574 for (j = i -
l; j < i && j < in_buffer_len;) {
1594 const char *s =
NULL;
1602 tl = startl = text->
sell;
1605 s = strstr(&tl->
line[text->
selc], findstr);
1622 s = strstr(tl->
line, findstr);
1634 int newc = (int)(s - tl->
line);
1636 txt_move_to(text, newl, newc + strlen(findstr), 1);
1722 if (!linea || !lineb) {
1760 unsigned int c =
'\n';
1781 size_t c_len = text->
curc;
1783 c_len -= text->
curc;
1808 unsigned int c =
'\n';
1819 if (text->
curc == 0) {
1845 text->
curc -= c_len;
1891 if (
add ==
'\t' && replace_tabs) {
1903 memcpy(tmp + text->
curc, ch, add_len);
1909 text->
curc += add_len;
1938 size_t del_size = 0, add_size;
1950 del_size = text->
curc;
1952 del_size -= text->
curc;
1956 if (add_size > del_size) {
1957 char *tmp =
MEM_mallocN(text->
curl->
len + add_size - del_size + 1,
"textline_string");
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)) {
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;
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;
2124 if (unindented_first) {
2139 const char *prefix =
"#";
2151 const char *prefix =
"#";
2217 const char *word =
":";
2218 const char *comm =
"#";
2220 static const char *back_words[] = {
"return",
"break",
"continue",
"pass",
"yield",
NULL};
2226 while (text->
curl->
line[i] == indent) {
2228 if (i == text->
curc) {
2234 if (strstr(text->
curl->
line, word)) {
2241 bool is_indent =
false;
2250 else if (!
ELEM(ch,
' ',
'\t')) {
2259 for (test = 0; back_words[test]; test++) {
2261 if (strstr(text->
curl->
line, back_words[test]) && i > 0) {
2262 if (strcspn(text->
curl->
line, back_words[test]) < strcspn(text->
curl->
line, comm)) {
2279 char opens[] =
"([{";
2280 char close[] =
")]}";
2282 for (
a = 0;
a < (
sizeof(opens) - 1);
a++) {
2283 if (ch == opens[
a]) {
2286 if (ch == close[
a]) {
2299 char delims[] =
"():\"\' ~!%^&*-+=[]{};/<>|.#\t,@";
2301 for (
a = 0;
a < (
sizeof(delims) - 1);
a++) {
2302 if (ch == delims[
a]) {
2331 if (ch <=
'Z' || ch ==
'_') {
2351 if (ch <=
'Z' || ch ==
'_') {
2377 if (
ELEM(ch,
' ',
'\t',
'\r',
'\n')) {
bool BKE_bpath_foreach_path_allocated_process(struct BPathForeachPathData *bpath_data, char **path)
@ IDTYPE_FLAGS_APPEND_IS_REUSABLE
@ IDTYPE_FLAGS_NO_ANIMDATA
void id_us_min(struct ID *id)
void * BKE_libblock_alloc(struct Main *bmain, short type, const char *name, int flag) ATTR_WARN_UNUSED_RESULT
void id_fake_user_set(struct ID *id)
void BKE_id_blend_write(struct BlendWriter *writer, struct ID *id)
void * BKE_id_new(struct Main *bmain, short type, const char *name)
File and directory operations.
int BLI_exists(const char *path) ATTR_WARN_UNUSED_RESULT ATTR_NONNULL()
void * BLI_file_read_text_as_mem(const char *filepath, size_t pad_bytes, size_t *r_size)
int BLI_stat(const char *path, BLI_stat_t *buffer) ATTR_WARN_UNUSED_RESULT ATTR_NONNULL()
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_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)
void * BLI_findlink(const struct ListBase *listbase, int number) ATTR_WARN_UNUSED_RESULT ATTR_NONNULL(1)
int BLI_listbase_count(const struct ListBase *listbase) ATTR_WARN_UNUSED_RESULT ATTR_NONNULL(1)
const char * BLI_path_basename(const char *path) ATTR_NONNULL() ATTR_WARN_UNUSED_RESULT
bool BLI_path_abs(char *path, const char *basepath) ATTR_NONNULL()
char * BLI_strcasestr(const char *s, const char *find) ATTR_WARN_UNUSED_RESULT ATTR_NONNULL()
size_t BLI_strcpy_rlen(char *__restrict dst, const char *__restrict src) ATTR_WARN_UNUSED_RESULT ATTR_NONNULL()
char * BLI_strdup(const char *str) ATTR_WARN_UNUSED_RESULT ATTR_NONNULL() ATTR_MALLOC
char * BLI_strdupn(const char *str, size_t len) ATTR_MALLOC ATTR_WARN_UNUSED_RESULT ATTR_NONNULL()
char * BLI_strncpy(char *__restrict dst, const char *__restrict src, size_t maxncpy) ATTR_NONNULL()
void BLI_str_cursor_step_utf8(const char *str, size_t maxlen, int *pos, eStrCursorJumpDirection direction, eStrCursorJumpType jump, bool use_init_step)
int BLI_str_utf8_offset_from_column(const char *str, int column) ATTR_WARN_UNUSED_RESULT ATTR_NONNULL(1)
int BLI_str_utf8_size(const char *p) ATTR_WARN_UNUSED_RESULT ATTR_NONNULL(1)
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, int index) ATTR_WARN_UNUSED_RESULT ATTR_NONNULL(1)
unsigned int BLI_str_utf8_as_unicode_step(const char *__restrict p, size_t p_len, size_t *__restrict index) ATTR_WARN_UNUSED_RESULT ATTR_NONNULL(1
int BLI_str_utf8_offset_to_column(const char *str, int offset) ATTR_WARN_UNUSED_RESULT ATTR_NONNULL(1)
const char * BLI_str_find_prev_char_utf8(const char *p, const char *str_start) ATTR_WARN_UNUSED_RESULT ATTR_RETURNS_NONNULL ATTR_NONNULL(1
size_t BLI_strlen_utf8(const char *strc) ATTR_NONNULL(1) ATTR_WARN_UNUSED_RESULT
size_t BLI_str_utf8_from_unicode(unsigned int c, char *outbuf, size_t outbuf_len) ATTR_NONNULL(2)
#define STREQLEN(a, b, n)
#define MEMCMP_STRUCT_AFTER_IS_ZERO(struct_var, member)
#define BLO_read_data_address(reader, ptr_p)
#define BLO_write_id_struct(writer, struct_name, id_address, id)
#define BLO_write_struct(writer, struct_name, data_ptr)
void BLO_read_list(BlendDataReader *reader, struct ListBase *list)
void BLO_write_string(BlendWriter *writer, const char *data_ptr)
void BLO_write_raw(BlendWriter *writer, size_t size_in_bytes, const void *data_ptr)
#define BLT_I18NCONTEXT_ID_TEXT
void BPY_text_free_code(struct Text *text)
#define ID_BLEND_PATH_FROM_GLOBAL(_id)
Object is a sort of wrapper for general info.
@ USER_TXT_TABSTOSPACES_DISABLE
_GL_VOID GLfloat value _GL_VOID_RET _GL_VOID const GLuint GLboolean *residences _GL_BOOL_RET _GL_VOID GLsizei GLfloat GLfloat GLfloat GLfloat const GLubyte *bitmap _GL_VOID_RET _GL_VOID GLenum const void *lists _GL_VOID_RET _GL_VOID const GLdouble *equation _GL_VOID_RET _GL_VOID GLdouble GLdouble blue _GL_VOID_RET _GL_VOID GLfloat GLfloat blue _GL_VOID_RET _GL_VOID GLint GLint blue _GL_VOID_RET _GL_VOID GLshort GLshort blue _GL_VOID_RET _GL_VOID GLubyte GLubyte blue _GL_VOID_RET _GL_VOID GLuint GLuint blue _GL_VOID_RET _GL_VOID GLushort GLushort blue _GL_VOID_RET _GL_VOID GLbyte GLbyte GLbyte alpha _GL_VOID_RET _GL_VOID GLdouble GLdouble GLdouble alpha _GL_VOID_RET _GL_VOID GLfloat GLfloat GLfloat alpha _GL_VOID_RET _GL_VOID GLint GLint GLint alpha _GL_VOID_RET _GL_VOID GLshort GLshort GLshort alpha _GL_VOID_RET _GL_VOID GLubyte GLubyte GLubyte alpha _GL_VOID_RET _GL_VOID GLuint GLuint GLuint alpha _GL_VOID_RET _GL_VOID GLushort GLushort GLushort alpha _GL_VOID_RET _GL_VOID GLenum mode _GL_VOID_RET _GL_VOID GLint GLsizei GLsizei GLenum type _GL_VOID_RET _GL_VOID GLsizei GLenum GLenum const void *pixels _GL_VOID_RET _GL_VOID const void *pointer _GL_VOID_RET _GL_VOID GLdouble v _GL_VOID_RET _GL_VOID GLfloat v _GL_VOID_RET _GL_VOID GLint GLint i2 _GL_VOID_RET _GL_VOID GLint j _GL_VOID_RET _GL_VOID GLfloat param _GL_VOID_RET _GL_VOID GLint param _GL_VOID_RET _GL_VOID GLdouble right
_GL_VOID GLfloat value _GL_VOID_RET _GL_VOID const GLuint GLboolean *residences _GL_BOOL_RET _GL_VOID GLsizei GLfloat GLfloat GLfloat GLfloat const GLubyte *bitmap _GL_VOID_RET _GL_VOID GLenum const void *lists _GL_VOID_RET _GL_VOID const GLdouble *equation _GL_VOID_RET _GL_VOID GLdouble GLdouble blue _GL_VOID_RET _GL_VOID GLfloat GLfloat blue _GL_VOID_RET _GL_VOID GLint GLint blue _GL_VOID_RET _GL_VOID GLshort GLshort blue _GL_VOID_RET _GL_VOID GLubyte GLubyte blue _GL_VOID_RET _GL_VOID GLuint GLuint blue _GL_VOID_RET _GL_VOID GLushort GLushort blue _GL_VOID_RET _GL_VOID GLbyte GLbyte GLbyte alpha _GL_VOID_RET _GL_VOID GLdouble GLdouble GLdouble alpha _GL_VOID_RET _GL_VOID GLfloat GLfloat GLfloat alpha _GL_VOID_RET _GL_VOID GLint GLint GLint alpha _GL_VOID_RET _GL_VOID GLshort GLshort GLshort alpha _GL_VOID_RET _GL_VOID GLubyte GLubyte GLubyte alpha _GL_VOID_RET _GL_VOID GLuint GLuint GLuint alpha _GL_VOID_RET _GL_VOID GLushort GLushort GLushort alpha _GL_VOID_RET _GL_VOID GLenum mode _GL_VOID_RET _GL_VOID GLint GLsizei GLsizei GLenum type _GL_VOID_RET _GL_VOID GLsizei GLenum GLenum const void *pixels _GL_VOID_RET _GL_VOID const void *pointer _GL_VOID_RET _GL_VOID GLdouble v _GL_VOID_RET _GL_VOID GLfloat v _GL_VOID_RET _GL_VOID GLint GLint i2 _GL_VOID_RET _GL_VOID GLint j _GL_VOID_RET _GL_VOID GLfloat param _GL_VOID_RET _GL_VOID GLint param _GL_VOID_RET _GL_VOID GLdouble GLdouble GLdouble top
Read Guarded memory(de)allocation.
#define MEM_reallocN(vmemh, len)
static void init_data(ModifierData *md)
Group Output data from inside of a node group A color picker Mix two input colors RGB to Convert a color s luminance to a grayscale value Generate a normal vector and a dot product Bright Control the brightness and contrast of the input color Vector Map an input vectors to used to fine tune the interpolation of the input Camera Retrieve information about the camera and how it relates to the current shading point s position CLAMP
ATTR_WARN_UNUSED_RESULT const BMLoop * l
SyclQueue void void size_t num_bytes void
ccl_global float * buffer
void(* MEM_freeN)(void *vmemh)
void *(* MEM_mallocN)(size_t len, const char *str)
bool add(void *owner, const AttributeIDRef &attribute_id, eAttrDomain domain, eCustomDataType data_type, const AttributeInit &initializer)
bool remove(void *owner, const AttributeIDRef &attribute_id)
static struct PartialUpdateUser * wrap(PartialUpdateUserImpl *user)
T length(const vec_base< T, Size > &a)
SymEdge< T > * prev(const SymEdge< T > *se)
static const pxr::TfToken st("st", pxr::TfToken::Immortal)
Text * BKE_text_add(Main *bmain, const char *name)
bool txt_uncomment(Text *text)
void txt_insert_buf(Text *text, const char *in_buffer, int in_buffer_len)
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 void txt_curs_swap(Text *text)
bool BKE_text_reload(Text *text)
bool txt_unindent(Text *text)
static void txt_make_dirty(Text *text)
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)
static void text_copy_data(Main *UNUSED(bmain), ID *id_dst, const ID *id_src, const int UNUSED(flag))
void txt_clean_text(Text *text)
char * txt_sel_to_buf(Text *text, size_t *r_buf_strlen)
void BKE_text_write(Text *text, const char *str, int str_len)
void txt_move_toline(Text *text, unsigned int line, const bool sel)
Text * BKE_text_load(Main *bmain, const char *filepath, const char *relbase)
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)
static void text_from_buf(Text *text, const unsigned char *buffer, const int len)
bool txt_cursor_is_line_end(const Text *text)
static void txt_delete_line(Text *text, TextLine *line)
int text_check_identifier_unicode(const unsigned int ch)
bool txt_add_char(Text *text, unsigned int add)
void txt_move_bof(Text *text, const bool sel)
void txt_delete_word(Text *text)
void txt_from_buf_for_undo(Text *text, const char *buf, size_t buf_len)
static TextLine * txt_new_linen(const char *str, int str_len)
static void txt_curs_cur(Text *text, TextLine ***linep, int **charp)
int txt_calc_tab_left(TextLine *tl, int ch)
void txt_split_curline(Text *text)
static void text_init_data(ID *id)
void txt_jump_right(Text *text, const bool sel, const bool use_init_step)
void txt_move_right(Text *text, const bool sel)
bool text_check_digit(const char ch)
bool txt_replace_char(Text *text, unsigned int add)
bool txt_has_sel(const Text *text)
void txt_backspace_char(Text *text)
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)
void txt_move_lines(struct Text *text, const int direction)
int BKE_text_file_modified_check(Text *text)
int txt_setcurr_tab_spaces(Text *text, int space)
int text_check_bracket(const char ch)
int text_check_identifier_nodigit_unicode(const unsigned int ch)
bool text_check_delim(const char ch)
void txt_move_bol(Text *text, const bool sel)
int txt_get_span(TextLine *from, TextLine *to)
static bool txt_select_unprefix(Text *text, const char *remove, const bool require_all)
Text * BKE_text_load_ex(Main *bmain, const char *filepath, const char *relbase, const bool is_internal)
void txt_delete_char(Text *text)
static void txt_pop_last(Text *text)
char * txt_to_buf_for_undo(Text *text, size_t *r_buf_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)
char * txt_to_buf(Text *text, size_t *r_buf_strlen)
static void text_blend_write(BlendWriter *writer, ID *id, const void *id_address)
void BKE_text_clear(Text *text)
void txt_move_to(Text *text, unsigned int line, unsigned int ch, const bool sel)
void txt_comment(Text *text)
static void txt_pop_first(Text *text)
static void txt_convert_tab_to_spaces(Text *text)
int txt_calc_tab_right(TextLine *tl, int ch)
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)
bool txt_add_raw_char(Text *text, unsigned int add)
static void txt_combine_lines(Text *text, TextLine *linea, TextLine *lineb)
void txt_backspace_word(Text *text)
static TextLine * txt_new_line(const char *str)
void txt_order_cursors(Text *text, const bool reverse)
void txt_sel_clear(Text *text)
static bool txt_add_char_intern(Text *text, unsigned int add, bool replace_tabs)
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[]