本文整理汇总了C++中FileParser::func方法的典型用法代码示例。如果您正苦于以下问题:C++ FileParser::func方法的具体用法?C++ FileParser::func怎么用?C++ FileParser::func使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类FileParser
的用法示例。
在下文中一共展示了FileParser::func方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: if
/**
* Process a file, checking if it should be listed and retrieving its data in
* XML format.
*/
xmlNodePtr
file_proc(const gchar *real_path,
const gchar *file_name)
{
gchar *file_name_utf8;
const gchar *file_extension;
FileParser *parser;
xmlNodePtr file_node = NULL;
/* get UTF-8 encoded filename and extension */
file_name_utf8 = g_filename_to_utf8(file_name, -1, NULL, NULL, NULL);
file_extension = filename_get_extension(file_name_utf8);
/* check if we support this file */
if (file_extension == NULL || file_extension[0] == '\0') {
/* extension-less file, we just ignore */
}
else if ((parser = file_parser_get_by_extension(file_extension)) != NULL) {
/* we have a parser for this file -- good -- go ahead */
FILE *fp;
/* create file node */
file_node = xmlNewNode(NULL, "file");
xmlNewProp(file_node, "name", file_name_utf8);
if ((fp = fopen(real_path, "rb")) != NULL) {
glong file_size;
gchar size_string[64];
/* retrieve file size */
/* @TODO support 64-bit file sizes */
fseek(fp, 0, SEEK_END);
file_size = ftell(fp);
g_snprintf(size_string, sizeof size_string, "%ld", file_size);
xmlNewProp(file_node, "size", size_string);
/* parse (or at least try to) the file */
rewind(fp);
parser->func(file_node, fp);
}
else { /* fopen() returned NULL */
xmlNodePtr comment = xmlNewComment("error opening file");
xmlAddChild(file_node, comment);
g_warning("%s: %s", real_path, g_strerror(errno));
}
}
g_free(file_name_utf8); /* free UTF-8 converted filename */
return file_node;
}