~ubuntu-branches/ubuntu/oneiric/geany/oneiric

« back to all changes in this revision

Viewing changes to src/highlighting.c

  • Committer: Bazaar Package Importer
  • Author(s): Jérôme Guelfucci
  • Date: 2009-05-02 23:57:29 UTC
  • mfrom: (1.1.10 upstream)
  • Revision ID: james.westby@ubuntu.com-20090502235729-uxjx39ku9jo1rssn
Tags: 0.17-0ubuntu1
* New upstream release:
  - Many, many bug fixes.
  - Add "Recent Projects" menu to the Project menu.
  - Allow appending the toolbar to the main menu bar.
  - Add 'Send Selection to Terminal' command to the Edit->Format menu.
  - New filetype ActionScript.
  - Updated translations: be, cs, de, es, fi, fr, hu, ja, pt_BR, ru, 
    sv, tr, zh_CN.
* debian/patches:
  - drop 01_fix_ubuntu_bug_147151.dpatch,
    30_dont_leave_around_copies_of_geany_run_script.dpatch,
    50_searchentry_enter.dpatch and
    40_fix_crashes_and_mem_corrup_at_exit.dpatch: integrated in the new
    upstream release.
* debian/copyright: updated

Show diffs side-by-side

added added

removed removed

Lines of Context:
18
18
 *      along with this program; if not, write to the Free Software
19
19
 *      Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
20
20
 *
21
 
 * $Id: highlighting.c 3482 2009-01-18 18:18:38Z eht16 $
 
21
 * $Id: highlighting.c 3708 2009-04-15 22:47:33Z eht16 $
22
22
 */
23
23
 
24
24
/**
58
58
} StyleSet;
59
59
 
60
60
/* each filetype has a styleset except GEANY_FILETYPES_NONE, which uses common_style_set */
61
 
static StyleSet style_sets[GEANY_MAX_BUILT_IN_FILETYPES - 1] = {{0, NULL, NULL, NULL}};
 
61
static StyleSet style_sets[GEANY_MAX_BUILT_IN_FILETYPES] = {{0, NULL, NULL, NULL}};
62
62
 
63
63
 
64
64
enum    /* Geany common styling */
128
128
        }
129
129
 
130
130
        result = g_key_file_get_string(configh, section, key, NULL);
131
 
        if (result == NULL) result = g_key_file_get_string(config, section, key, NULL);
 
131
        if (result == NULL)
 
132
                result = g_key_file_get_string(config, section, key, NULL);
132
133
 
133
134
        if (result == NULL)
134
135
        {
178
179
        gchar **list;
179
180
        gsize len;
180
181
 
181
 
        g_return_if_fail(config && configh && key_name && default_style && style);
 
182
        g_return_if_fail(config);
 
183
        g_return_if_fail(configh);
 
184
        g_return_if_fail(key_name);
 
185
        g_return_if_fail(default_style);
 
186
        g_return_if_fail(style);
182
187
 
183
188
        list = g_key_file_get_string_list(configh, "styling", key_name, &len, NULL);
184
189
        if (list == NULL)
185
190
                list = g_key_file_get_string_list(config, "styling", key_name, &len, NULL);
186
191
 
187
 
        if (list != NULL && list[0] != NULL)
 
192
        if (G_LIKELY(list != NULL) && G_UNLIKELY(list[0] != NULL))
188
193
                style->foreground = (gint) utils_strtod(list[0], NULL, FALSE);
189
194
        else
190
195
                style->foreground = rotate_rgb(default_style->foreground);
191
196
 
192
 
        if (list != NULL && list[1] != NULL)
 
197
        if (G_LIKELY(list != NULL) && G_LIKELY(list[1] != NULL))
193
198
                style->background = (gint) utils_strtod(list[1], NULL, FALSE);
194
199
        else
195
200
                style->background = rotate_rgb(default_style->background);
196
201
 
197
 
        if (list != NULL && list[2] != NULL) style->bold = utils_atob(list[2]);
 
202
        if (G_LIKELY(list != NULL) && G_LIKELY(list[2] != NULL))
 
203
                style->bold = utils_atob(list[2]);
198
204
        else style->bold = default_style->bold;
199
205
 
200
 
        if (list != NULL && list[3] != NULL) style->italic = utils_atob(list[3]);
 
206
        if (G_LIKELY(list != NULL) && list[3] != NULL)
 
207
                style->italic = utils_atob(list[3]);
201
208
        else style->italic = default_style->italic;
202
209
 
203
210
        g_strfreev(list);
212
219
        gchar **list;
213
220
        gsize len;
214
221
 
215
 
        if (config == NULL || configh == NULL || section == NULL) return;
 
222
        g_return_if_fail(config);
 
223
        g_return_if_fail(configh);
 
224
        g_return_if_fail(section);
 
225
        g_return_if_fail(key);
216
226
 
217
227
        list = g_key_file_get_string_list(configh, section, key, &len, NULL);
218
 
        if (list == NULL) list = g_key_file_get_string_list(config, section, key, &len, NULL);
 
228
        if (list == NULL)
 
229
                list = g_key_file_get_string_list(config, section, key, &len, NULL);
219
230
 
220
 
        if (list != NULL && list[0] != NULL)
 
231
        if (G_LIKELY(list != NULL) && G_LIKELY(list[0] != NULL))
221
232
                style->foreground = (gint) utils_strtod(list[0], NULL, FALSE);
222
233
        else if (foreground)
223
234
                style->foreground = (gint) utils_strtod(foreground, NULL, FALSE);
224
235
 
225
 
        if (list != NULL && list[1] != NULL)
 
236
        if (G_LIKELY(list != NULL) && G_LIKELY(list[1] != NULL))
226
237
                style->background = (gint) utils_strtod(list[1], NULL, FALSE);
227
238
        else if (background)
228
239
                style->background = (gint) utils_strtod(background, NULL, FALSE);
229
240
 
230
 
        if (list != NULL && list[2] != NULL) style->bold = utils_atob(list[2]);
231
 
        else style->bold = utils_atob(bold);
 
241
        if (G_LIKELY(list != NULL) && G_LIKELY(list[2] != NULL))
 
242
                style->bold = utils_atob(list[2]);
 
243
        else
 
244
                style->bold = utils_atob(bold);
232
245
 
233
 
        if (list != NULL && list[3] != NULL) style->italic = utils_atob(list[3]);
234
 
        else style->italic = FALSE;
 
246
        if (G_LIKELY(list != NULL) && list[3] != NULL)
 
247
                style->italic = utils_atob(list[3]);
 
248
        else
 
249
                style->italic = FALSE;
235
250
 
236
251
        g_strfreev(list);
237
252
}
245
260
        gchar *end1, *end2;
