美文网首页我爱编程
在STM32+FATFS上移植ezxml

在STM32+FATFS上移植ezxml

作者: RGW | 来源:发表于2017-03-09 10:36 被阅读209次

ezXML - XML Parsing C Library
version 0.8.5

ezXML is a C library for parsing XML documents inspired by simpleXML for PHP.
As the name implies, it's easy to use. It's ideal for parsing XML configuration
files or REST web service responses. It's also fast and lightweight (less than
20k compiled). The latest verions is available here:
http://prdownloads.sf.net/ezxml/ezxml-0.8.6.tar.gz?download

  • 添加头文件
#include "ff.h"
  • ezxml_parse_fp
    原函数
// Wrapper for ezxml_parse_str() that accepts a file stream. Reads the entire
// stream into memory and then parses it. For xml files, use ezxml_parse_file()
// or ezxml_parse_fd()
ezxml_t ezxml_parse_fp(FILE *fp)
{
    ezxml_root_t root;
    size_t l, len = 0;
    char *s;

    if (! (s = malloc(EZXML_BUFSIZE))) return NULL;
    do {
        len += (l = fread((s + len), 1, EZXML_BUFSIZE, fp));
        if (l == EZXML_BUFSIZE) s = realloc(s, len + EZXML_BUFSIZE);
    } while (s && l == EZXML_BUFSIZE);

    if (! s) return NULL;
    root = (ezxml_root_t)ezxml_parse_str(s, len);
    root->len = -1; // so we know to free s in ezxml_free()
    return &root->xml;
}

移植函数

ezxml_t ezxml_parse_fp(FIL *fp)
{
    ezxml_root_t root;
    size_t l, len = 0;
    char *s;

    if (! (s = malloc(EZXML_BUFSIZE))) return NULL;
    do {
        f_read(fp,(s + len),EZXML_BUFSIZE,&l);
        len += l;
        if (l == EZXML_BUFSIZE) s = realloc(s, len + EZXML_BUFSIZE);
    } while (s && l == EZXML_BUFSIZE);

    if (! s) return NULL;
    root = (ezxml_root_t)ezxml_parse_str(s, len);
    root->len = -1; // so we know to free s in ezxml_free()
    return &root->xml;
}
  • 没有用到ezxml_t ezxml_parse_fd(int fd), 删除之
  • ezxml_parse_file
    原函数
// a wrapper for ezxml_parse_fd that accepts a file name
ezxml_t ezxml_parse_file(const char *file)
{
    int fd = open(file, O_RDONLY, 0);
    ezxml_t xml = ezxml_parse_fd(fd);
    
    if (fd >= 0) close(fd);
    return xml;
}

移植函数

ezxml_t ezxml_parse_file(const char *file)
{
    FIL fp;
    FRESULT res;
    ezxml_t xml;
    res = f_open(&fp, file, FA_READ);

    xml = ezxml_parse_fp(&fp);
    
    if (res == FR_OK) f_close(&fp);
    return xml;
}
  • strdup 实现
#define strdup              ezxml_mem_strdup
/*rgw 2016.11.28*/
char *ezxml_mem_strdup(const char *s)
{
    char *result = (char *)malloc(strlen(s) + 1);
    if (result == NULL)
        return NULL;
    strcpy(result, s);
    return result;
}

相关文章

  • 在STM32+FATFS上移植ezxml

    ezXML - XML Parsing C Libraryversion 0.8.5 ezXML is a C l...

  • LVGL 在安卓上的移植

    LVGL 安卓移植 背景 LVGL(轻量级和通用图形库)是一个免费和开源的图形库,它提供了创建嵌入式GUI所需的绝...

  • AWTK 在腾讯 TOS 上的移植笔记

    AWTK 在腾讯 TOS 上的移植笔记 本文以 STM32f103ze 为例,介绍了 AWTK 在 RTOS 上移...

  • S3C2440移植uboot之支持NANDFLASH操作

      上一节我们移植了uboot,S3C2440移植uboot之支持NORFLASH。这节我们继续移植,支持NAND...

  • SQL学习07 使用函数处理数据

    可移植(portable)所编写的代码可以在多个系统上运行。 为了代码的可移植,许多SQL程序员不赞成使用特定于实...

  • glog for Android

    最近在移植的时候需要将glog移植到Android上运行,在捣鼓了几天2天之后终于搞定,在此分享一下。首选需要感谢...

  • 2020-12-22

    但移植后第22天,肾脏停止了工作。——《当死亡化作生命》 ——母亲鲜活的肾移植在儿子的病体上,却在第22天,停止了...

  • AWTK 在 RT-Thread 上的移植笔记

    AWTK 在 RT-Thread 上的移植笔记 本文以 STM32f103ze 为例,介绍了 AWTK 在 RTO...

  • AVFoundation(五.AVKit)

    AVKit本是Mac OS上的框架,在iOS8时移植到iOS平台上,在iOS上的使用主要是AVPlayerCont...

  • S3C2440移植uboot之支持DM9000

      上一节S3C2440移植uboot之支持NANDFLASH操作移植了uboot 支持了NANDFLASH的操作...

网友评论

    本文标题:在STM32+FATFS上移植ezxml

    本文链接:https://www.haomeiwen.com/subject/jfmopttx.html