Commit 848a3e19 authored by Sven Neumann's avatar Sven Neumann Committed by Sven Neumann

data/tips/gimp-tips.dtd data/tips/gimp-tips.xml.in reverted some of the

2008-03-28  Sven Neumann  <sven@gimp.org>

	* data/tips/gimp-tips.dtd
	* data/tips/gimp-tips.xml.in
	* app/dialogs/tips-parser.[ch]: reverted some of the changes 
from
	yesterday. The simplification went too far and we inadvertently
	lost an important feature.


svn path=/trunk/; revision=25269
parent cdb1dd17
/* GIMP - The GNU Image Manipulation Program
* Copyright (C) 1995 Spencer Kimball and Peter Mattis
*
* tips-parser.c -- Parse the gimp-tips.xml file.
* tips-parser.c - Parse the gimp-tips.xml file.
* Copyright (C) 2002, 2008 Sven Neumann <sven@gimp.org>
*
* This program is free software; you can redistribute it and/or modify
......@@ -38,50 +38,58 @@ typedef enum
TIPS_START,
TIPS_IN_TIPS,
TIPS_IN_TIP,
TIPS_IN_THETIP,
TIPS_IN_UNKNOWN
} TipsParserState;
typedef enum
{
TIPS_LOCALE_NONE,
TIPS_LOCALE_MATCH,
TIPS_LOCALE_MISMATCH
} TipsParserLocaleState;
typedef struct
{
TipsParserState state;
TipsParserState last_known_state;
const gchar *locale;
gboolean locale_match;
gint markup_depth;
gint unknown_depth;
GString *value;
GimpTip *current_tip;
GList *tips;
TipsParserState state;
TipsParserState last_known_state;
const gchar *locale;
TipsParserLocaleState locale_state;
gint markup_depth;
gint unknown_depth;
GString *value;
GimpTip *current_tip;
GList *tips;
} TipsParser;
static void tips_parser_start_element (GMarkupParseContext *context,
const gchar *element_name,
const gchar **attribute_names,
const gchar **attribute_values,
gpointer user_data,
GError **error);
static void tips_parser_end_element (GMarkupParseContext *context,
const gchar *element_name,
gpointer user_data,
GError **error);
static void tips_parser_characters (GMarkupParseContext *context,
const gchar *text,
gsize text_len,
gpointer user_data,
GError **error);
static void tips_parser_start_markup (TipsParser *parser,
const gchar *markup_name);
static void tips_parser_end_markup (TipsParser *parser,
const gchar *markup_name);
static void tips_parser_start_unknown (TipsParser *parser);
static void tips_parser_end_unknown (TipsParser *parser);
static void tips_parser_parse_locale (TipsParser *parser,
const gchar **names,
const gchar **values);
static gboolean tips_parser_set_by_locale (TipsParser *parser,
gchar **dest);
static void tips_parser_start_element (GMarkupParseContext *context,
const gchar *element_name,
const gchar **attribute_names,
const gchar **attribute_values,
gpointer user_data,
GError **error);
static void tips_parser_end_element (GMarkupParseContext *context,
const gchar *element_name,
gpointer user_data,
GError **error);
static void tips_parser_characters (GMarkupParseContext *context,
const gchar *text,
gsize text_len,
gpointer user_data,
GError **error);
static void tips_parser_start_markup (TipsParser *parser,
const gchar *markup_name);
static void tips_parser_end_markup (TipsParser *parser,
const gchar *markup_name);
static void tips_parser_start_unknown (TipsParser *parser);
static void tips_parser_end_unknown (TipsParser *parser);
static void tips_parser_parse_locale (TipsParser *parser,
const gchar **names,
const gchar **values);
static void tips_parser_set_by_locale (TipsParser *parser,
gchar **dest);
static const GMarkupParser markup_parser =
......@@ -208,13 +216,9 @@ tips_parser_start_element (GMarkupParseContext *context,
{
case TIPS_START:
if (strcmp (element_name, "gimp-tips") == 0)
{
parser->state = TIPS_IN_TIPS;
}
parser->state = TIPS_IN_TIPS;
else
{
tips_parser_start_unknown (parser);
}
tips_parser_start_unknown (parser);
break;
case TIPS_IN_TIPS:
......@@ -222,26 +226,29 @@ tips_parser_start_element (GMarkupParseContext *context,
{
parser->state = TIPS_IN_TIP;
parser->current_tip = g_slice_new0 (GimpTip);
tips_parser_parse_locale (parser, attribute_names, attribute_values);
}
else
tips_parser_start_unknown (parser);
break;
case TIPS_IN_TIP:
if (strcmp (element_name, "thetip") == 0)
{
tips_parser_start_unknown (parser);
parser->state = TIPS_IN_THETIP;
tips_parser_parse_locale (parser, attribute_names, attribute_values);
}
else
tips_parser_start_unknown (parser);
break;
case TIPS_IN_TIP:
case TIPS_IN_THETIP:
if (strcmp (element_name, "b" ) == 0 ||
strcmp (element_name, "big") == 0 ||
strcmp (element_name, "tt" ) == 0)
{
tips_parser_start_markup (parser, element_name);
}
tips_parser_start_markup (parser, element_name);
else
{
tips_parser_start_unknown (parser);
}
tips_parser_start_unknown (parser);
break;
case TIPS_IN_UNKNOWN:
tips_parser_start_unknown (parser);
......@@ -268,21 +275,20 @@ tips_parser_end_element (GMarkupParseContext *context,
break;
case TIPS_IN_TIP:
parser->tips = g_list_prepend (parser->tips, parser->current_tip);
parser->current_tip = NULL;
parser->state = TIPS_IN_TIPS;
break;
case TIPS_IN_THETIP:
if (parser->markup_depth == 0)
{
if (tips_parser_set_by_locale (parser, &parser->current_tip->thetip))
{
parser->tips = g_list_prepend (parser->tips, parser->current_tip);
parser->current_tip = NULL;
}
tips_parser_set_by_locale (parser, &parser->current_tip->thetip);
g_string_truncate (parser->value, 0);
parser->state = TIPS_IN_TIPS;
parser->state = TIPS_IN_TIP;
}
else
{
tips_parser_end_markup (parser, element_name);
}
tips_parser_end_markup (parser, element_name);
break;
case TIPS_IN_UNKNOWN:
......@@ -302,8 +308,8 @@ tips_parser_characters (GMarkupParseContext *context,
switch (parser->state)
{
case TIPS_IN_TIP:
if (parser->locale_match)
case TIPS_IN_THETIP:
if (parser->locale_state != TIPS_LOCALE_MISMATCH)
{
gint i;
......@@ -323,7 +329,6 @@ tips_parser_characters (GMarkupParseContext *context,
}
}
break;
default:
break;
}
......@@ -373,16 +378,15 @@ tips_parser_parse_locale (TipsParser *parser,
const gchar **names,
const gchar **values)
{
parser->locale_match = (parser->locale == NULL);
parser->locale_state = TIPS_LOCALE_NONE;
while (*names && *values)
{
if (strcmp (*names, "xml:lang") == 0 && **values)
{
if (parser->locale)
parser->locale_match = (strcmp (*values, parser->locale) == 0);
else
parser->locale_match = FALSE;
parser->locale_state = (parser->locale &&
strcmp (*values, parser->locale) == 0 ?
TIPS_LOCALE_MATCH : TIPS_LOCALE_MISMATCH);
}
names++;
......@@ -390,16 +394,30 @@ tips_parser_parse_locale (TipsParser *parser,
}
}
static gboolean
static void
tips_parser_set_by_locale (TipsParser *parser,
gchar **dest)
{
if (parser->locale_match)
switch (parser->locale_state)
{
case TIPS_LOCALE_NONE:
if (!parser->locale)
{
g_free (*dest);
*dest = g_strdup (parser->value->str);
}
else if (*dest == NULL)
{
*dest = g_strdup (parser->value->str);
}
break;
case TIPS_LOCALE_MATCH:
g_free (*dest);
*dest = g_strdup (parser->value->str);
return TRUE;
}
break;
return FALSE;
case TIPS_LOCALE_MISMATCH:
break;
}
}
/* GIMP - The GNU Image Manipulation Program
* Copyright (C) 1995 Spencer Kimball and Peter Mattis
*
* tips-parser.h -- Parse the gimp-tips.xml file.
* tips-parser.h - Parse the gimp-tips.xml file.
* Copyright (C) 2002, 2008 Sven Neumann <sven@gimp.org>
*
* This program is free software; you can redistribute it and/or modify
......@@ -33,9 +33,6 @@ struct _GimpTip
GimpTip * gimp_tip_new (const gchar *format,
...) G_GNUC_PRINTF(1, 2);
void gimp_tip_set (GimpTip *tip,
const gchar *format,
...) G_GNUC_PRINTF(2, 3);
void gimp_tip_free (GimpTip *tip);
GList * gimp_tips_from_file (const gchar *filename,
......
<!-- Simple DTD for GIMP tips -->
<!ENTITY % markup "(#PCDATA|b|big|tt)*" >
<!ELEMENT gimp-tips (tip+)>
<!ELEMENT gimp-tips (tip+) >
<!ELEMENT tip (thetip+)>
<!ATTLIST tip level (start|beginner|intermediate|advanced) #REQUIRED>
<!ELEMENT tip %markup; >
<!ATTLIST tip level (start|beginner|intermediate|advanced) #REQUIRED
xml:lang CDATA #IMPLIED >
<!ENTITY % markup "(#PCDATA|b|big|tt)*">
<!ELEMENT b %markup; >
<!ELEMENT big %markup; >
<!ELEMENT tt %markup; >
<!ELEMENT b %markup;>
<!ELEMENT big %markup;>
<!ELEMENT tt %markup;>
<!ELEMENT thetip %markup;>
<!ATTLIST thetip xml:lang CDATA #IMPLIED>
This diff is collapsed.
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment