[Bf-blender-cvs] SVN commit: /data/svn/bf-blender [53418] trunk/blender/source/blender/ editors/space_text: code cleanup: enum for formatting char ( avoid confusion when '#' is a comment for // in OSL)

Campbell Barton ideasman42 at gmail.com
Sun Dec 30 02:12:24 CET 2012


Revision: 53418
          http://projects.blender.org/scm/viewvc.php?view=rev&root=bf-blender&revision=53418
Author:   campbellbarton
Date:     2012-12-30 01:12:21 +0000 (Sun, 30 Dec 2012)
Log Message:
-----------
code cleanup: enum for formatting char (avoid confusion when '#' is a comment for // in OSL)

Modified Paths:
--------------
    trunk/blender/source/blender/editors/space_text/text_draw.c
    trunk/blender/source/blender/editors/space_text/text_format.h
    trunk/blender/source/blender/editors/space_text/text_format_osl.c
    trunk/blender/source/blender/editors/space_text/text_format_py.c

Modified: trunk/blender/source/blender/editors/space_text/text_draw.c
===================================================================
--- trunk/blender/source/blender/editors/space_text/text_draw.c	2012-12-30 00:47:55 UTC (rev 53417)
+++ trunk/blender/source/blender/editors/space_text/text_draw.c	2012-12-30 01:12:21 UTC (rev 53418)
@@ -117,33 +117,33 @@
 static void format_draw_color(char formatchar)
 {
 	switch (formatchar) {
-		case '_': /* Whitespace */
+		case FMT_TYPE_WHITESPACE:
 			break;
-		case '!': /* Symbols */
+		case FMT_TYPE_SYMBOL:
 			UI_ThemeColorBlend(TH_TEXT, TH_BACK, 0.5f);
 			break;
-		case '#': /* Comments */
+		case FMT_TYPE_COMMENT:
 			UI_ThemeColor(TH_SYNTAX_C);
 			break;
-		case 'n': /* Numerals */
+		case FMT_TYPE_NUMERAL:
 			UI_ThemeColor(TH_SYNTAX_N);
 			break;
-		case 'l': /* Strings */
+		case FMT_TYPE_STRING:
 			UI_ThemeColor(TH_SYNTAX_L);
 			break;
-		case 'd': /* Preprocessor directive */
+		case FMT_TYPE_DIRECTIVE:
 			UI_ThemeColor(TH_SYNTAX_D);
 			break;
-		case 'v': /* Specials: class, def */
+		case FMT_TYPE_SPECIAL:
 			UI_ThemeColor(TH_SYNTAX_V);
 			break;
-		case 'r': /* Reserved keywords */
+		case FMT_TYPE_RESERVED:
 			UI_ThemeColor(TH_SYNTAX_R);
 			break;
-		case 'b': /* Keywords: for, print, etc. */
+		case FMT_TYPE_KEYWORD:
 			UI_ThemeColor(TH_SYNTAX_B);
 			break;
-		case 'q': /* Other text (identifiers) */
+		case FMT_TYPE_DEFAULT:
 		default:
 			UI_ThemeColor(TH_TEXT);
 			break;
@@ -1174,7 +1174,7 @@
 	stack = 0;
 	
 	/* Don't highlight backets if syntax HL is off or bracket in string or comment. */
-	if (!linep->format || linep->format[fc] == 'l' || linep->format[fc] == '#')
+	if (!linep->format || linep->format[fc] == FMT_TYPE_STRING || linep->format[fc] == FMT_TYPE_COMMENT)
 		return;
 
 	if (b > 0) {
@@ -1183,7 +1183,7 @@
 		c += BLI_str_utf8_size_safe(linep->line + c);
 		while (linep) {
 			while (c < linep->len) {
-				if (linep->format && linep->format[fc] != 'l' && linep->format[fc] != '#') {
+				if (linep->format && linep->format[fc] != FMT_TYPE_STRING && linep->format[fc] != FMT_TYPE_COMMENT) {
 					b = text_check_bracket(linep->line[c]);
 					if (b == find) {
 						if (stack == 0) {
@@ -1212,7 +1212,7 @@
 		if (c > 0) c -= linep->line + c - BLI_str_prev_char_utf8(linep->line + c);
 		while (linep) {
 			while (fc >= 0) {
-				if (linep->format && linep->format[fc] != 'l' && linep->format[fc] != '#') {
+				if (linep->format && linep->format[fc] != FMT_TYPE_STRING && linep->format[fc] != FMT_TYPE_COMMENT) {
 					b = text_check_bracket(linep->line[c]);
 					if (b == find) {
 						if (stack == 0) {

Modified: trunk/blender/source/blender/editors/space_text/text_format.h
===================================================================
--- trunk/blender/source/blender/editors/space_text/text_format.h	2012-12-30 00:47:55 UTC (rev 53417)
+++ trunk/blender/source/blender/editors/space_text/text_format.h	2012-12-30 01:12:21 UTC (rev 53418)
@@ -69,23 +69,30 @@
 	/* Formats the specified line. If do_next is set, the process will move on to
 	 * the succeeding line if it is affected (eg. multiline strings). Format strings
 	 * may contain any of the following characters:
-	 *  '_'  Whitespace
-	 *  '#'  Comment text
-	 *  '!'  Punctuation and other symbols
-	 *  'n'  Numerals
-	 *  'l'  String letters
-	 *  'd'  Decorator / Preprocessor directive
-	 *  'v'  Special variables (class, def)
-	 *  'r'  Reserved keywords currently not in use, but still prohibited (OSL -> switch e.g.)
-	 *  'b'  Built-in names (print, for, etc.)
-	 *  'q'  Other text (identifiers, etc.)
+	 *
 	 * It is terminated with a null-terminator '\0' followed by a continuation
-	 * flag indicating whether the line is part of a multi-line string. */
+	 * flag indicating whether the line is part of a multi-line string.
+	 *
+	 * See: FMT_TYPE_ enums below
+	 */
 	void (*format_line)(SpaceText *st, TextLine *line, int do_next);
 
 	const char **ext;  /* NULL terminated extensions */
 } TextFormatType;
 
+enum {
+	FMT_TYPE_WHITESPACE = '_',  /* Whitespace */
+	FMT_TYPE_COMMENT    = '#',  /* Comment text */
+	FMT_TYPE_SYMBOL     = '!',  /* Punctuation and other symbols */
+	FMT_TYPE_NUMERAL    = 'n',  /* Numerals */
+	FMT_TYPE_STRING     = 'l',  /* String letters */
+	FMT_TYPE_DIRECTIVE  = 'd',  /* Decorator / Preprocessor directive */
+	FMT_TYPE_SPECIAL    = 'v',  /* Special variables (class, def) */
+	FMT_TYPE_RESERVED   = 'r',  /* Reserved keywords currently not in use, but still prohibited (OSL -> switch e.g.) */
+	FMT_TYPE_KEYWORD    = 'b',  /* Built-in names (return, for, etc.) */
+	FMT_TYPE_DEFAULT    = 'q',  /* Regular text (identifiers, etc.) */
+};
+
 TextFormatType *ED_text_format_get(Text *text);
 void            ED_text_format_register(TextFormatType *tft);
 

Modified: trunk/blender/source/blender/editors/space_text/text_format_osl.c
===================================================================
--- trunk/blender/source/blender/editors/space_text/text_format_osl.c	2012-12-30 00:47:55 UTC (rev 53417)
+++ trunk/blender/source/blender/editors/space_text/text_format_osl.c	2012-12-30 01:12:21 UTC (rev 53418)
@@ -232,23 +232,23 @@
 		else if (cont) {
 			/* C-Style comments */
 			if (cont & FMT_CONT_COMMENT_CXX) {
-				*fmt = '#';
+				*fmt = FMT_TYPE_COMMENT;
 			}
 			else if (cont & FMT_CONT_COMMENT_C) {
 				if (*str == '*' && *(str + 1) == '/') {
-					*fmt = '#'; fmt++; str++;
-					*fmt = '#';
+					*fmt = FMT_TYPE_COMMENT; fmt++; str++;
+					*fmt = FMT_TYPE_COMMENT;
 					cont = FMT_CONT_NOP;
 				}
 				else {
-					*fmt = '#';
+					*fmt = FMT_TYPE_COMMENT;
 				}
 				/* Handle other comments */
 			}
 			else {
 				find = (cont & FMT_CONT_QUOTEDOUBLE) ? '"' : '\'';
 				if (*str == find) cont = 0;
-				*fmt = 'l';
+				*fmt = FMT_TYPE_STRING;
 			}
 
 			str += BLI_str_utf8_size_safe(str) - 1;
@@ -258,44 +258,46 @@
 			/* Deal with comments first */
 			if (*str == '/' && *(str + 1) == '/') {
 				cont = FMT_CONT_COMMENT_CXX;
-				*fmt = '#';
+				*fmt = FMT_TYPE_COMMENT;
 			}
 			/* C-Style (multi-line) comments */
 			else if (*str == '/' && *(str + 1) == '*') {
 				cont = FMT_CONT_COMMENT_C;
-				*fmt = '#'; fmt++; str++;
-				*fmt = '#';
+				*fmt = FMT_TYPE_COMMENT; fmt++; str++;
+				*fmt = FMT_TYPE_COMMENT;
 			}
 			else if (*str == '"' || *str == '\'') {
 				/* Strings */
 				find = *str;
 				cont = (*str == '"') ? FMT_CONT_QUOTEDOUBLE : FMT_CONT_QUOTESINGLE;
-				*fmt = 'l';
+				*fmt = FMT_TYPE_STRING;
 			}
 			/* Whitespace (all ws. has been converted to spaces) */
 			else if (*str == ' ') {
-				*fmt = '_';
+				*fmt = FMT_TYPE_WHITESPACE;
 			}
 			/* Numbers (digits not part of an identifier and periods followed by digits) */
-			else if ((prev != 'q' && text_check_digit(*str)) || (*str == '.' && text_check_digit(*(str + 1)))) {
-				*fmt = 'n';
+			else if ((prev != FMT_TYPE_DEFAULT && text_check_digit(*str)) ||
+			         (*str == '.' && text_check_digit(*(str + 1))))
+			{
+				*fmt = FMT_TYPE_NUMERAL;
 			}
 			/* Punctuation */
 			else if ((*str != '#') && text_check_delim(*str)) {
-				*fmt = '!';
+				*fmt = FMT_TYPE_SYMBOL;
 			}
 			/* Identifiers and other text (no previous ws. or delims. so text continues) */
-			else if (prev == 'q') {
+			else if (prev == FMT_TYPE_DEFAULT) {
 				str += BLI_str_utf8_size_safe(str) - 1;
-				*fmt = 'q';
+				*fmt = FMT_TYPE_DEFAULT;
 			}
 			/* Not ws, a digit, punct, or continuing text. Must be new, check for special words */
 			else {
 				/* Special vars(v) or built-in keywords(b) */
-				if      ((i = txtfmt_osl_find_specialvar(str))   != -1) prev = 'v';
-				else if ((i = txtfmt_osl_find_builtinfunc(str))  != -1) prev = 'b';
-				else if ((i = txtfmt_osl_find_reserved(str))     != -1) prev = 'r';
-				else if ((i = txtfmt_osl_find_preprocessor(str)) != -1) prev = 'd';
+				if      ((i = txtfmt_osl_find_specialvar(str))   != -1) prev = FMT_TYPE_SPECIAL;
+				else if ((i = txtfmt_osl_find_builtinfunc(str))  != -1) prev = FMT_TYPE_KEYWORD;
+				else if ((i = txtfmt_osl_find_reserved(str))     != -1) prev = FMT_TYPE_RESERVED;
+				else if ((i = txtfmt_osl_find_preprocessor(str)) != -1) prev = FMT_TYPE_DIRECTIVE;
 
 				if (i > 0) {
 					memset(fmt, prev, i);
@@ -303,7 +305,7 @@
 				}
 				else {
 					str += BLI_str_utf8_size_safe(str) - 1;
-					*fmt = 'q';
+					*fmt = FMT_TYPE_DEFAULT;
 				}
 			}
 		}

Modified: trunk/blender/source/blender/editors/space_text/text_format_py.c
===================================================================
--- trunk/blender/source/blender/editors/space_text/text_format_py.c	2012-12-30 00:47:55 UTC (rev 53417)
+++ trunk/blender/source/blender/editors/space_text/text_format_py.c	2012-12-30 01:12:21 UTC (rev 53418)
@@ -204,8 +204,8 @@
 			if (cont & FMT_CONT_TRIPLE) {
 				find = (cont & FMT_CONT_QUOTEDOUBLE) ? '"' : '\'';
 				if (*str == find && *(str + 1) == find && *(str + 2) == find) {
-					*fmt = 'l'; fmt++; str++;
-					*fmt = 'l'; fmt++; str++;
+					*fmt = FMT_TYPE_STRING; fmt++; str++;
+					*fmt = FMT_TYPE_STRING; fmt++; str++;
 					cont = FMT_CONT_NOP;
 				}
 				/* Handle other strings */
@@ -215,14 +215,14 @@
 				if (*str == find) cont = FMT_CONT_NOP;
 			}
 
-			*fmt = 'l';
+			*fmt = FMT_TYPE_STRING;
 			str += BLI_str_utf8_size_safe(str) - 1;
 		}
 		/* Not in a string... */
 		else {
 			/* Deal with comments first */
-			if (prev == '#' || *str == '#') {
-				*fmt = '#';
+			if (prev == FMT_TYPE_COMMENT || *str == '#') {
+				*fmt = FMT_TYPE_COMMENT;
 				str += BLI_str_utf8_size_safe(str) - 1;
 			}
 			else if (*str == '"' || *str == '\'') {
@@ -230,46 +230,48 @@
 				find = *str;
 				cont = (*str == '"') ? FMT_CONT_QUOTEDOUBLE : FMT_CONT_QUOTESINGLE;
 				if (*(str + 1) == find && *(str + 2) == find) {
-					*fmt = 'l'; fmt++; str++;
-					*fmt = 'l'; fmt++; str++;
+					*fmt = FMT_TYPE_STRING; fmt++; str++;
+					*fmt = FMT_TYPE_STRING; fmt++; str++;
 					cont |= FMT_CONT_TRIPLE;
 				}
-				*fmt = 'l';
+				*fmt = FMT_TYPE_STRING;
 			}
 			/* Whitespace (all ws. has been converted to spaces) */
 			else if (*str == ' ') {
-				*fmt = '_';
+				*fmt = FMT_TYPE_WHITESPACE;
 			}
 			/* Numbers (digits not part of an identifier and periods followed by digits) */
-			else if ((prev != 'q' && text_check_digit(*str)) || (*str == '.' && text_check_digit(*(str + 1)))) {
-				*fmt = 'n';
+			else if ((prev != FMT_TYPE_DEFAULT && text_check_digit(*str)) ||
+			         (*str == '.' && text_check_digit(*(str + 1))))
+			{

@@ Diff output truncated at 10240 characters. @@



More information about the Bf-blender-cvs mailing list