27 #include <sys/types.h>
130 const Text *text_src = (
Text *)id_src;
149 line_dst->
len = line_src->len;
155 text_dst->
curc = text_dst->
selc = 0;
230 if (ln->len != (
int)strlen(ln->line)) {
231 printf(
"Error loading text, line lengths differ\n");
232 ln->len = strlen(ln->line);
243 .struct_size =
sizeof(
Text),
245 .name_plural =
"texts",
254 .foreach_cache =
NULL,
259 .blend_read_lib =
NULL,
260 .blend_read_expand =
NULL,
262 .blend_read_undo_preserve =
NULL,
264 .lib_override_apply_post =
NULL,
279 tmp_next = tmp->next;
309 ptrdiff_t bad_char, i = 0;
310 const ptrdiff_t
length = (ptrdiff_t)strlen(*
str);
329 memcpy(newstr + mi, (*
str) + i,
length - i + 1);
333 memcpy(newstr + mi, (*
str) + i, bad_char);
339 newstr[
length + added] =
'\0';
354 for (i = 0; i < tl->
len; i++) {
355 if (tl->
line[i] <
' ' && tl->
line[i] !=
'\t') {
356 memmove(tl->
line + i, tl->
line + i + 1, tl->
len - i);
370 int i, llen, lines_count;
376 for (i = 0; i <
len; i++) {
407 if (llen != 0 || lines_count == 0 ||
buffer[
len - 1] ==
'\n') {
455 if (
BLI_stat(filepath_abs, &st) != -1) {
456 text->
mtime = st.st_mtime;
505 if (is_internal ==
false) {
514 if (
BLI_stat(filepath_abs, &st) != -1) {
515 ta->
mtime = st.st_mtime;
580 if ((st.st_mode & S_IFMT) != S_IFREG) {
584 if (st.st_mtime > text->
mtime) {
610 if (
result == -1 || (st.st_mode & S_IFMT) != S_IFREG) {
614 text->
mtime = st.st_mtime;
632 line->
line = newline;
633 line->
len = strlen(newline);
693 while ((*top)->prev) {
696 while ((*bot)->next) {
774 *linep = &text->
curl;
775 *charp = &text->
curc;
780 *linep = &text->
sell;
781 *charp = &text->
selc;
786 return (text->
selc == 0);
820 if ((*linep)->prev) {
822 *linep = (*linep)->
prev;
850 if ((*linep)->next) {
852 *linep = (*linep)->
next;
870 for (
int i = 0; i < ch; i++) {
871 if (tl->
line[i] !=
' ') {
886 if (tl->
line[ch] ==
' ') {
888 for (i = 0; i < ch; i++) {
889 if (tl->
line[i] !=
' ') {
923 if ((*linep)->prev) {
925 *charp = (*linep)->len;
940 *charp = prev - (*linep)->line;
965 if (*charp == (*linep)->len) {
966 if ((*linep)->next) {
1078 *charp = (*linep)->len;
1124 *charp = (*linep)->len;
1154 for (i = 0; i < line; i++) {
1155 if ((*linep)->next) {
1156 *linep = (*linep)->
next;
1162 if (ch > (
unsigned int)((*linep)->len)) {
1163 ch = (
unsigned int)((*linep)->len);
1228 if (reverse ==
false) {
1274 while (tmpl != text->
curl) {
1323 int fromllen, tollen;
1326 if (startl < 0 || endl < 0) {
1329 startl = end + startl + 1;
1332 endl = end + endl + 1;
1339 if (froml ==
NULL) {
1342 if (startl == endl) {
1357 startc = fromllen + startc + 1;
1360 endc = tollen + endc + 1;
1363 CLAMP(startc, 0, fromllen);
1364 CLAMP(endc, 0, tollen);
1394 buf_len +=
l->len + 1;
1397 char *buf_step = buf;
1399 memcpy(buf_step,
l->line,
l->len);
1403 *r_buf_len = buf_len;
1412 const char *buf_end = buf + buf_len;
1413 const char *buf_step = buf;
1420 while (buf_step != buf_end && l_src) {
1422 const char *buf_step_next = strchr(buf_step,
'\n');
1423 const int len = buf_step_next - buf_step;
1426 l_src = l_src->
next;
1427 if (
l->len !=
len) {
1433 memcpy(
l->line, buf_step,
len);
1434 l->line[
len] =
'\0';
1436 buf_step = buf_step_next + 1;
1440 while (l_src !=
NULL) {
1450 while (buf_step != buf_end) {
1452 const char *buf_step_next = strchr(buf_step,
'\n');
1453 const int len = buf_step_next - buf_step;
1460 memcpy(
l->line, buf_step,
len);
1461 l->line[
len] =
'\0';
1463 buf_step = buf_step_next + 1;
1519 while (tmp && tmp != linel) {
1526 strncpy(buf, linef->
line + charf, linef->
len - charf);
1532 while (tmp && tmp != linel) {
1574 linef = linel = text->
curl;
1600 if (linef == linel) {
1613 while (tmp && tmp != linel) {
1620 strncpy(buf, linef->
line + charf, linef->
len - charf);
1626 while (tmp && tmp != linel) {
1660 len = strlen(in_buffer);
1687 for (j = i -
l; j < i && j <
len;) {
1707 const char *s =
NULL;
1715 tl = startl = text->
sell;
1718 s = strstr(&tl->
line[text->
selc], findstr);
1735 s = strstr(tl->
line, findstr);
1747 int newc = (int)(s - tl->
line);
1749 txt_move_to(text, newl, newc + strlen(findstr), 1);
1835 if (!linea || !lineb) {
1873 unsigned int c =
'\n';
1920 unsigned int c =
'\n';
1931 if (text->
curc == 0) {
1954 text->
curc -= c_len;
2000 if (
add ==
'\t' && replace_tabs) {
2012 memcpy(tmp + text->
curc, ch, add_len);
2018 text->
curc += add_len;
2047 size_t del_size = 0, add_size;
2063 if (add_size > del_size) {
2064 char *tmp =
MEM_mallocN(text->
curl->
len + add_size - del_size + 1,
"textline_string");
2066 memcpy(tmp + text->
curc + add_size,
2072 else if (add_size < del_size) {
2074 memmove(tmp + text->
curc + add_size,
2075 tmp + text->
curc + del_size,
2080 text->
curc += add_size;
2081 text->
curl->
len += add_size - del_size;
2096 int len, num, curc_old, selc_old;
2099 const int indentlen = strlen(
add);
2103 curc_old = text->
curc;
2104 selc_old = text->
selc;
2110 if ((text->
curl->
len != 0) || (skip_blank_lines == 0)) {
2117 memcpy(tmp + text->
curc,
add, indentlen);
2123 tmp[text->
curl->
len + indentlen] = 0;
2127 text->
curc += indentlen;
2135 text->
selc += indentlen;
2150 if (curc_old == 0 && !(text->
curl == text->
sell && curc_old == selc_old)) {
2160 text->
curc = curc_old + indentlen;
2176 const int indentlen = strlen(remove);
2177 bool unindented_first =
false;
2178 bool changed_any =
false;
2187 if (
STREQLEN(
l->line, remove, indentlen)) {
2192 for (
int i = 0; i <
l->len; i++) {
2193 if (!
ELEM(
l->line[i],
'\t',
' ')) {
2198 if (
l == text->
sell) {
2206 bool changed =
false;
2209 unindented_first =
true;
2231 if (unindented_first) {
2246 const char *prefix =
"#";
2258 const char *prefix =
"#";
2324 const char *word =
":";
2325 const char *comm =
"#";
2327 static const char *back_words[] = {
"return",
"break",
"continue",
"pass",
"yield",
NULL};
2333 while (text->
curl->
line[i] == indent) {
2335 if (i == text->
curc) {
2341 if (strstr(text->
curl->
line, word)) {
2348 bool is_indent =
false;
2357 else if (!
ELEM(ch,
' ',
'\t')) {
2366 for (test = 0; back_words[test]; test++) {
2368 if (strstr(text->
curl->
line, back_words[test]) && i > 0) {
2369 if (strcspn(text->
curl->
line, back_words[test]) < strcspn(text->
curl->
line, comm)) {
2386 char opens[] =
"([{";
2387 char close[] =
")]}";
2389 for (
a = 0;
a < (
sizeof(opens) - 1);
a++) {
2390 if (ch == opens[
a]) {
2393 if (ch == close[
a]) {
2405 char delims[] =
"():\"\' ~!%^&*-+=[]{};/<>|.#\t,@";
2407 for (
a = 0;
a < (
sizeof(delims) - 1);
a++) {
2408 if (ch == delims[
a]) {
2437 if (ch <=
'Z' || ch ==
'_') {
2457 if (ch <=
'Z' || ch ==
'_') {
2483 if (
ELEM(ch,
' ',
'\t',
'\r',
'\n')) {
@ IDTYPE_FLAGS_NO_ANIMDATA
void id_us_min(struct ID *id)
void id_fake_user_set(struct ID *id)
void * BKE_libblock_alloc(struct Main *bmain, short type, const char *name, const int flag) ATTR_WARN_UNUSED_RESULT
void BKE_id_blend_write(struct BlendWriter *writer, struct ID *id)
void * BKE_id_new(struct Main *bmain, const 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()
char * BLI_strdupn(const char *str, const size_t len) ATTR_MALLOC 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_strncpy(char *__restrict dst, const char *__restrict src, const 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)
size_t BLI_strlen_utf8(const char *strc) ATTR_NONNULL()
int BLI_str_utf8_size(const char *p) ATTR_NONNULL()
int BLI_str_utf8_offset_from_column(const char *str, int column)
ptrdiff_t BLI_utf8_invalid_byte(const char *str, size_t length) ATTR_NONNULL()
unsigned int BLI_str_utf8_as_unicode_and_size(const char *__restrict p, size_t *__restrict index) ATTR_NONNULL()
char * BLI_str_prev_char_utf8(const char *p) ATTR_NONNULL()
size_t BLI_str_utf8_from_unicode(unsigned int c, char *outbuf)
unsigned int BLI_str_utf8_as_unicode_step(const char *__restrict p, size_t *__restrict index) ATTR_NONNULL()
int BLI_str_utf8_offset_to_column(const char *str, int offset)
int BLI_str_utf8_offset_from_index(const char *str, int index)
#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)
bool BLO_write_is_undo(BlendWriter *writer)
#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 RGB to Bright Vector Camera CLAMP
ATTR_WARN_UNUSED_RESULT const BMLoop * l
SIMD_FORCE_INLINE btScalar length(const btQuaternion &q)
Return the length of a quaternion.
__kernel void ccl_constant KernelData ccl_global void ccl_global char ccl_global int ccl_global char ccl_global unsigned int ccl_global float * buffer
void(* MEM_freeN)(void *vmemh)
void *(* MEM_mallocN)(size_t len, const char *str)
static void add(GHash *messages, MemArena *memarena, const Message *msg)
static GPUContext * wrap(Context *ctx)
Text * BKE_text_add(Main *bmain, const char *name)
bool txt_uncomment(Text *text)
char * txt_sel_to_buf(Text *text, int *r_buf_strlen)
static void text_free_data(ID *id)
int txt_find_string(Text *text, const char *findstr, int wrap, int match_case)
Text * BKE_text_load_ex(Main *bmain, const char *file, const char *relpath, const bool is_internal)
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)
bool txt_cursor_is_line_start(Text *text)
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))
bool txt_cursor_is_line_end(Text *text)
void txt_clean_text(Text *text)
void txt_move_toline(Text *text, unsigned int line, const bool sel)
static void text_blend_read_data(BlendDataReader *reader, ID *id)
void txt_pop_sel(Text *text)
static void text_from_buf(Text *text, const unsigned char *buffer, const int len)
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)
static TextLine * txt_new_linen(const char *str, int n)
void txt_move_bof(Text *text, const bool sel)
char * txt_to_buf_for_undo(Text *text, int *r_buf_len)
void txt_delete_word(Text *text)
char * txt_to_buf(Text *text, int *r_buf_strlen)
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 BKE_text_write(Text *text, const char *str)
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)
Text * BKE_text_load(Main *bmain, const char *file, const char *relpath)
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 txt_from_buf_for_undo(Text *text, const char *buf, int buf_len)
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)
void txt_delete_char(Text *text)
static void txt_pop_last(Text *text)
static void txt_delete_sel(Text *text)
bool txt_has_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)
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_insert_buf(Text *text, const char *in_buffer)
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[]