246
261
        gsize len;
247
262
 
248
 
        if (config == NULL || configh == NULL || section == NULL) return;
 
263
        g_return_if_fail(config);
 
264
        g_return_if_fail(configh);
 
265
        g_return_if_fail(section);
 
266
        g_return_if_fail(key);
249
267
 
250
268
        list = g_key_file_get_string_list(configh, section, key, &len, NULL);
251
 
        if (list == NULL) list = g_key_file_get_string_list(config, section, key, &len, NULL);
 
269
        if (list == NULL)
 
270
                list = g_key_file_get_string_list(config, section, key, &len, NULL);
252
271
 
253
 
        if (list != NULL && list[0] != NULL) style->foreground = strtol(list[0], &end1, 10);
254
 
        else style->foreground = fdefault_val;
255
 
        if (list != NULL && list[1] != NULL) style->background = strtol(list[1], &end2, 10);
256
 
        else style->background = sdefault_val;
 
272
        if (G_LIKELY(list != NULL) && G_LIKELY(list[0] != NULL) )
 
273
                style->foreground = strtol(list[0], &end1, 10);
 
274
        else
 
275
                style->foreground = fdefault_val;
 
276
        if (G_LIKELY(list != NULL) && G_LIKELY(list[1] != NULL) )
 
277
                style->background = strtol(list[1], &end2, 10);
 
278
        else
 
279
                style->background = sdefault_val;
257
280
 
258
281
        /* if there was an error, strtol() returns 0 and end is list[x], so then we use default_val */
259
 
        if (list == NULL || list[0] == end1) style->foreground = fdefault_val;
260
 
        if (list == NULL || list[1] == end2) style->background = sdefault_val;
 
282
        if (G_UNLIKELY(list == NULL) || G_UNLIKELY(list[0] == end1))
 
283
                style->foreground = fdefault_val;
 
284
        if (G_UNLIKELY(list == NULL) || G_UNLIKELY(list[1] == end2))
 
285
                style->background = sdefault_val;
261
286
 
262
287
        g_strfreev(list);
