[Bf-blender-cvs] [9b292338009] master: Add PovRay syntax hilghting.

Bastien Montagne noreply at git.blender.org
Mon May 22 22:12:25 CEST 2017


Commit: 9b2923380092c7e3c771d354f8938c5ca20bfd9d
Author: Bastien Montagne
Date:   Mon May 22 21:53:32 2017 +0200
Branches: master
https://developer.blender.org/rB9b2923380092c7e3c771d354f8938c5ca20bfd9d

Add PovRay syntax hilghting.

Since we already have a rather advanced PovRay exporter, makes sense to
also nicely display generated 'code'.

Patch by Maurice Raybaud (@mauriceraybaud), thanks!
Cleanup (mostly styling) by @mont29.

===================================================================

M	source/blender/editors/space_text/CMakeLists.txt
M	source/blender/editors/space_text/space_text.c
M	source/blender/editors/space_text/text_format.h
A	source/blender/editors/space_text/text_format_pov.c
A	source/blender/editors/space_text/text_format_pov_ini.c

===================================================================

diff --git a/source/blender/editors/space_text/CMakeLists.txt b/source/blender/editors/space_text/CMakeLists.txt
index de85ddc40ab..39b48f5b52c 100644
--- a/source/blender/editors/space_text/CMakeLists.txt
+++ b/source/blender/editors/space_text/CMakeLists.txt
@@ -43,6 +43,8 @@ set(SRC
 	text_format.c
 	text_format_lua.c
 	text_format_osl.c
+	text_format_pov.c
+	text_format_pov_ini.c
 	text_format_py.c
 	text_header.c
 	text_ops.c
diff --git a/source/blender/editors/space_text/space_text.c b/source/blender/editors/space_text/space_text.c
index ca2380e510f..fcb46ced750 100644
--- a/source/blender/editors/space_text/space_text.c
+++ b/source/blender/editors/space_text/space_text.c
@@ -636,5 +636,7 @@ void ED_spacetype_text(void)
 	ED_text_format_register_py();
 	ED_text_format_register_osl();
 	ED_text_format_register_lua();
+	ED_text_format_register_pov();
+	ED_text_format_register_pov_ini();
 }
 
diff --git a/source/blender/editors/space_text/text_format.h b/source/blender/editors/space_text/text_format.h
index b901ec83a9c..d7cf31d0b41 100644
--- a/source/blender/editors/space_text/text_format.h
+++ b/source/blender/editors/space_text/text_format.h
@@ -102,6 +102,8 @@ void            ED_text_format_register(TextFormatType *tft);
 void ED_text_format_register_py(void);
 void ED_text_format_register_osl(void);
 void ED_text_format_register_lua(void);
+void ED_text_format_register_pov(void);
+void ED_text_format_register_pov_ini(void);
 
 #define STR_LITERAL_STARTSWITH(str, str_literal, len_var) \
 	(strncmp(str, str_literal, len_var = (sizeof(str_literal) - 1)) == 0)
