libcmml  0.9.1
cmml.h
Go to the documentation of this file.
1 /* Copyright (C) 2003 CSIRO Australia
2 
3  Redistribution and use in source and binary forms, with or without
4  modification, are permitted provided that the following conditions
5  are met:
6 
7  - Redistributions of source code must retain the above copyright
8  notice, this list of conditions and the following disclaimer.
9 
10  - Redistributions in binary form must reproduce the above copyright
11  notice, this list of conditions and the following disclaimer in the
12  documentation and/or other materials provided with the distribution.
13 
14  - Neither the name of the CSIRO nor the names of its
15  contributors may be used to endorse or promote products derived from
16  this software without specific prior written permission.
17 
18  THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
19  ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
20  LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A
21  PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE ORGANISATION OR
22  CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
23  EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
24  PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
25  PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
26  LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
27  NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
28  SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
29 */
30 
31 /* cmml.h */
32 
33 #ifndef __CMML_H__
34 #define __CMML_H__
35 
43 #include <stdio.h>
44 #include <expat.h>
45 
49 #ifndef _CMML_PRIVATE
50 typedef void CMML;
51 #endif
52 
53 /* ------------------------- TYPES --------------------------------- */
54 /* CMML_Time and CMML_List are kept here and not in cmml_private.h */
55 /* because the library user may need detailed access to these fields */
56 
61 typedef struct {
62  short tm_hsec;
63  short tm_sec;
64  short tm_min;
65  short tm_hour;
66  short tm_mday;
67  short tm_mon;
68  short tm_year;
70 } CMML_UTC;
71 
75 typedef enum _CMML_Time_Type {
79 
80 
85 typedef struct {
86  char *tstr;
89  union {
91  double sec;
92  } t;
93 } CMML_Time ;
94 
95 
99 typedef struct _CMML_List CMML_List;
105 struct _CMML_List {
108  void * data;
109 };
110 
114 typedef void * (*CMML_CloneFunc) (void * data);
115 
119 typedef void * (*CMML_FreeFunc) (void * data);
120 
128 typedef int (*CMML_CmpFunc) (void * cmp_ctx, void * s1, void * s2);
129 
130 
136 typedef struct {
137  char *xml_version;
138  char *xml_encoding;
141  char *cmml_lang;
142  char *cmml_dir;
143  char *cmml_id;
144  char *cmml_xmlns;
146 } CMML_Preamble;
147 
148 
153 typedef struct {
154  char *id;
155  char *name;
156  char *value;
158 
162 typedef struct {
163  char *id;
164  char *lang;
165  char *dir;
166  char *granulerate;
167  char *contenttype;
168  char *src;
171  char *title;
175 
182 typedef struct {
183  char *id;
186  CMML_List * import;
187 } CMML_Stream;
188 
189 
194 typedef struct {
195  char *id;
196  char *lang;
197  char *dir;
198  char *name;
199  char *content;
200  char *scheme;
202 
207 typedef struct {
208  char *id;
209  char *class;
210  char *title;
211  char *lang;
212  char *dir;
213  char *href;
214  char *type;
215  char *rel;
216  char *rev;
217  char *media;
219 
223 typedef struct {
224  char *head_id;
225  char *lang;
226  char *dir;
227  char *profile;
228  char *title;
229  char *title_id;
230  char *title_lang;
231  char *title_dir;
232  char *base_id;
233  char *base_href;
236 } CMML_Head;
237 
238 
242 typedef struct {
243  char *clip_id;
244  char *class;
245  char *title;
246  char *lang;
247  char *dir;
248  char *track;
252  char *anchor_id;
253  char *anchor_class;
254  char *anchor_title;
255  char *anchor_lang;
256  char *anchor_dir;
257  char *anchor_href;
258  char *anchor_text;
259  char *img_id;
260  char *img_class;
261  char *img_title;
262  char *img_lang;
263  char *img_dir;
264  char *img_src;
265  char *img_alt;
266  char *desc_id;
267  char *desc_class;
268  char *desc_title;
269  char *desc_lang;
270  char *desc_dir;
271  char *desc_text;
272 } CMML_Clip;
273 
278 typedef enum _CMML_Element_Type {
286 
287 
293 typedef struct {
296  union {
300  } e;
301 } CMML_Element;
302 
303 
312 typedef enum _CMML_Error_Type {
313  /* general processing feedback */
316  /* fatal errors */
328  /* sloppy errors */
335 
340 typedef struct {
342  long line;
343  long col;
344 } CMML_Error;
345 
357 typedef int (*CMMLReadStream) (CMML *cmml, const CMML_Stream *stream,
358  void * user_data);
370 typedef int (*CMMLReadHead) (CMML *cmml, const CMML_Head *head,
371  void * user_data);
372 
384 typedef int (*CMMLReadClip) (CMML *cmml, const CMML_Clip *clip,
385  void * user_data);
386 
387 
388 /* ---------------------- API --------------------------------*/
389 
390 /* --------------------------------- *
391  * CMML parsing: functions in cmml.c *
392  * --------------------------------- */
393 
404 CMML * cmml_open (char *XMLfilename);
405 
417 CMML * cmml_new (FILE * file);
418 
427 FILE * cmml_destroy (CMML * cmml);
428 
437 CMML * cmml_close (CMML * cmml);
438 
454 int cmml_set_read_callbacks (CMML *cmml,
458  void * user_data);
459 
472 long cmml_read (CMML *cmml, long n); /* file */
473 
483 void cmml_set_sloppy (CMML *cmml, int value);
484 
494 
504 
514 
524 
535 
546 
547 
553 void cmml_error_clear (CMML * cmml);
554 
565 int cmml_set_window (CMML * cmml, CMML_Time * start, CMML_Time * end);
566 
576 double cmml_skip_to_secs (CMML *cmml, double seconds);
577 
587 double cmml_skip_to_utc (CMML *cmml, const char * utc);
588 
598 double cmml_skip_to_id (CMML *cmml, const char * id);
599 
609 double cmml_skip_to_offset (CMML *cmml, const char * offset);
610 
611 
612 /* ---------------------------------------------------- *
613  * CMML element handling: cmml_element.c cmml_snprint.c *
614  * ---------------------------------------------------- */
615 
627 CMML_Preamble * cmml_preamble_new (char *encoding, char *id, char *lang, char *dir, char *granulerate);
628 
637 
644 
650 CMML_Head * cmml_head_new (void);
651 
660 CMML_Clip * cmml_clip_new (CMML_Time *start_time, CMML_Time *end_time);
661 
670 
679 
688 
697 
706 
715 
722 void cmml_preamble_destroy (CMML_Preamble *preamble);
723 
730 void cmml_element_destroy (CMML_Element *element);
731 
737 void cmml_stream_destroy (CMML_Stream *stream);
738 
744 void cmml_head_destroy (CMML_Head *head);
745 
751 void cmml_clip_destroy (CMML_Clip *clip);
752 
758 void cmml_error_destroy (CMML_Error *error);
759 
771 int cmml_preamble_snprint(char *buf, int n, CMML_Preamble *pre);
772 
785 int cmml_element_snprint (char *buf, int n, CMML_Element *elem);
786 
797 int cmml_stream_snprint (char *buf, int n, CMML_Stream *stream);
798 
809 int cmml_stream_pretty_snprint (char *buf, int n, CMML_Stream *stream);
810 
821 int cmml_head_snprint (char *buf, int n, CMML_Head *head);
822 
833 int cmml_head_pretty_snprint (char *buf, int n, CMML_Head *head);
834 
845 int cmml_clip_snprint (char *buf, int n, CMML_Clip *clip);
846 
857 int cmml_clip_pretty_snprint (char *buf, int n, CMML_Clip *clip);
858 
870 int cmml_error_snprint (char *buf, int n, CMML_Error *error, CMML *cmml);
871 
872 
873 /* ----------------------------------------------- *
874  * helper functions for list handling: cmml_list.c *
875  * ----------------------------------------------- */
876 
882 CMML_List * cmml_list_new (void);
883 
892 
902 
911 
920 CMML_List * cmml_list_prepend (CMML_List * list, void * data);
921 
930 CMML_List * cmml_list_append (CMML_List * list, void * data);
931 
942 CMML_List * cmml_list_add_before (CMML_List * list, void * data,
943  CMML_List * node);
954 CMML_List * cmml_list_add_after (CMML_List * list, void * data,
955  CMML_List * node);
956 
965 CMML_List * cmml_list_find (CMML_List * list, void * data);
966 
975 CMML_List * cmml_list_remove (CMML_List * list, CMML_List * node);
976 
984 int cmml_list_length (CMML_List * list);
985 
993 int cmml_list_is_empty (CMML_List * list);
994 
1003 int cmml_list_is_singleton (CMML_List * list);
1004 
1015  CMML_FreeFunc free_func);
1016 
1026 
1027 
1028 /* ----------------------------------------------- *
1029  * helper functions for time handling: cmml_time.c *
1030  * ----------------------------------------------- */
1031 
1040 CMML_Time * cmml_time_new (const char * s);
1041 
1049 CMML_Time * cmml_sec_new (const char * s);
1050 
1058 CMML_Time * cmml_time_new_secs (double seconds);
1059 
1067 CMML_Time * cmml_utc_new (const char * s);
1068 
1082 int cmml_time_interval_new (const char * s,
1083  CMML_Time ** t_start, CMML_Time ** t_end);
1084 
1096 CMML_Time *cmml_time_new_in_sec (const char * s, CMML_Time * ref, double base);
1097 
1108 CMML_Time *cmml_time_utc_to_sec (CMML_Time * t, CMML_Time * ref, double base);
1109 
1115 void cmml_time_free (CMML_Time *t);
1116 
1125 
1133 double cmml_sec_parse (const char *s);
1134 
1143 CMML_UTC * cmml_utc_parse (const char * s);
1144 
1153 
1163 double cmml_utc_diff (CMML_UTC *t2, CMML_UTC *t1);
1164 
1175 int cmml_npt_snprint (char * buf, int n, double seconds);
1176 
1187 int cmml_utc_snprint (char *buf, int n, CMML_UTC *t);
1188 
1199 int cmml_utc_pretty_snprint (char *buf, int n, CMML_UTC *t);
1200 
1201 
1202 
1203 #endif /* __CMML_H__ */
CMML_Time * cmml_time_new(const char *s)
void cmml_preamble_destroy(CMML_Preamble *preamble)
Definition: cmml.h:153
double cmml_skip_to_utc(CMML *cmml, const char *utc)
CMML_Time * cmml_time_new_secs(double seconds)
CMML_List * cmml_list_clone(CMML_List *list)
CMML_List * cmml_list_find(CMML_List *list, void *data)
Definition: cmml.h:223
Definition: cmml.h:320
void cmml_clip_destroy(CMML_Clip *clip)
CMML_List * cmml_list_free_with(CMML_List *list, CMML_FreeFunc free_func)
double cmml_skip_to_id(CMML *cmml, const char *id)
void cmml_stream_destroy(CMML_Stream *stream)
short tm_mon
Definition: cmml.h:67
Definition: cmml.h:331
Definition: cmml.h:76
Definition: cmml.h:293
short tm_sec
Definition: cmml.h:63
int cmml_clip_snprint(char *buf, int n, CMML_Clip *clip)
_CMML_Element_Type
Definition: cmml.h:278
CMML_Element * cmml_element_new(CMML_Element_Type type)
CMML_Time * cmml_time_utc_to_sec(CMML_Time *t, CMML_Time *ref, double base)
char * lang
Definition: cmml.h:225
Definition: cmml.h:315
Definition: cmml.h:105
_CMML_Error_Type
Definition: cmml.h:312
char * clip_id
Definition: cmml.h:243
CMML_Error * cmml_get_last_error(CMML *cmml)
CMML_Stream * cmml_get_last_stream(CMML *cmml)
CMML_Time * cmml_time_clone(CMML_Time *t)
char * desc_class
Definition: cmml.h:267
char * tstr
Definition: cmml.h:86
CMML_Stream * cmml_stream_new(void)
char * img_lang
Definition: cmml.h:262
CMML_Time * start_time
Definition: cmml.h:249
char * name
Definition: cmml.h:155
short tm_min
Definition: cmml.h:64
char * id
Definition: cmml.h:183
char * lang
Definition: cmml.h:196
CMML_List * cmml_list_append(CMML_List *list, void *data)
Definition: cmml.h:330
char * dir
Definition: cmml.h:247
FILE * cmml_destroy(CMML *cmml)
CMML_List * param
Definition: cmml.h:172
char * media
Definition: cmml.h:217
char * href
Definition: cmml.h:213
CMML_List * cmml_list_remove(CMML_List *list, CMML_List *node)
char * content
Definition: cmml.h:199
char * lang
Definition: cmml.h:246
char * anchor_id
Definition: cmml.h:252
CMML_Element_Type type
Definition: cmml.h:294
char * id
Definition: cmml.h:154
CMML_Clip * clip
Definition: cmml.h:299
char * base_href
Definition: cmml.h:233
CMML_Time * cmml_sec_new(const char *s)
char * name
Definition: cmml.h:198
char * cmml_dir
Definition: cmml.h:142
CMML_Preamble * cmml_get_preamble(CMML *cmml)
int cmml_list_is_singleton(CMML_List *list)
CMML_Time_Type type
Definition: cmml.h:87
char * dir
Definition: cmml.h:165
char * img_id
Definition: cmml.h:259
double cmml_skip_to_secs(CMML *cmml, double seconds)
int cmml_set_read_callbacks(CMML *cmml, CMMLReadStream read_stream, CMMLReadHead read_head, CMMLReadClip read_clip, void *user_data)
void *(* CMML_CloneFunc)(void *data)
Definition: cmml.h:114
CMML_Stream * stream
Definition: cmml.h:297
CMML_Clip * cmml_get_last_clip(CMML *cmml)
char * cmml_xmlns
Definition: cmml.h:144
char * id
Definition: cmml.h:208
char * desc_title
Definition: cmml.h:268
char * track
Definition: cmml.h:248
int cmml_utc_snprint(char *buf, int n, CMML_UTC *t)
int(* CMMLReadStream)(CMML *cmml, const CMML_Stream *stream, void *user_data)
Definition: cmml.h:357
Definition: cmml.h:324
Definition: cmml.h:327
char * contenttype
Definition: cmml.h:167
int(* CMMLReadClip)(CMML *cmml, const CMML_Clip *clip, void *user_data)
Definition: cmml.h:384
int doctype_declared
Definition: cmml.h:140
CMML_Time * cmml_utc_new(const char *s)
CMML_List * cmml_list_add_before(CMML_List *list, void *data, CMML_List *node)
CMML_Time * basetime
Definition: cmml.h:184
CMML_List * link
Definition: cmml.h:235
long cmml_read(CMML *cmml, long n)
char * rev
Definition: cmml.h:216
char * title_lang
Definition: cmml.h:230
int cmml_stream_pretty_snprint(char *buf, int n, CMML_Stream *stream)
CMML_List * cmml_list_prepend(CMML_List *list, void *data)
Definition: cmml.h:194
long line
Definition: cmml.h:342
char * xml_version
Definition: cmml.h:137
char * title
Definition: cmml.h:210
CMML_Stream * cmml_stream_clone(CMML_Stream *src)
CMML_List * next
Definition: cmml.h:107
void cmml_head_destroy(CMML_Head *head)
char * img_title
Definition: cmml.h:261
Definition: cmml.h:77
static int read_stream(CMML *cmml, const CMML_Stream *stream, void *user_data)
Definition: cmml-validate.c:133
Definition: cmml.h:207
char * img_dir
Definition: cmml.h:263
char * anchor_class
Definition: cmml.h:253
CMML_List * cmml_list_clone_with(CMML_List *list, CMML_CloneFunc clone)
CMML_Error_Type type
Definition: cmml.h:341
int cmml_npt_snprint(char *buf, int n, double seconds)
void CMML
Definition: cmml.h:50
CMML_List * meta
Definition: cmml.h:251
CMML_List * cmml_list_tail(CMML_List *list)
CMML * cmml_close(CMML *cmml)
char * anchor_lang
Definition: cmml.h:255
char * desc_id
Definition: cmml.h:266
Definition: cmml.h:242
int cmml_list_is_empty(CMML_List *list)
char * dir
Definition: cmml.h:226
char * img_src
Definition: cmml.h:264
char * title_dir
Definition: cmml.h:231
CMML_Clip * cmml_get_previous_clip(CMML *cmml)
char * lang
Definition: cmml.h:211
Definition: cmml.h:284
char * anchor_text
Definition: cmml.h:258
CMML_List * cmml_list_free(CMML_List *list)
void cmml_error_destroy(CMML_Error *error)
char * value
Definition: cmml.h:156
CMML_Time * end_time
Definition: cmml.h:250
Definition: cmml.h:314
Definition: cmml.h:162
char * scheme
Definition: cmml.h:200
int cmml_element_snprint(char *buf, int n, CMML_Element *elem)
CMML_Head * head
Definition: cmml.h:298
Definition: cmml.h:85
Definition: cmml.h:319
CMML_Preamble * cmml_preamble_new(char *encoding, char *id, char *lang, char *dir, char *granulerate)
short tm_hour
Definition: cmml.h:65
Definition: cmml.h:318
Definition: cmml.h:325
CMML_Head * cmml_head_new(void)
CMML_Clip * cmml_clip_new(CMML_Time *start_time, CMML_Time *end_time)
Definition: cmml.h:322
double cmml_utc_diff(CMML_UTC *t2, CMML_UTC *t1)
void * data
Definition: cmml.h:108
CMML * cmml_open(char *XMLfilename)
char * head_id
Definition: cmml.h:224
Definition: cmml.h:283
char * dir
Definition: cmml.h:197
CMML * cmml_new(FILE *file)
int cmml_clip_pretty_snprint(char *buf, int n, CMML_Clip *clip)
char * anchor_dir
Definition: cmml.h:256
Definition: cmml.h:282
enum _CMML_Element_Type CMML_Element_Type
CMML_List * meta
Definition: cmml.h:234
char * src
Definition: cmml.h:168
char * cmml_granulerate
Definition: cmml.h:145
char * anchor_title
Definition: cmml.h:254
CMML_Error * cmml_error_new(CMML_Error_Type type)
CMML_Element * cmml_element_clone(CMML_Element *src)
int cmml_error_snprint(char *buf, int n, CMML_Error *error, CMML *cmml)
char * cmml_lang
Definition: cmml.h:141
void *(* CMML_FreeFunc)(void *data)
Definition: cmml.h:119
Definition: cmml.h:340
Definition: cmml.h:323
CMML_Clip * cmml_clip_clone(CMML_Clip *src)
int(* CMML_CmpFunc)(void *cmp_ctx, void *s1, void *s2)
Definition: cmml.h:128
Definition: cmml.h:326
char * desc_dir
Definition: cmml.h:270
char * title
Definition: cmml.h:228
int cmml_list_length(CMML_List *list)
short tm_hsec
Definition: cmml.h:62
enum _CMML_Error_Type CMML_Error_Type
Definition: cmml.h:136
long col
Definition: cmml.h:343
Definition: cmml.h:321
Definition: cmml.h:332
double cmml_sec_parse(const char *s)
void cmml_set_sloppy(CMML *cmml, int value)
char * cmml_id
Definition: cmml.h:143
CMML_Time * cmml_time_new_in_sec(const char *s, CMML_Time *ref, double base)
Definition: cmml.h:279
char * id
Definition: cmml.h:163
CMML_Time * end_time
Definition: cmml.h:170
char * xml_encoding
Definition: cmml.h:138
int cmml_utc_pretty_snprint(char *buf, int n, CMML_UTC *t)
Definition: cmml.h:317
Definition: cmml.h:281
short tm_mday
Definition: cmml.h:66
int(* CMMLReadHead)(CMML *cmml, const CMML_Head *head, void *user_data)
Definition: cmml.h:370
CMML_List * prev
Definition: cmml.h:106
Definition: cmml.h:182
char * img_alt
Definition: cmml.h:265
void cmml_time_free(CMML_Time *t)
int cmml_preamble_snprint(char *buf, int n, CMML_Preamble *pre)
enum _CMML_Time_Type CMML_Time_Type
char * type
Definition: cmml.h:214
CMML_List * cmml_list_new(void)
int cmml_set_window(CMML *cmml, CMML_Time *start, CMML_Time *end)
void cmml_error_clear(CMML *cmml)
static int read_clip(CMML *cmml, const CMML_Clip *clip, void *user_data)
Definition: cmml-validate.c:189
int xml_standalone
Definition: cmml.h:139
char * lang
Definition: cmml.h:164
CMML_Time * start_time
Definition: cmml.h:169
char * base_id
Definition: cmml.h:232
Definition: cmml.h:333
int cmml_head_pretty_snprint(char *buf, int n, CMML_Head *head)
char * title
Definition: cmml.h:245
char * id
Definition: cmml.h:195
CMML_UTC * cmml_utc_parse(const char *s)
CMML_UTC * utc
Definition: cmml.h:90
CMML_Time * utc
Definition: cmml.h:185
int cmml_head_snprint(char *buf, int n, CMML_Head *head)
char * granulerate
Definition: cmml.h:166
CMML_List * cmml_list_add_after(CMML_List *list, void *data, CMML_List *node)
char * img_class
Definition: cmml.h:260
CMML_Head * cmml_head_clone(CMML_Head *src)
char * desc_text
Definition: cmml.h:271
CMML_Preamble * cmml_preamble_clone(CMML_Preamble *src)
int cmml_stream_snprint(char *buf, int n, CMML_Stream *stream)
short tm_year
Definition: cmml.h:68
double sec
Definition: cmml.h:91
char * anchor_href
Definition: cmml.h:257
void cmml_element_destroy(CMML_Element *element)
Definition: cmml.h:61
Definition: cmml.h:329
_CMML_Time_Type
Definition: cmml.h:75
char * rel
Definition: cmml.h:215
char * title
Definition: cmml.h:171
double cmml_skip_to_offset(CMML *cmml, const char *offset)
Definition: cmml.h:280
int cmml_time_interval_new(const char *s, CMML_Time **t_start, CMML_Time **t_end)
char * desc_lang
Definition: cmml.h:269
char * dir
Definition: cmml.h:212
CMML_Head * cmml_get_last_head(CMML *cmml)
CMML_UTC * cmml_utc_clone(CMML_UTC *t)
static int read_head(CMML *cmml, const CMML_Head *head, void *user_data)
Definition: cmml-validate.c:161
char * title_id
Definition: cmml.h:229
char * profile
Definition: cmml.h:227