SF.net SVN: geany:[2902] trunk
ntrel at users.sourceforge.net
ntrel at xxxxx
Tue Aug 26 09:48:19 UTC 2008
Revision: 2902
http://geany.svn.sourceforge.net/geany/?rev=2902&view=rev
Author: ntrel
Date: 2008-08-26 09:48:18 +0000 (Tue, 26 Aug 2008)
Log Message:
-----------
Add assert statements to check that the StyleSet styling arrays are
not exceeded.
(Also make highlighting_get_style() work with all filetypes, but
probably we should remove this from the API; plugins could just use
the SCI_STYLEGET* functions instead).
Modified Paths:
--------------
trunk/ChangeLog
trunk/src/highlighting.c
Modified: trunk/ChangeLog
===================================================================
--- trunk/ChangeLog 2008-08-25 15:44:51 UTC (rev 2901)
+++ trunk/ChangeLog 2008-08-26 09:48:18 UTC (rev 2902)
@@ -1,3 +1,13 @@
+2008-08-26 Nick Treleaven <nick(dot)treleaven(at)btinternet(dot)com>
+
+ * src/highlighting.c:
+ Add assert statements to check that the StyleSet styling arrays are
+ not exceeded.
+ (Also make highlighting_get_style() work with all filetypes, but
+ probably we should remove this from the API; plugins could just use
+ the SCI_STYLEGET* functions instead).
+
+
2008-08-25 Nick Treleaven <nick(dot)treleaven(at)btinternet(dot)com>
* src/document.c, src/editor.c, src/editor.h:
Modified: trunk/src/highlighting.c
===================================================================
--- trunk/src/highlighting.c 2008-08-25 15:44:51 UTC (rev 2901)
+++ trunk/src/highlighting.c 2008-08-26 09:48:18 UTC (rev 2902)
@@ -46,13 +46,14 @@
typedef struct
{
- HighlightingStyle *styling; /* array of styles, NULL if not used or uninitialised */
+ gsize count; /* number of styles */
+ HighlightingStyle *styling; /* array of styles, NULL if not used or uninitialised */
gchar **keywords;
- gchar *wordchars; /* NULL used for style sets with no styles */
+ gchar *wordchars; /* NULL used for style sets with no styles */
} StyleSet;
-/* each filetype has a styleset except GEANY_FILETYPE_ALL */
-static StyleSet style_sets[GEANY_MAX_BUILT_IN_FILETYPES - 1] = {{NULL, NULL, NULL}};
+/* each filetype has a styleset except GEANY_FILETYPES_NONE, which uses common_style_set */
+static StyleSet style_sets[GEANY_MAX_BUILT_IN_FILETYPES - 1] = {{0, NULL, NULL, NULL}};
enum /* Geany common styling */
@@ -103,7 +104,10 @@
static void new_style_array(gint file_type_id, gint styling_count)
{
- style_sets[file_type_id].styling = g_new0(HighlightingStyle, styling_count);
+ StyleSet *set = &style_sets[file_type_id];
+
+ set->count = styling_count;
+ set->styling = g_new0(HighlightingStyle, styling_count);
}
@@ -269,15 +273,29 @@
}
-static void set_sci_style(ScintillaObject *sci, gint style, gint ft, gint styling_index)
+static HighlightingStyle *get_style(guint ft_id, guint styling_index)
{
- HighlightingStyle *style_ptr;
+ g_assert(ft_id < GEANY_MAX_BUILT_IN_FILETYPES);
- if (ft == GEANY_FILETYPES_NONE)
- style_ptr = &common_style_set.styling[styling_index];
+ if (ft_id == GEANY_FILETYPES_NONE)
+ {
+ g_assert(styling_index < GCS_MAX);
+ return &common_style_set.styling[styling_index];
+ }
else
- style_ptr = &style_sets[ft].styling[styling_index];
+ {
+ StyleSet *set = &style_sets[ft_id];
+ g_assert(styling_index < set->count);
+ return &set->styling[styling_index];
+ }
+}
+
+
+static void set_sci_style(ScintillaObject *sci, gint style, guint ft_id, guint styling_index)
+{
+ HighlightingStyle *style_ptr = get_style(ft_id, styling_index);
+
SSM(sci, SCI_STYLESETFORE, style, invert(style_ptr->foreground));
SSM(sci, SCI_STYLESETBACK, style, invert(style_ptr->background));
SSM(sci, SCI_STYLESETBOLD, style, style_ptr->bold);
@@ -294,6 +312,7 @@
StyleSet *style_ptr;
style_ptr = &style_sets[i];
+ style_ptr->count = 0;
g_free(style_ptr->styling);
g_strfreev(style_ptr->keywords);
g_free(style_ptr->wordchars);
@@ -3046,10 +3065,10 @@
if (ft_id < 0 || ft_id > GEANY_MAX_BUILT_IN_FILETYPES)
return NULL;
- if (style_sets[ft_id].styling == NULL)
- filetypes_load_config(ft_id, FALSE);
+ /* ensure filetype loaded */
+ filetypes_load_config(ft_id, FALSE);
- /** TODO style_id might not be the real array index (Scintilla styles are not always synced
- * with array indices) */
- return (const HighlightingStyle*) &style_sets[ft_id].styling[style_id];
+ /* TODO: style_id might not be the real array index (Scintilla styles are not always synced
+ * with array indices) */
+ return get_style(ft_id, style_id);
}
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
More information about the Commits
mailing list