diff --git a/source/blender/editors/space_text/text_format_pov.c b/source/blender/editors/space_text/text_format_pov.c
new file mode 100644
index 00000000000..ed915d6b72c
--- /dev/null
+++ b/source/blender/editors/space_text/text_format_pov.c
@@ -0,0 +1,789 @@
+/*
+ * ***** BEGIN GPL LICENSE BLOCK *****
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License
+ * as published by the Free Software Foundation; either version 2
+ * of the License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+ *
+ * ***** END GPL LICENSE BLOCK *****
+ */
+
+/** \file blender/editors/space_text/text_format_pov.c
+ *  \ingroup sptext
+ */
+
+#include <string.h>
+
+#include "BLI_blenlib.h"
+
+#include "DNA_text_types.h"
+#include "DNA_space_types.h"
+
+#include "BKE_text.h"
+
+#include "text_format.h"
+
+/* *** POV Keywords (for format_line) *** */
+
+/* Checks the specified source string for a POV keyword (minus boolean & 'nil').
+ * This name must start at the beginning of the source string and must be
+ * followed by a non-identifier (see text_check_identifier(char)) or null char.
+ *
+ * If a keyword is found, the length of the matching word is returned.
+ * Otherwise, -1 is returned.
+ *
+ * See:
+ * http://www.povray.org/documentation/view/3.7.0/212/
+ */
+
+static int txtfmt_pov_find_keyword(const char *string)
+{
+	int i, len;
+	/* Language Directives */
+	if      (STR_LITERAL_STARTSWITH(string, "append",      len)) i = len;
+	else if (STR_LITERAL_STARTSWITH(string, "break",       len)) i = len;
+	else if (STR_LITERAL_STARTSWITH(string, "case",        len)) i = len;
+	else if (STR_LITERAL_STARTSWITH(string, "debug",       len)) i = len;
+	else if (STR_LITERAL_STARTSWITH(string, "declare",     len)) i = len;
+	else if (STR_LITERAL_STARTSWITH(string, "default",     len)) i = len;
+	else if (STR_LITERAL_STARTSWITH(string, "deprecated",  len)) i = len;
+	else if (STR_LITERAL_STARTSWITH(string, "else",        len)) i = len;
+	else if (STR_LITERAL_STARTSWITH(string, "elseif",      len)) i = len;
+	else if (STR_LITERAL_STARTSWITH(string, "end",         len)) i = len;
+	else if (STR_LITERAL_STARTSWITH(string, "error",       len)) i = len;
+	else if (STR_LITERAL_STARTSWITH(string, "fclose",      len)) i = len;
+	else if (STR_LITERAL_STARTSWITH(string, "fopen",       len)) i = len;
+	else if (STR_LITERAL_STARTSWITH(string, "for",         len)) i = len;
+	else if (STR_LITERAL_STARTSWITH(string, "if",          len)) i = len;
+	else if (STR_LITERAL_STARTSWITH(string, "ifdef",       len)) i = len;
+	else if (STR_LITERAL_STARTSWITH(string, "ifndef",      len)) i = len;
+	else if (STR_LITERAL_STARTSWITH(string, "include",     len)) i = len;
+	else if (STR_LITERAL_STARTSWITH(string, "local",       len)) i = len;
+	else if (STR_LITERAL_STARTSWITH(string, "macro",       len)) i = len;
+	else if (STR_LITERAL_STARTSWITH(string, "range",       len)) i = len;
+	else if (STR_LITERAL_STARTSWITH(string, "read",        len)) i = len;
+	else if (STR_LITERAL_STARTSWITH(string, "render",      len)) i = len;
+	else if (STR_LITERAL_STARTSWITH(string, "statistics",  len)) i = len;
+	else if (STR_LITERAL_STARTSWITH(string, "switch",      len)) i = len;
+	else if (STR_LITERAL_STARTSWITH(string, "undef",       len)) i = len;
+	else if (STR_LITERAL_STARTSWITH(string, "version",     len)) i = len;
+	else if (STR_LITERAL_STARTSWITH(string, "warning",     len)) i = len;
+	else if (STR_LITERAL_STARTSWITH(string, "while",       len)) i = len;
+	else if (STR_LITERAL_STARTSWITH(string, "write",       len)) i = len;
+	else                                                         i = 0;
+
+	/* If next source char is an identifier (eg. 'i' in "definate") no match */
+	return (i == 0 || text_check_identifier(string[i])) ? -1 : i;
+}
+
+static int txtfmt_pov_find_reserved(const char *string)
+{
+	int i, len;
+	/* POV-Ray Built-in Variables
+	 * list is from...
+	 * http://www.povray.org/documentation/view/3.7.0/212/
+	 */
+	if      (STR_LITERAL_STARTSWITH(string, "clock",               len)) i = len;
+	else if (STR_LITERAL_STARTSWITH(string, "clock_delta",         len)) i = len;
+	else if (STR_LITERAL_STARTSWITH(string, "clock_on",            len)) i = len;
+	else if (STR_LITERAL_STARTSWITH(string, "final_clock",         len)) i = len;
+	else if (STR_LITERAL_STARTSWITH(string, "final_frame",         len)) i = len;
+	else if (STR_LITERAL_STARTSWITH(string, "frame_number",        len)) i = len;
+	else if (STR_LITERAL_STARTSWITH(string, "initial_clock",       len)) i = len;
+	else if (STR_LITERAL_STARTSWITH(string, "initial_frame",       len)) i = len;
+	else if (STR_LITERAL_STARTSWITH(string, "image_height",        len)) i = len;
+	else if (STR_LITERAL_STARTSWITH(string, "image_width",         len)) i = len;
+	else if (STR_LITERAL_STARTSWITH(string, "input_file_name",     len)) i = len;
+	/* Language Keywords */
+	else if (STR_LITERAL_STARTSWITH(string, "aa_level",            len)) i = len;
+	else if (STR_LITERAL_STARTSWITH(string, "aa_threshold",        len)) i = len;
+	else if (STR_LITERAL_STARTSWITH(string, "absorption",          len)) i = len;
+	else if (STR_LITERAL_STARTSWITH(string, "accuracy",            len)) i = len;
+	else if (STR_LITERAL_STARTSWITH(string, "adc_bailout",         len)) i = len;
+	else if (STR_LITERAL_STARTSWITH(string, "albedo",              len)) i = len;
+	else if (STR_LITERAL_STARTSWITH(string, "all",                 len)) i = len;
+	else if (STR_LITERAL_STARTSWITH(string, "all_intersections",   len)) i = len;
+	else if (STR_LITERAL_STARTSWITH(string, "alpha",               len)) i = len;
+	else if (STR_LITERAL_STARTSWITH(string, "altitude",            len)) i = len;
+	else if (STR_LITERAL_STARTSWITH(string, "always_sample",       len)) i = len;
+	else if (STR_LITERAL_STARTSWITH(string, "ambient",             len)) i = len;
+	else if (STR_LITERAL_STARTSWITH(string, "ambient_light",       len)) i = len;
+	else if (STR_LITERAL_STARTSWITH(string, "angle",               len)) i = len;
+	else if (STR_LITERAL_STARTSWITH(string, "aperture",            len)) i = len;
+	else if (STR_LITERAL_STARTSWITH(string, "arc_angle",           len)) i = len;
+	else if (STR_LITERAL_STARTSWITH(string, "area_light",          len)) i = len;
+	else if (STR_LITERAL_STARTSWITH(string, "area_illumination",   len)) i = len;
+	else if (STR_LITERAL_STARTSWITH(string, "array",               len)) i = len;
+	else if (STR_LITERAL_STARTSWITH(string, "assumed_gamma",       len)) i = len;
+	else if (STR_LITERAL_STARTSWITH(string, "autostop",            len)) i = len;
+	else if (STR_LITERAL_STARTSWITH(string, "black_hole",          len)) i = len;
+	else if (STR_LITERAL_STARTSWITH(string, "blur_samples",        len)) i = len;
+	else if (STR_LITERAL_STARTSWITH(string, "brightness",          len)) i = len;
+	else if (STR_LITERAL_STARTSWITH(string, "brilliance",          len)) i = len;
+	else if (STR_LITERAL_STARTSWITH(string, "caustics",            len)) i = len;
+	else if (STR_LITERAL_STARTSWITH(string, "charset",             len)) i = len;
+	else if (STR_LITERAL_STARTSWITH(string, "collect",             len)) i = len;
+	else if (STR_LITERAL_STARTSWITH(string, "component",           len)) i = len;
+	else if (STR_LITERAL_STARTSWITH(string, "composite",           len)) i = len;
+	else if (STR_LITERAL_STARTSWITH(string, "confidence",          len)) i = len;
+	else if (STR_LITERAL_STARTSWITH(string, "conserve_energy",     len)) i = len;
+	else if (STR_LITERAL_STARTSWITH(string, "contained_by",        len)) i = len;
+	else if (STR_LITERAL_STARTSWITH(string, "coords",              len)) i = len;
+	else if (STR_LITERAL_STARTSWITH(string, "count",               len)) i = len;
+	else if (STR_LITERAL_STARTSWITH(string, "crand",               len)) i = len;
+	else if (STR_LITERAL_STARTSWITH(string, "cube",                len)) i = len;
+	else if (STR_LITERAL_STARTSWITH(string, "cutaway_textures",    len)) i = len;
+	else if (STR_LITERAL_STARTSWITH(string, "diffuse",             len)) i = len;
+	else if (STR_LITERAL_STARTSWITH(string, "direction",           len)) i = len;
+	else if (STR_LITERAL_STARTSWITH(string, "dispersion",          len)) i = len;
+	else if (STR_LITERAL_STARTSWITH(string, "dispersi

@@ Diff output truncated at 10240 characters. @@




More information about the Bf-blender-cvs mailing list