2006-04-29 12:38:28 -07:00
|
|
|
/*
|
2005-10-13 07:08:18 -07:00
|
|
|
* moolang.c
|
|
|
|
*
|
2007-04-07 01:21:52 -07:00
|
|
|
* Copyright (C) 2004-2007 by Yevgen Muntyan <muntyan@math.tamu.edu>
|
2005-10-13 07:08:18 -07:00
|
|
|
*
|
2007-06-24 10:56:20 -07:00
|
|
|
* This library is free software; you can redistribute it and/or
|
|
|
|
* modify it under the terms of the GNU Lesser General Public
|
2007-09-23 09:47:28 -07:00
|
|
|
* License version 2.1 as published by the Free Software Foundation.
|
2005-10-13 07:08:18 -07:00
|
|
|
*
|
|
|
|
* See COPYING file that comes with this distribution.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#define MOOEDIT_COMPILATION
|
2006-11-23 19:18:25 -08:00
|
|
|
#ifdef HAVE_CONFIG_H
|
2006-08-26 02:46:29 -07:00
|
|
|
#include "config.h"
|
2006-11-23 19:18:25 -08:00
|
|
|
#endif
|
2006-08-26 02:46:29 -07:00
|
|
|
#include "mooedit/moolang-private.h"
|
|
|
|
#include "mooutils/mooi18n.h"
|
|
|
|
#include <glib/gstdio.h>
|
|
|
|
#include <sys/stat.h>
|
|
|
|
#include <fcntl.h>
|
|
|
|
#ifdef HAVE_UNISTD_H
|
|
|
|
#include <unistd.h>
|
|
|
|
#endif
|
2005-10-13 07:08:18 -07:00
|
|
|
|
|
|
|
|
2007-06-17 22:17:05 -07:00
|
|
|
GType
|
|
|
|
moo_lang_get_type (void)
|
2005-10-13 07:08:18 -07:00
|
|
|
{
|
2007-06-17 22:17:05 -07:00
|
|
|
static GType type;
|
2005-10-13 07:08:18 -07:00
|
|
|
|
2007-06-17 22:17:05 -07:00
|
|
|
if (G_UNLIKELY (!type))
|
|
|
|
type = GTK_TYPE_SOURCE_LANGUAGE;
|
2005-10-13 07:08:18 -07:00
|
|
|
|
2007-06-17 22:17:05 -07:00
|
|
|
return type;
|
2005-10-13 07:08:18 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2006-08-26 02:46:29 -07:00
|
|
|
GtkSourceEngine *
|
|
|
|
_moo_lang_get_engine (MooLang *lang)
|
2005-10-13 07:08:18 -07:00
|
|
|
{
|
2006-08-26 02:46:29 -07:00
|
|
|
g_return_val_if_fail (MOO_IS_LANG (lang), NULL);
|
|
|
|
return _gtk_source_language_create_engine (GTK_SOURCE_LANGUAGE (lang));
|
2005-10-13 07:08:18 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2006-04-26 21:04:30 -07:00
|
|
|
const char *
|
2006-08-26 02:46:29 -07:00
|
|
|
_moo_lang_id (MooLang *lang)
|
2005-10-13 07:08:18 -07:00
|
|
|
{
|
2006-08-26 02:46:29 -07:00
|
|
|
g_return_val_if_fail (!lang || MOO_IS_LANG (lang), NULL);
|
2005-10-13 07:08:18 -07:00
|
|
|
|
2006-08-26 02:46:29 -07:00
|
|
|
if (lang)
|
|
|
|
return GTK_SOURCE_LANGUAGE(lang)->priv->id;
|
2005-10-13 07:08:18 -07:00
|
|
|
else
|
2006-08-26 02:46:29 -07:00
|
|
|
return MOO_LANG_NONE;
|
2005-10-13 07:08:18 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2006-08-26 02:46:29 -07:00
|
|
|
const char *
|
|
|
|
_moo_lang_display_name (MooLang *lang)
|
2005-10-13 07:08:18 -07:00
|
|
|
{
|
2006-08-26 02:46:29 -07:00
|
|
|
g_return_val_if_fail (!lang || MOO_IS_LANG (lang), NULL);
|
2005-10-13 07:08:18 -07:00
|
|
|
|
2006-08-26 02:46:29 -07:00
|
|
|
if (lang)
|
|
|
|
return GTK_SOURCE_LANGUAGE(lang)->priv->name;
|
|
|
|
else
|
|
|
|
return _(MOO_LANG_NONE_NAME);
|
2005-10-13 07:08:18 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2006-08-26 02:46:29 -07:00
|
|
|
const char *
|
|
|
|
_moo_lang_get_line_comment (MooLang *lang)
|
2005-10-13 07:08:18 -07:00
|
|
|
{
|
2006-08-26 02:46:29 -07:00
|
|
|
g_return_val_if_fail (MOO_IS_LANG (lang), NULL);
|
2006-10-01 23:15:27 -07:00
|
|
|
return g_hash_table_lookup (GTK_SOURCE_LANGUAGE(lang)->priv->properties, "line-comment-start");
|
2005-10-13 07:08:18 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2006-08-26 02:46:29 -07:00
|
|
|
const char *
|
|
|
|
_moo_lang_get_block_comment_start (MooLang *lang)
|
2005-10-13 07:08:18 -07:00
|
|
|
{
|
2006-08-26 02:46:29 -07:00
|
|
|
g_return_val_if_fail (MOO_IS_LANG (lang), NULL);
|
2006-10-01 23:15:27 -07:00
|
|
|
return g_hash_table_lookup (GTK_SOURCE_LANGUAGE(lang)->priv->properties, "block-comment-start");
|
2005-10-13 07:08:18 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2006-08-26 02:46:29 -07:00
|
|
|
const char *
|
|
|
|
_moo_lang_get_block_comment_end (MooLang *lang)
|
2005-10-13 07:08:18 -07:00
|
|
|
{
|
2006-08-26 02:46:29 -07:00
|
|
|
g_return_val_if_fail (MOO_IS_LANG (lang), NULL);
|
2006-10-01 23:15:27 -07:00
|
|
|
return g_hash_table_lookup (GTK_SOURCE_LANGUAGE(lang)->priv->properties, "block-comment-end");
|
2005-10-13 07:08:18 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2006-08-26 02:46:29 -07:00
|
|
|
const char *
|
|
|
|
_moo_lang_get_brackets (MooLang *lang)
|
2005-10-13 07:08:18 -07:00
|
|
|
{
|
2006-08-26 02:46:29 -07:00
|
|
|
g_return_val_if_fail (MOO_IS_LANG (lang), NULL);
|
2006-09-06 19:06:32 -07:00
|
|
|
return NULL;
|
2005-10-13 07:08:18 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2006-08-26 02:46:29 -07:00
|
|
|
const char *
|
|
|
|
_moo_lang_get_section (MooLang *lang)
|
2005-10-13 07:08:18 -07:00
|
|
|
{
|
2006-08-26 02:46:29 -07:00
|
|
|
g_return_val_if_fail (MOO_IS_LANG (lang), NULL);
|
|
|
|
return GTK_SOURCE_LANGUAGE(lang)->priv->section;
|
2005-10-13 07:08:18 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2006-08-26 02:46:29 -07:00
|
|
|
gboolean
|
|
|
|
_moo_lang_get_hidden (MooLang *lang)
|
2005-10-13 07:08:18 -07:00
|
|
|
{
|
2006-08-26 02:46:29 -07:00
|
|
|
g_return_val_if_fail (MOO_IS_LANG (lang), TRUE);
|
|
|
|
return GTK_SOURCE_LANGUAGE(lang)->priv->hidden != 0;
|
2005-10-13 07:08:18 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2006-08-26 02:46:29 -07:00
|
|
|
char *
|
|
|
|
_moo_lang_id_from_name (const char *whatever)
|
2005-10-13 07:08:18 -07:00
|
|
|
{
|
2006-08-26 02:46:29 -07:00
|
|
|
if (!whatever || !g_ascii_strcasecmp (whatever, MOO_LANG_NONE))
|
|
|
|
return g_strdup (MOO_LANG_NONE);
|
2005-10-13 07:08:18 -07:00
|
|
|
else
|
2006-08-26 02:46:29 -07:00
|
|
|
return g_strstrip (g_ascii_strdown (whatever, -1));
|
2005-10-13 07:08:18 -07:00
|
|
|
}
|
2006-11-09 02:59:35 -08:00
|
|
|
|
|
|
|
|
|
|
|
GSList *
|
|
|
|
_moo_lang_get_globs (MooLang *lang)
|
|
|
|
{
|
|
|
|
const char *prop;
|
|
|
|
g_return_val_if_fail (MOO_IS_LANG (lang), NULL);
|
2007-04-27 19:19:36 -07:00
|
|
|
prop = gtk_source_language_get_metadata (GTK_SOURCE_LANGUAGE (lang), "globs");
|
2006-11-09 02:59:35 -08:00
|
|
|
return _moo_lang_parse_string_list (prop);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
GSList *
|
|
|
|
_moo_lang_get_mime_types (MooLang *lang)
|
|
|
|
{
|
|
|
|
const char *prop;
|
|
|
|
g_return_val_if_fail (MOO_IS_LANG (lang), NULL);
|
2007-04-27 19:19:36 -07:00
|
|
|
prop = gtk_source_language_get_metadata (GTK_SOURCE_LANGUAGE (lang), "mimetypes");
|
2006-11-09 02:59:35 -08:00
|
|
|
return _moo_lang_parse_string_list (prop);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
GSList *
|
|
|
|
_moo_lang_parse_string_list (const char *string)
|
|
|
|
{
|
|
|
|
char *copy;
|
|
|
|
GSList *list = NULL;
|
|
|
|
char **pieces, **p;
|
|
|
|
|
|
|
|
if (!string || !string[0])
|
|
|
|
return NULL;
|
|
|
|
|
|
|
|
copy = g_strstrip (g_strdup (string));
|
|
|
|
|
|
|
|
pieces = g_strsplit_set (copy, ",;", 0);
|
|
|
|
g_return_val_if_fail (pieces != NULL, NULL);
|
|
|
|
|
|
|
|
for (p = pieces; *p; p++)
|
|
|
|
if (**p)
|
|
|
|
list = g_slist_prepend (list, g_strdup (*p));
|
|
|
|
|
|
|
|
g_strfreev (pieces);
|
|
|
|
g_free (copy);
|
|
|
|
|
|
|
|
return g_slist_reverse (list);
|
|
|
|
}
|