mirror of
https://github.com/radareorg/radare2.git
synced 2025-01-31 10:22:37 +00:00
shlr/yxml -> libr/util/rxml - fork the abandoned yxml parser and expose it ##util
This commit is contained in:
parent
9e13e11c4f
commit
62fdc0f0ff
@ -96,7 +96,6 @@ include ../../shlr/bochs/deps.mk
|
||||
include ../../shlr/grub/deps.mk
|
||||
include ../../shlr/qnx/deps.mk
|
||||
include ../../shlr/ar/deps.mk
|
||||
include ../../shlr/yxml/deps.mk
|
||||
include ../../shlr/sdb.mk
|
||||
|
||||
LDFLAGS+=$(LINK)
|
||||
|
@ -85,7 +85,6 @@ should be copied to `./plugins.cfg` before calling `./configure-plugins` to take
|
||||
* shlr/sdb: MIT
|
||||
* shlr/qnx: GPL (will be moved to extras soon)
|
||||
* shlr/grub: GPL (used by some fs plugins)
|
||||
* shlr/yxml: BSD
|
||||
* shlr/lz4: simplified BSD license
|
||||
* shlr/mpc: BSD3
|
||||
|
||||
|
@ -114,7 +114,6 @@ libr.${EXT_AR}: .libr2
|
||||
ifeq (1,$(WITH_GPL))
|
||||
E+=../shlr/grub/libgrubfs.${EXT_AR}
|
||||
endif
|
||||
E+=../shlr/yxml/libyxml.${EXT_AR}
|
||||
E+=../shlr/ar/libr_ar.${EXT_AR}
|
||||
E+=../shlr/winkd/libr_winkd.${EXT_AR}
|
||||
E+=../shlr/qnx/lib/libqnxr.${EXT_AR}
|
||||
|
@ -1,13 +1,10 @@
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <r_util.h>
|
||||
#include <r_util/r_xml.h>
|
||||
#include <r_list.h>
|
||||
|
||||
#include "yxml.h"
|
||||
#include "r_cf_dict.h"
|
||||
|
||||
#define XMLBUFSIZE 4096
|
||||
|
||||
typedef enum {
|
||||
R_CF_STATE_ROOT,
|
||||
R_CF_STATE_IN_DICT,
|
||||
@ -64,16 +61,10 @@ static void r_cf_value_free(RCFValue *value);
|
||||
|
||||
RCFValueDict *r_cf_value_dict_parse (RBuffer *file_buf, ut64 offset, ut64 size, int options) {
|
||||
RCFValueDict *result = NULL;
|
||||
yxml_t x;
|
||||
int i, depth = 0;
|
||||
char *content = NULL;
|
||||
|
||||
void *xml_buf = malloc (XMLBUFSIZE);
|
||||
if (!xml_buf) {
|
||||
return NULL;
|
||||
}
|
||||
|
||||
yxml_init (&x, xml_buf, XMLBUFSIZE);
|
||||
RXml *x = r_xml_new (4096);
|
||||
|
||||
RList *stack = r_list_newf ((RListFree)&r_cf_parse_state_free);
|
||||
if (!stack) {
|
||||
@ -89,48 +80,48 @@ RCFValueDict *r_cf_value_dict_parse (RBuffer *file_buf, ut64 offset, ut64 size,
|
||||
break;
|
||||
}
|
||||
|
||||
yxml_ret_t r = yxml_parse (&x, doc);
|
||||
RXmlRet r = r_xml_parse (x, doc);
|
||||
if (r < 0) {
|
||||
R_LOG_ERROR ("Parse at :%" PRIu32 ":%" PRIu64 " byte offset %" PRIu64, x.line, x.byte, x.total);
|
||||
R_LOG_ERROR ("Parse at :%08" PFMT64d ":%" PFMT64d " byte offset %" PFMT64d, x->line, x->byte, x->total);
|
||||
goto beach;
|
||||
}
|
||||
|
||||
switch (r) {
|
||||
case YXML_ELEMSTART: {
|
||||
case R_XML_ELEMSTART: {
|
||||
RCFParseState *state = (RCFParseState *)r_list_get_top (stack);
|
||||
RCFParseState *next_state = NULL;
|
||||
|
||||
if (!strcmp (x.elem, "dict")) {
|
||||
if (!strcmp (x->elem, "dict")) {
|
||||
next_state = r_cf_parse_state_new (R_CF_STATE_IN_DICT);
|
||||
if (!next_state) {
|
||||
goto beach;
|
||||
}
|
||||
next_state->dict = r_cf_value_dict_new ();
|
||||
} else if (!strcmp (x.elem, "array")) {
|
||||
} else if (!strcmp (x->elem, "array")) {
|
||||
next_state = r_cf_parse_state_new (R_CF_STATE_IN_ARRAY);
|
||||
if (!next_state) {
|
||||
goto beach;
|
||||
}
|
||||
next_state->array = r_cf_value_array_new ();
|
||||
} else if (!strcmp (x.elem, "key") && state->phase == R_CF_STATE_IN_DICT) {
|
||||
} else if (!strcmp (x->elem, "key") && state->phase == R_CF_STATE_IN_DICT) {
|
||||
next_state = r_cf_parse_state_new (R_CF_STATE_IN_KEY);
|
||||
if (!next_state) {
|
||||
goto beach;
|
||||
}
|
||||
next_state->dict = state->dict;
|
||||
} else if (!strcmp (x.elem, "string")) {
|
||||
} else if (!strcmp (x->elem, "string")) {
|
||||
next_state = r_cf_parse_state_new (R_CF_STATE_IN_SCALAR);
|
||||
if (!next_state) {
|
||||
goto beach;
|
||||
}
|
||||
next_state->value_type = R_CF_STRING;
|
||||
} else if (!strcmp (x.elem, "integer")) {
|
||||
} else if (!strcmp (x->elem, "integer")) {
|
||||
next_state = r_cf_parse_state_new (R_CF_STATE_IN_SCALAR);
|
||||
if (!next_state) {
|
||||
goto beach;
|
||||
}
|
||||
next_state->value_type = R_CF_INTEGER;
|
||||
} else if (!strcmp (x.elem, "data")) {
|
||||
} else if (!strcmp (x->elem, "data")) {
|
||||
if (options & R_CF_OPTION_SKIP_NSDATA) {
|
||||
next_state = r_cf_parse_state_new (R_CF_STATE_IN_IGNORE);
|
||||
} else {
|
||||
@ -140,13 +131,13 @@ RCFValueDict *r_cf_value_dict_parse (RBuffer *file_buf, ut64 offset, ut64 size,
|
||||
}
|
||||
next_state->value_type = R_CF_DATA;
|
||||
}
|
||||
} else if (!strcmp (x.elem, "true")) {
|
||||
} else if (!strcmp (x->elem, "true")) {
|
||||
next_state = r_cf_parse_state_new (R_CF_STATE_IN_SCALAR);
|
||||
if (!next_state) {
|
||||
goto beach;
|
||||
}
|
||||
next_state->value_type = R_CF_TRUE;
|
||||
} else if (!strcmp (x.elem, "false")) {
|
||||
} else if (!strcmp (x->elem, "false")) {
|
||||
next_state = r_cf_parse_state_new (R_CF_STATE_IN_SCALAR);
|
||||
if (!next_state) {
|
||||
goto beach;
|
||||
@ -157,14 +148,14 @@ RCFValueDict *r_cf_value_dict_parse (RBuffer *file_buf, ut64 offset, ut64 size,
|
||||
if (next_state) {
|
||||
r_list_push (stack, next_state);
|
||||
} else {
|
||||
eprintf ("Missing next state for elem: %s phase: %d\n", x.elem, state->phase);
|
||||
eprintf ("Missing next state for elem: %s phase: %d\n", x->elem, state->phase);
|
||||
break;
|
||||
}
|
||||
depth++;
|
||||
|
||||
break;
|
||||
}
|
||||
case YXML_ELEMEND: {
|
||||
case R_XML_ELEMEND: {
|
||||
RCFParseState *state = (RCFParseState *)r_list_pop (stack);
|
||||
RCFParseState *next_state = (RCFParseState *)r_list_get_top (stack);
|
||||
if (!state || !next_state) {
|
||||
@ -256,16 +247,12 @@ RCFValueDict *r_cf_value_dict_parse (RBuffer *file_buf, ut64 offset, ut64 size,
|
||||
r_cf_parse_state_free (state);
|
||||
break;
|
||||
}
|
||||
case YXML_CONTENT: {
|
||||
case R_XML_CONTENT: {
|
||||
RCFParseState *state = (RCFParseState *)r_list_get_top (stack);
|
||||
if (state->phase == R_CF_STATE_IN_IGNORE) {
|
||||
break;
|
||||
}
|
||||
if (!content) {
|
||||
content = r_str_new (x.data);
|
||||
} else {
|
||||
content = r_str_append (content, x.data);
|
||||
}
|
||||
content = r_str_append (content, x->data);
|
||||
break;
|
||||
}
|
||||
default:
|
||||
@ -277,16 +264,14 @@ RCFValueDict *r_cf_value_dict_parse (RBuffer *file_buf, ut64 offset, ut64 size,
|
||||
}
|
||||
}
|
||||
|
||||
yxml_ret_t r = yxml_eof (&x);
|
||||
RXmlRet r = r_xml_eof (x);
|
||||
if (r < 0) {
|
||||
eprintf ("Invalid xml\n");
|
||||
}
|
||||
|
||||
beach:
|
||||
R_FREE (xml_buf);
|
||||
if (stack) {
|
||||
r_list_free (stack);
|
||||
}
|
||||
r_xml_free (x);
|
||||
r_list_free (stack);
|
||||
free (content);
|
||||
|
||||
return result;
|
||||
|
@ -146,7 +146,7 @@ r_bin_sources = [
|
||||
|
||||
r_bin_sources += r_bin_d_sources
|
||||
|
||||
r_bin_inc = [platform_inc, yxml_inc, include_directories('mangling', 'format')]
|
||||
r_bin_inc = [platform_inc, include_directories('mangling', 'format')]
|
||||
|
||||
r_bin = library('r_bin', r_bin_sources,
|
||||
include_directories: r_bin_inc,
|
||||
@ -161,8 +161,7 @@ r_bin = library('r_bin', r_bin_sources,
|
||||
r_socket_dep,
|
||||
r_syscall_dep,
|
||||
java_dep,
|
||||
lz4_dep,
|
||||
yxml_dep
|
||||
lz4_dep
|
||||
],
|
||||
install: true,
|
||||
implicit_include_directories: false,
|
||||
@ -187,8 +186,7 @@ r_bin_static = static_library('r_bin_static', r_bin_sources,
|
||||
r_socket_static_dep,
|
||||
r_syscall_static_dep,
|
||||
java_static_dep,
|
||||
lz4_dep,
|
||||
yxml_dep
|
||||
lz4_dep
|
||||
],
|
||||
install: true,
|
||||
implicit_include_directories: false,
|
||||
|
@ -1,9 +1,6 @@
|
||||
OBJ_XNU_KERNELCACHE=bin_xnu_kernelcache.o
|
||||
OBJ_XNU_KERNELCACHE+=../format/xnu/r_cf_dict.o
|
||||
|
||||
LINK+=$(STOP)/yxml/libyxml.$(EXT_AR)
|
||||
CFLAGS+=-I$(STOP)/yxml/
|
||||
|
||||
STATIC_OBJ+=${OBJ_XNU_KERNELCACHE}
|
||||
TARGET_XNU_KERNELCACHE=bin_xnu_kernelcache.${EXT_SO}
|
||||
|
||||
|
225
libr/include/r_util/r_xml.h
Normal file
225
libr/include/r_util/r_xml.h
Normal file
@ -0,0 +1,225 @@
|
||||
/* Copyright (c) 2013-2014 Yoran Heling
|
||||
// Copyright (c) 2022 - pancake
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining
|
||||
a copy of this software and associated documentation files (the
|
||||
"Software"), to deal in the Software without restriction, including
|
||||
without limitation the rights to use, copy, modify, merge, publish,
|
||||
distribute, sublicense, and/or sell copies of the Software, and to
|
||||
permit persons to whom the Software is furnished to do so, subject to
|
||||
the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be included
|
||||
in all copies or substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
||||
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
||||
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
|
||||
IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
|
||||
CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
|
||||
TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
|
||||
SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
||||
*/
|
||||
|
||||
#ifndef R_XML_H
|
||||
#define R_XML_H
|
||||
|
||||
#include <r_types.h>
|
||||
#include <r_util/r_assert.h>
|
||||
|
||||
/* Full API documentation for this library can be found in the "r_xml.md" file
|
||||
* in the r_xml git repository, or online at http://dev.yorhel.nl/r_xml/man */
|
||||
|
||||
typedef enum {
|
||||
R_XML_EEOF = -5, /* Unexpected EOF */
|
||||
R_XML_EREF = -4, /* Invalid character or entity reference (&whatever;) */
|
||||
R_XML_ECLOSE = -3, /* Close tag does not match open tag (<Tag> .. </OtherTag>) */
|
||||
R_XML_ESTACK = -2, /* Stack overflow (too deeply nested tags or too long element/attribute name) */
|
||||
R_XML_ESYN = -1, /* Syntax error (unexpected byte) */
|
||||
R_XML_OK = 0, /* Character consumed, no new token present */
|
||||
R_XML_ELEMSTART = 1, /* Start of an element: '<Tag ..' */
|
||||
R_XML_CONTENT = 2, /* Element content */
|
||||
R_XML_ELEMEND = 3, /* End of an element: '.. />' or '</Tag>' */
|
||||
R_XML_ATTRSTART = 4, /* Attribute: 'Name=..' */
|
||||
R_XML_ATTRVAL = 5, /* Attribute value */
|
||||
R_XML_ATTREND = 6, /* End of attribute '.."' */
|
||||
R_XML_PISTART = 7, /* Start of a processing instruction */
|
||||
R_XML_PICONTENT = 8, /* Content of a PI */
|
||||
R_XML_PIEND = 9 /* End of a processing instruction */
|
||||
} RXmlRet;
|
||||
|
||||
/* When, exactly, are tokens returned?
|
||||
*
|
||||
* <TagName
|
||||
* '>' ELEMSTART
|
||||
* '/' ELEMSTART, '>' ELEMEND
|
||||
* ' ' ELEMSTART
|
||||
* '>'
|
||||
* '/', '>' ELEMEND
|
||||
* Attr
|
||||
* '=' ATTRSTART
|
||||
* "X ATTRVAL
|
||||
* 'Y' ATTRVAL
|
||||
* 'Z' ATTRVAL
|
||||
* '"' ATTREND
|
||||
* '>'
|
||||
* '/', '>' ELEMEND
|
||||
*
|
||||
* </TagName
|
||||
* '>' ELEMEND
|
||||
*/
|
||||
|
||||
typedef enum r_xml_state_t {
|
||||
R_XML_STATE_STRING,
|
||||
R_XML_STATE_ATTR0,
|
||||
R_XML_STATE_ATTR1,
|
||||
R_XML_STATE_ATTR2,
|
||||
R_XML_STATE_ATTR3,
|
||||
R_XML_STATE_ATTR4,
|
||||
R_XML_STATE_CD0,
|
||||
R_XML_STATE_CD1,
|
||||
R_XML_STATE_CD2,
|
||||
R_XML_STATE_COMMENT0,
|
||||
R_XML_STATE_COMMENT1,
|
||||
R_XML_STATE_COMMENT2,
|
||||
R_XML_STATE_COMMENT3,
|
||||
R_XML_STATE_COMMENT4,
|
||||
R_XML_STATE_DT0,
|
||||
R_XML_STATE_DT1,
|
||||
R_XML_STATE_DT2,
|
||||
R_XML_STATE_DT3,
|
||||
R_XML_STATE_DT4,
|
||||
R_XML_STATE_ELEM0,
|
||||
R_XML_STATE_ELEM1,
|
||||
R_XML_STATE_ELEM2,
|
||||
R_XML_STATE_ELEM3,
|
||||
R_XML_STATE_ENC0,
|
||||
R_XML_STATE_ENC1,
|
||||
R_XML_STATE_ENC2,
|
||||
R_XML_STATE_ENC3,
|
||||
R_XML_STATE_ETAG0,
|
||||
R_XML_STATE_ETAG1,
|
||||
R_XML_STATE_ETAG2,
|
||||
R_XML_STATE_INIT,
|
||||
R_XML_STATE_le0,
|
||||
R_XML_STATE_le1,
|
||||
R_XML_STATE_le2,
|
||||
R_XML_STATE_le3,
|
||||
R_XML_STATE_LEE1,
|
||||
R_XML_STATE_LEE2,
|
||||
R_XML_STATE_LEQ0,
|
||||
R_XML_STATE_MISC0,
|
||||
R_XML_STATE_MISC1,
|
||||
R_XML_STATE_MISC2,
|
||||
R_XML_STATE_MISC2a,
|
||||
R_XML_STATE_MISC3,
|
||||
R_XML_STATE_PI0,
|
||||
R_XML_STATE_PI1,
|
||||
R_XML_STATE_PI2,
|
||||
R_XML_STATE_PI3,
|
||||
R_XML_STATE_PI4,
|
||||
R_XML_STATE_STD0,
|
||||
R_XML_STATE_STD1,
|
||||
R_XML_STATE_STD2,
|
||||
R_XML_STATE_STD3,
|
||||
R_XML_STATE_VER0,
|
||||
R_XML_STATE_VER1,
|
||||
R_XML_STATE_VER2,
|
||||
R_XML_STATE_VER3,
|
||||
R_XML_STATE_XMLDECL0,
|
||||
R_XML_STATE_XMLDECL1,
|
||||
R_XML_STATE_XMLDECL2,
|
||||
R_XML_STATE_XMLDECL3,
|
||||
R_XML_STATE_XMLDECL4,
|
||||
R_XML_STATE_XMLDECL5,
|
||||
R_XML_STATE_XMLDECL6,
|
||||
R_XML_STATE_XMLDECL7,
|
||||
R_XML_STATE_XMLDECL8,
|
||||
R_XML_STATE_XMLDECL9
|
||||
} RXmlState;
|
||||
|
||||
|
||||
typedef struct r_xml_t {
|
||||
/* PUBLIC (read-only) */
|
||||
|
||||
/* Name of the current element, zero-length if not in any element. Changed
|
||||
* after R_XML_ELEMSTART. The pointer will remain valid up to and including
|
||||
* the next non-R_XML_ATTR* token, the pointed-to buffer will remain valid
|
||||
* up to and including the R_XML_ELEMEND for the corresponding element. */
|
||||
char *elem;
|
||||
|
||||
/* The last read character(s) of an attribute value (R_XML_ATTRVAL), element
|
||||
* data (R_XML_CONTENT), or processing instruction (R_XML_PICONTENT). Changed
|
||||
* after one of the respective R_XML_ values is returned, and only valid
|
||||
* until the next r_xml_parse() call. Usually, this string only consists of
|
||||
* a single byte, but multiple bytes are returned in the following cases:
|
||||
* - "<?SomePI ?x ?>": The two characters "?x"
|
||||
* - "<![CDATA[ ]x ]]>": The two characters "]x"
|
||||
* - "<![CDATA[ ]]x ]]>": The three characters "]]x"
|
||||
* - "&#N;" and "&#xN;", where dec(n) > 127. The referenced Unicode
|
||||
* character is then encoded in multiple UTF-8 bytes.
|
||||
*/
|
||||
char data[8];
|
||||
|
||||
/* Name of the current attribute. Changed after R_XML_ATTRSTART, valid up to
|
||||
* and including the next R_XML_ATTREND. */
|
||||
char *attr;
|
||||
|
||||
/* Name/target of the current processing instruction, zero-length if not in
|
||||
* a PI. Changed after R_XML_PISTART, valid up to (but excluding)
|
||||
* the next R_XML_PIEND. */
|
||||
char *pi;
|
||||
|
||||
/* Line number, byte offset within that line, and total bytes read. These
|
||||
* values refer to the position _after_ the last byte given to
|
||||
* r_xml_parse(). These are useful for debugging and error reporting. */
|
||||
ut64 byte;
|
||||
ut64 total;
|
||||
uint32_t line;
|
||||
|
||||
/* PRIVATE */
|
||||
RXmlState state;
|
||||
ut8 *stack; /* Stack of element names + attribute/PI name, separated by \0. Also starts with a \0. */
|
||||
size_t stacksize, stacklen;
|
||||
unsigned int reflen;
|
||||
unsigned int quote;
|
||||
int nextstate; /* Used for '@' state remembering and for the "string" consuming state */
|
||||
unsigned int ignore;
|
||||
ut8 *string;
|
||||
} RXml;
|
||||
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
R_API void r_xml_init(RXml *, void *, size_t);
|
||||
R_API RXmlRet r_xml_parse(RXml *, int);
|
||||
|
||||
R_API RXml *r_xml_new(int stacksize);
|
||||
R_API void r_xml_free(RXml *);
|
||||
|
||||
/* May be called after the last character has been given to r_xml_parse().
|
||||
* Returns R_XML_OK if the XML document is valid, R_XML_EEOF otherwise. Using
|
||||
* this function isn't really necessary, but can be used to detect documents
|
||||
* that don't end correctly. In particular, an error is returned when the XML
|
||||
* document did not contain a (complete) root element, or when the document
|
||||
* ended while in a comment or processing instruction. */
|
||||
R_API RXmlRet r_xml_eof(RXml *);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
|
||||
/* Returns the length of the element name (x->elem), attribute name (x->attr),
|
||||
* or PI name (x->pi). This function should ONLY be used directly after the
|
||||
* R_XML_ELEMSTART, R_XML_ATTRSTART or R_XML_PISTART (respectively) tokens have
|
||||
* been returned by r_xml_parse(), calling this at any other time may not give
|
||||
* the correct results. This function should also NOT be used on strings other
|
||||
* than x->elem, x->attr or x->pi. */
|
||||
static inline size_t r_xml_symlen(RXml *x, const char *s) {
|
||||
return (x->stack + x->stacklen) - (const ut8 *)s;
|
||||
}
|
||||
|
||||
#endif
|
@ -3,7 +3,7 @@ include ../config.mk
|
||||
NAME=r_util
|
||||
CFLAGS+=-DR2_PLUGIN_INCORE -I$(TOP)/shlr
|
||||
PCLIBS=@LIBZIP@ @DL_LIBS@
|
||||
OBJS=mem.o unum.o str.o hex.o file.o range.o charset.o xdg.o
|
||||
OBJS=mem.o unum.o str.o hex.o file.o range.o charset.o xdg.o rxml.o
|
||||
OBJS+=prof.o cache.o sys.o buf.o sys_w32.o ubase64.o base85.o base91.o
|
||||
OBJS+=list.o chmod.o graph.o event.o alloc.o donut.o print_code.o
|
||||
OBJS+=regex/regcomp.o regex/regerror.o regex/regexec.o uleb128.o rstr.o
|
||||
|
@ -6,6 +6,7 @@ r_util_sources = [
|
||||
'w32.c',
|
||||
'w32dw.c',
|
||||
'alloc.c',
|
||||
'rxml.c',
|
||||
'charset.c',
|
||||
'donut.c',
|
||||
'token.c',
|
||||
|
1004
libr/util/rxml.c
Normal file
1004
libr/util/rxml.c
Normal file
File diff suppressed because it is too large
Load Diff
@ -877,6 +877,7 @@ R_API char *r_str_prepend(char *ptr, const char *string) {
|
||||
}
|
||||
|
||||
R_API char *r_str_appendlen(char *ptr, const char *string, int slen) {
|
||||
r_return_val_if_fail (string, NULL);
|
||||
char *msg = r_str_newlen (string, slen);
|
||||
char *ret = r_str_append (ptr, msg);
|
||||
free (msg);
|
||||
|
@ -60,8 +60,8 @@ endif
|
||||
SHLR?=$(shell pwd)
|
||||
AR?=ar
|
||||
RANLIB?=ranlib
|
||||
# MODS=sdb zip java mpc yxml
|
||||
MODS=zip java mpc yxml
|
||||
# MODS=sdb zip java mpc
|
||||
MODS=zip java mpc
|
||||
MODS+=gdb qnx ar
|
||||
# lz4
|
||||
ifneq ($(CC),cccl)
|
||||
@ -326,13 +326,6 @@ spp-sync sync-spp:
|
||||
spp: spp-sync
|
||||
export CFLAGS="-DUSE_R2=1 -I../../libr/include -DHAVE_FORK=${HAVE_FORK} -fPIC"; $(MAKE) -C spp r2lib
|
||||
|
||||
sync-yxml yxml-sync:
|
||||
rm -rf yxml-git
|
||||
git clone https://g.blicky.net/yxml.git/ yxml-git
|
||||
cp -f yxml-git/yxml.c yxml/yxml.c
|
||||
cp -f yxml-git/yxml.h yxml/yxml.h
|
||||
rm -rf yxml-git
|
||||
|
||||
SHLRS+=ar/libr_ar.a
|
||||
SHLRS+=bochs/lib/libbochs.a
|
||||
SHLRS+=capstone/libcapstone.a
|
||||
@ -341,7 +334,6 @@ SHLRS+=grub/libgrubfs.a
|
||||
SHLRS+=java/libr_java.a
|
||||
SHLRS+=lz4/liblz4.a
|
||||
SHLRS+=qnx/lib/libqnxr.a
|
||||
SHLRS+=yxml/libyxml.a
|
||||
SHLRS+=winkd/libr_winkd.a
|
||||
SHLRS+=zip/librz.a
|
||||
|
||||
|
@ -484,20 +484,3 @@ mpc_dep = declare_dependency(
|
||||
link_with: libmpc,
|
||||
include_directories: mpc_inc
|
||||
)
|
||||
|
||||
# handle yxml dependency
|
||||
yxml_files = [
|
||||
'yxml/yxml.c'
|
||||
]
|
||||
|
||||
yxml_inc = [platform_inc, include_directories(['yxml'])]
|
||||
|
||||
libyxml = static_library('r2yxml', yxml_files,
|
||||
include_directories: yxml_inc,
|
||||
implicit_include_directories: false
|
||||
)
|
||||
|
||||
yxml_dep = declare_dependency(
|
||||
link_with: libyxml,
|
||||
include_directories: yxml_inc
|
||||
)
|
||||
|
@ -1,20 +0,0 @@
|
||||
include ../../libr/config.mk
|
||||
include ../../mk/platform.mk
|
||||
|
||||
CFLAGS+=-I.
|
||||
LIBMPC=libyxml.${EXT_AR}
|
||||
|
||||
OFILES=yxml.o
|
||||
|
||||
all: ${LIBMPC}
|
||||
|
||||
%.o: %.c
|
||||
$(CC) $(CFLAGS) $(LDFLAGS) -c $< -o $@
|
||||
|
||||
${LIBMPC}: $(OFILES)
|
||||
rm -f $(LIBMPC)
|
||||
$(AR) q $(LIBMPC) $(OFILES)
|
||||
$(RANLIB) $(LIBMPC)
|
||||
|
||||
clean:
|
||||
rm -f $(OBJS) ${LIBMPC} $(OFILES)
|
@ -1 +0,0 @@
|
||||
LINK+=$(SHLR)/yxml/libyxml.$(EXT_AR)
|
1060
shlr/yxml/yxml.c
1060
shlr/yxml/yxml.c
File diff suppressed because it is too large
Load Diff
162
shlr/yxml/yxml.h
162
shlr/yxml/yxml.h
@ -1,162 +0,0 @@
|
||||
/* Copyright (c) 2013-2014 Yoran Heling
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining
|
||||
a copy of this software and associated documentation files (the
|
||||
"Software"), to deal in the Software without restriction, including
|
||||
without limitation the rights to use, copy, modify, merge, publish,
|
||||
distribute, sublicense, and/or sell copies of the Software, and to
|
||||
permit persons to whom the Software is furnished to do so, subject to
|
||||
the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be included
|
||||
in all copies or substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
||||
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
||||
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
|
||||
IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
|
||||
CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
|
||||
TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
|
||||
SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
||||
*/
|
||||
|
||||
#ifndef YXML_H
|
||||
#define YXML_H
|
||||
|
||||
#include <stdint.h>
|
||||
#include <stddef.h>
|
||||
|
||||
#if defined(_MSC_VER) && !defined(__cplusplus) && !defined(inline)
|
||||
#define inline __inline
|
||||
#endif
|
||||
|
||||
/* Full API documentation for this library can be found in the "yxml.md" file
|
||||
* in the yxml git repository, or online at http://dev.yorhel.nl/yxml/man */
|
||||
|
||||
typedef enum {
|
||||
YXML_EEOF = -5, /* Unexpected EOF */
|
||||
YXML_EREF = -4, /* Invalid character or entity reference (&whatever;) */
|
||||
YXML_ECLOSE = -3, /* Close tag does not match open tag (<Tag> .. </OtherTag>) */
|
||||
YXML_ESTACK = -2, /* Stack overflow (too deeply nested tags or too long element/attribute name) */
|
||||
YXML_ESYN = -1, /* Syntax error (unexpected byte) */
|
||||
YXML_OK = 0, /* Character consumed, no new token present */
|
||||
YXML_ELEMSTART = 1, /* Start of an element: '<Tag ..' */
|
||||
YXML_CONTENT = 2, /* Element content */
|
||||
YXML_ELEMEND = 3, /* End of an element: '.. />' or '</Tag>' */
|
||||
YXML_ATTRSTART = 4, /* Attribute: 'Name=..' */
|
||||
YXML_ATTRVAL = 5, /* Attribute value */
|
||||
YXML_ATTREND = 6, /* End of attribute '.."' */
|
||||
YXML_PISTART = 7, /* Start of a processing instruction */
|
||||
YXML_PICONTENT = 8, /* Content of a PI */
|
||||
YXML_PIEND = 9 /* End of a processing instruction */
|
||||
} yxml_ret_t;
|
||||
|
||||
/* When, exactly, are tokens returned?
|
||||
*
|
||||
* <TagName
|
||||
* '>' ELEMSTART
|
||||
* '/' ELEMSTART, '>' ELEMEND
|
||||
* ' ' ELEMSTART
|
||||
* '>'
|
||||
* '/', '>' ELEMEND
|
||||
* Attr
|
||||
* '=' ATTRSTART
|
||||
* "X ATTRVAL
|
||||
* 'Y' ATTRVAL
|
||||
* 'Z' ATTRVAL
|
||||
* '"' ATTREND
|
||||
* '>'
|
||||
* '/', '>' ELEMEND
|
||||
*
|
||||
* </TagName
|
||||
* '>' ELEMEND
|
||||
*/
|
||||
|
||||
|
||||
typedef struct {
|
||||
/* PUBLIC (read-only) */
|
||||
|
||||
/* Name of the current element, zero-length if not in any element. Changed
|
||||
* after YXML_ELEMSTART. The pointer will remain valid up to and including
|
||||
* the next non-YXML_ATTR* token, the pointed-to buffer will remain valid
|
||||
* up to and including the YXML_ELEMEND for the corresponding element. */
|
||||
char *elem;
|
||||
|
||||
/* The last read character(s) of an attribute value (YXML_ATTRVAL), element
|
||||
* data (YXML_CONTENT), or processing instruction (YXML_PICONTENT). Changed
|
||||
* after one of the respective YXML_ values is returned, and only valid
|
||||
* until the next yxml_parse() call. Usually, this string only consists of
|
||||
* a single byte, but multiple bytes are returned in the following cases:
|
||||
* - "<?SomePI ?x ?>": The two characters "?x"
|
||||
* - "<![CDATA[ ]x ]]>": The two characters "]x"
|
||||
* - "<![CDATA[ ]]x ]]>": The three characters "]]x"
|
||||
* - "&#N;" and "&#xN;", where dec(n) > 127. The referenced Unicode
|
||||
* character is then encoded in multiple UTF-8 bytes.
|
||||
*/
|
||||
char data[8];
|
||||
|
||||
/* Name of the current attribute. Changed after YXML_ATTRSTART, valid up to
|
||||
* and including the next YXML_ATTREND. */
|
||||
char *attr;
|
||||
|
||||
/* Name/target of the current processing instruction, zero-length if not in
|
||||
* a PI. Changed after YXML_PISTART, valid up to (but excluding)
|
||||
* the next YXML_PIEND. */
|
||||
char *pi;
|
||||
|
||||
/* Line number, byte offset within that line, and total bytes read. These
|
||||
* values refer to the position _after_ the last byte given to
|
||||
* yxml_parse(). These are useful for debugging and error reporting. */
|
||||
uint64_t byte;
|
||||
uint64_t total;
|
||||
uint32_t line;
|
||||
|
||||
|
||||
/* PRIVATE */
|
||||
int state;
|
||||
unsigned char *stack; /* Stack of element names + attribute/PI name, separated by \0. Also starts with a \0. */
|
||||
size_t stacksize, stacklen;
|
||||
unsigned reflen;
|
||||
unsigned quote;
|
||||
int nextstate; /* Used for '@' state remembering and for the "string" consuming state */
|
||||
unsigned ignore;
|
||||
unsigned char *string;
|
||||
} yxml_t;
|
||||
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
void yxml_init(yxml_t *, void *, size_t);
|
||||
|
||||
|
||||
yxml_ret_t yxml_parse(yxml_t *, int);
|
||||
|
||||
|
||||
/* May be called after the last character has been given to yxml_parse().
|
||||
* Returns YXML_OK if the XML document is valid, YXML_EEOF otherwise. Using
|
||||
* this function isn't really necessary, but can be used to detect documents
|
||||
* that don't end correctly. In particular, an error is returned when the XML
|
||||
* document did not contain a (complete) root element, or when the document
|
||||
* ended while in a comment or processing instruction. */
|
||||
yxml_ret_t yxml_eof(yxml_t *);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
|
||||
/* Returns the length of the element name (x->elem), attribute name (x->attr),
|
||||
* or PI name (x->pi). This function should ONLY be used directly after the
|
||||
* YXML_ELEMSTART, YXML_ATTRSTART or YXML_PISTART (respectively) tokens have
|
||||
* been returned by yxml_parse(), calling this at any other time may not give
|
||||
* the correct results. This function should also NOT be used on strings other
|
||||
* than x->elem, x->attr or x->pi. */
|
||||
static inline size_t yxml_symlen(yxml_t *x, const char *s) {
|
||||
return (x->stack + x->stacklen) - (const unsigned char*)s;
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
/* vim: set noet sw=4 ts=4: */
|
Loading…
x
Reference in New Issue
Block a user