2
* ***** BEGIN GPL LICENSE BLOCK *****
4
* This program is free software; you can redistribute it and/or
5
* modify it under the terms of the GNU General Public License
6
* as published by the Free Software Foundation; either version 2
7
* of the License, or (at your option) any later version.
9
* This program is distributed in the hope that it will be useful,
10
* but WITHOUT ANY WARRANTY; without even the implied warranty of
11
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12
* GNU General Public License for more details.
14
* You should have received a copy of the GNU General Public License
15
* along with this program; if not, write to the Free Software Foundation,
16
* Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
18
* The Original Code is Copyright (C) 2009 Blender Foundation.
19
* All rights reserved.
22
* Contributor(s): Blender Foundation
24
* ***** END GPL LICENSE BLOCK *****
27
/** \file blender/editors/space_text/text_format.h
31
#ifndef __TEXT_FORMAT_H__
32
#define __TEXT_FORMAT_H__
34
/* *** Flatten String *** */
35
typedef struct FlattenString {
44
/* format continuation flags (stored just after the NULL terminator) */
46
FMT_CONT_NOP = 0, /* no continuation */
47
FMT_CONT_QUOTESINGLE = (1 << 0), /* single quotes */
48
FMT_CONT_QUOTEDOUBLE = (1 << 1), /* double quotes */
49
FMT_CONT_TRIPLE = (1 << 2), /* triplets of quotes: """ or ''' */
50
FMT_CONT_QUOTESINGLE_TRIPLE = (FMT_CONT_TRIPLE | FMT_CONT_QUOTESINGLE),
51
FMT_CONT_QUOTEDOUBLE_TRIPLE = (FMT_CONT_TRIPLE | FMT_CONT_QUOTEDOUBLE),
52
FMT_CONT_COMMENT_C = (1 << 3) /* multi-line comments, OSL only (C style) */
54
#define FMT_CONT_ALL \
55
(FMT_CONT_QUOTESINGLE | FMT_CONT_QUOTEDOUBLE | FMT_CONT_TRIPLE | FMT_CONT_COMMENT_C)
57
int flatten_string(struct SpaceText *st, FlattenString *fs, const char *in);
58
void flatten_string_free(FlattenString *fs);
59
int flatten_string_strlen(FlattenString *fs, const char *str);
61
int text_check_format_len(TextLine *line, unsigned int len);
62
void text_format_fill(const char **str_p, char **fmt_p, const char type, const int len);
63
void text_format_fill_ascii(const char **str_p, char **fmt_p, const char type, const int len);
65
/* *** Generalize Formatting *** */
66
typedef struct TextFormatType {
67
struct TextFormatType *next, *prev;
69
char (*format_identifier)(const char *string);
71
/* Formats the specified line. If do_next is set, the process will move on to
72
* the succeeding line if it is affected (eg. multiline strings). Format strings
73
* may contain any of the following characters:
75
* It is terminated with a null-terminator '\0' followed by a continuation
76
* flag indicating whether the line is part of a multi-line string.
78
* See: FMT_TYPE_ enums below
80
void (*format_line)(SpaceText *st, TextLine *line, int do_next);
82
const char **ext; /* NULL terminated extensions */
86
FMT_TYPE_WHITESPACE = '_', /* Whitespace */
87
FMT_TYPE_COMMENT = '#', /* Comment text */
88
FMT_TYPE_SYMBOL = '!', /* Punctuation and other symbols */
89
FMT_TYPE_NUMERAL = 'n', /* Numerals */
90
FMT_TYPE_STRING = 'l', /* String letters */
91
FMT_TYPE_DIRECTIVE = 'd', /* Decorator / Preprocessor directive */
92
FMT_TYPE_SPECIAL = 'v', /* Special variables (class, def) */
93
FMT_TYPE_RESERVED = 'r', /* Reserved keywords currently not in use, but still prohibited (OSL -> switch e.g.) */
94
FMT_TYPE_KEYWORD = 'b', /* Built-in names (return, for, etc.) */
95
FMT_TYPE_DEFAULT = 'q', /* Regular text (identifiers, etc.) */
98
TextFormatType *ED_text_format_get(Text *text);
99
void ED_text_format_register(TextFormatType *tft);
102
void ED_text_format_register_py(void);
103
void ED_text_format_register_osl(void);
104
void ED_text_format_register_lua(void);
106
#define STR_LITERAL_STARTSWITH(str, str_literal, len_var) \
107
(strncmp(str, str_literal, len_var = (sizeof(str_literal) - 1)) == 0)
109
#endif /* __TEXT_FORMAT_H__ */