int
main (int argc, char** argv)
{
xml_g_set_prgname(argv[0]);
if (argc < 3)
{
g_printerr ("> %s filename xpath [options]\n"
"\t print the text enclosed by the xpath node given\n"
"\t as the argument (abbreviated forms)\n"
"\t option: -text (enclose in <text> markups)\n",
g_get_prgname());
return 1;
} |
___ gchar *filename = 0;
const gchar *xpath = 0, *styleflag = "";
{ int i ; for (i=1; i < argc ; i++) {
if (argv[i][0] == '-') { styleflag = argv[i]; continue; } |
if (! filename) { filename = argv[i]; continue; } |
if (! xpath) { xpath = argv[i]; continue; } |
g_warning ("extra argument on commandline, ignored: %s", argv[i]);
} | } |
___ xml_GNode* tree; GError* error = 0;
tree = xml_g_markup_parse_file (0, filename, &error);
if (error)
xml_g_show_error (&error, "after parsing file:\n\t'%s'", filename);
___ xml_GNode* node = xml_path_node (tree, xpath);
if (! node)
g_error ("node not found: %s\n", xpath);
___ int style = 0;
if (strstr (styleflag, "-text")) style = 1;
if (node->text)
{
if (style) write (STDOUT_FILENO, "<text>", 6);
write (STDOUT_FILENO,
node->text->str + node->off, node->end - node->off);
if (style) write (STDOUT_FILENO, "</text>\n", 7);
} | else if (node->name[0] == '<')
{
write (STDOUT_FILENO, node->name, strlen(node->name));
} | else{
g_printerr ("node has no text associated\n");
return 2;
} |
return 0;
____;____;____;____;
} |
|