Bug 470455 - test_database_sync_embed_visits.js leaks, r=sdwilsh
[wine-gecko.git] / media / libtheora / lib / dec / info.c
blobd4989efd547a84e87901d1aaa1bcc61a13b3fdc1
1 /********************************************************************
2 * *
3 * THIS FILE IS PART OF THE OggTheora SOFTWARE CODEC SOURCE CODE. *
4 * USE, DISTRIBUTION AND REPRODUCTION OF THIS LIBRARY SOURCE IS *
5 * GOVERNED BY A BSD-STYLE SOURCE LICENSE INCLUDED WITH THIS SOURCE *
6 * IN 'COPYING'. PLEASE READ THESE TERMS BEFORE DISTRIBUTING. *
7 * *
8 * THE Theora SOURCE CODE IS COPYRIGHT (C) 2002-2007 *
9 * by the Xiph.Org Foundation http://www.xiph.org/ *
10 * *
11 ********************************************************************
13 function:
14 last mod: $Id: info.c 13884 2007-09-22 08:38:10Z giles $
16 ********************************************************************/
18 #include <stdlib.h>
19 #include <ctype.h>
20 #include <string.h>
21 #include "../internal.h"
25 /*This is more or less the same as strncasecmp, but that doesn't exist
26 everywhere, and this is a fairly trivial function, so we include it.
27 Note: We take advantage of the fact that we know _n is less than or equal to
28 the length of at least one of the strings.*/
29 static int oc_tagcompare(const char *_s1,const char *_s2,int _n){
30 int c;
31 for(c=0;c<_n;c++){
32 if(toupper(_s1[c])!=toupper(_s2[c]))return !0;
34 return _s1[c]!='=';
39 void th_info_init(th_info *_info){
40 memset(_info,0,sizeof(*_info));
41 _info->version_major=TH_VERSION_MAJOR;
42 _info->version_minor=TH_VERSION_MINOR;
43 _info->version_subminor=TH_VERSION_SUB;
44 _info->keyframe_granule_shift=6;
47 void th_info_clear(th_info *_info){
48 memset(_info,0,sizeof(*_info));
53 void th_comment_init(th_comment *_tc){
54 memset(_tc,0,sizeof(*_tc));
57 void th_comment_add(th_comment *_tc,char *_comment){
58 int comment_len;
59 _tc->user_comments=_ogg_realloc(_tc->user_comments,
60 (_tc->comments+2)*sizeof(*_tc->user_comments));
61 _tc->comment_lengths=_ogg_realloc(_tc->comment_lengths,
62 (_tc->comments+2)*sizeof(*_tc->comment_lengths));
63 comment_len=strlen(_comment);
64 _tc->comment_lengths[_tc->comments]=comment_len;
65 _tc->user_comments[_tc->comments]=_ogg_malloc(comment_len+1);
66 memcpy(_tc->user_comments[_tc->comments],_comment,comment_len+1);
67 _tc->comments++;
68 _tc->user_comments[_tc->comments]=NULL;
71 void th_comment_add_tag(th_comment *_tc,char *_tag,char *_val){
72 char *comment;
73 int tag_len;
74 int val_len;
75 tag_len=strlen(_tag);
76 val_len=strlen(_val);
77 /*+2 for '=' and '\0'.*/
78 comment=_ogg_malloc(tag_len+val_len+2);
79 memcpy(comment,_tag,tag_len);
80 comment[tag_len]='=';
81 memcpy(comment+tag_len+1,_val,val_len+1);
82 th_comment_add(_tc,comment);
83 _ogg_free(comment);
86 char *th_comment_query(th_comment *_tc,char *_tag,int _count){
87 long i;
88 int found;
89 int tag_len;
90 tag_len=strlen(_tag);
91 found=0;
92 for(i=0;i<_tc->comments;i++){
93 if(!oc_tagcompare(_tc->user_comments[i],_tag,tag_len)){
94 /*We return a pointer to the data, not a copy.*/
95 if(_count==found++)return _tc->user_comments[i]+tag_len+1;
98 /*Didn't find anything.*/
99 return NULL;
102 int th_comment_query_count(th_comment *_tc,char *_tag){
103 long i;
104 int tag_len;
105 int count;
106 tag_len=strlen(_tag);
107 count=0;
108 for(i=0;i<_tc->comments;i++){
109 if(!oc_tagcompare(_tc->user_comments[i],_tag,tag_len))count++;
111 return count;
114 void th_comment_clear(th_comment *_tc){
115 if(_tc!=NULL){
116 long i;
117 for(i=0;i<_tc->comments;i++)_ogg_free(_tc->user_comments[i]);
118 _ogg_free(_tc->user_comments);
119 _ogg_free(_tc->comment_lengths);
120 _ogg_free(_tc->vendor);
121 memset(_tc,0,sizeof(*_tc));