263
288
}
282
307
{
283
308
        g_assert(ft_id < GEANY_MAX_BUILT_IN_FILETYPES);
284
309
 
285
 
        if (ft_id == GEANY_FILETYPES_NONE)
 
310
        if (G_UNLIKELY(ft_id == GEANY_FILETYPES_NONE))
286
311
        {
287
312
                g_assert(styling_index < GCS_MAX);
288
313
                return &common_style_set.styling[styling_index];
312
337
{
313
338
        gint i;
314
339
 
315
 
        for (i = 0; i < GEANY_MAX_BUILT_IN_FILETYPES - 1; i++)
 
340
        for (i = 0; i < GEANY_MAX_BUILT_IN_FILETYPES; i++)
316
341
        {
317
342
                StyleSet *style_ptr;
318
343
                style_ptr = &style_sets[i];
605
630
        GString *s;
606
631
 
607
632
        s = get_global_typenames(lang);
608
 
        if (s == NULL)
 
633
        if (G_UNLIKELY(s == NULL))
609
634
                s = g_string_sized_new(200);
610
635
        else
611
636
                g_string_append_c(s, ' '); /* append a space as delimiter to the existing list of words */
2272
2297
        set_sci_style(sci, SCE_PROPS_KEY, GEANY_FILETYPES_CONF, 3);
2273
2298
        set_sci_style(sci, SCE_PROPS_ASSIGNMENT, GEANY_FILETYPES_CONF, 4);
2274
2299
        set_sci_style(sci, SCE_PROPS_DEFVAL, GEANY_FILETYPES_CONF, 5);
 
2300
 
 
2301
        SSM(sci, SCI_SETPROPERTY, (uptr_t) "lexer.props.allow.initial.spaces", (sptr_t) "0");
2275
2302
}
2276
2303
 
2277
2304
 
3236
3263
        set_sci_style(sci, SCE_B_BINNUMBER, GEANY_FILETYPES_BASIC, 18);
3237
3264
}
3238
3265
 
 
3266
 
 
3267
static void styleset_actionscript_init(gint ft_id, GKeyFile *config, GKeyFile *config_home)
 
3268
{
 
3269
        new_style_array(GEANY_FILETYPES_AS, 20);
 
3270
        styleset_c_like_init(config, config_home, GEANY_FILETYPES_AS);
 
3271
 
 
3272
        style_sets[GEANY_FILETYPES_AS].keywords = g_new(gchar *, 4);
 
3273
 
 
3274
        get_keyfile_keywords(config, config_home, "keywords", "primary", GEANY_FILETYPES_AS, 0, "");
 
3275
        get_keyfile_keywords(config, config_home, "keywords", "secondary", GEANY_FILETYPES_AS, 1, "");
 
3276
        get_keyfile_keywords(config, config_home, "keywords", "classes", GEANY_FILETYPES_AS, 2, "");
 
3277
        style_sets[GEANY_FILETYPES_AS].keywords[3] = NULL;
 
3278
 
 
3279
        get_keyfile_wordchars(config, config_home, &style_sets[GEANY_FILETYPES_AS].wordchars);
 
3280
}
 
3281
 
 
3282
 
 
3283
static void styleset_actionscript(ScintillaObject *sci)
 
3284
{
 
3285
        apply_filetype_properties(sci, SCLEX_CPP, GEANY_FILETYPES_AS);
 
3286
 
 
3287
        SSM(sci, SCI_SETKEYWORDS, 0, (sptr_t) style_sets[GEANY_FILETYPES_AS].keywords[0]);
 
3288
        SSM(sci, SCI_SETKEYWORDS, 1, (sptr_t) style_sets[GEANY_FILETYPES_AS].keywords[2]);
 
3289
        SSM(sci, SCI_SETKEYWORDS, 3, (sptr_t) style_sets[GEANY_FILETYPES_AS].keywords[1]);
 
3290
 
 
3291
        styleset_c_like(sci, GEANY_FILETYPES_AS);
 
3292
}
 
3293
 
 
3294
 
3239
3295
static void styleset_haxe_init(gint ft_id, GKeyFile *config, GKeyFile *config_home)
3240
3296
{
3241
3297
        new_style_array(GEANY_FILETYPES_HAXE, 20);
3366
3422
                init_styleset_case(GEANY_FILETYPES_GLSL,        glsl);
3367
3423
                init_styleset_case(GEANY_FILETYPES_HASKELL,     haskell);
3368
3424
                init_styleset_case(GEANY_FILETYPES_HAXE,        haxe);
 
3425
                init_styleset_case(GEANY_FILETYPES_AS,          actionscript);
3369
3426
                init_styleset_case(GEANY_FILETYPES_HTML,        html);
3370
3427
                init_styleset_case(GEANY_FILETYPES_JAVA,        java);
3371
3428
                init_styleset_case(GEANY_FILETYPES_JS,          js);
3403
3460
        filetypes_load_config(filetype_idx, FALSE);     /* load filetypes.ext */
3404
3461
 
3405
3462
        /* load tags files (some lexers highlight global typenames) */
3406
 
        if (filetype_idx < GEANY_FILETYPES_NONE)
 
3463
        if (filetype_idx != GEANY_FILETYPES_NONE)
3407
3464
                symbols_global_tags_loaded(filetype_idx);
3408
3465
 
3409
3466
        switch (filetype_idx)
3427
3484
                styleset_case(GEANY_FILETYPES_GLSL,             glsl);
3428
3485
                styleset_case(GEANY_FILETYPES_HASKELL,  haskell);
3429
3486
                styleset_case(GEANY_FILETYPES_HAXE,             haxe);
 
3487
                styleset_case(GEANY_FILETYPES_AS,               actionscript);
3430
3488
                styleset_case(GEANY_FILETYPES_HTML,             html);
3431
3489
                styleset_case(GEANY_FILETYPES_JAVA,             java);
3432
3490
                styleset_case(GEANY_FILETYPES_JS,               js);