summaryrefslogtreecommitdiff
path: root/src/xine-utils
diff options
context:
space:
mode:
Diffstat (limited to 'src/xine-utils')
-rw-r--r--src/xine-utils/Makefile.am34
-rw-r--r--src/xine-utils/array.c4
-rw-r--r--src/xine-utils/array.h57
-rw-r--r--src/xine-utils/attributes.h121
-rw-r--r--src/xine-utils/color.c3
-rw-r--r--src/xine-utils/compat.h55
-rw-r--r--src/xine-utils/copy.c2
-rw-r--r--src/xine-utils/cpu_accel.c36
-rw-r--r--src/xine-utils/list.c4
-rw-r--r--src/xine-utils/list.h104
-rw-r--r--src/xine-utils/memcpy.c46
-rw-r--r--src/xine-utils/monitor.c2
-rw-r--r--src/xine-utils/pool.c6
-rw-r--r--src/xine-utils/pool.h48
-rw-r--r--src/xine-utils/ring_buffer.c8
-rw-r--r--src/xine-utils/ring_buffer.h55
-rw-r--r--src/xine-utils/sorted_array.c4
-rw-r--r--src/xine-utils/sorted_array.h94
-rw-r--r--src/xine-utils/utils.c376
-rw-r--r--src/xine-utils/xine_buffer.c2
-rw-r--r--src/xine-utils/xine_buffer.h136
-rw-r--r--src/xine-utils/xine_check.c2
-rw-r--r--src/xine-utils/xine_mutex.c2
-rw-r--r--src/xine-utils/xineutils.h546
-rw-r--r--src/xine-utils/xmllexer.c160
-rw-r--r--src/xine-utils/xmllexer.h77
-rw-r--r--src/xine-utils/xmlparser.c419
-rw-r--r--src/xine-utils/xmlparser.h97
28 files changed, 745 insertions, 1755 deletions
diff --git a/src/xine-utils/Makefile.am b/src/xine-utils/Makefile.am
index 501f489fe..783bc7633 100644
--- a/src/xine-utils/Makefile.am
+++ b/src/xine-utils/Makefile.am
@@ -1,19 +1,21 @@
+include $(top_srcdir)/misc/Makefile.quiet
include $(top_srcdir)/misc/Makefile.common
-LIBTOOL = $(SHELL) $(top_builddir)/libtool
-noinst_LTLIBRARIES = libxineutils.la
+AM_CFLAGS = $(DEFAULT_OCFLAGS) $(X_CFLAGS) $(VISIBILITY_FLAG)
+AM_CPPFLAGS = -DXINE_LIBRARY_COMPILE
EXTRA_DIST = ppcasm_string.S ppc_asm.tmpl
-if PPC_ARCH
+noinst_HEADERS = ppcasm_string.h mangle.h xine_mmx.h
+
+noinst_LTLIBRARIES = libxineutils.la
+
+if ARCH_PPC
if !HOST_OS_DARWIN
pppc_files = ppcasm_string.S
endif
endif
-AM_CFLAGS = $(X_CFLAGS) $(VISIBILITY_FLAG)
-AM_CPPFLAGS= -DXINE_LIBRARY_COMPILE
-
libxineutils_la_SOURCES = $(pppc_files) \
cpu_accel.c \
color.c \
@@ -32,20 +34,6 @@ libxineutils_la_SOURCES = $(pppc_files) \
pool.c \
ring_buffer.c
-xineinclude_HEADERS = \
- attributes.h \
- compat.h \
- xine_buffer.h \
- xineutils.h \
- xine_mmx.h \
- xmllexer.h \
- xmlparser.h \
- list.h \
- array.h \
- sorted_array.h \
- pool.h \
- ring_buffer.h
-
-
-noinst_HEADERS = ppcasm_string.h mangle.h
-
+noinst_PROGRAMS = xmltest
+xmltest_SOURCES = xmllexer.c xmlparser.c
+xmltest_CFLAGS = -DLOG -DXINE_XML_PARSER_TEST $(AM_CFLAGS)
diff --git a/src/xine-utils/array.c b/src/xine-utils/array.c
index 5cb3100ad..2cc540c34 100644
--- a/src/xine-utils/array.c
+++ b/src/xine-utils/array.c
@@ -23,8 +23,8 @@
#include <stdlib.h>
#include <string.h>
-#include "attributes.h"
-#include "array.h"
+#include <xine/attributes.h>
+#include <xine/array.h>
#define MIN_CHUNK_SIZE 32
diff --git a/src/xine-utils/array.h b/src/xine-utils/array.h
deleted file mode 100644
index cd0780e04..000000000
--- a/src/xine-utils/array.h
+++ /dev/null
@@ -1,57 +0,0 @@
-/*
- * Copyright (C) 2000-2006 the xine project
- *
- * This file is part of xine, a free video player.
- *
- * xine is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation; either version 2 of the License, or
- * (at your option) any later version.
- *
- * xine is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program; if not, write to the Free Software
- * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110, USA
- *
- * Array that can grow automatically when you add elements.
- * Inserting an element in the middle of the array implies memory moves.
- */
-#ifndef XINE_ARRAY_H
-#define XINE_ARRAY_H
-
-/* Array type */
-typedef struct xine_array_s xine_array_t;
-
-/* Constructor */
-xine_array_t *xine_array_new(size_t initial_size) XINE_MALLOC XINE_PROTECTED;
-
-/* Destructor */
-void xine_array_delete(xine_array_t *array) XINE_PROTECTED;
-
-/* Returns the number of element stored in the array */
-size_t xine_array_size(const xine_array_t *array) XINE_PROTECTED;
-
-/* Removes all elements from an array */
-void xine_array_clear(xine_array_t *array) XINE_PROTECTED;
-
-/* Adds the element at the end of the array */
-void xine_array_add(xine_array_t *array, void *value) XINE_PROTECTED;
-
-/* Inserts an element into an array at the position specified */
-void xine_array_insert(xine_array_t *array, unsigned int position, void *value) XINE_PROTECTED;
-
-/* Removes one element from an array at the position specified */
-void xine_array_remove(xine_array_t *array, unsigned int position) XINE_PROTECTED;
-
-/* Get the element at the position specified */
-void *xine_array_get(const xine_array_t *array, unsigned int position) XINE_PROTECTED;
-
-/* Set the element at the position specified */
-void xine_array_set(xine_array_t *array, unsigned int position, void *value) XINE_PROTECTED;
-
-#endif
-
diff --git a/src/xine-utils/attributes.h b/src/xine-utils/attributes.h
deleted file mode 100644
index 2326dab18..000000000
--- a/src/xine-utils/attributes.h
+++ /dev/null
@@ -1,121 +0,0 @@
-/*
- * attributes.h
- * Copyright (C) 1999-2000 Aaron Holtzman <aholtzma@ess.engr.uvic.ca>
- * Copyright (C) 2001-2008 xine developers
- *
- * This file was originally part of mpeg2dec, a free MPEG-2 video stream
- * decoder.
- *
- * mpeg2dec is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation; either version 2 of the License, or
- * (at your option) any later version.
- *
- * mpeg2dec is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program; if not, write to the Free Software
- * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110, USA
- */
-
-/* use gcc attribs to align critical data structures */
-
-#ifndef ATTRIBUTE_H_
-#define ATTRIBUTE_H_
-
-#ifdef ATTRIBUTE_ALIGNED_MAX
-#define ATTR_ALIGN(align) __attribute__ ((__aligned__ ((ATTRIBUTE_ALIGNED_MAX < align) ? ATTRIBUTE_ALIGNED_MAX : align)))
-#else
-#define ATTR_ALIGN(align)
-#endif
-
-#ifdef XINE_COMPILE
-# include "configure.h"
-#else
-# if __GNUC__ > 2 || (__GNUC__ == 2 && __GNUC_MINOR__ >= 95 )
-# define SUPPORT_ATTRIBUTE_PACKED 1
-# endif
-
-# if __GNUC__ > 3 || (__GNUC__ == 3 && __GNUC_MINOR__ >= 3 )
-# define SUPPORT_ATTRIBUTE_DEPRECATED 1
-# define SUPPORT_ATTRIBUTE_FORMAT 1
-# define SUPPORT_ATTRIBUTE_FORMAT_ARG 1
-# define SUPPORT_ATTRIBUTE_MALLOC 1
-# define SUPPORT_ATTRIBUTE_UNUSED 1
-# define SUPPORT_ATTRIBUTE_CONST 1
-# endif
-
-# if __GNUC__ >= 4
-# define SUPPORT_ATTRIBUTE_VISIBILITY_DEFAULT 1
-# if __ELF__
-# define SUPPORT_ATTRIBUTE_VISIBILITY_PROTECTED 1
-# endif
-# define SUPPORT_ATTRIBUTE_SENTINEL 1
-# endif
-#endif
-
-/* Export protected only for libxine functions */
-#if defined(XINE_LIBRARY_COMPILE) && defined(SUPPORT_ATTRIBUTE_VISIBILITY_PROTECTED)
-# define XINE_PROTECTED __attribute__((__visibility__("protected")))
-#elif defined(XINE_LIBRARY_COMPILE) && defined(SUPPORT_ATTRIBUTE_VISIBILITY_DEFAULT)
-# define XINE_PROTECTED __attribute__((__visibility__("default")))
-#else
-# define XINE_PROTECTED
-#endif
-
-#ifdef SUPPORT_ATTRIBUTE_SENTINEL
-# define XINE_SENTINEL __attribute__((__sentinel__))
-#else
-# define XINE_SENTINEL
-#endif
-
-#if defined(SUPPORT_ATTRIBUTE_DEPRECATED) && !defined(XINE_COMPILE)
-# define XINE_DEPRECATED __attribute__((__deprecated__))
-#else
-# define XINE_DEPRECATED
-#endif
-
-#ifndef __attr_unused
-# ifdef SUPPORT_ATTRIBUTE_UNUSED
-# define __attr_unused __attribute__((__unused__))
-# else
-# define __attr_unused
-# endif
-#endif
-
-/* Format attributes */
-#ifdef SUPPORT_ATTRIBUTE_FORMAT
-# define XINE_FORMAT_PRINTF(fmt,var) __attribute__((__format__(__printf__, fmt, var)))
-# define XINE_FORMAT_SCANF(fmt,var) __attribute__((__format__(__scanf__, fmt, var)))
-#else
-# define XINE_FORMAT_PRINTF(fmt,var)
-# define XINE_FORMAT_SCANF(fmt,var)
-#endif
-#ifdef SUPPORT_ATTRIBUTE_FORMAT_ARG
-# define XINE_FORMAT_PRINTF_ARG(fmt) __attribute__((__format_arg__(fmt)))
-#else
-# define XINE_FORMAT_PRINTF_ARG(fmt)
-#endif
-
-#ifdef SUPPORT_ATTRIBUTE_MALLOC
-# define XINE_MALLOC __attribute__((__malloc__))
-#else
-# define XINE_MALLOC
-#endif
-
-#ifdef SUPPORT_ATTRIBUTE_PACKED
-# define XINE_PACKED __attribute__((__packed__))
-#else
-# define XINE_PACKED
-#endif
-
-#ifdef SUPPORT_ATTRIBUTE_CONST
-# define XINE_CONST __attribute__((__const__))
-#else
-# define XINE_CONST
-#endif
-
-#endif /* ATTRIBUTE_H_ */
diff --git a/src/xine-utils/color.c b/src/xine-utils/color.c
index bea4cd952..5c433ed59 100644
--- a/src/xine-utils/color.c
+++ b/src/xine-utils/color.c
@@ -62,7 +62,8 @@
* instructions.
*/
-#include "xine_internal.h"
+#include <xine/xine_internal.h>
+#include "xine_mmx.h"
/*
* In search of the perfect colorspace conversion formulae...
diff --git a/src/xine-utils/compat.h b/src/xine-utils/compat.h
deleted file mode 100644
index 0392b45fd..000000000
--- a/src/xine-utils/compat.h
+++ /dev/null
@@ -1,55 +0,0 @@
-/*
- * Copyright (C) 2000-2001 the xine project
- *
- * This file is part of xine, a unix video player.
- *
- * xine is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation; either version 2 of the License, or
- * (at your option) any later version.
- *
- * xine is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program; if not, write to the Free Software
- * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110, USA
- */
-
-#ifndef XINE_COMPAT_H
-#define XINE_COMPAT_H
-
-#include <limits.h>
-
-#ifdef __cplusplus
-extern "C" {
-#endif
-
-#if defined _MSC_VER
-#define __XINE_FUNCTION__ __FILE__
-#elif defined __GNUC__
-#define __XINE_FUNCTION__ __FUNCTION__
-#else
-#define __XINE_FUNCTION__ __func__
-#endif
-
-#ifndef NAME_MAX
-#define XINE_NAME_MAX 256
-#else
-#define XINE_NAME_MAX NAME_MAX
-#endif
-
-#ifndef PATH_MAX
-#define XINE_PATH_MAX 768
-#else
-#define XINE_PATH_MAX PATH_MAX
-#endif
-
-
-#ifdef __cplusplus
-}
-#endif
-
-#endif
diff --git a/src/xine-utils/copy.c b/src/xine-utils/copy.c
index 277cb64af..ed762fad1 100644
--- a/src/xine-utils/copy.c
+++ b/src/xine-utils/copy.c
@@ -25,7 +25,7 @@
#include "config.h"
#endif
-#include "xineutils.h"
+#include <xine/xineutils.h>
void yv12_to_yv12
(const unsigned char *y_src, int y_src_pitch, unsigned char *y_dst, int y_dst_pitch,
diff --git a/src/xine-utils/cpu_accel.c b/src/xine-utils/cpu_accel.c
index 1e12986fb..adcc4edc0 100644
--- a/src/xine-utils/cpu_accel.c
+++ b/src/xine-utils/cpu_accel.c
@@ -24,9 +24,10 @@
#include <stdio.h>
#include <stdlib.h>
#include <inttypes.h>
-#include <signal.h>
-#include <setjmp.h>
+
+#if defined(HAVE_MLIB) && defined(MLIB_LAZYLOAD)
#include <dlfcn.h>
+#endif
#if defined (__SVR4) && defined (__sun)
#include <sys/systeminfo.h>
@@ -38,28 +39,38 @@
#define LOG
*/
-#include "xineutils.h"
+#include <xine/xineutils.h>
#if defined(PIC) && ! defined(__PIC__)
#define __PIC__
#endif
-#if defined(ARCH_X86) || defined(ARCH_X86_64)
+#if defined(__i386__) || defined(__x86_64__)
+
+#ifndef __x86_64__
+#include <signal.h>
+#include <setjmp.h>
static jmp_buf sigill_return;
static void sigill_handler (int n) {
longjmp(sigill_return, 1);
}
+#endif
static uint32_t arch_accel (void)
{
uint32_t caps;
-#ifdef __x86_64__
+#if defined(__x86_64__) || \
+ ( defined(__SSE__) && defined(__SSE2__) && defined(__MMX__) )
/* No need to test for this on AMD64, we know what the
platform has. */
- caps = MM_ACCEL_X86_MMX | MM_ACCEL_X86_SSE | MM_ACCEL_X86_MMXEXT | MM_ACCEL_X86_SSE2;
+ caps = MM_ACCEL_X86_MMX | MM_ACCEL_X86_SSE | MM_ACCEL_X86_MMXEXT | MM_ACCEL_X86_SSE2
+# if defined(__3dNOW__)
+ | MM_ACCEL_X86_3DNOW
+# endif
+ ;
#else
#ifndef _MSC_VER
@@ -152,6 +163,9 @@ static uint32_t arch_accel (void)
caps = 0;
#endif /* _MSC_VER */
+#endif /* x86_64 or built-in options */
+
+#ifndef __x86_64__
/* test OS support for SSE */
if (caps & MM_ACCEL_X86_SSE) {
void (*old_sigill_handler)(int);
@@ -173,9 +187,12 @@ static uint32_t arch_accel (void)
return caps;
}
-#endif /* ARCH_X86 */
+#endif /* i386 or x86_64 */
#if defined(ARCH_PPC) && defined(ENABLE_ALTIVEC)
+#include <signal.h>
+#include <setjmp.h>
+
static sigjmp_buf jmpbuf;
static volatile sig_atomic_t canjump = 0;
@@ -260,6 +277,9 @@ static uint32_t arch_accel (void)
return flags;
}
#else
+#include <signal.h>
+#include <setjmp.h>
+
static sigjmp_buf jmpbuf;
static volatile sig_atomic_t canjump = 0;
@@ -330,7 +350,7 @@ uint32_t xine_mm_accel (void)
#endif
#endif
-#if defined(ARCH_X86) || defined(ARCH_X86_64) || (defined(ARCH_PPC) && defined(ENABLE_ALTIVEC)) || (defined(ARCH_SPARC) && defined(ENABLE_VIS))
+#if defined(__i386__) || defined(__x86_64__) || (defined(ARCH_PPC) && defined(ENABLE_ALTIVEC)) || (defined(ARCH_SPARC) && defined(ENABLE_VIS))
accel |= arch_accel();
#endif
diff --git a/src/xine-utils/list.c b/src/xine-utils/list.c
index 48ef0bff6..32c1d8fac 100644
--- a/src/xine-utils/list.c
+++ b/src/xine-utils/list.c
@@ -23,8 +23,8 @@
#endif
#include <stdlib.h>
-#include "attributes.h"
-#include "list.h"
+#include <xine/attributes.h>
+#include <xine/list.h>
#define MIN_CHUNK_SIZE 32
#define MAX_CHUNK_SIZE 65536
diff --git a/src/xine-utils/list.h b/src/xine-utils/list.h
deleted file mode 100644
index 4910f9982..000000000
--- a/src/xine-utils/list.h
+++ /dev/null
@@ -1,104 +0,0 @@
-/*
- * Copyright (C) 2000-2006 the xine project
- *
- * This file is part of xine, a free video player.
- *
- * xine is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation; either version 2 of the License, or
- * (at your option) any later version.
- *
- * xine is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program; if not, write to the Free Software
- * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110, USA
- *
- * Doubly-linked linked list.
- *
- * Exemples:
- *
- * Create a list:
- * xine_list_t *list = xine_list_new();
- *
- * Delete a list:
- * xine_list_delete(list);
- *
- * Walk thru a list:
- * xine_list_iterator_t ite = xine_list_front(list);
- * while (ite) {
- * _useful code here_
- * ite = xine_list_next(list, ite);
- * }
- *
- * The list elements are managed using memory chunks and a free list. The first
- * chunk contains 32 elements, each following chunk is two time as big as the
- * previous one, with a limit of 64K elements.
- */
-#ifndef XINE_LIST_H
-#define XINE_LIST_H
-
-/* Doubly-linked list type */
-typedef struct xine_list_s xine_list_t;
-
-/* List iterator */
-typedef void* xine_list_iterator_t;
-
-/* Constructor */
-xine_list_t *xine_list_new(void) XINE_MALLOC XINE_PROTECTED;
-
-/* Destructor */
-void xine_list_delete(xine_list_t *list) XINE_PROTECTED;
-
-/* Returns the number of element stored in the list */
-unsigned int xine_list_size(xine_list_t *list) XINE_PROTECTED;
-
-/* Returns true if the number of elements is zero, false otherwise */
-unsigned int xine_list_empty(xine_list_t *list) XINE_PROTECTED;
-
-/* Adds the element at the beginning of the list */
-void xine_list_push_front(xine_list_t *list, void *value) XINE_PROTECTED;
-
-/* Adds the element at the end of the list */
-void xine_list_push_back(xine_list_t *list, void *value) XINE_PROTECTED;
-
-/* Remove all elements from a list */
-void xine_list_clear(xine_list_t *list) XINE_PROTECTED;
-
-/* Insert the element elem into the list at the position specified by the
- iterator (before the element, if any, that was previously at the iterator's
- position). The return value is an iterator that specifies the position of
- the inserted element. */
-xine_list_iterator_t xine_list_insert(xine_list_t *list,
- xine_list_iterator_t position,
- void *value) XINE_PROTECTED;
-
-/* Remove one element from a list.*/
-void xine_list_remove(xine_list_t *list, xine_list_iterator_t position) XINE_PROTECTED;
-
-/* Returns an iterator that references the first element of the list */
-xine_list_iterator_t xine_list_front(xine_list_t *list) XINE_PROTECTED;
-
-/* Returns an iterator that references the last element of the list */
-xine_list_iterator_t xine_list_back(xine_list_t *list) XINE_PROTECTED;
-
-/* Perform a linear search of a given value, and returns an iterator that
- references this value or NULL if not found */
-xine_list_iterator_t xine_list_find(xine_list_t *list, void *value) XINE_PROTECTED;
-
-/* Increments the iterator's value, so it specifies the next element in the list
- or NULL at the end of the list */
-xine_list_iterator_t xine_list_next(xine_list_t *list, xine_list_iterator_t ite) XINE_PROTECTED;
-
-/* Increments the iterator's value, so it specifies the previous element in the list
- or NULL at the beginning of the list */
-xine_list_iterator_t xine_list_prev(xine_list_t *list, xine_list_iterator_t ite) XINE_PROTECTED;
-
-/* Returns the value at the position specified by the iterator */
-void *xine_list_get_value(xine_list_t *list, xine_list_iterator_t ite) XINE_PROTECTED;
-
-#endif
-
diff --git a/src/xine-utils/memcpy.c b/src/xine-utils/memcpy.c
index df514b682..515919a41 100644
--- a/src/xine-utils/memcpy.c
+++ b/src/xine-utils/memcpy.c
@@ -1,4 +1,4 @@
-/*
+;/*
* Copyright (C) 2001-2004 the xine project
*
* This file is part of xine, a free video player.
@@ -52,7 +52,7 @@
#define LOG
*/
-#include "xine_internal.h"
+#include <xine/xine_internal.h>
void *(* xine_fast_memcpy)(void *to, const void *from, size_t len);
@@ -384,30 +384,30 @@ static void *linux_kernel_memcpy(void *to, const void *from, size_t len) {
#endif /* _MSC_VER */
#endif /* ARCH_X86 */
-static struct {
- char *name;
- void *(* function)(void *to, const void *from, size_t len);
-
- uint64_t time; /* This type could be used for non-MSC build too! */
+static const struct {
+ const char name[16];
+ void *(*const function)(void *to, const void *from, size_t len);
uint32_t cpu_require;
} memcpy_method[] =
{
- { NULL, NULL, 0, 0 },
- { "libc memcpy()", memcpy, 0, 0 },
+ { "", NULL, 0 },
+ { "libc", memcpy, 0 },
#if (defined(ARCH_X86) || defined(ARCH_X86_64)) && !defined(_MSC_VER)
- { "linux kernel memcpy()", linux_kernel_memcpy, 0, 0 },
- { "MMX optimized memcpy()", mmx_memcpy, 0, MM_MMX },
- { "MMXEXT optimized memcpy()", mmx2_memcpy, 0, MM_MMXEXT },
- { "SSE optimized memcpy()", sse_memcpy, 0, MM_MMXEXT|MM_SSE },
+ { "linux kernel", linux_kernel_memcpy, 0 },
+ { "MMX ", mmx_memcpy, MM_MMX },
+ { "MMXEXT", mmx2_memcpy, MM_MMXEXT },
+ { "SSE", sse_memcpy, MM_MMXEXT|MM_SSE },
#endif /* ARCH_X86 */
#if defined (ARCH_PPC) && !defined (HOST_OS_DARWIN)
- { "ppcasm_memcpy()", ppcasm_memcpy, 0, 0 },
- { "ppcasm_cacheable_memcpy()", ppcasm_cacheable_memcpy, 0, MM_ACCEL_PPC_CACHE32 },
+ { "ppcasm", ppcasm_memcpy, 0 },
+ { "ppcasm_cached", ppcasm_cacheable_memcpy, MM_ACCEL_PPC_CACHE32 },
#endif /* ARCH_PPC && !HOST_OS_DARWIN */
- { NULL, NULL, 0, 0 }
+ { "", NULL, 0 }
};
+static uint64_t memcpy_timing[sizeof(memcpy_method)/sizeof(memcpy_method[0])] = { 0, };
+
#ifdef HAVE_POSIX_TIMERS
/* Prefer clock_gettime() where available. */
static int64_t _x_gettime(void)
@@ -459,7 +459,7 @@ static void update_fast_memcpy(void *user_data, xine_cfg_entry_t *entry) {
if (method != 0
&& (config_flags & memcpy_method[method].cpu_require) ==
memcpy_method[method].cpu_require ) {
- lprintf("using %s\n", memcpy_method[method].name );
+ lprintf("using %s memcpy()\n", memcpy_method[method].name );
xine_fast_memcpy = memcpy_method[method].function;
return;
} else {
@@ -474,7 +474,7 @@ void xine_probe_fast_memcpy(xine_t *xine)
char *buf1, *buf2;
int i, j, best;
int config_flags = -1;
- static const char *memcpy_methods[] = {
+ static const char *const memcpy_methods[] = {
"probe", "libc",
#if (defined(ARCH_X86) || defined(ARCH_X86_64)) && !defined(_MSC_VER)
"kernel", "mmx", "mmxext", "sse",
@@ -500,7 +500,7 @@ void xine_probe_fast_memcpy(xine_t *xine)
if( best != 0 &&
(config_flags & memcpy_method[best].cpu_require) ==
memcpy_method[best].cpu_require ) {
- lprintf("using %s\n", memcpy_method[best].name );
+ lprintf("using %s memcpy()\n", memcpy_method[best].name );
xine_fast_memcpy = memcpy_method[best].function;
return;
}
@@ -528,7 +528,7 @@ void xine_probe_fast_memcpy(xine_t *xine)
memcpy_method[1].function(buf1,buf2,BUFSIZE);
}
- for(i=1; memcpy_method[i].name; i++)
+ for(i=1; memcpy_method[i].name[0]; i++)
{
if( (config_flags & memcpy_method[i].cpu_require) !=
memcpy_method[i].cpu_require )
@@ -541,11 +541,11 @@ void xine_probe_fast_memcpy(xine_t *xine)
}
t = rdtsc(config_flags) - t;
- memcpy_method[i].time = t;
+ memcpy_timing[i] = t;
- xprintf(xine, XINE_VERBOSITY_LOG, "\t%s : %" PRIu64 "\n", memcpy_method[i].name, t);
+ xprintf(xine, XINE_VERBOSITY_LOG, "\t%s memcpy() : %" PRIu64 "\n", memcpy_method[i].name, t);
- if( best == 0 || t < memcpy_method[best].time )
+ if( best == 0 || t < memcpy_timing[best] )
best = i;
}
diff --git a/src/xine-utils/monitor.c b/src/xine-utils/monitor.c
index 3fe83b3f7..0c68cd59b 100644
--- a/src/xine-utils/monitor.c
+++ b/src/xine-utils/monitor.c
@@ -26,7 +26,7 @@
#include <stdio.h>
#include <sys/time.h>
-#include "xineutils.h"
+#include <xine/xineutils.h>
#define MAX_ID 10
diff --git a/src/xine-utils/pool.c b/src/xine-utils/pool.c
index 8b7f6d9f3..a6166bf62 100644
--- a/src/xine-utils/pool.c
+++ b/src/xine-utils/pool.c
@@ -22,9 +22,9 @@
#endif
#include <assert.h>
-#include "attributes.h"
-#include "pool.h"
-#include "array.h"
+#include <xine/attributes.h>
+#include <xine/pool.h>
+#include <xine/array.h>
#define MIN_CHUNK_SIZE 32
#define MAX_CHUNK_SIZE 65536
diff --git a/src/xine-utils/pool.h b/src/xine-utils/pool.h
deleted file mode 100644
index 37f60220c..000000000
--- a/src/xine-utils/pool.h
+++ /dev/null
@@ -1,48 +0,0 @@
-/*
- * Copyright (C) 2000-2006 the xine project
- *
- * This file is part of xine, a free video player.
- *
- * xine is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation; either version 2 of the License, or
- * (at your option) any later version.
- *
- * xine is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program; if not, write to the Free Software
- * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110, USA
- *
- * Object Pool
- */
-
-#include <stdlib.h>
-#include <inttypes.h>
-
-typedef struct xine_pool_s xine_pool_t;
-
-/* Creates a new pool
- * object_size: sizeof(your struct)
- * create_object: function called to create an object (can be NULL)
- * prepare_object: function called to prepare an object to returned to the client (can be NULL)
- * return_object: function called to prepare an object to returned to the pool (can be NULL)
- * delete_object: function called to delete an object (can be NULL)
- */
-xine_pool_t *xine_pool_new(size_t object_size,
- void (create_object)(void *object),
- void (prepare_object)(void *object),
- void (return_object)(void *object),
- void (delete_object)(void *object)) XINE_MALLOC XINE_PROTECTED;
-
-/* Deletes a pool */
-void xine_pool_delete(xine_pool_t *pool) XINE_PROTECTED;
-
-/* Get an object from the pool */
-void *xine_pool_get(xine_pool_t *pool) XINE_PROTECTED;
-
-/* Returns an object to the pool */
-void xine_pool_put(xine_pool_t *pool, void *object) XINE_PROTECTED;
diff --git a/src/xine-utils/ring_buffer.c b/src/xine-utils/ring_buffer.c
index da3e2450c..1da9d7c4d 100644
--- a/src/xine-utils/ring_buffer.c
+++ b/src/xine-utils/ring_buffer.c
@@ -27,10 +27,10 @@
#include <assert.h>
#include <stdio.h>
#include <string.h>
-#include "attributes.h"
-#include "pool.h"
-#include "list.h"
-#include "ring_buffer.h"
+#include <xine/attributes.h>
+#include <xine/pool.h>
+#include <xine/list.h>
+#include <xine/ring_buffer.h>
#define RING_BUFFER_EXTRA_BUFFER_SIZE (1024 * 8)
diff --git a/src/xine-utils/ring_buffer.h b/src/xine-utils/ring_buffer.h
deleted file mode 100644
index 7678aa903..000000000
--- a/src/xine-utils/ring_buffer.h
+++ /dev/null
@@ -1,55 +0,0 @@
-/*
- * Copyright (C) 2000-2006 the xine project
- *
- * This file is part of xine, a free video player.
- *
- * xine is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation; either version 2 of the License, or
- * (at your option) any later version.
- *
- * xine is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program; if not, write to the Free Software
- * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110, USA
- *
- * Fifo + Ring Buffer
- */
-typedef struct xine_ring_buffer_s xine_ring_buffer_t;
-
-/* Creates a new ring buffer */
-xine_ring_buffer_t *xine_ring_buffer_new(size_t size) XINE_MALLOC XINE_PROTECTED;
-
-/* Deletes a ring buffer */
-void xine_ring_buffer_delete(xine_ring_buffer_t *ring_buffer) XINE_PROTECTED;
-
-/* Returns a new chunk of the specified size */
-/* Might block if the ring buffer is full */
-void *xine_ring_buffer_alloc(xine_ring_buffer_t *ring_buffer, size_t size) XINE_PROTECTED;
-
-/* Put a chunk into the ring */
-void xine_ring_buffer_put(xine_ring_buffer_t *ring_buffer, void *chunk) XINE_PROTECTED;
-
-/* Get a chunk of a specified size from the ring buffer
- * Might block if the ring buffer is empty
- * param size: the desired size
- * param rsize: the size of the chunk returned
- * rsize is not equal to size at the end of stream, the caller MUST check
- * rsize value.
- */
-void *xine_ring_buffer_get(xine_ring_buffer_t *ring_buffer, size_t size, size_t *rsize) XINE_PROTECTED;
-
-/* Releases the chunk, makes memory available for the alloc function */
-void xine_ring_buffer_release(xine_ring_buffer_t *ring_buffer, void *chunk) XINE_PROTECTED;
-
-/* Closes the ring buffer
- * The writer uses this function to signal the end of stream to the reader.
- * The reader MUST check the rsize value returned by the get function.
- */
-void xine_ring_buffer_close(xine_ring_buffer_t *ring_buffer) XINE_PROTECTED;
-
-
diff --git a/src/xine-utils/sorted_array.c b/src/xine-utils/sorted_array.c
index 4bb618d4c..2f4bbeb0f 100644
--- a/src/xine-utils/sorted_array.c
+++ b/src/xine-utils/sorted_array.c
@@ -23,8 +23,8 @@
#include <stdlib.h>
#include <string.h>
-#include "attributes.h"
-#include "sorted_array.h"
+#include <xine/attributes.h>
+#include <xine/sorted_array.h>
/* Array internal struct */
struct xine_sarray_s {
diff --git a/src/xine-utils/sorted_array.h b/src/xine-utils/sorted_array.h
deleted file mode 100644
index 0d229199a..000000000
--- a/src/xine-utils/sorted_array.h
+++ /dev/null
@@ -1,94 +0,0 @@
-/*
- * Copyright (C) 2000-2006 the xine project
- *
- * This file is part of xine, a free video player.
- *
- * xine is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation; either version 2 of the License, or
- * (at your option) any later version.
- *
- * xine is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program; if not, write to the Free Software
- * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110, USA
- *
- * Sorted array which grows automatically when you add elements.
- * A binary search is used to find the position of a new element.
- *
- * Example:
- * Let's create de comparison method for integers:
- *
- * int int_comparator(void *a, void *b) {
- * if ((int)a < (int)b) {
- * return -1;
- * } else if ((int)a == (int)b) {
- * return 0;
- * } else {
- * return 1;
- * }
- * }
- *
- * Create a sorted array for integers:
- * xine_sarray_t *sarray = xine_sarray_new(10, int_comparator);
- *
- * Add elements:
- * xine_sarray_add(sarray, (void*)4);
- * xine_sarray_add(sarray, (void*)28);
- * xine_sarray_add(sarray, (void*)7);
- *
- * Find an element:
- * int pos = xine_sarray_binary_search(sarray, (void*)7);
- * if (pos >= 0)
- * FOUND
- * else
- * NOT FOUND
- *
- * Delete the array:
- * xine_sarray_delete(sarray);
- */
-#ifndef XINE_SORTED_ARRAY_H
-#define XINE_SORTED_ARRAY_H
-
-#include "array.h"
-
-/* Array type */
-typedef struct xine_sarray_s xine_sarray_t;
-
-/* Array element comparator */
-typedef int (*xine_sarray_comparator_t)(void*, void*);
-
-/* Constructor */
-xine_sarray_t *xine_sarray_new(size_t initial_size, xine_sarray_comparator_t comparator) XINE_MALLOC XINE_PROTECTED;
-
-/* Destructor */
-void xine_sarray_delete(xine_sarray_t *sarray) XINE_PROTECTED;
-
-/* Returns the number of element stored in the array */
-size_t xine_sarray_size(const xine_sarray_t *sarray) XINE_PROTECTED;
-
-/* Removes all elements from an array */
-void xine_sarray_clear(xine_sarray_t *sarray) XINE_PROTECTED;
-
-/* Adds the element into the array
- Returns the insertion position */
-int xine_sarray_add(xine_sarray_t *sarray, void *value) XINE_PROTECTED;
-
-/* Removes one element from an array at the position specified */
-void xine_sarray_remove(xine_sarray_t *sarray, unsigned int position) XINE_PROTECTED;
-
-/* Get the element at the position specified */
-void *xine_sarray_get(xine_sarray_t *sarray, unsigned int position) XINE_PROTECTED;
-
-/* Returns the index of the search key, if it is contained in the list.
- Otherwise, (-(insertion point) - 1) or ~(insertion point).
- The insertion point is defined as the point at which the key would be
- inserted into the array. */
-int xine_sarray_binary_search(xine_sarray_t *sarray, void *key) XINE_PROTECTED;
-
-#endif
-
diff --git a/src/xine-utils/utils.c b/src/xine-utils/utils.c
index 82cf5c0d4..e2aac22f5 100644
--- a/src/xine-utils/utils.c
+++ b/src/xine-utils/utils.c
@@ -27,10 +27,10 @@
#include "config.h"
#endif
-#include "xineutils.h"
-#include "xineintl.h"
+#include <xine/xineutils.h>
+#include <xine/xineintl.h>
#ifdef _MSC_VER
-#include "xine_internal.h"
+#include <xine/xine_internal.h>
#endif
#include "xine_private.h"
@@ -38,10 +38,10 @@
#include <pwd.h>
#include <sys/types.h>
#include <sys/time.h>
-#include <sys/socket.h>
#include <time.h>
#include <unistd.h>
#include <fcntl.h>
+#include <sys/socket.h>
#if HAVE_EXECINFO_H
#include <execinfo.h>
@@ -65,10 +65,10 @@
#endif
typedef struct {
- char *language; /* name of the locale */
- char *encoding; /* typical encoding */
- char *spu_encoding; /* default spu encoding */
- char *modifier;
+ const char language[16]; /* name of the locale */
+ const char encoding[16]; /* typical encoding */
+ const char spu_encoding[16]; /* default spu encoding */
+ const char modifier[8];
} lang_locale_t;
@@ -76,172 +76,172 @@ typedef struct {
* information about locales used in xine
*/
static const lang_locale_t lang_locales[] = {
- { "af_ZA", "iso-8859-1", "iso-8859-1", NULL },
- { "ar_AE", "iso-8859-6", "iso-8859-6", NULL },
- { "ar_BH", "iso-8859-6", "iso-8859-6", NULL },
- { "ar_DZ", "iso-8859-6", "iso-8859-6", NULL },
- { "ar_EG", "iso-8859-6", "iso-8859-6", NULL },
- { "ar_IN", "utf-8", "utf-8", NULL },
- { "ar_IQ", "iso-8859-6", "iso-8859-6", NULL },
- { "ar_JO", "iso-8859-6", "iso-8859-6", NULL },
- { "ar_KW", "iso-8859-6", "iso-8859-6", NULL },
- { "ar_LB", "iso-8859-6", "iso-8859-6", NULL },
- { "ar_LY", "iso-8859-6", "iso-8859-6", NULL },
- { "ar_MA", "iso-8859-6", "iso-8859-6", NULL },
- { "ar_OM", "iso-8859-6", "iso-8859-6", NULL },
- { "ar_QA", "iso-8859-6", "iso-8859-6", NULL },
- { "ar_SA", "iso-8859-6", "iso-8859-6", NULL },
- { "ar_SD", "iso-8859-6", "iso-8859-6", NULL },
- { "ar_SY", "iso-8859-6", "iso-8859-6", NULL },
- { "ar_TN", "iso-8859-6", "iso-8859-6", NULL },
- { "ar_YE", "iso-8859-6", "iso-8859-6", NULL },
- { "be_BY", "cp1251", "cp1251", NULL },
- { "bg_BG", "cp1251", "cp1251", NULL },
- { "br_FR", "iso-8859-1", "iso-88591", NULL },
- { "bs_BA", "iso-8859-2", "cp1250", NULL },
- { "ca_ES", "iso-8859-1", "iso-88591", NULL },
+ { "af_ZA", "iso-8859-1", "iso-8859-1", "" },
+ { "ar_AE", "iso-8859-6", "iso-8859-6", "" },
+ { "ar_BH", "iso-8859-6", "iso-8859-6", "" },
+ { "ar_DZ", "iso-8859-6", "iso-8859-6", "" },
+ { "ar_EG", "iso-8859-6", "iso-8859-6", "" },
+ { "ar_IN", "utf-8", "utf-8", "" },
+ { "ar_IQ", "iso-8859-6", "iso-8859-6", "" },
+ { "ar_JO", "iso-8859-6", "iso-8859-6", "" },
+ { "ar_KW", "iso-8859-6", "iso-8859-6", "" },
+ { "ar_LB", "iso-8859-6", "iso-8859-6", "" },
+ { "ar_LY", "iso-8859-6", "iso-8859-6", "" },
+ { "ar_MA", "iso-8859-6", "iso-8859-6", "" },
+ { "ar_OM", "iso-8859-6", "iso-8859-6", "" },
+ { "ar_QA", "iso-8859-6", "iso-8859-6", "" },
+ { "ar_SA", "iso-8859-6", "iso-8859-6", "" },
+ { "ar_SD", "iso-8859-6", "iso-8859-6", "" },
+ { "ar_SY", "iso-8859-6", "iso-8859-6", "" },
+ { "ar_TN", "iso-8859-6", "iso-8859-6", "" },
+ { "ar_YE", "iso-8859-6", "iso-8859-6", "" },
+ { "be_BY", "cp1251", "cp1251", "" },
+ { "bg_BG", "cp1251", "cp1251", "" },
+ { "br_FR", "iso-8859-1", "iso-88591", "" },
+ { "bs_BA", "iso-8859-2", "cp1250", "" },
+ { "ca_ES", "iso-8859-1", "iso-88591", "" },
{ "ca_ES", "iso-8859-15", "iso-8859-15", "euro" },
- { "cs_CZ", "iso-8859-2", "cp1250", NULL },
- { "cy_GB", "iso-8859-14", "iso-8859-14", NULL },
- { "da_DK", "iso-8859-1", "iso-8859-1", NULL },
- { "de_AT", "iso-8859-1", "iso-8859-1", NULL },
+ { "cs_CZ", "iso-8859-2", "cp1250", "" },
+ { "cy_GB", "iso-8859-14", "iso-8859-14", "" },
+ { "da_DK", "iso-8859-1", "iso-8859-1", "" },
+ { "de_AT", "iso-8859-1", "iso-8859-1", "" },
{ "de_AT", "iso-8859-15", "iso-8859-15", "euro" },
- { "de_BE", "iso-8859-1", "iso-8859-1", NULL },
+ { "de_BE", "iso-8859-1", "iso-8859-1", "" },
{ "de_BE", "iso-8859-15", "iso-8859-15", "euro" },
- { "de_CH", "iso-8859-1", "iso-8859-1", NULL },
- { "de_DE", "iso-8859-1", "iso-8859-1", NULL },
+ { "de_CH", "iso-8859-1", "iso-8859-1", "" },
+ { "de_DE", "iso-8859-1", "iso-8859-1", "" },
{ "de_DE", "iso-8859-15", "iso-8859-15", "euro" },
- { "de_LU", "iso-8859-1", "iso-8859-1", NULL },
+ { "de_LU", "iso-8859-1", "iso-8859-1", "" },
{ "de_LU", "iso-8859-15", "iso-8859-15", "euro" },
- { "el_GR", "iso-8859-7", "iso-8859-7", NULL },
- { "en_AU", "iso-8859-1", "iso-8859-1", NULL },
- { "en_BW", "iso-8859-1", "iso-8859-1", NULL },
- { "en_CA", "iso-8859-1", "iso-8859-1", NULL },
- { "en_DK", "iso-8859-1", "iso-8859-1", NULL },
- { "en_GB", "iso-8859-1", "iso-8859-1", NULL },
- { "en_HK", "iso-8859-1", "iso-8859-1", NULL },
- { "en_IE", "iso-8859-1", "iso-8859-1", NULL },
+ { "el_GR", "iso-8859-7", "iso-8859-7", "" },
+ { "en_AU", "iso-8859-1", "iso-8859-1", "" },
+ { "en_BW", "iso-8859-1", "iso-8859-1", "" },
+ { "en_CA", "iso-8859-1", "iso-8859-1", "" },
+ { "en_DK", "iso-8859-1", "iso-8859-1", "" },
+ { "en_GB", "iso-8859-1", "iso-8859-1", "" },
+ { "en_HK", "iso-8859-1", "iso-8859-1", "" },
+ { "en_IE", "iso-8859-1", "iso-8859-1", "" },
{ "en_IE", "iso-8859-15", "iso-8859-15", "euro" },
- { "en_IN", "utf-8", "utf-8", NULL },
- { "en_NZ", "iso-8859-1", "iso-8859-1", NULL },
- { "en_PH", "iso-8859-1", "iso-8859-1", NULL },
- { "en_SG", "iso-8859-1", "iso-8859-1", NULL },
- { "en_US", "iso-8859-1", "iso-8859-1", NULL },
- { "en_ZA", "iso-8859-1", "iso-8859-1", NULL },
- { "en_ZW", "iso-8859-1", "iso-8859-1", NULL },
- { "es_AR", "iso-8859-1", "iso-8859-1", NULL },
- { "es_BO", "iso-8859-1", "iso-8859-1", NULL },
- { "es_CL", "iso-8859-1", "iso-8859-1", NULL },
- { "es_CO", "iso-8859-1", "iso-8859-1", NULL },
- { "es_CR", "iso-8859-1", "iso-8859-1", NULL },
- { "es_DO", "iso-8859-1", "iso-8859-1", NULL },
- { "es_EC", "iso-8859-1", "iso-8859-1", NULL },
- { "es_ES", "iso-8859-1", "iso-8859-1", NULL },
+ { "en_IN", "utf-8", "utf-8", "" },
+ { "en_NZ", "iso-8859-1", "iso-8859-1", "" },
+ { "en_PH", "iso-8859-1", "iso-8859-1", "" },
+ { "en_SG", "iso-8859-1", "iso-8859-1", "" },
+ { "en_US", "iso-8859-1", "iso-8859-1", "" },
+ { "en_ZA", "iso-8859-1", "iso-8859-1", "" },
+ { "en_ZW", "iso-8859-1", "iso-8859-1", "" },
+ { "es_AR", "iso-8859-1", "iso-8859-1", "" },
+ { "es_BO", "iso-8859-1", "iso-8859-1", "" },
+ { "es_CL", "iso-8859-1", "iso-8859-1", "" },
+ { "es_CO", "iso-8859-1", "iso-8859-1", "" },
+ { "es_CR", "iso-8859-1", "iso-8859-1", "" },
+ { "es_DO", "iso-8859-1", "iso-8859-1", "" },
+ { "es_EC", "iso-8859-1", "iso-8859-1", "" },
+ { "es_ES", "iso-8859-1", "iso-8859-1", "" },
{ "es_ES", "iso-8859-15", "iso-8859-15", "euro" },
- { "es_GT", "iso-8859-1", "iso-8859-1", NULL },
- { "es_HN", "iso-8859-1", "iso-8859-1", NULL },
- { "es_MX", "iso-8859-1", "iso-8859-1", NULL },
- { "es_NI", "iso-8859-1", "iso-8859-1", NULL },
- { "es_PA", "iso-8859-1", "iso-8859-1", NULL },
- { "es_PE", "iso-8859-1", "iso-8859-1", NULL },
- { "es_PR", "iso-8859-1", "iso-8859-1", NULL },
- { "es_PY", "iso-8859-1", "iso-8859-1", NULL },
- { "es_SV", "iso-8859-1", "iso-8859-1", NULL },
- { "es_US", "iso-8859-1", "iso-8859-1", NULL },
- { "es_UY", "iso-8859-1", "iso-8859-1", NULL },
- { "es_VE", "iso-8859-1", "iso-8859-1", NULL },
- { "et_EE", "iso-8859-1", "iso-8859-1", NULL },
- { "eu_ES", "iso-8859-1", "iso-8859-1", NULL },
+ { "es_GT", "iso-8859-1", "iso-8859-1", "" },
+ { "es_HN", "iso-8859-1", "iso-8859-1", "" },
+ { "es_MX", "iso-8859-1", "iso-8859-1", "" },
+ { "es_NI", "iso-8859-1", "iso-8859-1", "" },
+ { "es_PA", "iso-8859-1", "iso-8859-1", "" },
+ { "es_PE", "iso-8859-1", "iso-8859-1", "" },
+ { "es_PR", "iso-8859-1", "iso-8859-1", "" },
+ { "es_PY", "iso-8859-1", "iso-8859-1", "" },
+ { "es_SV", "iso-8859-1", "iso-8859-1", "" },
+ { "es_US", "iso-8859-1", "iso-8859-1", "" },
+ { "es_UY", "iso-8859-1", "iso-8859-1", "" },
+ { "es_VE", "iso-8859-1", "iso-8859-1", "" },
+ { "et_EE", "iso-8859-1", "iso-8859-1", "" },
+ { "eu_ES", "iso-8859-1", "iso-8859-1", "" },
{ "eu_ES", "iso-8859-15", "iso-8859-15", "euro" },
- { "fa_IR", "utf-8", "utf-8", NULL },
- { "fi_FI", "iso-8859-1", "iso-8859-1", NULL },
+ { "fa_IR", "utf-8", "utf-8", "" },
+ { "fi_FI", "iso-8859-1", "iso-8859-1", "" },
{ "fi_FI", "iso-8859-15", "iso-8859-15", "euro" },
- { "fo_FO", "iso-8859-1", "iso-8859-1", NULL },
- { "fr_BE", "iso-8859-1", "iso-8859-1", NULL },
+ { "fo_FO", "iso-8859-1", "iso-8859-1", "" },
+ { "fr_BE", "iso-8859-1", "iso-8859-1", "" },
{ "fr_BE", "iso-8859-15", "iso-8859-15", "euro" },
- { "fr_CA", "iso-8859-1", "iso-8859-1", NULL },
- { "fr_CH", "iso-8859-1", "iso-8859-1", NULL },
- { "fr_FR", "iso-8859-1", "iso-8859-1", NULL },
+ { "fr_CA", "iso-8859-1", "iso-8859-1", "" },
+ { "fr_CH", "iso-8859-1", "iso-8859-1", "" },
+ { "fr_FR", "iso-8859-1", "iso-8859-1", "" },
{ "fr_FR", "iso-8859-15", "iso-8859-15", "euro" },
- { "fr_LU", "iso-8859-1", "iso-8859-1", NULL },
+ { "fr_LU", "iso-8859-1", "iso-8859-1", "" },
{ "fr_LU", "iso-8859-15", "iso-8859-15", "euro" },
- { "ga_IE", "iso-8859-1", "iso-8859-1", NULL },
+ { "ga_IE", "iso-8859-1", "iso-8859-1", "" },
{ "ga_IE", "iso-8859-15", "iso-8859-15", "euro" },
- { "gl_ES", "iso-8859-1", "iso-8859-1", NULL },
+ { "gl_ES", "iso-8859-1", "iso-8859-1", "" },
{ "gl_ES", "iso-8859-15", "iso-8859-15", "euro" },
- { "gv_GB", "iso-8859-1", "iso-8859-1", NULL },
- { "he_IL", "iso-8859-8", "iso-8859-8", NULL },
- { "hi_IN", "utf-8", "utf-8", NULL },
- { "hr_HR", "iso-8859-2", "cp1250", NULL },
- { "hu_HU", "iso-8859-2", "cp1250", NULL },
- { "id_ID", "iso-8859-1", "iso-8859-1", NULL },
- { "is_IS", "iso-8859-1", "iso-8859-1", NULL },
- { "it_CH", "iso-8859-1", "iso-8859-1", NULL },
- { "it_IT", "iso-8859-1", "iso-8859-1", NULL },
+ { "gv_GB", "iso-8859-1", "iso-8859-1", "" },
+ { "he_IL", "iso-8859-8", "iso-8859-8", "" },
+ { "hi_IN", "utf-8", "utf-8", "" },
+ { "hr_HR", "iso-8859-2", "cp1250", "" },
+ { "hu_HU", "iso-8859-2", "cp1250", "" },
+ { "id_ID", "iso-8859-1", "iso-8859-1", "" },
+ { "is_IS", "iso-8859-1", "iso-8859-1", "" },
+ { "it_CH", "iso-8859-1", "iso-8859-1", "" },
+ { "it_IT", "iso-8859-1", "iso-8859-1", "" },
{ "it_IT", "iso-8859-15", "iso-8859-15", "euro" },
- { "iw_IL", "iso-8859-8", "iso-8859-8", NULL },
- { "ja_JP", "euc-jp", "euc-jp", NULL },
- { "ja_JP", "ujis", "ujis", NULL },
- { "japanese", "euc", "euc", NULL },
- { "ka_GE", "georgian-ps", "georgian-ps", NULL },
- { "kl_GL", "iso-8859-1", "iso-8859-1", NULL },
- { "ko_KR", "euc-kr", "euc-kr", NULL },
- { "ko_KR", "utf-8", "utf-8", NULL },
- { "korean", "euc", "euc", NULL },
- { "kw_GB", "iso-8859-1", "iso-8859-1", NULL },
- { "lt_LT", "iso-8859-13", "iso-8859-13", NULL },
- { "lv_LV", "iso-8859-13", "iso-8859-13", NULL },
- { "mi_NZ", "iso-8859-13", "iso-8859-13", NULL },
- { "mk_MK", "iso-8859-5", "cp1251", NULL },
- { "mr_IN", "utf-8", "utf-8", NULL },
- { "ms_MY", "iso-8859-1", "iso-8859-1", NULL },
- { "mt_MT", "iso-8859-3", "iso-8859-3", NULL },
- { "nb_NO", "ISO-8859-1", "ISO-8859-1", NULL },
- { "nl_BE", "iso-8859-1", "iso-8859-1", NULL },
+ { "iw_IL", "iso-8859-8", "iso-8859-8", "" },
+ { "ja_JP", "euc-jp", "euc-jp", "" },
+ { "ja_JP", "ujis", "ujis", "" },
+ { "japanese", "euc", "euc", "" },
+ { "ka_GE", "georgian-ps", "georgian-ps", "" },
+ { "kl_GL", "iso-8859-1", "iso-8859-1", "" },
+ { "ko_KR", "euc-kr", "euc-kr", "" },
+ { "ko_KR", "utf-8", "utf-8", "" },
+ { "korean", "euc", "euc", "" },
+ { "kw_GB", "iso-8859-1", "iso-8859-1", "" },
+ { "lt_LT", "iso-8859-13", "iso-8859-13", "" },
+ { "lv_LV", "iso-8859-13", "iso-8859-13", "" },
+ { "mi_NZ", "iso-8859-13", "iso-8859-13", "" },
+ { "mk_MK", "iso-8859-5", "cp1251", "" },
+ { "mr_IN", "utf-8", "utf-8", "" },
+ { "ms_MY", "iso-8859-1", "iso-8859-1", "" },
+ { "mt_MT", "iso-8859-3", "iso-8859-3", "" },
+ { "nb_NO", "ISO-8859-1", "ISO-8859-1", "" },
+ { "nl_BE", "iso-8859-1", "iso-8859-1", "" },
{ "nl_BE", "iso-8859-15", "iso-8859-15", "euro" },
- { "nl_NL", "iso-8859-1", "iso-8859-1", NULL },
+ { "nl_NL", "iso-8859-1", "iso-8859-1", "" },
{ "nl_NL", "iso-8859-15", "iso-8859-15", "euro" },
- { "nn_NO", "iso-8859-1", "iso-8859-1", NULL },
- { "no_NO", "iso-8859-1", "iso-8859-1", NULL },
- { "oc_FR", "iso-8859-1", "iso-8859-1", NULL },
- { "pl_PL", "iso-8859-2", "cp1250", NULL },
- { "pt_BR", "iso-8859-1", "iso-8859-1", NULL },
- { "pt_PT", "iso-8859-1", "iso-8859-1", NULL },
+ { "nn_NO", "iso-8859-1", "iso-8859-1", "" },
+ { "no_NO", "iso-8859-1", "iso-8859-1", "" },
+ { "oc_FR", "iso-8859-1", "iso-8859-1", "" },
+ { "pl_PL", "iso-8859-2", "cp1250", "" },
+ { "pt_BR", "iso-8859-1", "iso-8859-1", "" },
+ { "pt_PT", "iso-8859-1", "iso-8859-1", "" },
{ "pt_PT", "iso-8859-15", "iso-8859-15", "euro" },
- { "ro_RO", "iso-8859-2", "cp1250", NULL },
- { "ru_RU", "iso-8859-5", "cp1251", NULL },
- { "ru_RU", "koi8-r", "cp1251", NULL },
- { "ru_UA", "koi8-u", "cp1251", NULL },
- { "se_NO", "utf-8", "utf-8", NULL },
- { "sk_SK", "iso-8859-2", "cp1250", NULL },
- { "sl_SI", "iso-8859-2", "cp1250", NULL },
- { "sq_AL", "iso-8859-1", "iso-8859-1", NULL },
- { "sr_YU", "iso-8859-2", "cp1250", NULL },
+ { "ro_RO", "iso-8859-2", "cp1250", "" },
+ { "ru_RU", "iso-8859-5", "cp1251", "" },
+ { "ru_RU", "koi8-r", "cp1251", "" },
+ { "ru_UA", "koi8-u", "cp1251", "" },
+ { "se_NO", "utf-8", "utf-8", "" },
+ { "sk_SK", "iso-8859-2", "cp1250", "" },
+ { "sl_SI", "iso-8859-2", "cp1250", "" },
+ { "sq_AL", "iso-8859-1", "iso-8859-1", "" },
+ { "sr_YU", "iso-8859-2", "cp1250", "" },
{ "sr_YU", "iso-8859-5", "cp1251", "cyrillic" },
- { "sv_FI", "iso-8859-1", "iso-8859-1", NULL },
+ { "sv_FI", "iso-8859-1", "iso-8859-1", "" },
{ "sv_FI", "iso-8859-15", "iso-8859-15", "euro" },
- { "sv_SE", "iso-8859-1", "iso-8859-1", NULL },
- { "ta_IN", "utf-8", "utf-8", NULL },
- { "te_IN", "utf-8", "utf-8", NULL },
- { "tg_TJ", "koi8-t", "cp1251", NULL },
- { "th_TH", "tis-620", "tis-620", NULL },
- { "tl_PH", "iso-8859-1", "iso-8859-1", NULL },
- { "tr_TR", "iso-8859-9", "iso-8859-9", NULL },
- { "uk_UA", "koi8-u", "cp1251", NULL },
- { "ur_PK", "utf-8", "utf-8", NULL },
- { "uz_UZ", "iso-8859-1", "iso-8859-1", NULL },
- { "vi_VN", "tcvn", "tcvn", NULL },
- { "vi_VN", "utf-8", "utf-8", NULL },
- { "wa_BE", "iso-8859-1", "iso-8859-1", NULL },
+ { "sv_SE", "iso-8859-1", "iso-8859-1", "" },
+ { "ta_IN", "utf-8", "utf-8", "" },
+ { "te_IN", "utf-8", "utf-8", "" },
+ { "tg_TJ", "koi8-t", "cp1251", "" },
+ { "th_TH", "tis-620", "tis-620", "" },
+ { "tl_PH", "iso-8859-1", "iso-8859-1", "" },
+ { "tr_TR", "iso-8859-9", "iso-8859-9", "" },
+ { "uk_UA", "koi8-u", "cp1251", "" },
+ { "ur_PK", "utf-8", "utf-8", "" },
+ { "uz_UZ", "iso-8859-1", "iso-8859-1", "" },
+ { "vi_VN", "tcvn", "tcvn", "" },
+ { "vi_VN", "utf-8", "utf-8", "" },
+ { "wa_BE", "iso-8859-1", "iso-8859-1", "" },
{ "wa_BE", "iso-8859-15", "iso-8859-15", "euro" },
- { "yi_US", "cp1255", "cp1255", NULL },
- { "zh_CN", "gb18030", "gb18030", NULL },
- { "zh_CN", "gb2312", "gb2312", NULL },
- { "zh_CN", "gbk", "gbk", NULL },
- { "zh_HK", "big5-hkscs", "big5-hkscs", NULL },
- { "zh_TW", "big-5", "big-5", NULL },
- { "zh_TW", "euc-tw", "euc-tw", NULL },
- { NULL, NULL, NULL, NULL }
+ { "yi_US", "cp1255", "cp1255", "" },
+ { "zh_CN", "gb18030", "gb18030", "" },
+ { "zh_CN", "gb2312", "gb2312", "" },
+ { "zh_CN", "gbk", "gbk", "" },
+ { "zh_HK", "big5-hkscs", "big5-hkscs", "" },
+ { "zh_TW", "big-5", "big-5", "" },
+ { "zh_TW", "euc-tw", "euc-tw", "" },
+ { "" }
};
/**
@@ -279,16 +279,38 @@ void *xine_xmalloc(size_t size) {
return ptr;
}
-void *xine_xmalloc_aligned(size_t alignment, size_t size, void **base) {
+/**
+ * @brief Wrapper around calloc() function.
+ * @param nmemb Number of elements to allocate
+ * @param size Size of each element to allocate
+ *
+ * This is a simple wrapper around calloc(), the only thing
+ * it does more than calloc() is outputting an error if
+ * the calloc fails (returning NULL).
+ */
+void *xine_xcalloc(size_t nmemb, size_t size) {
+ void *ptr;
- char *ptr;
+ if((ptr = calloc(nmemb, size)) == NULL) {
+ fprintf(stderr, "%s: calloc() failed: %s.\n",
+ __XINE_FUNCTION__, strerror(errno));
+ return NULL;
+ }
- *base = ptr = calloc(1, size+alignment);
+ return ptr;
+}
- while ((size_t) ptr % alignment)
- ptr++;
+void *xine_memdup (const void *src, size_t length)
+{
+ void *dst = malloc (length);
+ return xine_fast_memcpy (dst, src, length);
+}
- return ptr;
+void *xine_memdup0 (const void *src, size_t length)
+{
+ char *dst = xine_xmalloc (length + 1);
+ dst[length] = 0;
+ return xine_fast_memcpy (dst, src, length);
}
#ifdef WIN32
@@ -493,38 +515,36 @@ void xine_usec_sleep(unsigned usec) {
/* print a hexdump of length bytes from the data given in buf */
-void xine_hexdump (const char *buf, int length) {
- int i,j;
- unsigned char c;
+void xine_hexdump (const void *buf_gen, int length) {
+ static const char separator[70] = "---------------------------------------------------------------------";
+
+ const uint8_t *const buf = (const uint8_t*)buf_gen;
+ int j = 0;
/* printf ("Hexdump: %i Bytes\n", length);*/
- for(j=0; j<69; j++)
- printf ("-");
- printf ("\n");
+ puts(separator);
- j=0;
while(j<length) {
+ int i;
+ const int imax = (j+16 < length) ? (j+16) : length;
+
printf ("%04X ",j);
for (i=j; i<j+16; i++) {
if( i<length )
- printf ("%02X ", (unsigned char) buf[i]);
+ printf ("%02X ", buf[i]);
else
printf(" ");
}
- for (i=j;i<(j+16<length?j+16:length);i++) {
- c=buf[i];
- if ((c>=32) && (c<127))
- printf ("%c", c);
- else
- printf (".");
+
+ for (i=j; i < imax; i++) {
+ fputc ((buf[i] >= 32 && buf[i] <= 126) ? buf[i] : '.', stdout);
}
j=i;
- printf("\n");
+
+ fputc('\n', stdout);
}
- for(j=0; j<69; j++)
- printf("-");
- printf("\n");
+ puts(separator);
}
@@ -541,7 +561,7 @@ static const lang_locale_t *_get_first_lang_locale(const char *lcal) {
else
lang_len = strlen(lcal);
- while(llocale->language) {
+ while(*(llocale->language)) {
if(!strncmp(lcal, llocale->language, lang_len)) {
if ((!mod && !llocale->modifier) || (mod && llocale->modifier && !strcmp(mod, llocale->modifier)))
return llocale;
diff --git a/src/xine-utils/xine_buffer.c b/src/xine-utils/xine_buffer.c
index b1cfcf76b..436991b33 100644
--- a/src/xine-utils/xine_buffer.c
+++ b/src/xine-utils/xine_buffer.c
@@ -62,7 +62,7 @@
#define LOG
*/
-#include "xineutils.h"
+#include <xine/xineutils.h>
#define CHECKS
diff --git a/src/xine-utils/xine_buffer.h b/src/xine-utils/xine_buffer.h
deleted file mode 100644
index f88a21aef..000000000
--- a/src/xine-utils/xine_buffer.h
+++ /dev/null
@@ -1,136 +0,0 @@
-/*
- * Copyright (C) 2000-2004 the xine project
- *
- * This file is part of xine, a free video player.
- *
- * xine is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation; either version 2 of the License, or
- * (at your option) any later version.
- *
- * xine is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program; if not, write to the Free Software
- * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110, USA
- *
- *
- * generic dynamic buffer functions. The goals
- * of these functions are (in fact many of these points
- * are todos):
- * - dynamic allocation and reallocation depending
- * on the size of data written to it.
- * - fast and transparent access to the data.
- * The user sees only the raw data chunk as it is
- * returned by the well-known malloc function.
- * This is necessary since not all data-accessing
- * functions can be wrapped here.
- * - some additional health checks are made during
- * development (eg boundary checks after direct
- * access to a buffer). This can be turned off in
- * production state for higher performance.
- * - A lot of convenient string and memory manipulation
- * functions are implemented here, where the user
- * do not have to care about memory chunk sizes.
- * - Some garbage collention could be implemented as well;
- * i think of a global structure containing infos
- * about all allocated chunks. This must be implemented
- * in a thread-save way...
- *
- * Here are some drawbacks (aka policies):
- * - The user must not pass indexed buffers to xine_buffer_*
- * functions.
- * - The pointers passed to xine_buffer_* functions may change
- * (eg during reallocation). The user must respect that.
- */
-
-#ifndef HAVE_XINE_BUFFER_H
-#define HAVE_XINE_BUFFER_H
-
-#ifdef XINE_COMPILE
-# include <inttypes.h>
-#else
-# include <xine/os_types.h>
-#endif
-
-/*
- * returns an initialized pointer to a buffer.
- * The buffer will be allocated in blocks of
- * chunk_size bytes. This will prevent permanent
- * reallocation on slow growing buffers.
- */
-void *xine_buffer_init(int chunk_size) XINE_PROTECTED;
-
-/*
- * frees a buffer, the macro ensures, that a freed
- * buffer pointer is set to NULL
- */
-#define xine_buffer_free(buf) buf=_xine_buffer_free(buf)
-void *_xine_buffer_free(void *buf) XINE_PROTECTED;
-
-/*
- * duplicates a buffer
- */
-void *xine_buffer_dup(const void *buf) XINE_PROTECTED;
-
-/*
- * will copy len bytes of data into buf at position index.
- */
-#define xine_buffer_copyin(buf,i,data,len) \
- buf=_xine_buffer_copyin(buf,i,data,len)
-void *_xine_buffer_copyin(void *buf, int index, const void *data, int len) XINE_PROTECTED;
-
-/*
- * will copy len bytes out of buf+index into data.
- * no checks are made in data. It is treated as an ordinary
- * user-malloced data chunk.
- */
-void xine_buffer_copyout(const void *buf, int index, void *data, int len) XINE_PROTECTED;
-
-/*
- * set len bytes in buf+index to b.
- */
-#define xine_buffer_set(buf,i,b,len) \
- buf=_xine_buffer_set(buf,i,b,len)
-void *_xine_buffer_set(void *buf, int index, uint8_t b, int len) XINE_PROTECTED;
-
-/*
- * concatenates given buf (which should contain a null terminated string)
- * with another string.
- */
-#define xine_buffer_strcat(buf,data) \
- buf=_xine_buffer_strcat(buf,data)
-void *_xine_buffer_strcat(void *buf, const char *data) XINE_PROTECTED;
-
-/*
- * copies given string to buf+index
- */
-#define xine_buffer_strcpy(buf,index,data) \
- buf=_xine_buffer_strcpy(buf,index,data)
-void *_xine_buffer_strcpy(void *buf, int index, const char *data) XINE_PROTECTED;
-
-/*
- * returns a pointer to the first occurence of ch.
- * note, that the returned pointer cannot be used
- * in any other xine_buffer_* functions.
- */
-char *xine_buffer_strchr(const void *buf, int ch) XINE_PROTECTED;
-
-/*
- * get allocated memory size
- */
-int xine_buffer_get_size(const void *buf) XINE_PROTECTED;
-
-/*
- * ensures a specified buffer size if the user want to
- * write directly to the buffer. Normally the special
- * access functions defined here should be used.
- */
-#define xine_buffer_ensure_size(buf,data) \
- buf=_xine_buffer_ensure_size(buf,data)
-void *_xine_buffer_ensure_size(void *buf, int size) XINE_PROTECTED;
-
-#endif
diff --git a/src/xine-utils/xine_check.c b/src/xine-utils/xine_check.c
index 1b8c65130..e6323dceb 100644
--- a/src/xine-utils/xine_check.c
+++ b/src/xine-utils/xine_check.c
@@ -44,7 +44,7 @@
#include <fcntl.h>
#include <unistd.h>
-#include "xineutils.h"
+#include <xine/xineutils.h>
#ifndef O_CLOEXEC
# define O_CLOEXEC 0
diff --git a/src/xine-utils/xine_mutex.c b/src/xine-utils/xine_mutex.c
index e53de574b..64722e0be 100644
--- a/src/xine-utils/xine_mutex.c
+++ b/src/xine-utils/xine_mutex.c
@@ -24,7 +24,7 @@
#include <stdio.h>
#include <pthread.h>
-#include "xineutils.h"
+#include <xine/xineutils.h>
/*
#define DBG_MUTEX
diff --git a/src/xine-utils/xineutils.h b/src/xine-utils/xineutils.h
deleted file mode 100644
index 5b16e6e3c..000000000
--- a/src/xine-utils/xineutils.h
+++ /dev/null
@@ -1,546 +0,0 @@
-/*
- * Copyright (C) 2000-2006 the xine project
- *
- * This file is part of xine, a free video player.
- *
- * xine is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation; either version 2 of the License, or
- * (at your option) any later version.
- *
- * xine is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program; if not, write to the Free Software
- * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110, USA
- */
-#ifndef XINEUTILS_H
-#define XINEUTILS_H
-
-#ifdef __cplusplus
-extern "C" {
-#endif
-
-#include <stdlib.h>
-#include <string.h>
-#include <stdarg.h>
-#include <pthread.h>
-
-#ifdef XINE_COMPILE
-# include <inttypes.h>
-# include "attributes.h"
-# include "compat.h"
-# include "xmlparser.h"
-# include "xine_buffer.h"
-# include "configfile.h"
-# include "list.h"
-# include "array.h"
-# include "sorted_array.h"
-# include "xine_mmx.h"
-#else
-# ifdef WIN32
-# include <winsock.h>
-# else
-# include <sys/time.h>
-# endif
-# include <xine/os_types.h>
-# include <xine/attributes.h>
-# include <xine/compat.h>
-# include <xine/xmlparser.h>
-# include <xine/xine_buffer.h>
-# include <xine/configfile.h>
-# include <xine/list.h>
-# include <xine/array.h>
-# include <xine/sorted_array.h>
-# include <xine/xine_mmx.h>
-#endif
-
-#include <stdio.h>
-#include <string.h>
-
-/*
- * Mark exported data symbols for link engine library clients with older
- * Win32 compilers
- */
-#if defined(WIN32) && !defined(XINE_LIBRARY_COMPILE)
-# define DL_IMPORT __declspec(dllimport)
-# define extern DL_IMPORT extern
-#endif
-
- /*
- * debugable mutexes
- */
-
- typedef struct {
- pthread_mutex_t mutex;
- char id[80];
- char *locked_by;
- } xine_mutex_t;
-
- int xine_mutex_init (xine_mutex_t *mutex, const pthread_mutexattr_t *mutexattr,
- const char *id) XINE_PROTECTED;
-
- int xine_mutex_lock (xine_mutex_t *mutex, const char *who) XINE_PROTECTED;
- int xine_mutex_unlock (xine_mutex_t *mutex, const char *who) XINE_PROTECTED;
- int xine_mutex_destroy (xine_mutex_t *mutex) XINE_PROTECTED;
-
-
-
- /* CPU Acceleration */
-
-/*
- * The type of an value that fits in an MMX register (note that long
- * long constant values MUST be suffixed by LL and unsigned long long
- * values by ULL, lest they be truncated by the compiler)
- */
-
-/* generic accelerations */
-#define MM_ACCEL_MLIB 0x00000001
-
-/* x86 accelerations */
-#define MM_ACCEL_X86_MMX 0x80000000
-#define MM_ACCEL_X86_3DNOW 0x40000000
-#define MM_ACCEL_X86_MMXEXT 0x20000000
-#define MM_ACCEL_X86_SSE 0x10000000
-#define MM_ACCEL_X86_SSE2 0x08000000
-
-/* powerpc accelerations and features */
-#define MM_ACCEL_PPC_ALTIVEC 0x04000000
-#define MM_ACCEL_PPC_CACHE32 0x02000000
-
-/* SPARC accelerations */
-
-#define MM_ACCEL_SPARC_VIS 0x01000000
-#define MM_ACCEL_SPARC_VIS2 0x00800000
-
-/* x86 compat defines */
-#define MM_MMX MM_ACCEL_X86_MMX
-#define MM_3DNOW MM_ACCEL_X86_3DNOW
-#define MM_MMXEXT MM_ACCEL_X86_MMXEXT
-#define MM_SSE MM_ACCEL_X86_SSE
-#define MM_SSE2 MM_ACCEL_X86_SSE2
-
-uint32_t xine_mm_accel (void) XINE_CONST XINE_PROTECTED;
-
-
-
- /* Optimized/fast memcpy */
-
-extern void *(* xine_fast_memcpy)(void *to, const void *from, size_t len) XINE_PROTECTED;
-
-#ifdef HAVE_XINE_INTERNAL_H
-/* Benchmark available memcpy methods */
-void xine_probe_fast_memcpy(xine_t *xine) XINE_PROTECTED;
-#endif
-
-
-/*
- * Debug stuff
- */
-/*
- * profiling (unworkable in non DEBUG isn't defined)
- */
-void xine_profiler_init (void) XINE_PROTECTED;
-int xine_profiler_allocate_slot (const char *label) XINE_PROTECTED;
-void xine_profiler_start_count (int id) XINE_PROTECTED;
-void xine_profiler_stop_count (int id) XINE_PROTECTED;
-void xine_profiler_print_results (void) XINE_PROTECTED;
-
-/*
- * Allocate and clean memory size_t 'size', then return the pointer
- * to the allocated memory.
- */
-void *xine_xmalloc(size_t size) XINE_MALLOC XINE_DEPRECATED XINE_PROTECTED;
-
-/*
- * Same as above, but memory is aligned to 'alignement'.
- * **base is used to return pointer to un-aligned memory, use
- * this to free the mem chunk
- */
-void *xine_xmalloc_aligned(size_t alignment, size_t size, void **base) XINE_PROTECTED;
-
-/*
- * Get user home directory.
- */
-const char *xine_get_homedir(void) XINE_PROTECTED;
-
-#if defined(WIN32) || defined(__CYGWIN__)
-/*
- * Get other xine directories.
- */
-const char *xine_get_pluginroot(void) XINE_PROTECTED;
-const char *xine_get_plugindir(void) XINE_PROTECTED;
-const char *xine_get_fontdir(void) XINE_PROTECTED;
-const char *xine_get_localedir(void) XINE_PROTECTED;
-#endif
-
-/*
- * Clean a string (remove spaces and '=' at the begin,
- * and '\n', '\r' and spaces at the end.
- */
-char *xine_chomp (char *str) XINE_PROTECTED;
-
-/*
- * A thread-safe usecond sleep
- */
-void xine_usec_sleep(unsigned usec) XINE_PROTECTED;
-
-
- /*
- * Some string functions
- */
-
-
-void xine_strdupa(char *dest, char *src) XINE_PROTECTED XINE_DEPRECATED;
-#define xine_strdupa(d, s) do { \
- (d) = NULL; \
- if((s) != NULL) { \
- (d) = (char *) alloca(strlen((s)) + 1); \
- strcpy((d), (s)); \
- } \
- } while(0)
-
-/* compatibility macros */
-#define xine_strpbrk(S, ACCEPT) strpbrk((S), (ACCEPT))
-#define xine_strsep(STRINGP, DELIM) strsep((STRINGP), (DELIM))
-#define xine_setenv(NAME, VAL, XX) setenv((NAME), (VAL), (XX))
-
-/**
- * append to a string, reallocating
- * normally, updates & returns *dest
- * on error, *dest is unchanged & NULL is returned.
- */
-char *xine_strcat_realloc (char **dest, char *append) XINE_PROTECTED;
-
-/**
- * asprintf wrapper
- * allocate a string large enough to hold the output, and return a pointer to
- * it. This pointer should be passed to free when it is no longer needed.
- * return NULL on error.
- */
-char *_x_asprintf(const char *format, ...) XINE_PROTECTED XINE_MALLOC XINE_FORMAT_PRINTF(1, 2);
-
-/**
- * opens a file, ensuring that the descriptor will be closed
- * automatically after a fork/execute.
- */
-int xine_open_cloexec(const char *name, int flags) XINE_PROTECTED;
-
-/**
- * creates a file, ensuring that the descriptor will be closed
- * automatically after a fork/execute.
- */
-int xine_create_cloexec(const char *name, int flags, mode_t mode) XINE_PROTECTED;
-
-/**
- * creates a socket, ensuring that the descriptor will be closed
- * automatically after a fork/execute.
- */
-int xine_socket_cloexec(int domain, int type, int protocol) XINE_PROTECTED;
-
-/*
- * Color Conversion Utility Functions
- * The following data structures and functions facilitate the conversion
- * of RGB images to packed YUV (YUY2) images. There are also functions to
- * convert from YUV9 -> YV12. All of the meaty details are written in
- * color.c.
- */
-
-typedef struct yuv_planes_s {
-
- unsigned char *y;
- unsigned char *u;
- unsigned char *v;
- unsigned int row_width; /* frame width */
- unsigned int row_count; /* frame height */
-
-} yuv_planes_t;
-
-void init_yuv_conversion(void) XINE_PROTECTED;
-void init_yuv_planes(yuv_planes_t *yuv_planes, int width, int height) XINE_PROTECTED;
-void free_yuv_planes(yuv_planes_t *yuv_planes) XINE_PROTECTED;
-
-extern void (*yuv444_to_yuy2)
- (const yuv_planes_t *yuv_planes, unsigned char *yuy2_map, int pitch) XINE_PROTECTED;
-extern void (*yuv9_to_yv12)
- (const unsigned char *y_src, int y_src_pitch, unsigned char *y_dest, int y_dest_pitch,
- const unsigned char *u_src, int u_src_pitch, unsigned char *u_dest, int u_dest_pitch,
- const unsigned char *v_src, int v_src_pitch, unsigned char *v_dest, int v_dest_pitch,
- int width, int height) XINE_PROTECTED;
-extern void (*yuv411_to_yv12)
- (const unsigned char *y_src, int y_src_pitch, unsigned char *y_dest, int y_dest_pitch,
- const unsigned char *u_src, int u_src_pitch, unsigned char *u_dest, int u_dest_pitch,
- const unsigned char *v_src, int v_src_pitch, unsigned char *v_dest, int v_dest_pitch,
- int width, int height) XINE_PROTECTED;
-extern void (*yv12_to_yuy2)
- (const unsigned char *y_src, int y_src_pitch,
- const unsigned char *u_src, int u_src_pitch,
- const unsigned char *v_src, int v_src_pitch,
- unsigned char *yuy2_map, int yuy2_pitch,
- int width, int height, int progressive) XINE_PROTECTED;
-extern void (*yuy2_to_yv12)
- (const unsigned char *yuy2_map, int yuy2_pitch,
- unsigned char *y_dst, int y_dst_pitch,
- unsigned char *u_dst, int u_dst_pitch,
- unsigned char *v_dst, int v_dst_pitch,
- int width, int height) XINE_PROTECTED;
-
-#define SCALEFACTOR 65536
-#define CENTERSAMPLE 128
-
-#define COMPUTE_Y(r, g, b) \
- (unsigned char) \
- ((y_r_table[r] + y_g_table[g] + y_b_table[b]) / SCALEFACTOR)
-#define COMPUTE_U(r, g, b) \
- (unsigned char) \
- ((u_r_table[r] + u_g_table[g] + u_b_table[b]) / SCALEFACTOR + CENTERSAMPLE)
-#define COMPUTE_V(r, g, b) \
- (unsigned char) \
- ((v_r_table[r] + v_g_table[g] + v_b_table[b]) / SCALEFACTOR + CENTERSAMPLE)
-
-#define UNPACK_BGR15(packed_pixel, r, g, b) \
- b = (packed_pixel & 0x7C00) >> 7; \
- g = (packed_pixel & 0x03E0) >> 2; \
- r = (packed_pixel & 0x001F) << 3;
-
-#define UNPACK_BGR16(packed_pixel, r, g, b) \
- b = (packed_pixel & 0xF800) >> 8; \
- g = (packed_pixel & 0x07E0) >> 3; \
- r = (packed_pixel & 0x001F) << 3;
-
-#define UNPACK_RGB15(packed_pixel, r, g, b) \
- r = (packed_pixel & 0x7C00) >> 7; \
- g = (packed_pixel & 0x03E0) >> 2; \
- b = (packed_pixel & 0x001F) << 3;
-
-#define UNPACK_RGB16(packed_pixel, r, g, b) \
- r = (packed_pixel & 0xF800) >> 8; \
- g = (packed_pixel & 0x07E0) >> 3; \
- b = (packed_pixel & 0x001F) << 3;
-
-extern int y_r_table[256] XINE_PROTECTED;
-extern int y_g_table[256] XINE_PROTECTED;
-extern int y_b_table[256] XINE_PROTECTED;
-
-extern int u_r_table[256] XINE_PROTECTED;
-extern int u_g_table[256] XINE_PROTECTED;
-extern int u_b_table[256] XINE_PROTECTED;
-
-extern int v_r_table[256] XINE_PROTECTED;
-extern int v_g_table[256] XINE_PROTECTED;
-extern int v_b_table[256] XINE_PROTECTED;
-
-/* frame copying functions */
-extern void yv12_to_yv12
- (const unsigned char *y_src, int y_src_pitch, unsigned char *y_dst, int y_dst_pitch,
- const unsigned char *u_src, int u_src_pitch, unsigned char *u_dst, int u_dst_pitch,
- const unsigned char *v_src, int v_src_pitch, unsigned char *v_dst, int v_dst_pitch,
- int width, int height) XINE_PROTECTED;
-extern void yuy2_to_yuy2
- (const unsigned char *src, int src_pitch,
- unsigned char *dst, int dst_pitch,
- int width, int height) XINE_PROTECTED;
-
-/* print a hexdump of the given data */
-void xine_hexdump (const char *buf, int length) XINE_PROTECTED;
-
-/*
- * Optimization macros for conditions
- * Taken from the FIASCO L4 microkernel sources
- */
-#if !defined(__GNUC__) || __GNUC__ < 3
-# define EXPECT_TRUE(x) (x)
-# define EXPECT_FALSE(x) (x)
-#else
-# define EXPECT_TRUE(x) __builtin_expect((x),1)
-# define EXPECT_FALSE(x) __builtin_expect((x),0)
-#endif
-
-#ifdef NDEBUG
-#define _x_assert(exp) \
- do { \
- if (!(exp)) \
- fprintf(stderr, "assert: %s:%d: %s: Assertion `%s' failed.\n", \
- __FILE__, __LINE__, __XINE_FUNCTION__, #exp); \
- } while(0)
-#else
-#define _x_assert(exp) \
- do { \
- if (!(exp)) { \
- fprintf(stderr, "assert: %s:%d: %s: Assertion `%s' failed.\n", \
- __FILE__, __LINE__, __XINE_FUNCTION__, #exp); \
- abort(); \
- } \
- } while(0)
-#endif
-
-#define _x_abort() \
- do { \
- fprintf(stderr, "abort: %s:%d: %s: Aborting.\n", \
- __FILE__, __LINE__, __XINE_FUNCTION__); \
- abort(); \
- } while(0)
-
-
-/****** logging with xine **********************************/
-
-#ifndef LOG_MODULE
- #define LOG_MODULE __FILE__
-#endif /* LOG_MODULE */
-
-#define LOG_MODULE_STRING printf("%s: ", LOG_MODULE );
-
-#ifdef LOG_VERBOSE
- #define LONG_LOG_MODULE_STRING \
- printf("%s: (%s:%d) ", LOG_MODULE, __XINE_FUNCTION__, __LINE__ );
-#else
- #define LONG_LOG_MODULE_STRING LOG_MODULE_STRING
-#endif /* LOG_VERBOSE */
-
-#ifdef LOG
- #ifdef __GNUC__
- #define lprintf(fmt, args...) \
- do { \
- LONG_LOG_MODULE_STRING \
- printf(fmt, ##args); \
- fflush(stdout); \
- } while(0)
- #else /* __GNUC__ */
- #ifdef _MSC_VER
- #define lprintf(fmtargs) \
- do { \
- LONG_LOG_MODULE_STRING \
- printf("%s", fmtargs); \
- fflush(stdout); \
- } while(0)
- #else /* _MSC_VER */
- #define lprintf(...) \
- do { \
- LONG_LOG_MODULE_STRING \
- printf(__VA_ARGS__); \
- fflush(stdout); \
- } while(0)
- #endif /* _MSC_VER */
- #endif /* __GNUC__ */
-#else /* LOG */
- #ifdef __GNUC__
- #define lprintf(fmt, args...) do {} while(0)
- #else
- #ifdef _MSC_VER
-void __inline lprintf(const char * fmt, ...) {}
- #else
- #define lprintf(...) do {} while(0)
- #endif /* _MSC_VER */
- #endif /* __GNUC__ */
-#endif /* LOG */
-
-#ifdef __GNUC__
- #define llprintf(cat, fmt, args...) \
- do{ \
- if(cat){ \
- LONG_LOG_MODULE_STRING \
- printf( fmt, ##args ); \
- } \
- }while(0)
-#else
-#ifdef _MSC_VER
- #define llprintf(cat, fmtargs) \
- do{ \
- if(cat){ \
- LONG_LOG_MODULE_STRING \
- printf( "%s", fmtargs ); \
- } \
- }while(0)
-#else
- #define llprintf(cat, ...) \
- do{ \
- if(cat){ \
- LONG_LOG_MODULE_STRING \
- printf( __VA_ARGS__ ); \
- } \
- }while(0)
-#endif /* _MSC_VER */
-#endif /* __GNUC__ */
-
-#ifdef __GNUC__
- #define xprintf(xine, verbose, fmt, args...) \
- do { \
- if((xine) && (xine)->verbosity >= verbose){ \
- xine_log(xine, XINE_LOG_TRACE, fmt, ##args); \
- } \
- } while(0)
-#else
-#ifdef _MSC_VER
-void xine_xprintf(xine_t *xine, int verbose, const char *fmt, ...);
- #define xprintf xine_xprintf
-#else
- #define xprintf(xine, verbose, ...) \
- do { \
- if((xine) && (xine)->verbosity >= verbose){ \
- xine_log(xine, XINE_LOG_TRACE, __VA_ARGS__); \
- } \
- } while(0)
-#endif /* _MSC_VER */
-#endif /* __GNUC__ */
-
-/* time measuring macros for profiling tasks */
-
-#ifdef DEBUG
-# define XINE_PROFILE(function) \
- do { \
- struct timeval current_time; \
- double dtime; \
- gettimeofday(&current_time, NULL); \
- dtime = -(current_time.tv_sec + (current_time.tv_usec / 1000000.0)); \
- function; \
- gettimeofday(&current_time, NULL); \
- dtime += current_time.tv_sec + (current_time.tv_usec / 1000000.0); \
- printf("%s: (%s:%d) took %lf seconds\n", \
- LOG_MODULE, __XINE_FUNCTION__, __LINE__, dtime); \
- } while(0)
-# define XINE_PROFILE_ACCUMULATE(function) \
- do { \
- struct timeval current_time; \
- static double dtime = 0; \
- gettimeofday(&current_time, NULL); \
- dtime -= current_time.tv_sec + (current_time.tv_usec / 1000000.0); \
- function; \
- gettimeofday(&current_time, NULL); \
- dtime += current_time.tv_sec + (current_time.tv_usec / 1000000.0); \
- printf("%s: (%s:%d) took %lf seconds\n", \
- LOG_MODULE, __XINE_FUNCTION__, __LINE__, dtime); \
- } while(0)
-#else
-# define XINE_PROFILE(function) function
-# define XINE_PROFILE_ACCUMULATE(function) function
-#endif /* DEBUG */
-
-/**
- * get encoding of current locale
- */
-char *xine_get_system_encoding(void) XINE_MALLOC XINE_PROTECTED;
-
-/*
- * guess default encoding for the subtitles
- */
-const char *xine_guess_spu_encoding(void) XINE_PROTECTED;
-
-/*
- * use the best clock reference (API compatible with gettimeofday)
- * note: it will be a monotonic clock, if available.
- */
-int xine_monotonic_clock(struct timeval *tv, struct timezone *tz) XINE_PROTECTED;
-
-/* don't harm following code */
-#ifdef extern
-# undef extern
-#endif
-
-#ifdef __cplusplus
-}
-#endif
-
-#endif
diff --git a/src/xine-utils/xmllexer.c b/src/xine-utils/xmllexer.c
index fb504f430..4e72ba57c 100644
--- a/src/xine-utils/xmllexer.c
+++ b/src/xine-utils/xmllexer.c
@@ -30,11 +30,11 @@
#endif
#ifdef XINE_COMPILE
-#include "xineutils.h"
+#include <xine/xineutils.h>
#else
#define lprintf(...)
#endif
-#include "xmllexer.h"
+#include <xine/xmllexer.h>
#include <stdio.h>
#include <ctype.h>
#include <string.h>
@@ -46,8 +46,6 @@
#include "bswap.h"
/* private constants*/
-#define NORMAL 0 /* normal lex mode */
-#define DATA 1 /* data lex mode */
/* private global variables */
struct lexer * static_lexer;
@@ -98,6 +96,12 @@ void lexer_init(const char * buf, int size) {
static_lexer = lexer_init_r(buf, size);
}
+static enum {
+ NORMAL,
+ DATA,
+ CDATA,
+} lex_mode = NORMAL;
+
struct lexer *lexer_init_r(const char * buf, int size) {
static const char boms[] = { 0xFF, 0xFE, 0, 0, 0xFE, 0xFF },
bom_utf8[] = { 0xEF, 0xBB, 0xBF };
@@ -134,6 +138,24 @@ void lexer_finalize_r(struct lexer * lexer)
free(lexer);
}
+typedef enum {
+ STATE_UNKNOWN = -1,
+ STATE_IDLE,
+ STATE_EOL,
+ STATE_SEPAR,
+ STATE_T_M_START,
+ STATE_T_M_STOP_1,
+ STATE_T_M_STOP_2,
+ STATE_T_EQUAL,
+ STATE_T_STRING_SINGLE,
+ STATE_T_STRING_DOUBLE,
+ STATE_T_COMMENT,
+ STATE_T_TI_STOP,
+ STATE_T_DASHDASH,
+ STATE_T_C_STOP,
+ STATE_IDENT /* must be last */
+} lexer_state_t;
+
/* for ABI compatibility */
int lexer_get_token_d(char ** _tok, int * _tok_size, int fixed) {
return lexer_get_token_d_r(static_lexer, _tok, _tok_size, fixed);
@@ -144,7 +166,7 @@ int lexer_get_token_d_r(struct lexer * lexer, char ** _tok, int * _tok_size, int
int tok_size = *_tok_size;
int tok_pos = 0;
- int state = 0;
+ lexer_state_t state = STATE_IDLE;
char c;
if (tok) {
@@ -152,73 +174,74 @@ int lexer_get_token_d_r(struct lexer * lexer, char ** _tok, int * _tok_size, int
c = lexer->lexbuf[lexer->lexbuf_pos];
lprintf("c=%c, state=%d, in_comment=%d\n", c, state, lexer->in_comment);
- if (lexer->lex_mode == NORMAL) {
- /* normal mode */
+ switch (lexer->lex_mode) {
+ case NORMAL:
switch (state) {
/* init state */
- case 0:
+ case STATE_IDLE:
switch (c) {
case '\n':
case '\r':
- state = 1;
+ state = STATE_EOL;
tok[tok_pos] = c;
tok_pos++;
break;
case ' ':
case '\t':
- state = 2;
+ state = STATE_SEPAR;
tok[tok_pos] = c;
tok_pos++;
break;
case '<':
- state = 3;
+ state = STATE_T_M_START;
tok[tok_pos] = c;
tok_pos++;
break;
case '>':
- state = 4;
+ state = STATE_T_M_STOP_1;
tok[tok_pos] = c;
tok_pos++;
break;
case '/':
if (!lexer->in_comment)
- state = 5;
+ state = STATE_T_M_STOP_2;
tok[tok_pos] = c;
tok_pos++;
break;
case '=':
- state = 6;
+ state = STATE_T_EQUAL;
tok[tok_pos] = c;
tok_pos++;
break;
case '\"': /* " */
- state = 7;
+ state = STATE_T_STRING_DOUBLE;
break;
case '\'': /* " */
- state = 12;
+ state = STATE_T_STRING_SINGLE;
break;
case '-':
- state = 10;
+ state = STATE_T_DASHDASH;
tok[tok_pos] = c;
tok_pos++;
break;
case '?':
- state = 9;
+ if (!lexer->in_comment)
+ state = STATE_T_TI_STOP;
tok[tok_pos] = c;
tok_pos++;
break;
default:
- state = 100;
+ state = STATE_IDENT;
tok[tok_pos] = c;
tok_pos++;
break;
@@ -227,7 +250,7 @@ int lexer_get_token_d_r(struct lexer * lexer, char ** _tok, int * _tok_size, int
break;
/* end of line */
- case 1:
+ case STATE_EOL:
if (c == '\n' || (c == '\r')) {
tok[tok_pos] = c;
lexer->lexbuf_pos++;
@@ -239,7 +262,7 @@ int lexer_get_token_d_r(struct lexer * lexer, char ** _tok, int * _tok_size, int
break;
/* T_SEPAR */
- case 2:
+ case STATE_SEPAR:
if (c == ' ' || (c == '\t')) {
tok[tok_pos] = c;
lexer->lexbuf_pos++;
@@ -251,7 +274,7 @@ int lexer_get_token_d_r(struct lexer * lexer, char ** _tok, int * _tok_size, int
break;
/* T_M_START < or </ or <! or <? */
- case 3:
+ case STATE_T_M_START:
switch (c) {
case '/':
tok[tok_pos] = c;
@@ -264,7 +287,7 @@ int lexer_get_token_d_r(struct lexer * lexer, char ** _tok, int * _tok_size, int
tok[tok_pos] = c;
lexer->lexbuf_pos++;
tok_pos++;
- state = 8;
+ state = STATE_T_COMMENT;
break;
case '?':
tok[tok_pos] = c;
@@ -280,7 +303,7 @@ int lexer_get_token_d_r(struct lexer * lexer, char ** _tok, int * _tok_size, int
break;
/* T_M_STOP_1 */
- case 4:
+ case STATE_T_M_STOP_1:
tok[tok_pos] = '\0';
if (!lexer->in_comment)
lexer->lex_mode = DATA;
@@ -288,7 +311,7 @@ int lexer_get_token_d_r(struct lexer * lexer, char ** _tok, int * _tok_size, int
break;
/* T_M_STOP_2 */
- case 5:
+ case STATE_T_M_STOP_2:
if (c == '>') {
tok[tok_pos] = c;
lexer->lexbuf_pos++;
@@ -304,13 +327,13 @@ int lexer_get_token_d_r(struct lexer * lexer, char ** _tok, int * _tok_size, int
break;
/* T_EQUAL */
- case 6:
+ case STATE_T_EQUAL:
tok[tok_pos] = '\0';
return T_EQUAL;
break;
/* T_STRING */
- case 7:
+ case STATE_T_STRING_DOUBLE:
tok[tok_pos] = c;
lexer->lexbuf_pos++;
if (c == '\"') { /* " */
@@ -320,8 +343,8 @@ int lexer_get_token_d_r(struct lexer * lexer, char ** _tok, int * _tok_size, int
tok_pos++;
break;
- /* T_C_START or T_DOCTYPE_START */
- case 8:
+ /* T_C_START or T_DOCTYPE_START or T_CDATA_START */
+ case STATE_T_COMMENT:
switch (c) {
case '-':
lexer->lexbuf_pos++;
@@ -345,6 +368,17 @@ int lexer_get_token_d_r(struct lexer * lexer, char ** _tok, int * _tok_size, int
return T_ERROR;
}
break;
+ case '[':
+ lexer->lexbuf_pos++;
+ if (strncmp(lexer->lexbuf + lexer->lexbuf_pos, "CDATA[", 6) == 0) {
+ strncpy (tok + tok_pos, "[CDATA[", 7); /* FIXME */
+ lexer->lexbuf_pos += 6;
+ lexer->lex_mode = CDATA;
+ return T_CDATA_START;
+ } else{
+ return T_ERROR;
+ }
+ break;
default:
/* error */
return T_ERROR;
@@ -352,12 +386,14 @@ int lexer_get_token_d_r(struct lexer * lexer, char ** _tok, int * _tok_size, int
break;
/* T_TI_STOP */
- case 9:
+ case STATE_T_TI_STOP:
if (c == '>') {
tok[tok_pos] = c;
lexer->lexbuf_pos++;
tok_pos++; /* FIXME */
tok[tok_pos] = '\0';
+ if (!lexer->in_comment)
+ lexer->lex_mode = DATA;
return T_TI_STOP;
} else {
tok[tok_pos] = '\0';
@@ -366,24 +402,24 @@ int lexer_get_token_d_r(struct lexer * lexer, char ** _tok, int * _tok_size, int
break;
/* -- */
- case 10:
+ case STATE_T_DASHDASH:
switch (c) {
case '-':
tok[tok_pos] = c;
tok_pos++;
lexer->lexbuf_pos++;
- state = 11;
+ state = STATE_T_C_STOP;
break;
default:
tok[tok_pos] = c;
tok_pos++;
lexer->lexbuf_pos++;
- state = 100;
+ state = STATE_IDENT;
}
break;
/* --> */
- case 11:
+ case STATE_T_C_STOP:
switch (c) {
case '>':
tok[tok_pos] = c;
@@ -403,12 +439,12 @@ int lexer_get_token_d_r(struct lexer * lexer, char ** _tok, int * _tok_size, int
tok[tok_pos] = c;
tok_pos++;
lexer->lexbuf_pos++;
- state = 100;
+ state = STATE_IDENT;
}
break;
/* T_STRING (single quotes) */
- case 12:
+ case STATE_T_STRING_SINGLE:
tok[tok_pos] = c;
lexer->lexbuf_pos++;
if (c == '\'') { /* " */
@@ -419,7 +455,7 @@ int lexer_get_token_d_r(struct lexer * lexer, char ** _tok, int * _tok_size, int
break;
/* IDENT */
- case 100:
+ case STATE_IDENT:
switch (c) {
case '<':
case '>':
@@ -438,13 +474,13 @@ int lexer_get_token_d_r(struct lexer * lexer, char ** _tok, int * _tok_size, int
tok[tok_pos] = c;
tok_pos++;
lexer->lexbuf_pos++;
- state = 9;
+ state = STATE_T_TI_STOP;
break;
case '-':
tok[tok_pos] = c;
tok_pos++;
lexer->lexbuf_pos++;
- state = 10;
+ state = STATE_T_DASHDASH;
break;
default:
tok[tok_pos] = c;
@@ -456,8 +492,9 @@ int lexer_get_token_d_r(struct lexer * lexer, char ** _tok, int * _tok_size, int
lprintf("expected char \'%c\'\n", tok[tok_pos - 1]); /* FIX ME */
return T_ERROR;
}
- } else {
- /* data mode, stop if char equal '<' */
+ break;
+
+ case DATA: /* data mode, stop if char equal '<' */
switch (c)
{
case '<':
@@ -469,6 +506,28 @@ int lexer_get_token_d_r(struct lexer * lexer, char ** _tok, int * _tok_size, int
tok_pos++;
lexer->lexbuf_pos++;
}
+ break;
+
+ case CDATA: /* cdata mode, stop if next token is "]]>" */
+ switch (c)
+ {
+ case ']':
+ if (strncmp(lexer->lexbuf + lexer->lexbuf_pos, "]]>", 3) == 0) {
+ lexer->lexbuf_pos += 3;
+ lexer->lex_mode = DATA;
+ return T_CDATA_STOP;
+ } else {
+ tok[tok_pos] = c;
+ tok_pos++;
+ lexer->lexbuf_pos++;
+ }
+ break;
+ default:
+ tok[tok_pos] = c;
+ tok_pos++;
+ lexer->lexbuf_pos++;
+ }
+ break;
}
}
lprintf ("loop done tok_pos = %d, tok_size=%d, lexbuf_pos=%d, lexbuf_size=%d\n",
@@ -492,27 +551,28 @@ int lexer_get_token_d_r(struct lexer * lexer, char ** _tok, int * _tok_size, int
/* Terminate the current token */
tok[tok_pos] = '\0';
switch (state) {
- case 0:
- case 1:
- case 2:
+ case STATE_IDLE:
+ case STATE_EOL:
+ case STATE_SEPAR:
return T_EOF;
break;
- case 3:
+ case STATE_T_M_START:
return T_M_START_1;
break;
- case 4:
+ case STATE_T_M_STOP_1:
return T_M_STOP_1;
break;
- case 5:
+ case STATE_T_M_STOP_2:
return T_ERROR;
break;
- case 6:
+ case STATE_T_EQUAL:
return T_EQUAL;
break;
- case 7:
+ case STATE_T_STRING_SINGLE:
+ case STATE_T_STRING_DOUBLE:
return T_STRING;
break;
- case 100:
+ case STATE_IDENT:
return T_DATA;
break;
default:
diff --git a/src/xine-utils/xmllexer.h b/src/xine-utils/xmllexer.h
deleted file mode 100644
index bcea7d6b4..000000000
--- a/src/xine-utils/xmllexer.h
+++ /dev/null
@@ -1,77 +0,0 @@
-/*
- * Copyright (C) 2002-2003,2007 the xine project
- *
- * This file is part of xine, a free video player.
- *
- * The xine-lib XML parser is free software; you can redistribute it and/or
- * modify it under the terms of the GNU Library General Public License as
- * published by the Free Software Foundation; either version 2 of the
- * License, or (at your option) any later version.
- *
- * The xine-lib XML parser is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * Library General Public License for more details.
- *
- * You should have received a copy of the GNU Library General Public
- * License along with the Gnome Library; see the file COPYING.LIB. If not,
- * write to the Free Software Foundation, Inc., 51 Franklin Street, Fifth
- * Floor, Boston, MA 02110, USA
- */
-
-/* xml lexer */
-#ifndef XML_LEXER_H
-#define XML_LEXER_H
-
-#ifndef XINE_DEPRECATED
-#define XINE_DEPRECATED
-#endif
-
-#ifndef XINE_PROTECTED
-#define XINE_PROTECTED
-#endif
-
-/* public constants */
-#define T_ERROR -1 /* lexer error */
-#define T_EOF 0 /* end of file */
-#define T_EOL 1 /* end of line */
-#define T_SEPAR 2 /* separator ' ' '/t' '\n' '\r' */
-#define T_M_START_1 3 /* markup start < */
-#define T_M_START_2 4 /* markup start </ */
-#define T_M_STOP_1 5 /* markup stop > */
-#define T_M_STOP_2 6 /* markup stop /> */
-#define T_EQUAL 7 /* = */
-#define T_QUOTE 8 /* \" or \' */
-#define T_STRING 9 /* "string" */
-#define T_IDENT 10 /* identifier */
-#define T_DATA 11 /* data */
-#define T_C_START 12 /* <!-- */
-#define T_C_STOP 13 /* --> */
-#define T_TI_START 14 /* <? */
-#define T_TI_STOP 15 /* ?> */
-#define T_DOCTYPE_START 16 /* <!DOCTYPE */
-#define T_DOCTYPE_STOP 17 /* > */
-
-
-/* public structure */
-struct lexer
-{
- const char * lexbuf;
- int lexbuf_size;
- int lexbuf_pos;
- int lex_mode;
- int in_comment;
- char *lex_malloc;
-};
-
-
-/* public functions */
-void lexer_init(const char * buf, int size) XINE_DEPRECATED XINE_PROTECTED;
-struct lexer *lexer_init_r(const char * buf, int size) XINE_PROTECTED;
-void lexer_finalize_r(struct lexer * lexer) XINE_PROTECTED;
-int lexer_get_token_d_r(struct lexer * lexer, char ** tok, int * tok_size, int fixed) XINE_PROTECTED;
-int lexer_get_token_d(char ** tok, int * tok_size, int fixed) XINE_DEPRECATED XINE_PROTECTED;
-int lexer_get_token(char * tok, int tok_size) XINE_DEPRECATED XINE_PROTECTED;
-char *lexer_decode_entities (const char *tok) XINE_PROTECTED;
-
-#endif
diff --git a/src/xine-utils/xmlparser.c b/src/xine-utils/xmlparser.c
index 1b82074fb..8619b1be8 100644
--- a/src/xine-utils/xmlparser.c
+++ b/src/xine-utils/xmlparser.c
@@ -22,6 +22,12 @@
#ifdef HAVE_CONFIG_H
#include "config.h"
#endif
+
+#ifdef XINE_COMPILE
+# include "config.h"
+#endif
+
+#include <unistd.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
@@ -40,13 +46,13 @@
*/
#ifdef XINE_COMPILE
-#include "xineutils.h"
+#include <xine/xineutils.h>
#else
#define lprintf(...)
#define XINE_MALLOC
#endif
-#include "xmllexer.h"
-#include "xmlparser.h"
+#include <xine/xmllexer.h>
+#include <xine/xmlparser.h>
#define TOKEN_SIZE 4 * 1024
@@ -80,8 +86,11 @@ static xml_node_t * new_xml_node(void) {
return new_node;
}
+static const char cdata[] = CDATA_MARKER;
+
static void free_xml_node(xml_node_t * node) {
- free (node->name);
+ if (node->name != cdata)
+ free (node->name);
free (node->data);
free(node);
}
@@ -170,23 +179,86 @@ void xml_parser_free_tree(xml_node_t *current_node) {
xml_parser_free_tree_rec(current_node, 1);
}
-#define STATE_IDLE 0
-#define STATE_NODE 1
-#define STATE_COMMENT 7
+typedef enum {
+ /*0*/
+ STATE_IDLE,
+ /* <foo ...> */
+ STATE_NODE,
+ STATE_ATTRIBUTE,
+ STATE_NODE_CLOSE,
+ STATE_TAG_TERM,
+ STATE_ATTRIBUTE_EQUALS,
+ STATE_STRING,
+ STATE_TAG_TERM_IGNORE,
+ /* <?foo ...?> */
+ STATE_Q_NODE,
+ STATE_Q_ATTRIBUTE,
+ STATE_Q_NODE_CLOSE,
+ STATE_Q_TAG_TERM,
+ STATE_Q_ATTRIBUTE_EQUALS,
+ STATE_Q_STRING,
+ /* Others */
+ STATE_COMMENT,
+ STATE_DOCTYPE,
+ STATE_CDATA,
+} parser_state_t;
+
+static xml_node_t *xml_parser_append_text (xml_node_t *node, xml_node_t *subnode, const char *text, int flags)
+{
+ if (!text || !*text)
+ return subnode; /* empty string -> nothing to do */
+
+ if ((flags & XML_PARSER_MULTI_TEXT) && subnode) {
+ /* we have a subtree, so we can't use node->data */
+ if (subnode->name == cdata) {
+ /* most recent node is CDATA - append to it */
+ char *newtext;
+ if (asprintf (&newtext, "%s%s", subnode->data, text) < 0)
+ newtext = NULL;
+ free (subnode->data);
+ subnode->data = newtext;
+ } else {
+ /* most recent node is not CDATA - add a sibling */
+ subnode->next = new_xml_node ();
+ subnode->next->name = cdata;
+ subnode->next->data = strdup (text);
+ subnode = subnode->next;
+ }
+ } else if (node->data) {
+ /* "no" subtree, but we have existing text - append to it */
+ char *newtext;
+ if (asprintf (&newtext, "%s%s", node->data, text) < 0)
+ newtext = NULL;
+ free (node->data);
+ node->data = newtext;
+ } else {
+ /* no text, "no" subtree - duplicate & assign */
+ while (isspace (*text))
+ ++text;
+ if (*text)
+ node->data = strdup (text);
+ }
+
+ return subnode;
+}
-static int xml_parser_get_node (xml_parser_t *xml_parser, xml_node_t *current_node, char *root_name, int rec);
+#define Q_STATE(CURRENT,NEW) (STATE_##NEW + state - STATE_##CURRENT)
-static int _xml_parser_get_node (xml_parser_t *xml_parser, char ** token_buffer, int * token_buffer_size,
+
+static int xml_parser_get_node_internal (xml_parser_t *xml_parser,
+ char ** token_buffer, int * token_buffer_size,
char ** pname_buffer, int * pname_buffer_size,
char ** nname_buffer, int * nname_buffer_size,
- xml_node_t *current_node, char *root_name, int rec) {
+ xml_node_t *current_node, char *root_names[], int rec, int flags)
+{
char *tok = *token_buffer;
char *property_name = *pname_buffer;
char *node_name = *nname_buffer;
- int state = STATE_IDLE;
+ parser_state_t state = STATE_IDLE;
int res = 0;
int parse_res;
int bypass_get_token = 0;
+ int retval = 0; /* used when state==4; non-0 if there are missing </...> */
xml_node_t *subtree = NULL;
xml_node_t *current_subtree = NULL;
xml_property_t *current_property = NULL;
@@ -209,30 +281,33 @@ static int _xml_parser_get_node (xml_parser_t *xml_parser, char ** token_buffer,
/* do nothing */
break;
case (T_EOF):
- return 0; /* normal end */
+ return retval; /* normal end */
break;
case (T_M_START_1):
state = STATE_NODE;
break;
case (T_M_START_2):
- state = 3;
+ state = STATE_NODE_CLOSE;
break;
case (T_C_START):
state = STATE_COMMENT;
break;
case (T_TI_START):
- state = 8;
+ state = STATE_Q_NODE;
break;
case (T_DOCTYPE_START):
- state = 9;
+ state = STATE_DOCTYPE;
+ break;
+ case (T_CDATA_START):
+ state = STATE_CDATA;
break;
case (T_DATA):
/* current data */
- if (current_node->data) {
- /* avoid a memory leak */
- free(current_node->data);
+ {
+ char *decoded = lexer_decode_entities (tok);
+ current_subtree = xml_parser_append_text (current_node, current_subtree, decoded, flags);
+ free (decoded);
}
- current_node->data = lexer_decode_entities(tok);
lprintf("info: node data : %s\n", current_node->data);
break;
default:
@@ -243,6 +318,7 @@ static int _xml_parser_get_node (xml_parser_t *xml_parser, char ** token_buffer,
break;
case STATE_NODE:
+ case STATE_Q_NODE:
switch (res) {
case (T_IDENT):
properties = NULL;
@@ -252,14 +328,19 @@ static int _xml_parser_get_node (xml_parser_t *xml_parser, char ** token_buffer,
if (xml_parser->mode == XML_PARSER_CASE_INSENSITIVE) {
strtoupper(tok);
}
- /* make sure the buffer for the node name is big enough */
- if (*token_buffer_size > *nname_buffer_size) {
- *nname_buffer_size = *token_buffer_size;
- *nname_buffer = realloc (*nname_buffer, *nname_buffer_size);
- node_name = *nname_buffer;
+ if (state == STATE_Q_NODE) {
+ if (asprintf (&node_name, "?%s", tok) < 0)
+ node_name = NULL;
+ free (*nname_buffer);
+ *nname_buffer = node_name;
+ *nname_buffer_size = strlen (node_name) + 1;
+ state = STATE_Q_ATTRIBUTE;
+ } else {
+ free (*nname_buffer);
+ *nname_buffer = node_name = strdup (tok);
+ *nname_buffer_size = strlen (node_name) + 1;
+ state = STATE_ATTRIBUTE;
}
- strcpy(node_name, tok);
- state = 2;
lprintf("info: current node name \"%s\"\n", node_name);
break;
default:
@@ -268,7 +349,8 @@ static int _xml_parser_get_node (xml_parser_t *xml_parser, char ** token_buffer,
break;
}
break;
- case 2:
+
+ case STATE_ATTRIBUTE:
switch (res) {
case (T_EOL):
case (T_SEPAR):
@@ -284,8 +366,13 @@ static int _xml_parser_get_node (xml_parser_t *xml_parser, char ** token_buffer,
/* set node propertys */
subtree->props = properties;
lprintf("info: rec %d new subtree %s\n", rec, node_name);
- parse_res = xml_parser_get_node(xml_parser, subtree, node_name, rec + 1);
- if (parse_res != 0) {
+ root_names[rec + 1] = strdup (node_name);
+ parse_res = xml_parser_get_node_internal (xml_parser, token_buffer, token_buffer_size,
+ pname_buffer, pname_buffer_size,
+ nname_buffer, nname_buffer_size,
+ subtree, root_names, rec + 1, flags);
+ free (root_names[rec + 1]);
+ if (parse_res == -1 || parse_res > 0) {
return parse_res;
}
if (current_subtree == NULL) {
@@ -295,11 +382,16 @@ static int _xml_parser_get_node (xml_parser_t *xml_parser, char ** token_buffer,
current_subtree->next = subtree;
current_subtree = subtree;
}
+ if (parse_res < -1) {
+ /* badly-formed XML (missing close tag) */
+ return parse_res + 1 + (parse_res == -2);
+ }
state = STATE_IDLE;
break;
case (T_M_STOP_2):
/* new leaf */
/* new subtree */
+ new_leaf:
subtree = new_xml_node();
/* set node name */
@@ -321,6 +413,7 @@ static int _xml_parser_get_node (xml_parser_t *xml_parser, char ** token_buffer,
break;
case (T_IDENT):
/* save property name */
+ new_prop:
if (xml_parser->mode == XML_PARSER_CASE_INSENSITIVE) {
strtoupper(tok);
}
@@ -331,7 +424,7 @@ static int _xml_parser_get_node (xml_parser_t *xml_parser, char ** token_buffer,
property_name = *pname_buffer;
}
strcpy(property_name, tok);
- state = 5;
+ state = Q_STATE(ATTRIBUTE, ATTRIBUTE_EQUALS);
lprintf("info: current property name \"%s\"\n", property_name);
break;
default:
@@ -341,17 +434,50 @@ static int _xml_parser_get_node (xml_parser_t *xml_parser, char ** token_buffer,
}
break;
- case 3:
+ case STATE_Q_ATTRIBUTE:
+ switch (res) {
+ case (T_EOL):
+ case (T_SEPAR):
+ /* nothing */
+ break;
+ case (T_TI_STOP):
+ goto new_leaf;
+ case (T_IDENT):
+ goto new_prop;
+ default:
+ lprintf("error: unexpected token \"%s\", state %d\n", tok, state);
+ return -1;
+ break;
+ }
+ break;
+
+ case STATE_NODE_CLOSE:
switch (res) {
case (T_IDENT):
/* must be equal to root_name */
if (xml_parser->mode == XML_PARSER_CASE_INSENSITIVE) {
strtoupper(tok);
}
- if (strcmp(tok, root_name) == 0) {
- state = 4;
- } else {
- lprintf("error: xml struct, tok=%s, waited_tok=%s\n", tok, root_name);
+ if (strcmp(tok, root_names[rec]) == 0) {
+ state = STATE_TAG_TERM;
+ } else if (flags & XML_PARSER_RELAXED) {
+ int r = rec;
+ while (--r >= 0)
+ if (strcmp(tok, root_names[r]) == 0) {
+ lprintf("warning: wanted %s, got %s - assuming missing close tags\n", root_names[rec], tok);
+ retval = r - rec - 1; /* -1 - (no. of implied close tags) */
+ state = STATE_TAG_TERM;
+ break;
+ }
+ /* relaxed parsing, ignoring extra close tag (but we don't handle out-of-order) */
+ if (r < 0) {
+ lprintf("warning: extra close tag %s - ignoring\n", tok);
+ state = STATE_TAG_TERM_IGNORE;
+ }
+ }
+ else
+ {
+ lprintf("error: xml struct, tok=%s, waited_tok=%s\n", tok, root_names[rec]);
return -1;
}
break;
@@ -363,10 +489,10 @@ static int _xml_parser_get_node (xml_parser_t *xml_parser, char ** token_buffer,
break;
/* > expected */
- case 4:
+ case STATE_TAG_TERM:
switch (res) {
case (T_M_STOP_1):
- return 0;
+ return retval;
break;
default:
lprintf("error: unexpected token \"%s\", state %d\n", tok, state);
@@ -376,18 +502,18 @@ static int _xml_parser_get_node (xml_parser_t *xml_parser, char ** token_buffer,
break;
/* = or > or ident or separator expected */
- case 5:
+ case STATE_ATTRIBUTE_EQUALS:
switch (res) {
case (T_EOL):
case (T_SEPAR):
/* do nothing */
break;
case (T_EQUAL):
- state = 6;
+ state = STATE_STRING;
break;
case (T_IDENT):
bypass_get_token = 1; /* jump to state 2 without get a new token */
- state = 2;
+ state = STATE_ATTRIBUTE;
break;
case (T_M_STOP_1):
/* add a new property without value */
@@ -401,7 +527,42 @@ static int _xml_parser_get_node (xml_parser_t *xml_parser, char ** token_buffer,
current_property->name = strdup (property_name);
lprintf("info: new property %s\n", current_property->name);
bypass_get_token = 1; /* jump to state 2 without get a new token */
- state = 2;
+ state = STATE_ATTRIBUTE;
+ break;
+ default:
+ lprintf("error: unexpected token \"%s\", state %d\n", tok, state);
+ return -1;
+ break;
+ }
+ break;
+
+ /* = or ?> or ident or separator expected */
+ case STATE_Q_ATTRIBUTE_EQUALS:
+ switch (res) {
+ case (T_EOL):
+ case (T_SEPAR):
+ /* do nothing */
+ break;
+ case (T_EQUAL):
+ state = STATE_Q_STRING;
+ break;
+ case (T_IDENT):
+ bypass_get_token = 1; /* jump to state 2 without get a new token */
+ state = STATE_Q_ATTRIBUTE;
+ break;
+ case (T_TI_STOP):
+ /* add a new property without value */
+ if (current_property == NULL) {
+ properties = new_xml_property();
+ current_property = properties;
+ } else {
+ current_property->next = new_xml_property();
+ current_property = current_property->next;
+ }
+ current_property->name = strdup (property_name);
+ lprintf("info: new property %s\n", current_property->name);
+ bypass_get_token = 1; /* jump to state 2 without get a new token */
+ state = STATE_Q_ATTRIBUTE;
break;
default:
lprintf("error: unexpected token \"%s\", state %d\n", tok, state);
@@ -411,7 +572,8 @@ static int _xml_parser_get_node (xml_parser_t *xml_parser, char ** token_buffer,
break;
/* string or ident or separator expected */
- case 6:
+ case STATE_STRING:
+ case STATE_Q_STRING:
switch (res) {
case (T_EOL):
case (T_SEPAR):
@@ -430,7 +592,7 @@ static int _xml_parser_get_node (xml_parser_t *xml_parser, char ** token_buffer,
current_property->name = strdup(property_name);
current_property->value = lexer_decode_entities(tok);
lprintf("info: new property %s=%s\n", current_property->name, current_property->value);
- state = 2;
+ state = Q_STATE(STRING, ATTRIBUTE);
break;
default:
lprintf("error: unexpected token \"%s\", state %d\n", tok, state);
@@ -446,31 +608,45 @@ static int _xml_parser_get_node (xml_parser_t *xml_parser, char ** token_buffer,
state = STATE_IDLE;
break;
default:
- state = STATE_COMMENT;
break;
}
break;
- /* ?> expected */
- case 8:
+ /* > expected */
+ case STATE_DOCTYPE:
switch (res) {
- case (T_TI_STOP):
+ case (T_M_STOP_1):
state = 0;
break;
default:
- state = 8;
break;
}
break;
- /* > expected */
- case 9:
+ /* ]]> expected */
+ case STATE_CDATA:
+ switch (res) {
+ case (T_CDATA_STOP):
+ current_subtree = xml_parser_append_text (current_node, current_subtree, tok, flags);
+ lprintf("info: node cdata : %s\n", tok);
+ state = STATE_IDLE;
+ break;
+ default:
+ lprintf("error: unexpected token \"%s\", state %d\n", tok, state);
+ return -1;
+ break;
+ }
+ break;
+
+ /* > expected (following unmatched "</...") */
+ case STATE_TAG_TERM_IGNORE:
switch (res) {
case (T_M_STOP_1):
- state = 0;
+ state = STATE_IDLE;
break;
default:
- state = 9;
+ lprintf("error: unexpected token \"%s\", state %d\n", tok, state);
+ return -1;
break;
}
break;
@@ -491,7 +667,7 @@ static int _xml_parser_get_node (xml_parser_t *xml_parser, char ** token_buffer,
}
}
-static int xml_parser_get_node (xml_parser_t *xml_parser, xml_node_t *current_node, char *root_name, int rec)
+static int xml_parser_get_node (xml_parser_t *xml_parser, xml_node_t *current_node, int flags)
{
int res = 0;
int token_buffer_size = TOKEN_SIZE;
@@ -500,11 +676,14 @@ static int xml_parser_get_node (xml_parser_t *xml_parser, xml_node_t *current_no
char *token_buffer = calloc(1, token_buffer_size);
char *pname_buffer = calloc(1, pname_buffer_size);
char *nname_buffer = calloc(1, nname_buffer_size);
+ char *root_names[MAX_RECURSION + 1];
+ root_names[0] = "";
- res = _xml_parser_get_node(xml_parser, &token_buffer, &token_buffer_size,
+ res = xml_parser_get_node_internal (xml_parser,
+ &token_buffer, &token_buffer_size,
&pname_buffer, &pname_buffer_size,
&nname_buffer, &nname_buffer_size,
- current_node, root_name, rec);
+ current_node, root_names, 0, flags);
free (token_buffer);
free (pname_buffer);
@@ -514,18 +693,48 @@ static int xml_parser_get_node (xml_parser_t *xml_parser, xml_node_t *current_no
}
/* for ABI compatibility */
-int xml_parser_build_tree(xml_node_t **root_node) {
- return xml_parser_build_tree_r(static_xml_parser, root_node);
+int xml_parser_build_tree_with_options(xml_node_t **root_node, int flags) {
+ return xml_parser_build_tree_with_options_r(static_xml_parser, root_node, flags);
}
-int xml_parser_build_tree_r(xml_parser_t *xml_parser, xml_node_t **root_node) {
- xml_node_t *tmp_node;
+int xml_parser_build_tree_with_options_r(xml_parser_t *xml_parser, xml_node_t **root_node, int flags) {
+ xml_node_t *tmp_node, *pri_node, *q_node;
int res;
tmp_node = new_xml_node();
- res = xml_parser_get_node(xml_parser, tmp_node, "", 0);
- if ((tmp_node->child) && (!tmp_node->child->next)) {
- *root_node = tmp_node->child;
+ res = xml_parser_get_node(xml_parser, tmp_node, flags);
+
+ /* delete any top-level [CDATA] nodes */;
+ pri_node = tmp_node->child;
+ q_node = NULL;
+ while (pri_node) {
+ if (pri_node->name == cdata) {
+ xml_node_t *old = pri_node;
+ if (q_node)
+ q_node->next = pri_node->next;
+ else
+ q_node = pri_node;
+ pri_node = pri_node->next;
+ free_xml_node (old);
+ } else {
+ q_node = pri_node;
+ pri_node = pri_node->next;
+ }
+ }
+
+ /* find first non-<?...?> node */;
+ for (pri_node = tmp_node->child, q_node = NULL;
+ pri_node && pri_node->name[0] == '?';
+ pri_node = pri_node->next)
+ q_node = pri_node; /* last <?...?> node (eventually), or NULL */
+
+ if (pri_node && !pri_node->next) {
+ /* move the tail to the head (for compatibility reasons) */
+ if (q_node) {
+ pri_node->next = tmp_node->child;
+ q_node->next = NULL;
+ }
+ *root_node = pri_node;
free_xml_node(tmp_node);
res = 0;
} else {
@@ -536,6 +745,15 @@ int xml_parser_build_tree_r(xml_parser_t *xml_parser, xml_node_t **root_node) {
return res;
}
+/* for ABI compatibility */
+int xml_parser_build_tree(xml_node_t **root_node) {
+ return xml_parser_build_tree_with_options_r (static_xml_parser, root_node, 0);
+}
+
+int xml_parser_build_tree_r(xml_parser_t *xml_parser, xml_node_t **root_node) {
+ return xml_parser_build_tree_with_options_r(xml_parser, root_node, 0);
+}
+
const char *xml_parser_get_property (const xml_node_t *node, const char *name) {
xml_property_t *prop;
@@ -637,7 +855,7 @@ static void xml_parser_dump_node (const xml_node_t *node, int indent) {
free (value);
p = p->next;
if (p) {
- printf ("\n%*s", (int)(indent+2+l), "");
+ printf ("\n%*s", indent+2+l, "");
}
}
printf (">\n");
@@ -654,5 +872,78 @@ static void xml_parser_dump_node (const xml_node_t *node, int indent) {
}
void xml_parser_dump_tree (const xml_node_t *node) {
- xml_parser_dump_node (node, 0);
+ do {
+ xml_parser_dump_node (node, 0);
+ node = node->next;
+ } while (node);
}
+
+#ifdef XINE_XML_PARSER_TEST
+#include <sys/mman.h>
+#include <sys/types.h>
+#include <sys/stat.h>
+#include <fcntl.h>
+
+void *xine_xmalloc (size_t size)
+{
+ return malloc (size);
+}
+
+int main (int argc, char **argv)
+{
+ int i, ret = 0;
+ for (i = 1; argv[i]; ++i)
+ {
+ xml_node_t *tree;
+ int fd;
+ void *buf;
+ struct stat st;
+
+ if (stat (argv[i], &st))
+ {
+ perror (argv[i]);
+ ret = 1;
+ continue;
+ }
+ if (!S_ISREG (st.st_mode))
+ {
+ printf ("%s: not a file\n", argv[i]);
+ ret = 1;
+ continue;
+ }
+ fd = open (argv[i], O_RDONLY);
+ if (!fd)
+ {
+ perror (argv[i]);
+ ret = 1;
+ continue;
+ }
+ buf = mmap (NULL, st.st_size, PROT_READ, MAP_SHARED, fd, 0);
+ if (!buf)
+ {
+ perror (argv[i]);
+ if (close (fd))
+ perror (argv[i]);
+ ret = 1;
+ continue;
+ }
+
+ xml_parser_init (buf, st.st_size, 0);
+ if (!xml_parser_build_tree (&tree))
+ {
+ puts (argv[i]);
+ xml_parser_dump_tree (tree);
+ xml_parser_free_tree (tree);
+ }
+ else
+ printf ("%s: parser failure\n", argv[i]);
+
+ if (close (fd))
+ {
+ perror (argv[i]);
+ ret = 1;
+ }
+ }
+ return ret;
+}
+#endif
diff --git a/src/xine-utils/xmlparser.h b/src/xine-utils/xmlparser.h
deleted file mode 100644
index 832925bd0..000000000
--- a/src/xine-utils/xmlparser.h
+++ /dev/null
@@ -1,97 +0,0 @@
-/*
- * Copyright (C) 2002-2003,2007 the xine project
- *
- * This file is part of xine, a free video player.
- *
- * The xine-lib XML parser is free software; you can redistribute it and/or
- * modify it under the terms of the GNU Library General Public License as
- * published by the Free Software Foundation; either version 2 of the
- * License, or (at your option) any later version.
- *
- * The xine-lib XML parser is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * Library General Public License for more details.
- *
- * You should have received a copy of the GNU Library General Public
- * License along with the Gnome Library; see the file COPYING.LIB. If not,
- * write to the Free Software Foundation, Inc., 51 Franklin Street, Fifth
- * Floor, Boston, MA 02110, USA
- */
-
-#ifndef XML_PARSER_H
-#define XML_PARSER_H
-
-#ifndef XINE_DEPRECATED
-#define XINE_DEPRECATED
-#endif
-
-#ifndef XINE_PROTECTED
-#define XINE_PROTECTED
-#endif
-
-/* parser modes */
-#define XML_PARSER_CASE_INSENSITIVE 0
-#define XML_PARSER_CASE_SENSITIVE 1
-
-/* return codes */
-#define XML_PARSER_OK 0
-#define XML_PARSER_ERROR 1
-
-
-/* xml property */
-typedef struct xml_property_s {
- char *name;
- char *value;
- struct xml_property_s *next;
-} xml_property_t;
-
-/* xml node */
-typedef struct xml_node_s {
- char *name;
- char *data;
- struct xml_property_s *props;
- struct xml_node_s *child;
- struct xml_node_s *next;
-} xml_node_t;
-
-/* xml parser */
-typedef struct xml_parser_s {
- struct lexer *lexer;
- int mode;
-} xml_parser_t;
-
-void xml_parser_init(const char * buf, int size, int mode) XINE_DEPRECATED XINE_PROTECTED;
-xml_parser_t *xml_parser_init_r(const char * buf, int size, int mode) XINE_PROTECTED;
-void xml_parser_finalize_r(xml_parser_t *xml_parser) XINE_PROTECTED;
-
-int xml_parser_build_tree(xml_node_t **root_node) XINE_DEPRECATED XINE_PROTECTED;
-int xml_parser_build_tree_r(xml_parser_t *xml_parser, xml_node_t **root_node) XINE_PROTECTED;
-
-void xml_parser_free_tree(xml_node_t *root_node) XINE_PROTECTED;
-
-const char *xml_parser_get_property (const xml_node_t *node, const char *name) XINE_PROTECTED;
-int xml_parser_get_property_int (const xml_node_t *node, const char *name,
- int def_value) XINE_PROTECTED;
-int xml_parser_get_property_bool (const xml_node_t *node, const char *name,
- int def_value) XINE_PROTECTED;
-
-/* for output:
- * returns an escaped string (free() it when done)
- * input must be in ASCII or UTF-8
- */
-
-typedef enum {
- XML_ESCAPE_NO_QUOTE,
- XML_ESCAPE_SINGLE_QUOTE,
- XML_ESCAPE_DOUBLE_QUOTE
-} xml_escape_quote_t;
-char *xml_escape_string (const char *s, xml_escape_quote_t quote_type) XINE_PROTECTED;
-
-/* for debugging purposes: dump read-in xml tree in a nicely
- * indented fashion
- */
-
-void xml_parser_dump_tree (const xml_node_t *node) XINE_PROTECTED;
-
-#endif