[PATCH] matchbox-keyboard: Better parse error handling
Paul Sokolovsky <[email protected]> Thu, 20 Jul 2006 02:56:51 +0300
| Newsgroups | gmane.comp.handhelds.gpe |
|---|---|
| Message-ID | <[email protected]> |
Hello Matthew, Per your previous suggestion, I tried matchbox-keyboard (SVN HEAD). Immediate problem I faced is that it doesn't work with keyboard-ru.xml, giving a parse error. I had to add better error output to catch the issue, but I hope it's good addition to matchbox-keyboard. It turned out that keyboard-ru.xml uses non-implemented modifier "layout1". Both patches are attached, ChangeLog entry is: 2006-07-16 Paul Sokolovsky <[email protected]> * src/config-parser.c: Add XML validation error messages, print parsing error in consistent (gcc-like) manner. * layout/keyboard-ru.xml: Remove unsupported (as of yet) modifier 'layout1', so this file may be loaded. Well, after doing all that, I discovered it does have some layout issues, see screenshot at http://handhelds.org/moin/moin.cgi/GPEInternationalisation . So, I guess it makes sense to maintain xkbd yet (at least in the area of layouts, if not code). Ok, hope to do more matchbox-keyboard work still (to start, I have some suggetions regarding support of multiple layouts.) -- Best regards, Paul mailto:[email protected] _______________________________________________ GPE mailing list [email protected] http://handhelds.org/mailman/listinfo/gpe
layout-ru.diff
(application/octet-stream, 474 B)
Index: layouts/keyboard-ru.xml
===================================================================
--- layouts/keyboard-ru.xml (revision 1360)
+++ layouts/keyboard-ru.xml (working copy)
@@ -305,7 +305,7 @@
<default display="äëö" action="modifier:mod1"/>
</key>
<key>
- <default display="EN" action="modifier:layout1"/>
+ <default display="EN" action="modifier:mod2"/>
</key>
<key fill="true">
parse_error_handling.diff
(application/octet-stream, 2.8 KB)
Index: src/config-parser.c
===================================================================
--- src/config-parser.c (revision 1360)
+++ src/config-parser.c (working copy)
@@ -35,10 +35,10 @@
fill="true" // Set width to available space
>
- <defualt
+ <default
display="a"
display="image:"
- action="utf8char" // optional, action defulats to this
+ action="utf8char" // optional, action defaults to this
action="string" // from lookup below
action="modifier:Shift|Alt|ctrl|mod1|mod2|mod3|caps"
action="xkeysym:XK_BLAH"
@@ -124,9 +124,19 @@
MBKeyboardKey *current_key;
Bool error;
char *error_msg;
+ int error_lineno;
+ XML_Parser parser;
}
MBKeyboardConfigState;
+void
+set_error(MBKeyboardConfigState *state, char *msg)
+{
+ state->error = True;
+ state->error_lineno = XML_GetCurrentLineNumber(state->parser);
+ state->error_msg = msg;
+}
+
KeySym
config_str_to_keysym(const char* str)
{
@@ -331,13 +341,13 @@
}
else
{
- state->error = True;
+ set_error(state, "Unknown key subtag");
return;
}
if ((val = attr_get_val("display", attr)) == NULL)
{
- state->error = True;
+ set_error(state, "Attribute 'display' is required");
return;
}
@@ -399,7 +409,7 @@
}
else
{
- state->error = True;
+ set_error(state, "Unknown modifier");
return;
}
@@ -419,7 +429,7 @@
else
{
/* Should this error really be terminal */
- state->error = True;
+ set_error(state, "Unknown keysym");
return;
}
}
@@ -463,7 +473,7 @@
if ((val = attr_get_val("id", attr)) == NULL)
{
- state->error = True;
+ set_error(state, "Attribute 'id' is required");
return;
}
@@ -548,6 +558,8 @@
if (state->error)
{
+ fprintf(stderr, "matchbox-keyboard:%s:%d: %s\n", state->keyboard->config_file,
+ state->error_lineno, state->error_msg);
util_fatal_error("Error parsing\n");
}
}
@@ -577,6 +589,7 @@
state = util_malloc0(sizeof(MBKeyboardConfigState));
state->keyboard = kbd;
+ state->parser = p;
XML_SetElementHandler(p, config_xml_start_cb, NULL);
@@ -586,10 +599,10 @@
if (! XML_Parse(p, data, strlen(data), 1)) {
fprintf(stderr,
- "matchbox-keyboard: XML Parse error at line %d:\n%s\n of %s",
+ "matchbox-keyboard:%s:%d: XML Parse error:%s\n",
+ kbd->config_file,
XML_GetCurrentLineNumber(p),
- XML_ErrorString(XML_GetErrorCode(p)),
- kbd->config_file);
+ XML_ErrorString(XML_GetErrorCode(p)));
util_fatal_error("XML Parse failed.\n");
}