~ubuntu-branches/ubuntu/wily/pianobar/wily-proposed

« back to all changes in this revision

Viewing changes to src/libezxml/ezxml.h

  • Committer: Bazaar Package Importer
  • Author(s): Luke Faraone
  • Date: 2011-02-08 17:23:25 UTC
  • mfrom: (1.3.3 upstream)
  • Revision ID: james.westby@ubuntu.com-20110208172325-0qf3sxpsu37j5ez9
Tags: 2011.01.24-1
* New upstream version. 
* Switch to DEP5 copyright.
* Augment CFLAGS to use the c99 standard.
* Don't install the now-removed AUTHORS file into docs.
* Drop dep on cmake.

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/* ezxml.h
 
2
 *
 
3
 * Copyright 2004-2006 Aaron Voisine <aaron@voisine.org>
 
4
 *
 
5
 * Permission is hereby granted, free of charge, to any person obtaining
 
6
 * a copy of this software and associated documentation files (the
 
7
 * "Software"), to deal in the Software without restriction, including
 
8
 * without limitation the rights to use, copy, modify, merge, publish,
 
9
 * distribute, sublicense, and/or sell copies of the Software, and to
 
10
 * permit persons to whom the Software is furnished to do so, subject to
 
11
 * the following conditions:
 
12
 *
 
13
 * The above copyright notice and this permission notice shall be included
 
14
 * in all copies or substantial portions of the Software.
 
15
 *
 
16
 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
 
17
 * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
 
18
 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
 
19
 * IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
 
20
 * CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
 
21
 * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
 
22
 * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
 
23
 */
 
24
 
 
25
#ifndef _EZXML_H
 
26
#define _EZXML_H
 
27
 
 
28
#include <stdlib.h>
 
29
#include <stdio.h>
 
30
#include <stdarg.h>
 
31
#include <fcntl.h>
 
32
 
 
33
#define EZXML_BUFSIZE 1024 // size of internal memory buffers
 
34
#define EZXML_NAMEM   0x80 // name is malloced
 
35
#define EZXML_TXTM    0x40 // txt is malloced
 
36
#define EZXML_DUP     0x20 // attribute name and value are strduped
 
37
 
 
38
typedef struct ezxml *ezxml_t;
 
39
struct ezxml {
 
40
    char *name;      // tag name
 
41
    char **attr;     // tag attributes { name, value, name, value, ... NULL }
 
42
    char *txt;       // tag character content, empty string if none
 
43
    size_t off;      // tag offset from start of parent tag character content
 
44
    ezxml_t next;    // next tag with same name in this section at this depth
 
45
    ezxml_t sibling; // next tag with different name in same section and depth
 
46
    ezxml_t ordered; // next tag, same section and depth, in original order
 
47
    ezxml_t child;   // head of sub tag list, NULL if none
 
48
    ezxml_t parent;  // parent tag, NULL if current tag is root tag
 
49
    short flags;     // additional information
 
50
};
 
51
 
 
52
// Given a string of xml data and its length, parses it and creates an ezxml
 
53
// structure. For efficiency, modifies the data by adding null terminators
 
54
// and decoding ampersand sequences. If you don't want this, copy the data and
 
55
// pass in the copy. Returns NULL on failure.
 
56
ezxml_t ezxml_parse_str(char *s, size_t len);
 
57
 
 
58
// returns the first child tag (one level deeper) with the given name or NULL
 
59
// if not found
 
60
ezxml_t ezxml_child(ezxml_t xml, const char *name);
 
61
 
 
62
// returns the next tag of the same name in the same section and depth or NULL
 
63
// if not found
 
64
#define ezxml_next(xml) ((xml) ? xml->next : NULL)
 
65
 
 
66
// Returns the Nth tag with the same name in the same section at the same depth
 
67
// or NULL if not found. An index of 0 returns the tag given.
 
68
ezxml_t ezxml_idx(ezxml_t xml, int idx);
 
69
 
 
70
// returns the name of the given tag
 
71
#define ezxml_name(xml) ((xml) ? xml->name : NULL)
 
72
 
 
73
// returns the given tag's character content or empty string if none
 
74
#define ezxml_txt(xml) ((xml) ? xml->txt : "")
 
75
 
 
76
// returns the value of the requested tag attribute, or NULL if not found
 
77
const char *ezxml_attr(ezxml_t xml, const char *attr);
 
78
 
 
79
// Traverses the ezxml sturcture to retrieve a specific subtag. Takes a
 
80
// variable length list of tag names and indexes. The argument list must be
 
81
// terminated by either an index of -1 or an empty string tag name. Example: 
 
82
// title = ezxml_get(library, "shelf", 0, "book", 2, "title", -1);
 
83
// This retrieves the title of the 3rd book on the 1st shelf of library.
 
84
// Returns NULL if not found.
 
85
ezxml_t ezxml_get(ezxml_t xml, ...);
 
86
 
 
87
// frees the memory allocated for an ezxml structure
 
88
void ezxml_free(ezxml_t xml);
 
89
    
 
90
// returns parser error message or empty string if none
 
91
const char *ezxml_error(ezxml_t xml);
 
92
 
 
93
#endif // _EZXML_H