/* * moolang.c * * Copyright (C) 2004-2006 by Yevgen Muntyan * * 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. * * See COPYING file that comes with this distribution. */ #define MOOEDIT_COMPILATION #include "config.h" #include "mooedit/moolang-private.h" #include "mooutils/mooi18n.h" #include "gtksourceview/gtksourcelanguage-private.h" #include #include #include #include #ifdef HAVE_UNISTD_H #include #endif struct _MooLangPrivate { char *version; /* not NULL; "" by default */ char *author; /* not NULL; "" by default */ char *brackets; char *line_comment; char *block_comment_start; char *block_comment_end; guint hidden : 1; }; G_DEFINE_TYPE (MooLang, moo_lang, GTK_TYPE_SOURCE_LANGUAGE) static void moo_lang_init (MooLang *lang) { lang->priv = G_TYPE_INSTANCE_GET_PRIVATE (lang, MOO_TYPE_LANG, MooLangPrivate); lang->priv->version = g_strdup (""); lang->priv->author = g_strdup (""); } static void moo_lang_finalize (GObject *object) { MooLang *lang = MOO_LANG (object); g_free (lang->priv->version); g_free (lang->priv->author); g_free (lang->priv->brackets); g_free (lang->priv->line_comment); g_free (lang->priv->block_comment_start); g_free (lang->priv->block_comment_end); G_OBJECT_CLASS (moo_lang_parent_class)->finalize (object); } static void moo_lang_class_init (MooLangClass *klass) { G_OBJECT_CLASS (klass)->finalize = moo_lang_finalize; g_type_class_add_private (klass, sizeof (MooLangPrivate)); } GtkSourceEngine * _moo_lang_get_engine (MooLang *lang) { g_return_val_if_fail (MOO_IS_LANG (lang), NULL); return _gtk_source_language_create_engine (GTK_SOURCE_LANGUAGE (lang)); } MooLangMgr * _moo_lang_get_mgr (MooLang *lang) { g_return_val_if_fail (MOO_IS_LANG (lang), NULL); return MOO_LANG_MGR (_gtk_source_language_get_languages_manager (GTK_SOURCE_LANGUAGE (lang))); } void _moo_lang_parse_file (MooLang *lang) { GtkSourceLanguage *slang; xmlTextReaderPtr reader; int ret; int fd; g_return_if_fail (MOO_IS_LANG (lang)); slang = GTK_SOURCE_LANGUAGE (lang); g_return_if_fail (slang->priv->lang_file_name != NULL); fd = g_open (slang->priv->lang_file_name, O_RDONLY, 0); g_return_if_fail (fd != -1); reader = xmlReaderForFd (fd, slang->priv->lang_file_name, NULL, 0); if (!reader) { g_critical ("%s: oops", G_STRLOC); close (fd); return; } ret = xmlTextReaderRead (reader); while (ret == 1) { if (xmlTextReaderNodeType (reader) == XML_READER_TYPE_ELEMENT) { xmlChar *name = xmlTextReaderName (reader); if (xmlStrcmp (name, BAD_CAST "language") == 0) { // read_language_node (lang, reader, slang->priv->lang_file_name); ret = 0; } xmlFree (name); } if (ret == 1) ret = xmlTextReaderRead (reader); } xmlFreeTextReader (reader); close (fd); } const char * _moo_lang_id (MooLang *lang) { g_return_val_if_fail (!lang || MOO_IS_LANG (lang), NULL); if (lang) return GTK_SOURCE_LANGUAGE(lang)->priv->id; else return MOO_LANG_NONE; } const char * _moo_lang_display_name (MooLang *lang) { g_return_val_if_fail (!lang || MOO_IS_LANG (lang), NULL); if (lang) return GTK_SOURCE_LANGUAGE(lang)->priv->name; else return _(MOO_LANG_NONE_NAME); } const char * _moo_lang_get_line_comment (MooLang *lang) { g_return_val_if_fail (MOO_IS_LANG (lang), NULL); return GTK_SOURCE_LANGUAGE(lang)->priv->line_comment; } const char * _moo_lang_get_block_comment_start (MooLang *lang) { g_return_val_if_fail (MOO_IS_LANG (lang), NULL); return GTK_SOURCE_LANGUAGE(lang)->priv->block_comment_start; } const char * _moo_lang_get_block_comment_end (MooLang *lang) { g_return_val_if_fail (MOO_IS_LANG (lang), NULL); return GTK_SOURCE_LANGUAGE(lang)->priv->block_comment_end; } const char * _moo_lang_get_brackets (MooLang *lang) { g_return_val_if_fail (MOO_IS_LANG (lang), NULL); return GTK_SOURCE_LANGUAGE(lang)->priv->brackets; } const char * _moo_lang_get_section (MooLang *lang) { g_return_val_if_fail (MOO_IS_LANG (lang), NULL); return GTK_SOURCE_LANGUAGE(lang)->priv->section; } gboolean _moo_lang_get_hidden (MooLang *lang) { g_return_val_if_fail (MOO_IS_LANG (lang), TRUE); return GTK_SOURCE_LANGUAGE(lang)->priv->hidden != 0; } char * _moo_lang_id_from_name (const char *whatever) { if (!whatever || !g_ascii_strcasecmp (whatever, MOO_LANG_NONE)) return g_strdup (MOO_LANG_NONE); else return g_strstrip (g_ascii_strdown (whatever, -1)); }