Blender  V2.93
text_format.h
Go to the documentation of this file.
1 /*
2  * This program is free software; you can redistribute it and/or
3  * modify it under the terms of the GNU General Public License
4  * as published by the Free Software Foundation; either version 2
5  * of the License, or (at your option) any later version.
6  *
7  * This program is distributed in the hope that it will be useful,
8  * but WITHOUT ANY WARRANTY; without even the implied warranty of
9  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
10  * GNU General Public License for more details.
11  *
12  * You should have received a copy of the GNU General Public License
13  * along with this program; if not, write to the Free Software Foundation,
14  * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
15  *
16  * The Original Code is Copyright (C) 2009 Blender Foundation.
17  * All rights reserved.
18  */
19 
24 #pragma once
25 
26 /* *** Flatten String *** */
27 typedef struct FlattenString {
28  char fixedbuf[256];
29  int fixedaccum[256];
30 
31  char *buf;
32  int *accum;
33  int pos, len;
35 
36 /* format continuation flags (stored just after the NULL terminator) */
37 enum {
38  FMT_CONT_NOP = 0, /* no continuation */
39  FMT_CONT_QUOTESINGLE = (1 << 0), /* single quotes */
40  FMT_CONT_QUOTEDOUBLE = (1 << 1), /* double quotes */
41  FMT_CONT_TRIPLE = (1 << 2), /* triplets of quotes: """ or ''' */
44  FMT_CONT_COMMENT_C = (1 << 3) /* multi-line comments, OSL only (C style) */
45 };
46 #define FMT_CONT_ALL \
47  (FMT_CONT_QUOTESINGLE | FMT_CONT_QUOTEDOUBLE | FMT_CONT_TRIPLE | FMT_CONT_COMMENT_C)
48 
49 int flatten_string(const struct SpaceText *st, FlattenString *fs, const char *in);
51 int flatten_string_strlen(FlattenString *fs, const char *str);
52 
53 int text_check_format_len(TextLine *line, unsigned int len);
54 void text_format_fill(const char **str_p, char **fmt_p, const char type, const int len);
55 void text_format_fill_ascii(const char **str_p, char **fmt_p, const char type, const int len);
56 
57 /* *** Generalize Formatting *** */
58 typedef struct TextFormatType {
60 
61  char (*format_identifier)(const char *string);
62 
63  /* Formats the specified line. If do_next is set, the process will move on to
64  * the succeeding line if it is affected (eg. multi-line strings). Format strings
65  * may contain any of the following characters:
66  *
67  * It is terminated with a null-terminator '\0' followed by a continuation
68  * flag indicating whether the line is part of a multi-line string.
69  *
70  * See: FMT_TYPE_ enums below
71  */
72  void (*format_line)(SpaceText *st, TextLine *line, const bool do_next);
73 
74  const char **ext; /* NULL terminated extensions */
76 
77 enum {
98 };
99 
102 
103 /* formatters */
104 void ED_text_format_register_py(void);
105 void ED_text_format_register_osl(void);
106 void ED_text_format_register_lua(void);
107 void ED_text_format_register_pov(void);
109 
110 #define STR_LITERAL_STARTSWITH(str, str_literal, len_var) \
111  (strncmp(str, str_literal, len_var = (sizeof(str_literal) - 1)) == 0)
_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 type
#define str(s)
int fixedaccum[256]
Definition: text_format.h:29
char fixedbuf[256]
Definition: text_format.h:28
struct TextFormatType * prev
Definition: text_format.h:59
void(* format_line)(SpaceText *st, TextLine *line, const bool do_next)
Definition: text_format.h:72
struct TextFormatType * next
Definition: text_format.h:59
char(* format_identifier)(const char *string)
Definition: text_format.h:61
const char ** ext
Definition: text_format.h:74
struct TextFormatType TextFormatType
int flatten_string_strlen(FlattenString *fs, const char *str)
Definition: text_format.c:115
void text_format_fill(const char **str_p, char **fmt_p, const char type, const int len)
Definition: text_format.c:151
void ED_text_format_register_lua(void)
void flatten_string_free(FlattenString *fs)
Definition: text_format.c:104
int flatten_string(const struct SpaceText *st, FlattenString *fs, const char *in)
void ED_text_format_register_osl(void)
void ED_text_format_register_py(void)
TextFormatType * ED_text_format_get(Text *text)
Definition: text_format.c:200
@ FMT_TYPE_DIRECTIVE
Definition: text_format.h:89
@ FMT_TYPE_STRING
Definition: text_format.h:87
@ FMT_TYPE_COMMENT
Definition: text_format.h:81
@ FMT_TYPE_SPECIAL
Definition: text_format.h:91
@ FMT_TYPE_DEFAULT
Definition: text_format.h:97
@ FMT_TYPE_KEYWORD
Definition: text_format.h:95
@ FMT_TYPE_WHITESPACE
Definition: text_format.h:79
@ FMT_TYPE_NUMERAL
Definition: text_format.h:85
@ FMT_TYPE_RESERVED
Definition: text_format.h:93
@ FMT_TYPE_SYMBOL
Definition: text_format.h:83
@ FMT_CONT_QUOTEDOUBLE
Definition: text_format.h:40
@ FMT_CONT_QUOTESINGLE_TRIPLE
Definition: text_format.h:42
@ FMT_CONT_QUOTEDOUBLE_TRIPLE
Definition: text_format.h:43
@ FMT_CONT_QUOTESINGLE
Definition: text_format.h:39
@ FMT_CONT_TRIPLE
Definition: text_format.h:41
@ FMT_CONT_NOP
Definition: text_format.h:38
@ FMT_CONT_COMMENT_C
Definition: text_format.h:44
void ED_text_format_register_pov_ini(void)
struct FlattenString FlattenString
void ED_text_format_register_pov(void)
void text_format_fill_ascii(const char **str_p, char **fmt_p, const char type, const int len)
Definition: text_format.c:177
void ED_text_format_register(TextFormatType *tft)
Definition: text_format.c:195
int text_check_format_len(TextLine *line, unsigned int len)
Definition: text_format.c:124
uint len