From 7a1df8370c3fa8ae1d6748863d58df4c79c33a5d Mon Sep 17 00:00:00 2001 From: Darren Salt Date: Tue, 14 Feb 2006 02:25:00 +0000 Subject: Minor constness fixups. Remove some unnecessary NULL tests (free()). Replace an unneeded printf() wrapper. CVS patchset: 7891 CVS date: 2006/02/14 02:25:00 --- src/xine-utils/xmllexer.c | 14 ++++++------ src/xine-utils/xmllexer.h | 6 +++--- src/xine-utils/xmlparser.c | 53 +++++++++++++--------------------------------- src/xine-utils/xmlparser.h | 12 +++++------ 4 files changed, 31 insertions(+), 54 deletions(-) (limited to 'src') diff --git a/src/xine-utils/xmllexer.c b/src/xine-utils/xmllexer.c index 0319964d7..91f5bf88d 100644 --- a/src/xine-utils/xmllexer.c +++ b/src/xine-utils/xmllexer.c @@ -17,7 +17,7 @@ * along with this program; if not, write to the Free Software * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA * - * $Id: xmllexer.c,v 1.10 2005/01/16 18:47:19 mroi Exp $ + * $Id: xmllexer.c,v 1.11 2006/02/14 02:25:00 dsalt Exp $ * */ @@ -38,13 +38,13 @@ #define DATA 1 /* data lex mode */ /* private global variables */ -static char * lexbuf; +static const char * lexbuf; static int lexbuf_size = 0; static int lexbuf_pos = 0; static int lex_mode = NORMAL; static int in_comment = 0; -void lexer_init(char * buf, int size) { +void lexer_init(const char * buf, int size) { lexbuf = buf; lexbuf_size = size; lexbuf_pos = 0; @@ -427,7 +427,7 @@ static struct { { 0 } }; -char *lexer_decode_entities (char *tok) +char *lexer_decode_entities (const char *tok) { char *buf = xine_xmalloc (strlen (tok) + 1); char *bp = buf; @@ -440,7 +440,7 @@ char *lexer_decode_entities (char *tok) else { /* parse the character entity (on failure, treat it as literal text) */ - char *tp = tok; + const char *tp = tok; long i; for (i = 0; lexer_entities[i].code; ++i) @@ -465,9 +465,9 @@ char *lexer_decode_entities (char *tok) * (note: strtol() allows "0x" prefix for hexadecimal, but we don't) */ if (*tp == 'x' && tp[1] && tp[2] != 'x') - i = strtol (tp + 1, &tp, 16); + i = strtol (tp + 1, (char **)&tp, 16); else - i = strtol (tp, &tp, 10); + i = strtol (tp, (char **)&tp, 10); if (i < 1 || i > 255 || *tp != ';') { diff --git a/src/xine-utils/xmllexer.h b/src/xine-utils/xmllexer.h index 77c28c631..abc0189e9 100644 --- a/src/xine-utils/xmllexer.h +++ b/src/xine-utils/xmllexer.h @@ -17,7 +17,7 @@ * along with this program; if not, write to the Free Software * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA * - * $Id: xmllexer.h,v 1.5 2005/01/16 18:47:19 mroi Exp $ + * $Id: xmllexer.h,v 1.6 2006/02/14 02:25:01 dsalt Exp $ * */ @@ -48,8 +48,8 @@ /* public functions */ -void lexer_init(char * buf, int size); +void lexer_init(const char * buf, int size); int lexer_get_token(char * tok, int tok_size); -char *lexer_decode_entities (char *tok); +char *lexer_decode_entities (const char *tok); #endif diff --git a/src/xine-utils/xmlparser.c b/src/xine-utils/xmlparser.c index 95f9642f5..2e8c84ae0 100644 --- a/src/xine-utils/xmlparser.c +++ b/src/xine-utils/xmlparser.c @@ -18,7 +18,7 @@ * along with this program; if not, write to the Free Software * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA * - * $Id: xmlparser.c,v 1.14 2005/01/16 17:51:04 dsalt Exp $ + * $Id: xmlparser.c,v 1.15 2006/02/14 02:25:01 dsalt Exp $ * */ @@ -72,10 +72,8 @@ static xml_node_t * new_xml_node(void) { } static void free_xml_node(xml_node_t * node) { - if (node->name) - free (node->name); - if (node->data) - free (node->data); + free (node->name); + free (node->data); free(node); } @@ -90,14 +88,12 @@ static xml_property_t * new_xml_property(void) { } static void free_xml_property(xml_property_t * property) { - if (property->name) - free (property->name); - if (property->value) - free (property->value); + free (property->name); + free (property->value); free(property); } -void xml_parser_init(char * buf, int size, int mode) { +void xml_parser_init(const char * buf, int size, int mode) { lexer_init(buf, size); xml_parser_mode = mode; @@ -470,7 +466,7 @@ int xml_parser_build_tree(xml_node_t **root_node) { return res; } -char *xml_parser_get_property (xml_node_t *node, const char *name) { +char *xml_parser_get_property (const xml_node_t *node, const char *name) { xml_property_t *prop; @@ -490,7 +486,7 @@ char *xml_parser_get_property (xml_node_t *node, const char *name) { return NULL; } -int xml_parser_get_property_int (xml_node_t *node, const char *name, +int xml_parser_get_property_int (const xml_node_t *node, const char *name, int def_value) { char *v; @@ -507,7 +503,7 @@ int xml_parser_get_property_int (xml_node_t *node, const char *name, return ret; } -int xml_parser_get_property_bool (xml_node_t *node, const char *name, +int xml_parser_get_property_bool (const xml_node_t *node, const char *name, int def_value) { char *v; @@ -517,10 +513,7 @@ int xml_parser_get_property_bool (xml_node_t *node, const char *name, if (!v) return def_value; - if (!strcasecmp (v, "true")) - return 1; - else - return 0; + return !strcasecmp (v, "true"); } static int xml_escape_string_internal (char *buf, const char *s, @@ -557,28 +550,13 @@ char *xml_escape_string (const char *s, xml_escape_quote_t quote_type) return buf ? (xml_escape_string_internal (buf, s, quote_type), buf) : NULL; } -static void printf_indent (int indent, const char *format, ...) { - - int i ; - va_list argp; - - for (i=0; iname); + printf ("%*s<%s ", indent, "", node->name); l = strlen (node->name); @@ -589,8 +567,7 @@ static void xml_parser_dump_node (xml_node_t *node, int indent) { free (value); p = p->next; if (p) { - printf ("\n"); - printf_indent (indent+2+l, ""); + printf ("\n%*s", indent+2+l, ""); } } printf (">\n"); @@ -603,9 +580,9 @@ static void xml_parser_dump_node (xml_node_t *node, int indent) { n = n->next; } - printf_indent (indent, "\n", node->name); + printf ("%*s\n", indent, "", node->name); } -void xml_parser_dump_tree (xml_node_t *node) { +void xml_parser_dump_tree (const xml_node_t *node) { xml_parser_dump_node (node, 0); } diff --git a/src/xine-utils/xmlparser.h b/src/xine-utils/xmlparser.h index 45217d3f9..35155fa79 100644 --- a/src/xine-utils/xmlparser.h +++ b/src/xine-utils/xmlparser.h @@ -17,7 +17,7 @@ * along with this program; if not, write to the Free Software * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA * - * $Id: xmlparser.h,v 1.3 2005/01/16 17:51:04 dsalt Exp $ + * $Id: xmlparser.h,v 1.4 2006/02/14 02:25:01 dsalt Exp $ * */ #ifndef XML_PARSER_H @@ -48,16 +48,16 @@ typedef struct xml_node_s { struct xml_node_s *next; } xml_node_t; -void xml_parser_init(char * buf, int size, int mode); +void xml_parser_init(const char * buf, int size, int mode); int xml_parser_build_tree(xml_node_t **root_node); void xml_parser_free_tree(xml_node_t *root_node); -char *xml_parser_get_property (xml_node_t *node, const char *name); -int xml_parser_get_property_int (xml_node_t *node, const char *name, +char *xml_parser_get_property (const xml_node_t *node, const char *name); +int xml_parser_get_property_int (const xml_node_t *node, const char *name, int def_value); -int xml_parser_get_property_bool (xml_node_t *node, const char *name, +int xml_parser_get_property_bool (const xml_node_t *node, const char *name, int def_value); /* for output: @@ -76,6 +76,6 @@ char *xml_escape_string (const char *s, xml_escape_quote_t quote_type); * indented fashion */ -void xml_parser_dump_tree (xml_node_t *node) ; +void xml_parser_dump_tree (const xml_node_t *node) ; #endif -- cgit v1.2.3