Changeset View
Changeset View
Standalone View
Standalone View
source/blender/blenkernel/intern/text.c
| Context not available. | |||||
| char str[FILE_MAX]; | char str[FILE_MAX]; | ||||
| BLI_stat_t st; | BLI_stat_t st; | ||||
| if (!text->name) return 0; | if (!text || !text->name) return 0; | ||||
| BLI_strncpy(str, text->name, FILE_MAX); | BLI_strncpy(str, text->name, FILE_MAX); | ||||
| BLI_path_abs(str, G.main->name); | BLI_path_abs(str, G.main->name); | ||||
| Context not available. | |||||
| int result; | int result; | ||||
| char file[FILE_MAX]; | char file[FILE_MAX]; | ||||
| if (!text->name) | if (!text || !text->name) | ||||
| return 0; | return 0; | ||||
| BLI_strncpy(file, text->name, FILE_MAX); | BLI_strncpy(file, text->name, FILE_MAX); | ||||
| Context not available. | |||||
| int result; | int result; | ||||
| char file[FILE_MAX]; | char file[FILE_MAX]; | ||||
| if (!text->name) return; | if (!text || !text->name) return; | ||||
| BLI_strncpy(file, text->name, FILE_MAX); | BLI_strncpy(file, text->name, FILE_MAX); | ||||
| BLI_path_abs(file, G.main->name); | BLI_path_abs(file, G.main->name); | ||||
| Context not available. | |||||
| void txt_clean_text(Text *text) | void txt_clean_text(Text *text) | ||||
| { | { | ||||
| TextLine **top, **bot; | TextLine **top, **bot; | ||||
| if (!text) return; | |||||
| if (!text->lines.first) { | if (!text->lines.first) { | ||||
| if (text->lines.last) text->lines.first = text->lines.last; | if (text->lines.last) text->lines.first = text->lines.last; | ||||
| else text->lines.first = text->lines.last = txt_new_line(NULL); | else text->lines.first = text->lines.last = txt_new_line(NULL); | ||||
| Context not available. | |||||
| { | { | ||||
| TextLine **linep; | TextLine **linep; | ||||
| int *charp; | int *charp; | ||||
| if (!text) return; | |||||
| if (sel) txt_curs_sel(text, &linep, &charp); | if (sel) txt_curs_sel(text, &linep, &charp); | ||||
| else { txt_pop_first(text); txt_curs_cur(text, &linep, &charp); } | else { txt_pop_first(text); txt_curs_cur(text, &linep, &charp); } | ||||
| if (!*linep) return; | if (!*linep) return; | ||||
| Context not available. | |||||
| { | { | ||||
| TextLine **linep; | TextLine **linep; | ||||
| int *charp; | int *charp; | ||||
| if (!text) return; | |||||
| if (sel) txt_curs_sel(text, &linep, &charp); | if (sel) txt_curs_sel(text, &linep, &charp); | ||||
| else { txt_pop_last(text); txt_curs_cur(text, &linep, &charp); } | else { txt_pop_last(text); txt_curs_cur(text, &linep, &charp); } | ||||
| if (!*linep) return; | if (!*linep) return; | ||||
| Context not available. | |||||
| TextLine **linep; | TextLine **linep; | ||||
| int *charp; | int *charp; | ||||
| int tabsize = 0, i = 0; | int tabsize = 0, i = 0; | ||||
| if (!text) return; | |||||
| if (sel) txt_curs_sel(text, &linep, &charp); | if (sel) txt_curs_sel(text, &linep, &charp); | ||||
| else { txt_pop_first(text); txt_curs_cur(text, &linep, &charp); } | else { txt_pop_first(text); txt_curs_cur(text, &linep, &charp); } | ||||
| if (!*linep) return; | if (!*linep) return; | ||||
| Context not available. | |||||
| TextLine **linep; | TextLine **linep; | ||||
| int *charp, i; | int *charp, i; | ||||
| bool do_tab = false; | bool do_tab = false; | ||||
| if (!text) return; | |||||
| if (sel) txt_curs_sel(text, &linep, &charp); | if (sel) txt_curs_sel(text, &linep, &charp); | ||||
| else { txt_pop_last(text); txt_curs_cur(text, &linep, &charp); } | else { txt_pop_last(text); txt_curs_cur(text, &linep, &charp); } | ||||
| if (!*linep) return; | if (!*linep) return; | ||||
| Context not available. | |||||
| { | { | ||||
| TextLine **linep; | TextLine **linep; | ||||
| int *charp; | int *charp; | ||||
| if (!text) return; | |||||
| if (sel) txt_curs_sel(text, &linep, &charp); | if (sel) txt_curs_sel(text, &linep, &charp); | ||||
| else { txt_pop_first(text); txt_curs_cur(text, &linep, &charp); } | else { txt_pop_first(text); txt_curs_cur(text, &linep, &charp); } | ||||
| if (!*linep) return; | if (!*linep) return; | ||||
| Context not available. | |||||
| { | { | ||||
| TextLine **linep; | TextLine **linep; | ||||
| int *charp; | int *charp; | ||||
| if (!text) return; | |||||
| if (sel) txt_curs_sel(text, &linep, &charp); | if (sel) txt_curs_sel(text, &linep, &charp); | ||||
| else { txt_pop_last(text); txt_curs_cur(text, &linep, &charp); } | else { txt_pop_last(text); txt_curs_cur(text, &linep, &charp); } | ||||
| if (!*linep) return; | if (!*linep) return; | ||||
| Context not available. | |||||
| { | { | ||||
| TextLine **linep; | TextLine **linep; | ||||
| int *charp; | int *charp; | ||||
| if (!text) return; | |||||
| if (sel) txt_curs_sel(text, &linep, &charp); | if (sel) txt_curs_sel(text, &linep, &charp); | ||||
| else txt_curs_cur(text, &linep, &charp); | else txt_curs_cur(text, &linep, &charp); | ||||
| if (!*linep) return; | if (!*linep) return; | ||||
| Context not available. | |||||
| { | { | ||||
| TextLine **linep; | TextLine **linep; | ||||
| int *charp; | int *charp; | ||||
| if (!text) return; | |||||
| if (sel) txt_curs_sel(text, &linep, &charp); | if (sel) txt_curs_sel(text, &linep, &charp); | ||||
| else txt_curs_cur(text, &linep, &charp); | else txt_curs_cur(text, &linep, &charp); | ||||
| if (!*linep) return; | if (!*linep) return; | ||||
| Context not available. | |||||
| { | { | ||||
| TextLine **linep; | TextLine **linep; | ||||
| int *charp; | int *charp; | ||||
| if (!text) return; | |||||
| if (sel) txt_curs_sel(text, &linep, &charp); | if (sel) txt_curs_sel(text, &linep, &charp); | ||||
| else txt_curs_cur(text, &linep, &charp); | else txt_curs_cur(text, &linep, &charp); | ||||
| if (!*linep) return; | if (!*linep) return; | ||||
| Context not available. | |||||
| { | { | ||||
| TextLine **linep; | TextLine **linep; | ||||
| int *charp; | int *charp; | ||||
| if (!text) return; | |||||
| if (sel) txt_curs_sel(text, &linep, &charp); | if (sel) txt_curs_sel(text, &linep, &charp); | ||||
| else txt_curs_cur(text, &linep, &charp); | else txt_curs_cur(text, &linep, &charp); | ||||
| if (!*linep) return; | if (!*linep) return; | ||||
| Context not available. | |||||
| TextLine **linep; | TextLine **linep; | ||||
| int *charp; | int *charp; | ||||
| unsigned int i; | unsigned int i; | ||||
| if (!text) return; | |||||
| if (sel) txt_curs_sel(text, &linep, &charp); | if (sel) txt_curs_sel(text, &linep, &charp); | ||||
| else txt_curs_cur(text, &linep, &charp); | else txt_curs_cur(text, &linep, &charp); | ||||
| if (!*linep) return; | if (!*linep) return; | ||||
| Context not available. | |||||
| static void txt_pop_first(Text *text) | static void txt_pop_first(Text *text) | ||||
| { | { | ||||
| if (txt_get_span(text->curl, text->sell) < 0 || | if (txt_get_span(text->curl, text->sell) < 0 || | ||||
| (text->curl == text->sell && text->curc > text->selc)) | (text->curl == text->sell && text->curc > text->selc)) | ||||
| { | { | ||||
| Context not available. | |||||
| void txt_order_cursors(Text *text, const bool reverse) | void txt_order_cursors(Text *text, const bool reverse) | ||||
| { | { | ||||
| if (!text) return; | |||||
| if (!text->curl) return; | if (!text->curl) return; | ||||
| if (!text->sell) return; | if (!text->sell) return; | ||||
| Context not available. | |||||
| { | { | ||||
| TextLine *tmpl; | TextLine *tmpl; | ||||
| char *buf; | char *buf; | ||||
| if (!text) return; | |||||
| if (!text->curl) return; | if (!text->curl) return; | ||||
| if (!text->sell) return; | if (!text->sell) return; | ||||
| Context not available. | |||||
| void txt_sel_all(Text *text) | void txt_sel_all(Text *text) | ||||
| { | { | ||||
| if (!text) return; | |||||
| text->curl = text->lines.first; | text->curl = text->lines.first; | ||||
| text->curc = 0; | text->curc = 0; | ||||
| Context not available. | |||||
| void txt_sel_line(Text *text) | void txt_sel_line(Text *text) | ||||
| { | { | ||||
| if (!text) return; | |||||
| if (!text->curl) return; | if (!text->curl) return; | ||||
| text->curc = 0; | text->curc = 0; | ||||
| Context not available. | |||||
| TextLine *tmp, *linef, *linel; | TextLine *tmp, *linef, *linel; | ||||
| int charf, charl; | int charf, charl; | ||||
| char *buf; | char *buf; | ||||
| if (!text) return NULL; | |||||
| if (!text->curl) return NULL; | if (!text->curl) return NULL; | ||||
| if (!text->sell) return NULL; | if (!text->sell) return NULL; | ||||
| if (!text->lines.first) return NULL; | if (!text->lines.first) return NULL; | ||||
| Context not available. | |||||
| TextLine *tl, *startl; | TextLine *tl, *startl; | ||||
| const char *s = NULL; | const char *s = NULL; | ||||
| if (!text->curl || !text->sell) return 0; | if (!text || !text->curl || !text->sell) return 0; | ||||
| txt_order_cursors(text, false); | txt_order_cursors(text, false); | ||||
| Context not available. | |||||
| int length = 0; | int length = 0; | ||||
| TextLine *tmp, *linef, *linel; | TextLine *tmp, *linef, *linel; | ||||
| int charf, charl; | int charf, charl; | ||||
| if (!text) return NULL; | |||||
| if (!text->curl) return NULL; | if (!text->curl) return NULL; | ||||
| if (!text->sell) return NULL; | if (!text->sell) return NULL; | ||||
| Context not available. | |||||
| TextLine *add; | TextLine *add; | ||||
| char *buffer; | char *buffer; | ||||
| if (!text) return; | |||||
| if (!in_buffer) return; | if (!in_buffer) return; | ||||
| txt_delete_sel(text); | txt_delete_sel(text); | ||||
| Context not available. | |||||
| { | { | ||||
| TextLine *ins; | TextLine *ins; | ||||
| char *left, *right; | char *left, *right; | ||||
| if (!text) return; | |||||
| if (!text->curl) return; | if (!text->curl) return; | ||||
| txt_delete_sel(text); | txt_delete_sel(text); | ||||
| Context not available. | |||||
| static void txt_delete_line(Text *text, TextLine *line) | static void txt_delete_line(Text *text, TextLine *line) | ||||
| { | { | ||||
| if (!text) return; | |||||
| if (!text->curl) return; | if (!text->curl) return; | ||||
| BLI_remlink(&text->lines, line); | BLI_remlink(&text->lines, line); | ||||
| Context not available. | |||||
| static void txt_combine_lines(Text *text, TextLine *linea, TextLine *lineb) | static void txt_combine_lines(Text *text, TextLine *linea, TextLine *lineb) | ||||
| { | { | ||||
| char *tmp, *s; | char *tmp, *s; | ||||
| if (!text) return; | |||||
| if (!linea || !lineb) return; | if (!linea || !lineb) return; | ||||
| Context not available. | |||||
| { | { | ||||
| TextLine *textline; | TextLine *textline; | ||||
| if (!text->curl) return; | if (!text || !text->curl) return; | ||||
| if (text->curl == text->sell) { | if (text->curl == text->sell) { | ||||
| textline = txt_new_line(text->curl->line); | textline = txt_new_line(text->curl->line); | ||||
| Context not available. | |||||
| void txt_delete_char(Text *text) | void txt_delete_char(Text *text) | ||||
| { | { | ||||
| unsigned int c = '\n'; | unsigned int c = '\n'; | ||||
| if (!text) return; | |||||
| if (!text->curl) return; | if (!text->curl) return; | ||||
| if (txt_has_sel(text)) { /* deleting a selection */ | if (txt_has_sel(text)) { /* deleting a selection */ | ||||
| Context not available. | |||||
| { | { | ||||
| unsigned int c = '\n'; | unsigned int c = '\n'; | ||||
| if (!text) return; | |||||
| if (!text->curl) return; | if (!text->curl) return; | ||||
| if (txt_has_sel(text)) { /* deleting a selection */ | if (txt_has_sel(text)) { /* deleting a selection */ | ||||
| Context not available. | |||||
| { | { | ||||
| char *tmp, ch[BLI_UTF8_MAX]; | char *tmp, ch[BLI_UTF8_MAX]; | ||||
| size_t add_len; | size_t add_len; | ||||
| if (!text) return 0; | |||||
| if (!text->curl) return 0; | if (!text->curl) return 0; | ||||
| if (add == '\n') { | if (add == '\n') { | ||||
| Context not available. | |||||
| unsigned int del; | unsigned int del; | ||||
| size_t del_size = 0, add_size; | size_t del_size = 0, add_size; | ||||
| char ch[BLI_UTF8_MAX]; | char ch[BLI_UTF8_MAX]; | ||||
| if (!text) return 0; | |||||
| if (!text->curl) return 0; | if (!text->curl) return 0; | ||||
| /* If text is selected or we're at the end of the line just use txt_add_char */ | /* If text is selected or we're at the end of the line just use txt_add_char */ | ||||
| Context not available. | |||||
| /* hardcoded: TXT_TABSIZE = 4 spaces: */ | /* hardcoded: TXT_TABSIZE = 4 spaces: */ | ||||
| int spaceslen = TXT_TABSIZE; | int spaceslen = TXT_TABSIZE; | ||||
| if (ELEM(NULL, text->curl, text->sell)) { | if (ELEM(NULL, text, text->curl, text->sell)) { | ||||
| return; | return; | ||||
| } | } | ||||
| Context not available. | |||||
| /* hardcoded: TXT_TABSIZE = 4 spaces: */ | /* hardcoded: TXT_TABSIZE = 4 spaces: */ | ||||
| int spaceslen = TXT_TABSIZE; | int spaceslen = TXT_TABSIZE; | ||||
| if (ELEM(NULL, text->curl, text->sell)) { | if (ELEM(NULL, text, text->curl, text->sell)) { | ||||
| return; | return; | ||||
| } | } | ||||
| Context not available. | |||||
| int len, num; | int len, num; | ||||
| char *tmp; | char *tmp; | ||||
| char add = '#'; | char add = '#'; | ||||
| if (!text) return; | |||||
| if (!text->curl) return; | if (!text->curl) return; | ||||
| if (!text->sell) return; // Need to change this need to check if only one line is selected to more than one | if (!text->sell) return; // Need to change this need to check if only one line is selected to more than one | ||||
| Context not available. | |||||
| { | { | ||||
| int num = 0; | int num = 0; | ||||
| char remove = '#'; | char remove = '#'; | ||||
| if (!text) return; | |||||
| if (!text->curl) return; | if (!text->curl) return; | ||||
| if (!text->sell) return; | if (!text->sell) return; | ||||
| Context not available. | |||||
| BLI_assert(ELEM(direction, TXT_MOVE_LINE_UP, TXT_MOVE_LINE_DOWN)); | BLI_assert(ELEM(direction, TXT_MOVE_LINE_UP, TXT_MOVE_LINE_DOWN)); | ||||
| if (!text->curl || !text->sell) return; | if (!text || !text->curl || !text->sell) return; | ||||
| txt_order_cursors(text, false); | txt_order_cursors(text, false); | ||||
| Context not available. | |||||
| const char *comm = "#"; | const char *comm = "#"; | ||||
| const char indent = (text->flags & TXT_TABSTOSPACES) ? ' ' : '\t'; | const char indent = (text->flags & TXT_TABSTOSPACES) ? ' ' : '\t'; | ||||
| static const char *back_words[] = {"return", "break", "continue", "pass", "yield", NULL}; | static const char *back_words[] = {"return", "break", "continue", "pass", "yield", NULL}; | ||||
| if (!text->curl) return 0; | if (!text->curl) return 0; | ||||
| while (text->curl->line[i] == indent) { | while (text->curl->line[i] == indent) { | ||||
| Context not available. | |||||