Smrender
 All Data Structures Files Functions Variables Macros
libhpxml.h
Go to the documentation of this file.
1 /* Copyright 2011 Bernhard R. Fischer, 2048R/5C5FFD47 <bf@abenteuerland.at>
2  *
3  * This file is part of libhpxml.
4  *
5  * Libhpxml is free software: you can redistribute it and/or modify
6  * it under the terms of the GNU General Public License as published by
7  * the Free Software Foundation, version 3 of the License.
8  *
9  * Libhpxml is distributed in the hope that it will be useful,
10  * but WITHOUT ANY WARRANTY; without even the implied warranty of
11  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12  * GNU General Public License for more details.
13  *
14  * You should have received a copy of the GNU General Public License
15  * along with libhpxml. If not, see <http://www.gnu.org/licenses/>.
16  */
17 
25 #ifndef HPXML_H
26 #define HPXML_H
27 
28 #include <stdio.h>
29 #include <stdlib.h>
30 #include <ctype.h>
31 
32 #include "bstring.h"
33 
34 
35 #define IS_XML1CHAR(x) (isalpha(x) || (x == '_') || (x == ':'))
36 #define IS_XMLCHAR(x) (isalpha(x) || isdigit(x) || (x == '.') || (x == '-') || (x == '_') || (x == ':'))
37 
38 #define hpx_init_simple() hpx_init(0, 10*1024*1024)
39 
40 #define MMAP_PAGES (1L << 15)
41 
42 
43 typedef struct hpx_ctrl
44 {
46  //bstring_t buf;
47  struct bstringl buf;
49  int fd;
51  short eof;
53  long len;
55  long pos;
57  int in_tag;
59  short empty;
61  short mmap;
63  char *madv_ptr;
65  long pg_siz;
67  long pg_blk_siz;
68 } hpx_ctrl_t;
69 
70 typedef struct hpx_attr
71 {
72  bstring_t name;
74  char delim;
75 } hpx_attr_t;
76 
77 typedef struct hpx_tag
78 {
79  bstring_t tag;
80  int type;
81  long line;
82  int nattr;
83  int mattr;
84  hpx_attr_t attr[];
85 } hpx_tag_t;
86 
87 typedef struct hpx_tree
88 {
89  hpx_tag_t *tag;
90  int nsub;
91  int msub;
92  struct hpx_tree *subtag[];
93 } hpx_tree_t;
94 
95 enum
96 {
97  HPX_ILL, HPX_OPEN, HPX_SINGLE, HPX_CLOSE, HPX_LITERAL, HPX_ATT, HPX_INSTR, HPX_COMMENT
98 };
99 
100 
101 long hpx_lineno(void);
102 void hpx_tm_free(hpx_tag_t *t);
104 hpx_tag_t *hpx_tm_create(int n);
106 hpx_ctrl_t *hpx_init(int fd, long len);
107 void hpx_init_membuf(hpx_ctrl_t *ctl, void *buf, int len);
108 void hpx_free(hpx_ctrl_t *ctl);
109 int hpx_get_elem(hpx_ctrl_t *ctl, bstring_t *b, int *in_tag, long *lno);
110 long hpx_get_eleml(hpx_ctrl_t *ctl, bstringl_t *b, int *in_tag, long *lno);
111 int hpx_fprintf_tag(FILE *f, const hpx_tag_t *p);
112 int hpx_tree_resize(hpx_tree_t **tl, int n);
113 
114 #endif
115 
long pos
current working position
Definition: libhpxml.h:55
long hpx_get_eleml(hpx_ctrl_t *ctl, bstringl_t *b, int *in_tag, long *lno)
Definition: libhpxml.c:552
long pg_siz
system page size
Definition: libhpxml.h:65
short empty
flag set if data should be read from file
Definition: libhpxml.h:59
Definition: bstring.h:34
hpx_ctrl_t * hpx_init(int fd, long len)
Definition: libhpxml.c:457
int in_tag
flag to deter if next element is in or out of tag
Definition: libhpxml.h:57
short eof
flag set if eof
Definition: libhpxml.h:51
short mmap
flag set if data is memory mapped
Definition: libhpxml.h:61
long pg_blk_siz
length of advised region (multiple of sysconf(_SC_PAGESIZE))
Definition: libhpxml.h:67
void hpx_init_membuf(hpx_ctrl_t *ctl, void *buf, int len)
Definition: libhpxml.c:519
long len
total length of buffer
Definition: libhpxml.h:53
void hpx_tm_free_tree(hpx_tree_t *)
Definition: libhpxml.c:72
Definition: libhpxml.h:70
Definition: libhpxml.h:77
int fd
file descriptor of input file
Definition: libhpxml.h:49
Definition: bstring.h:28
bstring_t value
name of attribute
Definition: libhpxml.h:73
char delim
value of attribute
Definition: libhpxml.h:74
char * madv_ptr
pointer to madvise()'d region (MADV_WILLNEED)
Definition: libhpxml.h:63
int hpx_process_elem(bstring_t b, hpx_tag_t *p)
Definition: libhpxml.c:173
Definition: libhpxml.h:87
Definition: libhpxml.h:43
int hpx_tree_resize(hpx_tree_t **tl, int n)
Definition: libhpxml.c:708